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

Add TCP server reflexive candidates

For TCP server reflexive candidates, since STUN can't work on TCP
candidates, we will use STUN on UDP or TCP and once we get an
externally mapped address, we will create a server reflexive candidate
for all local TCP candidates that share the same base address, and use
the same mapped port as the base addresse's port.
parent 77fbf5fc
......@@ -2423,6 +2423,13 @@ static gboolean priv_map_reply_to_discovery_request (NiceAgent *agent, StunMessa
NICE_CANDIDATE_TRANSPORT_UDP,
d->nicesock,
FALSE);
if (d->agent->use_ice_tcp)
discovery_discover_tcp_server_reflexive_candidates (
d->agent,
d->stream->id,
d->component->id,
&niceaddr,
d->nicesock);
d->stun_message.buffer = NULL;
d->stun_message.buffer_len = 0;
......@@ -2548,9 +2555,7 @@ static gboolean priv_map_reply_to_relay_request (NiceAgent *agent, StunMessage *
NiceAddress niceaddr;
NiceCandidate *relay_cand;
/* Server reflexive candidates are only valid for UDP sockets */
if (res == STUN_USAGE_TURN_RETURN_MAPPED_SUCCESS &&
!nice_socket_is_reliable (d->nicesock)) {
if (res == STUN_USAGE_TURN_RETURN_MAPPED_SUCCESS) {
/* We also received our mapped address */
nice_address_set_from_sockaddr (&niceaddr, &sockaddr.addr);
......@@ -2568,6 +2573,13 @@ static gboolean priv_map_reply_to_relay_request (NiceAgent *agent, StunMessage *
d->nicesock,
FALSE);
}
if (d->agent->use_ice_tcp)
discovery_discover_tcp_server_reflexive_candidates (
d->agent,
d->stream->id,
d->component->id,
&niceaddr,
d->nicesock);
}
nice_address_set_from_sockaddr (&niceaddr, &relayaddr.addr);
......
......@@ -591,6 +591,51 @@ discovery_add_server_reflexive_candidate (
return candidate;
}
/*
* Creates a server reflexive candidate for 'component_id' of stream
* 'stream_id' for each TCP_PASSIVE and TCP_ACTIVE candidates for each
* base address.
*
* @return pointer to the created candidate, or NULL on error
*/
void
discovery_discover_tcp_server_reflexive_candidates (
NiceAgent *agent,
guint stream_id,
guint component_id,
NiceAddress *address,
NiceSocket *base_socket)
{
Component *component;
Stream *stream;
NiceAddress base_addr = base_socket->addr;
GSList *i;
if (!agent_find_component (agent, stream_id, component_id, &stream, &component))
return;
nice_address_set_port (&base_addr, 0);
for (i = component->local_candidates; i; i = i ->next) {
NiceCandidate *c = i->data;
NiceAddress caddr;
caddr = c->addr;
nice_address_set_port (&caddr, 0);
if (c->transport != NICE_CANDIDATE_TRANSPORT_UDP &&
c->type == NICE_CANDIDATE_TYPE_HOST &&
nice_address_equal (&base_addr, &caddr)) {
nice_address_set_port (address, nice_address_get_port (&c->addr));
discovery_add_server_reflexive_candidate (
agent,
stream_id,
component_id,
address,
c->transport,
c->sockptr,
FALSE);
}
}
}
/*
* Creates a server reflexive candidate for 'component_id' of stream
......
......@@ -110,7 +110,7 @@ discovery_add_relay_candidate (
NiceSocket *base_socket,
TurnServer *turn);
NiceCandidate*
NiceCandidate*
discovery_add_server_reflexive_candidate (
NiceAgent *agent,
guint stream_id,
......@@ -120,7 +120,15 @@ discovery_add_server_reflexive_candidate (
NiceSocket *base_socket,
gboolean nat_assisted);
NiceCandidate*
void
discovery_discover_tcp_server_reflexive_candidates (
NiceAgent *agent,
guint stream_id,
guint component_id,
NiceAddress *address,
NiceSocket *base_socket);
NiceCandidate*
discovery_add_peer_reflexive_candidate (
NiceAgent *agent,
guint stream_id,
......
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