aboutsummaryrefslogtreecommitdiffstats
path: root/src/api/peers.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/api/peers.rs')
-rw-r--r--src/api/peers.rs25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/api/peers.rs b/src/api/peers.rs
index cd9381f..2bdde96 100644
--- a/src/api/peers.rs
+++ b/src/api/peers.rs
@@ -50,6 +50,9 @@ pub(crate) struct PeerStatus {
/// How long its heads have differed from ours with no sync message from it in
/// between; absent while they match.
pub(crate) diverged_for_secs: Option<u64>,
+ /// Whether we refuse it as a whole, its own change having broken the swarm's rules
+ /// (`access::screen`): then we send it nothing.
+ pub(crate) refused: Option<RefusedPeer>,
pub(crate) has_pending_delivery: bool,
/// Epoch the peer last advertised; absent until it has sent a message.
pub(crate) epoch: Option<EpochRecord>,
@@ -113,6 +116,16 @@ pub(crate) struct ThroughputInfo {
pub(crate) secs_ago: u64,
}
+/// A peer refused as a whole (`PeerStatus::refused`).
+#[derive(Debug, Clone, Serialize)]
+#[serde(rename_all = "camelCase")]
+pub(crate) struct RefusedPeer {
+ pub(crate) secs_ago: u64,
+ /// The change of its that broke the rules, and why.
+ pub(crate) change: String,
+ pub(crate) why: String,
+}
+
#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub(crate) struct PeerListResponse {
@@ -176,6 +189,17 @@ pub(crate) async fn peer_list(state: &AppState) -> PeerListResponse {
samples: estimate.samples,
secs_ago: now.saturating_duration_since(estimate.at).as_secs(),
});
+ let refused = {
+ state
+ .screening
+ .lock_or_recover()
+ .refusing(&peer)
+ .map(|refusing| RefusedPeer {
+ secs_ago: now.saturating_duration_since(refusing.since).as_secs(),
+ change: refusing.change.to_string(),
+ why: refusing.why.clone(),
+ })
+ };
let ps = peer_state_mutex.lock().await;
let (status, dormant_for_secs) = match ps.liveness {
@@ -223,6 +247,7 @@ pub(crate) async fn peer_list(state: &AppState) -> PeerListResponse {
diverged_for_secs: ps
.diverged_since
.map(|t| now.saturating_duration_since(t).as_secs()),
+ refused,
has_pending_delivery: ps.sync.sending.is_some() || ps.sync.retry_at.is_some(),
epoch: ps.epoch.map(EpochRecord::from),
same_epoch: ps.epoch.map(|epoch| epoch == local_epoch),