2015-10-28 21:59:15 +00:00
js-libp2p
=========
2015-08-25 11:00:19 +01:00
2016-09-02 15:22:28 -04:00

[](http://ipn.io)
[[](http://webchat.freenode.net/?channels=%23ipfs)
[](https://travis-ci.org/diasdavid/js-libp2p)

[](https://david-dm.org/diasdavid/js-libp2p)
[](https://github.com/feross/standard)
2015-08-25 11:00:19 +01:00
2015-11-18 16:28:20 +00:00
> JavaScript implementation of libp2p
2016-09-02 15:22:28 -04:00
libp2p is a networking stack and library modularized out of The IPFS Project, and bundled separately for other tools to use.
2015-11-18 16:28:20 +00:00
2016-09-02 15:22:28 -04:00
## Table of Contents
2015-11-18 16:28:20 +00:00
2016-09-02 15:22:28 -04:00
- [Background ](#background )
- [Packages ](#packages )
- [Notes ](#notes )
- [Install ](#install )
- [Usage ](#usage )
- [Setting everything up ](#setting-everything-up )
- [Dialing and listening ](#dialing-and-listening )
- [Using Peer Routing ](#using-peer-routing )
- [Using Records ](#using-records )
- [Stats ](#stats )
- [Contribute ](#contribute )
- [License ](#license )
## Background
2015-11-18 16:28:20 +00:00
libp2p is the product of a long, and arduous quest of understanding -- a deep dive into the internet's network stack, and plentiful peer-to-peer protocols from the past. Building large scale peer-to-peer systems has been complex and difficult in the last 15 years, and libp2p is a way to fix that. It is a "network stack" -- a protocol suite -- that cleanly separates concerns, and enables sophisticated applications to only use the protocols they absolutely need, without giving up interoperability and upgradeability. libp2p grew out of IPFS, but it is built so that lots of people can use it, for lots of different projects.
We will be writing a set of docs, posts, tutorials, and talks to explain what p2p is, why it is tremendously useful, and how it can help your existing and new projects.
2016-09-02 15:22:28 -04:00
### Packages
2015-11-18 16:28:20 +00:00
2016-08-01 15:40:47 +02:00
| Package | Version | Dependencies | DevDependencies |
|--------|-------|------------|----------|
| [`peer-book` ](//github.com/libp2p/js-peer-book ) | [](//github.com/libp2p/js-peer-book/releases) | [](https://david-dm.org/libp2p/js-peer-book) | [](https://david-dm.org/libp2p/js-peer-book?type=dev) |
| [`libp2p-ipfs` ](//github.com/ipfs/js-libp2p-ipfs ) | [](//github.com/ipfs/js-libp2p-ipfs/releases) | [](https://david-dm.org/ipfs/js-libp2p-ipfs) | [](https://david-dm.org/ipfs/js-libp2p-ipfs?type=dev) |
| [`libp2p-ipfs-browser` ](//github.com/ipfs/js-libp2p-ipfs-browser ) | [](//github.com/ipfs/js-libp2p-ipfs-browser/releases) | [](https://david-dm.org/ipfs/js-libp2p-ipfs-browser) | [](https://david-dm.org/ipfs/js-libp2p-ipfs-browser?type=dev) |
| [`libp2p-secio` ](//github.com/libp2p/js-libp2p-secio ) | [](//github.com/libp2p/js-libp2p-secio/releases) | [](https://david-dm.org/libp2p/js-libp2p-secio) | [](https://david-dm.org/libp2p/js-libp2p-secio?type=dev) |
| [`libp2p-swarm` ](//github.com/diasdavid/js-libp2p-swarm ) | [](//github.com/diasdavid/js-libp2p-swarm/releases) | [](https://david-dm.org/diasdavid/js-libp2p-swarm) | [](https://david-dm.org/diasdavid/js-libp2p-swarm?type=dev) |
| [`libp2p-ping` ](//github.com/diasdavid/js-libp2p-ping ) | [](//github.com/diasdavid/js-libp2p-ping/releases) | [](https://david-dm.org/diasdavid/js-libp2p-ping) | [](https://david-dm.org/diasdavid/js-libp2p-ping?type=dev) |
| [`interface-connection` ](//github.com/diasdavid/interface-connection ) | [](//github.com/diasdavid/interface-connection/releases) | [](https://david-dm.org/diasdavid/interface-connection) | [](https://david-dm.org/diasdavid/interface-connection?type=dev) |
| [`libp2p-utp` ](//github.com/diasdavid/js-libp2p-utp ) | [](//github.com/diasdavid/js-libp2p-utp/releases) | [](https://david-dm.org/diasdavid/js-libp2p-utp) | [](https://david-dm.org/diasdavid/js-libp2p-utp?type=dev) |
| [`interface-stream-muxer` ](//github.com/diasdavid/interface-stream-muxer ) | [](//github.com/diasdavid/interface-stream-muxer/releases) | [](https://david-dm.org/diasdavid/interface-stream-muxer) | [](https://david-dm.org/diasdavid/interface-stream-muxer?type=dev) |
| [`libp2p-spdy` ](//github.com/diasdavid/js-libp2p-spdy ) | [](//github.com/diasdavid/js-libp2p-spdy/releases) | [](https://david-dm.org/diasdavid/js-libp2p-spdy) | [](https://david-dm.org/diasdavid/js-libp2p-spdy?type=dev) |
| [`libp2p-kad-routing` ](//github.com/diasdavid/js-libp2p-kad-routing ) | [](//github.com/diasdavid/js-libp2p-kad-routing/releases) | [](https://david-dm.org/diasdavid/js-libp2p-kad-routing) | [](https://david-dm.org/diasdavid/js-libp2p-kad-routing?type=dev) |
| [`libp2p-mdns-discovery` ](//github.com/diasdavid/js-libp2p-mdns-discovery ) | [](//github.com/diasdavid/js-libp2p-mdns-discovery/releases) | [](https://david-dm.org/diasdavid/js-libp2p-mdns-discovery) | [](https://david-dm.org/diasdavid/js-libp2p-mdns-discovery?type=dev) |
| [`libp2p-railing` ](//github.com/diasdavid/js-libp2p-railing ) | [](//github.com/diasdavid/js-libp2p-railing/releases) | [](https://david-dm.org/diasdavid/js-libp2p-railing) | [](https://david-dm.org/diasdavid/js-libp2p-railing?type=dev) |
| [`libp2p-record` ](//github.com/diasdavid/js-libp2p-record ) | [](//github.com/diasdavid/js-libp2p-record/releases) | [](https://david-dm.org/diasdavid/js-libp2p-record) | [](https://david-dm.org/diasdavid/js-libp2p-record?type=dev) |
| [`interface-record-store` ](//github.com/diasdavid/interface-record-store ) | [](//github.com/diasdavid/interface-record-store/releases) | [](https://david-dm.org/diasdavid/interface-record-store) | [](https://david-dm.org/diasdavid/interface-record-store?type=dev) |
| [`libp2p-distributed-record-store` ](//github.com/diasdavid/js-libp2p-distributed-record-store ) | [](//github.com/diasdavid/js-libp2p-distributed-record-store/releases) | [](https://david-dm.org/diasdavid/js-libp2p-distributed-record-store) | [](https://david-dm.org/diasdavid/js-libp2p-distributed-record-store?type=dev) |
| [`libp2p-kad-record-store` ](//github.com/diasdavid/js-libp2p-kad-record-store ) | [](//github.com/diasdavid/js-libp2p-kad-record-store/releases) | [](https://david-dm.org/diasdavid/js-libp2p-kad-record-store) | [](https://david-dm.org/diasdavid/js-libp2p-kad-record-store?type=dev) |
| [`libp2p-websockets` ](//github.com/diasdavid/js-libp2p-websockets ) | [](//github.com/diasdavid/js-libp2p-websockets/releases) | [](https://david-dm.org/diasdavid/js-libp2p-websockets) | [](https://david-dm.org/diasdavid/js-libp2p-websockets?type=dev) |
| [`libp2p-webrtc-star` ](//github.com/libp2p/js-libp2p-webrtc-star ) | [](//github.com/libp2p/js-libp2p-webrtc-star/releases) | [](https://david-dm.org/libp2p/js-libp2p-webrtc-star) | [](https://david-dm.org/libp2p/js-libp2p-webrtc-star?type=dev) |
| [`multistream-select` ](//github.com/diasdavid/js-multistream ) | [](//github.com/diasdavid/js-multistream/releases) | [](https://david-dm.org/diasdavid/js-multistream) | [](https://david-dm.org/diasdavid/js-multistream?type=dev) |
2015-11-18 16:28:20 +00:00
2016-09-02 15:22:28 -04:00
### Notes
Img for ref (till we get a better graph)

## Install
2015-09-20 16:18:34 +01:00
2016-09-02 15:22:28 -04:00
```sh
npm i --save libp2p
```
## Usage
2015-09-20 16:18:34 +01:00
2016-09-02 15:22:28 -04:00
> **This is a work in progress. The interface might change at anytime.**
2015-09-20 16:18:34 +01:00
libp2p expects a [Record Store interface ](https://github.com/diasdavid/abstract-record-store ), a swarm and one or more Peer Routers that implement the [Peer Routing ](https://github.com/diasdavid/abstract-peer-routing ), the goal is to keep simplicity and plugability while the remaining modules execute the heavy lifting.
2015-09-27 00:14:40 +01:00
libp2p becomes very simple and basically acts as a glue for every module that compose this library. Since it can be highly customized, it requires some setup. What we recommend is to have a libp2p build for the system you are developing taking into account in your needs (e.g. for a browser working version of libp2p that acts as the network layer of IPFS, we have a built and minified version that browsers can require)
2015-09-20 16:18:34 +01:00
### Setting everything up
2016-09-02 15:22:28 -04:00
```js
2015-09-27 00:14:40 +01:00
var Libp2p = require('libp2p')
// set up a Swarm, Peer Routing and Record Store instances, the last two are optional
var p2p = new Libp2p(swarm, [peerRouting, recordStore])
2015-09-20 16:18:34 +01:00
```
### Dialing and listening
2016-09-02 15:22:28 -04:00
```js
2015-09-27 00:14:40 +01:00
p2p.swarm.dial(peerInfo, options, protocol, function (err, stream) {})
p2p.swarm.handleProtocol(protocol, options, handlerFunction)
2016-09-02 15:22:28 -04:00
```
2015-09-20 16:18:34 +01:00
### Using Peer Routing
2016-09-02 15:22:28 -04:00
```js
2015-09-27 00:14:40 +01:00
p2p.routing.findPeers(key, function (err, peerInfos) {})
2016-09-02 15:22:28 -04:00
```
2015-09-20 16:18:34 +01:00
### Using Records
2016-09-02 15:22:28 -04:00
```js
2015-09-27 00:14:40 +01:00
p2p.record.get(key, function (err, records) {})
p2p.record.store(key, record)
2016-09-02 15:22:28 -04:00
```
2015-09-20 16:18:34 +01:00
### Stats
2016-09-02 15:22:28 -04:00
TODO
2016-08-01 15:40:47 +02:00
2016-09-02 15:22:28 -04:00
## Contribute
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:
2016-08-01 15:40:47 +02:00
- Go through the modules below and **check out existing issues** . This would be especially useful for modules in active development. Some knowledge of IPFS/libp2p may be required, as well as the infrasture behind it - for instance, you may need to read up on p2p and more complex operations like muxing to be able to help technically.
- **Perform code reviews**. Most of this has been developed by @diasdavid , which means that more eyes will help a) speed the project along b) ensure quality and c) reduce possible future bugs.
- **Add tests**. There can never be enough tests.
2015-09-20 16:18:34 +01:00
2016-09-02 15:22:28 -04:00
## License
2015-09-20 16:18:34 +01:00
2016-09-02 15:22:28 -04:00
[MIT ](LICENSE ) © David Dias