|
23 | 23 | //!
|
24 | 24 | //! Some generally useful discovery implementations are provided:
|
25 | 25 | //!
|
26 |
| -//! - The [`DnsDiscovery`] which supports publishing to a special DNS server and performs |
27 |
| -//! lookups via the standard DNS systems. [Number 0] runs a public instance of this which |
28 |
| -//! is globally available and a reliable default choice. |
| 26 | +//! - The [`DnsDiscovery`] which performs lookups via the standard DNS systems. To publish |
| 27 | +//! to this DNS server a [`PkarrPublisher`] is needed. [Number 0] runs a public instance |
| 28 | +//! of a [`PkarrPublisher`] with attached DNS server which is globally available and a |
| 29 | +//! reliable default choice. |
29 | 30 | //!
|
30 | 31 | //! - The [`PkarrResolver`] which can perform lookups from designated [pkarr relay servers]
|
31 | 32 | //! using HTTP.
|
32 | 33 | //!
|
| 34 | +//! - The [`LocalSwarmDiscovery`] discovers iroh-net nodes present on the local network, |
| 35 | +//! very similar to mdNS. |
| 36 | +//! |
| 37 | +//! - The [`DhtDiscovery`] also uses the [`pkarr`] system but can also publish and lookup |
| 38 | +//! records to/from the Mainline DHT. |
| 39 | +//! |
33 | 40 | //! To use multiple discovery systems simultaneously use [`ConcurrentDiscovery`] which will
|
34 | 41 | //! perform lookups to all discovery systems at the same time.
|
35 | 42 | //!
|
| 43 | +//! # Examples |
| 44 | +//! |
| 45 | +//! A very common setup is to enable DNS discovery, which needs to be done in two parts as a |
| 46 | +//! [`PkarrPublisher`] and [`DnsDiscovery`]: |
| 47 | +//! |
| 48 | +//! ```no_run |
| 49 | +//! use iroh_net::discovery::dns::DnsDiscovery; |
| 50 | +//! use iroh_net::discovery::pkarr::PkarrPublisher; |
| 51 | +//! use iroh_net::discovery::ConcurrentDiscovery; |
| 52 | +//! use iroh_net::key::SecretKey; |
| 53 | +//! use iroh_net::Endpoint; |
| 54 | +//! |
| 55 | +//! # async fn wrapper() -> anyhow::Result<()> { |
| 56 | +//! let secret_key = SecretKey::generate(); |
| 57 | +//! let discovery = ConcurrentDiscovery::from_services(vec![ |
| 58 | +//! Box::new(PkarrPublisher::n0_dns(secret_key.clone())), |
| 59 | +//! Box::new(DnsDiscovery::n0_dns()), |
| 60 | +//! ]); |
| 61 | +//! let ep = Endpoint::builder() |
| 62 | +//! .secret_key(secret_key) |
| 63 | +//! .discovery(Box::new(discovery)) |
| 64 | +//! .bind() |
| 65 | +//! .await?; |
| 66 | +//! # Ok(()) |
| 67 | +//! # } |
| 68 | +//! ``` |
| 69 | +//! |
| 70 | +//! To also enable [`LocalSwarmDiscovery`], it can be added as another service in the |
| 71 | +//! [`ConcurrentDiscovery`]: |
| 72 | +//! |
| 73 | +//! ```no_run |
| 74 | +//! # use iroh_net::discovery::dns::DnsDiscovery; |
| 75 | +//! # use iroh_net::discovery::local_swarm_discovery::LocalSwarmDiscovery; |
| 76 | +//! # use iroh_net::discovery::pkarr::PkarrPublisher; |
| 77 | +//! # use iroh_net::discovery::ConcurrentDiscovery; |
| 78 | +//! # use iroh_net::key::SecretKey; |
| 79 | +//! # |
| 80 | +//! # async fn wrapper() -> anyhow::Result<()> { |
| 81 | +//! # let secret_key = SecretKey::generate(); |
| 82 | +//! let discovery = ConcurrentDiscovery::from_services(vec![ |
| 83 | +//! Box::new(PkarrPublisher::n0_dns(secret_key.clone())), |
| 84 | +//! Box::new(DnsDiscovery::n0_dns()), |
| 85 | +//! Box::new(LocalSwarmDiscovery::new(secret_key.public())?), |
| 86 | +//! ]); |
| 87 | +//! # Ok(()) |
| 88 | +//! # } |
| 89 | +//! ``` |
| 90 | +//! |
36 | 91 | //! [`RelayUrl`]: crate::relay::RelayUrl
|
37 | 92 | //! [`Builder::discovery`]: crate::endpoint::Builder::discovery
|
38 | 93 | //! [`DnsDiscovery`]: dns::DnsDiscovery
|
39 | 94 | //! [Number 0]: https://n0.computer
|
40 | 95 | //! [`PkarrResolver`]: pkarr::PkarrResolver
|
| 96 | +//! [`PkarrPublisher`]: pkarr::PkarrPublisher |
| 97 | +//! [`LocalSwarmDiscovery`]: local_swarm_discovery::LocalSwarmDiscovery |
| 98 | +//! [`DhtDiscovery`]: pkarr::dht::DhtDiscovery |
41 | 99 | //! [pkarr relay servers]: https://pkarr.org/#servers
|
42 | 100 |
|
43 | 101 | use std::time::Duration;
|
|
0 commit comments