feat(explorer-api): use mixnode port in ip lookup

This commit is contained in:
pierre
2022-10-26 12:23:33 +02:00
parent cb1e93e58d
commit cf10bb12ef
3 changed files with 10 additions and 6 deletions
@@ -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);
+5 -4
View File
@@ -57,21 +57,22 @@ impl GeoIp {
GeoIp { db: reader }
}
pub fn query(&self, address: &str) -> Result<Option<Location>, GeoIpError> {
pub fn query(&self, address: &str, port: Option<u16>) -> Result<Option<Location>, 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())
+1 -1
View File
@@ -39,7 +39,7 @@ fn find_location(request: &Request<'_>) -> Result<Location, (Status, LocationErr
let location = geo_ip
.0
.clone()
.query(&ip)
.query(&ip, None)
.map_err(|e| match e {
GeoIpError::NoValidIP => (Status::Forbidden, LocationError::NoIP),
GeoIpError::InternalError => {