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 <teor@riseup.net>
This commit is contained in:
parent
fa35c9b4f1
commit
9eac43a8bb
|
@ -366,18 +366,17 @@ fn validate_addrs(
|
||||||
///
|
///
|
||||||
/// If the `addrs` list is empty.
|
/// If the `addrs` list is empty.
|
||||||
fn limit_last_seen_times(addrs: &mut Vec<MetaAddr>, last_seen_limit: DateTime32) {
|
fn limit_last_seen_times(addrs: &mut Vec<MetaAddr>, last_seen_limit: DateTime32) {
|
||||||
let most_recent_reported_seen_time = addrs
|
let most_recent_reported_seen_timestamp = addrs
|
||||||
.iter()
|
.iter()
|
||||||
.map(|addr| addr.get_last_seen())
|
.map(|addr| addr.get_last_seen().timestamp())
|
||||||
.max()
|
.max()
|
||||||
.expect("unexpected empty address list");
|
.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 {
|
for addr in addrs {
|
||||||
let old_last_seen = addr.get_last_seen().timestamp();
|
let old_last_seen = addr.get_last_seen().timestamp();
|
||||||
|
|
||||||
if old_last_seen > last_seen_limit.timestamp() {
|
|
||||||
let new_last_seen = old_last_seen - offset;
|
let new_last_seen = old_last_seen - offset;
|
||||||
|
|
||||||
addr.set_last_seen(new_last_seen.into());
|
addr.set_last_seen(new_last_seen.into());
|
||||||
|
|
Loading…
Reference in New Issue