Diff

mod_firewall/mod_firewall.lua @ 2128:21bc4d7cddae

mod_firewall: Add support for throttling based on user-defined properties (experimental)
author Matthew Wild <mwild1@gmail.com>
date Fri, 18 Mar 2016 09:47:52 +0000
parent 2126:b0d711cd3da5
child 2130:9239893a2400
line wrap: on
line diff
--- a/mod_firewall/mod_firewall.lua	Fri Mar 18 09:45:02 2016 +0000
+++ b/mod_firewall/mod_firewall.lua	Fri Mar 18 09:47:52 2016 +0000
@@ -108,11 +108,18 @@
 		return table.concat(defs, " ");
 	end, depends = { "date_time" }; };
 	timestamp = { global_code = [[local get_time = require "socket".gettime]]; local_code = [[local current_timestamp = get_time()]]; };
-	throttle = {
+	globalthrottle = {
 		global_code = function (throttle)
 			assert(idsafe(throttle), "Invalid rate limit name: "..throttle);
 			assert(active_definitions.RATE[throttle], "Unknown rate limit: "..throttle);
-			return ("local throttle_%s = rates.%s;"):format(throttle, throttle);
+			return ("local global_throttle_%s = rates.%s:single();"):format(throttle, throttle);
+		end;
+	};
+	multithrottle = {
+		global_code = function (throttle)
+			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);
 		end;
 	};
 };