diff --git a/crates/librqbit/src/lib.rs b/crates/librqbit/src/lib.rs index 7b337d4..a17687c 100644 --- a/crates/librqbit/src/lib.rs +++ b/crates/librqbit/src/lib.rs @@ -7,6 +7,7 @@ pub mod lengths; pub mod peer_binary_protocol; pub mod peer_connection; pub mod peer_id; +pub mod peer_state; pub mod serde_bencode; pub mod spawn_utils; pub mod torrent_manager; diff --git a/crates/librqbit/src/peer_connection.rs b/crates/librqbit/src/peer_connection.rs index 150cf1f..49243de 100644 --- a/crates/librqbit/src/peer_connection.rs +++ b/crates/librqbit/src/peer_connection.rs @@ -17,7 +17,8 @@ use crate::{ }, peer_id::try_decode_peer_id, spawn_utils::{spawn, spawn_blocking}, - torrent_state::{InflightRequest, PeerHandle, TorrentState}, + torrent_state::{InflightRequest, TorrentState}, + type_aliases::PeerHandle, }; #[derive(Clone)] diff --git a/crates/librqbit/src/peer_state.rs b/crates/librqbit/src/peer_state.rs new file mode 100644 index 0000000..79e1265 --- /dev/null +++ b/crates/librqbit/src/peer_state.rs @@ -0,0 +1,24 @@ +use std::{collections::HashSet, net::SocketAddr, sync::Arc}; + +use tokio::sync::{Notify, Semaphore}; + +use crate::{torrent_state::InflightRequest, type_aliases::BF}; + +pub enum PeerState { + Connecting(SocketAddr), + Live(LivePeerState), +} + +pub struct LivePeerState { + #[allow(unused)] + pub peer_id: [u8; 20], + pub i_am_choked: bool, + #[allow(unused)] + pub peer_choked: bool, + #[allow(unused)] + pub peer_interested: bool, + pub outstanding_requests: Arc, + pub have_notify: Arc, + pub bitfield: Option, + pub inflight_requests: HashSet, +} diff --git a/crates/librqbit/src/torrent_state.rs b/crates/librqbit/src/torrent_state.rs index 7ab9357..0d21e91 100644 --- a/crates/librqbit/src/torrent_state.rs +++ b/crates/librqbit/src/torrent_state.rs @@ -21,17 +21,11 @@ use crate::{ file_checking::update_hash_from_file, lengths::{ChunkInfo, Lengths, ValidPieceIndex}, peer_binary_protocol::{Handshake, Message, MessageOwned, Piece}, + peer_state::{LivePeerState, PeerState}, torrent_metainfo::TorrentMetaV1Owned, - type_aliases::BF, + type_aliases::{PeerHandle, BF}, }; -pub type PeerHandle = SocketAddr; - -pub enum PeerState { - Connecting(SocketAddr), - Live(LivePeerState), -} - #[derive(Debug, Hash, PartialEq, Eq)] pub struct InflightRequest { pub piece: ValidPieceIndex, @@ -47,20 +41,6 @@ impl From<&ChunkInfo> for InflightRequest { } } -pub struct LivePeerState { - #[allow(unused)] - pub peer_id: [u8; 20], - pub i_am_choked: bool, - #[allow(unused)] - pub peer_choked: bool, - #[allow(unused)] - pub peer_interested: bool, - pub outstanding_requests: Arc, - pub have_notify: Arc, - pub bitfield: Option, - pub inflight_requests: HashSet, -} - #[derive(Default)] pub struct PeerStates { states: HashMap, diff --git a/crates/librqbit/src/type_aliases.rs b/crates/librqbit/src/type_aliases.rs index 2dfc5b9..dc4de81 100644 --- a/crates/librqbit/src/type_aliases.rs +++ b/crates/librqbit/src/type_aliases.rs @@ -1 +1,5 @@ +use std::net::SocketAddr; + pub type BF = bitvec::vec::BitVec; + +pub type PeerHandle = SocketAddr;