From 88eb1e795516453044b61f7cb07d496820d6621f Mon Sep 17 00:00:00 2001 From: Fina Wilke Date: Mon, 23 Jan 2023 01:14:30 +0100 Subject: [PATCH] Don't expire mDNS nodes on connection close Fixes #3309 --- protocols/mdns/CHANGELOG.md | 2 ++ protocols/mdns/src/behaviour.rs | 14 +++----------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/protocols/mdns/CHANGELOG.md b/protocols/mdns/CHANGELOG.md index 6eb10041197..e41bfe9b4be 100644 --- a/protocols/mdns/CHANGELOG.md +++ b/protocols/mdns/CHANGELOG.md @@ -6,6 +6,8 @@ - Update to `libp2p-swarm` `v0.42.0`. +- Don't expire mDNS records when the last connection was closed. mDNS records will only be expired when the TTL is reached and the DNS record is no longer valid. + [PR 3153]: https://github.com/libp2p/rust-libp2p/pull/3153 # 0.42.0 diff --git a/protocols/mdns/src/behaviour.rs b/protocols/mdns/src/behaviour.rs index 9c280980e35..0507d9d1f58 100644 --- a/protocols/mdns/src/behaviour.rs +++ b/protocols/mdns/src/behaviour.rs @@ -28,7 +28,7 @@ use crate::Config; use futures::Stream; use if_watch::IfEvent; use libp2p_core::{Multiaddr, PeerId}; -use libp2p_swarm::behaviour::{ConnectionClosed, FromSwarm}; +use libp2p_swarm::behaviour::FromSwarm; use libp2p_swarm::{ dummy, ConnectionHandler, ListenAddresses, NetworkBehaviour, NetworkBehaviourAction, PollParameters, @@ -199,22 +199,14 @@ where self.listen_addresses.on_swarm_event(&event); match event { - FromSwarm::ConnectionClosed(ConnectionClosed { - peer_id, - remaining_established, - .. - }) => { - if remaining_established == 0 { - self.expire_node(&peer_id); - } - } FromSwarm::NewListener(_) => { log::trace!("waking interface state because listening address changed"); for iface in self.iface_states.values_mut() { iface.fire_timer(); } } - FromSwarm::ConnectionEstablished(_) + FromSwarm::ConnectionClosed(_) + | FromSwarm::ConnectionEstablished(_) | FromSwarm::DialFailure(_) | FromSwarm::AddressChange(_) | FromSwarm::ListenFailure(_)