diff --git a/src/p2p_server.cpp b/src/p2p_server.cpp index bb6f972..7ec6f19 100644 --- a/src/p2p_server.cpp +++ b/src/p2p_server.cpp @@ -1272,7 +1272,7 @@ P2PServer::P2PClient::P2PClient() , m_peerListPendingRequests(0) , m_protocolVersion(PROTOCOL_VERSION_1_0) , m_SoftwareVersion(0) - , m_SoftwareID(0) + , m_SoftwareID(SoftwareID::P2Pool) , m_pingTime(-1) , m_lastAlive(0) , m_lastBroadcastTimestamp(0) @@ -1385,7 +1385,7 @@ void P2PServer::P2PClient::reset() m_peerListPendingRequests = 0; m_protocolVersion = PROTOCOL_VERSION_1_0; m_SoftwareVersion = 0; - m_SoftwareID = 0; + m_SoftwareID = SoftwareID::P2Pool; m_pingTime = -1; m_blockPendingRequests.clear(); m_lastAlive = 0; @@ -2265,6 +2265,7 @@ bool P2PServer::P2PClient::on_peer_list_request(const uint8_t*) 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 + 8) = static_cast(SoftwareID::P2Pool); *reinterpret_cast(peers[0].m_addr.data + sizeof(raw_ip::ipv4_prefix)) = 0xFFFFFFFFU; peers[0].m_port = 0xFFFF; @@ -2347,11 +2348,19 @@ void P2PServer::P2PClient::on_peer_list_response(const uint8_t* buf) } m_SoftwareVersion = *reinterpret_cast(ip.data + 4); - m_SoftwareID = *reinterpret_cast(ip.data + 8); + const uint32_t id_value = *reinterpret_cast(ip.data + 8); + m_SoftwareID = get_software_id(id_value); + LOGINFO(5, "peer " << log::Gray() << static_cast(m_addrString) << log::NoColor() << " supports protocol version " << (m_protocolVersion >> 16) << '.' << (m_protocolVersion & 0xFFFF) << ", runs " << software_name() << " v" << (m_SoftwareVersion >> 16) << '.' << (m_SoftwareVersion & 0xFFFF) ); + + if (m_SoftwareID == SoftwareID::Unknown) { + LOGWARN(4, "peer " << log::Gray() << static_cast(m_addrString) << log::NoColor() + << "runs an unknown software with id = " << log::Hex(id_value) + ); + } } continue; } @@ -2613,9 +2622,9 @@ void P2PServer::P2PClient::post_handle_incoming_block(p2pool* pool, const PoolBl const char* P2PServer::P2PClient::software_name() const { switch (m_SoftwareID) { - case 0: + case SoftwareID::P2Pool: return "P2Pool"; - case 0x624F6F47UL: + case SoftwareID::GoObserver: return "GoObserver"; default: return "Unknown"; diff --git a/src/p2p_server.h b/src/p2p_server.h index 4948346..1006c60 100644 --- a/src/p2p_server.h +++ b/src/p2p_server.h @@ -142,7 +142,7 @@ public: uint32_t m_protocolVersion; uint32_t m_SoftwareVersion; - uint32_t m_SoftwareID; + SoftwareID m_SoftwareID; int64_t m_pingTime; diff --git a/src/util.cpp b/src/util.cpp index 2d9b2c4..f7c809c 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -60,6 +60,20 @@ const char* VERSION = "v" STR2(P2POOL_VERSION_MAJOR) "." STR2(P2POOL_VERSION_MIN #endif " on " __DATE__ ")"; +SoftwareID get_software_id(uint32_t value) +{ + switch (value) { + case static_cast(SoftwareID::P2Pool): + return SoftwareID::P2Pool; + + case static_cast(SoftwareID::GoObserver): + return SoftwareID::GoObserver; + + default: + return SoftwareID::Unknown; + } +} + const raw_ip raw_ip::localhost_ipv4 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x01 }; const raw_ip raw_ip::localhost_ipv6 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }; diff --git a/src/util.h b/src/util.h index bb373f3..5fc8fc8 100644 --- a/src/util.h +++ b/src/util.h @@ -40,6 +40,14 @@ namespace p2pool { extern const char* VERSION; +enum class SoftwareID : uint32_t { + P2Pool = 0, + GoObserver = 0x624F6F47UL, + Unknown = 0xFFFFFFFFUL, +}; + +SoftwareID get_software_id(uint32_t value); + template struct not_implemented { enum { value = 0 }; }; struct nocopy_nomove