mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-04-28 03:00:18 -04:00
dnetview: add external_addr to node info
* add external addr to Model.NodeInfo * parse external addr from RPC * display in View
This commit is contained in:
@@ -9,12 +9,14 @@ pub enum DnetViewError {
|
||||
ValueIsNotObject,
|
||||
#[error("Failed to find ID at current index")]
|
||||
NoIdAtIndex,
|
||||
#[error("Found unexpected data in View")]
|
||||
UnexpectedData(String),
|
||||
#[error("Message log does not contain ID")]
|
||||
CannotFindId,
|
||||
#[error("ID does not return a selectable object")]
|
||||
NotSelectableObject,
|
||||
#[error("JSON data does not contain an external addr")]
|
||||
NoExternalAddr,
|
||||
#[error("Found unexpected data in View")]
|
||||
UnexpectedData(String),
|
||||
#[error("InternalError")]
|
||||
Darkfi(#[from] darkfi::error::Error),
|
||||
#[error("Json serialization error: `{0}`")]
|
||||
|
||||
@@ -165,7 +165,7 @@ async fn parse_data(
|
||||
client: &DnetView,
|
||||
model: Arc<Model>,
|
||||
) -> DnetViewResult<()> {
|
||||
let _ext_addr = reply.get("external_addr");
|
||||
let addr = &reply.get("external_addr");
|
||||
let inbound = &reply["session_inbound"];
|
||||
let manual = &reply["session_manual"];
|
||||
let outbound = &reply["session_outbound"];
|
||||
@@ -174,7 +174,9 @@ async fn parse_data(
|
||||
|
||||
let node_name = &client.name;
|
||||
let node_id = make_node_id(node_name)?;
|
||||
//let external_addr = ext_addr.unwrap().as_str().unwrap();
|
||||
|
||||
let ext_addr = parse_external_addr(addr).await?;
|
||||
let in_session = parse_inbound(inbound, &node_id).await?;
|
||||
let out_session = parse_outbound(outbound, &node_id).await?;
|
||||
let man_session = parse_manual(manual, &node_id).await?;
|
||||
@@ -183,7 +185,7 @@ 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());
|
||||
let node = NodeInfo::new(node_id.clone(), node_name.to_string(), sessions.clone(), ext_addr);
|
||||
|
||||
update_node(model.clone(), node.clone(), node_id.clone()).await;
|
||||
update_selectable_and_ids(model.clone(), sessions.clone(), node.clone()).await?;
|
||||
@@ -247,6 +249,16 @@ async fn update_selectable_and_ids(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn parse_external_addr(addr: &Option<&Value>) -> DnetViewResult<String> {
|
||||
match addr {
|
||||
Some(addr) => match addr.as_str() {
|
||||
Some(addr) => return Ok(addr.to_string()),
|
||||
None => return Ok("null".to_string()),
|
||||
},
|
||||
None => Err(DnetViewError::NoExternalAddr),
|
||||
}
|
||||
}
|
||||
|
||||
async fn parse_inbound(inbound: &Value, node_id: &String) -> DnetViewResult<SessionInfo> {
|
||||
let name = "Inbound".to_string();
|
||||
let session_type = Session::Inbound;
|
||||
|
||||
@@ -40,11 +40,17 @@ pub struct NodeInfo {
|
||||
pub id: String,
|
||||
pub name: String,
|
||||
pub children: Vec<SessionInfo>,
|
||||
pub external_addr: String,
|
||||
}
|
||||
|
||||
impl NodeInfo {
|
||||
pub fn new(id: String, name: String, children: Vec<SessionInfo>) -> NodeInfo {
|
||||
NodeInfo { id, name, children }
|
||||
pub fn new(
|
||||
id: String,
|
||||
name: String,
|
||||
children: Vec<SessionInfo>,
|
||||
external_addr: String,
|
||||
) -> NodeInfo {
|
||||
NodeInfo { id, name, children, external_addr }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -194,9 +194,10 @@ impl View {
|
||||
let info = self.selectables.get(&selected);
|
||||
|
||||
match info {
|
||||
Some(SelectableObject::Node(_node)) => {
|
||||
//let name_span = Spans::from("Node Info");
|
||||
//spans.push(name_span);
|
||||
Some(SelectableObject::Node(node)) => {
|
||||
let node_info =
|
||||
Span::styled(format!("External addr: {}", node.external_addr), style);
|
||||
lines.push(Spans::from(node_info));
|
||||
}
|
||||
Some(SelectableObject::Session(_session)) => {
|
||||
//let name_span = Spans::from("Session Info");
|
||||
|
||||
Reference in New Issue
Block a user