fix peer_remove & peer_add event handler (#27)

This commit is contained in:
Sijie.Sun 2024-03-06 23:52:56 +08:00 committed by GitHub
parent 278a4846f1
commit 5f30747f62
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 12 additions and 6 deletions

View File

@ -220,8 +220,8 @@ impl ManualConnectorManager {
log::warn!("peer conn removed: {:?}", conn_info);
}
GlobalCtxEvent::PeerAdded(..) => todo!(),
GlobalCtxEvent::PeerRemoved(..) => todo!(),
GlobalCtxEvent::PeerAdded(..) => {}
GlobalCtxEvent::PeerRemoved(..) => {}
}
}

View File

@ -146,8 +146,6 @@ impl Peer {
impl Drop for Peer {
fn drop(&mut self) {
self.shutdown_notifier.notify_one();
self.global_ctx
.issue_event(GlobalCtxEvent::PeerRemoved(self.peer_node_id));
tracing::info!("peer {} drop", self.peer_node_id);
}
}

View File

@ -6,7 +6,10 @@ use tokio::sync::{mpsc, RwLock};
use tokio_util::bytes::Bytes;
use crate::{
common::{error::Error, global_ctx::ArcGlobalCtx},
common::{
error::Error,
global_ctx::{ArcGlobalCtx, GlobalCtxEvent},
},
rpc::PeerConnInfo,
tunnels::TunnelError,
};
@ -31,7 +34,10 @@ impl PeerMap {
}
async fn add_new_peer(&self, peer: Peer) {
self.peer_map.insert(peer.peer_node_id, Arc::new(peer));
let peer_id = peer.peer_node_id.clone();
self.peer_map.insert(peer_id.clone(), Arc::new(peer));
self.global_ctx
.issue_event(GlobalCtxEvent::PeerAdded(peer_id));
}
pub async fn add_new_peer_conn(&self, peer_conn: PeerConn) {
@ -174,6 +180,8 @@ impl PeerMap {
pub async fn close_peer(&self, peer_id: &PeerId) -> Result<(), TunnelError> {
let remove_ret = self.peer_map.remove(peer_id);
self.global_ctx
.issue_event(GlobalCtxEvent::PeerRemoved(peer_id.clone()));
tracing::info!(
?peer_id,
has_old_value = ?remove_ret.is_some(),