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

bug fix: stop saving duplicate incoming values

removed nested loop that was causing incoming data to be saved twice.
lunar-mining 4 лет назад
Родитель
Сommit
7b57c39314
2 измененных файлов с 17 добавлено и 10 удалено
  1. 8 8
      bin/dnetview/src/main.rs
  2. 9 2
      bin/dnetview/src/ui.rs

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

@@ -178,15 +178,15 @@ async fn poll(client: Map, model: Arc<Model>) -> Result<()> {
                 // channel is not empty. initialize with whole values
                 let ic = i_connected.as_object().unwrap();
                 for k in ic.keys() {
+                    let node = ic.get(k);
                     let addr = k.to_string();
-                    for v in ic.values() {
-                        let msg = v.get("last_msg").unwrap().as_str().unwrap().to_string();
-                        let status = v.get("last_status").unwrap().as_str().unwrap().to_string();
-                        let channel = Channel::new(msg, status);
-                        let is_empty = false;
-                        let iinfo = InboundInfo::new(is_empty, addr.clone(), channel);
-                        iconnects.push(iinfo);
-                    }
+                    let msg = node.unwrap().get("last_msg").unwrap().as_str().unwrap().to_string();
+                    let status =
+                        node.unwrap().get("last_status").unwrap().as_str().unwrap().to_string();
+                    let channel = Channel::new(msg, status);
+                    let is_empty = false;
+                    let iinfo = InboundInfo::new(is_empty, addr.clone(), channel);
+                    iconnects.push(iinfo);
                 }
             }
 

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

@@ -24,12 +24,17 @@ pub fn ui<B: Backend>(f: &mut Frame<'_, B>, mut view: View) {
         let id_span = Span::raw(id.to_string());
         let mut lines = vec![Spans::from(id_span)];
         data.push(id.to_string());
+
         match &view.info_list.infos.get(id) {
+            // TODO:
+            //      1. Only print 'outbound' or 'inbound':
+            //              * if in/outbound is not empty
+            //              * only print it once
+            //
+            //      2. Fix error whereby duplicates outbounds are being printed (nested loop)
             Some(node) => {
                 for outbound in &node.outbound.clone() {
                     if outbound.is_empty == false {
-                        lines.push(Spans::from(Span::styled("   Outbound", Style::default())));
-                        data.push("Outbound".to_string());
                         for slot in outbound.slots.clone() {
                             let addr = Span::styled(format!("       {}", slot.addr), style);
                             data.push(format!("{}", slot.addr));
@@ -49,7 +54,9 @@ pub fn ui<B: Backend>(f: &mut Frame<'_, B>, mut view: View) {
                         }
                     }
                 }
+                //debug!("{:?}", &node.inbound);
                 for inbound in &node.inbound {
+                    //debug!("{:?}", inbound);
                     if inbound.is_empty == false {
                         lines.push(Spans::from(Span::styled("   Incoming", Style::default())));
                         data.push("Incoming".to_string());