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

map: update NodeInfo data structure

lunar-mining 4 лет назад
Родитель
Сommit
5ff07727d5
3 измененных файлов с 55 добавлено и 42 удалено
  1. 27 27
      bin/map/src/main.rs
  2. 16 9
      bin/map/src/model.rs
  3. 12 6
      bin/map/src/ui.rs

+ 27 - 27
bin/map/src/main.rs

@@ -179,33 +179,33 @@ async fn poll(client: Map, model: Arc<Model>) -> Result<()> {
 
             // change NodeInfo
             // TODO: error handling
-            let infos = vec![
-                NodeInfo {
-                    id: node1["id"].to_string(),
-                    connections: node1["connections"].as_u64().unwrap() as usize,
-                    is_active: node1["is_active"].as_bool().unwrap(),
-                    last_message: node1["message"].to_string(),
-                },
-                //NodeInfo {
-                //    id: node2["id"].to_string(),
-                //    connections: node2["connections"].as_u64().unwrap() as usize,
-                //    is_active: node2["is_active"].as_bool().unwrap(),
-                //    last_message: node2["message"].to_string(),
-                //},
-                //NodeInfo {
-                //    id: node3["id"].to_string(),
-                //    connections: node3["connections"].as_u64().unwrap() as usize,
-                //    is_active: node3["is_active"].as_bool().unwrap(),
-                //    last_message: node3["message"].to_string(),
-                //},
-            ];
-
-            for node in infos {
-                // write nodes
-                model.info_list.infos.lock().await.push(node.clone());
-                // write node id
-                model.id_list.node_id.lock().await.push(node.clone().id);
-            }
+            //let infos = vec![
+            //    NodeInfo {
+            //        id: node1["id"].to_string(),
+            //        connections: node1["connections"].as_u64().unwrap() as usize,
+            //        is_active: node1["is_active"].as_bool().unwrap(),
+            //        last_message: node1["message"].to_string(),
+            //    },
+            //    //NodeInfo {
+            //    //    id: node2["id"].to_string(),
+            //    //    connections: node2["connections"].as_u64().unwrap() as usize,
+            //    //    is_active: node2["is_active"].as_bool().unwrap(),
+            //    //    last_message: node2["message"].to_string(),
+            //    //},
+            //    //NodeInfo {
+            //    //    id: node3["id"].to_string(),
+            //    //    connections: node3["connections"].as_u64().unwrap() as usize,
+            //    //    is_active: node3["is_active"].as_bool().unwrap(),
+            //    //    last_message: node3["message"].to_string(),
+            //    //},
+            //];
+
+            //for node in infos {
+            //    // write nodes
+            //    model.info_list.infos.lock().await.push(node.clone());
+            //    // write node id
+            //    model.id_list.node_id.lock().await.push(node.clone().id);
+            //}
         } else {
             // TODO: error handling
             println!("Reply is an error");

+ 16 - 9
bin/map/src/model.rs

@@ -1,5 +1,5 @@
 use async_std::sync::Mutex;
-use darkfi::error::{Error, Result};
+use darkfi::error::Result;
 use tui::widgets::ListState;
 
 pub struct Model {
@@ -48,21 +48,16 @@ impl InfoList {
     }
 }
 
-//pub type NodeId = u32;
-
 #[derive(Clone, Debug)]
 pub struct NodeInfo {
     pub id: String,
-    pub connections: usize,
-    pub is_active: bool,
-    pub last_message: String,
+    pub out_connects: Vec<Connection>,
+    pub in_connects: Vec<Connection>,
 }
 
 impl NodeInfo {
     pub fn new() -> NodeInfo {
-        let connections = 0;
-        let is_active = false;
-        NodeInfo { id: String::new(), connections, is_active, last_message: String::new() }
+        NodeInfo { id: String::new(), out_connects: Vec::new(), in_connects: Vec::new() }
     }
 }
 
@@ -71,3 +66,15 @@ impl Default for NodeInfo {
         Self::new()
     }
 }
+
+#[derive(Clone, Debug)]
+pub struct Connection {
+    pub id: String,
+    pub message: String,
+}
+
+impl Connection {
+    pub fn new() -> Connection {
+        Connection { id: String::new(), message: String::new() }
+    }
+}

+ 12 - 6
bin/map/src/ui.rs

@@ -37,16 +37,22 @@ pub fn ui<B: Backend>(f: &mut Frame<'_, B>, mut view: View) {
 }
 
 fn render_info<B: Backend>(view: View, f: &mut Frame<'_, B>, index: usize, slice: Vec<Rect>) {
+    // TODO: create new list of outgoing and incoming connections
     let info = &view.info_list.infos;
     let id = &info[index].id;
-    let connections = info[index].connections;
-    let is_active = info[index].is_active;
-    let message = &info[index].last_message;
+    //for connect in info[index].in_connects.clone() {
+    //    let id = connect.id;
+    //    let message = connect.message;
+    //}
+    //for connect in info[index].out_connects.clone() {
+    //    let id = connect.id;
+    //    let message = connect.message;
+    //}
     let span = vec![
         Spans::from(format!("NodeId: {}", id)),
-        Spans::from(format!("Number of connections: {}", connections)),
-        Spans::from(format!("Is active: {}", is_active)),
-        Spans::from(format!("Last message: {}", message)),
+        //Spans::from(format!("Number of connections: {}", connections)),
+        //Spans::from(format!("Is active: {}", is_active)),
+        //Spans::from(format!("Last message: {}", message)),
     ];
     let graph =
         Paragraph::new(span).block(Block::default().borders(Borders::ALL)).style(Style::default());