From dd4d8c3483a9ec8d6480a14b0a1b53e18b4f77a5 Mon Sep 17 00:00:00 2001 From: Jacob Heun Date: Mon, 20 Aug 2018 16:01:00 +0200 Subject: [PATCH] fix: resolve inconsistency with peerInfo and peerId usage License: MIT Signed-off-by: Jacob Heun --- README.md | 9 +++++++-- src/index.js | 16 ++++++++-------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index dc1b604..d6997fb 100644 --- a/README.md +++ b/README.md @@ -8,11 +8,16 @@ Leverage other peers in the network to perform Content Routing calls. ## Example -``` +```js const DelegatedContentRouting = require('libp2p-delegated-content-routing') // default is to use ipfs.io -const routing = new DelegatedContentRouing() +const routing = new DelegatedContentRouing(peerId, { + // use default api settings + protocol: 'https', + port: 443, + host: 'ipfs.io' +}) routing.findProviders(key, (err, peerInfos) => { if (err) { diff --git a/src/index.js b/src/index.js index 83a71b0..f669b63 100644 --- a/src/index.js +++ b/src/index.js @@ -34,13 +34,13 @@ class DelegatedContentRouting { /** * Create a new DelegatedContentRouting instance. * - * @param {PeerInfo} peerInfo - the node that is using this routing. - * @param {object} [api] - the api endpoint of the delegated node to use. - * @param {Array} [bootstrappers] - list of bootstrapper nodes we are connected to. + * @param {PeerID} peerId - the id of the node that is using this routing. + * @param {object} [api] - (Optional) the api endpoint of the delegated node to use. + * @param {Array} [bootstrappers] - (Optional) list of bootstrapper nodes we are connected to. */ - constructor (peerInfo, api, bootstrappers) { - if (peerInfo == null) { - throw new Error('missing self peerInfo') + constructor (peerId, api, bootstrappers) { + if (peerId == null) { + throw new Error('missing self peerId') } this.api = Object.assign({}, defaultConfig(), DEFAULT_IPFS_API, api) @@ -48,7 +48,7 @@ class DelegatedContentRouting { this.swarm = swarm(this.api) this.refs = refs(this.api) - this.peerInfo = peerInfo + this.peerId = peerId this.bootstrappers = bootstrappers || DEFAULT_BOOSTRAP_NODES.map((addr) => multiaddr(addr)) } @@ -99,7 +99,7 @@ class DelegatedContentRouting { */ provide (key, callback) { const addrs = this.bootstrappers.map((addr) => { - return addr.encapsulate(`/p2p-circuit/ipfs/${this.peerInfo.id}`) + return addr.encapsulate(`/p2p-circuit/ipfs/${this.peerId.id}`) }) series([