فهرست منبع

map/poll: parse info from rpc request and render in ui.rs.

there is now a new type of connection called manual session. this change
passes manual session to NodeInfo and renders.

rendering here is still very primitive-- we are still working with dummy
network values.
lunar-mining 4 سال پیش
والد
کامیت
e8bb31873b
3فایلهای تغییر یافته به همراه68 افزوده شده و 69 حذف شده
  1. 43 56
      bin/map/src/main.rs
  2. 4 3
      bin/map/src/model.rs
  3. 21 10
      bin/map/src/ui.rs

+ 43 - 56
bin/map/src/main.rs

@@ -174,63 +174,50 @@ async fn poll(client: Map, model: Arc<Model>) -> Result<()> {
         let reply = client.get_info().await?;
         debug!("{:?}", reply);
 
-        //if reply.as_object().is_some() && !reply.as_object().unwrap().is_empty() {
-        //    let id = reply.as_object().unwrap().get("id").unwrap();
-
-        //    let connections = reply.as_object().unwrap().get("connections").unwrap();
-        //    let outgoing = connections.get("outgoing").unwrap();
-        //    let incoming = connections.get("incoming").unwrap();
-
-        //    let mut outconnects = Vec::new();
-        //    let mut inconnects = Vec::new();
-
-        //    // here we are simulating new messages by scrolling through a vector
-        //    let msgs = outgoing[1].get("message").unwrap();
-        //    if index == 0 {
-        //        index += 1;
-        //    } else if index >= 5 {
-        //        index = 0
-        //    } else {
-        //        index = index + 1;
-        //    }
+        if reply.as_object().is_some() && !reply.as_object().unwrap().is_empty() {
+            let session_inbound = reply.as_object().unwrap().get("session_inbound");
+            let si_key =
+                session_inbound.unwrap().as_object().unwrap().get("key").unwrap().as_u64().unwrap();
 
-        //    let out0 = Connection::new(
-        //        outgoing[0].get("id").unwrap().as_str().unwrap().to_string(),
-        //        msgs[index].as_str().unwrap().to_string(),
-        //    );
-        //    let out1 = Connection::new(
-        //        outgoing[1].get("id").unwrap().as_str().unwrap().to_string(),
-        //        msgs[index].as_str().unwrap().to_string(),
-        //    );
-
-        //    let in0 = Connection::new(
-        //        incoming[0].get("id").unwrap().as_str().unwrap().to_string(),
-        //        msgs[index].as_str().unwrap().to_string(),
-        //    );
-        //    let in1 = Connection::new(
-        //        incoming[1].get("id").unwrap().as_str().unwrap().to_string(),
-        //        msgs[index].as_str().unwrap().to_string(),
-        //    );
-
-        //    outconnects.push(out0);
-        //    outconnects.push(out1);
-
-        //    inconnects.push(in0);
-        //    inconnects.push(in1);
-
-        //    let infos = NodeInfo { outgoing: outconnects, incoming: inconnects };
-
-        //    let mut node_info = HashMap::new();
-        //    node_info.insert(id.as_str().unwrap().to_string(), infos);
-
-        //    for (id, value) in node_info.clone() {
-        //        model.id_list.node_id.lock().await.insert(id.clone());
-        //        model.info_list.infos.lock().await.insert(id, value);
-        //    }
-        //} else {
-        //    // TODO: error handling
-        //    debug!("Reply is empty");
-        //}
+            let session_manual = reply.as_object().unwrap().get("session_manual");
+            let sm_key =
+                session_manual.unwrap().as_object().unwrap().get("key").unwrap().as_u64().unwrap();
+
+            let session_outbound = reply.as_object().unwrap().get("session_outbound");
+            let so_key =
+                session_manual.unwrap().as_object().unwrap().get("key").unwrap().as_u64().unwrap();
+
+            let channel_state = reply.as_object().unwrap().get("state").unwrap().as_str().unwrap();
+            debug!("{:?}", channel_state);
+
+            let session_in = Connection::new(si_key.to_string(), channel_state.to_string());
+            let session_man = Connection::new(sm_key.to_string(), channel_state.to_string());
+            let session_out = Connection::new(so_key.to_string(), channel_state.to_string());
+
+            let mut outconnects = Vec::new();
+            let mut inconnects = Vec::new();
+            let mut manconnects = Vec::new();
+
+            outconnects.push(session_out);
+            inconnects.push(session_in);
+            manconnects.push(session_man);
+
+            let infos =
+                NodeInfo { outbound: outconnects, manual: manconnects, inbound: inconnects };
+
+            let mut node_info = HashMap::new();
+            // TODO: fix this. this key should be global identifier for each connection
+            // right now we are using si_key, which is the inbound session key.
+            node_info.insert(si_key, infos);
+
+            for (si_key, value) in node_info.clone() {
+                model.id_list.node_id.lock().await.insert(si_key.to_string().clone());
+                model.info_list.infos.lock().await.insert(si_key.to_string(), value);
+            }
+        } else {
+            // TODO: error handling
+            debug!("Reply is empty");
+        }
         async_util::sleep(2).await;
     }
     //} else {

+ 4 - 3
bin/map/src/model.rs

@@ -42,13 +42,14 @@ impl InfoList {
 
 #[derive(Clone, Debug, PartialEq, Eq, Hash)]
 pub struct NodeInfo {
-    pub outgoing: Vec<Connection>,
-    pub incoming: Vec<Connection>,
+    pub outbound: Vec<Connection>,
+    pub manual: Vec<Connection>,
+    pub inbound: Vec<Connection>,
 }
 
 impl NodeInfo {
     pub fn new() -> NodeInfo {
-        NodeInfo { outgoing: Vec::new(), incoming: Vec::new() }
+        NodeInfo { outbound: Vec::new(), manual: Vec::new(), inbound: Vec::new() }
     }
 }
 

+ 21 - 10
bin/map/src/ui.rs

@@ -57,10 +57,13 @@ fn render_info_left<B: Backend>(view: View, f: &mut Frame<'_, B>, _index: usize)
     for id in &view.id_list.node_id {
         match info.get(id) {
             Some(_) => {
-                titles.push(Spans::from(Span::styled("Outgoing:", Style::default())));
+                titles.push(Spans::from(Span::styled("Outbound:", Style::default())));
                 titles.push(Spans::from(""));
                 titles.push(Spans::from(""));
-                titles.push(Spans::from(Span::styled("Incoming:", Style::default())));
+                titles.push(Spans::from(Span::styled("Inbound:", Style::default())));
+                titles.push(Spans::from(""));
+                titles.push(Spans::from(""));
+                titles.push(Spans::from(Span::styled("Manual:", Style::default())));
                 titles.push(Spans::from(""));
                 titles.push(Spans::from(""));
                 titles.push(Spans::from(""));
@@ -87,11 +90,14 @@ fn render_info_left<B: Backend>(view: View, f: &mut Frame<'_, B>, _index: usize)
         match info.get(id) {
             Some(connects) => {
                 msgs.push(Spans::from(""));
-                msgs.push(Spans::from(format!("[R: {}]", connects.outgoing[0].message)));
-                msgs.push(Spans::from(format!("[S: {}]", connects.outgoing[1].message)));
+                msgs.push(Spans::from(format!("[R: {}]", connects.outbound[0].message)));
+                //msgs.push(Spans::from(format!("[S: {}]", connects.outgoing[1].message)));
+                msgs.push(Spans::from(""));
+                msgs.push(Spans::from(format!("[R: {}]", connects.inbound[0].message)));
+                //msgs.push(Spans::from(format!("[S: {}]", connects.incoming[1].message)));
+                msgs.push(Spans::from(""));
                 msgs.push(Spans::from(""));
-                msgs.push(Spans::from(format!("[R: {}]", connects.incoming[0].message)));
-                msgs.push(Spans::from(format!("[S: {}]", connects.incoming[1].message)));
+                msgs.push(Spans::from(format!("[R: {}]", connects.manual[0].message)));
                 msgs.push(Spans::from(""));
             }
             None => {
@@ -117,11 +123,16 @@ fn render_info_left<B: Backend>(view: View, f: &mut Frame<'_, B>, _index: usize)
         match info.get(id) {
             Some(connects) => {
                 ids.push(Spans::from(""));
-                ids.push(Spans::from(format!("{}", connects.outgoing[0].id)));
-                ids.push(Spans::from(format!("{}", connects.outgoing[1].id)));
+                ids.push(Spans::from(format!("{}", connects.outbound[0].id)));
+                //ids.push(Spans::from(format!("{}", connects.outgoing[1].id)));
+                ids.push(Spans::from(""));
+                ids.push(Spans::from(""));
+                ids.push(Spans::from(format!("{}", connects.inbound[0].id)));
+                //ids.push(Spans::from(format!("{}", connects.incoming[1].id)));
+                ids.push(Spans::from(""));
+                ids.push(Spans::from(""));
+                ids.push(Spans::from(format!("{}", connects.manual[0].id)));
                 ids.push(Spans::from(""));
-                ids.push(Spans::from(format!("{}", connects.incoming[0].id)));
-                ids.push(Spans::from(format!("{}", connects.incoming[1].id)));
                 ids.push(Spans::from(""));
             }
             None => {