From d7514fc3debb9e7112ffbcbe42914c797c588518 Mon Sep 17 00:00:00 2001 From: driftluo Date: Thu, 17 Mar 2022 15:01:51 +0800 Subject: [PATCH] chore: add some logs --- network/src/protocols/mod.rs | 5 +++++ network/src/protocols/support_protocols.rs | 24 ++++++++++++++-------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/network/src/protocols/mod.rs b/network/src/protocols/mod.rs index 948865aaa0..4c1e6cfe2f 100644 --- a/network/src/protocols/mod.rs +++ b/network/src/protocols/mod.rs @@ -247,6 +247,7 @@ impl ServiceProtocol for CKBHandler { } fn connected(&mut self, context: ProtocolContextMutRef, version: &str) { + // This judgment will be removed in the first release after hardfork if self .network_state .ckb2021 @@ -254,6 +255,10 @@ impl ServiceProtocol for CKBHandler { && version != "2" && context.proto_id != SupportProtocols::Relay.protocol_id() { + debug!( + "session {}, protocol {} with version {}, not 2, so disconnect it", + context.session.id, context.proto_id, version + ); let id = context.session.id; let _ignore = context.disconnect(id); return; diff --git a/network/src/protocols/support_protocols.rs b/network/src/protocols/support_protocols.rs index e7c8ebdd89..1042d3ab9b 100644 --- a/network/src/protocols/support_protocols.rs +++ b/network/src/protocols/support_protocols.rs @@ -6,6 +6,8 @@ use p2p::{ }; use tokio_util::codec::length_delimited; +const LASTEST_VERSION: &str = "2"; + /// All supported protocols /// /// The underlying network of CKB is flexible and complex. The flexibility lies in that it can support any number of protocols. @@ -91,17 +93,21 @@ impl SupportProtocols { // we didn't invoke MetaBuilder#support_versions fn for these protocols (Ping/Discovery/Identify/Feeler/DisconnectMessage) // in previous code, so the default 0.0.1 value is used ( https://github.com/nervosnetwork/tentacle/blob/master/src/builder.rs#L312 ) // have to keep 0.0.1 for compatibility... + // + // Here you have to make sure that the list of supported versions is sorted from smallest to largest match self { - SupportProtocols::Ping => vec!["0.0.1".to_owned(), "2".to_owned()], - SupportProtocols::Discovery => vec!["0.0.1".to_owned(), "2".to_owned()], - SupportProtocols::Identify => vec!["0.0.1".to_owned(), "2".to_owned()], - SupportProtocols::Feeler => vec!["0.0.1".to_owned(), "2".to_owned()], - SupportProtocols::DisconnectMessage => vec!["0.0.1".to_owned(), "2".to_owned()], - SupportProtocols::Sync => vec!["1".to_owned(), "2".to_owned()], + SupportProtocols::Ping => vec!["0.0.1".to_owned(), LASTEST_VERSION.to_owned()], + SupportProtocols::Discovery => vec!["0.0.1".to_owned(), LASTEST_VERSION.to_owned()], + SupportProtocols::Identify => vec!["0.0.1".to_owned(), LASTEST_VERSION.to_owned()], + SupportProtocols::Feeler => vec!["0.0.1".to_owned(), LASTEST_VERSION.to_owned()], + SupportProtocols::DisconnectMessage => { + vec!["0.0.1".to_owned(), LASTEST_VERSION.to_owned()] + } + SupportProtocols::Sync => vec!["1".to_owned(), LASTEST_VERSION.to_owned()], SupportProtocols::Relay => vec!["1".to_owned()], - SupportProtocols::Time => vec!["1".to_owned(), "2".to_owned()], - SupportProtocols::Alert => vec!["1".to_owned(), "2".to_owned()], - SupportProtocols::RelayV2 => vec!["2".to_owned()], + SupportProtocols::Time => vec!["1".to_owned(), LASTEST_VERSION.to_owned()], + SupportProtocols::Alert => vec!["1".to_owned(), LASTEST_VERSION.to_owned()], + SupportProtocols::RelayV2 => vec![LASTEST_VERSION.to_owned()], } }