-
Notifications
You must be signed in to change notification settings - Fork 234
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- validate entries don't spam the logs
- Loading branch information
1 parent
700cd16
commit 89746e7
Showing
2 changed files
with
49 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
// Copyright 2022 - Nym Technologies SA <[email protected]> | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use crate::helpers::{append_ip_to_file, ip_exists_in_file}; | ||
use isocountry::CountryCode; | ||
use log::warn; | ||
use maxminddb::{geoip2::City, MaxMindDBError, Reader}; | ||
|
@@ -78,20 +79,28 @@ impl GeoIp { | |
&address | ||
); | ||
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, p, e); | ||
GeoIpError::NoValidIP | ||
})? | ||
.next() | ||
.ok_or_else(|| { | ||
debug!("Fail to resolve IP address from {}:{}", &address, p); | ||
GeoIpError::NoValidIP | ||
})?; | ||
let ip = socket_addr.ip(); | ||
debug!("Internal lookup succeed, resolved ip: {}", ip); | ||
Ok(ip) | ||
match (address, p).to_socket_addrs() { | ||
Ok(mut addrs) => { | ||
if let Some(socket_addr) = addrs.next() { | ||
let ip = socket_addr.ip(); | ||
debug!("Internal lookup succeeded, resolved ip: {}", ip); | ||
Ok(ip) | ||
} else { | ||
debug!("Fail to resolve IP address from {}:{}", &address, p); | ||
if !ip_exists_in_file(address) { | ||
append_ip_to_file(address); | ||
} | ||
Err(GeoIpError::NoValidIP) | ||
} | ||
} | ||
Err(_) => { | ||
debug!("Fail to resolve IP address from {}:{}.", &address, p); | ||
if !ip_exists_in_file(address) { | ||
append_ip_to_file(address); | ||
} | ||
Err(GeoIpError::NoValidIP) | ||
} | ||
} | ||
})?; | ||
let result = self | ||
.db | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters