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

Closed
wants to merge 27 commits into from

Conversation

matheus23
Copy link
Member

@matheus23 matheus23 commented Jan 22, 2025

Description

So far this enables this demo: https://github.com/matheus23/browser-iroh-net-demo/blob/update/src/lib.rs

Breaking Changes

Notes & open questions

Needs lots of love and refactoring, and other PRs landing first.

Change checklist

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

Sorry, something went wrong.

@matheus23 matheus23 self-assigned this Jan 22, 2025
@matheus23 matheus23 changed the base branch from main to matheus23/iroh-relay-browser January 24, 2025 08:36
@matheus23 matheus23 changed the base branch from matheus23/iroh-relay-browser to matheus23/iroh-net-report-browser January 24, 2025 09:13
Copy link

github-actions bot commented Jan 24, 2025

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

Last updated: 2025-01-24T10:46:54Z

Copy link

github-actions bot commented Jan 24, 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: 6d1acd9

@matheus23 matheus23 force-pushed the matheus23/iroh-net-report-browser branch from 942d4ac to 766164e Compare January 24, 2025 11:10
@matheus23 matheus23 force-pushed the matheus23/iroh-browser branch from 3458ef3 to d6250d3 Compare January 24, 2025 11:19
@matheus23 matheus23 force-pushed the matheus23/iroh-net-report-browser branch from 766164e to 18eb0d2 Compare January 27, 2025 12:36
@matheus23 matheus23 force-pushed the matheus23/iroh-browser branch from d6250d3 to 445d014 Compare January 27, 2025 12:45
@matheus23 matheus23 force-pushed the matheus23/iroh-net-report-browser branch 2 times, most recently from 4a84051 to 5191a9c Compare January 28, 2025 17:10
@matheus23 matheus23 force-pushed the matheus23/iroh-net-report-browser branch from 5286020 to d4149ba Compare January 29, 2025 10:07
@matheus23 matheus23 force-pushed the matheus23/iroh-net-report-browser branch from d4149ba to 0df6a79 Compare January 29, 2025 10:17
@matheus23 matheus23 force-pushed the matheus23/iroh-browser branch from 8111662 to d9d798e Compare January 29, 2025 10:56
@matheus23 matheus23 force-pushed the matheus23/iroh-net-report-browser branch from 13b0ae0 to 3fd7585 Compare January 29, 2025 10:58
@matheus23 matheus23 force-pushed the matheus23/iroh-browser branch from d747692 to 3320d80 Compare January 29, 2025 10:59
@matheus23 matheus23 force-pushed the matheus23/iroh-net-report-browser branch from 3fd7585 to f9a3720 Compare January 29, 2025 15:48
@matheus23 matheus23 force-pushed the matheus23/iroh-net-report-browser branch 2 times, most recently from 059ec18 to 85ea312 Compare February 11, 2025 14:56
@matheus23 matheus23 added this to the v0.33.0 milestone Feb 13, 2025
github-merge-queue bot pushed a commit that referenced this pull request Feb 14, 2025
## Description

This makes iroh-net-report compile to Wasm. We make sure it's likely to
work by grepping the generated Wasm file for "env" imports (which would
make it not work in browsers).
Mostly this will disable functionality in iroh-net-report for the
browser target - specifically, it disables STUN, QAD, ICMP and all other
probes besides HTTPS to relays.
I've experimentally verified this code works with an integration test,
it's really hard to come up with a good strategy for automating this
testing due to requiring running cross-languages.
I'd like to do that as a follow-up once #3145 is merged.

## Change checklist

- [x] Self-review.
- [x] 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.
Base automatically changed from matheus23/iroh-net-report-browser to main February 14, 2025 11:13
github-merge-queue bot pushed a commit that referenced this pull request Feb 21, 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

- [x] Self-review.
- [x] 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.
- [x] Tests if relevant.
- [x] All breaking changes documented.
@ramfox ramfox closed this Feb 25, 2025
@ramfox
Copy link
Contributor

ramfox commented Feb 25, 2025

replaced by #3189

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.

None yet

2 participants