changeset 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 (2016-03-18)
parents 26334f4a8eb9
children ba42c8882026
files mod_firewall/definitions.lib.lua mod_firewall/mod_firewall.lua
diffstat 2 files changed, 2 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mod_firewall/definitions.lib.lua	Fri Mar 18 09:51:01 2016 +0000
+++ b/mod_firewall/definitions.lib.lua	Fri Mar 18 09:57:09 2016 +0000
@@ -33,14 +33,13 @@
 			local burst = tonumber(line:match("%(%s*burst%s+([%d.]+)%s*%)")) or 1;
 			local max_throttles = tonumber(line:match("%(%s*entries%s+([%d]+)%s*%)")) or multirate_cache_size;
 
-			local cache = new_cache(max_throttles, evict_only_unthrottled);
-
 			return {
 				single = function ()
 					return new_throttle(rate*burst, burst);
 				end;
 				
 				multi = function ()
+					local cache = new_cache(max_throttles, evict_only_unthrottled);
 					return {
 						poll_on = function (_, key, amount)
 							assert(key, "no key");
--- a/mod_firewall/mod_firewall.lua	Fri Mar 18 09:51:01 2016 +0000
+++ b/mod_firewall/mod_firewall.lua	Fri Mar 18 09:57:09 2016 +0000
@@ -117,6 +117,7 @@
 	};
 	multithrottle = {
 		global_code = function (throttle)
+			assert(pcall(require, "util.cache"), "Using LIMIT with 'on' requires Prosody 0.10 or higher");
 			assert(idsafe(throttle), "Invalid rate limit name: "..throttle);
 			assert(active_definitions.RATE[throttle], "Unknown rate limit: "..throttle);
 			return ("local multi_throttle_%s = rates.%s:multi();"):format(throttle, throttle);