add rateLimiter to estimateFee

This commit is contained in:
Matias Alejo Garcia 2017-10-19 14:52:53 -03:00
parent ffea739a19
commit 9d6af8cd0e
No known key found for this signature in database
GPG Key ID: 02470DB551277AB3
2 changed files with 24 additions and 2 deletions

View File

@ -108,6 +108,15 @@ Defaults.RateLimit = {
max: 20, // start blocking after 20 request
message: "Too many wallets created from this IP, please try again after an hour"
},
estimateFee: {
windowMs: 60 * 10 *1000, // 10 min window
delayAfter: 10, // begin slowing down responses after the 3rd request
delayMs: 300, // slow down subsequent responses by 3 seconds per request
max: 20, // start blocking after 200 request
message: "Too many request"
},
// otherPosts: {
// windowMs: 60 * 60 * 1000, // 1 hour window
// max: 1200 , // 1 post every 3 sec average, max.

View File

@ -431,8 +431,21 @@ ExpressApp.prototype.start = function(opts, cb) {
});
});
var estimateFeeLimiter;
if (Defaults.RateLimit.estimateFee && !opts.ignoreRateLimiter) {
log.info('', 'Limiting estimate fee per IP: %d req/h', (Defaults.RateLimit.estimateFee.max / Defaults.RateLimit.estimateFee.windowMs * 60 * 60 * 1000).toFixed(2))
estimateFeeLimiter = new RateLimit(Defaults.RateLimit.estimateFee);
// router.use(/\/v\d+\/wallets\/$/, createWalletLimiter)
} else {
estimateFeeLimiter = function(req, res, next) {
next()
};
}
// DEPRECATED
router.get('/v1/feelevels/', function(req, res) {
router.get('/v1/feelevels/', estimateFeeLimiter, function(req, res) {
logDeprecated(req);
var opts = {};
if (req.query.network) opts.network = req.query.network;
@ -452,7 +465,7 @@ ExpressApp.prototype.start = function(opts, cb) {
});
});
router.get('/v2/feelevels/', function(req, res) {
router.get('/v2/feelevels/', estimateFeeLimiter, function(req, res) {
var opts = {};
if (req.query.coin) opts.coin = req.query.coin;
if (req.query.network) opts.network = req.query.network;