Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
395 changes: 366 additions & 29 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,15 @@ skip = [
{ name = "hashbrown", version = "0.12.3" },
{ name = "hashbrown", version = "0.15.5" },
{ name = "heck", version = "0.4.1" },
{ name = "hmac", version = "0.10.1" },
{ name = "indexmap", version = "1.9.3" },
{ name = "serde_yaml", version = "0.8.26" },
{ name = "sha2", version = "0.9.9" },
{ name = "strsim", version = "0.10.0" },
{ name = "syn", version = "1.0.109" },
{ name = "thiserror", version = "1.0.69" },
{ name = "thiserror-impl", version = "1.0.69" },
{ name = "windows-link", version = "0.1.3" },
{ name = "windows-sys", version = "0.52.0" },
{ name = "windows-sys", version = "0.59.0" },
{ name = "windows-sys", version = "0.60.2" },
{ name = "windows-targets", version = "0.52.6" },
Expand Down
2 changes: 2 additions & 0 deletions lightway-app-utils/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ mod connection_type;
mod duration;
mod ip_map;
mod logging;
mod nonzero_duration;

pub use cipher::Cipher;
pub use connection_type::ConnectionType;
pub use duration::Duration;
pub use ip_map::IpMap;
pub use logging::{LogFormat, LogLevel};
pub use nonzero_duration::NonZeroDuration;
7 changes: 7 additions & 0 deletions lightway-app-utils/src/args/duration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,10 @@ impl std::str::FromStr for Duration {
Ok(Duration(s.parse::<humantime::Duration>()?))
}
}

impl Duration {
/// Returns true if this `Duration` spans no time.
pub fn is_zero(&self) -> bool {
self.0.is_zero()
}
}
37 changes: 37 additions & 0 deletions lightway-app-utils/src/args/nonzero_duration.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use serde::{Deserialize, Serialize};
use serde_with::{DisplayFromStr, serde_as};

/// Wrapper for compatibility with both clap and twelf at the same time
#[serde_as]
#[derive(Copy, Clone, Serialize, Deserialize)]
pub struct NonZeroDuration(#[serde_as(as = "DisplayFromStr")] humantime::Duration);

impl std::fmt::Display for NonZeroDuration {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.0.fmt(f)
}
}

impl std::fmt::Debug for NonZeroDuration {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.0.fmt(f)
}
}

impl From<NonZeroDuration> for std::time::Duration {
fn from(d: NonZeroDuration) -> Self {
d.0.into()
}
}

impl std::str::FromStr for NonZeroDuration {
type Err = humantime::DurationError;

fn from_str(s: &str) -> Result<Self, Self::Err> {
let duration = NonZeroDuration(s.parse::<humantime::Duration>()?);
if duration.0.is_zero() {
return Err(humantime::DurationError::Empty);
}
Ok(duration)
}
}
16 changes: 10 additions & 6 deletions lightway-client/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use super::route_manager::RouteMode;
use anyhow::{Result, anyhow};
use bytesize::ByteSize;
use clap::Parser;
use lightway_app_utils::args::{Cipher, ConnectionType, Duration, LogLevel};
use lightway_app_utils::args::{Cipher, ConnectionType, Duration, LogLevel, NonZeroDuration};
use lightway_core::{AuthMethod, MAX_OUTSIDE_MTU};
use serde::Serialize;
use std::{net::Ipv4Addr, path::PathBuf};
Expand Down Expand Up @@ -89,17 +89,21 @@ pub struct Config {
pub enable_pqc: bool,

/// Interval between keepalives
#[clap(long, default_value = "0s")]
pub keepalive_interval: Duration,
#[clap(long, default_value = "10s")]
pub keepalive_interval: NonZeroDuration,

/// Keepalive timeout
#[clap(long, default_value = "0s")]
pub keepalive_timeout: Duration,
#[clap(long, default_value = "60s")]
pub keepalive_timeout: NonZeroDuration,

/// Enable continuous Keepalive
#[clap(long, default_value_t = true)]
pub keepalive_continuous: bool,

/// Time it takes to trigger a tracer packet
/// when we haven't received an outside packet
#[clap(long, default_value = "10s")]
pub tracer_packet_timeout: Duration,
pub tracer_packet_timeout: NonZeroDuration,

/// How long to wait before selecting the best connection. If the preferred
/// connection connects before the timeout, it will be used immediately.
Expand Down
Loading
Loading