mirror of
https://github.com/matrix-construct/construct
synced 2024-06-11 06:28:55 +02:00
ircd::server: Add interface to iterate all requests.
This commit is contained in:
parent
5f1f0d0d7f
commit
d38c5801c9
|
@ -100,6 +100,7 @@ struct ircd::server::request
|
|||
:ctx::future<http::code>
|
||||
{
|
||||
struct opts;
|
||||
using each_closure = std::function<bool (const peer &, const link &, const request &)>;
|
||||
|
||||
static const opts opts_default;
|
||||
|
||||
|
|
|
@ -36,17 +36,27 @@ namespace ircd::server
|
|||
|
||||
namespace ircd::server
|
||||
{
|
||||
// const utils
|
||||
size_t tag_count();
|
||||
size_t link_count();
|
||||
size_t peer_count();
|
||||
size_t peer_unfinished();
|
||||
|
||||
// iteration of all requests.
|
||||
bool for_each(const link &, const request::each_closure &);
|
||||
bool for_each(const peer &, const request::each_closure &);
|
||||
bool for_each(const request::each_closure &);
|
||||
|
||||
// const utils
|
||||
string_view errmsg(const net::hostport &);
|
||||
bool errclear(const net::hostport &);
|
||||
bool exists(const net::hostport &);
|
||||
peer &find(const net::hostport &);
|
||||
peer &get(const net::hostport &);
|
||||
|
||||
// mutable utils
|
||||
bool errclear(const net::hostport &);
|
||||
peer &get(const net::hostport &); // creates the peer if not found.
|
||||
|
||||
// control panel
|
||||
void interrupt_all();
|
||||
void close_all();
|
||||
void wait_all();
|
||||
|
|
|
@ -196,6 +196,44 @@ ircd::server::errmsg(const net::hostport &hostport)
|
|||
return it->second->err_msg();
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::server::for_each(const request::each_closure &closure)
|
||||
{
|
||||
for(const auto &[name, peer] : peers)
|
||||
if(!for_each(*peer, closure))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::server::for_each(const peer &peer,
|
||||
const request::each_closure &closure)
|
||||
{
|
||||
for(const auto &link : peer.links)
|
||||
if(!for_each(link, closure))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::server::for_each(const link &link,
|
||||
const request::each_closure &closure)
|
||||
{
|
||||
for(const auto &tag : link.queue)
|
||||
{
|
||||
assert(link.peer);
|
||||
if(!tag.request)
|
||||
continue;
|
||||
|
||||
if(!closure(*link.peer, link, *tag.request))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
size_t
|
||||
ircd::server::peer_unfinished()
|
||||
{
|
||||
|
|
|
@ -4273,6 +4273,87 @@ catch(const std::out_of_range &e)
|
|||
};
|
||||
}
|
||||
|
||||
bool
|
||||
console_cmd__peer__request(opt &out, const string_view &line)
|
||||
try
|
||||
{
|
||||
const params param{line, " ",
|
||||
{
|
||||
"servername", "linkid"
|
||||
}};
|
||||
|
||||
const auto &servername
|
||||
{
|
||||
param["servername"]
|
||||
};
|
||||
|
||||
const auto &linkid
|
||||
{
|
||||
param["linkid"]
|
||||
};
|
||||
|
||||
const auto each{[&out]
|
||||
(const server::peer &peer, const server::link &link, const server::request &request)
|
||||
{
|
||||
const auto out_head(request.out.gethead(request));
|
||||
if(!out_head.method || !out_head.path)
|
||||
return true;
|
||||
|
||||
thread_local char rembuf[128];
|
||||
const string_view &remote
|
||||
{
|
||||
link.socket?
|
||||
string(rembuf, remote_ipport(*link.socket)):
|
||||
"<no socket>"_sv
|
||||
};
|
||||
|
||||
out << std::setw(48) << peer.server_name << " "
|
||||
<< std::setw(56) << remote << " "
|
||||
<< std::setw(8) << out_head.method << " "
|
||||
<< std::setw(0) << out_head.path << " "
|
||||
<< std::endl;
|
||||
|
||||
return true;
|
||||
}};
|
||||
|
||||
if(servername && linkid)
|
||||
{
|
||||
auto &peer
|
||||
{
|
||||
server::find(servername)
|
||||
};
|
||||
|
||||
throw m::UNSUPPORTED
|
||||
{
|
||||
"Link identifiers are not yet implemented;"
|
||||
" cannot iterate request for one link."
|
||||
};
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if(servername)
|
||||
{
|
||||
auto &peer
|
||||
{
|
||||
server::find(servername)
|
||||
};
|
||||
|
||||
server::for_each(peer, each);
|
||||
return true;
|
||||
}
|
||||
|
||||
server::for_each(each);
|
||||
return true;
|
||||
}
|
||||
catch(const std::out_of_range &e)
|
||||
{
|
||||
throw error
|
||||
{
|
||||
"Peer not found"
|
||||
};
|
||||
}
|
||||
|
||||
//
|
||||
// net
|
||||
//
|
||||
|
|
Loading…
Reference in a new issue