var replay = require('request-replay')
var ursa = require('ursa')
+ var constants = require('./constants')
var logger = require('./logger')
var utils = {}
}
}
- 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
+ logger.debug('Make retry requests to %s.', to_pod.url)
replay(
request.post(params, function (err, response, body) {
- callbackEach(err, response, body, to_pod)
+ callbackEach(err, response, body, params.url, to_pod)
}),
{
- retries: retries,
+ retries: constants.REQUEST_RETRIES,
factor: 3,
maxTimeout: Infinity,
errorCodes: [ 'EADDRINFO', 'ETIMEDOUT', 'ECONNRESET', 'ESOCKETTIMEDOUT', 'ENOTFOUND', 'ECONNREFUSED' ]
// Make a request for each pod
async.each(pods, function (pod, callback_each_async) {
- function callbackEachRetryRequest (err, response, body, pod) {
- callbackEach(err, response, body, pod, function () {
+ function callbackEachRetryRequest (err, response, body, url, pod) {
+ callbackEach(err, response, body, url, pod, function () {
callback_each_async()
})
}
// Add data with POST requst ?
if (all_data.method === 'POST' && all_data.data) {
- logger.debug('Make a POST request.')
-
// Encrypt data ?
if (all_data.encrypt === true) {
var crt = ursa.createPublicKey(pod.publicKey)
makeRetryRequest(params, url, pod, signature, callbackEachRetryRequest)
}
} else {
- logger.debug('Make a GET/DELETE request')
makeRetryRequest(params, url, pod, signature, callbackEachRetryRequest)
}
}, callback)
process.kill(-webtorrent_process.pid)
}
- utils.isTestInstance = function () {
- return (process.env.NODE_ENV === 'test')
- }
-
module.exports = utils
})()