Commit 7a16e23d authored by Youness Alaoui's avatar Youness Alaoui

Porting libnice to the new stun usage API. I know it's a big commit, but it...

Porting libnice to the new stun usage API. I know it's a big commit, but it can't be divided into smaller ones, it's all one big chunk
parent d691619e
This diff is collapsed.
...@@ -43,8 +43,8 @@ ...@@ -43,8 +43,8 @@
#include "agent.h" #include "agent.h"
#include "stream.h" #include "stream.h"
#include "stun/usages/stun-ice.h" #include "stun/stunagent.h"
#include "stun/usages/bind.h" #include "stun/usages/timer.h"
#define NICE_CANDIDATE_PAIR_MAX_FOUNDATION NICE_CANDIDATE_MAX_FOUNDATION*2 #define NICE_CANDIDATE_PAIR_MAX_FOUNDATION NICE_CANDIDATE_MAX_FOUNDATION*2
...@@ -75,7 +75,9 @@ struct _CandidateCheckPair ...@@ -75,7 +75,9 @@ struct _CandidateCheckPair
guint64 priority; guint64 priority;
GTimeVal next_tick; /* next tick timestamp */ GTimeVal next_tick; /* next tick timestamp */
gboolean traffic_after_tick; gboolean traffic_after_tick;
stun_bind_t *stun_ctx; stun_timer_t timer;
uint8_t stun_buffer[STUN_MAX_MESSAGE_SIZE];
StunMessage stun_message;
}; };
int conn_check_add_for_candidate (NiceAgent *agent, guint stream_id, Component *component, NiceCandidate *remote); int conn_check_add_for_candidate (NiceAgent *agent, guint stream_id, Component *component, NiceCandidate *remote);
......
...@@ -466,6 +466,7 @@ static gboolean priv_discovery_tick_unlocked (gpointer pointer) ...@@ -466,6 +466,7 @@ static gboolean priv_discovery_tick_unlocked (gpointer pointer)
NiceAgent *agent = pointer; NiceAgent *agent = pointer;
GSList *i; GSList *i;
int not_done = 0; /* note: track whether to continue timer */ int not_done = 0; /* note: track whether to continue timer */
size_t buffer_len;
#ifndef NDEBUG #ifndef NDEBUG
{ {
...@@ -490,7 +491,6 @@ static gboolean priv_discovery_tick_unlocked (gpointer pointer) ...@@ -490,7 +491,6 @@ static gboolean priv_discovery_tick_unlocked (gpointer pointer)
if (cand->type == NICE_CANDIDATE_TYPE_SERVER_REFLEXIVE && if (cand->type == NICE_CANDIDATE_TYPE_SERVER_REFLEXIVE &&
cand->server_addr) { cand->server_addr) {
NiceAddress stun_server; NiceAddress stun_server;
int res;
/* XXX FIXME TODO: handle error here?! Kai, help me! */ /* XXX FIXME TODO: handle error here?! Kai, help me! */
if (!nice_address_set_from_string (&stun_server, cand->server_addr)) if (!nice_address_set_from_string (&stun_server, cand->server_addr))
...@@ -502,18 +502,25 @@ static gboolean priv_discovery_tick_unlocked (gpointer pointer) ...@@ -502,18 +502,25 @@ static gboolean priv_discovery_tick_unlocked (gpointer pointer)
cand->component->id, cand->component->id,
NICE_COMPONENT_STATE_GATHERING); NICE_COMPONENT_STATE_GATHERING);
res = stun_bind_start (&cand->stun_ctx, cand->socket, buffer_len = stun_usage_bind_create (&agent->stun_agent,
&stun_server.s.addr, sizeof(stun_server.s), &cand->stun_message, cand->stun_buffer, sizeof(cand->stun_buffer));
agent->compatibility);
if (res == 0) {
if (buffer_len > 0) {
stun_timer_start (&cand->timer);
/* send the conncheck */
nice_udp_socket_send (cand->nicesock, &stun_server,
buffer_len, (gchar *)cand->stun_buffer);
/* case: success, start waiting for the result */ /* case: success, start waiting for the result */
g_get_current_time (&cand->next_tick); g_get_current_time (&cand->next_tick);
} } else {
else {
/* case: error in starting discovery, start the next discovery */ /* case: error in starting discovery, start the next discovery */
cand->done = TRUE; cand->done = TRUE;
cand->stun_ctx = NULL; cand->stun_message.buffer = NULL;
cand->stun_message.buffer_len = 0;
continue; continue;
} }
} }
...@@ -529,27 +536,44 @@ static gboolean priv_discovery_tick_unlocked (gpointer pointer) ...@@ -529,27 +536,44 @@ static gboolean priv_discovery_tick_unlocked (gpointer pointer)
g_get_current_time (&now); g_get_current_time (&now);
if (cand->stun_ctx == NULL) { if (cand->stun_message.buffer == NULL) {
g_debug ("Agent %p : STUN discovery was cancelled, marking discovery done.", agent); g_debug ("Agent %p : STUN discovery was cancelled, marking discovery done.", agent);
cand->done = TRUE; cand->done = TRUE;
} }
else if (priv_timer_expired (&cand->next_tick, &now)) { else if (priv_timer_expired (&cand->next_tick, &now)) {
int res = stun_bind_elapse (cand->stun_ctx); switch (stun_timer_refresh (&cand->timer)) {
if (res == EAGAIN) { case -1:
/* case: error, abort processing */
cand->done = TRUE;
cand->stun_message.buffer = NULL;
cand->stun_message.buffer_len = 0;
g_debug ("Agent %p : Error with stun_bind_elapse(), aborting discovery item.", agent);
break;
case 0:
{
/* case: not ready complete, so schedule next timeout */ /* case: not ready complete, so schedule next timeout */
unsigned int timeout = stun_bind_timeout (cand->stun_ctx); unsigned int timeout = stun_timer_remainder (&cand->timer);
NiceAddress stun_server;
if (!nice_address_set_from_string (&stun_server, cand->server_addr))
g_assert_not_reached();
nice_address_set_port (&stun_server, cand->server_port);
stun_debug ("STUN transaction retransmitted (timeout %dms).\n",
timeout);
/* TODO retransmit */
nice_udp_socket_send (cand->nicesock, &stun_server,
stun_message_length (&cand->stun_message),
(gchar *)cand->stun_buffer);
/* note: convert from milli to microseconds for g_time_val_add() */ /* note: convert from milli to microseconds for g_time_val_add() */
cand->next_tick = now; cand->next_tick = now;
g_time_val_add (&cand->next_tick, timeout * 1000); g_time_val_add (&cand->next_tick, timeout * 1000);
++not_done; /* note: retry later */ ++not_done; /* note: retry later */
break;
} }
else {
/* case: error, abort processing */
cand->done = TRUE;
cand->stun_ctx = NULL;
g_debug ("Agent %p : Error with stun_bind_elapse(), aborting discovery item.", agent);
} }
} }
......
...@@ -53,12 +53,14 @@ struct _CandidateDiscovery ...@@ -53,12 +53,14 @@ struct _CandidateDiscovery
const gchar *server_addr; /**< STUN/TURN server address, not owned */ const gchar *server_addr; /**< STUN/TURN server address, not owned */
guint server_port; /**< STUN/TURN server port */ guint server_port; /**< STUN/TURN server port */
NiceAddress *interface; /**< Address of local interface */ NiceAddress *interface; /**< Address of local interface */
stun_bind_t *stun_ctx;
GTimeVal next_tick; /**< next tick timestamp */ GTimeVal next_tick; /**< next tick timestamp */
gboolean pending; /**< is discovery in progress? */ gboolean pending; /**< is discovery in progress? */
gboolean done; /**< is discovery complete? */ gboolean done; /**< is discovery complete? */
Stream *stream; Stream *stream;
Component *component; Component *component;
stun_timer_t timer;
uint8_t stun_buffer[STUN_MAX_MESSAGE_SIZE];
StunMessage stun_message;
}; };
void discovery_free_item (gpointer data, gpointer user_data); void discovery_free_item (gpointer data, gpointer user_data);
......
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