Mercurial > prosody-modules
comparison mod_throttle_unsolicited/mod_throttle_unsolicited.lua @ 3541:4d8a68557941
mod_throttle_unsolicited: reduce debug logs, rename firewall mark
author | Georg Lukas <georg@op-co.de> |
---|---|
date | Tue, 02 Apr 2019 16:19:11 +0200 |
parents | 231d47e61c81 |
children |
comparison
equal
deleted
inserted
replaced
3540:1b45bac50f3d | 3541:4d8a68557941 |
---|---|
10 local multiplier = module:get_option_number("throttle_unsolicited_burst", 1); | 10 local multiplier = module:get_option_number("throttle_unsolicited_burst", 1); |
11 | 11 |
12 function check_subscribed(event) | 12 function check_subscribed(event) |
13 local stanza, origin = event.stanza, event.origin; | 13 local stanza, origin = event.stanza, event.origin; |
14 local log = origin.log or module._log; | 14 local log = origin.log or module._log; |
15 log("debug", "check_subscribed(%s)", stanza:top_tag()); | |
16 if stanza.attr.type == "error" then return end | 15 if stanza.attr.type == "error" then return end |
17 | 16 |
18 local to_orig = stanza.attr.to; | 17 local to_orig = stanza.attr.to; |
19 if to_orig == nil or to_orig == origin.full_jid then return end -- to self | 18 if to_orig == nil or to_orig == origin.full_jid then return end -- to self |
20 | 19 |
23 if to_bare == from_jid then return end -- to own resource | 22 if to_bare == from_jid then return end -- to own resource |
24 | 23 |
25 -- Check if it's a message to a joined room | 24 -- Check if it's a message to a joined room |
26 local rooms = origin.rooms_joined; | 25 local rooms = origin.rooms_joined; |
27 if rooms and rooms[to_bare] then | 26 if rooms and rooms[to_bare] then |
28 log("debug", "Message to joined room, no limit"); | |
29 return | 27 return |
30 end | 28 end |
31 | 29 |
32 -- Retrieve or create throttle object | 30 -- Retrieve or create throttle object |
33 local lim = origin.throttle_unsolicited; | 31 local lim = origin.throttle_unsolicited; |
34 if not lim then | 32 if not lim then |
35 log("debug", "New throttle"); | |
36 lim = throttle.create(max * multiplier, 60 * multiplier); | 33 lim = throttle.create(max * multiplier, 60 * multiplier); |
37 origin.throttle_unsolicited = lim; | 34 origin.throttle_unsolicited = lim; |
38 end | 35 end |
39 | 36 |
40 local to_user, to_host = jid_split(to_orig); | 37 local to_user, to_host = jid_split(to_orig); |
41 if to_user and not is_contact_subscribed(to_user, to_host, from_jid) then | 38 if to_user and not is_contact_subscribed(to_user, to_host, from_jid) then |
42 log("debug", "%s is not subscribed to %s@%s", from_jid, to_user, to_host); | 39 log("debug", "[unsolicited] %s is not subscribed to %s@%s", from_jid, to_user, to_host); |
43 if not lim:poll(1) then | 40 if not lim:poll(1) then |
44 log("warn", "Sent too many messages to non-contacts, bouncing message"); | 41 log("warn", "[unsolicited] Sent too many messages to non-contacts, bouncing message"); |
45 origin.firewall_mark_throttle_unsolicited = gettime(); | 42 origin.firewall_mark_unsolicited = gettime(); |
46 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); | 43 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); |
47 return true; | 44 return true; |
48 end | 45 end |
49 end | 46 end |
50 end | 47 end |