0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-25 08:12:37 +01:00

ircd::net: Add loghead() similar to client::loghead().

This commit is contained in:
Jason Volk 2018-12-12 08:59:36 -08:00
parent d7da57e073
commit e97742ef39
2 changed files with 23 additions and 0 deletions

View file

@ -55,6 +55,8 @@ namespace ircd::net
ipport remote_ipport(const socket &) noexcept;
std::pair<size_t, size_t> bytes(const socket &) noexcept; // <in, out>
std::pair<size_t, size_t> calls(const socket &) noexcept; // <in, out>
string_view loghead(const mutable_buffer &out, const socket &);
string_view loghead(const socket &);
const_buffer peer_cert_der(const mutable_buffer &, const socket &);
const_buffer peer_cert_der_sha256(const mutable_buffer &, const socket &);

View file

@ -123,6 +123,27 @@ noexcept
};
}
ircd::string_view
ircd::net::loghead(const socket &socket)
{
thread_local char buf[512];
return loghead(buf, socket);
}
ircd::string_view
ircd::net::loghead(const mutable_buffer &out,
const socket &socket)
{
thread_local char buf[2][128];
return fmt::sprintf
{
out, "socket:%lu local[%s] remote[%s]",
id(*socket),
string(buf[0], local_ipport(socket)),
string(buf[1], remote_ipport(socket)),
};
}
ircd::net::ipport
ircd::net::remote_ipport(const socket &socket)
noexcept try