From 43afc79a4a3f9c4eac0f0943a2f1b69b2979a380 Mon Sep 17 00:00:00 2001 From: boqiu <82121246@qq.com> Date: Fri, 25 Oct 2024 10:53:16 +0800 Subject: [PATCH] Change P2P protocol version --- node/network/src/lib.rs | 5 ++++- node/router/src/libp2p_event_handler.rs | 6 +++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/node/network/src/lib.rs b/node/network/src/lib.rs index c6a21d8..09a0dfb 100644 --- a/node/network/src/lib.rs +++ b/node/network/src/lib.rs @@ -93,7 +93,10 @@ pub use peer_manager::{ }; pub use service::{load_private_key, Context, Libp2pEvent, Service, NETWORK_KEY_FILENAME}; -pub const PROTOCOL_VERSION: [u8; 3] = [0, 1, 0]; +/// Defines the current P2P protocol version. +/// - v1: Broadcast FindFile & AnnounceFile messages in the whole network, which caused network too heavey. +/// - v2: Publish NewFile to neighbors only and announce file via RPC message. +pub const PROTOCOL_VERSION: [u8; 3] = [0, 2, 0]; /// Application level requests sent to the network. #[derive(Debug, Clone, Copy)] diff --git a/node/router/src/libp2p_event_handler.rs b/node/router/src/libp2p_event_handler.rs index 57fa79d..fa62a5f 100644 --- a/node/router/src/libp2p_event_handler.rs +++ b/node/router/src/libp2p_event_handler.rs @@ -397,6 +397,9 @@ impl Libp2pEventHandler { Err(_) => return MessageAcceptance::Reject, }; + // update shard config cache + self.file_location_cache.insert_peer_config(from, announced_shard_config); + // ignore if already exists match self.store.check_tx_completed(msg.tx_id.seq).await { Ok(true) => return MessageAcceptance::Ignore, @@ -423,9 +426,6 @@ impl Libp2pEventHandler { self.send_to_sync(SyncMessage::NewFile { from, msg }); } - self.file_location_cache - .insert_peer_config(from, announced_shard_config); - MessageAcceptance::Ignore }