iroh icon indicating copy to clipboard operation
iroh copied to clipboard

Build Web Assemply

Open DAOCUONG opened this issue 2 years ago • 7 comments

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)
    |              ^^

DAOCUONG avatar Nov 12 '23 03:11 DAOCUONG

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.

dignifiedquire avatar Nov 12 '23 12:11 dignifiedquire

Quinn recommends WebTransport for browser WebAssembly environment.

silicology1 avatar Nov 13 '23 04:11 silicology1

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?

dpc avatar Jun 26 '24 05:06 dpc

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.

Voronar avatar Jun 26 '24 09:06 Voronar

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.

matheus23 avatar Jun 26 '24 10:06 matheus23

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?

silicology1 avatar Jul 01 '24 20:07 silicology1

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

silicology1 avatar Jul 01 '24 21:07 silicology1

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.

DougAnderson444 avatar Jul 23 '24 20:07 DougAnderson444

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

matheus23 avatar Oct 10 '24 09:10 matheus23