Create ManagedTorrent struct

This commit is contained in:
Igor Katson 2023-11-23 17:14:08 +00:00
parent f45a15c89a
commit cc1ef9d0e4
No known key found for this signature in database
GPG key ID: B4EC22B66D61A3F5
3 changed files with 40 additions and 8 deletions

View file

@ -123,7 +123,7 @@ pub struct TorrentStateOptions {
pub peer_read_write_timeout: Option<Duration>,
}
pub struct TorrentState {
pub struct TorrentStateLive {
peers: PeerStates,
info: TorrentMetaV1Info<ByteString>,
locked: Arc<RwLock<TorrentStateLocked>>,
@ -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<ByteString>,
@ -163,7 +163,7 @@ impl TorrentState {
) -> Arc<Self> {
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<TorrentState>,
state: Arc<TorrentStateLive>,
counters: Arc<AtomicPeerCounters>,
// Semantically, we don't need an RwLock here, as this is only requested from
// one future (requester + manage_peer).

View file

@ -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<Vec<usize>>,
trackers_tx: Sender<Url>,
},
}
pub(crate) struct ManagedTorrentLocked {
pub trackers: Vec<Url>,
pub only_files: Vec<usize>,
pub state: ManagedTorrentState,
}
pub struct ManagedTorrentInfo {
pub info: TorrentMetaV1Info<ByteString>,
pub info_hash: Id20,
}
pub(crate) struct ManagedTorrent {
pub info: Arc<ManagedTorrentInfo>,
pub(crate) locked: RwLock<ManagedTorrentLocked>,
}