aboutsummaryrefslogtreecommitdiffstats
path: root/src/transport
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport')
-rw-r--r--src/transport/identity.rs4
-rw-r--r--src/transport/libp2p/book.rs5
-rw-r--r--src/transport/libp2p/mod.rs4
-rw-r--r--src/transport/mod.rs6
-rw-r--r--src/transport/paths.rs7
-rw-r--r--src/transport/traffic.rs4
6 files changed, 30 insertions, 0 deletions
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<tokio::sync::Notify>) {
+ 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 (`<scheme>:...`) 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<Multiaddr>,
+ /// Told when a seed is found (`Transport::on_seeds_found`).
+ pub(super) seeds_found: Option<Arc<tokio::sync::Notify>>,
}
/// 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<tokio::sync::Notify>) {
+ lock(&self.book).seeds_found = Some(found);
+ }
+
/// Nodes found on the LAN (mDNS) that speak continuum.
fn discovered_seeds(&self) -> Vec<String> {
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<tokio::sync::Notify>) {
+ 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<tokio::sync::Notify>) {
+ 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
/// (`<scheme>:...`) 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<tokio::sync::Notify>) {
+ self.inner.on_seeds_found(found)
+ }
+
fn transports(&self) -> Vec<String> {
self.inner.transports()
}