mirror of
https://github.com/matrix-construct/construct
synced 2024-11-17 15:30:52 +01:00
ircd::net: Improve listener to-string related.
This commit is contained in:
parent
14bbe13c45
commit
570f715c87
3 changed files with 58 additions and 37 deletions
|
@ -35,7 +35,6 @@ struct ircd::net::listener::acceptor
|
||||||
bool interrupting {false};
|
bool interrupting {false};
|
||||||
ctx::dock joining;
|
ctx::dock joining;
|
||||||
|
|
||||||
explicit operator std::string() const;
|
|
||||||
void configure(const json::object &opts);
|
void configure(const json::object &opts);
|
||||||
|
|
||||||
// Handshake stack
|
// Handshake stack
|
||||||
|
@ -58,6 +57,8 @@ struct ircd::net::listener::acceptor
|
||||||
listener::callback);
|
listener::callback);
|
||||||
|
|
||||||
~acceptor() noexcept;
|
~acceptor() noexcept;
|
||||||
|
|
||||||
|
friend std::ostream &operator<<(std::ostream &s, const acceptor &);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ircd::net::listener_udp::acceptor
|
struct ircd::net::listener_udp::acceptor
|
||||||
|
|
|
@ -38,6 +38,8 @@ struct ircd::net::listener
|
||||||
callback);
|
callback);
|
||||||
|
|
||||||
~listener() noexcept;
|
~listener() noexcept;
|
||||||
|
|
||||||
|
friend std::ostream &operator<<(std::ostream &s, const listener &);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ircd::net::listener_udp
|
struct ircd::net::listener_udp
|
||||||
|
@ -62,6 +64,8 @@ struct ircd::net::listener_udp
|
||||||
const std::string &options);
|
const std::string &options);
|
||||||
|
|
||||||
~listener_udp() noexcept;
|
~listener_udp() noexcept;
|
||||||
|
|
||||||
|
friend std::ostream &operator<<(std::ostream &s, const listener_udp &);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ircd::net::listener_udp::datagram
|
struct ircd::net::listener_udp::datagram
|
||||||
|
|
88
ircd/net.cc
88
ircd/net.cc
|
@ -889,6 +889,17 @@ ircd::net::blocking(const socket &socket)
|
||||||
// listener
|
// listener
|
||||||
//
|
//
|
||||||
|
|
||||||
|
std::ostream &
|
||||||
|
ircd::net::operator<<(std::ostream &s, const listener &a)
|
||||||
|
{
|
||||||
|
s << *a.acceptor;
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// listener::listener
|
||||||
|
//
|
||||||
|
|
||||||
ircd::net::listener::listener(const string_view &name,
|
ircd::net::listener::listener(const string_view &name,
|
||||||
const std::string &opts,
|
const std::string &opts,
|
||||||
callback cb)
|
callback cb)
|
||||||
|
@ -926,6 +937,17 @@ noexcept
|
||||||
// listener_udp
|
// listener_udp
|
||||||
//
|
//
|
||||||
|
|
||||||
|
std::ostream &
|
||||||
|
ircd::net::operator<<(std::ostream &s, const listener_udp &a)
|
||||||
|
{
|
||||||
|
s << *a.acceptor;
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// listener_udp::listener_udp
|
||||||
|
//
|
||||||
|
|
||||||
ircd::net::listener_udp::listener_udp(const string_view &name,
|
ircd::net::listener_udp::listener_udp(const string_view &name,
|
||||||
const std::string &opts)
|
const std::string &opts)
|
||||||
:listener_udp
|
:listener_udp
|
||||||
|
@ -980,6 +1002,13 @@ ircd::net::listener::acceptor::timeout
|
||||||
{ "default", 12000L },
|
{ "default", 12000L },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
std::ostream &
|
||||||
|
ircd::net::operator<<(std::ostream &s, const struct listener::acceptor &a)
|
||||||
|
{
|
||||||
|
s << "'" << a.name << "' @ [" << string(a.ep.address()) << "]:" << a.ep.port();
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// listener::acceptor::acceptor
|
// listener::acceptor::acceptor
|
||||||
//
|
//
|
||||||
|
@ -1031,20 +1060,20 @@ try
|
||||||
configure(opts);
|
configure(opts);
|
||||||
|
|
||||||
log.debug("%s configured listener SSL",
|
log.debug("%s configured listener SSL",
|
||||||
std::string(*this));
|
string(*this));
|
||||||
|
|
||||||
a.open(ep.protocol());
|
a.open(ep.protocol());
|
||||||
a.set_option(reuse_address);
|
a.set_option(reuse_address);
|
||||||
log.debug("%s opened listener socket",
|
log.debug("%s opened listener socket",
|
||||||
std::string(*this));
|
string(*this));
|
||||||
|
|
||||||
a.bind(ep);
|
a.bind(ep);
|
||||||
log.debug("%s bound listener socket",
|
log.debug("%s bound listener socket",
|
||||||
std::string(*this));
|
string(*this));
|
||||||
|
|
||||||
a.listen(backlog);
|
a.listen(backlog);
|
||||||
log.debug("%s listening (backlog: %lu, max connections: %zu)",
|
log.debug("%s listening (backlog: %lu, max connections: %zu)",
|
||||||
std::string(*this),
|
string(*this),
|
||||||
backlog,
|
backlog,
|
||||||
max_connections);
|
max_connections);
|
||||||
}
|
}
|
||||||
|
@ -1107,7 +1136,7 @@ try
|
||||||
auto sock(std::make_shared<ircd::socket>(ssl));
|
auto sock(std::make_shared<ircd::socket>(ssl));
|
||||||
/*
|
/*
|
||||||
log.debug("%s: socket(%p) is the next socket to accept",
|
log.debug("%s: socket(%p) is the next socket to accept",
|
||||||
std::string(*this),
|
string(*this),
|
||||||
sock.get());
|
sock.get());
|
||||||
*/
|
*/
|
||||||
++accepting;
|
++accepting;
|
||||||
|
@ -1118,7 +1147,7 @@ catch(const std::exception &e)
|
||||||
{
|
{
|
||||||
throw assertive
|
throw assertive
|
||||||
{
|
{
|
||||||
"%s: %s", std::string(*this), e.what()
|
"%s: %s", string(*this), e.what()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1146,7 +1175,7 @@ noexcept try
|
||||||
|
|
||||||
assert(bool(sock));
|
assert(bool(sock));
|
||||||
log.debug("%s: socket(%p) accepted(%zu) %s %s",
|
log.debug("%s: socket(%p) accepted(%zu) %s %s",
|
||||||
std::string(*this),
|
string(*this),
|
||||||
sock.get(),
|
sock.get(),
|
||||||
accepting,
|
accepting,
|
||||||
string(remote_ipport(*sock)),
|
string(remote_ipport(*sock)),
|
||||||
|
@ -1175,7 +1204,7 @@ noexcept try
|
||||||
catch(const ctx::interrupted &e)
|
catch(const ctx::interrupted &e)
|
||||||
{
|
{
|
||||||
log.debug("%s: acceptor interrupted socket(%p) %s",
|
log.debug("%s: acceptor interrupted socket(%p) %s",
|
||||||
std::string(*this),
|
string(*this),
|
||||||
sock.get(),
|
sock.get(),
|
||||||
string(ec));
|
string(ec));
|
||||||
|
|
||||||
|
@ -1184,14 +1213,14 @@ catch(const ctx::interrupted &e)
|
||||||
catch(const boost::system::system_error &e)
|
catch(const boost::system::system_error &e)
|
||||||
{
|
{
|
||||||
log.derror("%s: socket(%p) in accept(): %s",
|
log.derror("%s: socket(%p) in accept(): %s",
|
||||||
std::string(*this),
|
string(*this),
|
||||||
sock.get(),
|
sock.get(),
|
||||||
string(e));
|
string(e));
|
||||||
}
|
}
|
||||||
catch(const std::exception &e)
|
catch(const std::exception &e)
|
||||||
{
|
{
|
||||||
log.error("%s: socket(%p) in accept(): %s",
|
log.error("%s: socket(%p) in accept(): %s",
|
||||||
std::string(*this),
|
string(*this),
|
||||||
sock.get(),
|
sock.get(),
|
||||||
e.what());
|
e.what());
|
||||||
}
|
}
|
||||||
|
@ -1260,7 +1289,7 @@ noexcept try
|
||||||
catch(const ctx::interrupted &e)
|
catch(const ctx::interrupted &e)
|
||||||
{
|
{
|
||||||
log.debug("%s: SSL handshake interrupted socket(%p) %s",
|
log.debug("%s: SSL handshake interrupted socket(%p) %s",
|
||||||
std::string(*this),
|
string(*this),
|
||||||
sock.get(),
|
sock.get(),
|
||||||
string(ec));
|
string(ec));
|
||||||
|
|
||||||
|
@ -1269,14 +1298,14 @@ catch(const ctx::interrupted &e)
|
||||||
catch(const boost::system::system_error &e)
|
catch(const boost::system::system_error &e)
|
||||||
{
|
{
|
||||||
log.derror("%s: socket(%p) in handshake(): %s",
|
log.derror("%s: socket(%p) in handshake(): %s",
|
||||||
std::string(*this),
|
string(*this),
|
||||||
sock.get(),
|
sock.get(),
|
||||||
string(e));
|
string(e));
|
||||||
}
|
}
|
||||||
catch(const std::exception &e)
|
catch(const std::exception &e)
|
||||||
{
|
{
|
||||||
log.error("%s: socket(%p) in handshake(): %s",
|
log.error("%s: socket(%p) in handshake(): %s",
|
||||||
std::string(*this),
|
string(*this),
|
||||||
sock.get(),
|
sock.get(),
|
||||||
e.what());
|
e.what());
|
||||||
}
|
}
|
||||||
|
@ -1318,7 +1347,7 @@ void
|
||||||
ircd::net::listener::acceptor::configure(const json::object &opts)
|
ircd::net::listener::acceptor::configure(const json::object &opts)
|
||||||
{
|
{
|
||||||
log.debug("%s preparing listener socket configuration...",
|
log.debug("%s preparing listener socket configuration...",
|
||||||
std::string(*this));
|
string(*this));
|
||||||
|
|
||||||
ssl.set_options
|
ssl.set_options
|
||||||
(
|
(
|
||||||
|
@ -1337,7 +1366,7 @@ ircd::net::listener::acceptor::configure(const json::object &opts)
|
||||||
(const auto &size, const auto &purpose)
|
(const auto &size, const auto &purpose)
|
||||||
{
|
{
|
||||||
log.debug("%s asking for password with purpose '%s' (size: %zu)",
|
log.debug("%s asking for password with purpose '%s' (size: %zu)",
|
||||||
std::string(*this),
|
string(*this),
|
||||||
purpose,
|
purpose,
|
||||||
size);
|
size);
|
||||||
|
|
||||||
|
@ -1356,13 +1385,13 @@ ircd::net::listener::acceptor::configure(const json::object &opts)
|
||||||
throw error
|
throw error
|
||||||
{
|
{
|
||||||
"%s: SSL certificate chain file @ `%s' not found",
|
"%s: SSL certificate chain file @ `%s' not found",
|
||||||
std::string(*this),
|
string(*this),
|
||||||
filename
|
filename
|
||||||
};
|
};
|
||||||
|
|
||||||
ssl.use_certificate_chain_file(filename);
|
ssl.use_certificate_chain_file(filename);
|
||||||
log.info("%s using certificate chain file '%s'",
|
log.info("%s using certificate chain file '%s'",
|
||||||
std::string(*this),
|
string(*this),
|
||||||
filename);
|
filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1377,13 +1406,13 @@ ircd::net::listener::acceptor::configure(const json::object &opts)
|
||||||
throw error
|
throw error
|
||||||
{
|
{
|
||||||
"%s: SSL certificate pem file @ `%s' not found",
|
"%s: SSL certificate pem file @ `%s' not found",
|
||||||
std::string(*this),
|
string(*this),
|
||||||
filename
|
filename
|
||||||
};
|
};
|
||||||
|
|
||||||
ssl.use_certificate_file(filename, asio::ssl::context::pem);
|
ssl.use_certificate_file(filename, asio::ssl::context::pem);
|
||||||
log.info("%s using certificate file '%s'",
|
log.info("%s using certificate file '%s'",
|
||||||
std::string(*this),
|
string(*this),
|
||||||
filename);
|
filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1398,13 +1427,13 @@ ircd::net::listener::acceptor::configure(const json::object &opts)
|
||||||
throw error
|
throw error
|
||||||
{
|
{
|
||||||
"%s: SSL private key file @ `%s' not found",
|
"%s: SSL private key file @ `%s' not found",
|
||||||
std::string(*this),
|
string(*this),
|
||||||
filename
|
filename
|
||||||
};
|
};
|
||||||
|
|
||||||
ssl.use_private_key_file(filename, asio::ssl::context::pem);
|
ssl.use_private_key_file(filename, asio::ssl::context::pem);
|
||||||
log.info("%s using private key file '%s'",
|
log.info("%s using private key file '%s'",
|
||||||
std::string(*this),
|
string(*this),
|
||||||
filename);
|
filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1419,30 +1448,17 @@ ircd::net::listener::acceptor::configure(const json::object &opts)
|
||||||
throw error
|
throw error
|
||||||
{
|
{
|
||||||
"%s: SSL tmp dh file @ `%s' not found",
|
"%s: SSL tmp dh file @ `%s' not found",
|
||||||
std::string(*this),
|
string(*this),
|
||||||
filename
|
filename
|
||||||
};
|
};
|
||||||
|
|
||||||
ssl.use_tmp_dh_file(filename);
|
ssl.use_tmp_dh_file(filename);
|
||||||
log.info("%s using tmp dh file '%s'",
|
log.info("%s using tmp dh file '%s'",
|
||||||
std::string(*this),
|
string(*this),
|
||||||
filename);
|
filename);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ircd::net::listener::acceptor::operator
|
|
||||||
std::string()
|
|
||||||
const
|
|
||||||
{
|
|
||||||
return fmt::snstringf
|
|
||||||
{
|
|
||||||
256, "'%s' @ [%s]:%u",
|
|
||||||
name,
|
|
||||||
string(ep.address()),
|
|
||||||
ep.port()
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// listener_udp::acceptor
|
// listener_udp::acceptor
|
||||||
//
|
//
|
||||||
|
|
Loading…
Reference in a new issue