collect node capabilities
This commit is contained in:
@@ -303,6 +303,8 @@ impl PublicNode {
|
||||
pub struct ConnectedNode {
|
||||
pub address: String,
|
||||
pub user_agent: String,
|
||||
pub bits: u32,
|
||||
pub is_archival: bool,
|
||||
pub location: String,
|
||||
pub flag: String,
|
||||
pub isp: String,
|
||||
@@ -313,6 +315,8 @@ impl ConnectedNode {
|
||||
ConnectedNode {
|
||||
address: String::new(),
|
||||
user_agent: String::new(),
|
||||
bits: 0,
|
||||
is_archival: false,
|
||||
location: String::new(),
|
||||
flag: String::new(),
|
||||
isp: String::new(),
|
||||
|
||||
+18
-4
@@ -141,22 +141,30 @@ pub async fn get_connected_peers(dashboard: Arc<Mutex<Dashboard>>, 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::<u32>().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<Mutex<Dashboard>>, 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::<u32>().unwrap();
|
||||
if node.bits & (1 << 5) != 0 {
|
||||
node.is_archival = true;
|
||||
}
|
||||
|
||||
connected_nodes.push(node.clone());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,7 +82,6 @@
|
||||
<div class="card border-bottom-0 border-start-0 border-end-0 rounded-0">
|
||||
<div class="card-body" align="left">
|
||||
<div class="d-flex justify-content-start">
|
||||
<i class="bi bi-pc-display-horizontal darkorange-text"></i>
|
||||
<div class="darkorange-text">{{ node.name }}</div>
|
||||
</div>
|
||||
<br>
|
||||
@@ -157,7 +156,11 @@
|
||||
<div class="card-group rounded-0">
|
||||
<div class="card border-top-0 border-start-0 rounded-0">
|
||||
<div class="card-body">
|
||||
{% if node.is_archival == true %}
|
||||
<div class="value-text">{{ node.address }} <i class="bi bi-database" title="archival"></i></div>
|
||||
{% else %}
|
||||
<div class="value-text">{{ node.address }}</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="card border-top-0 rounded-0">
|
||||
@@ -186,8 +189,11 @@
|
||||
<div class="card border-bottom-0 border-start-0 border-end-0 rounded-0">
|
||||
<div class="card-body" align="left">
|
||||
<div class="d-flex justify-content-start">
|
||||
<i class="bi bi-pc-display-horizontal darkorange-text"></i>
|
||||
{% if node.is_archival == true %}
|
||||
<div class="darkorange-text">{{ node.address }} <i class="bi bi-database" title="archival"></i></div>
|
||||
{% else %}
|
||||
<div class="darkorange-text">{{ node.address }}</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
<br>
|
||||
<div class="d-flex justify-content-between">
|
||||
@@ -197,7 +203,7 @@
|
||||
<br>
|
||||
<div class="d-flex justify-content-between">
|
||||
<div class="value-text">ISP</div>
|
||||
<div class="value-text">{{ node.isp }}</div>
|
||||
<div class="value-text text-end">{{ node.isp }}</div>
|
||||
</div>
|
||||
<br>
|
||||
<div class="d-flex justify-content-between">
|
||||
|
||||
Reference in New Issue
Block a user