collect node capabilities
This commit is contained in:
@@ -303,6 +303,8 @@ impl PublicNode {
|
|||||||
pub struct ConnectedNode {
|
pub struct ConnectedNode {
|
||||||
pub address: String,
|
pub address: String,
|
||||||
pub user_agent: String,
|
pub user_agent: String,
|
||||||
|
pub bits: u32,
|
||||||
|
pub is_archival: bool,
|
||||||
pub location: String,
|
pub location: String,
|
||||||
pub flag: String,
|
pub flag: String,
|
||||||
pub isp: String,
|
pub isp: String,
|
||||||
@@ -313,6 +315,8 @@ impl ConnectedNode {
|
|||||||
ConnectedNode {
|
ConnectedNode {
|
||||||
address: String::new(),
|
address: String::new(),
|
||||||
user_agent: String::new(),
|
user_agent: String::new(),
|
||||||
|
bits: 0,
|
||||||
|
is_archival: false,
|
||||||
location: String::new(),
|
location: String::new(),
|
||||||
flag: String::new(),
|
flag: String::new(),
|
||||||
isp: 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?;
|
let resp = call("get_connected_peers", "[]", "1", "owner").await?;
|
||||||
|
|
||||||
if resp != Value::Null {
|
if resp != Value::Null {
|
||||||
let mut node = ConnectedNode::new();
|
|
||||||
|
|
||||||
// Collecting peers from local node
|
// Collecting peers from local node
|
||||||
for peer in resp["result"]["Ok"].as_array().unwrap() {
|
for peer in resp["result"]["Ok"].as_array().unwrap() {
|
||||||
|
let mut node = ConnectedNode::new();
|
||||||
|
|
||||||
if peer["direction"] == "Inbound" {
|
if peer["direction"] == "Inbound" {
|
||||||
inbound += 1;
|
inbound += 1;
|
||||||
}
|
}
|
||||||
if peer["direction"] == "Outbound" {
|
if peer["direction"] == "Outbound" {
|
||||||
outbound += 1;
|
outbound += 1;
|
||||||
}
|
}
|
||||||
// Collecting user_agent nodes stats
|
|
||||||
|
// Collecting peers
|
||||||
if !addrs.contains(&peer["addr"].to_string()) {
|
if !addrs.contains(&peer["addr"].to_string()) {
|
||||||
*peers.entry(peer["user_agent"].to_string()).or_insert(0) += 1;
|
*peers.entry(peer["user_agent"].to_string()).or_insert(0) += 1;
|
||||||
addrs.push(peer["addr"].to_string());
|
addrs.push(peer["addr"].to_string());
|
||||||
node.address = peer["addr"].as_str().unwrap().to_string();
|
node.address = peer["addr"].as_str().unwrap().to_string();
|
||||||
node.user_agent = peer["user_agent"].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());
|
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 {
|
match call_external("get_connected_peers", "[]", "1", "owner", endpoint).await {
|
||||||
Ok(resp) => {
|
Ok(resp) => {
|
||||||
if resp != Value::Null {
|
if resp != Value::Null {
|
||||||
let mut node = ConnectedNode::new();
|
|
||||||
if resp["result"]["Ok"].is_null() == false {
|
if resp["result"]["Ok"].is_null() == false {
|
||||||
for peer in resp["result"]["Ok"].as_array().unwrap() {
|
for peer in resp["result"]["Ok"].as_array().unwrap() {
|
||||||
|
let mut node = ConnectedNode::new();
|
||||||
|
|
||||||
// Collecting user_agent nodes stats
|
// Collecting user_agent nodes stats
|
||||||
if !addrs.contains(&peer["addr"].to_string()) {
|
if !addrs.contains(&peer["addr"].to_string()) {
|
||||||
*peers.entry(peer["user_agent"].to_string()).or_insert(0) += 1;
|
*peers.entry(peer["user_agent"].to_string()).or_insert(0) += 1;
|
||||||
addrs.push(peer["addr"].to_string());
|
addrs.push(peer["addr"].to_string());
|
||||||
node.address = peer["addr"].as_str().unwrap().to_string();
|
node.address = peer["addr"].as_str().unwrap().to_string();
|
||||||
node.user_agent = peer["user_agent"].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());
|
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 border-bottom-0 border-start-0 border-end-0 rounded-0">
|
||||||
<div class="card-body" align="left">
|
<div class="card-body" align="left">
|
||||||
<div class="d-flex justify-content-start">
|
<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 class="darkorange-text">{{ node.name }}</div>
|
||||||
</div>
|
</div>
|
||||||
<br>
|
<br>
|
||||||
@@ -157,7 +156,11 @@
|
|||||||
<div class="card-group rounded-0">
|
<div class="card-group rounded-0">
|
||||||
<div class="card border-top-0 border-start-0 rounded-0">
|
<div class="card border-top-0 border-start-0 rounded-0">
|
||||||
<div class="card-body">
|
<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>
|
<div class="value-text">{{ node.address }}</div>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="card border-top-0 rounded-0">
|
<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 border-bottom-0 border-start-0 border-end-0 rounded-0">
|
||||||
<div class="card-body" align="left">
|
<div class="card-body" align="left">
|
||||||
<div class="d-flex justify-content-start">
|
<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>
|
<div class="darkorange-text">{{ node.address }}</div>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
<br>
|
<br>
|
||||||
<div class="d-flex justify-content-between">
|
<div class="d-flex justify-content-between">
|
||||||
@@ -197,7 +203,7 @@
|
|||||||
<br>
|
<br>
|
||||||
<div class="d-flex justify-content-between">
|
<div class="d-flex justify-content-between">
|
||||||
<div class="value-text">ISP</div>
|
<div class="value-text">ISP</div>
|
||||||
<div class="value-text">{{ node.isp }}</div>
|
<div class="value-text text-end">{{ node.isp }}</div>
|
||||||
</div>
|
</div>
|
||||||
<br>
|
<br>
|
||||||
<div class="d-flex justify-content-between">
|
<div class="d-flex justify-content-between">
|
||||||
|
|||||||
Reference in New Issue
Block a user