Skip to content

Commit b2b773d

Browse files
committed
feat: discover nodes over DNS by default
1 parent 878fd52 commit b2b773d

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

iroh/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ hashlink = "0.8.4"
2929
hex = { version = "0.4.3" }
3030
iroh-bytes = { version = "0.12.0", path = "../iroh-bytes", features = ["downloader"] }
3131
iroh-base = { version = "0.12.0", path = "../iroh-base" }
32+
iroh-dns = { version = "0.12.0", path = "../iroh-dns" }
3233
iroh-io = { version = "0.4.0", features = ["stats"] }
3334
iroh-metrics = { version = "0.12.0", path = "../iroh-metrics", optional = true }
3435
iroh-net = { version = "0.12.0", path = "../iroh-net" }

iroh/src/commands/start.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use iroh::{
1414
rpc_protocol::{ProviderRequest, ProviderResponse, ProviderService},
1515
util::{fs::load_secret_key, path::IrohPaths},
1616
};
17+
use iroh_dns::discovery::{DnsDiscovery};
1718
use iroh_net::{
1819
derp::{DerpMap, DerpMode},
1920
key::SecretKey,
@@ -219,12 +220,15 @@ pub(crate) async fn start_node(
219220
Some(derp_map) => DerpMode::Custom(derp_map),
220221
};
221222

223+
let discovery = DnsDiscovery::with_iroh_test(Some(secret_key.clone()))?;
224+
222225
Node::builder(bao_store, doc_store)
223226
.derp_mode(derp_mode)
224227
.peers_data_path(peers_data_path)
225228
.local_pool(rt)
226229
.rpc_endpoint(rpc_endpoint)
227230
.secret_key(secret_key)
231+
.node_discovery(Box::new(discovery))
228232
.spawn()
229233
.await
230234
}

iroh/src/node.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ use iroh_net::derp::DerpUrl;
3737
use iroh_net::magic_endpoint::get_alpn;
3838
use iroh_net::magicsock::LocalEndpointsStream;
3939
use iroh_net::util::AbortingJoinHandle;
40+
use iroh_net::magicsock::Discovery;
4041
use iroh_net::{
4142
derp::DerpMode,
4243
key::{PublicKey, SecretKey},
@@ -135,6 +136,8 @@ where
135136
docs: S,
136137
/// Path to store peer data. If `None`, peer data will not be persisted.
137138
peers_data_path: Option<PathBuf>,
139+
/// Discovery service to retreive node dialing info.
140+
node_discovery: Option<Box<dyn Discovery>>,
138141
}
139142

140143
const PROTOCOLS: [&[u8]; 3] = [&iroh_bytes::protocol::ALPN, GOSSIP_ALPN, SYNC_ALPN];
@@ -153,6 +156,7 @@ impl<D: Map, S: DocStore> Builder<D, S> {
153156
rt: None,
154157
docs,
155158
peers_data_path: None,
159+
node_discovery: None,
156160
}
157161
}
158162
}
@@ -180,6 +184,7 @@ where
180184
rt: self.rt,
181185
docs: self.docs,
182186
peers_data_path: self.peers_data_path,
187+
node_discovery: self.node_discovery,
183188
}
184189
}
185190

@@ -243,6 +248,14 @@ where
243248
self
244249
}
245250

251+
/// Sets the node discovery service.
252+
///
253+
/// If not set, nodes without direct or derp addresses will not be dialable.
254+
pub fn node_discovery(mut self, discovery: Box<dyn Discovery>) -> Self {
255+
self.node_discovery = Some(discovery);
256+
self
257+
}
258+
246259
/// Spawns the [`Node`] in a tokio task.
247260
///
248261
/// This will create the underlying network server and spawn a tokio task accepting
@@ -274,6 +287,10 @@ where
274287
.transport_config(transport_config)
275288
.concurrent_connections(MAX_CONNECTIONS)
276289
.derp_mode(self.derp_mode);
290+
let endpoint = match self.node_discovery {
291+
Some(discovery) => endpoint.discovery(discovery),
292+
None => endpoint
293+
};
277294
let endpoint = match self.peers_data_path {
278295
Some(path) => endpoint.peers_data_path(path),
279296
None => endpoint,

0 commit comments

Comments
 (0)