Update outgoing address for incoming peers

This commit is contained in:
Ivan 2024-09-25 22:32:38 +02:00
parent 5994d84a14
commit a483bc6586
2 changed files with 14 additions and 0 deletions

View file

@ -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) = <u32 as TryInto<u16>>::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(())
}

View file

@ -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<WriterRequest>;
pub(crate) struct Peer {
pub state: PeerStateNoMut,
pub stats: stats::atomic::PeerStats,
pub outgoing_address: Option<SocketAddr>,
}
impl Peer {
@ -35,6 +37,7 @@ impl Peer {
Self {
state,
stats: Default::default(),
outgoing_address: None,
}
}
}