From da9cdf7df31c64106de7edf3321293157503ec45 Mon Sep 17 00:00:00 2001 From: SChernykh Date: Thu, 10 Nov 2022 11:33:57 +0100 Subject: [PATCH] Send our P2Pool version to other peers --- src/p2p_server.cpp | 28 ++++++++++++++++++++++++---- src/p2p_server.h | 1 + src/util.cpp | 2 +- src/util.h | 3 +++ 4 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/p2p_server.cpp b/src/p2p_server.cpp index 27e231d..0e0fdfa 100644 --- a/src/p2p_server.cpp +++ b/src/p2p_server.cpp @@ -964,7 +964,18 @@ 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) { - LOGINFO(0, (client->m_isIncoming ? "I " : "O ") << client->m_pingTime << " ms\t" << static_cast(client->m_addrString)); + char buf[32]; + log::Stream s(buf); + if (client->m_P2PoolVersion) { + s << 'v' << (client->m_P2PoolVersion >> 16) << '.' << (client->m_P2PoolVersion & 0xFFFF) << " \0"; + } + else { + s << "<= v2.5 \0"; + } + LOGINFO(0, (client->m_isIncoming ? "I " : "O ") + << log::pad_right(client->m_pingTime, 4) << " ms " + << log::pad_right(static_cast(buf), 8) + << static_cast(client->m_addrString)); ++n; } } @@ -1173,6 +1184,7 @@ P2PServer::P2PClient::P2PClient() , m_lastPeerListRequestTime{} , m_peerListPendingRequests(0) , m_protocolVersion(PROTOCOL_VERSION_1_0) + , m_P2PoolVersion(0) , m_pingTime(-1) , m_blockPendingRequests(0) , m_chainTipBlockRequest(false) @@ -1219,6 +1231,7 @@ void P2PServer::P2PClient::reset() m_lastPeerListRequestTime = {}; m_peerListPendingRequests = 0; m_protocolVersion = PROTOCOL_VERSION_1_0; + m_P2PoolVersion = 0; m_pingTime = -1; m_blockPendingRequests = 0; m_chainTipBlockRequest = false; @@ -2051,12 +2064,15 @@ bool P2PServer::P2PClient::on_peer_list_request(const uint8_t*) // - IPv4 address = 255.255.255.255 // - port = 65535 // - first 12 bytes of the 16-byte raw IP address are ignored by older clients if it's IPv4 - // - use first 4 bytes of the 16-byte raw IP address to send supported protocol version + // - use first 8 bytes of the 16-byte raw IP address to send supported protocol version and p2pool version if (first) { - LOGINFO(5, "sending protocol version " << (SUPPORTED_PROTOCOL_VERSION >> 16) << '.' << (SUPPORTED_PROTOCOL_VERSION & 0xFFFF) << " to peer " << log::Gray() << static_cast(m_addrString)); + LOGINFO(5, "sending protocol version " << (SUPPORTED_PROTOCOL_VERSION >> 16) << '.' << (SUPPORTED_PROTOCOL_VERSION & 0xFFFF) + << ", P2Pool version " << P2POOL_VERSION_MAJOR << '.' << P2POOL_VERSION_MINOR + << " to peer " << log::Gray() << static_cast(m_addrString)); peers[0] = {}; *reinterpret_cast(peers[0].m_addr.data) = SUPPORTED_PROTOCOL_VERSION; + *reinterpret_cast(peers[0].m_addr.data + 4) = (P2POOL_VERSION_MAJOR << 16) | P2POOL_VERSION_MINOR; *reinterpret_cast(peers[0].m_addr.data + 12) = 0xFFFFFFFFU; peers[0].m_port = 0xFFFF; @@ -2128,7 +2144,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); - LOGINFO(5, "peer " << log::Gray() << static_cast(m_addrString) << log::NoColor() << " supports protocol version " << (m_protocolVersion >> 16) << '.' << (m_protocolVersion & 0xFFFF)); + m_P2PoolVersion = *reinterpret_cast(ip.data + 4); + 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) + ); } continue; } diff --git a/src/p2p_server.h b/src/p2p_server.h index 69917c9..5a63ea2 100644 --- a/src/p2p_server.h +++ b/src/p2p_server.h @@ -125,6 +125,7 @@ public: int m_peerListPendingRequests; uint32_t m_protocolVersion; + uint32_t m_P2PoolVersion; int64_t m_pingTime; diff --git a/src/util.cpp b/src/util.cpp index 2693364..d228a66 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -32,7 +32,7 @@ namespace p2pool { #define STR2(X) STR(X) #define STR(X) #X -const char* VERSION = "v2.5 (built" +const char* VERSION = "v" STR2(P2POOL_VERSION_MAJOR) "." STR2(P2POOL_VERSION_MINOR) " (built" #if defined(__clang__) " with clang/" __clang_version__ #elif defined(__GNUC__) diff --git a/src/util.h b/src/util.h index 3896014..0981a9b 100644 --- a/src/util.h +++ b/src/util.h @@ -34,6 +34,9 @@ namespace p2pool { +#define P2POOL_VERSION_MAJOR 2 +#define P2POOL_VERSION_MINOR 5 + extern const char* VERSION; template struct not_implemented { enum { value = 0 }; };