comparison mod_throttle_unsolicited/mod_throttle_unsolicited.lua @ 2120:f6dcfe263b85

mod_throttle_unsolicited: Mark sessions so they can be matched with 'ORIGIN_MARKED: throttle_unsolicited' by mod_firewall
author Kim Alvefur <zash@zash.se>
date Thu, 17 Mar 2016 16:45:27 +0100
parents 163d55777ad5
children d6fbb57a216c
comparison
equal deleted inserted replaced
2119:5f6c18fd0161 2120:f6dcfe263b85
1 local st = require"util.stanza"; 1 local st = require"util.stanza";
2 local jid_split = require "util.jid".split; 2 local jid_split = require "util.jid".split;
3 local jid_bare = require "util.jid".bare; 3 local jid_bare = require "util.jid".bare;
4 local is_contact_subscribed = require "core.rostermanager".is_contact_subscribed; 4 local is_contact_subscribed = require "core.rostermanager".is_contact_subscribed;
5 local throttle = require "util.throttle"; 5 local throttle = require "util.throttle";
6 local gettime = require "socket".gettime;
6 7
7 local sessions = prosody.full_sessions; 8 local sessions = prosody.full_sessions;
8 9
9 local max = module:get_option_number("unsolicited_messages_per_minute", 10); 10 local max = module:get_option_number("unsolicited_messages_per_minute", 10);
10 local multiplier = module:get_option_number("throttle_unsolicited_burst", 1); 11 local multiplier = module:get_option_number("throttle_unsolicited_burst", 1);
35 local from_jid = jid_bare(stanza.attr.from); 36 local from_jid = jid_bare(stanza.attr.from);
36 if to_user and not is_contact_subscribed(to_user, to_host, from_jid) then 37 if to_user and not is_contact_subscribed(to_user, to_host, from_jid) then
37 log("debug", "%s is not subscribed to %s@%s", from_jid, to_user, to_host); 38 log("debug", "%s is not subscribed to %s@%s", from_jid, to_user, to_host);
38 if not lim:poll(1) then 39 if not lim:poll(1) then
39 log("warn", "Sent too many messages to non-contacts, bouncing message"); 40 log("warn", "Sent too many messages to non-contacts, bouncing message");
41 event.origin.firewall_mark_throttle_unsolicited = gettime();
40 event.origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); 42 event.origin.send(st.error_reply(stanza, "cancel", "service-unavailable"));
41 return true; 43 return true;
42 end 44 end
43 end 45 end
44 end 46 end