mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 10:01:17 +00:00
Improvements to system_networkState (#2088)
This commit is contained in:
@@ -129,6 +129,11 @@ impl<TMessage, TSubstream> Behaviour<TMessage, TSubstream> {
|
||||
pub fn drop_node(&mut self, peer_id: &PeerId) {
|
||||
self.custom_protocols.disconnect_peer(peer_id)
|
||||
}
|
||||
|
||||
/// Returns the state of the peerset manager, for debugging purposes.
|
||||
pub fn peerset_debug_info(&self) -> serde_json::Value {
|
||||
self.custom_protocols.peerset_debug_info()
|
||||
}
|
||||
}
|
||||
|
||||
/// Event that can be emitted by the behaviour.
|
||||
|
||||
@@ -317,6 +317,11 @@ impl<TMessage, TSubstream> CustomProto<TMessage, TSubstream> {
|
||||
self.peerset.discovered(peer_id.clone())
|
||||
}
|
||||
|
||||
/// Returns the state of the peerset manager, for debugging purposes.
|
||||
pub fn peerset_debug_info(&self) -> serde_json::Value {
|
||||
self.peerset.debug_info()
|
||||
}
|
||||
|
||||
/// Function that is called when the peerset wants us to connect to a node.
|
||||
fn peerset_report_connect(&mut self, peer_id: PeerId) {
|
||||
let mut occ_entry = match self.peers.entry(peer_id) {
|
||||
|
||||
@@ -99,7 +99,8 @@ pub struct NetworkState {
|
||||
pub peer_id: String,
|
||||
/// List of addresses the node is currently listening on.
|
||||
pub listened_addresses: HashSet<Multiaddr>,
|
||||
// TODO (https://github.com/libp2p/rust-libp2p/issues/978): external_addresses: Vec<Multiaddr>,
|
||||
/// List of addresses the node knows it can be reached as.
|
||||
pub external_addresses: HashSet<Multiaddr>,
|
||||
/// List of node we're connected to.
|
||||
pub connected_peers: HashMap<String, NetworkStatePeer>,
|
||||
/// List of node that we know of but that we're not connected to.
|
||||
@@ -108,6 +109,8 @@ pub struct NetworkState {
|
||||
pub average_download_per_sec: u64,
|
||||
/// Uploaded bytes per second averaged over the past few seconds.
|
||||
pub average_upload_per_sec: u64,
|
||||
/// State of the peerset manager.
|
||||
pub peerset: serde_json::Value,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Serialize)]
|
||||
|
||||
@@ -220,10 +220,12 @@ where TMessage: CustomMessage + Send + 'static {
|
||||
NetworkState {
|
||||
peer_id: Swarm::local_peer_id(&self.swarm).to_base58(),
|
||||
listened_addresses: Swarm::listeners(&self.swarm).cloned().collect(),
|
||||
external_addresses: Swarm::external_addresses(&self.swarm).cloned().collect(),
|
||||
average_download_per_sec: self.bandwidth.average_download_per_sec(),
|
||||
average_upload_per_sec: self.bandwidth.average_upload_per_sec(),
|
||||
connected_peers,
|
||||
not_connected_peers,
|
||||
peerset: self.swarm.peerset_debug_info(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user