Commit 6981429e authored by Fabrice Bellet's avatar Fabrice Bellet

discovery: enforce stun requests pacing

Only a single STUN request should be sent per discovery tick to enforce
an overall pacing of 20ms per default between two STUN requests.
parent 3273cacf
...@@ -1087,6 +1087,7 @@ static gboolean priv_discovery_tick_unlocked (NiceAgent *agent) ...@@ -1087,6 +1087,7 @@ static gboolean priv_discovery_tick_unlocked (NiceAgent *agent)
CandidateDiscovery *cand; CandidateDiscovery *cand;
GSList *i; GSList *i;
int not_done = 0; /* note: track whether to continue timer */ int not_done = 0; /* note: track whether to continue timer */
int need_pacing = 0;
size_t buffer_len = 0; size_t buffer_len = 0;
{ {
...@@ -1166,6 +1167,7 @@ static gboolean priv_discovery_tick_unlocked (NiceAgent *agent) ...@@ -1166,6 +1167,7 @@ static gboolean priv_discovery_tick_unlocked (NiceAgent *agent)
} }
cand->next_tick = g_get_monotonic_time (); cand->next_tick = g_get_monotonic_time ();
++need_pacing;
} else { } else {
/* case: error in starting discovery, start the next discovery */ /* case: error in starting discovery, start the next discovery */
nice_debug ("Agent %p : Error starting discovery, skipping the item.", nice_debug ("Agent %p : Error starting discovery, skipping the item.",
...@@ -1183,6 +1185,9 @@ static gboolean priv_discovery_tick_unlocked (NiceAgent *agent) ...@@ -1183,6 +1185,9 @@ static gboolean priv_discovery_tick_unlocked (NiceAgent *agent)
++not_done; /* note: new discovery scheduled */ ++not_done; /* note: new discovery scheduled */
} }
if (need_pacing)
break;
if (cand->done != TRUE) { if (cand->done != TRUE) {
gint64 now = g_get_monotonic_time (); gint64 now = g_get_monotonic_time ();
...@@ -1224,6 +1229,7 @@ static gboolean priv_discovery_tick_unlocked (NiceAgent *agent) ...@@ -1224,6 +1229,7 @@ static gboolean priv_discovery_tick_unlocked (NiceAgent *agent)
cand->next_tick = now + (timeout * 1000); cand->next_tick = now + (timeout * 1000);
++not_done; /* note: retry later */ ++not_done; /* note: retry later */
++need_pacing;
break; break;
} }
case STUN_USAGE_TIMER_RETURN_SUCCESS: case STUN_USAGE_TIMER_RETURN_SUCCESS:
...@@ -1244,6 +1250,9 @@ static gboolean priv_discovery_tick_unlocked (NiceAgent *agent) ...@@ -1244,6 +1250,9 @@ static gboolean priv_discovery_tick_unlocked (NiceAgent *agent)
++not_done; /* note: discovery not expired yet */ ++not_done; /* note: discovery not expired yet */
} }
} }
if (need_pacing)
break;
} }
if (not_done == 0) { if (not_done == 0) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment