mirror of
https://github.com/EasyTier/EasyTier.git
synced 2024-11-16 03:32:43 +08:00
fix peer_remove & peer_add event handler (#27)
This commit is contained in:
parent
278a4846f1
commit
5f30747f62
|
@ -220,8 +220,8 @@ impl ManualConnectorManager {
|
|||
log::warn!("peer conn removed: {:?}", conn_info);
|
||||
}
|
||||
|
||||
GlobalCtxEvent::PeerAdded(..) => todo!(),
|
||||
GlobalCtxEvent::PeerRemoved(..) => todo!(),
|
||||
GlobalCtxEvent::PeerAdded(..) => {}
|
||||
GlobalCtxEvent::PeerRemoved(..) => {}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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(),
|
||||
|
|
Loading…
Reference in New Issue
Block a user