0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-29 18:22:50 +01:00
construct/include/ircd
2017-11-30 11:23:46 -08:00
..
ctx ircd::ctx: Improve the pool counters. 2017-11-30 11:23:46 -08:00
db ircd:Ⓜ️ Checkpoint matrix top-half / modules. 2017-11-30 11:23:44 -08:00
js ircd: Rename ircd::scope to ircd::unwind. 2017-09-24 18:16:41 -07:00
json ircd::json: Add uint64_t ctor to value. 2017-11-30 11:23:45 -08:00
m ircd:Ⓜ️ Improve server keys related functions. 2017-11-30 11:23:46 -08:00
net ircd::net: OpenSSL/net interface for peer certificates so m:: can hash/verify. 2017-11-30 11:23:44 -08:00
.gitignore What is the Matrix? Control. 2017-03-10 17:51:18 -08:00
allocator.h ircd: Truncate comment. 2017-11-30 11:23:42 -08:00
array_view.h ircd: Split up string_view.h. 2017-11-30 11:23:44 -08:00
asio.h ircd::net: Various net/client/listener bugfixes/cleanup. 2017-11-30 11:23:42 -08:00
buffer.h ircd::buffer: Add full() and some assertions. 2017-11-30 11:23:45 -08:00
byte_view.h ircd: Split up string_view.h. 2017-11-30 11:23:44 -08:00
client.h ircd::net: Various net/client/listener bugfixes/cleanup. 2017-11-30 11:23:42 -08:00
color.h Update various documentation and comments. 2017-09-24 18:16:33 -07:00
date.h ircd: Wrap call to gettimeofday() with posix exception generator. 2017-10-17 00:43:25 -07:00
ed25519.h ircd::ed25519: Add exception hierarchy here; add bad_sig exception. 2017-10-15 21:14:38 -07:00
exception.h ircd: Wrap the std::terminate() handler and add some related toys. 2017-11-30 11:23:46 -08:00
fmt.h ircd: Add additional comments / documentation. 2017-10-15 21:40:10 -07:00
fs.h ircd::fs: Add very preliminary aio and ircd init for such. 2017-10-11 20:54:01 -07:00
hash.h ircd: Remove the $() for hashes. This will make for a better $(event_id) device... 2017-11-30 11:23:43 -08:00
http.h ircd::http: Parse a connection header. 2017-11-30 11:23:39 -08:00
info.h Update various documentation and comments. 2017-09-24 18:16:33 -07:00
ios.h ircd: Improve thread id related; add public functions to post to ios. 2017-10-11 18:18:19 -07:00
iov.h ircd: Evade type-punning the iov list node. 2017-10-11 18:18:18 -07:00
ircd.h ircd: Improve and comment on runlevel / client interruption. 2017-11-30 11:23:43 -08:00
js.h Update various documentation and comments. 2017-09-24 18:16:33 -07:00
lex_cast.h ircd: Add std::chrono lex_cast; cleanup lex_cast buffer argument related. 2017-10-17 00:41:51 -07:00
life_guard.h Update various documentation and comments. 2017-09-24 18:16:33 -07:00
localee.h ircd: Employ namespace scope extensions from c++1z/gnu++14. 2017-09-08 03:47:46 -07:00
logger.h ircd::log: Address any logger reentrancy; various cleanup. 2017-10-17 00:41:10 -07:00
Makefile.am configure.ac/Makefile: Add debug conditionals. 2017-09-24 18:16:34 -07:00
mapi.h Update various documentation and comments. 2017-09-24 18:16:33 -07:00
mods.h ircd: Move ircd::mods::demangle() to ircd::demangle(). 2017-09-24 18:16:39 -07:00
nacl.h ircd: Add ed25519 dsa; reorg sodium related. 2017-10-03 04:27:13 -07:00
openssl.h ircd::net: OpenSSL/net interface for peer certificates so m:: can hash/verify. 2017-11-30 11:23:44 -08:00
params.h ircd::util: Add a count for the params size. 2017-11-30 11:23:44 -08:00
parse.h ircd: Add mutable_buffer ctor to parse::buffer; cleanup parse related. 2017-10-11 18:18:17 -07:00
rand.h Update various documentation and comments. 2017-09-24 18:16:33 -07:00
README.md ircd: Update include README. 2017-11-30 11:23:45 -08:00
resource.h ircd: Add X-Matrix verification for resources. 2017-10-15 21:30:19 -07:00
rfc1459.h ircd: Add lex_cast wrapper interface; various cleanup. 2017-03-14 15:03:15 -07:00
rfc1459_gen.h ircd: Add lex_cast wrapper interface; various cleanup. 2017-03-14 15:03:15 -07:00
rfc1459_parse.h ircd: Minor cleanup. 2017-03-30 16:04:20 -07:00
server.h ircd: Develop various server. 2017-11-30 11:23:45 -08:00
spirit.h ircd: Make asio header; comments; add special continuation for yielding to asio. 2017-09-24 18:16:39 -07:00
stdinc.h ircd: Split up string_view.h. 2017-11-30 11:23:44 -08:00
string_view.h ircd: Split up string_view.h. 2017-11-30 11:23:44 -08:00
stringops.h ircd: Maintain data pointer of string_view's through various ops. 2017-11-30 11:23:43 -08:00
timer.h ircd::util: Rename stopped overload to nostart. 2017-09-24 18:16:44 -07:00
tokens.h fixup! ircd: Add std::chrono lex_cast; cleanup lex_cast buffer argument related. 2017-10-17 00:46:09 -07:00
util.h ircd::util: Consolidate a few typographical constexprs here. 2017-11-30 11:23:45 -08:00
vector_view.h ircd: Split up string_view.h. 2017-11-30 11:23:44 -08:00

IRCd Library

This library can be embedded by developers creating their own server or those who simply want to use the library of routines it provides. See the section for Using libircd.

The purpose of libircd is to facilitate the execution of a server which handles requests from end-users. The library hosts a set of pluggable modules which may introduce the actual application features (or the "business logic") of the server. These additional modules are found in the modules/ directory;

Things to know about libircd

libircd can be embedded in your application with very minimal overhead.

Linking to libircd from your executable allows you to customize and extend the functionality of the server and have control over its execution, or, simply use library routines provided by the library without any daemonization. Including libircd headers will not include any other headers beyond those in the standard library, with minimal impact on your project's compile complexity. The prototypical embedding of libircd is construct found in the construct/ directory.

libircd runs only one server at a time.

Keeping with the spirit of simplicity of the original architecture, libircd continues to be a "singleton" object which uses globals and keeps actual server state in the library itself. In other words, only one IRC daemon can exist within a process's address space at a time. Whether or not this was a pitfall of the original design, it has emerged over the decades as a very profitable decision for making IRCd an accessible open source internet project.

libircd is single-threaded✝

The library is based around the boost::asio::io_service event loop. It is still an asynchronous event-based system. We process one event at a time; developers must not block execution. While the io_service can be run safely on multiple threads by the embedder's application, libircd will use a single io_service::strand.

This methodology ensures there is an uninterrupted execution working through a single event queue providing service which is not otherwise computationally bound. Even if there are periods of execution which are computationally intense like parsing, hashing, signature verification etc -- this is insignificant compared to the amortized cost of thread synchronization and bus contention for a network application.

✝ However, don't start assuming a truly threadless execution. If there is ever a truly long-running background computation or a call to a 3rd party library which will do IO and block the event loop, we may use an additional std::thread to "offload" such an operation. Thus we do have a threading model, but it is heterogeneous.

libircd introduces userspace threading✝

IRCd presents an interface introducing stackful coroutines, a.k.a. userspace context switching, or green threads. The library avoids callbacks as the way to break up execution when waiting for events. Instead, we harken back to the simple old ways of synchronous programming where control flow and data are easy to follow.

✝ If there are certain cases where we don't want a stack to linger which may jeopardize the c10k'ness of the daemon the asynchronous pattern is still used.

libircd innovates with formal grammars

We leverage the boost::spirit system of parsing and printing through formal grammars, rather than writing our own parsers manually. In addition, we build several tools on top of such formal devices like a type-safe format string library acting as a drop-in for ::sprintf(), but accepting objects like std::string without .c_str() and prevention of outputting unprintable/unwanted characters that may have been injected into the system somewhere prior.

Developing libircd

libircd headers are organized into several aggregate "stacks"

As a C++ project there are a lot of header files. Header files depend on other header files. We don't expect the developer of a compilation unit to figure out an exact list of header files necessary to include for that unit. Instead we have aggregated groups of header files which are then precompiled. These aggregations are mostly oriented around a specific project dependency.

  • Standard Include stack <ircd/ircd.h> is the main header group. This stack involves the standard library and most of libircd. This is what an embedder will be working with. These headers will expose our own interfaces wrapping 3rd party dependencies which are not included there. Note that the actual file to properly include this stack is <ircd/ircd.h> (not stdinc.h).

  • Boost ASIO include stack <ircd/asio.h> is a header group exposing the boost::asio library. We only involve this header in compilation units working directly with asio for networking et al. Involving this header file slows down compilation compared with the standard stack.

  • Boost Spirit include stack <ircd/spirit.h> is a header group exposing the spirit parser framework to compilation units which involve formal grammars. Involving this header is a monumental slowdown when compiling.

  • JavaScript include stack <ircd/js/js.h> is a header group exposing symbols from the SpiderMonkey JS engine. Alternatively, <ircd/js.h> is part of the standard include stack which includes any wrapping to hide SpiderMonkey.

  • MAPI include stack <ircd/mapi.h> is the standard header group for modules. This stack is an extension to the standard include stack but has specific tools for pluggable modules which are not part of the libircd core.