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 e859a81 commit 2b548be
Show file tree
Hide file tree
Showing 13 changed files with 34 additions and 33 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
4 changes: 3 additions & 1 deletion src/cli/commands/dht/find-peer.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ module.exports = {
const peers = await ipfs.dht.findPeer(peerID)
const addresses = peers.multiaddrs.toArray().map((ma) => ma.toString())

print(addresses)
addresses.forEach((addr) => {
print(addr)
})
})())
}
}
8 changes: 5 additions & 3 deletions src/cli/commands/dht/provide.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ module.exports = {
}
},

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

resolve((async () => {
await ipfs.dht.provide(key)
await ipfs.dht.provide(key, opts)
})())
}
}
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
4 changes: 2 additions & 2 deletions src/http/api/resources/dht.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ exports.provide = {
}).code(500)
}

reply({})
reply()
})
}
}
Expand Down Expand Up @@ -176,7 +176,7 @@ exports.put = {
}).code(500)
}

reply({})
reply()
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/core/interface.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ describe('interface-ipfs-core tests', function () {

tests.name(CommonFactory.create({
spawnOptions: {
args: ['--pass ipfs-is-awesome-software', '--local'],
args: ['--pass ipfs-is-awesome-software', '--offline'],
initOptions: { bits: 512 },
config: {
Bootstrap: [],
Expand Down
8 changes: 3 additions & 5 deletions test/core/libp2p.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const PeerBook = require('peer-book')
const WebSocketStar = require('libp2p-websocket-star')
const Multiplex = require('libp2p-mplex')
const SECIO = require('libp2p-secio')
const KadDHT = require('libp2p-kad-dht')
const Libp2p = require('libp2p')

const libp2pComponent = require('../../src/core/components/libp2p')
Expand Down Expand Up @@ -45,7 +46,6 @@ describe('libp2p customization', function () {
}
},
EXPERIMENTAL: {
dht: false,
pubsub: false
}
}
Expand Down Expand Up @@ -94,7 +94,8 @@ describe('libp2p customization', function () {
],
peerDiscovery: [
wsstar.discovery
]
],
dht: KadDHT
}
})
}
Expand Down Expand Up @@ -144,7 +145,6 @@ describe('libp2p customization', function () {
}
},
EXPERIMENTAL: {
dht: true,
pubsub: false
}
})
Expand Down Expand Up @@ -172,7 +172,6 @@ describe('libp2p customization', function () {
}
},
EXPERIMENTAL: {
dht: false,
pubsub: true
},
libp2p: {
Expand Down Expand Up @@ -209,7 +208,6 @@ describe('libp2p customization', function () {
}
},
EXPERIMENTAL: {
dht: true,
pubsub: true
}
})
Expand Down
6 changes: 3 additions & 3 deletions test/core/name.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe('name', function () {
this.timeout(50 * 1000)
df.spawn({
exec: IPFS,
args: [`--pass ${hat()}`, '--local'],
args: [`--pass ${hat()}`, '--offline'],
config: { Bootstrap: [] }
}, (err, _ipfsd) => {
expect(err).to.not.exist()
Expand Down Expand Up @@ -152,7 +152,7 @@ describe('name', function () {
this.timeout(40 * 1000)
df.spawn({
exec: IPFS,
args: [`--pass ${hat()}`, '--local'],
args: [`--pass ${hat()}`, '--offline'],
config: { Bootstrap: [] }
}, (err, _ipfsd) => {
expect(err).to.not.exist()
Expand Down Expand Up @@ -474,7 +474,7 @@ describe('name', function () {
this.timeout(40 * 1000)
df.spawn({
exec: IPFS,
args: [`--pass ${hat()}`, '--local'],
args: [`--pass ${hat()}`, '--offline'],
config: {
Bootstrap: [],
Discovery: {
Expand Down
2 changes: 1 addition & 1 deletion test/core/ping.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const config = {
}

function spawnNode ({ dht = false, type = 'js' }, cb) {
const args = dht ? [] : ['--local']
const args = dht ? [] : ['--offline']
const factory = type === 'js' ? df : dfProc
factory.spawn({
args,
Expand Down

0 comments on commit 2b548be

Please sign in to comment.