diff --git a/bin/dnetview/src/main.rs b/bin/dnetview/src/main.rs index f27d5c34e..6c7f827d2 100644 --- a/bin/dnetview/src/main.rs +++ b/bin/dnetview/src/main.rs @@ -33,6 +33,8 @@ use dnetview::{ view::{IdListView, NodeInfoView, View}, }; +use log::debug; + struct DnetView { name: String, rpc_client: RpcClient, @@ -167,8 +169,16 @@ async fn parse_offline(client: &DnetView, model: Arc) -> DnetViewResult<( let is_empty = true; let last_msg = "Null".to_string(); let last_status = "Null".to_string(); - let connect_info = - ConnectInfo::new(id, addr, state, parent.clone(), msg_log, is_empty, last_msg, last_status); + let connect_info = ConnectInfo::new( + id, + addr, + state.clone(), + parent.clone(), + msg_log, + is_empty, + last_msg, + last_status, + ); connects.push(connect_info.clone()); let accept_addr = None; @@ -176,7 +186,14 @@ async fn parse_offline(client: &DnetView, model: Arc) -> DnetViewResult<( SessionInfo::new(session_id, name, is_empty, parent.clone(), connects, accept_addr); sessions.push(session_info); - let node = NodeInfo::new(node_id.clone(), node_name.to_string(), sessions.clone(), None, true); + let node = NodeInfo::new( + node_id.clone(), + node_name.to_string(), + state.clone(), + sessions.clone(), + None, + true, + ); update_node(model.clone(), node.clone(), node_id.clone()).await; update_selectable_and_ids(model.clone(), sessions, node.clone()).await?; @@ -192,6 +209,7 @@ async fn parse_data( let inbound = &reply["session_inbound"]; let _manual = &reply["session_manual"]; let outbound = &reply["session_outbound"]; + let state = &reply["state"]; let mut sessions: Vec = Vec::new(); @@ -208,8 +226,14 @@ async fn parse_data( sessions.push(out_session.clone()); //sessions.push(man_session.clone()); - let node = - NodeInfo::new(node_id.clone(), node_name.to_string(), sessions.clone(), ext_addr, false); + let node = NodeInfo::new( + node_id.clone(), + node_name.to_string(), + state.as_str().unwrap().to_string(), + sessions.clone(), + ext_addr, + false, + ); update_node(model.clone(), node.clone(), node_id.clone()).await; update_selectable_and_ids(model.clone(), sessions.clone(), node.clone()).await?; diff --git a/bin/dnetview/src/model.rs b/bin/dnetview/src/model.rs index f0dff4d47..32bc84ebd 100644 --- a/bin/dnetview/src/model.rs +++ b/bin/dnetview/src/model.rs @@ -44,6 +44,7 @@ impl Model { pub struct NodeInfo { pub id: String, pub name: String, + pub state: String, pub children: Vec, pub external_addr: Option, pub is_offline: bool, @@ -53,11 +54,12 @@ impl NodeInfo { pub fn new( id: String, name: String, + state: String, children: Vec, external_addr: Option, is_offline: bool, ) -> NodeInfo { - NodeInfo { id, name, children, external_addr, is_offline } + NodeInfo { id, name, state, children, external_addr, is_offline } } } diff --git a/bin/dnetview/src/view.rs b/bin/dnetview/src/view.rs index d683f38cb..1bbc2a142 100644 --- a/bin/dnetview/src/view.rs +++ b/bin/dnetview/src/view.rs @@ -228,16 +228,22 @@ impl View { let info = self.selectables.get(&selected); match info { - Some(SelectableObject::Node(node)) => match &node.external_addr { - Some(addr) => { - let node_info = Span::styled(format!("External addr: {}", addr), style); - lines.push(Spans::from(node_info)); + Some(SelectableObject::Node(node)) => { + match &node.external_addr { + Some(addr) => { + let node_info = Span::styled(format!("External addr: {}", addr), style); + lines.push(Spans::from(node_info)); + } + None => { + let node_info = Span::styled(format!("External addr: Null"), style); + lines.push(Spans::from(node_info)); + } } - None => { - let node_info = Span::styled(format!("External addr: Null"), style); - lines.push(Spans::from(node_info)); - } - }, + lines.push(Spans::from(Span::styled( + format!("P2P state: {}", node.state), + style, + ))); + } Some(SelectableObject::Session(session)) => { if session.accept_addr.is_some() { let session_info = Span::styled( @@ -248,6 +254,7 @@ impl View { } } Some(SelectableObject::Connect(connect)) => { + // get + display the msg log let log = self.msg_log.get(&connect.id); match log { Some(values) => { @@ -267,6 +274,11 @@ impl View { } None => return Err(DnetViewError::CannotFindId), } + // display the connection state + lines.push(Spans::from(Span::styled( + format!("State: {}", &connect.state), + style, + ))); } None => return Err(DnetViewError::NotSelectableObject), }