Updating visilibity little by little

This commit is contained in:
Igor Katson 2021-06-28 14:42:19 +01:00
parent 1e478aabac
commit c6cf9776d1
2 changed files with 17 additions and 11 deletions

View file

@ -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<BF>,
pub inflight_requests: HashSet<InflightRequest>,
}
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(),
}
}
}

View file

@ -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);