feat(bootstrap): always load bootstrap peers when no peers situation (not only on startup)

This commit is contained in:
Alexey Kasyanchuk 2018-07-12 06:52:49 +03:00
parent 67b0215c93
commit fce0d0b275

View File

@ -228,6 +228,7 @@ app.get('*', function(req, res)
}); });
}) })
let p2pBootstrapLoop = null
if(config.p2pBootstrap) if(config.p2pBootstrap)
{ {
const loadBootstrapPeers = async (url) => { const loadBootstrapPeers = async (url) => {
@ -262,8 +263,25 @@ app.get('*', function(req, res)
} }
} }
loadBootstrapPeers('https://api.myjson.com/bins/1e5rmh') const loadBootstrap = () => {
loadBootstrapPeers('https://jsonblob.com/api/jsonBlob/013a4415-3533-11e8-8290-a901f3cf34aa') checkInternet((connected) => {
if(!connected)
return
loadBootstrapPeers('https://api.myjson.com/bins/1e5rmh')
loadBootstrapPeers('https://jsonblob.com/api/jsonBlob/013a4415-3533-11e8-8290-a901f3cf34aa')
})
}
// first bootstrap load
loadBootstrap()
p2pBootstrapLoop = setInterval(() => {
if(p2p.size === 0)
{
console.log('load peers from bootstap again because no peers at this moment')
loadBootstrap()
}
}, 90000) // try to load new peers if there is no one found
} }
let undoneQueries = 0; let undoneQueries = 0;
@ -791,7 +809,14 @@ setInterval(() => {
// save feed // save feed
await feed.save() await feed.save()
// stop bootstrap interval
if(config.p2pBootstrap && p2pBootstrapLoop)
{
clearInterval(p2pBootstrapLoop)
console.log('bootstrap loop stoped')
}
// safe future peers // safe future peers
if(dataDirectory) if(dataDirectory)
{ {