Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(iroh): Make iroh compile to Wasm & run in browsers #3145

Draft
wants to merge 27 commits into
base: matheus23/iroh-net-report-browser
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
9fddcc4
Use `n0-future` in favor of `futures-*` packages, setup semgrep rules
matheus23 Jan 28, 2025
ea817c2
Also avoid `std::time` imports
matheus23 Jan 29, 2025
cd3f394
Fully switch to `n0_future` re-exports outside of tests
matheus23 Jan 29, 2025
cb9b351
Remove semgrep
matheus23 Jan 29, 2025
1fb26fa
Clean up a bit
matheus23 Jan 29, 2025
abcb366
chore: Update n0-future version
matheus23 Jan 29, 2025
4d7a455
feat(iroh-net-report): Compile and run in wasm/browsers
matheus23 Jan 20, 2025
dd90ed1
Use `n0_future` and remove `task` module in favor for it
matheus23 Jan 24, 2025
1a123ed
remove deps that now moved from net-report to n0-future
matheus23 Jan 27, 2025
8f54402
Depend on iroh-quinn version 0.13 everywhere
matheus23 Jan 28, 2025
8984563
Improve `iroh-net-report/Cargo.toml` diff
matheus23 Jan 28, 2025
1f83a06
Reduce diff
matheus23 Jan 29, 2025
3fd7585
Fix rebase
matheus23 Jan 29, 2025
ad7c3a8
Add `wasm_browser` cfg-alias to `iroh`
matheus23 Jan 20, 2025
b8cdfe3
Adjust `iroh.toml` to avoid unused and non-browser dependencies in wa…
matheus23 Jan 20, 2025
ff02a6d
Add `web_runtime` for `quinn`, cfg out everything non-browser-runnable
matheus23 Jan 22, 2025
537a295
Make `Endpoint::connect` work in browsers
matheus23 Jan 22, 2025
44879bc
Disable sending UDP pings & NodeMap UDP receive path in wasm_browser
matheus23 Jan 23, 2025
1eacf01
Try to not depend on `iroh-net-report` at all in `iroh` in browsers
matheus23 Jan 24, 2025
e19702c
Don't print a warning when we try to send UDP pings in browsers
matheus23 Jan 24, 2025
1a03a75
cfg out network link changes in wasm_browser
matheus23 Jan 24, 2025
0cbd762
Partially revert "Try to not depend on `iroh-net-report` at all in `i…
matheus23 Jan 24, 2025
9ec7a57
Enable periodic re_stun, which enables finding a home relay
matheus23 Jan 24, 2025
5f1ce95
Small cleanups
matheus23 Jan 24, 2025
c1fe5ec
Depend on `n0-future` for `task` and `time` utils
matheus23 Jan 24, 2025
43ee5a8
Fix `ClientBuilder` constructor with new rebase
matheus23 Jan 28, 2025
3320d80
Fix rebase
matheus23 Jan 29, 2025
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
47 changes: 31 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion iroh-dns-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ derive_more = { version = "1.0.0", features = [
"from",
] }
dirs-next = "2.0.0"
futures-lite = "2.5"
governor = "0.6.3" #needs new release of tower_governor for 0.7.0
hickory-server = { version = "=0.25.0-alpha.4", features = ["dns-over-rustls", "dns-over-https-rustls"] }
http = "1.0.0"
humantime-serde = "1.1.1"
iroh-metrics = { version = "0.31.0" }
lru = "0.12.3"
n0-future = "0.1.2"
pkarr = { version = "2.3.1", features = [ "async", "relay", "dht"], default-features = false }
rcgen = "0.13"
redb = "2.0.0"
Expand Down
2 changes: 1 addition & 1 deletion iroh-dns-server/benches/write.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use anyhow::Result;
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput};
use iroh::{discovery::pkarr::PkarrRelayClient, dns::node_info::NodeInfo, SecretKey};
use iroh::{discovery::pkarr::PkarrRelayClient, node_info::NodeInfo, SecretKey};
use iroh_dns_server::{config::Config, server::Server, ZoneStore};
use rand_chacha::rand_core::SeedableRng;
use tokio::runtime::Runtime;
Expand Down
2 changes: 1 addition & 1 deletion iroh-dns-server/examples/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use iroh::{
dns::{N0_DNS_NODE_ORIGIN_PROD, N0_DNS_NODE_ORIGIN_STAGING},
pkarr::{PkarrRelayClient, N0_DNS_PKARR_RELAY_PROD, N0_DNS_PKARR_RELAY_STAGING},
},
dns::node_info::{to_z32, NodeInfo, IROH_TXT_NAME},
node_info::{to_z32, NodeInfo, IROH_TXT_NAME},
NodeId, SecretKey,
};
use url::Url;
Expand Down
3 changes: 2 additions & 1 deletion iroh-dns-server/examples/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ use hickory_resolver::{
};
use iroh::{
discovery::dns::{N0_DNS_NODE_ORIGIN_PROD, N0_DNS_NODE_ORIGIN_STAGING},
dns::{node_info::TxtAttrs, DnsResolver},
dns::DnsResolver,
node_info::TxtAttrs,
NodeId,
};

Expand Down
2 changes: 1 addition & 1 deletion iroh-dns-server/src/http/tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use axum_server::{
accept::Accept,
tls_rustls::{RustlsAcceptor, RustlsConfig},
};
use futures_lite::{future::Boxed as BoxFuture, FutureExt};
use n0_future::{future::Boxed as BoxFuture, FutureExt};
use serde::{Deserialize, Serialize};
use tokio::io::{AsyncRead, AsyncWrite};
use tokio_rustls_acme::{axum::AxumAcceptor, caches::DirCache, AcmeConfig};
Expand Down
3 changes: 2 additions & 1 deletion iroh-dns-server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ mod tests {
use hickory_server::proto::xfer::Protocol;
use iroh::{
discovery::pkarr::PkarrRelayClient,
dns::{node_info::NodeInfo, DnsResolver, ResolverExt},
dns::{DnsResolver, ResolverExt},
node_info::NodeInfo,
SecretKey,
};
use pkarr::{PkarrClient, SignedPacket};
Expand Down
25 changes: 16 additions & 9 deletions iroh-net-report/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,39 @@ workspace = true
anyhow = "1"
bytes = "1.7"
derive_more = { version = "1.0.0", features = ["display"] }
futures-buffered = "0.2.8"
futures-lite = "2.3"
hickory-resolver = "=0.25.0-alpha.4"
iroh-base = { version = "0.31.0", path = "../iroh-base", default-features = false, features = ["relay"] }
iroh-metrics = { version = "0.31", default-features = false }
iroh-relay = { version = "0.31", path = "../iroh-relay" }
netwatch = { version = "0.3" }
portmapper = { version = "0.3", default-features = false }
quinn = { package = "iroh-quinn", version = "0.13.0" }
iroh-relay = { version = "0.31", path = "../iroh-relay", default-features = false }
n0-future = "0.1.2"
quinn = { package = "iroh-quinn", version = "0.13.0", default-features = false }
rand = "0.8"
reqwest = { version = "0.12", default-features = false }
reqwest = { version = "0.12", default-features = false, features = ["stream"] }
rustls = { version = "0.23", default-features = false }
surge-ping = "0.8.0"
thiserror = "2"
tokio = { version = "1", default-features = false, features = ["sync", "time", "macros", "rt"] }
tokio-util = { version = "0.7.12", default-features = false }
tracing = "0.1"
url = { version = "2.4" }

# non-wasm-in-browser dependencies
[target.'cfg(not(all(target_family = "wasm", target_os = "unknown")))'.dependencies]
hickory-resolver = "=0.25.0-alpha.4"
netwatch = { version = "0.3" }
portmapper = { version = "0.3", default-features = false }
surge-ping = "0.8.0"

[dev-dependencies]
futures-lite = "2.3"
iroh-relay = { path = "../iroh-relay", features = ["test-utils", "server"] }
iroh-test = { path = "../iroh-test" }
pretty_assertions = "1.4"
quinn = { package = "iroh-quinn", version = "0.13.0" }
testresult = "0.4.0"
tokio = { version = "1", default-features = false, features = ["test-util"] }

[build-dependencies]
cfg_aliases = { version = "0.2" }

[features]
default = ["metrics"]
metrics = ["iroh-metrics/metrics", "portmapper/metrics"]
Expand Down
9 changes: 9 additions & 0 deletions iroh-net-report/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use cfg_aliases::cfg_aliases;

fn main() {
// Setup cfg aliases
cfg_aliases! {
// Convenience aliases
wasm_browser: { all(target_family = "wasm", target_os = "unknown") },
}
}
2 changes: 1 addition & 1 deletion iroh-net-report/src/defaults.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/// Contains all timeouts that we use in `iroh-net-report`.
pub(crate) mod timeouts {
use std::time::Duration;
use n0_future::time::Duration;

// Timeouts for net_report

Expand Down
12 changes: 6 additions & 6 deletions iroh-net-report/src/dns.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::{fmt::Write, net::IpAddr};

use anyhow::Result;
use futures_lite::{Future, StreamExt};
use hickory_resolver::{IntoName, TokioResolver};
use n0_future::{time, Future, StreamExt};

use crate::defaults::timeouts::DNS_TIMEOUT;

Expand Down Expand Up @@ -66,12 +66,12 @@ pub(crate) trait ResolverExt {

impl ResolverExt for TokioResolver {
async fn lookup_ipv4<N: IntoName>(&self, host: N) -> Result<impl Iterator<Item = IpAddr>> {
let addrs = tokio::time::timeout(DNS_TIMEOUT, self.ipv4_lookup(host)).await??;
let addrs = time::timeout(DNS_TIMEOUT, self.ipv4_lookup(host)).await??;
Ok(addrs.into_iter().map(|ip| IpAddr::V4(ip.0)))
}

async fn lookup_ipv6<N: IntoName>(&self, host: N) -> Result<impl Iterator<Item = IpAddr>> {
let addrs = tokio::time::timeout(DNS_TIMEOUT, self.ipv6_lookup(host)).await??;
let addrs = time::timeout(DNS_TIMEOUT, self.ipv6_lookup(host)).await??;
Ok(addrs.into_iter().map(|ip| IpAddr::V6(ip.0)))
}

Expand Down Expand Up @@ -150,14 +150,14 @@ async fn stagger_call<T, F: Fn() -> Fut, Fut: Future<Output = Result<T>>>(
f: F,
delays_ms: &[u64],
) -> Result<T> {
let mut calls = futures_buffered::FuturesUnorderedBounded::new(delays_ms.len() + 1);
let mut calls = n0_future::FuturesUnorderedBounded::new(delays_ms.len() + 1);
// NOTE: we add the 0 delay here to have a uniform set of futures. This is more performant than
// using alternatives that allow futures of different types.
for delay in std::iter::once(&0u64).chain(delays_ms) {
let delay = std::time::Duration::from_millis(*delay);
let delay = time::Duration::from_millis(*delay);
let fut = f();
let staggered_fut = async move {
tokio::time::sleep(delay).await;
time::sleep(delay).await;
fut.await
};
calls.push(staggered_fut)
Expand Down
Loading
Loading