Skip to main content

TorrentHandle

Struct TorrentHandle 

Source
pub struct TorrentHandle { /* private fields */ }
Expand description

Cloneable handle for interacting with a running torrent.

Implementations§

Source§

impl TorrentHandle

Source

pub async fn stats(&self) -> Result<TorrentStats>

Query current torrent statistics.

§Errors

Returns an error if the session is shut down.

Source

pub async fn get_meta(&self) -> Result<Option<TorrentMetaV1>>

v0.173.1: fetch the torrent’s current metadata from the TorrentActor.

Returns Ok(None) if metadata has not yet been assembled (magnet pre-resolution), Ok(Some(meta)) once the info dict is known. Returns Err(Shutdown) if the actor has already exited. Callers that need the meta to exist should fall back to crate::Error::MetadataNotReady on the Ok(None) branch.

This replaces SessionActor.TorrentEntry.meta as the single source of truth: see docs/plans/2026-04-22-irontide-v0.173.1-qbt-v2-bug-sweep.md for the Class A archaeology.

§Errors

Returns an error if the session is shut down.

Source

pub async fn add_peers( &self, peers: Vec<SocketAddr>, source: PeerSource, ) -> Result<()>

Add peer addresses to the available-peer pool.

§Errors

Returns an error if the session is shut down.

Source

pub async fn pause(&self) -> Result<()>

Pause the torrent session (disconnect peers, announce Stopped).

§Errors

Returns an error if the session is shut down.

Source

pub async fn queue(&self) -> Result<()>

Queue a torrent via auto-manage (system-managed pause).

§Errors

Returns an error if the session is shut down.

Source

pub async fn set_category(&self, category: Option<String>) -> Result<()>

M170: update the qBt-compat category label on this torrent.

Pass None to clear the label. The change is visible via the next stats() call and persists across save_resume_data.

§Errors

Returns an error if the session is shut down.

Source

pub async fn set_tags(&self, tags: Vec<String>) -> Result<()>

M171: replace this torrent’s tag set wholesale (qBt-compat).

Mirrors qBt’s addTags / removeTags wire behaviour at the API layer — always a wholesale replacement at the engine layer. The change is visible via the next stats() call and persists across save_resume_data.

§Errors

Returns an error if the session is shut down.

Source

pub async fn resume(&self) -> Result<()>

Resume a paused torrent session (reconnect, announce Started).

§Errors

Returns an error if the session is shut down.

Source

pub async fn shutdown(&self) -> Result<()>

Gracefully shut down the torrent session.

§Errors

Returns an error if the session is shut down.

Source

pub async fn save_resume_data(&self) -> Result<FastResumeData>

Snapshot current torrent state into libtorrent-compatible resume data.

§Errors

Returns an error if the I/O operation fails.

Source

pub async fn set_file_priority( &self, index: usize, priority: FilePriority, ) -> Result<()>

Set the download priority for a specific file.

§Errors

Returns an error if the session is shut down.

Source

pub async fn file_priorities(&self) -> Result<Vec<FilePriority>>

Get the current per-file priorities.

§Errors

Returns an error if the session is shut down.

Source

pub async fn tracker_list(&self) -> Result<Vec<TrackerInfo>>

Get the list of all configured trackers with their status.

§Errors

Returns an error if the session is shut down.

Source

pub async fn get_web_seeds(&self) -> Result<Vec<String>>

M171 Lane B: snapshot the web seed URLs (BEP 19 + BEP 17 merged).

§Errors

Returns an error if the session is shut down.

Source

pub async fn get_piece_states(&self) -> Result<Vec<u8>>

M171 Lane B: snapshot the per-piece qBt state codes.

§Errors

Returns an error if the session is shut down.

Source

pub async fn get_piece_hashes( &self, offset: u32, limit: u32, ) -> Result<Vec<String>>

M171 Lane B: paginated piece hash list.

offset and limit are clamped to the real hash count inside the actor — callers can pass arbitrary values without overflow concerns.

§Errors

Returns an error if the session is shut down.

Source

pub async fn force_reannounce(&self) -> Result<()>

Force all trackers to re-announce immediately.

§Errors

Returns an error if the session is shut down.

Source

pub async fn scrape(&self) -> Result<Option<(String, ScrapeInfo)>>

Scrape trackers for seeder/leecher counts.

§Errors

Returns an error if the session is shut down.

Source

pub async fn open_file(&self, file_index: usize) -> Result<FileStream>

Open a streaming reader for a file within the torrent.

§Errors

Returns an error if the session is shut down.

Source

pub async fn move_storage(&self, new_path: PathBuf) -> Result<()>

Move torrent data files to a new download directory.

Relocates existing files (rename or copy+delete), re-registers storage with the disk manager, and fires a StorageMoved alert on success.

§Errors

Returns an error if the session is shut down.

Source

pub async fn set_download_limit(&self, bytes_per_sec: u64) -> Result<()>

Set the per-torrent download rate limit in bytes/sec (0 = unlimited).

§Errors

Returns an error if the data cannot be parsed or I/O fails.

Source

pub async fn set_upload_limit(&self, bytes_per_sec: u64) -> Result<()>

Set the per-torrent upload rate limit in bytes/sec (0 = unlimited).

§Errors

Returns an error if the data cannot be parsed or I/O fails.

Source

pub async fn download_limit(&self) -> Result<u64>

Get the current per-torrent download rate limit in bytes/sec (0 = unlimited).

§Errors

Returns an error if the data cannot be parsed or I/O fails.

Source

pub async fn upload_limit(&self) -> Result<u64>

Get the current per-torrent upload rate limit in bytes/sec (0 = unlimited).

§Errors

Returns an error if the data cannot be parsed or I/O fails.

Source

pub async fn set_sequential_download(&self, enabled: bool) -> Result<()>

Enable or disable sequential (in-order) piece downloading.

§Errors

Returns an error if the data cannot be parsed or I/O fails.

Source

pub async fn is_sequential_download(&self) -> Result<bool>

Query whether sequential downloading is enabled.

§Errors

Returns an error if the data cannot be parsed or I/O fails.

Source

pub async fn set_super_seeding(&self, enabled: bool) -> Result<()>

Enable or disable BEP 16 super seeding mode.

§Errors

Returns an error if the session is shut down.

Source

pub async fn is_super_seeding(&self) -> Result<bool>

Query whether BEP 16 super seeding mode is enabled.

§Errors

Returns an error if the session is shut down.

Source

pub async fn set_seed_mode(&self, enabled: bool) -> Result<()>

Enable or disable user-requested seed-only mode (M159).

When enabled is true, the actor stops scheduling new block requests and cancels all in-flight requests, but keeps existing peers connected and continues serving uploads. Toggling back to false restores normal piece scheduling.

§Errors

Returns crate::Error::Shutdown if the torrent actor has terminated.

Source

pub async fn add_tracker(&self, url: String) -> Result<()>

Add a new tracker URL to this torrent (fire-and-forget).

The URL is validated and deduplicated by the tracker manager.

§Errors

Returns an error if the session is shut down.

Source

pub async fn replace_trackers(&self, urls: Vec<String>) -> Result<()>

Replace all tracker URLs for this torrent.

§Errors

Returns an error if the session is shut down.

Source

pub async fn force_recheck(&self) -> Result<()>

Trigger a full piece verification (force recheck).

Transitions the torrent through Checking state, clears all piece completion data, re-verifies every piece against its hash, then transitions to Seeding (all valid) or Downloading (some missing). Returns after the check is complete.

§Errors

Returns an error if the session is shut down.

Source

pub async fn rename_file( &self, file_index: usize, new_name: String, ) -> Result<()>

Rename a file within the torrent on disk.

Changes the filename of the specified file (by index) to new_name. The file stays in the same directory; only the filename component changes. Fires a FileRenamed alert on success.

§Errors

Returns an error if the session is shut down.

Source

pub async fn set_max_connections(&self, limit: usize) -> Result<()>

Set the per-torrent maximum number of connections (0 = use global default).

§Errors

Returns an error if the connection or binding fails.

Source

pub async fn max_connections(&self) -> Result<usize>

Get the current per-torrent maximum connection limit (0 = use global default).

§Errors

Returns an error if the connection or binding fails.

Source

pub async fn set_max_uploads(&self, limit: usize) -> Result<()>

Set the per-torrent maximum number of upload slots (unchoke slots).

§Errors

Returns an error if the data cannot be parsed or I/O fails.

Source

pub async fn max_uploads(&self) -> Result<usize>

Get the current per-torrent maximum upload slots (unchoke slots).

§Errors

Returns an error if the data cannot be parsed or I/O fails.

Source

pub async fn get_peer_info(&self) -> Result<Vec<PeerInfo>>

Get per-peer details for all connected peers.

§Errors

Returns an error if the session is shut down.

Source

pub async fn get_download_queue(&self) -> Result<Vec<PartialPieceInfo>>

Get in-flight piece download status (the download queue).

§Errors

Returns an error if the data cannot be parsed or I/O fails.

Source

pub async fn have_piece(&self, index: u32) -> Result<bool>

Check whether a specific piece has been downloaded.

§Errors

Returns an error if the session is shut down.

Source

pub async fn piece_availability(&self) -> Result<Vec<u32>>

Get per-piece availability counts from connected peers.

§Errors

Returns an error if the session is shut down.

Source

pub async fn file_progress(&self) -> Result<Vec<u64>>

Get per-file bytes-downloaded progress.

§Errors

Returns an error if the session is shut down.

Source

pub async fn info_hashes(&self) -> Result<InfoHashes>

Get the torrent’s identity hashes (v1 and/or v2).

§Errors

Returns an error if the session is shut down.

Source

pub async fn torrent_file(&self) -> Result<Option<TorrentMetaV1>>

Get the full v1 metainfo, if available.

Returns None for magnet links before metadata has been received.

§Errors

Returns an error if the session is shut down.

Source

pub async fn torrent_file_v2(&self) -> Result<Option<TorrentMetaV2>>

Get the full v2 metainfo, if available.

Returns None if the torrent is not a v2/hybrid torrent, or for magnet links before metadata has been received.

§Errors

Returns an error if the session is shut down.

Source

pub async fn force_dht_announce(&self) -> Result<()>

Force an immediate DHT announce for this torrent.

Fire-and-forget at the torrent level — the DHT announce is best-effort.

§Errors

Returns an error if the session is shut down.

Source

pub async fn read_piece(&self, index: u32) -> Result<Bytes>

Read all data for a specific piece from disk.

Returns the complete piece data as Bytes. The piece must have been downloaded already; use have_piece to check first.

§Errors

Returns an error if the data cannot be parsed or I/O fails.

Source

pub async fn flush_cache(&self) -> Result<()>

Flush the disk write cache, ensuring all buffered writes are persisted.

§Errors

Returns an error if the session is shut down.

Source

pub fn is_valid(&self) -> bool

Check whether this handle refers to a live torrent.

Returns false after the torrent has been removed or shut down. This is a synchronous check on the channel state — no command dispatch.

Source

pub async fn clear_error(&self) -> Result<()>

Clear any error state on the torrent and resume if it was paused due to error.

§Errors

Returns an error if the session is shut down.

Source

pub async fn file_status(&self) -> Result<Vec<FileStatus>>

Get per-file open/mode status based on the current torrent state.

Returns one crate::types::FileStatus entry per file in the torrent.

§Errors

Returns an error if the session is shut down.

Source

pub async fn flags(&self) -> Result<TorrentFlags>

Read the current torrent state as a [TorrentFlags] bitflag set.

§Errors

Returns an error if the session is shut down.

Source

pub async fn set_flags(&self, flags: TorrentFlags) -> Result<()>

Set (enable) the specified torrent flags.

Delegates to the underlying operations (pause/resume, sequential download, etc.).

§Errors

Returns an error if the session is shut down.

Source

pub async fn unset_flags(&self, flags: TorrentFlags) -> Result<()>

Unset (disable) the specified torrent flags.

Delegates to the underlying operations (pause/resume, sequential download, etc.).

§Errors

Returns an error if the session is shut down.

Source

pub async fn connect_peer(&self, addr: SocketAddr) -> Result<()>

Immediately initiate a peer connection to the given address.

Bypasses the normal peer selection queue — the connection attempt starts right away. Fire-and-forget: no reply is sent.

§Errors

Returns an error if the connection or binding fails.

Trait Implementations§

Source§

impl Clone for TorrentHandle

Source§

fn clone(&self) -> TorrentHandle

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more