UNPKG

ntrnetwork

Version:

Transledger peer to peer wire communication

24 lines (18 loc) 610 B
const LRUCache = require('lru-cache') const KBucket = require('./kbucket') const debug = false; class BanList { constructor () { this._lru = new LRUCache({ max: 30000 }) // 10k should be enough (each peer obj can has 3 keys) } add (obj, maxAge) { for (let key of KBucket.getKeys(obj)) { debug ? console.log(`${Date().toString().substring(0, 24)} BanList:add ${key}, size: ${this._lru.length}`) : null; this._lru.set(key, true, maxAge) } } has (obj) { return KBucket.getKeys(obj).some((key) => this._lru.get(key)) } } module.exports = BanList