Skip to content

Commit

Permalink
fix: pass subscriptions immediately on new peer connection (#10)
Browse files Browse the repository at this point in the history
* fix: pass subscriptions immediately on new peer connection

* test: add test to ensure subs are passed on connection

* test: remove .only
  • Loading branch information
gavinmcdermott authored and daviddias committed Dec 11, 2016
1 parent 7391fe7 commit 078383a
Show file tree
Hide file tree
Showing 3 changed files with 239 additions and 135 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -65,4 +65,4 @@
"Gavin McDermott <gavinmcdermott@gmail.com>",
"Haad <haadcode@users.noreply.github.com>"
]
}
}
14 changes: 13 additions & 1 deletion src/dial-floodsub.js
@@ -1,6 +1,7 @@
'use strict'

const config = require('./config')
const pb = require('./message')
const log = config.log
const multicodec = config.multicodec
const stream = require('stream')
Expand Down Expand Up @@ -50,8 +51,19 @@ module.exports = (libp2pNode, peerSet, subscriptions) => {
conn
)

// Immediately send my own subscriptions to the newly established conn
if (subscriptions.length > 0) {
// TODO send my subscriptions through the new conn
const subopts = subscriptions.map((topic) => {
return {
subscribe: true,
topicCID: topic
}
})
const rpc = pb.rpc.RPC.encode({
subscriptions: subopts
})

peerSet[idB58Str].stream.write(rpc)
}
}
}
Expand Down

0 comments on commit 078383a

Please sign in to comment.