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

Pubsub message fields #1077

Merged
merged 11 commits into from
Nov 17, 2017
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down
2 changes: 0 additions & 2 deletions src/cli/commands/ls.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
'use strict'

const utils = require('../utils')
const Unixfs = require('ipfs-unixfs')
const pull = require('pull-stream')

module.exports = {
command: 'ls <key>',
Expand Down
1 change: 0 additions & 1 deletion src/http/api/resources/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,4 +317,3 @@ function toTypeCode (type) {
return 0
}
}

5 changes: 3 additions & 2 deletions src/http/api/resources/pubsub.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict'

const PassThrough = require('stream').PassThrough
const bs58 = require('bs58')

exports = module.exports

Expand All @@ -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')
}

Expand Down
1 change: 1 addition & 0 deletions test/interop/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ require('./repo')
require('./exchange-files')
require('./circuit-relay')
require('./kad-dht')
require('./pubsub')
80 changes: 80 additions & 0 deletions test/interop/pubsub.js
Original file line number Diff line number Diff line change
@@ -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)
})
})
3 changes: 2 additions & 1 deletion test/utils/interop-daemon-spawner/go.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class GoDaemon {
this.node = null
this.api = null
this.config = opts.config || {}
this.flags = opts.flags || {}
}

start (callback) {
Expand All @@ -39,7 +40,7 @@ class GoDaemon {
this.node = node
this.node.setConfig('Bootstrap', '[]', cb)
},
(res, cb) => this.node.startDaemon(cb),
(res, cb) => this.node.startDaemon(this.flags, cb),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@richardschneider this was causing all interop tests to fail.

(api, cb) => {
this.api = api

Expand Down