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 wasm32-unknown-unknown #3189

Merged
merged 34 commits into from
Feb 21, 2025

Conversation

matheus23
Copy link
Member

@matheus23 matheus23 commented Feb 19, 2025

Description

(This PR is a rebase & some changes from the #3145 PR, so we don't disturb users who are trying out the iroh browser alpha.)

  • Adds a bunch of #[cfg(not(wasm_browser))] to anything related to socket networking (UDP sockets, DNS, etc.)
  • Implements a WebRuntime for quinn to use instead of TokioRuntime in browsers
  • Implements sleeping & timing utilities for backoff that work in browsers
  • Moves node_info out of the dns module, so we can disable dns as a whole, but keep node_info for discovery
  • Disables MappedAddr::Ip in browsers
  • Adjusts dependencies so we don't depend on unused/unsupported things in browsers

Breaking Changes

  • iroh-relay: The iroh_relay::dns::node_info module was moved to iroh_relay::node_info

Notes & open questions

I'm holding off on refactoring bigger parts for now. I have two main ideas:

  • Group a bunch of structs in magicsock.rs, i.e. everything that depends on sockets.
    However, to do this, I want to refactor the way we sometimes use Arc<netwatch::UdpSocket> and sometimes use UdpConn, which is just a newtype over said type.
    Ideally we store Arc<netwatch::UdpSocket> everywhere, since it's more commonly used in APIs, e.g. in iroh-net-report, and only use UdpConn, when we need the udp sockets to implement AsyncUdpSocket from quinn.
  • Refactor the node_info module so there's fewer places that depend on DnsResolver in it.
    There's a bunch of things in that module that IMO are needless indirections (we go from hickory::TxtLookup -> node_info::TxtAttrs<IrohAttr> -> (NodeId, NodeData) -> NodeInfo. And even then, NodeInfo is mostly isomorphic to NodeAttr).

I think both these refactors are helpful, but don't necessarily make the diff easier to read? Not sure. I'd like to merge this & then work on these refactors next week.

Change checklist

  • Self-review.
  • Documentation updates following the style guide, if relevant.
  • Tests if relevant.
  • All breaking changes documented.

@matheus23 matheus23 self-assigned this Feb 19, 2025
Copy link

github-actions bot commented Feb 19, 2025

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

Last updated: 2025-02-21T16:21:36Z

Copy link

github-actions bot commented Feb 19, 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: 83683bf

Comment on lines 47 to +49
#[cfg(not(wasm_browser))]
pub mod dns;
pub mod node_info;
Copy link
Member Author

Choose a reason for hiding this comment

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

Moving node_info from crate::dns::node_info to crate::node_info, because we need it for discovery in browsers, but it's still nice to disable the whole dns module in browsers, too.

Comment on lines -499 to -507
impl Drop for DiscoveryTask {
fn drop(&mut self) {
self.task.abort();
}
}

Copy link
Member Author

Choose a reason for hiding this comment

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

DiscoveryTask::task is an AbortOnDropHandle.

@matheus23 matheus23 marked this pull request as ready for review February 21, 2025 11:02
Copy link
Contributor

@dignifiedquire dignifiedquire left a comment

Choose a reason for hiding this comment

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

some small comments, otherwise LGTM
Cleaning up the cfgs a bit will certainly be needed, but can definitely land as follow ups

@dignifiedquire dignifiedquire added this to the v0.33.0 milestone Feb 21, 2025
@matheus23 matheus23 enabled auto-merge February 21, 2025 15:19
@matheus23 matheus23 disabled auto-merge February 21, 2025 16:00
@matheus23 matheus23 enabled auto-merge February 21, 2025 16:00
@matheus23 matheus23 disabled auto-merge February 21, 2025 16:00
@matheus23 matheus23 enabled auto-merge February 21, 2025 16:14
@matheus23 matheus23 added this pull request to the merge queue Feb 21, 2025
Merged via the queue into main with commit 247b891 Feb 21, 2025
25 of 26 checks passed
@Arqu Arqu deleted the matheus23/browser branch February 24, 2025 08:24
Frando added a commit to n0-computer/iroh-examples that referenced this pull request Feb 25, 2025
This adds a new example: A chat app based on iroh gossip, running both in the browser and on the command line.

See the README for details.

* based on #106 for CI infrastructure added there
* uses n0-computer/iroh#3189 and n0-computer/iroh-gossip#37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

2 participants