Commit 88c841a9 authored by Olivier Crête's avatar Olivier Crête

component: Close other sockets

parent 2bb0fc58
......@@ -2982,6 +2982,14 @@ agent_recv_message_unlocked (
retval = nice_udp_turn_socket_parse_recv_message (
component->turn_candidate->sockptr, &nicesock, message);
}
if (!is_turn && component->selected_pair.local &&
component->selected_pair.local->turn &&
nice_address_equal (message->from,
&component->selected_pair.local->turn->server)) {
is_turn = TRUE;
retval = nice_udp_turn_socket_parse_recv_message (
component->selected_pair.local->sockptr, &nicesock, message);
}
for (item = component->turn_servers; item && !is_turn;
item = g_list_next (item)) {
TurnServer *turn = item->data;
......@@ -5306,6 +5314,32 @@ nice_agent_forget_relays (NiceAgent *agent, guint stream_id, guint component_id)
return ret;
}
NICEAPI_EXPORT gboolean
nice_agent_close_other_sockets (NiceAgent *agent, guint stream_id,
guint component_id)
{
Component *component;
gboolean ret = TRUE;
g_return_val_if_fail (NICE_IS_AGENT (agent), FALSE);
g_return_val_if_fail (stream_id >= 1, FALSE);
g_return_val_if_fail (component_id >= 1, FALSE);
agent_lock ();
if (!agent_find_component (agent, stream_id, component_id, NULL, &component)) {
ret = FALSE;
goto done;
}
component_clean_candidates (component);
done:
agent_unlock_and_emit (agent);
return ret;
}
/* Helper function to allow us to send connchecks reliably.
* If the transport is reliable, then we request a reliable send, which will
* either send the data, or queue it in the case of unestablished http/socks5
......
......@@ -1521,6 +1521,10 @@ nice_agent_get_component_state (NiceAgent *agent,
guint stream_id,
guint component_id);
gboolean
nice_agent_close_other_sockets (NiceAgent *agent, guint stream_id,
guint component_id);
G_END_DECLS
#endif /* __LIBNICE_AGENT_H__ */
......@@ -286,6 +286,44 @@ component_clean_turn_servers (Component *cmp)
}
}
void
component_clean_candidates (Component *cmp)
{
GSList *i;
g_list_free_full (cmp->turn_servers, (GDestroyNotify) turn_server_unref);
cmp->turn_servers = NULL;
for (i = cmp->local_candidates; i;) {
NiceCandidate *candidate = i->data;
GSList *next = i->next;
/* note: do not remove the remote candidate that is
* currently part of the 'selected pair', see ICE
* 9.1.1.1. "ICE Restarts" (ID-19)
*
* So what we do instead is that we put the selected candidate
* in a special location and keep it "alive" that way. This is
* especially important for TURN, because refresh requests to the
* server need to keep happening.
*/
if (candidate != cmp->selected_pair.local &&
cmp->selected_pair.local->sockptr != candidate->sockptr &&
!nice_socket_has_base_socket (cmp->selected_pair.local->sockptr,
candidate->sockptr)) {
refresh_prune_candidate (cmp->agent, candidate);
discovery_prune_socket (cmp->agent, candidate->sockptr);
conn_check_prune_socket (cmp->agent, cmp->stream, cmp,
candidate->sockptr);
component_detach_socket (cmp, candidate->sockptr);
agent_remove_local_candidate (cmp->agent, candidate);
nice_candidate_free (candidate);
cmp->local_candidates = g_slist_delete_link (cmp->local_candidates, i);
}
i = next;
}
}
static void
component_clear_selected_pair (Component *component)
{
......
......@@ -263,6 +263,8 @@ component_has_io_callback (Component *component);
void
component_clean_turn_servers (Component *component);
void
component_clean_candidates (Component *cmp);
TurnServer *
turn_server_new (const gchar *server_ip, guint server_port,
......
......@@ -22,6 +22,7 @@ nice_agent_recv_messages
nice_agent_recv_nonblocking
nice_agent_recv_messages_nonblocking
nice_agent_attach_recv
nice_agent_close_other_sockets
nice_agent_forget_relays
nice_agent_gather_candidates
nice_agent_generate_local_candidate_sdp
......
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