Software /
code /
prosody
Diff
plugins/mod_limits.lua @ 10099:7e3196e0263e
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.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 29 Mar 2019 00:58:22 +0100 |
parent | 9943:46773fe2be45 |
child | 10111:0f335815244f |
line wrap: on
line diff
--- a/plugins/mod_limits.lua Sun Dec 18 17:39:16 2016 +0000 +++ b/plugins/mod_limits.lua Fri Mar 29 00:58:22 2019 +0100 @@ -84,8 +84,13 @@ 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 @@ 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