Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
3342: chore: add some logs r=quake,zhangsoledad a=driftluo

### What problem does this PR solve?

1. Add logging to abnormal disconnects
2. Align the highest version number of all protocols with a constant

### Check List

Tests

- Unit test
- Integration test

### Release note

```release-note
None: Exclude this PR from the release note.
```



Co-authored-by: driftluo <[email protected]>
  • Loading branch information
bors[bot] and driftluo authored Mar 22, 2022
2 parents 0bc6db8 + d7514fc commit 45a7514
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
5 changes: 5 additions & 0 deletions network/src/protocols/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,13 +247,18 @@ 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
.load(std::sync::atomic::Ordering::SeqCst)
&& 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;
Expand Down
24 changes: 15 additions & 9 deletions network/src/protocols/support_protocols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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()],
}
}

Expand Down

0 comments on commit 45a7514

Please sign in to comment.