From 34b0a91dbb107962dae4f593a36d30a29ea87c45 Mon Sep 17 00:00:00 2001 From: hozan23 Date: Wed, 22 Nov 2023 12:42:00 +0300 Subject: p2p: Improve error handling during handshake: Introduce a new entry status, INCOMPATIBLE_ENTRY. Entries with this status will not increase the failure attempts, instead, they will persist in the routing table until replaced by a new peer. This feature is useful for seeding and the lookup process. Add a boolean value to the VerAck message to indicate whether the version is accepted or not. --- p2p/src/routing_table/bucket.rs | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'p2p/src/routing_table/bucket.rs') diff --git a/p2p/src/routing_table/bucket.rs b/p2p/src/routing_table/bucket.rs index 13edd24..0f43b13 100644 --- a/p2p/src/routing_table/bucket.rs +++ b/p2p/src/routing_table/bucket.rs @@ -6,23 +6,28 @@ use rand::{rngs::OsRng, seq::SliceRandom}; pub type EntryStatusFlag = u16; /// The entry is connected. -pub const CONNECTED_ENTRY: EntryStatusFlag = 0b00001; +pub const CONNECTED_ENTRY: EntryStatusFlag = 0b000001; /// The entry is disconnected. This will increase the failure counter. -pub const DISCONNECTED_ENTRY: EntryStatusFlag = 0b00010; +pub const DISCONNECTED_ENTRY: EntryStatusFlag = 0b000010; /// The entry is ready to reconnect, meaning it has either been added and /// has no connection attempts, or it has been refreshed. -pub const PENDING_ENTRY: EntryStatusFlag = 0b00100; +pub const PENDING_ENTRY: EntryStatusFlag = 0b000100; /// The entry is unreachable. This will increase the failure counter. -pub const UNREACHABLE_ENTRY: EntryStatusFlag = 0b01000; +pub const UNREACHABLE_ENTRY: EntryStatusFlag = 0b001000; /// The entry is unstable. This will increase the failure counter. -pub const UNSTABLE_ENTRY: EntryStatusFlag = 0b10000; +pub const UNSTABLE_ENTRY: EntryStatusFlag = 0b010000; + +/// The entry is incompatible. This entry will not contribute to an increase in +/// failure attempts, instead, it will persist in the routing table for the +/// lookup process and will only be removed in the presence of a new entry. +pub const INCOMPATIBLE_ENTRY: EntryStatusFlag = 0b100000; #[allow(dead_code)] -pub const ALL_ENTRY: EntryStatusFlag = 0b11111; +pub const ALL_ENTRY: EntryStatusFlag = 0b111111; /// A BucketEntry represents a peer in the routing table. #[derive(Clone, Debug)] @@ -38,6 +43,10 @@ impl BucketEntry { self.status ^ CONNECTED_ENTRY == 0 } + pub fn is_incompatible(&self) -> bool { + self.status ^ INCOMPATIBLE_ENTRY == 0 + } + pub fn is_unreachable(&self) -> bool { self.status ^ UNREACHABLE_ENTRY == 0 } -- cgit v1.2.3