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:
@@ -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
|
||||
|
||||
+5
-23
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user