Expose ratelimits in CLI

This commit is contained in:
Igor Katson 2024-11-18 17:40:04 +00:00
parent 1168307189
commit 2a7c632b2b
No known key found for this signature in database
GPG key ID: B4EC22B66D61A3F5
2 changed files with 15 additions and 3 deletions

View file

@ -51,7 +51,7 @@ mod file_ops;
pub mod http_api;
#[cfg(feature = "http-api")]
pub mod http_api_client;
mod limits;
pub mod limits;
mod merge_streams;
mod peer_connection;
mod peer_info_reader;

View file

@ -1,6 +1,7 @@
use std::{
io,
net::SocketAddr,
num::NonZeroU32,
path::{Path, PathBuf},
sync::Arc,
thread,
@ -14,6 +15,7 @@ use librqbit::{
api::ApiAddTorrentResponse,
http_api::{HttpApi, HttpApiOptions},
http_api_client, librqbit_spawn,
limits::LimitsConfig,
storage::{
filesystem::{FilesystemStorageFactory, MmapFilesystemStorageFactory},
StorageFactory, StorageFactoryExt,
@ -218,6 +220,14 @@ struct Opts {
#[cfg(feature = "disable-upload")]
#[arg(long, env = "RQBIT_DISABLE_UPLOAD")]
disable_upload: bool,
/// Limit download to bytes-per-second.
#[arg(long = "ratelimit-download", env = "RQBIT_RATELIMIT_DOWNLOAD")]
ratelimit_download_bps: Option<NonZeroU32>,
/// Limit upload to bytes-per-second.
#[arg(long = "ratelimit-upload", env = "RQBIT_RATELIMIT_UPLOAD")]
ratelimit_upload_bps: Option<NonZeroU32>,
}
#[derive(Parser)]
@ -480,8 +490,10 @@ async fn async_main(opts: Opts, cancel: CancellationToken) -> anyhow::Result<()>
cancellation_token: Some(cancel.clone()),
#[cfg(feature = "disable-upload")]
disable_upload: opts.disable_upload,
// TODO: expose
ratelimits: Default::default(),
ratelimits: LimitsConfig {
upload_bps: opts.ratelimit_upload_bps,
download_bps: opts.ratelimit_download_bps,
},
};
let stats_printer = |session: Arc<Session>| async move {