mirror of
https://github.com/fluencelabs/js-libp2p-interfaces
synced 2025-04-24 17:52:21 +00:00
add API description
This commit is contained in:
parent
a0208f5908
commit
587e550197
26
README.md
26
README.md
@ -19,6 +19,8 @@ Send a PR to add a new one if you happen to find or write one.
|
|||||||
|
|
||||||
# Badge
|
# Badge
|
||||||
|
|
||||||
|
Include this badge in your readme if you make a new module that uses abstract-stream-muxer API.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
# How to use
|
# How to use
|
||||||
@ -30,17 +32,31 @@ A valid (read: that follows this abstraction) stream muxer, must implement the f
|
|||||||
|
|
||||||
### Attach muxer to a transport
|
### Attach muxer to a transport
|
||||||
|
|
||||||
- `Node.js` muxer.attach(transport, function (err, conn))
|
- `Node.js` muxer.attach(transport, function (err, conn))
|
||||||
- `Go` conn, err := muxer.attach(transport)
|
- `Go` conn, err := muxer.Attach(transport)
|
||||||
|
|
||||||
|
This method attaches our stream muxer to the desired transport (UDP, TCP) and returns/callbacks with the `err, conn`(error, connection).
|
||||||
|
|
||||||
|
If `err` is passed, no operation should be made in `conn`.
|
||||||
|
|
||||||
|
`conn` abstracts our established Connection with the other endpoint, it must offer an interface to open a stream inside this connection and to receive incomming stream requests.
|
||||||
|
|
||||||
### Dial(open/create) a new stream
|
### Dial(open/create) a new stream
|
||||||
|
|
||||||
- `Node.js` conn.dialStream(function (err, stream))
|
- `Node.js` conn.dialStream(function (err, stream))
|
||||||
- `Go` stream, err := conn.dialStream()
|
- `Go` stream, err := conn.DialStream()
|
||||||
|
|
||||||
|
This method negotiates and opens a new stream with the other endpoint.
|
||||||
|
|
||||||
### Listen(wait/receive) a new incoming stream
|
If `err` is passed, no operation should be made in `stream`.
|
||||||
|
|
||||||
|
`stream` abstract our established Stream with the other endpoint, it must implement the [Duplex Stream interface](https://nodejs.org/api/stream.html#stream_class_stream_duplex) in Node.js or the [ReadWriteCloser](http://golang.org/pkg/io/#ReadWriteCloser) in Go.
|
||||||
|
|
||||||
|
### Listen(wait/accept) a new incoming stream
|
||||||
|
|
||||||
- `Node.js` conn.on('stream', function (stream))
|
- `Node.js` conn.on('stream', function (stream))
|
||||||
- `Go` stream := conn.listen()
|
- `Go` stream := conn.Accept()
|
||||||
|
|
||||||
|
Each time a dialing peer initiates the new stream handshake, a new stream is created on the listening side.
|
||||||
|
|
||||||
|
In Node.js, the Event Emitter pattern is expected to be used in order to receive new incoming streams, while in Go, it expects to wait when Accept is called.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user