From b901215b8a0aa37eedd80dfc8c332aedabfaa675 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jo=C3=A3o=20Oliveira?= <hello@jxs.pt>
Date: Mon, 8 Jan 2024 11:38:16 +0000
Subject: [PATCH] add PeerId to ListenFailure

---
 swarm/CHANGELOG.md     | 2 ++
 swarm/src/behaviour.rs | 3 ++-
 swarm/src/lib.rs       | 3 +++
 3 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/swarm/CHANGELOG.md b/swarm/CHANGELOG.md
index 65dce4b002a..26022508d49 100644
--- a/swarm/CHANGELOG.md
+++ b/swarm/CHANGELOG.md
@@ -1,5 +1,7 @@
 ## 0.44.1
 
+- Add `PeerId` to `ListenFailure`
+
 - Implement `Clone` & `Copy` for `FromSwarm.
   This makes it easier to forward these events when wrapping other behaviours.
   See [PR 4825](https://github.com/libp2p/rust-libp2p/pull/4825).
diff --git a/swarm/src/behaviour.rs b/swarm/src/behaviour.rs
index 4be129a4eea..d3f3b491950 100644
--- a/swarm/src/behaviour.rs
+++ b/swarm/src/behaviour.rs
@@ -267,7 +267,7 @@ pub enum ToSwarm<TOutEvent, TInEvent> {
     /// The emphasis on a **new** candidate is important.
     /// Protocols MUST take care to only emit a candidate once per "source".
     /// For example, the observed address of a TCP connection does not change throughout its lifetime.
-    /// Thus, only one candidate should be emitted per connection.    
+    /// Thus, only one candidate should be emitted per connection.
     ///
     /// This makes the report frequency of an address a meaningful data-point for consumers of this event.
     /// This address will be shared with all [`NetworkBehaviour`]s via [`FromSwarm::NewExternalAddrCandidate`].
@@ -487,6 +487,7 @@ pub struct ListenFailure<'a> {
     pub send_back_addr: &'a Multiaddr,
     pub error: &'a ListenError,
     pub connection_id: ConnectionId,
+    pub peer_id: Option<PeerId>,
 }
 
 /// [`FromSwarm`] variant that informs the behaviour that a new listener was created.
diff --git a/swarm/src/lib.rs b/swarm/src/lib.rs
index 0354f39cfdc..d673e41170e 100644
--- a/swarm/src/lib.rs
+++ b/swarm/src/lib.rs
@@ -741,6 +741,7 @@ where
                                         send_back_addr: &send_back_addr,
                                         error: &listen_error,
                                         connection_id: id,
+                                        peer_id: Some(peer_id),
                                     },
                                 ));
 
@@ -854,6 +855,7 @@ where
                         send_back_addr: &send_back_addr,
                         error: &error,
                         connection_id: id,
+                        peer_id: None,
                     }));
                 self.pending_swarm_events
                     .push_back(SwarmEvent::IncomingConnectionError {
@@ -957,6 +959,7 @@ where
                                 send_back_addr: &send_back_addr,
                                 error: &listen_error,
                                 connection_id,
+                                peer_id: None,
                             }));
 
                         self.pending_swarm_events