feat(bootstrap): reserved p2p peers server

This commit is contained in:
Alexey Kasyanchuk
2018-04-01 01:58:37 +03:00
parent ce11073df9
commit bda58b135c

View File

@ -288,7 +288,8 @@ if(dataDirectory && fs.existsSync(dataDirectory + '/peers.p2p'))
if(config.p2pBootstrap)
{
http.get('https://api.myjson.com/bins/1e5rmh', (resp) => {
const loadBootstrapPeers = (url) => {
http.get(url, (resp) => {
let data = '';
resp.on('data', (chunk) => {
@ -307,12 +308,15 @@ if(config.p2pBootstrap)
}
}
});
}).on("error", (err) => {
console.log("Error: " + err.message);
});
}
loadBootstrapPeers('https://api.myjson.com/bins/1e5rmh')
loadBootstrapPeers('https://jsonblob.com/api/jsonBlob/013a4415-3533-11e8-8290-a901f3cf34aa')
}
let undoneQueries = 0;
let pushDatabaseBalance = () => {
undoneQueries++;
@ -760,22 +764,49 @@ this.stop = (callback) => {
console.log('local peers saved')
}
if(config.p2pBootstrap && addresses.length > 5)
if(config.p2pBootstrap)
{
const saveBootstrapPeers = (host, path, callback) => {
const options = {
port: 443,
host: 'api.myjson.com',
host,
method: 'PUT',
path: '/bins/1e5rmh',
path,
headers: {
'Content-Type' : "application/json",
}
};
console.log('bootstrap peers saved')
const req = http.request(options, close);
req.on('error', close)
console.log('bootstrap peers saved to', host)
const req = http.request(options, callback);
req.on('error', callback)
req.end(JSON.stringify({bootstrap: peersEncripted}))
}
if(addresses.length > 5)
{
saveBootstrapPeers(
'api.myjson.com',
'/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()