diff --git a/crates/librqbit/src/torrent_manager.rs b/crates/librqbit/src/torrent_manager.rs index b953530..4be9c9c 100644 --- a/crates/librqbit/src/torrent_manager.rs +++ b/crates/librqbit/src/torrent_manager.rs @@ -24,7 +24,7 @@ use crate::{ chunk_tracker::ChunkTracker, file_ops::FileOps, spawn_utils::{spawn, BlockingSpawner}, - torrent_state::{TorrentState, TorrentStateOptions}, + torrent_state::{TorrentStateLive, TorrentStateOptions}, tracker_comms::{TrackerError, TrackerRequest, TrackerRequestEvent, TrackerResponse}, }; @@ -131,7 +131,7 @@ impl TorrentManagerHandle { pub fn add_peer(&self, addr: SocketAddr) -> bool { self.manager.state.add_peer_if_not_seen(addr) } - pub fn torrent_state(&self) -> &TorrentState { + pub fn torrent_state(&self) -> &TorrentStateLive { &self.manager.state } pub fn speed_estimator(&self) -> &Arc { @@ -147,7 +147,7 @@ impl TorrentManagerHandle { } struct TorrentManager { - state: Arc, + state: Arc, #[allow(dead_code)] speed_estimator: Arc, trackers: Mutex>, @@ -267,7 +267,7 @@ impl TorrentManager { ..Default::default() }; - let state = TorrentState::new( + let state = TorrentStateLive::new( info, info_hash, peer_id, diff --git a/crates/librqbit/src/torrent_state/live/mod.rs b/crates/librqbit/src/torrent_state/live/mod.rs index b2be121..6335f6f 100644 --- a/crates/librqbit/src/torrent_state/live/mod.rs +++ b/crates/librqbit/src/torrent_state/live/mod.rs @@ -123,7 +123,7 @@ pub struct TorrentStateOptions { pub peer_read_write_timeout: Option, } -pub struct TorrentState { +pub struct TorrentStateLive { peers: PeerStates, info: TorrentMetaV1Info, locked: Arc>, @@ -146,7 +146,7 @@ pub struct TorrentState { finished_notify: Notify, } -impl TorrentState { +impl TorrentStateLive { #[allow(clippy::too_many_arguments)] pub(crate) fn new( info: TorrentMetaV1Info, @@ -163,7 +163,7 @@ impl TorrentState { ) -> Arc { let options = options.unwrap_or_default(); let (peer_queue_tx, peer_queue_rx) = unbounded_channel(); - let state = Arc::new(TorrentState { + let state = Arc::new(TorrentStateLive { info_hash, info, peer_id, @@ -478,7 +478,7 @@ struct PeerHandlerLocked { // All peer state that would never be used by other actors should pe put here. // This state tracks a live peer. struct PeerHandler { - state: Arc, + state: Arc, counters: Arc, // Semantically, we don't need an RwLock here, as this is only requested from // one future (requester + manage_peer). diff --git a/crates/librqbit/src/torrent_state/mod.rs b/crates/librqbit/src/torrent_state/mod.rs index c1c0d09..6b8347b 100644 --- a/crates/librqbit/src/torrent_state/mod.rs +++ b/crates/librqbit/src/torrent_state/mod.rs @@ -2,4 +2,36 @@ pub mod utils; pub mod live; +use std::sync::Arc; + +use buffers::ByteString; +use librqbit_core::id20::Id20; +use librqbit_core::torrent_metainfo::TorrentMetaV1Info; pub use live::*; +use parking_lot::RwLock; +use tokio::sync::mpsc::Sender; +use url::Url; + +pub(crate) enum ManagedTorrentState { + Live { + state: TorrentStateLive, + only_files_tx: Sender>, + trackers_tx: Sender, + }, +} + +pub(crate) struct ManagedTorrentLocked { + pub trackers: Vec, + pub only_files: Vec, + pub state: ManagedTorrentState, +} + +pub struct ManagedTorrentInfo { + pub info: TorrentMetaV1Info, + pub info_hash: Id20, +} + +pub(crate) struct ManagedTorrent { + pub info: Arc, + pub(crate) locked: RwLock, +}