diff --git a/crates/librqbit/src/torrent_state/live/mod.rs b/crates/librqbit/src/torrent_state/live/mod.rs index 0712cb3..eec629f 100644 --- a/crates/librqbit/src/torrent_state/live/mod.rs +++ b/crates/librqbit/src/torrent_state/live/mod.rs @@ -381,6 +381,7 @@ impl TorrentStateLive { Entry::Vacant(vac) => { atomic_inc(&self.peers.stats.seen); let peer = Peer::new_live_for_incoming_connection( + *vac.key(), Id20::new(checked_peer.handshake.peer_id), tx.clone(), &self.peers, diff --git a/crates/librqbit/src/torrent_state/live/peer/mod.rs b/crates/librqbit/src/torrent_state/live/peer/mod.rs index 94e4daf..e173b96 100644 --- a/crates/librqbit/src/torrent_state/live/peer/mod.rs +++ b/crates/librqbit/src/torrent_state/live/peer/mod.rs @@ -18,8 +18,9 @@ pub(crate) type InflightRequest = ChunkInfo; pub(crate) type PeerRx = UnboundedReceiver; pub(crate) type PeerTx = UnboundedSender; -#[derive(Debug, Default)] +#[derive(Debug)] pub(crate) struct Peer { + pub addr: SocketAddr, pub state: PeerStateNoMut, pub stats: stats::atomic::PeerStats, pub outgoing_address: Option, @@ -27,6 +28,7 @@ pub(crate) struct Peer { impl Peer { pub fn new_live_for_incoming_connection( + addr: SocketAddr, peer_id: Id20, tx: PeerTx, counters: &PeerStates, @@ -36,6 +38,7 @@ impl Peer { counter.inc(&state.0); } Self { + addr, state, stats: Default::default(), outgoing_address: None, @@ -44,8 +47,10 @@ impl Peer { pub fn new_with_outgoing_address(addr: SocketAddr) -> Self { Self { + addr, outgoing_address: Some(addr), - ..Default::default() + stats: Default::default(), + state: Default::default(), } }