Skip to content

Commit 13a56a4

Browse files
committed
feat: added a time cache and a mapping of topics to peers
1 parent 96f5334 commit 13a56a4

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@
6060
"err-code": "^1.1.2",
6161
"length-prefixed-stream": "^1.6.0",
6262
"protons": "^1.0.1",
63-
"pull-pushable": "^2.2.0"
63+
"pull-pushable": "^2.2.0",
64+
"time-cache": "^0.3.0"
6465
},
6566
"contributors": [
6667
"Vasco Santos <[email protected]>"

src/index.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const EventEmitter = require('events')
44
const pull = require('pull-stream/pull')
55
const empty = require('pull-stream/sources/empty')
66
const asyncEach = require('async/each')
7-
7+
const TimeCache = require('time-cache')
88
const debug = require('debug')
99
const errcode = require('err-code')
1010

@@ -31,6 +31,20 @@ class PubsubBaseProtocol extends EventEmitter {
3131
this.multicodec = multicodec
3232
this.libp2p = libp2p
3333
this.started = false
34+
35+
/**
36+
* Map of topics to which peers are subscribed to
37+
*
38+
* @type {Map<string, Peer>}
39+
*/
40+
this.topics = new Map()
41+
42+
/**
43+
* Cache of seen messages
44+
*
45+
* @type {TimeCache}
46+
*/
47+
this.seenCache = new TimeCache()
3448

3549
/**
3650
* Map of peers.

0 commit comments

Comments
 (0)