This commit is contained in:
Igor Katson 2021-06-30 00:00:44 +01:00
parent 2fc225cfa2
commit e843209aa9
3 changed files with 22 additions and 18 deletions

View file

@ -18,8 +18,9 @@ use crate::{
MessageOwned, Piece, Request, PIECE_MESSAGE_DEFAULT_LEN,
},
peer_id::try_decode_peer_id,
peer_state::InflightRequest,
spawn_utils::{spawn, spawn_block_in_place},
torrent_state::{InflightRequest, TorrentState},
torrent_state::TorrentState,
type_aliases::PeerHandle,
};

View file

@ -2,7 +2,25 @@ use std::{collections::HashSet, net::SocketAddr, sync::Arc};
use tokio::sync::{Notify, Semaphore};
use crate::{torrent_state::InflightRequest, type_aliases::BF};
use crate::{
lengths::{ChunkInfo, ValidPieceIndex},
type_aliases::BF,
};
#[derive(Debug, Hash, PartialEq, Eq)]
pub struct InflightRequest {
pub piece: ValidPieceIndex,
pub chunk: u32,
}
impl From<&ChunkInfo> for InflightRequest {
fn from(c: &ChunkInfo) -> Self {
Self {
piece: c.piece_index,
chunk: c.chunk_index,
}
}
}
pub enum PeerState {
Connecting(SocketAddr),

View file

@ -16,7 +16,7 @@ use tokio::sync::mpsc::{channel, Sender};
use crate::{
chunk_tracker::ChunkTracker,
file_ops::FileOps,
lengths::{ChunkInfo, Lengths, ValidPieceIndex},
lengths::{Lengths, ValidPieceIndex},
peer_binary_protocol::{Handshake, Message},
peer_connection::{PeerConnection, WriterRequest},
peer_state::{LivePeerState, PeerState},
@ -25,21 +25,6 @@ use crate::{
type_aliases::{PeerHandle, BF},
};
#[derive(Debug, Hash, PartialEq, Eq)]
pub struct InflightRequest {
pub piece: ValidPieceIndex,
pub chunk: u32,
}
impl From<&ChunkInfo> for InflightRequest {
fn from(c: &ChunkInfo) -> Self {
Self {
piece: c.piece_index,
chunk: c.chunk_index,
}
}
}
#[derive(Default)]
pub struct PeerStates {
states: HashMap<PeerHandle, PeerState>,