From 27d5a575c58a445bba4ba1f86d22ccc76623ef64 Mon Sep 17 00:00:00 2001 From: David Dias Date: Wed, 31 Oct 2018 09:57:19 +0000 Subject: [PATCH] feat: get Ping to work properly --- .../browser-webpack/src/components/app.js | 6 +- examples/run-in-electron/main.js | 2 +- package.json | 5 +- src/cli/bin.js | 2 +- src/cli/commands/file/ls.js | 2 +- src/cli/commands/files/add.js | 2 +- src/cli/commands/ls.js | 2 +- src/cli/commands/object/get.js | 2 +- src/cli/commands/object/put.js | 2 +- src/cli/commands/repo/stat.js | 2 +- src/cli/commands/stats/repo.js | 2 +- src/core/components/bootstrap.js | 6 +- src/core/components/init.js | 2 +- src/core/components/pin.js | 8 +-- src/core/components/ping-pull-stream.js | 58 +++++++++---------- src/core/components/ping.js | 6 +- src/core/components/pre-start.js | 2 +- src/core/runtime/dns-browser.js | 3 +- src/core/runtime/libp2p-browser.js | 4 +- src/core/runtime/libp2p-nodejs.js | 2 +- src/http/api/resources/bootstrap.js | 8 +-- src/http/api/resources/files.js | 4 +- src/http/api/resources/pin.js | 2 +- src/http/api/resources/ping.js | 28 +++++++-- src/http/api/resources/pubsub.js | 6 +- src/http/api/resources/repo.js | 2 +- src/http/api/resources/swarm.js | 2 +- test/core/libp2p.spec.js | 4 +- test/core/ping.spec.js | 12 +--- test/gateway/index.js | 2 +- test/http-api/inject/ping.js | 7 +-- test/http-api/inject/pubsub.js | 11 ---- 32 files changed, 102 insertions(+), 106 deletions(-) diff --git a/examples/browser-webpack/src/components/app.js b/examples/browser-webpack/src/components/app.js index 57f88a85d0..94a191c8ad 100644 --- a/examples/browser-webpack/src/components/app.js +++ b/examples/browser-webpack/src/components/app.js @@ -49,18 +49,18 @@ class App extends React.Component { if (err) { throw err } const hash = filesAdded[0].hash - self.setState({added_file_hash: hash}) + self.setState({ added_file_hash: hash }) node.files.cat(hash, (err, data) => { if (err) { throw err } - self.setState({added_file_contents: data.toString()}) + self.setState({ added_file_contents: data.toString() }) }) }) } } render () { return ( -
+

Everything is working!

Your ID is {this.state.id}

Your IPFS version is {this.state.version}

diff --git a/examples/run-in-electron/main.js b/examples/run-in-electron/main.js index ac40ba2e8a..74597803c9 100755 --- a/examples/run-in-electron/main.js +++ b/examples/run-in-electron/main.js @@ -11,7 +11,7 @@ const url = require('url') let mainWindow function createWindow () { - mainWindow = new BrowserWindow({width: 800, height: 600}) + mainWindow = new BrowserWindow({ width: 800, height: 600 }) // and load the index.html of the app. mainWindow.loadURL(url.format({ diff --git a/package.json b/package.json index 95c711a7ad..039499f08e 100644 --- a/package.json +++ b/package.json @@ -68,7 +68,7 @@ "execa": "^1.0.0", "form-data": "^2.3.3", "hat": "0.0.3", - "interface-ipfs-core": "~0.83.0", + "interface-ipfs-core": "~0.84.2", "ipfsd-ctl": "~0.39.5", "ncp": "^2.0.0", "qs": "^6.5.2", @@ -98,7 +98,7 @@ "hoek": "^5.0.4", "human-to-milliseconds": "^1.0.0", "interface-datastore": "~0.6.0", - "ipfs-api": "^26.0.3", + "ipfs-api": "^26.1.0", "ipfs-bitswap": "~0.21.0", "ipfs-block": "~0.8.0", "ipfs-block-service": "~0.15.1", @@ -150,6 +150,7 @@ "progress": "^2.0.1", "promisify-es6": "^1.0.3", "pull-abortable": "^4.1.1", + "pull-catch": "^1.0.0", "pull-defer": "~0.2.3", "pull-file": "^1.1.0", "pull-ndjson": "~0.1.1", diff --git a/src/cli/bin.js b/src/cli/bin.js index 3307b6e9ef..49163d909e 100755 --- a/src/cli/bin.js +++ b/src/cli/bin.js @@ -11,7 +11,7 @@ const print = utils.print const mfs = require('ipfs-mfs/cli') const debug = require('debug')('ipfs:cli') -const pkg = readPkgUp.sync({cwd: __dirname}).pkg +const pkg = readPkgUp.sync({ cwd: __dirname }).pkg updateNotifier({ pkg, updateCheckInterval: 1000 * 60 * 60 * 24 * 7 // 1 week diff --git a/src/cli/commands/file/ls.js b/src/cli/commands/file/ls.js index 31abd73e60..e9aeaee4e6 100644 --- a/src/cli/commands/file/ls.js +++ b/src/cli/commands/file/ls.js @@ -20,7 +20,7 @@ module.exports = { // Single file? Then print its hash if (links.length === 0) { - links = [{hash: path}] + links = [{ hash: path }] } links.forEach((file) => print(file.hash)) diff --git a/src/cli/commands/files/add.js b/src/cli/commands/files/add.js index e9f87a81d5..2ab492f27f 100644 --- a/src/cli/commands/files/add.js +++ b/src/cli/commands/files/add.js @@ -227,7 +227,7 @@ module.exports = { if (argv.progress) { const bar = createProgressBar(totalBytes) options.progress = function (byteLength) { - bar.update(byteLength / totalBytes, {progress: byteman(byteLength, 2, 'MB')}) + bar.update(byteLength / totalBytes, { progress: byteman(byteLength, 2, 'MB') }) } } diff --git a/src/cli/commands/ls.js b/src/cli/commands/ls.js index cf63dde2e1..97ba7ca692 100644 --- a/src/cli/commands/ls.js +++ b/src/cli/commands/ls.js @@ -39,7 +39,7 @@ module.exports = { } if (argv.headers) { - links = [{hash: 'Hash', size: 'Size', name: 'Name'}].concat(links) + links = [{ hash: 'Hash', size: 'Size', name: 'Name' }].concat(links) } const multihashWidth = Math.max.apply(null, links.map((file) => file.hash.length)) diff --git a/src/cli/commands/object/get.js b/src/cli/commands/object/get.js index 9bb9e71542..80190d8d96 100644 --- a/src/cli/commands/object/get.js +++ b/src/cli/commands/object/get.js @@ -15,7 +15,7 @@ module.exports = { }, handler (argv) { - argv.ipfs.object.get(argv.key, {enc: 'base58'}, (err, node) => { + argv.ipfs.object.get(argv.key, { enc: 'base58' }, (err, node) => { if (err) { throw err } diff --git a/src/cli/commands/object/put.js b/src/cli/commands/object/put.js index b832a5dc36..98617080df 100644 --- a/src/cli/commands/object/put.js +++ b/src/cli/commands/object/put.js @@ -5,7 +5,7 @@ const fs = require('fs') const print = require('../../utils').print function putNode (buf, enc, ipfs) { - ipfs.object.put(buf, {enc: enc}, (err, node) => { + ipfs.object.put(buf, { enc: enc }, (err, node) => { if (err) { throw err } diff --git a/src/cli/commands/repo/stat.js b/src/cli/commands/repo/stat.js index 27f3f46ed1..97b0813e29 100644 --- a/src/cli/commands/repo/stat.js +++ b/src/cli/commands/repo/stat.js @@ -15,7 +15,7 @@ module.exports = { }, handler (argv) { - argv.ipfs.repo.stat({human: argv.human}, (err, stats) => { + argv.ipfs.repo.stat({ human: argv.human }, (err, stats) => { if (err) { throw err } diff --git a/src/cli/commands/stats/repo.js b/src/cli/commands/stats/repo.js index 366f2ae719..a0537e902d 100644 --- a/src/cli/commands/stats/repo.js +++ b/src/cli/commands/stats/repo.js @@ -15,7 +15,7 @@ module.exports = { }, handler (argv) { - argv.ipfs.stats.repo({human: argv.human}, (err, stats) => { + argv.ipfs.stats.repo({ human: argv.human }, (err, stats) => { if (err) { throw err } diff --git a/src/core/components/bootstrap.js b/src/core/components/bootstrap.js index 0db01a9b54..551405ba2e 100644 --- a/src/core/components/bootstrap.js +++ b/src/core/components/bootstrap.js @@ -23,7 +23,7 @@ module.exports = function bootstrap (self) { if (err) { return callback(err) } - callback(null, {Peers: config.Bootstrap}) + callback(null, { Peers: config.Bootstrap }) }) }), add: promisify((multiaddr, args, callback) => { @@ -59,7 +59,7 @@ module.exports = function bootstrap (self) { rm: promisify((multiaddr, args, callback) => { if (typeof args === 'function') { callback = args - args = {all: false} + args = { all: false } } if (multiaddr && !isValidMultiaddr(multiaddr)) { return setImmediate(() => callback(invalidMultiaddrError(multiaddr))) @@ -85,7 +85,7 @@ module.exports = function bootstrap (self) { res.push(multiaddr) } - callback(null, {Peers: res}) + callback(null, { Peers: res }) }) }) }) diff --git a/src/core/components/init.js b/src/core/components/init.js index 258e8a411a..3265c496fc 100644 --- a/src/core/components/init.js +++ b/src/core/components/init.js @@ -98,7 +98,7 @@ module.exports = function init (self) { self.log('repo opened') if (opts.pass) { self.log('creating keychain') - const keychainOptions = Object.assign({passPhrase: opts.pass}, config.Keychain) + const keychainOptions = Object.assign({ passPhrase: opts.pass }, config.Keychain) self._keychain = new Keychain(self._repo.keys, keychainOptions) self._keychain.importPeer('self', { privKey: privateKey }, cb) } else { diff --git a/src/core/components/pin.js b/src/core/components/pin.js index 196ca1a67b..1b231a86fd 100644 --- a/src/core/components/pin.js +++ b/src/core/components/pin.js @@ -333,17 +333,17 @@ module.exports = (self) => { const { recursive, direct, all } = types // recursive if ((type === recursive || type === all) && recursivePins.has(key)) { - return callback(null, {pinned: true, reason: recursive}) + return callback(null, { pinned: true, reason: recursive }) } if ((type === recursive)) { - return callback(null, {pinned: false}) + return callback(null, { pinned: false }) } // direct if ((type === direct || type === all) && directPins.has(key)) { - return callback(null, {pinned: true, reason: direct}) + return callback(null, { pinned: true, reason: direct }) } if ((type === direct)) { - return callback(null, {pinned: false}) + return callback(null, { pinned: false }) } // indirect (default) diff --git a/src/core/components/ping-pull-stream.js b/src/core/components/ping-pull-stream.js index c4a2acfeae..4af423ce34 100644 --- a/src/core/components/ping-pull-stream.js +++ b/src/core/components/ping-pull-stream.js @@ -5,7 +5,6 @@ const OFFLINE_ERROR = require('../utils').OFFLINE_ERROR const PeerId = require('peer-id') const pull = require('pull-stream') const Pushable = require('pull-pushable') -const waterfall = require('async/waterfall') const log = debug('jsipfs:pingPullStream') log.error = debug('jsipfs:pingPullStream:error') @@ -20,15 +19,20 @@ module.exports = function pingPullStream (self) { const source = Pushable() - waterfall([ - (cb) => getPeer(self._libp2pNode, source, peerId, cb), - (peer, cb) => runPing(self._libp2pNode, source, opts.count, peer, cb) - ], (err) => { + getPeer(self._libp2pNode, source, peerId, (err, peer) => { if (err) { log.error(err) - source.push(getPacket({ success: false, text: err.toString() })) source.end(err) + return } + + runPing(self._libp2pNode, source, opts.count, peer, (err) => { + if (err) { + log.error(err) + source.push(getPacket({ success: false, text: err.toString() })) + source.end() + } + }) }) return source @@ -41,45 +45,40 @@ function getPacket (msg) { return Object.assign(basePacket, msg) } -function getPeer (libp2pNode, statusStream, peerId, cb) { - let peer +function getPeer (libp2pNode, statusStream, peerIdStr, cb) { + let peerId + + try { + peerId = PeerId.createFromB58String(peerIdStr) + } catch (err) { + return cb(err) + } + + let peerInfo try { - peer = libp2pNode.peerBook.get(peerId) + peerInfo = libp2pNode.peerBook.get(peerId) } catch (err) { log('Peer not found in peer book, trying peer routing') - // Share lookup status just as in the go implemmentation - statusStream.push(getPacket({ text: `Looking up peer ${peerId}` })) - - // Try to use peerRouting - try { - peerId = PeerId.createFromB58String(peerId) - } catch (err) { - return cb(Object.assign(err, { - message: `failed to parse peer address '${peerId}': input isn't valid multihash` - })) - } + // Share lookup status just as in the go implemmentation + statusStream.push(getPacket({ text: `Looking up peer ${peerIdStr}` })) return libp2pNode.peerRouting.findPeer(peerId, cb) } - cb(null, peer) + cb(null, peerInfo) } function runPing (libp2pNode, statusStream, count, peer, cb) { libp2pNode.ping(peer, (err, p) => { - if (err) { - return cb(err) - } - - log('Got peer', peer) + if (err) { return cb(err) } let packetCount = 0 let totalTime = 0 statusStream.push(getPacket({ text: `PING ${peer.id.toB58String()}` })) p.on('ping', (time) => { - statusStream.push(getPacket({ time: time })) + statusStream.push(getPacket({ time })) totalTime += time packetCount++ if (packetCount >= count) { @@ -93,12 +92,9 @@ function runPing (libp2pNode, statusStream, count, peer, cb) { p.on('error', (err) => { log.error(err) p.stop() - statusStream.push(getPacket({ success: false, text: err.toString() })) - statusStream.end(err) + cb(err) }) p.start() - - return cb() }) } diff --git a/src/core/components/ping.js b/src/core/components/ping.js index a92e31c24a..5f0aa61be3 100644 --- a/src/core/components/ping.js +++ b/src/core/components/ping.js @@ -4,15 +4,15 @@ const promisify = require('promisify-es6') const pull = require('pull-stream/pull') module.exports = function ping (self) { - return promisify((peerId, opts, cb) => { + return promisify((peerId, opts, callback) => { if (typeof opts === 'function') { - cb = opts + callback = opts opts = {} } pull( self.pingPullStream(peerId, opts), - pull.collect(cb) + pull.collect(callback) ) }) } diff --git a/src/core/components/pre-start.js b/src/core/components/pre-start.js index ed30190a0a..51e08a10a9 100644 --- a/src/core/components/pre-start.js +++ b/src/core/components/pre-start.js @@ -48,7 +48,7 @@ module.exports = function preStart (self) { if (self._keychain) { // most likely an init or upgrade has happened } else if (pass) { - const keychainOptions = Object.assign({passPhrase: pass}, config.Keychain) + const keychainOptions = Object.assign({ passPhrase: pass }, config.Keychain) self._keychain = new Keychain(self._repo.keys, keychainOptions) self.log('keychain constructed') } else { diff --git a/src/core/runtime/dns-browser.js b/src/core/runtime/dns-browser.js index c68de233fe..a0abb9a4fe 100644 --- a/src/core/runtime/dns-browser.js +++ b/src/core/runtime/dns-browser.js @@ -1,3 +1,4 @@ +/* global self */ 'use strict' module.exports = (domain, opts, callback) => { @@ -8,7 +9,7 @@ module.exports = (domain, opts, callback) => { url += `&${prop}=${opts[prop]}` } - self.fetch(url, {mode: 'cors'}) + self.fetch(url, { mode: 'cors' }) .then((response) => { return response.json() }) diff --git a/src/core/runtime/libp2p-browser.js b/src/core/runtime/libp2p-browser.js index d497881c14..fec12fa9a3 100644 --- a/src/core/runtime/libp2p-browser.js +++ b/src/core/runtime/libp2p-browser.js @@ -11,8 +11,8 @@ const defaultsDeep = require('@nodeutils/defaults-deep') class Node extends libp2p { constructor (_options) { - const wrtcstar = new WebRTCStar({id: _options.peerInfo.id}) - const wsstar = new WebSocketStar({id: _options.peerInfo.id}) + const wrtcstar = new WebRTCStar({ id: _options.peerInfo.id }) + const wsstar = new WebSocketStar({ id: _options.peerInfo.id }) const defaults = { modules: { diff --git a/src/core/runtime/libp2p-nodejs.js b/src/core/runtime/libp2p-nodejs.js index a71430cfa3..1b59c435c7 100644 --- a/src/core/runtime/libp2p-nodejs.js +++ b/src/core/runtime/libp2p-nodejs.js @@ -13,7 +13,7 @@ const defaultsDeep = require('@nodeutils/defaults-deep') class Node extends libp2p { constructor (_options) { - const wsstar = new WebSocketStar({id: _options.peerInfo.id}) + const wsstar = new WebSocketStar({ id: _options.peerInfo.id }) const defaults = { modules: { diff --git a/src/http/api/resources/bootstrap.js b/src/http/api/resources/bootstrap.js index 80f97d8e81..affc3a2126 100644 --- a/src/http/api/resources/bootstrap.js +++ b/src/http/api/resources/bootstrap.js @@ -38,7 +38,7 @@ exports.add = { return applyError(reply, new Error('Not a valid multiaddr')) } } else { - reply({default: def}) + reply({ default: def }) } }, handler (request, reply) { @@ -46,7 +46,7 @@ exports.add = { const addr = request.pre.args.addr const def = request.pre.args.default - ipfs.bootstrap.add(addr && addr.toString(), {default: def}, (err, list) => { + ipfs.bootstrap.add(addr && addr.toString(), { default: def }, (err, list) => { if (err) { return applyError(reply, err) } @@ -71,7 +71,7 @@ exports.rm = { return applyError(reply, new Error('Not a valid multiaddr')) } } else { - reply({all: all}) + reply({ all: all }) } }, handler (request, reply) { @@ -79,7 +79,7 @@ exports.rm = { const addr = request.pre.args.addr const all = request.pre.args.all - ipfs.bootstrap.rm(addr && addr.toString(), {all: all}, (err, list) => { + ipfs.bootstrap.rm(addr && addr.toString(), { all: all }, (err, list) => { if (err) { return applyError(reply, err) } diff --git a/src/http/api/resources/files.js b/src/http/api/resources/files.js index 3e2fb28d38..939ac25df3 100644 --- a/src/http/api/resources/files.js +++ b/src/http/api/resources/files.js @@ -83,9 +83,9 @@ exports.cat = { if (err) { log.error(err) if (err.message === 'No such file') { - reply({Message: 'No such file', Code: 0, Type: 'error'}).code(500) + reply({ Message: 'No such file', Code: 0, Type: 'error' }).code(500) } else { - reply({Message: 'Failed to cat file: ' + err, Code: 0, Type: 'error'}).code(500) + reply({ Message: 'Failed to cat file: ' + err, Code: 0, Type: 'error' }).code(500) } return } diff --git a/src/http/api/resources/pin.js b/src/http/api/resources/pin.js index e42dd1f8c4..5499dfd34f 100644 --- a/src/http/api/resources/pin.js +++ b/src/http/api/resources/pin.js @@ -48,7 +48,7 @@ exports.ls = { return reply({ Keys: _.mapValues( _.keyBy(result, obj => obj.hash), - obj => ({Type: obj.type}) + obj => ({ Type: obj.type }) ) }) }) diff --git a/src/http/api/resources/ping.js b/src/http/api/resources/ping.js index 56824db629..56b54b3c05 100644 --- a/src/http/api/resources/ping.js +++ b/src/http/api/resources/ping.js @@ -23,9 +23,15 @@ exports.get = { handler: (request, reply) => { const ipfs = request.server.app.ipfs const peerId = request.query.arg + // Default count to 10 const count = request.query.n || request.query.count || 10 + // Streams from pull-stream-to-stream don't seem to be compatible + // with the stream2 readable interface + // see: https://github.com/hapijs/hapi/blob/c23070a3de1b328876d5e64e679a147fafb04b38/lib/response.js#L533 + // and: https://github.com/pull-stream/pull-stream-to-stream/blob/e436acee18b71af8e71d1b5d32eee642351517c7/index.js#L28 + const source = pull( ipfs.pingPullStream(peerId, { count: count }), pull.map((chunk) => ({ @@ -36,13 +42,25 @@ exports.get = { ndjson.serialize() ) - // Streams from pull-stream-to-stream don't seem to be compatible - // with the stream2 readable interface - // see: https://github.com/hapijs/hapi/blob/c23070a3de1b328876d5e64e679a147fafb04b38/lib/response.js#L533 - // and: https://github.com/pull-stream/pull-stream-to-stream/blob/e436acee18b71af8e71d1b5d32eee642351517c7/index.js#L28 const responseStream = toStream.source(source) const stream2 = new PassThrough() + let replied = false pump(responseStream, stream2) - return reply(stream2).type('application/json').header('X-Chunked-Output', '1') + + // FIXME: This is buffering all ping responses before sending them so that + // we can capture the error if it happens. #fixTheHTTPAPI + responseStream.on('error', (err) => { + if (!replied) { + replied = true + reply(err) + } + }) + + responseStream.on('end', () => { + if (!replied) { + replied = true + reply(stream2).type('application/json').header('X-Chunked-Output', '1') + } + }) } } diff --git a/src/http/api/resources/pubsub.js b/src/http/api/resources/pubsub.js index 8b88bd3dce..f28bd5f090 100644 --- a/src/http/api/resources/pubsub.js +++ b/src/http/api/resources/pubsub.js @@ -18,7 +18,7 @@ exports.subscribe = { const ipfs = request.server.app.ipfs - const res = new PassThrough({highWaterMark: 1}) + const res = new PassThrough({ highWaterMark: 1 }) const handler = (msg) => { res.write(JSON.stringify({ @@ -89,7 +89,7 @@ exports.ls = { return reply(new Error(`Failed to list subscriptions: ${err}`)) } - reply({Strings: subscriptions}) + reply({ Strings: subscriptions }) }) } } @@ -108,7 +108,7 @@ exports.peers = { return reply(new Error(message)) } - reply({Strings: peers}) + reply({ Strings: peers }) }) } } diff --git a/src/http/api/resources/repo.js b/src/http/api/resources/repo.js index d6add2c6e9..13b68e115a 100644 --- a/src/http/api/resources/repo.js +++ b/src/http/api/resources/repo.js @@ -38,7 +38,7 @@ exports.stat = (request, reply) => { const ipfs = request.server.app.ipfs const human = request.query.human === 'true' - ipfs.repo.stat({human: human}, (err, stat) => { + ipfs.repo.stat({ human: human }, (err, stat) => { if (err) { return reply({ Message: err.toString(), diff --git a/src/http/api/resources/swarm.js b/src/http/api/resources/swarm.js index af003400e2..918f7c8ba3 100644 --- a/src/http/api/resources/swarm.js +++ b/src/http/api/resources/swarm.js @@ -39,7 +39,7 @@ exports.peers = { const verbose = rawVerbose === 'true' const ipfs = request.server.app.ipfs - ipfs.swarm.peers({verbose: verbose}, (err, peers) => { + ipfs.swarm.peers({ verbose: verbose }, (err, peers) => { if (err) { log.error(err) return reply({ diff --git a/test/core/libp2p.spec.js b/test/core/libp2p.spec.js index 135a6870ac..19248eb535 100644 --- a/test/core/libp2p.spec.js +++ b/test/core/libp2p.spec.js @@ -73,7 +73,7 @@ describe('libp2p customization', function () { config: mockConfig, _options: { libp2p: (opts) => { - const wsstar = new WebSocketStar({id: opts.peerInfo.id}) + const wsstar = new WebSocketStar({ id: opts.peerInfo.id }) return new Libp2p({ peerInfo: opts.peerInfo, @@ -147,7 +147,7 @@ describe('libp2p customization', function () { }) it('should allow for overriding via options', (done) => { - const wsstar = new WebSocketStar({id: peerInfo.id}) + const wsstar = new WebSocketStar({ id: peerInfo.id }) const ipfs = { _peerInfo: peerInfo, diff --git a/test/core/ping.spec.js b/test/core/ping.spec.js index 37121f7c55..da5be6035b 100644 --- a/test/core/ping.spec.js +++ b/test/core/ping.spec.js @@ -172,26 +172,20 @@ describe('ping', function () { ) }) - it('pinging an unknown peer will fail accordingly', (done) => { + it('pinging a not available peer will fail accordingly', (done) => { const unknownPeerId = 'QmUmaEnH1uMmvckMZbh3yShaasvELPW4ZLPWnB4entMTEn' let messageNum = 0 - const count = 2 + const count = 1 pull( - ipfsdA.api.pingPullStream(unknownPeerId, { count }), + ipfsdA.api.pingPullStream(unknownPeerId, {}), drain(({ success, time, text }) => { messageNum++ // Assert that the ping command falls back to the peerRouting if (messageNum === 1) { expect(text).to.include('Looking up') } - - // Fails accordingly while trying to use peerRouting - if (messageNum === 2) { - expect(success).to.be.false() - } }, (err) => { expect(err).to.exist() - expect(err.message).to.include('DHT is not available') expect(messageNum).to.equal(count) done() }) diff --git a/test/gateway/index.js b/test/gateway/index.js index fde341d73e..837261be84 100644 --- a/test/gateway/index.js +++ b/test/gateway/index.js @@ -93,7 +93,7 @@ describe('HTTP Gateway', function () { (cb) => { const expectedMultihash = 'QmT78zSuBmuS4z925WZfrqQ1qHaJ56DQaTfyMUF7F8ff5o' - http.api.node.files.add(Buffer.from('hello world' + '\n'), {cidVersion: 0}, (err, res) => { + http.api.node.files.add(Buffer.from('hello world' + '\n'), { cidVersion: 0 }, (err, res) => { expect(err).to.not.exist() const file = res[0] expect(file.path).to.equal(expectedMultihash) diff --git a/test/http-api/inject/ping.js b/test/http-api/inject/ping.js index 7ccf747816..42759c38f3 100644 --- a/test/http-api/inject/ping.js +++ b/test/http-api/inject/ping.js @@ -36,15 +36,12 @@ module.exports = (http) => { }) }) - it('returns 200 and the response stream with the ping result', (done) => { + it('returns 500 for incorrect Peer Id', (done) => { api.inject({ method: 'GET', url: `/api/v0/ping?arg=peerid` }, (res) => { - expect(res.statusCode).to.equal(200) - expect(res.headers['x-chunked-output']).to.equal('1') - expect(res.headers['transfer-encoding']).to.equal('chunked') - expect(res.headers['content-type']).to.include('application/json') + expect(res.statusCode).to.equal(500) done() }) }) diff --git a/test/http-api/inject/pubsub.js b/test/http-api/inject/pubsub.js index 2248a660af..b51ab21cf3 100644 --- a/test/http-api/inject/pubsub.js +++ b/test/http-api/inject/pubsub.js @@ -91,17 +91,6 @@ module.exports = (http) => { }) describe('/peers', () => { - it('returns 200 if no topic is provided', (done) => { - api.inject({ - method: 'GET', - url: `/api/v0/pubsub/peers` - }, (res) => { - expect(res.statusCode).to.equal(200) - expect(res.result.Strings).to.be.eql([]) - done() - }) - }) - it('returns 200 if not subscribed to a topic', (done) => { api.inject({ method: 'GET',