diff --git a/src/handler/mod.rs b/src/handler/mod.rs index 6c0a859a1..d5ac1131c 100644 --- a/src/handler/mod.rs +++ b/src/handler/mod.rs @@ -117,8 +117,8 @@ pub enum HandlerIn { /// [`Notification::RelayMsg`] we intend to relay to that peer. HolePunchEnr(Enr, Notification), - /// Observed socket has been update. The old socket and the current socket. - SocketUpdate(Option, SocketAddr), + /// Observed socket has been update, contains the current socket. + SocketUpdate(SocketAddr), } /// Messages sent between a node on the network and `Handler`. @@ -377,19 +377,15 @@ impl Handler { warn!("Failed to relay. Error: {}", e); } } - HandlerIn::SocketUpdate(old_socket, socket) => { + HandlerIn::SocketUpdate(socket) => { let ip = socket.ip(); let port = socket.port(); - if old_socket.is_none() { - // This node goes from being unreachable to being reachable. Remove - // its sessions to trigger a WHOAREYOU from peers on next sent - // message. If the peer is running this implementation of - // discovery, this makes it possible for the local node to be - // 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() - } + // This node goes from being unreachable to being reachable. + // Reasonably assuming all its peers are indexing sessions based on + // `node_id`, like this implementation, the first message sent in each + // session from here on will trigger a WHOAREYOU message from the peer + // (since the peer won't be able to find the decryption key for the + // session with the new node id as message's src id). 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 17258be7e..ea72e5339 100644 --- a/src/service.rs +++ b/src/service.rs @@ -855,11 +855,9 @@ impl Service { new_ip6, )); // Notify Handler of socket update - if let Err(e) = - self.handler_send.send(HandlerIn::SocketUpdate( - local_ip6_socket.map(SocketAddr::V6), - new_ip6, - )) + if let Err(e) = self + .handler_send + .send(HandlerIn::SocketUpdate(new_ip6)) { warn!("Failed to send socket update to handler: {}", e); }; @@ -883,11 +881,9 @@ impl Service { new_ip4, )); // Notify Handler of socket update - if let Err(e) = - self.handler_send.send(HandlerIn::SocketUpdate( - local_ip4_socket.map(SocketAddr::V4), - new_ip4, - )) + if let Err(e) = self + .handler_send + .send(HandlerIn::SocketUpdate(new_ip4)) { warn!("Failed to send socket update {}", e); };