dnetview: update data structures

Update dnetview data structures according to
f73c9c8f61.
This commit is contained in:
lunar-mining
2023-08-03 11:32:34 +02:00
parent 75cbdeca86
commit 782fd151b2
5 changed files with 450 additions and 393 deletions

View File

@@ -39,13 +39,13 @@ pub enum SelectableObject {
Lilith(LilithInfo),
Network(NetworkInfo),
Session(SessionInfo),
Connect(ConnectInfo),
Connect(SlotInfo),
}
#[derive(Debug)]
pub struct Model {
pub msg_map: MsgMap,
pub msg_log: Mutex<MsgLog>,
pub log: Mutex<MsgLog>,
pub selectables: Mutex<HashMap<String, SelectableObject>>,
}
@@ -53,86 +53,88 @@ impl Model {
pub fn new() -> Arc<Self> {
let selectables = Mutex::new(HashMap::new());
let msg_map = Mutex::new(HashMap::new());
let msg_log = Mutex::new(Vec::new());
Arc::new(Model { msg_map, msg_log, selectables })
let log = Mutex::new(Vec::new());
Arc::new(Model { msg_map, log, selectables })
}
}
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Eq)]
pub struct NodeInfo {
pub id: String,
pub dnet_id: String,
pub name: String,
pub state: String,
pub children: Vec<SessionInfo>,
pub external_addr: Option<String>,
pub hosts: Vec<String>,
pub info: Vec<SessionInfo>,
pub is_offline: bool,
}
impl NodeInfo {
pub fn new(
id: String,
dnet_id: String,
name: String,
state: String,
children: Vec<SessionInfo>,
external_addr: Option<String>,
hosts: Vec<String>,
info: Vec<SessionInfo>,
is_offline: bool,
) -> Self {
Self { id, name, state, children, external_addr, is_offline }
Self { dnet_id, name, hosts, info, is_offline }
}
}
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Eq)]
pub struct SessionInfo {
pub id: String,
pub dnet_id: String,
pub node_id: String,
pub name: String,
pub parent: String,
pub addr: String,
pub state: String,
pub info: Vec<SlotInfo>,
pub is_empty: bool,
pub children: Vec<ConnectInfo>,
pub accept_addr: Option<String>,
pub hosts: Option<Vec<String>>,
}
impl SessionInfo {
pub fn new(
id: String,
dnet_id: String,
node_id: String,
name: String,
addr: String,
state: String,
info: Vec<SlotInfo>,
is_empty: bool,
parent: String,
children: Vec<ConnectInfo>,
accept_addr: Option<String>,
hosts: Option<Vec<String>>,
) -> Self {
Self { id, name, is_empty, parent, children, accept_addr, hosts }
Self { dnet_id, node_id, name, addr, state, info, is_empty }
}
}
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Eq)]
pub struct ConnectInfo {
pub id: String,
pub struct SlotInfo {
pub dnet_id: String,
pub node_id: String,
pub addr: String,
pub state: String,
pub parent: String,
pub msg_log: Vec<(NanoTimestamp, String, String)>,
pub random_id: String,
pub remote_id: String,
pub log: Vec<(NanoTimestamp, String, String)>,
pub is_empty: bool,
pub last_msg: String,
pub last_status: String,
pub remote_node_id: String,
}
impl ConnectInfo {
impl SlotInfo {
#[allow(clippy::too_many_arguments)]
pub fn new(
id: String,
dnet_id: String,
node_id: String,
addr: String,
state: String,
parent: String,
msg_log: Vec<(NanoTimestamp, String, String)>,
random_id: String,
remote_id: String,
log: Vec<(NanoTimestamp, String, String)>,
is_empty: bool,
last_msg: String,
last_status: String,
remote_node_id: String,
) -> Self {
Self { id, addr, state, parent, msg_log, is_empty, last_msg, last_status, remote_node_id }
Self {
dnet_id,
addr,
random_id,
remote_id,
log,
node_id,
is_empty,
}
}
}

View File

@@ -30,8 +30,7 @@ use crate::{
config::{DnvConfig, Node, NodeType},
error::{DnetViewError, DnetViewResult},
model::{
ConnectInfo, LilithInfo, Model, NetworkInfo, NodeInfo, SelectableObject, Session,
SessionInfo,
LilithInfo, Model, NetworkInfo, NodeInfo, SelectableObject, Session, SessionInfo, SlotInfo,
},
rpc::RpcConnect,
util::{is_empty_session, make_connect_id, make_empty_id, make_node_id, make_session_id},
@@ -87,13 +86,14 @@ impl DataParser {
// Retrieve node info, based on its type
let response = match &node.node_type {
NodeType::LILITH => client.lilith_spawns().await,
NodeType::NORMAL => client.get_info().await,
NodeType::NORMAL => client.dnet_info().await,
NodeType::CONSENSUS => client.get_consensus_info().await,
};
// Parse response
match response {
Ok(reply) => {
debug!("dnetview:: reply {:?}", reply);
if reply.as_object().is_none() || reply.as_object().unwrap().is_empty() {
return Err(DnetViewError::EmptyRpcReply)
}
@@ -117,86 +117,80 @@ impl DataParser {
}
}
async fn parse_offline(&self, node_name: String) -> DnetViewResult<()> {
// If poll times out, inititalize data structures with empty values.
async fn parse_offline(&self, name: String) -> DnetViewResult<()> {
let name = "Offline".to_string();
let session_type = Session::Offline;
let node_id = make_node_id(&node_name)?;
let session_id = make_session_id(&node_id, &session_type)?;
let mut connects: Vec<ConnectInfo> = Vec::new();
let mut sessions: Vec<SessionInfo> = Vec::new();
// initialize with empty values
let id = make_empty_id(&node_id, &session_type, 0)?;
let mut slots: Vec<SlotInfo> = Vec::new();
let mut info: Vec<SessionInfo> = Vec::new();
let hosts = Vec::new();
// Initialize with empty values
let node_id = make_node_id(&name)?;
let dnet_id = make_empty_id(&node_id, &session_type, 0)?;
let addr = "Null".to_string();
let state = "Null".to_string();
let parent = node_id.clone();
let msg_log = Vec::new();
let random_id = "Null".to_string();
let remote_id = "Null".to_string();
let log = Vec::new();
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,
state.clone(),
parent.clone(),
msg_log,
let slot = SlotInfo::new(
dnet_id.clone(),
node_id.clone(),
addr.clone(),
random_id,
remote_id,
log,
is_empty,
last_msg,
last_status,
remote_node_id,
);
connects.push(connect_info.clone());
slots.push(slot.clone());
let accept_addr = None;
let session_info =
SessionInfo::new(session_id, name, is_empty, parent, connects, accept_addr, None);
sessions.push(session_info);
let session_info = SessionInfo::new(
dnet_id,
node_id.clone(),
name.clone(),
addr.clone(),
state,
slots,
is_empty,
);
info.push(session_info);
let node = NodeInfo::new(node_id, node_name, state, sessions.clone(), None, true);
let node = NodeInfo::new(node_id.clone(), name.clone(), hosts, info.clone(), is_empty);
self.update_selectables(sessions, node).await?;
self.update_selectables(info, node).await?;
Ok(())
}
async fn parse_data(
&self,
reply: &serde_json::Map<String, Value>,
node_name: String,
name: String,
) -> DnetViewResult<()> {
//let addr = &reply.get("addr");
let hosts = &reply["hosts"];
let inbound = &reply["inbound"];
//let _manual = &reply["session_manual"];
let outbound = &reply["outbound"];
let state = String::new();
let mut sessions: Vec<SessionInfo> = Vec::new();
let dnet_id = make_node_id(&name)?;
let node_id = make_node_id(&node_name)?;
let mut info: Vec<SessionInfo> = Vec::new();
//let ext_addr = self.parse_external_addr(addr).await?;
let ext_addr = None;
let inbound = self.parse_inbound(inbound, &dnet_id).await?;
let outbound = self.parse_outbound(outbound, &dnet_id).await?;
let in_session = self.parse_inbound(inbound, &node_id).await?;
let out_session = self.parse_outbound(outbound, &node_id).await?;
//let man_session = self.parse_manual(manual, &node_id).await?;
// TODO
// let hosts = self.parse_hosts(hosts)...
let hosts = Vec::new();
sessions.push(in_session.clone());
sessions.push(out_session.clone());
//sessions.push(man_session.clone());
info.push(inbound.clone());
info.push(outbound.clone());
let node = NodeInfo::new(
node_id,
node_name,
state,
//state.as_str().unwrap().to_string(),
sessions.clone(),
ext_addr,
false,
);
let node = NodeInfo::new(dnet_id, name, hosts, info.clone(), false);
self.update_selectables(sessions.clone(), node).await?;
self.update_msgs(sessions).await?;
self.update_selectables(info.clone(), node).await?;
self.update_msgs(info.clone()).await?;
//debug!("IDS: {:?}", self.model.ids.lock().await);
//debug!("INFOS: {:?}", self.model.nodes.lock().await);
@@ -238,22 +232,22 @@ impl DataParser {
async fn update_msgs(&self, sessions: Vec<SessionInfo>) -> DnetViewResult<()> {
for session in sessions {
for connection in session.children {
if !self.model.msg_map.lock().await.contains_key(&connection.id) {
for connection in session.info {
if !self.model.msg_map.lock().await.contains_key(&connection.dnet_id) {
// we don't have this ID: it is a new node
self.model
.msg_map
.lock()
.await
.insert(connection.id, connection.msg_log.clone());
.insert(connection.dnet_id, connection.log.clone());
} else {
// we have this id: append the msg values
match self.model.msg_map.lock().await.entry(connection.id) {
match self.model.msg_map.lock().await.entry(connection.dnet_id) {
Entry::Vacant(e) => {
e.insert(connection.msg_log);
e.insert(connection.log);
}
Entry::Occupied(mut e) => {
for msg in connection.msg_log {
for msg in connection.log {
e.get_mut().push(msg);
}
}
@@ -271,10 +265,10 @@ impl DataParser {
) -> DnetViewResult<()> {
if node.is_offline {
let node_obj = SelectableObject::Node(node.clone());
self.model.selectables.lock().await.insert(node.id.clone(), node_obj.clone());
self.model.selectables.lock().await.insert(node.dnet_id.clone(), node_obj.clone());
} else {
let node_obj = SelectableObject::Node(node.clone());
self.model.selectables.lock().await.insert(node.id.clone(), node_obj.clone());
self.model.selectables.lock().await.insert(node.dnet_id.clone(), node_obj.clone());
for session in sessions {
if !session.is_empty {
let session_obj = SelectableObject::Session(session.clone());
@@ -282,14 +276,14 @@ impl DataParser {
.selectables
.lock()
.await
.insert(session.clone().id, session_obj.clone());
for connect in session.children {
.insert(session.clone().dnet_id, session_obj.clone());
for connect in session.info {
let connect_obj = SelectableObject::Connect(connect.clone());
self.model
.selectables
.lock()
.await
.insert(connect.clone().id, connect_obj.clone());
.insert(connect.clone().dnet_id, connect_obj.clone());
}
}
}
@@ -314,124 +308,158 @@ impl DataParser {
) -> DnetViewResult<SessionInfo> {
let name = "Inbound".to_string();
let session_type = Session::Inbound;
let parent = node_id.to_string();
let id = make_session_id(&parent, &session_type)?;
let mut connects: Vec<ConnectInfo> = Vec::new();
let connections = &inbound["connected"];
let dnet_id = make_session_id(node_id, &session_type)?;
let mut info: Vec<SlotInfo> = Vec::new();
// TODO: fixme
let mut connect_count = 0;
let mut accept_vec = Vec::new();
match connections.as_object() {
Some(connect) => {
match connect.is_empty() {
true => {
connect_count += 1;
// channel is empty. initialize with empty values
let id = make_empty_id(node_id, &session_type, connect_count)?;
let addr = "Null".to_string();
let state = "Null".to_string();
let parent = parent.clone();
let msg_log = Vec::new();
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,
state,
parent,
msg_log,
is_empty,
last_msg,
last_status,
remote_node_id,
);
connects.push(connect_info);
}
false => {
// channel is not empty. initialize with whole values
for k in connect.keys() {
let node = connect.get(k);
let addr = k.to_string();
let info = node.unwrap().as_array();
// get the accept address
let accept_addr = info.unwrap().get(0);
let acc_addr = accept_addr
.unwrap()
.get("accept_addr")
.unwrap()
.as_str()
.unwrap()
.to_string();
accept_vec.push(acc_addr);
let info2 = info.unwrap().get(1);
let id = info2.unwrap().get("random_id").unwrap().as_u64().unwrap();
let id = make_connect_id(&id)?;
let state = "state".to_string();
let parent = parent.clone();
// this will return true rn
if inbound.is_null() {
let dnet_id = make_empty_id(node_id, &session_type, connect_count)?;
let addr = "Null".to_string();
//let state = "Null".to_string();
let node_id = node_id.clone();
let log = Vec::new();
let is_empty = true;
//let last_msg = "Null".to_string();
//let last_status = "Null".to_string();
let remote_id = "Null".to_string();
let random_id = "Null".to_string();
// Empty message log for now.
let msg_log = Vec::new();
let node_id = node_id.to_string();
let is_empty = false;
let last_msg = info2
.unwrap()
.get("last_msg")
.unwrap()
.as_str()
.unwrap()
.to_string();
let last_status = info2
.unwrap()
.get("last_status")
.unwrap()
.as_str()
.unwrap()
.to_string();
let remote_node_id = info2
.unwrap()
.get("remote_node_id")
.unwrap()
.as_str()
.unwrap()
.to_string();
let r_node_id: String = match remote_node_id.is_empty() {
true => "no remote id".to_string(),
false => remote_node_id,
};
let connect_info = ConnectInfo::new(
id,
addr,
state,
parent,
msg_log,
is_empty,
last_msg,
last_status,
r_node_id,
);
connects.push(connect_info.clone());
}
}
}
let is_empty = is_empty_session(&connects);
// TODO: clean this up
if accept_vec.is_empty() {
let accept_addr = None;
let session_info =
SessionInfo::new(id, name, is_empty, parent, connects, accept_addr, None);
Ok(session_info)
} else {
let accept_addr = Some(accept_vec[0].clone());
let session_info =
SessionInfo::new(id, name, is_empty, parent, connects, accept_addr, None);
Ok(session_info)
}
}
None => Err(DnetViewError::ValueIsNotObject),
let slot = SlotInfo::new(
dnet_id, node_id, addr, random_id, remote_id, log,
is_empty,
//state,
//last_msg,
//last_status,
);
info.push(slot);
}
let is_empty = is_empty_session(&info);
let addr = String::new();
let state = String::new();
let session_info =
SessionInfo::new(dnet_id, node_id.clone(), name, addr, state, info, is_empty);
Ok(session_info)
//return Err(DnetViewError::ValueIsNotObject)
//let connections = &inbound["connected"];
//match connections.as_object() {
// Some(connect) => {
// match connect.is_empty() {
// true => {
// connect_count += 1;
// // channel is empty. initialize with empty values
// let id = make_empty_id(node_id, &session_type, connect_count)?;
// let addr = "Null".to_string();
// let state = "Null".to_string();
// let node_id = node_id.clone();
// let log = Vec::new();
// let is_empty = true;
// let last_msg = "Null".to_string();
// let last_status = "Null".to_string();
// let remote_id = "Null".to_string();
// let slot = SlotInfo::new(
// id,
// addr,
// state,
// node_id,
// log,
// is_empty,
// last_msg,
// last_status,
// remote_id,
// );
// info.push(slot);
// }
// false => {
// // channel is not empty. initialize with whole values
// for k in connect.keys() {
// let node = connect.get(k);
// let addr = k.to_string();
// let info = node.unwrap().as_array();
// // get the accept address
// let accept_addr = info.unwrap().get(0);
// let acc_addr = accept_addr
// .unwrap()
// .get("accept_addr")
// .unwrap()
// .as_str()
// .unwrap()
// .to_string();
// accept_vec.push(acc_addr);
// let info2 = info.unwrap().get(1);
// let id = info2.unwrap().get("random_id").unwrap().as_u64().unwrap();
// let id = make_connect_id(&id)?;
// let state = "state".to_string();
// let node_id = node_id.clone();
// // Empty message log for now.
// let log = Vec::new();
// let is_empty = false;
// let last_msg = info2
// .unwrap()
// .get("last_msg")
// .unwrap()
// .as_str()
// .unwrap()
// .to_string();
// let last_status = info2
// .unwrap()
// .get("last_status")
// .unwrap()
// .as_str()
// .unwrap()
// .to_string();
// let remote_id = info2
// .unwrap()
// .get("remote_id")
// .unwrap()
// .as_str()
// .unwrap()
// .to_string();
// let r_node_id: String = match remote_id.is_empty() {
// true => "no remote id".to_string(),
// false => remote_id,
// };
// let slot = SlotInfo::new(
// id,
// addr,
// state,
// node_id,
// log,
// is_empty,
// last_msg,
// last_status,
// r_node_id,
// );
// info.push(slot.clone());
// }
// }
// }
// // TODO: clean this up
// if accept_vec.is_empty() {
// let accept_addr = None;
// let session_info =
// SessionInfo::new(id, name, is_empty, node_id, info, accept_addr, None);
// Ok(session_info)
// } else {
// let accept_addr = Some(accept_vec[0].clone());
// let session_info =
// SessionInfo::new(id, name, is_empty, node_id, info, accept_addr, None);
// Ok(session_info)
// }
// }
// None => Err(DnetViewError::ValueIsNotObject),
//}
}
// TODO: placeholder for now
@@ -442,44 +470,39 @@ impl DataParser {
) -> DnetViewResult<SessionInfo> {
let name = "Manual".to_string();
let session_type = Session::Manual;
let mut connects: Vec<ConnectInfo> = Vec::new();
let parent = node_id.to_string();
let mut info: Vec<SlotInfo> = Vec::new();
let session_id = make_session_id(&parent, &session_type)?;
//let dnet_id = make_session_id(&node_id, &session_type)?;
//let id: u64 = 0;
let connect_id = make_empty_id(node_id, &session_type, 0)?;
let dnet_id = make_empty_id(node_id, &session_type, 0)?;
//let connect_id = make_connect_id(&id)?;
let addr = "Null".to_string();
let state = "Null".to_string();
let msg_log = Vec::new();
let log = Vec::new();
let is_empty = true;
let msg = "Null".to_string();
let status = "Null".to_string();
let remote_node_id = "Null".to_string();
let connect_info = ConnectInfo::new(
connect_id.clone(),
addr,
state,
parent,
msg_log,
let remote_id = "Null".to_string();
let random_id = "Null".to_string();
let node_id = node_id.to_string();
let slot = SlotInfo::new(
dnet_id.clone(),
node_id.clone(),
addr.clone(),
random_id,
remote_id,
log,
is_empty,
msg,
status,
remote_node_id,
);
connects.push(connect_info);
let parent = connect_id;
let is_empty = is_empty_session(&connects);
let accept_addr = None;
let session_info = SessionInfo::new(
session_id,
name,
is_empty,
parent,
connects.clone(),
accept_addr,
None,
//state,
//msg,
//status,
);
info.push(slot);
//let node_id = connect_id;
let is_empty = is_empty_session(&info);
let session_info = SessionInfo::new(dnet_id, node_id, name, addr, state, info, is_empty);
Ok(session_info)
}
@@ -491,106 +514,139 @@ impl DataParser {
) -> DnetViewResult<SessionInfo> {
let name = "Outbound".to_string();
let session_type = Session::Outbound;
let parent = node_id.to_string();
let id = make_session_id(&parent, &session_type)?;
let mut connects: Vec<ConnectInfo> = Vec::new();
let slots = &outbound["slots"];
let dnet_id = make_session_id(node_id, &session_type)?;
let node_id = node_id.to_string();
let mut info: Vec<SlotInfo> = Vec::new();
// TODO: fixme
let mut slot_count = 0;
let hosts = &outbound["hosts"];
match slots.as_array() {
Some(slots) => {
for slot in slots {
slot_count += 1;
match slot["channel"].is_null() {
true => {
// TODO: this is not actually empty
let id = make_empty_id(node_id, &session_type, slot_count)?;
let addr = "Null".to_string();
let state = &slot["state"];
let state = state.as_str().unwrap().to_string();
let parent = parent.clone();
let msg_log = Vec::new();
let is_empty = false;
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,
state,
parent,
msg_log,
is_empty,
last_msg,
last_status,
remote_node_id,
);
connects.push(connect_info.clone());
}
false => {
// channel is not empty. initialize with whole values
let channel = &slot["channel"];
let id = channel["random_id"].as_u64().unwrap();
let id = make_connect_id(&id)?;
let addr = &slot["addr"];
let addr = addr.as_str().unwrap().to_string();
let state = &slot["state"];
let state = state.as_str().unwrap().to_string();
let parent = parent.clone();
// Empty message log for now.
let msg_log = Vec::new();
let is_empty = false;
let last_msg = channel["last_msg"].as_str().unwrap().to_string();
let last_status = channel["last_status"].as_str().unwrap().to_string();
let remote_node_id =
channel["remote_node_id"].as_str().unwrap().to_string();
let r_node_id: String = match remote_node_id.is_empty() {
true => "no remote id".to_string(),
false => remote_node_id,
};
let connect_info = ConnectInfo::new(
id,
addr,
state,
parent,
msg_log,
is_empty,
last_msg,
last_status,
r_node_id,
);
connects.push(connect_info.clone());
}
}
}
let is_empty = is_empty_session(&connects);
let accept_addr = None;
match hosts.as_array() {
Some(hosts) => {
let hosts: Vec<String> =
hosts.iter().map(|addr| addr.as_str().unwrap().to_string()).collect();
let session_info = SessionInfo::new(
id,
name,
is_empty,
parent,
connects,
accept_addr,
Some(hosts),
);
Ok(session_info)
}
None => Err(DnetViewError::ValueIsNotObject),
}
}
None => Err(DnetViewError::ValueIsNotObject),
// this will return true rn
if outbound.is_null() {
let dnet_id = make_empty_id(&node_id, &session_type, slot_count)?;
let addr = "Null".to_string();
//let state = &slot["state"];
//let state = state.as_str().unwrap().to_string();
let node_id = node_id.clone();
let log = Vec::new();
let is_empty = false;
//let last_msg = "Null".to_string();
//let last_status = "Null".to_string();
let random_id = "Null".to_string();
let remote_id = "Null".to_string();
let slot = SlotInfo::new(
dnet_id, node_id, addr, random_id, remote_id, log,
is_empty,
//state,
//last_msg,
//last_status,
);
info.push(slot.clone());
}
let state = String::new();
let addr = String::new();
let is_empty = true;
let session_info = SessionInfo::new(dnet_id, node_id, name, addr, state, info, is_empty);
Ok(session_info)
//return Err(DnetViewError::ValueIsNotObject)
//let slots = &outbound["slots"];
//let hosts = &outbound["hosts"];
//match slots.as_array() {
// Some(slots) => {
// for slot in slots {
// slot_count += 1;
// match slot["channel"].is_null() {
// true => {
// // TODO: this is not actually empty
// let id = make_empty_id(node_id, &session_type, slot_count)?;
// let addr = "Null".to_string();
// let state = &slot["state"];
// let state = state.as_str().unwrap().to_string();
// let node_id = node_id.clone();
// let log = Vec::new();
// let is_empty = false;
// let last_msg = "Null".to_string();
// let last_status = "Null".to_string();
// let remote_id = "Null".to_string();
// let slot = SlotInfo::new(
// id,
// addr,
// state,
// node_id,
// log,
// is_empty,
// last_msg,
// last_status,
// remote_id,
// );
// info.push(slot.clone());
// }
// false => {
// // channel is not empty. initialize with whole values
// let channel = &slot["channel"];
// let id = channel["random_id"].as_u64().unwrap();
// let id = make_connect_id(&id)?;
// let addr = &slot["addr"];
// let addr = addr.as_str().unwrap().to_string();
// let state = &slot["state"];
// let state = state.as_str().unwrap().to_string();
// let node_id = node_id.clone();
// // Empty message log for now.
// let log = Vec::new();
// let is_empty = false;
// let last_msg = channel["last_msg"].as_str().unwrap().to_string();
// let last_status = channel["last_status"].as_str().unwrap().to_string();
// let remote_id =
// channel["remote_id"].as_str().unwrap().to_string();
// let r_node_id: String = match remote_id.is_empty() {
// true => "no remote id".to_string(),
// false => remote_id,
// };
// let slot = SlotInfo::new(
// id,
// addr,
// state,
// node_id,
// log,
// is_empty,
// last_msg,
// last_status,
// r_node_id,
// );
// info.push(slot.clone());
// }
// }
// }
// let is_empty = is_empty_session(&info);
// let accept_addr = None;
// match hosts.as_array() {
// Some(hosts) => {
// let hosts: Vec<String> =
// hosts.iter().map(|addr| addr.as_str().unwrap().to_string()).collect();
// let session_info = SessionInfo::new(
// id,
// name,
// is_empty,
// node_id,
// info,
// accept_addr,
// Some(hosts),
// );
// Ok(session_info)
// }
// None => Err(DnetViewError::ValueIsNotObject),
// }
// }
// None => Err(DnetViewError::ValueIsNotObject),
//}
}
}

View File

@@ -44,9 +44,9 @@ impl RpcConnect {
self.rpc_client.request(req).await
}
// --> {"jsonrpc": "2.0", "method": "get_info", "params": [], "id": 42}
// --> {"jsonrpc": "2.0", "method": "dnet_info", "params": [], "id": 42}
// <-- {"jsonrpc": "2.0", "result": {"nodeID": [], "nodeinfo" [], "id": 42}
pub async fn get_info(&self) -> DnetViewResult<Value> {
pub async fn dnet_info(&self) -> DnetViewResult<Value> {
let req = JsonRequest::new("dnet_info", json!([]));
match self.rpc_client.request(req).await {
Ok(req) => Ok(req),

View File

@@ -18,7 +18,7 @@
use darkfi::Result;
use crate::model::{ConnectInfo, Session};
use crate::model::{Session, SlotInfo};
pub fn make_node_id(node_name: &String) -> Result<String> {
let mut id = hex::encode(node_name);
@@ -118,6 +118,6 @@ pub fn make_empty_id(node_id: &str, session: &Session, count: u64) -> Result<Str
Ok(id)
}
pub fn is_empty_session(connects: &[ConnectInfo]) -> bool {
pub fn is_empty_session(connects: &[SlotInfo]) -> bool {
return connects.iter().all(|conn| conn.is_empty)
}

View File

@@ -88,18 +88,17 @@ impl<'a> View {
for obj in self.selectables.values() {
match obj {
SelectableObject::Node(node) => {
if !self.ordered_list.iter().any(|i| i == &node.id) {
self.ordered_list.push(node.id.clone());
}
if !self.ordered_list.iter().any(|i| i == &node.dnet_id) {
self.ordered_list.push(node.dnet_id.clone()); }
if !node.is_offline {
for session in &node.children {
for session in &node.info {
if !session.is_empty {
if !self.ordered_list.iter().any(|i| i == &session.id) {
self.ordered_list.push(session.id.clone());
if !self.ordered_list.iter().any(|i| i == &session.dnet_id) {
self.ordered_list.push(session.dnet_id.clone());
}
for connection in &session.children {
if !self.ordered_list.iter().any(|i| i == &connection.id) {
self.ordered_list.push(connection.id.clone());
for connection in &session.info {
if !self.ordered_list.iter().any(|i| i == &connection.dnet_id) {
self.ordered_list.push(connection.dnet_id.clone());
}
}
}
@@ -201,13 +200,13 @@ impl<'a> View {
let lines = vec![Spans::from(name_span)];
let names = ListItem::new(lines);
nodes.push(names);
for session in &node.children {
for session in &node.info {
if !session.is_empty {
let name = Span::styled(format!(" {}", session.name), style);
let lines = vec![Spans::from(name)];
let names = ListItem::new(lines);
nodes.push(names);
for connection in &session.children {
for connection in &session.info {
let mut info = Vec::new();
match connection.addr.as_str() {
"Null" => {
@@ -224,7 +223,7 @@ impl<'a> View {
let name = Span::styled(
format!(
" {} ({})",
addr, connection.remote_node_id
addr, connection.remote_id
),
style,
);
@@ -315,42 +314,42 @@ impl<'a> View {
Some(SelectableObject::Node(node)) => {
//debug!(target: "dnetview", "render_info()::SelectableObject::Node");
lines.push(Spans::from(Span::styled("Type: Normal", style)));
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("External addr: Null".to_string(), style);
lines.push(Spans::from(node_info));
}
}
lines.push(Spans::from(Span::styled(
format!("P2P state: {}", node.state),
style,
)));
//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("External addr: Null".to_string(), style);
// lines.push(Spans::from(node_info));
// }
//}
//lines.push(Spans::from(Span::styled(
// format!("P2P state: {}", node.state),
// style,
//)));
}
Some(SelectableObject::Session(session)) => {
//debug!(target: "dnetview", "render_info()::SelectableObject::Session");
if session.accept_addr.is_some() {
let accept_addr = Span::styled(
format!("Accept addr: {}", session.accept_addr.as_ref().unwrap()),
style,
);
lines.push(Spans::from(accept_addr));
}
if session.hosts.is_some() {
let hosts = Span::styled("Hosts:".to_string(), style);
lines.push(Spans::from(hosts));
for host in session.hosts.as_ref().unwrap() {
let host = Span::styled(format!(" {}", host), style);
lines.push(Spans::from(host));
}
}
//if session.addr.is_some() {
// let accept_addr = Span::styled(
// format!("Accept addr: {}", session.addr.as_ref().unwrap()),
// style,
// );
// lines.push(Spans::from(accept_addr));
//}
//if session.hosts.is_some() {
// let hosts = Span::styled("Hosts:".to_string(), style);
// lines.push(Spans::from(hosts));
// for host in session.hosts.as_ref().unwrap() {
// let host = Span::styled(format!(" {}", host), style);
// lines.push(Spans::from(host));
// }
//}
}
Some(SelectableObject::Connect(connect)) => {
//debug!(target: "dnetview", "render_info()::SelectableObject::Connect");
let text = self.parse_msg_list(connect.id.clone())?;
let text = self.parse_msg_list(connect.dnet_id.clone())?;
f.render_stateful_widget(text, slice[1], &mut self.msg_list.state);
}
Some(SelectableObject::Lilith(_lilith)) => {