-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
37 lines (30 loc) · 964 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
'use strict'
const { DWebDHT } = require('@dswarm/dht')
const LRU = require('hashlru')
const { UserStore, RoomStore } = require('./stores')
const { MutableUser } = require('./mutable-stores')
module.exports = opts => new USwarm(opts)
class USwarm extends DWebDHT {
constructor (opts) {
if (!opts) opts = {}
super(opts)
const {
maxAge = 12 * 60 * 1000,
maxValues = 5000
} = opts
this._store = LRU(maxValues)
this.user = new UserStore(this, this._store)
this.room = new RoomStore(this, this._store)
this.muser = new MutableUser(this, this._store)
// Kademilia DHT custom commands
this.command('user-store', this.user._command())
this.command('room-store', this.room._command())
this.command('mutable-user', this.muser._command())
}
getUser (username, cb) {
return this.query('user-store', username, cb)
}
getRoom (roomName, cb) {
return this.query('room-store', roomName, cb)
}
}