Downgrade visibility within librqbit
This commit is contained in:
parent
84766f92fb
commit
f45a15c89a
9 changed files with 44 additions and 72 deletions
|
|
@ -15,7 +15,7 @@ use crate::type_aliases::BF;
|
|||
use super::peers::stats::atomic::AggregatePeerStatsAtomic;
|
||||
|
||||
#[derive(Debug, Hash, PartialEq, Eq)]
|
||||
pub struct InflightRequest {
|
||||
pub(crate) struct InflightRequest {
|
||||
pub piece: ValidPieceIndex,
|
||||
pub chunk: u32,
|
||||
}
|
||||
|
|
@ -30,8 +30,8 @@ impl From<&ChunkInfo> for InflightRequest {
|
|||
}
|
||||
|
||||
// TODO: Arc can be removed probably, as UnboundedSender should be clone + it can be downgraded to weak.
|
||||
pub type PeerRx = UnboundedReceiver<WriterRequest>;
|
||||
pub type PeerTx = UnboundedSender<WriterRequest>;
|
||||
pub(crate) type PeerRx = UnboundedReceiver<WriterRequest>;
|
||||
pub(crate) type PeerTx = UnboundedSender<WriterRequest>;
|
||||
|
||||
pub trait SendMany {
|
||||
fn send_many(&self, requests: impl IntoIterator<Item = WriterRequest>) -> anyhow::Result<()>;
|
||||
|
|
@ -47,13 +47,13 @@ impl SendMany for PeerTx {
|
|||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct Peer {
|
||||
pub(crate) struct Peer {
|
||||
pub state: PeerStateNoMut,
|
||||
pub stats: stats::atomic::PeerStats,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub enum PeerState {
|
||||
pub(crate) enum PeerState {
|
||||
#[default]
|
||||
// Will be tried to be connected as soon as possible.
|
||||
Queued,
|
||||
|
|
@ -93,7 +93,7 @@ impl PeerState {
|
|||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct PeerStateNoMut(PeerState);
|
||||
pub(crate) struct PeerStateNoMut(PeerState);
|
||||
|
||||
impl PeerStateNoMut {
|
||||
pub fn get(&self) -> &PeerState {
|
||||
|
|
@ -109,13 +109,6 @@ impl PeerStateNoMut {
|
|||
std::mem::replace(&mut self.0, new)
|
||||
}
|
||||
|
||||
pub fn get_live(&self) -> Option<&LivePeerState> {
|
||||
match &self.0 {
|
||||
PeerState::Live(l) => Some(l),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_live_mut(&mut self) -> Option<&mut LivePeerState> {
|
||||
match &mut self.0 {
|
||||
PeerState::Live(l) => Some(l),
|
||||
|
|
@ -153,18 +146,16 @@ impl PeerStateNoMut {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn to_dead(&mut self, counters: &AggregatePeerStatsAtomic) -> PeerState {
|
||||
self.set(PeerState::Dead, counters)
|
||||
}
|
||||
|
||||
pub fn to_not_needed(&mut self, counters: &AggregatePeerStatsAtomic) -> PeerState {
|
||||
pub fn set_not_needed(&mut self, counters: &AggregatePeerStatsAtomic) -> PeerState {
|
||||
self.set(PeerState::NotNeeded, counters)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct LivePeerState {
|
||||
pub peer_id: Id20,
|
||||
pub(crate) struct LivePeerState {
|
||||
#[allow(dead_code)]
|
||||
peer_id: Id20,
|
||||
|
||||
pub peer_interested: bool,
|
||||
|
||||
// This is used to track the pieces the peer has.
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ use std::{
|
|||
use backoff::{ExponentialBackoff, ExponentialBackoffBuilder};
|
||||
|
||||
#[derive(Default, Debug)]
|
||||
pub struct PeerCounters {
|
||||
pub(crate) struct PeerCountersAtomic {
|
||||
pub fetched_bytes: AtomicU64,
|
||||
pub total_time_connecting_ms: AtomicU64,
|
||||
pub connection_attempts: AtomicU32,
|
||||
|
|
@ -21,8 +21,8 @@ pub struct PeerCounters {
|
|||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct PeerStats {
|
||||
pub counters: Arc<PeerCounters>,
|
||||
pub(crate) struct PeerStats {
|
||||
pub counters: Arc<PeerCountersAtomic>,
|
||||
pub backoff: ExponentialBackoff,
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,8 +21,8 @@ pub struct PeerStats {
|
|||
pub state: &'static str,
|
||||
}
|
||||
|
||||
impl From<&super::atomic::PeerCounters> for PeerCounters {
|
||||
fn from(counters: &super::atomic::PeerCounters) -> Self {
|
||||
impl From<&super::atomic::PeerCountersAtomic> for PeerCounters {
|
||||
fn from(counters: &super::atomic::PeerCountersAtomic) -> Self {
|
||||
Self {
|
||||
fetched_bytes: counters.fetched_bytes.load(Ordering::Relaxed),
|
||||
total_time_connecting_ms: counters.total_time_connecting_ms.load(Ordering::Relaxed),
|
||||
|
|
@ -59,12 +59,8 @@ pub enum PeerStatsFilterState {
|
|||
}
|
||||
|
||||
impl PeerStatsFilterState {
|
||||
pub fn matches(&self, s: &PeerState) -> bool {
|
||||
match (self, s) {
|
||||
(Self::All, _) => true,
|
||||
(Self::Live, PeerState::Live(_)) => true,
|
||||
_ => false,
|
||||
}
|
||||
pub(crate) fn matches(&self, s: &PeerState) -> bool {
|
||||
matches!((self, s), (Self::All, _) | (Self::Live, PeerState::Live(_)))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue