comparison mod_firewall/definitions.lib.lua @ 2130:9239893a2400

mod_firewall: Don't use util.cache unless it's needed, and add explanatory error if it is not available
author Matthew Wild <mwild1@gmail.com>
date Fri, 18 Mar 2016 09:57:09 +0000
parents 21bc4d7cddae
children ba42c8882026
comparison
equal deleted inserted replaced
2129:26334f4a8eb9 2130:9239893a2400
31 function definition_handlers.RATE(name, line) 31 function definition_handlers.RATE(name, line)
32 local rate = assert(tonumber(line:match("([%d.]+)")), "Unable to parse rate"); 32 local rate = assert(tonumber(line:match("([%d.]+)")), "Unable to parse rate");
33 local burst = tonumber(line:match("%(%s*burst%s+([%d.]+)%s*%)")) or 1; 33 local burst = tonumber(line:match("%(%s*burst%s+([%d.]+)%s*%)")) or 1;
34 local max_throttles = tonumber(line:match("%(%s*entries%s+([%d]+)%s*%)")) or multirate_cache_size; 34 local max_throttles = tonumber(line:match("%(%s*entries%s+([%d]+)%s*%)")) or multirate_cache_size;
35 35
36 local cache = new_cache(max_throttles, evict_only_unthrottled);
37
38 return { 36 return {
39 single = function () 37 single = function ()
40 return new_throttle(rate*burst, burst); 38 return new_throttle(rate*burst, burst);
41 end; 39 end;
42 40
43 multi = function () 41 multi = function ()
42 local cache = new_cache(max_throttles, evict_only_unthrottled);
44 return { 43 return {
45 poll_on = function (_, key, amount) 44 poll_on = function (_, key, amount)
46 assert(key, "no key"); 45 assert(key, "no key");
47 local throttle = cache:get(key); 46 local throttle = cache:get(key);
48 if not throttle then 47 if not throttle then