From 9f5e79aa00f02fd80c0ad8da1e159587f9ae1305 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Mon, 14 May 2018 00:04:44 -0700 Subject: [PATCH] modules/console: Add peer find cmd. --- modules/console.cc | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/modules/console.cc b/modules/console.cc index 8b6c35c6e..0063e634a 100644 --- a/modules/console.cc +++ b/modules/console.cc @@ -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 //