diff --git a/package.json b/package.json index ff2b7571a4..3716f0aaf7 100644 --- a/package.json +++ b/package.json @@ -75,7 +75,7 @@ "form-data": "^2.3.1", "gulp": "^3.9.1", "hat": "0.0.3", - "interface-ipfs-core": "~0.34.3", + "interface-ipfs-core": "~0.35.0", "ipfsd-ctl": "~0.24.1", "left-pad": "^1.1.3", "lodash": "^4.17.4", @@ -94,6 +94,7 @@ "async": "^2.6.0", "bl": "^1.2.1", "boom": "^7.1.1", + "bs58": "^4.0.1", "byteman": "^1.3.5", "cids": "^0.5.2", "debug": "^3.1.0", @@ -105,7 +106,7 @@ "hapi": "^16.6.2", "hapi-set-header": "^1.0.2", "hoek": "^5.0.2", - "ipfs-api": "^15.1.0", + "ipfs-api": "^16.0.0", "ipfs-bitswap": "~0.17.4", "ipfs-block": "~0.6.1", "ipfs-block-service": "~0.13.0", @@ -119,7 +120,7 @@ "joi": "^13.0.2", "libp2p": "~0.13.1", "libp2p-circuit": "~0.1.4", - "libp2p-floodsub": "~0.11.1", + "libp2p-floodsub": "~0.12.0", "libp2p-kad-dht": "~0.6.0", "libp2p-mdns": "~0.9.1", "libp2p-multiplex": "~0.5.0", diff --git a/src/cli/commands/ls.js b/src/cli/commands/ls.js index 61a19e760c..e7beecbaee 100644 --- a/src/cli/commands/ls.js +++ b/src/cli/commands/ls.js @@ -1,8 +1,6 @@ 'use strict' const utils = require('../utils') -const Unixfs = require('ipfs-unixfs') -const pull = require('pull-stream') module.exports = { command: 'ls ', diff --git a/src/http/api/resources/files.js b/src/http/api/resources/files.js index ebb1353f35..4bf13f2ac6 100644 --- a/src/http/api/resources/files.js +++ b/src/http/api/resources/files.js @@ -317,4 +317,3 @@ function toTypeCode (type) { return 0 } } - diff --git a/src/http/api/resources/pubsub.js b/src/http/api/resources/pubsub.js index 8d35abce97..6aa1ad6f82 100644 --- a/src/http/api/resources/pubsub.js +++ b/src/http/api/resources/pubsub.js @@ -1,6 +1,7 @@ 'use strict' const PassThrough = require('stream').PassThrough +const bs58 = require('bs58') exports = module.exports @@ -20,10 +21,10 @@ exports.subscribe = { const handler = (msg) => { res.write(JSON.stringify({ - from: msg.from, + from: bs58.decode(msg.from).toString('base64'), data: msg.data.toString('base64'), seqno: msg.seqno.toString('base64'), - topicCIDs: msg.topicCIDs + topicIDs: msg.topicIDs }) + '\n', 'utf8') } diff --git a/test/interop/node.js b/test/interop/node.js index b3108e28bf..7e4a513445 100644 --- a/test/interop/node.js +++ b/test/interop/node.js @@ -5,3 +5,4 @@ require('./repo') require('./exchange-files') require('./circuit-relay') require('./kad-dht') +require('./pubsub') diff --git a/test/interop/pubsub.js b/test/interop/pubsub.js new file mode 100644 index 0000000000..b76f21967f --- /dev/null +++ b/test/interop/pubsub.js @@ -0,0 +1,80 @@ +/* eslint-env mocha */ +'use strict' + +const chai = require('chai') +const dirtyChai = require('dirty-chai') +const expect = chai.expect +chai.use(dirtyChai) +const series = require('async/series') +const parallel = require('async/parallel') + +const GODaemon = require('../utils/interop-daemon-spawner/go') +const JSDaemon = require('../utils/interop-daemon-spawner/js') + +describe('pubsub', () => { + let jsD + let goD + let jsId + let goId + + before(function (done) { + this.timeout(50 * 1000) + + goD = new GODaemon({ + disposable: true, + init: true, + flags: ['--enable-pubsub-experiment'] + }) + jsD = new JSDaemon() + + parallel([ + (cb) => goD.start(cb), + (cb) => jsD.start(cb) + ], (done)) + }) + + after((done) => { + series([ + (cb) => goD.stop(cb), + (cb) => jsD.stop(cb) + ], done) + }) + + it('make connections', (done) => { + parallel([ + (cb) => jsD.api.id(cb), + (cb) => goD.api.id(cb) + ], (err, ids) => { + expect(err).to.not.exist() + + jsId = ids[0].ID + goId = ids[0].ID + + console.log('jsId:', jsId) + console.log('goId:', goId) + + parallel([ + (cb) => jsD.api.swarm.connect(ids[1].addresses[0], cb), + (cb) => goD.api.swarm.connect(ids[0].addresses[0], cb) + ], done) + }) + }) + + it.skip('publish from JS, subscribe on Go', (done) => { + // TODO write this test + }) + + it.skip('publish from Go, subscribe on JS', (done) => { + const topic = 'pubsub-go-js' + const data = Buffer.from('hello world') + + function checkMessage () { + console.log('check message', arguments) + } + + series([ + cb => jsD.api.pubsub.subscribe(topic, checkMessage, cb), + cb => goD.api.pubsub.publish(topic, data, cb) + ], done) + }) +}) diff --git a/test/utils/interop-daemon-spawner/go.js b/test/utils/interop-daemon-spawner/go.js index 286f559afc..92a04ca99e 100644 --- a/test/utils/interop-daemon-spawner/go.js +++ b/test/utils/interop-daemon-spawner/go.js @@ -16,6 +16,7 @@ class GoDaemon { this.node = null this.api = null this.config = opts.config || {} + this.flags = opts.flags || {} } start (callback) { @@ -40,6 +41,7 @@ class GoDaemon { this.node.setConfig('Bootstrap', '[]', cb) }, (res, cb) => this.node.startDaemon(cb), + // (res, cb) => this.node.startDaemon(this.flags, cb), (api, cb) => { this.api = api