summaryrefslogtreecommitdiff
path: root/res
diff options
context:
space:
mode:
authorKinsey Moore <kmoore@digium.com>2014-12-09 14:00:50 +0000
committerKinsey Moore <kmoore@digium.com>2014-12-09 14:00:50 +0000
commit64581d894d570a3cfa5ae8b947f326e6fcaa9ef3 (patch)
treea00cdb38a3aa13c04596bac9826a4fadb6e269a8 /res
parentcbc91f50c1bd1ebeb62bcfc174fd8b1538dd67f7 (diff)
PJSIP: Stagger outbound qualifies
This change staggers initiation of outbound qualify (OPTIONS) attempts to reduce instantaneous server load and prevent network congestion. Review: https://reviewboard.asterisk.org/r/4246/ ASTERISK-24342 #close Reported by: Richard Mudgett ........ Merged revisions 429127 from http://svn.asterisk.org/svn/asterisk/branches/12 git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/13@429128 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'res')
-rw-r--r--res/res_pjsip/pjsip_options.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/res/res_pjsip/pjsip_options.c b/res/res_pjsip/pjsip_options.c
index 300f851ef..ac8302fae 100644
--- a/res/res_pjsip/pjsip_options.c
+++ b/res/res_pjsip/pjsip_options.c
@@ -418,14 +418,14 @@ static int qualify_contact_sched(const void *obj)
* up the data object ref between self deletion and an external
* deletion.
*/
- return 1;
+ return data->contact->qualify_frequency * 1000;
}
/*!
* \internal
* \brief Set up a scheduled qualify contact check.
*/
-static void schedule_qualify(struct ast_sip_contact *contact)
+static void schedule_qualify(struct ast_sip_contact *contact, int initial_interval)
{
struct sched_data *data;
@@ -437,8 +437,8 @@ static void schedule_qualify(struct ast_sip_contact *contact)
ast_assert(contact->qualify_frequency != 0);
ao2_t_ref(data, +1, "Ref for qualify_contact_sched() scheduler entry");
- data->id = ast_sched_add_variable(sched, contact->qualify_frequency * 1000,
- qualify_contact_sched, data, 0);
+ data->id = ast_sched_add_variable(sched, initial_interval,
+ qualify_contact_sched, data, 1);
if (data->id < 0) {
ao2_t_ref(data, -1, "Cleanup failed scheduler add");
ast_log(LOG_ERROR, "Unable to schedule qualify for contact %s\n",
@@ -482,7 +482,7 @@ static void qualify_and_schedule(struct ast_sip_contact *contact)
ao2_ref(contact, -1);
}
- schedule_qualify(contact);
+ schedule_qualify(contact, contact->qualify_frequency * 1000);
} else {
delete_contact_status(contact);
}
@@ -951,11 +951,16 @@ static int qualify_and_schedule_cb(void *obj, void *arg, int flags)
{
struct ast_sip_contact *contact = obj;
struct ast_sip_aor *aor = arg;
+ int initial_interval;
contact->qualify_frequency = aor->qualify_frequency;
contact->authenticate_qualify = aor->authenticate_qualify;
- qualify_and_schedule(contact);
+ /* Delay initial qualification by a random fraction of the specified interval */
+ initial_interval = contact->qualify_frequency * 1000;
+ initial_interval = (int)(initial_interval * ast_random_double());
+
+ schedule_qualify(contact, initial_interval);
return 0;
}