diff options
author | Kim Alvefur <zash@zash.se> | 2019-03-29 00:58:22 +0100 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2019-03-29 00:58:22 +0100 |
commit | 1f194ad556aa754c72be6aeabbdb93cd12ce57a0 (patch) | |
tree | 1aa06d2839c504d6b8bf94fad048b01f4ca098f2 /plugins/mod_limits.lua | |
parent | 97b80c860af1dd2913f457243f64276a8136b165 (diff) | |
download | prosody-1f194ad556aa754c72be6aeabbdb93cd12ce57a0.tar.gz prosody-1f194ad556aa754c72be6aeabbdb93cd12ce57a0.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.lua | 20 |
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 |