Comparison

plugins/mod_limits.lua @ 9941:a2f8d54dd445

mod_limits: Fix indentation Appears to have been messed up in 60e113f3682f
author Kim Alvefur <zash@zash.se>
date Tue, 02 Apr 2019 21:17:28 +0200
parent 8803:60e113f3682f
child 9942:b0d5f4ae92b7
comparison
equal deleted inserted replaced
9940:5d5e3d982bdc 9941:a2f8d54dd445
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 sess_throttle = session.throttle; 54 local sess_throttle = session.throttle;
55 if sess_throttle then 55 if sess_throttle then
56 local ok, balance, outstanding = sess_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", sess_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 sess_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);