Remove CandidateSet state and add last seen time limit to candidate_set::validate_addrs (#2177)

This commit is contained in:
teor 2021-05-21 12:21:13 +10:00 committed by GitHub
parent 752358d236
commit 2685fc746e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 32 additions and 25 deletions

View File

@ -1,5 +1,6 @@
use std::{cmp::min, mem, sync::Arc, time::Duration}; use std::{cmp::min, mem, sync::Arc, time::Duration};
use chrono::{DateTime, Utc};
use futures::stream::{FuturesUnordered, StreamExt}; use futures::stream::{FuturesUnordered, StreamExt};
use tokio::time::{sleep, sleep_until, timeout, Sleep}; use tokio::time::{sleep, sleep_until, timeout, Sleep};
use tower::{Service, ServiceExt}; use tower::{Service, ServiceExt};
@ -228,7 +229,7 @@ where
?addrs, ?addrs,
"got response to GetPeers" "got response to GetPeers"
); );
let addrs = self.validate_addrs(addrs); let addrs = validate_addrs(addrs, Utc::now());
self.send_addrs(addrs); self.send_addrs(addrs);
} }
Err(e) => { Err(e) => {
@ -243,30 +244,6 @@ where
Ok(()) Ok(())
} }
/// Check new `addrs` before adding them to the address book.
///
/// If the data in an address is invalid, this function can:
/// - modify the address data, or
/// - delete the address.
fn validate_addrs(
&self,
addrs: impl IntoIterator<Item = MetaAddr>,
) -> impl IntoIterator<Item = MetaAddr> {
// Note: The address book handles duplicate addresses internally,
// so we don't need to de-duplicate addresses here.
// TODO:
// We should eventually implement these checks in this function:
// - Zebra should stop believing far-future last_seen times from peers (#1871)
// - Zebra should ignore peers that are older than 3 weeks (part of #1865)
// - Zebra should count back 3 weeks from the newest peer timestamp sent
// by the other peer, to compensate for clock skew
// - Zebra should limit the number of addresses it uses from a single Addrs
// response (#1869)
addrs
}
/// Add new `addrs` to the address book. /// Add new `addrs` to the address book.
fn send_addrs(&self, addrs: impl IntoIterator<Item = MetaAddr>) { fn send_addrs(&self, addrs: impl IntoIterator<Item = MetaAddr>) {
// # Correctness // # Correctness
@ -343,3 +320,33 @@ where
self.address_book.lock().unwrap().update(addr); self.address_book.lock().unwrap().update(addr);
} }
} }
/// Check new `addrs` before adding them to the address book.
///
/// `last_seen_limit` is the maximum permitted last seen time, typically
/// [`Utc::now`].
///
/// If the data in an address is invalid, this function can:
/// - modify the address data, or
/// - delete the address.
//
// TODO: re-enable this lint when last_seen_limit is used
#[allow(unused_variables)]
fn validate_addrs(
addrs: impl IntoIterator<Item = MetaAddr>,
last_seen_limit: DateTime<Utc>,
) -> impl IntoIterator<Item = MetaAddr> {
// Note: The address book handles duplicate addresses internally,
// so we don't need to de-duplicate addresses here.
// TODO:
// We should eventually implement these checks in this function:
// - Zebra should stop believing far-future last_seen times from peers (#1871)
// - Zebra should ignore peers that are older than 3 weeks (part of #1865)
// - Zebra should count back 3 weeks from the newest peer timestamp sent
// by the other peer, to compensate for clock skew
// - Zebra should limit the number of addresses it uses from a single Addrs
// response (#1869)
addrs
}