Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Install it using `cargo add iroh`, then on the connecting side:
```rs
const ALPN: &[u8] = b"iroh-example/echo/0";

let endpoint = Endpoint::builder().discovery_n0().bind().await?;
let endpoint = Endpoint::bind().await?;

// Open a connection to the accepting endpoint
let conn = endpoint.connect(addr, ALPN).await?;
Expand All @@ -85,7 +85,7 @@ endpoint.close().await;

And on the accepting side:
```rs
let endpoint = Endpoint::builder().discovery_n0().bind().await?;
let endpoint = Endpoint::bind().await?;

let router = Router::builder(endpoint)
.accept(ALPN.to_vec(), Arc::new(Echo))
Expand Down
3 changes: 1 addition & 2 deletions iroh/examples/echo-no-router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ async fn main() -> Result<()> {
}

async fn connect_side(addr: EndpointAddr) -> Result<()> {
let endpoint = Endpoint::builder().discovery_n0().bind().await?;
let endpoint = Endpoint::bind().await?;

// Open a connection to the accepting endpoint
let conn = endpoint.connect(addr, ALPN).await?;
Expand Down Expand Up @@ -68,7 +68,6 @@ async fn connect_side(addr: EndpointAddr) -> Result<()> {

async fn start_accept_side() -> Result<Endpoint> {
let endpoint = Endpoint::builder()
.discovery_n0()
// The accept side needs to opt-in to the protocols it accepts,
// as any connection attempts that can't be found with a matching ALPN
// will be rejected.
Expand Down
4 changes: 2 additions & 2 deletions iroh/examples/echo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ async fn main() -> Result<()> {
}

async fn connect_side(addr: EndpointAddr) -> Result<()> {
let endpoint = Endpoint::builder().discovery_n0().bind().await?;
let endpoint = Endpoint::bind().await?;

// Open a connection to the accepting endpoint
let conn = endpoint.connect(addr, ALPN).await?;
Expand Down Expand Up @@ -68,7 +68,7 @@ async fn connect_side(addr: EndpointAddr) -> Result<()> {
}

async fn start_accept_side() -> Result<Router> {
let endpoint = Endpoint::builder().discovery_n0().bind().await?;
let endpoint = Endpoint::bind().await?;

// Build our protocol handler and add our protocol, identified by its ALPN, and spawn the endpoint.
let router = Router::builder(endpoint).accept(ALPN, Echo).spawn();
Expand Down
5 changes: 3 additions & 2 deletions iroh/examples/locally-discovered-nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ async fn main() -> Result<()> {
tracing_subscriber::fmt::init();
println!("Discovering Local Endpoints Example!");

let ep = Endpoint::builder().bind().await?;
let ep = Endpoint::bind().await?;
let endpoint_id = ep.id();

let mdns = MdnsDiscovery::builder().build(endpoint_id)?;
Expand Down Expand Up @@ -68,7 +68,8 @@ async fn main() -> Result<()> {
for _ in 0..endpoint_count {
let ud = user_data.clone();
set.spawn(async move {
let ep = Endpoint::builder().discovery_local_network().bind().await?;
let ep = Endpoint::bind().await?;
ep.discovery().add(MdnsDiscovery::builder().build(ep.id())?);
ep.set_user_data_for_discovery(Some(ud));
tokio::time::sleep(Duration::from_secs(3)).await;
ep.close().await;
Expand Down
4 changes: 2 additions & 2 deletions iroh/examples/screening-connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ async fn main() -> Result<()> {
}

async fn connect_side(addr: &EndpointAddr) -> Result<()> {
let endpoint = Endpoint::builder().discovery_n0().bind().await?;
let endpoint = Endpoint::bind().await?;

// Open a connection to the accepting endpoint
let conn = endpoint.connect(addr.clone(), ALPN).await?;
Expand Down Expand Up @@ -79,7 +79,7 @@ async fn connect_side(addr: &EndpointAddr) -> Result<()> {
}

async fn start_accept_side() -> Result<Router> {
let endpoint = Endpoint::builder().discovery_n0().bind().await?;
let endpoint = Endpoint::bind().await?;

let echo = ScreenedEcho {
conn_attempt_count: Arc::new(AtomicU64::new(0)),
Expand Down
2 changes: 1 addition & 1 deletion iroh/examples/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ async fn main() -> Result<()> {
let args = Cli::parse();

// Build an endpoint
let endpoint = Endpoint::builder().discovery_n0().bind().await?;
let endpoint = Endpoint::bind().await?;

// Build our protocol handler. The `builder` exposes access to various subsystems in the
// iroh endpoint. In our case, we need a blobs client and the endpoint.
Expand Down
34 changes: 19 additions & 15 deletions iroh/examples/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,27 +220,14 @@ impl EndpointArgs {
let url = self
.pkarr_relay_url
.unwrap_or_else(|| self.env.pkarr_relay_url());
builder = builder.add_discovery(PkarrPublisher::builder(url));
builder = builder.discovery(PkarrPublisher::builder(url));
}

if !self.no_dns_resolve {
let domain = self
.dns_origin_domain
.unwrap_or_else(|| self.env.dns_origin_domain());
builder = builder.add_discovery(DnsDiscovery::builder(domain));
}

if self.mdns {
#[cfg(feature = "discovery-local-network")]
{
builder = builder.discovery_local_network();
}
#[cfg(not(feature = "discovery-local-network"))]
{
snafu::whatever!(
"Must have the `test-utils` feature enabled when using the `--relay-only` flag"
);
}
builder = builder.discovery(DnsDiscovery::builder(domain));
}

if self.relay_only {
Expand Down Expand Up @@ -270,6 +257,23 @@ impl EndpointArgs {

let endpoint = builder.alpns(vec![TRANSFER_ALPN.to_vec()]).bind().await?;

if self.mdns {
#[cfg(feature = "discovery-local-network")]
{
use iroh::discovery::mdns::MdnsDiscovery;

endpoint
.discovery()
.add(MdnsDiscovery::builder().build(endpoint.id())?);
}
#[cfg(not(feature = "discovery-local-network"))]
{
snafu::whatever!(
"Must have the `test-utils` feature enabled when using the `--relay-only` flag"
);
}
}

let endpoint_id = endpoint.id();
println!("Our endpoint id:\n\t{endpoint_id}");

Expand Down
Loading
Loading