From 46c15a4a2bccca2f8616d78fd5a9ecf223bf404d Mon Sep 17 00:00:00 2001 From: Niko PLP Date: Wed, 22 May 2024 01:59:24 +0300 Subject: [PATCH] fix reconnecting with same peer ID --- ng-net/src/broker.rs | 2 +- ng-net/src/connection.rs | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/ng-net/src/broker.rs b/ng-net/src/broker.rs index 2bc65b0..6a3e2d9 100644 --- a/ng-net/src/broker.rs +++ b/ng-net/src/broker.rs @@ -767,7 +767,7 @@ impl Broker { match already.unwrap().connected { PeerConnection::NONE => {} PeerConnection::Client(mut cnx) => { - cnx.close().await; + cnx.close_silently().await; } _ => {} }; diff --git a/ng-net/src/connection.rs b/ng-net/src/connection.rs index 48a3b1e..820fb00 100644 --- a/ng-net/src/connection.rs +++ b/ng-net/src/connection.rs @@ -1319,6 +1319,17 @@ impl ConnectionBase { self.send(ConnectionCommand::Close).await; } + pub async fn close_silently(&mut self) { + log_debug!("closing silently..."); + let _ = self + .shutdown_sender + .take() + .unwrap() + .send(Either::Left(NetError::Closing)) + .await; + self.send(ConnectionCommand::Close).await; + } + pub async fn admin< A: Into + Into