Merge the nostr rendezvous reorg into the next line

Forward-merge the src/nostr / src/mdns rendezvous reorganization
(relocation out of src/discovery/, the Discovery->Rendezvous rename, the
RendezvousDriver consolidation, and the trace-target reference updates)
onto the next branch. The sole conflict was in the LAN poll method's
doc-comment and signature: kept next's XX-handshake wording and applied
the lan_rendezvous rename. Merged tree builds clean; next lib suite 1583
passing, fmt/clippy clean.
This commit is contained in:
Johnathan Corgan
2026-07-09 23:48:53 +00:00
27 changed files with 661 additions and 449 deletions
+9 -7
View File
@@ -259,13 +259,13 @@ impl Node {
// is polled separately from `reload_peer_acl` because the
// ACL's embedded alias reloader and this snapshot are
// distinct resources; the `path_mtu_lookup` cache and the
// `nostr_discovery` subsystem are deliberately excluded
// `nostr_rendezvous` subsystem are deliberately excluded
// from `Reloadable` since neither reloads from a backing
// file (see `node::reloadable`).
self.reload_host_map().await;
self.poll_pending_connects().await;
self.poll_nostr_discovery().await;
self.poll_lan_discovery().await;
self.poll_nostr_rendezvous().await;
self.poll_lan_rendezvous().await;
self.resend_pending_handshakes(now_ms).await;
self.resend_pending_rekeys(now_ms).await;
self.resend_pending_fmp_rekey_msg3(now_ms).await;
@@ -322,12 +322,14 @@ impl Node {
// though no msg1/msg2 exchange can ever succeed. Bump the
// discovery-layer cooldown to the long protocol-mismatch
// window and emit a single WARN per fresh observation.
if self.bootstrap_transports.contains(&packet.transport_id)
if self
.nostr_rendezvous
.is_bootstrap_transport(&packet.transport_id)
&& let Some(npub) = self
.bootstrap_transport_npubs
.get(&packet.transport_id)
.nostr_rendezvous
.bootstrap_transport_npub(&packet.transport_id)
.cloned()
&& let Some(handle) = self.nostr_discovery_handle()
&& let Some(handle) = self.nostr_rendezvous_handle()
{
let now_ms = Self::now_ms();
let cooldown_secs = handle.protocol_mismatch_cooldown_secs();
+85 -257
View File
@@ -2,13 +2,10 @@
use super::{Node, NodeError, NodeState};
use crate::config::{ConnectPolicy, PeerAddress, PeerConfig};
use crate::discovery::nostr::{
ADVERT_IDENTIFIER, ADVERT_VERSION, BootstrapEvent, NostrDiscovery, OverlayAdvert,
OverlayEndpointAdvert, OverlayTransportKind,
};
use crate::discovery::{BootstrapHandoffResult, EstablishedTraversal};
use crate::node::acl::PeerAclContext;
use crate::node::wire::build_msg1;
use crate::nostr::{BootstrapEvent, NostrRendezvous};
use crate::nostr::{BootstrapHandoffResult, EstablishedTraversal};
use crate::peer::PeerConnection;
use crate::proto::fmp::{Disconnect, DisconnectReason};
use crate::transport::{Link, LinkDirection, LinkId, TransportAddr, TransportId, packet_channel};
@@ -266,7 +263,7 @@ impl Node {
// would loop on the same dead address until expiry. Force a
// re-fetch so the next retry tick picks up fresh endpoints.
if matches!(e, crate::node::NodeError::NoTransportForType(_))
&& let Some(bootstrap) = self.nostr_discovery.clone()
&& let Some(bootstrap) = self.nostr_rendezvous.engine_arc()
{
let npub = peer_config.npub.clone();
tokio::spawn(async move {
@@ -360,7 +357,7 @@ impl Node {
.filter(|(id, handle)| {
handle.transport_type().name == "udp"
&& handle.is_operational()
&& !self.bootstrap_transports.contains(id)
&& !self.nostr_rendezvous.is_bootstrap_transport(id)
})
.filter_map(|(id, handle)| {
let local_addr = handle.local_addr()?;
@@ -736,8 +733,8 @@ impl Node {
}
}
pub(super) async fn poll_nostr_discovery(&mut self) {
let Some(bootstrap) = self.nostr_discovery.clone() else {
pub(super) async fn poll_nostr_rendezvous(&mut self) {
let Some(bootstrap) = self.nostr_rendezvous.engine_arc() else {
return;
};
@@ -883,19 +880,19 @@ impl Node {
tokio::spawn(async move {
let outcome = bootstrap.refetch_advert_for_stale_check(&npub).await;
match outcome {
crate::discovery::nostr::NostrRefetchOutcome::Evicted => info!(
crate::nostr::NostrRefetchOutcome::Evicted => info!(
npub = %npub,
"stale-advert sweep: peer evicted from advert cache"
),
crate::discovery::nostr::NostrRefetchOutcome::Refreshed => info!(
crate::nostr::NostrRefetchOutcome::Refreshed => info!(
npub = %npub,
"stale-advert sweep: peer republished, cache refreshed and streak reset"
),
crate::discovery::nostr::NostrRefetchOutcome::SameAdvert => debug!(
crate::nostr::NostrRefetchOutcome::SameAdvert => debug!(
npub = %npub,
"stale-advert sweep: advert unchanged, cooldown stands"
),
crate::discovery::nostr::NostrRefetchOutcome::Skipped => debug!(
crate::nostr::NostrRefetchOutcome::Skipped => debug!(
npub = %npub,
"stale-advert sweep: skipped (relay error or no advert_relays)"
),
@@ -934,7 +931,7 @@ impl Node {
/// changing the public Nostr discovery `app` tag. The older fallback
/// extracts a scope from the Nostr app tag used by default scoped
/// discovery.
pub(super) fn lan_discovery_scope(&self) -> Option<String> {
pub(super) fn lan_rendezvous_scope(&self) -> Option<String> {
if let Some(scope) = self.config().node.rendezvous.lan.scope.as_deref() {
let scope = scope.trim();
if !scope.is_empty() {
@@ -961,8 +958,8 @@ impl Node {
/// Drain mDNS-discovered peers and initiate Noise XX handshakes.
/// The handshake itself is the authentication — a spoofed mDNS advert
/// with someone else's npub fails the XX exchange and is dropped.
pub(super) async fn poll_lan_discovery(&mut self) {
let Some(runtime) = self.lan_discovery.clone() else {
pub(super) async fn poll_lan_rendezvous(&mut self) {
let Some(runtime) = self.lan_rendezvous.clone() else {
return;
};
let events = runtime.drain_events().await;
@@ -970,7 +967,7 @@ impl Node {
return;
}
for event in events {
let crate::discovery::lan::LanEvent::Discovered(peer) = event;
let crate::mdns::LanEvent::Discovered(peer) = event;
let Some((transport_id, local_addr)) =
self.find_udp_transport_for_remote_addr(peer.addr)
else {
@@ -1198,7 +1195,7 @@ impl Node {
}
if self.config().node.rendezvous.nostr.enabled {
match NostrDiscovery::start(
match NostrRendezvous::start(
self.identity(),
self.config().node.rendezvous.nostr.clone(),
)
@@ -1208,8 +1205,8 @@ impl Node {
if let Err(err) = self.refresh_overlay_advert(&runtime).await {
warn!(error = %err, "Failed to publish initial Nostr overlay advert");
}
self.nostr_discovery = Some(runtime);
self.nostr_discovery_started_at_ms = Some(Self::now_ms());
self.nostr_rendezvous.set_engine(runtime);
self.nostr_rendezvous.set_started_at_ms(Self::now_ms());
info!("Nostr overlay discovery enabled");
}
Err(err) => {
@@ -1234,14 +1231,14 @@ impl Node {
.filter(|(id, h)| {
h.transport_type().name == "udp"
&& h.is_operational()
&& !self.bootstrap_transports.contains(id)
&& !self.nostr_rendezvous.is_bootstrap_transport(id)
})
.filter_map(|(id, h)| h.local_addr().map(|addr| (*id, addr.port())))
.min_by_key(|(id, _)| id.as_u32())
.map(|(_, port)| port)
.unwrap_or(0);
let scope = self.lan_discovery_scope();
match crate::discovery::lan::LanDiscovery::start(
let scope = self.lan_rendezvous_scope();
match crate::mdns::LanRendezvous::start(
self.identity(),
scope,
advertised_udp_port,
@@ -1250,7 +1247,7 @@ impl Node {
.await
{
Ok(runtime) => {
self.lan_discovery = Some(runtime);
self.lan_rendezvous = Some(runtime);
info!("LAN mDNS discovery enabled");
}
Err(err) => {
@@ -1538,7 +1535,7 @@ impl Node {
.await;
// Stop Nostr overlay discovery background work and withdraw any advert.
if let Some(bootstrap) = self.nostr_discovery.take()
if let Some(bootstrap) = self.nostr_rendezvous.take_engine()
&& let Err(e) = bootstrap.shutdown().await
{
warn!(error = %e, "Failed to shutdown Nostr overlay discovery");
@@ -1547,7 +1544,7 @@ impl Node {
// Tear down LAN mDNS responder + browser. Best-effort: the
// OS will eventually time the advert out via its TTL even if
// we don't get a clean unregister out before the daemon exits.
if let Some(lan) = self.lan_discovery.take() {
if let Some(lan) = self.lan_rendezvous.take() {
lan.shutdown().await;
}
@@ -1680,89 +1677,6 @@ impl Node {
.collect()
}
async fn nostr_peer_fallback_addresses(
&self,
peer_config: &PeerConfig,
existing: &[PeerAddress],
) -> Vec<PeerAddress> {
if !self.config().node.rendezvous.nostr.enabled
|| !peer_config.via_nostr
|| self.config().node.rendezvous.nostr.policy
== crate::config::NostrDiscoveryPolicy::Disabled
{
return Vec::new();
}
let Some(bootstrap) = self.nostr_discovery.clone() else {
return Vec::new();
};
let endpoints = match bootstrap.advert_endpoints_for_peer(&peer_config.npub).await {
Ok(endpoints) => endpoints,
Err(err) => {
debug!(
npub = %peer_config.npub,
error = %err,
"Failed to resolve Nostr advert endpoints for configured peer"
);
return Vec::new();
}
};
let mut fallback = Vec::new();
let mut next_priority = existing
.iter()
.map(|addr| addr.priority)
.max()
.unwrap_or(100)
.saturating_add(1);
let seen_at_ms = Self::now_ms();
for endpoint in endpoints {
let Some(candidate) =
Self::overlay_endpoint_to_peer_address(&endpoint, next_priority, seen_at_ms)
else {
continue;
};
if existing
.iter()
.any(|addr| addr.transport == candidate.transport && addr.addr == candidate.addr)
|| fallback.iter().any(|addr: &PeerAddress| {
addr.transport == candidate.transport && addr.addr == candidate.addr
})
{
continue;
}
fallback.push(candidate);
next_priority = next_priority.saturating_add(1);
}
fallback
}
fn overlay_endpoint_to_peer_address(
endpoint: &OverlayEndpointAdvert,
priority: u8,
seen_at_ms: u64,
) -> Option<PeerAddress> {
let transport = match endpoint.transport {
OverlayTransportKind::Udp => "udp",
OverlayTransportKind::Tcp => "tcp",
OverlayTransportKind::Tor => "tor",
};
Some(
PeerAddress::with_priority(transport, endpoint.addr.clone(), priority)
.with_seen_at_ms(seen_at_ms),
)
}
async fn request_nostr_bootstrap(&self, peer_config: &PeerConfig) -> bool {
let Some(bootstrap) = self.nostr_discovery.clone() else {
debug!(npub = %peer_config.npub, "No Nostr overlay runtime for udp:nat address");
return false;
};
bootstrap.request_connect(peer_config.clone()).await;
info!(npub = %peer_config.npub, "Started Nostr UDP NAT traversal attempt");
true
}
async fn attempt_peer_address_list(
&mut self,
peer_config: &PeerConfig,
@@ -1788,7 +1702,11 @@ impl Node {
if !allow_bootstrap_nat {
continue;
}
if self.request_nostr_bootstrap(peer_config).await {
if self
.nostr_rendezvous
.request_nostr_bootstrap(peer_config)
.await
{
attempted = attempted.saturating_add(1);
}
continue;
@@ -1890,7 +1808,7 @@ impl Node {
)))
}
async fn queue_open_discovery_retries(&mut self, bootstrap: &std::sync::Arc<NostrDiscovery>) {
async fn queue_open_discovery_retries(&mut self, bootstrap: &std::sync::Arc<NostrRendezvous>) {
self.run_open_discovery_sweep(bootstrap, None, "per-tick")
.await;
}
@@ -1907,13 +1825,13 @@ impl Node {
/// startup sweeps are distinguishable in operator-facing logs.
pub(in crate::node) async fn run_open_discovery_sweep(
&mut self,
bootstrap: &std::sync::Arc<NostrDiscovery>,
bootstrap: &std::sync::Arc<NostrRendezvous>,
max_age_secs: Option<u64>,
caller: &'static str,
) {
if !self.config().node.rendezvous.nostr.enabled
|| self.config().node.rendezvous.nostr.policy
!= crate::config::NostrDiscoveryPolicy::Open
!= crate::config::NostrRendezvousPolicy::Open
{
return;
}
@@ -2019,7 +1937,9 @@ impl Node {
let seen_at_ms = Self::now_ms();
for endpoint in endpoints {
let Some(candidate) =
Self::overlay_endpoint_to_peer_address(&endpoint, priority, seen_at_ms)
crate::nostr::RendezvousDriver::overlay_endpoint_to_peer_address(
&endpoint, priority, seen_at_ms,
)
else {
continue;
};
@@ -2105,20 +2025,20 @@ impl Node {
/// `node.rendezvous.nostr.enabled` and `policy == open`.
async fn maybe_run_startup_open_discovery_sweep(
&mut self,
bootstrap: &std::sync::Arc<NostrDiscovery>,
bootstrap: &std::sync::Arc<NostrRendezvous>,
) {
if self.startup_open_discovery_sweep_done {
if self.nostr_rendezvous.startup_sweep_done() {
return;
}
if !self.config().node.rendezvous.nostr.enabled
|| self.config().node.rendezvous.nostr.policy
!= crate::config::NostrDiscoveryPolicy::Open
!= crate::config::NostrRendezvousPolicy::Open
{
// Mark done so we don't keep re-checking on every tick.
self.startup_open_discovery_sweep_done = true;
self.nostr_rendezvous.set_startup_sweep_done();
return;
}
let Some(started_at_ms) = self.nostr_discovery_started_at_ms else {
let Some(started_at_ms) = self.nostr_rendezvous.started_at_ms() else {
return;
};
let now_ms = Self::now_ms();
@@ -2141,7 +2061,7 @@ impl Node {
.startup_sweep_max_age_secs;
self.run_open_discovery_sweep(bootstrap, Some(max_age_secs), "startup")
.await;
self.startup_open_discovery_sweep_done = true;
self.nostr_rendezvous.set_startup_sweep_done();
}
fn available_outbound_slots(&self) -> usize {
@@ -2254,163 +2174,66 @@ impl Node {
)
}
async fn build_overlay_advert(
&self,
bootstrap: &std::sync::Arc<NostrDiscovery>,
) -> Option<OverlayAdvert> {
if !self.config().node.rendezvous.nostr.enabled {
return None;
}
let mut endpoints = Vec::new();
let mut has_udp_nat = false;
/// Capture the advertisable-endpoint inputs of every operational
/// transport into a snapshot the rendezvous driver can turn into an
/// `OverlayAdvert` without borrowing the transport table across the
/// STUN await. Iteration order matches `self.transports.values()`, and
/// only transports whose type matched a configured listener are
/// included, mirroring the original per-transport branch structure.
fn advert_transport_snapshot(&self) -> Vec<crate::nostr::AdvertTransportSnapshot> {
use crate::nostr::AdvertTransportSnapshot;
let mut snapshot = Vec::new();
for handle in self.transports.values() {
if !handle.is_operational() {
continue;
}
match handle.transport_type().name {
"udp" => {
let Some(cfg) = self.lookup_udp_config(handle.name()) else {
continue;
};
if !cfg.advertise_on_nostr() {
continue;
}
if cfg.is_public() {
// Precedence:
// 1. operator-supplied `external_addr` (skips STUN)
// 2. non-wildcard `local_addr` (operator bound to
// a specific public IP directly)
// 3. STUN auto-discovery against ephemeral socket
// 4. loud warn + omit endpoint
if let Some(explicit) = cfg.external_advert_addr() {
endpoints.push(OverlayEndpointAdvert {
transport: OverlayTransportKind::Udp,
addr: explicit.to_string(),
});
} else {
match handle.local_addr() {
Some(addr) if !addr.ip().is_unspecified() => {
endpoints.push(OverlayEndpointAdvert {
transport: OverlayTransportKind::Udp,
addr: addr.to_string(),
});
}
Some(addr) => {
let key = handle.transport_id().as_u32();
let port = addr.port();
if let Some(public) =
bootstrap.learn_public_udp_addr(key, port).await
{
endpoints.push(OverlayEndpointAdvert {
transport: OverlayTransportKind::Udp,
addr: public.to_string(),
});
} else {
warn!(
transport_id = key,
bind_addr = %addr,
"advert: udp public=true bound to wildcard but \
STUN observation failed; advertising no UDP \
endpoint. Either set transports.udp.external_addr, \
bind to a specific public IP, or ensure \
node.rendezvous.nostr.stun_servers is reachable"
);
}
}
None => {}
}
}
} else {
endpoints.push(OverlayEndpointAdvert {
transport: OverlayTransportKind::Udp,
addr: "nat".to_string(),
});
has_udp_nat = true;
}
snapshot.push(AdvertTransportSnapshot::Udp {
advertise: cfg.advertise_on_nostr(),
is_public: cfg.is_public(),
external_addr: cfg.external_advert_addr(),
local_addr: handle.local_addr(),
transport_key: handle.transport_id().as_u32(),
});
}
"tcp" => {
let Some(cfg) = self.lookup_tcp_config(handle.name()) else {
continue;
};
if !cfg.advertise_on_nostr() {
continue;
}
// Precedence:
// 1. operator-supplied `external_addr` (only path that
// works on cloud-NAT setups where the public IP is
// not on a host interface).
// 2. non-wildcard `local_addr` (operator bound to a
// specific public IP directly).
// 3. loud warn + omit endpoint (no TCP STUN equivalent).
if let Some(explicit) = cfg.external_advert_addr() {
endpoints.push(OverlayEndpointAdvert {
transport: OverlayTransportKind::Tcp,
addr: explicit.to_string(),
});
} else {
match handle.local_addr() {
Some(addr) if !addr.ip().is_unspecified() => {
endpoints.push(OverlayEndpointAdvert {
transport: OverlayTransportKind::Tcp,
addr: addr.to_string(),
});
}
Some(addr) => {
warn!(
bind_addr = %addr,
"advert: tcp advertise_on_nostr=true bound to wildcard \
and no transports.tcp.external_addr set; advertising no \
TCP endpoint. Either set external_addr to the public \
IP (recommended for cloud 1:1-NAT setups) or bind \
explicitly to the public IP"
);
}
None => {}
}
}
snapshot.push(AdvertTransportSnapshot::Tcp {
advertise: cfg.advertise_on_nostr(),
external_addr: cfg.external_advert_addr(),
local_addr: handle.local_addr(),
});
}
"tor" => {
let Some(cfg) = self.lookup_tor_config(handle.name()) else {
continue;
};
if !cfg.advertise_on_nostr() {
continue;
}
if let Some(addr) = handle.onion_address() {
endpoints.push(OverlayEndpointAdvert {
transport: OverlayTransportKind::Tor,
addr: format!("{}:{}", addr, cfg.advertised_port()),
});
}
snapshot.push(AdvertTransportSnapshot::Tor {
advertise: cfg.advertise_on_nostr(),
onion_addr: handle.onion_address().map(|s| s.to_string()),
advertised_port: cfg.advertised_port(),
});
}
_ => {}
}
}
if endpoints.is_empty() {
return None;
}
Some(OverlayAdvert {
identifier: ADVERT_IDENTIFIER.to_string(),
version: ADVERT_VERSION,
endpoints,
signal_relays: has_udp_nat
.then(|| self.config().node.rendezvous.nostr.dm_relays.clone()),
stun_servers: has_udp_nat
.then(|| self.config().node.rendezvous.nostr.stun_servers.clone()),
})
snapshot
}
async fn refresh_overlay_advert(
&self,
bootstrap: &std::sync::Arc<NostrDiscovery>,
) -> Result<(), crate::discovery::nostr::BootstrapError> {
let advert = self.build_overlay_advert(bootstrap).await;
bootstrap.update_local_advert(advert).await
bootstrap: &std::sync::Arc<NostrRendezvous>,
) -> Result<(), crate::nostr::BootstrapError> {
let snapshot = self.advert_transport_snapshot();
self.nostr_rendezvous
.refresh_overlay_advert(bootstrap, snapshot, &self.config().node.rendezvous.nostr)
.await
}
fn lookup_udp_config(&self, transport_name: Option<&str>) -> Option<&crate::config::UdpConfig> {
@@ -2527,7 +2350,13 @@ impl Node {
async fn peer_address_candidates(&self, peer_config: &PeerConfig) -> Vec<PeerAddress> {
let static_addresses = self.static_peer_addresses(peer_config);
let overlay_addresses = self
.nostr_peer_fallback_addresses(peer_config, &static_addresses)
.nostr_rendezvous
.nostr_peer_fallback_addresses(
peer_config,
&static_addresses,
&self.config().node.rendezvous.nostr,
Self::now_ms(),
)
.await;
let mut candidates = Vec::with_capacity(overlay_addresses.len() + static_addresses.len());
@@ -2595,7 +2424,7 @@ impl Node {
};
if peer
.transport_id()
.map(|id| self.bootstrap_transports.contains(&id))
.map(|id| self.nostr_rendezvous.is_bootstrap_transport(&id))
.unwrap_or(false)
{
return false;
@@ -2791,17 +2620,16 @@ impl Node {
transport_id,
crate::transport::TransportHandle::Udp(transport),
);
self.bootstrap_transports.insert(transport_id);
self.bootstrap_transport_npubs
.insert(transport_id, traversal.peer_npub.clone());
self.nostr_rendezvous
.insert_bootstrap_transport(transport_id, traversal.peer_npub.clone());
let remote_addr = TransportAddr::from_string(&traversal.remote_addr.to_string());
if let Err(err) = self
.initiate_connection(transport_id, remote_addr.clone(), Some(peer_identity))
.await
{
self.bootstrap_transports.remove(&transport_id);
self.bootstrap_transport_npubs.remove(&transport_id);
self.nostr_rendezvous
.remove_bootstrap_transport(&transport_id);
if let Some(mut handle) = self.transports.remove(&transport_id) {
let _ = handle.stop().await;
}
+17 -40
View File
@@ -79,7 +79,7 @@ use crate::upper::tun::{TunError, TunOutboundRx, TunState, TunTx};
use crate::utils::index::IndexAllocator;
use crate::{Config, ConfigError, Identity, IdentityError, NodeAddr, PeerIdentity, TreeCoordinate};
use rand::Rng;
use std::collections::{BTreeSet, HashMap, HashSet, VecDeque};
use std::collections::{BTreeSet, HashMap, VecDeque};
use std::fmt;
use std::sync::Arc;
use std::thread::JoinHandle;
@@ -464,31 +464,16 @@ pub struct Node {
/// are exhausted.
retry_pending: HashMap<NodeAddr, retry::RetryState>,
/// Optional Nostr/STUN overlay discovery coordinator for `udp:nat` peers.
nostr_discovery: Option<Arc<crate::discovery::nostr::NostrDiscovery>>,
/// Node-side driver state for the Nostr overlay peer-rendezvous
/// subsystem: the engine handle, its startup timestamp, the one-shot
/// startup-sweep latch, and the per-peer bootstrap-transport bookkeeping
/// adopted from NAT-traversal handoffs.
nostr_rendezvous: crate::nostr::RendezvousDriver,
/// mDNS / DNS-SD responder + browser for local-link peer discovery.
/// Identity is unverified at this layer — the Noise XX handshake
/// initiated against an mDNS-observed endpoint is what proves the
/// peer holds the matching private key.
lan_discovery: Option<Arc<crate::discovery::lan::LanDiscovery>>,
/// Wall-clock ms when Nostr discovery successfully started, used to
/// schedule the one-shot startup advert sweep after a settle delay.
/// `None` until discovery comes up; remains `None` if discovery is
/// disabled or failed to start.
nostr_discovery_started_at_ms: Option<u64>,
/// Whether the one-shot startup advert sweep has run. Set to true
/// after the first sweep fires (under `policy: open`); thereafter
/// only the per-tick `queue_open_discovery_retries` continues.
startup_open_discovery_sweep_done: bool,
/// Per-peer UDP transports adopted from NAT traversal handoff.
bootstrap_transports: HashSet<TransportId>,
/// Originating peer npub (bech32) for each adopted bootstrap
/// transport, captured at `adopt_established_traversal` time.
/// Populated alongside `bootstrap_transports`; cleared in
/// `cleanup_bootstrap_transport_if_unused`. Used by the rx loop to
/// route fatal-protocol-mismatch observations back to the
/// Nostr-discovery `failure_state` for long cooldown application.
bootstrap_transport_npubs: HashMap<TransportId, String>,
lan_rendezvous: Option<Arc<crate::mdns::LanRendezvous>>,
// === Periodic Parent Re-evaluation ===
/// Timestamp of last periodic parent re-evaluation (for pacing).
@@ -707,12 +692,8 @@ impl Node {
),
pending_connects: Vec::new(),
retry_pending: HashMap::new(),
nostr_discovery: None,
nostr_discovery_started_at_ms: None,
lan_discovery: None,
startup_open_discovery_sweep_done: false,
bootstrap_transports: HashSet::new(),
bootstrap_transport_npubs: HashMap::new(),
nostr_rendezvous: crate::nostr::RendezvousDriver::default(),
lan_rendezvous: None,
last_parent_reeval: None,
last_congestion_log: None,
estimated_mesh_size: None,
@@ -871,12 +852,8 @@ impl Node {
lookup: Lookup::new(LookupBackoff::new(), LookupForwardRateLimiter::new()),
pending_connects: Vec::new(),
retry_pending: HashMap::new(),
nostr_discovery: None,
nostr_discovery_started_at_ms: None,
lan_discovery: None,
startup_open_discovery_sweep_done: false,
bootstrap_transports: HashSet::new(),
bootstrap_transport_npubs: HashMap::new(),
nostr_rendezvous: crate::nostr::RendezvousDriver::default(),
lan_rendezvous: None,
last_parent_reeval: None,
last_congestion_log: None,
estimated_mesh_size: None,
@@ -1874,7 +1851,7 @@ impl Node {
// Per-npub Nostr-traversal failure-state, indexed by npub for O(1)
// per-peer lookup (empty when Nostr discovery is disabled).
let nostr_state: std::collections::HashMap<String, _> = self
.nostr_discovery_handle()
.nostr_rendezvous_handle()
.map(|d| {
d.failure_state_snapshot()
.into_iter()
@@ -2331,7 +2308,7 @@ impl Node {
}
pub(crate) fn cleanup_bootstrap_transport_if_unused(&mut self, transport_id: TransportId) {
if !self.bootstrap_transports.contains(&transport_id) {
if !self.nostr_rendezvous.is_bootstrap_transport(&transport_id) {
return;
}
@@ -2361,8 +2338,8 @@ impl Node {
"bootstrap transport has no remaining references; dropping"
);
self.bootstrap_transports.remove(&transport_id);
self.bootstrap_transport_npubs.remove(&transport_id);
self.nostr_rendezvous
.remove_bootstrap_transport(&transport_id);
self.transport_drops.remove(&transport_id);
self.transports.remove(&transport_id);
}
@@ -2437,8 +2414,8 @@ impl Node {
/// Reference to the Nostr discovery handle if discovery is enabled.
/// Used by control queries (`show_peers` per-peer Nostr-traversal
/// state) to read failure-state without taking shared ownership.
pub fn nostr_discovery_handle(&self) -> Option<&crate::discovery::nostr::NostrDiscovery> {
self.nostr_discovery.as_deref()
pub fn nostr_rendezvous_handle(&self) -> Option<&crate::nostr::NostrRendezvous> {
self.nostr_rendezvous.engine()
}
/// Iterate over all peer node IDs.
+1 -1
View File
@@ -41,7 +41,7 @@
//! file. There is nothing to poll. (Its read side could adopt the same
//! lock-free `ArcSwap` shape in the future, but that is an optimization, not
//! a reload.)
//! - `nostr_discovery` is an async spawned subsystem, not a snapshot of disk
//! - `nostr_rendezvous` is an async spawned subsystem, not a snapshot of disk
//! state.
//!
//! Both [`HostMapReloadable`] and the peer ACL reloader currently stat
+2 -2
View File
@@ -282,7 +282,7 @@ impl Node {
// evicts if the relay has nothing, otherwise leaves it. Cheap
// (one Filter fetch with 2s timeout) and bounded by the retry
// backoff cadence.
if let Some(bootstrap) = self.nostr_discovery.clone() {
if let Some(bootstrap) = self.nostr_rendezvous.engine_arc() {
let _ = bootstrap
.refetch_advert_for_stale_check(&peer_config.npub)
.await;
@@ -318,7 +318,7 @@ impl Node {
// entry expires. Force a re-fetch so the next retry tick
// picks up fresh endpoints.
if matches!(e, NodeError::NoTransportForType(_))
&& let Some(bootstrap) = self.nostr_discovery.clone()
&& let Some(bootstrap) = self.nostr_rendezvous.engine_arc()
{
let npub = peer_config.npub.clone();
tokio::spawn(async move {
+8 -8
View File
@@ -1043,20 +1043,20 @@ async fn test_response_path_mtu_four_node_chain() {
/// Pin the iterate-filter-queue contract of `run_open_discovery_sweep`.
///
/// Builds a `Node` with `nostr.policy = Open` and an empty peer list,
/// then injects three cached adverts into a test `NostrDiscovery` and
/// then injects three cached adverts into a test `NostrRendezvous` and
/// asserts the sweep:
/// - queues a retry for an eligible (unknown, not-self) advert,
/// - skips the advert whose author is our own node identity, and
/// - skips the advert whose author is an already-connected peer.
///
/// Uses `NostrDiscovery::new_for_test()` and `insert_advert_for_test()`
/// Uses `NostrRendezvous::new_for_test()` and `insert_advert_for_test()`
/// (both `#[cfg(test)]`-gated test escape hatches in
/// `src/discovery/nostr/runtime.rs`) to populate the cache without
/// requiring live relay subscriptions.
#[tokio::test]
async fn test_open_discovery_sweep_queues_eligible_skips_filtered() {
use crate::config::NostrDiscoveryPolicy;
use crate::discovery::nostr::{NostrDiscovery, OverlayEndpointAdvert, OverlayTransportKind};
use crate::config::NostrRendezvousPolicy;
use crate::nostr::{NostrRendezvous, OverlayEndpointAdvert, OverlayTransportKind};
use crate::peer::ActivePeer;
use crate::transport::LinkId;
use std::sync::Arc;
@@ -1064,7 +1064,7 @@ async fn test_open_discovery_sweep_queues_eligible_skips_filtered() {
// Build node with open-discovery enabled.
let mut config = crate::Config::new();
config.node.rendezvous.nostr.enabled = true;
config.node.rendezvous.nostr.policy = NostrDiscoveryPolicy::Open;
config.node.rendezvous.nostr.policy = NostrRendezvousPolicy::Open;
let mut node = crate::Node::new(config).unwrap();
// Identity of an already-connected peer; insert into node.peers
@@ -1087,8 +1087,8 @@ async fn test_open_discovery_sweep_queues_eligible_skips_filtered() {
let self_npub = crate::encode_npub(&node.identity().pubkey());
let self_node_addr = *node.identity().node_addr();
// Build a NostrDiscovery test instance and inject the three adverts.
let bootstrap = Arc::new(NostrDiscovery::new_for_test());
// Build a NostrRendezvous test instance and inject the three adverts.
let bootstrap = Arc::new(NostrRendezvous::new_for_test());
let endpoint = OverlayEndpointAdvert {
transport: OverlayTransportKind::Udp,
addr: "203.0.113.7:2121".to_string(),
@@ -1099,7 +1099,7 @@ async fn test_open_discovery_sweep_queues_eligible_skips_filtered() {
.unwrap_or(0);
for npub in [&eligible_npub, &connected_npub, &self_npub] {
let advert =
NostrDiscovery::cached_advert_for_test(npub.clone(), endpoint.clone(), now_secs);
NostrRendezvous::cached_advert_for_test(npub.clone(), endpoint.clone(), now_secs);
bootstrap.insert_advert_for_test(npub.clone(), advert).await;
}
+17 -17
View File
@@ -1,5 +1,5 @@
use super::*;
use crate::discovery::nostr::{BootstrapEvent, NostrDiscovery};
use crate::nostr::{BootstrapEvent, NostrRendezvous};
use crate::peer::PromotionResult;
use crate::transport::udp::UdpTransport;
use crate::transport::{TransportHandle, packet_channel};
@@ -171,7 +171,7 @@ async fn test_node_start_does_not_wait_for_nostr_relay_startup() {
config.node.control.enabled = false;
config.node.rendezvous.nostr.enabled = true;
config.node.rendezvous.nostr.advertise = true;
config.node.rendezvous.nostr.policy = crate::config::NostrDiscoveryPolicy::Open;
config.node.rendezvous.nostr.policy = crate::config::NostrRendezvousPolicy::Open;
config.node.rendezvous.nostr.advert_relays = vec!["wss://127.0.0.1:9".to_string()];
config.node.rendezvous.nostr.dm_relays = vec!["wss://127.0.0.1:9".to_string()];
config.transports.udp = crate::config::TransportInstances::Single(crate::config::UdpConfig {
@@ -189,7 +189,7 @@ async fn test_node_start_does_not_wait_for_nostr_relay_startup() {
.unwrap();
assert!(node.is_running());
assert!(node.nostr_discovery_handle().is_some());
assert!(node.nostr_rendezvous_handle().is_some());
node.stop().await.unwrap();
}
@@ -1128,14 +1128,14 @@ async fn test_nostr_traversal_failure_skips_connected_peer() {
node.promote_connection(link_id, peer_identity, 2000)
.unwrap();
let bootstrap = Arc::new(NostrDiscovery::new_for_test());
let bootstrap = Arc::new(NostrRendezvous::new_for_test());
bootstrap.push_event_for_test(BootstrapEvent::Failed {
peer_config: crate::config::PeerConfig::new(peer_identity.npub(), "udp", "127.0.0.1:9"),
reason: "stale traversal failure".to_string(),
});
node.nostr_discovery = Some(bootstrap.clone());
node.nostr_rendezvous.set_engine(bootstrap.clone());
node.poll_nostr_discovery().await;
node.poll_nostr_rendezvous().await;
assert!(
bootstrap.failure_state_snapshot().is_empty(),
@@ -1149,7 +1149,7 @@ async fn test_nostr_traversal_failure_skips_connected_peer() {
#[tokio::test]
async fn test_nostr_traversal_established_skips_connected_peer() {
use crate::discovery::EstablishedTraversal;
use crate::nostr::EstablishedTraversal;
use std::net::UdpSocket;
let mut node = make_node();
@@ -1162,7 +1162,7 @@ async fn test_nostr_traversal_established_skips_connected_peer() {
let link_count = node.link_count();
let connection_count = node.connection_count();
let bootstrap = Arc::new(NostrDiscovery::new_for_test());
let bootstrap = Arc::new(NostrRendezvous::new_for_test());
let socket = UdpSocket::bind("127.0.0.1:0").expect("bind local UDP socket");
let remote_addr = "127.0.0.1:9999".parse().expect("parse remote addr");
bootstrap.push_event_for_test(BootstrapEvent::Established {
@@ -1173,9 +1173,9 @@ async fn test_nostr_traversal_established_skips_connected_peer() {
socket,
),
});
node.nostr_discovery = Some(bootstrap.clone());
node.nostr_rendezvous.set_engine(bootstrap.clone());
node.poll_nostr_discovery().await;
node.poll_nostr_rendezvous().await;
assert_eq!(
node.link_count(),
@@ -1711,14 +1711,14 @@ async fn process_pending_retries_gated_at_capacity() {
}
#[tokio::test]
async fn poll_nostr_discovery_established_gated_at_capacity() {
use crate::discovery::EstablishedTraversal;
async fn poll_nostr_rendezvous_established_gated_at_capacity() {
use crate::nostr::EstablishedTraversal;
use std::net::UdpSocket;
let mut node = make_node_with_max_peers(2);
inject_dummy_peers(&mut node, 2);
let bootstrap = Arc::new(NostrDiscovery::new_for_test());
let bootstrap = Arc::new(NostrRendezvous::new_for_test());
let socket = UdpSocket::bind("127.0.0.1:0").expect("bind local UDP socket");
let remote_addr = "127.0.0.1:9999".parse().expect("parse remote addr");
let peer_identity = Identity::generate();
@@ -1730,13 +1730,13 @@ async fn poll_nostr_discovery_established_gated_at_capacity() {
socket,
),
});
node.nostr_discovery = Some(bootstrap.clone());
node.nostr_rendezvous.set_engine(bootstrap.clone());
let before_peers = node.peer_count();
let before_links = node.link_count();
let before_connections = node.connection_count();
node.poll_nostr_discovery().await;
node.poll_nostr_rendezvous().await;
assert_eq!(
node.peer_count(),
@@ -1756,11 +1756,11 @@ async fn poll_nostr_discovery_established_gated_at_capacity() {
}
#[test]
fn nostr_discovery_outbound_admission_atomic_roundtrip() {
fn nostr_rendezvous_outbound_admission_atomic_roundtrip() {
// Verifies the runtime-side plumbing for the two NAT-traversal gate
// points: the setter mutates the atomic and the (super-visible)
// reader observes the value the Node-side wiring would publish.
let bootstrap = NostrDiscovery::new_for_test();
let bootstrap = NostrRendezvous::new_for_test();
assert!(
bootstrap.outbound_admission_allowed(),
"default must allow (start unsaturated)"