Commit 4ee70c86 authored by Youness Alaoui's avatar Youness Alaoui

Merge remote branch 'tester/misc-fixes' into nice-kakaroto

Conflicts:
	agent/agent.c
parents 358a999f 3b16d8b0
...@@ -1294,171 +1294,134 @@ agent_candidate_pair_priority (NiceAgent *agent, NiceCandidate *local, NiceCandi ...@@ -1294,171 +1294,134 @@ agent_candidate_pair_priority (NiceAgent *agent, NiceCandidate *local, NiceCandi
return nice_candidate_pair_priority (remote->priority, local->priority); return nice_candidate_pair_priority (remote->priority, local->priority);
} }
static gboolean static void
priv_add_new_candidate_discovery_stun (NiceAgent *agent, priv_add_new_candidate_discovery_stun (NiceAgent *agent,
NiceSocket *socket, NiceAddress server, NiceSocket *socket, NiceAddress server,
Stream *stream, guint component_id) Stream *stream, guint component_id)
{ {
CandidateDiscovery *cdisco; CandidateDiscovery *cdisco;
GSList *modified_list;
/* note: no need to check for redundant candidates, as this is /* note: no need to check for redundant candidates, as this is
* done later on in the process */ * done later on in the process */
cdisco = g_slice_new0 (CandidateDiscovery); cdisco = g_slice_new0 (CandidateDiscovery);
if (cdisco) {
modified_list = g_slist_append (agent->discovery_list, cdisco);
if (modified_list) {
cdisco->type = NICE_CANDIDATE_TYPE_SERVER_REFLEXIVE;
cdisco->nicesock = socket;
cdisco->server = server;
cdisco->stream = stream;
cdisco->component = stream_find_component_by_id (stream, component_id);
cdisco->agent = agent;
stun_agent_init (&cdisco->stun_agent, STUN_ALL_KNOWN_ATTRIBUTES,
STUN_COMPATIBILITY_RFC3489, 0);
nice_debug ("Agent %p : Adding new srv-rflx candidate discovery %p\n",
agent, cdisco);
agent->discovery_list = modified_list;
++agent->discovery_unsched_items;
}
return TRUE; cdisco->type = NICE_CANDIDATE_TYPE_SERVER_REFLEXIVE;
} cdisco->nicesock = socket;
cdisco->server = server;
cdisco->stream = stream;
cdisco->component = stream_find_component_by_id (stream, component_id);
cdisco->agent = agent;
stun_agent_init (&cdisco->stun_agent, STUN_ALL_KNOWN_ATTRIBUTES,
STUN_COMPATIBILITY_RFC3489, 0);
return FALSE; nice_debug ("Agent %p : Adding new srv-rflx candidate discovery %p\n",
agent, cdisco);
agent->discovery_list = g_slist_append (agent->discovery_list, cdisco);
++agent->discovery_unsched_items;
} }
static gboolean static void
priv_add_new_candidate_discovery_turn (NiceAgent *agent, priv_add_new_candidate_discovery_turn (NiceAgent *agent,
NiceSocket *socket, TurnServer *turn, NiceSocket *socket, TurnServer *turn,
Stream *stream, guint component_id) Stream *stream, guint component_id)
{ {
CandidateDiscovery *cdisco; CandidateDiscovery *cdisco;
GSList *modified_list; Component *component = stream_find_component_by_id (stream, component_id);
GSList *socket_modified_list;
/* note: no need to check for redundant candidates, as this is /* note: no need to check for redundant candidates, as this is
* done later on in the process */ * done later on in the process */
cdisco = g_slice_new0 (CandidateDiscovery); cdisco = g_slice_new0 (CandidateDiscovery);
if (cdisco) { cdisco->type = NICE_CANDIDATE_TYPE_RELAYED;
modified_list = g_slist_append (agent->discovery_list, cdisco);
if (modified_list) {
Component *component = stream_find_component_by_id (stream, component_id);
cdisco->type = NICE_CANDIDATE_TYPE_RELAYED;
if (turn->type == NICE_RELAY_TYPE_TURN_UDP) {
if (agent->compatibility == NICE_COMPATIBILITY_GOOGLE) {
NiceAddress addr = socket->addr;
NiceSocket *new_socket;
nice_address_set_port (&addr, 0);
new_socket = nice_udp_bsd_socket_new (&addr);
if (new_socket) {
_priv_set_socket_tos (agent, new_socket, stream->tos);
agent_attach_stream_component_socket (agent, stream,
component, new_socket);
socket_modified_list = g_slist_append (component->sockets, new_socket);
if (socket_modified_list) {
/* success: store a pointer to the sockaddr */
component->sockets = socket_modified_list;
socket = new_socket;
} else {
nice_socket_free (new_socket);
}
}
}
cdisco->nicesock = socket;
} else {
NiceAddress proxy_server;
socket = NULL;
if (agent->proxy_type != NICE_PROXY_TYPE_NONE &&
agent->proxy_ip != NULL &&
nice_address_set_from_string (&proxy_server, agent->proxy_ip)) {
nice_address_set_port (&proxy_server, agent->proxy_port);
socket = nice_tcp_bsd_socket_new (agent, component->ctx, &proxy_server);
if (socket) {
_priv_set_socket_tos (agent, socket, stream->tos);
if (agent->proxy_type == NICE_PROXY_TYPE_SOCKS5) {
socket = nice_socks5_socket_new (socket, &turn->server,
agent->proxy_username, agent->proxy_password);
} else if (agent->proxy_type == NICE_PROXY_TYPE_HTTP){
socket = nice_http_socket_new (socket, &turn->server,
agent->proxy_username, agent->proxy_password);
} else {
nice_socket_free (socket);
socket = NULL;
}
}
}
if (socket == NULL) {
socket = nice_tcp_bsd_socket_new (agent, component->ctx, &turn->server);
_priv_set_socket_tos (agent, socket, stream->tos);
}
if (turn->type == NICE_RELAY_TYPE_TURN_TLS &&
agent->compatibility == NICE_COMPATIBILITY_GOOGLE) {
socket = nice_pseudossl_socket_new (agent, socket);
}
cdisco->nicesock = nice_tcp_turn_socket_new (agent, socket,
agent_to_turn_socket_compatibility (agent));
if (!cdisco->nicesock) { if (turn->type == NICE_RELAY_TYPE_TURN_UDP) {
agent->discovery_list = g_slist_remove (modified_list, cdisco); if (agent->compatibility == NICE_COMPATIBILITY_GOOGLE) {
g_slice_free (CandidateDiscovery, cdisco); NiceAddress addr = socket->addr;
return FALSE; NiceSocket *new_socket;
} nice_address_set_port (&addr, 0);
new_socket = nice_udp_bsd_socket_new (&addr);
if (new_socket) {
_priv_set_socket_tos (agent, new_socket, stream->tos);
agent_attach_stream_component_socket (agent, stream, agent_attach_stream_component_socket (agent, stream,
component, cdisco->nicesock); component, new_socket);
socket_modified_list = g_slist_append (component->sockets, cdisco->nicesock); component->sockets= g_slist_append (component->sockets, new_socket);
if (socket_modified_list) { socket = new_socket;
/* success: store a pointer to the sockaddr */
component->sockets = socket_modified_list;
}
} }
cdisco->turn = turn; }
cdisco->server = turn->server; cdisco->nicesock = socket;
} else {
cdisco->stream = stream; NiceAddress proxy_server;
cdisco->component = stream_find_component_by_id (stream, component_id); socket = NULL;
cdisco->agent = agent;
if (agent->proxy_type != NICE_PROXY_TYPE_NONE &&
if (agent->compatibility == NICE_COMPATIBILITY_GOOGLE) { agent->proxy_ip != NULL &&
stun_agent_init (&cdisco->stun_agent, STUN_ALL_KNOWN_ATTRIBUTES, nice_address_set_from_string (&proxy_server, agent->proxy_ip)) {
STUN_COMPATIBILITY_RFC3489, nice_address_set_port (&proxy_server, agent->proxy_port);
STUN_AGENT_USAGE_SHORT_TERM_CREDENTIALS | socket = nice_tcp_bsd_socket_new (agent, component->ctx, &proxy_server);
STUN_AGENT_USAGE_IGNORE_CREDENTIALS);
} else if (agent->compatibility == NICE_COMPATIBILITY_MSN || if (socket) {
agent->compatibility == NICE_COMPATIBILITY_WLM2009) { _priv_set_socket_tos (agent, socket, stream->tos);
stun_agent_init (&cdisco->stun_agent, STUN_ALL_KNOWN_ATTRIBUTES, if (agent->proxy_type == NICE_PROXY_TYPE_SOCKS5) {
STUN_COMPATIBILITY_RFC3489, socket = nice_socks5_socket_new (socket, &turn->server,
STUN_AGENT_USAGE_SHORT_TERM_CREDENTIALS); agent->proxy_username, agent->proxy_password);
} else { } else if (agent->proxy_type == NICE_PROXY_TYPE_HTTP){
stun_agent_init (&cdisco->stun_agent, STUN_ALL_KNOWN_ATTRIBUTES, socket = nice_http_socket_new (socket, &turn->server,
STUN_COMPATIBILITY_RFC5389, agent->proxy_username, agent->proxy_password);
STUN_AGENT_USAGE_ADD_SOFTWARE | } else {
STUN_AGENT_USAGE_LONG_TERM_CREDENTIALS); nice_socket_free (socket);
socket = NULL;
}
} }
stun_agent_set_software (&cdisco->stun_agent, agent->software_attribute);
nice_debug ("Agent %p : Adding new relay-rflx candidate discovery %p\n",
agent, cdisco);
agent->discovery_list = modified_list;
++agent->discovery_unsched_items;
} }
if (socket == NULL) {
return TRUE; socket = nice_tcp_bsd_socket_new (agent, component->ctx, &turn->server);
_priv_set_socket_tos (agent, socket, stream->tos);
}
if (turn->type == NICE_RELAY_TYPE_TURN_TLS &&
agent->compatibility == NICE_COMPATIBILITY_GOOGLE) {
socket = nice_pseudossl_socket_new (agent, socket);
}
cdisco->nicesock = nice_tcp_turn_socket_new (agent, socket,
agent_to_turn_socket_compatibility (agent));
agent_attach_stream_component_socket (agent, stream,
component, cdisco->nicesock);
component->sockets = g_slist_append (component->sockets, cdisco->nicesock);
}
cdisco->turn = turn;
cdisco->server = turn->server;
cdisco->stream = stream;
cdisco->component = stream_find_component_by_id (stream, component_id);
cdisco->agent = agent;
if (agent->compatibility == NICE_COMPATIBILITY_GOOGLE) {
stun_agent_init (&cdisco->stun_agent, STUN_ALL_KNOWN_ATTRIBUTES,
STUN_COMPATIBILITY_RFC3489,
STUN_AGENT_USAGE_SHORT_TERM_CREDENTIALS |
STUN_AGENT_USAGE_IGNORE_CREDENTIALS);
} else if (agent->compatibility == NICE_COMPATIBILITY_MSN ||
agent->compatibility == NICE_COMPATIBILITY_WLM2009) {
stun_agent_init (&cdisco->stun_agent, STUN_ALL_KNOWN_ATTRIBUTES,
STUN_COMPATIBILITY_RFC3489,
STUN_AGENT_USAGE_SHORT_TERM_CREDENTIALS);
} else {
stun_agent_init (&cdisco->stun_agent, STUN_ALL_KNOWN_ATTRIBUTES,
STUN_COMPATIBILITY_RFC5389,
STUN_AGENT_USAGE_ADD_SOFTWARE |
STUN_AGENT_USAGE_LONG_TERM_CREDENTIALS);
} }
stun_agent_set_software (&cdisco->stun_agent, agent->software_attribute);
return FALSE; nice_debug ("Agent %p : Adding new relay-rflx candidate discovery %p\n",
agent, cdisco);
agent->discovery_list = g_slist_append (agent->discovery_list, cdisco);
++agent->discovery_unsched_items;
} }
NICEAPI_EXPORT guint NICEAPI_EXPORT guint
...@@ -1467,51 +1430,43 @@ nice_agent_add_stream ( ...@@ -1467,51 +1430,43 @@ nice_agent_add_stream (
guint n_components) guint n_components)
{ {
Stream *stream; Stream *stream;
GSList *modified_list = NULL;
guint ret = 0; guint ret = 0;
guint i; guint i;
agent_lock(); agent_lock();
stream = stream_new (n_components); stream = stream_new (n_components);
if (stream) {
modified_list = g_slist_append (agent->streams, stream);
if (modified_list) {
stream->id = agent->next_stream_id++;
nice_debug ("Agent %p : allocating stream id %u (%p)", agent, stream->id, stream);
if (agent->reliable) {
nice_debug ("Agent %p : reliable stream", agent);
for (i = 0; i < n_components; i++) {
Component *component = stream_find_component_by_id (stream, i + 1);
if (component) {
TcpUserData *data = g_slice_new0 (TcpUserData);
PseudoTcpCallbacks tcp_callbacks = {data,
pseudo_tcp_socket_opened,
pseudo_tcp_socket_readable,
pseudo_tcp_socket_writable,
pseudo_tcp_socket_closed,
pseudo_tcp_socket_write_packet};
data->agent = agent;
data->stream = stream;
data->component = component;
component->tcp_data = data;
component->tcp = pseudo_tcp_socket_new (0, &tcp_callbacks);
adjust_tcp_clock (agent, stream, component);
nice_debug ("Agent %p: Create Pseudo Tcp Socket for component %d",
agent, i+1);
} else {
nice_debug ("Agent %p: couldn't find component %d", agent, i+1);
}
}
}
stream_initialize_credentials (stream, agent->rng); agent->streams = g_slist_append (agent->streams, stream);
stream->id = agent->next_stream_id++;
agent->streams = modified_list; nice_debug ("Agent %p : allocating stream id %u (%p)", agent, stream->id, stream);
if (agent->reliable) {
nice_debug ("Agent %p : reliable stream", agent);
for (i = 0; i < n_components; i++) {
Component *component = stream_find_component_by_id (stream, i + 1);
if (component) {
TcpUserData *data = g_slice_new0 (TcpUserData);
PseudoTcpCallbacks tcp_callbacks = {data,
pseudo_tcp_socket_opened,
pseudo_tcp_socket_readable,
pseudo_tcp_socket_writable,
pseudo_tcp_socket_closed,
pseudo_tcp_socket_write_packet};
data->agent = agent;
data->stream = stream;
data->component = component;
component->tcp_data = data;
component->tcp = pseudo_tcp_socket_new (0, &tcp_callbacks);
adjust_tcp_clock (agent, stream, component);
nice_debug ("Agent %p: Create Pseudo Tcp Socket for component %d",
agent, i+1);
} else {
nice_debug ("Agent %p: couldn't find component %d", agent, i+1);
}
} }
else
stream_free (stream);
} }
stream_initialize_credentials (stream, agent->rng);
ret = stream->id; ret = stream->id;
agent_unlock(); agent_unlock();
...@@ -1703,7 +1658,7 @@ static void _upnp_error_mapping_port (GUPnPSimpleIgd *self, GError *error, ...@@ -1703,7 +1658,7 @@ static void _upnp_error_mapping_port (GUPnPSimpleIgd *self, GError *error,
#endif #endif
NICEAPI_EXPORT void NICEAPI_EXPORT gboolean
nice_agent_gather_candidates ( nice_agent_gather_candidates (
NiceAgent *agent, NiceAgent *agent,
guint stream_id) guint stream_id)
...@@ -1788,8 +1743,8 @@ nice_agent_gather_candidates ( ...@@ -1788,8 +1743,8 @@ nice_agent_gather_candidates (
n + 1, addr); n + 1, addr);
if (!host_candidate) { if (!host_candidate) {
g_error ("No host candidate??"); g_warning ("No host candidate??");
break; return FALSE;
} }
#ifdef HAVE_GUPNP #ifdef HAVE_GUPNP
...@@ -1808,20 +1763,13 @@ nice_agent_gather_candidates ( ...@@ -1808,20 +1763,13 @@ nice_agent_gather_candidates (
agent->stun_server_ip) { agent->stun_server_ip) {
NiceAddress stun_server; NiceAddress stun_server;
if (nice_address_set_from_string (&stun_server, agent->stun_server_ip)) { if (nice_address_set_from_string (&stun_server, agent->stun_server_ip)) {
gboolean res;
nice_address_set_port (&stun_server, agent->stun_server_port); nice_address_set_port (&stun_server, agent->stun_server_port);
res = priv_add_new_candidate_discovery_stun (agent,
priv_add_new_candidate_discovery_stun (agent, host_candidate->sockptr,
host_candidate->sockptr, stun_server,
stun_server, stream,
stream, n + 1);
n + 1);
if (res != TRUE) {
/* note: memory allocation failure, return error */
g_error ("Memory allocation failure?");
}
} }
} }
...@@ -1831,17 +1779,11 @@ nice_agent_gather_candidates ( ...@@ -1831,17 +1779,11 @@ nice_agent_gather_candidates (
for (item = component->turn_servers; item; item = item->next) { for (item = component->turn_servers; item; item = item->next) {
TurnServer *turn = item->data; TurnServer *turn = item->data;
gboolean res = priv_add_new_candidate_discovery_turn (agent,
priv_add_new_candidate_discovery_turn (agent, host_candidate->sockptr,
host_candidate->sockptr, turn,
turn, stream,
stream, n + 1);
n + 1);
if (res != TRUE) {
/* note: memory allocation failure, return error */
g_error ("Memory allocation failure?");
}
} }
} }
} }
...@@ -1863,6 +1805,8 @@ nice_agent_gather_candidates ( ...@@ -1863,6 +1805,8 @@ nice_agent_gather_candidates (
done: done:
agent_unlock(); agent_unlock();
return TRUE;
} }
static void priv_free_upnp (NiceAgent *agent) static void priv_free_upnp (NiceAgent *agent)
...@@ -1935,24 +1879,15 @@ NICEAPI_EXPORT gboolean ...@@ -1935,24 +1879,15 @@ NICEAPI_EXPORT gboolean
nice_agent_add_local_address (NiceAgent *agent, NiceAddress *addr) nice_agent_add_local_address (NiceAgent *agent, NiceAddress *addr)
{ {
NiceAddress *dup; NiceAddress *dup;
GSList *modified_list;
gboolean ret = FALSE;
agent_lock(); agent_lock();
dup = nice_address_dup (addr); dup = nice_address_dup (addr);
nice_address_set_port (dup, 0); nice_address_set_port (dup, 0);
modified_list = g_slist_append (agent->local_addresses, dup); agent->local_addresses = g_slist_append (agent->local_addresses, dup);
if (modified_list) {
agent->local_addresses = modified_list;
ret = TRUE;
goto done;
}
done:
agent_unlock(); agent_unlock();
return ret; return TRUE;
} }
static gboolean priv_add_remote_candidate ( static gboolean priv_add_remote_candidate (
...@@ -1970,7 +1905,6 @@ static gboolean priv_add_remote_candidate ( ...@@ -1970,7 +1905,6 @@ static gboolean priv_add_remote_candidate (
{ {
Component *component; Component *component;
NiceCandidate *candidate; NiceCandidate *candidate;
gboolean error_flag = FALSE;
if (!agent_find_component (agent, stream_id, component_id, NULL, &component)) if (!agent_find_component (agent, stream_id, component_id, NULL, &component))
return FALSE; return FALSE;
...@@ -2013,62 +1947,53 @@ static gboolean priv_add_remote_candidate ( ...@@ -2013,62 +1947,53 @@ static gboolean priv_add_remote_candidate (
candidate->password = g_strdup (password); candidate->password = g_strdup (password);
} }
if (conn_check_add_for_candidate (agent, stream_id, component, candidate) < 0) if (conn_check_add_for_candidate (agent, stream_id, component, candidate) < 0)
error_flag = TRUE; goto errors;
} }
else { else {
/* case 2: add a new candidate */ /* case 2: add a new candidate */
candidate = nice_candidate_new (type); candidate = nice_candidate_new (type);
if (candidate) { component->remote_candidates = g_slist_append (component->remote_candidates,
GSList *modified_list = g_slist_append (component->remote_candidates, candidate); candidate);
if (modified_list) {
component->remote_candidates = modified_list;
candidate->stream_id = stream_id; candidate->stream_id = stream_id;
candidate->component_id = component_id; candidate->component_id = component_id;
candidate->type = type; candidate->type = type;
if (addr) if (addr)
candidate->addr = *addr; candidate->addr = *addr;
{
gchar tmpbuf[INET6_ADDRSTRLEN] = {0};
if(addr)
nice_address_to_string (addr, tmpbuf);
nice_debug ("Agent %p : Adding remote candidate with addr [%s]:%u"
" for s%d/c%d. U/P '%s'/'%s' prio: %u", agent, tmpbuf,
addr? nice_address_get_port (addr) : 0, stream_id, component_id,
username, password, priority);
}
if (base_addr) {
candidate->base_addr = *base_addr; gchar tmpbuf[INET6_ADDRSTRLEN] = {0};
if(addr)
nice_address_to_string (addr, tmpbuf);
nice_debug ("Agent %p : Adding remote candidate with addr [%s]:%u"
" for s%d/c%d. U/P '%s'/'%s' prio: %u", agent, tmpbuf,
addr? nice_address_get_port (addr) : 0, stream_id, component_id,
username, password, priority);
}
candidate->transport = transport; if (base_addr)
candidate->priority = priority; candidate->base_addr = *base_addr;
candidate->username = g_strdup (username);
candidate->password = g_strdup (password);
if (foundation) candidate->transport = transport;
g_strlcpy (candidate->foundation, foundation, candidate->priority = priority;
NICE_CANDIDATE_MAX_FOUNDATION); candidate->username = g_strdup (username);
candidate->password = g_strdup (password);
if (conn_check_add_for_candidate (agent, stream_id, component, candidate) < 0) if (foundation)
error_flag = TRUE; g_strlcpy (candidate->foundation, foundation,
} NICE_CANDIDATE_MAX_FOUNDATION);
else /* memory alloc error: list insert */
error_flag = TRUE;
}
else /* memory alloc error: candidate creation */
error_flag = TRUE;
}
if (error_flag) { if (conn_check_add_for_candidate (agent, stream_id, component, candidate) < 0)
if (candidate) goto errors;
nice_candidate_free (candidate);
return FALSE;
} }
return TRUE; return TRUE;
errors:
nice_candidate_free (candidate);
return FALSE;
} }
NICEAPI_EXPORT gboolean NICEAPI_EXPORT gboolean
...@@ -2490,14 +2415,13 @@ io_ctx_new ( ...@@ -2490,14 +2415,13 @@ io_ctx_new (
IOCtx *ctx; IOCtx *ctx;
ctx = g_slice_new0 (IOCtx); ctx = g_slice_new0 (IOCtx);
if (ctx) { ctx->agent = agent;
ctx->agent = agent; ctx->stream = stream;
ctx->stream = stream; ctx->component = component;
ctx->component = component; ctx->socket = socket;
ctx->socket = socket; ctx->channel = channel;
ctx->channel = channel; ctx->source = source;
ctx->source = source;
}
return ctx; return ctx;
} }
......
...@@ -385,6 +385,8 @@ gboolean nice_agent_set_relay_info( ...@@ -385,6 +385,8 @@ gboolean nice_agent_set_relay_info(
* Start the candidate gathering process. * Start the candidate gathering process.
* Once done, #NiceAgent::candidate-gathering-done is called for the stream * Once done, #NiceAgent::candidate-gathering-done is called for the stream
* *
* Returns: %FALSE if there were no local addresses and they couldn't be discovered. In this case, call nice_agent_add_local_address() first.
*
* See also: nice_agent_add_local_address() * See also: nice_agent_add_local_address()
<note> <note>
<para> <para>
...@@ -397,7 +399,7 @@ gboolean nice_agent_set_relay_info( ...@@ -397,7 +399,7 @@ gboolean nice_agent_set_relay_info(
</para> </para>
</note> </note>
*/ */
void gboolean
nice_agent_gather_candidates ( nice_agent_gather_candidates (
NiceAgent *agent, NiceAgent *agent,
guint stream_id); guint stream_id);
......
...@@ -310,20 +310,10 @@ component_set_selected_remote_candidate (NiceAgent *agent, Component *component, ...@@ -310,20 +310,10 @@ component_set_selected_remote_candidate (NiceAgent *agent, Component *component,
candidate->transport); candidate->transport);
if (!remote) { if (!remote) {
GSList *modified_list = NULL;
remote = nice_candidate_copy (candidate); remote = nice_candidate_copy (candidate);
component->remote_candidates = g_slist_append (component->remote_candidates,
modified_list = g_slist_append (component->remote_candidates, remote);
remote); agent_signal_new_remote_candidate (agent, remote);
if (modified_list) {
component->remote_candidates = modified_list;
agent_signal_new_remote_candidate (agent, remote);
}
else { /* error: memory alloc / list */
nice_candidate_free (remote), remote = NULL;
return NULL;
}
} }
if (component->selected_pair.keepalive.tick_source != NULL) { if (component->selected_pair.keepalive.tick_source != NULL) {
......
...@@ -1249,60 +1249,39 @@ static void priv_mark_pair_nominated (NiceAgent *agent, Stream *stream, Componen ...@@ -1249,60 +1249,39 @@ static void priv_mark_pair_nominated (NiceAgent *agent, Stream *stream, Componen
* Creates a new connectivity check pair and adds it to * Creates a new connectivity check pair and adds it to
* the agent's list of checks. * the agent's list of checks.
*/ */
static gboolean priv_add_new_check_pair (NiceAgent *agent, guint stream_id, Component *component, NiceCandidate *local, NiceCandidate *remote, NiceCheckState initial_state, gboolean use_candidate) static void priv_add_new_check_pair (NiceAgent *agent, guint stream_id, Component *component, NiceCandidate *local, NiceCandidate *remote, NiceCheckState initial_state, gboolean use_candidate)
{ {
gboolean result = FALSE;
Stream *stream = agent_find_stream (agent, stream_id); Stream *stream = agent_find_stream (agent, stream_id);
CandidateCheckPair *pair = g_slice_new0 (CandidateCheckPair); CandidateCheckPair *pair = g_slice_new0 (CandidateCheckPair);
if (pair) {
GSList *modified_list =
g_slist_insert_sorted (stream->conncheck_list, pair, (GCompareFunc)conn_check_compare);
if (modified_list) {
/* step: allocation and addition succesful, do rest of the work */
pair->agent = agent;
pair->stream_id = stream_id;
pair->component_id = component->id;;
pair->local = local;
pair->remote = remote;
g_snprintf (pair->foundation, NICE_CANDIDATE_PAIR_MAX_FOUNDATION, "%s:%s", local->foundation, remote->foundation);
pair->priority = agent_candidate_pair_priority (agent, local, remote);
pair->state = initial_state;
nice_debug ("Agent %p : creating new pair %p state %d", agent, pair, initial_state);
pair->nominated = use_candidate;
pair->controlling = agent->controlling_mode;
/* note: for the first added check */
if (!stream->conncheck_list)
stream->conncheck_state = NICE_CHECKLIST_RUNNING;
stream->conncheck_list = modified_list;
result = TRUE;
nice_debug ("Agent %p : added a new conncheck %p with foundation of '%s' to list %u.", agent, pair, pair->foundation, stream_id);
/* implement the hard upper limit for number of
checks (see sect 5.7.3 ICE ID-19): */
if (agent->compatibility == NICE_COMPATIBILITY_RFC5245) {
stream->conncheck_list =
priv_limit_conn_check_list_size (stream->conncheck_list, agent->max_conn_checks);
}
if (!stream->conncheck_list) {
stream->conncheck_state = NICE_CHECKLIST_FAILED;
result = FALSE;
}
}
else {
/* memory alloc failed: list insert */
conn_check_free_item (pair, NULL);
stream->conncheck_state = NICE_CHECKLIST_FAILED;
}
}
else { /* memory alloc failed: new pair */
stream->conncheck_state = NICE_CHECKLIST_FAILED;
}
return result; stream->conncheck_list = g_slist_insert_sorted (stream->conncheck_list, pair,
(GCompareFunc)conn_check_compare);
pair->agent = agent;
pair->stream_id = stream_id;
pair->component_id = component->id;;
pair->local = local;
pair->remote = remote;
g_snprintf (pair->foundation, NICE_CANDIDATE_PAIR_MAX_FOUNDATION, "%s:%s", local->foundation, remote->foundation);
pair->priority = agent_candidate_pair_priority (agent, local, remote);
pair->state = initial_state;
nice_debug ("Agent %p : creating new pair %p state %d", agent, pair, initial_state);
pair->nominated = use_candidate;
pair->controlling = agent->controlling_mode;
/* note: for the first added check */
if (!stream->conncheck_list)
stream->conncheck_state = NICE_CHECKLIST_RUNNING;
nice_debug ("Agent %p : added a new conncheck %p with foundation of '%s' to list %u.", agent, pair, pair->foundation, stream_id);
/* implement the hard upper limit for number of
checks (see sect 5.7.3 ICE ID-19): */
if (agent->compatibility == NICE_COMPATIBILITY_RFC5245) {
stream->conncheck_list =
priv_limit_conn_check_list_size (stream->conncheck_list, agent->max_conn_checks);
}
} }
/* /*
...@@ -1330,8 +1309,6 @@ int conn_check_add_for_candidate (NiceAgent *agent, guint stream_id, Component * ...@@ -1330,8 +1309,6 @@ int conn_check_add_for_candidate (NiceAgent *agent, guint stream_id, Component *
if (local->transport == remote->transport && if (local->transport == remote->transport &&
local->addr.s.addr.sa_family == remote->addr.s.addr.sa_family) { local->addr.s.addr.sa_family == remote->addr.s.addr.sa_family) {
gboolean result;
/* note: do not create pairs where local candidate is /* note: do not create pairs where local candidate is
* a srv-reflexive (ICE 5.7.3. "Pruning the Pairs" ID-19) */ * a srv-reflexive (ICE 5.7.3. "Pruning the Pairs" ID-19) */
if ((agent->compatibility == NICE_COMPATIBILITY_RFC5245 || if ((agent->compatibility == NICE_COMPATIBILITY_RFC5245 ||
...@@ -1339,24 +1316,18 @@ int conn_check_add_for_candidate (NiceAgent *agent, guint stream_id, Component * ...@@ -1339,24 +1316,18 @@ int conn_check_add_for_candidate (NiceAgent *agent, guint stream_id, Component *
local->type == NICE_CANDIDATE_TYPE_SERVER_REFLEXIVE) local->type == NICE_CANDIDATE_TYPE_SERVER_REFLEXIVE)
continue; continue;
result = priv_add_new_check_pair (agent, stream_id, component, local, remote, NICE_CHECK_FROZEN, FALSE); priv_add_new_check_pair (agent, stream_id, component, local, remote, NICE_CHECK_FROZEN, FALSE);
if (result) { ++added;
++added; if (component->state < NICE_COMPONENT_STATE_CONNECTED) {
if (component->state < NICE_COMPONENT_STATE_CONNECTED) { agent_signal_component_state_change (agent,
agent_signal_component_state_change (agent, stream_id,
stream_id, component->id,
component->id, NICE_COMPONENT_STATE_CONNECTING);
NICE_COMPONENT_STATE_CONNECTING); } else {
} else { agent_signal_component_state_change (agent,
agent_signal_component_state_change (agent, stream_id,
stream_id, component->id,
component->id, NICE_COMPONENT_STATE_CONNECTED);
NICE_COMPONENT_STATE_CONNECTED);
}
}
else {
added = -1;
break;
} }
} }
} }
...@@ -1766,7 +1737,7 @@ static guint priv_prune_pending_checks (Stream *stream, guint component_id) ...@@ -1766,7 +1737,7 @@ static guint priv_prune_pending_checks (Stream *stream, guint component_id)
static gboolean priv_schedule_triggered_check (NiceAgent *agent, Stream *stream, Component *component, NiceSocket *local_socket, NiceCandidate *remote_cand, gboolean use_candidate) static gboolean priv_schedule_triggered_check (NiceAgent *agent, Stream *stream, Component *component, NiceSocket *local_socket, NiceCandidate *remote_cand, gboolean use_candidate)
{ {
GSList *i; GSList *i;
gboolean result = FALSE; NiceCandidate *local = NULL;
for (i = stream->conncheck_list; i ; i = i->next) { for (i = stream->conncheck_list; i ; i = i->next) {
CandidateCheckPair *p = i->data; CandidateCheckPair *p = i->data;
...@@ -1807,23 +1778,21 @@ static gboolean priv_schedule_triggered_check (NiceAgent *agent, Stream *stream, ...@@ -1807,23 +1778,21 @@ static gboolean priv_schedule_triggered_check (NiceAgent *agent, Stream *stream,
} }
} }
{ for (i = component->local_candidates; i ; i = i->next) {
NiceCandidate *local = NULL; local = i->data;
if (local->sockptr == local_socket)
for (i = component->local_candidates; i ; i = i->next) { break;
local = i->data;
if (local->sockptr == local_socket)
break;
}
if (i) {
nice_debug ("Agent %p : Adding a triggered check to conn.check list (local=%p).", agent, local);
result = priv_add_new_check_pair (agent, stream->id, component, local, remote_cand, NICE_CHECK_WAITING, use_candidate);
}
else
nice_debug ("Agent %p : Didn't find a matching pair for triggered check (remote-cand=%p).", agent, remote_cand);
} }
return result; if (i) {
nice_debug ("Agent %p : Adding a triggered check to conn.check list (local=%p).", agent, local);
priv_add_new_check_pair (agent, stream->id, component, local, remote_cand, NICE_CHECK_WAITING, use_candidate);
return TRUE;
}
else {
nice_debug ("Agent %p : Didn't find a matching pair for triggered check (remote-cand=%p).", agent, remote_cand);
return FALSE;
}
} }
...@@ -1895,23 +1864,17 @@ static int priv_store_pending_check (NiceAgent *agent, Component *component, ...@@ -1895,23 +1864,17 @@ static int priv_store_pending_check (NiceAgent *agent, Component *component,
} }
icheck = g_slice_new0 (IncomingCheck); icheck = g_slice_new0 (IncomingCheck);
if (icheck) { component->incoming_checks = g_slist_append (component->incoming_checks, icheck);
GSList *pending = g_slist_append (component->incoming_checks, icheck); icheck->from = *from;
if (pending) { icheck->local_socket = socket;
component->incoming_checks = pending; icheck->priority = priority;
icheck->from = *from; icheck->use_candidate = use_candidate;
icheck->local_socket = socket; icheck->username_len = username_len;
icheck->priority = priority; icheck->username = NULL;
icheck->use_candidate = use_candidate; if (username_len > 0)
icheck->username_len = username_len; icheck->username = g_memdup (username, username_len);
icheck->username = NULL;
if (username_len > 0)
icheck->username = g_memdup (username, username_len);
return 0;
}
}
return -1; return 0;
} }
/* /*
...@@ -1923,31 +1886,29 @@ static int priv_store_pending_check (NiceAgent *agent, Component *component, ...@@ -1923,31 +1886,29 @@ static int priv_store_pending_check (NiceAgent *agent, Component *component,
static CandidateCheckPair *priv_add_peer_reflexive_pair (NiceAgent *agent, guint stream_id, guint component_id, NiceCandidate *local_cand, CandidateCheckPair *parent_pair) static CandidateCheckPair *priv_add_peer_reflexive_pair (NiceAgent *agent, guint stream_id, guint component_id, NiceCandidate *local_cand, CandidateCheckPair *parent_pair)
{ {
CandidateCheckPair *pair = g_slice_new0 (CandidateCheckPair); CandidateCheckPair *pair = g_slice_new0 (CandidateCheckPair);
if (pair) { Stream *stream = agent_find_stream (agent, stream_id);
Stream *stream = agent_find_stream (agent, stream_id);
GSList *modified_list = g_slist_append (stream->conncheck_list, pair);
if (modified_list) {
stream->conncheck_list = modified_list;
pair->agent = agent;
pair->stream_id = stream_id;
pair->component_id = component_id;;
pair->local = local_cand;
pair->remote = parent_pair->remote;
pair->state = NICE_CHECK_DISCOVERED;
nice_debug ("Agent %p : pair %p state DISCOVERED", agent, pair);
g_snprintf (pair->foundation, NICE_CANDIDATE_PAIR_MAX_FOUNDATION, "%s:%s", local_cand->foundation, parent_pair->remote->foundation);
if (agent->controlling_mode == TRUE)
pair->priority = nice_candidate_pair_priority (local_cand->priority, parent_pair->priority);
else
pair->priority = nice_candidate_pair_priority (parent_pair->priority, local_cand->priority);
pair->nominated = FALSE;
pair->controlling = agent->controlling_mode;
nice_debug ("Agent %p : added a new peer-discovered pair with foundation of '%s'.", agent, pair->foundation);
return pair;
}
}
return NULL; stream->conncheck_list = g_slist_append (stream->conncheck_list, pair);
pair->agent = agent;
pair->stream_id = stream_id;
pair->component_id = component_id;;
pair->local = local_cand;
pair->remote = parent_pair->remote;
pair->state = NICE_CHECK_DISCOVERED;
nice_debug ("Agent %p : pair %p state DISCOVERED", agent, pair);
g_snprintf (pair->foundation, NICE_CANDIDATE_PAIR_MAX_FOUNDATION, "%s:%s",
local_cand->foundation, parent_pair->remote->foundation);
if (agent->controlling_mode == TRUE)
pair->priority = nice_candidate_pair_priority (local_cand->priority,
parent_pair->priority);
else
pair->priority = nice_candidate_pair_priority (parent_pair->priority,
local_cand->priority);
pair->nominated = FALSE;
pair->controlling = agent->controlling_mode;
nice_debug ("Agent %p : added a new peer-discovered pair with foundation of '%s'.", agent, pair->foundation);
return pair;
} }
/* /*
...@@ -2254,34 +2215,28 @@ priv_add_new_turn_refresh (CandidateDiscovery *cdisco, NiceCandidate *relay_cand ...@@ -2254,34 +2215,28 @@ priv_add_new_turn_refresh (CandidateDiscovery *cdisco, NiceCandidate *relay_cand
{ {
CandidateRefresh *cand; CandidateRefresh *cand;
NiceAgent *agent = cdisco->agent; NiceAgent *agent = cdisco->agent;
GSList *modified_list;
cand = g_slice_new0 (CandidateRefresh); cand = g_slice_new0 (CandidateRefresh);
if (cand) { agent->refresh_list = g_slist_append (agent->refresh_list, cand);
modified_list = g_slist_append (agent->refresh_list, cand);
cand->nicesock = cdisco->nicesock;
if (modified_list) { cand->relay_socket = relay_cand->sockptr;
cand->nicesock = cdisco->nicesock; cand->server = cdisco->server;
cand->relay_socket = relay_cand->sockptr; cand->turn = cdisco->turn;
cand->server = cdisco->server; cand->stream = cdisco->stream;
cand->turn = cdisco->turn; cand->component = cdisco->component;
cand->stream = cdisco->stream; cand->agent = cdisco->agent;
cand->component = cdisco->component; memcpy (&cand->stun_agent, &cdisco->stun_agent, sizeof(StunAgent));
cand->agent = cdisco->agent; nice_debug ("Agent %p : Adding new refresh candidate %p with timeout %d",
memcpy (&cand->stun_agent, &cdisco->stun_agent, sizeof(StunAgent)); agent, cand, (lifetime - 60) * 1000);
nice_debug ("Agent %p : Adding new refresh candidate %p with timeout %d",
agent, cand, (lifetime - 60) * 1000); /* step: also start the refresh timer */
agent->refresh_list = modified_list; /* refresh should be sent 1 minute before it expires */
cand->timer_source =
/* step: also start the refresh timer */ agent_timeout_add_with_context (agent, (lifetime - 60) * 1000,
/* refresh should be sent 1 minute before it expires */ priv_turn_allocate_refresh_tick, cand);
cand->timer_source =
agent_timeout_add_with_context (agent, (lifetime - 60) * 1000, nice_debug ("timer source is : %d", cand->timer_source);
priv_turn_allocate_refresh_tick, cand);
nice_debug ("timer source is : %d", cand->timer_source);
}
}
return cand; return cand;
} }
...@@ -2700,9 +2655,7 @@ gboolean conn_check_handle_inbound_stun (NiceAgent *agent, Stream *stream, ...@@ -2700,9 +2655,7 @@ gboolean conn_check_handle_inbound_stun (NiceAgent *agent, Stream *stream,
} }
} }
g_free (validater_data.password);
if (validater_data.password)
g_free (validater_data.password);
if (valid == STUN_VALIDATION_NOT_STUN || if (valid == STUN_VALIDATION_NOT_STUN ||
valid == STUN_VALIDATION_INCOMPLETE_STUN || valid == STUN_VALIDATION_INCOMPLETE_STUN ||
......
...@@ -87,15 +87,12 @@ void discovery_free_item (gpointer data, gpointer user_data) ...@@ -87,15 +87,12 @@ void discovery_free_item (gpointer data, gpointer user_data)
*/ */
void discovery_free (NiceAgent *agent) void discovery_free (NiceAgent *agent)
{ {
if (agent->discovery_list) {
GSList *tmp = agent->discovery_list;
agent->discovery_list = NULL;
g_slist_foreach (tmp, discovery_free_item, NULL); g_slist_foreach (agent->discovery_list, discovery_free_item, NULL);
g_slist_free (tmp); g_slist_free (agent->discovery_list);
agent->discovery_list = NULL;
agent->discovery_unsched_items = 0;
agent->discovery_unsched_items = 0;
}
if (agent->discovery_timer_source != NULL) { if (agent->discovery_timer_source != NULL) {
g_source_destroy (agent->discovery_timer_source); g_source_destroy (agent->discovery_timer_source);
g_source_unref (agent->discovery_timer_source); g_source_unref (agent->discovery_timer_source);
...@@ -204,14 +201,9 @@ void refresh_free_item (gpointer data, gpointer user_data) ...@@ -204,14 +201,9 @@ void refresh_free_item (gpointer data, gpointer user_data)
*/ */
void refresh_free (NiceAgent *agent) void refresh_free (NiceAgent *agent)
{ {
if (agent->refresh_list) { g_slist_foreach (agent->refresh_list, refresh_free_item, NULL);
GSList *tmp = agent->refresh_list; g_slist_free (agent->refresh_list);
agent->refresh_list = NULL; agent->refresh_list = NULL;
g_slist_foreach (tmp, refresh_free_item, NULL);
g_slist_free (tmp);
}
} }
/* /*
...@@ -252,11 +244,11 @@ void refresh_cancel (CandidateRefresh *refresh) ...@@ -252,11 +244,11 @@ void refresh_cancel (CandidateRefresh *refresh)
*/ */
static gboolean priv_add_local_candidate_pruned (Component *component, NiceCandidate *candidate) static gboolean priv_add_local_candidate_pruned (Component *component, NiceCandidate *candidate)
{ {
GSList *modified_list, *i; GSList *i;
for (i = component->local_candidates; i ; i = i->next) { for (i = component->local_candidates; i ; i = i->next) {
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)) {
nice_debug ("Candidate %p (component-id %u) redundant, ignoring.", candidate, component->id); nice_debug ("Candidate %p (component-id %u) redundant, ignoring.", candidate, component->id);
...@@ -264,11 +256,8 @@ static gboolean priv_add_local_candidate_pruned (Component *component, NiceCandi ...@@ -264,11 +256,8 @@ static gboolean priv_add_local_candidate_pruned (Component *component, NiceCandi
} }
} }
modified_list = g_slist_append (component->local_candidates, component->local_candidates = g_slist_append (component->local_candidates,
candidate); candidate);
if (modified_list) {
component->local_candidates = modified_list;
}
return TRUE; return TRUE;
} }
...@@ -418,10 +407,8 @@ void priv_generate_candidate_credentials (NiceAgent *agent, ...@@ -418,10 +407,8 @@ void priv_generate_candidate_credentials (NiceAgent *agent,
guchar username[32]; guchar username[32];
guchar password[16]; guchar password[16];
if (candidate->username) g_free (candidate->username);
g_free (candidate->username); g_free (candidate->password);
if (candidate->password)
g_free (candidate->password);
nice_rng_generate_bytes (agent->rng, 32, (gchar *)username); nice_rng_generate_bytes (agent->rng, 32, (gchar *)username);
nice_rng_generate_bytes (agent->rng, 16, (gchar *)password); nice_rng_generate_bytes (agent->rng, 16, (gchar *)password);
...@@ -432,10 +419,8 @@ void priv_generate_candidate_credentials (NiceAgent *agent, ...@@ -432,10 +419,8 @@ void priv_generate_candidate_credentials (NiceAgent *agent,
} else if (agent->compatibility == NICE_COMPATIBILITY_GOOGLE) { } else if (agent->compatibility == NICE_COMPATIBILITY_GOOGLE) {
gchar username[16]; gchar username[16];
if (candidate->username) g_free (candidate->username);
g_free (candidate->username); g_free (candidate->password);
if (candidate->password)
g_free (candidate->password);
candidate->password = NULL; candidate->password = NULL;
nice_rng_generate_bytes_print (agent->rng, 16, (gchar *)username); nice_rng_generate_bytes_print (agent->rng, 16, (gchar *)username);
...@@ -462,72 +447,54 @@ NiceCandidate *discovery_add_local_host_candidate ( ...@@ -462,72 +447,54 @@ NiceCandidate *discovery_add_local_host_candidate (
Component *component; Component *component;
Stream *stream; Stream *stream;
NiceSocket *udp_socket = NULL; NiceSocket *udp_socket = NULL;
gboolean errors = FALSE;
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);
if (candidate) { 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; candidate->base_addr = *address;
candidate->base_addr = *address; 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) { candidate->priority = nice_candidate_msn_priority (candidate);
candidate->priority = nice_candidate_msn_priority (candidate); } else {
} else { candidate->priority = nice_candidate_ice_priority (candidate);
candidate->priority = nice_candidate_ice_priority (candidate);
}
priv_generate_candidate_credentials (agent, candidate);
priv_assign_foundation (agent, candidate);
/* note: candidate username and password are left NULL as stream
level ufrag/password are used */
udp_socket = nice_udp_bsd_socket_new (address);
if (udp_socket) {
gboolean result;
_priv_set_socket_tos (agent, udp_socket, stream->tos);
agent_attach_stream_component_socket (agent, stream,
component, udp_socket);
candidate->sockptr = udp_socket;
candidate->addr = udp_socket->addr;
candidate->base_addr = udp_socket->addr;
result = priv_add_local_candidate_pruned (component, candidate);
if (result == TRUE) {
GSList *modified_list = g_slist_append (component->sockets, udp_socket);
if (modified_list) {
/* success: store a pointer to the sockaddr */
component->sockets = modified_list;
agent_signal_new_candidate (agent, candidate);
} else { /* error: list memory allocation */
candidate = NULL; /* note: candidate already owned by component */
}
} else {
/* error: memory allocation, or duplicate candidates */
errors = TRUE;
}
} else {
/* error: socket new */
errors = TRUE;
}
} }
/* clean up after errors */ priv_generate_candidate_credentials (agent, candidate);
if (errors) { priv_assign_foundation (agent, candidate);
if (candidate)
nice_candidate_free (candidate), candidate = NULL; /* note: candidate username and password are left NULL as stream
if (udp_socket) level ufrag/password are used */
nice_socket_free (udp_socket); udp_socket = nice_udp_bsd_socket_new (address);
} if (!udp_socket)
goto errors;
_priv_set_socket_tos (agent, udp_socket, stream->tos);
agent_attach_stream_component_socket (agent, stream,
component, udp_socket);
candidate->sockptr = udp_socket;
candidate->addr = udp_socket->addr;
candidate->base_addr = udp_socket->addr;
if (!priv_add_local_candidate_pruned (component, candidate))
goto errors;
component->sockets = g_slist_append (component->sockets, udp_socket);
agent_signal_new_candidate (agent, candidate);
return candidate; return candidate;
errors:
nice_candidate_free (candidate);
if (udp_socket)
nice_socket_free (udp_socket);
return NULL;
} }
/* /*
...@@ -553,34 +520,33 @@ discovery_add_server_reflexive_candidate ( ...@@ -553,34 +520,33 @@ discovery_add_server_reflexive_candidate (
return NULL; return NULL;
candidate = nice_candidate_new (NICE_CANDIDATE_TYPE_SERVER_REFLEXIVE); candidate = nice_candidate_new (NICE_CANDIDATE_TYPE_SERVER_REFLEXIVE);
if (candidate) {
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) {
candidate->priority = nice_candidate_msn_priority (candidate); candidate->priority = nice_candidate_msn_priority (candidate);
} else { } else {
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->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;
/* step: link to the base candidate+socket */ /* step: link to the base candidate+socket */
candidate->sockptr = base_socket; candidate->sockptr = base_socket;
candidate->base_addr = base_socket->addr; candidate->base_addr = base_socket->addr;
priv_generate_candidate_credentials (agent, candidate); priv_generate_candidate_credentials (agent, candidate);
priv_assign_foundation (agent, candidate); priv_assign_foundation (agent, candidate);
result = priv_add_local_candidate_pruned (component, candidate); result = priv_add_local_candidate_pruned (component, candidate);
if (result) { if (result) {
agent_signal_new_candidate (agent, candidate); agent_signal_new_candidate (agent, candidate);
} }
else { else {
/* error: memory allocation, or duplicate candidatet */ /* error: duplicate candidate */
nice_candidate_free (candidate), candidate = NULL; nice_candidate_free (candidate), candidate = NULL;
}
} }
return candidate; return candidate;
...@@ -605,76 +571,60 @@ discovery_add_relay_candidate ( ...@@ -605,76 +571,60 @@ discovery_add_relay_candidate (
NiceCandidate *candidate; NiceCandidate *candidate;
Component *component; Component *component;
Stream *stream; Stream *stream;
gboolean result = FALSE;
gboolean errors = FALSE;
NiceSocket *relay_socket = NULL; NiceSocket *relay_socket = 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_RELAYED); candidate = nice_candidate_new (NICE_CANDIDATE_TYPE_RELAYED);
if (candidate) {
if (agent->compatibility == NICE_COMPATIBILITY_GOOGLE) {
candidate->priority = nice_candidate_jingle_priority (candidate);
} else if (agent->compatibility == NICE_COMPATIBILITY_MSN) {
candidate->priority = nice_candidate_msn_priority (candidate);
} else {
candidate->priority = nice_candidate_ice_priority_full
(NICE_CANDIDATE_TYPE_PREF_RELAYED, 0, component_id);
}
candidate->stream_id = stream_id;
candidate->component_id = component_id;
candidate->addr = *address;
candidate->turn = turn;
/* step: link to the base candidate+socket */
relay_socket = nice_turn_socket_new (agent, address,
base_socket, &turn->server,
turn->username, turn->password,
agent_to_turn_socket_compatibility (agent));
if (relay_socket) {
candidate->sockptr = relay_socket;
candidate->base_addr = base_socket->addr;
priv_generate_candidate_credentials (agent, candidate);
/* Google uses the turn username as the candidate username */
if (agent->compatibility == NICE_COMPATIBILITY_GOOGLE) {
g_free (candidate->username);
candidate->username = g_strdup (turn->username);
}
priv_assign_foundation (agent, candidate);
result = priv_add_local_candidate_pruned (component, candidate); if (agent->compatibility == NICE_COMPATIBILITY_GOOGLE) {
if (result) { candidate->priority = nice_candidate_jingle_priority (candidate);
GSList *modified_list = g_slist_append (component->sockets, relay_socket); } else if (agent->compatibility == NICE_COMPATIBILITY_MSN) {
if (modified_list) { candidate->priority = nice_candidate_msn_priority (candidate);
/* success: store a pointer to the sockaddr */
component->sockets = modified_list;
}
agent_signal_new_candidate (agent, candidate);
} else {
/* error: memory allocation, or duplicate candidate */
errors = TRUE;
}
} else {
/* error: socket factory make */
errors = TRUE;
}
} else { } else {
/* error: udp socket memory allocation */ candidate->priority = nice_candidate_ice_priority_full
errors = TRUE; (NICE_CANDIDATE_TYPE_PREF_RELAYED, 0, component_id);
} }
candidate->stream_id = stream_id;
/* clean up after errors */ candidate->component_id = component_id;
if (errors) { candidate->addr = *address;
if (candidate) candidate->turn = turn;
nice_candidate_free (candidate), candidate = NULL;
if (relay_socket) /* step: link to the base candidate+socket */
nice_socket_free (relay_socket); relay_socket = nice_turn_socket_new (agent, address,
base_socket, &turn->server,
turn->username, turn->password,
agent_to_turn_socket_compatibility (agent));
if (!relay_socket)
goto errors;
candidate->sockptr = relay_socket;
candidate->base_addr = base_socket->addr;
priv_generate_candidate_credentials (agent, candidate);
/* Google uses the turn username as the candidate username */
if (agent->compatibility == NICE_COMPATIBILITY_GOOGLE) {
g_free (candidate->username);
candidate->username = g_strdup (turn->username);
} }
priv_assign_foundation (agent, candidate);
if (!priv_add_local_candidate_pruned (component, candidate))
goto errors;
component->sockets = g_slist_append (component->sockets, relay_socket);
agent_signal_new_candidate (agent, candidate);
return candidate; return candidate;
errors:
nice_candidate_free (candidate);
if (relay_socket)
nice_socket_free (relay_socket);
return NULL;
} }
/* /*
...@@ -683,7 +633,7 @@ discovery_add_relay_candidate ( ...@@ -683,7 +633,7 @@ discovery_add_relay_candidate (
* *
* @return pointer to the created candidate, or NULL on error * @return pointer to the created candidate, or NULL on error
*/ */
NiceCandidate* NiceCandidate*
discovery_add_peer_reflexive_candidate ( discovery_add_peer_reflexive_candidate (
NiceAgent *agent, NiceAgent *agent,
guint stream_id, guint stream_id,
...@@ -696,71 +646,69 @@ discovery_add_peer_reflexive_candidate ( ...@@ -696,71 +646,69 @@ discovery_add_peer_reflexive_candidate (
NiceCandidate *candidate; NiceCandidate *candidate;
Component *component; Component *component;
Stream *stream; Stream *stream;
gboolean result;
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_PEER_REFLEXIVE); candidate = nice_candidate_new (NICE_CANDIDATE_TYPE_PEER_REFLEXIVE);
if (candidate) {
gboolean result; candidate->transport = NICE_CANDIDATE_TRANSPORT_UDP;
if (agent->compatibility == NICE_COMPATIBILITY_GOOGLE) {
candidate->transport = NICE_CANDIDATE_TRANSPORT_UDP; candidate->priority = nice_candidate_jingle_priority (candidate);
if (agent->compatibility == NICE_COMPATIBILITY_GOOGLE) { } else if (agent->compatibility == NICE_COMPATIBILITY_MSN) {
candidate->priority = nice_candidate_jingle_priority (candidate); candidate->priority = nice_candidate_msn_priority (candidate);
} else if (agent->compatibility == NICE_COMPATIBILITY_MSN) { } else {
candidate->priority = nice_candidate_msn_priority (candidate); candidate->priority = nice_candidate_ice_priority_full
} else {
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->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;
candidate->base_addr = base_socket->addr; candidate->base_addr = base_socket->addr;
priv_assign_foundation (agent, candidate); priv_assign_foundation (agent, candidate);
if (agent->compatibility == NICE_COMPATIBILITY_MSN && if (agent->compatibility == NICE_COMPATIBILITY_MSN &&
remote && local) { remote && local) {
guchar *new_username = NULL; guchar *new_username = NULL;
guchar *decoded_local = NULL; guchar *decoded_local = NULL;
guchar *decoded_remote = NULL; guchar *decoded_remote = NULL;
gsize local_size; gsize local_size;
gsize remote_size; gsize remote_size;
g_free(candidate->username); g_free(candidate->username);
g_free(candidate->password); g_free(candidate->password);
decoded_local = g_base64_decode (local->username, &local_size); decoded_local = g_base64_decode (local->username, &local_size);
decoded_remote = g_base64_decode (remote->username, &remote_size); decoded_remote = g_base64_decode (remote->username, &remote_size);
new_username = g_new0(guchar, local_size + remote_size); new_username = g_new0(guchar, local_size + remote_size);
memcpy(new_username, decoded_local, local_size); memcpy(new_username, decoded_local, local_size);
memcpy(new_username + local_size, decoded_remote, remote_size); memcpy(new_username + local_size, decoded_remote, remote_size);
candidate->username = g_base64_encode (new_username, local_size + remote_size); candidate->username = g_base64_encode (new_username, local_size + remote_size);
g_free(new_username); g_free(new_username);
g_free(decoded_local); g_free(decoded_local);
g_free(decoded_remote); g_free(decoded_remote);
candidate->password = g_strdup(local->password); candidate->password = g_strdup(local->password);
} else if (local) { } else if (local) {
g_free(candidate->username); g_free(candidate->username);
g_free(candidate->password); g_free(candidate->password);
candidate->username = g_strdup(local->username); candidate->username = g_strdup(local->username);
candidate->password = g_strdup(local->password); candidate->password = g_strdup(local->password);
} }
/* step: link to the base candidate+socket */ /* step: link to the base candidate+socket */
candidate->sockptr = base_socket; candidate->sockptr = base_socket;
candidate->base_addr = base_socket->addr; candidate->base_addr = base_socket->addr;
result = priv_add_local_candidate_pruned (component, candidate); result = priv_add_local_candidate_pruned (component, candidate);
if (result != TRUE) { if (result != TRUE) {
/* error: memory allocation, or duplicate candidatet */ /* error: memory allocation, or duplicate candidatet */
nice_candidate_free (candidate), candidate = NULL; nice_candidate_free (candidate), candidate = NULL;
}
} }
return candidate; return candidate;
...@@ -792,76 +740,67 @@ NiceCandidate *discovery_learn_remote_peer_reflexive_candidate ( ...@@ -792,76 +740,67 @@ NiceCandidate *discovery_learn_remote_peer_reflexive_candidate (
(void)udp_socket; (void)udp_socket;
candidate = nice_candidate_new (NICE_CANDIDATE_TYPE_PEER_REFLEXIVE); candidate = nice_candidate_new (NICE_CANDIDATE_TYPE_PEER_REFLEXIVE);
if (candidate) {
GSList *modified_list; candidate->transport = NICE_CANDIDATE_TRANSPORT_UDP;
candidate->addr = *remote_address;
candidate->transport = NICE_CANDIDATE_TRANSPORT_UDP; candidate->base_addr = *remote_address;
candidate->addr = *remote_address;
candidate->base_addr = *remote_address; /* if the check didn't contain the PRIORITY attribute, then the priority will
* be 0, which is invalid... */
/* if the check didn't contain the PRIORITY attribute, then the priority will if (priority != 0) {
* be 0, which is invalid... */ candidate->priority = priority;
if (priority != 0) { } else if (agent->compatibility == NICE_COMPATIBILITY_GOOGLE) {
candidate->priority = priority; candidate->priority = nice_candidate_jingle_priority (candidate);
} else if (agent->compatibility == NICE_COMPATIBILITY_GOOGLE) { } else if (agent->compatibility == NICE_COMPATIBILITY_MSN) {
candidate->priority = nice_candidate_jingle_priority (candidate); candidate->priority = nice_candidate_msn_priority (candidate);
} else if (agent->compatibility == NICE_COMPATIBILITY_MSN) { } else {
candidate->priority = nice_candidate_msn_priority (candidate); candidate->priority = nice_candidate_ice_priority_full
} else {
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->stream_id = stream->id; candidate->stream_id = stream->id;
candidate->component_id = component->id; candidate->component_id = component->id;
priv_assign_remote_foundation (agent, candidate); priv_assign_remote_foundation (agent, candidate);
if (agent->compatibility == NICE_COMPATIBILITY_MSN && if (agent->compatibility == NICE_COMPATIBILITY_MSN &&
remote && local) { remote && local) {
guchar *new_username = NULL; guchar *new_username = NULL;
guchar *decoded_local = NULL; guchar *decoded_local = NULL;
guchar *decoded_remote = NULL; guchar *decoded_remote = NULL;
gsize local_size; gsize local_size;
gsize remote_size; gsize remote_size;
g_free(candidate->username); g_free(candidate->username);
g_free (candidate->password); g_free (candidate->password);
decoded_local = g_base64_decode (local->username, &local_size); decoded_local = g_base64_decode (local->username, &local_size);
decoded_remote = g_base64_decode (remote->username, &remote_size); decoded_remote = g_base64_decode (remote->username, &remote_size);
new_username = g_new0(guchar, local_size + remote_size); new_username = g_new0(guchar, local_size + remote_size);
memcpy(new_username, decoded_remote, remote_size); memcpy(new_username, decoded_remote, remote_size);
memcpy(new_username + remote_size, decoded_local, local_size); memcpy(new_username + remote_size, decoded_local, local_size);
candidate->username = g_base64_encode (new_username, local_size + remote_size); candidate->username = g_base64_encode (new_username, local_size + remote_size);
g_free(new_username); g_free(new_username);
g_free(decoded_local); g_free(decoded_local);
g_free(decoded_remote); g_free(decoded_remote);
candidate->password = g_strdup(remote->password); candidate->password = g_strdup(remote->password);
} else if (remote) { } else if (remote) {
g_free (candidate->username); g_free (candidate->username);
g_free (candidate->password); g_free (candidate->password);
candidate->username = g_strdup(remote->username); candidate->username = g_strdup(remote->username);
candidate->password = g_strdup(remote->password); candidate->password = g_strdup(remote->password);
} }
candidate->sockptr = NULL; /* not stored for remote candidates */
/* note: candidate username and password are left NULL as stream
level ufrag/password are used */
candidate->sockptr = NULL; /* not stored for remote candidates */ component->remote_candidates = g_slist_append (component->remote_candidates,
/* note: candidate username and password are left NULL as stream candidate);
level ufrag/password are used */
modified_list = g_slist_append (component->remote_candidates, agent_signal_new_remote_candidate (agent, candidate);
candidate);
if (modified_list) {
component->remote_candidates = modified_list;
agent_signal_new_remote_candidate (agent, candidate);
}
else { /* error: memory alloc / list */
nice_candidate_free (candidate), candidate = NULL;
}
}
return candidate; return candidate;
} }
......
...@@ -52,27 +52,12 @@ stream_new (guint n_components) ...@@ -52,27 +52,12 @@ stream_new (guint n_components)
{ {
Stream *stream; Stream *stream;
guint n; guint n;
gboolean errors = FALSE;
GSList *modified_list;
Component *component; Component *component;
stream = g_slice_new0 (Stream); stream = g_slice_new0 (Stream);
for (n = 0; n < n_components; n++) { for (n = 0; n < n_components; n++) {
component = component_new (n + 1); component = component_new (n + 1);
if (component) { stream->components = g_slist_append (stream->components, component);
modified_list = g_slist_append (stream->components, component);
if (modified_list)
stream->components = modified_list;
else
errors = TRUE;
}
else
errors = TRUE;
}
if (errors) {
stream_free (stream);
return NULL;
} }
stream->n_components = n_components; stream->n_components = n_components;
......
...@@ -91,7 +91,7 @@ nice_tcp_bsd_socket_new (NiceAgent *agent, GMainContext *ctx, NiceAddress *addr) ...@@ -91,7 +91,7 @@ nice_tcp_bsd_socket_new (NiceAgent *agent, GMainContext *ctx, NiceAddress *addr)
int ret; int ret;
struct sockaddr_storage name; struct sockaddr_storage name;
guint name_len = sizeof (name); guint name_len = sizeof (name);
NiceSocket *sock = g_slice_new0 (NiceSocket); NiceSocket *sock;
TcpPriv *priv; TcpPriv *priv;
if (addr == NULL) { if (addr == NULL) {
...@@ -99,6 +99,8 @@ nice_tcp_bsd_socket_new (NiceAgent *agent, GMainContext *ctx, NiceAddress *addr) ...@@ -99,6 +99,8 @@ nice_tcp_bsd_socket_new (NiceAgent *agent, GMainContext *ctx, NiceAddress *addr)
return NULL; return NULL;
} }
sock = g_slice_new0 (NiceSocket);
nice_address_copy_to_sockaddr(addr, (struct sockaddr *)&name); nice_address_copy_to_sockaddr(addr, (struct sockaddr *)&name);
if (sockfd == -1) { if (sockfd == -1) {
......
...@@ -73,10 +73,6 @@ nice_udp_bsd_socket_new (NiceAddress *addr) ...@@ -73,10 +73,6 @@ nice_udp_bsd_socket_new (NiceAddress *addr)
socklen_t name_len = sizeof (name); socklen_t name_len = sizeof (name);
NiceSocket *sock = g_slice_new0 (NiceSocket); NiceSocket *sock = g_slice_new0 (NiceSocket);
if (!sock) {
return NULL;
}
if (addr != NULL) { if (addr != NULL) {
nice_address_copy_to_sockaddr(addr, (struct sockaddr *)&name); nice_address_copy_to_sockaddr(addr, (struct sockaddr *)&name);
} else { } else {
......
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