diff --git a/kamailio/websockets-role.cfg b/kamailio/websockets-role.cfg index 0dcc48b..83c337e 100644 --- a/kamailio/websockets-role.cfg +++ b/kamailio/websockets-role.cfg @@ -12,18 +12,26 @@ loadmodule "nathelper.so" #!endif ######## Generic Hash Table container in shared memory ######## -modparam("htable", "htable", "websockets=>size=16;autoexpire=7200;initval=0") +modparam("htable", "htable", "websockets=>size=16;initval=0") ######## Basic HTTP request handling ######## loadmodule "xhttp.so" + +#!trydef WS_KEEPALIVE_MECHANISM 1 +#!trydef WS_KEEPALIVE_TIMEOUT 30 +#!trydef WS_KEEPALIVE_PROCESSES 3 +#!trydef WS_KEEPALIVE_INTERVAL 1 +#!trydef WS_KEEPALIVE_DATA "Kazoo encourages you to keep alive" +#!trydef WS_MAX_CONNECTIONS_PER_IP 50 + ######## Websocket module ######## loadmodule "websocket.so" -modparam("websocket", "keepalive_mechanism", 0) -modparam("websocket", "keepalive_timeout", 30) -modparam("websocket", "keepalive_processes", 1) -modparam("websocket", "keepalive_interval", 1) -modparam("websocket", "ping_application_data", "Kazoo encourages you to keep alive") +modparam("websocket", "keepalive_mechanism", WS_KEEPALIVE_MECHANISM) +modparam("websocket", "keepalive_timeout", WS_KEEPALIVE_TIMEOUT) +modparam("websocket", "keepalive_processes", WS_KEEPALIVE_PROCESSES) +modparam("websocket", "keepalive_interval", WS_KEEPALIVE_INTERVAL) +modparam("websocket", "ping_application_data", WS_KEEPALIVE_DATA) modparam("websocket", "sub_protocols", 1) ####### Websocket Logic ######## @@ -86,15 +94,15 @@ event_route[xhttp:request] } #!endif - if($sht(websockets=>$si::count) > 50) { - xlog("L_WARN", "websocket|log|$si:$sp is at the maximum allowable sockets per IP, rejecting request for another websocket\n"); + if($sht(websockets=>$si::count) > WS_MAX_CONNECTIONS_PER_IP) { + xlog("L_WARN", "websocket|log|$si:$sp is at the maximum $def(WS_MAX_CONNECTIONS_PER_IP) allowable sockets per IP, rejecting request for another websocket\n"); xhttp_reply("403", "Forbidden", "", ""); exit; } if (ws_handle_handshake()) { - $var(shtinc) = $shtinc(websockets=>$si::count); - xlog("L_INFO", "websocket|log|opened websocket $var(count) of 50 for $si:$sp\n"); + $var(count) = $shtinc(websockets=>$si::count); + xlog("L_INFO", "websocket|log|opened websocket $var(count) of $def(WS_MAX_CONNECTIONS_PER_IP) for $si:$sp\n"); exit; } @@ -103,10 +111,10 @@ event_route[xhttp:request] } event_route[websocket:closed] { - $var(shtdec) = $shtdec(websockets=>$si::count); - if ($sht(websockets=>$si::count) < 1) { + $var(count) = $shtdec(websockets=>$si::count); + if ($var(count) < 1) { xlog("L_INFO", "websocket|log|$si:$sp closed last websocket to that IP\n"); - sht_rm_name_re("websockets=>$(si{re.subst,/\\./\\\\./g})::.*"); + $sht(websockets=>$si::count) = $null; } else { xlog("L_INFO", "websocket|log|closed websocket from $si:$sp, $var(count) remaining from that IP\n"); }