node: Move timestamp to peer
Signed-off-by: Alexis Sellier <self@cloudhead.io>
This commit is contained in:
parent
e040ea5ec7
commit
90486f3051
|
|
@ -657,8 +657,6 @@ pub struct Context<S, T> {
|
||||||
io: VecDeque<Io<(), DisconnectReason>>,
|
io: VecDeque<Io<(), DisconnectReason>>,
|
||||||
/// Clock. Tells the time.
|
/// Clock. Tells the time.
|
||||||
clock: RefClock,
|
clock: RefClock,
|
||||||
/// Timestamps of known peers.
|
|
||||||
timestamps: HashMap<PeerId, u64>,
|
|
||||||
/// Project storage.
|
/// Project storage.
|
||||||
storage: T,
|
storage: T,
|
||||||
/// Peer address manager.
|
/// Peer address manager.
|
||||||
|
|
@ -682,7 +680,6 @@ where
|
||||||
config,
|
config,
|
||||||
clock,
|
clock,
|
||||||
routing: HashMap::with_hasher(rng.clone().into()),
|
routing: HashMap::with_hasher(rng.clone().into()),
|
||||||
timestamps: HashMap::with_hasher(rng.clone().into()),
|
|
||||||
io: VecDeque::new(),
|
io: VecDeque::new(),
|
||||||
storage,
|
storage,
|
||||||
addrmgr,
|
addrmgr,
|
||||||
|
|
@ -812,6 +809,8 @@ pub struct Peer {
|
||||||
state: PeerState,
|
state: PeerState,
|
||||||
/// Connection direction.
|
/// Connection direction.
|
||||||
link: Link,
|
link: Link,
|
||||||
|
/// Last known peer time.
|
||||||
|
timestamp: Timestamp,
|
||||||
/// Whether we should attempt to re-connect
|
/// Whether we should attempt to re-connect
|
||||||
/// to this peer upon disconnection.
|
/// to this peer upon disconnection.
|
||||||
persistent: bool,
|
persistent: bool,
|
||||||
|
|
@ -828,6 +827,7 @@ impl Peer {
|
||||||
inbox: Decoder::new(256),
|
inbox: Decoder::new(256),
|
||||||
state: PeerState::default(),
|
state: PeerState::default(),
|
||||||
link,
|
link,
|
||||||
|
timestamp: Timestamp::default(),
|
||||||
persistent,
|
persistent,
|
||||||
attempts: 0,
|
attempts: 0,
|
||||||
}
|
}
|
||||||
|
|
@ -885,10 +885,7 @@ impl Peer {
|
||||||
origin,
|
origin,
|
||||||
} => {
|
} => {
|
||||||
let now = ctx.clock.local_time();
|
let now = ctx.clock.local_time();
|
||||||
let last = ctx
|
let last = self.timestamp;
|
||||||
.timestamps
|
|
||||||
.entry(self.id())
|
|
||||||
.or_insert_with(Timestamp::default);
|
|
||||||
|
|
||||||
// Don't allow messages from too far in the past or future.
|
// Don't allow messages from too far in the past or future.
|
||||||
if timestamp.abs_diff(now.as_secs()) > MAX_TIME_DELTA.as_secs() {
|
if timestamp.abs_diff(now.as_secs()) > MAX_TIME_DELTA.as_secs() {
|
||||||
|
|
@ -896,8 +893,8 @@ impl Peer {
|
||||||
}
|
}
|
||||||
// Discard inventory messages we've already seen, otherwise update
|
// Discard inventory messages we've already seen, otherwise update
|
||||||
// out last seen time.
|
// out last seen time.
|
||||||
if timestamp > *last {
|
if timestamp > last {
|
||||||
*last = timestamp;
|
self.timestamp = timestamp;
|
||||||
} else {
|
} else {
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue