Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
fix: code review
Browse files Browse the repository at this point in the history
  • Loading branch information
vasco-santos committed Feb 6, 2019
1 parent 045e305 commit 2956637
Show file tree
Hide file tree
Showing 22 changed files with 174 additions and 277 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"form-data": "^2.3.3",
"hat": "0.0.3",
"interface-ipfs-core": "~0.96.0",
"ipfsd-ctl": "~0.40.2",
"ipfsd-ctl": "~0.41.0",
"ncp": "^2.0.0",
"qs": "^6.5.2",
"rimraf": "^2.6.2",
Expand Down Expand Up @@ -128,7 +128,7 @@
"joi": "^14.3.0",
"joi-browser": "^13.4.0",
"joi-multiaddr": "^4.0.0",
"libp2p": "~0.24.3",
"libp2p": "libp2p/js-libp2p#master",
"libp2p-bootstrap": "~0.9.3",
"libp2p-crypto": "~0.16.0",
"libp2p-kad-dht": "~0.14.4",
Expand Down
4 changes: 0 additions & 4 deletions src/cli/commands/daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ module.exports = {
type: 'boolean',
default: false
})
.option('enable-dht-experiment', {
type: 'boolean',
default: false
})
.option('offline', {
desc: 'Run offline. Do not connect to the rest of the network but provide local API.',
default: false
Expand Down
7 changes: 5 additions & 2 deletions src/cli/commands/dht/find-peer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ module.exports = {

builder: {},

handler ({ ipfs, peerID, resolve }) {
handler ({ getIpfs, peerID, resolve }) {
resolve((async () => {
const ipfs = await getIpfs()
const peers = await ipfs.dht.findPeer(peerID)
const addresses = peers.multiaddrs.toArray().map((ma) => ma.toString())

print(addresses)
addresses.forEach((addr) => {
print(addr)
})
})())
}
}
3 changes: 2 additions & 1 deletion src/cli/commands/dht/find-providers.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ module.exports = {
},

handler (argv) {
const { ipfs, key, resolve } = argv
const { getIpfs, key, resolve } = argv
const opts = {
maxNumProviders: argv['num-providers']
}

resolve((async () => {
const ipfs = await getIpfs()
const provs = await ipfs.dht.findProvs(key, opts)

provs.forEach((element) => {
Expand Down
3 changes: 2 additions & 1 deletion src/cli/commands/dht/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ module.exports = {

builder: {},

handler ({ ipfs, key, resolve }) {
handler ({ getIpfs, key, resolve }) {
resolve((async () => {
const ipfs = await getIpfs()
const value = await ipfs.dht.get(key)

print(value)
Expand Down
9 changes: 6 additions & 3 deletions src/cli/commands/dht/provide.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@ module.exports = {
}
},

handler ({ ipfs, key, resolve }) {
// TODO add recursive option
handler ({ getIpfs, key, recursive, resolve }) {
const opts = {
recursive
}

resolve((async () => {
await ipfs.dht.provide(key)
const ipfs = await getIpfs()
await ipfs.dht.provide(key, opts)
})())
}
}
3 changes: 2 additions & 1 deletion src/cli/commands/dht/put.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ module.exports = {

builder: {},

handler ({ ipfs, key, value, resolve }) {
handler ({ getIpfs, key, value, resolve }) {
resolve((async () => {
const ipfs = await getIpfs()
await ipfs.dht.put(key, value)
})())
}
Expand Down
3 changes: 2 additions & 1 deletion src/cli/commands/dht/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ module.exports = {

builder: {},

handler ({ ipfs, peerID, resolve }) {
handler ({ getIpfs, peerID, resolve }) {
resolve((async () => {
const ipfs = await getIpfs()
const result = await ipfs.dht.query(peerID)

result.forEach((peerID) => {
Expand Down
9 changes: 5 additions & 4 deletions src/core/components/dht.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ const PeerId = require('peer-id')
const PeerInfo = require('peer-info')
const CID = require('cids')
const each = require('async/each')
const setImmediate = require('async/setImmediate')
const nextTick = require('async/nextTick')

const errcode = require('err-code')

const debug = require('debug')
Expand Down Expand Up @@ -38,7 +39,7 @@ module.exports = (self) => {
} catch (err) {
log.error(err)

return setImmediate(() => callback(errcode(err, 'ERR_INVALID_CID')))
return nextTick(() => callback(errcode(err, 'ERR_INVALID_CID')))
}
}

Expand All @@ -64,7 +65,7 @@ module.exports = (self) => {
} catch (err) {
log.error(err)

return setImmediate(() => callback(errcode(err, 'ERR_INVALID_CID')))
return nextTick(() => callback(errcode(err, 'ERR_INVALID_CID')))
}
}

Expand Down Expand Up @@ -95,7 +96,7 @@ module.exports = (self) => {
} catch (err) {
log.error(err)

return setImmediate(() => callback(errcode(err, 'ERR_INVALID_CID')))
return nextTick(() => callback(errcode(err, 'ERR_INVALID_CID')))
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/core/components/libp2p.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ function defaultBundle ({ datastore, peerInfo, peerBook, options, config }) {
},
dht: {
kBucketSize: get(options, 'dht.kBucketSize', 20),
enabledDiscovery: get(options, 'dht.enabledDiscovery', true),
enabled: get(options, 'dht.enabled', true) && !(get(options, 'offline', false)),
randomWalk: {
enabled: get(options, 'dht.randomWalk.enabled', true)
},
validators: {
ipns: ipnsUtils.validator
},
Expand All @@ -86,7 +89,6 @@ function defaultBundle ({ datastore, peerInfo, peerBook, options, config }) {
}
},
EXPERIMENTAL: {
dht: !(get(options, 'local', false)),
pubsub: get(options, 'EXPERIMENTAL.pubsub', false)
}
},
Expand Down
4 changes: 1 addition & 3 deletions src/core/runtime/libp2p-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,9 @@ class Node extends libp2p {
}
},
dht: {
kBucketSize: 20,
enabledDiscovery: true
enabled: false
},
EXPERIMENTAL: {
dht: true,
pubsub: false
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/core/runtime/libp2p-nodejs.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,12 @@ class Node extends libp2p {
},
dht: {
kBucketSize: 20,
enabledDiscovery: true
enabled: true,
randomWalk: {
enabled: true
}
},
EXPERIMENTAL: {
dht: true,
pubsub: false
}
}
Expand Down
Loading

0 comments on commit 2956637

Please sign in to comment.