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

dnetview: final bug fix and clean up

clear active_ids before writing to it to insure offline nodes don't get
saved perpetually
lunar-mining 4 лет назад
Родитель
Сommit
837292472e
3 измененных файлов с 28 добавлено и 88 удалено
  1. 2 9
      bin/dnetview/src/main.rs
  2. 20 20
      bin/dnetview/src/util.rs
  3. 6 59
      bin/dnetview/src/view.rs

+ 2 - 9
bin/dnetview/src/main.rs

@@ -34,7 +34,7 @@ use dnetview::{
     view::{IdListView, NodeInfoView, View},
 };
 
-use log::{debug, error};
+use log::error;
 
 struct DnetView {
     name: String,
@@ -162,7 +162,6 @@ async fn parse_offline(client: &DnetView, model: Arc<Model>) -> DnetViewResult<(
 
     // initialize with empty values
     let id = make_empty_id(&node_id, &session_type, 0)?;
-    //debug!("Make EMPTY ID: {}", id);
     let addr = "Null".to_string();
     let state = "Null".to_string();
     let parent = node_id.clone();
@@ -193,7 +192,7 @@ async fn parse_data(
 ) -> DnetViewResult<()> {
     let addr = &reply.get("external_addr");
     let inbound = &reply["session_inbound"];
-    let manual = &reply["session_manual"];
+    let _manual = &reply["session_manual"];
     let outbound = &reply["session_outbound"];
 
     let mut sessions: Vec<SessionInfo> = Vec::new();
@@ -243,7 +242,6 @@ async fn update_msgs(model: Arc<Model>, sessions: Vec<SessionInfo>) -> DnetViewR
             }
         }
     }
-    //debug!("MSGS: {:?}", model.msg_log.lock().await);
     Ok(())
 }
 
@@ -303,7 +301,6 @@ async fn parse_inbound(inbound: &Value, node_id: &String) -> DnetViewResult<Sess
                     connect_count += 1;
                     // channel is empty. initialize with empty values
                     let id = make_empty_id(&node_id, &session_type, connect_count)?;
-                    //debug!("Make INBOUND EMPTY ID: {}", id);
                     let addr = "Null".to_string();
                     let state = "Null".to_string();
                     let parent = parent.clone();
@@ -342,7 +339,6 @@ async fn parse_inbound(inbound: &Value, node_id: &String) -> DnetViewResult<Sess
                         let info2 = info.unwrap().get(1);
                         let id = info2.unwrap().get("random_id").unwrap().as_u64().unwrap();
                         let id = make_connect_id(&id)?;
-                        //debug!("Made INBOUND connect ID: {}", id);
                         let state = "state".to_string();
                         let parent = parent.clone();
                         let msg_values = info2.unwrap().get("log").unwrap().as_array().unwrap();
@@ -406,7 +402,6 @@ async fn parse_manual(_manual: &Value, node_id: &String) -> DnetViewResult<Sessi
     //let id: u64 = 0;
     let connect_id = make_empty_id(&node_id, &session_type, 0)?;
     //let connect_id = make_connect_id(&id)?;
-    //debug!("Made MANUAL connect ID: {}", id);
     let addr = "Null".to_string();
     let state = "Null".to_string();
     let msg_log = Vec::new();
@@ -442,7 +437,6 @@ async fn parse_outbound(outbound: &Value, node_id: &String) -> DnetViewResult<Se
                     true => {
                         // channel is empty. initialize with empty values
                         let id = make_empty_id(&node_id, &session_type, slot_count)?;
-                        //debug!("Make OUTBOUND EMPTY ID: {}", id);
                         let addr = "Null".to_string();
                         let state = &slot["state"];
                         let state = state.as_str().unwrap().to_string();
@@ -468,7 +462,6 @@ async fn parse_outbound(outbound: &Value, node_id: &String) -> DnetViewResult<Se
                         let channel = &slot["channel"];
                         let id = channel["random_id"].as_u64().unwrap();
                         let id = make_connect_id(&id)?;
-                        //debug!("Made OUTBOUND connect id {}", id);
                         let addr = &slot["addr"];
                         let addr = addr.as_str().unwrap().to_string();
                         let state = &slot["state"];

+ 20 - 20
bin/dnetview/src/util.rs

@@ -3,11 +3,11 @@ use darkfi::{util::serial, Result};
 use log::debug;
 
 pub fn make_node_id(node_name: &String) -> Result<String> {
-    match serial::serialize_hex(node_name).as_str() {
-        e => {
-            debug!("NODE {} IS NODE NAME {} ", e, node_name);
-        }
-    }
+    //match serial::serialize_hex(node_name).as_str() {
+    //    e => {
+    //        debug!("NODE ID {} IS DERIVED FROM NODE NAME {} ", e, node_name);
+    //    }
+    //}
     Ok(serial::serialize_hex(node_name))
 }
 
@@ -41,20 +41,20 @@ pub fn make_session_id(node_id: &String, session: &Session) -> Result<String> {
         num += i as u64
     }
 
-    match serial::serialize_hex(&num).as_str() {
-        e => {
-            debug!("SESSION {} IS NODE ID {} SESSION {:?}", e, node_id, session);
-        }
-    }
+    //match serial::serialize_hex(&num).as_str() {
+    //    e => {
+    //        debug!("SESSION ID {} IS DERIVED FROM NODE ID {} AND SESSION {:?}", e, node_id, session);
+    //    }
+    //}
     Ok(serial::serialize_hex(&num))
 }
 
 pub fn make_connect_id(id: &u64) -> Result<String> {
-    match serial::serialize_hex(id).as_str() {
-        e => {
-            debug!("CONNECT ID {} IS ID {}", e, id);
-        }
-    }
+    //match serial::serialize_hex(id).as_str() {
+    //    e => {
+    //        debug!("CONNECT ID {} IS DERIVED FROM ID {}", e, id);
+    //    }
+    //}
     Ok(serial::serialize_hex(id))
 }
 
@@ -92,11 +92,11 @@ pub fn make_empty_id(node_id: &String, session: &Session, count: u64) -> Result<
 
     num += count;
 
-    match serial::serialize_hex(&num).as_str() {
-        e => {
-            debug!("EMPTY ID {} IS NODE ID {} SESSION {:?} COUNT {}", e, node_id, session, count);
-        }
-    }
+    //match serial::serialize_hex(&num).as_str() {
+    //    e => {
+    //        debug!("EMPTY ID {} IS DERIVED FROM NODE ID {} AND SESSION {:?} AND COUNT {}", e, node_id, session, count);
+    //    }
+    //}
     Ok(serial::serialize_hex(&num))
 }
 

+ 6 - 59
bin/dnetview/src/view.rs

@@ -62,64 +62,14 @@ impl View {
     }
 
     fn update_active_ids(&mut self) {
-        // this removes the empty ids from the offline node
-        // but doesn't remove the actual ids that were previously there
-        // we need to know what those ideas are in order to remove them
-        // need to keep track of ids somewhere in memory so we can remove them
+        self.active_ids.ids.clear();
         for info in self.nodes.infos.values() {
             self.active_ids.ids.insert(info.id.to_string());
-            //debug!("INFO {:?}", info);
-            match info.is_offline {
-                true => {
-                    // get the corresponding selectable object
-
-                    // get the selectable that corresponds to node id
-                    let offline = self.selectables.get(&info.id.to_string());
-                    match offline {
-                        //debug!("NODE {} is offline", info.id.to_string());
-                        Some(SelectableObject::Node(node)) => {
-                            //self.active_ids.ids.remove(&node.id);
-                            for session in &node.children {
-                                debug!("REMOVED {}", session.id.to_string());
-                                self.active_ids.ids.remove(&session.id);
-                                for connect in &session.children {
-                                    debug!("REMOVED {}", connect.id.to_string());
-                                    self.active_ids.ids.remove(&connect.id);
-                                    //
-                                }
-                            }
-                        }
-                        Some(e) => {}
-                        //Some(SelectableObject::Session(session)) => {
-                        //    self.active_ids.ids.remove(&session.id);
-                        //}
-                        //Some(SelectableObject::Connect(connect)) => {
-                        //    self.active_ids.ids.remove(&connect.id);
-                        //}
-                        None => {}
-                    }
-
-                    //self.active_ids.ids.get(&info.id.to_string());
-                    //debug!("OFFLINE INFO {:?}", info);
-                    //debug!("NODE {} is offline", info.id.to_string());
-                    //for session in &info.children {
-                    //    debug!("FOUND SESSION ID {}", session.id.to_string());
-                    //    for connect in &session.children {
-                    //        debug!("FOUND CONNECT ID {}", connect.id.to_string());
-                    //        //self.active_ids.ids.remove(&connect.id.to_string());
-                    //    }
-                    //    //self.active_ids.ids.remove(&session.id.to_string());
-                    //}
-                }
-                false => {
-                    //debug!("ONLINE INFO {:?}", info);
-                    for session in &info.children {
-                        if !session.is_empty == true {
-                            self.active_ids.ids.insert(session.id.to_string());
-                            for connect in &session.children {
-                                self.active_ids.ids.insert(connect.id.to_string());
-                            }
-                        }
+            for session in &info.children {
+                if !session.is_empty == true {
+                    self.active_ids.ids.insert(session.id.to_string());
+                    for connect in &session.children {
+                        self.active_ids.ids.insert(connect.id.to_string());
                     }
                 }
             }
@@ -255,9 +205,6 @@ impl View {
                 }
             }
         }
-        //debug!("NODES: {:?}", node_ids);
-        //debug!("SESSIONS: {:?}", session_ids);
-        //debug!("CONNECTs : {:?}", connect_ids);
         let nodes =
             List::new(nodes).block(Block::default().borders(Borders::ALL)).highlight_symbol(">> ");