Respect external ip config

This commit is contained in:
Edward Shen 2021-07-15 00:54:31 -04:00
parent acf6dc1cb1
commit 6415c3dee6
Signed by: edward
GPG key ID: 19182661E818369F
2 changed files with 12 additions and 3 deletions

View file

@ -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<String>,
ip_address: Option<IpAddr>,
}
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),
}
}
}

View file

@ -13,7 +13,6 @@ impl Port {
self.0.get()
}
#[cfg(test)]
pub fn new(amt: u16) -> Option<Self> {
NonZeroU16::new(amt).map(Self)
}