From ee1e2b436f19e31c06be531e7ef4efd4460c8dd5 Mon Sep 17 00:00:00 2001 From: Christien Rioux Date: Sun, 15 Jun 2025 19:38:20 -0400 Subject: [PATCH] fix sending unpublish event --- .../src/routing_table/routing_table_inner/mod.rs | 2 +- .../routing_domains/local_network/mod.rs | 11 ++++++++++- .../routing_table_inner/routing_domains/mod.rs | 2 +- .../routing_domains/public_internet/mod.rs | 11 ++++++++++- veilid-core/src/routing_table/tasks/ping_validator.rs | 2 +- 5 files changed, 23 insertions(+), 5 deletions(-) diff --git a/veilid-core/src/routing_table/routing_table_inner/mod.rs b/veilid-core/src/routing_table/routing_table_inner/mod.rs index ac516a80..f021672f 100644 --- a/veilid-core/src/routing_table/routing_table_inner/mod.rs +++ b/veilid-core/src/routing_table/routing_table_inner/mod.rs @@ -275,7 +275,7 @@ impl RoutingTableInner { } /// Unpublish the node's current peer info pub fn unpublish_peer_info(&mut self, routing_domain: RoutingDomain) { - self.with_routing_domain(routing_domain, |rdd| rdd.unpublish_peer_info()) + self.with_routing_domain(routing_domain, |rdd| rdd.unpublish_peer_info(self)) } /// Get the current published peer info diff --git a/veilid-core/src/routing_table/routing_table_inner/routing_domains/local_network/mod.rs b/veilid-core/src/routing_table/routing_table_inner/routing_domains/local_network/mod.rs index 375e8ef2..cefe59b8 100644 --- a/veilid-core/src/routing_table/routing_table_inner/routing_domains/local_network/mod.rs +++ b/veilid-core/src/routing_table/routing_table_inner/routing_domains/local_network/mod.rs @@ -191,10 +191,19 @@ impl RoutingDomainDetail for LocalNetworkRoutingDomainDetail { true } - fn unpublish_peer_info(&self) { + fn unpublish_peer_info(&self, rti: &RoutingTableInner) { let mut ppi_lock = self.published_peer_info.lock(); veilid_log!(self debug "[LocalNetwork] Unpublished peer info"); + let opt_old_peer_info = ppi_lock.clone(); *ppi_lock = None; + + if let Err(e) = rti.event_bus().post(PeerInfoChangeEvent { + routing_domain: RoutingDomain::LocalNetwork, + opt_old_peer_info, + opt_new_peer_info: None, + }) { + veilid_log!(self debug "Failed to post event: {}", e); + } } fn ensure_dial_info_is_valid(&self, dial_info: &DialInfo) -> bool { diff --git a/veilid-core/src/routing_table/routing_table_inner/routing_domains/mod.rs b/veilid-core/src/routing_table/routing_table_inner/routing_domains/mod.rs index 99545c5b..d4216fb1 100644 --- a/veilid-core/src/routing_table/routing_table_inner/routing_domains/mod.rs +++ b/veilid-core/src/routing_table/routing_table_inner/routing_domains/mod.rs @@ -40,7 +40,7 @@ pub trait RoutingDomainDetail { // Publish current peer info to the world fn publish_peer_info(&self, rti: &RoutingTableInner) -> bool; - fn unpublish_peer_info(&self); + fn unpublish_peer_info(&self, rti: &RoutingTableInner); // Get the contact method required for node A to reach node B in this routing domain // Routing table must be locked for reading to use this function diff --git a/veilid-core/src/routing_table/routing_table_inner/routing_domains/public_internet/mod.rs b/veilid-core/src/routing_table/routing_table_inner/routing_domains/public_internet/mod.rs index 3fcda45d..756181b9 100644 --- a/veilid-core/src/routing_table/routing_table_inner/routing_domains/public_internet/mod.rs +++ b/veilid-core/src/routing_table/routing_table_inner/routing_domains/public_internet/mod.rs @@ -170,10 +170,19 @@ impl RoutingDomainDetail for PublicInternetRoutingDomainDetail { true } - fn unpublish_peer_info(&self) { + fn unpublish_peer_info(&self, rti: &RoutingTableInner) { let mut ppi_lock = self.published_peer_info.lock(); veilid_log!(self debug "[PublicInternet] Unpublished peer info"); + let opt_old_peer_info = ppi_lock.clone(); *ppi_lock = None; + + if let Err(e) = rti.event_bus().post(PeerInfoChangeEvent { + routing_domain: RoutingDomain::PublicInternet, + opt_old_peer_info, + opt_new_peer_info: None, + }) { + veilid_log!(self debug "Failed to post event: {}", e); + } } fn ensure_dial_info_is_valid(&self, dial_info: &DialInfo) -> bool { diff --git a/veilid-core/src/routing_table/tasks/ping_validator.rs b/veilid-core/src/routing_table/tasks/ping_validator.rs index 4b064c78..7fec338b 100644 --- a/veilid-core/src/routing_table/tasks/ping_validator.rs +++ b/veilid-core/src/routing_table/tasks/ping_validator.rs @@ -347,7 +347,7 @@ impl RoutingTable { let atomic_count = AtomicUsize::new(count); let _ = process_batched_future_queue_result(future_queue, MAX_PARALLEL_PINGS, stop_token, |res| { if let Err(e) = res { - veilid_log!(self error "[{}] Error performing status ping: {}", name, e); + veilid_log!(self debug "[{}] Error performing status ping: {}", name, e); } let remaining = atomic_count.fetch_sub(1, Ordering::AcqRel) - 1; if remaining > 0 {