From 61875972eeeb858b3c20a18032ada604d46fd9ee Mon Sep 17 00:00:00 2001 From: Emilia Hane Date: Mon, 15 Jan 2024 04:31:10 +0100 Subject: [PATCH] Trigger ping all peers on upgrade to reachable enr --- src/handler/mod.rs | 18 +++++++++++++++++- src/service.rs | 1 + 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/handler/mod.rs b/src/handler/mod.rs index 6c9f1e713..bcdf97042 100644 --- a/src/handler/mod.rs +++ b/src/handler/mod.rs @@ -150,6 +150,15 @@ pub enum HandlerOut { /// Look-up an ENR in k-buckets. Passes the node id of the peer to look up and the /// [`RelayMsgNotification`] we intend to send to it. FindHolePunchEnr(RelayInitNotification), + + /// Triggers a ping to all peers, outside of the regular ping interval. Needed to trigger + /// renewed session establishment after updating the local ENR from unreachable to reachable + /// and clearing all sessions. Only this way does the local node have a chance to make it into + /// its peers kbuckets before the session expires (defaults to 24 hours). This is the case + /// since its peers, running this implementation, will only respond to PINGs from nodes in its + /// kbucktes and unreachable ENRs don't make it into kbuckets upon [`HandlerOut::Established`] + /// event. + PingAllPeers, } /// How we connected to the node. @@ -393,7 +402,14 @@ impl Handler { // inserted into its peers' kbuckets before the session they // already had expires. Session duration, in this impl defaults to // 24 hours. - self.sessions.cache.clear() + self.sessions.cache.clear(); + if let Err(e) = self + .service_send + .send(HandlerOut::PingAllPeers) + .await + { + warn!("Failed to inform that request failed {}", e); + } } self.nat_hole_puncher.set_is_behind_nat(self.listen_sockets.iter(), Some(ip), Some(port)); } diff --git a/src/service.rs b/src/service.rs index 1bb246442..783d175ca 100644 --- a/src/service.rs +++ b/src/service.rs @@ -451,6 +451,7 @@ impl Service { ); } } + HandlerOut::PingAllPeers => self.ping_connected_peers() } } event = Service::bucket_maintenance_poll(&self.kbuckets) => {