Skip to content

Commit

Permalink
Trigger ping all peers on upgrade to reachable enr
Browse files Browse the repository at this point in the history
  • Loading branch information
emhane committed Jan 15, 2024
1 parent 41f0ef6 commit 6187597
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/handler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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));
}
Expand Down
1 change: 1 addition & 0 deletions src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@ impl Service {
);
}
}
HandlerOut::PingAllPeers => self.ping_connected_peers()
}
}
event = Service::bucket_maintenance_poll(&self.kbuckets) => {
Expand Down

0 comments on commit 6187597

Please sign in to comment.