diff --git a/Cargo.lock b/Cargo.lock index 6d420466..2e0072e3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1326,7 +1326,7 @@ dependencies = [ [[package]] name = "g3-ip-locate" -version = "0.2.0" +version = "0.3.0" dependencies = [ "anyhow", "g3-geoip-types", @@ -1334,7 +1334,6 @@ dependencies = [ "g3-socket", "g3-types", "g3-yaml", - "ip_network", "ip_network_table", "log", "rmpv", diff --git a/Cargo.toml b/Cargo.toml index 464e1202..14e778f2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -216,7 +216,7 @@ g3-icap-client = { version = "0.4", path = "lib/g3-icap-client" } g3-imap-proto = { version = "0.3", path = "lib/g3-imap-proto" } g3-io-ext = { version = "0.9", path = "lib/g3-io-ext" } g3-io-sys = { version = "0.1", path = "lib/g3-io-sys" } -g3-ip-locate = { version = "0.2", path = "lib/g3-ip-locate" } +g3-ip-locate = { version = "0.3", path = "lib/g3-ip-locate" } g3-journal = { version = "0.3", path = "lib/g3-journal" } g3-json = { version = "0.4", path = "lib/g3-json" } g3-macros = { version = "0.1", path = "lib/g3-macros" } diff --git a/lib/g3-ip-locate/Cargo.toml b/lib/g3-ip-locate/Cargo.toml index 9f9a7b3d..16e2aa16 100644 --- a/lib/g3-ip-locate/Cargo.toml +++ b/lib/g3-ip-locate/Cargo.toml @@ -1,13 +1,13 @@ [package] name = "g3-ip-locate" -version = "0.2.0" +version = "0.3.0" license.workspace = true edition.workspace = true +rust-version.workspace = true [dependencies] anyhow.workspace = true log.workspace = true -ip_network.workspace = true ip_network_table.workspace = true tokio = { workspace = true, features = ["sync", "net", "rt"] } tokio-util = { workspace = true, features = ["time"] } diff --git a/lib/g3-ip-locate/src/cache.rs b/lib/g3-ip-locate/src/cache.rs index 87de7130..bebb111c 100644 --- a/lib/g3-ip-locate/src/cache.rs +++ b/lib/g3-ip-locate/src/cache.rs @@ -55,11 +55,11 @@ impl IpLocationCacheRuntime { let net = location.network_addr(); let location = Arc::new(location); - if let Some(ip) = ip { - if let Some(vec) = self.doing.remove(&ip) { - for req in vec.into_iter() { - let _ = req.notifier.send(location.clone()); - } + if let Some(ip) = ip + && let Some(vec) = self.doing.remove(&ip) + { + for req in vec.into_iter() { + let _ = req.notifier.send(location.clone()); } } @@ -73,11 +73,11 @@ impl IpLocationCacheRuntime { ); } else if let Some(ip) = ip { // if no new value found, just use the old expired value - if let Some((_net, v)) = self.cache.longest_match(ip) { - if let Some(vec) = self.doing.remove(&ip) { - for req in vec.into_iter() { - let _ = req.notifier.send(v.location.clone()); - } + if let Some((_net, v)) = self.cache.longest_match(ip) + && let Some(vec) = self.doing.remove(&ip) + { + for req in vec.into_iter() { + let _ = req.notifier.send(v.location.clone()); } } } @@ -91,11 +91,11 @@ impl IpLocationCacheRuntime { } fn handle_req(&mut self, req: CacheQueryRequest) { - if let Some((_net, v)) = self.cache.longest_match(req.ip) { - if v.valid_before >= Instant::now() { - let _ = req.notifier.send(v.location.clone()); - return; - } + if let Some((_net, v)) = self.cache.longest_match(req.ip) + && v.valid_before >= Instant::now() + { + let _ = req.notifier.send(v.location.clone()); + return; } match self.doing.entry(req.ip) { diff --git a/lib/g3-ip-locate/src/handle.rs b/lib/g3-ip-locate/src/handle.rs index 091a7f7b..9a6110d6 100644 --- a/lib/g3-ip-locate/src/handle.rs +++ b/lib/g3-ip-locate/src/handle.rs @@ -98,12 +98,11 @@ impl IpLocationQueryHandle { data: IpLocationCacheResponse, expired: bool, ) { - if let Some(ip) = ip { - if let Some(timeout_key) = self.doing_cache.remove(&ip) { - if !expired { - self.doing_timeout_queue.remove(&timeout_key); - } - } + if let Some(ip) = ip + && let Some(timeout_key) = self.doing_cache.remove(&ip) + && !expired + { + self.doing_timeout_queue.remove(&timeout_key); } let _ = self.rsp_sender.send((ip, data)); }