diff --git a/crates/librqbit/src/torrent_state/live/mod.rs b/crates/librqbit/src/torrent_state/live/mod.rs index 5cd70ad..13e10a5 100644 --- a/crates/librqbit/src/torrent_state/live/mod.rs +++ b/crates/librqbit/src/torrent_state/live/mod.rs @@ -919,6 +919,17 @@ impl<'a> PeerConnectionHandler for &'a PeerHandler { if let Some(peer_pex_msg_id) = hs.ut_pex() { trace!("peer supports pex at {peer_pex_msg_id}"); } + if let Some(port) = hs.p { + // Lets update outgoing Socket address for incoming connection + if self.incoming { + if let Ok(port) = >::try_into(port) { + let outgoing_addr = SocketAddr::new(self.addr.ip(), port); + self.state.peers.with_peer_mut(self.addr, "update outgoing addr", + |peer| peer.outgoing_address=Some(outgoing_addr)); + } + + } + } Ok(()) } diff --git a/crates/librqbit/src/torrent_state/live/peer/mod.rs b/crates/librqbit/src/torrent_state/live/peer/mod.rs index 9efd6b0..d932f55 100644 --- a/crates/librqbit/src/torrent_state/live/peer/mod.rs +++ b/crates/librqbit/src/torrent_state/live/peer/mod.rs @@ -1,6 +1,7 @@ pub mod stats; use std::collections::HashSet; +use std::net::SocketAddr; use librqbit_core::hash_id::Id20; use librqbit_core::lengths::ChunkInfo; @@ -20,6 +21,7 @@ pub(crate) type PeerTx = UnboundedSender; pub(crate) struct Peer { pub state: PeerStateNoMut, pub stats: stats::atomic::PeerStats, + pub outgoing_address: Option, } impl Peer { @@ -35,6 +37,7 @@ impl Peer { Self { state, stats: Default::default(), + outgoing_address: None, } } }