Skip to content

Commit 078383a

Browse files
gavinmcdermottdaviddias
authored andcommitted
fix: pass subscriptions immediately on new peer connection (#10)
* fix: pass subscriptions immediately on new peer connection * test: add test to ensure subs are passed on connection * test: remove .only
1 parent 7391fe7 commit 078383a

File tree

3 files changed

+239
-135
lines changed

3 files changed

+239
-135
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,4 @@
6565
"Gavin McDermott <gavinmcdermott@gmail.com>",
6666
"Haad <haadcode@users.noreply.github.com>"
6767
]
68-
}
68+
}

src/dial-floodsub.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict'
22

33
const config = require('./config')
4+
const pb = require('./message')
45
const log = config.log
56
const multicodec = config.multicodec
67
const stream = require('stream')
@@ -50,8 +51,19 @@ module.exports = (libp2pNode, peerSet, subscriptions) => {
5051
conn
5152
)
5253

54+
// Immediately send my own subscriptions to the newly established conn
5355
if (subscriptions.length > 0) {
54-
// TODO send my subscriptions through the new conn
56+
const subopts = subscriptions.map((topic) => {
57+
return {
58+
subscribe: true,
59+
topicCID: topic
60+
}
61+
})
62+
const rpc = pb.rpc.RPC.encode({
63+
subscriptions: subopts
64+
})
65+
66+
peerSet[idB58Str].stream.write(rpc)
5567
}
5668
}
5769
}

0 commit comments

Comments
 (0)