Commit f5dd8ac5 authored by Youness Alaoui's avatar Youness Alaoui Committed by Olivier Crête

Refactor discovery/agent to add support for non-udp candidates

parent a1091a90
...@@ -2024,7 +2024,7 @@ static void _upnp_mapped_external_port (GUPnPSimpleIgd *self, gchar *proto, ...@@ -2024,7 +2024,7 @@ static void _upnp_mapped_external_port (GUPnPSimpleIgd *self, gchar *proto,
NiceAgent *agent = (NiceAgent*)user_data; NiceAgent *agent = (NiceAgent*)user_data;
NiceAddress localaddr; NiceAddress localaddr;
NiceAddress externaddr; NiceAddress externaddr;
NiceCandidateTransport transport;
GSList *i, *j, *k; GSList *i, *j, *k;
agent_lock(); agent_lock();
...@@ -2036,6 +2036,11 @@ static void _upnp_mapped_external_port (GUPnPSimpleIgd *self, gchar *proto, ...@@ -2036,6 +2036,11 @@ static void _upnp_mapped_external_port (GUPnPSimpleIgd *self, gchar *proto,
goto end; goto end;
nice_address_set_port (&localaddr, local_port); nice_address_set_port (&localaddr, local_port);
if (g_strcmp0 (proto, "TCP") == 0)
transport = NICE_CANDIDATE_TRANSPORT_TCP_PASSIVE;
else
transport = NICE_CANDIDATE_TRANSPORT_UDP;
for (i = agent->upnp_mapping; i; i = i->next) { for (i = agent->upnp_mapping; i; i = i->next) {
NiceAddress *addr = i->data; NiceAddress *addr = i->data;
if (nice_address_equal (&localaddr, addr)) { if (nice_address_equal (&localaddr, addr)) {
...@@ -2062,6 +2067,7 @@ static void _upnp_mapped_external_port (GUPnPSimpleIgd *self, gchar *proto, ...@@ -2062,6 +2067,7 @@ static void _upnp_mapped_external_port (GUPnPSimpleIgd *self, gchar *proto,
stream->id, stream->id,
component->id, component->id,
&externaddr, &externaddr,
transport,
local_candidate->sockptr); local_candidate->sockptr);
goto end; goto end;
} }
...@@ -2214,7 +2220,7 @@ nice_agent_gather_candidates ( ...@@ -2214,7 +2220,7 @@ nice_agent_gather_candidates (
nice_debug ("Agent %p: Trying to create host candidate on port %d", agent, current_port); nice_debug ("Agent %p: Trying to create host candidate on port %d", agent, current_port);
nice_address_set_port (addr, current_port); nice_address_set_port (addr, current_port);
host_candidate = discovery_add_local_host_candidate (agent, stream->id, host_candidate = discovery_add_local_host_candidate (agent, stream->id,
cid, addr); cid, addr, NICE_CANDIDATE_TRANSPORT_UDP);
if (current_port > 0) if (current_port > 0)
current_port++; current_port++;
if (current_port > component->max_port) current_port = component->min_port; if (current_port > component->max_port) current_port = component->min_port;
...@@ -4712,9 +4718,11 @@ nice_agent_parse_remote_candidate_sdp (NiceAgent *agent, guint stream_id, ...@@ -4712,9 +4718,11 @@ nice_agent_parse_remote_candidate_sdp (NiceAgent *agent, guint stream_id,
const gchar *addr = NULL; const gchar *addr = NULL;
guint16 port = 0; guint16 port = 0;
const gchar *type = NULL; const gchar *type = NULL;
const gchar *tcptype = NULL;
const gchar *raddr = NULL; const gchar *raddr = NULL;
guint16 rport = 0; guint16 rport = 0;
static const gchar *type_names[] = {"host", "srflx", "prflx", "relay"}; static const gchar *type_names[] = {"host", "srflx", "prflx", "relay"};
NiceCandidateTransport ctransport;
guint i; guint i;
if (!g_str_has_prefix (sdp, "a=candidate:")) if (!g_str_has_prefix (sdp, "a=candidate:"))
...@@ -4751,6 +4759,8 @@ nice_agent_parse_remote_candidate_sdp (NiceAgent *agent, guint stream_id, ...@@ -4751,6 +4759,8 @@ nice_agent_parse_remote_candidate_sdp (NiceAgent *agent, guint stream_id,
raddr = tokens[i + 1]; raddr = tokens[i + 1];
} else if (g_strcmp0 (tokens[i], "rport") == 0) { } else if (g_strcmp0 (tokens[i], "rport") == 0) {
rport = (guint16) g_ascii_strtoull (tokens[i + 1], NULL, 10); rport = (guint16) g_ascii_strtoull (tokens[i + 1], NULL, 10);
} else if (g_strcmp0 (tokens[i], "tcptype") == 0) {
tcptype = tokens[i + 1];
} }
i++; i++;
break; break;
...@@ -4769,11 +4779,30 @@ nice_agent_parse_remote_candidate_sdp (NiceAgent *agent, guint stream_id, ...@@ -4769,11 +4779,30 @@ nice_agent_parse_remote_candidate_sdp (NiceAgent *agent, guint stream_id,
if (ntype == -1) if (ntype == -1)
goto done; goto done;
if (g_strcmp0 (transport, "UDP") == 0) { if (g_ascii_strcasecmp (transport, "UDP") == 0)
ctransport = NICE_CANDIDATE_TRANSPORT_UDP;
else if (g_ascii_strcasecmp (transport, "TCP-SO") == 0)
ctransport = NICE_CANDIDATE_TRANSPORT_TCP_SO;
else if (g_ascii_strcasecmp (transport, "TCP-ACT") == 0)
ctransport = NICE_CANDIDATE_TRANSPORT_TCP_ACTIVE;
else if (g_ascii_strcasecmp (transport, "TCP-PASS") == 0)
ctransport = NICE_CANDIDATE_TRANSPORT_TCP_PASSIVE;
else if (g_ascii_strcasecmp (transport, "TCP") == 0) {
if (g_ascii_strcasecmp (tcptype, "so") == 0)
ctransport = NICE_CANDIDATE_TRANSPORT_TCP_SO;
else if (g_ascii_strcasecmp (tcptype, "active") == 0)
ctransport = NICE_CANDIDATE_TRANSPORT_TCP_ACTIVE;
else if (g_ascii_strcasecmp (tcptype, "passive") == 0)
ctransport = NICE_CANDIDATE_TRANSPORT_TCP_PASSIVE;
else
goto done;
} else
goto done;
candidate = nice_candidate_new(ntype); candidate = nice_candidate_new(ntype);
candidate->component_id = component_id; candidate->component_id = component_id;
candidate->stream_id = stream_id; candidate->stream_id = stream_id;
candidate->transport = NICE_CANDIDATE_TRANSPORT_UDP; candidate->transport = ctransport;
g_strlcpy(candidate->foundation, foundation, NICE_CANDIDATE_MAX_FOUNDATION); g_strlcpy(candidate->foundation, foundation, NICE_CANDIDATE_MAX_FOUNDATION);
candidate->priority = priority; candidate->priority = priority;
...@@ -4792,7 +4821,6 @@ nice_agent_parse_remote_candidate_sdp (NiceAgent *agent, guint stream_id, ...@@ -4792,7 +4821,6 @@ nice_agent_parse_remote_candidate_sdp (NiceAgent *agent, guint stream_id,
} }
nice_address_set_port (&candidate->base_addr, rport); nice_address_set_port (&candidate->base_addr, rport);
} }
}
done: done:
if (tokens) if (tokens)
......
...@@ -2294,6 +2294,7 @@ static gboolean priv_map_reply_to_discovery_request (NiceAgent *agent, StunMessa ...@@ -2294,6 +2294,7 @@ static gboolean priv_map_reply_to_discovery_request (NiceAgent *agent, StunMessa
d->stream->id, d->stream->id,
d->component->id, d->component->id,
&niceaddr, &niceaddr,
NICE_CANDIDATE_TRANSPORT_UDP,
d->nicesock); d->nicesock);
d->stun_message.buffer = NULL; d->stun_message.buffer = NULL;
...@@ -2431,6 +2432,7 @@ static gboolean priv_map_reply_to_relay_request (NiceAgent *agent, StunMessage * ...@@ -2431,6 +2432,7 @@ static gboolean priv_map_reply_to_relay_request (NiceAgent *agent, StunMessage *
d->stream->id, d->stream->id,
d->component->id, d->component->id,
&niceaddr, &niceaddr,
NICE_CANDIDATE_TRANSPORT_UDP,
d->nicesock); d->nicesock);
} }
...@@ -2440,6 +2442,7 @@ static gboolean priv_map_reply_to_relay_request (NiceAgent *agent, StunMessage * ...@@ -2440,6 +2442,7 @@ static gboolean priv_map_reply_to_relay_request (NiceAgent *agent, StunMessage *
d->stream->id, d->stream->id,
d->component->id, d->component->id,
&niceaddr, &niceaddr,
NICE_CANDIDATE_TRANSPORT_UDP,
d->nicesock, d->nicesock,
d->turn); d->turn);
......
...@@ -269,7 +269,8 @@ static gboolean priv_add_local_candidate_pruned (NiceAgent *agent, guint stream_ ...@@ -269,7 +269,8 @@ static gboolean priv_add_local_candidate_pruned (NiceAgent *agent, guint stream_
NiceCandidate *c = i->data; NiceCandidate *c = i->data;
if (nice_address_equal (&c->base_addr, &candidate->base_addr) && if (nice_address_equal (&c->base_addr, &candidate->base_addr) &&
nice_address_equal (&c->addr, &candidate->addr)) { nice_address_equal (&c->addr, &candidate->addr) &&
c->transport == candidate->transport) {
nice_debug ("Candidate %p (component-id %u) redundant, ignoring.", candidate, component->id); nice_debug ("Candidate %p (component-id %u) redundant, ignoring.", candidate, component->id);
return FALSE; return FALSE;
} }
...@@ -462,17 +463,19 @@ NiceCandidate *discovery_add_local_host_candidate ( ...@@ -462,17 +463,19 @@ NiceCandidate *discovery_add_local_host_candidate (
NiceAgent *agent, NiceAgent *agent,
guint stream_id, guint stream_id,
guint component_id, guint component_id,
NiceAddress *address) NiceAddress *address,
NiceCandidateTransport transport)
{ {
NiceCandidate *candidate; NiceCandidate *candidate;
Component *component; Component *component;
Stream *stream; Stream *stream;
NiceSocket *udp_socket = NULL; NiceSocket *nicesock = NULL;
if (!agent_find_component (agent, stream_id, component_id, &stream, &component)) if (!agent_find_component (agent, stream_id, component_id, &stream, &component))
return NULL; return NULL;
candidate = nice_candidate_new (NICE_CANDIDATE_TYPE_HOST); candidate = nice_candidate_new (NICE_CANDIDATE_TYPE_HOST);
candidate->transport = transport;
candidate->stream_id = stream_id; candidate->stream_id = stream_id;
candidate->component_id = component_id; candidate->component_id = component_id;
candidate->addr = *address; candidate->addr = *address;
...@@ -491,26 +494,30 @@ NiceCandidate *discovery_add_local_host_candidate ( ...@@ -491,26 +494,30 @@ NiceCandidate *discovery_add_local_host_candidate (
/* note: candidate username and password are left NULL as stream /* note: candidate username and password are left NULL as stream
level ufrag/password are used */ level ufrag/password are used */
udp_socket = nice_udp_bsd_socket_new (address); if (transport == NICE_CANDIDATE_TRANSPORT_UDP) {
if (!udp_socket) nicesock = nice_udp_bsd_socket_new (address);
} else {
/* TODO: Add ICE-TCP */
}
if (!nicesock)
goto errors; goto errors;
candidate->sockptr = udp_socket; candidate->sockptr = nicesock;
candidate->addr = udp_socket->addr; candidate->addr = nicesock->addr;
candidate->base_addr = udp_socket->addr; candidate->base_addr = nicesock->addr;
if (!priv_add_local_candidate_pruned (agent, stream_id, component, candidate)) if (!priv_add_local_candidate_pruned (agent, stream_id, component, candidate))
goto errors; goto errors;
_priv_set_socket_tos (agent, udp_socket, stream->tos); _priv_set_socket_tos (agent, nicesock, stream->tos);
component_attach_socket (component, udp_socket); component_attach_socket (component, nicesock);
return candidate; return candidate;
errors: errors:
nice_candidate_free (candidate); nice_candidate_free (candidate);
if (udp_socket) if (nicesock)
nice_socket_free (udp_socket); nice_socket_free (nicesock);
return NULL; return NULL;
} }
...@@ -526,6 +533,7 @@ discovery_add_server_reflexive_candidate ( ...@@ -526,6 +533,7 @@ discovery_add_server_reflexive_candidate (
guint stream_id, guint stream_id,
guint component_id, guint component_id,
NiceAddress *address, NiceAddress *address,
NiceCandidateTransport transport,
NiceSocket *base_socket) NiceSocket *base_socket)
{ {
NiceCandidate *candidate; NiceCandidate *candidate;
...@@ -547,6 +555,8 @@ discovery_add_server_reflexive_candidate ( ...@@ -547,6 +555,8 @@ discovery_add_server_reflexive_candidate (
candidate->priority = nice_candidate_ice_priority_full candidate->priority = nice_candidate_ice_priority_full
(NICE_CANDIDATE_TYPE_PREF_SERVER_REFLEXIVE, 0, component_id); (NICE_CANDIDATE_TYPE_PREF_SERVER_REFLEXIVE, 0, component_id);
} }
candidate->transport = transport;
candidate->stream_id = stream_id; candidate->stream_id = stream_id;
candidate->component_id = component_id; candidate->component_id = component_id;
candidate->addr = *address; candidate->addr = *address;
...@@ -583,6 +593,7 @@ discovery_add_relay_candidate ( ...@@ -583,6 +593,7 @@ discovery_add_relay_candidate (
guint stream_id, guint stream_id,
guint component_id, guint component_id,
NiceAddress *address, NiceAddress *address,
NiceCandidateTransport transport,
NiceSocket *base_socket, NiceSocket *base_socket,
TurnServer *turn) TurnServer *turn)
{ {
...@@ -605,6 +616,7 @@ discovery_add_relay_candidate ( ...@@ -605,6 +616,7 @@ discovery_add_relay_candidate (
candidate->priority = nice_candidate_ice_priority_full candidate->priority = nice_candidate_ice_priority_full
(NICE_CANDIDATE_TYPE_PREF_RELAYED, 0, component_id); (NICE_CANDIDATE_TYPE_PREF_RELAYED, 0, component_id);
} }
candidate->transport = transport;
candidate->stream_id = stream_id; candidate->stream_id = stream_id;
candidate->component_id = component_id; candidate->component_id = component_id;
candidate->addr = *address; candidate->addr = *address;
...@@ -672,7 +684,6 @@ discovery_add_peer_reflexive_candidate ( ...@@ -672,7 +684,6 @@ discovery_add_peer_reflexive_candidate (
candidate = nice_candidate_new (NICE_CANDIDATE_TYPE_PEER_REFLEXIVE); candidate = nice_candidate_new (NICE_CANDIDATE_TYPE_PEER_REFLEXIVE);
candidate->transport = NICE_CANDIDATE_TRANSPORT_UDP;
if (agent->compatibility == NICE_COMPATIBILITY_GOOGLE) { if (agent->compatibility == NICE_COMPATIBILITY_GOOGLE) {
candidate->priority = nice_candidate_jingle_priority (candidate); candidate->priority = nice_candidate_jingle_priority (candidate);
} else if (agent->compatibility == NICE_COMPATIBILITY_MSN || } else if (agent->compatibility == NICE_COMPATIBILITY_MSN ||
...@@ -682,6 +693,7 @@ discovery_add_peer_reflexive_candidate ( ...@@ -682,6 +693,7 @@ discovery_add_peer_reflexive_candidate (
candidate->priority = nice_candidate_ice_priority_full candidate->priority = nice_candidate_ice_priority_full
(NICE_CANDIDATE_TYPE_PREF_PEER_REFLEXIVE, 0, component_id); (NICE_CANDIDATE_TYPE_PREF_PEER_REFLEXIVE, 0, component_id);
} }
candidate->transport = local->transport;
candidate->stream_id = stream_id; candidate->stream_id = stream_id;
candidate->component_id = component_id; candidate->component_id = component_id;
candidate->addr = *address; candidate->addr = *address;
...@@ -762,7 +774,6 @@ NiceCandidate *discovery_learn_remote_peer_reflexive_candidate ( ...@@ -762,7 +774,6 @@ NiceCandidate *discovery_learn_remote_peer_reflexive_candidate (
candidate = nice_candidate_new (NICE_CANDIDATE_TYPE_PEER_REFLEXIVE); candidate = nice_candidate_new (NICE_CANDIDATE_TYPE_PEER_REFLEXIVE);
candidate->transport = NICE_CANDIDATE_TRANSPORT_UDP;
candidate->addr = *remote_address; candidate->addr = *remote_address;
candidate->base_addr = *remote_address; candidate->base_addr = *remote_address;
...@@ -779,6 +790,7 @@ NiceCandidate *discovery_learn_remote_peer_reflexive_candidate ( ...@@ -779,6 +790,7 @@ NiceCandidate *discovery_learn_remote_peer_reflexive_candidate (
candidate->priority = nice_candidate_ice_priority_full candidate->priority = nice_candidate_ice_priority_full
(NICE_CANDIDATE_TYPE_PREF_PEER_REFLEXIVE, 0, component->id); (NICE_CANDIDATE_TYPE_PREF_PEER_REFLEXIVE, 0, component->id);
} }
candidate->transport = remote->transport;
candidate->stream_id = stream->id; candidate->stream_id = stream->id;
candidate->component_id = component->id; candidate->component_id = component->id;
......
...@@ -97,7 +97,8 @@ discovery_add_local_host_candidate ( ...@@ -97,7 +97,8 @@ discovery_add_local_host_candidate (
NiceAgent *agent, NiceAgent *agent,
guint stream_id, guint stream_id,
guint component_id, guint component_id,
NiceAddress *address); NiceAddress *address,
NiceCandidateTransport transport);
NiceCandidate* NiceCandidate*
discovery_add_relay_candidate ( discovery_add_relay_candidate (
...@@ -105,6 +106,7 @@ discovery_add_relay_candidate ( ...@@ -105,6 +106,7 @@ discovery_add_relay_candidate (
guint stream_id, guint stream_id,
guint component_id, guint component_id,
NiceAddress *address, NiceAddress *address,
NiceCandidateTransport transport,
NiceSocket *base_socket, NiceSocket *base_socket,
TurnServer *turn); TurnServer *turn);
...@@ -114,6 +116,7 @@ discovery_add_server_reflexive_candidate ( ...@@ -114,6 +116,7 @@ discovery_add_server_reflexive_candidate (
guint stream_id, guint stream_id,
guint component_id, guint component_id,
NiceAddress *address, NiceAddress *address,
NiceCandidateTransport transport,
NiceSocket *base_socket); NiceSocket *base_socket);
NiceCandidate* NiceCandidate*
......
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