Commit cd380325 authored by Fabrice Bellet's avatar Fabrice Bellet Committed by Olivier Crête

discovery: remove turn refresh after discarding relay candidate

When a redundant relay candidate is discarded, a turn refresh with zero
lifetime must be sent to release its allocation on the turn server.
parent b3426662
...@@ -1676,7 +1676,8 @@ static void priv_turn_allocate_refresh_tick_unlocked (NiceAgent *agent, ...@@ -1676,7 +1676,8 @@ static void priv_turn_allocate_refresh_tick_unlocked (NiceAgent *agent,
buffer_len = stun_usage_turn_create_refresh (&cand->stun_agent, buffer_len = stun_usage_turn_create_refresh (&cand->stun_agent,
&cand->stun_message, cand->stun_buffer, sizeof(cand->stun_buffer), &cand->stun_message, cand->stun_buffer, sizeof(cand->stun_buffer),
cand->stun_resp_msg.buffer == NULL ? NULL : &cand->stun_resp_msg, -1, cand->stun_resp_msg.buffer == NULL ? NULL : &cand->stun_resp_msg,
cand->disposing ? 0 : -1,
username, username_len, username, username_len,
password, password_len, password, password_len,
turn_compat); turn_compat);
...@@ -3823,7 +3824,6 @@ priv_add_new_turn_refresh (NiceAgent *agent, CandidateDiscovery *cdisco, ...@@ -3823,7 +3824,6 @@ priv_add_new_turn_refresh (NiceAgent *agent, CandidateDiscovery *cdisco,
return; return;
cand = g_slice_new0 (CandidateRefresh); cand = g_slice_new0 (CandidateRefresh);
agent->refresh_list = g_slist_append (agent->refresh_list, cand);
cand->candidate = relay_cand; cand->candidate = relay_cand;
cand->nicesock = cdisco->nicesock; cand->nicesock = cdisco->nicesock;
...@@ -3842,6 +3842,8 @@ priv_add_new_turn_refresh (NiceAgent *agent, CandidateDiscovery *cdisco, ...@@ -3842,6 +3842,8 @@ priv_add_new_turn_refresh (NiceAgent *agent, CandidateDiscovery *cdisco,
cand->stun_resp_msg.key = NULL; cand->stun_resp_msg.key = NULL;
} }
if (lifetime > 0) {
agent->refresh_list = g_slist_append (agent->refresh_list, cand);
nice_debug ("Agent %p : Adding new refresh candidate %p with timeout %d", nice_debug ("Agent %p : Adding new refresh candidate %p with timeout %d",
agent, cand, priv_calc_turn_timeout (lifetime)); agent, cand, priv_calc_turn_timeout (lifetime));
/* step: also start the refresh timer */ /* step: also start the refresh timer */
...@@ -3852,6 +3854,15 @@ priv_add_new_turn_refresh (NiceAgent *agent, CandidateDiscovery *cdisco, ...@@ -3852,6 +3854,15 @@ priv_add_new_turn_refresh (NiceAgent *agent, CandidateDiscovery *cdisco,
priv_turn_allocate_refresh_tick_agent_locked, cand); priv_turn_allocate_refresh_tick_agent_locked, cand);
nice_debug ("timer source is : %p", cand->timer_source); nice_debug ("timer source is : %p", cand->timer_source);
} else {
nice_debug ("Agent %p : Sending request to remove TURN allocation "
"for refresh %p", agent, cand);
cand->disposing = TRUE;
priv_turn_allocate_refresh_tick_unlocked (agent, cand);
if (relay_cand->sockptr)
nice_socket_free (relay_cand->sockptr);
nice_candidate_free ((NiceCandidate *)relay_cand);
}
return; return;
} }
...@@ -4022,7 +4033,8 @@ static gboolean priv_map_reply_to_relay_request (NiceAgent *agent, StunMessage * ...@@ -4022,7 +4033,8 @@ static gboolean priv_map_reply_to_relay_request (NiceAgent *agent, StunMessage *
&niceaddr, &niceaddr,
NICE_CANDIDATE_TRANSPORT_TCP_ACTIVE, NICE_CANDIDATE_TRANSPORT_TCP_ACTIVE,
d->nicesock, d->nicesock,
d->turn); d->turn,
&lifetime);
if (relay_cand) { if (relay_cand) {
if (agent->compatibility == NICE_COMPATIBILITY_OC2007 || if (agent->compatibility == NICE_COMPATIBILITY_OC2007 ||
...@@ -4042,7 +4054,8 @@ static gboolean priv_map_reply_to_relay_request (NiceAgent *agent, StunMessage * ...@@ -4042,7 +4054,8 @@ static gboolean priv_map_reply_to_relay_request (NiceAgent *agent, StunMessage *
&niceaddr, &niceaddr,
NICE_CANDIDATE_TRANSPORT_TCP_PASSIVE, NICE_CANDIDATE_TRANSPORT_TCP_PASSIVE,
d->nicesock, d->nicesock,
d->turn); d->turn,
&lifetime);
} else { } else {
relay_cand = discovery_add_relay_candidate ( relay_cand = discovery_add_relay_candidate (
agent, agent,
...@@ -4051,7 +4064,8 @@ static gboolean priv_map_reply_to_relay_request (NiceAgent *agent, StunMessage * ...@@ -4051,7 +4064,8 @@ static gboolean priv_map_reply_to_relay_request (NiceAgent *agent, StunMessage *
&niceaddr, &niceaddr,
NICE_CANDIDATE_TRANSPORT_UDP, NICE_CANDIDATE_TRANSPORT_UDP,
d->nicesock, d->nicesock,
d->turn); d->turn,
&lifetime);
} }
if (relay_cand) { if (relay_cand) {
......
...@@ -921,7 +921,8 @@ discovery_add_relay_candidate ( ...@@ -921,7 +921,8 @@ discovery_add_relay_candidate (
NiceAddress *address, NiceAddress *address,
NiceCandidateTransport transport, NiceCandidateTransport transport,
NiceSocket *base_socket, NiceSocket *base_socket,
TurnServer *turn) TurnServer *turn,
uint32_t *lifetime)
{ {
NiceCandidate *candidate; NiceCandidate *candidate;
NiceCandidateImpl *c; NiceCandidateImpl *c;
...@@ -974,8 +975,11 @@ discovery_add_relay_candidate ( ...@@ -974,8 +975,11 @@ discovery_add_relay_candidate (
priv_assign_foundation (agent, candidate); priv_assign_foundation (agent, candidate);
if (!priv_add_local_candidate_pruned (agent, stream_id, component, candidate)) if (!priv_add_local_candidate_pruned (agent, stream_id, component, candidate)) {
goto errors; if (lifetime)
*lifetime = 0;
return c;
}
nice_component_attach_socket (component, relay_socket); nice_component_attach_socket (component, relay_socket);
agent_signal_new_candidate (agent, candidate); agent_signal_new_candidate (agent, candidate);
......
...@@ -127,7 +127,8 @@ discovery_add_relay_candidate ( ...@@ -127,7 +127,8 @@ discovery_add_relay_candidate (
NiceAddress *address, NiceAddress *address,
NiceCandidateTransport transport, NiceCandidateTransport transport,
NiceSocket *base_socket, NiceSocket *base_socket,
TurnServer *turn); TurnServer *turn,
uint32_t *lifetime);
NiceCandidate* NiceCandidate*
discovery_add_server_reflexive_candidate ( discovery_add_server_reflexive_candidate (
......
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