2/n Wrap PeerState into peer

This commit is contained in:
Igor Katson 2023-11-17 22:51:05 +00:00
parent 8e50829586
commit 55e692d476
No known key found for this signature in database
GPG key ID: B4EC22B66D61A3F5
2 changed files with 50 additions and 23 deletions

View file

@ -2,7 +2,7 @@ use std::{collections::HashSet, sync::Arc};
use librqbit_core::id20::Id20;
use librqbit_core::lengths::{ChunkInfo, ValidPieceIndex};
use tokio::sync::mpsc::UnboundedSender;
use tokio::sync::mpsc::{UnboundedReceiver, UnboundedSender};
use tokio::sync::{Notify, Semaphore};
use crate::peer_connection::WriterRequest;
@ -24,8 +24,20 @@ 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 = Arc<UnboundedSender<WriterRequest>>;
#[derive(Debug, Default)]
pub struct PeerStats {
pub unsuccessful_connection_attempts: usize,
}
#[derive(Debug, Default)]
pub struct Peer {
pub state: PeerState,
pub stats: PeerStats,
}
#[derive(Debug, Default)]
pub enum PeerState {
#[default]