Module: sems Branch: master Commit: 81d0a755f3d3e90f634bbeae000943c51e410562 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sems/?a=commit;h=81d0a755f3d3e90f634bbeae000943c51e410562
Author: Stefan Sayer <[email protected]> Committer: Stefan Sayer <[email protected]> Date: Mon Feb 6 16:27:20 2012 +0100 b/f: cc redis BL: if server unavailable, refuse (or let through) adds pass_on_bl_unavailable option: pass (let call through) if server is unavailable? [no] pass_on_bl_unavailable=yes --- apps/sbc/call_control/bl_redis/BLRedis.cpp | 30 ++++++++++++++++++--- apps/sbc/call_control/bl_redis/BLRedis.h | 3 ++ apps/sbc/call_control/bl_redis/etc/bl_redis.conf | 3 ++ 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/apps/sbc/call_control/bl_redis/BLRedis.cpp b/apps/sbc/call_control/bl_redis/BLRedis.cpp index e71ffb7..d4ae4e9 100644 --- a/apps/sbc/call_control/bl_redis/BLRedis.cpp +++ b/apps/sbc/call_control/bl_redis/BLRedis.cpp @@ -30,6 +30,7 @@ #include "BLRedis.h" #include "ampi/SBCCallControlAPI.h" +#include "AmSipHeaders.h" #include <string.h> @@ -78,6 +79,7 @@ int CCBLRedis::onLoad() { string redis_reconnect_timers = "5,10,20,50,100,500,1000"; string redis_connections = "10"; string redis_max_conn_wait = "1000"; + pass_on_bl_unavailable = false; full_logging = false; @@ -92,6 +94,8 @@ int CCBLRedis::onLoad() { redis_connections = cfg.getParameter("redis_connections", redis_connections); redis_max_conn_wait = cfg.getParameter("redis_max_conn_wait", redis_max_conn_wait); full_logging = cfg.getParameter("redis_full_logging", "no")=="yes"; + + pass_on_bl_unavailable = cfg.getParameter("pass_on_bl_unavailable", "no")=="yes"; } unsigned int i_redis_connections; @@ -130,6 +134,9 @@ int CCBLRedis::onLoad() { connection_pool.add_connections(i_redis_connections); connection_pool.start(); + DBG("setting max number max_retries to %u (as connections)\n", i_redis_connections); + max_retries = i_redis_connections; + return 0; } @@ -290,7 +297,7 @@ void CCBLRedis::start(const string& cc_name, const string& ltag, ERROR("deciphering argc\n"); res_cmd[SBC_CC_ACTION] = SBC_CC_REFUSE_ACTION; res_cmd[SBC_CC_REFUSE_CODE] = 500; - res_cmd[SBC_CC_REFUSE_REASON] = "Server Internal Error"; + res_cmd[SBC_CC_REFUSE_REASON] = SIP_REPLY_SERVER_INTERNAL_ERROR; return; } @@ -308,13 +315,16 @@ void CCBLRedis::start(const string& cc_name, const string& ltag, bool hit = false; - for (int retries = 0;retries<10;retries++) { + unsigned int retries = 0; + for (;retries<max_retries;retries++) { redisContext* redis_context = connection_pool.getActiveConnection(); if (NULL == redis_context) { INFO("no connection to REDIS\n"); - res_cmd[SBC_CC_ACTION] = SBC_CC_REFUSE_ACTION; - res_cmd[SBC_CC_REFUSE_CODE] = 500; - res_cmd[SBC_CC_REFUSE_REASON] = "Server Internal Error"; + if (!pass_on_bl_unavailable) { + res_cmd[SBC_CC_ACTION] = SBC_CC_REFUSE_ACTION; + res_cmd[SBC_CC_REFUSE_CODE] = 500; + res_cmd[SBC_CC_REFUSE_REASON] = SIP_REPLY_SERVER_INTERNAL_ERROR; + } return; } @@ -335,6 +345,16 @@ void CCBLRedis::start(const string& cc_name, const string& ltag, break; } + if (retries == max_retries) { + if (!pass_on_bl_unavailable) { + res_cmd[SBC_CC_ACTION] = SBC_CC_REFUSE_ACTION; + res_cmd[SBC_CC_REFUSE_CODE] = 500; + res_cmd[SBC_CC_REFUSE_REASON] = SIP_REPLY_SERVER_INTERNAL_ERROR; + } + return; + } + + if (hit) { if (values.hasMember("action") && isArgCStr(values["action"]) && values["action"] == "drop") { diff --git a/apps/sbc/call_control/bl_redis/BLRedis.h b/apps/sbc/call_control/bl_redis/BLRedis.h index a9a1769..bc31002 100644 --- a/apps/sbc/call_control/bl_redis/BLRedis.h +++ b/apps/sbc/call_control/bl_redis/BLRedis.h @@ -49,6 +49,9 @@ class CCBLRedis : public AmDynInvoke { static CCBLRedis* _instance; + bool pass_on_bl_unavailable; + unsigned int max_retries; + bool full_logging; int handle_redis_reply(redisContext* redis_context, redisReply* reply, bool& hit); diff --git a/apps/sbc/call_control/bl_redis/etc/bl_redis.conf b/apps/sbc/call_control/bl_redis/etc/bl_redis.conf index 1419c89..07a4cf2 100644 --- a/apps/sbc/call_control/bl_redis/etc/bl_redis.conf +++ b/apps/sbc/call_control/bl_redis/etc/bl_redis.conf @@ -13,3 +13,6 @@ # enable full logging? (all responses) [no] #redis_full_logging=yes + +# pass (let call through) if server is unavailable? [no] +#pass_on_bl_unavailable=yes _______________________________________________ Semsdev mailing list [email protected] http://lists.iptel.org/mailman/listinfo/semsdev
