Skip to content
This repository has been archived by the owner on Jul 21, 2023. It is now read-only.

Commit

Permalink
refactor(async): providers refactor
Browse files Browse the repository at this point in the history
* refactor(async): providers refactor from #82

* test: providers dedupes redundant providers

* added feedback from PR review

* aegir - increase bundle size to 222kB
  • Loading branch information
kumavis authored and vasco-santos committed Jun 10, 2019
1 parent 9e777e5 commit 30fd44a
Show file tree
Hide file tree
Showing 10 changed files with 243 additions and 300 deletions.
2 changes: 1 addition & 1 deletion .aegir.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
bundlesize: { maxSize: '197kB' }
bundlesize: { maxSize: '222kB' }
}

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"merge-options": "^1.0.1",
"multihashes": "~0.4.14",
"multihashing-async": "~0.5.2",
"p-queue": "^5.0.0",
"peer-id": "~0.12.2",
"peer-info": "~0.15.1",
"priorityqueue": "~0.2.1",
Expand All @@ -62,6 +63,7 @@
"protons": "^1.0.1",
"pull-length-prefixed": "^1.3.2",
"pull-stream": "^3.6.9",
"pull-stream-to-async-iterator": "^1.0.1",
"varint": "^5.0.0",
"xor-distance": "^2.0.0"
},
Expand Down
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,8 @@ class KadDHT extends EventEmitter {

const errors = []
waterfall([
(cb) => this.providers.addProvider(key, this.peerInfo.id, cb),
// TODO: refactor this in method in async and remove this wrapper
(cb) => promiseToCallback(this.providers.addProvider(key, this.peerInfo.id))(err => cb(err)),
(cb) => this.getClosestPeers(key.buffer, cb),
(peers, cb) => {
const msg = new Message(Message.TYPES.ADD_PROVIDER, key.buffer, 0)
Expand Down
2 changes: 1 addition & 1 deletion src/private.js
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ module.exports = (dht) => ({
async _findNProvidersAsync (key, providerTimeout, n) {
const out = new LimitedPeerList(n)

const provs = await promisify(cb => dht.providers.getProviders(key, cb))()
const provs = await dht.providers.getProviders(key)

provs.forEach((id) => {
let info
Expand Down
Loading

0 comments on commit 30fd44a

Please sign in to comment.