diff options
| author | tv <tv@krebsco.de> | 2026-10-26 04:24:52 +0100 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-10-26 04:24:52 +0100 |
| commit | 2f3d191a12b6e03ef1845c202d15c7b90736558c (patch) | |
| tree | f9e0aecafd5d32f904ffd62893132994ee52958f /src/state/mod.rs | |
| parent | 7b7dcb5a77061cb69d368de263a02b5ad26fbf51 (diff) | |
unify peers snapshot logic
Diffstat (limited to 'src/state/mod.rs')
| -rw-r--r-- | src/state/mod.rs | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/state/mod.rs b/src/state/mod.rs index 3336b00..1c31c61 100644 --- a/src/state/mod.rs +++ b/src/state/mod.rs @@ -280,6 +280,19 @@ impl AppState { Ok(()) } + /// Every known peer with its state, copied out of the peer map. Lock a peer's state + /// only from such a copy, never while holding the map's lock: the map would then + /// wait for the peer, and with it everything that only needs the map (a lookup, a + /// new peer). + pub(crate) async fn peers_snapshot(&self) -> Vec<(String, Arc<Mutex<PeerState>>)> { + self.peer_states + .read() + .await + .iter() + .map(|(peer, state)| (peer.clone(), Arc::clone(state))) + .collect() + } + /// Looks up a peer without creating it. Background work (sync, retries, /// keepalives) must use this so a forgotten peer isn't resurrected. pub(crate) async fn get_peer_state(&self, pk: &str) -> Option<Arc<Mutex<PeerState>>> { |
