0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-30 02:32:43 +01:00
construct/modules
2019-06-07 02:49:25 -07:00
..
app ircd:Ⓜ️:app: Add configuration access interface for appservice. 2019-03-15 16:19:05 -07:00
client modules/client/rooms/join: Spawn context for asynchronous joinstrap; improve various. 2019-06-07 02:49:25 -07:00
federation ircd: Fix ambiguous references to BSD stringops. 2019-06-06 03:49:54 -07:00
identity modules: Start and identity service stub area. 2019-02-18 10:28:09 -08:00
js ircd::m/modules: Update various client listeners w/ callback. 2018-07-06 18:40:15 -07:00
key modules/key/server: Move static ed25519 test to s_keys from here. 2019-05-01 13:12:27 -07:00
media modules/media/thumbnail: Get magick availability this way for now. 2019-06-04 02:22:09 -07:00
console.cc ircd: Fix ambiguous references to BSD stringops. 2019-06-06 03:49:54 -07:00
m_device.cc ircd:Ⓜ️:device: Add has(user, device_id, property) overload to interface suite. 2019-03-09 18:48:32 -08:00
m_device_list_update.cc modules: Stub m.device_list_update edu handler; json schema. 2019-02-20 13:36:29 -08:00
m_direct.cc modules/m_direct: Modify the user's account_data for m.direct. 2019-04-22 14:30:55 -07:00
m_direct_to_device.cc modules/m_direct_to_device: Tweak logic for local message handling; handle exception per msg. 2019-02-22 15:40:53 -08:00
m_events.cc ircd::fmt: Fix specifier escaping. 2019-06-01 02:31:03 -07:00
m_ignored_user_list.cc ircd:Ⓜ️:user: Add framework around m.ignored_user_list; w/ console cmd. 2019-03-14 17:27:45 -07:00
m_noop.cc modules/m_noop: Update header / comment. 2019-01-25 14:53:59 -08:00
m_presence.cc ircd: Rename various matrix loggers; increase log name width. 2019-04-05 18:12:22 -07:00
m_receipt.cc modules: Implement 13.29 room server access control list checks. 2019-05-26 20:41:13 -07:00
m_room_aliases.cc modules/m_room_aliases: Allow fallback to expired cache data on fetch failure. 2019-04-15 17:09:35 -07:00
m_room_canonical_alias.cc modules: Use the apropos matrix logger for various log messages. 2018-12-22 17:44:18 -08:00
m_room_create.cc modules: Use the apropos matrix logger for various log messages. 2018-12-22 17:44:18 -08:00
m_room_history_visibility.cc ircd:Ⓜ️ Abort the experimental id::node. 2019-05-26 19:13:20 -07:00
m_room_join_rules.cc modules: Use the apropos matrix logger for various log messages. 2018-12-22 17:44:18 -08:00
m_room_member.cc modules/client/rooms/invite: Move the foreign invite hook here; do namespace modernizations. 2019-05-31 14:21:41 -07:00
m_room_message.cc modules: Use the apropos matrix logger for various log messages. 2018-12-22 17:44:18 -08:00
m_room_power_levels.cc modules: Use the apropos matrix logger for various log messages. 2018-12-22 17:44:18 -08:00
m_room_server_acl.cc modules/m_room_server_acl: Fix missing export tag. 2019-05-31 14:05:50 -07:00
m_rooms.cc ircd:Ⓜ️:rooms: Partial removal of unnamespaced module definitions. 2019-05-06 11:49:14 -07:00
m_state.cc modules/m_state: Add a state clear routine. 2019-01-25 13:59:34 -08:00
m_typing.cc modules: Implement 13.29 room server access control list checks. 2019-05-26 20:41:13 -07:00
m_user.cc modules/m_room: Make notification count iteration upper bound exclusive. 2019-03-27 23:55:14 -07:00
Makefile.am configure: Add --enable-compact for the smallest possible building and linking. 2019-06-06 05:29:07 -07:00
metrics.cc modules: Add preliminary prometheus metrics endpoint. 2019-03-08 12:31:08 -08:00
README.md modules: Update README blerb. 2019-05-03 15:58:39 -07:00
s_command.cc modules/s_command: Improve ping command. 2019-05-16 22:36:19 -07:00
s_conf.cc modules/s_conf: Allow manual updating of persist=false conf::item. 2019-04-17 04:59:00 -07:00
s_control.cc modules/s_control: Fix context switch in exception handler. 2019-03-28 22:01:42 -07:00
s_dns.cc ircd::rfc1035: Rename constant. 2019-05-26 18:37:40 -07:00
s_dns.h ircd::rfc1035: Rename constant. 2019-05-26 18:37:40 -07:00
s_dns_resolver.cc ircd::rfc1035: Rename constant. 2019-05-26 18:37:40 -07:00
s_feds.cc modules/s_feds: Devirtualize call to destructor. 2019-04-20 14:20:18 -07:00
s_fetch.cc modules/s_fetch: Add requests limit w/ conf item. 2019-06-05 17:12:02 -07:00
s_fetch.h modules/s_fetch: Add requests limit w/ conf item. 2019-06-05 17:12:02 -07:00
s_keys.cc ircd:Ⓜ️ Abort the experimental id::node. 2019-05-26 19:13:20 -07:00
s_listen.cc modules/s_listen: Add accept flow control mechanism. 2019-04-15 22:47:24 -07:00
s_node.cc ircd:Ⓜ️ Abort the experimental id::node. 2019-05-26 19:13:20 -07:00
vm.cc ircd:Ⓜ️:vm: Improve aggregated eval loop. 2019-06-01 18:38:07 -07:00
webhook.cc modules/webhook: Mute all watch events and just allow star events. 2019-06-04 00:35:21 -07:00
webroot.cc ircd::resource: Handle and generate an OPTIONS response. 2019-03-31 23:08:29 -07:00
well_known.cc modules: Add .well-known handler to serve the m::self::servername string for now. 2019-03-28 13:13:35 -07:00

IRCd Module Tree

This directory contains dynamically loadable functionality to libircd. These modules are not mere extensions -- they provide essential application functionality, but are not always required to be directly linked in libircd proper. Most application-specific functionality (i.e "business logic") is contained in modules within this tree. At the time of this writing, a significant amount of matrix functionality is still contained within libircd proper, but it is intended that as many definitions as possible are pushed out into modules.

Layout

The modules/ directory is primarily shaped the same as the HTTP resource tree in which most of its modules register themselves in. This is not automatic and the mere inclusion of files/directories in modules/ does not automatically expose them over HTTP.

Note that the installation layout is not the same as the development source layout (i.e in git). Upon installation, the module tree is collapsed into a single directory and installed into $prefix/lib/modules/construct/$directory_$module.so; this may be subject to improvement.

  • client/ contains resource handlers for the /_matrix/client/ API
  • federation/ contains resource handlers for the /_matrix/federation/ API
  • key/ contains resource handlers for the /_matrix/key/ API
  • media/ contains resource handlers for the /_matrix/media/ API
  • js/ contains modules specific to the unreleased javascript embedding.
  • s_ modules provide utility to the server's operation.
  • m_ modules implement protocol logic for matrix event types.
  • vm_ modules provide the processing logic for matrix events.

Approach

We use a hybrid system to build modules with two techniques:

  • Self-contained shared objects loaded for explicit import and export of their symbols. This is the classical module which is safely loaded, unloaded and accessed at any time via the ircd::mods::import system. This approach is preferred for the majority of module and extension cases. Definitions in these modules are not declared in include/ircd unless a "thunk" definition inside libircd contains am ircd::mods::import calling out to the module (this is not generated; developer must place this).

  • "core" modules which directly implement symbols declared in include/ircd headers. When this type of module is not loaded those headers declare an undefined symbol and accesses will immediately crash. This approach is used when large interfaces are implemented by modules and individual imports defined in libircd are too cumbersome. This involves global binding made possible by the dynamic linker. This approach is satisfactory because of C++ symbol namespacing and modern compiler and linker controls. These modules can still be unloaded (and are during shutdown) but only after every other module which has accessed its symbols has also been unloaded. At this time, we have no access or control over that reference system and the reasons for a failure to unload may not be immediately clear or easy to trace.

Loading

Modules may be automatically loaded based on their prefix. Certain prefixes are sought by libircd for auto-loading, arbitrarily (i.e there is no magic autoloading prefix; see: ircd/m/m.cc for explicit prefixes). A module may also be loaded when an attempt is made to call into it (i.e with m::import or low-level with ircd::mods::*). Furthermore, a module may be loaded by the console mod command suite, specifically mod load. Otherwise the module is not loaded.

Unloading

Unlike previous incarnations of IRCd, every module is [eventually] "unloadable" and the notion of a "core" module is modernized based on the dynamic linker technology available.

Many central linkages within libircd (and direct links made by other modules) are imports which tolerate the unavailability of a module by using weak-pointers and throwing exceptions. Unlike the Atheme approach as well, importing from a module does not prevent unloading due to dependency; the unloading of a module is propagated to linksites through the weak_ptr's dependency graph and exceptions are thrown from the link upon next use.

Furthermore, modules are free to leverage the ircd::ctx system to wait synchronously for events which are essential for a clean load or unload, even during static initialization and destruction. This is a useful feature which allows all modules to be robustly loadable and unloadable at any time and every time in an intuitive manner.

No modules used through imports in this system "stick" whether by accident or on purpose upon unload. Though we all know that dlclose() does not guarantee a module is actually unloaded, we expend the extra effort to ensure there is no reason why dlclose() would not unload the module. This static destruction of a module is verified and alarms will go off if it is actually "stuck" and the developer must fix this.

Getting started

The header mods/mapi.h is specific to modules and included for modules in addition to the core ircd.h. Both of these are included automatically via the compiler's command-line and the developer does not have to #include either in the module.

Every loadable module requires a static ircd::mapi::header with the explicit name of IRCD_MODULE. This is an object which will be sought by the module loader in libircd. Nothing else is required.

Developer's Approach

The ideal module in this system is one that is self-contained in that its only interface is through "registrations" to various facilities provided by libircd. The module can still freely read and write to state within libircd or other modules.

  • An example of such is an HTTP resource (see: ircd/resource.h) registration of a URL to handle incoming HTTP requests.

  • Another example is a Matrix Event Hook (see: ircd/m/hook.h) to process matrix events.

Next is a module providing definitions and making them available through exposition (i.e extern "C"). In this approach, function definitions are provided in the module but a "central interface" may be provided by libircd. That central interface is tolerant of the function call failing when the module is not available (or automatically tries to load it, see: ircd/m/import.h and ircd/mods/*.h etc).

Note that many modules use any of these approaches at the same time.