From 03cc2c28fb1e54148cc953d785607065d48cad6f Mon Sep 17 00:00:00 2001 From: David Dias Date: Sun, 27 Sep 2015 00:14:40 +0100 Subject: [PATCH] Initial version, readme docs, expectations, and so on --- README.md | 18 ++++++++++++------ src/index.js | 18 ++++++++++++++++++ 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 815c97e3..fa2bf2b4 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/index.js b/src/index.js index e69de29b..7f704ef8 100644 --- a/src/index.js +++ b/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 +}