examples: improve transfer example (#3873)

## Description

Improves the transfer example we use for dogfooding:

* Change protocol such that the size is client- and not
server-controlled
* Add `--mode` feature on `fetch` side to either download (like
currently), upload, or transfer in both directions
* Add `--duration` feature on `fetch` side to limit by transfer duration
instead of size
* Remove the unordered receive mode. It wasn't used (there was no cli
flag so it was never enabled).
* Add `--output json` to print JSON instead of human-readable text.
* Improve docs

Because the protocol change is wire-breaking the ALPN is updated.

The JSON support was requested @Arqu a couple of time and should make
our integration in netsim easier and less brittle. Output looks like
this atm:

Provide side:
```
{"kind":"EndpointArgs","env":"Staging","relay_url":[],"no_relay":true,"no_discovery":false,"relay_only":false,"pkarr_relay_url":null,"no_pkarr_publish":false,"dns_origin_domain":null,"dns_server":null,"no_dns_resolve":false,"mdns":false,"bind_addr_v4":"127.0.0.1:1234","bind_addr_v4_additional":[],"bind_addr_v6":null,"bind_addr_v6_additional":[],"no_default_bind":false}
{"kind":"EndpointBound","endpoint_id":"5cc1982c0bc2612a2b62e7811242ec317576dace66688af743769e7eebdbb8c7","direct_addresses":["127.0.0.1:1234","[2003:f9:f724:8240:1566:102:9d0d:ea24]:33990","[2003:f9:f724:8240:a6e3:ea7a:0:edb]:33990"],"relay_url":null}
{"kind":"ConnectionAccepted","remote_id":"f2b872754fcaad0efac0bb57e3f19e38a8c4880f6c2789705f2b69b7a2211bed"}
{"kind":"ConnectionTypeChanged","status":"Selected","addr":{"Ip":"127.0.0.1:47519"},"rtt":2046,"remote_id":"f2b872754fcaad0efac0bb57e3f19e38a8c4880f6c2789705f2b69b7a2211bed"}
{"kind":"HandleRequest","request":{"Download":{"Duration":3000000}},"remote_id":"f2b872754fcaad0efac0bb57e3f19e38a8c4880f6c2789705f2b69b7a2211bed"}
{"kind":"UploadComplete","size":1216070367,"duration":3002590,"remote_id":"f2b872754fcaad0efac0bb57e3f19e38a8c4880f6c2789705f2b69b7a2211bed"}
{"kind":"ConnectionClosed","duration":3002772,"error":null,"remote_id":"f2b872754fcaad0efac0bb57e3f19e38a8c4880f6c2789705f2b69b7a2211bed"}
{"kind":"PathStats","paths":[{"remote_addr":{"Ip":"127.0.0.1:47519"},"rtt":95,"bytes_sent":813274,"bytes_recv":1244335203}],"remote_id":"f2b872754fcaad0efac0bb57e3f19e38a8c4880f6c2789705f2b69b7a2211bed"}
```

Fetch side:
```
{"kind":"EndpointArgs","env":"Staging","relay_url":[],"no_relay":true,"no_discovery":false,"relay_only":false,"pkarr_relay_url":null,"no_pkarr_publish":false,"dns_origin_domain":null,"dns_server":null,"no_dns_resolve":false,"mdns":false,"bind_addr_v4":null,"bind_addr_v4_additional":[],"bind_addr_v6":null,"bind_addr_v6_additional":[],"no_default_bind":false}
{"kind":"SecretGenerated","secret_key":"a0952bebe97106c30d6b22a50402d55d894b8e5e3d5b63d7e643bc5e6ad8f59a"}
{"kind":"EndpointBound","endpoint_id":"f2b872754fcaad0efac0bb57e3f19e38a8c4880f6c2789705f2b69b7a2211bed","direct_addresses":["172.16.10.33:47519","[2003:f9:f724:8240:1566:102:9d0d:ea24]:45524","[2003:f9:f724:8240:a6e3:ea7a:0:edb]:45524"],"relay_url":null}
{"kind":"Connected","remote_id":"5cc1982c0bc2612a2b62e7811242ec317576dace66688af743769e7eebdbb8c7","duration":3820}
{"kind":"StartRequest","mode":"Download","length":{"Duration":3000000}}
{"kind":"ConnectionTypeChanged","status":"Selected","addr":{"Ip":"127.0.0.1:1234"},"rtt":1162}
{"kind":"DownloadComplete","size":1216070367,"time_to_first_byte":5699,"num_chunks":31134,"duration":3004047}
{"kind":"ConnectionClosed","duration":3007952,"error":null}
{"kind":"EndpointClosed","duration":81556,"timed_out":false}
{"kind":"PathStats","paths":[{"remote_addr":{"Ip":"127.0.0.1:1234"},"rtt":84,"bytes_sent":1244335156,"bytes_recv":956724}]}
```

## Breaking Changes

<!-- Optional, if there are any breaking changes document them,
including how to migrate older code. -->

## Notes & open questions

This will likely break netsim.

## Change checklist
<!-- Remove any that are not relevant. -->
- [ ] Self-review.
- [ ] Documentation updates following the [style
guide](https://rust-lang.github.io/rfcs/1574-more-api-documentation-conventions.html#appendix-a-full-conventions-text),
if relevant.
- [ ] Tests if relevant.
- [ ] All breaking changes documented.
- [ ] List all breaking changes in the above "Breaking Changes" section.
- [ ] Open an issue or PR on any number0 repos that are affected by this
breaking change. Give guidance on how the updates should be handled or
do the actual updates themselves. The major ones are:
    - [ ] [`quic-rpc`](https://github.com/n0-computer/quic-rpc)
    - [ ] [`iroh-gossip`](https://github.com/n0-computer/iroh-gossip)
    - [ ] [`iroh-blobs`](https://github.com/n0-computer/iroh-blobs)
    - [ ] [`dumbpipe`](https://github.com/n0-computer/dumbpipe)
    - [ ] [`sendme`](https://github.com/n0-computer/sendme)
This commit is contained in:
Franz Heinzmann
2026-01-27 21:26:46 +00:00
committed by GitHub
parent a738ac7788
commit f4bfc9d7b7
4 changed files with 754 additions and 268 deletions
Generated
+1
View File
@@ -1964,6 +1964,7 @@ dependencies = [
"bytes",
"cfg_aliases",
"clap",
"console",
"console_error_panic_hook",
"data-encoding",
"derive_more",
+2 -1
View File
@@ -132,7 +132,7 @@ impl PublicKey {
/// Convert to a hex string limited to the first 5 bytes for a friendly string
/// representation of the key.
pub fn fmt_short(&self) -> impl Display + 'static {
pub fn fmt_short(&self) -> impl Display + Copy + 'static {
PublicKeyShort(
self.0.as_bytes()[0..5]
.try_into()
@@ -153,6 +153,7 @@ impl PublicKey {
}
}
#[derive(Copy, Clone)]
struct PublicKeyShort([u8; 5]);
impl Display for PublicKeyShort {
+1
View File
@@ -135,6 +135,7 @@ tracing-subscriber = { version = "0.3", features = [
indicatif = { version = "0.18", features = ["tokio"] }
parse-size = { version = "1.1.0", features = ['std'] }
iroh-base = { version = "0.95.1", default-features = false, features = ["key", "relay"], path = "../iroh-base" }
console = { version = "0.16" }
# wasm-in-browser test/dev dependencies
[target.'cfg(all(target_family = "wasm", target_os = "unknown"))'.dev-dependencies]
+750 -267
View File
File diff suppressed because it is too large Load Diff