0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-27 07:54:05 +01:00

modules/console: Add peer find cmd.

This commit is contained in:
Jason Volk 2018-05-14 00:04:44 -07:00
parent 915076296f
commit 9f5e79aa00

View file

@ -1765,6 +1765,43 @@ console_cmd__peer__version(opt &out, const string_view &line)
return true;
}
bool
console_cmd__peer__find(opt &out, const string_view &line)
{
const params param{line, " ",
{
"ip:port"
}};
const auto &ip{rsplit(param.at(0), ':').first};
const auto &port{rsplit(param.at(0), ':').second};
const net::ipport ipp{ip, port? port : "0"};
for(const auto &p : server::peers)
{
const auto &hostname{p.first};
const auto &peer{*p.second};
const net::ipport &ipp_
{
peer.remote
};
if(is_v6(ipp) && (!is_v6(ipp_) || host6(ipp) != host6(ipp_)))
continue;
if(is_v4(ipp) && (!is_v4(ipp_) || host4(ipp) != host4(ipp_)))
continue;
if(net::port(ipp) && net::port(ipp) != net::port(ipp_))
continue;
out << hostname << std::endl;
break;
}
return true;
}
//
// net
//