annotate mod_muc_limits/mod_muc_limits.lua @ 6257:fa45ae704b79

mod_cloud_notify: Update Readme diff --git a/mod_cloud_notify/README.md b/mod_cloud_notify/README.md --- a/mod_cloud_notify/README.md +++ b/mod_cloud_notify/README.md @@ -1,109 +1,106 @@ ---- -labels: -- 'Stage-Beta' -summary: 'XEP-0357: Cloud push notifications' ---- +# Introduction -Introduction -============ +This module enables support for sending "push notifications" to clients +that need it, typically those running on certain mobile devices. -This module enables support for sending "push notifications" to clients that -need it, typically those running on certain mobile devices. +As well as this module, your client must support push notifications (the +apps that need it generally do, of course) and the app developer's push +gateway must be reachable from your Prosody server (this happens over a +normal XMPP server-to-server 's2s' connection). -As well as this module, your client must support push notifications (the apps -that need it generally do, of course) and the app developer's push gateway -must be reachable from your Prosody server (this happens over a normal XMPP -server-to-server 's2s' connection). - -Details -======= +# Details Some platforms, notably Apple's iOS and many versions of Android, impose -limits that prevent applications from running or accessing the network in the -background. This makes it difficult or impossible for an XMPP application to -remain reliably connected to a server to receive messages. - -In order for messaging and other apps to receive notifications, the OS vendors -run proprietary servers that their OS maintains a permanent connection to in -the background. Then they provide APIs to application developers that allow -sending notifications to specific devices via those servers. +limits that prevent applications from running or accessing the network +in the background. This makes it difficult or impossible for an XMPP +application to remain reliably connected to a server to receive +messages. -When you connect to your server with an app that requires push notifications, -it will use this module to set up a "push registration". When you receive -a message but your device is not connected to the server, this module will -generate a notification and send it to the push gateway operated by your -application's developers). Their gateway will then connect to your device's -OS vendor and ask them to forward the notification to your device. When your -device receives the notification, it will display it or wake up the app so it -can connect to XMPP and receive any pending messages. +In order for messaging and other apps to receive notifications, the OS +vendors run proprietary servers that their OS maintains a permanent +connection to in the background. Then they provide APIs to application +developers that allow sending notifications to specific devices via +those servers. -This protocol is described for developers in [XEP-0357: Push Notifications]. +When you connect to your server with an app that requires push +notifications, it will use this module to set up a "push registration". +When you receive a message but your device is not connected to the +server, this module will generate a notification and send it to the push +gateway operated by your application's developers). Their gateway will +then connect to your device's OS vendor and ask them to forward the +notification to your device. When your device receives the notification, +it will display it or wake up the app so it can connect to XMPP and +receive any pending messages. -For this module to work reliably, you must have [mod_smacks], [mod_mam] and -[mod_carbons] also enabled on your server. +This protocol is described for developers in \[XEP-0357: Push +Notifications\]. + +For this module to work reliably, you must have \[mod_smacks\], +\[mod_mam\] and \[mod_carbons\] also enabled on your server. -Some clients, notably Siskin and Snikket iOS need some additional extensions -that are not currently defined in a standard XEP. To support these clients, -see [mod_cloud_notify_extensions]. +Some clients, notably Siskin and Snikket iOS need some additional +extensions that are not currently defined in a standard XEP. To support +these clients, see \[mod_cloud_notify_extensions\]. -Configuration -============= +# Configuration - Option Default Description - ------------------------------------ ----------------- ------------------------------------------------------------------------------------------------------------------- - `push_notification_important_body` `New Message!` The body text to use when the stanza is important (see above), no message body is sent if this is empty - `push_max_errors` `16` How much persistent push errors are tolerated before notifications for the identifier in question are disabled - `push_max_devices` `5` The number of allowed devices per user (the oldest devices are automatically removed if this threshold is reached) - `push_max_hibernation_timeout` `259200` (72h) Number of seconds to extend the smacks timeout if no push was triggered yet (default: 72 hours) - `push_notification_with_body` (\*) `false` Whether or not to send the real message body to remote pubsub node. Without end-to-end encryption, enabling this may expose your message contents to your client developers and OS vendor. Not recommended. - `push_notification_with_sender` (\*) `false` Whether or not to send the real message sender to remote pubsub node. Enabling this may expose your contacts to your client developers and OS vendor. Not recommended. + Option Default Description + -------------------------------------- ---------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + `push_notification_important_body` `New Message!` The body text to use when the stanza is important (see above), no message body is sent if this is empty + `push_max_errors` `16` How much persistent push errors are tolerated before notifications for the identifier in question are disabled + `push_max_devices` `5` The number of allowed devices per user (the oldest devices are automatically removed if this threshold is reached) + `push_max_hibernation_timeout` `259200` (72h) Number of seconds to extend the smacks timeout if no push was triggered yet (default: 72 hours) + `push_notification_with_body` (\*) `false` Whether or not to send the real message body to remote pubsub node. Without end-to-end encryption, enabling this may expose your message contents to your client developers and OS vendor. Not recommended. + `push_notification_with_sender` (\*) `false` Whether or not to send the real message sender to remote pubsub node. Enabling this may expose your contacts to your client developers and OS vendor. Not recommended. -(\*) There are privacy implications for enabling these options. +(\*) There are privacy implications for enabling these options.[^1] -Internal design notes -===================== +# Internal design notes -App servers are notified about offline messages, messages stored by [mod_mam] -or messages waiting in the smacks queue. -The business rules outlined [here](//mail.jabber.org/pipermail/standards/2016-February/030925.html) are all honored[^2]. +App servers are notified about offline messages, messages stored by +\[mod_mam\] or messages waiting in the smacks queue. The business rules +outlined +[here](//mail.jabber.org/pipermail/standards/2016-February/030925.html) +are all honored[^2]. -To cooperate with [mod_smacks] this module consumes some events: -`smacks-ack-delayed`, `smacks-hibernation-start` and `smacks-hibernation-end`. -These events allow this module to send out notifications for messages received -while the session is hibernated by [mod_smacks] or even when smacks -acknowledgements for messages are delayed by a certain amount of seconds -configurable with the [mod_smacks] setting `smacks_max_ack_delay`. +To cooperate with \[mod_smacks\] this module consumes some events: +`smacks-ack-delayed`, `smacks-hibernation-start` and +`smacks-hibernation-end`. These events allow this module to send out +notifications for messages received while the session is hibernated by +\[mod_smacks\] or even when smacks acknowledgements for messages are +delayed by a certain amount of seconds configurable with the +\[mod_smacks\] setting `smacks_max_ack_delay`. -The `smacks_max_ack_delay` setting allows to send out notifications to clients -which aren't already in smacks hibernation state (because the read timeout or -connection close didn't already happen) but also aren't responding to acknowledgement -request in a timely manner. This setting thus allows conversations to be smoother -under such circumstances. +The `smacks_max_ack_delay` setting allows to send out notifications to +clients which aren't already in smacks hibernation state (because the +read timeout or connection close didn't already happen) but also aren't +responding to acknowledgement request in a timely manner. This setting +thus allows conversations to be smoother under such circumstances. -The new event `cloud-notify-ping` can be used by any module to send out a cloud -notification to either all registered endpoints for the given user or only the endpoints -given in the event data. +The new event `cloud-notify-ping` can be used by any module to send out +a cloud notification to either all registered endpoints for the given +user or only the endpoints given in the event data. -The config setting `push_notification_important_body` can be used to specify an alternative -body text to send to the remote pubsub node if the stanza is encrypted or has a body. -This way the real contents of the message aren't revealed to the push appserver but it -can still see that the push is important. -This is used by Chatsecure on iOS to send out high priority pushes in those cases for example. +The config setting `push_notification_important_body` can be used to +specify an alternative body text to send to the remote pubsub node if +the stanza is encrypted or has a body. This way the real contents of the +message aren't revealed to the push appserver but it can still see that +the push is important. This is used by Chatsecure on iOS to send out +high priority pushes in those cases for example. -Compatibility -============= - -**Note:** This module should be used with Lua 5.2 and higher. Using it with -Lua 5.1 may cause push notifications to not be sent to some clients. +# Compatibility ------- ----------------------------------------------------------------------------- - trunk Works - 0.12 Works - 0.11 Works - 0.10 Works - 0.9 Support dropped, use last supported version [675726ab06d3](//hg.prosody.im/prosody-modules/raw-file/675726ab06d3/mod_cloud_notify/mod_cloud_notify.lua) ------- ----------------------------------------------------------------------------- +**Note:** This module should be used with Lua 5.2 and higher. Using it +with Lua 5.1 may cause push notifications to not be sent to some +clients. + ------- ----------------------------------------------------------------- + trunk Works as of 25-06-13 + 13 Works + 0.12 Works + ------- ----------------------------------------------------------------- -[^1]: The service which is expected to forward notifications to something like Google Cloud Messaging or Apple Notification Service -[^2]: [business_rules.markdown](//hg.prosody.im/prosody-modules/file/tip/mod_cloud_notify/business_rules.markdown) +[^1]: The service which is expected to forward notifications to + something like Google Cloud Messaging or Apple Notification Service + +[^2]: [business_rules.md](//hg.prosody.im/prosody-modules/file/tip/mod_cloud_notify/business_rules.md)
author Menel <menel@snikket.de>
date Fri, 13 Jun 2025 10:36:52 +0200
parents 6680a1f53353
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1057
0b41122b19f9 mod_muc_limits: Abort loading on non-MUC hosts (thanks Ge0rG)
Matthew Wild <mwild1@gmail.com>
parents: 1042
diff changeset
1
1768
163967467308 mod_muc_limits: Update to work with both the new and the old MUC API
Kim Alvefur <zash@zash.se>
parents: 1428
diff changeset
2 local mod_muc = module:depends"muc";
163967467308 mod_muc_limits: Update to work with both the new and the old MUC API
Kim Alvefur <zash@zash.se>
parents: 1428
diff changeset
3 local rooms = rawget(mod_muc, "rooms"); -- Old MUC API
554
a2b0174b5c48 mod_muc_limits: New module to impose overall rate-limits on a MUC (not on individual users)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
4
1042
5fd0860c86cd mod_muc_limits: Allow stanzas from affiliated users even if they are not in the room
Matthew Wild <mwild1@gmail.com>
parents: 1040
diff changeset
5 local jid_split, jid_bare = require "util.jid".split, require "util.jid".bare;
554
a2b0174b5c48 mod_muc_limits: New module to impose overall rate-limits on a MUC (not on individual users)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
6 local st = require "util.stanza";
a2b0174b5c48 mod_muc_limits: New module to impose overall rate-limits on a MUC (not on individual users)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
7 local new_throttle = require "util.throttle".create;
1038
edb06824a5a4 mod_muc_limits: Condense multiple dropped stanzas into a single log message every 5 seconds
Matthew Wild <mwild1@gmail.com>
parents: 1036
diff changeset
8 local t_insert, t_concat = table.insert, table.concat;
554
a2b0174b5c48 mod_muc_limits: New module to impose overall rate-limits on a MUC (not on individual users)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
9
557
14f39769c9e0 mod_muc_limits: Echo any MUC <x> or <body> in the error reply (required to make Gajim display the error)
Matthew Wild <mwild1@gmail.com>
parents: 556
diff changeset
10 local xmlns_muc = "http://jabber.org/protocol/muc";
14f39769c9e0 mod_muc_limits: Echo any MUC <x> or <body> in the error reply (required to make Gajim display the error)
Matthew Wild <mwild1@gmail.com>
parents: 556
diff changeset
11
554
a2b0174b5c48 mod_muc_limits: New module to impose overall rate-limits on a MUC (not on individual users)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12 local period = math.max(module:get_option_number("muc_event_rate", 0.5), 0);
a2b0174b5c48 mod_muc_limits: New module to impose overall rate-limits on a MUC (not on individual users)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
13 local burst = math.max(module:get_option_number("muc_burst_factor", 6), 1);
a2b0174b5c48 mod_muc_limits: New module to impose overall rate-limits on a MUC (not on individual users)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14
1036
a44e755f7579 mod_muc_limits: Add muc_max_nick_length option, defaulting to 23 (bytes)
Matthew Wild <mwild1@gmail.com>
parents: 1035
diff changeset
15 local max_nick_length = module:get_option_number("muc_max_nick_length", 23); -- Default chosen through scientific methods
5566
f71d66bd87be mod_muc_limits: Add a limit on number of lines per message
Kim Alvefur <zash@zash.se>
parents: 5564
diff changeset
16 local max_line_count = module:get_option_number("muc_max_line_count", 23); -- Default chosen through s/scientific methods/copy and paste/
5567
d52cc18f0aa8 mod_muc_limits: Add a limit on number of bytes in a message body
Kim Alvefur <zash@zash.se>
parents: 5566
diff changeset
17 local max_char_count = module:get_option_number("muc_max_char_count", 5664); -- Default chosen by multiplying a number by 23
5601
6680a1f53353 mod_muc_limits: Reduce cost of multi-line messages, make configurable
Kim Alvefur <zash@zash.se>
parents: 5567
diff changeset
18 local base_cost = math.max(module:get_option_number("muc_limit_base_cost", 1), 0);
6680a1f53353 mod_muc_limits: Reduce cost of multi-line messages, make configurable
Kim Alvefur <zash@zash.se>
parents: 5567
diff changeset
19 local line_multiplier = math.max(module:get_option_number("muc_line_count_multiplier", 0.1), 0);
5566
f71d66bd87be mod_muc_limits: Add a limit on number of lines per message
Kim Alvefur <zash@zash.se>
parents: 5564
diff changeset
20
3965
2b10e51d85a6 mod_muc_limits: Add config option to limit to join stanzas only
Matthew Wild <mwild1@gmail.com>
parents: 3964
diff changeset
21 local join_only = module:get_option_boolean("muc_limit_joins_only", false);
1038
edb06824a5a4 mod_muc_limits: Condense multiple dropped stanzas into a single log message every 5 seconds
Matthew Wild <mwild1@gmail.com>
parents: 1036
diff changeset
22 local dropped_count = 0;
edb06824a5a4 mod_muc_limits: Condense multiple dropped stanzas into a single log message every 5 seconds
Matthew Wild <mwild1@gmail.com>
parents: 1036
diff changeset
23 local dropped_jids;
edb06824a5a4 mod_muc_limits: Condense multiple dropped stanzas into a single log message every 5 seconds
Matthew Wild <mwild1@gmail.com>
parents: 1036
diff changeset
24
edb06824a5a4 mod_muc_limits: Condense multiple dropped stanzas into a single log message every 5 seconds
Matthew Wild <mwild1@gmail.com>
parents: 1036
diff changeset
25 local function log_dropped()
edb06824a5a4 mod_muc_limits: Condense multiple dropped stanzas into a single log message every 5 seconds
Matthew Wild <mwild1@gmail.com>
parents: 1036
diff changeset
26 module:log("warn", "Dropped %d stanzas from %d JIDs: %s", dropped_count, #dropped_jids, t_concat(dropped_jids, ", "));
edb06824a5a4 mod_muc_limits: Condense multiple dropped stanzas into a single log message every 5 seconds
Matthew Wild <mwild1@gmail.com>
parents: 1036
diff changeset
27 dropped_count = 0;
edb06824a5a4 mod_muc_limits: Condense multiple dropped stanzas into a single log message every 5 seconds
Matthew Wild <mwild1@gmail.com>
parents: 1036
diff changeset
28 dropped_jids = nil;
edb06824a5a4 mod_muc_limits: Condense multiple dropped stanzas into a single log message every 5 seconds
Matthew Wild <mwild1@gmail.com>
parents: 1036
diff changeset
29 end
1036
a44e755f7579 mod_muc_limits: Add muc_max_nick_length option, defaulting to 23 (bytes)
Matthew Wild <mwild1@gmail.com>
parents: 1035
diff changeset
30
554
a2b0174b5c48 mod_muc_limits: New module to impose overall rate-limits on a MUC (not on individual users)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
31 local function handle_stanza(event)
a2b0174b5c48 mod_muc_limits: New module to impose overall rate-limits on a MUC (not on individual users)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
32 local origin, stanza = event.origin, event.stanza;
555
2356ad05fdb6 mod_muc_limits: Don't limit room leaving
Matthew Wild <mwild1@gmail.com>
parents: 554
diff changeset
33 if stanza.name == "presence" and stanza.attr.type == "unavailable" then -- Don't limit room leaving
2356ad05fdb6 mod_muc_limits: Don't limit room leaving
Matthew Wild <mwild1@gmail.com>
parents: 554
diff changeset
34 return;
2356ad05fdb6 mod_muc_limits: Don't limit room leaving
Matthew Wild <mwild1@gmail.com>
parents: 554
diff changeset
35 end
1042
5fd0860c86cd mod_muc_limits: Allow stanzas from affiliated users even if they are not in the room
Matthew Wild <mwild1@gmail.com>
parents: 1040
diff changeset
36 local dest_room, dest_host, dest_nick = jid_split(stanza.attr.to);
3417
1534d0715d35 mod_muc_limits: Add support for new MUC API in Prosody 0.11
Kim Alvefur <zash@zash.se>
parents: 3402
diff changeset
37 local room = event.room or rooms[dest_room.."@"..dest_host];
554
a2b0174b5c48 mod_muc_limits: New module to impose overall rate-limits on a MUC (not on individual users)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
38 if not room then return; end
a2b0174b5c48 mod_muc_limits: New module to impose overall rate-limits on a MUC (not on individual users)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
39 local from_jid = stanza.attr.from;
3418
9be9dd434813 mod_muc_limits: Simplify bypass for affiliated users
Kim Alvefur <zash@zash.se>
parents: 3417
diff changeset
40 if room:get_affiliation(jid_bare(from_jid)) then
554
a2b0174b5c48 mod_muc_limits: New module to impose overall rate-limits on a MUC (not on individual users)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
41 module:log("debug", "Skipping stanza from affiliated user...");
a2b0174b5c48 mod_muc_limits: New module to impose overall rate-limits on a MUC (not on individual users)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
42 return;
1058
1255de347dd4 mod_muc_limits: Fix traceback on presence sent to the room's bare JID
Matthew Wild <mwild1@gmail.com>
parents: 1057
diff changeset
43 elseif dest_nick and max_nick_length and stanza.name == "presence" and not room._occupants[stanza.attr.to] and #dest_nick > max_nick_length then
1036
a44e755f7579 mod_muc_limits: Add muc_max_nick_length option, defaulting to 23 (bytes)
Matthew Wild <mwild1@gmail.com>
parents: 1035
diff changeset
44 module:log("debug", "Forbidding long (%d bytes) nick in %s", #dest_nick, dest_room)
a44e755f7579 mod_muc_limits: Add muc_max_nick_length option, defaulting to 23 (bytes)
Matthew Wild <mwild1@gmail.com>
parents: 1035
diff changeset
45 origin.send(st.error_reply(stanza, "modify", "policy-violation", "Your nick name is too long, please use a shorter one")
a44e755f7579 mod_muc_limits: Add muc_max_nick_length option, defaulting to 23 (bytes)
Matthew Wild <mwild1@gmail.com>
parents: 1035
diff changeset
46 :up():tag("x", { xmlns = xmlns_muc }));
a44e755f7579 mod_muc_limits: Add muc_max_nick_length option, defaulting to 23 (bytes)
Matthew Wild <mwild1@gmail.com>
parents: 1035
diff changeset
47 return true;
554
a2b0174b5c48 mod_muc_limits: New module to impose overall rate-limits on a MUC (not on individual users)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
48 end
a2b0174b5c48 mod_muc_limits: New module to impose overall rate-limits on a MUC (not on individual users)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
49 local throttle = room.throttle;
a2b0174b5c48 mod_muc_limits: New module to impose overall rate-limits on a MUC (not on individual users)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
50 if not room.throttle then
a2b0174b5c48 mod_muc_limits: New module to impose overall rate-limits on a MUC (not on individual users)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
51 throttle = new_throttle(period*burst, burst);
a2b0174b5c48 mod_muc_limits: New module to impose overall rate-limits on a MUC (not on individual users)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
52 room.throttle = throttle;
a2b0174b5c48 mod_muc_limits: New module to impose overall rate-limits on a MUC (not on individual users)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
53 end
5601
6680a1f53353 mod_muc_limits: Reduce cost of multi-line messages, make configurable
Kim Alvefur <zash@zash.se>
parents: 5567
diff changeset
54 local cost = base_cost;
5564
731ba9400c10 mod_muc_limits: Raise cost for multi-line messages
Kim Alvefur <zash@zash.se>
parents: 3965
diff changeset
55 local body = stanza:get_child_text("body");
731ba9400c10 mod_muc_limits: Raise cost for multi-line messages
Kim Alvefur <zash@zash.se>
parents: 3965
diff changeset
56 if body then
731ba9400c10 mod_muc_limits: Raise cost for multi-line messages
Kim Alvefur <zash@zash.se>
parents: 3965
diff changeset
57 -- TODO calculate a text diagonal cross-section or some mathemagical
731ba9400c10 mod_muc_limits: Raise cost for multi-line messages
Kim Alvefur <zash@zash.se>
parents: 3965
diff changeset
58 -- number, maybe some cost multipliers
5567
d52cc18f0aa8 mod_muc_limits: Add a limit on number of bytes in a message body
Kim Alvefur <zash@zash.se>
parents: 5566
diff changeset
59 if #body > max_char_count then
d52cc18f0aa8 mod_muc_limits: Add a limit on number of bytes in a message body
Kim Alvefur <zash@zash.se>
parents: 5566
diff changeset
60 origin.send(st.error_reply(stanza, "modify", "policy-violation", "Your message is too long, please write a shorter one")
d52cc18f0aa8 mod_muc_limits: Add a limit on number of bytes in a message body
Kim Alvefur <zash@zash.se>
parents: 5566
diff changeset
61 :up():tag("x", { xmlns = xmlns_muc }));
d52cc18f0aa8 mod_muc_limits: Add a limit on number of bytes in a message body
Kim Alvefur <zash@zash.se>
parents: 5566
diff changeset
62 return true;
d52cc18f0aa8 mod_muc_limits: Add a limit on number of bytes in a message body
Kim Alvefur <zash@zash.se>
parents: 5566
diff changeset
63 end
5564
731ba9400c10 mod_muc_limits: Raise cost for multi-line messages
Kim Alvefur <zash@zash.se>
parents: 3965
diff changeset
64 local body_lines = select(2, body:gsub("\n[^\n]*", ""));
5566
f71d66bd87be mod_muc_limits: Add a limit on number of lines per message
Kim Alvefur <zash@zash.se>
parents: 5564
diff changeset
65 if body_lines > max_line_count then
f71d66bd87be mod_muc_limits: Add a limit on number of lines per message
Kim Alvefur <zash@zash.se>
parents: 5564
diff changeset
66 origin.send(st.error_reply(stanza, "modify", "policy-violation", "Your message is too long, please write a shorter one"):up()
f71d66bd87be mod_muc_limits: Add a limit on number of lines per message
Kim Alvefur <zash@zash.se>
parents: 5564
diff changeset
67 :tag("x", { xmlns = xmlns_muc; }));
f71d66bd87be mod_muc_limits: Add a limit on number of lines per message
Kim Alvefur <zash@zash.se>
parents: 5564
diff changeset
68 return true;
f71d66bd87be mod_muc_limits: Add a limit on number of lines per message
Kim Alvefur <zash@zash.se>
parents: 5564
diff changeset
69 end
5601
6680a1f53353 mod_muc_limits: Reduce cost of multi-line messages, make configurable
Kim Alvefur <zash@zash.se>
parents: 5567
diff changeset
70 cost = cost + (body_lines * line_multiplier);
5564
731ba9400c10 mod_muc_limits: Raise cost for multi-line messages
Kim Alvefur <zash@zash.se>
parents: 3965
diff changeset
71 end
731ba9400c10 mod_muc_limits: Raise cost for multi-line messages
Kim Alvefur <zash@zash.se>
parents: 3965
diff changeset
72 if not throttle:poll(cost) then
1038
edb06824a5a4 mod_muc_limits: Condense multiple dropped stanzas into a single log message every 5 seconds
Matthew Wild <mwild1@gmail.com>
parents: 1036
diff changeset
73 module:log("debug", "Dropping stanza for %s@%s from %s, over rate limit", dest_room, dest_host, from_jid);
edb06824a5a4 mod_muc_limits: Condense multiple dropped stanzas into a single log message every 5 seconds
Matthew Wild <mwild1@gmail.com>
parents: 1036
diff changeset
74 if not dropped_jids then
edb06824a5a4 mod_muc_limits: Condense multiple dropped stanzas into a single log message every 5 seconds
Matthew Wild <mwild1@gmail.com>
parents: 1036
diff changeset
75 dropped_jids = { [from_jid] = true, from_jid };
edb06824a5a4 mod_muc_limits: Condense multiple dropped stanzas into a single log message every 5 seconds
Matthew Wild <mwild1@gmail.com>
parents: 1036
diff changeset
76 module:add_timer(5, log_dropped);
edb06824a5a4 mod_muc_limits: Condense multiple dropped stanzas into a single log message every 5 seconds
Matthew Wild <mwild1@gmail.com>
parents: 1036
diff changeset
77 elseif not dropped_jids[from_jid] then
edb06824a5a4 mod_muc_limits: Condense multiple dropped stanzas into a single log message every 5 seconds
Matthew Wild <mwild1@gmail.com>
parents: 1036
diff changeset
78 dropped_jids[from_jid] = true;
edb06824a5a4 mod_muc_limits: Condense multiple dropped stanzas into a single log message every 5 seconds
Matthew Wild <mwild1@gmail.com>
parents: 1036
diff changeset
79 t_insert(dropped_jids, from_jid);
edb06824a5a4 mod_muc_limits: Condense multiple dropped stanzas into a single log message every 5 seconds
Matthew Wild <mwild1@gmail.com>
parents: 1036
diff changeset
80 end
edb06824a5a4 mod_muc_limits: Condense multiple dropped stanzas into a single log message every 5 seconds
Matthew Wild <mwild1@gmail.com>
parents: 1036
diff changeset
81 dropped_count = dropped_count + 1;
1205
7d2d440e2fa5 mod_muc_limits: Just drop error stanzas instead of bouncing them with more error stanzas
Kim Alvefur <zash@zash.se>
parents: 1058
diff changeset
82 if stanza.attr.type == "error" then -- We don't want to bounce errors
7d2d440e2fa5 mod_muc_limits: Just drop error stanzas instead of bouncing them with more error stanzas
Kim Alvefur <zash@zash.se>
parents: 1058
diff changeset
83 return true;
7d2d440e2fa5 mod_muc_limits: Just drop error stanzas instead of bouncing them with more error stanzas
Kim Alvefur <zash@zash.se>
parents: 1058
diff changeset
84 end
557
14f39769c9e0 mod_muc_limits: Echo any MUC <x> or <body> in the error reply (required to make Gajim display the error)
Matthew Wild <mwild1@gmail.com>
parents: 556
diff changeset
85 local reply = st.error_reply(stanza, "wait", "policy-violation", "The room is currently overactive, please try again later");
14f39769c9e0 mod_muc_limits: Echo any MUC <x> or <body> in the error reply (required to make Gajim display the error)
Matthew Wild <mwild1@gmail.com>
parents: 556
diff changeset
86 if body then
14f39769c9e0 mod_muc_limits: Echo any MUC <x> or <body> in the error reply (required to make Gajim display the error)
Matthew Wild <mwild1@gmail.com>
parents: 556
diff changeset
87 reply:up():tag("body"):text(body):up();
14f39769c9e0 mod_muc_limits: Echo any MUC <x> or <body> in the error reply (required to make Gajim display the error)
Matthew Wild <mwild1@gmail.com>
parents: 556
diff changeset
88 end
14f39769c9e0 mod_muc_limits: Echo any MUC <x> or <body> in the error reply (required to make Gajim display the error)
Matthew Wild <mwild1@gmail.com>
parents: 556
diff changeset
89 local x = stanza:get_child("x", xmlns_muc);
14f39769c9e0 mod_muc_limits: Echo any MUC <x> or <body> in the error reply (required to make Gajim display the error)
Matthew Wild <mwild1@gmail.com>
parents: 556
diff changeset
90 if x then
14f39769c9e0 mod_muc_limits: Echo any MUC <x> or <body> in the error reply (required to make Gajim display the error)
Matthew Wild <mwild1@gmail.com>
parents: 556
diff changeset
91 reply:add_child(st.clone(x));
14f39769c9e0 mod_muc_limits: Echo any MUC <x> or <body> in the error reply (required to make Gajim display the error)
Matthew Wild <mwild1@gmail.com>
parents: 556
diff changeset
92 end
14f39769c9e0 mod_muc_limits: Echo any MUC <x> or <body> in the error reply (required to make Gajim display the error)
Matthew Wild <mwild1@gmail.com>
parents: 556
diff changeset
93 origin.send(reply);
554
a2b0174b5c48 mod_muc_limits: New module to impose overall rate-limits on a MUC (not on individual users)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
94 return true;
a2b0174b5c48 mod_muc_limits: New module to impose overall rate-limits on a MUC (not on individual users)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
95 end
a2b0174b5c48 mod_muc_limits: New module to impose overall rate-limits on a MUC (not on individual users)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
96 end
a2b0174b5c48 mod_muc_limits: New module to impose overall rate-limits on a MUC (not on individual users)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
97
3449
5e91a34b1e71 mod_muc_limits: Fix being unload on trunk
Kim Alvefur <zash@zash.se>
parents: 3418
diff changeset
98 if rooms then
5e91a34b1e71 mod_muc_limits: Fix being unload on trunk
Kim Alvefur <zash@zash.se>
parents: 3418
diff changeset
99 function module.unload()
3964
15355caf4553 mod_muc_limits: Add [luacheck] annotation to silence unused loop variable warning
Matthew Wild <mwild1@gmail.com>
parents: 3449
diff changeset
100 for room_jid, room in pairs(rooms) do --luacheck: ignore 213/room_jid
3449
5e91a34b1e71 mod_muc_limits: Fix being unload on trunk
Kim Alvefur <zash@zash.se>
parents: 3418
diff changeset
101 room.throttle = nil;
5e91a34b1e71 mod_muc_limits: Fix being unload on trunk
Kim Alvefur <zash@zash.se>
parents: 3418
diff changeset
102 end
556
e50bdbaa7802 mod_muc_limits: Remove throttle object from all rooms on unload (to make sure new settings are applied on reload)
Matthew Wild <mwild1@gmail.com>
parents: 555
diff changeset
103 end
e50bdbaa7802 mod_muc_limits: Remove throttle object from all rooms on unload (to make sure new settings are applied on reload)
Matthew Wild <mwild1@gmail.com>
parents: 555
diff changeset
104
3417
1534d0715d35 mod_muc_limits: Add support for new MUC API in Prosody 0.11
Kim Alvefur <zash@zash.se>
parents: 3402
diff changeset
105 module:hook("presence/full", handle_stanza, 501);
3965
2b10e51d85a6 mod_muc_limits: Add config option to limit to join stanzas only
Matthew Wild <mwild1@gmail.com>
parents: 3964
diff changeset
106 if not join_only then
2b10e51d85a6 mod_muc_limits: Add config option to limit to join stanzas only
Matthew Wild <mwild1@gmail.com>
parents: 3964
diff changeset
107 module:hook("message/bare", handle_stanza, 501);
2b10e51d85a6 mod_muc_limits: Add config option to limit to join stanzas only
Matthew Wild <mwild1@gmail.com>
parents: 3964
diff changeset
108 module:hook("message/full", handle_stanza, 501);
2b10e51d85a6 mod_muc_limits: Add config option to limit to join stanzas only
Matthew Wild <mwild1@gmail.com>
parents: 3964
diff changeset
109 module:hook("presence/bare", handle_stanza, 501);
2b10e51d85a6 mod_muc_limits: Add config option to limit to join stanzas only
Matthew Wild <mwild1@gmail.com>
parents: 3964
diff changeset
110 end
3417
1534d0715d35 mod_muc_limits: Add support for new MUC API in Prosody 0.11
Kim Alvefur <zash@zash.se>
parents: 3402
diff changeset
111 else
1534d0715d35 mod_muc_limits: Add support for new MUC API in Prosody 0.11
Kim Alvefur <zash@zash.se>
parents: 3402
diff changeset
112 module:hook("muc-occupant-pre-join", handle_stanza);
3965
2b10e51d85a6 mod_muc_limits: Add config option to limit to join stanzas only
Matthew Wild <mwild1@gmail.com>
parents: 3964
diff changeset
113 if not join_only then
2b10e51d85a6 mod_muc_limits: Add config option to limit to join stanzas only
Matthew Wild <mwild1@gmail.com>
parents: 3964
diff changeset
114 module:hook("muc-occupant-pre-change", handle_stanza);
2b10e51d85a6 mod_muc_limits: Add config option to limit to join stanzas only
Matthew Wild <mwild1@gmail.com>
parents: 3964
diff changeset
115 module:hook("muc-occupant-groupchat", handle_stanza);
2b10e51d85a6 mod_muc_limits: Add config option to limit to join stanzas only
Matthew Wild <mwild1@gmail.com>
parents: 3964
diff changeset
116 end
3417
1534d0715d35 mod_muc_limits: Add support for new MUC API in Prosody 0.11
Kim Alvefur <zash@zash.se>
parents: 3402
diff changeset
117 end