diff --git a/common/wireguard-types/src/lib.rs b/common/wireguard-types/src/lib.rs index 3c2cc66951..977ea6bf1d 100644 --- a/common/wireguard-types/src/lib.rs +++ b/common/wireguard-types/src/lib.rs @@ -6,6 +6,8 @@ pub mod error; pub mod public_key; pub mod registration; +use std::time::Duration; + pub use config::Config; pub use error::Error; pub use public_key::PeerPublicKey; @@ -13,5 +15,10 @@ pub use registration::{ ClientMac, ClientMessage, GatewayClient, GatewayClientRegistry, InitMessage, Nonce, }; +// To avoid any problems, keep this stale check time bigger (>2x) then the bandwidth cap +// reset time (currently that one is 24h, at UTC midnight) +pub const DEFAULT_PEER_TIMEOUT: Duration = Duration::from_secs(60 * 60 * 24 * 3); // 3 days +pub const DEFAULT_PEER_TIMEOUT_CHECK: Duration = Duration::from_secs(5); // 5 seconds + #[cfg(feature = "verify")] pub use registration::HmacSha256; diff --git a/common/wireguard/src/peer_controller.rs b/common/wireguard/src/peer_controller.rs index 6b6bc3f33c..ff40ce5f7b 100644 --- a/common/wireguard/src/peer_controller.rs +++ b/common/wireguard/src/peer_controller.rs @@ -4,19 +4,15 @@ use chrono::{Timelike, Utc}; use defguard_wireguard_rs::{host::Peer, key::Key, WireguardInterfaceApi}; use nym_wireguard_types::registration::{RemainingBandwidthData, BANDWIDTH_CAP_PER_DAY}; +use nym_wireguard_types::{DEFAULT_PEER_TIMEOUT, DEFAULT_PEER_TIMEOUT_CHECK}; use std::time::SystemTime; -use std::{collections::HashMap, sync::Arc, time::Duration}; +use std::{collections::HashMap, sync::Arc}; use tokio::sync::mpsc; use tokio_stream::{wrappers::IntervalStream, StreamExt}; use crate::error::Error; use crate::WgApiWrapper; -// To avoid any problems, keep this stale check time bigger (>2x) then the bandwidth cap -// reset time (currently that one is 24h, at UTC midnight) -const DEFAULT_PEER_TIMEOUT: Duration = Duration::from_secs(60 * 60 * 24 * 3); // 3 days -const DEFAULT_PEER_TIMEOUT_CHECK: Duration = Duration::from_secs(5); // 5 seconds - pub enum PeerControlRequest { AddPeer(Peer), RemovePeer(Key),