Commit cbcff613 authored by Kai Vehmanen's avatar Kai Vehmanen

Added support for forcing selection of a candidate pair. This allows to...

Added support for forcing selection of a candidate pair. This allows to interoperate with clients that do not support ICE. Added a unit test for fallback functionality. Some 64bit compilation fixes included.

darcs-hash:20070830070718-77cd4-02e9764b213673506df7d71ec768e42a29bb09dd.gz
parent bd46f868
...@@ -65,7 +65,8 @@ check_PROGRAMS = \ ...@@ -65,7 +65,8 @@ check_PROGRAMS = \
test-poll \ test-poll \
test-mainloop \ test-mainloop \
test-fullmode \ test-fullmode \
test-restart test-restart \
test-fallback
check_SCRIPTS = \ check_SCRIPTS = \
check-test-fullmode-with-stun.sh check-test-fullmode-with-stun.sh
......
...@@ -126,6 +126,6 @@ void agent_signal_new_remote_candidate (NiceAgent *agent, NiceCandidate *candida ...@@ -126,6 +126,6 @@ void agent_signal_new_remote_candidate (NiceAgent *agent, NiceCandidate *candida
void agent_signal_initial_binding_request_received (NiceAgent *agent, Stream *stream); void agent_signal_initial_binding_request_received (NiceAgent *agent, Stream *stream);
void agent_free_discovery_candidate_udp (gpointer data, gpointer user_data); guint64 agent_candidate_pair_priority (NiceAgent *agent, NiceCandidate *local, NiceCandidate *remote);
#endif /*_NICE_AGENT_PRIV_H */ #endif /*_NICE_AGENT_PRIV_H */
...@@ -528,6 +528,15 @@ void agent_signal_component_state_change (NiceAgent *agent, guint stream_id, gui ...@@ -528,6 +528,15 @@ void agent_signal_component_state_change (NiceAgent *agent, guint stream_id, gui
} }
} }
guint64
agent_candidate_pair_priority (NiceAgent *agent, NiceCandidate *local, NiceCandidate *remote)
{
if (agent->controlling_mode == TRUE)
return nice_candidate_pair_priority (local->priority, remote->priority);
return nice_candidate_pair_priority (remote->priority, local->priority);
}
static gboolean static gboolean
priv_add_srv_rfx_candidate_discovery (NiceAgent *agent, NiceCandidate *host_candidate, const gchar *stun_server_ip, const guint stun_server_port, Stream *stream, guint component_id, NiceAddress *addr) priv_add_srv_rfx_candidate_discovery (NiceAgent *agent, NiceCandidate *host_candidate, const gchar *stun_server_ip, const guint stun_server_port, Stream *stream, guint component_id, NiceAddress *addr)
{ {
...@@ -998,7 +1007,8 @@ _nice_agent_recv ( ...@@ -998,7 +1007,8 @@ _nice_agent_recv (
if (len >= 0) { if (len >= 0) {
gchar tmpbuf[INET6_ADDRSTRLEN]; gchar tmpbuf[INET6_ADDRSTRLEN];
nice_address_to_string (&from, tmpbuf); nice_address_to_string (&from, tmpbuf);
g_debug ("Packet received on local socket %u from %s:%u (%u octets).", udp_socket->fileno, tmpbuf, from.port, len); g_debug ("Packet received on local socket %u from [%s]:%u (%u octets).",
udp_socket->fileno, tmpbuf, nice_address_get_port (&from), len);
} }
#endif #endif
...@@ -1596,3 +1606,41 @@ nice_agent_main_context_attach ( ...@@ -1596,3 +1606,41 @@ nice_agent_main_context_attach (
return TRUE; return TRUE;
} }
/**
* Sets the selected candidate pair for media transmission
* for given stream component. Calling this function will
* disable all further ICE processing (connection check,
* state machine updates, etc). Note that keepalives will
* continue to be sent.
*/
NICEAPI_EXPORT gboolean
nice_agent_set_selected_pair (
NiceAgent *agent,
guint stream_id,
guint component_id,
const gchar *lfoundation,
const gchar *rfoundation)
{
Component *component;
CandidatePair pair;
/* step: check that params specify an existing pair */
if (!agent_find_component (agent, stream_id, component_id, NULL, &component))
return FALSE;
if (!component_find_pair (component, agent, lfoundation, rfoundation, &pair))
return FALSE;
/* step: stop connectivity checks (note: for the whole stream) */
conn_check_prune_stream (agent, stream_id);
/* step: change component state */
agent_signal_component_state_change (agent, stream_id, component_id, NICE_COMPONENT_STATE_READY);
/* step: set the selected pair */
component_update_selected_pair (component, &pair);
agent_signal_new_selected_pair (agent, stream_id, component_id, lfoundation, rfoundation);
return TRUE;
}
...@@ -224,6 +224,14 @@ nice_agent_main_context_attach ( ...@@ -224,6 +224,14 @@ nice_agent_main_context_attach (
NiceAgentRecvFunc func, NiceAgentRecvFunc func,
gpointer data); gpointer data);
gboolean
nice_agent_set_selected_pair (
NiceAgent *agent,
guint stream_id,
guint component_id,
const gchar *lfoundation,
const gchar *rfoundation);
G_END_DECLS G_END_DECLS
#endif /* _AGENT_H */ #endif /* _AGENT_H */
......
...@@ -45,7 +45,10 @@ ...@@ -45,7 +45,10 @@
# include <config.h> # include <config.h>
#endif #endif
#include <string.h>
#include "component.h" #include "component.h"
#include "agent-priv.h"
Component * Component *
component_new ( component_new (
...@@ -126,6 +129,43 @@ component_find_udp_socket_by_fd (Component *component, guint fd) ...@@ -126,6 +129,43 @@ component_find_udp_socket_by_fd (Component *component, guint fd)
return NULL; return NULL;
} }
/**
* Finds a candidate pair that has matching foundation ids.
*
* @return TRUE if pair found, pointer to pair stored at 'pair'
*/
gboolean
component_find_pair (Component *cmp, NiceAgent *agent, const gchar *lfoundation, const gchar *rfoundation, CandidatePair *pair)
{
GSList *i;
CandidatePair result = { NULL, NULL, 0 };
for (i = cmp->local_candidates; i; i = i->next) {
NiceCandidate *candidate = i->data;
if (strncmp (candidate->foundation, lfoundation, NICE_CANDIDATE_MAX_FOUNDATION) == 0) {
result.local = candidate;
break;
}
}
for (i = cmp->remote_candidates; i; i = i->next) {
NiceCandidate *candidate = i->data;
if (strncmp (candidate->foundation, rfoundation, NICE_CANDIDATE_MAX_FOUNDATION) == 0) {
result.remote = candidate;
break;
}
}
if (result.local && result.remote) {
result.priority = agent_candidate_pair_priority (agent, result.local, result.remote);
if (pair)
*pair = result;
return TRUE;
}
return FALSE;
}
/** /**
* Resets the component state to that of a ICE restarted * Resets the component state to that of a ICE restarted
* session. * session.
...@@ -156,3 +196,18 @@ component_restart (Component *cmp) ...@@ -156,3 +196,18 @@ component_restart (Component *cmp)
return TRUE; return TRUE;
} }
/**
* Changes the selected pair for the component to 'pair'. Does not
* emit the "selected-pair-changed" signal.
*/
void component_update_selected_pair (Component *component, const CandidatePair *pair)
{
g_assert (component);
g_assert (pair);
g_debug ("setting SELECTED PAIR for component %u: %s:%s (prio:%lu).",
component->id, pair->local->foundation, pair->remote->foundation, (long unsigned)pair->priority);
component->selected_pair.local = pair->local;
component->selected_pair.remote = pair->remote;
component->selected_pair.priority = pair->priority;
}
...@@ -65,7 +65,7 @@ struct _CandidatePair ...@@ -65,7 +65,7 @@ struct _CandidatePair
struct _Component struct _Component
{ {
NiceComponentType type; NiceComponentType type;
guint id; guint id; /**< component id */
NiceComponentState state; NiceComponentState state;
GSList *local_candidates; /**< list of Candidate objs */ GSList *local_candidates; /**< list of Candidate objs */
GSList *remote_candidates; /**< list of Candidate objs */ GSList *remote_candidates; /**< list of Candidate objs */
...@@ -89,9 +89,15 @@ component_free (Component *cmp); ...@@ -89,9 +89,15 @@ component_free (Component *cmp);
NiceUDPSocket * NiceUDPSocket *
component_find_udp_socket_by_fd (Component *component, guint fd); component_find_udp_socket_by_fd (Component *component, guint fd);
gboolean
component_find_pair (Component *cmp, NiceAgent *agent, const gchar *lfoundation, const gchar *rfoundation, CandidatePair *pair);
gboolean gboolean
component_restart (Component *cmp); component_restart (Component *cmp);
void
component_update_selected_pair (Component *component, const CandidatePair *pair);
G_END_DECLS G_END_DECLS
#endif /* _NICE_COMPONENT_H */ #endif /* _NICE_COMPONENT_H */
......
...@@ -95,7 +95,7 @@ static gboolean priv_conn_check_initiate (NiceAgent *agent, CandidateCheckPair * ...@@ -95,7 +95,7 @@ static gboolean priv_conn_check_initiate (NiceAgent *agent, CandidateCheckPair *
* see "7.2.1.4 Triggered Checks" * see "7.2.1.4 Triggered Checks"
*/ */
g_get_current_time (&pair->next_tick); g_get_current_time (&pair->next_tick);
g_time_val_add (&pair->next_tick, agent->timer_ta * 10); g_time_val_add (&pair->next_tick, agent->timer_ta * 1000);
pair->state = NICE_CHECK_IN_PROGRESS; pair->state = NICE_CHECK_IN_PROGRESS;
conn_check_send (agent, pair); conn_check_send (agent, pair);
return TRUE; return TRUE;
...@@ -118,7 +118,6 @@ static gboolean priv_conn_check_unfreeze_next (NiceAgent *agent, GSList *connche ...@@ -118,7 +118,6 @@ static gboolean priv_conn_check_unfreeze_next (NiceAgent *agent, GSList *connche
GSList *i; GSList *i;
guint c; guint c;
guint max_components = 0; guint max_components = 0;
gboolean frozen = FALSE;
/* step: calculate the max number of components across streams */ /* step: calculate the max number of components across streams */
for (i = agent->streams; i; i = i->next) { for (i = agent->streams; i; i = i->next) {
...@@ -142,7 +141,6 @@ static gboolean priv_conn_check_unfreeze_next (NiceAgent *agent, GSList *connche ...@@ -142,7 +141,6 @@ static gboolean priv_conn_check_unfreeze_next (NiceAgent *agent, GSList *connche
CandidateCheckPair *p = i->data; CandidateCheckPair *p = i->data;
if (p->component_id == c + 1) { if (p->component_id == c + 1) {
if (p->state == NICE_CHECK_FROZEN) { if (p->state == NICE_CHECK_FROZEN) {
frozen = TRUE;
if (p->priority > max_frozen_priority) { if (p->priority > max_frozen_priority) {
max_frozen_priority = p->priority; max_frozen_priority = p->priority;
pair = p; pair = p;
...@@ -255,7 +253,6 @@ static gboolean priv_conn_check_tick (gpointer pointer) ...@@ -255,7 +253,6 @@ static gboolean priv_conn_check_tick (gpointer pointer)
CandidateCheckPair *p = i->data; CandidateCheckPair *p = i->data;
if (p->state == NICE_CHECK_IN_PROGRESS) { if (p->state == NICE_CHECK_IN_PROGRESS) {
/* note: macro from sys/time.h but compatible with GTimeVal */
if (p->stun_ctx == NULL) { if (p->stun_ctx == NULL) {
g_debug ("STUN connectivity check was cancelled, marking as done."); g_debug ("STUN connectivity check was cancelled, marking as done.");
p->state = NICE_CHECK_FAILED; p->state = NICE_CHECK_FAILED;
...@@ -267,8 +264,8 @@ static gboolean priv_conn_check_tick (gpointer pointer) ...@@ -267,8 +264,8 @@ static gboolean priv_conn_check_tick (gpointer pointer)
unsigned int timeout = stun_bind_timeout (p->stun_ctx); unsigned int timeout = stun_bind_timeout (p->stun_ctx);
/* note: convert from milli to microseconds for g_time_val_add() */ /* note: convert from milli to microseconds for g_time_val_add() */
g_get_current_time (&p->next_tick); p->next_tick = now;
g_time_val_add (&p->next_tick, timeout * 10); g_time_val_add (&p->next_tick, timeout * 1000);
keep_timer_going = TRUE; keep_timer_going = TRUE;
p->traffic_after_tick = TRUE; /* for keepalive timer */ p->traffic_after_tick = TRUE; /* for keepalive timer */
...@@ -469,10 +466,7 @@ static gboolean priv_add_new_check_pair (NiceAgent *agent, guint stream_id, Comp ...@@ -469,10 +466,7 @@ static gboolean priv_add_new_check_pair (NiceAgent *agent, guint stream_id, Comp
pair->remote = remote; pair->remote = remote;
g_snprintf (pair->foundation, NICE_CANDIDATE_PAIR_MAX_FOUNDATION, "%s:%s", local->foundation, remote->foundation); g_snprintf (pair->foundation, NICE_CANDIDATE_PAIR_MAX_FOUNDATION, "%s:%s", local->foundation, remote->foundation);
if (agent->controlling_mode == TRUE) pair->priority = agent_candidate_pair_priority (agent, local, remote);
pair->priority = nice_candidate_pair_priority (local->priority, remote->priority);
else
pair->priority = nice_candidate_pair_priority (remote->priority, local->priority);
pair->state = initial_state; pair->state = initial_state;
pair->nominated = use_candidate; pair->nominated = use_candidate;
pair->controlling = agent->controlling_mode; pair->controlling = agent->controlling_mode;
...@@ -736,7 +730,7 @@ int conn_check_send (NiceAgent *agent, CandidateCheckPair *pair) ...@@ -736,7 +730,7 @@ int conn_check_send (NiceAgent *agent, CandidateCheckPair *pair)
timeout = stun_bind_timeout (pair->stun_ctx); timeout = stun_bind_timeout (pair->stun_ctx);
/* note: convert from milli to microseconds for g_time_val_add() */ /* note: convert from milli to microseconds for g_time_val_add() */
g_get_current_time (&pair->next_tick); g_get_current_time (&pair->next_tick);
g_time_val_add (&pair->next_tick, timeout * 10); g_time_val_add (&pair->next_tick, timeout * 1000);
pair->traffic_after_tick = TRUE; /* for keepalive timer */ pair->traffic_after_tick = TRUE; /* for keepalive timer */
} }
...@@ -891,6 +885,7 @@ static gboolean priv_update_selected_pair (NiceAgent *agent, Component *componen ...@@ -891,6 +885,7 @@ static gboolean priv_update_selected_pair (NiceAgent *agent, Component *componen
static gboolean priv_schedule_triggered_check (NiceAgent *agent, Stream *stream, Component *component, NiceUDPSocket *local_socket, NiceCandidate *remote_cand, gboolean use_candidate) static gboolean priv_schedule_triggered_check (NiceAgent *agent, Stream *stream, Component *component, NiceUDPSocket *local_socket, NiceCandidate *remote_cand, gboolean use_candidate)
{ {
GSList *i; GSList *i;
gboolean result = FALSE;
for (i = agent->conncheck_list; i ; i = i->next) { for (i = agent->conncheck_list; i ; i = i->next) {
CandidateCheckPair *p = i->data; CandidateCheckPair *p = i->data;
...@@ -931,7 +926,6 @@ static gboolean priv_schedule_triggered_check (NiceAgent *agent, Stream *stream, ...@@ -931,7 +926,6 @@ static gboolean priv_schedule_triggered_check (NiceAgent *agent, Stream *stream,
} }
{ {
gboolean result = FALSE;
NiceCandidate *local = NULL; NiceCandidate *local = NULL;
for (i = component->local_candidates; i ; i = i->next) { for (i = component->local_candidates; i ; i = i->next) {
...@@ -947,7 +941,7 @@ static gboolean priv_schedule_triggered_check (NiceAgent *agent, Stream *stream, ...@@ -947,7 +941,7 @@ static gboolean priv_schedule_triggered_check (NiceAgent *agent, Stream *stream,
g_debug ("Didn't find a matching pair for triggered check (remote-cand=%p).", remote_cand); g_debug ("Didn't find a matching pair for triggered check (remote-cand=%p).", remote_cand);
} }
return FALSE; return result;
} }
/** /**
...@@ -993,7 +987,7 @@ static void priv_reply_to_conn_check (NiceAgent *agent, Stream *stream, Componen ...@@ -993,7 +987,7 @@ static void priv_reply_to_conn_check (NiceAgent *agent, Stream *stream, Componen
tmpbuf, tmpbuf,
nice_address_get_port (&cand->addr), nice_address_get_port (&cand->addr),
udp_socket->fileno, udp_socket->fileno,
rbuf_len, (unsigned)rbuf_len,
cand, component->id, cand, component->id,
(int)use_candidate); (int)use_candidate);
} }
...@@ -1030,9 +1024,9 @@ static CandidateCheckPair *priv_add_peer_reflexive_pair (NiceAgent *agent, guint ...@@ -1030,9 +1024,9 @@ static CandidateCheckPair *priv_add_peer_reflexive_pair (NiceAgent *agent, guint
pair->state = NICE_CHECK_DISCOVERED; pair->state = NICE_CHECK_DISCOVERED;
g_snprintf (pair->foundation, NICE_CANDIDATE_PAIR_MAX_FOUNDATION, "%s:%s", local_cand->foundation, parent_pair->remote->foundation); g_snprintf (pair->foundation, NICE_CANDIDATE_PAIR_MAX_FOUNDATION, "%s:%s", local_cand->foundation, parent_pair->remote->foundation);
if (agent->controlling_mode == TRUE) if (agent->controlling_mode == TRUE)
pair->priority = nice_candidate_pair_priority (local_cand->priority, parent_pair->remote->priority); pair->priority = nice_candidate_pair_priority (local_cand->priority, parent_pair->priority);
else else
pair->priority = nice_candidate_pair_priority (parent_pair->remote->priority, local_cand->priority); pair->priority = nice_candidate_pair_priority (parent_pair->priority, local_cand->priority);
pair->nominated = FALSE; pair->nominated = FALSE;
pair->controlling = agent->controlling_mode; pair->controlling = agent->controlling_mode;
g_debug ("added a new peer-discovered pair with foundation of '%s'.", pair->foundation); g_debug ("added a new peer-discovered pair with foundation of '%s'.", pair->foundation);
...@@ -1053,10 +1047,7 @@ static void priv_recalculate_pair_priorities (NiceAgent *agent) ...@@ -1053,10 +1047,7 @@ static void priv_recalculate_pair_priorities (NiceAgent *agent)
for (i = agent->conncheck_list; i; i = i->next) { for (i = agent->conncheck_list; i; i = i->next) {
CandidateCheckPair *p = i->data; CandidateCheckPair *p = i->data;
if (agent->controlling_mode == TRUE) p->priority = agent_candidate_pair_priority (agent, p->local, p->remote);
p->priority = nice_candidate_pair_priority (p->local->priority, p->remote->priority);
else
p->priority = nice_candidate_pair_priority (p->remote->priority, p->local->priority);
} }
} }
...@@ -1098,7 +1089,7 @@ static gboolean priv_map_reply_to_conn_check_request (NiceAgent *agent, Stream * ...@@ -1098,7 +1089,7 @@ static gboolean priv_map_reply_to_conn_check_request (NiceAgent *agent, Stream *
CandidateCheckPair *p = i->data; CandidateCheckPair *p = i->data;
if (p->stun_ctx) { if (p->stun_ctx) {
res = stun_bind_process (p->stun_ctx, buf, len, &sockaddr, &socklen); res = stun_bind_process (p->stun_ctx, buf, len, &sockaddr, &socklen);
g_debug ("stun_bind_process/conncheck for %p res %d (%s) (controlling=%d).", p, res, strerror (res), agent->controlling_mode); g_debug ("stun_bind_process/conncheck for %p res %d (%s) (controlling=%d).", p, (int)res, strerror (res), agent->controlling_mode);
if (res == 0) { if (res == 0) {
/* case: found a matching connectivity check request */ /* case: found a matching connectivity check request */
...@@ -1224,7 +1215,8 @@ static gboolean priv_map_reply_to_discovery_request (NiceAgent *agent, gchar *bu ...@@ -1224,7 +1215,8 @@ static gboolean priv_map_reply_to_discovery_request (NiceAgent *agent, gchar *bu
CandidateDiscovery *d = i->data; CandidateDiscovery *d = i->data;
if (d->stun_ctx) { if (d->stun_ctx) {
res = stun_bind_process (d->stun_ctx, buf, len, &sockaddr, &socklen); res = stun_bind_process (d->stun_ctx, buf, len, &sockaddr, &socklen);
g_debug ("stun_bind_process/disc for %p res %d (%s).", d, res, strerror (res)); g_debug ("stun_bind_process/disc for %p res %d (%s).", d, (int)res,
strerror (res));
if (res == 0) { if (res == 0) {
/* case: succesful binding discovery, create a new local candidate */ /* case: succesful binding discovery, create a new local candidate */
NiceAddress niceaddr; NiceAddress niceaddr;
......
...@@ -172,19 +172,24 @@ static gboolean priv_add_local_candidate_pruned (Component *component, NiceCandi ...@@ -172,19 +172,24 @@ static gboolean priv_add_local_candidate_pruned (Component *component, NiceCandi
* Implements the mechanism described in ICE sect * Implements the mechanism described in ICE sect
* 4.1.1.4 "Computing Foundations" (ID-17). * 4.1.1.4 "Computing Foundations" (ID-17).
*/ */
static void priv_assign_foundation (NiceAgent *agent, Component *component, NiceCandidate *candidate) static void priv_assign_foundation (NiceAgent *agent, NiceCandidate *candidate)
{ {
GSList *i; GSList *i, *j, *k;
for (i = component->local_candidates; i; i = i->next) { for (i = agent->streams; i; i = i->next) {
NiceCandidate *n = i->data; Stream *stream = i->data;
for (j = stream->components; j; j = j->next) {
Component *component = j->data;
for (k = component->local_candidates; k; k = k->next) {
NiceCandidate *n = k->data;
NiceAddress temp = n->base_addr; NiceAddress temp = n->base_addr;
/* note: ports are not be compared */ /* note: ports are not be compared */
temp.port = candidate->base_addr.port; nice_address_set_port (&temp,
nice_address_get_port (&candidate->base_addr));
if (candidate->type == n->type && if (candidate->type == n->type &&
nice_address_equal (&candidate->base_addr, &n->base_addr)) { nice_address_equal (&candidate->base_addr, &temp)) {
/* note: currently only one STUN/TURN server per stream at a /* note: currently only one STUN/TURN server per stream at a
* time is supported, so there is no need to check * time is supported, so there is no need to check
* for candidates that would otherwise share the * for candidates that would otherwise share the
...@@ -193,6 +198,8 @@ static void priv_assign_foundation (NiceAgent *agent, Component *component, Nice ...@@ -193,6 +198,8 @@ static void priv_assign_foundation (NiceAgent *agent, Component *component, Nice
return; return;
} }
} }
}
}
g_snprintf (candidate->foundation, NICE_CANDIDATE_MAX_FOUNDATION, "%u", agent->next_candidate_id++); g_snprintf (candidate->foundation, NICE_CANDIDATE_MAX_FOUNDATION, "%u", agent->next_candidate_id++);
} }
...@@ -222,13 +229,14 @@ NiceCandidate *discovery_add_local_host_candidate ( ...@@ -222,13 +229,14 @@ NiceCandidate *discovery_add_local_host_candidate (
if (candidate) { if (candidate) {
NiceUDPSocket *udp_socket = g_slice_new0 (NiceUDPSocket); NiceUDPSocket *udp_socket = g_slice_new0 (NiceUDPSocket);
if (udp_socket) { if (udp_socket) {
priv_assign_foundation (agent, component, candidate);
candidate->stream_id = stream_id; candidate->stream_id = stream_id;
candidate->component_id = component_id; candidate->component_id = component_id;
candidate->addr = *address; candidate->addr = *address;
candidate->base_addr = *address; candidate->base_addr = *address;
candidate->priority = nice_candidate_ice_priority (candidate); candidate->priority = nice_candidate_ice_priority (candidate);
priv_assign_foundation (agent, candidate);
/* note: candidate username and password are left NULL as stream /* note: candidate username and password are left NULL as stream
level ufrag/password are used */ level ufrag/password are used */
...@@ -299,7 +307,6 @@ discovery_add_server_reflexive_candidate ( ...@@ -299,7 +307,6 @@ discovery_add_server_reflexive_candidate (
candidate->priority = candidate->priority =
nice_candidate_ice_priority_full nice_candidate_ice_priority_full
(NICE_CANDIDATE_TYPE_PREF_SERVER_REFLEXIVE, 0, component_id); (NICE_CANDIDATE_TYPE_PREF_SERVER_REFLEXIVE, 0, component_id);
priv_assign_foundation (agent, component, candidate);
candidate->stream_id = stream_id; candidate->stream_id = stream_id;
candidate->component_id = component_id; candidate->component_id = component_id;
candidate->addr = *address; candidate->addr = *address;
...@@ -308,6 +315,8 @@ discovery_add_server_reflexive_candidate ( ...@@ -308,6 +315,8 @@ discovery_add_server_reflexive_candidate (
candidate->sockptr = base_socket; candidate->sockptr = base_socket;
candidate->base_addr = base_socket->addr; candidate->base_addr = base_socket->addr;
priv_assign_foundation (agent, candidate);
result = priv_add_local_candidate_pruned (component, candidate); result = priv_add_local_candidate_pruned (component, candidate);
if (result) { if (result) {
agent_signal_new_candidate (agent, candidate); agent_signal_new_candidate (agent, candidate);
...@@ -352,7 +361,7 @@ discovery_add_peer_reflexive_candidate ( ...@@ -352,7 +361,7 @@ discovery_add_peer_reflexive_candidate (
(NICE_CANDIDATE_TYPE_PREF_PEER_REFLEXIVE, 0, component_id); (NICE_CANDIDATE_TYPE_PREF_PEER_REFLEXIVE, 0, component_id);
candidate->stream_id = stream_id; candidate->stream_id = stream_id;
candidate->component_id = component_id; candidate->component_id = component_id;
priv_assign_foundation (agent, component, candidate); priv_assign_foundation (agent, candidate);
candidate->addr = *address; candidate->addr = *address;
candidate->base_addr = base_socket->addr; candidate->base_addr = base_socket->addr;
...@@ -471,7 +480,8 @@ static gboolean priv_discovery_tick (gpointer pointer) ...@@ -471,7 +480,8 @@ static gboolean priv_discovery_tick (gpointer pointer)
if (agent->discovery_unsched_items) if (agent->discovery_unsched_items)
--agent->discovery_unsched_items; --agent->discovery_unsched_items;
g_debug ("discovery - scheduling cand type %u addr %s and socket %d.\n", cand->type, cand->server_addr, cand->socket); g_debug ("discovery - scheduling cand type %u addr %s and socket %d.\n",
cand->type, cand->server_addr, cand->socket);
if (cand->type == NICE_CANDIDATE_TYPE_SERVER_REFLEXIVE && if (cand->type == NICE_CANDIDATE_TYPE_SERVER_REFLEXIVE &&
cand->server_addr) { cand->server_addr) {
...@@ -518,7 +528,6 @@ static gboolean priv_discovery_tick (gpointer pointer) ...@@ -518,7 +528,6 @@ static gboolean priv_discovery_tick (gpointer pointer)
g_debug ("STUN discovery was cancelled, marking discovery done."); g_debug ("STUN discovery was cancelled, marking discovery done.");
cand->done = TRUE; cand->done = TRUE;
} }
/* note: macro from sys/time.h but compatible with GTimeVal */
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); int res = stun_bind_elapse (cand->stun_ctx);
if (res == EAGAIN) { if (res == EAGAIN) {
...@@ -526,8 +535,8 @@ static gboolean priv_discovery_tick (gpointer pointer) ...@@ -526,8 +535,8 @@ static gboolean priv_discovery_tick (gpointer pointer)
unsigned int timeout = stun_bind_timeout (cand->stun_ctx); unsigned int timeout = stun_bind_timeout (cand->stun_ctx);
/* note: convert from milli to microseconds for g_time_val_add() */ /* note: convert from milli to microseconds for g_time_val_add() */
g_get_current_time (&cand->next_tick); cand->next_tick = now;
g_time_val_add (&cand->next_tick, timeout * 10); g_time_val_add (&cand->next_tick, timeout * 1000);
++not_done; /* note: retry later */ ++not_done; /* note: retry later */
} }
......
/*
* This file is part of the Nice GLib ICE library.
*
* Contains a unit test for functionality to fallback to non-ICE
* operation if remote party does not support ICE.
*
* (C) 2007 Nokia Corporation. All rights reserved.
* Contact: Kai Vehmanen
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is the Nice GLib ICE library.
*
* The Initial Developers of the Original Code are Collabora Ltd and Nokia
* Corporation. All Rights Reserved.
*
* Contributors:
* Kai Vehmanen, Nokia
*
* Alternatively, the contents of this file may be used under the terms of the
* the GNU Lesser General Public License Version 2.1 (the "LGPL"), in which
* case the provisions of LGPL are applicable instead of those above. If you
* wish to allow use of your version of this file only under the terms of the
* LGPL and not to allow others to use your version of this file under the
* MPL, indicate your decision by deleting the provisions above and replace
* them with the notice and other provisions required by the LGPL. If you do
* not delete the provisions above, a recipient may use your version of this
* file under either the MPL or the LGPL.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdlib.h>
#include <string.h>
#include "agent.h"
#include "agent-priv.h" /* for testing purposes */
#include "udp-bsd.h"
static NiceComponentState global_lagent_state = NICE_COMPONENT_STATE_LAST;
static NiceComponentState global_ragent_state = NICE_COMPONENT_STATE_LAST;
static guint global_components_ready = 0;
static guint global_components_ready_exit = 0;
static guint global_components_failed = 0;
static guint global_components_failed_exit = 0;
static GMainLoop *global_mainloop = NULL;
static gboolean global_lagent_gathering_done = FALSE;
static gboolean global_ragent_gathering_done = FALSE;
static gboolean global_lagent_ibr_received = FALSE;
static gboolean global_ragent_ibr_received = FALSE;
static int global_lagent_cands = 0;
static int global_ragent_cands = 0;
static gint global_ragent_read = 0;
static gint global_ragent_read_exit = 0;
static void priv_print_global_status (void)
{
g_debug ("\tgathering_done=%d", global_lagent_gathering_done && global_ragent_gathering_done);
g_debug ("\tlstate=%d", global_lagent_state);
g_debug ("\trstate=%d", global_ragent_state);
}
static gboolean timer_cb (gpointer pointer)
{
g_debug ("test-fallback:%s: %p", G_STRFUNC, pointer);
/* signal status via a global variable */
/* note: should not be reached, abort */
g_debug ("ERROR: test has got stuck, aborting...");
exit (-1);
}
static void cb_nice_recv (NiceAgent *agent, guint stream_id, guint component_id, guint len, gchar *buf, gpointer user_data)
{
g_debug ("test-fallback:%s: %p", G_STRFUNC, user_data);
/* XXX: dear compiler, these are for you: */
(void)agent; (void)stream_id; (void)component_id; (void)buf;
if ((intptr_t)user_data == 2) {
global_ragent_read += len;
if (global_ragent_read == global_ragent_read_exit)
g_main_loop_quit (global_mainloop);
}
}
static void cb_candidate_gathering_done(NiceAgent *agent, gpointer data)
{
g_debug ("test-fallback:%s: %p", G_STRFUNC, data);
if ((intptr_t)data == 1)
global_lagent_gathering_done = TRUE;
else if ((intptr_t)data == 2)
global_ragent_gathering_done = TRUE;
if (global_lagent_gathering_done &&
global_ragent_gathering_done)
g_main_loop_quit (global_mainloop);
/* XXX: dear compiler, these are for you: */
(void)agent;
}
static void cb_component_state_changed (NiceAgent *agent, guint stream_id, guint component_id, guint state, gpointer data)
{
g_debug ("test-fallback:%s: %p", __func__, data);
if ((intptr_t)data == 1)
global_lagent_state = state;
else if ((intptr_t)data == 2)
global_ragent_state = state;
if (state == NICE_COMPONENT_STATE_READY)
global_components_ready++;
if (state == NICE_COMPONENT_STATE_FAILED)
global_components_failed++;
g_debug ("test-fallback: READY %u exit at %u.", global_components_ready, global_components_ready_exit);
/* signal status via a global variable */
if (global_components_ready == global_components_ready_exit) {
g_main_loop_quit (global_mainloop);
return;
}
/* signal status via a global variable */
if (global_components_failed == global_components_failed_exit) {
g_main_loop_quit (global_mainloop);
return;
}
/* XXX: dear compiler, these are for you: */
(void)agent; (void)stream_id; (void)data; (void)component_id;
}
static void cb_new_selected_pair(NiceAgent *agent, guint stream_id, guint component_id,
gchar *lfoundation, gchar* rfoundation, gpointer data)
{
g_debug ("test-fallback:%s: %p", __func__, data);
if ((intptr_t)data == 1)
++global_lagent_cands;
else if ((intptr_t)data == 2)
++global_ragent_cands;
/* XXX: dear compiler, these are for you: */
(void)agent; (void)stream_id; (void)component_id; (void)lfoundation; (void)rfoundation;
}
static void cb_new_candidate(NiceAgent *agent, guint stream_id, guint component_id,
gchar *foundation, gpointer data)
{
g_debug ("test-fallback:%s: %p", __func__, data);
/* XXX: dear compiler, these are for you: */
(void)agent; (void)stream_id; (void)data; (void)component_id; (void)foundation;
}
static void cb_initial_binding_request_received(NiceAgent *agent, guint stream_id, gpointer data)
{
g_debug ("test-fallback:%s: %p", __func__, data);
if ((intptr_t)data == 1)
global_lagent_ibr_received = TRUE;
else if ((intptr_t)data == 2)
global_ragent_ibr_received = TRUE;
/* XXX: dear compiler, these are for you: */
(void)agent; (void)stream_id; (void)data;
}
static void priv_get_local_addr (NiceAgent *agent, guint stream_id, guint component_id, NiceAddress *dstaddr)
{
GSList *cands, *i;
cands = nice_agent_get_local_candidates(agent, stream_id, component_id);
for (i = cands; i; i = i->next) {
NiceCandidate *cand = i->data;
if (cand) {
g_assert (dstaddr);
*dstaddr = cand->addr;
break;
}
}
g_slist_free (cands);
}
static int run_fallback_test (NiceAgent *lagent, NiceAgent *ragent, NiceAddress *baseaddr)
{
NiceAddress laddr, raddr, laddr_rtcp, raddr_rtcp;
NiceCandidateDesc cdes = { /* candidate description (no ports) */
(gchar *)"1", /* foundation */
0, /* component-id; filled later */
NICE_CANDIDATE_TRANSPORT_UDP, /* transport */
100000, /* priority */
NULL, /* address */
NICE_CANDIDATE_TYPE_HOST, /* type */
baseaddr /* base-address */
};
GSList *cands;
guint ls_id, rs_id;
/* XXX: dear compiler, these are for you: */
(void)baseaddr;
/* step: initialize variables modified by the callbacks */
global_components_ready = 0;
global_components_ready_exit = 4;
global_components_failed = 0;
global_components_failed_exit = 4;
global_lagent_gathering_done = FALSE;
global_ragent_gathering_done = FALSE;
global_lagent_ibr_received =
global_ragent_ibr_received = FALSE;
global_lagent_cands =
global_ragent_cands = 0;
global_ragent_read_exit = -1;
g_object_set (G_OBJECT (lagent), "controlling-mode", TRUE, NULL);
g_object_set (G_OBJECT (ragent), "controlling-mode", FALSE, NULL);
/* step: add one stream, with RTP+RTCP components, to each agent */
ls_id = nice_agent_add_stream (lagent, 2);
rs_id = nice_agent_add_stream (ragent, 2);
g_assert (ls_id > 0);
g_assert (rs_id > 0);
/* step: run mainloop until local candidates are ready
* (see timer_cb() above) */
if (global_lagent_gathering_done != TRUE ||
global_ragent_gathering_done != TRUE) {
g_debug ("test-fallback: Added streams, running mainloop until 'candidate-gathering-done'...");
g_main_loop_run (global_mainloop);
g_assert (global_lagent_gathering_done == TRUE);
g_assert (global_ragent_gathering_done == TRUE);
}
/* step: find out the local candidates of each agent */
priv_get_local_addr (ragent, rs_id, NICE_COMPONENT_TYPE_RTP, &raddr);
g_debug ("test-fallback: local RTP port R %u",
nice_address_get_port (&raddr));
priv_get_local_addr (lagent, ls_id, NICE_COMPONENT_TYPE_RTP, &laddr);
g_debug ("test-fallback: local RTP port L %u",
nice_address_get_port (&laddr));
priv_get_local_addr (ragent, rs_id, NICE_COMPONENT_TYPE_RTCP, &raddr_rtcp);
g_debug ("test-fallback: local RTCP port R %u",
nice_address_get_port (&raddr_rtcp));
priv_get_local_addr (lagent, ls_id, NICE_COMPONENT_TYPE_RTCP, &laddr_rtcp);
g_debug ("test-fallback: local RTCP port L %u",
nice_address_get_port (&laddr_rtcp));
/* step: exchange candidate information but not the credentials */
cands = g_slist_append (NULL, &cdes);
cdes.component_id = NICE_COMPONENT_TYPE_RTP;
cdes.addr = &raddr;
nice_agent_set_remote_candidates (lagent, ls_id, NICE_COMPONENT_TYPE_RTP, cands);
cdes.addr = &laddr;
nice_agent_set_remote_candidates (ragent, rs_id, NICE_COMPONENT_TYPE_RTP, cands);
cdes.component_id = NICE_COMPONENT_TYPE_RTCP;
cdes.addr = &raddr_rtcp;
nice_agent_set_remote_candidates (lagent, ls_id, NICE_COMPONENT_TYPE_RTCP, cands);
cdes.addr = &laddr_rtcp;
nice_agent_set_remote_candidates (ragent, rs_id, NICE_COMPONENT_TYPE_RTCP, cands);
/* step: fall back to non-ICE mode on both sides */
g_assert (nice_agent_set_selected_pair (lagent, ls_id, NICE_COMPONENT_TYPE_RTP, "1", "1") == TRUE);
g_assert (nice_agent_set_selected_pair (lagent, ls_id, NICE_COMPONENT_TYPE_RTCP, "1", "1") == TRUE);
g_assert (nice_agent_set_selected_pair (ragent, rs_id, NICE_COMPONENT_TYPE_RTP, "1", "1") == TRUE);
g_assert (nice_agent_set_selected_pair (ragent, rs_id, NICE_COMPONENT_TYPE_RTCP, "1", "1") == TRUE);
g_debug ("test-fallback: Requested for fallback, running mainloop until component state change is completed...");
/* step: run the mainloop until connectivity checks succeed
* (see timer_cb() above) */
if (global_components_ready < global_components_ready_exit)
g_main_loop_run (global_mainloop);
/* note: verify that agents are in correct state */
g_assert (global_lagent_state == NICE_COMPONENT_STATE_READY);
g_assert (global_ragent_state == NICE_COMPONENT_STATE_READY);
/* step: next send a packet -> should work even if no ICE processing
* has been done */
g_debug ("test-fallback: Sent a payload packet, run mainloop until packet received.");
/* step: send a new test packet from L ot R */
global_ragent_read = 0;
g_assert (nice_agent_send (lagent, ls_id, 1, 16, "1234567812345678") == 16);
global_ragent_read_exit = 16;
g_main_loop_run (global_mainloop);
/* note: verify that payload was succesfully received */
g_assert (global_ragent_read == 16);
g_debug ("test-fallback: Ran mainloop, removing streams...");
/* step: clean up resources and exit */
g_slist_free (cands);
nice_agent_remove_stream (lagent, ls_id);
nice_agent_remove_stream (ragent, rs_id);
g_debug ("test-fallback: test COMPLETED");
return 0;
}
int main (void)
{
NiceAgent *lagent, *ragent; /* agent's L and R */
NiceUDPSocketFactory udpfactory;
NiceAddress baseaddr;
int result;
guint timer_id;
const char *stun_server = NULL, *stun_server_port = NULL;
g_type_init ();
global_mainloop = g_main_loop_new (NULL, FALSE);
/* Note: impl limits ...
* - no multi-stream support
* - no IPv6 support
*/
nice_udp_bsd_socket_factory_init (&udpfactory);
/* step: create the agents L and R */
lagent = nice_agent_new (&udpfactory);
ragent = nice_agent_new (&udpfactory);
/* step: attach to mainloop (needed to register the fds) */
nice_agent_main_context_attach (lagent, g_main_loop_get_context (global_mainloop), cb_nice_recv, (gpointer)1);
nice_agent_main_context_attach (ragent, g_main_loop_get_context (global_mainloop), cb_nice_recv, (gpointer)2);
/* step: add a timer to catch state changes triggered by signals */
timer_id = g_timeout_add (30000, timer_cb, NULL);
/* step: specify which local interface to use */
if (!nice_address_set_from_string (&baseaddr, "127.0.0.1"))
g_assert_not_reached ();
nice_agent_add_local_address (lagent, &baseaddr);
nice_agent_add_local_address (ragent, &baseaddr);
g_signal_connect (G_OBJECT (lagent), "candidate-gathering-done",
G_CALLBACK (cb_candidate_gathering_done), (gpointer)1);
g_signal_connect (G_OBJECT (ragent), "candidate-gathering-done",
G_CALLBACK (cb_candidate_gathering_done), (gpointer)2);
g_signal_connect (G_OBJECT (lagent), "component-state-changed",
G_CALLBACK (cb_component_state_changed), (gpointer)1);
g_signal_connect (G_OBJECT (ragent), "component-state-changed",
G_CALLBACK (cb_component_state_changed), (gpointer)2);
g_signal_connect (G_OBJECT (lagent), "new-selected-pair",
G_CALLBACK (cb_new_selected_pair), (gpointer)1);
g_signal_connect (G_OBJECT (ragent), "new-selected-pair",
G_CALLBACK (cb_new_selected_pair), (gpointer)2);
g_signal_connect (G_OBJECT (lagent), "new-candidate",
G_CALLBACK (cb_new_candidate), (gpointer)1);
g_signal_connect (G_OBJECT (ragent), "new-candidate",
G_CALLBACK (cb_new_candidate), (gpointer)2);
g_signal_connect (G_OBJECT (lagent), "initial-binding-request-received",
G_CALLBACK (cb_initial_binding_request_received), (gpointer)1);
g_signal_connect (G_OBJECT (ragent), "initial-binding-request-received",
G_CALLBACK (cb_initial_binding_request_received), (gpointer)2);
stun_server = getenv ("NICE_STUN_SERVER");
stun_server_port = getenv ("NICE_STUN_SERVER_PORT");
if (stun_server) {
g_object_set (G_OBJECT (lagent), "stun-server", stun_server, NULL);
g_object_set (G_OBJECT (lagent), "stun-server-port", atoi (stun_server_port), NULL);
g_object_set (G_OBJECT (ragent), "stun-server", stun_server, NULL);
g_object_set (G_OBJECT (ragent), "stun-server-port", atoi (stun_server_port), NULL);
}
/* step: run test the first time */
g_debug ("test-fallback: TEST STARTS / fallback test");
result = run_fallback_test (lagent, ragent, &baseaddr);
priv_print_global_status ();
g_assert (result == 0);
g_assert (global_lagent_state == NICE_COMPONENT_STATE_READY);
g_assert (global_ragent_state == NICE_COMPONENT_STATE_READY);
g_object_unref (lagent);
g_object_unref (ragent);
nice_udp_socket_factory_close (&udpfactory);
g_main_loop_unref (global_mainloop),
global_mainloop = NULL;
g_source_remove (timer_id);
return result;
}
/* /*
* This file is part of the Nice GLib ICE library. * This file is part of the Nice GLib ICE library.
* *
* Unit test for ICE full-mode related features.
*
* (C) 2007 Nokia Corporation. All rights reserved. * (C) 2007 Nokia Corporation. All rights reserved.
* Contact: Kai Vehmanen * Contact: Kai Vehmanen
* *
...@@ -83,7 +85,7 @@ static void cb_nice_recv (NiceAgent *agent, guint stream_id, guint component_id, ...@@ -83,7 +85,7 @@ static void cb_nice_recv (NiceAgent *agent, guint stream_id, guint component_id,
/* XXX: dear compiler, these are for you: */ /* XXX: dear compiler, these are for you: */
(void)agent; (void)stream_id; (void)component_id; (void)buf; (void)agent; (void)stream_id; (void)component_id; (void)buf;
if ((int)user_data == 2) { if ((intptr_t)user_data == 2) {
global_ragent_read = len; global_ragent_read = len;
g_main_loop_quit (global_mainloop); g_main_loop_quit (global_mainloop);
} }
...@@ -93,9 +95,9 @@ static void cb_candidate_gathering_done(NiceAgent *agent, gpointer data) ...@@ -93,9 +95,9 @@ static void cb_candidate_gathering_done(NiceAgent *agent, gpointer data)
{ {
g_debug ("test-fullmode:%s: %p", G_STRFUNC, data); g_debug ("test-fullmode:%s: %p", G_STRFUNC, data);
if ((int)data == 1) if ((intptr_t)data == 1)
global_lagent_gathering_done = TRUE; global_lagent_gathering_done = TRUE;
else if ((int)data == 2) else if ((intptr_t)data == 2)
global_ragent_gathering_done = TRUE; global_ragent_gathering_done = TRUE;
if (global_lagent_gathering_done && if (global_lagent_gathering_done &&
...@@ -110,9 +112,9 @@ static void cb_component_state_changed (NiceAgent *agent, guint stream_id, guint ...@@ -110,9 +112,9 @@ static void cb_component_state_changed (NiceAgent *agent, guint stream_id, guint
{ {
g_debug ("test-fullmode:%s: %p", __func__, data); g_debug ("test-fullmode:%s: %p", __func__, data);
if ((int)data == 1) if ((intptr_t)data == 1)
global_lagent_state = state; global_lagent_state = state;
else if ((int)data == 2) else if ((intptr_t)data == 2)
global_ragent_state = state; global_ragent_state = state;
if (state == NICE_COMPONENT_STATE_READY) if (state == NICE_COMPONENT_STATE_READY)
...@@ -143,9 +145,9 @@ static void cb_new_selected_pair(NiceAgent *agent, guint stream_id, guint compon ...@@ -143,9 +145,9 @@ static void cb_new_selected_pair(NiceAgent *agent, guint stream_id, guint compon
{ {
g_debug ("test-fullmode:%s: %p", __func__, data); g_debug ("test-fullmode:%s: %p", __func__, data);
if ((int)data == 1) if ((intptr_t)data == 1)
++global_lagent_cands; ++global_lagent_cands;
else if ((int)data == 2) else if ((intptr_t)data == 2)
++global_ragent_cands; ++global_ragent_cands;
/* XXX: dear compiler, these are for you: */ /* XXX: dear compiler, these are for you: */
...@@ -165,9 +167,9 @@ static void cb_initial_binding_request_received(NiceAgent *agent, guint stream_i ...@@ -165,9 +167,9 @@ static void cb_initial_binding_request_received(NiceAgent *agent, guint stream_i
{ {
g_debug ("test-fullmode:%s: %p", __func__, data); g_debug ("test-fullmode:%s: %p", __func__, data);
if ((int)data == 1) if ((intptr_t)data == 1)
global_lagent_ibr_received = TRUE; global_lagent_ibr_received = TRUE;
else if ((int)data == 2) else if ((intptr_t)data == 2)
global_ragent_ibr_received = TRUE; global_ragent_ibr_received = TRUE;
/* XXX: dear compiler, these are for you: */ /* XXX: dear compiler, these are for you: */
...@@ -240,16 +242,20 @@ static int run_full_test (NiceAgent *lagent, NiceAgent *ragent, NiceAddress *bas ...@@ -240,16 +242,20 @@ static int run_full_test (NiceAgent *lagent, NiceAgent *ragent, NiceAddress *bas
/* step: find out the local candidates of each agent */ /* step: find out the local candidates of each agent */
priv_get_local_addr (ragent, rs_id, NICE_COMPONENT_TYPE_RTP, &raddr); priv_get_local_addr (ragent, rs_id, NICE_COMPONENT_TYPE_RTP, &raddr);
g_debug ("test-fullmode: local RTP port R %u", raddr.port); g_debug ("test-fullmode: local RTP port R %u",
nice_address_get_port (&raddr));
priv_get_local_addr (lagent, ls_id, NICE_COMPONENT_TYPE_RTP, &laddr); priv_get_local_addr (lagent, ls_id, NICE_COMPONENT_TYPE_RTP, &laddr);
g_debug ("test-fullmode: local RTP port L %u", laddr.port); g_debug ("test-fullmode: local RTP port L %u",
nice_address_get_port (&laddr));
priv_get_local_addr (ragent, rs_id, NICE_COMPONENT_TYPE_RTCP, &raddr_rtcp); priv_get_local_addr (ragent, rs_id, NICE_COMPONENT_TYPE_RTCP, &raddr_rtcp);
g_debug ("test-fullmode: local RTCP port R %u", raddr_rtcp.port); g_debug ("test-fullmode: local RTCP port R %u",
nice_address_get_port (&raddr_rtcp));
priv_get_local_addr (lagent, ls_id, NICE_COMPONENT_TYPE_RTCP, &laddr_rtcp); priv_get_local_addr (lagent, ls_id, NICE_COMPONENT_TYPE_RTCP, &laddr_rtcp);
g_debug ("test-fullmode: local RTCP port L %u", laddr_rtcp.port); g_debug ("test-fullmode: local RTCP port L %u",
nice_address_get_port (&laddr_rtcp));
/* step: pass the remote candidates to agents */ /* step: pass the remote candidates to agents */
cands = g_slist_append (NULL, &cdes); cands = g_slist_append (NULL, &cdes);
...@@ -358,7 +364,8 @@ static int run_full_test_wrong_password (NiceAgent *lagent, NiceAgent *ragent, N ...@@ -358,7 +364,8 @@ static int run_full_test_wrong_password (NiceAgent *lagent, NiceAgent *ragent, N
for (i = cands; i; i = i->next) { for (i = cands; i; i = i->next) {
NiceCandidate *cand = i->data; NiceCandidate *cand = i->data;
if (cand) { if (cand) {
g_debug ("test-fullmode: local port L %u", cand->addr.port); g_debug ("test-fullmode: local port L %u",
nice_address_get_port (&cand->addr));
laddr = cand->addr; laddr = cand->addr;
} }
} }
...@@ -368,7 +375,8 @@ static int run_full_test_wrong_password (NiceAgent *lagent, NiceAgent *ragent, N ...@@ -368,7 +375,8 @@ static int run_full_test_wrong_password (NiceAgent *lagent, NiceAgent *ragent, N
for (i = cands; i; i = i->next) { for (i = cands; i; i = i->next) {
NiceCandidate *cand = i->data; NiceCandidate *cand = i->data;
if (cand) { if (cand) {
g_debug ("test-fullmode: local port R %u", cand->addr.port); g_debug ("test-fullmode: local port R %u",
nice_address_get_port (&cand->addr));
raddr = cand->addr; raddr = cand->addr;
} }
} }
...@@ -467,7 +475,8 @@ static int run_full_test_control_conflict (NiceAgent *lagent, NiceAgent *ragent, ...@@ -467,7 +475,8 @@ static int run_full_test_control_conflict (NiceAgent *lagent, NiceAgent *ragent,
for (i = cands; i; i = i->next) { for (i = cands; i; i = i->next) {
NiceCandidate *cand = i->data; NiceCandidate *cand = i->data;
if (cand) { if (cand) {
g_debug ("test-fullmode: local port L %u", cand->addr.port); g_debug ("test-fullmode: local port L %u",
nice_address_get_port (&cand->addr));
laddr = cand->addr; laddr = cand->addr;
} }
} }
......
...@@ -85,7 +85,7 @@ static void cb_nice_recv (NiceAgent *agent, guint stream_id, guint component_id, ...@@ -85,7 +85,7 @@ static void cb_nice_recv (NiceAgent *agent, guint stream_id, guint component_id,
/* XXX: dear compiler, these are for you: */ /* XXX: dear compiler, these are for you: */
(void)agent; (void)stream_id; (void)component_id; (void)buf; (void)agent; (void)stream_id; (void)component_id; (void)buf;
if ((int)user_data == 2) { if ((intptr_t)user_data == 2) {
global_ragent_read += len; global_ragent_read += len;
if (global_ragent_read == global_ragent_read_exit) if (global_ragent_read == global_ragent_read_exit)
...@@ -97,9 +97,9 @@ static void cb_candidate_gathering_done(NiceAgent *agent, gpointer data) ...@@ -97,9 +97,9 @@ static void cb_candidate_gathering_done(NiceAgent *agent, gpointer data)
{ {
g_debug ("test-restart:%s: %p", G_STRFUNC, data); g_debug ("test-restart:%s: %p", G_STRFUNC, data);
if ((int)data == 1) if ((intptr_t)data == 1)
global_lagent_gathering_done = TRUE; global_lagent_gathering_done = TRUE;
else if ((int)data == 2) else if ((intptr_t)data == 2)
global_ragent_gathering_done = TRUE; global_ragent_gathering_done = TRUE;
if (global_lagent_gathering_done && if (global_lagent_gathering_done &&
...@@ -114,9 +114,9 @@ static void cb_component_state_changed (NiceAgent *agent, guint stream_id, guint ...@@ -114,9 +114,9 @@ static void cb_component_state_changed (NiceAgent *agent, guint stream_id, guint
{ {
g_debug ("test-restart:%s: %p", __func__, data); g_debug ("test-restart:%s: %p", __func__, data);
if ((int)data == 1) if ((intptr_t)data == 1)
global_lagent_state = state; global_lagent_state = state;
else if ((int)data == 2) else if ((intptr_t)data == 2)
global_ragent_state = state; global_ragent_state = state;
if (state == NICE_COMPONENT_STATE_READY) if (state == NICE_COMPONENT_STATE_READY)
...@@ -147,9 +147,9 @@ static void cb_new_selected_pair(NiceAgent *agent, guint stream_id, guint compon ...@@ -147,9 +147,9 @@ static void cb_new_selected_pair(NiceAgent *agent, guint stream_id, guint compon
{ {
g_debug ("test-restart:%s: %p", __func__, data); g_debug ("test-restart:%s: %p", __func__, data);
if ((int)data == 1) if ((intptr_t)data == 1)
++global_lagent_cands; ++global_lagent_cands;
else if ((int)data == 2) else if ((intptr_t)data == 2)
++global_ragent_cands; ++global_ragent_cands;
/* XXX: dear compiler, these are for you: */ /* XXX: dear compiler, these are for you: */
...@@ -169,9 +169,9 @@ static void cb_initial_binding_request_received(NiceAgent *agent, guint stream_i ...@@ -169,9 +169,9 @@ static void cb_initial_binding_request_received(NiceAgent *agent, guint stream_i
{ {
g_debug ("test-restart:%s: %p", __func__, data); g_debug ("test-restart:%s: %p", __func__, data);
if ((int)data == 1) if ((intptr_t)data == 1)
global_lagent_ibr_received = TRUE; global_lagent_ibr_received = TRUE;
else if ((int)data == 2) else if ((intptr_t)data == 2)
global_ragent_ibr_received = TRUE; global_ragent_ibr_received = TRUE;
/* XXX: dear compiler, these are for you: */ /* XXX: dear compiler, these are for you: */
......
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