2018-02-04 03:22:01 +01:00
|
|
|
// Matrix Construct
|
|
|
|
//
|
|
|
|
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
|
|
|
// Copyright (C) 2016-2018 Jason Volk <jason@zemos.net>
|
|
|
|
//
|
|
|
|
// Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice is present in all copies. The
|
|
|
|
// full license for this software is available in the LICENSE file.
|
2017-11-16 02:37:09 +01:00
|
|
|
|
2019-09-25 21:48:00 +02:00
|
|
|
namespace ircd::m
|
|
|
|
{
|
2019-09-27 04:28:25 +02:00
|
|
|
static void on_load(), on_unload() noexcept;
|
2019-09-25 21:48:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ircd::mapi::header
|
|
|
|
IRCD_MODULE
|
|
|
|
{
|
|
|
|
"Matrix Chat Protocol",
|
|
|
|
ircd::m::on_load,
|
|
|
|
ircd::m::on_unload,
|
|
|
|
};
|
|
|
|
|
2018-03-28 22:05:15 +02:00
|
|
|
decltype(ircd::m::log)
|
|
|
|
ircd::m::log
|
|
|
|
{
|
2019-08-04 01:25:43 +02:00
|
|
|
"m", 'm'
|
2018-03-28 22:05:15 +02:00
|
|
|
};
|
|
|
|
|
2020-03-05 18:48:17 +01:00
|
|
|
decltype(ircd::m::canon_port)
|
|
|
|
ircd::m::canon_port
|
|
|
|
{
|
|
|
|
8448
|
|
|
|
};
|
|
|
|
|
|
|
|
decltype(ircd::m::canon_service)
|
|
|
|
ircd::m::canon_service
|
|
|
|
{
|
|
|
|
"matrix"
|
|
|
|
};
|
|
|
|
|
2019-10-01 05:50:58 +02:00
|
|
|
/// This is an ordered list for loading and unloading modules. This is not the
|
|
|
|
/// solution I really want at all so consider it temporary. Modules are loaded
|
|
|
|
/// in the order of the lines and unloaded in reverse order.
|
2022-03-21 23:23:47 +01:00
|
|
|
decltype(ircd::m::module_names)
|
|
|
|
ircd::m::module_names
|
2019-10-01 05:50:58 +02:00
|
|
|
{
|
2019-10-03 21:15:41 +02:00
|
|
|
"well_known",
|
|
|
|
"web_root",
|
|
|
|
"web_hook",
|
|
|
|
"stats",
|
|
|
|
|
2019-10-04 04:12:10 +02:00
|
|
|
"key_query",
|
|
|
|
"key_server",
|
|
|
|
|
|
|
|
"identity_pubkey",
|
|
|
|
"identity_v1",
|
|
|
|
|
2019-10-01 05:50:58 +02:00
|
|
|
"m_noop",
|
2020-08-23 04:22:41 +02:00
|
|
|
"m_breadcrumbs",
|
2020-04-10 02:24:50 +02:00
|
|
|
"m_bridge",
|
2023-02-14 03:58:33 +01:00
|
|
|
"m_bridge_register",
|
2019-10-01 05:50:58 +02:00
|
|
|
"m_command",
|
|
|
|
"m_control",
|
|
|
|
"m_device",
|
|
|
|
"m_device_list_update",
|
2021-01-04 21:58:40 +01:00
|
|
|
"m_signing_key_update",
|
2019-10-01 05:50:58 +02:00
|
|
|
"m_direct",
|
|
|
|
"m_direct_to_device",
|
|
|
|
"m_ignored_user_list",
|
|
|
|
"m_listen",
|
|
|
|
"m_presence",
|
|
|
|
"m_profile",
|
2020-03-22 03:31:21 +01:00
|
|
|
"m_push",
|
2020-10-24 15:58:31 +02:00
|
|
|
"m_pusher",
|
2019-10-01 05:50:58 +02:00
|
|
|
"m_receipt",
|
2020-03-11 05:59:15 +01:00
|
|
|
"m_relation",
|
2019-10-01 05:50:58 +02:00
|
|
|
"m_room_aliases",
|
|
|
|
"m_room_canonical_alias",
|
|
|
|
"m_room_create",
|
|
|
|
"m_room_history_visibility",
|
|
|
|
"m_room_join_rules",
|
|
|
|
"m_room_member",
|
|
|
|
"m_room_message",
|
|
|
|
"m_room_name",
|
|
|
|
"m_room_power_levels",
|
|
|
|
"m_room_redaction",
|
|
|
|
"m_room_server_acl",
|
|
|
|
"m_room_third_party_invite",
|
2020-11-12 00:33:48 +01:00
|
|
|
"m_room_tombstone",
|
2019-10-01 05:50:58 +02:00
|
|
|
|
2020-07-14 01:11:59 +02:00
|
|
|
"media_media",
|
|
|
|
|
2019-10-01 05:50:58 +02:00
|
|
|
"federation_backfill",
|
|
|
|
"federation_event_auth",
|
|
|
|
"federation_event",
|
|
|
|
"federation_get_groups_publicised",
|
|
|
|
"federation_get_missing_events",
|
2022-07-02 21:44:12 +02:00
|
|
|
"federation_hierarchy",
|
2019-10-01 05:50:58 +02:00
|
|
|
"federation_invite",
|
|
|
|
"federation_make_join",
|
|
|
|
"federation_make_leave",
|
|
|
|
"federation_publicrooms",
|
|
|
|
"federation_query_auth",
|
|
|
|
"federation_query",
|
2020-07-30 22:25:15 +02:00
|
|
|
"federation_rooms",
|
2019-10-01 05:50:58 +02:00
|
|
|
"federation_sender",
|
|
|
|
"federation_send_join",
|
|
|
|
"federation_send_leave",
|
|
|
|
"federation_send",
|
|
|
|
"federation_state",
|
|
|
|
"federation_user_devices",
|
|
|
|
"federation_user_keys_claim",
|
|
|
|
"federation_user_keys_query",
|
|
|
|
"federation_version",
|
|
|
|
|
|
|
|
"client_user",
|
|
|
|
"client_rooms",
|
|
|
|
"client_createroom",
|
|
|
|
"client_join",
|
|
|
|
"client_account",
|
|
|
|
"client_profile",
|
|
|
|
"client_notifications",
|
|
|
|
"client_devices",
|
|
|
|
"client_delete_devices",
|
|
|
|
"client_send_to_device",
|
2023-02-01 20:10:24 +01:00
|
|
|
"client_dehydrated_device",
|
2019-10-01 05:50:58 +02:00
|
|
|
"client_keys_changes",
|
|
|
|
"client_keys_upload",
|
|
|
|
"client_keys_claim",
|
|
|
|
"client_keys_query",
|
2020-03-31 00:23:28 +02:00
|
|
|
"client_keys_signatures_upload",
|
|
|
|
"client_keys_device_signing_upload",
|
2020-03-29 01:10:32 +01:00
|
|
|
"client_room_keys_version",
|
|
|
|
"client_room_keys_keys",
|
2019-10-01 05:50:58 +02:00
|
|
|
"client_presence",
|
2020-07-30 16:19:16 +02:00
|
|
|
"client_groups",
|
2019-10-01 05:50:58 +02:00
|
|
|
"client_joined_groups",
|
|
|
|
"client_publicised_groups",
|
2020-07-30 17:21:33 +02:00
|
|
|
"client_create_group",
|
2019-10-01 05:50:58 +02:00
|
|
|
"client_login",
|
|
|
|
"client_logout",
|
|
|
|
"client_register_available",
|
|
|
|
"client_register_email",
|
|
|
|
"client_register",
|
|
|
|
"client_directory_list_appservice",
|
|
|
|
"client_directory_list_room",
|
|
|
|
"client_directory_room",
|
|
|
|
"client_directory_user",
|
|
|
|
"client_publicrooms",
|
|
|
|
"client_search",
|
|
|
|
"client_pushers",
|
|
|
|
"client_pushrules",
|
|
|
|
"client_events",
|
|
|
|
"client_initialsync",
|
|
|
|
"client_sync",
|
|
|
|
"client_sync_account_data",
|
|
|
|
"client_sync_device_lists",
|
|
|
|
"client_sync_device_one_time_keys_count",
|
2020-07-30 22:22:36 +02:00
|
|
|
"client_sync_groups",
|
2019-10-01 05:50:58 +02:00
|
|
|
"client_sync_presence",
|
|
|
|
"client_sync_to_device",
|
|
|
|
"client_sync_rooms_account_data",
|
|
|
|
"client_sync_rooms_ephemeral_receipt",
|
|
|
|
"client_sync_rooms_ephemeral",
|
|
|
|
"client_sync_rooms_ephemeral_typing",
|
|
|
|
"client_sync_rooms",
|
|
|
|
"client_sync_rooms_state",
|
|
|
|
"client_sync_rooms_timeline",
|
|
|
|
"client_sync_rooms_unread_notifications",
|
|
|
|
"client_sync_rooms_summary",
|
|
|
|
"client_voip_turnserver",
|
|
|
|
"client_thirdparty_protocols",
|
|
|
|
"client_versions",
|
|
|
|
"client_capabilities",
|
2020-04-30 10:04:35 +02:00
|
|
|
|
2020-10-16 12:19:08 +02:00
|
|
|
"widget_widget",
|
|
|
|
"widget_register",
|
2020-10-16 12:29:14 +02:00
|
|
|
"widget_account",
|
2020-10-16 12:38:29 +02:00
|
|
|
"widget_ui",
|
2020-10-16 12:19:08 +02:00
|
|
|
|
2020-04-30 10:04:35 +02:00
|
|
|
"admin_users",
|
2020-05-02 21:30:14 +02:00
|
|
|
"admin_deactivate",
|
2019-10-01 05:50:58 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/// This is a list of modules that are considered "optional" and any loading
|
|
|
|
/// error for them will not propagate and interrupt m::init.
|
2022-03-21 23:23:47 +01:00
|
|
|
decltype(ircd::m::module_names_optional)
|
|
|
|
ircd::m::module_names_optional
|
2019-10-01 05:50:58 +02:00
|
|
|
{
|
|
|
|
"web_hook",
|
|
|
|
};
|
|
|
|
|
2017-12-12 21:33:14 +01:00
|
|
|
//
|
|
|
|
// init
|
|
|
|
//
|
|
|
|
|
2019-09-25 21:48:00 +02:00
|
|
|
void
|
|
|
|
ircd::m::on_load()
|
2017-12-12 21:33:14 +01:00
|
|
|
try
|
2018-03-28 22:27:39 +02:00
|
|
|
{
|
2020-12-19 01:37:05 +01:00
|
|
|
assert(ircd::run::level == run::level::START);
|
2017-11-16 02:37:09 +01:00
|
|
|
}
|
2019-06-07 04:01:53 +02:00
|
|
|
catch(const m::error &e)
|
2017-11-16 02:37:09 +01:00
|
|
|
{
|
2019-06-07 04:01:53 +02:00
|
|
|
log::error
|
2018-06-15 06:29:30 +02:00
|
|
|
{
|
2019-06-07 04:01:53 +02:00
|
|
|
log, "Failed to start matrix (%u) %s :%s :%s",
|
|
|
|
uint(e.code),
|
|
|
|
http::status(e.code),
|
|
|
|
e.errcode(),
|
|
|
|
e.errstr(),
|
2018-06-15 06:29:30 +02:00
|
|
|
};
|
2018-09-21 23:59:58 +02:00
|
|
|
|
2020-02-19 21:03:07 +01:00
|
|
|
// Don't rethrow m::error so the catcher doesn't depend on
|
|
|
|
// RTTI/personality from this shlib after it unloads.
|
|
|
|
throw ircd::error
|
|
|
|
{
|
|
|
|
"Failed to start matrix (%u) %s :%s :%s",
|
|
|
|
uint(e.code),
|
|
|
|
http::status(e.code),
|
|
|
|
e.errcode(),
|
|
|
|
e.errstr(),
|
|
|
|
};
|
2017-11-30 19:51:01 +01:00
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
2019-06-07 04:01:53 +02:00
|
|
|
log::error
|
2018-06-15 06:29:30 +02:00
|
|
|
{
|
2018-09-21 23:59:58 +02:00
|
|
|
log, "Failed to start matrix :%s", e.what()
|
2018-06-15 06:29:30 +02:00
|
|
|
};
|
2018-09-21 23:59:58 +02:00
|
|
|
|
|
|
|
throw;
|
2017-11-16 02:37:09 +01:00
|
|
|
}
|
|
|
|
|
2019-09-25 21:48:00 +02:00
|
|
|
void
|
|
|
|
ircd::m::on_unload()
|
2017-11-16 02:37:09 +01:00
|
|
|
noexcept try
|
|
|
|
{
|
2020-02-28 00:46:05 +01:00
|
|
|
|
2017-11-16 02:37:09 +01:00
|
|
|
}
|
|
|
|
catch(const m::error &e)
|
|
|
|
{
|
2018-08-17 19:37:12 +02:00
|
|
|
log::critical
|
|
|
|
{
|
|
|
|
log, "%s %s", e.what(), e.content
|
|
|
|
};
|
|
|
|
|
2017-11-26 01:20:42 +01:00
|
|
|
ircd::terminate();
|
2017-11-16 02:37:09 +01:00
|
|
|
}
|
|
|
|
|
2019-06-07 04:01:53 +02:00
|
|
|
//
|
|
|
|
// init::modules
|
|
|
|
//
|
|
|
|
|
2019-10-01 05:50:58 +02:00
|
|
|
/*
|
2019-06-07 04:01:53 +02:00
|
|
|
ircd::m::init::modules::modules()
|
2018-08-17 19:37:12 +02:00
|
|
|
{
|
2019-12-03 22:05:32 +01:00
|
|
|
const unwind_exceptional unload{[this]
|
2018-08-17 19:37:12 +02:00
|
|
|
{
|
2019-06-07 04:01:53 +02:00
|
|
|
this->fini_imports();
|
|
|
|
}};
|
2018-08-17 19:37:12 +02:00
|
|
|
|
2019-06-07 04:01:53 +02:00
|
|
|
init_imports();
|
2018-09-21 23:59:58 +02:00
|
|
|
}
|
2019-06-07 04:01:53 +02:00
|
|
|
|
|
|
|
ircd::m::init::modules::~modules()
|
|
|
|
noexcept
|
2018-09-21 23:59:58 +02:00
|
|
|
{
|
2019-06-07 04:01:53 +02:00
|
|
|
fini_imports();
|
2018-08-17 19:37:12 +02:00
|
|
|
}
|
|
|
|
|
2018-09-21 23:59:58 +02:00
|
|
|
void
|
|
|
|
ircd::m::init::modules::init_imports()
|
2017-12-12 21:33:14 +01:00
|
|
|
{
|
2018-12-09 00:17:13 +01:00
|
|
|
if(!bool(ircd::mods::autoload))
|
2018-03-17 03:03:09 +01:00
|
|
|
{
|
|
|
|
log::warning
|
|
|
|
{
|
|
|
|
"Not loading modules because noautomod flag is set. "
|
|
|
|
"You may still load modules manually."
|
|
|
|
};
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-06-14 00:25:17 +02:00
|
|
|
for(const auto &name : module_names) try
|
|
|
|
{
|
2019-06-05 02:53:28 +02:00
|
|
|
mods::imports.emplace(name, name);
|
2019-06-14 00:25:17 +02:00
|
|
|
}
|
|
|
|
catch(...)
|
|
|
|
{
|
|
|
|
const auto &optional(module_names_optional);
|
|
|
|
if(std::count(begin(optional), end(optional), name))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
throw;
|
|
|
|
}
|
2018-09-14 03:02:10 +02:00
|
|
|
|
2019-07-15 00:42:36 +02:00
|
|
|
if(vm::sequence::retired == 0)
|
|
|
|
{
|
|
|
|
log::notice
|
|
|
|
{
|
|
|
|
log, "This appears to be your first time running IRCd because the events "
|
|
|
|
"database is empty. I will be bootstrapping it with initial events now..."
|
|
|
|
};
|
|
|
|
|
2019-09-25 21:48:00 +02:00
|
|
|
m::init::bootstrap{};
|
2019-07-15 00:42:36 +02:00
|
|
|
}
|
2017-12-12 21:33:14 +01:00
|
|
|
}
|
2018-09-21 23:59:58 +02:00
|
|
|
|
2019-06-07 04:01:53 +02:00
|
|
|
void
|
|
|
|
ircd::m::init::modules::fini_imports()
|
2018-09-21 23:59:58 +02:00
|
|
|
noexcept
|
2018-03-28 22:27:39 +02:00
|
|
|
{
|
2019-06-14 00:24:56 +02:00
|
|
|
for(auto it(module_names.rbegin()); it != module_names.rend(); ++it)
|
2019-06-05 02:53:28 +02:00
|
|
|
mods::imports.erase(*it);
|
2018-03-28 22:27:39 +02:00
|
|
|
}
|
2019-10-01 05:50:58 +02:00
|
|
|
*/
|