1
1
'use strict'
2
2
3
- const TimeCache = require ( 'time-cache' )
4
3
const pull = require ( 'pull-stream' )
5
4
const lp = require ( 'pull-length-prefixed' )
6
5
const assert = require ( 'assert' )
@@ -27,13 +26,6 @@ class FloodSub extends BaseProtocol {
27
26
constructor ( libp2p ) {
28
27
super ( 'libp2p:floodsub' , multicodec , libp2p )
29
28
30
- /**
31
- * Time based cache for sequence numbers.
32
- *
33
- * @type {TimeCache }
34
- */
35
- this . cache = new TimeCache ( )
36
-
37
29
/**
38
30
* List of our subscriptions
39
31
* @type {Set<string> }
@@ -109,11 +101,11 @@ class FloodSub extends BaseProtocol {
109
101
msgs . forEach ( ( msg ) => {
110
102
const seqno = utils . msgId ( msg . from , msg . seqno )
111
103
// 1. check if I've seen the message, if yes, ignore
112
- if ( this . cache . has ( seqno ) ) {
104
+ if ( this . seenCache . has ( seqno ) ) {
113
105
return
114
106
}
115
107
116
- this . cache . put ( seqno )
108
+ this . seenCache . put ( seqno )
117
109
118
110
// 2. emit to self
119
111
this . _emitMessages ( msg . topicIDs , [ msg ] )
@@ -182,7 +174,7 @@ class FloodSub extends BaseProtocol {
182
174
183
175
const buildMessage = ( msg ) => {
184
176
const seqno = utils . randomSeqno ( )
185
- this . cache . put ( utils . msgId ( from , seqno ) )
177
+ this . seenCache . put ( utils . msgId ( from , seqno ) )
186
178
187
179
return {
188
180
from : from ,
0 commit comments