diff --git a/src/data.rs b/src/data.rs index fdad46a..1153dbf 100644 --- a/src/data.rs +++ b/src/data.rs @@ -301,21 +301,25 @@ impl PublicNode { // Connected node data #[derive(PartialEq, Eq, Debug, Clone, Serialize, Deserialize)] pub struct ConnectedNode { - pub address: String, - pub user_agent: String, - pub location: String, - pub flag: String, - pub isp: String, + pub address: String, + pub user_agent: String, + pub bits: u32, + pub is_archival: bool, + pub location: String, + pub flag: String, + pub isp: String, } impl ConnectedNode { pub fn new() -> ConnectedNode { ConnectedNode { - address: String::new(), - user_agent: String::new(), - location: String::new(), - flag: String::new(), - isp: String::new(), + address: String::new(), + user_agent: String::new(), + bits: 0, + is_archival: false, + location: String::new(), + flag: String::new(), + isp: String::new(), } } } diff --git a/src/requests.rs b/src/requests.rs index e6ac3d1..c68b204 100644 --- a/src/requests.rs +++ b/src/requests.rs @@ -141,22 +141,30 @@ pub async fn get_connected_peers(dashboard: Arc>, statistics: A let resp = call("get_connected_peers", "[]", "1", "owner").await?; if resp != Value::Null { - let mut node = ConnectedNode::new(); - // Collecting peers from local node for peer in resp["result"]["Ok"].as_array().unwrap() { + let mut node = ConnectedNode::new(); + if peer["direction"] == "Inbound" { inbound += 1; } if peer["direction"] == "Outbound" { outbound += 1; } - // Collecting user_agent nodes stats + + // Collecting peers if !addrs.contains(&peer["addr"].to_string()) { *peers.entry(peer["user_agent"].to_string()).or_insert(0) += 1; addrs.push(peer["addr"].to_string()); node.address = peer["addr"].as_str().unwrap().to_string(); node.user_agent = peer["user_agent"].as_str().unwrap().to_string(); + node.bits = peer["capabilities"]["bits"].to_string().parse::().unwrap(); + // Check for BLOCK_HIST bit (archival mode) + // https://github.com/mimblewimble/grin/blob/2ec7b4d5cdba44db20d0007a71396e4bfd381cc5/p2p/src/types.rs#L393 + if node.bits & (1 << 5) != 0 { + node.is_archival = true; + } + connected_nodes.push(node.clone()); } } @@ -168,15 +176,21 @@ pub async fn get_connected_peers(dashboard: Arc>, statistics: A match call_external("get_connected_peers", "[]", "1", "owner", endpoint).await { Ok(resp) => { if resp != Value::Null { - let mut node = ConnectedNode::new(); if resp["result"]["Ok"].is_null() == false { for peer in resp["result"]["Ok"].as_array().unwrap() { + let mut node = ConnectedNode::new(); + // Collecting user_agent nodes stats if !addrs.contains(&peer["addr"].to_string()) { *peers.entry(peer["user_agent"].to_string()).or_insert(0) += 1; addrs.push(peer["addr"].to_string()); node.address = peer["addr"].as_str().unwrap().to_string(); node.user_agent = peer["user_agent"].as_str().unwrap().to_string(); + node.bits = peer["capabilities"]["bits"].to_string().parse::().unwrap(); + if node.bits & (1 << 5) != 0 { + node.is_archival = true; + } + connected_nodes.push(node.clone()); } } diff --git a/templates/network.html.tera b/templates/network.html.tera index 137f6cc..e2a7be7 100644 --- a/templates/network.html.tera +++ b/templates/network.html.tera @@ -82,8 +82,7 @@
-   -
{{ node.name }}
+
{{ node.name }}

@@ -157,7 +156,11 @@
-
{{ node.address }}
+ {% if node.is_archival == true %} +
{{ node.address }}
+ {% else %} +
{{ node.address }}
+ {% endif %}
@@ -186,8 +189,11 @@
-   + {% if node.is_archival == true %} +
{{ node.address }}
+ {% else %}
{{ node.address }}
+ {% endif %}

@@ -197,7 +203,7 @@
ISP
-
{{ node.isp }}
+
{{ node.isp }}