Skip to content

Commit

Permalink
Ready to test session limits
Browse files Browse the repository at this point in the history
  • Loading branch information
ikatson committed Nov 7, 2024
1 parent becf7b4 commit 9904083
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions crates/librqbit/src/http_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ use tokio::net::TcpListener;
use tower_http::trace::{DefaultOnFailure, DefaultOnResponse, OnFailure};
use tracing::{debug, error_span, trace, Span};

use axum::Router;
use axum::{Json, Router};

use crate::api::{Api, ApiTorrentListOpts, TorrentIdOrHash};
use crate::api::{Api, ApiTorrentListOpts, EmptyJsonResponse, TorrentIdOrHash};
use crate::limits::LimitsConfig;
use crate::peer_connection::PeerConnectionOptions;
use crate::session::{AddTorrent, AddTorrentOptions, SUPPORTED_SCHEMES};
use crate::torrent_state::peer::stats::snapshot::PeerStatsFilter;
Expand Down Expand Up @@ -490,6 +491,18 @@ impl HttpApi {
Ok(axum::body::Body::from_stream(s))
}

async fn update_session_ratelimits(
State(state): State<ApiState>,
Json(limits): Json<LimitsConfig>,
) -> Result<impl IntoResponse> {
state.session().ratelimits.set_upload_bps(limits.upload_bps);
state
.session()
.ratelimits
.set_download_bps(limits.download_bps);
Ok(Json(EmptyJsonResponse {}))
}

let mut app = Router::new()
.route("/", get(api_root))
.route("/stream_logs", get(stream_logs))
Expand All @@ -515,6 +528,7 @@ impl HttpApi {
if !self.opts.read_only {
app = app
.route("/torrents", post(torrents_post))
.route("/torrents/limits", post(update_session_ratelimits))
.route("/torrents/:id/pause", post(torrent_action_pause))
.route("/torrents/:id/start", post(torrent_action_start))
.route("/torrents/:id/forget", post(torrent_action_forget))
Expand Down

0 comments on commit 9904083

Please sign in to comment.