summaryrefslogtreecommitdiff
path: root/pjsip
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
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')
-rw-r--r--pjsip/include/pjsua-lib/pjsua.h22
-rw-r--r--pjsip/include/pjsua2/account.hpp29
-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
5 files changed, 59 insertions, 13 deletions
diff --git a/pjsip/include/pjsua-lib/pjsua.h b/pjsip/include/pjsua-lib/pjsua.h
index 4d5fa69a..31c5378b 100644
--- a/pjsip/include/pjsua-lib/pjsua.h
+++ b/pjsip/include/pjsua-lib/pjsua.h
@@ -3292,8 +3292,9 @@ typedef struct pjsua_acc_config
* disable auto re-registration. Note that if the registration retry
* occurs because of transport failure, the first retry will be done
* after \a reg_first_retry_interval seconds instead. Also note that
- * the interval will be randomized slightly by approximately +/- ten
- * seconds to avoid all clients re-registering at the same time.
+ * the interval will be randomized slightly by some seconds (specified
+ * in \a reg_retry_random_interval) to avoid all clients re-registering
+ * at the same time.
*
* See also \a reg_first_retry_interval setting.
*
@@ -3304,13 +3305,28 @@ typedef struct pjsua_acc_config
/**
* This specifies the interval for the first registration retry. The
* registration retry is explained in \a reg_retry_interval. Note that
- * the value here will also be randomized by +/- ten seconds.
+ * the value here will also be randomized by some seconds (specified
+ * in \a reg_retry_random_interval) to avoid all clients re-registering
+ * at the same time.
*
* Default: 0
*/
unsigned reg_first_retry_interval;
/**
+ * This specifies maximum randomized value to be added/substracted
+ * to/from the registration retry interval specified in \a
+ * reg_retry_interval and \a reg_first_retry_interval, in second.
+ * This is useful to avoid all clients re-registering at the same time.
+ * For example, if the registration retry interval is set to 100 seconds
+ * and this is set to 10 seconds, the actual registration retry interval
+ * will be in the range of 90 to 110 seconds.
+ *
+ * Default: 10
+ */
+ unsigned reg_retry_random_interval;
+
+ /**
* Specify whether calls of the configured account should be dropped
* after registration failure and an attempt of re-registration has
* also failed.
diff --git a/pjsip/include/pjsua2/account.hpp b/pjsip/include/pjsua2/account.hpp
index 106ad9d7..acb78165 100644
--- a/pjsip/include/pjsua2/account.hpp
+++ b/pjsip/include/pjsua2/account.hpp
@@ -81,10 +81,12 @@ struct AccountRegConfig : public PersistentObject
* disable auto re-registration. Note that if the registration retry
* occurs because of transport failure, the first retry will be done
* after \a firstRetryIntervalSec seconds instead. Also note that
- * the interval will be randomized slightly by approximately +/- ten
- * seconds to avoid all clients re-registering at the same time.
+ * the interval will be randomized slightly by some seconds (specified
+ * in \a reg_retry_random_interval) to avoid all clients re-registering
+ * at the same time.
*
- * See also \a firstRetryIntervalSec setting.
+ * See also \a firstRetryIntervalSec and \a randomRetryIntervalSec
+ * settings.
*
* Default: PJSUA_REG_RETRY_INTERVAL
*/
@@ -93,13 +95,32 @@ struct AccountRegConfig : public PersistentObject
/**
* This specifies the interval for the first registration retry. The
* registration retry is explained in \a retryIntervalSec. Note that
- * the value here will also be randomized by +/- ten seconds.
+ * the value here will also be randomized by some seconds (specified
+ * in \a reg_retry_random_interval) to avoid all clients re-registering
+ * at the same time.
+ *
+ * See also \a retryIntervalSec and \a randomRetryIntervalSec settings.
*
* Default: 0
*/
unsigned firstRetryIntervalSec;
/**
+ * This specifies maximum randomized value to be added/substracted
+ * to/from the registration retry interval specified in \a
+ * reg_retry_interval and \a reg_first_retry_interval, in second.
+ * This is useful to avoid all clients re-registering at the same time.
+ * For example, if the registration retry interval is set to 100 seconds
+ * and this is set to 10 seconds, the actual registration retry interval
+ * will be in the range of 90 to 110 seconds.
+ *
+ * See also \a retryIntervalSec and \a firstRetryIntervalSec settings.
+ *
+ * Default: 10
+ */
+ unsigned randomRetryIntervalSec;
+
+ /**
* Specify the number of seconds to refresh the client registration
* before the registration expires.
*
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;