JavaScript implementation of multistream-select.
tl;dr: multistream-select is protocol multiplexing per connection/stream. Full spec here
The caller will send "interactive" messages, expecting for some acknowledgement from the callee, which will "select" the handler for the desired and supported protocol
< /multistream-select/0.3.0 # i speak multistream-select/0.3.0
> /multistream-select/0.3.0 # ok, let's speak multistream-select/0.3.0
> /ipfs-dht/0.2.3 # i want to speak ipfs-dht/0.2.3
< na # ipfs-dht/0.2.3 is not available
> /ipfs-dht/0.1.9 # What about ipfs-dht/0.1.9 ?
< /ipfs-dht/0.1.9 # ok let's speak ipfs-dht/0.1.9 -- in a sense acts as an ACK
> <dht-message>
> <dht-message>
> <dht-message>
This mode also packs a ls
option, so that the callee can list the protocols it currently supports
> npm i multistream-select
const multistream = require('multistream-select')
The code published to npm that gets loaded on require is in fact a ES5 transpiled version with the right shims added. This means that you can require it and use with your favourite bundler without having to adjust asset management process.
const multistream = require('multistream-select')
Loading this module through a script tag will make the MultistreamSelect
obj available in
the global namespace.
<script src="https://unpkg.com/multistream-select/dist/index.min.js"></script>
<!-- OR -->
<script src="https://unpkg.com/multistream-select/dist/index.js"></script>
const multistream = require('multistream-select')
const ms = new multistream.Listener()
// or
const ms = new multistream.Dialer()
// apply the multistream to the conn
ms.handle(conn, callback)
We expose a streaming interface based on pull-streams
, rather than on the Node.js core streams implementation (aka Node.js streams). pull-streams
offers us a better mechanism for error handling and flow control guarantees. If you would like to know more about why we did this, see the discussion at this issue.
You can learn more about pull-streams at:
- The history of Node.js streams, nodebp April 2014
- The history of streams, 2016
- pull-streams, the simple streaming primitive
- pull-streams documentation
If you are a Node.js streams user, you can convert a pull-stream to a Node.js stream using the module pull-stream-to-stream
, giving you an instance of a Node.js stream that is linked to the pull-stream. For example:
const pullToStream = require('pull-stream-to-stream')
const nodeStreamInstance = pullToStream(pullStreamInstance)
// nodeStreamInstance is an instance of a Node.js Stream
To learn more about this utility, visit https://pull-stream.github.io/#pull-stream-to-stream.
https://multiformats.github.io/js-multistream-select/
Captain: @diasdavid.
Contributions welcome. Please check out the issues.
Check out our contributing document for more information on how we work, and about contributing in general. Please be aware that all interactions related to multiformats are subject to the IPFS Code of Conduct.
Small note: If editing the README, please conform to the standard-readme specification.
MIT © 2015 David Dias