Use startup_time from system.connected (#300)

* Handle startup time

* Remove dead code

* Bump protocol version + FE changes
This commit is contained in:
Maciej Hirsz
2020-11-30 12:05:49 +01:00
committed by GitHub
parent ebb01c1a7d
commit 262dbd6f14
11 changed files with 27 additions and 27 deletions
+1 -1
View File
@@ -290,7 +290,7 @@ impl Handler<Connect> for Aggregator {
connector.do_send(Connected(fid));
self.serializer.push(feed::Version(30));
self.serializer.push(feed::Version(31));
// TODO: keep track on number of nodes connected to each chain
for (_, entry) in self.chains.iter() {
+1 -1
View File
@@ -172,7 +172,7 @@ impl Serialize for AddedNode<'_> {
tup.serialize_element(node.hardware())?;
tup.serialize_element(node.block_details())?;
tup.serialize_element(&node.location())?;
tup.serialize_element(&node.connected_at())?;
tup.serialize_element(&node.startup_time())?;
tup.end()
}
}
+10 -7
View File
@@ -33,16 +33,19 @@ pub struct Node {
location: Option<Arc<NodeLocation>>,
/// Flag marking if the node is stale (not syncing or producing blocks)
stale: bool,
/// Connected at timestamp
connected_at: Timestamp,
/// Unix timestamp for when node started up (falls back to connection time)
startup_time: Option<Timestamp>,
/// Network state
network_state: Option<Bytes>,
}
impl Node {
pub fn new(details: NodeDetails) -> Self {
Node {
pub fn new(mut details: NodeDetails) -> Self {
let startup_time = details.startup_time
.take()
.and_then(|time| time.parse().ok());
Node {
details,
stats: NodeStats::default(),
io: NodeIO::default(),
@@ -52,7 +55,7 @@ impl Node {
hardware: NodeHardware::default(),
location: None,
stale: false,
connected_at: now(),
startup_time,
network_state: None,
}
}
@@ -230,7 +233,7 @@ impl Node {
}
}
pub fn connected_at(&self) -> Timestamp {
self.connected_at
pub fn startup_time(&self) -> Option<Timestamp> {
self.startup_time
}
}
-1
View File
@@ -161,7 +161,6 @@ impl StreamHandler<Result<ws::Message, ws::ProtocolError>> for NodeConnector {
match serde_json::from_slice(&data) {
Ok(msg) => {
// info!("New node message: {}", std::str::from_utf8(&data).unwrap_or_else(|_| "INVALID UTF8"));
self.handle_message(msg, data, ctx)
},
#[cfg(debug)]
-7
View File
@@ -8,18 +8,11 @@ use crate::types::{Block, BlockNumber, BlockHash};
#[derive(Deserialize, Debug, Message)]
#[rtype(result = "()")]
pub struct NodeMessage {
pub level: Level,
pub ts: DateTime<Utc>,
#[serde(flatten)]
pub details: Details,
}
#[derive(Deserialize, Debug)]
pub enum Level {
#[serde(rename = "INFO")]
Info,
}
#[derive(Deserialize, Debug)]
#[serde(tag = "msg")]
pub enum Details {
+1
View File
@@ -17,6 +17,7 @@ pub struct NodeDetails {
pub version: Box<str>,
pub validator: Option<Box<str>>,
pub network_id: Option<Box<str>>,
pub startup_time: Option<Box<str>>,
}
#[derive(Deserialize, Debug, Clone, Copy, PartialEq, Eq, Default)]