diff --git a/src/app/core/bt.rs b/src/app/core/bt.rs index 68337c2..081b9fd 100644 --- a/src/app/core/bt.rs +++ b/src/app/core/bt.rs @@ -18,6 +18,9 @@ pub struct BtHandler { file_regex: Option, seed: bool, trackers: Option>, + peer_connect_timeout: Option, + peer_read_write_timeout: Option, + peer_keep_alive_interval: Option, } impl BtHandler { @@ -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(), } } @@ -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 { @@ -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; diff --git a/src/arguments/clap_cli.rs b/src/arguments/clap_cli.rs index 9b5f3ac..eccf9eb 100644 --- a/src/arguments/clap_cli.rs +++ b/src/arguments/clap_cli.rs @@ -69,6 +69,15 @@ pub struct AgetCli { )] pub bt_trackers: Option>, + #[clap(long, help = "Peer connect timeout in seconds. [default: 10]")] + pub bt_peer_connect_timeout: Option, + + #[clap(long, help = "Peer read/write timeout in seconds. [default: 10]")] + pub bt_peer_read_write_timeout: Option, + + #[clap(long, help = "Peer keep-alive interval in seconds. [default: 120]")] + pub bt_peer_keep_alive_interval: Option, + #[clap(long, help = "Debug output. Print all trackback for debugging")] pub debug: bool, diff --git a/src/arguments/cmd_args.rs b/src/arguments/cmd_args.rs index 71b8ac3..859a334 100644 --- a/src/arguments/cmd_args.rs +++ b/src/arguments/cmd_args.rs @@ -275,6 +275,21 @@ impl Args for CmdArgs { self.cli.bt_trackers.to_owned() } + /// Peer connect timeout + fn bt_peer_connect_timeout(&self) -> Option { + self.cli.bt_peer_connect_timeout + } + + /// Peer read/write timeout + fn bt_peer_read_write_timeout(&self) -> Option { + self.cli.bt_peer_read_write_timeout + } + + /// Peer keep alive interval + fn bt_peer_keep_alive_interval(&self) -> Option { + self.cli.bt_peer_keep_alive_interval + } + /// To debug mode, if it returns true fn debug(&self) -> bool { self.cli.debug @@ -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() diff --git a/src/features/args.rs b/src/features/args.rs index 8e98719..73faec2 100644 --- a/src/features/args.rs +++ b/src/features/args.rs @@ -79,6 +79,15 @@ pub trait Args { /// Trackers for the torrent fn bt_trackers(&self) -> Option>; + /// Peer connect timeout + fn bt_peer_connect_timeout(&self) -> Option; + + /// Peer read/write timeout + fn bt_peer_read_write_timeout(&self) -> Option; + + /// Peer keep alive interval + fn bt_peer_keep_alive_interval(&self) -> Option; + /// To debug mode, if it returns true fn debug(&self) -> bool;