Queuing only peers that will be retried
This commit is contained in:
parent
a31e8344b2
commit
cd7349121c
2 changed files with 41 additions and 12 deletions
|
|
@ -784,18 +784,17 @@ impl TorrentStateLive {
|
|||
}
|
||||
|
||||
pub(crate) fn reconnect_all_not_needed_peers(&self) {
|
||||
for mut pe in self.peers.states.iter_mut() {
|
||||
if pe.state.not_needed_to_queued(&self.peer_stats()) {
|
||||
let retry_addr = match pe.value().outgoing_address {
|
||||
peer::OutgoingAddressType::Default => *pe.key(),
|
||||
peer::OutgoingAddressType::None => continue,
|
||||
peer::OutgoingAddressType::Known(socket_addr) => socket_addr,
|
||||
};
|
||||
if self.peer_queue_tx.send(retry_addr).is_err() {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
self.peers
|
||||
.states
|
||||
.iter_mut()
|
||||
.filter_map(|mut p| {
|
||||
let known_addr = *p.key();
|
||||
p.value_mut()
|
||||
.reconnect_not_needed_peer(known_addr, &self.peer_stats())
|
||||
})
|
||||
.map(|socket_addr| self.peer_queue_tx.send(socket_addr))
|
||||
.take_while(|r| r.is_ok())
|
||||
.last();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -48,6 +48,36 @@ impl Peer {
|
|||
outgoing_address: OutgoingAddressType::None,
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn reconnect_not_needed_peer(
|
||||
&mut self,
|
||||
known_address: SocketAddr,
|
||||
counters: &[&AggregatePeerStatsAtomic],
|
||||
) -> Option<SocketAddr> {
|
||||
if let PeerState::NotNeeded = self.state.get() {
|
||||
match self.outgoing_address {
|
||||
OutgoingAddressType::Default => {
|
||||
self.state.set(PeerState::Queued, counters);
|
||||
Some(known_address)
|
||||
}
|
||||
OutgoingAddressType::None => None,
|
||||
OutgoingAddressType::Known(socket_addr) => {
|
||||
if known_address == socket_addr {
|
||||
self.state.set(PeerState::Queued, counters);
|
||||
}
|
||||
Some(socket_addr)
|
||||
},
|
||||
}
|
||||
} else {
|
||||
None
|
||||
}
|
||||
// pe.state.not_needed_to_queued(&self.peer_stats()) {
|
||||
// let retry_addr = match pe.value().outgoing_address {
|
||||
// peer::OutgoingAddressType::Default => *pe.key(),
|
||||
// peer::OutgoingAddressType::None => unreachable!("bug"), // already filtered
|
||||
// peer::OutgoingAddressType::Known(socket_addr) => socket_addr,
|
||||
// };
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue