From 7f018573730dc57f9608fe41faa54b44abba841d Mon Sep 17 00:00:00 2001 From: tv Date: Sun, 1 Nov 2026 20:34:59 +0100 Subject: bootstrap: replace pull by progress notify --- src/transport/identity.rs | 4 ++++ src/transport/libp2p/book.rs | 5 +++++ src/transport/libp2p/mod.rs | 4 ++++ src/transport/mod.rs | 6 ++++++ src/transport/paths.rs | 7 +++++++ src/transport/traffic.rs | 4 ++++ 6 files changed, 30 insertions(+) (limited to 'src/transport') diff --git a/src/transport/identity.rs b/src/transport/identity.rs index fb1600b..3ac06cb 100644 --- a/src/transport/identity.rs +++ b/src/transport/identity.rs @@ -632,6 +632,10 @@ impl Transport for IdentityTransport { self.shared.paths.discovered_seeds() } + fn on_seeds_found(&self, found: std::sync::Arc) { + self.shared.paths.on_seeds_found(found) + } + /// A node ID resolves to itself if this node knows where it is; anything else is /// an address (`:...`) or what one of the transports resolves to one (the /// first that does), asked WHO. diff --git a/src/transport/libp2p/book.rs b/src/transport/libp2p/book.rs index 8620895..3de8cef 100644 --- a/src/transport/libp2p/book.rs +++ b/src/transport/libp2p/book.rs @@ -111,6 +111,8 @@ pub(super) struct Book { /// Peers found on the LAN that speak continuum, with their address: seeds not /// handed out yet (`discovered_seeds`). pub(super) discovered: Vec, + /// Told when a seed is found (`Transport::on_seeds_found`). + pub(super) seeds_found: Option>, } /// What `Libp2pStats` counts since start. @@ -253,6 +255,9 @@ impl Book { && self.discovered.len() < MAX_PEERS { self.discovered.push(address); + if let Some(found) = &self.seeds_found { + found.notify_one(); + } } } diff --git a/src/transport/libp2p/mod.rs b/src/transport/libp2p/mod.rs index 0bbabc7..a159280 100644 --- a/src/transport/libp2p/mod.rs +++ b/src/transport/libp2p/mod.rs @@ -488,6 +488,10 @@ impl Transport for Libp2pTransport { } } + fn on_seeds_found(&self, found: Arc) { + lock(&self.book).seeds_found = Some(found); + } + /// Nodes found on the LAN (mDNS) that speak continuum. fn discovered_seeds(&self) -> Vec { std::mem::take(&mut lock(&self.book).discovered) diff --git a/src/transport/mod.rs b/src/transport/mod.rs index 5ad2427..a802269 100644 --- a/src/transport/mod.rs +++ b/src/transport/mod.rs @@ -818,6 +818,12 @@ pub(crate) trait Transport: Send + Sync { Vec::new() } + /// Has the transport tell `found` whenever it finds a seed by itself + /// (`discovered_seeds`). By default it never does. + fn on_seeds_found(&self, found: std::sync::Arc) { + let _ = found; + } + /// Whether this node has a way to reach `peer` at all: an address of it on one of /// its transports. Members it can't reach aren't its neighbours (`swarm::topology`). /// By default yes, as for `local_addresses`. diff --git a/src/transport/paths.rs b/src/transport/paths.rs index ce19fd4..8149781 100644 --- a/src/transport/paths.rs +++ b/src/transport/paths.rs @@ -667,6 +667,13 @@ impl Paths { .collect() } + /// Each transport's (`Transport::on_seeds_found`). + pub(crate) fn on_seeds_found(&self, found: std::sync::Arc) { + for link in &self.links { + link.inner.on_seeds_found(found.clone()); + } + } + /// The address of the node a seed leads to, as paths keep it: an address of ours /// (`:...`) whose transport reads it at once; with a scheme of ours, what /// that transport resolves the rest to (an address the transport can't read as an diff --git a/src/transport/traffic.rs b/src/transport/traffic.rs index e6d4a0c..6385f2e 100644 --- a/src/transport/traffic.rs +++ b/src/transport/traffic.rs @@ -330,6 +330,10 @@ impl Transport for CountingTransport { self.inner.discovered_seeds() } + fn on_seeds_found(&self, found: std::sync::Arc) { + self.inner.on_seeds_found(found) + } + fn transports(&self) -> Vec { self.inner.transports() } -- cgit v1.3.1