From 9eac43a8bb83aa2bdeae02916a751da0e8cdd7a4 Mon Sep 17 00:00:00 2001 From: Janito Vaqueiro Ferreira Filho Date: Mon, 24 May 2021 17:20:06 -0300 Subject: [PATCH] Apply offset to all times received from a peer If any of the times gossiped by a peer are in the future, apply the necessary offset to all the times gossiped by that peer. This ensures that all gossiped peers from a malicious peer are moved further back in the queue. Co-authored-by: teor --- zebra-network/src/peer_set/candidate_set.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/zebra-network/src/peer_set/candidate_set.rs b/zebra-network/src/peer_set/candidate_set.rs index ea4d00b7..fcf1ee9a 100644 --- a/zebra-network/src/peer_set/candidate_set.rs +++ b/zebra-network/src/peer_set/candidate_set.rs @@ -366,18 +366,17 @@ fn validate_addrs( /// /// If the `addrs` list is empty. fn limit_last_seen_times(addrs: &mut Vec, last_seen_limit: DateTime32) { - let most_recent_reported_seen_time = addrs + let most_recent_reported_seen_timestamp = addrs .iter() - .map(|addr| addr.get_last_seen()) + .map(|addr| addr.get_last_seen().timestamp()) .max() .expect("unexpected empty address list"); - let offset = most_recent_reported_seen_time.timestamp() - last_seen_limit.timestamp(); + if most_recent_reported_seen_timestamp > last_seen_limit.timestamp() { + let offset = most_recent_reported_seen_timestamp - last_seen_limit.timestamp(); - for addr in addrs { - let old_last_seen = addr.get_last_seen().timestamp(); - - if old_last_seen > last_seen_limit.timestamp() { + for addr in addrs { + let old_last_seen = addr.get_last_seen().timestamp(); let new_last_seen = old_last_seen - offset; addr.set_last_seen(new_last_seen.into());