Skip to content

Commit

Permalink
chore: remove unused dep and superfluous node
Browse files Browse the repository at this point in the history
  • Loading branch information
achingbrain committed Jul 11, 2019
1 parent 4d00e23 commit 7c7df12
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 45 deletions.
10 changes: 4 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,12 @@
"chai": "^4.2.0",
"cids": "^0.7.1",
"go-ipfs-dep": "~0.4.17",
"ipfsd-ctl": "~0.44.0"
"ipfsd-ctl": "~0.44.0",
"peer-id": "~0.12.2"
},
"dependencies": {
"ipfs": "^0.36.4",
"ipfs-http-client": "^32.0.1",
"multiaddr": "^6.1.0",
"peer-id": "^0.12.2",
"peer-info": "^0.15.1"
"ipfs-http-client": "^33.0.2",
"multiaddr": "^6.1.0"
},
"contributors": [
"David Dias <[email protected]>",
Expand Down
33 changes: 1 addition & 32 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,9 @@
'use strict'

<<<<<<< HEAD
=======
const PeerInfo = require('peer-info')
const PeerID = require('peer-id')
>>>>>>> feat: refactor to use async/await
const dht = require('ipfs-http-client/src/dht')
const swarm = require('ipfs-http-client/src/swarm')
const refs = require('ipfs-http-client/src/files-regular/refs')
const defaultConfig = require('ipfs-http-client/src/utils/default-config')
<<<<<<< HEAD
const series = require('async/series')
const parallel = require('async/parallel')
const reflect = require('async/reflect')
=======
>>>>>>> feat: refactor to use async/await
const multiaddr = require('multiaddr')

const DEFAULT_MAX_TIMEOUT = 30e3 // 30 second default
Expand Down Expand Up @@ -73,19 +62,13 @@ class DelegatedContentRouting {
async * findProviders (key, options = {}) {
options.maxTimeout = options.maxTimeout || DEFAULT_MAX_TIMEOUT

<<<<<<< HEAD
this.dht.findProvs(key.toString(), {
timeout: `${options.maxTimeout}ms` // The api requires specification of the time unit (s/ms)
}, callback)
=======
const results = await this.dht.findProvs(key.toBaseEncodedString(), {
const results = await this.dht.findProvs(key, {
timeout: `${options.maxTimeout}ms` // The api requires specification of the time unit (s/ms)
})

for (let i = 0; i < results.length; i++) {
yield results[i]
}
>>>>>>> feat: refactor to use async/await
}

/**
Expand Down Expand Up @@ -113,27 +96,13 @@ class DelegatedContentRouting {
// only some need to succeed
const success = results.filter((res) => res && res.error == null)

<<<<<<< HEAD
// only some need to succeed
const success = results.filter((res) => res.error == null)
if (success.length === 0) {
return cb(new Error('unable to swarm.connect using p2p-circuit'))
}
cb()
}),
(cb) => {
this.refs(key.toString(), { recursive: true }, cb)
}
], (err) => callback(err))
=======
if (success.length === 0) {
throw new Error('unable to swarm.connect using p2p-circuit')
}

this.refs(key.toBaseEncodedString(), {
recursive: true
})
>>>>>>> feat: refactor to use async/await
}
}

Expand Down
15 changes: 8 additions & 7 deletions test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ describe('DelegatedContentRouting', function () {
let delegateNode
let bootstrapNode
let bootstrapId
let cid

before(async () => {
// Spawn a "Boostrap" node that doesnt connect to anything
Expand All @@ -57,14 +56,9 @@ describe('DelegatedContentRouting', function () {
// Spawn the delegate node and bootstrap the bootstrapper node
const delegate = await spawnNode(bootstrapId.addresses)
delegateNode = delegate.node

// Add a piece of content to the bootstrap node
const content = Buffer.from(`hello-${Math.random()}`)
const res = await bootstrapNode.api.add(content)
cid = new CID(res[0].hash)
})

after(async () => {
after(() => {
return Promise.all([
selfNode.stop(),
delegateNode.stop(),
Expand Down Expand Up @@ -115,6 +109,13 @@ describe('DelegatedContentRouting', function () {
})

describe('findProviders', () => {
const cid = new CID('QmS4ustL54uo8FzR9455qaxZwuMiUhyvMcX9Ba8nUH4uVv')

before('register providers', async () => {
await bootstrapNode.api.dht.provide(cid)
await selfNode.api.dht.provide(cid)
})

it('should be able to find providers through the delegate node', async () => {
const opts = delegateNode.apiAddr.toOptions()
const routing = new DelegatedContentRouting(selfId, {
Expand Down

0 comments on commit 7c7df12

Please sign in to comment.