Skip to content

Commit

Permalink
Added a command line argument to set the the idle session timeout (#22)…
Browse files Browse the repository at this point in the history
…. (#23)
  • Loading branch information
hannesdejager authored Nov 15, 2019
1 parent 184466c commit d4a6789
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 17 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "unftp"
version = "0.5.0"
version = "0.6.0"
authors = [
"Agoston Horvath <[email protected]>",
"Dávid Kosztka <[email protected]>",
Expand All @@ -17,7 +17,7 @@ license = "Apache-2.0"
readme = "README.md"

[dependencies]
libunftp = "0.4.3"
libunftp = "0.5.0"
log = "0.4"
env_logger = "0.6"
redis = "0.9.0"
Expand Down
33 changes: 22 additions & 11 deletions src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub const FTPS_KEY_FILE: &str = "ftps-key-file";
pub const GCS_BUCKET: &str = "sbe-gcs-bucket";
pub const GCS_KEY_FILE: &str = "sbe-gcs-key-file";
pub const HTTP_BIND_ADDR: &str = "bind-address-http";
pub const IDLE_SESSION_TIMEOUT: &str = "idle-session-timeout";
pub const PASSIVE_PORTS: &str = "passive-ports";
pub const REDIS_HOST: &str = "log-redis-host";
pub const REDIS_KEY: &str = "log-redis-key";
Expand Down Expand Up @@ -58,18 +59,18 @@ pub(crate) fn clap_app(tmp_dir: &str) -> clap::App {
.long("bind-address")
.value_name("HOST_PORT")
.help("Sets the host and port to listen on for FTP control connections")
.default_value("0.0.0.0:2121")
.env("UNFTP_ADDRESS")
.takes_value(true),
.takes_value(true)
.default_value("0.0.0.0:2121"),
)
.arg(
Arg::with_name(ROOT_DIR)
.long("root-dir")
.value_name("PATH")
.help("Sets the FTP root directory")
.default_value(tmp_dir)
.env("UNFTP_ROOT")
.takes_value(true),
.takes_value(true)
.default_value(tmp_dir),
)
.arg(
Arg::with_name(FTPS_CERTS_FILE)
Expand Down Expand Up @@ -117,27 +118,28 @@ pub(crate) fn clap_app(tmp_dir: &str) -> clap::App {
.value_name("HOST_PORT")
.help("Sets the host and port for the HTTP server used by prometheus metrics collection")
.env("UNFTP_HTTP_ADDRESS")
.takes_value(true),
.takes_value(true)
.default_value("0.0.0.0:8080"),
)
.arg(
Arg::with_name(PASSIVE_PORTS)
.long("passive-ports")
.value_name("PORT_RANGE")
.help("Sets the port range for data ports.")
.default_value("49152-65535")
.env("UNFTP_PASV_PORT_RANGE")
.takes_value(true),
.takes_value(true)
.default_value("49152-65535"),
)
.arg(
Arg::with_name(AUTH_TYPE)
.long("auth-type")
.value_name("NAME")
.help("The type of authorization to use")
.default_value("anonymous")
.possible_values(&AuthType::variants())
//.case_insensitive(true)
.env("UNFTP_AUTH_REST_URL")
.takes_value(true),
.takes_value(true)
.default_value("anonymous"),
)
.arg(
Arg::with_name(AUTH_PAM_SERVICE)
Expand Down Expand Up @@ -193,10 +195,10 @@ pub(crate) fn clap_app(tmp_dir: &str) -> clap::App {
.long("sbe-type")
.value_name("NAME")
.help("The type of storage backend to use.")
.default_value("filesystem")
.possible_values(&StorageBackendType::variants())
.env("UNFTP_SBE_TYPE")
.takes_value(true),
.takes_value(true)
.default_value("filesystem"),
)
.arg(
Arg::with_name(GCS_BUCKET)
Expand All @@ -214,4 +216,13 @@ pub(crate) fn clap_app(tmp_dir: &str) -> clap::App {
.env("UNFTP_GCS_KEY_FILE")
.takes_value(true),
)
.arg(
Arg::with_name(IDLE_SESSION_TIMEOUT)
.long("idle-session-timeout")
.value_name("TIMEOUT_SECONDS")
.help("The timeout in seconds after which idle connections will be closed")
.env("UNFTP_IDLE_SESSION_TIMEOUT")
.takes_value(true)
.default_value("600"),
)
}
13 changes: 13 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,23 @@ where

info!(log, "Using passive port range {}..{}", start_port, end_port);

let idle_timeout_str = arg_matches.value_of(args::IDLE_SESSION_TIMEOUT).unwrap();
let idle_timeout = String::from(idle_timeout_str).parse::<u64>().map_err(move |e| {
format!(
"unable to parse given value '{}' for --{}: {}. Please use a numeric value",
idle_timeout_str,
args::IDLE_SESSION_TIMEOUT,
e
)
})?;

info!(log, "Idle session timeout is set to {} seconds", idle_timeout);

let mut server = Server::new(storage_backend)
.greeting("Welcome to unFTP")
.authenticator(make_auth(&arg_matches)?)
.passive_ports(start_port..end_port)
.idle_session_timeout(idle_timeout)
.with_metrics();

// Setup FTPS
Expand Down

0 comments on commit d4a6789

Please sign in to comment.