comparison mod_firewall/definitions.lib.lua @ 2370:5fe483b73fd2

mod_firewall: Rate limiting: Document 'entries' and add option to allow overflowing when full
author Matthew Wild <mwild1@gmail.com>
date Tue, 15 Nov 2016 21:55:12 +0000
parents ba42c8882026
children c6fd8975704b
comparison
equal deleted inserted replaced
2369:2fb11d34087e 2370:5fe483b73fd2
29 29
30 function definition_handlers.RATE(name, line) 30 function definition_handlers.RATE(name, line)
31 local rate = assert(tonumber(line:match("([%d.]+)")), "Unable to parse rate"); 31 local rate = assert(tonumber(line:match("([%d.]+)")), "Unable to parse rate");
32 local burst = tonumber(line:match("%(%s*burst%s+([%d.]+)%s*%)")) or 1; 32 local burst = tonumber(line:match("%(%s*burst%s+([%d.]+)%s*%)")) or 1;
33 local max_throttles = tonumber(line:match("%(%s*entries%s+([%d]+)%s*%)")) or multirate_cache_size; 33 local max_throttles = tonumber(line:match("%(%s*entries%s+([%d]+)%s*%)")) or multirate_cache_size;
34 34 local deny_when_full = not line:match("%(allow overflow%)");
35 return { 35 return {
36 single = function () 36 single = function ()
37 return new_throttle(rate*burst, burst); 37 return new_throttle(rate*burst, burst);
38 end; 38 end;
39 39
40 multi = function () 40 multi = function ()
41 local cache = require "util.cache".new(max_throttles, evict_only_unthrottled); 41 local cache = require "util.cache".new(max_throttles, deny_when_full and evict_only_unthrottled or nil);
42 return { 42 return {
43 poll_on = function (_, key, amount) 43 poll_on = function (_, key, amount)
44 assert(key, "no key"); 44 assert(key, "no key");
45 local throttle = cache:get(key); 45 local throttle = cache:get(key);
46 if not throttle then 46 if not throttle then