diff options
author | Alex Auvolat <alex@adnab.me> | 2023-03-09 13:12:47 +0100 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2023-03-09 13:12:47 +0100 |
commit | 67280bd8613d96b6edd82c9c685ae29b4d27896a (patch) | |
tree | 9d817b3a1044691aa6dba587bb34cc526b585cca | |
parent | 0407ca9387b0906e8091762c0eff52210f0c99f5 (diff) | |
download | wgautomesh-67280bd8613d96b6edd82c9c685ae29b4d27896a.tar.gz wgautomesh-67280bd8613d96b6edd82c9c685ae29b4d27896a.zip |
fix logic
-rw-r--r-- | src/main.rs | 10 |
1 files changed, 5 insertions, 5 deletions
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::<Vec<_>>(); @@ -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, |