Mercurial > prosody-modules
comparison mod_throttle_unsolicited/mod_throttle_unsolicited.lua @ 2142:d6fbb57a216c
mod_throttle_unsolicited: Skip checking messages to self
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 30 Mar 2016 10:54:47 +0200 |
parents | f6dcfe263b85 |
children | 7cab309a26b2 |
comparison
equal
deleted
inserted
replaced
2141:218a3d3f7f97 | 2142:d6fbb57a216c |
---|---|
14 local stanza, origin = event.stanza, event.origin; | 14 local stanza, origin = event.stanza, event.origin; |
15 local log = origin.log or module._log; | 15 local log = origin.log or module._log; |
16 log("debug", "check_subscribed(%s)", stanza:top_tag()); | 16 log("debug", "check_subscribed(%s)", stanza:top_tag()); |
17 if stanza.attr.type == "error" then return end | 17 if stanza.attr.type == "error" then return end |
18 | 18 |
19 local to_orig = stanza.attr.to; | |
20 if to_orig == nil or to_orig == origin.full_jid then return end -- to self | |
21 | |
22 local to_bare = jid_bare(to_orig); | |
23 local from_jid = jid_bare(stanza.attr.from); | |
24 if to_bare == from_jid then return end -- to own resource | |
25 | |
19 -- Check if it's a message to a joined room | 26 -- Check if it's a message to a joined room |
20 local to_bare = jid_bare(stanza.attr.to); | |
21 local rooms = origin.rooms_joined; | 27 local rooms = origin.rooms_joined; |
22 if rooms and rooms[to_bare] then | 28 if rooms and rooms[to_bare] then |
23 log("debug", "Message to joined room, no limit"); | 29 log("debug", "Message to joined room, no limit"); |
24 return | 30 return |
25 end | 31 end |
30 log("debug", "New throttle"); | 36 log("debug", "New throttle"); |
31 lim = throttle.create(max * multiplier, 60 * multiplier); | 37 lim = throttle.create(max * multiplier, 60 * multiplier); |
32 origin.throttle_unsolicited = lim; | 38 origin.throttle_unsolicited = lim; |
33 end | 39 end |
34 | 40 |
35 local to_user, to_host = jid_split(stanza.attr.to); | 41 local to_user, to_host = jid_split(to_orig); |
36 local from_jid = jid_bare(stanza.attr.from); | |
37 if to_user and not is_contact_subscribed(to_user, to_host, from_jid) then | 42 if to_user and not is_contact_subscribed(to_user, to_host, from_jid) then |
38 log("debug", "%s is not subscribed to %s@%s", from_jid, to_user, to_host); | 43 log("debug", "%s is not subscribed to %s@%s", from_jid, to_user, to_host); |
39 if not lim:poll(1) then | 44 if not lim:poll(1) then |
40 log("warn", "Sent too many messages to non-contacts, bouncing message"); | 45 log("warn", "Sent too many messages to non-contacts, bouncing message"); |
41 event.origin.firewall_mark_throttle_unsolicited = gettime(); | 46 event.origin.firewall_mark_throttle_unsolicited = gettime(); |