From cf10bb12efd3dcc3d3a905cdfabbced38d730176 Mon Sep 17 00:00:00 2001 From: pierre Date: Wed, 26 Oct 2022 12:23:33 +0200 Subject: [PATCH] feat(explorer-api): use mixnode port in ip lookup --- explorer-api/src/country_statistics/geolocate.rs | 5 ++++- explorer-api/src/geo_ip/location.rs | 9 +++++---- explorer-api/src/guards/location.rs | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/explorer-api/src/country_statistics/geolocate.rs b/explorer-api/src/country_statistics/geolocate.rs index 60603a2aaf..42fe9405be 100644 --- a/explorer-api/src/country_statistics/geolocate.rs +++ b/explorer-api/src/country_statistics/geolocate.rs @@ -58,7 +58,10 @@ impl GeoLocateTask { continue; } - match geo_ip.query(&cache_item.mix_node().host) { + match geo_ip.query( + &cache_item.mix_node().host, + Some(cache_item.mix_node().mix_port), + ) { Ok(opt) => match opt { Some(location) => { let location = Location::new(location); diff --git a/explorer-api/src/geo_ip/location.rs b/explorer-api/src/geo_ip/location.rs index 65f7edc120..ba75d4e52c 100644 --- a/explorer-api/src/geo_ip/location.rs +++ b/explorer-api/src/geo_ip/location.rs @@ -57,21 +57,22 @@ impl GeoIp { GeoIp { db: reader } } - pub fn query(&self, address: &str) -> Result, GeoIpError> { + pub fn query(&self, address: &str, port: Option) -> Result, GeoIpError> { let ip: IpAddr = FromStr::from_str(address).or_else(|_| { warn!( "Fail to create IpAddr from {}. Trying using internal lookup...", &address ); - let socket_addr = (address, FAKE_PORT) + let p = port.unwrap_or(FAKE_PORT); + let socket_addr = (address, p) .to_socket_addrs() .map_err(|e| { - error!("Fail to resolve IP address from {}: {}", &address, e); + error!("Fail to resolve IP address from {}:{}: {}", &address, p, e); GeoIpError::NoValidIP })? .next() .ok_or_else(|| { - error!("Fail to resolve IP address from {}", &address); + error!("Fail to resolve IP address from {}:{}", &address, p); GeoIpError::NoValidIP })?; Ok(socket_addr.ip()) diff --git a/explorer-api/src/guards/location.rs b/explorer-api/src/guards/location.rs index dd1bfe1ff8..23bb92d941 100644 --- a/explorer-api/src/guards/location.rs +++ b/explorer-api/src/guards/location.rs @@ -39,7 +39,7 @@ fn find_location(request: &Request<'_>) -> Result (Status::Forbidden, LocationError::NoIP), GeoIpError::InternalError => {