diff --git a/core/src/connection/listeners.rs b/core/src/connection/listeners.rs index c703095dbb4..46e3824112d 100644 --- a/core/src/connection/listeners.rs +++ b/core/src/connection/listeners.rs @@ -148,6 +148,8 @@ where Closed { /// The ID of the listener that closed. listener_id: ListenerId, + /// The addresses that the listener was listening on. + addresses: SmallVec<[Multiaddr; 4]>, /// Reason for the closure. Contains `Ok(())` if the stream produced `None`, or `Err` /// if the stream produced an error. reason: Result<(), TTrans::Error>, @@ -283,12 +285,14 @@ where Poll::Ready(None) => { return Poll::Ready(ListenersEvent::Closed { listener_id: *listener_project.id, + addresses: listener.addresses.clone(), reason: Ok(()), }) } Poll::Ready(Some(Err(err))) => { return Poll::Ready(ListenersEvent::Closed { listener_id: *listener_project.id, + addresses: listener.addresses.clone(), reason: Err(err), }) } @@ -351,9 +355,10 @@ where .field("listener_id", listener_id) .field("local_addr", local_addr) .finish(), - ListenersEvent::Closed { listener_id, reason } => f + ListenersEvent::Closed { listener_id, addresses, reason } => f .debug_struct("ListenersEvent::Closed") .field("listener_id", listener_id) + .field("addresses", addresses) .field("reason", reason) .finish(), ListenersEvent::Error { listener_id, error } => f diff --git a/core/src/network.rs b/core/src/network.rs index 49911505d75..d2d786b8bbf 100644 --- a/core/src/network.rs +++ b/core/src/network.rs @@ -357,8 +357,8 @@ where Poll::Ready(ListenersEvent::AddressExpired { listener_id, listen_addr }) => { return Poll::Ready(NetworkEvent::ExpiredListenerAddress { listener_id, listen_addr }) } - Poll::Ready(ListenersEvent::Closed { listener_id, reason }) => { - return Poll::Ready(NetworkEvent::ListenerClosed { listener_id, reason }) + Poll::Ready(ListenersEvent::Closed { listener_id, addresses, reason }) => { + return Poll::Ready(NetworkEvent::ListenerClosed { listener_id, addresses, reason }) } Poll::Ready(ListenersEvent::Error { listener_id, error }) => { return Poll::Ready(NetworkEvent::ListenerError { listener_id, error }) diff --git a/core/src/network/event.rs b/core/src/network/event.rs index ef28fd0a37d..f91ba5cb8f0 100644 --- a/core/src/network/event.rs +++ b/core/src/network/event.rs @@ -44,6 +44,7 @@ use crate::{ }; use futures::prelude::*; use std::{error, fmt, hash::Hash}; +use smallvec::SmallVec; /// Event that can happen on the `Network`. pub enum NetworkEvent<'a, TTrans, TInEvent, TOutEvent, THandler, TConnInfo, TPeerId> @@ -55,6 +56,8 @@ where ListenerClosed { /// The listener ID that closed. listener_id: ListenerId, + /// The addresses that the listener was listening on. + addresses: SmallVec<[Multiaddr; 4]>, /// Reason for the closure. Contains `Ok(())` if the stream produced `None`, or `Err` /// if the stream produced an error. reason: Result<(), TTrans::Error>, @@ -183,9 +186,10 @@ where .field("listen_addr", listen_addr) .finish() } - NetworkEvent::ListenerClosed { listener_id, reason } => { + NetworkEvent::ListenerClosed { listener_id, addresses, reason } => { f.debug_struct("ListenerClosed") .field("listener_id", listener_id) + .field("addresses", addresses) .field("reason", reason) .finish() } diff --git a/swarm/src/lib.rs b/swarm/src/lib.rs index 01bffcce074..4cc21d4668a 100644 --- a/swarm/src/lib.rs +++ b/swarm/src/lib.rs @@ -445,9 +445,12 @@ where TBehaviour: NetworkBehaviour, this.behaviour.inject_expired_listen_addr(&listen_addr); return Poll::Ready(SwarmEvent::ExpiredListenAddr(listen_addr)); } - Poll::Ready(NetworkEvent::ListenerClosed { listener_id, reason }) => { + Poll::Ready(NetworkEvent::ListenerClosed { listener_id, addresses, reason }) => { log::debug!("Listener {:?}; Closed by {:?}.", listener_id, reason); this.behaviour.inject_listener_closed(listener_id); + for addr in addresses.iter() { + this.behaviour.inject_expired_listen_addr(addr); + } } Poll::Ready(NetworkEvent::ListenerError { listener_id, error }) => this.behaviour.inject_listener_error(listener_id, &error),