From 993aa5622ce65e9d89fd54d4981f1db8ea52cfc5 Mon Sep 17 00:00:00 2001 From: Niko PLP Date: Wed, 22 May 2024 01:25:22 +0300 Subject: [PATCH] allow reconecting with same peer ID (in case cnx wasnt closed properly) --- ng-net/src/broker.rs | 9 +++++---- ng-repo/src/branch.rs | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/ng-net/src/broker.rs b/ng-net/src/broker.rs index e24bc91..2bc65b0 100644 --- a/ng-net/src/broker.rs +++ b/ng-net/src/broker.rs @@ -680,7 +680,7 @@ impl Broker { .or_insert(HashSet::with_capacity(1)); if !peers_set.insert(peer) { - return Err(ProtocolError::PeerAlreadyConnected); + //return Err(ProtocolError::PeerAlreadyConnected); } Ok(()) } @@ -762,13 +762,14 @@ impl Broker { ) -> Result<(), ProtocolError> { log_debug!("ATTACH PEER_ID {:?}", remote_peer_id); - let already = self.peers.get(&(None, Some(remote_peer_id))); + let already = self.peers.remove(&(None, Some(remote_peer_id))); if already.is_some() { match already.unwrap().connected { PeerConnection::NONE => {} - _ => { - return Err(ProtocolError::PeerAlreadyConnected); + PeerConnection::Client(mut cnx) => { + cnx.close().await; } + _ => {} }; } diff --git a/ng-repo/src/branch.rs b/ng-repo/src/branch.rs index cd9f1bc..cc44220 100644 --- a/ng-repo/src/branch.rs +++ b/ng-repo/src/branch.rs @@ -103,7 +103,7 @@ impl DagNode { let mut res = vec![*id]; already_in.insert(*id); for child in this.future.iter() { - log_debug!("child of {} : {}", id, child); + // log_debug!("child of {} : {}", id, child); res.append(&mut Self::collapse(child, dag, dag_ids, already_in)); } res