summaryrefslogtreecommitdiff
path: root/pjsip/src
diff options
context:
space:
mode:
authorNanang Izzuddin <nanang@teluu.com>2014-11-04 08:00:15 +0000
committerNanang Izzuddin <nanang@teluu.com>2014-11-04 08:00:15 +0000
commit58ecec36e6e30a9f9066381e1a8e1751bfd94671 (patch)
tree953900613ae387dec82743df8fb3ba0e169bd4a1 /pjsip/src
parent5d027102466dca0528f6ac0da87a23517f6a3f07 (diff)
Close #1802: Configurable randomized value range for auto re-registration interval.
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@4957 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjsip/src')
-rw-r--r--pjsip/src/pjsua-lib/pjsua_acc.c16
-rw-r--r--pjsip/src/pjsua-lib/pjsua_core.c1
-rw-r--r--pjsip/src/pjsua2/account.cpp4
3 files changed, 15 insertions, 6 deletions
diff --git a/pjsip/src/pjsua-lib/pjsua_acc.c b/pjsip/src/pjsua-lib/pjsua_acc.c
index 8e49c8ba..89ecd257 100644
--- a/pjsip/src/pjsua-lib/pjsua_acc.c
+++ b/pjsip/src/pjsua-lib/pjsua_acc.c
@@ -1204,6 +1204,7 @@ PJ_DEF(pj_status_t) pjsua_acc_modify( pjsua_acc_id acc_id,
acc->cfg.allow_contact_rewrite = cfg->allow_contact_rewrite;
acc->cfg.reg_retry_interval = cfg->reg_retry_interval;
acc->cfg.reg_first_retry_interval = cfg->reg_first_retry_interval;
+ acc->cfg.reg_retry_random_interval = cfg->reg_retry_random_interval;
acc->cfg.drop_calls_on_reg_fail = cfg->drop_calls_on_reg_fail;
acc->cfg.register_on_acc_add = cfg->register_on_acc_add;
if (acc->cfg.reg_delay_before_refresh != cfg->reg_delay_before_refresh) {
@@ -3539,12 +3540,15 @@ static void schedule_reregistration(pjsua_acc *acc)
acc->cfg.reg_first_retry_interval;
delay.msec = 0;
- /* Randomize interval by +/- 10 secs */
- if (delay.sec >= 10) {
- delay.msec = -10000 + (pj_rand() % 20000);
- } else {
- delay.sec = 0;
- delay.msec = (pj_rand() % 10000);
+ /* Randomize interval by +/- reg_retry_random_interval, if configured */
+ if (acc->cfg.reg_retry_random_interval) {
+ long rand_ms = acc->cfg.reg_retry_random_interval * 1000;
+ if (delay.sec >= (long)acc->cfg.reg_retry_random_interval) {
+ delay.msec = -rand_ms + (pj_rand() % (rand_ms * 2));
+ } else {
+ delay.sec = 0;
+ delay.msec = (pj_rand() % (delay.sec * 1000 + rand_ms));
+ }
}
pj_time_val_normalize(&delay);
diff --git a/pjsip/src/pjsua-lib/pjsua_core.c b/pjsip/src/pjsua-lib/pjsua_core.c
index e94c4829..c7f54eed 100644
--- a/pjsip/src/pjsua-lib/pjsua_core.c
+++ b/pjsip/src/pjsua-lib/pjsua_core.c
@@ -288,6 +288,7 @@ PJ_DEF(void) pjsua_acc_config_default(pjsua_acc_config *cfg)
cfg->srtp_secure_signaling = pjsua_var.ua_cfg.srtp_secure_signaling;
cfg->srtp_optional_dup_offer = pjsua_var.ua_cfg.srtp_optional_dup_offer;
cfg->reg_retry_interval = PJSUA_REG_RETRY_INTERVAL;
+ cfg->reg_retry_random_interval = 10;
cfg->contact_rewrite_method = PJSUA_CONTACT_REWRITE_METHOD;
cfg->contact_use_src_port = PJ_TRUE;
cfg->use_rfc5626 = PJ_TRUE;
diff --git a/pjsip/src/pjsua2/account.cpp b/pjsip/src/pjsua2/account.cpp
index 533b8211..cb4fe6da 100644
--- a/pjsip/src/pjsua2/account.cpp
+++ b/pjsip/src/pjsua2/account.cpp
@@ -38,6 +38,7 @@ void AccountRegConfig::readObject(const ContainerNode &node) throw(Error)
NODE_READ_UNSIGNED (this_node, timeoutSec);
NODE_READ_UNSIGNED (this_node, retryIntervalSec);
NODE_READ_UNSIGNED (this_node, firstRetryIntervalSec);
+ NODE_READ_UNSIGNED (this_node, randomRetryIntervalSec);
NODE_READ_UNSIGNED (this_node, delayBeforeRefreshSec);
NODE_READ_BOOL (this_node, dropCallsOnFail);
NODE_READ_UNSIGNED (this_node, unregWaitMsec);
@@ -55,6 +56,7 @@ void AccountRegConfig::writeObject(ContainerNode &node) const throw(Error)
NODE_WRITE_UNSIGNED (this_node, timeoutSec);
NODE_WRITE_UNSIGNED (this_node, retryIntervalSec);
NODE_WRITE_UNSIGNED (this_node, firstRetryIntervalSec);
+ NODE_WRITE_UNSIGNED (this_node, randomRetryIntervalSec);
NODE_WRITE_UNSIGNED (this_node, delayBeforeRefreshSec);
NODE_WRITE_BOOL (this_node, dropCallsOnFail);
NODE_WRITE_UNSIGNED (this_node, unregWaitMsec);
@@ -318,6 +320,7 @@ void AccountConfig::toPj(pjsua_acc_config &ret) const
ret.reg_timeout = regConfig.timeoutSec;
ret.reg_retry_interval = regConfig.retryIntervalSec;
ret.reg_first_retry_interval= regConfig.firstRetryIntervalSec;
+ ret.reg_retry_random_interval= regConfig.randomRetryIntervalSec;
ret.reg_delay_before_refresh= regConfig.delayBeforeRefreshSec;
ret.drop_calls_on_reg_fail = regConfig.dropCallsOnFail;
ret.unreg_timeout = regConfig.unregWaitMsec;
@@ -445,6 +448,7 @@ void AccountConfig::fromPj(const pjsua_acc_config &prm,
regConfig.timeoutSec = prm.reg_timeout;
regConfig.retryIntervalSec = prm.reg_retry_interval;
regConfig.firstRetryIntervalSec = prm.reg_first_retry_interval;
+ regConfig.randomRetryIntervalSec = prm.reg_retry_random_interval;
regConfig.delayBeforeRefreshSec = prm.reg_delay_before_refresh;
regConfig.dropCallsOnFail = PJ2BOOL(prm.drop_calls_on_reg_fail);
regConfig.unregWaitMsec = prm.unreg_timeout;