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.
|
|
|
|
|
2019-06-02 00:01:19 +02:00
|
|
|
/// Implementation to net::listener. See listener.h for additional interface.
|
2019-03-10 21:48:06 +01:00
|
|
|
struct ircd::net::acceptor
|
|
|
|
: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
|
|
|
|
2018-01-19 15:55:48 +01:00
|
|
|
static log::log log;
|
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
|
|
|
|
2019-03-10 21:48:06 +01:00
|
|
|
net::listener *listener_;
|
2018-01-19 15:55:48 +01:00
|
|
|
std::string name;
|
2018-08-30 00:50:55 +02:00
|
|
|
std::string opts;
|
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;
|
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;
|
2018-01-19 15:55:48 +01:00
|
|
|
bool interrupting {false};
|
|
|
|
ctx::dock joining;
|
|
|
|
|
|
|
|
void configure(const json::object &opts);
|
|
|
|
|
|
|
|
// Handshake stack
|
2019-03-13 20:05:57 +01:00
|
|
|
bool handle_sni(SSL &, int &ad);
|
2019-05-31 09:31:59 +02:00
|
|
|
string_view handle_alpn(SSL &, const vector_view<const string_view> &in);
|
2018-01-19 15:55:48 +01:00
|
|
|
void check_handshake_error(const error_code &ec, socket &);
|
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
|
|
|
|
bool check_accept_error(const error_code &ec, socket &);
|
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;
|
|
|
|
};
|