Skip to main content

BtSeedManager

Struct BtSeedManager 

Source
pub struct BtSeedManager {
    pub total_uploaded: u64,
    pub seeding_start_time: Instant,
    pub choking_algo: Option<ChokingAlgorithm>,
    /* private fields */
}

Fields§

§total_uploaded: u64§seeding_start_time: Instant§choking_algo: Option<ChokingAlgorithm>

Choking algorithm for tit-for-tat peer selection during seeding. When present, drives intelligent choke/unchoke decisions every rotation interval.

Implementations§

Source§

impl BtSeedManager

Source

pub fn new( connections: Vec<PeerConnection>, piece_data: Arc<dyn PieceDataProvider>, config: BtSeedingConfig, exit_condition: SeedExitCondition, total_downloaded: u64, ) -> Self

Create a new BtSeedManager with default settings.

§Arguments
  • connections - Peer connections to use for seeding
  • piece_data - Provider for piece data
  • config - Seeding configuration
  • exit_condition - Conditions for exiting seeding
  • total_downloaded - Total bytes downloaded (for ratio calculation)
Source

pub fn new_with_choking_algo( connections: Vec<PeerConnection>, piece_data: Arc<dyn PieceDataProvider>, config: BtSeedingConfig, exit_condition: SeedExitCondition, total_downloaded: u64, choking_algo: Option<ChokingAlgorithm>, ) -> Self

Create a new BtSeedManager with an optional ChokingAlgorithm.

When choking_algo is Some, the seeding loop will call ChokingAlgorithm::rotate_choke every config.choke_rotation_interval_secs and apply the resulting choke/unchoke actions to sessions.

Source

pub fn new_with_info_hash( info_hash: [u8; 20], connections: Vec<PeerConnection>, piece_data: Arc<dyn PieceDataProvider>, config: BtSeedingConfig, exit_condition: SeedExitCondition, total_downloaded: u64, ) -> Self

Create a new BtSeedManager with explicit info_hash.

This is the preferred constructor when the info_hash is known.

Source

pub async fn handle_piece_request( &mut self, peer: SocketAddr, index: u32, begin: u32, length: u32, ) -> Result<Vec<u8>>

Handle a piece request from a peer.

This method reads the requested piece data from the piece provider and returns it for sending to the peer.

§Arguments
  • peer - The peer’s socket address
  • index - The piece index
  • begin - The offset within the piece
  • length - The length of data to read
§Returns

The requested piece data, or an error if the piece is not available.

Source

pub fn should_stop_seeding(&self, downloaded_bytes: u64) -> bool

Check if seeding should stop based on configured conditions.

Returns true when either:

  • The seed ratio has been reached (uploaded >= ratio * downloaded)
  • The seed time has elapsed
§Arguments
  • downloaded_bytes - Total bytes downloaded (for ratio calculation)
Source

pub fn get_upload_stats(&self) -> (u64, u64)

Get upload statistics.

Returns a tuple of (total_uploaded_bytes, current_upload_speed).

Source

pub fn update_upload_speed(&self, speed: u64)

Update the upload speed statistic.

This should be called periodically to track the current upload rate.

Source

pub fn info_hash(&self) -> &[u8; 20]

Get the info hash of the torrent being seeded.

Source

pub fn set_info_hash(&mut self, info_hash: [u8; 20])

Set the info hash.

Source

pub fn num_active_uploads(&self) -> usize

Get the number of active upload sessions.

Source

pub fn max_uploads(&self) -> usize

Get the maximum number of concurrent uploads.

Source

pub fn set_max_uploads(&mut self, max: usize)

Set the maximum number of concurrent uploads.

Source

pub fn seed_ratio(&self) -> f64

Get the seed ratio target.

Source

pub fn seed_time(&self) -> Duration

Get the seed time target.

Source

pub fn active_uploads(&self) -> &HashMap<SocketAddr, UploadSession>

Get a reference to active upload sessions.

Source

pub fn total_downloaded(&self) -> u64

Get total downloaded bytes.

Source

pub async fn run_seeding_loop(&mut self) -> Result<()>

Source

pub fn should_exit(&self) -> bool

Source

pub fn total_uploaded(&self) -> u64

Source

pub fn seeding_duration(&self) -> Duration

Source

pub fn num_alive_peers(&self) -> usize

Source

pub fn num_total_peers(&self) -> usize

Source

pub fn sync_choking_algo_stats(&mut self)

Sync upload statistics from sessions into the choking algorithm.

Call this periodically (e.g., after each message handling round) so the algorithm has up-to-date speed data for scoring.

Source

pub fn choking_algo(&self) -> Option<&ChokingAlgorithm>

Get a reference to the choking algorithm, if configured.

Source

pub fn choking_algo_mut(&mut self) -> Option<&mut ChokingAlgorithm>

Get a mutable reference to the choking algorithm, if configured.

Source

pub fn max_upload_speed(&self) -> Option<u64>

Get the maximum upload speed limit (bytes/sec).

Returns None if unlimited.

Source

pub fn set_max_upload_speed(&mut self, speed: Option<u64>)

Set the maximum upload speed limit (bytes/sec).

Set to None or Some(0) for unlimited.

Source

pub fn current_upload_speed(&self) -> u64

Get the current upload speed (bytes/sec).

Source

pub fn calculate_upload_speed(&self) -> u64

Calculate and update the current upload speed.

This should be called periodically (e.g., every second) to track the actual upload rate.

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> 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: Sized + 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: Sized + 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, 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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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