pub struct RateLimiterSet { /* private fields */ }Expand description
Per-class rate limiter set (BEP 40 / libtorrent parity).
Maintains separate upload/download buckets for TCP and uTP, plus global upload/download buckets. Uses check-before-consume pattern to avoid partial consumption when one bucket has capacity but another doesn’t.
Implementations§
Source§impl RateLimiterSet
impl RateLimiterSet
Sourcepub fn new(
tcp_upload_rate: u64,
tcp_download_rate: u64,
utp_upload_rate: u64,
utp_download_rate: u64,
global_upload_rate: u64,
global_download_rate: u64,
) -> Self
pub fn new( tcp_upload_rate: u64, tcp_download_rate: u64, utp_upload_rate: u64, utp_download_rate: u64, global_upload_rate: u64, global_download_rate: u64, ) -> Self
Create a new rate limiter set. Rate of 0 = unlimited.
Sourcepub fn try_consume_upload(
&mut self,
amount: u64,
transport: PeerTransport,
) -> bool
pub fn try_consume_upload( &mut self, amount: u64, transport: PeerTransport, ) -> bool
Try to consume upload tokens for the given transport class.
Checks both the class bucket and global bucket before consuming either, to avoid partial consumption without refund.
Sourcepub fn try_consume_download(
&mut self,
amount: u64,
transport: PeerTransport,
) -> bool
pub fn try_consume_download( &mut self, amount: u64, transport: PeerTransport, ) -> bool
Try to consume download tokens for the given transport class.
Sourcepub fn set_rates(
&mut self,
tcp_upload: u64,
tcp_download: u64,
utp_upload: u64,
utp_download: u64,
global_upload: u64,
global_download: u64,
)
pub fn set_rates( &mut self, tcp_upload: u64, tcp_download: u64, utp_upload: u64, utp_download: u64, global_upload: u64, global_download: u64, )
Update per-class rates at runtime (e.g., from apply_settings).
Sourcepub fn apply_mixed_mode(
&mut self,
algorithm: MixedModeAlgorithm,
tcp_peers: usize,
utp_peers: usize,
global_upload_rate: u64,
)
pub fn apply_mixed_mode( &mut self, algorithm: MixedModeAlgorithm, tcp_peers: usize, utp_peers: usize, global_upload_rate: u64, )
Apply mixed-mode bandwidth allocation based on peer transport composition. Only adjusts upload — download is not throttled by transport type.