Mercurial > prosody-modules
comparison mod_muc_limits/mod_muc_limits.lua @ 3188:5c3f3f5a4377
Backed out parts of changeset a81456a13797
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 18 Jul 2018 15:57:13 +0200 |
parents | a81456a13797 |
children | 6a3060d5e85d |
comparison
equal
deleted
inserted
replaced
3187:7c450c27d4ba | 3188:5c3f3f5a4377 |
---|---|
23 module:log("warn", "Dropped %d stanzas from %d JIDs: %s", dropped_count, #dropped_jids, t_concat(dropped_jids, ", ")); | 23 module:log("warn", "Dropped %d stanzas from %d JIDs: %s", dropped_count, #dropped_jids, t_concat(dropped_jids, ", ")); |
24 dropped_count = 0; | 24 dropped_count = 0; |
25 dropped_jids = nil; | 25 dropped_jids = nil; |
26 end | 26 end |
27 | 27 |
28 local function get_non_outcast_affiliations(room) | |
29 local nmembers = 0; | |
30 -- this is an evil hack, we probably should not access _affiliations | |
31 -- directly ... | |
32 for _, aff in pairs(room._affiliations) do | |
33 if aff ~= "outcast" then | |
34 nmembers = nmembers + 1; | |
35 end | |
36 end | |
37 return nmembers; | |
38 end | |
39 | |
40 local function handle_stanza(event) | 28 local function handle_stanza(event) |
41 local origin, stanza = event.origin, event.stanza; | 29 local origin, stanza = event.origin, event.stanza; |
42 if stanza.name == "presence" and stanza.attr.type == "unavailable" then -- Don't limit room leaving | 30 if stanza.name == "presence" and stanza.attr.type == "unavailable" then -- Don't limit room leaving |
43 return; | 31 return; |
44 end | 32 end |
59 local throttle = room.throttle; | 47 local throttle = room.throttle; |
60 if not room.throttle then | 48 if not room.throttle then |
61 throttle = new_throttle(period*burst, burst); | 49 throttle = new_throttle(period*burst, burst); |
62 room.throttle = throttle; | 50 room.throttle = throttle; |
63 end | 51 end |
64 | 52 if not throttle:poll(1) then |
65 local cost = 1; | |
66 -- we scale the cost by the inverse of the square root of the number of | |
67 -- members; this should effectively raise the limit by a factor of | |
68 -- sqrt(nmembers) | |
69 local nmembers = math.max(get_non_outcast_affiliations(room), 1); | |
70 cost = cost / math.sqrt(nmembers); | |
71 | |
72 if not throttle:poll(cost) then | |
73 module:log("debug", "Dropping stanza for %s@%s from %s, over rate limit", dest_room, dest_host, from_jid); | 53 module:log("debug", "Dropping stanza for %s@%s from %s, over rate limit", dest_room, dest_host, from_jid); |
74 if not dropped_jids then | 54 if not dropped_jids then |
75 dropped_jids = { [from_jid] = true, from_jid }; | 55 dropped_jids = { [from_jid] = true, from_jid }; |
76 module:add_timer(5, log_dropped); | 56 module:add_timer(5, log_dropped); |
77 elseif not dropped_jids[from_jid] then | 57 elseif not dropped_jids[from_jid] then |