~ubuntu-branches/debian/stretch/libnice/stretch

« back to all changes in this revision

Viewing changes to stun/usages/timer.c

Tags: 0.1.0-2
Add a Breaks: libgstfarsight0.10-0 (<< 0.22) for the gstreamer plugin as
farsight uses one libnice ABI and the gstreamer element uses another
libnice ABI things tend to go horribly wrong.

Show diffs side-by-side

added added

removed removed

Lines of Context:
51
51
 
52
52
#include <stdlib.h> /* div() */
53
53
 
54
 
 
55
 
/*
56
 
 * Initial STUN timeout (milliseconds). The spec says it should be 100ms,
57
 
 * but that's way too short for most types of wireless Internet access.
58
 
 */
59
 
#define STUN_INIT_TIMEOUT 600
60
 
#define STUN_END_TIMEOUT 4800
61
 
 
62
 
#define STUN_RELIABLE_TIMEOUT 7900
63
 
 
64
 
#if STUN_RELIABLE_TIMEOUT < STUN_END_TIMEOUT
65
 
/* Reliable timeout MUST be bigger (or equal) to end timeout, so that
66
 
 * retransmissions never happen with reliable transports. */
67
 
# error Inconsistent STUN timeout values!
68
 
#endif
69
 
 
70
 
 
71
54
/*
72
55
 * Clock used throughout the STUN code.
73
56
 * STUN requires a monotonic 1kHz clock to operate properly.
99
82
  {  // fallback to wall clock
100
83
    gettimeofday (now, NULL);
101
84
  }
102
 
#endif 
 
85
#endif
103
86
}
104
87
 
105
88
 
117
100
}
118
101
 
119
102
 
120
 
void stun_timer_start (StunTimer *timer)
 
103
void stun_timer_start (StunTimer *timer, unsigned int initial_timeout,
 
104
    unsigned int max_retransmissions)
121
105
{
122
106
  stun_gettime (&timer->deadline);
123
 
  add_delay (&timer->deadline, timer->delay = STUN_INIT_TIMEOUT);
 
107
  timer->delay = initial_timeout;
 
108
  timer->max_retransmissions = max_retransmissions;
 
109
  add_delay (&timer->deadline, timer->delay);
124
110
}
125
111
 
126
112
 
127
 
void stun_timer_start_reliable (StunTimer *timer)
 
113
void stun_timer_start_reliable (StunTimer *timer, unsigned int initial_timeout)
128
114
{
129
 
  stun_gettime (&timer->deadline);
130
 
  add_delay (&timer->deadline, timer->delay = STUN_RELIABLE_TIMEOUT);
 
115
  stun_timer_start (timer, initial_timeout, 0);
131
116
}
132
117
 
133
118
 
156
141
  unsigned delay = stun_timer_remainder (timer);
157
142
  if (delay == 0)
158
143
  {
159
 
    if (timer->delay >= STUN_END_TIMEOUT)
 
144
    if (timer->retransmissions >= timer->max_retransmissions)
160
145
      return STUN_USAGE_TIMER_RETURN_TIMEOUT;
161
146
 
162
147
    add_delay (&timer->deadline, timer->delay *= 2);
 
148
    timer->retransmissions++;
163
149
    return STUN_USAGE_TIMER_RETURN_RETRANSMIT;
164
150
  }
165
151