Add peer count data to TimestampData::update trace (#66)
* Add peer count data to TimestampData::update trace * Update docstring typo
This commit is contained in:
parent
ae1a164ff8
commit
b45efbdaf2
|
|
@ -1,8 +1,14 @@
|
||||||
//! Definitions of constants.
|
//! Definitions of constants.
|
||||||
|
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
// XXX should these constants be split into protocol also?
|
// XXX should these constants be split into protocol also?
|
||||||
use crate::protocol::types::*;
|
use crate::protocol::types::*;
|
||||||
|
|
||||||
|
/// We expect to receive a message from a live peer at least once in this time duration.
|
||||||
|
/// XXX this needs to be synchronized with the ping transmission times.
|
||||||
|
pub const LIVE_PEER_DURATION: Duration = Duration::from_secs(12);
|
||||||
|
|
||||||
/// The User-Agent string provided by the node.
|
/// The User-Agent string provided by the node.
|
||||||
pub const USER_AGENT: &'static str = "🦓Zebra v2.0.0-alpha.0🦓";
|
pub const USER_AGENT: &'static str = "🦓Zebra v2.0.0-alpha.0🦓";
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,8 @@ use chrono::{DateTime, Utc};
|
||||||
use futures::channel::mpsc;
|
use futures::channel::mpsc;
|
||||||
use tokio::prelude::*;
|
use tokio::prelude::*;
|
||||||
|
|
||||||
|
use crate::constants;
|
||||||
|
|
||||||
/// A type alias for a timestamp event sent to a `TimestampCollector`.
|
/// A type alias for a timestamp event sent to a `TimestampCollector`.
|
||||||
pub(crate) type PeerLastSeen = (SocketAddr, DateTime<Utc>);
|
pub(crate) type PeerLastSeen = (SocketAddr, DateTime<Utc>);
|
||||||
|
|
||||||
|
|
@ -38,9 +40,23 @@ struct TimestampData {
|
||||||
|
|
||||||
impl TimestampData {
|
impl TimestampData {
|
||||||
fn update(&mut self, event: PeerLastSeen) {
|
fn update(&mut self, event: PeerLastSeen) {
|
||||||
|
use chrono::Duration as CD;
|
||||||
use std::collections::hash_map::Entry;
|
use std::collections::hash_map::Entry;
|
||||||
let (addr, timestamp) = event;
|
let (addr, timestamp) = event;
|
||||||
trace!(?addr, ?timestamp);
|
trace!(
|
||||||
|
?addr,
|
||||||
|
?timestamp,
|
||||||
|
data.total = self.by_time.len(),
|
||||||
|
// This would be cleaner if it used "variables" but keeping
|
||||||
|
// it inside the trace! invocation prevents running the range
|
||||||
|
// query unless the output will actually be used.
|
||||||
|
data.recent = self
|
||||||
|
.by_time
|
||||||
|
.range(
|
||||||
|
(Utc::now() - CD::from_std(constants::LIVE_PEER_DURATION).unwrap())..Utc::now()
|
||||||
|
)
|
||||||
|
.count()
|
||||||
|
);
|
||||||
match self.by_addr.entry(addr) {
|
match self.by_addr.entry(addr) {
|
||||||
Entry::Occupied(mut entry) => {
|
Entry::Occupied(mut entry) => {
|
||||||
let last_timestamp = entry.get();
|
let last_timestamp = entry.get();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue