Mercurial > prosody-hg
comparison plugins/mod_limits.lua @ 11560:3bbb1af92514
Merge 0.11->trunk
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Thu, 13 May 2021 11:17:13 +0100 |
| parents | 27b275633156 db8e41eb6eff |
| children | c0fc4ca74046 |
comparison
equal
deleted
inserted
replaced
| 11538:30feeb4d9d0b | 11560:3bbb1af92514 |
|---|---|
| 29 local function parse_burst(burst, sess_type) | 29 local function parse_burst(burst, sess_type) |
| 30 if type(burst) == "string" then | 30 if type(burst) == "string" then |
| 31 burst = burst:match("^(%d+) ?s$"); | 31 burst = burst:match("^(%d+) ?s$"); |
| 32 end | 32 end |
| 33 local n_burst = tonumber(burst); | 33 local n_burst = tonumber(burst); |
| 34 if not n_burst then | 34 if burst and not n_burst then |
| 35 module:log("error", "Unable to parse burst for %s: %q, using default burst interval (%ds)", sess_type, burst, default_burst); | 35 module:log("error", "Unable to parse burst for %s: %q, using default burst interval (%ds)", sess_type, burst, default_burst); |
| 36 end | 36 end |
| 37 return n_burst or default_burst; | 37 return n_burst or default_burst; |
| 38 end | 38 end |
| 39 | 39 |
| 40 -- Process config option into limits table: | 40 -- Process config option into limits table: |
| 41 -- limits = { c2s = { bytes_per_second = X, burst_seconds = Y } } | 41 -- limits = { c2s = { bytes_per_second = X, burst_seconds = Y } } |
| 42 local limits = {}; | 42 local limits = { |
| 43 c2s = { | |
| 44 bytes_per_second = 10 * 1024; | |
| 45 burst_seconds = 2; | |
| 46 }; | |
| 47 s2sin = { | |
| 48 bytes_per_second = 30 * 1024; | |
| 49 burst_seconds = 2; | |
| 50 }; | |
| 51 }; | |
| 43 | 52 |
| 44 for sess_type, sess_limits in pairs(limits_cfg) do | 53 for sess_type, sess_limits in pairs(limits_cfg) do |
| 45 limits[sess_type] = { | 54 limits[sess_type] = { |
| 46 bytes_per_second = parse_rate(sess_limits.rate, sess_type); | 55 bytes_per_second = parse_rate(sess_limits.rate, sess_type); |
| 47 burst_seconds = parse_burst(sess_limits.burst, sess_type); | 56 burst_seconds = parse_burst(sess_limits.burst, sess_type); |
