0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-07-05 18:18:35 +02:00

modules/console: Add 'net node'; default list the nodes.

This commit is contained in:
Jason Volk 2018-03-03 09:41:37 -08:00
parent 9cf25a2d3b
commit 9db8b9d6a5

View file

@ -338,6 +338,7 @@ console_cmd__db_list(const string_view &line)
// net
//
static bool console_cmd__net_node(const string_view &line);
static bool console_cmd__net_host(const string_view &line);
bool
@ -353,11 +354,74 @@ console_cmd__net(const string_view &line)
case hash("host"):
return console_cmd__net_host(args);
case hash("node"):
return console_cmd__net_node(args);
default:
throw bad_command{};
}
}
static bool console_cmd__net_node__default();
bool
console_cmd__net_node(const string_view &line)
{
const auto args
{
tokens_after(line, ' ', 0)
};
if(empty(line))
return console_cmd__net_node__default();
switch(hash(token(line, ' ', 0)))
{
default:
throw bad_command{};
}
return true;
}
bool
console_cmd__net_node__default()
{
for(const auto &p : server::nodes)
{
using std::setw;
using std::left;
using std::right;
const auto &host{p.first};
const auto &node{*p.second};
const net::ipport &ipp{node.remote};
out << setw(40) << right << host;
if(ipp)
out << ' ' << setw(22) << left << ipp;
else
out << ' ' << setw(22) << left << " ";
out << " "
<< " " << setw(2) << right << node.link_count() << " L"
<< " " << setw(2) << right << node.tag_count() << " T"
<< " " << setw(9) << right << node.write_total() << " UP"
<< " " << setw(9) << right << node.read_total() << " DN"
;
if(node.err_has() && node.err_msg())
out << " :" << node.err_msg();
else if(node.err_has())
out << " <unknown error>"_sv;
out << std::endl;
}
return true;
}
static bool console_cmd__net_host_cache(const string_view &line);
static bool console_cmd__net_host__default(const string_view &line);