2018-02-04 03:22:01 +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.
|
2017-10-19 10:30:19 +02:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#define HAVE_IRCD_NET_LISTENER_H
|
|
|
|
|
|
|
|
namespace ircd::net
|
|
|
|
{
|
|
|
|
struct listener;
|
2019-03-10 21:48:06 +01:00
|
|
|
struct acceptor;
|
2018-12-09 00:17:13 +01:00
|
|
|
|
|
|
|
extern conf::item<bool> listen;
|
2019-03-14 01:32:39 +01:00
|
|
|
|
|
|
|
std::string cipher_list(const acceptor &);
|
2019-03-16 23:13:44 +01:00
|
|
|
json::object config(const acceptor &);
|
|
|
|
string_view name(const acceptor &);
|
2019-03-25 20:55:59 +01:00
|
|
|
ipport binder(const acceptor &);
|
|
|
|
ipport local(const acceptor &);
|
2019-06-01 22:54:55 +02:00
|
|
|
|
|
|
|
size_t handshaking_count(const acceptor &, const ipaddr &);
|
|
|
|
size_t handshaking_count(const acceptor &);
|
|
|
|
size_t accepting_count(const acceptor &);
|
|
|
|
|
2019-05-31 11:35:22 +02:00
|
|
|
string_view loghead(const mutable_buffer &, const acceptor &);
|
|
|
|
string_view loghead(const acceptor &);
|
|
|
|
std::ostream &operator<<(std::ostream &s, const acceptor &);
|
|
|
|
std::ostream &operator<<(std::ostream &s, const listener &);
|
2019-03-16 23:13:44 +01:00
|
|
|
|
2019-03-22 01:07:35 +01:00
|
|
|
bool allow(acceptor &);
|
2019-03-16 23:13:44 +01:00
|
|
|
bool start(acceptor &);
|
2019-03-16 23:32:58 +01:00
|
|
|
bool stop(acceptor &);
|
2017-10-19 10:30:19 +02:00
|
|
|
}
|
|
|
|
|
2019-06-02 00:01:19 +02:00
|
|
|
/// This object is a wrapper interface to the internal net::acceptor object
|
|
|
|
/// which contains boost assets which we cannot forward declare here. It
|
|
|
|
/// implicitly converts as a reference to the internal acceptor. Users wishing
|
|
|
|
/// to listen on a network interface for incoming connections create and hold
|
|
|
|
/// an instance of this object.
|
|
|
|
///
|
|
|
|
/// The configuration is provided in JSON. The operations are asynchronous on
|
|
|
|
/// the main stack and connected sockets are called back in callback. There is
|
|
|
|
/// also a proffer callback which is made as early as possible (before the SSL
|
|
|
|
/// handshake, and ideally if the platform supports it before a SYN-ACK) to
|
|
|
|
/// reject connections by returning false.
|
2017-10-19 10:30:19 +02:00
|
|
|
struct ircd::net::listener
|
|
|
|
{
|
2019-01-18 18:42:44 +01:00
|
|
|
using callback = std::function<void (listener &, const std::shared_ptr<socket> &)>;
|
|
|
|
using proffer = std::function<bool (listener &, const ipport &)>;
|
2017-10-19 10:30:19 +02:00
|
|
|
|
2018-07-08 04:44:45 +02:00
|
|
|
IRCD_EXCEPTION(net::error, error)
|
2017-10-19 10:30:19 +02:00
|
|
|
|
|
|
|
private:
|
2019-03-10 21:48:06 +01:00
|
|
|
std::shared_ptr<net::acceptor> acceptor;
|
2017-10-19 10:30:19 +02:00
|
|
|
|
|
|
|
public:
|
2019-03-14 01:32:16 +01:00
|
|
|
operator const net::acceptor &() const;
|
|
|
|
operator net::acceptor &();
|
|
|
|
|
2018-08-30 00:50:55 +02:00
|
|
|
explicit operator json::object() const;
|
2018-08-31 04:15:28 +02:00
|
|
|
string_view name() const;
|
2018-08-30 00:50:55 +02:00
|
|
|
|
2018-07-07 03:38:08 +02:00
|
|
|
listener(const string_view &name,
|
|
|
|
const json::object &options,
|
2018-09-02 07:00:38 +02:00
|
|
|
callback,
|
|
|
|
proffer = {});
|
2018-07-07 03:38:08 +02:00
|
|
|
|
|
|
|
explicit
|
|
|
|
listener(const string_view &name,
|
|
|
|
const std::string &options,
|
2018-09-02 07:00:38 +02:00
|
|
|
callback,
|
|
|
|
proffer = {});
|
2018-07-07 03:38:08 +02:00
|
|
|
|
2017-10-19 10:30:19 +02:00
|
|
|
~listener() noexcept;
|
2018-08-16 09:55:23 +02:00
|
|
|
|
|
|
|
friend std::ostream &operator<<(std::ostream &s, const listener &);
|
2017-10-19 10:30:19 +02:00
|
|
|
};
|