ircd: Internalize various loghead utils; remove legacy ostream operators.

This commit is contained in:
Jason Volk 2023-02-09 10:12:11 -08:00
parent 39b5a334a6
commit aa8ce19c7c
18 changed files with 95 additions and 118 deletions

View File

@ -17,6 +17,9 @@ namespace ircd
const ipport &remote(const client &);
const ipport &local(const client &);
string_view loghead(const mutable_buffer &buf, const client &);
string_view loghead(const client &);
}
/// Remote party connecting to our daemon to make requests.
@ -51,7 +54,6 @@ struct ircd::client
size_t content_consumed {0};
resource::request request;
string_view loghead() const;
size_t write_all(const net::const_buffers &);
size_t write_all(const const_buffer &);
void close(const net::close_opts &, net::close_callback);

View File

@ -16,6 +16,14 @@
// 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.
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
}
/// Implementation to net::listener. See listener.h for additional interface.
struct [[gnu::visibility("protected")]]
ircd::net::acceptor

View File

@ -16,6 +16,14 @@
// 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.
namespace ircd::net
{
#pragma GCC visibility push(hidden)
string_view loghead(const mutable_buffer &, const acceptor_udp &);
string_view loghead(const acceptor_udp &);
#pragma GCC visibility pop
}
struct [[gnu::visibility("protected")]]
ircd::net::acceptor_udp
{

View File

@ -28,11 +28,6 @@ namespace ircd::net
size_t handshaking_count(const acceptor &);
size_t accepting_count(const acceptor &);
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 &);
bool allow(acceptor &);
bool start(acceptor &);
bool stop(acceptor &);
@ -78,6 +73,4 @@ struct ircd::net::listener
proffer = {});
~listener() noexcept;
friend std::ostream &operator<<(std::ostream &s, const listener &);
};

View File

@ -15,11 +15,6 @@ namespace ircd::net
{
struct listener_udp;
struct acceptor_udp;
string_view loghead(const mutable_buffer &, const acceptor_udp &);
string_view loghead(const acceptor_udp &);
std::ostream &operator<<(std::ostream &s, const listener_udp &);
std::ostream &operator<<(std::ostream &s, const acceptor_udp &);
}
struct ircd::net::listener_udp
@ -46,8 +41,6 @@ struct ircd::net::listener_udp
const std::string &options);
~listener_udp() noexcept;
friend std::ostream &operator<<(std::ostream &s, const listener_udp &);
};
struct ircd::net::listener_udp::datagram

View File

@ -60,8 +60,6 @@ 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

@ -22,6 +22,9 @@ namespace ircd::net
extern conf::item<std::string> ssl_cipher_list;
extern conf::item<std::string> ssl_cipher_blacklist;
extern asio::ssl::context sslv23_client;
string_view loghead(const mutable_buffer &out, const socket &);
string_view loghead(const socket &);
}
/// Internal socket interface

View File

@ -11,12 +11,6 @@
#pragma once
#define HAVE_IRCD_SERVER_LINK_H
namespace ircd::server
{
string_view loghead(const mutable_buffer &out, const link &);
string_view loghead(const link &);
}
/// A single connection to a remote peer.
///
struct ircd::server::link

View File

@ -24,12 +24,6 @@ namespace ircd::server
// gets the unique tag number from request or 0 if no tag associated.
uint64_t id(const request &) noexcept;
// convenience suite used to prefix log messages.
string_view loghead(const mutable_buffer &out, const request &);
string_view loghead(const request &);
string_view loghead(const mutable_buffer &out, const link &, const request &);
string_view loghead(const link &, const request &);
// control panel
void submit(const hostport &, request &);
bool cancel(request &);

View File

@ -155,6 +155,38 @@ noexcept
// util
//
ircd::string_view
ircd::loghead(const client &client)
{
thread_local char buf[512];
return loghead(buf, client);
}
ircd::string_view
ircd::loghead(const mutable_buffer &buf,
const client &client)
{
const string_view alpn
{
client.sock?
client.sock->alpn:
"h1"_sv
};
char rembuf[64], locbuf[64];
return fmt::sprintf
{
buf, "socket:%lu local:%s remote:%s client:%lu %s %lu:%lu",
client.sock? net::id(*client.sock) : -1UL,
string(locbuf, local(client)),
string(rembuf, remote(client)),
client.id,
alpn,
client.ready_count,
client.request_count,
};
}
const ircd::ipport &
ircd::local(const client &client)
{
@ -199,10 +231,11 @@ ircd::client::wait_all()
{
for(const auto &[remote, client] : client::map)
{
assert(client);
log::dwarning
{
log, "Waiting for client %s",
client->loghead(),
loghead(*client),
};
assert(!client->sock || client->sock->fini);
@ -233,7 +266,8 @@ ircd::client::close_all()
if(!client::map.empty())
log::debug
{
log, "Closing %zu clients", client::map.size()
log, "Closing %zu clients",
client::map.size()
};
auto it(begin(client::map));
@ -247,7 +281,9 @@ ircd::client::close_all()
{
log::derror
{
log, "Error disconnecting client @%p: %s", c.get(), e.what()
log, "Error disconnecting client @%p: %s",
c.get(),
e.what(),
};
}
}
@ -451,7 +487,7 @@ try
log::debug
{
log, "%s enter",
client->loghead()
loghead(*client),
};
#endif
@ -466,7 +502,7 @@ try
log::debug
{
log, "%s leave %s",
client->loghead(),
loghead(*client),
pretty(buf, timer.at<microseconds>(), true)
};
#endif
@ -478,7 +514,7 @@ catch(const std::exception &e)
log::error
{
log, "%s fault :%s",
client->loghead(),
loghead(*client),
e.what()
};
}
@ -496,7 +532,7 @@ ircd::handle_ec(client &client,
log::dwarning
{
client::log, "%s refusing client request in runlevel %s",
client.loghead(),
loghead(client),
reflect(run::level)
};
@ -533,7 +569,7 @@ try
log::debug
{
client::log, "%s end of file",
client.loghead()
loghead(client),
};
client.close(net::dc::SSL_NOTIFY, net::close_ignore);
@ -544,7 +580,7 @@ catch(const std::exception &e)
log::error
{
client::log, "%s end of file :%s",
client.loghead(),
loghead(client),
e.what()
};
@ -561,7 +597,7 @@ try
log::dwarning
{
client::log, "%s short_read",
client.loghead()
loghead(client),
};
client.close(net::dc::RST, net::close_ignore);
@ -572,7 +608,7 @@ catch(const std::exception &e)
log::error
{
client::log, "%s short_read :%s",
client.loghead(),
loghead(client),
e.what()
};
@ -591,7 +627,7 @@ try
log::debug
{
client::log, "%s disconnecting after inactivity timeout",
client.loghead()
loghead(client),
};
client.close(net::dc::SSL_NOTIFY, net::close_ignore);
@ -602,7 +638,7 @@ catch(const std::exception &e)
log::derror
{
client::log, "%s timeout :%s",
client.loghead(),
loghead(client),
e.what()
};
@ -619,7 +655,7 @@ ircd::handle_ec_default(client &client,
log::derror
{
client::log, "%s :%s",
client.loghead(),
loghead(client),
string(buf, ec)
};
@ -722,7 +758,7 @@ catch(const ctx::interrupted &e)
log::warning
{
log, "%s request interrupted :%s",
loghead(),
loghead(*this),
e.what()
};
@ -734,7 +770,7 @@ catch(const std::exception &e)
log::critical
{
log, "%s :%s",
loghead(),
loghead(*this),
e.what()
};
@ -786,7 +822,7 @@ try
log::debug
{
resource::log, "%s HTTP %s `%s' content-length:%zu have:%zu",
loghead(),
loghead(*this),
head.method,
head.path,
head.content_length,
@ -849,7 +885,7 @@ catch(const http::error &e)
{
log, log::level::DERROR,
"%s HTTP %u %s :%s",
loghead(),
loghead(*this),
uint(e.code),
http::status(e.code),
e.content
@ -913,7 +949,7 @@ catch(const http::error &e)
{
resource::log, log::level::DERROR,
"%s HTTP %u `%s' %s :%s",
loghead(),
loghead(*this),
uint(e.code),
head.uri,
http::status(e.code),
@ -956,7 +992,7 @@ catch(const std::exception &e)
log::error
{
resource::log, "%s HTTP 500 Internal Error `%s' :%s",
loghead(),
loghead(*this),
head.uri,
e.what()
};
@ -992,7 +1028,7 @@ ircd::client::discard_unconsumed(const http::request::head &head)
log::debug
{
log, "%s discarding %zu unconsumed of %zu bytes content...",
loghead(),
loghead(*this),
unconsumed,
head.content_length
};
@ -1039,35 +1075,3 @@ ircd::client::write_all(const net::const_buffers &bufs)
return net::write_all(*sock, bufs);
}
/// Returns a string_view to a static (tls) buffer containing common
/// information used to prefix log calls for this client: i.e id, remote
/// address, etc. This is meant to be used as the first argument to all log
/// calls apropos this client and should not be held over a context switch
/// as there is only one static buffer.
ircd::string_view
ircd::client::loghead()
const
{
thread_local char buf[512];
const string_view alpn
{
sock?
sock->alpn:
nullptr
};
char rembuf[64], locbuf[64];
return fmt::sprintf
{
buf, "socket:%lu local:%s remote:%s client:%lu %s %lu:%lu",
sock? net::id(*sock) : -1UL,
string(locbuf, ircd::local(*this)),
string(rembuf, ircd::remote(*this)),
id,
alpn?: "h1"_sv,
ready_count,
request_count,
};
}

View File

@ -49,20 +49,6 @@ ircd::net::allow(acceptor &a)
return true;
}
std::ostream &
ircd::net::operator<<(std::ostream &s, const acceptor &a)
{
s << loghead(a);
return s;
}
std::ostream &
ircd::net::operator<<(std::ostream &s, const listener &a)
{
s << *a.acceptor;
return s;
}
ircd::string_view
ircd::net::loghead(const acceptor &a)
{

View File

@ -8,20 +8,6 @@
// copyright notice and this permission notice is present in all copies. The
// full license for this software is available in the LICENSE file.
std::ostream &
ircd::net::operator<<(std::ostream &s, const listener_udp &a)
{
s << *a.acceptor;
return s;
}
std::ostream &
ircd::net::operator<<(std::ostream &s, const acceptor_udp &a)
{
s << loghead(a);
return s;
}
ircd::string_view
ircd::net::loghead(const acceptor_udp &a)
{

View File

@ -688,7 +688,7 @@ const
log::derror
{
log, "%s Timed out in %s `%s'",
client.loghead(),
loghead(client),
name,
resource->path
};
@ -951,7 +951,7 @@ noexcept try
log::derror
{
log, "%s HTTP response chunks:%u wrote:%zu flushed:%zu :stream interrupted...",
c->loghead(),
loghead(*c),
count,
wrote,
flushed,
@ -991,7 +991,7 @@ ircd::resource::response::chunked::finish(const bool psh)
log::debug
{
log, "%s HTTP --- `%s' in %s wrote:%zu flushed:%zu chunks:%u psh:%b",
c->loghead(),
loghead(*c),
c->request.head.path,
pretty(tmbuf, c->timer.at<microseconds>(), true),
wrote,
@ -1371,7 +1371,7 @@ ircd::resource::response::response(client &client,
{
log, level,
"%s HTTP %u `%s' %s in %s; %s content-length:%s head-length:%zu %s%s",
client.loghead(),
loghead(client),
uint(code),
client.request.head.path,
http::status(code),

View File

@ -23,6 +23,14 @@ namespace ircd::server
template<class F> static size_t accumulate_tags(F&&);
static string_view canonize(const hostport &); // TLS buffer
// convenience suite used to prefix log messages.
static string_view loghead(const mutable_buffer &out, const request &);
static string_view loghead(const request &);
static string_view loghead(const mutable_buffer &out, const link &, const request &);
static string_view loghead(const link &, const request &);
static string_view loghead(const mutable_buffer &out, const link &);
static string_view loghead(const link &);
// Internal control
static decltype(ircd::server::peers)::iterator
create(const net::hostport &, decltype(peers)::iterator &);

View File

@ -211,7 +211,7 @@ try
log::debug
{
log, "%s %s %s %s `%s'",
client.loghead(),
loghead(client),
ident,
request.head.method,
request.version?: "??"_sv,

View File

@ -310,7 +310,7 @@ get__context(client &client,
log::debug
{
context_log, "%s %s in %s before:%zu start:%s after:%zu end:%s state:%zu",
client.loghead(),
loghead(client),
string_view{event_id},
string_view{room_id},
counts.before,

View File

@ -201,7 +201,7 @@ get__messages(client &client,
log::debug
{
messages_log, "%s in %s from:%s to:%s dir:%c limit:%zu start:%s end:%s hit:%zu miss:%zu post:%zu",
client.loghead(),
loghead(client),
string_view{room_id},
string_view{page.from},
string_view{page.to},

View File

@ -17307,7 +17307,7 @@ console_cmd__synchron(opt &out, const string_view &line)
{
const auto *const &client(data_p->client);
if(client)
out << client->loghead() << " | ";
out << loghead(*client) << " | ";
out << m::sync::loghead(*data_p) << " | ";
out << '\n';