diff options
author | Kim Alvefur <zash@zash.se> | 2019-06-10 13:22:22 +0200 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2019-06-10 13:22:22 +0200 |
commit | 0269157c4511472cf0bf377d84f6e99876f83d12 (patch) | |
tree | 8cd84a76fb673cbfefa00ba1516bd16150f1c780 /plugins/mod_limits.lua | |
parent | a4764762b3dad679f40dadd6eb2eb31ea1d5cace (diff) | |
parent | 9a5a3fd0f10693e6cba2779095398614eb94e68c (diff) | |
download | prosody-0269157c4511472cf0bf377d84f6e99876f83d12.tar.gz prosody-0269157c4511472cf0bf377d84f6e99876f83d12.zip |
Merge 0.11->trunk
Diffstat (limited to 'plugins/mod_limits.lua')
-rw-r--r-- | plugins/mod_limits.lua | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/plugins/mod_limits.lua b/plugins/mod_limits.lua index 914d5c44..7ae8bb34 100644 --- a/plugins/mod_limits.lua +++ b/plugins/mod_limits.lua @@ -51,18 +51,18 @@ end local default_filter_set = {}; function default_filter_set.bytes_in(bytes, session) - local sess_throttle = session.throttle; - if sess_throttle then - local ok, balance, outstanding = sess_throttle:poll(#bytes, true); + local sess_throttle = session.throttle; + if sess_throttle then + local ok, balance, outstanding = sess_throttle:poll(#bytes, true); if not ok then - session.log("debug", "Session over rate limit (%d) with %d (by %d), pausing", sess_throttle.max, #bytes, outstanding); + session.log("debug", "Session over rate limit (%d) with %d (by %d), pausing", sess_throttle.max, #bytes, outstanding); outstanding = ceil(outstanding); session.conn:pause(); -- Read no more data from the connection until there is no outstanding data local outstanding_data = bytes:sub(-outstanding); bytes = bytes:sub(1, #bytes-outstanding); timer.add_task(limits_resolution, function () if not session.conn then return; end - if sess_throttle:peek(#outstanding_data) then + if sess_throttle:peek(#outstanding_data) then session.log("debug", "Resuming paused session"); session.conn:resume(); end @@ -96,3 +96,20 @@ end function module.unload() filters.remove_filter_hook(filter_hook); end + +function module.add_host(module) + local unlimited_jids = module:get_option_inherited_set("unlimited_jids", {}); + + if not unlimited_jids:empty() then + module:hook("authentication-success", function (event) + local session = event.session; + 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; + end + end); + end +end |