Commit ce745d25 authored by Rohan Garg's avatar Rohan Garg
Browse files

Add conn_check_add_for_local_candidate to add the newly found local candidate to the conncheck list

conn_check_add_for_local_candidate works exactly like conn_check_add_for_candidate
except that it starts connchecks for newly found local candidates with existing
remote candidates

Refactor priv_add_local_candidate_pruned to accept a NiceAgent and a stream_id
in order to call conn_check_add_for_local_candidate for newly gathered local candidate
parent 2f8773d4
......@@ -1286,6 +1286,40 @@ static void priv_add_new_check_pair (NiceAgent *agent, guint stream_id, Componen
}
}
static gboolean priv_conn_check_add_for_candidate_pair (NiceAgent *agent, guint stream_id, Component *component, NiceCandidate *local, NiceCandidate *remote)
{
gboolean ret = FALSE;
/* note: do not create pairs where the local candidate is
* a srv-reflexive (ICE 5.7.3. "Pruning the pairs" ID-9) */
if ((agent->compatibility == NICE_COMPATIBILITY_RFC5245 ||
agent->compatibility == NICE_COMPATIBILITY_WLM2009 ||
agent->compatibility == NICE_COMPATIBILITY_OC2007R2) &&
local->type == NICE_CANDIDATE_TYPE_SERVER_REFLEXIVE) {
return FALSE;
}
/* note: match pairs only if transport and address family are the same */
if (local->transport == remote->transport &&
local->addr.s.addr.sa_family == remote->addr.s.addr.sa_family) {
priv_add_new_check_pair (agent, stream_id, component, local, remote, NICE_CHECK_FROZEN, FALSE);
ret = TRUE;
if (component->state < NICE_COMPONENT_STATE_CONNECTED) {
agent_signal_component_state_change (agent,
stream_id,
component->id,
NICE_COMPONENT_STATE_CONNECTING);
} else {
agent_signal_component_state_change (agent,
stream_id,
component->id,
NICE_COMPONENT_STATE_CONNECTED);
}
}
return ret;
}
/*
* Forms new candidate pairs by matching the new remote candidate
* 'remote_cand' with all existing local candidates of 'component'.
......@@ -1301,37 +1335,45 @@ static void priv_add_new_check_pair (NiceAgent *agent, guint stream_id, Componen
int conn_check_add_for_candidate (NiceAgent *agent, guint stream_id, Component *component, NiceCandidate *remote)
{
GSList *i;
int added = 0;
int added = 0;
int ret = 0;
for (i = component->local_candidates; i ; i = i->next) {
NiceCandidate *local = i->data;
ret = priv_conn_check_add_for_candidate_pair (agent, stream_id, component, local, remote);
if (ret) {
++added;
}
}
return added;
}
/*
* Forms new candidate pairs by matching the new local candidate
* 'local_cand' with all existing remote candidates of 'component'.
*
* @param agent context
* @param component pointer to the component
* @param local local candidate to match with
*
* @return number of checks added, negative on fatal errors
*/
int conn_check_add_for_local_candidate (NiceAgent *agent, guint stream_id, Component *component, NiceCandidate *local)
{
GSList *i;
int added = 0;
int ret = 0;
/* note: match pairs only if transport and address family are the same */
if (local->transport == remote->transport &&
local->addr.s.addr.sa_family == remote->addr.s.addr.sa_family) {
for (i = component->remote_candidates; i ; i = i->next) {
/* note: do not create pairs where local candidate is
* a srv-reflexive (ICE 5.7.3. "Pruning the Pairs" ID-19) */
if ((agent->compatibility == NICE_COMPATIBILITY_RFC5245 ||
agent->compatibility == NICE_COMPATIBILITY_WLM2009 ||
agent->compatibility == NICE_COMPATIBILITY_OC2007R2) &&
local->type == NICE_CANDIDATE_TYPE_SERVER_REFLEXIVE)
continue;
NiceCandidate *remote = i->data;
ret = priv_conn_check_add_for_candidate_pair (agent, stream_id, component, local, remote);
priv_add_new_check_pair (agent, stream_id, component, local, remote, NICE_CHECK_FROZEN, FALSE);
if (ret) {
++added;
if (component->state < NICE_COMPONENT_STATE_CONNECTED) {
agent_signal_component_state_change (agent,
stream_id,
component->id,
NICE_COMPONENT_STATE_CONNECTING);
} else {
agent_signal_component_state_change (agent,
stream_id,
component->id,
NICE_COMPONENT_STATE_CONNECTED);
}
}
}
......
......@@ -82,6 +82,7 @@ struct _CandidateCheckPair
};
int conn_check_add_for_candidate (NiceAgent *agent, guint stream_id, Component *component, NiceCandidate *remote);
int conn_check_add_for_local_candidate (NiceAgent *agent, guint stream_id, Component *component, NiceCandidate *local);
void conn_check_free_item (gpointer data, gpointer user_data);
void conn_check_free (NiceAgent *agent);
gboolean conn_check_schedule_next (NiceAgent *agent);
......
......@@ -247,7 +247,7 @@ void refresh_cancel (CandidateRefresh *refresh)
* defined in ICE spec section 4.1.3 "Eliminating Redundant
* Candidates" (ID-19).
*/
static gboolean priv_add_local_candidate_pruned (Component *component, NiceCandidate *candidate)
static gboolean priv_add_local_candidate_pruned (NiceAgent *agent, guint stream_id, Component *component, NiceCandidate *candidate)
{
GSList *i;
......@@ -263,6 +263,7 @@ static gboolean priv_add_local_candidate_pruned (Component *component, NiceCandi
component->local_candidates = g_slist_append (component->local_candidates,
candidate);
conn_check_add_for_local_candidate(agent, stream_id, component, candidate);
return TRUE;
}
......@@ -489,7 +490,7 @@ NiceCandidate *discovery_add_local_host_candidate (
candidate->addr = udp_socket->addr;
candidate->base_addr = udp_socket->addr;
if (!priv_add_local_candidate_pruned (component, candidate))
if (!priv_add_local_candidate_pruned (agent, stream_id, component, candidate))
goto errors;
component->sockets = g_slist_append (component->sockets, udp_socket);
......@@ -547,7 +548,7 @@ discovery_add_server_reflexive_candidate (
priv_generate_candidate_credentials (agent, candidate);
priv_assign_foundation (agent, candidate);
result = priv_add_local_candidate_pruned (component, candidate);
result = priv_add_local_candidate_pruned (agent, stream_id, component, candidate);
if (result) {
agent_signal_new_candidate (agent, candidate);
}
......@@ -620,7 +621,7 @@ discovery_add_relay_candidate (
priv_assign_foundation (agent, candidate);
if (!priv_add_local_candidate_pruned (component, candidate))
if (!priv_add_local_candidate_pruned (agent, stream_id, component, candidate))
goto errors;
component->sockets = g_slist_append (component->sockets, relay_socket);
......@@ -715,9 +716,9 @@ discovery_add_peer_reflexive_candidate (
candidate->sockptr = base_socket;
candidate->base_addr = base_socket->addr;
result = priv_add_local_candidate_pruned (component, candidate);
result = priv_add_local_candidate_pruned (agent, stream_id, component, candidate);
if (result != TRUE) {
/* error: memory allocation, or duplicate candidatet */
/* error: memory allocation, or duplicate candidate */
nice_candidate_free (candidate), candidate = NULL;
}
......
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