diff --git a/bin/dnetview/src/main.rs b/bin/dnetview/src/main.rs index ce468eab1..f4bfdfcbc 100644 --- a/bin/dnetview/src/main.rs +++ b/bin/dnetview/src/main.rs @@ -21,7 +21,7 @@ use darkfi::{ util::{ async_util, cli::{log_config, spawn_config, Config}, - join_config_path, + join_config_path, Timestamp, }, }; @@ -281,9 +281,10 @@ async fn parse_inbound(inbound: &Value, node_id: &String) -> DnetViewResult = Vec::new(); + let mut msg_log: Vec<(Timestamp, String, String)> = Vec::new(); for msg in msg_values { - let msg: (u64, String, String) = serde_json::from_value(msg.clone())?; + let msg: (Timestamp, String, String) = + serde_json::from_value(msg.clone())?; msg_log.push(msg); } let is_empty = false; @@ -388,9 +389,10 @@ async fn parse_outbound(outbound: &Value, node_id: &String) -> DnetViewResult = Vec::new(); + let mut msg_log: Vec<(Timestamp, String, String)> = Vec::new(); for msg in msg_values { - let msg: (u64, String, String) = serde_json::from_value(msg.clone())?; + let msg: (Timestamp, String, String) = + serde_json::from_value(msg.clone())?; msg_log.push(msg); } let is_empty = false; diff --git a/bin/dnetview/src/model.rs b/bin/dnetview/src/model.rs index ba829a31f..b56ee7063 100644 --- a/bin/dnetview/src/model.rs +++ b/bin/dnetview/src/model.rs @@ -1,16 +1,16 @@ use async_std::sync::Mutex; - +use darkfi::util::Timestamp; use fxhash::{FxHashMap, FxHashSet}; use serde::{Deserialize, Serialize}; -#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize, Hash)] +#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] pub enum Session { Inbound, Outbound, Manual, } -#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize, Hash)] +#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] pub enum SelectableObject { Node(NodeInfo), Session(SessionInfo), @@ -20,7 +20,7 @@ pub enum SelectableObject { pub struct Model { pub ids: Mutex>, pub nodes: Mutex>, - pub msg_log: Mutex>>, + pub msg_log: Mutex>>, pub selectables: Mutex>, } @@ -28,14 +28,14 @@ impl Model { pub fn new( ids: Mutex>, nodes: Mutex>, - msg_log: Mutex>>, + msg_log: Mutex>>, selectables: Mutex>, ) -> Model { Model { ids, nodes, msg_log, selectables } } } -#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize, Hash)] +#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] pub struct NodeInfo { pub id: String, pub name: String, @@ -54,7 +54,7 @@ impl NodeInfo { } } -#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize, Hash)] +#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] pub struct SessionInfo { pub id: String, pub name: String, @@ -75,13 +75,13 @@ impl SessionInfo { } } -#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize, Hash)] +#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] pub struct ConnectInfo { pub id: String, pub addr: String, pub state: String, pub parent: String, - pub msg_log: Vec<(u64, String, String)>, + pub msg_log: Vec<(Timestamp, String, String)>, pub is_empty: bool, pub last_msg: String, pub last_status: String, @@ -93,7 +93,7 @@ impl ConnectInfo { addr: String, state: String, parent: String, - msg_log: Vec<(u64, String, String)>, + msg_log: Vec<(Timestamp, String, String)>, is_empty: bool, last_msg: String, last_status: String, diff --git a/bin/dnetview/src/view.rs b/bin/dnetview/src/view.rs index 13e7545cf..009e6e08d 100644 --- a/bin/dnetview/src/view.rs +++ b/bin/dnetview/src/view.rs @@ -11,16 +11,18 @@ use tui::{ Frame, }; +use darkfi::util::Timestamp; + use crate::{ error::{DnetViewError, DnetViewResult}, model::{NodeInfo, SelectableObject}, }; -use log::debug; +//use log::debug; #[derive(Debug)] pub struct View { pub nodes: NodeInfoView, - pub msg_log: FxHashMap>, + pub msg_log: FxHashMap>, pub active_ids: IdListView, pub selectables: FxHashMap, } @@ -28,7 +30,7 @@ pub struct View { impl View { pub fn new( nodes: NodeInfoView, - msg_log: FxHashMap>, + msg_log: FxHashMap>, active_ids: IdListView, selectables: FxHashMap, ) -> View { @@ -38,7 +40,7 @@ impl View { pub fn update( &mut self, nodes: FxHashMap, - msg_log: FxHashMap>, + msg_log: FxHashMap>, selectables: FxHashMap, ) { self.update_nodes(nodes); @@ -73,7 +75,7 @@ impl View { } } - fn update_msg_log(&mut self, msg_log: FxHashMap>) { + fn update_msg_log(&mut self, msg_log: FxHashMap>) { for (id, msg) in msg_log { self.msg_log.insert(id, msg); } @@ -209,8 +211,12 @@ impl View { Some(values) => { for (t, k, v) in values { lines.push(Spans::from(match k.as_str() { - "send" => Span::styled(format!("S: {}", v), style), - "recv" => Span::styled(format!("R: {}", v), style), + "send" => { + Span::styled(format!("{} S: {}", t, v), style) + } + "recv" => { + Span::styled(format!("{} R: {}", t, v), style) + } data => { return Err(DnetViewError::UnexpectedData(data.to_string())) } diff --git a/src/net/channel.rs b/src/net/channel.rs index 6f200784d..6950f3bac 100644 --- a/src/net/channel.rs +++ b/src/net/channel.rs @@ -12,7 +12,7 @@ use url::Url; use crate::{ system::{StoppableTask, StoppableTaskPtr, Subscriber, SubscriberPtr, Subscription}, - util::time, + util::Timestamp, Error, Result, }; @@ -30,7 +30,7 @@ struct ChannelInfo { last_msg: String, last_status: String, // Message log which is cleared on querying get_info - log: Mutex>, + log: Mutex>, } impl ChannelInfo { @@ -192,7 +192,8 @@ impl Channel { let mut payload = Vec::new(); message.encode(&mut payload)?; let packet = message::Packet { command: String::from(M::name()), payload }; - let time = time::unix_timestamp()?; + let time = Timestamp::current_time(); + //let time = time::unix_timestamp()?; { let info = &mut *self.info.lock().await; @@ -278,7 +279,8 @@ impl Channel { let info = &mut *self.info.lock().await; info.last_msg = packet.command.clone(); info.last_status = "recv".to_string(); - let time = time::unix_timestamp()?; + let time = Timestamp::current_time(); + //let time = time::unix_timestamp()?; info.log.lock().await.push((time, "recv".to_string(), packet.command.clone())); }