fix(config): saving config restored

This commit is contained in:
Alexey Kasyanchuk 2018-02-02 20:10:07 +03:00
parent 316072008a
commit fa1512dee5
3 changed files with 16 additions and 4 deletions

View File

@ -39,7 +39,6 @@ class Spider extends Emiter {
constructor(client) { constructor(client) {
super() super()
const options = arguments.length? arguments[0]: {} const options = arguments.length? arguments[0]: {}
this.udp = dgram.createSocket('udp4')
this.table = new Table(options.tableCaption || 1000) this.table = new Table(options.tableCaption || 1000)
this.bootstraps = options.bootstraps || bootstraps this.bootstraps = options.bootstraps || bootstraps
this.token = new Token() this.token = new Token()
@ -225,6 +224,8 @@ class Spider extends Emiter {
return return
this.initialized = true this.initialized = true
this.closing = false
this.udp = dgram.createSocket('udp4')
this.udp.bind(port) this.udp.bind(port)
this.udp.on('listening', () => { this.udp.on('listening', () => {
console.log(`Listen DHT protocol on ${this.udp.address().address}:${this.udp.address().port}`) console.log(`Listen DHT protocol on ${this.udp.address().address}:${this.udp.address().port}`)
@ -270,6 +271,11 @@ class Spider extends Emiter {
close(callback) close(callback)
{ {
if(!this.initialized) {
if(callback)
callback()
return
}
clearInterval(this.joinInterval) clearInterval(this.joinInterval)
if(this.trafficInterval) if(this.trafficInterval)
clearInterval(this.trafficInterval) clearInterval(this.trafficInterval)

View File

@ -51,7 +51,6 @@ if(app.getPath("userData") && app.getPath("userData").length > 0)
const configProxy = new Proxy(config, { const configProxy = new Proxy(config, {
set: (target, prop, value, receiver) => { set: (target, prop, value, receiver) => {
target[prop] = value target[prop] = value
console.log('set op', configPath)
if(!fs.existsSync(configPath)) if(!fs.existsSync(configPath))
fs.writeFileSync(configPath, '{}') fs.writeFileSync(configPath, '{}')

View File

@ -544,10 +544,17 @@ setInterval(() => {
if(typeof options !== 'object') if(typeof options !== 'object')
return; return;
if(typeof options.indexer !== 'undefined')
{
if(options.indexer)
spider.listen(config.spiderPort)
else
spider.close()
}
for(const option in options) for(const option in options)
{ {
console.log('set', option, options[option]) if(option in config)
if(config[option])
config[option] = options[option] config[option] = options[option]
} }