From e49f7450d2a57765e4e3a65f375b289b1178f770 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Fri, 31 May 2019 09:09:24 +0000 Subject: [PATCH] daemon: display peer address type in print_cn --- .../cryptonote_protocol_defs.h | 3 +++ .../cryptonote_protocol_handler.inl | 1 + src/daemon/rpc_command_executor.cpp | 15 +++++++++++++++ src/serialization/json_object.cpp | 2 ++ 4 files changed, 21 insertions(+) diff --git a/src/cryptonote_protocol/cryptonote_protocol_defs.h b/src/cryptonote_protocol/cryptonote_protocol_defs.h index 3083a5b4c..0c8155593 100644 --- a/src/cryptonote_protocol/cryptonote_protocol_defs.h +++ b/src/cryptonote_protocol/cryptonote_protocol_defs.h @@ -83,6 +83,8 @@ namespace cryptonote uint32_t pruning_seed; + uint8_t address_type; + BEGIN_KV_SERIALIZE_MAP() KV_SERIALIZE(incoming) KV_SERIALIZE(localhost) @@ -107,6 +109,7 @@ namespace cryptonote KV_SERIALIZE(connection_id) KV_SERIALIZE(height) KV_SERIALIZE(pruning_seed) + KV_SERIALIZE(address_type) END_KV_SERIALIZE_MAP() }; diff --git a/src/cryptonote_protocol/cryptonote_protocol_handler.inl b/src/cryptonote_protocol/cryptonote_protocol_handler.inl index 399441b0e..455d6b06e 100644 --- a/src/cryptonote_protocol/cryptonote_protocol_handler.inl +++ b/src/cryptonote_protocol/cryptonote_protocol_handler.inl @@ -285,6 +285,7 @@ namespace cryptonote cnx.height = cntxt.m_remote_blockchain_height; cnx.pruning_seed = cntxt.m_pruning_seed; + cnx.address_type = (uint8_t)cntxt.m_remote_address.get_type_id(); connections.push_back(cnx); diff --git a/src/daemon/rpc_command_executor.cpp b/src/daemon/rpc_command_executor.cpp index ba02a0c38..8be574eba 100644 --- a/src/daemon/rpc_command_executor.cpp +++ b/src/daemon/rpc_command_executor.cpp @@ -46,6 +46,19 @@ namespace daemonize { namespace { + const char *get_address_type_name(epee::net_utils::address_type address_type) + { + switch (address_type) + { + default: + case epee::net_utils::address_type::invalid: return "invalid"; + case epee::net_utils::address_type::ipv4: return "IPv4"; + case epee::net_utils::address_type::ipv6: return "IPv6"; + case epee::net_utils::address_type::i2p: return "I2P"; + case epee::net_utils::address_type::tor: return "Tor"; + } + } + void print_peer(std::string const & prefix, cryptonote::peer const & peer) { time_t now; @@ -590,6 +603,7 @@ bool t_rpc_command_executor::print_connections() { } tools::msg_writer() << std::setw(30) << std::left << "Remote Host" + << std::setw(8) << "Type" << std::setw(6) << "SSL" << std::setw(20) << "Peer id" << std::setw(20) << "Support Flags" @@ -610,6 +624,7 @@ bool t_rpc_command_executor::print_connections() { tools::msg_writer() //<< std::setw(30) << std::left << in_out << std::setw(30) << std::left << address + << std::setw(8) << (get_address_type_name((epee::net_utils::address_type)info.address_type)) << std::setw(6) << (info.ssl ? "yes" : "no") << std::setw(20) << epee::string_tools::pad_string(info.peer_id, 16, '0', true) << std::setw(20) << info.support_flags diff --git a/src/serialization/json_object.cpp b/src/serialization/json_object.cpp index 73e17a775..cc52bde58 100644 --- a/src/serialization/json_object.cpp +++ b/src/serialization/json_object.cpp @@ -566,6 +566,7 @@ void toJsonValue(rapidjson::Document& doc, const cryptonote::connection_info& in INSERT_INTO_JSON_OBJECT(val, doc, incoming, info.incoming); INSERT_INTO_JSON_OBJECT(val, doc, localhost, info.localhost); INSERT_INTO_JSON_OBJECT(val, doc, local_ip, info.local_ip); + INSERT_INTO_JSON_OBJECT(val, doc, address_type, info.address_type); INSERT_INTO_JSON_OBJECT(val, doc, ip, info.ip); INSERT_INTO_JSON_OBJECT(val, doc, port, info.port); @@ -601,6 +602,7 @@ void fromJsonValue(const rapidjson::Value& val, cryptonote::connection_info& inf GET_FROM_JSON_OBJECT(val, info.incoming, incoming); GET_FROM_JSON_OBJECT(val, info.localhost, localhost); GET_FROM_JSON_OBJECT(val, info.local_ip, local_ip); + GET_FROM_JSON_OBJECT(val, info.address_type, address_type); GET_FROM_JSON_OBJECT(val, info.ip, ip); GET_FROM_JSON_OBJECT(val, info.port, port);