Skip to content

Commit eab5ef5

Browse files
fix: handle relay mode and add timeout for ticket generation
1 parent 6ba9e3f commit eab5ef5

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

src/main.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,9 @@ async fn export(db: &Store, collection: Collection, mp: &mut MultiProgress) -> a
479479
"target {} already exists. Export stopped.",
480480
target.display()
481481
);
482-
eprintln!("You can remove the file or directory and try again. The download will not be repeated.");
482+
eprintln!(
483+
"You can remove the file or directory and try again. The download will not be repeated."
484+
);
483485
anyhow::bail!("target {} already exists", target.display());
484486
}
485487
let mut stream = db
@@ -632,10 +634,11 @@ async fn send(args: SendArgs) -> anyhow::Result<()> {
632634
eprintln!("using secret key {secret_key}");
633635
}
634636
// create a magicsocket endpoint
637+
let relay_mode: RelayMode = args.common.relay.into();
635638
let mut builder = Endpoint::builder()
636639
.alpns(vec![iroh_blobs::protocol::ALPN.to_vec()])
637640
.secret_key(secret_key)
638-
.relay_mode(args.common.relay.into());
641+
.relay_mode(relay_mode.clone());
639642
if args.ticket_type == AddrInfoOptions::Id {
640643
builder = builder.add_discovery(PkarrPublisher::n0_dns());
641644
}
@@ -647,7 +650,7 @@ async fn send(args: SendArgs) -> anyhow::Result<()> {
647650
}
648651

649652
// use a flat store - todo: use a partial in mem store instead
650-
let suffix = rand::thread_rng().gen::<[u8; 16]>();
653+
let suffix = rand::thread_rng().r#gen::<[u8; 16]>();
651654
let cwd = std::env::current_dir()?;
652655
let blobs_data_dir = cwd.join(format!(".sendme-send-{}", HEXLOWER.encode(&suffix)));
653656
if blobs_data_dir.exists() {
@@ -705,8 +708,19 @@ async fn send(args: SendArgs) -> anyhow::Result<()> {
705708
let router = iroh::protocol::Router::builder(endpoint)
706709
.accept(iroh_blobs::ALPN, blobs.clone())
707710
.spawn();
711+
708712
// wait for the endpoint to figure out its address before making a ticket
709-
let _ = router.endpoint().home_relay().initialized().await;
713+
let ep = router.endpoint();
714+
tokio::time::timeout(Duration::from_secs(30), async move {
715+
if matches!(relay_mode, RelayMode::Disabled) {
716+
// no relay will arrive, as we disabled it, so wait for general init
717+
let _ = ep.node_addr().initialized().await;
718+
} else {
719+
let _ = ep.home_relay().initialized().await;
720+
}
721+
})
722+
.await?;
723+
710724
anyhow::Ok((router, import_result, dt))
711725
};
712726
let (router, (temp_tag, size, collection), dt) = select! {

0 commit comments

Comments
 (0)