aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/mod_limits.lua
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2019-03-29 00:58:22 +0100
committerKim Alvefur <zash@zash.se>2019-03-29 00:58:22 +0100
commit9df663276b0cd3821e18a2c626cec15677ddc62d (patch)
tree1aa06d2839c504d6b8bf94fad048b01f4ca098f2 /plugins/mod_limits.lua
parent5c48dbda51bac9bf58dff9be6bc19524734ac42a (diff)
downloadprosody-9df663276b0cd3821e18a2c626cec15677ddc62d.tar.gz
prosody-9df663276b0cd3821e18a2c626cec15677ddc62d.zip
mod_limits: Use rate limiting in net.server if provided
This should be simpler and more efficient, as well avoid problems caused by using filters.
Diffstat (limited to 'plugins/mod_limits.lua')
-rw-r--r--plugins/mod_limits.lua20
1 files changed, 15 insertions, 5 deletions
diff --git a/plugins/mod_limits.lua b/plugins/mod_limits.lua
index 7ae8bb34..3c7f4d40 100644
--- a/plugins/mod_limits.lua
+++ b/plugins/mod_limits.lua
@@ -84,8 +84,13 @@ local function filter_hook(session)
local session_type = session.type:match("^[^_]+");
local filter_set, opts = type_filters[session_type], limits[session_type];
if opts then
- session.throttle = throttle.create(opts.bytes_per_second * opts.burst_seconds, opts.burst_seconds);
- filters.add_filter(session, "bytes/in", filter_set.bytes_in, 1000);
+ if session.conn and session.conn.setlimit then
+ session.conn:setlimit(opts.bytes_per_second);
+ -- Currently no burst support
+ else
+ session.throttle = throttle.create(opts.bytes_per_second * opts.burst_seconds, opts.burst_seconds);
+ filters.add_filter(session, "bytes/in", filter_set.bytes_in, 1000);
+ end
end
end
@@ -106,9 +111,14 @@ function module.add_host(module)
local session_type = session.type:match("^[^_]+");
local jid = session.username .. "@" .. session.host;
if unlimited_jids:contains(jid) then
- local filter_set = type_filters[session_type];
- filters.remove_filter(session, "bytes/in", filter_set.bytes_in);
- session.throttle = nil;
+ if session.conn and session.conn.setlimit then
+ session.conn:setlimit(0);
+ -- Currently no burst support
+ else
+ local filter_set = type_filters[session_type];
+ filters.remove_filter(session, "bytes/in", filter_set.bytes_in);
+ session.throttle = nil;
+ end
end
end);
end