refactor(closing): refactoring saving peers on closing
This commit is contained in:
parent
0df65846e6
commit
5daf9f5c65
@ -770,23 +770,13 @@ if(config.spaceQuota)
|
|||||||
quotaDebug('disk quota enabled');
|
quotaDebug('disk quota enabled');
|
||||||
}
|
}
|
||||||
|
|
||||||
this.stop = (callback) => {
|
this.stop = async (callback) => {
|
||||||
console.log('spider closing...')
|
console.log('spider closing...')
|
||||||
if(upnp)
|
if(upnp)
|
||||||
upnp.ratsUnmap()
|
upnp.ratsUnmap()
|
||||||
|
|
||||||
console.log('closing p2p...')
|
console.log('closing p2p...')
|
||||||
p2p.close()
|
p2p.close()
|
||||||
|
|
||||||
const close = () => {
|
|
||||||
torrentClient.destroy(() => {
|
|
||||||
sphinx.end(() => spider.close(() => {
|
|
||||||
mysqlSingle.destroy()
|
|
||||||
console.log('spider closed')
|
|
||||||
callback()
|
|
||||||
}))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// safe future peers
|
// safe future peers
|
||||||
if(dataDirectory)
|
if(dataDirectory)
|
||||||
@ -801,10 +791,10 @@ this.stop = (callback) => {
|
|||||||
|
|
||||||
if(config.p2pBootstrap)
|
if(config.p2pBootstrap)
|
||||||
{
|
{
|
||||||
const saveBootstrapPeers = (host, path, callback) => {
|
const saveBootstrapPeers = (host, path) => new Promise(resolve => {
|
||||||
if(env === 'test')
|
if(env === 'test')
|
||||||
{
|
{
|
||||||
callback()
|
resolve()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -818,45 +808,25 @@ this.stop = (callback) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
console.log('bootstrap peers saved to', host)
|
console.log('bootstrap peers saved to', host)
|
||||||
const req = http.request(options, callback);
|
const req = http.request(options, resolve);
|
||||||
req.on('error', callback)
|
req.on('error', resolve)
|
||||||
req.end(JSON.stringify({bootstrap: peersEncripted}))
|
req.end(JSON.stringify({bootstrap: peersEncripted}))
|
||||||
}
|
})
|
||||||
|
|
||||||
if(addresses.length > 5)
|
if(addresses.length > 5)
|
||||||
{
|
await saveBootstrapPeers('api.myjson.com', '/bins/1e5rmh')
|
||||||
saveBootstrapPeers(
|
if(addresses.length > 0)
|
||||||
'api.myjson.com',
|
await saveBootstrapPeers('jsonblob.com', '/api/jsonBlob/013a4415-3533-11e8-8290-a901f3cf34aa')
|
||||||
'/bins/1e5rmh',
|
|
||||||
() => saveBootstrapPeers(
|
|
||||||
'jsonblob.com',
|
|
||||||
'/api/jsonBlob/013a4415-3533-11e8-8290-a901f3cf34aa',
|
|
||||||
close
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
else if(addresses.length > 0)
|
|
||||||
{
|
|
||||||
saveBootstrapPeers(
|
|
||||||
'jsonblob.com',
|
|
||||||
'/api/jsonBlob/013a4415-3533-11e8-8290-a901f3cf34aa',
|
|
||||||
close
|
|
||||||
)
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
close()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
close()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
torrentClient.destroy(() => {
|
||||||
close()
|
sphinx.end(() => spider.close(() => {
|
||||||
}
|
mysqlSingle.destroy()
|
||||||
|
console.log('spider closed')
|
||||||
|
callback()
|
||||||
|
}))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
return this
|
return this
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user