diff --git a/bin/dnetview/src/main.rs b/bin/dnetview/src/main.rs index e6f706787..bf0f7b38d 100644 --- a/bin/dnetview/src/main.rs +++ b/bin/dnetview/src/main.rs @@ -30,7 +30,7 @@ use dnetview::{ model::{ConnectInfo, Model, NodeInfo, SelectableObject, Session, SessionInfo}, options::ProgramOptions, ui, - util::{generate_id, make_connect_id, make_node_id, make_session_id}, + util::{generate_id, make_connect_id, make_empty_id, make_node_id, make_session_id}, view::{ConnectInfoView, IdListView, InfoListView, NodeInfoView, SessionInfoView, View}, }; @@ -220,14 +220,16 @@ async fn parse_inbound(inbound: &Value, node_id: String) -> Result let session_id = make_session_id(node_id.clone(), &session_type)?; let mut connects: Vec = Vec::new(); let connections = &inbound["connected"]; + let mut connect_count = 0; match connections.as_object() { Some(connect) => { match connect.is_empty() { true => { + connect_count += 1; // channel is empty. initialize with empty values // TODO: fix this - let connect_id = generate_id()?; + let connect_id = make_empty_id(node_id.clone(), &session_type, connect_count)?; let addr = "Null".to_string(); let msg = "Null".to_string(); let status = "Null".to_string(); @@ -305,15 +307,17 @@ async fn parse_outbound(outbound: &Value, node_id: String) -> Result = Vec::new(); let slots = &outbound["slots"]; let session_id = make_session_id(node_id.clone(), &session_type)?; + let mut slot_count = 0; match slots.as_array() { Some(slots) => { for slot in slots { + slot_count += 1; match slot["channel"].is_null() { true => { // channel is empty. initialize with empty values // TODO: fix this - let connect_id = generate_id()?; + let connect_id = make_empty_id(node_id.clone(), &session_type, slot_count)?; let is_empty = true; let addr = "Null".to_string(); let state = &slot["state"]; diff --git a/bin/dnetview/src/util.rs b/bin/dnetview/src/util.rs index 3df2030c1..8294f6bcd 100644 --- a/bin/dnetview/src/util.rs +++ b/bin/dnetview/src/util.rs @@ -45,6 +45,35 @@ pub fn generate_id() -> Result { Ok(serial::serialize_hex(&id)) } +pub fn make_empty_id(node_id: String, session: &Session, count: u64) -> Result { + let mut num = 0_u64; + + match session { + Session::Inbound => { + for i in ['i', 'n'] { + num += i as u64; + } + } + Session::Outbound => { + for i in ['o', 'u', 't'] { + num += i as u64; + } + } + Session::Manual => { + for i in ['m', 'a', 'n'] { + num += i as u64; + } + } + } + + for i in node_id.chars() { + num += i as u64 + } + + num += count; + + Ok(serial::serialize_hex(&num)) +} //pub fn is_empty_outbound(slots: Vec) -> bool { // return slots.iter().all(|slot| slot.is_empty); //} diff --git a/bin/dnetview/src/view.rs b/bin/dnetview/src/view.rs index 82cb2ab63..ef2117081 100644 --- a/bin/dnetview/src/view.rs +++ b/bin/dnetview/src/view.rs @@ -92,8 +92,20 @@ impl View { nodes.push(names); //nodes.push(node); } - SelectableObject::Session(info) => self.session_info.clone().render(info), - SelectableObject::Connect(info) => self.connect_info.clone().render(info), + SelectableObject::Session(info) => { + let name_span = Span::raw(&info.session_name); + let lines = vec![Spans::from(name_span)]; + let names = ListItem::new(lines); + nodes.push(names); + //self.session_info.clone().render(info), + } + SelectableObject::Connect(info) => { + let name_span = Span::raw(&info.connect_id); + let lines = vec![Spans::from(name_span)]; + let names = ListItem::new(lines); + nodes.push(names); + //self.connect_info.clone().render(info), + } } // }