Compare commits

...

5 Commits

Author SHA1 Message Date
c007c4cdd0 Release v0.1.1. 2015-10-28 22:00:28 +00:00
dd4db33c03 Merge pull request #2 from diasdavid/rn
update README and package.json
2015-10-28 21:59:40 +00:00
640cea2252 update README and package.json 2015-10-28 21:59:15 +00:00
51631eae5e Release v0.1.0. 2015-09-27 00:15:04 +01:00
03cc2c28fb Initial version, readme docs, expectations, and so on 2015-09-27 00:14:40 +01:00
3 changed files with 37 additions and 13 deletions

View File

@ -1,7 +1,7 @@
node-libp2p
===========
js-libp2p
=========
[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io) [[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs) ![Build Status](https://travis-ci.org/diasdavid/node-libp2p.svg?style=flat-square)](https://travis-ci.org/diasdavid/node-libp2p) ![](https://img.shields.io/badge/coverage-%3F-yellow.svg?style=flat-square) [![Dependency Status](https://david-dm.org/diasdavid/node-libp2p.svg?style=flat-square)](https://david-dm.org/diasdavid/node-libp2p) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)
[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io) [[![](https://img.shields.io/badge/freejs-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs) ![Build Status](https://travis-ci.org/diasdavid/js-libp2p.svg?style=flat-square)](https://travis-ci.org/diasdavid/js-libp2p) ![](https://img.shields.io/badge/coverage-%3F-yellow.svg?style=flat-square) [![Dependency Status](https://david-dm.org/diasdavid/js-libp2p.svg?style=flat-square)](https://david-dm.org/diasdavid/js-libp2p) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)
> Node.js implementation of libp2p
@ -11,25 +11,31 @@ node-libp2p
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.
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)
### Setting everything up
```
var libp2p = require('libp2p')
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])
```
### Dialing and listening
libp2p.swarm.dialStream(peerInfo, protocol, options, function (err, stream) {})
libp2p.swarm.handleProtocol(protocol, options, handlerFunction)
p2p.swarm.dial(peerInfo, options, protocol, function (err, stream) {})
p2p.swarm.handleProtocol(protocol, options, handlerFunction)
### Using Peer Routing
libp2p.routing.findPeers(key, function (err, peerInfos) {})
p2p.routing.findPeers(key, function (err, peerInfos) {})
### Using Records
libp2p.record.get(key, function (err, records) {})
libp2p.record.store(key, record)
p2p.record.get(key, function (err, records) {})
p2p.record.store(key, record)
### Stats

View File

@ -1,6 +1,6 @@
{
"name": "libp2p",
"version": "0.0.1",
"version": "0.1.1",
"description": "Node.js implementation of libp2p",
"main": "src/index.js",
"scripts": {
@ -8,7 +8,7 @@
},
"repository": {
"type": "git",
"url": "https://github.com/diasdavid/node-libp2p.git"
"url": "https://github.com/diasdavid/js-libp2p.git"
},
"keywords": [
"IPFS"
@ -20,9 +20,9 @@
"author": "David Dias <daviddias@ipfs.io>",
"license": "MIT",
"bugs": {
"url": "https://github.com/diasdavid/node-libp2p/issues"
"url": "https://github.com/diasdavid/js-libp2p/issues"
},
"homepage": "https://github.com/diasdavid/node-libp2p",
"homepage": "https://github.com/diasdavid/js-libp2p",
"devDependencies": {
"code": "^1.5.0",
"lab": "^5.17.0",

View File

@ -0,0 +1,18 @@
exports = module.exports = Libp2p
function Libp2p (swarm, peerRouting, recordStore) {
var self = this
if (!(self instanceof Libp2p)) {
throw new Error('Must be called with new')
}
if (!swarm) {
throw new Error('a swarm must be passed')
}
self.swarm = swarm
self.routing = peerRouting
self.record = recordStore
}