Skip to content

Commit

Permalink
Add peer connectons timeout options
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterDing committed Oct 25, 2024
1 parent 335a737 commit 7d87a2f
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/app/core/bt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ pub struct BtHandler {
file_regex: Option<String>,
seed: bool,
trackers: Option<Vec<String>>,
peer_connect_timeout: Option<u64>,
peer_read_write_timeout: Option<u64>,
peer_keep_alive_interval: Option<u64>,
}

impl BtHandler {
Expand All @@ -30,6 +33,9 @@ impl BtHandler {
file_regex: args.bt_file_regex(),
seed: args.seed(),
trackers: args.bt_trackers(),
peer_connect_timeout: args.bt_peer_connect_timeout(),
peer_read_write_timeout: args.bt_peer_read_write_timeout(),
peer_keep_alive_interval: args.bt_peer_keep_alive_interval(),
}
}

Expand Down Expand Up @@ -59,9 +65,9 @@ impl BtHandler {
}),
peer_id: None,
peer_opts: Some(PeerConnectionOptions {
connect_timeout: Some(Duration::from_secs(10)),
read_write_timeout: Some(Duration::from_secs(30)),
..Default::default()
connect_timeout: self.peer_connect_timeout.map(Duration::from_secs),
read_write_timeout: self.peer_read_write_timeout.map(Duration::from_secs),
keep_alive_interval: self.peer_keep_alive_interval.map(Duration::from_secs),
}),
fastresume: true,
persistence: Some(SessionPersistenceConfig::Json {
Expand Down Expand Up @@ -120,6 +126,7 @@ impl BtHandler {
// 4. Start seeding
if self.seed {
tracing::debug!("BtHandler: start seeding");
println!("\nSeeding...");
}
while self.seed {
actix_rt::time::sleep(Duration::from_secs(1)).await;
Expand Down
9 changes: 9 additions & 0 deletions src/arguments/clap_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ pub struct AgetCli {
)]
pub bt_trackers: Option<Vec<String>>,

#[clap(long, help = "Peer connect timeout in seconds. [default: 10]")]
pub bt_peer_connect_timeout: Option<u64>,

#[clap(long, help = "Peer read/write timeout in seconds. [default: 10]")]
pub bt_peer_read_write_timeout: Option<u64>,

#[clap(long, help = "Peer keep-alive interval in seconds. [default: 120]")]
pub bt_peer_keep_alive_interval: Option<u64>,

#[clap(long, help = "Debug output. Print all trackback for debugging")]
pub debug: bool,

Expand Down
21 changes: 21 additions & 0 deletions src/arguments/cmd_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,21 @@ impl Args for CmdArgs {
self.cli.bt_trackers.to_owned()
}

/// Peer connect timeout
fn bt_peer_connect_timeout(&self) -> Option<u64> {
self.cli.bt_peer_connect_timeout
}

/// Peer read/write timeout
fn bt_peer_read_write_timeout(&self) -> Option<u64> {
self.cli.bt_peer_read_write_timeout
}

/// Peer keep alive interval
fn bt_peer_keep_alive_interval(&self) -> Option<u64> {
self.cli.bt_peer_keep_alive_interval
}

/// To debug mode, if it returns true
fn debug(&self) -> bool {
self.cli.debug
Expand Down Expand Up @@ -305,6 +320,12 @@ impl fmt::Debug for CmdArgs {
.field("retries", &self.retries())
.field("retry_wait", &self.retry_wait())
.field("task_type", &self.task_type())
.field("bt_file_regex", &self.bt_file_regex())
.field("seed", &self.seed())
.field("bt_trackers", &self.bt_trackers())
.field("bt_peer_connect_timeout", &self.bt_peer_connect_timeout())
.field("bt_peer_read_write_timeout", &self.bt_peer_read_write_timeout())
.field("bt_peer_keep_alive_interval", &self.bt_peer_keep_alive_interval())
.field("debug", &self.debug())
.field("quiet", &self.quiet())
.finish()
Expand Down
9 changes: 9 additions & 0 deletions src/features/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ pub trait Args {
/// Trackers for the torrent
fn bt_trackers(&self) -> Option<Vec<String>>;

/// Peer connect timeout
fn bt_peer_connect_timeout(&self) -> Option<u64>;

/// Peer read/write timeout
fn bt_peer_read_write_timeout(&self) -> Option<u64>;

/// Peer keep alive interval
fn bt_peer_keep_alive_interval(&self) -> Option<u64>;

/// To debug mode, if it returns true
fn debug(&self) -> bool;

Expand Down

0 comments on commit 7d87a2f

Please sign in to comment.