Skip to content

Commit

Permalink
fix: resolve inconsistency with peerInfo and peerId usage
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Jacob Heun <jacobheun@gmail.com>
  • Loading branch information
jacobheun authored and daviddias committed Aug 22, 2018
1 parent d3924c1 commit dd4d8c3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
16 changes: 8 additions & 8 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,21 @@ 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<Multiaddr>} [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<Multiaddr>} [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)
this.dht = dht(this.api)
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))
}

Expand Down Expand Up @@ -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([
Expand Down

0 comments on commit dd4d8c3

Please sign in to comment.