Просмотр исходного кода

dnetview: display p2p state w each node

lunar-mining 4 лет назад
Родитель
Сommit
9495c43a2e
3 измененных файлов с 53 добавлено и 15 удалено
  1. 29 5
      bin/dnetview/src/main.rs
  2. 3 1
      bin/dnetview/src/model.rs
  3. 21 9
      bin/dnetview/src/view.rs

+ 29 - 5
bin/dnetview/src/main.rs

@@ -33,6 +33,8 @@ use dnetview::{
     view::{IdListView, NodeInfoView, View},
     view::{IdListView, NodeInfoView, View},
 };
 };
 
 
+use log::debug;
+
 struct DnetView {
 struct DnetView {
     name: String,
     name: String,
     rpc_client: RpcClient,
     rpc_client: RpcClient,
@@ -167,8 +169,16 @@ async fn parse_offline(client: &DnetView, model: Arc<Model>) -> DnetViewResult<(
     let is_empty = true;
     let is_empty = true;
     let last_msg = "Null".to_string();
     let last_msg = "Null".to_string();
     let last_status = "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());
     connects.push(connect_info.clone());
 
 
     let accept_addr = None;
     let accept_addr = None;
@@ -176,7 +186,14 @@ async fn parse_offline(client: &DnetView, model: Arc<Model>) -> DnetViewResult<(
         SessionInfo::new(session_id, name, is_empty, parent.clone(), connects, accept_addr);
         SessionInfo::new(session_id, name, is_empty, parent.clone(), connects, accept_addr);
     sessions.push(session_info);
     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_node(model.clone(), node.clone(), node_id.clone()).await;
     update_selectable_and_ids(model.clone(), sessions, node.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 inbound = &reply["session_inbound"];
     let _manual = &reply["session_manual"];
     let _manual = &reply["session_manual"];
     let outbound = &reply["session_outbound"];
     let outbound = &reply["session_outbound"];
+    let state = &reply["state"];
 
 
     let mut sessions: Vec<SessionInfo> = Vec::new();
     let mut sessions: Vec<SessionInfo> = Vec::new();
 
 
@@ -208,8 +226,14 @@ async fn parse_data(
     sessions.push(out_session.clone());
     sessions.push(out_session.clone());
     //sessions.push(man_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_node(model.clone(), node.clone(), node_id.clone()).await;
     update_selectable_and_ids(model.clone(), sessions.clone(), node.clone()).await?;
     update_selectable_and_ids(model.clone(), sessions.clone(), node.clone()).await?;

+ 3 - 1
bin/dnetview/src/model.rs

@@ -44,6 +44,7 @@ impl Model {
 pub struct NodeInfo {
 pub struct NodeInfo {
     pub id: String,
     pub id: String,
     pub name: String,
     pub name: String,
+    pub state: String,
     pub children: Vec<SessionInfo>,
     pub children: Vec<SessionInfo>,
     pub external_addr: Option<String>,
     pub external_addr: Option<String>,
     pub is_offline: bool,
     pub is_offline: bool,
@@ -53,11 +54,12 @@ impl NodeInfo {
     pub fn new(
     pub fn new(
         id: String,
         id: String,
         name: String,
         name: String,
+        state: String,
         children: Vec<SessionInfo>,
         children: Vec<SessionInfo>,
         external_addr: Option<String>,
         external_addr: Option<String>,
         is_offline: bool,
         is_offline: bool,
     ) -> NodeInfo {
     ) -> NodeInfo {
-        NodeInfo { id, name, children, external_addr, is_offline }
+        NodeInfo { id, name, state, children, external_addr, is_offline }
     }
     }
 }
 }
 
 

+ 21 - 9
bin/dnetview/src/view.rs

@@ -228,16 +228,22 @@ impl View {
             let info = self.selectables.get(&selected);
             let info = self.selectables.get(&selected);
 
 
             match info {
             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));
-                    }
-                    None => {
-                        let node_info = Span::styled(format!("External addr: Null"), 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));
+                        }
                     }
                     }
-                },
+                    lines.push(Spans::from(Span::styled(
+                        format!("P2P state: {}", node.state),
+                        style,
+                    )));
+                }
                 Some(SelectableObject::Session(session)) => {
                 Some(SelectableObject::Session(session)) => {
                     if session.accept_addr.is_some() {
                     if session.accept_addr.is_some() {
                         let session_info = Span::styled(
                         let session_info = Span::styled(
@@ -248,6 +254,7 @@ impl View {
                     }
                     }
                 }
                 }
                 Some(SelectableObject::Connect(connect)) => {
                 Some(SelectableObject::Connect(connect)) => {
+                    // get + display the msg log
                     let log = self.msg_log.get(&connect.id);
                     let log = self.msg_log.get(&connect.id);
                     match log {
                     match log {
                         Some(values) => {
                         Some(values) => {
@@ -267,6 +274,11 @@ impl View {
                         }
                         }
                         None => return Err(DnetViewError::CannotFindId),
                         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),
                 None => return Err(DnetViewError::NotSelectableObject),
             }
             }