Software /
code /
prosody
Comparison
plugins/mod_limits.lua @ 8803:60e113f3682f
mod_limits: Rename variable to avoid name clash [luacheck]
FIXME better name, s_throttle doesn't seem nice
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 02 May 2018 13:58:28 +0200 |
parent | 8453:6b3e7fddd723 |
child | 9941:a2f8d54dd445 |
child | 11550:929de6ade6b6 |
comparison
equal
deleted
inserted
replaced
8802:befffddf1b25 | 8803:60e113f3682f |
---|---|
49 end | 49 end |
50 | 50 |
51 local default_filter_set = {}; | 51 local default_filter_set = {}; |
52 | 52 |
53 function default_filter_set.bytes_in(bytes, session) | 53 function default_filter_set.bytes_in(bytes, session) |
54 local throttle = session.throttle; | 54 local sess_throttle = session.throttle; |
55 if throttle then | 55 if sess_throttle then |
56 local ok, balance, outstanding = throttle:poll(#bytes, true); | 56 local ok, balance, outstanding = sess_throttle:poll(#bytes, true); |
57 if not ok then | 57 if not ok then |
58 session.log("debug", "Session over rate limit (%d) with %d (by %d), pausing", throttle.max, #bytes, outstanding); | 58 session.log("debug", "Session over rate limit (%d) with %d (by %d), pausing", sess_throttle.max, #bytes, outstanding); |
59 outstanding = ceil(outstanding); | 59 outstanding = ceil(outstanding); |
60 session.conn:pause(); -- Read no more data from the connection until there is no outstanding data | 60 session.conn:pause(); -- Read no more data from the connection until there is no outstanding data |
61 local outstanding_data = bytes:sub(-outstanding); | 61 local outstanding_data = bytes:sub(-outstanding); |
62 bytes = bytes:sub(1, #bytes-outstanding); | 62 bytes = bytes:sub(1, #bytes-outstanding); |
63 timer.add_task(limits_resolution, function () | 63 timer.add_task(limits_resolution, function () |
64 if not session.conn then return; end | 64 if not session.conn then return; end |
65 if throttle:peek(#outstanding_data) then | 65 if sess_throttle:peek(#outstanding_data) then |
66 session.log("debug", "Resuming paused session"); | 66 session.log("debug", "Resuming paused session"); |
67 session.conn:resume(); | 67 session.conn:resume(); |
68 end | 68 end |
69 -- Handle what we can of the outstanding data | 69 -- Handle what we can of the outstanding data |
70 session.data(outstanding_data); | 70 session.data(outstanding_data); |