pub struct WebSeedClient { /* private fields */ }Expand description
HTTP client for downloading individual BT pieces from a single web-seed URL.
Uses HTTP Range requests (Range: bytes={start}-{end}) to fetch specific
byte ranges corresponding to torrent pieces.
Implementations§
Source§impl WebSeedClient
impl WebSeedClient
Create a WebSeedClient with shared stats (for aggregated statistics).
Sourcepub fn can_request(&self, piece_index: u32) -> bool
pub fn can_request(&self, piece_index: u32) -> bool
Check if a piece can be requested (not already active).
Sourcepub fn mark_requesting(&self, piece_index: u32)
pub fn mark_requesting(&self, piece_index: u32)
Mark a piece as being requested.
Sourcepub fn clear_request(&self, piece_index: u32)
pub fn clear_request(&self, piece_index: u32)
Mark a piece as no longer being requested.
Sourcepub fn active_request_count(&self) -> usize
pub fn active_request_count(&self) -> usize
Get the number of active requests.
Sourcepub fn stats(&self) -> &WebSeedStats
pub fn stats(&self) -> &WebSeedStats
Get reference to the stats.
Sourcepub async fn download_piece(
&self,
piece_index: u32,
_piece_length: u64,
piece_offset: u64,
length: u64,
) -> Result<Vec<u8>, String>
pub async fn download_piece( &self, piece_index: u32, _piece_length: u64, piece_offset: u64, length: u64, ) -> Result<Vec<u8>, String>
Download a specific piece range via HTTP GET with Range header.
Constructs an HTTP request to fetch bytes [piece_offset, piece_offset+length)
from the web-seed server using the Range header.
§Arguments
piece_index- Logical index of the piece (for logging)piece_length- Total length of this piece (unused in request but for context)piece_offset- Byte offset within the full file where this piece startslength- Number of bytes to download
§Returns
Ok(Vec<u8>)- Raw piece data on success (HTTP 206 Partial Content or 200 OK)Err(String)- Network error or non-success HTTP status
Sourcepub async fn request_piece(
&self,
piece_index: u32,
piece_length: u32,
total_length: u64,
) -> Result<Vec<u8>, String>
pub async fn request_piece( &self, piece_index: u32, piece_length: u32, total_length: u64, ) -> Result<Vec<u8>, String>
Request a piece from this web seed with concurrency control.
This method:
- Checks if the piece is already being requested
- Marks the piece as active
- Downloads the piece
- Clears the active flag
§Arguments
piece_index- Index of the piece to downloadpiece_length- Length of each piecetotal_length- Total file length (for calculating the last piece size)
§Returns
Ok(Vec<u8>)- Piece dataErr(String)- Error or “already active”
Sourcepub fn is_available(&self) -> bool
pub fn is_available(&self) -> bool
Check whether this web-seed appears to be available.
Currently returns true unconditionally; a future implementation
could perform a lightweight HEAD request or health check.
Auto Trait Implementations§
impl !RefUnwindSafe for WebSeedClient
impl !UnwindSafe for WebSeedClient
impl Freeze for WebSeedClient
impl Send for WebSeedClient
impl Sync for WebSeedClient
impl Unpin for WebSeedClient
impl UnsafeUnpin for WebSeedClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more