From b5934980554ae2f7cbfb506fee1fa6f1955bbdbe Mon Sep 17 00:00:00 2001 From: lunar-mining Date: Wed, 22 Jun 2022 17:13:58 +0200 Subject: [PATCH] dnetview: get and render remote_node_id. fix bug w unnecessary async thread --- bin/dnetview/src/main.rs | 41 ++++++++++++++++++++++++++++++++++++--- bin/dnetview/src/model.rs | 14 ++++++++++++- bin/dnetview/src/view.rs | 9 +++++++-- 3 files changed, 58 insertions(+), 6 deletions(-) diff --git a/bin/dnetview/src/main.rs b/bin/dnetview/src/main.rs index 4847996b1..9d5743cdb 100644 --- a/bin/dnetview/src/main.rs +++ b/bin/dnetview/src/main.rs @@ -137,7 +137,7 @@ async fn try_connect( info!("Attempting to poll {}, RPC URL: {}", node_name, rpc_url); match DnetView::new(Url::parse(&rpc_url)?, node_name.clone()).await { Ok(client) => { - ex.spawn(poll(client, model.clone())).detach(); + poll(client, model.clone()).await?; } Err(e) => { error!("{}", e); @@ -183,6 +183,7 @@ async fn parse_offline(node_name: String, model: Arc) -> DnetViewResult<( let is_empty = true; let last_msg = "Null".to_string(); let last_status = "Null".to_string(); + let remote_node_id = "Null".to_string(); let connect_info = ConnectInfo::new( id, addr, @@ -192,6 +193,7 @@ async fn parse_offline(node_name: String, model: Arc) -> DnetViewResult<( is_empty, last_msg, last_status, + remote_node_id, ); connects.push(connect_info.clone()); @@ -344,6 +346,7 @@ async fn parse_inbound(inbound: &Value, node_id: &String) -> DnetViewResult DnetViewResult DnetViewResult "no remote id".to_string(), + false => remote_node_id, + }; let connect_info = ConnectInfo::new( id, addr, @@ -403,6 +418,7 @@ async fn parse_inbound(inbound: &Value, node_id: &String) -> DnetViewResult DnetViewResult DnetViewResult DnetViewResult DnetViewResult "no remote id".to_string(), + false => remote_node_id, + }; let connect_info = ConnectInfo::new( id, addr, @@ -522,6 +556,7 @@ async fn parse_outbound(outbound: &Value, node_id: &String) -> DnetViewResult ConnectInfo { - ConnectInfo { id, addr, state, parent, msg_log, is_empty, last_msg, last_status } + ConnectInfo { + id, + addr, + state, + parent, + msg_log, + is_empty, + last_msg, + last_status, + remote_node_id, + } } } diff --git a/bin/dnetview/src/view.rs b/bin/dnetview/src/view.rs index 1bbc2a142..8548bdb42 100644 --- a/bin/dnetview/src/view.rs +++ b/bin/dnetview/src/view.rs @@ -161,8 +161,13 @@ impl View { ids.push(session.id.clone()); for connection in &session.children { let mut info = Vec::new(); - let name = - Span::styled(format!(" {}", connection.addr), style); + let name = Span::styled( + format!( + " {} ({})", + connection.addr, connection.remote_node_id + ), + style, + ); info.push(name); match connection.last_status.as_str() { "recv" => {