Mercurial > prosody-hg
comparison plugins/mod_pep.lua @ 12086:1dc00ca6ee9d 0.11
mod_pep: Limit possible growth of number of pubsub services
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Thu, 04 Nov 2021 00:35:44 +0100 |
| parents | 1d213c6f781b |
| children | 19f67d44ec37 |
comparison
equal
deleted
inserted
replaced
| 12085:1d213c6f781b | 12086:1dc00ca6ee9d |
|---|---|
| 16 | 16 |
| 17 local lib_pubsub = module:require "pubsub"; | 17 local lib_pubsub = module:require "pubsub"; |
| 18 | 18 |
| 19 local empty_set = set_new(); | 19 local empty_set = set_new(); |
| 20 | 20 |
| 21 -- username -> object passed to module:add_items() | |
| 22 local pep_service_items = {}; | |
| 23 | |
| 24 -- size of caches with full pubsub service objects | |
| 25 local service_cache_size = module:get_option_number("pep_service_cache_size", 1000); | |
| 26 | |
| 21 -- username -> util.pubsub service object | 27 -- username -> util.pubsub service object |
| 22 local services = {}; | 28 local services = cache.new(service_cache_size, function (username, _) |
| 29 local item = pep_service_items[username]; | |
| 30 pep_service_items[username] = nil; | |
| 31 if item then | |
| 32 module:remove_item("pep-service", item); | |
| 33 end | |
| 34 end):table(); | |
| 23 | 35 |
| 24 -- username -> recipient -> set of nodes | 36 -- username -> recipient -> set of nodes |
| 25 local recipients = {}; | 37 local recipients = {}; |
| 26 | 38 |
| 27 -- caps hash -> set of nodes | 39 -- caps hash -> set of nodes |
| 200 normalize_jid = jid_bare; | 212 normalize_jid = jid_bare; |
| 201 | 213 |
| 202 check_node_config = check_node_config; | 214 check_node_config = check_node_config; |
| 203 }); | 215 }); |
| 204 services[username] = service; | 216 services[username] = service; |
| 205 module:add_item("pep-service", { service = service, jid = user_bare }); | 217 local item = { service = service, jid = user_bare } |
| 218 pep_service_items[username] = item; | |
| 219 module:add_item("pep-service", item); | |
| 206 return service; | 220 return service; |
| 207 end | 221 end |
| 208 | 222 |
| 209 function handle_pubsub_iq(event) | 223 function handle_pubsub_iq(event) |
| 210 local origin, stanza = event.origin, event.stanza; | 224 local origin, stanza = event.origin, event.stanza; |
