Browse Source

websocket logs and macros

4.3
lazedo 7 years ago
committed by Luis Azedo
parent
commit
5daf2d9b54
1 changed files with 21 additions and 13 deletions
  1. +21
    -13
      kamailio/websockets-role.cfg

+ 21
- 13
kamailio/websockets-role.cfg View File

@ -12,18 +12,26 @@ loadmodule "nathelper.so"
#!endif #!endif
######## Generic Hash Table container in shared memory ######## ######## 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 ######## ######## Basic HTTP request handling ########
loadmodule "xhttp.so" 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 ######## ######## Websocket module ########
loadmodule "websocket.so" 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) modparam("websocket", "sub_protocols", 1)
####### Websocket Logic ######## ####### Websocket Logic ########
@ -86,15 +94,15 @@ event_route[xhttp:request]
} }
#!endif #!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", "", ""); xhttp_reply("403", "Forbidden", "", "");
exit; exit;
} }
if (ws_handle_handshake()) { 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; exit;
} }
@ -103,10 +111,10 @@ event_route[xhttp:request]
} }
event_route[websocket:closed] { 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"); 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 { } else {
xlog("L_INFO", "websocket|log|closed websocket from $si:$sp, $var(count) remaining from that IP\n"); xlog("L_INFO", "websocket|log|closed websocket from $si:$sp, $var(count) remaining from that IP\n");
} }


Loading…
Cancel
Save