mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-07-09 13:51:34 +00:00
Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
c007c4cdd0 | |||
dd4db33c03 | |||
640cea2252 | |||
51631eae5e | |||
03cc2c28fb |
24
README.md
24
README.md
@ -1,7 +1,7 @@
|
||||
node-libp2p
|
||||
===========
|
||||
js-libp2p
|
||||
=========
|
||||
|
||||
[](http://ipn.io) [[](http://webchat.freenode.net/?channels=%23ipfs) ](https://travis-ci.org/diasdavid/node-libp2p)  [](https://david-dm.org/diasdavid/node-libp2p) [](https://github.com/feross/standard)
|
||||
[](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)
|
||||
|
||||
> 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
|
||||
|
||||
|
@ -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",
|
||||
|
18
src/index.js
18
src/index.js
@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user