Commit ade16ee9 authored by Fabrice Bellet's avatar Fabrice Bellet Committed by Olivier Crête
Browse files

stun: set delay in retransmission instead of adding it

We may have situation when stun_timer_refresh is called with a
significant delay after the current deadline. In the actual situation,
this delay is just included to the computation of the new deadline of the
next stun retransmission. We think this may lead to unfair situations,
where the next deadline may be too short, just to compensate the first
deadline that was too long.

For example, if a stun request is scheduled with a delay of
200ms for the 2nd transmission, and 400ms for the 3rd transmission,
if stun_timer_remainder() is called 300ms after the start of the
timer, the second delay will last only 300ms, instead of 400ms.
parent c4993988
Pipeline #143182 passed with stages
in 11 minutes and 36 seconds
......@@ -86,8 +86,10 @@ static void stun_gettime (struct timeval *now)
}
static void add_delay (struct timeval *ts, unsigned delay)
static void set_delay (struct timeval *ts, unsigned delay)
{
stun_gettime (ts);
/* Delay is in ms. */
ts->tv_sec += delay / 1000;
ts->tv_usec += (delay % 1000) * 1000;
......@@ -103,11 +105,10 @@ static void add_delay (struct timeval *ts, unsigned delay)
void stun_timer_start (StunTimer *timer, unsigned int initial_timeout,
unsigned int max_retransmissions)
{
stun_gettime (&timer->deadline);
timer->retransmissions = 1;
timer->delay = initial_timeout;
timer->max_retransmissions = max_retransmissions;
add_delay (&timer->deadline, timer->delay);
set_delay (&timer->deadline, timer->delay);
}
......@@ -149,7 +150,7 @@ StunUsageTimerReturn stun_timer_refresh (StunTimer *timer)
timer->delay = timer->delay / 2;
else
timer->delay = timer->delay * 2;
add_delay (&timer->deadline, timer->delay);
set_delay (&timer->deadline, timer->delay);
timer->retransmissions++;
return STUN_USAGE_TIMER_RETURN_RETRANSMIT;
}
......
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