From e708a00460d4cf444d9a3c8b20c8276d71a8691e Mon Sep 17 00:00:00 2001 From: lazedo Date: Fri, 16 Nov 2018 23:24:24 +0000 Subject: [PATCH] HELP-40268 impose a maximum calls per presentity * usefull for multiple dialog in notify but it also prevents the loaded bodies from presentity to calculate final body (even on single, because we need to check the state) to fill PKG memory --- kamailio/db_queries_kazoo.cfg | 2 +- kamailio/presence-role.cfg | 44 +++++++++++++++++++++-------------- 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/kamailio/db_queries_kazoo.cfg b/kamailio/db_queries_kazoo.cfg index 29801d5..cb23157 100644 --- a/kamailio/db_queries_kazoo.cfg +++ b/kamailio/db_queries_kazoo.cfg @@ -2,7 +2,7 @@ #!substdef "!KZQ_CHECK_MEDIA_SERVER_INSERT!insert into dispatcher (setid, destination) select \$var(SetId), \"\$var(MediaUrl)\" where not exists(select * from dispatcher where destination = \"\$var(MediaUrl)\")!g" #!substdef "!KZQ_COUNT_ALL_SUBSCRIBERS!select a.event, count(distinct watcher_username || \"@\" || watcher_domain) count_unique, count(*) count from event_list a, active_watchers b where b.event = a.event group by a.event!g" #!substdef "!KZQ_COUNT_PRESENTITIES!select event, (select count(*) from presentity b where username = \"\$(var(payload){kz.json,From}{uri.user})\" and domain = \"\$(var(payload){kz.json,From}{uri.domain})\" and b.event = a.event) count from event_list a!g" -#!substdef "!KZQ_COUNT_SUBSCRIBERS!select event, (select count(*) from active_watchers b where presentity_uri = \"\$var(presentity)\" and b.event = a.event) count from event_list a!g" +#!substdef "!KZQ_COUNT_SUBSCRIBERS!select event, (select count(*) from active_watchers b where presentity_uri = \"\$var(presentity)\" and b.event = a.event) count from event_list a union select \"self\", count(*) from presentities where presentity_uri = \"\$var(presentity)\"!g" #!substdef "!KZQ_EVENT_PRESENCE_RESET_DELETE!delete from presentity where domain=\"\$(kzE{kz.json,Realm})\" and username = \"\$(kzE{kz.json,Username})\"!g" #!substdef "!KZQ_HANDLE_NEW_SUBSCRIBE_DELETE1!delete from active_watchers where callid = \"\$ci\"!g" #!substdef "!KZQ_HANDLE_NEW_SUBSCRIBE_DELETE2!delete from active_watchers where watcher_username=\"\$fU\" and presentity_uri=\"\$var(presentity_uri)\" and to_user=\"\$tU\" and watcher_domain=\"\$fd\" and event=\"\$hdr(Event)\"!g" diff --git a/kamailio/presence-role.cfg b/kamailio/presence-role.cfg index 3ce222f..ab3540e 100644 --- a/kamailio/presence-role.cfg +++ b/kamailio/presence-role.cfg @@ -4,6 +4,8 @@ #!trydef PRESENCE_MAX_EXPIRES 3600 #!trydef KZ_PRESENCE_IGNORE_STATUS_PROBE_RESP 1 +#!trydef KZ_PRESENCE_MAX_CALL_PER_PRESENTITY 10 + modparam("htable", "htable", "p=>size=32;autoexpire=3600;") modparam("htable", "htable", "first=>size=32;autoexpire=3600;initval =0;updateexpire=1;") @@ -60,6 +62,7 @@ kazoo.presence_sync_amqp = KZ_PRESENCE_AMQP_PUBLISH descr "sync subscriptions to kazoo.presence_request_probe = KZ_PRESENCE_REQUEST_PROBE descr "request probe for new subscriptions" kazoo.presence_request_resubscribe_probe = KZ_PRESENCE_REQUEST_RESUBSCRIBE_PROBE descr "request probe for resubscriptions" kazoo.presence_ignore_status_probe_resp = KZ_PRESENCE_IGNORE_STATUS_PROBE_RESP descr "ignore online/offline probe replies" +kazoo.presence_max_call_per_presentity = KZ_PRESENCE_MAX_CALL_PER_PRESENTITY descr "max number of calls per presentity" #!ifdef FAST_PICKUP_ROLE #!include_file "fast-pickup-role.cfg" @@ -400,23 +403,30 @@ route[PRESENCE_UPDATE] route(COUNT_SUBSCRIBERS); } - if($xavp(watchers=>dialog) > 0) { - if($(var(payload){kz.json,State}) == "terminated") { - xlog("L_DEBUG", "$(var(payload){kz.json,Call-ID})|log|publishing $var(presentity) dialog update for terminated dialog\n"); - } else { - xlog("L_DEBUG", "$(var(payload){kz.json,Call-ID})|log|publishing $var(presentity) dialog update for $xavp(watchers=>dialog) watchers\n"); - } - if(kazoo_pua_publish_dialoginfo($var(JObj)) == 1) { - pres_refresh_watchers("$var(presentity)", "dialog", 1); - } else { - xlog("L_ERR", "$(var(payload){kz.json,Call-ID})|log|error publishing $var(presentity) dialog update\n"); - }; - } - - if($xavp(watchers=>presence) > 0) { - xlog("L_DEBUG", "$(var(payload){kz.json,Call-ID})|log|publishing $var(presentity) presence update for $xavp(watchers=>presence) watchers\n"); - kazoo_pua_publish_presence($var(payload)); - pres_refresh_watchers("$var(presentity)", "presence", 1); + if($xavp(watchers=>self) > $sel(cfg_get.kazoo.presence_max_call_per_presentity) && + ( $(var(payload){kz.json,State}) == "early" || + ($(var(payload){kz.json,State}) == "confirmed" && $(var(payload){kz.json,State}) == "initiator") + )) { + xlog("L_WARN", "$(var(payload){kz.json,Call-ID})|log|not publishing state $(var(payload){kz.json,State}) for presentity $var(presentity) with $xavp(watchers=>self) calls, policy limit of $sel(cfg_get.kazoo.presence_max_call_per_presentity) calls per presentity \n"); + } else { + if($xavp(watchers=>dialog) > 0) { + if($(var(payload){kz.json,State}) == "terminated") { + xlog("L_DEBUG", "$(var(payload){kz.json,Call-ID})|log|publishing $var(presentity) dialog update for terminated dialog\n"); + } else { + xlog("L_DEBUG", "$(var(payload){kz.json,Call-ID})|log|publishing $var(presentity) dialog update for $xavp(watchers=>dialog) watchers\n"); + } + if(kazoo_pua_publish_dialoginfo($var(JObj)) == 1) { + pres_refresh_watchers("$var(presentity)", "dialog", 1); + } else { + xlog("L_ERR", "$(var(payload){kz.json,Call-ID})|log|error publishing $var(presentity) dialog update\n"); + }; + } + + if($xavp(watchers=>presence) > 0) { + xlog("L_DEBUG", "$(var(payload){kz.json,Call-ID})|log|publishing $var(presentity) presence update for $xavp(watchers=>presence) watchers\n"); + kazoo_pua_publish_presence($var(payload)); + pres_refresh_watchers("$var(presentity)", "presence", 1); + } } }