Updating visilibity little by little
This commit is contained in:
parent
1e478aabac
commit
c6cf9776d1
2 changed files with 17 additions and 11 deletions
|
|
@ -11,7 +11,7 @@ pub enum PeerState {
|
||||||
|
|
||||||
pub struct LivePeerState {
|
pub struct LivePeerState {
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
pub peer_id: [u8; 20],
|
peer_id: [u8; 20],
|
||||||
pub i_am_choked: bool,
|
pub i_am_choked: bool,
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
pub peer_choked: bool,
|
pub peer_choked: bool,
|
||||||
|
|
@ -22,3 +22,18 @@ pub struct LivePeerState {
|
||||||
pub bitfield: Option<BF>,
|
pub bitfield: Option<BF>,
|
||||||
pub inflight_requests: HashSet<InflightRequest>,
|
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(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -364,16 +364,7 @@ impl TorrentState {
|
||||||
let mut g = self.locked.write();
|
let mut g = self.locked.write();
|
||||||
match g.peers.states.get_mut(&handle) {
|
match g.peers.states.get_mut(&handle) {
|
||||||
Some(s @ &mut PeerState::Connecting(_)) => {
|
Some(s @ &mut PeerState::Connecting(_)) => {
|
||||||
*s = PeerState::Live(LivePeerState {
|
*s = PeerState::Live(LivePeerState::new(h.peer_id));
|
||||||
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(),
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
warn!("peer {} was in wrong state", handle);
|
warn!("peer {} was in wrong state", handle);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue