From 3e4f877ec0fa8c98ce8bc51216bc5d0898a74037 Mon Sep 17 00:00:00 2001 From: SChernykh Date: Fri, 2 Dec 2022 15:29:35 +0100 Subject: [PATCH] Display software name in peers list --- src/common.h | 2 +- src/p2p_server.cpp | 36 ++++++++++++++++++++++++------------ src/p2p_server.h | 5 ++++- 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/src/common.h b/src/common.h index c00950e..40d6638 100644 --- a/src/common.h +++ b/src/common.h @@ -19,7 +19,7 @@ #ifdef _MSC_VER -#pragma warning(disable : 4005 4061 4324 4365 4464 4625 4626 4668 4710 4711 4804 4820 5039 5045 5220 5246) +#pragma warning(disable : 4005 4061 4324 4365 4464 4619 4625 4626 4668 4710 4711 4804 4820 5039 5045 5220 5246 5264) #define FORCEINLINE __forceinline #define NOINLINE __declspec(noinline) #define LIKELY(expression) expression diff --git a/src/p2p_server.cpp b/src/p2p_server.cpp index ae9348a..7dfd1b3 100644 --- a/src/p2p_server.cpp +++ b/src/p2p_server.cpp @@ -963,17 +963,14 @@ void P2PServer::show_peers() for (P2PClient* client = static_cast(m_connectedClientsList->m_next); client != m_connectedClientsList; client = static_cast(client->m_next)) { if (client->m_listenPort >= 0) { - char buf[32]; + char buf[32] = {}; log::Stream s(buf); - if (client->m_P2PoolVersion) { - s << "\tv" << (client->m_P2PoolVersion >> 16) << '.' << (client->m_P2PoolVersion & 0xFFFF) << "\t\0"; - } - else { - s << "\t \t\0"; + if (client->m_SoftwareVersion) { + s << client->software_name() << " v" << (client->m_SoftwareVersion >> 16) << '.' << (client->m_SoftwareVersion & 0xFFFF); } LOGINFO(0, (client->m_isIncoming ? "I\t" : "O\t") - << log::pad_right(client->m_pingTime, 4) << " ms\t" - << static_cast(buf) + << log::pad_right(client->m_pingTime, 4) << " ms\t\t" + << log::pad_right(static_cast(buf), 20) << '\t' << static_cast(client->m_addrString)); ++n; } @@ -1183,7 +1180,8 @@ P2PServer::P2PClient::P2PClient() , m_lastPeerListRequestTime{} , m_peerListPendingRequests(0) , m_protocolVersion(PROTOCOL_VERSION_1_0) - , m_P2PoolVersion(0) + , m_SoftwareVersion(0) + , m_SoftwareID(0) , m_pingTime(-1) , m_blockPendingRequests(0) , m_chainTipBlockRequest(false) @@ -1230,7 +1228,8 @@ void P2PServer::P2PClient::reset() m_lastPeerListRequestTime = {}; m_peerListPendingRequests = 0; m_protocolVersion = PROTOCOL_VERSION_1_0; - m_P2PoolVersion = 0; + m_SoftwareVersion = 0; + m_SoftwareID = 0; m_pingTime = -1; m_blockPendingRequests = 0; m_chainTipBlockRequest = false; @@ -2140,10 +2139,11 @@ bool P2PServer::P2PClient::on_peer_list_response(const uint8_t* buf) // Check for protocol version message if ((*reinterpret_cast(ip.data + 12) == 0xFFFFFFFFU) && (port == 0xFFFF)) { m_protocolVersion = *reinterpret_cast(ip.data); - m_P2PoolVersion = *reinterpret_cast(ip.data + 4); + m_SoftwareVersion = *reinterpret_cast(ip.data + 4); + m_SoftwareID = *reinterpret_cast(ip.data + 8); LOGINFO(5, "peer " << log::Gray() << static_cast(m_addrString) << log::NoColor() << " supports protocol version " << (m_protocolVersion >> 16) << '.' << (m_protocolVersion & 0xFFFF) - << ", runs P2Pool version " << (m_P2PoolVersion >> 16) << '.' << (m_P2PoolVersion & 0xFFFF) + << ", runs " << software_name() << " v" << (m_SoftwareVersion >> 16) << '.' << (m_SoftwareVersion & 0xFFFF) ); } continue; @@ -2346,4 +2346,16 @@ void P2PServer::P2PClient::post_handle_incoming_block(const uint32_t reset_count } } +const char* P2PServer::P2PClient::software_name() const +{ + switch (m_SoftwareID) { + case 0: + return "P2Pool"; + case 0x624F6F47UL: + return "GoObserver"; + default: + return "Unknown"; + } +} + } // namespace p2pool diff --git a/src/p2p_server.h b/src/p2p_server.h index a1fff51..6ab7c7f 100644 --- a/src/p2p_server.h +++ b/src/p2p_server.h @@ -110,6 +110,8 @@ public: bool is_good() const { return m_handshakeComplete && !m_handshakeInvalid && (m_listenPort >= 0); } + const char* software_name() const; + uint64_t m_peerId; MessageId m_expectedMessage; uint64_t m_handshakeChallenge; @@ -125,7 +127,8 @@ public: int m_peerListPendingRequests; uint32_t m_protocolVersion; - uint32_t m_P2PoolVersion; + uint32_t m_SoftwareVersion; + uint32_t m_SoftwareID; int64_t m_pingTime;