1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-04 10:19:35 +02:00

Make the network auto sufficient (eject bad pods with scores)

This commit is contained in:
Chocobozzz 2015-11-24 08:33:59 +01:00
parent 2e3b5b0db6
commit 3bcb78b3af
14 changed files with 310 additions and 49 deletions

View file

@ -1,6 +1,7 @@
;(function () {
'use strict'
var async = require('async')
var config = require('config')
var crypto = require('crypto')
var fs = require('fs')
@ -30,14 +31,15 @@
}
logger.debug('Sending informations to %s.', to_pod.url, { params: params })
// Default 10 but in tests we want to be faster
var retries = utils.isTestInstance() ? 2 : 10
// Replay 15 times, with factor 3
replay(
request.post(params, function (err, response, body) {
callbackEach(err, response, body, to_pod.url)
callbackEach(err, response, body, to_pod)
}),
{
retries: 10,
retries: retries,
factor: 3,
maxTimeout: Infinity,
errorCodes: [ 'EADDRINFO', 'ETIMEDOUT', 'ECONNRESET', 'ESOCKETTIMEDOUT', 'ENOTFOUND', 'ECONNREFUSED' ]
@ -68,7 +70,13 @@
}
// Make a request for each pod
for (var pod of pods) {
async.each(pods, function (pod, callback_each_async) {
function callbackEachRetryRequest (err, response, body, pod) {
callbackEach(err, response, body, pod, function () {
callback_each_async()
})
}
var params = {
url: pod.url + all_data.path,
method: all_data.method
@ -93,20 +101,18 @@
key: passwordEncrypted
}
makeRetryRequest(copy_params, copy_url, copy_pod, copy_signature, callbackEach)
makeRetryRequest(copy_params, copy_url, copy_pod, copy_signature, callbackEachRetryRequest)
})
})(crt, params, url, pod, signature)
} else {
params.json = { data: all_data.data }
makeRetryRequest(params, url, pod, signature, callbackEach)
makeRetryRequest(params, url, pod, signature, callbackEachRetryRequest)
}
} else {
logger.debug('Make a GET/DELETE request')
makeRetryRequest(params, url, pod, signature, callbackEach)
makeRetryRequest(params, url, pod, signature, callbackEachRetryRequest)
}
}
return callback()
}, callback)
}
utils.certsExist = function (callback) {
@ -192,5 +198,9 @@
process.kill(-webtorrent_process.pid)
}
utils.isTestInstance = function () {
return (process.env.NODE_ENV === 'test')
}
module.exports = utils
})()