dnetview: display p2p state w each node

This commit is contained in:
lunar-mining
2022-06-21 20:31:32 +02:00
parent 2eba9954af
commit 9495c43a2e
3 changed files with 53 additions and 15 deletions

View File

@@ -33,6 +33,8 @@ use dnetview::{
view::{IdListView, NodeInfoView, View},
};
use log::debug;
struct DnetView {
name: String,
rpc_client: RpcClient,
@@ -167,8 +169,16 @@ async fn parse_offline(client: &DnetView, model: Arc<Model>) -> DnetViewResult<(
let is_empty = true;
let last_msg = "Null".to_string();
let last_status = "Null".to_string();
let connect_info =
ConnectInfo::new(id, addr, state, parent.clone(), msg_log, is_empty, last_msg, last_status);
let connect_info = ConnectInfo::new(
id,
addr,
state.clone(),
parent.clone(),
msg_log,
is_empty,
last_msg,
last_status,
);
connects.push(connect_info.clone());
let accept_addr = None;
@@ -176,7 +186,14 @@ async fn parse_offline(client: &DnetView, model: Arc<Model>) -> DnetViewResult<(
SessionInfo::new(session_id, name, is_empty, parent.clone(), connects, accept_addr);
sessions.push(session_info);
let node = NodeInfo::new(node_id.clone(), node_name.to_string(), sessions.clone(), None, true);
let node = NodeInfo::new(
node_id.clone(),
node_name.to_string(),
state.clone(),
sessions.clone(),
None,
true,
);
update_node(model.clone(), node.clone(), node_id.clone()).await;
update_selectable_and_ids(model.clone(), sessions, node.clone()).await?;
@@ -192,6 +209,7 @@ async fn parse_data(
let inbound = &reply["session_inbound"];
let _manual = &reply["session_manual"];
let outbound = &reply["session_outbound"];
let state = &reply["state"];
let mut sessions: Vec<SessionInfo> = Vec::new();
@@ -208,8 +226,14 @@ async fn parse_data(
sessions.push(out_session.clone());
//sessions.push(man_session.clone());
let node =
NodeInfo::new(node_id.clone(), node_name.to_string(), sessions.clone(), ext_addr, false);
let node = NodeInfo::new(
node_id.clone(),
node_name.to_string(),
state.as_str().unwrap().to_string(),
sessions.clone(),
ext_addr,
false,
);
update_node(model.clone(), node.clone(), node_id.clone()).await;
update_selectable_and_ids(model.clone(), sessions.clone(), node.clone()).await?;

View File

@@ -44,6 +44,7 @@ impl Model {
pub struct NodeInfo {
pub id: String,
pub name: String,
pub state: String,
pub children: Vec<SessionInfo>,
pub external_addr: Option<String>,
pub is_offline: bool,
@@ -53,11 +54,12 @@ impl NodeInfo {
pub fn new(
id: String,
name: String,
state: String,
children: Vec<SessionInfo>,
external_addr: Option<String>,
is_offline: bool,
) -> NodeInfo {
NodeInfo { id, name, children, external_addr, is_offline }
NodeInfo { id, name, state, children, external_addr, is_offline }
}
}

View File

@@ -228,16 +228,22 @@ impl View {
let info = self.selectables.get(&selected);
match info {
Some(SelectableObject::Node(node)) => match &node.external_addr {
Some(addr) => {
let node_info = Span::styled(format!("External addr: {}", addr), style);
lines.push(Spans::from(node_info));
Some(SelectableObject::Node(node)) => {
match &node.external_addr {
Some(addr) => {
let node_info = Span::styled(format!("External addr: {}", addr), style);
lines.push(Spans::from(node_info));
}
None => {
let node_info = Span::styled(format!("External addr: Null"), style);
lines.push(Spans::from(node_info));
}
}
None => {
let node_info = Span::styled(format!("External addr: Null"), style);
lines.push(Spans::from(node_info));
}
},
lines.push(Spans::from(Span::styled(
format!("P2P state: {}", node.state),
style,
)));
}
Some(SelectableObject::Session(session)) => {
if session.accept_addr.is_some() {
let session_info = Span::styled(
@@ -248,6 +254,7 @@ impl View {
}
}
Some(SelectableObject::Connect(connect)) => {
// get + display the msg log
let log = self.msg_log.get(&connect.id);
match log {
Some(values) => {
@@ -267,6 +274,11 @@ impl View {
}
None => return Err(DnetViewError::CannotFindId),
}
// display the connection state
lines.push(Spans::from(Span::styled(
format!("State: {}", &connect.state),
style,
)));
}
None => return Err(DnetViewError::NotSelectableObject),
}