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

Some refactoring to allow for ice-tcp (non pseudotcp reliable)

parent c0ca6c65
......@@ -184,8 +184,8 @@ void agent_signal_new_selected_pair (
NiceAgent *agent,
guint stream_id,
guint component_id,
const gchar *local_foundation,
const gchar *remote_foundation);
NiceCandidate *lcandidate,
NiceCandidate *rcandidate);
void agent_signal_component_state_change (
NiceAgent *agent,
......
......@@ -1610,7 +1610,8 @@ process_queued_tcp_packets (NiceAgent *agent, Stream *stream,
}
}
void agent_signal_new_selected_pair (NiceAgent *agent, guint stream_id, guint component_id, const gchar *local_foundation, const gchar *remote_foundation)
void agent_signal_new_selected_pair (NiceAgent *agent, guint stream_id,
guint component_id, NiceCandidate *lcandidate, NiceCandidate *rcandidate)
{
Component *component;
Stream *stream;
......@@ -1620,23 +1621,29 @@ void agent_signal_new_selected_pair (NiceAgent *agent, guint stream_id, guint co
return;
if (component->selected_pair.local->type == NICE_CANDIDATE_TYPE_RELAYED) {
nice_turn_socket_set_peer (component->selected_pair.local->sockptr,
&component->selected_pair.remote->addr);
nice_turn_socket_set_peer (lcandidate->sockptr, &rcandidate->addr);
}
if(agent->reliable) {
if (lcandidate->transport == NICE_CANDIDATE_TRANSPORT_UDP) {
if (component->tcp) {
process_queued_tcp_packets (agent, stream, component);
pseudo_tcp_socket_connect (component->tcp);
pseudo_tcp_socket_notify_mtu (component->tcp, MAX_TCP_MTU);
adjust_tcp_clock (agent, stream, component);
} else if(agent->reliable) {
nice_debug ("New selected pair received when pseudo tcp socket in error");
} else {
nice_debug ("New reliable UDP pair selected but pseudo tcp socket in error");
return;
}
} else {
nice_debug ("ICE-TCP not yet supported");
return;
}
}
agent_queue_signal (agent, signals[SIGNAL_NEW_SELECTED_PAIR],
stream_id, component_id, local_foundation, remote_foundation);
stream_id, component_id, lcandidate->foundation, rcandidate->foundation);
}
void agent_signal_new_candidate (NiceAgent *agent, NiceCandidate *candidate)
......@@ -3505,7 +3512,18 @@ nice_agent_send_messages_nonblocking_internal (
/* FIXME: Cancellation isn’t yet supported, but it doesn’t matter because
* we only deal with non-blocking writes. */
if (component->selected_pair.local != NULL) {
if (nice_debug_is_enabled ()) {
gchar tmpbuf[INET6_ADDRSTRLEN];
nice_address_to_string (&component->selected_pair.remote->addr, tmpbuf);
nice_debug ("Agent %p : s%d:%d: sending %u messages to "
"[%s]:%d", agent, stream_id, component_id, n_messages, tmpbuf,
nice_address_get_port (&component->selected_pair.remote->addr));
}
if(agent->reliable) {
if (component->selected_pair.local->transport == NICE_CANDIDATE_TRANSPORT_UDP) {
if (component->tcp != NULL) {
/* Send on the pseudo-TCP socket. */
n_sent = pseudo_tcp_socket_send_messages (component->tcp, messages,
......@@ -3519,22 +3537,18 @@ nice_agent_send_messages_nonblocking_internal (
/* Signal errors */
priv_pseudo_tcp_error (agent, stream, component);
}
} else if (agent->reliable) {
} else {
g_set_error (&child_error, G_IO_ERROR, G_IO_ERROR_FAILED,
"Error writing data to failed pseudo-TCP socket.");
} else if (component->selected_pair.local != NULL) {
}
} else {
g_set_error (&child_error, G_IO_ERROR, G_IO_ERROR_FAILED,
"ICE-TCP not yet supported.");
}
} else {
NiceSocket *sock;
NiceAddress *addr;
if (nice_debug_is_enabled ()) {
gchar tmpbuf[INET6_ADDRSTRLEN];
nice_address_to_string (&component->selected_pair.remote->addr, tmpbuf);
nice_debug ("Agent %p : s%d:%d: sending %u messages to "
"[%s]:%d", agent, stream_id, component_id, n_messages, tmpbuf,
nice_address_get_port (&component->selected_pair.remote->addr));
}
sock = component->selected_pair.local->sockptr;
addr = &component->selected_pair.remote->addr;
......@@ -3547,6 +3561,7 @@ nice_agent_send_messages_nonblocking_internal (
g_assert (n_messages == 1);
n_sent = output_message_get_size (messages);
}
}
} else {
/* Socket isn’t properly open yet. */
n_sent = 0; /* EWOULDBLOCK */
......@@ -4061,7 +4076,8 @@ nice_agent_set_selected_pair (
/* step: set the selected pair */
component_update_selected_pair (component, &pair);
agent_signal_new_selected_pair (agent, stream_id, component_id, lfoundation, rfoundation);
agent_signal_new_selected_pair (agent, stream_id, component_id,
pair.local, pair.remote);
ret = TRUE;
......@@ -4189,8 +4205,7 @@ nice_agent_set_selected_remote_candidate (
agent_signal_component_state_change (agent, stream_id, component_id, NICE_COMPONENT_STATE_READY);
agent_signal_new_selected_pair (agent, stream_id, component_id,
lcandidate->foundation,
candidate->foundation);
lcandidate, candidate);
ret = TRUE;
......
......@@ -375,6 +375,14 @@ void component_update_selected_pair (Component *component, const CandidatePair *
component->selected_pair.keepalive.tick_source = NULL;
}
if (component->selected_pair.local &&
component->selected_pair.local == component->turn_candidate) {
refresh_prune_candidate (component->agent, component->turn_candidate);
component_detach_socket (component, component->turn_candidate->sockptr);
nice_candidate_free (component->turn_candidate);
component->turn_candidate = NULL;
}
memset (&component->selected_pair, 0, sizeof(CandidatePair));
component->selected_pair.local = pair->local;
......
......@@ -1115,35 +1115,23 @@ static GSList *priv_limit_conn_check_list_size (GSList *conncheck_list, guint up
*/
static gboolean priv_update_selected_pair (NiceAgent *agent, Component *component, CandidateCheckPair *pair)
{
CandidatePair cpair;
g_assert (component);
g_assert (pair);
if (pair->priority > component->selected_pair.priority) {
if (pair->priority > component->selected_pair.priority &&
component_find_pair (component, agent, pair->local->foundation,
pair->remote->foundation, &cpair)) {
nice_debug ("Agent %p : changing SELECTED PAIR for component %u: %s:%s "
"(prio:%" G_GUINT64_FORMAT ").", agent, component->id, pair->local->foundation,
pair->remote->foundation, pair->priority);
if (component->selected_pair.keepalive.tick_source != NULL) {
g_source_destroy (component->selected_pair.keepalive.tick_source);
g_source_unref (component->selected_pair.keepalive.tick_source);
component->selected_pair.keepalive.tick_source = NULL;
}
if (component->selected_pair.local &&
component->selected_pair.local == component->turn_candidate) {
refresh_prune_candidate (agent, component->turn_candidate);
component_detach_socket (component, component->turn_candidate->sockptr);
nice_candidate_free (component->turn_candidate);
component->turn_candidate = NULL;
}
"(prio:%" G_GUINT64_FORMAT ").", agent, component->id,
pair->local->foundation, pair->remote->foundation, pair->priority);
memset (&component->selected_pair, 0, sizeof(CandidatePair));
component->selected_pair.local = pair->local;
component->selected_pair.remote = pair->remote;
component->selected_pair.priority = pair->priority;
component_update_selected_pair (component, &cpair);
priv_conn_keepalive_tick_unlocked (agent);
agent_signal_new_selected_pair (agent, pair->stream_id, component->id, pair->local->foundation, pair->remote->foundation);
agent_signal_new_selected_pair (agent, pair->stream_id, component->id,
pair->local, pair->remote);
}
......
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