From 67280bd8613d96b6edd82c9c685ae29b4d27896a Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Thu, 9 Mar 2023 13:12:47 +0100 Subject: fix logic --- src/main.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index 3c5df47..6eb5171 100644 --- a/src/main.rs +++ b/src/main.rs @@ -232,12 +232,12 @@ impl Daemon { .iter() .filter_map(|(pk, info)| info.endpoint.map(|ip| (pk, ip, info.last_seen))) .filter(|(pk, ip, last_seen)| { - !state + state .gossip .get(pk.as_str()) .unwrap_or(&vec![]) .iter() - .any(|(a, t)| a == ip && *last_seen > t + GOSSIP_INTERVAL.as_secs()) + .all(|(a, t)| a != ip || *last_seen > t + GOSSIP_INTERVAL.as_secs()) }) .map(|(pk, ip, last_seen)| (pk.to_string(), vec![(ip, last_seen)])) .collect::>(); @@ -380,9 +380,9 @@ impl State { Some(existing) => { let mut has_new = false; for (new_addr, new_t) in endpoints { - if !existing + if existing .iter() - .any(|(addr, t)| *addr == new_addr && *t >= new_t) + .all(|(addr, t)| *addr != new_addr || *t < new_t) { existing.retain(|(addr, _)| *addr != new_addr); existing.push((new_addr, new_t)); @@ -390,7 +390,7 @@ impl State { } } if has_new { - existing.sort_by_key(|(_, t)| *t); + existing.sort_by_key(|(_, t)| -(*t as i64)); existing.truncate(KEEP_MAX_ADDRESSES); Some(Gossip::Announce { pubkey, -- cgit v1.2.3