js-libp2p icon indicating copy to clipboard operation
js-libp2p copied to clipboard

[feature request] Yamux support

Open nazar-pc opened this issue 3 years ago • 14 comments

Since there is no placeholder repository and no corresponding issue in this repo yet, I decided to create one here.

There is Yamux implementation in TypeScript at https://github.com/th-ch/yamux-js, it must be possible to create js-libp2p-yamux on top of it and make Yamux the go to implementation across Go/Rust/JS.

I don't have time and experience to do it right now, but if no one takes it, I might eventually write js-libp2p-yamux myself.

nazar-pc avatar Feb 03 '22 20:02 nazar-pc

@lidel I would love to take this if we make it priority^^

mpetrunic avatar Feb 09 '22 13:02 mpetrunic

Maintainer of go-libp2p here 👋

This would be super valuable for the entire libp2p ecosystem. mplex is a terrible muxer, yet we've been keeping support for it, just because JS didn't have support for any other muxer.

Do we have any data on how spec-compliant / reliable https://github.com/th-ch/yamux-js is? The repo doesn't have many stars or users, so there might be some bugs lurking in the code. We might need to be prepared to submit a few fixes to that repo.

marten-seemann avatar Mar 03 '22 05:03 marten-seemann

I think https://github.com/th-ch/yamux-js is a good start, but honestly, I would rather fork it, convert it to use Uint8Array (instead of Buffer) to be in line with the rest of js-libp2p (and for the smaller bundle in browser) and export js-libp2p compliant muxer interface.

@BigLep Since there is quite some work on #1166 should I pause this and focus on this issue instead? Seems like this is a lot more straightforward and higher priority.

mpetrunic avatar Mar 03 '22 09:03 mpetrunic

@mpetrunic : thanks for raising. I started a public Discord thread on priorities here with my thoughts: https://discord.com/channels/806902334369824788/949091153247084605/949091166694027294 . We can also discuss more tomorrow during js-libp2p triage.

BigLep avatar Mar 03 '22 23:03 BigLep

Triage note:

  • done: researched https://github.com/th-ch/yamux-js - identified gaps around working with streams
  • next: implementing gaps + migrating forked yamux-js to async/iter

lidel avatar Mar 11 '22 15:03 lidel

This work is happening in https://github.com/ChainSafe/js-libp2p-yamux

BigLep avatar May 03 '22 15:05 BigLep

2022-05-03 conversation: for testing this work against a go-libp2p implementation, it would be easiest if https://github.com/libp2p/go-libp2p-daemon/issues/266 was handled.

BigLep avatar May 03 '22 18:05 BigLep

@wemeetagain : I know it's been discussed at js-libp2p triage, but since various folks are watching this issue, can you provide an update on how this is going? Is there any milestones or checkpoints here or a sense of timing? Thanks.

BigLep avatar May 31 '22 04:05 BigLep

I've been busy with many competing priorities, I'm sorry.

I've pushed the latest progress here: https://github.com/ChainSafe/js-libp2p-yamux

I'd estimate its ~30% complete. The following is implemented:

  • basic scaffolding of the muxer, management of streams
  • frame decoding pipeline
  • frame type handling
  • stream closing / reseting

I'm working towards passing compliance tests, which would be a minimally working muxer that allows creation/deletion of streams and sending/receiving data within them. Then after, adding handling of window updates.

I'll continue to work on this, I should have 8+hrs to contribute this week. But if this becomes a critical blocker, feel free to PR to the repo or fork and continue forward. I'll happily merge additions and merge forks back into this repo and continue from there.

wemeetagain avatar May 31 '22 15:05 wemeetagain

It's now passing the js-libp2p stream-muxer compliance tests.

I'll now be working on handling of window updates and additional features for parity with go-libp2p's implementation.

wemeetagain avatar Jun 02 '22 20:06 wemeetagain

2022-06-07 conversation:

Done criteria:

  1. Implement the spec
  2. Interop test with go
  3. Certain features of go implementation (per muxer: limits on number of streams, number of in-progress incoming streams, number of in-progress outgoing stream)

@wemeetagain will create a PR for the implementation and then followup with the interop tests and resource limiting.

BigLep avatar Jun 07 '22 15:06 BigLep

Draft PR open here: https://github.com/ChainSafe/js-libp2p-yamux/pull/2

wemeetagain avatar Jun 07 '22 16:06 wemeetagain

libp2p interop PR: https://github.com/libp2p/js-libp2p/pull/1290

BigLep avatar Jul 19 '22 15:07 BigLep

Related mplex change: https://github.com/libp2p/js-libp2p-mplex/pull/192

BigLep avatar Jul 19 '22 15:07 BigLep