diff --git a/package.json b/package.json index 264f309619..f6e9f8b7a1 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,8 @@ "err-code": "^1.1.2", "length-prefixed-stream": "^1.6.0", "protons": "^1.0.1", - "pull-pushable": "^2.2.0" + "pull-pushable": "^2.2.0", + "time-cache": "^0.3.0" }, "contributors": [ "Vasco Santos " diff --git a/src/index.js b/src/index.js index a51c68ae7f..c2f5a3aa2e 100644 --- a/src/index.js +++ b/src/index.js @@ -4,7 +4,7 @@ const EventEmitter = require('events') const pull = require('pull-stream/pull') const empty = require('pull-stream/sources/empty') const asyncEach = require('async/each') - +const TimeCache = require('time-cache') const debug = require('debug') const errcode = require('err-code') @@ -31,6 +31,20 @@ class PubsubBaseProtocol extends EventEmitter { this.multicodec = multicodec this.libp2p = libp2p this.started = false + + /** + * Map of topics to which peers are subscribed to + * + * @type {Map} + */ + this.topics = new Map() + + /** + * Cache of seen messages + * + * @type {TimeCache} + */ + this.seenCache = new TimeCache() /** * Map of peers.