fix logic

This commit is contained in:
Alex 2023-03-09 13:12:47 +01:00
parent 0407ca9387
commit 67280bd861

View file

@ -232,12 +232,12 @@ impl Daemon {
.iter() .iter()
.filter_map(|(pk, info)| info.endpoint.map(|ip| (pk, ip, info.last_seen))) .filter_map(|(pk, info)| info.endpoint.map(|ip| (pk, ip, info.last_seen)))
.filter(|(pk, ip, last_seen)| { .filter(|(pk, ip, last_seen)| {
!state state
.gossip .gossip
.get(pk.as_str()) .get(pk.as_str())
.unwrap_or(&vec![]) .unwrap_or(&vec![])
.iter() .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)])) .map(|(pk, ip, last_seen)| (pk.to_string(), vec![(ip, last_seen)]))
.collect::<Vec<_>>(); .collect::<Vec<_>>();
@ -380,9 +380,9 @@ impl State {
Some(existing) => { Some(existing) => {
let mut has_new = false; let mut has_new = false;
for (new_addr, new_t) in endpoints { for (new_addr, new_t) in endpoints {
if !existing if existing
.iter() .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.retain(|(addr, _)| *addr != new_addr);
existing.push((new_addr, new_t)); existing.push((new_addr, new_t));
@ -390,7 +390,7 @@ impl State {
} }
} }
if has_new { if has_new {
existing.sort_by_key(|(_, t)| *t); existing.sort_by_key(|(_, t)| -(*t as i64));
existing.truncate(KEEP_MAX_ADDRESSES); existing.truncate(KEEP_MAX_ADDRESSES);
Some(Gossip::Announce { Some(Gossip::Announce {
pubkey, pubkey,