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