diff --git a/src/ping.rs b/src/ping.rs index 4f1af43..768917d 100644 --- a/src/ping.rs +++ b/src/ping.rs @@ -1,3 +1,4 @@ +use std::net::{IpAddr, SocketAddr}; use std::sync::atomic::Ordering; use std::{io::BufReader, sync::Arc}; @@ -29,19 +30,24 @@ pub struct Request<'a> { network_speed: BytesPerSecond, build_version: usize, tls_created_at: Option, + ip_address: Option, } impl<'a> Request<'a> { fn from_config_and_state(secret: &'a ClientSecret, config: &Config) -> Self { Self { secret, - port: config.port, + port: config + .external_address + .and_then(|v| Port::new(v.port())) + .unwrap_or(config.port), disk_space: config.disk_quota, network_speed: config.network_speed.into(), build_version: CLIENT_API_VERSION, tls_created_at: TLS_PREVIOUSLY_CREATED .get() .map(|v| v.load().as_ref().clone()), + ip_address: config.external_address.as_ref().map(SocketAddr::ip), } } } @@ -50,11 +56,15 @@ impl<'a> From<(&'a ClientSecret, &Config)> for Request<'a> { fn from((secret, config): (&'a ClientSecret, &Config)) -> Self { Self { secret, - port: config.port, + port: config + .external_address + .and_then(|v| Port::new(v.port())) + .unwrap_or(config.port), disk_space: config.disk_quota, network_speed: config.network_speed.into(), build_version: CLIENT_API_VERSION, tls_created_at: None, + ip_address: config.external_address.as_ref().map(SocketAddr::ip), } } } diff --git a/src/units.rs b/src/units.rs index a1c77df..510c29c 100644 --- a/src/units.rs +++ b/src/units.rs @@ -13,7 +13,6 @@ impl Port { self.0.get() } - #[cfg(test)] pub fn new(amt: u16) -> Option { NonZeroU16::new(amt).map(Self) }