From 18e5dff4f25b12522e857c13d3ef3bdb40212246 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Olivier=20Cr=C3=AAte?= Date: Sat, 17 May 2014 15:57:15 +0900 Subject: [PATCH] agent: Separate reliability from ice-tcp vs ice-udp We want ICE-TCP to not have reliable behavior unless the agent is reliable otherwise it will confuse existing VoIP applications. --- agent/agent.c | 7 ++++--- agent/discovery.c | 6 ++++-- socket/tcp-active.c | 7 +++++-- socket/tcp-active.h | 3 ++- socket/tcp-passive.c | 10 ++++++++-- socket/tcp-passive.h | 3 ++- tests/test-icetcp.c | 8 ++++---- tests/test-tcp.c | 4 ++-- 8 files changed, 31 insertions(+), 17 deletions(-) diff --git a/agent/agent.c b/agent/agent.c index 30a15a9..0810485 100644 --- a/agent/agent.c +++ b/agent/agent.c @@ -1787,12 +1787,13 @@ void agent_gathering_done (NiceAgent *agent) if (nice_debug_is_enabled ()) { gchar tmpbuf[INET6_ADDRSTRLEN]; nice_address_to_string (&local_candidate->addr, tmpbuf); - nice_debug ("Agent %p: gathered %s local candidate : [%s]:%u" - " for s%d/c%d. U/P '%s'/'%s'", agent, + nice_debug ("Agent %p: gathered %s local candidate: [%s]:%u" + " for s%d/c%d. U/P '%s'/'%s' prio: %u", agent, _transport_to_string (local_candidate->transport), tmpbuf, nice_address_get_port (&local_candidate->addr), local_candidate->stream_id, local_candidate->component_id, - local_candidate->username, local_candidate->password); + local_candidate->username, local_candidate->password, + local_candidate->priority); } for (l = component->remote_candidates; l; l = l->next) { NiceCandidate *remote_candidate = l->data; diff --git a/agent/discovery.c b/agent/discovery.c index f457edf..6bb777c 100644 --- a/agent/discovery.c +++ b/agent/discovery.c @@ -512,9 +512,11 @@ HostCandidateResult discovery_add_local_host_candidate ( if (transport == NICE_CANDIDATE_TRANSPORT_UDP) { nicesock = nice_udp_bsd_socket_new (address); } else if (transport == NICE_CANDIDATE_TRANSPORT_TCP_ACTIVE) { - nicesock = nice_tcp_active_socket_new (agent->main_context, address); + nicesock = nice_tcp_active_socket_new (agent->main_context, address, + agent->reliable); } else if (transport == NICE_CANDIDATE_TRANSPORT_TCP_PASSIVE) { - nicesock = nice_tcp_passive_socket_new (agent->main_context, address); + nicesock = nice_tcp_passive_socket_new (agent->main_context, address, + agent->reliable); } else { /* TODO: Add TCP-SO */ } diff --git a/socket/tcp-active.c b/socket/tcp-active.c index 374782c..643c70e 100644 --- a/socket/tcp-active.c +++ b/socket/tcp-active.c @@ -51,6 +51,7 @@ #endif typedef struct { + gboolean reliable; GSocketAddress *local_addr; GMainContext *context; } TcpActivePriv; @@ -70,7 +71,8 @@ static void socket_set_writable_callback (NiceSocket *sock, NiceSocket * -nice_tcp_active_socket_new (GMainContext *ctx, NiceAddress *addr) +nice_tcp_active_socket_new (GMainContext *ctx, NiceAddress *addr, + gboolean reliable) { union { struct sockaddr_storage storage; @@ -103,6 +105,7 @@ nice_tcp_active_socket_new (GMainContext *ctx, NiceAddress *addr) sock->priv = priv = g_slice_new0 (TcpActivePriv); + priv->reliable = reliable; priv->context = g_main_context_ref (ctx); priv->local_addr = gaddr; @@ -249,7 +252,7 @@ nice_tcp_active_socket_connect (NiceSocket *sock, NiceAddress *addr) nice_address_set_from_sockaddr (&local_addr, &name.addr); new_socket = nice_tcp_bsd_socket_new_from_gsock (priv->context, gsock, - &local_addr, addr, TRUE); + &local_addr, addr, priv->reliable); g_object_unref (gsock); return new_socket; diff --git a/socket/tcp-active.h b/socket/tcp-active.h index cf4a0d9..beba033 100644 --- a/socket/tcp-active.h +++ b/socket/tcp-active.h @@ -41,7 +41,8 @@ G_BEGIN_DECLS -NiceSocket * nice_tcp_active_socket_new (GMainContext *ctx, NiceAddress *addr); +NiceSocket * nice_tcp_active_socket_new (GMainContext *ctx, NiceAddress *addr, + gboolean reliable); NiceSocket * nice_tcp_active_socket_connect (NiceSocket *socket, NiceAddress *addr); diff --git a/socket/tcp-passive.c b/socket/tcp-passive.c index 2eb05dd..eeda236 100644 --- a/socket/tcp-passive.c +++ b/socket/tcp-passive.c @@ -51,6 +51,8 @@ #endif typedef struct { + gboolean reliable; + GMainContext *context; GHashTable *connections; NiceSocketWritableCb writable_cb; @@ -75,7 +77,8 @@ static void _set_child_callbacks (NiceAddress *addr, NiceSocket *child, NiceSocket *sock); NiceSocket * -nice_tcp_passive_socket_new (GMainContext *ctx, NiceAddress *addr) +nice_tcp_passive_socket_new (GMainContext *ctx, NiceAddress *addr, + gboolean reliable) { union { struct sockaddr_storage storage; @@ -149,6 +152,7 @@ nice_tcp_passive_socket_new (GMainContext *ctx, NiceAddress *addr) nice_address_set_from_sockaddr (&sock->addr, &name.addr); sock->priv = priv = g_slice_new0 (TcpPassivePriv); + priv->reliable = reliable; priv->context = g_main_context_ref (ctx); priv->connections = g_hash_table_new_full ((GHashFunc) nice_address_hash, (GEqualFunc) nice_address_equal, ( @@ -217,7 +221,9 @@ static gint socket_send_messages_reliable (NiceSocket *sock, static gboolean socket_is_reliable (NiceSocket *sock) { - return TRUE; + TcpPassivePriv *priv = sock->priv; + + return priv->reliable; } static gboolean diff --git a/socket/tcp-passive.h b/socket/tcp-passive.h index 37e780b..9be521d 100644 --- a/socket/tcp-passive.h +++ b/socket/tcp-passive.h @@ -43,7 +43,8 @@ G_BEGIN_DECLS -NiceSocket * nice_tcp_passive_socket_new (GMainContext *ctx, NiceAddress *addr); +NiceSocket * nice_tcp_passive_socket_new (GMainContext *ctx, NiceAddress *addr, + gboolean reliable); NiceSocket * nice_tcp_passive_socket_accept (NiceSocket *socket); diff --git a/tests/test-icetcp.c b/tests/test-icetcp.c index 8be28ba..649f7e4 100644 --- a/tests/test-icetcp.c +++ b/tests/test-icetcp.c @@ -391,13 +391,13 @@ int main (void) global_mainloop = g_main_loop_new (NULL, FALSE); /* step: create the agents L and R */ - lagent = nice_agent_new (g_main_loop_get_context (global_mainloop), + lagent = nice_agent_new_reliable (g_main_loop_get_context (global_mainloop), NICE_COMPATIBILITY_RFC5245); - ragent = nice_agent_new (g_main_loop_get_context (global_mainloop), + ragent = nice_agent_new_reliable (g_main_loop_get_context (global_mainloop), NICE_COMPATIBILITY_RFC5245); - g_object_set (G_OBJECT (lagent), "ice-udp", FALSE, NULL); - g_object_set (G_OBJECT (ragent), "ice-udp", FALSE, NULL); + g_object_set (G_OBJECT (lagent), "ice-udp", FALSE, NULL); + g_object_set (G_OBJECT (ragent), "ice-udp", FALSE, NULL); nice_agent_set_software (lagent, "Test-icetcp, Left Agent"); nice_agent_set_software (ragent, "Test-icetcp, Right Agent"); diff --git a/tests/test-tcp.c b/tests/test-tcp.c index dd259a4..8b5ca97 100644 --- a/tests/test-tcp.c +++ b/tests/test-tcp.c @@ -102,7 +102,7 @@ main (void) nice_address_init (&tmp); passive_sock = nice_tcp_passive_socket_new (g_main_loop_get_context (mainloop), - &passive_bind_addr); + &passive_bind_addr, TRUE); g_assert (passive_sock); srv_listen_source = g_socket_create_source (passive_sock->fileno, @@ -112,7 +112,7 @@ main (void) g_source_attach (srv_listen_source, g_main_loop_get_context (mainloop)); active_sock = nice_tcp_active_socket_new (g_main_loop_get_context (mainloop), - &active_bind_addr); + &active_bind_addr, TRUE); g_assert (active_sock); client = nice_tcp_active_socket_connect (active_sock, &passive_bind_addr); -- 2.7.4