File tree 3 files changed +15
-10
lines changed
3 files changed +15
-10
lines changed Original file line number Diff line number Diff line change @@ -158,7 +158,7 @@ class FloodSub extends EventEmitter {
158
158
this . cache . put ( seqno )
159
159
160
160
// 2. emit to self
161
- this . _emitMessages ( msg . topicCIDs , [ msg . data ] )
161
+ this . _emitMessages ( msg . topicCIDs , [ msg ] )
162
162
163
163
// 3. propagate msg to others
164
164
this . _forwardMessages ( msg . topicCIDs , [ msg ] )
@@ -213,9 +213,6 @@ class FloodSub extends EventEmitter {
213
213
topics = ensureArray ( topics )
214
214
messages = ensureArray ( messages )
215
215
216
- // Emit to self if I'm interested
217
- this . _emitMessages ( topics , messages )
218
-
219
216
const from = this . libp2p . peerInfo . id . toB58String ( )
220
217
221
218
const buildMessage = ( msg ) => {
@@ -230,6 +227,11 @@ class FloodSub extends EventEmitter {
230
227
}
231
228
}
232
229
230
+ const msgObjects = messages . map ( buildMessage )
231
+
232
+ // Emit to self if I'm interested
233
+ this . _emitMessages ( topics , msgObjects )
234
+
233
235
// send to all the other peers
234
236
this . _forwardMessages ( topics , messages . map ( buildMessage ) )
235
237
}
Original file line number Diff line number Diff line change @@ -81,7 +81,7 @@ describe('basics', () => {
81
81
function shouldNotHappen ( msg ) { expect . fail ( ) }
82
82
83
83
psA . once ( 'Z' , ( msg ) => {
84
- expect ( msg . toString ( ) ) . to . equal ( 'hey' )
84
+ expect ( msg . data . toString ( ) ) . to . equal ( 'hey' )
85
85
psB . removeListener ( 'Z' , shouldNotHappen )
86
86
done ( )
87
87
} )
@@ -96,7 +96,7 @@ describe('basics', () => {
96
96
97
97
psA . once ( 'Z' , ( msg ) => {
98
98
psA . once ( 'Z' , shouldNotHappen )
99
- expect ( msg . toString ( ) ) . to . equal ( 'banana' )
99
+ expect ( msg . data . toString ( ) ) . to . equal ( 'banana' )
100
100
setTimeout ( ( ) => {
101
101
psA . removeListener ( 'Z' , shouldNotHappen )
102
102
psB . removeListener ( 'Z' , shouldNotHappen )
@@ -117,7 +117,10 @@ describe('basics', () => {
117
117
psA . on ( 'Z' , receivedMsg )
118
118
119
119
function receivedMsg ( msg ) {
120
- expect ( msg . toString ( ) ) . to . equal ( 'banana' )
120
+ expect ( msg . data . toString ( ) ) . to . equal ( 'banana' )
121
+ expect ( msg . from ) . to . be . eql ( psB . libp2p . peerInfo . id . toB58String ( ) )
122
+ expect ( Buffer . isBuffer ( msg . seqno ) ) . to . be . true
123
+ expect ( msg . topicCIDs ) . to . be . eql ( [ 'Z' ] )
121
124
122
125
if ( ++ counter === 10 ) {
123
126
psA . removeListener ( 'Z' , receivedMsg )
Original file line number Diff line number Diff line change @@ -123,7 +123,7 @@ describe('multiple nodes', () => {
123
123
a . ps . publish ( 'Z' , new Buffer ( 'hey' ) )
124
124
125
125
function incMsg ( msg ) {
126
- expect ( msg . toString ( ) ) . to . equal ( 'hey' )
126
+ expect ( msg . data . toString ( ) ) . to . equal ( 'hey' )
127
127
check ( )
128
128
}
129
129
@@ -156,7 +156,7 @@ describe('multiple nodes', () => {
156
156
b . ps . publish ( 'Z' , new Buffer ( 'hey' ) )
157
157
158
158
function incMsg ( msg ) {
159
- expect ( msg . toString ( ) ) . to . equal ( 'hey' )
159
+ expect ( msg . data . toString ( ) ) . to . equal ( 'hey' )
160
160
check ( )
161
161
}
162
162
@@ -268,7 +268,7 @@ describe('multiple nodes', () => {
268
268
c . ps . publish ( 'Z' , new Buffer ( 'hey from c' ) )
269
269
270
270
function incMsg ( msg ) {
271
- expect ( msg . toString ( ) ) . to . equal ( 'hey from c' )
271
+ expect ( msg . data . toString ( ) ) . to . equal ( 'hey from c' )
272
272
check ( )
273
273
}
274
274
You can’t perform that action at this time.
0 commit comments