diff options
Diffstat (limited to 'src/swarm/roots.rs')
| -rw-r--r-- | src/swarm/roots.rs | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/swarm/roots.rs b/src/swarm/roots.rs index c0aa4ea..1df0129 100644 --- a/src/swarm/roots.rs +++ b/src/swarm/roots.rs @@ -16,7 +16,8 @@ //! neither ends the wait nor starts its clock, only disputes. One seed hands a joiner //! another root only if it is all the joiner hears of its seeds within the wait. A //! seed naming none, joining itself, names it once ready, in a handshake again with -//! each peer it named none to (`named_to`, `unnamed`). +//! each peer it named none to (`named_to`, `unnamed`); and a joiner, with a seed +//! that named none, once it says it is ready (`seed_ready`), for older seeds. use std::collections::{HashMap, HashSet}; use std::time::Duration; @@ -194,6 +195,21 @@ pub(crate) fn seed_found(state: &AppState, node: &str) { } } +/// `peer` says it is ready now (a STATUS): where it is a seed this node still waits for, +/// and named no root in its handshake (joining itself then), a handshake again has it +/// name one. A seed whose build does so itself (`unnamed`) does it anyway: this is for +/// those that don't. +pub(crate) fn seed_ready(state: &AppState, peer: &str) { + let ask = { + let roots = state.roots.lock_or_recover(); + roots.awaiting.is_some() && roots.seeds.contains(peer) && !roots.named.contains_key(peer) + }; + if ask { + let (state, peer) = (state.clone(), peer.to_owned()); + tokio::spawn(async move { crate::swarm::peer::rehandshake(&state, &peer).await }); + } +} + /// Until when a joining node still waits for its seeds to name the swarm's root, if it /// waits on a clock (`await_seeds`): then `repin`. pub(crate) fn waiting_until(state: &AppState) -> Option<tokio::time::Instant> { |
