0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-07-01 00:08:22 +02:00
construct/modules/s_listen.cc

121 lines
2 KiB
C++
Raw Normal View History

2018-08-15 01:47:42 +02: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.
using namespace ircd;
2018-08-16 08:41:12 +02:00
extern "C" std::list<net::listener> listeners;
static void init_listener(const string_view &, const json::object &);
2018-08-16 08:41:12 +02:00
static void init_listener(const m::event &);
static void init_listeners();
static void on_load();
2018-08-15 01:47:42 +02:00
mapi::header
IRCD_MODULE
{
"Server listeners", on_load
2018-08-15 01:47:42 +02:00
};
2018-08-16 08:41:12 +02:00
/// Active listener state
decltype(listeners)
listeners;
2018-08-15 01:47:42 +02:00
//
// init
//
2018-08-15 01:47:42 +02:00
void
on_load()
2018-08-15 01:47:42 +02:00
{
if(ircd::nolisten)
{
log::warning
{
"Not listening on any addresses because nolisten flag is set."
};
return;
}
init_listeners();
}
2018-08-15 01:47:42 +02:00
void
init_listeners()
{
m::room::state{m::my_room}.for_each("ircd.listen", []
(const m::event &event)
2018-08-15 01:47:42 +02:00
{
2018-08-16 08:41:12 +02:00
init_listener(event);
});
if(listeners.empty())
log::warning
2018-08-15 01:47:42 +02:00
{
"No listening sockets configured; can't hear anyone."
};
}
2018-08-16 08:41:12 +02:00
void
init_listener(const m::event &event)
{
const string_view &name
{
at<"state_key"_>(event)
};
const json::object &opts
{
json::get<"content"_>(event)
};
init_listener(name, opts);
}
void
init_listener(const string_view &name,
const json::object &opts)
{
if(!opts.has("tmp_dh_path"))
throw user_error
2018-08-15 01:47:42 +02:00
{
"Listener %s requires a 'tmp_dh_path' in the config. We do not"
" create this yet. Try `openssl dhparam -outform PEM -out dh512.pem 512`",
name
2018-08-15 01:47:42 +02:00
};
listeners.emplace_back(name, opts, []
(const auto &sock)
{
ircd::add_client(sock);
});
}
//
//
//
2018-08-16 08:41:12 +02:00
static void
create_listener(const m::event &event)
{
init_listener(event);
}
const m::hookfn<>
create_listener_hook
{
create_listener,
{
2018-08-16 08:41:12 +02:00
{ "_site", "vm.notify" },
{ "room_id", "!ircd" },
{ "type", "ircd.listen" },
2018-08-15 01:47:42 +02:00
}
};