Skip to content

Commit 3502542

Browse files
authored
fix: Use discovery when ticket type is not the default (#62)
* fix: Use discovery when ticket type is not the default * Fix README a bit
1 parent 4295842 commit 3502542

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
# Sendme
22

3-
This is an example to use [iroh-bytes](https://crates.io/crates/iroh-bytes) and
4-
[iroh-net](https://crates.io/crates/iroh-net) to send files and directories over
5-
the internet.
3+
This is an example application using [iroh](https://crates.io/crates/iroh) with
4+
the [iroh-blobs](https://crates.io/crates/iroh-blobs) protocol to send files and
5+
directories over the internet.
66

77
It is also useful as a standalone tool for quick copy jobs.
88

9-
Iroh-net will take case of hole punching and NAT traversal whenever possible,
9+
Iroh will take case of hole punching and NAT traversal whenever possible,
1010
and fall back to a relay if hole punching does not succeed.
1111

12-
Iroh-bytes will take care of [blake3](https://crates.io/crates/blake3) verified
12+
Iroh-blobs will take care of [blake3](https://crates.io/crates/blake3) verified
1313
streaming, including resuming interrupted downloads.
1414

15-
Sendme works with 256 bit node ids and therefore location transparent. A ticket
15+
Sendme works with 256 bit node ids and is therefore location transparent. A ticket
1616
will remain valid if the IP address changes. Connections are encrypted using
1717
TLS.
1818

src/main.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ use futures_lite::{future::Boxed, StreamExt};
2222
use indicatif::{
2323
HumanBytes, HumanDuration, MultiProgress, ProgressBar, ProgressDrawTarget, ProgressStyle,
2424
};
25-
use iroh::{Endpoint, NodeAddr, RelayMap, RelayMode, RelayUrl, SecretKey};
25+
use iroh::{
26+
discovery::{dns::DnsDiscovery, pkarr::PkarrPublisher},
27+
Endpoint, NodeAddr, RelayMap, RelayMode, RelayUrl, SecretKey,
28+
};
2629
use iroh_blobs::{
2730
format::collection::Collection,
2831
get::{
@@ -582,6 +585,10 @@ async fn send(args: SendArgs) -> anyhow::Result<()> {
582585
.alpns(vec![iroh_blobs::protocol::ALPN.to_vec()])
583586
.secret_key(secret_key)
584587
.relay_mode(args.common.relay.into());
588+
if args.ticket_type == AddrInfoOptions::Id {
589+
builder =
590+
builder.add_discovery(|secret_key| Some(PkarrPublisher::n0_dns(secret_key.clone())));
591+
}
585592
if let Some(addr) = args.common.magic_ipv4_addr {
586593
builder = builder.bind_addr_v4(addr);
587594
}
@@ -779,6 +786,9 @@ async fn receive(args: ReceiveArgs) -> anyhow::Result<()> {
779786
.secret_key(secret_key)
780787
.relay_mode(args.common.relay.into());
781788

789+
if ticket.node_addr().relay_url.is_none() && ticket.node_addr().direct_addresses.is_empty() {
790+
builder = builder.add_discovery(|_| Some(DnsDiscovery::n0_dns()));
791+
}
782792
if let Some(addr) = args.common.magic_ipv4_addr {
783793
builder = builder.bind_addr_v4(addr);
784794
}
@@ -875,6 +885,9 @@ async fn main() -> anyhow::Result<()> {
875885
Commands::Send(args) => send(args).await,
876886
Commands::Receive(args) => receive(args).await,
877887
};
888+
if let Err(e) = &res {
889+
eprintln!("{e}");
890+
}
878891
match res {
879892
Ok(()) => std::process::exit(0),
880893
Err(_) => std::process::exit(1),

0 commit comments

Comments
 (0)