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

Commit 9de6f4c

Browse files
richardschneiderdaviddias
authored andcommitted
fix: pubsub message fields (#1077)
* fix(pubsub): topicCIDs should be topicIDs * fix(pubsub): msg.from field is base64 encoding of peer id * fix: oops * chore: update deps * write interop test setup for richard * fix: allow go daemon flags to be specified * test: pubsub interop with go (WIP) * chore: fix linting * fix more linting * fix interop tests
1 parent cafa52b commit 9de6f4c

File tree

5 files changed

+90
-5
lines changed

5 files changed

+90
-5
lines changed

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
"form-data": "^2.3.1",
7676
"gulp": "^3.9.1",
7777
"hat": "0.0.3",
78-
"interface-ipfs-core": "~0.34.3",
78+
"interface-ipfs-core": "~0.35.0",
7979
"ipfsd-ctl": "~0.24.1",
8080
"left-pad": "^1.1.3",
8181
"lodash": "^4.17.4",
@@ -94,6 +94,7 @@
9494
"async": "^2.6.0",
9595
"bl": "^1.2.1",
9696
"boom": "^7.1.1",
97+
"bs58": "^4.0.1",
9798
"byteman": "^1.3.5",
9899
"cids": "^0.5.2",
99100
"debug": "^3.1.0",
@@ -105,7 +106,7 @@
105106
"hapi": "^16.6.2",
106107
"hapi-set-header": "^1.0.2",
107108
"hoek": "^5.0.2",
108-
"ipfs-api": "^15.1.0",
109+
"ipfs-api": "^16.0.0",
109110
"ipfs-bitswap": "~0.17.4",
110111
"ipfs-block": "~0.6.1",
111112
"ipfs-block-service": "~0.13.0",
@@ -119,7 +120,7 @@
119120
"joi": "^13.0.2",
120121
"libp2p": "~0.13.1",
121122
"libp2p-circuit": "~0.1.4",
122-
"libp2p-floodsub": "~0.11.1",
123+
"libp2p-floodsub": "~0.12.0",
123124
"libp2p-kad-dht": "~0.6.0",
124125
"libp2p-mdns": "~0.9.1",
125126
"libp2p-multiplex": "~0.5.0",

src/http/api/resources/pubsub.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict'
22

33
const PassThrough = require('stream').PassThrough
4+
const bs58 = require('bs58')
45

56
exports = module.exports
67

@@ -20,10 +21,10 @@ exports.subscribe = {
2021

2122
const handler = (msg) => {
2223
res.write(JSON.stringify({
23-
from: msg.from,
24+
from: bs58.decode(msg.from).toString('base64'),
2425
data: msg.data.toString('base64'),
2526
seqno: msg.seqno.toString('base64'),
26-
topicCIDs: msg.topicCIDs
27+
topicIDs: msg.topicIDs
2728
}) + '\n', 'utf8')
2829
}
2930

test/interop/node.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ require('./repo')
55
require('./exchange-files')
66
require('./circuit-relay')
77
require('./kad-dht')
8+
require('./pubsub')

test/interop/pubsub.js

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/* eslint-env mocha */
2+
'use strict'
3+
4+
const chai = require('chai')
5+
const dirtyChai = require('dirty-chai')
6+
const expect = chai.expect
7+
chai.use(dirtyChai)
8+
const series = require('async/series')
9+
const parallel = require('async/parallel')
10+
11+
const GODaemon = require('../utils/interop-daemon-spawner/go')
12+
const JSDaemon = require('../utils/interop-daemon-spawner/js')
13+
14+
describe('pubsub', () => {
15+
let jsD
16+
let goD
17+
let jsId
18+
let goId
19+
20+
before(function (done) {
21+
this.timeout(50 * 1000)
22+
23+
goD = new GODaemon({
24+
disposable: true,
25+
init: true,
26+
flags: ['--enable-pubsub-experiment']
27+
})
28+
jsD = new JSDaemon()
29+
30+
parallel([
31+
(cb) => goD.start(cb),
32+
(cb) => jsD.start(cb)
33+
], (done))
34+
})
35+
36+
after((done) => {
37+
series([
38+
(cb) => goD.stop(cb),
39+
(cb) => jsD.stop(cb)
40+
], done)
41+
})
42+
43+
it('make connections', (done) => {
44+
parallel([
45+
(cb) => jsD.api.id(cb),
46+
(cb) => goD.api.id(cb)
47+
], (err, ids) => {
48+
expect(err).to.not.exist()
49+
50+
jsId = ids[0].ID
51+
goId = ids[0].ID
52+
53+
console.log('jsId:', jsId)
54+
console.log('goId:', goId)
55+
56+
parallel([
57+
(cb) => jsD.api.swarm.connect(ids[1].addresses[0], cb),
58+
(cb) => goD.api.swarm.connect(ids[0].addresses[0], cb)
59+
], done)
60+
})
61+
})
62+
63+
it.skip('publish from JS, subscribe on Go', (done) => {
64+
// TODO write this test
65+
})
66+
67+
it.skip('publish from Go, subscribe on JS', (done) => {
68+
const topic = 'pubsub-go-js'
69+
const data = Buffer.from('hello world')
70+
71+
function checkMessage () {
72+
console.log('check message', arguments)
73+
}
74+
75+
series([
76+
cb => jsD.api.pubsub.subscribe(topic, checkMessage, cb),
77+
cb => goD.api.pubsub.publish(topic, data, cb)
78+
], done)
79+
})
80+
})

test/utils/interop-daemon-spawner/go.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class GoDaemon {
1616
this.node = null
1717
this.api = null
1818
this.config = opts.config || {}
19+
this.flags = opts.flags || {}
1920
}
2021

2122
start (callback) {
@@ -40,6 +41,7 @@ class GoDaemon {
4041
this.node.setConfig('Bootstrap', '[]', cb)
4142
},
4243
(res, cb) => this.node.startDaemon(cb),
44+
// (res, cb) => this.node.startDaemon(this.flags, cb),
4345
(api, cb) => {
4446
this.api = api
4547

0 commit comments

Comments
 (0)