Skip to content

feat(iroh-relay): Make the client side of iroh-relay compile & run in browsers #3119

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

Merged
merged 23 commits into from
Jan 28, 2025

Conversation

matheus23
Copy link
Member

@matheus23 matheus23 commented Jan 10, 2025

Description

Allows compiling and running iroh-relay in browsers (as long as the server feature is disabled).

By default uses websockets to connect to relays when compiling for the wasm32-unknown-unknown target.
If configured to Protocol::Relay specifically, it'll error out.

Test it yourself: cargo rustc -p iroh-relay --no-default-features --target=wasm32-unknown-unknown --crate-type=cdylib

Breaking Changes

  • iroh: iroh-quinn re-exports are now updated from version 0.12 to version 0.13

Notes & open questions

Note: This updates all crate's versions to iroh-quinn 0.13!
(Because we need them to be consistent between crates in this workspace.)

TODO

  • Add CI check to make sure the built .wasm is (import "env" ...)-free
  • Need a new release of iroh-quinn with my browser PR in
  • Blocking this from merging: Need a new netwatch release with the quinn-udp = "0.5.5" version bound relaxed it's already relaxed

Change checklist

  • Self-review.
  • All breaking changes documented.

@matheus23 matheus23 self-assigned this Jan 10, 2025
@matheus23 matheus23 changed the title feat: Make the client side of iroh-relay compile & run in browsers feat(iroh-relay): Make the client side of iroh-relay compile & run in browsers Jan 10, 2025
Copy link

github-actions bot commented Jan 10, 2025

Documentation for this PR has been generated and is available at: https://n0-computer.github.io/iroh/pr/3119/docs/iroh/

Last updated: 2025-01-28T15:09:34Z

Copy link

github-actions bot commented Jan 10, 2025

Netsim report & logs for this PR have been generated and is available at: LOGS
This report will remain available for 3 days.

Last updated for commit: b91bc27

@matheus23 matheus23 added this to the v0.32.0 milestone Jan 13, 2025
@matheus23 matheus23 force-pushed the matheus23/iroh-relay-browser branch from 687d7bb to d3c1753 Compare January 14, 2025 18:19
Comment on lines -146 to -164
let roots = rustls::RootCertStore {
roots: webpki_roots::TLS_SERVER_ROOTS.to_vec(),
};
let mut config = rustls::client::ClientConfig::builder_with_provider(Arc::new(
rustls::crypto::ring::default_provider(),
))
.with_safe_default_protocol_versions()
.expect("protocols supported by ring")
.with_root_certificates(roots)
.with_no_client_auth();
#[cfg(any(test, feature = "test-utils"))]
if self.insecure_skip_cert_verify {
warn!("Insecure config: SSL certificates from relay servers not verified");
config
.dangerous()
.set_certificate_verifier(Arc::new(NoCertVerifier));
}
config.resumption = Resumption::default();
let tls_connector: tokio_rustls::TlsConnector = Arc::new(config).into();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of immediately constructing the tls_connector in connect, and then either using it or discarding it depending on whether we use connect_ws or connect_relay, I've moved it into connect_relay.

@@ -211,94 +185,6 @@ impl ClientBuilder {
Ok(conn)
}

async fn connect_relay(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

connect_relay and all of its call graph dependencies are now moved into a submodule iroh_relay::client::connect_relay, this makes cfg-ing out much easier.

@matheus23 matheus23 marked this pull request as ready for review January 27, 2025 12:30
@dignifiedquire
Copy link
Contributor

other than my comments this is looking pretty good

Self::Relay { ref mut conn } => Pin::new(conn).poll_flush(cx).map_err(Into::into),
Self::Ws { ref mut conn, .. } => Pin::new(conn).poll_flush(cx).map_err(Into::into),
}
}

fn poll_close(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
match *self {
#[cfg(not(wasm_browser))]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just noting this down: it's really unfortunate we have to do this on all the branches, but I don't have a better idea

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think we can remove them, once/if we go websocket connections only.

@matheus23 matheus23 added this pull request to the merge queue Jan 28, 2025
Merged via the queue into main with commit 03e3e3c Jan 28, 2025
27 checks passed
@dignifiedquire dignifiedquire deleted the matheus23/iroh-relay-browser branch January 28, 2025 16:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants