Nothing
This commit is contained in:
parent
5a075c8ef3
commit
5f8100ebad
3 changed files with 17 additions and 34 deletions
|
|
@ -405,7 +405,7 @@ impl PeerConnection {
|
||||||
None => return Ok(()),
|
None => return Ok(()),
|
||||||
};
|
};
|
||||||
let sem = match self.state.locked.read().peers.get_live(handle) {
|
let sem = match self.state.locked.read().peers.get_live(handle) {
|
||||||
Some(live) => live.outstanding_requests.clone(),
|
Some(live) => live.requests_sem.clone(),
|
||||||
None => return Ok(()),
|
None => return Ok(()),
|
||||||
};
|
};
|
||||||
for chunk in self.state.lengths.iter_chunk_infos(next) {
|
for chunk in self.state.lengths.iter_chunk_infos(next) {
|
||||||
|
|
@ -451,7 +451,7 @@ impl PeerConnection {
|
||||||
};
|
};
|
||||||
live.i_am_choked = false;
|
live.i_am_choked = false;
|
||||||
live.have_notify.notify_waiters();
|
live.have_notify.notify_waiters();
|
||||||
live.outstanding_requests.add_permits(16);
|
live.requests_sem.add_permits(16);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_received_piece(
|
fn on_received_piece(
|
||||||
|
|
@ -472,7 +472,7 @@ impl PeerConnection {
|
||||||
|
|
||||||
let mut g = self.state.locked.write();
|
let mut g = self.state.locked.write();
|
||||||
let h = g.peers.try_get_live_mut(handle)?;
|
let h = g.peers.try_get_live_mut(handle)?;
|
||||||
h.outstanding_requests.add_permits(1);
|
h.requests_sem.add_permits(1);
|
||||||
|
|
||||||
self.state
|
self.state
|
||||||
.stats
|
.stats
|
||||||
|
|
|
||||||
|
|
@ -12,9 +12,8 @@ pub enum PeerState {
|
||||||
pub struct LivePeerState {
|
pub struct LivePeerState {
|
||||||
pub peer_id: [u8; 20],
|
pub peer_id: [u8; 20],
|
||||||
pub i_am_choked: bool,
|
pub i_am_choked: bool,
|
||||||
pub peer_choked: bool,
|
|
||||||
pub peer_interested: bool,
|
pub peer_interested: bool,
|
||||||
pub outstanding_requests: Arc<Semaphore>,
|
pub requests_sem: Arc<Semaphore>,
|
||||||
pub have_notify: Arc<Notify>,
|
pub have_notify: Arc<Notify>,
|
||||||
pub bitfield: Option<BF>,
|
pub bitfield: Option<BF>,
|
||||||
pub inflight_requests: HashSet<InflightRequest>,
|
pub inflight_requests: HashSet<InflightRequest>,
|
||||||
|
|
@ -25,11 +24,10 @@ impl LivePeerState {
|
||||||
LivePeerState {
|
LivePeerState {
|
||||||
peer_id: peer_id,
|
peer_id: peer_id,
|
||||||
i_am_choked: true,
|
i_am_choked: true,
|
||||||
peer_choked: true,
|
|
||||||
peer_interested: false,
|
peer_interested: false,
|
||||||
bitfield: None,
|
bitfield: None,
|
||||||
have_notify: Arc::new(Notify::new()),
|
have_notify: Arc::new(Notify::new()),
|
||||||
outstanding_requests: Arc::new(Semaphore::new(0)),
|
requests_sem: Arc::new(Semaphore::new(0)),
|
||||||
inflight_requests: Default::default(),
|
inflight_requests: Default::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -114,29 +114,21 @@ impl PeerStates {
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
pub fn mark_i_am_choked(&mut self, handle: PeerHandle, is_choked: bool) -> Option<bool> {
|
pub fn mark_i_am_choked(&mut self, handle: PeerHandle, is_choked: bool) -> Option<bool> {
|
||||||
match self.states.get_mut(&handle) {
|
let live = self.get_live_mut(handle)?;
|
||||||
Some(PeerState::Live(live)) => {
|
let prev = live.i_am_choked;
|
||||||
let prev = live.i_am_choked;
|
live.i_am_choked = is_choked;
|
||||||
live.i_am_choked = is_choked;
|
Some(prev)
|
||||||
return Some(prev);
|
|
||||||
}
|
|
||||||
_ => return None,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
pub fn update_bitfield_from_vec(
|
pub fn update_bitfield_from_vec(
|
||||||
&mut self,
|
&mut self,
|
||||||
handle: PeerHandle,
|
handle: PeerHandle,
|
||||||
bitfield: Vec<u8>,
|
bitfield: Vec<u8>,
|
||||||
) -> Option<Option<BF>> {
|
) -> Option<Option<BF>> {
|
||||||
match self.states.get_mut(&handle) {
|
let live = self.get_live_mut(handle)?;
|
||||||
Some(PeerState::Live(live)) => {
|
let bitfield = BF::from_vec(bitfield);
|
||||||
let bitfield = BF::from_vec(bitfield);
|
let prev = live.bitfield.take();
|
||||||
let prev = live.bitfield.take();
|
live.bitfield = Some(bitfield);
|
||||||
live.bitfield = Some(bitfield);
|
Some(prev)
|
||||||
Some(prev)
|
|
||||||
}
|
|
||||||
_ => None,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
pub fn clone_tx(&self, handle: PeerHandle) -> Option<Arc<Sender<MessageOwned>>> {
|
pub fn clone_tx(&self, handle: PeerHandle) -> Option<Arc<Sender<MessageOwned>>> {
|
||||||
Some(self.tx.get(&handle)?.clone())
|
Some(self.tx.get(&handle)?.clone())
|
||||||
|
|
@ -223,10 +215,7 @@ impl TorrentState {
|
||||||
|
|
||||||
pub fn get_next_needed_piece(&self, peer_handle: PeerHandle) -> Option<ValidPieceIndex> {
|
pub fn get_next_needed_piece(&self, peer_handle: PeerHandle) -> Option<ValidPieceIndex> {
|
||||||
let g = self.locked.read();
|
let g = self.locked.read();
|
||||||
let bf = match g.peers.states.get(&peer_handle)? {
|
let bf = g.peers.get_live(peer_handle)?.bitfield.as_ref()?;
|
||||||
PeerState::Live(l) => l.bitfield.as_ref()?,
|
|
||||||
_ => return None,
|
|
||||||
};
|
|
||||||
for n in g.chunks.get_needed_pieces().iter_ones() {
|
for n in g.chunks.get_needed_pieces().iter_ones() {
|
||||||
if bf.get(n).map(|v| *v) == Some(true) {
|
if bf.get(n).map(|v| *v) == Some(true) {
|
||||||
// in theory it should be safe without validation, but whatever.
|
// in theory it should be safe without validation, but whatever.
|
||||||
|
|
@ -240,12 +229,8 @@ impl TorrentState {
|
||||||
self.locked
|
self.locked
|
||||||
.read()
|
.read()
|
||||||
.peers
|
.peers
|
||||||
.states
|
.get_live(peer_handle)
|
||||||
.get(&peer_handle)
|
.map(|l| l.i_am_choked)
|
||||||
.and_then(|s| match s {
|
|
||||||
PeerState::Live(l) => Some(l.i_am_choked),
|
|
||||||
_ => None,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn reserve_next_needed_piece(&self, peer_handle: PeerHandle) -> Option<ValidPieceIndex> {
|
pub fn reserve_next_needed_piece(&self, peer_handle: PeerHandle) -> Option<ValidPieceIndex> {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue