From a5b10d13363973511614a8f739586a0c4ee05446 Mon Sep 17 00:00:00 2001 From: driftluo Date: Fri, 24 Sep 2021 09:06:24 +0800 Subject: [PATCH] fix: fix identify disconnect --- network/src/protocols/identify/mod.rs | 4 +++- network/src/protocols/tests/mod.rs | 10 +++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/network/src/protocols/identify/mod.rs b/network/src/protocols/identify/mod.rs index 6b6f1e2c3a..b568cee408 100644 --- a/network/src/protocols/identify/mod.rs +++ b/network/src/protocols/identify/mod.rs @@ -407,7 +407,9 @@ impl Callback for IdentifyCallback { // it is possible that the node will be accidentally evicted, so it is necessary // to reset the information of the node when disconnected. self.network_state.with_peer_store_mut(|peer_store| { - peer_store.add_outbound_addr(context.session.address.clone()); + if !peer_store.is_addr_banned(&context.session.address) { + peer_store.add_outbound_addr(context.session.address.clone()); + } }); } } diff --git a/network/src/protocols/tests/mod.rs b/network/src/protocols/tests/mod.rs index a816a4f46e..028eaf927c 100644 --- a/network/src/protocols/tests/mod.rs +++ b/network/src/protocols/tests/mod.rs @@ -312,8 +312,16 @@ fn test_identify_behavior() { wait_connect_state(&node1, 1); wait_connect_state(&node2, 0); + if !wait_until(10, || { + node1.network_state.with_peer_store_mut(|peer_store| { + peer_store.is_addr_banned(&node2.listen_addr) + && peer_store.addr_manager().get(&node2.listen_addr).is_none() + }) + }) { + panic!("identify can't ban not same net") + } + let sessions = node3.connected_sessions(); - assert_eq!(sessions.len(), 1); if !wait_until(10, || node3.connected_protocols(sessions[0]).len() == 4) { panic!("identify can't open other protocols")