aboutsummaryrefslogtreecommitdiffstats
path: root/src/swarm
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-02 23:31:25 +0100
committertv <tv@krebsco.de>2026-11-02 23:31:25 +0100
commit6d66ebdb6d38e7a9b891fb05d5c9c1ca933ceb21 (patch)
tree8b338fd8f34c2cb3adad5c9e7d3aba9d8fc1e1b3 /src/swarm
parent0c096a524531c180798f0712bb7100f0b7557f76 (diff)
add links relay test
Diffstat (limited to 'src/swarm')
-rw-r--r--src/swarm/links.rs33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/swarm/links.rs b/src/swarm/links.rs
index 80def7a..cdbae67 100644
--- a/src/swarm/links.rs
+++ b/src/swarm/links.rs
@@ -131,6 +131,39 @@ impl Links {
.collect()
}
+ /// Who is subscribed to our links (not run out).
+ #[cfg(test)]
+ pub(crate) fn subscribers(&self) -> Vec<String> {
+ let now = Instant::now();
+ self.inner
+ .lock_or_recover()
+ .subscribers
+ .iter()
+ .filter(|(_, (_, until))| now < *until)
+ .map(|(peer, _)| peer.clone())
+ .collect()
+ }
+
+ /// The members we ask on others' behalf (relayed, not run out), and who asked.
+ #[cfg(test)]
+ pub(crate) fn relaying(&self) -> Vec<(String, Vec<String>)> {
+ let now = Instant::now();
+ self.inner
+ .lock_or_recover()
+ .relaying
+ .iter()
+ .map(|(member, askers)| {
+ let askers: Vec<String> = askers
+ .iter()
+ .filter(|(_, relaying)| now < relaying.until)
+ .map(|(asker, _)| asker.clone())
+ .collect();
+ (member.clone(), askers)
+ })
+ .filter(|(_, askers)| !askers.is_empty())
+ .collect()
+ }
+
/// The members our subscriptions are with, and the peers relaying for us (not run
/// out).
#[cfg_attr(not(feature = "dashboard"), allow(dead_code))]