mirror of
https://github.com/fluencelabs/js-libp2p-tcp
synced 2025-04-25 01:42:20 +00:00
docs: update and polish
This commit is contained in:
parent
de1d7fe75c
commit
3b7e68bc8a
46
README.md
46
README.md
@ -9,23 +9,17 @@
|
||||

|
||||

|
||||
|
||||

|
||||

|
||||
[](https://github.com/libp2p/interface-transport)
|
||||
[](https://github.com/libp2p/interface-connection)
|
||||
|
||||
> Node.js implementation of the TCP module that libp2p uses, which implements the [interface-connection](https://github.com/libp2p/interface-connection) interface for dial/listen.
|
||||
|
||||
`libp2p-tcp` in Node.js is a very thin shim that adds support for dialing to a `multiaddr`. This small shim will enable libp2p to use other different transports.
|
||||
|
||||
**Note:** This module uses [pull-streams](https://pull-stream.github.io) for all stream based interfaces.
|
||||
> JavaScript implementation of the TCP module for libp2p. It exposes the [interface-transport](https://github.com/libp2p/interface-connection) for dial/listen. `libp2p-tcp` is a very thin shim that adds support for dialing to a `multiaddr`. This small shim will enable libp2p to use other different transports.
|
||||
|
||||
## Table of Contents
|
||||
|
||||
- [Install](#install)
|
||||
- [npm](#npm)
|
||||
- [Usage](#usage)
|
||||
- [Example](#example)
|
||||
- [This module uses `pull-streams`](#this-module-uses-pull-streams)
|
||||
- [Converting `pull-streams` to Node.js Streams](#converting-pull-streams-to-nodejs-streams)
|
||||
- [API](#api)
|
||||
- [Contribute](#contribute)
|
||||
- [License](#license)
|
||||
@ -35,13 +29,11 @@
|
||||
### npm
|
||||
|
||||
```sh
|
||||
> npm i libp2p-tcp
|
||||
> npm install libp2p-tcp
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
### Example
|
||||
|
||||
```js
|
||||
const TCP = require('libp2p-tcp')
|
||||
const multiaddr = require('multiaddr')
|
||||
@ -81,32 +73,10 @@ new connection opened
|
||||
hello
|
||||
```
|
||||
|
||||
### This module uses `pull-streams`
|
||||
|
||||
We expose a streaming interface based on `pull-streams`, rather then 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](https://github.com/ipfs/js-ipfs/issues/362).
|
||||
|
||||
You can learn more about pull-streams at:
|
||||
|
||||
- [The history of Node.js streams, nodebp April 2014](https://www.youtube.com/watch?v=g5ewQEuXjsQ)
|
||||
- [The history of streams, 2016](http://dominictarr.com/post/145135293917/history-of-streams)
|
||||
- [pull-streams, the simple streaming primitive](http://dominictarr.com/post/149248845122/pull-streams-pull-streams-are-a-very-simple)
|
||||
- [pull-streams documentation](https://pull-stream.github.io/)
|
||||
|
||||
#### Converting `pull-streams` to Node.js Streams
|
||||
|
||||
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`](https://github.com/dominictarr/pull-stream-to-stream), giving you an instance of a Node.js stream that is linked to the pull-stream. For example:
|
||||
|
||||
```js
|
||||
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.
|
||||
|
||||
## API
|
||||
|
||||
### Transport
|
||||
|
||||
[](https://github.com/libp2p/interface-transport)
|
||||
|
||||
`libp2p-tcp` accepts TCP addresses both IPFS and non IPFS encapsulated addresses, i.e:
|
||||
@ -116,6 +86,10 @@ To learn more about this utility, visit https://pull-stream.github.io/#pull-stre
|
||||
|
||||
Both for dialing and listening.
|
||||
|
||||
### Connection
|
||||
|
||||
[](https://github.com/libp2p/interface-connection)
|
||||
|
||||
## Contribute
|
||||
|
||||
Contributions are welcome! The libp2p implementation in JavaScript is a work in progress. As such, there's a few things you can do right now to help out:
|
||||
|
Loading…
x
Reference in New Issue
Block a user