mirror of
https://github.com/mimblewimble/grin.git
synced 2025-01-21 03:21:08 +03:00
Add last_seen to peer info (#1688)
* add last_seen to peer and update on ping/pong expose last_seen in tui * rustfmt * chrono serde features
This commit is contained in:
parent
fd2eda2308
commit
de5b6868fb
6 changed files with 25 additions and 27 deletions
|
@ -16,7 +16,7 @@ rand = "0.5"
|
|||
serde = "1"
|
||||
serde_derive = "1"
|
||||
slog = { version = "~2.3", features = ["max_level_trace", "release_max_level_trace"] }
|
||||
chrono = "0.4.4"
|
||||
chrono = { version = "0.4.4", features = ["serde"] }
|
||||
|
||||
grin_core = { path = "../core" }
|
||||
grin_store = { path = "../store" }
|
||||
|
|
|
@ -16,6 +16,7 @@ use std::collections::VecDeque;
|
|||
use std::net::{SocketAddr, TcpStream};
|
||||
use std::sync::{Arc, RwLock};
|
||||
|
||||
use chrono::prelude::*;
|
||||
use rand::{thread_rng, Rng};
|
||||
|
||||
use core::core::hash::Hash;
|
||||
|
@ -100,6 +101,7 @@ impl Handshake {
|
|||
total_difficulty: shake.total_difficulty,
|
||||
height: 0,
|
||||
direction: Direction::Outbound,
|
||||
last_seen: Utc::now(),
|
||||
};
|
||||
|
||||
// If denied then we want to close the connection
|
||||
|
@ -156,6 +158,7 @@ impl Handshake {
|
|||
total_difficulty: hand.total_difficulty,
|
||||
height: 0,
|
||||
direction: Direction::Inbound,
|
||||
last_seen: Utc::now(),
|
||||
};
|
||||
|
||||
// At this point we know the published ip and port of the peer
|
||||
|
|
|
@ -19,7 +19,7 @@ use std::sync::{Arc, RwLock};
|
|||
|
||||
use rand::{thread_rng, Rng};
|
||||
|
||||
use chrono::prelude::Utc;
|
||||
use chrono::prelude::*;
|
||||
use core::core;
|
||||
use core::core::hash::{Hash, Hashed};
|
||||
use core::pow::Difficulty;
|
||||
|
@ -644,29 +644,11 @@ impl NetAdapter for Peers {
|
|||
}
|
||||
|
||||
fn peer_difficulty(&self, addr: SocketAddr, diff: Difficulty, height: u64) {
|
||||
if diff != self.total_difficulty() || height != self.total_height() {
|
||||
trace!(
|
||||
LOGGER,
|
||||
"ping/pong: {}: {} @ {} vs us: {} @ {}",
|
||||
addr,
|
||||
diff,
|
||||
height,
|
||||
self.total_difficulty(),
|
||||
self.total_height()
|
||||
);
|
||||
}
|
||||
|
||||
if let Some(peer) = self.get_connected_peer(&addr) {
|
||||
let (prev_diff, prev_height) = {
|
||||
let peer = peer.read().unwrap();
|
||||
(peer.info.total_difficulty, peer.info.height)
|
||||
};
|
||||
|
||||
if diff != prev_diff || height != prev_height {
|
||||
let mut peer = peer.write().unwrap();
|
||||
peer.info.total_difficulty = diff;
|
||||
peer.info.height = height;
|
||||
}
|
||||
let mut peer = peer.write().unwrap();
|
||||
peer.info.total_difficulty = diff;
|
||||
peer.info.height = height;
|
||||
peer.info.last_seen = Utc::now();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -18,6 +18,8 @@ use std::io;
|
|||
use std::net::{IpAddr, SocketAddr};
|
||||
use std::sync::mpsc;
|
||||
|
||||
use chrono::prelude::*;
|
||||
|
||||
use core::core::hash::Hash;
|
||||
use core::pow::Difficulty;
|
||||
use core::{core, ser};
|
||||
|
@ -243,6 +245,7 @@ pub struct PeerInfo {
|
|||
pub total_difficulty: Difficulty,
|
||||
pub height: u64,
|
||||
pub direction: Direction,
|
||||
pub last_seen: DateTime<Utc>,
|
||||
}
|
||||
|
||||
/// The full txhashset data along with indexes required for a consumer to
|
||||
|
|
|
@ -19,6 +19,8 @@ use std::sync::atomic::AtomicBool;
|
|||
use std::sync::{Arc, RwLock};
|
||||
use std::time::SystemTime;
|
||||
|
||||
use chrono::prelude::*;
|
||||
|
||||
use chain;
|
||||
use common::types::SyncStatus;
|
||||
use p2p;
|
||||
|
@ -144,6 +146,8 @@ pub struct PeerStats {
|
|||
pub height: u64,
|
||||
/// direction
|
||||
pub direction: String,
|
||||
/// Last time we saw a ping/pong from this peer.
|
||||
pub last_seen: DateTime<Utc>,
|
||||
}
|
||||
|
||||
impl StratumStats {
|
||||
|
@ -176,6 +180,7 @@ impl PeerStats {
|
|||
total_difficulty: peer.info.total_difficulty.to_num(),
|
||||
height: peer.info.height,
|
||||
direction: direction.to_string(),
|
||||
last_seen: peer.info.last_seen,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,8 @@ use std::cmp::Ordering;
|
|||
|
||||
use servers::{PeerStats, ServerStats};
|
||||
|
||||
use chrono::prelude::*;
|
||||
|
||||
use cursive::direction::Orientation;
|
||||
use cursive::traits::{Boxable, Identifiable};
|
||||
use cursive::view::View;
|
||||
|
@ -54,9 +56,12 @@ impl TableViewItem<PeerColumn> for PeerStats {
|
|||
match column {
|
||||
PeerColumn::Address => self.addr.clone(),
|
||||
PeerColumn::State => self.state.clone(),
|
||||
PeerColumn::TotalDifficulty => {
|
||||
format!("{} D @ {} H", self.total_difficulty, self.height).to_string()
|
||||
}
|
||||
PeerColumn::TotalDifficulty => format!(
|
||||
"{} D @ {} H ({}s)",
|
||||
self.total_difficulty,
|
||||
self.height,
|
||||
(Utc::now() - self.last_seen).num_seconds(),
|
||||
).to_string(),
|
||||
PeerColumn::Direction => self.direction.clone(),
|
||||
PeerColumn::Version => self.version.to_string(),
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue