2018-01-19 15:55:48 +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.
|
|
|
|
|
2018-02-04 03:22:01 +01:00
|
|
|
#pragma once
|
|
|
|
#define HAVE_IRCD_NET_ACCEPTOR_H
|
|
|
|
|
2018-01-19 15:55:48 +01:00
|
|
|
// This file is not included with the IRCd standard include stack because
|
|
|
|
// it requires symbols we can't forward declare without boost headers. It
|
|
|
|
// is part of the <ircd/asio.h> stack which can be included in your
|
|
|
|
// definition file if you need low level access to this acceptor API.
|
|
|
|
|
2023-02-09 19:12:11 +01:00
|
|
|
namespace ircd::net
|
|
|
|
{
|
|
|
|
#pragma GCC visibility push(hidden)
|
|
|
|
string_view loghead(const mutable_buffer &, const acceptor &);
|
|
|
|
string_view loghead(const acceptor &);
|
|
|
|
#pragma GCC visibility pop
|
|
|
|
}
|
|
|
|
|
2019-06-02 00:01:19 +02:00
|
|
|
/// Implementation to net::listener. See listener.h for additional interface.
|
2022-06-14 23:15:53 +02:00
|
|
|
struct [[gnu::visibility("protected")]]
|
|
|
|
ircd::net::acceptor
|
2019-03-10 21:48:06 +01:00
|
|
|
:std::enable_shared_from_this<struct ircd::net::acceptor>
|
2018-01-19 15:55:48 +01:00
|
|
|
{
|
|
|
|
using error_code = boost::system::error_code;
|
2019-03-10 21:48:06 +01:00
|
|
|
using callback = listener::callback;
|
|
|
|
using proffer = listener::proffer;
|
2019-06-01 22:54:55 +02:00
|
|
|
using sockets = std::list<std::shared_ptr<socket>>;
|
2018-01-19 15:55:48 +01:00
|
|
|
|
2019-03-13 20:04:21 +01:00
|
|
|
IRCD_EXCEPTION(listener::error, error)
|
2019-03-13 20:05:57 +01:00
|
|
|
IRCD_EXCEPTION(error, sni_warning)
|
2019-03-13 20:04:21 +01:00
|
|
|
|
2023-02-18 04:10:06 +01:00
|
|
|
static constexpr bool debug_alpn {false};
|
|
|
|
|
2018-01-19 15:55:48 +01:00
|
|
|
static log::log log;
|
2020-12-18 05:27:44 +01:00
|
|
|
static ios::descriptor accept_desc;
|
|
|
|
static ios::descriptor handshake_desc;
|
2019-06-01 22:54:55 +02:00
|
|
|
static conf::item<size_t> handshaking_max;
|
|
|
|
static conf::item<size_t> handshaking_max_per_peer;
|
2018-03-09 21:22:10 +01:00
|
|
|
static conf::item<milliseconds> timeout;
|
2019-04-16 04:54:31 +02:00
|
|
|
static conf::item<std::string> ssl_curve_list;
|
2019-03-13 01:27:56 +01:00
|
|
|
static conf::item<std::string> ssl_cipher_list;
|
2019-03-13 01:47:57 +01:00
|
|
|
static conf::item<std::string> ssl_cipher_blacklist;
|
2018-01-19 15:55:48 +01:00
|
|
|
|
|
|
|
std::string name;
|
2018-08-30 00:50:55 +02:00
|
|
|
std::string opts;
|
2019-09-30 22:24:50 +02:00
|
|
|
std::string cname;
|
2018-01-19 15:55:48 +01:00
|
|
|
size_t backlog;
|
2018-07-07 03:38:08 +02:00
|
|
|
listener::callback cb;
|
2018-09-02 07:00:38 +02:00
|
|
|
listener::proffer pcb;
|
2022-07-08 07:07:59 +02:00
|
|
|
bpf::prog filter;
|
2018-01-19 15:55:48 +01:00
|
|
|
asio::ssl::context ssl;
|
|
|
|
ip::tcp::endpoint ep;
|
|
|
|
ip::tcp::acceptor a;
|
2019-06-02 00:31:38 +02:00
|
|
|
size_t accepting {0};
|
2019-06-01 22:54:55 +02:00
|
|
|
sockets handshaking;
|
2023-03-18 19:34:45 +01:00
|
|
|
bool secure {false};
|
2018-01-19 15:55:48 +01:00
|
|
|
bool interrupting {false};
|
|
|
|
ctx::dock joining;
|
|
|
|
|
2019-09-30 21:55:53 +02:00
|
|
|
// Internal configuration
|
|
|
|
void configure_dh(const json::object &);
|
2023-03-18 19:34:45 +01:00
|
|
|
bool configure_certs(const json::object &);
|
2019-09-30 21:55:53 +02:00
|
|
|
void configure_curves(const json::object &);
|
|
|
|
void configure_ciphers(const json::object &);
|
|
|
|
void configure_flags(const json::object &);
|
|
|
|
void configure_password(const json::object &);
|
2023-03-18 19:10:34 +01:00
|
|
|
void configure_sni(const json::object &);
|
2023-03-18 19:34:45 +01:00
|
|
|
bool configure(const json::object &opts);
|
|
|
|
|
|
|
|
// Completion stack
|
|
|
|
void accepted(const std::shared_ptr<socket> &);
|
2018-01-19 15:55:48 +01:00
|
|
|
|
|
|
|
// Handshake stack
|
2020-05-31 07:27:53 +02:00
|
|
|
bool handle_sni(socket &, int &ad);
|
|
|
|
string_view handle_alpn(socket &, const vector_view<const string_view> &in);
|
2020-03-03 23:12:28 +01:00
|
|
|
void check_handshake_error(const error_code &ec, socket &) const;
|
2019-06-01 22:54:55 +02:00
|
|
|
void handshake(const error_code &, const std::shared_ptr<socket>, const decltype(handshaking)::const_iterator) noexcept;
|
2018-01-19 15:55:48 +01:00
|
|
|
|
|
|
|
// Acceptance stack
|
2023-03-08 17:36:04 +01:00
|
|
|
static bool proffer_default(acceptor &, const ipport &);
|
2020-03-03 23:12:28 +01:00
|
|
|
bool check_handshake_limit(socket &, const ipport &) const;
|
|
|
|
bool check_accept_error(const error_code &ec, socket &) const;
|
2019-06-02 00:31:38 +02:00
|
|
|
void accept(const error_code &, const std::shared_ptr<socket>) noexcept;
|
2018-01-19 15:55:48 +01:00
|
|
|
|
|
|
|
// Accept next
|
2019-01-18 18:42:44 +01:00
|
|
|
bool set_handle();
|
2018-01-19 15:55:48 +01:00
|
|
|
|
|
|
|
// Acceptor shutdown
|
|
|
|
bool interrupt() noexcept;
|
|
|
|
void join() noexcept;
|
2019-03-16 23:32:58 +01:00
|
|
|
void close();
|
|
|
|
void open();
|
2018-01-19 15:55:48 +01:00
|
|
|
|
2019-01-18 18:42:44 +01:00
|
|
|
acceptor(net::listener &,
|
|
|
|
const string_view &name,
|
2018-07-07 03:38:08 +02:00
|
|
|
const json::object &opts,
|
2018-09-02 07:00:38 +02:00
|
|
|
listener::callback,
|
|
|
|
listener::proffer);
|
2018-07-07 03:38:08 +02:00
|
|
|
|
2018-01-19 15:55:48 +01:00
|
|
|
~acceptor() noexcept;
|
|
|
|
};
|