Skip to content

Commit

Permalink
fix relay stats
Browse files Browse the repository at this point in the history
  • Loading branch information
sdbondi committed Nov 8, 2024
1 parent f9087a8 commit c78fac2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 15 deletions.
7 changes: 2 additions & 5 deletions applications/minotari_node/src/commands/command/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,8 @@ impl CommandContext {
},
}

if relay_stats.num_active_relay_reservations > 0 || relay_stats.num_active_circuits > 0 {
status_line.add("relay");
}
if relay_stats.num_active_relay_reservations > 0 {
status_line.add_field("rsrv", relay_stats.num_active_relay_reservations.to_string());
if !relay_stats.active_relay_reservations.is_empty() {
status_line.add_field("rsrv", relay_stats.active_relay_reservations.len().to_string());
}
if relay_stats.num_active_circuits > 0 {
status_line.add_field("circ", relay_stats.num_active_circuits.to_string());
Expand Down
4 changes: 2 additions & 2 deletions network/core/src/relay_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ pub(crate) struct RelayPeer {
pub remote_address: Option<Multiaddr>,
}

#[derive(Debug, Clone, Copy, Default)]
#[derive(Debug, Clone, Default)]
pub struct RelayStats {
pub num_active_relay_reservations: usize,
pub active_relay_reservations: HashSet<PeerId>,
pub num_active_circuits: usize,
pub current_relay_peer: Option<PeerId>,
}
12 changes: 4 additions & 8 deletions network/core/src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ where
let _ignore = reply.send(Ok(self.seed_peers.clone()));
},
NetworkingRequest::GetRelayStats { reply } => {
let _ignore = reply.send(Ok(self.relay_stats));
let _ignore = reply.send(Ok(self.relay_stats.clone()));
},
}
}
Expand Down Expand Up @@ -715,6 +715,7 @@ where
if self.relay_stats.current_relay_peer == Some(peer_id) {
self.relay_stats.current_relay_peer = None;
}
self.relay_stats.active_relay_reservations.remove(&peer_id);

self.publish_event(NetworkEvent::PeerDisconnected { peer_id });
},
Expand Down Expand Up @@ -1201,14 +1202,9 @@ where
#[allow(clippy::enum_glob_use)]
use relay::Event::*;
match event {
ReservationReqAccepted { .. } => {
self.relay_stats.num_active_relay_reservations += 1;
ReservationReqAccepted { src_peer_id, .. } => {
self.relay_stats.active_relay_reservations.insert(*src_peer_id);
},
ReservationReqDenied { .. } => {},
ReservationTimedOut { .. } => {
self.relay_stats.num_active_relay_reservations -= 1;
},
CircuitReqDenied { .. } => {},
CircuitReqAccepted { .. } => {
self.relay_stats.num_active_circuits += 1;
},
Expand Down

0 comments on commit c78fac2

Please sign in to comment.