diff --git a/crates/librqbit/src/peer_state.rs b/crates/librqbit/src/peer_state.rs index 79e1265..492e8bc 100644 --- a/crates/librqbit/src/peer_state.rs +++ b/crates/librqbit/src/peer_state.rs @@ -11,7 +11,7 @@ pub enum PeerState { pub struct LivePeerState { #[allow(unused)] - pub peer_id: [u8; 20], + peer_id: [u8; 20], pub i_am_choked: bool, #[allow(unused)] pub peer_choked: bool, @@ -22,3 +22,18 @@ pub struct LivePeerState { pub bitfield: Option, pub inflight_requests: HashSet, } + +impl LivePeerState { + pub fn new(peer_id: [u8; 20]) -> Self { + LivePeerState { + peer_id: peer_id, + i_am_choked: true, + peer_choked: true, + peer_interested: false, + bitfield: None, + have_notify: Arc::new(Notify::new()), + outstanding_requests: Arc::new(Semaphore::new(0)), + inflight_requests: Default::default(), + } + } +} diff --git a/crates/librqbit/src/torrent_state.rs b/crates/librqbit/src/torrent_state.rs index 0d21e91..12a3b3f 100644 --- a/crates/librqbit/src/torrent_state.rs +++ b/crates/librqbit/src/torrent_state.rs @@ -364,16 +364,7 @@ impl TorrentState { let mut g = self.locked.write(); match g.peers.states.get_mut(&handle) { Some(s @ &mut PeerState::Connecting(_)) => { - *s = PeerState::Live(LivePeerState { - peer_id: h.peer_id, - i_am_choked: true, - peer_choked: true, - peer_interested: false, - bitfield: None, - have_notify: Arc::new(Notify::new()), - outstanding_requests: Arc::new(Semaphore::new(0)), - inflight_requests: Default::default(), - }); + *s = PeerState::Live(LivePeerState::new(h.peer_id)); } _ => { warn!("peer {} was in wrong state", handle);