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

dnetview: display null outbound connections as null instead of ignoring

lunar-mining 4 лет назад
Родитель
Сommit
249e4d46b6
2 измененных файлов с 25 добавлено и 11 удалено
  1. 3 3
      bin/dnetview/src/main.rs
  2. 22 8
      bin/dnetview/src/view.rs

+ 3 - 3
bin/dnetview/src/main.rs

@@ -153,6 +153,7 @@ async fn poll(client: DnetView, model: Arc<Model>) -> DnetViewResult<()> {
         match client.get_info().await {
         match client.get_info().await {
             Ok(reply) => {
             Ok(reply) => {
                 if reply.as_object().is_some() && !reply.as_object().unwrap().is_empty() {
                 if reply.as_object().is_some() && !reply.as_object().unwrap().is_empty() {
+                    debug!("FROM {}", client.name);
                     parse_data(reply.as_object().unwrap(), &client, model.clone()).await?;
                     parse_data(reply.as_object().unwrap(), &client, model.clone()).await?;
                 } else {
                 } else {
                     return Err(DnetViewError::EmptyRpcReply)
                     return Err(DnetViewError::EmptyRpcReply)
@@ -232,7 +233,6 @@ async fn parse_data(
 
 
     let node_name = &client.name;
     let node_name = &client.name;
     let node_id = make_node_id(node_name)?;
     let node_id = make_node_id(node_name)?;
-    //let external_addr = ext_addr.unwrap().as_str().unwrap();
 
 
     let ext_addr = parse_external_addr(addr).await?;
     let ext_addr = parse_external_addr(addr).await?;
     let in_session = parse_inbound(inbound, &node_id).await?;
     let in_session = parse_inbound(inbound, &node_id).await?;
@@ -498,14 +498,14 @@ async fn parse_outbound(outbound: &Value, node_id: &String) -> DnetViewResult<Se
                 slot_count += 1;
                 slot_count += 1;
                 match slot["channel"].is_null() {
                 match slot["channel"].is_null() {
                     true => {
                     true => {
-                        // channel is empty. initialize with empty values
+                        // TODO: this is not actually empty
                         let id = make_empty_id(node_id, &session_type, slot_count)?;
                         let id = make_empty_id(node_id, &session_type, slot_count)?;
                         let addr = "Null".to_string();
                         let addr = "Null".to_string();
                         let state = &slot["state"];
                         let state = &slot["state"];
                         let state = state.as_str().unwrap().to_string();
                         let state = state.as_str().unwrap().to_string();
                         let parent = parent.clone();
                         let parent = parent.clone();
                         let msg_log = Vec::new();
                         let msg_log = Vec::new();
-                        let is_empty = true;
+                        let is_empty = false;
                         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 remote_node_id = "Null".to_string();
                         let remote_node_id = "Null".to_string();

+ 22 - 8
bin/dnetview/src/view.rs

@@ -161,14 +161,28 @@ impl View {
                             ids.push(session.id.clone());
                             ids.push(session.id.clone());
                             for connection in &session.children {
                             for connection in &session.children {
                                 let mut info = Vec::new();
                                 let mut info = Vec::new();
-                                let name = Span::styled(
-                                    format!(
-                                        "        {} ({})",
-                                        connection.addr, connection.remote_node_id
-                                    ),
-                                    style,
-                                );
-                                info.push(name);
+                                match connection.addr.as_str() {
+                                    "Null" => {
+                                        let style = Style::default()
+                                            .fg(Color::Blue)
+                                            .add_modifier(Modifier::ITALIC);
+                                        let name = Span::styled(
+                                            format!("        {} ", connection.addr),
+                                            style,
+                                        );
+                                        info.push(name);
+                                    }
+                                    addr => {
+                                        let name = Span::styled(
+                                            format!(
+                                                "        {} ({})",
+                                                addr, connection.remote_node_id
+                                            ),
+                                            style,
+                                        );
+                                        info.push(name);
+                                    }
+                                }
                                 match connection.last_status.as_str() {
                                 match connection.last_status.as_str() {
                                     "recv" => {
                                     "recv" => {
                                         let msg = Span::styled(
                                         let msg = Span::styled(