Commit 8b0b8320 authored by Youness Alaoui's avatar Youness Alaoui

Fix checking for the remote candidate using the username, and correctly create...

Fix checking for the remote candidate using the username, and correctly create the remote peer reflexive candidate
parent 03f35676
......@@ -617,7 +617,7 @@ void conn_check_remote_candidates_set(NiceAgent *agent)
for (k = component->incoming_checks; k; k = k->next) {
IncomingCheck *icheck = k->data;
/* sect 7.2.1.3., "Learning Peer Reflexive Candidates", has to
/* sect 7.2.1.3., "Learning Peer Reflexive Candidates", has to
* be handled separately */
for (l = component->remote_candidates; l; l = l->next) {
NiceCandidate *cand = l->data;
......@@ -627,15 +627,16 @@ void conn_check_remote_candidates_set(NiceAgent *agent)
}
}
if (match != TRUE) {
/* note: we have gotten an incoming connectivity check from
/* note: we have gotten an incoming connectivity check from
* an address that is not a known remote candidate */
NiceCandidate *candidate =
discovery_learn_remote_peer_reflexive_candidate (agent,
stream,
component,
icheck->priority,
&icheck->from,
icheck->local_socket);
NiceCandidate *candidate =
discovery_learn_remote_peer_reflexive_candidate (agent,
stream,
component,
icheck->priority,
&icheck->from,
icheck->local_socket,
NULL, NULL);
if (candidate) {
priv_schedule_triggered_check (agent, stream, component, icheck->local_socket, candidate, icheck->use_candidate);
}
......@@ -1935,20 +1936,13 @@ gboolean conn_check_handle_inbound_stun (NiceAgent *agent, Stream *stream,
StunMessage msg;
StunValidationStatus valid;
conncheck_validater_data validater_data = {agent, stream, component, NULL};
GSList *i;
GSList *i, *j;
NiceCandidate *remote_candidate = NULL;
NiceCandidate *remote_candidate2 = NULL;
NiceCandidate *local_candidate = NULL;
nice_address_copy_to_sockaddr (from, &sockaddr);
for (i = component->remote_candidates; i; i = i->next) {
NiceCandidate *cand = i->data;
if (nice_address_equal (from, &cand->addr)) {
remote_candidate = cand;
break;
}
}
/* note: contents of 'buf' already validated, so it is
* a valid and fully received STUN message */
......@@ -1967,7 +1961,8 @@ gboolean conn_check_handle_inbound_stun (NiceAgent *agent, Stream *stream,
valid == STUN_VALIDATION_INCOMPLETE_STUN ||
valid == STUN_VALIDATION_BAD_REQUEST)
{
nice_debug ("Agent %p : Incorrectly multiplexed STUN message ignored.", agent);
nice_debug ("Agent %p : Incorrectly multiplexed STUN message ignored.",
agent);
return FALSE;
}
......@@ -2009,28 +2004,40 @@ gboolean conn_check_handle_inbound_stun (NiceAgent *agent, Stream *stream,
username = (uint8_t *) stun_message_find (&req, STUN_ATTRIBUTE_USERNAME,
&username_len);
/* We need to find which local candidate was used */
for (i = component->local_candidates; i; i = i->next) {
gboolean inbound = TRUE;
for (i = component->remote_candidates; i; i = i->next) {
NiceCandidate *cand = i->data;
if (nice_address_equal (from, &cand->addr)) {
remote_candidate = cand;
break;
}
}
/* We need to find which local candidate was used */
for (i = component->remote_candidates; i; i = i->next) {
for (j = component->local_candidates; j; j = j->next) {
gboolean inbound = TRUE;
NiceCandidate *rcand = i->data;
NiceCandidate *lcand = j->data;
/* If we receive a response, then the username is local:remote */
if (agent->compatibility != NICE_COMPATIBILITY_MSN) {
if (stun_message_get_class (&req) == STUN_REQUEST ||
stun_message_get_class (&req) == STUN_INDICATION) {
inbound = TRUE;
} else {
inbound = FALSE;
if (agent->compatibility != NICE_COMPATIBILITY_MSN) {
if (stun_message_get_class (&req) == STUN_REQUEST ||
stun_message_get_class (&req) == STUN_INDICATION) {
inbound = TRUE;
} else {
inbound = FALSE;
}
}
uname_len = priv_create_username (agent, stream,
component->id, rcand, lcand,
uname, sizeof (uname), inbound);
if (username &&
uname_len == username_len &&
memcmp (uname, username, username_len) == 0) {
local_candidate = lcand;
remote_candidate2 = rcand;
break;
}
}
uname_len = priv_create_username (agent, stream,
component->id, remote_candidate, cand,
uname, sizeof (uname), inbound);
if (username &&
uname_len == username_len &&
memcmp (uname, username, username_len) == 0) {
local_candidate = cand;
break;
}
}
......@@ -2056,14 +2063,17 @@ gboolean conn_check_handle_inbound_stun (NiceAgent *agent, Stream *stream,
if (stun_message_get_class (&req) == STUN_REQUEST) {
if (agent->compatibility == NICE_COMPATIBILITY_MSN) {
username = (uint8_t *) stun_message_find (&req, STUN_ATTRIBUTE_USERNAME,
&username_len);
username = (uint8_t *) stun_message_find (&req,
STUN_ATTRIBUTE_USERNAME, &username_len);
uname_len = priv_create_username (agent, stream,
component->id, remote_candidate, local_candidate,
component->id, remote_candidate2, local_candidate,
uname, sizeof (uname), FALSE);
memcpy (username, uname, username_len);
req.key = g_base64_decode ((gchar *) remote_candidate->password,
&req.key_len);
if (remote_candidate2)
req.key = g_base64_decode ((gchar *) remote_candidate2->password,
&req.key_len);
else
req.key = NULL;
}
rbuf_len = sizeof (rbuf);
......@@ -2097,7 +2107,8 @@ gboolean conn_check_handle_inbound_stun (NiceAgent *agent, Stream *stream,
nice_debug ("Agent %p : No matching remote candidate for incoming check ->"
"peer-reflexive candidate.", agent);
remote_candidate = discovery_learn_remote_peer_reflexive_candidate (
agent, stream, component, priority, from, udp_socket);
agent, stream, component, priority, from, udp_socket,
local_candidate, remote_candidate2);
}
priv_reply_to_conn_check (agent, stream, component, remote_candidate,
......
......@@ -465,8 +465,8 @@ discovery_add_peer_reflexive_candidate (
guint component_id,
NiceAddress *address,
NiceUDPSocket *base_socket,
NiceCandidate *local_candidate,
NiceCandidate *remote_candidate)
NiceCandidate *local,
NiceCandidate *remote)
{
NiceCandidate *candidate;
Component *component;
......@@ -497,7 +497,7 @@ discovery_add_peer_reflexive_candidate (
priv_assign_foundation (agent, candidate);
if (agent->compatibility == NICE_COMPATIBILITY_MSN &&
remote_candidate && local_candidate) {
remote && local) {
guchar *new_username = NULL;
guchar *decoded_local = NULL;
guchar *decoded_remote = NULL;
......@@ -506,8 +506,8 @@ discovery_add_peer_reflexive_candidate (
g_free(candidate->username);
g_free(candidate->password);
decoded_local = g_base64_decode (local_candidate->username, &local_size);
decoded_remote = g_base64_decode (remote_candidate->username, &remote_size);
decoded_local = g_base64_decode (local->username, &local_size);
decoded_remote = g_base64_decode (remote->username, &remote_size);
new_username = g_new0(guchar, local_size + remote_size);
memcpy(new_username, decoded_local, local_size);
......@@ -518,7 +518,7 @@ discovery_add_peer_reflexive_candidate (
g_free(decoded_local);
g_free(decoded_remote);
candidate->password = g_strdup(local_candidate->password);
candidate->password = g_strdup(local->password);
}
/* step: link to the base candidate+socket */
......@@ -565,7 +565,9 @@ NiceCandidate *discovery_learn_remote_peer_reflexive_candidate (
Component *component,
guint32 priority,
const NiceAddress *remote_address,
NiceUDPSocket *udp_socket)
NiceUDPSocket *udp_socket,
NiceCandidate *local,
NiceCandidate *remote)
{
NiceCandidate *candidate;
......@@ -578,7 +580,7 @@ NiceCandidate *discovery_learn_remote_peer_reflexive_candidate (
guint next_remote_id = priv_highest_remote_foundation (component);
candidate->transport = NICE_CANDIDATE_TRANSPORT_UDP;
candidate->transport = NICE_CANDIDATE_TRANSPORT_UDP;
candidate->addr = *remote_address;
candidate->base_addr = *remote_address;
candidate->priority = priority;;
......@@ -587,20 +589,20 @@ NiceCandidate *discovery_learn_remote_peer_reflexive_candidate (
g_snprintf (candidate->foundation, NICE_CANDIDATE_MAX_FOUNDATION, "%u", next_remote_id);
#if 0
if (agent->compatibility == NICE_COMPATIBILITY_MSN &&
remote && local) {
gchar *new_username = NULL;
gchar *decoded_local = NULL;
gchar *decoded_remote = NULL;
guchar *new_username = NULL;
guchar *decoded_local = NULL;
guchar *decoded_remote = NULL;
gsize local_size;
gsize remote_size;
g_free(candidate->username);
g_free (candidate->password);
decoded_local = g_base64_decode (local->username, &local_size);
decoded_remote = g_base64_decode (remote->username, &remote_size);
new_username = g_new0(gchar, local_size + remote_size);
new_username = g_new0(guchar, local_size + remote_size);
memcpy(new_username, decoded_remote, remote_size);
memcpy(new_username + remote_size, decoded_local, local_size);
......@@ -608,8 +610,10 @@ NiceCandidate *discovery_learn_remote_peer_reflexive_candidate (
g_free(new_username);
g_free(decoded_local);
g_free(decoded_remote);
candidate->password = g_strdup(remote->password);
}
#endif
candidate->sockptr = NULL; /* not stored for remote candidates */
/* note: candidate username and password are left NULL as stream
level ufrag/password are used */
......
......@@ -99,8 +99,8 @@ discovery_add_peer_reflexive_candidate (
guint component_id,
NiceAddress *address,
NiceUDPSocket *base_socket,
NiceCandidate *local_candidate,
NiceCandidate *remote_candidate);
NiceCandidate *local,
NiceCandidate *remote);
NiceCandidate *
discovery_learn_remote_peer_reflexive_candidate (
......@@ -109,6 +109,8 @@ discovery_learn_remote_peer_reflexive_candidate (
Component *component,
guint32 priority,
const NiceAddress *remote_address,
NiceUDPSocket *udp_socket);
NiceUDPSocket *udp_socket,
NiceCandidate *local,
NiceCandidate *remote);
#endif /*_NICE_CONNCHECK_H */
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