Added protocol version negotiation

Protocol version 1.1: compact block broadcasts
This commit is contained in:
SChernykh
2022-11-09 19:03:58 +01:00
parent 47ff7e228e
commit 25806b67a2
2 changed files with 65 additions and 24 deletions
+11 -2
View File
@@ -30,6 +30,11 @@ static constexpr size_t PEER_LIST_RESPONSE_MAX_PEERS = 16;
static constexpr int DEFAULT_P2P_PORT = 37889;
static constexpr int DEFAULT_P2P_PORT_MINI = 37888;
static constexpr uint32_t PROTOCOL_VERSION_1_0 = 0x00010000UL;
static constexpr uint32_t PROTOCOL_VERSION_1_1 = 0x00010001UL;
static constexpr uint32_t SUPPORTED_PROTOCOL_VERSION = PROTOCOL_VERSION_1_1;
class P2PServer : public TCPServer<P2P_BUF_SIZE, P2P_BUF_SIZE>
{
public:
@@ -42,6 +47,7 @@ public:
BLOCK_BROADCAST = 5,
PEER_LIST_REQUEST = 6,
PEER_LIST_RESPONSE = 7,
BLOCK_BROADCAST_COMPACT = 8,
};
explicit P2PServer(p2pool *pool);
@@ -94,9 +100,9 @@ public:
bool on_listen_port(const uint8_t* buf);
bool on_block_request(const uint8_t* buf);
bool on_block_response(const uint8_t* buf, uint32_t size);
bool on_block_broadcast(const uint8_t* buf, uint32_t size);
bool on_block_broadcast(const uint8_t* buf, uint32_t size, bool compact);
bool on_peer_list_request(const uint8_t* buf);
bool on_peer_list_response(const uint8_t* buf) const;
bool on_peer_list_response(const uint8_t* buf);
bool handle_incoming_block_async(const PoolBlock* block, uint64_t max_time_delta = 0);
void handle_incoming_block(p2pool* pool, PoolBlock& block, const uint32_t reset_counter, const raw_ip& addr, std::vector<hash>& missing_blocks);
@@ -117,6 +123,9 @@ public:
uint64_t m_nextOutgoingPeerListRequest;
std::chrono::high_resolution_clock::time_point m_lastPeerListRequestTime;
int m_peerListPendingRequests;
uint32_t m_protocolVersion;
int64_t m_pingTime;
int m_blockPendingRequests;