aboutsummaryrefslogtreecommitdiffstats
path: root/src/swarm/peer/forget.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/swarm/peer/forget.rs')
-rw-r--r--src/swarm/peer/forget.rs15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/swarm/peer/forget.rs b/src/swarm/peer/forget.rs
index b911993..5eb5026 100644
--- a/src/swarm/peer/forget.rs
+++ b/src/swarm/peer/forget.rs
@@ -41,6 +41,21 @@ fn forgotten_peers(doc: &(impl Read + ?Sized)) -> Vec<String> {
/// The forget records this node acted on: peer → the record as it read then.
pub(super) type AppliedForgets = HashMap<String, JsonValue>;
+/// Whether a forget record of a peer this node knows is not acted on yet (`applied`):
+/// the peer was alive, and is looked at again.
+pub(super) async fn unapplied(state: &AppState, applied: &AppliedForgets) -> bool {
+ let forgotten = forgotten_peers(&state.doc.read().await.doc);
+ for peer in forgotten {
+ if peer != state.local_id()
+ && !applied.contains_key(&peer)
+ && state.get_peer_state(&peer).await.is_some()
+ {
+ return true;
+ }
+ }
+ false
+}
+
/// Acts on each forget record once (`applied`). A peer forgotten here may be heard of
/// again before its cancel arrives (named in a peer list, or alive again), and is kept
/// then; forgetting it again every check would only make it flap. A new record (another