-
Notifications
You must be signed in to change notification settings - Fork 976
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
Add an example of rust-libp2p running in the browser #23
Comments
This is somewhat an objective. You're more experienced with the WASM side of things than I am, but I'd imagine all our generic future-based stuff would work, while tokio/mio/specific transports would not. We would need JS glue for hooking into the event loop, WS, WebRTC transports from there, along with Rust libraries meant to interface with that JS glue. Datastore could be useful as well. Plugging that into the light client code would be pretty straightforward then, and we could have a light client running in the chrome extension from that point. |
You can run libp2p in the browser today by using the JavaScript implementation https://github.com/libp2p/js-libp2p You can find an example here https://github.com/libp2p/js-libp2p/tree/master/examples/libp2p-in-the-browser |
It is now possible to open a websocket listener from the browser by compiling for emscripten. Things still to be done:
|
This is done.
This is not going to happen anytime soon. |
Futures supports stdweb (since version 0.2), which in turn supports Regarding
I very much agree with brian smith, that getting WebCrypto into Ring will be a challenge, already because ring is synchronous, while WebCrypto returns promises. I think the better approach would be to refactor libp2p to use Edit: that might also turn out to be non-trivial, as |
Nothing in the Rust ecosystem supports futures 0.2, so that's no-no. However it's possible to use futures 0.1 as well. We just need some manual glueing. |
See also openethereum/parity-ethereum#7915 |
Once #900 is done, it should be trivial to write an example. |
@tomaka are there any other blockers? |
No, libp2p is running just fine from within a browser, provided you use wasm-pack. The last thing to do would be add an example that is tested on CI, so that we don't accidentally break it. |
i would love to see an example of this :D |
Hello! I'd like to take up this issue. I haven't thought of any specific example yet (any ideas/suggestions welcome). I'll figure it out in a few days. |
A chat with the recently added Gossipsub protocol? That's what I'll try soon for my project so you'll be saving me some work 😅 |
To give some hints:
|
@tomaka, what do you mean by "non-desktop" in the previous comment? Do you mean "non-browser", i.e, a node/peer running on a terminal and not in a browser? |
BTW |
Allow application layer to update its enr attestation bitfield
@tomaka I've had a minimum working example of this done a few weeks back. It was based off of the way substrate's browser light node uses the libp2p library. Repo Link. I'd be happy to make a PR if I could get some guidance on how the example should be setup. The linked repo is using vue as the front end but I'd imagine that a plain HTML version would be better for upstream. |
@dt665m I would definitely appreciate a browser example! I think a simple plain HTML example would be good, or maybe using Vue would even be fine, if you just used the UMD build of Vue from a CDN so it doesn't require any Webpack setup or anything. There's a super-remote chance I could help if you needed review or other input. I'm really wanting to understand if it's possible to effectively use Rust and libp2p in the Browser and it looks like the answer is yes! |
After looking around a bit, it looks like you need a signaling server like a webrtc star server to actually find peers and listen on a websocket, because Browsers can't listen on websockets. I'm not exactly sure what that looks like, but it also looks like I can't get I'm a little confused, but would appreciate help figuring this out if anybody has any ideas. 😃 I'm wanting to experiment with something like @olanod mentioned: a peer-to-peer chat built on |
@zicklag should be possible by using the websocket server as a relay. I'm not too familiar this is supported in the Rust side, but I'd assume so. There's a separate issue open regarding webrtc, but websockets should work (although like you mentioned, the browser won't be able to actually listen natively). |
transports/quic: Muxer and Connection
I am closing here in favor of #2617. |
With asmjs and/or wasm.
Is that an objective as well? It should be easy to achieve.
The text was updated successfully, but these errors were encountered: