Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
L
libnice
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
libnice
Commits
f159c3aa
Commit
f159c3aa
authored
Sep 29, 2010
by
Youness Alaoui
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make stun_timer timeouts configurable (breaks API)
parent
ea418a22
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
75 additions
and
36 deletions
+75
-36
agent/conncheck.c
agent/conncheck.c
+6
-3
agent/discovery.c
agent/discovery.c
+2
-1
docs/reference/libnice/libnice-sections.txt
docs/reference/libnice/libnice-sections.txt
+3
-0
socket/turn.c
socket/turn.c
+4
-2
stun/usages/bind.c
stun/usages/bind.c
+4
-2
stun/usages/timer.c
stun/usages/timer.c
+10
-24
stun/usages/timer.h
stun/usages/timer.h
+46
-4
No files found.
agent/conncheck.c
View file @
f159c3aa
...
@@ -605,7 +605,8 @@ static gboolean priv_conn_keepalive_tick_unlocked (NiceAgent *agent)
...
@@ -605,7 +605,8 @@ static gboolean priv_conn_keepalive_tick_unlocked (NiceAgent *agent)
agent
,
buf_len
,
p
->
keepalive
.
stun_message
.
buffer
);
agent
,
buf_len
,
p
->
keepalive
.
stun_message
.
buffer
);
if
(
buf_len
>
0
)
{
if
(
buf_len
>
0
)
{
stun_timer_start
(
&
p
->
keepalive
.
timer
);
stun_timer_start
(
&
p
->
keepalive
.
timer
,
STUN_TIMER_DEFAULT_TIMEOUT
,
STUN_TIMER_DEFAULT_MAX_RETRANSMISSIONS
);
agent
->
media_after_tick
=
FALSE
;
agent
->
media_after_tick
=
FALSE
;
...
@@ -823,7 +824,8 @@ static void priv_turn_allocate_refresh_tick_unlocked (CandidateRefresh *cand)
...
@@ -823,7 +824,8 @@ static void priv_turn_allocate_refresh_tick_unlocked (CandidateRefresh *cand)
}
}
if
(
buffer_len
>
0
)
{
if
(
buffer_len
>
0
)
{
stun_timer_start
(
&
cand
->
timer
);
stun_timer_start
(
&
cand
->
timer
,
STUN_TIMER_DEFAULT_TIMEOUT
,
STUN_TIMER_DEFAULT_MAX_RETRANSMISSIONS
);
/* send the refresh */
/* send the refresh */
nice_socket_send
(
cand
->
nicesock
,
&
cand
->
server
,
nice_socket_send
(
cand
->
nicesock
,
&
cand
->
server
,
...
@@ -1642,7 +1644,8 @@ int conn_check_send (NiceAgent *agent, CandidateCheckPair *pair)
...
@@ -1642,7 +1644,8 @@ int conn_check_send (NiceAgent *agent, CandidateCheckPair *pair)
}
}
if
(
buffer_len
>
0
)
{
if
(
buffer_len
>
0
)
{
stun_timer_start
(
&
pair
->
timer
);
stun_timer_start
(
&
pair
->
timer
,
STUN_TIMER_DEFAULT_TIMEOUT
,
STUN_TIMER_DEFAULT_MAX_RETRANSMISSIONS
);
/* send the conncheck */
/* send the conncheck */
nice_socket_send
(
pair
->
local
->
sockptr
,
&
pair
->
remote
->
addr
,
nice_socket_send
(
pair
->
local
->
sockptr
,
&
pair
->
remote
->
addr
,
...
...
agent/discovery.c
View file @
f159c3aa
...
@@ -886,7 +886,8 @@ static gboolean priv_discovery_tick_unlocked (gpointer pointer)
...
@@ -886,7 +886,8 @@ static gboolean priv_discovery_tick_unlocked (gpointer pointer)
}
}
if
(
buffer_len
>
0
)
{
if
(
buffer_len
>
0
)
{
stun_timer_start
(
&
cand
->
timer
);
stun_timer_start
(
&
cand
->
timer
,
200
,
STUN_TIMER_DEFAULT_MAX_RETRANSMISSIONS
);
/* send the conncheck */
/* send the conncheck */
nice_socket_send
(
cand
->
nicesock
,
&
cand
->
server
,
nice_socket_send
(
cand
->
nicesock
,
&
cand
->
server
,
...
...
docs/reference/libnice/libnice-sections.txt
View file @
f159c3aa
...
@@ -205,6 +205,9 @@ stun_usage_ice_conncheck_use_candidate
...
@@ -205,6 +205,9 @@ stun_usage_ice_conncheck_use_candidate
<TITLE>Timer</TITLE>
<TITLE>Timer</TITLE>
StunTimer
StunTimer
StunUsageTimerReturn
StunUsageTimerReturn
STUN_TIMER_DEFAULT_MAX_RETRANSMISSIONS
STUN_TIMER_DEFAULT_RELIABLE_TIMEOUT
STUN_TIMER_DEFAULT_TIMEOUT
stun_timer_start
stun_timer_start
stun_timer_start_reliable
stun_timer_start_reliable
stun_timer_refresh
stun_timer_refresh
...
...
socket/turn.c
View file @
f159c3aa
...
@@ -697,9 +697,11 @@ priv_send_turn_message (TurnPriv *priv, TURNMessage *msg)
...
@@ -697,9 +697,11 @@ priv_send_turn_message (TurnPriv *priv, TURNMessage *msg)
stun_len
,
(
gchar
*
)
msg
->
buffer
);
stun_len
,
(
gchar
*
)
msg
->
buffer
);
if
(
nice_socket_is_reliable
(
priv
->
base_socket
))
{
if
(
nice_socket_is_reliable
(
priv
->
base_socket
))
{
stun_timer_start_reliable
(
&
msg
->
timer
);
stun_timer_start_reliable
(
&
msg
->
timer
,
STUN_TIMER_DEFAULT_RELIABLE_TIMEOUT
);
}
else
{
}
else
{
stun_timer_start
(
&
msg
->
timer
);
stun_timer_start
(
&
msg
->
timer
,
STUN_TIMER_DEFAULT_TIMEOUT
,
STUN_TIMER_DEFAULT_MAX_RETRANSMISSIONS
);
}
}
priv
->
current_binding_msg
=
msg
;
priv
->
current_binding_msg
=
msg
;
...
...
stun/usages/bind.c
View file @
f159c3aa
...
@@ -460,7 +460,8 @@ StunUsageBindReturn stun_usage_bind_run (const struct sockaddr *srv,
...
@@ -460,7 +460,8 @@ StunUsageBindReturn stun_usage_bind_run (const struct sockaddr *srv,
return
STUN_USAGE_BIND_RETURN_ERROR
;
return
STUN_USAGE_BIND_RETURN_ERROR
;
}
}
stun_timer_start
(
&
timer
);
stun_timer_start
(
&
timer
,
STUN_TIMER_DEFAULT_TIMEOUT
,
STUN_TIMER_DEFAULT_MAX_RETRANSMISSIONS
);
stun_debug
(
"STUN transaction started (timeout %dms).
\n
"
,
stun_debug
(
"STUN transaction started (timeout %dms).
\n
"
,
stun_timer_remainder
(
&
timer
));
stun_timer_remainder
(
&
timer
));
...
@@ -516,7 +517,8 @@ StunUsageBindReturn stun_usage_bind_run (const struct sockaddr *srv,
...
@@ -516,7 +517,8 @@ StunUsageBindReturn stun_usage_bind_run (const struct sockaddr *srv,
if
(
val
<
-
1
)
if
(
val
<
-
1
)
return
STUN_USAGE_BIND_RETURN_ERROR
;
return
STUN_USAGE_BIND_RETURN_ERROR
;
stun_timer_start
(
&
timer
);
stun_timer_start
(
&
timer
,
STUN_TIMER_DEFAULT_TIMEOUT
,
STUN_TIMER_DEFAULT_MAX_RETRANSMISSIONS
);
ret
=
STUN_USAGE_TRANS_RETURN_RETRY
;
ret
=
STUN_USAGE_TRANS_RETURN_RETRY
;
}
else
if
(
bind_ret
==
STUN_USAGE_BIND_RETURN_INVALID
)
{
}
else
if
(
bind_ret
==
STUN_USAGE_BIND_RETURN_INVALID
)
{
ret
=
STUN_USAGE_TRANS_RETURN_RETRY
;
ret
=
STUN_USAGE_TRANS_RETURN_RETRY
;
...
...
stun/usages/timer.c
View file @
f159c3aa
...
@@ -51,23 +51,6 @@
...
@@ -51,23 +51,6 @@
#include <stdlib.h>
/* div() */
#include <stdlib.h>
/* div() */
/*
* Initial STUN timeout (milliseconds). The spec says it should be 100ms,
* but that's way too short for most types of wireless Internet access.
*/
#define STUN_INIT_TIMEOUT 600
#define STUN_END_TIMEOUT 4800
#define STUN_RELIABLE_TIMEOUT 7900
#if STUN_RELIABLE_TIMEOUT < STUN_END_TIMEOUT
/* Reliable timeout MUST be bigger (or equal) to end timeout, so that
* retransmissions never happen with reliable transports. */
# error Inconsistent STUN timeout values!
#endif
/*
/*
* Clock used throughout the STUN code.
* Clock used throughout the STUN code.
* STUN requires a monotonic 1kHz clock to operate properly.
* STUN requires a monotonic 1kHz clock to operate properly.
...
@@ -117,17 +100,19 @@ static void add_delay (struct timeval *ts, unsigned delay)
...
@@ -117,17 +100,19 @@ static void add_delay (struct timeval *ts, unsigned delay)
}
}
void
stun_timer_start
(
StunTimer
*
timer
)
void
stun_timer_start
(
StunTimer
*
timer
,
unsigned
int
initial_timeout
,
unsigned
int
max_retransmissions
)
{
{
stun_gettime
(
&
timer
->
deadline
);
stun_gettime
(
&
timer
->
deadline
);
add_delay
(
&
timer
->
deadline
,
timer
->
delay
=
STUN_INIT_TIMEOUT
);
timer
->
delay
=
initial_timeout
;
timer
->
max_retransmissions
=
max_retransmissions
;
add_delay
(
&
timer
->
deadline
,
timer
->
delay
);
}
}
void
stun_timer_start_reliable
(
StunTimer
*
timer
)
void
stun_timer_start_reliable
(
StunTimer
*
timer
,
unsigned
int
initial_timeout
)
{
{
stun_gettime
(
&
timer
->
deadline
);
stun_timer_start
(
timer
,
initial_timeout
,
0
);
add_delay
(
&
timer
->
deadline
,
timer
->
delay
=
STUN_RELIABLE_TIMEOUT
);
}
}
...
@@ -156,10 +141,11 @@ StunUsageTimerReturn stun_timer_refresh (StunTimer *timer)
...
@@ -156,10 +141,11 @@ StunUsageTimerReturn stun_timer_refresh (StunTimer *timer)
unsigned
delay
=
stun_timer_remainder
(
timer
);
unsigned
delay
=
stun_timer_remainder
(
timer
);
if
(
delay
==
0
)
if
(
delay
==
0
)
{
{
if
(
timer
->
delay
>=
STUN_END_TIMEOUT
)
if
(
timer
->
retransmissions
>=
timer
->
max_retransmissions
)
return
STUN_USAGE_TIMER_RETURN_TIMEOUT
;
return
STUN_USAGE_TIMER_RETURN_TIMEOUT
;
add_delay
(
&
timer
->
deadline
,
timer
->
delay
*=
2
);
add_delay
(
&
timer
->
deadline
,
timer
->
delay
*=
2
);
timer
->
retransmissions
++
;
return
STUN_USAGE_TIMER_RETURN_RETRANSMIT
;
return
STUN_USAGE_TIMER_RETURN_RETRANSMIT
;
}
}
...
...
stun/usages/timer.h
View file @
f159c3aa
...
@@ -62,7 +62,8 @@
...
@@ -62,7 +62,8 @@
// Send the message and start the timer
// Send the message and start the timer
send(socket, request, sizeof(request));
send(socket, request, sizeof(request));
stun_timer_start(&timer);
stun_timer_start(&timer, STUN_TIMER_DEFAULT_TIMEOUT,
STUN_TIMER_DEFAULT_MAX_RETRANSMISSIONS);
// Loop until we get the response
// Loop until we get the response
for (;;) {
for (;;) {
...
@@ -120,9 +121,32 @@ typedef struct stun_timer_s StunTimer;
...
@@ -120,9 +121,32 @@ typedef struct stun_timer_s StunTimer;
struct
stun_timer_s
{
struct
stun_timer_s
{
struct
timeval
deadline
;
struct
timeval
deadline
;
unsigned
delay
;
unsigned
delay
;
unsigned
retransmissions
;
unsigned
max_retransmissions
;
};
};
/**
* STUN_TIMER_DEFAULT_TIMEOUT:
*
* The default intial timeout to use for the timer
*/
#define STUN_TIMER_DEFAULT_TIMEOUT 600
/**
* STUN_TIMER_DEFAULT_MAX_RETRANSMISSIONS:
*
* The default maximum retransmissions allowed before a timer decides to timeout
*/
#define STUN_TIMER_DEFAULT_MAX_RETRANSMISSIONS 3
/**
* STUN_TIMER_DEFAULT_RELIABLE_TIMEOUT:
*
* The default intial timeout to use for a reliable timer
*/
#define STUN_TIMER_DEFAULT_RELIABLE_TIMEOUT 7900
/**
/**
* StunUsageTimerReturn:
* StunUsageTimerReturn:
* @STUN_USAGE_TIMER_RETURN_SUCCESS: The timer was refreshed successfully
* @STUN_USAGE_TIMER_RETURN_SUCCESS: The timer was refreshed successfully
...
@@ -145,15 +169,33 @@ typedef enum {
...
@@ -145,15 +169,33 @@ typedef enum {
extern
"C"
{
extern
"C"
{
# endif
# endif
/**
/**
* stun_timer_start:
* stun_timer_start:
* @timer: The #StunTimer to start
* @timer: The #StunTimer to start
* @initial_timeout: The initial timeout to use before the first retransmission
* @max_retransmissions: The maximum number of transmissions before the
* #StunTimer times out
*
*
* Starts a STUN transaction retransmission timer.
* Starts a STUN transaction retransmission timer.
* This should be called as soon as you send the message for the first time on
* This should be called as soon as you send the message for the first time on
* a UDP socket
* a UDP socket.
* The timeout before the next retransmission is set to @initial_timeout, then
* each time a packet is retransmited, that timeout will be doubled, until the
* @max_retransmissions retransmissions limit is reached.
* <para>
* To determine the total timeout value, one can use the following equation :
<programlisting>
total_timeout = initial_timeout * (2^(max_retransmissions + 1) - 1);
</programlisting>
* </para>
*
* See also: #STUN_TIMER_DEFAULT_TIMEOUT
*
* See also: #STUN_TIMER_DEFAULT_MAX_RETRANSMISSIONS
*/
*/
void
stun_timer_start
(
StunTimer
*
timer
);
void
stun_timer_start
(
StunTimer
*
timer
,
unsigned
int
initial_timeout
,
unsigned
int
max_retransmissions
);
/**
/**
* stun_timer_start_reliable:
* stun_timer_start_reliable:
...
@@ -163,7 +205,7 @@ void stun_timer_start (StunTimer *timer);
...
@@ -163,7 +205,7 @@ void stun_timer_start (StunTimer *timer);
* This should be called as soon as you send the message for the first time on
* This should be called as soon as you send the message for the first time on
* a TCP socket
* a TCP socket
*/
*/
void
stun_timer_start_reliable
(
StunTimer
*
timer
);
void
stun_timer_start_reliable
(
StunTimer
*
timer
,
unsigned
int
initial_timeout
);
/**
/**
* stun_timer_refresh:
* stun_timer_refresh:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment