From f4a18726b51cb9a71fefd5b9efc88851c0cef5e1 Mon Sep 17 00:00:00 2001 From: SChernykh Date: Fri, 4 Aug 2023 15:52:28 +0200 Subject: [PATCH] P2PServer: support future major protocol changes --- src/p2p_server.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/p2p_server.cpp b/src/p2p_server.cpp index cfa512d..c6be892 100644 --- a/src/p2p_server.cpp +++ b/src/p2p_server.cpp @@ -2312,7 +2312,17 @@ void 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 = std::min(*reinterpret_cast(ip.data), SUPPORTED_PROTOCOL_VERSION); + const uint32_t version = *reinterpret_cast(ip.data); + + // Clients with different major protocol versions communicate using v1.0 protocol + // to reduce backwards compatibility requirements for newer clients + if ((version >> 16) != (SUPPORTED_PROTOCOL_VERSION >> 16)) { + m_protocolVersion = PROTOCOL_VERSION_1_0; + } + else { + m_protocolVersion = std::min(version, SUPPORTED_PROTOCOL_VERSION); + } + 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()