aboutsummaryrefslogtreecommitdiffstats
path: root/src/api/peers.rs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-03 04:44:49 +0100
committertv <tv@krebsco.de>2026-11-03 04:44:49 +0100
commit5581992d5603322d7f02bd76625334be3f8a2b18 (patch)
tree3c904680730e7fa6071b2712746092c67d91e644 /src/api/peers.rs
parent05dc2d0373cc8d7b0dc4da63a03a7850e4fefdc8 (diff)
measure 2-hop neighbourhood
Diffstat (limited to 'src/api/peers.rs')
-rw-r--r--src/api/peers.rs17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/api/peers.rs b/src/api/peers.rs
index 537ad98..cd70f7d 100644
--- a/src/api/peers.rs
+++ b/src/api/peers.rs
@@ -60,6 +60,10 @@ pub(crate) struct PeerStatus {
pub(crate) heads: Option<usize>,
/// We keep it alive and sync with it on our own; other peers we only answer.
pub(crate) neighbour: bool,
+ /// The members it said it reaches (`swarm::reach`), by node ID, while that holds;
+ /// absent before it said so, or once it is stale. Keys of members not in our member
+ /// list are left out.
+ pub(crate) reaches: Option<Vec<String>>,
/// Messages and payload bytes exchanged with it, by kind, since we started (or
/// since it was last listed).
pub(crate) traffic: PeerTraffic,
@@ -92,6 +96,8 @@ pub(crate) struct PeerListResponse {
pub(crate) local_heads: usize,
/// Where this node can be reached (`Transport::local_addresses`).
pub(crate) local_addresses: Vec<String>,
+ /// The members we reach (`swarm::reach`), as we last told our neighbours.
+ pub(crate) local_reaches: Vec<String>,
/// By node ID.
pub(crate) peers: BTreeMap<String, PeerStatus>,
}
@@ -117,6 +123,15 @@ pub(crate) async fn peer_list(state: &AppState) -> PeerListResponse {
let now = Instant::now();
let local_epoch = state.local_epoch();
let mut aliases = crate::swarm::members::aliases(&state.doc.read().await.doc);
+ let names = crate::swarm::reach::names(&state).await;
+ let named = |keys: Vec<u64>| -> Vec<String> {
+ let mut named: Vec<String> = keys
+ .iter()
+ .filter_map(|key| names.get(key).cloned())
+ .collect();
+ named.sort();
+ named
+ };
let mut peers = BTreeMap::new();
for (peer, peer_state_mutex) in snapshot {
@@ -172,6 +187,7 @@ pub(crate) async fn peer_list(state: &AppState) -> PeerListResponse {
same_epoch: ps.epoch.map(|epoch| epoch == local_epoch),
heads: ps.reported_heads,
neighbour,
+ reaches: crate::swarm::reach::of(&state, ps.reaches.as_ref()).map(&named),
traffic,
incidents: ps.incidents,
sync_throughput,
@@ -185,6 +201,7 @@ pub(crate) async fn peer_list(state: &AppState) -> PeerListResponse {
local_alias: state.alias.clone(),
local_addresses: state.transport.local_addresses(),
local_epoch: local_epoch.into(),
+ local_reaches: named(crate::swarm::reach::published(&state)),
local_heads,
peers,
}