diff --git a/package.json b/package.json index f3a4778..abbe59d 100644 --- a/package.json +++ b/package.json @@ -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 ", diff --git a/src/index.js b/src/index.js index 7730f62..59d899e 100644 --- a/src/index.js +++ b/src/index.js @@ -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 @@ -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 } /** @@ -113,19 +96,6 @@ 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') } @@ -133,7 +103,6 @@ class DelegatedContentRouting { this.refs(key.toBaseEncodedString(), { recursive: true }) ->>>>>>> feat: refactor to use async/await } } diff --git a/test/index.spec.js b/test/index.spec.js index a9f23c3..81a0ab6 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -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 @@ -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(), @@ -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, {