summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabrice Bellet <fabrice@bellet.info>2020-04-05 21:02:47 +0200
committerOlivier CrĂȘte <olivier.crete@ocrete.ca>2020-05-07 00:22:48 +0000
commitade16ee939e54ab8ebf73043169edc6d32c3239c (patch)
treef1c42fbdc36bdddf508ff156dd7bd3d783ee8723
parentc4993988067a2bf5056fa3146314992c06bfe51d (diff)
downloadlibnice-ade16ee939e54ab8ebf73043169edc6d32c3239c.tar.gz
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.
-rw-r--r--stun/usages/timer.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/stun/usages/timer.c b/stun/usages/timer.c
index 5370cba..3a2f2e6 100644
--- a/stun/usages/timer.c
+++ b/stun/usages/timer.c
@@ -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;
}