Software /
code /
prosody
Comparison
plugins/mod_limits.lua @ 11734:c0fc4ca74046
mod_limits: Factor out function for disabling limits allowing use from shell
Also enables reuse for s2s, which we will add next.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 29 Jul 2021 20:11:48 +0200 |
parent | 11560:3bbb1af92514 |
child | 11735:7d29167bfcc3 |
comparison
equal
deleted
inserted
replaced
11733:27699cc148df | 11734:c0fc4ca74046 |
---|---|
109 | 109 |
110 function module.unload() | 110 function module.unload() |
111 filters.remove_filter_hook(filter_hook); | 111 filters.remove_filter_hook(filter_hook); |
112 end | 112 end |
113 | 113 |
114 function unlimited(session) | |
115 local session_type = session.type:match("^[^_]+"); | |
116 if session.conn and session.conn.setlimit then | |
117 session.conn:setlimit(0); | |
118 -- Currently no burst support | |
119 else | |
120 local filter_set = type_filters[session_type]; | |
121 filters.remove_filter(session, "bytes/in", filter_set.bytes_in); | |
122 session.throttle = nil; | |
123 end | |
124 end | |
125 | |
114 function module.add_host(module) | 126 function module.add_host(module) |
115 local unlimited_jids = module:get_option_inherited_set("unlimited_jids", {}); | 127 local unlimited_jids = module:get_option_inherited_set("unlimited_jids", {}); |
116 | 128 |
117 if not unlimited_jids:empty() then | 129 if not unlimited_jids:empty() then |
118 module:hook("authentication-success", function (event) | 130 module:hook("authentication-success", function (event) |
119 local session = event.session; | 131 local session = event.session; |
120 local session_type = session.type:match("^[^_]+"); | |
121 local jid = session.username .. "@" .. session.host; | 132 local jid = session.username .. "@" .. session.host; |
122 if unlimited_jids:contains(jid) then | 133 if unlimited_jids:contains(jid) then |
123 if session.conn and session.conn.setlimit then | 134 unlimited(session); |
124 session.conn:setlimit(0); | |
125 -- Currently no burst support | |
126 else | |
127 local filter_set = type_filters[session_type]; | |
128 filters.remove_filter(session, "bytes/in", filter_set.bytes_in); | |
129 session.throttle = nil; | |
130 end | |
131 end | 135 end |
132 end); | 136 end); |
133 end | 137 end |
134 end | 138 end |