Commit 675487c9 authored by Youness Alaoui's avatar Youness Alaoui

(WIP) Ported libnice to the new API...

parent 8febb558
...@@ -72,8 +72,8 @@ check_PROGRAMS = \ ...@@ -72,8 +72,8 @@ check_PROGRAMS = \
test-mainloop \ test-mainloop \
test-fullmode \ test-fullmode \
test-restart \ test-restart \
test-fallback \ test-fallback
test-thread # test-thread
dist_check_SCRIPTS = \ dist_check_SCRIPTS = \
check-test-fullmode-with-stun.sh check-test-fullmode-with-stun.sh
......
...@@ -48,6 +48,7 @@ ...@@ -48,6 +48,7 @@
#include "stream.h" #include "stream.h"
#include "conncheck.h" #include "conncheck.h"
#include "component.h" #include "component.h"
#include "stun/stunagent.h"
/* XXX: starting from ICE ID-18, Ta SHOULD now be set according /* XXX: starting from ICE ID-18, Ta SHOULD now be set according
* to session bandwidth -> this is not yet implemented in NICE */ * to session bandwidth -> this is not yet implemented in NICE */
...@@ -93,6 +94,7 @@ struct _NiceAgent ...@@ -93,6 +94,7 @@ struct _NiceAgent
"Determining Role" ID-19) */ "Determining Role" ID-19) */
GStaticRecMutex mutex; /* Mutex used for thread-safe lib */ GStaticRecMutex mutex; /* Mutex used for thread-safe lib */
NiceCompatibility compatibility; /* property: Compatibility mode */ NiceCompatibility compatibility; /* property: Compatibility mode */
StunAgent stun_agent; /* STUN agent */
/* XXX: add pointer to internal data struct for ABI-safe extensions */ /* XXX: add pointer to internal data struct for ABI-safe extensions */
}; };
......
...@@ -399,6 +399,11 @@ nice_agent_init (NiceAgent *agent) ...@@ -399,6 +399,11 @@ nice_agent_init (NiceAgent *agent)
agent->keepalive_timer_id = 0; agent->keepalive_timer_id = 0;
agent->compatibility = NICE_COMPATIBILITY_ID19; agent->compatibility = NICE_COMPATIBILITY_ID19;
stun_agent_init (&agent->stun_agent, STUN_ALL_KNOWN_ATTRIBUTES,
STUN_COMPATIBILITY_3489BIS,
STUN_AGENT_USAGE_SHORT_TERM_CREDENTIALS |
STUN_AGENT_USAGE_USE_FINGERPRINT);
agent->rng = nice_rng_new (); agent->rng = nice_rng_new ();
priv_generate_tie_breaker (agent); priv_generate_tie_breaker (agent);
...@@ -517,6 +522,18 @@ nice_agent_set_property ( ...@@ -517,6 +522,18 @@ nice_agent_set_property (
case PROP_COMPATIBILITY: case PROP_COMPATIBILITY:
agent->compatibility = g_value_get_uint (value); agent->compatibility = g_value_get_uint (value);
if (agent->compatibility == NICE_COMPATIBILITY_ID19) {
stun_agent_init (&agent->stun_agent, STUN_ALL_KNOWN_ATTRIBUTES,
STUN_COMPATIBILITY_3489BIS,
STUN_AGENT_USAGE_SHORT_TERM_CREDENTIALS |
STUN_AGENT_USAGE_USE_FINGERPRINT);
} else if (agent->compatibility == NICE_COMPATIBILITY_GOOGLE) {
stun_agent_init (&agent->stun_agent, STUN_ALL_KNOWN_ATTRIBUTES,
STUN_COMPATIBILITY_RFC3489,
STUN_AGENT_USAGE_SHORT_TERM_CREDENTIALS |
STUN_AGENT_USAGE_IGNORE_CREDENTIALS);
}
break; break;
case PROP_STUN_SERVER: case PROP_STUN_SERVER:
...@@ -1260,7 +1277,7 @@ _nice_agent_recv ( ...@@ -1260,7 +1277,7 @@ _nice_agent_recv (
} }
/* step: validate using the new STUN API */ /* step: validate using the new STUN API */
/* - note: old check '((buf[0] & 0xc0) == 0)' */ /* - note: old check '((buf[0] & 0xc0) == 0)' */
else if (stun_validate ((uint8_t*)buf, len) > 0) { else if (stun_message_validate_buffer_length ((uint8_t *) buf, (size_t) len) == len) {
/* If the retval is no 0, its not a valid stun packet, probably data */ /* If the retval is no 0, its not a valid stun packet, probably data */
conn_check_handle_inbound_stun (agent, stream, component, udp_socket, conn_check_handle_inbound_stun (agent, stream, component, udp_socket,
&from, buf, len); &from, buf, len);
......
...@@ -46,6 +46,7 @@ ...@@ -46,6 +46,7 @@
#include "candidate.h" #include "candidate.h"
#include "random.h" #include "random.h"
G_BEGIN_DECLS G_BEGIN_DECLS
#define NICE_TYPE_AGENT nice_agent_get_type() #define NICE_TYPE_AGENT nice_agent_get_type()
......
...@@ -1564,6 +1564,8 @@ gboolean conn_check_handle_inbound_stun (NiceAgent *agent, Stream *stream, Compo ...@@ -1564,6 +1564,8 @@ gboolean conn_check_handle_inbound_stun (NiceAgent *agent, Stream *stream, Compo
size_t rbuf_len = sizeof (rbuf); size_t rbuf_len = sizeof (rbuf);
bool control = agent->controlling_mode; bool control = agent->controlling_mode;
gchar uname[NICE_STREAM_MAX_UNAME]; gchar uname[NICE_STREAM_MAX_UNAME];
StunMessage req;
StunMessage msg;
nice_address_copy_to_sockaddr (from, &sockaddr); nice_address_copy_to_sockaddr (from, &sockaddr);
g_snprintf (uname, sizeof (uname), "%s:%s", stream->local_ufrag, g_snprintf (uname, sizeof (uname), "%s:%s", stream->local_ufrag,
...@@ -1576,9 +1578,10 @@ gboolean conn_check_handle_inbound_stun (NiceAgent *agent, Stream *stream, Compo ...@@ -1576,9 +1578,10 @@ gboolean conn_check_handle_inbound_stun (NiceAgent *agent, Stream *stream, Compo
/* note: ICE 7.2. "STUN Server Procedures" (ID-19) */ /* note: ICE 7.2. "STUN Server Procedures" (ID-19) */
res = stun_conncheck_reply (rbuf, &rbuf_len, (const uint8_t*)buf, &sockaddr, sizeof (sockaddr), res = stun_conncheck_reply (&agent->stun_agent, &req, (uint8_t *)buf, (size_t) len, &msg, rbuf, &rbuf_len,
stream->local_ufrag, stream->local_password, &sockaddr, sizeof (sockaddr), (uint8_t *) stream->local_ufrag, strlen (stream->local_ufrag),
&control, agent->tie_breaker, agent->compatibility); (uint8_t *)stream->local_password, strlen (stream->local_password),
&control, agent->tie_breaker, agent->compatibility);
if (res == EACCES) if (res == EACCES)
priv_check_for_role_conflict (agent, control); priv_check_for_role_conflict (agent, control);
...@@ -1588,8 +1591,8 @@ gboolean conn_check_handle_inbound_stun (NiceAgent *agent, Stream *stream, Compo ...@@ -1588,8 +1591,8 @@ gboolean conn_check_handle_inbound_stun (NiceAgent *agent, Stream *stream, Compo
GSList *i; GSList *i;
bool use_candidate = bool use_candidate =
stun_conncheck_use_candidate ((const uint8_t*)buf); stun_conncheck_use_candidate (&req);
uint32_t priority = stun_conncheck_priority ((const uint8_t*)buf); uint32_t priority = stun_conncheck_priority (&req);
if (agent->controlling_mode || if (agent->controlling_mode ||
agent->compatibility == NICE_COMPATIBILITY_GOOGLE) agent->compatibility == NICE_COMPATIBILITY_GOOGLE)
......
...@@ -43,7 +43,8 @@ ...@@ -43,7 +43,8 @@
#include "agent.h" #include "agent.h"
#include "stream.h" #include "stream.h"
#include "usages/stun-ice.h" /* note: the new STUN API */ #include "stun/usages/stun-ice.h"
#include "stun/usages/bind.h"
#define NICE_CANDIDATE_PAIR_MAX_FOUNDATION NICE_CANDIDATE_MAX_FOUNDATION*2 #define NICE_CANDIDATE_PAIR_MAX_FOUNDATION NICE_CANDIDATE_MAX_FOUNDATION*2
......
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