Allow peers to reconnect
This commit is contained in:
parent
124be19e43
commit
fd17ddc46b
5 changed files with 47 additions and 8 deletions
|
|
@ -135,6 +135,25 @@ impl PeerStateNoMut {
|
|||
None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn incoming_connection(
|
||||
&mut self,
|
||||
peer_id: Id20,
|
||||
tx: PeerTx,
|
||||
counters: &AggregatePeerStatsAtomic,
|
||||
) -> anyhow::Result<()> {
|
||||
if matches!(&self.0, PeerState::Connecting(..) | PeerState::Live(..)) {
|
||||
anyhow::bail!("peer already active");
|
||||
}
|
||||
match self.take(counters) {
|
||||
PeerState::Queued | PeerState::Dead | PeerState::NotNeeded => {
|
||||
self.set(PeerState::Live(LivePeerState::new(peer_id, tx)), counters);
|
||||
}
|
||||
PeerState::Connecting(..) | PeerState::Live(..) => unreachable!(),
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn connecting_to_live(
|
||||
&mut self,
|
||||
peer_id: Id20,
|
||||
|
|
|
|||
|
|
@ -12,8 +12,9 @@ use backoff::{ExponentialBackoff, ExponentialBackoffBuilder};
|
|||
pub(crate) struct PeerCountersAtomic {
|
||||
pub fetched_bytes: AtomicU64,
|
||||
pub total_time_connecting_ms: AtomicU64,
|
||||
pub connection_attempts: AtomicU32,
|
||||
pub connections: AtomicU32,
|
||||
pub incoming_connections: AtomicU32,
|
||||
pub outgoing_connection_attempts: AtomicU32,
|
||||
pub outgoing_connections: AtomicU32,
|
||||
pub errors: AtomicU32,
|
||||
pub fetched_chunks: AtomicU32,
|
||||
pub downloaded_and_checked_pieces: AtomicU32,
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ use crate::torrent_state::live::peer::{Peer, PeerState};
|
|||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct PeerCounters {
|
||||
pub incoming_connections: u32,
|
||||
pub fetched_bytes: u64,
|
||||
pub total_time_connecting_ms: u64,
|
||||
pub connection_attempts: u32,
|
||||
|
|
@ -24,10 +25,13 @@ pub struct PeerStats {
|
|||
impl From<&super::atomic::PeerCountersAtomic> for PeerCounters {
|
||||
fn from(counters: &super::atomic::PeerCountersAtomic) -> Self {
|
||||
Self {
|
||||
incoming_connections: counters.incoming_connections.load(Ordering::Relaxed),
|
||||
fetched_bytes: counters.fetched_bytes.load(Ordering::Relaxed),
|
||||
total_time_connecting_ms: counters.total_time_connecting_ms.load(Ordering::Relaxed),
|
||||
connection_attempts: counters.connection_attempts.load(Ordering::Relaxed),
|
||||
connections: counters.connections.load(Ordering::Relaxed),
|
||||
connection_attempts: counters
|
||||
.outgoing_connection_attempts
|
||||
.load(Ordering::Relaxed),
|
||||
connections: counters.outgoing_connections.load(Ordering::Relaxed),
|
||||
errors: counters.errors.load(Ordering::Relaxed),
|
||||
fetched_chunks: counters.fetched_chunks.load(Ordering::Relaxed),
|
||||
downloaded_and_checked_pieces: counters
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue