n0-computer / iroh

A toolkit for building distributed applications
https://iroh.computer
Apache License 2.0
2.59k stars 163 forks source link

Build Web Assembly #1803

Closed DAOCUONG closed 1 month ago

DAOCUONG commented 1 year ago

Try to run :

rustup target add wasm32-unknown-unknown
cargo build --release --target wasm32-unknown-unknown

Got error with mio 

ener.rs:103:18
    |
103 | ...   sys::tcp::accept(inner).map(|(stream, addr)| (TcpStream::from_std(stream), addr))
    |            ^^^ could not find `tcp` in `sys`

error[E0433]: failed to resolve: could not find `udp` in `sys`
   --> /Users/.cargo/registry/src/index.crates.io-6f17d22bba15001f/mio-0.8.9/src/net/udp.rs:122:14
    |
122 |         sys::udp::bind(addr).map(UdpSocket::from_std)
    |              ^^
dignifiedquire commented 1 year ago

Currently iroh is not compatible with wasm building. There are multiple dependencies (like quinn) and internal code that need to first change to support it.

amiyatulu commented 1 year ago

Quinn recommends WebTransport for browser WebAssembly environment.

dpc commented 4 months ago

Quinn recommends WebTransport for browser WebAssembly environment.

Last comment in that thread says:

There are now implementations of WebTransport that use Quinn, e.g. https://github.com/kixelated/webtransport-rs. Quinn is a QUIC implementation, and WebTransport is built on top of (HTTP/3 which is built on top of) QUIC.

And https://developer.chrome.com/docs/capabilities/web-apis/webtransport indicates that all major browsers other than Safari support it now.

So ... how more or less one would go about it?

Voronar commented 4 months ago

Does WebTransport allow a browser side be a server part of the WebTransport protocol? If no, then how iroh would work in the browser environment? As I know iroh node is a "client" and a "server" at the same time. I suppose it will work only as a client. In theory WebRTC may help, but in that case non-browser iroh node should support 2 communication protocols at the same time QUIC and WebRTC, that is problematic.

matheus23 commented 4 months ago

We have a plan for getting iroh to

  1. compile to wasm and
  2. work in the browser via wasm_bindgen.

But for the first iteration - that will require that the browser node is permanently connected to an iroh relay node & forwarding traffic over that.

IIUC (I'm fairly new to the project), @Voronar is spot on. Our current plan is websockets + relay, and later potentially trying WebRTC data channels for peer-to-peer connections. Some of us have looked at WebTransport and found that it probably won't work.

amiyatulu commented 4 months ago

As I know iroh node is a "client" and a "server" at the same time

How does webtorrent works? Is it not client and server at the same time?

amiyatulu commented 4 months ago

Also wasm doesn't mean only for browser environment, Iroh need to also support edge serverless computing like wasmedge, spin or everywhere computer

DougAnderson444 commented 3 months ago

work in the browser via wasm_bindgen.

We did this with rust-libp2p and it works pretty well.

I'm here because I stumbled upon Willow which is apparently partially implemented in iroh which is cool.

Ideally I'd use the iroh willow portions but most of my current connecting and networking is built in libp2p over webRTC though, as I want the ability to connect the browser to "the node", whatever the node shall be.

On the server side you might consider str0m for WebRTC as it's sans-io, though less mature than webrtc-rs it may be easier to work with in the long run.

One last random point that I'll note on wasm is that we will eventually be moving toward WebAssembly Component Model which uses wasm interface types (WIT) which is what spin and everywhere comp are built upon. It's still early (v0.2.0) but it might be worthwhile to look down the road at what Wasm is going to look like in a year or two and design around that.

matheus23 commented 1 month ago

Closing in favor of a unified issue: https://github.com/n0-computer/iroh/issues/2799