Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

Pubsub do not eat error messages #632

Merged
merged 3 commits into from
Nov 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/pubsub.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ module.exports = (arg) => {

function subscribe (topic, options, handler, callback) {
ps.on(topic, handler)

if (subscriptions[topic]) {
return callback()
}
Expand Down
17 changes: 9 additions & 8 deletions src/utils/pubsub-message-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,18 @@ class PubsubMessageStream extends TransformStream {
}

_transform (obj, enc, callback) {
let msg
try {
msg = PubsubMessage.deserialize(obj, 'base64')
} catch (err) {
// Not a valid pubsub message
// go-ipfs returns '{}' as the very first object atm, we skip that
// go-ipfs returns '{}' as the very first object atm, we skip that
if (Object.keys(obj).length === 0) {
return callback()
}

this.push(msg)
callback()
try {
const msg = PubsubMessage.deserialize(obj, 'base64')
this.push(msg)
callback()
} catch (err) {
return callback(err)
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/utils/pubsub-message-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ function deserializeFromBase64 (obj) {
from: bs58.encode(Buffer.from(obj.from, 'base64')).toString(),
seqno: Buffer.from(obj.seqno, 'base64'),
data: Buffer.from(obj.data, 'base64'),
topicIDs: obj.topicIDs
topicIDs: obj.topicIDs || obj.topicCIDs
}
}

function isPubsubMessage (obj) {
return obj && obj.from && obj.seqno && obj.data && obj.topicIDs
return obj && obj.from && obj.seqno && obj.data && (obj.topicIDs || obj.topicCIDs)
}