Skip to content

Commit

Permalink
feat: added a time cache and a mapping of topics to peers
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikerah committed Feb 7, 2019
1 parent 96f5334 commit 13a56a4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 <vasco.santos@moxy.studio>"
Expand Down
16 changes: 15 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand All @@ -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<string, Peer>}
*/
this.topics = new Map()

/**
* Cache of seen messages
*
* @type {TimeCache}
*/
this.seenCache = new TimeCache()

/**
* Map of peers.
Expand Down

0 comments on commit 13a56a4

Please sign in to comment.