From 13a56a4a2fd965ca87c5155bbab14b4f4c2b5220 Mon Sep 17 00:00:00 2001 From: Mikerah Date: Fri, 25 Jan 2019 18:10:26 -0500 Subject: [PATCH 1/2] feat: added a time cache and a mapping of topics to peers --- package.json | 3 ++- src/index.js | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) 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. From b1e0695b658d7c9675e288936efbebcbb9254d3d Mon Sep 17 00:00:00 2001 From: Mikerah Date: Thu, 7 Feb 2019 15:38:15 -0500 Subject: [PATCH 2/2] chore: updated package.json and linted index.js --- package.json | 2 +- src/index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index f6e9f8b7a1..12da2718b5 100644 --- a/package.json +++ b/package.json @@ -61,7 +61,7 @@ "length-prefixed-stream": "^1.6.0", "protons": "^1.0.1", "pull-pushable": "^2.2.0", - "time-cache": "^0.3.0" + "time-cache": "~0.3.0" }, "contributors": [ "Vasco Santos " diff --git a/src/index.js b/src/index.js index c2f5a3aa2e..09f52559e2 100644 --- a/src/index.js +++ b/src/index.js @@ -31,7 +31,7 @@ class PubsubBaseProtocol extends EventEmitter { this.multicodec = multicodec this.libp2p = libp2p this.started = false - + /** * Map of topics to which peers are subscribed to *