From fce0d0b275af3f6c023b6d2a1e9a96841c74f5cb Mon Sep 17 00:00:00 2001 From: Alexey Kasyanchuk Date: Thu, 12 Jul 2018 06:52:49 +0300 Subject: [PATCH] feat(bootstrap): always load bootstrap peers when no peers situation (not only on startup) --- src/background/spider.js | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/src/background/spider.js b/src/background/spider.js index 0af7c85..487a551 100644 --- a/src/background/spider.js +++ b/src/background/spider.js @@ -228,6 +228,7 @@ app.get('*', function(req, res) }); }) + let p2pBootstrapLoop = null if(config.p2pBootstrap) { const loadBootstrapPeers = async (url) => { @@ -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; @@ -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) {