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
impl BtSeedManager
Sourcepub fn new(
connections: Vec<PeerConnection>,
piece_data: Arc<dyn PieceDataProvider>,
config: BtSeedingConfig,
exit_condition: SeedExitCondition,
total_downloaded: u64,
) -> Self
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 seedingpiece_data- Provider for piece dataconfig- Seeding configurationexit_condition- Conditions for exiting seedingtotal_downloaded- Total bytes downloaded (for ratio calculation)
Sourcepub 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
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.
Sourcepub 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
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.
Sourcepub async fn handle_piece_request(
&mut self,
peer: SocketAddr,
index: u32,
begin: u32,
length: u32,
) -> Result<Vec<u8>>
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 addressindex- The piece indexbegin- The offset within the piecelength- The length of data to read
§Returns
The requested piece data, or an error if the piece is not available.
Sourcepub fn should_stop_seeding(&self, downloaded_bytes: u64) -> bool
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)
Sourcepub fn get_upload_stats(&self) -> (u64, u64)
pub fn get_upload_stats(&self) -> (u64, u64)
Get upload statistics.
Returns a tuple of (total_uploaded_bytes, current_upload_speed).
Sourcepub fn update_upload_speed(&self, speed: u64)
pub fn update_upload_speed(&self, speed: u64)
Update the upload speed statistic.
This should be called periodically to track the current upload rate.
Sourcepub fn set_info_hash(&mut self, info_hash: [u8; 20])
pub fn set_info_hash(&mut self, info_hash: [u8; 20])
Set the info hash.
Sourcepub fn num_active_uploads(&self) -> usize
pub fn num_active_uploads(&self) -> usize
Get the number of active upload sessions.
Sourcepub fn max_uploads(&self) -> usize
pub fn max_uploads(&self) -> usize
Get the maximum number of concurrent uploads.
Sourcepub fn set_max_uploads(&mut self, max: usize)
pub fn set_max_uploads(&mut self, max: usize)
Set the maximum number of concurrent uploads.
Sourcepub fn seed_ratio(&self) -> f64
pub fn seed_ratio(&self) -> f64
Get the seed ratio target.
Sourcepub fn active_uploads(&self) -> &HashMap<SocketAddr, UploadSession>
pub fn active_uploads(&self) -> &HashMap<SocketAddr, UploadSession>
Get a reference to active upload sessions.
Sourcepub fn total_downloaded(&self) -> u64
pub fn total_downloaded(&self) -> u64
Get total downloaded bytes.
pub async fn run_seeding_loop(&mut self) -> Result<()>
pub fn should_exit(&self) -> bool
pub fn total_uploaded(&self) -> u64
pub fn seeding_duration(&self) -> Duration
pub fn num_alive_peers(&self) -> usize
pub fn num_total_peers(&self) -> usize
Sourcepub fn sync_choking_algo_stats(&mut self)
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.
Sourcepub fn choking_algo(&self) -> Option<&ChokingAlgorithm>
pub fn choking_algo(&self) -> Option<&ChokingAlgorithm>
Get a reference to the choking algorithm, if configured.
Sourcepub fn choking_algo_mut(&mut self) -> Option<&mut ChokingAlgorithm>
pub fn choking_algo_mut(&mut self) -> Option<&mut ChokingAlgorithm>
Get a mutable reference to the choking algorithm, if configured.
Sourcepub fn max_upload_speed(&self) -> Option<u64>
pub fn max_upload_speed(&self) -> Option<u64>
Get the maximum upload speed limit (bytes/sec).
Returns None if unlimited.
Sourcepub fn set_max_upload_speed(&mut self, speed: Option<u64>)
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.
Sourcepub fn current_upload_speed(&self) -> u64
pub fn current_upload_speed(&self) -> u64
Get the current upload speed (bytes/sec).
Sourcepub fn calculate_upload_speed(&self) -> u64
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.