refactor: peristent peer-store extended class and disabled by defaul

This commit is contained in:
Vasco Santos
2020-05-01 15:52:06 +02:00
committed by Jacob Heun
parent 9ea9287bea
commit 48a9a3eecc
16 changed files with 695 additions and 386 deletions

View File

@ -32,18 +32,10 @@ class PeerStore extends EventEmitter {
/**
* @constructor
* @param {Object} properties
* @param {Datastore} [properties.datastore] Datastore to persist data.
* @param {boolean} [properties.persistance = true] Persist peerstore data.
*/
constructor ({ datastore, persistance = true } = {}) {
constructor () {
super()
/**
* Backend datastore used to persist data.
*/
this._datastore = datastore
/**
* AddressBook containing a map of peerIdStr to Address.
*/
@ -60,19 +52,17 @@ class PeerStore extends EventEmitter {
* @type {Map<string, Array<PeerId>}
*/
this.peerIds = new Map()
this._enabledPersistance = persistance
}
/**
* Load data from the datastore to populate the PeerStore.
* Start the PeerStore.
*/
async load () {
if (this._enabledPersistance) {
await this.addressBook._loadData()
await this.protoBook._loadData()
}
}
start () {}
/**
* Stop the PeerStore.
*/
stop () {}
/**
* Get all the stored information of every peer.