Skip to content

Commit

Permalink
feat(bootstrap): always load bootstrap peers when no peers situation …
Browse files Browse the repository at this point in the history
…(not only on startup)
  • Loading branch information
DEgITx committed Jul 12, 2018
1 parent 6ec6609 commit 3a5c934
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions src/background/spider.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ app.get('*', function(req, res)
});
})

let p2pBootstrapLoop = null
if(config.p2pBootstrap)
{
const loadBootstrapPeers = async (url) => {
Expand Down Expand Up @@ -262,8 +263,25 @@ app.get('*', function(req, res)
}
}

loadBootstrapPeers('https://api.myjson.com/bins/1e5rmh')
loadBootstrapPeers('https://jsonblob.com/api/jsonBlob/013a4415-3533-11e8-8290-a901f3cf34aa')
const loadBootstrap = () => {
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;
Expand Down Expand Up @@ -791,7 +809,14 @@ setInterval(() => {

// save feed
await feed.save()


// stop bootstrap interval
if(config.p2pBootstrap && p2pBootstrapLoop)
{
clearInterval(p2pBootstrapLoop)
console.log('bootstrap loop stoped')
}

// safe future peers
if(dataDirectory)
{
Expand Down

0 comments on commit 3a5c934

Please sign in to comment.