Commit 355dafd0 authored by Kai Vehmanen's avatar Kai Vehmanen

Major update to the nice/agent interface: Added full-mode API and initial...

Major update to the nice/agent interface: Added full-mode API and initial implementation using the new nice/stun interface. Added unit test test-fullmode.c to cover the added functionality. Some public APIs of nice/agent/agent.h have been modified, making this change API/ABI incompatible.

darcs-hash:20070521153033-77cd4-c76ab583d06839e601f46b6734355dd8b66f7494.gz
parent 91d4e0a1
/*
* This file is part of the Nice GLib ICE library.
*
* (C) 2006, 2007 Collabora Ltd.
* Contact: Dafydd Harries
* (C) 2006, 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:
* Dafydd Harries, Collabora Ltd.
* 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.
*/
#ifndef _NICE_AGENT_PRIV_H
#define _NICE_AGENT_PRIV_H
/* note: this is a private header part of agent.h */
#include <glib.h>
#include "agent.h"
#include "component.h"
#include "candidate.h"
#include "stream.h"
#include "conncheck.h"
#define NICE_AGENT_TIMER_TA_DEFAULT 20 /* timer Ta, msecs */
#define NICE_AGENT_TIMER_TR_DEFAULT 15000 /* timer Tr, msecs */
/** An upper limit to size of STUN packets handled (based on Ethernet
* MTU and estimated typical sizes of ICE STUN packet */
#define MAX_STUN_DATAGRAM_PAYLOAD 1300
struct _NiceAgent
{
GObject parent; /**< gobject pointer */
gboolean full_mode; /**< property: full-mode */
NiceUDPSocketFactory *socket_factory; /**< property: socket factory */
GTimeVal next_check_tv; /**< property: next conncheck timestamp */
gchar *stun_server_ip; /**< property: STUN server IP */
guint stun_server_port; /**< property: STUN server port */
gchar *turn_server_ip; /**< property: TURN server IP */
guint turn_server_port; /**< property: TURN server port */
gboolean controlling_mode; /**< property: controlling-mode */
GSList *local_addresses; /**< list of NiceAddresses for local
interfaces */
GSList *streams; /**< list of Stream objects */
gboolean main_context_set; /**< is the main context set */
GMainContext *main_context; /**< main context pointer */
NiceAgentRecvFunc read_func; /**< callback for media deliver */
gpointer read_func_data; /**< media delivery callback context */
guint next_candidate_id; /**< id of next created candidate */
guint next_stream_id; /**< id of next created candidate */
NiceRNG *rng; /**< random number generator */
GSList *discovery_list; /**< list of CandidateDiscovery items */
guint discovery_unsched_items; /**< number of discovery items unscheduled */
guint discovery_timer_id; /**< id of discovery timer */
GSList *conncheck_list; /**< list of CandidatePair items */
guint conncheck_timer_id; /**< id of discovery timer */
NiceCheckListState conncheck_state; /**< checklist state */
/* XXX: add pointer to internal data struct for ABI-safe extensions */
};
gboolean
agent_find_component (
NiceAgent *agent,
guint stream_id,
guint component_id,
Stream **stream,
Component **component);
Stream *agent_find_stream (NiceAgent *agent, guint stream_id);
void agent_signal_gathering_done (NiceAgent *agent);
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_component_state_change (
NiceAgent *agent,
guint stream_id,
guint component_id,
NiceComponentState state);
void agent_signal_new_candidate (
NiceAgent *agent,
NiceCandidate *candidate);
void agent_signal_initial_binding_request_received (NiceAgent *agent, Stream *stream);
void agent_free_discovery_candidate_udp (gpointer data, gpointer user_data);
#endif /*_NICE_AGENT_PRIV_H */
...@@ -2,3 +2,10 @@ ...@@ -2,3 +2,10 @@
VOID:UINT,UINT,UINT VOID:UINT,UINT,UINT
# candidate-gathering-done # candidate-gathering-done
VOID:VOID VOID:VOID
# new-selected-pair
VOID:UINT,UINT,STRING,STRING
# new-candidate
VOID:UINT,UINT,STRING
# initial-binding-request-received
VOID:UINT
This diff is collapsed.
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
* *
* Contributors: * Contributors:
* Dafydd Harries, Collabora Ltd. * Dafydd Harries, Collabora Ltd.
* Kai Vehmanen, Nokia
* *
* Alternatively, the contents of this file may be used under the terms of the * 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 * the GNU Lesser General Public License Version 2.1 (the "LGPL"), in which
...@@ -77,8 +78,9 @@ typedef enum ...@@ -77,8 +78,9 @@ typedef enum
NICE_COMPONENT_STATE_CONNECTED, /* at least one working candidate pair */ NICE_COMPONENT_STATE_CONNECTED, /* at least one working candidate pair */
NICE_COMPONENT_STATE_READY, /* ICE concluded, candidate pair NICE_COMPONENT_STATE_READY, /* ICE concluded, candidate pair
selection is now final */ selection is now final */
NICE_COMPONENT_STATE_FAILED /* connectivity checks have been completed, NICE_COMPONENT_STATE_FAILED, /* connectivity checks have been completed,
but connectivity was not established */ but connectivity was not established */
NICE_COMPONENT_STATE_LAST
} NiceComponentState; } NiceComponentState;
typedef enum typedef enum
...@@ -105,29 +107,6 @@ typedef void (*NiceAgentRecvFunc) ( ...@@ -105,29 +107,6 @@ typedef void (*NiceAgentRecvFunc) (
NiceAgent *agent, guint stream_id, guint component_id, guint len, NiceAgent *agent, guint stream_id, guint component_id, guint len,
gchar *buf, gpointer user_data); gchar *buf, gpointer user_data);
struct _NiceAgent
{
GObject parent;
guint next_candidate_id;
guint next_stream_id;
gboolean full_mode;
NiceUDPSocketFactory *socket_factory;
GSList *local_addresses;
GSList *streams;
gboolean main_context_set;
GMainContext *main_context;
NiceAgentRecvFunc read_func;
gpointer read_func_data;
GSList *discovery_list;
guint discovery_unsched_items;
GSList *conncheck_list;
gchar *stun_server_ip;
guint stun_server_port;
gchar *turn_server_ip;
guint turn_server_port;
GTimeVal next_check_tv;
NiceRNG *rng;
};
typedef struct _NiceAgentClass NiceAgentClass; typedef struct _NiceAgentClass NiceAgentClass;
...@@ -154,6 +133,18 @@ nice_agent_remove_stream ( ...@@ -154,6 +133,18 @@ nice_agent_remove_stream (
NiceAgent *agent, NiceAgent *agent,
guint stream_id); guint stream_id);
gboolean
nice_agent_set_remote_credentials (
NiceAgent *agent,
guint stream_id,
const gchar *ufrag, const gchar *pwd);
gboolean
nice_agent_get_local_credentials (
NiceAgent *agent,
guint stream_id,
const gchar **ufrag, const gchar **pwd);
void void
nice_agent_add_remote_candidate ( nice_agent_add_remote_candidate (
NiceAgent *agent, NiceAgent *agent,
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
* *
* Contributors: * Contributors:
* Dafydd Harries, Collabora Ltd. * Dafydd Harries, Collabora Ltd.
* Kai Vehmanen, Nokia
* *
* Alternatively, the contents of this file may be used under the terms of the * 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 * the GNU Lesser General Public License Version 2.1 (the "LGPL"), in which
...@@ -36,7 +37,7 @@ ...@@ -36,7 +37,7 @@
*/ */
#include "agent.h" #include "agent.h"
#include "component.h"
/* (ICE-13 §4.1.1) Every candidate is a transport address. It also has a type and /* (ICE-13 §4.1.1) Every candidate is a transport address. It also has a type and
* a base. Three types are defined and gathered by this specification - host * a base. Three types are defined and gathered by this specification - host
...@@ -59,12 +60,15 @@ nice_candidate_free (NiceCandidate *candidate) ...@@ -59,12 +60,15 @@ nice_candidate_free (NiceCandidate *candidate)
{ {
/* better way of checking if socket is allocated? */ /* better way of checking if socket is allocated? */
if (candidate->sock.addr.addr_ipv4 != 0)
nice_udp_socket_close (&(candidate->sock));
if (candidate->source) if (candidate->source)
g_source_destroy (candidate->source); g_source_destroy (candidate->source);
if (candidate->username)
g_free (candidate->username);
if (candidate->password)
g_free (candidate->password);
if (candidate->foundation) if (candidate->foundation)
g_free (candidate->foundation); g_free (candidate->foundation);
...@@ -88,10 +92,10 @@ nice_candidate_jingle_priority (NiceCandidate *candidate) ...@@ -88,10 +92,10 @@ nice_candidate_jingle_priority (NiceCandidate *candidate)
} }
/* ICE-13 §4.1.2; returns number between 1 and 0x7effffff */ /* ICE-15 §4.1.2.1; returns number between 1 and 0x7effffff */
G_GNUC_CONST G_GNUC_CONST
static guint32 guint32
_candidate_ice_priority ( nice_candidate_ice_priority_full (
// must be ∈ (0, 126) (max 2^7 - 2) // must be ∈ (0, 126) (max 2^7 - 2)
guint type_preference, guint type_preference,
// must be ∈ (0, 65535) (max 2^16 - 1) // must be ∈ (0, 65535) (max 2^16 - 1)
...@@ -114,12 +118,28 @@ nice_candidate_ice_priority (const NiceCandidate *candidate) ...@@ -114,12 +118,28 @@ nice_candidate_ice_priority (const NiceCandidate *candidate)
switch (candidate->type) switch (candidate->type)
{ {
case NICE_CANDIDATE_TYPE_HOST: type_preference = 120; break; case NICE_CANDIDATE_TYPE_HOST:
case NICE_CANDIDATE_TYPE_PEER_REFLEXIVE: type_preference = 110; break; type_preference = NICE_CANDIDATE_TYPE_PREF_HOST; break;
case NICE_CANDIDATE_TYPE_SERVER_REFLEXIVE: type_preference = 100; break; case NICE_CANDIDATE_TYPE_PEER_REFLEXIVE:
case NICE_CANDIDATE_TYPE_RELAYED: type_preference = 60; break; type_preference = NICE_CANDIDATE_TYPE_PREF_PEER_REFLEXIVE; break;
case NICE_CANDIDATE_TYPE_SERVER_REFLEXIVE:
type_preference = NICE_CANDIDATE_TYPE_PREF_SERVER_REFLEXIVE; break;
case NICE_CANDIDATE_TYPE_RELAYED:
type_preference = NICE_CANDIDATE_TYPE_PREF_RELAYED; break;
} }
return _candidate_ice_priority (type_preference, 1, candidate->component_id); /* return _candidate_ice_priority (type_preference, 1, candidate->component_id); */
return nice_candidate_ice_priority_full (type_preference, 1, candidate->component_id);
} }
/**
* Calculates the pair priority as specified in ICE -15 spec 5.7.2.
*/
guint64
nice_candidate_pair_priority (guint32 o_prio, guint32 a_prio)
{
guint32 max = o_prio > a_prio ? o_prio : a_prio;
guint32 min = o_prio < a_prio ? o_prio : a_prio;
return ((guint64)1 << 32) * min + 2 * max + (o_prio > a_prio ? 1 : 0);
}
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
* *
* Contributors: * Contributors:
* Dafydd Harries, Collabora Ltd. * Dafydd Harries, Collabora Ltd.
* Kai Vehmanen, Nokia
* *
* Alternatively, the contents of this file may be used under the terms of the * 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 * the GNU Lesser General Public License Version 2.1 (the "LGPL"), in which
...@@ -42,6 +43,11 @@ ...@@ -42,6 +43,11 @@
G_BEGIN_DECLS G_BEGIN_DECLS
#define NICE_CANDIDATE_TYPE_PREF_HOST 120
#define NICE_CANDIDATE_TYPE_PREF_PEER_REFLEXIVE 110
#define NICE_CANDIDATE_TYPE_PREF_SERVER_REFLEXIVE 100
#define NICE_CANDIDATE_TYPE_PREF_RELAYED 60
typedef enum typedef enum
{ {
NICE_CANDIDATE_TYPE_HOST, NICE_CANDIDATE_TYPE_HOST,
...@@ -61,17 +67,15 @@ struct _NiceCandidate ...@@ -61,17 +67,15 @@ struct _NiceCandidate
{ {
NiceCandidateType type; NiceCandidateType type;
NiceCandidateTransport transport; NiceCandidateTransport transport;
guint id;
NiceAddress addr; NiceAddress addr;
NiceAddress base_addr; NiceAddress base_addr;
guint32 priority; guint32 priority;
guint stream_id; guint stream_id;
guint component_id; guint component_id;
// guint generation; gchar *foundation;
gchar *foundation; /* note: if NULL, derive foundation from 'id' */ NiceUDPSocket *sockptr; /* XXX: to replace 'sock', see comment above */
NiceUDPSocket sock; gchar *username; /* pointer to a NULL-terminated username string */
gchar username[128]; /* XXX: why 128 chars? */ gchar *password; /* pointer to a NULL-terminated password string */
gchar password[128]; /* XXX: why 128 chars? */
GSource *source; GSource *source;
}; };
...@@ -85,9 +89,15 @@ nice_candidate_free (NiceCandidate *candidate); ...@@ -85,9 +89,15 @@ nice_candidate_free (NiceCandidate *candidate);
gfloat gfloat
nice_candidate_jingle_priority (NiceCandidate *candidate); nice_candidate_jingle_priority (NiceCandidate *candidate);
guint32
nice_candidate_ice_priority_full (guint type_pref, guint local_pref, guint component_id);
guint32 guint32
nice_candidate_ice_priority (const NiceCandidate *candidate); nice_candidate_ice_priority (const NiceCandidate *candidate);
guint64
nice_candidate_pair_priority (guint32 o_prio, guint32 a_prio);
G_END_DECLS G_END_DECLS
#endif /* _CANDIDATE_H */ #endif /* _CANDIDATE_H */
......
...@@ -55,22 +55,50 @@ component_free (Component *cmp) ...@@ -55,22 +55,50 @@ component_free (Component *cmp)
{ {
GSList *i; GSList *i;
for (i = cmp->local_candidates; i; i = i->next) for (i = cmp->local_candidates; i; i = i->next) {
{
NiceCandidate *candidate = i->data; NiceCandidate *candidate = i->data;
nice_candidate_free (candidate); nice_candidate_free (candidate);
} }
for (i = cmp->remote_candidates; i; i = i->next) for (i = cmp->remote_candidates; i; i = i->next) {
{
NiceCandidate *candidate = i->data; NiceCandidate *candidate = i->data;
nice_candidate_free (candidate); nice_candidate_free (candidate);
} }
for (i = cmp->sockets; i; i = i->next) {
NiceUDPSocket *udpsocket = i->data;
nice_udp_socket_close (udpsocket);
}
for (i = cmp->gsources; i; i = i->next) {
GSource *source = i->data;
g_source_destroy (source);
}
g_slist_free (cmp->gsources),
cmp->gsources = NULL;
g_slist_free (cmp->local_candidates); g_slist_free (cmp->local_candidates);
g_slist_free (cmp->remote_candidates); g_slist_free (cmp->remote_candidates);
g_slist_free (cmp->sockets);
g_slice_free (Component, cmp); g_slice_free (Component, cmp);
} }
NiceUDPSocket *
component_find_udp_socket_by_fd (Component *component, guint fd)
{
GSList *i;
/* XXX: this won't work anymore, a single fd may be used
* by multiple candidates */
for (i = component->sockets; i; i = i->next)
{
NiceUDPSocket *sockptr = i->data;
if (sockptr->fileno == fd)
return sockptr;
}
return NULL;
}
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
* *
* Contributors: * Contributors:
* Dafydd Harries, Collabora Ltd. * Dafydd Harries, Collabora Ltd.
* Kai Vehmanen, Nokia
* *
* Alternatively, the contents of this file may be used under the terms of the * 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 * the GNU Lesser General Public License Version 2.1 (the "LGPL"), in which
...@@ -59,19 +60,35 @@ typedef enum ...@@ -59,19 +60,35 @@ typedef enum
typedef struct _Component Component; typedef struct _Component Component;
typedef struct _CandidatePair CandidatePair;
struct _CandidatePair
{
NiceCandidate *local;
NiceCandidate *remote;
guint64 priority; /**< candidate pair priority */
};
struct _Component struct _Component
{ {
ComponentType type; ComponentType type;
/* the local candidate that last received a valid connectivity check */
NiceCandidate *active_candidate;
/* the remote address that the last connectivity check came from */
NiceAddress peer_addr;
guint id; guint id;
NiceComponentState state; NiceComponentState state;
GSList *local_candidates; GSList *local_candidates; /**< list of Candidate objs */
GSList *remote_candidates; GSList *remote_candidates; /**< list of Candidate objs */
GSList *sockets; /**< list of NiceUDPSocket objs */
GSList *gsources; /**< list of GSource objs */
CandidatePair selected_pair; /**< independent from checklists,
see ICE 11.1.1 (ID-15) */
/* XXX: **to be removed**
* --cut--
GSList *checks; GSList *checks;
* the local candidate that last received a valid connectivity */
NiceCandidate *active_candidate;
/* the remote address that the last connectivity check came from */
NiceAddress peer_addr;
/* --cut-- */
}; };
Component * Component *
...@@ -82,6 +99,9 @@ component_new ( ...@@ -82,6 +99,9 @@ component_new (
void void
component_free (Component *cmp); component_free (Component *cmp);
NiceUDPSocket *
component_find_udp_socket_by_fd (Component *component, guint fd);
G_END_DECLS G_END_DECLS
#endif /* _NICE_COMPONENT_H */ #endif /* _NICE_COMPONENT_H */
......
This diff is collapsed.
/*
* This file is part of the Nice GLib ICE library.
*
* (C) 2006, 2007 Collabora Ltd.
* Contact: Dafydd Harries
* (C) 2006, 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:
* Dafydd Harries, Collabora Ltd.
* 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.
*/
#ifndef _NICE_CONNCHECK_H
#define _NICE_CONNCHECK_H
/* note: this is a private header to libnice */
#include "agent.h"
#include "stream.h"
#include "stun.h" /* XXX: using the old STUN API, to be removed */
#include "stun/conncheck.h" /* note: the new STUN API */
typedef enum
{
NICE_CHECK_WAITING = 1, /**< waiting to be scheduled */
NICE_CHECK_IN_PROGRESS, /**< conn. checks started */
NICE_CHECK_SUCCEEDED, /**< conn. succesfully checked */
NICE_CHECK_FAILED, /**< no connectivity, retransmissions ceased */
NICE_CHECK_FROZEN, /**< waiting to be scheduled to WAITING */
NICE_CHECK_CANCELLED /**< check cancelled */
} NiceCheckState;
typedef enum
{
NICE_CHECKLIST_NOT_STARTED = 1,
NICE_CHECKLIST_RUNNING,
NICE_CHECKLIST_COMPLETED,
NICE_CHECKLIST_FAILED
} NiceCheckListState;
typedef struct _CandidateCheckPair CandidateCheckPair;
struct _CandidateCheckPair
{
NiceAgent *agent; /* back pointer to owner */
guint stream_id;
guint component_id;
NiceCandidate *local;
NiceCandidate *remote;
gchar *foundation;
NiceCheckState state;
gboolean nominated;
guint64 priority;
GTimeVal next_tick; /* next tick timestamp */
stun_bind_t *stun_ctx;
};
int conn_check_add_for_candidate (NiceAgent *agent, guint stream_id, Component *component, NiceCandidate *remote);
void conn_check_free_item (gpointer data, gpointer user_data);
void conn_check_free (NiceAgent *agent);
void conn_check_schedule_next (NiceAgent *agent);
int conn_check_send (NiceAgent *agent, CandidateCheckPair *pair);
gboolean conn_check_prune_stream (NiceAgent *agent, guint stream_id);
gboolean conn_check_handle_inbound_stun (NiceAgent *agent, Stream *stream, Component *component, const NiceAddress *from, gchar *buf, guint len);
/* functions using the old STUN API:
* ---------------------------------*/
void conn_check_handle_inbound_stun_old (
NiceAgent *agent,
Stream *stream,
Component *component,
NiceCandidate *local,
NiceAddress from,
StunMessage *msg);
#endif /*_NICE_CONNCHECK_H */
This diff is collapsed.
/*
* This file is part of the Nice GLib ICE library.
*
* (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.
*/
#ifndef _NICE_DISCOVERY_H
#define _NICE_DISCOVERY_H
/* note: this is a private header to libnice */
#include "stun/bind.h"
#include "agent.h"
typedef struct _CandidateDiscovery CandidateDiscovery;
struct _CandidateDiscovery
{
NiceAgent *agent; /**< back pointer to owner */
NiceCandidateType type; /**< candidate type STUN or TURN */
guint socket; /**< XXX: should be taken from local cand: existing socket to use */
NiceUDPSocket *nicesock; /**< XXX: should be taken from local cand: existing socket to use */
const gchar *server_addr; /**< STUN/TURN server address, not owned */
NiceAddress *interface; /**< Address of local interface */
stun_bind_t *stun_ctx;
GTimeVal next_tick; /**< next tick timestamp */
gboolean pending; /**< is discovery in progress? */
gboolean done; /**< is discovery complete? */
Stream *stream;
Component *component;
};
void discovery_free_item (gpointer data, gpointer user_data);
void discovery_free (NiceAgent *agent);
gboolean discovery_prune_stream (NiceAgent *agent, guint stream_id);
void discovery_schedule (NiceAgent *agent);
NiceCandidate *discovery_add_local_host_candidate (
NiceAgent *agent,
guint stream_id,
guint component_id,
NiceAddress *address);
NiceCandidate*
discovery_add_server_reflexive_candidate (
NiceAgent *agent,
guint stream_id,
guint component_id,
NiceAddress *address,
NiceUDPSocket *base_socket);
#endif /*_NICE_CONNCHECK_H */
...@@ -35,6 +35,8 @@ ...@@ -35,6 +35,8 @@
* file under either the MPL or the LGPL. * file under either the MPL or the LGPL.
*/ */
#include <string.h>
#include "stream.h" #include "stream.h"
Stream * Stream *
...@@ -44,6 +46,9 @@ stream_new (void) ...@@ -44,6 +46,9 @@ stream_new (void)
stream = g_slice_new0 (Stream); stream = g_slice_new0 (Stream);
stream->component = component_new (COMPONENT_TYPE_RTP); stream->component = component_new (COMPONENT_TYPE_RTP);
stream->n_components = 1;
stream->initial_binding_request_received = FALSE;
return stream; return stream;
} }
......
...@@ -44,13 +44,24 @@ ...@@ -44,13 +44,24 @@
G_BEGIN_DECLS G_BEGIN_DECLS
/* Following do not including the terminating NULL */
#define NICE_STREAM_MAX_UFRAG_LEN 4
#define NICE_STREAM_MAX_PWD_LEN 22
typedef struct _Stream Stream; typedef struct _Stream Stream;
struct _Stream struct _Stream
{ {
guint id; guint id;
guint n_components;
gboolean initial_binding_request_received;
/* XXX: streams can have multiple components */ /* XXX: streams can have multiple components */
Component *component; Component *component;
gchar local_ufrag[NICE_STREAM_MAX_UFRAG_LEN + 1];
gchar local_password[NICE_STREAM_MAX_PWD_LEN + 1];
gchar remote_ufrag[NICE_STREAM_MAX_UFRAG_LEN + 1];
gchar remote_password[NICE_STREAM_MAX_PWD_LEN + 1];
}; };
Stream * Stream *
......
...@@ -36,15 +36,18 @@ ...@@ -36,15 +36,18 @@
*/ */
#include "agent.h" #include "agent.h"
#include "agent-priv.h"
#include "udp-fake.h" #include "udp-fake.h"
#include <string.h>
int int
main (void) main (void)
{ {
NiceAgent *agent; NiceAgent *agent;
NiceAddress addr = {0,}; NiceAddress addr;
NiceUDPSocketFactory factory; NiceUDPSocketFactory factory;
memset (&addr, 0, sizeof (addr));
g_type_init (); g_type_init ();
nice_udp_fake_socket_factory_init (&factory); nice_udp_fake_socket_factory_init (&factory);
......
This diff is collapsed.
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
* *
* Contributors: * Contributors:
* Dafydd Harries, Collabora Ltd. * Dafydd Harries, Collabora Ltd.
* Kai Vehmanen, Nokia
* *
* Alternatively, the contents of this file may be used under the terms of the * 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 * the GNU Lesser General Public License Version 2.1 (the "LGPL"), in which
...@@ -63,9 +64,10 @@ int ...@@ -63,9 +64,10 @@ int
main (void) main (void)
{ {
NiceAgent *agent; NiceAgent *agent;
NiceAddress addr = {0,}; NiceAddress addr;
NiceUDPSocketFactory factory; NiceUDPSocketFactory factory;
memset (&addr, 0, sizeof (addr));
g_type_init (); g_type_init ();
nice_udp_fake_socket_factory_init (&factory); nice_udp_fake_socket_factory_init (&factory);
...@@ -83,7 +85,7 @@ main (void) ...@@ -83,7 +85,7 @@ main (void)
candidates = nice_agent_get_local_candidates (agent, 1, 1); candidates = nice_agent_get_local_candidates (agent, 1, 1);
candidate = candidates->data; candidate = candidates->data;
sock = &candidate->sock; sock = candidate->sockptr;
g_slist_free (candidates); g_slist_free (candidates);
nice_udp_fake_socket_push_recv (sock, &addr, 6, "\x80hello"); nice_udp_fake_socket_push_recv (sock, &addr, 6, "\x80hello");
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
* *
* Contributors: * Contributors:
* Dafydd Harries, Collabora Ltd. * Dafydd Harries, Collabora Ltd.
* Kai Vehmanen, Nokia
* *
* Alternatively, the contents of this file may be used under the terms of the * 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 * the GNU Lesser General Public License Version 2.1 (the "LGPL"), in which
...@@ -66,13 +67,14 @@ int ...@@ -66,13 +67,14 @@ int
main (void) main (void)
{ {
NiceAgent *agent; NiceAgent *agent;
NiceAddress addr = {0,}; NiceAddress addr;
NiceUDPSocketFactory factory; NiceUDPSocketFactory factory;
NiceUDPSocket *sock; NiceUDPSocket *sock;
gint pipe_fds[2]; gint pipe_fds[2];
GSList *fds = NULL; GSList *fds = NULL;
GSList *readable; GSList *readable;
memset (&addr, 0, sizeof (addr));
g_type_init (); g_type_init ();
/* set up agent */ /* set up agent */
...@@ -91,7 +93,7 @@ main (void) ...@@ -91,7 +93,7 @@ main (void)
candidates = nice_agent_get_local_candidates (agent, 1, 1); candidates = nice_agent_get_local_candidates (agent, 1, 1);
candidate = candidates->data; candidate = candidates->data;
sock = &candidate->sock; sock = candidate->sockptr;
g_slist_free (candidates); g_slist_free (candidates);
} }
......
...@@ -42,11 +42,22 @@ main (void) ...@@ -42,11 +42,22 @@ main (void)
{ {
NiceCandidate *candidate; NiceCandidate *candidate;
/* test 1 */
candidate = nice_candidate_new (NICE_CANDIDATE_TYPE_HOST); candidate = nice_candidate_new (NICE_CANDIDATE_TYPE_HOST);
g_assert (nice_candidate_ice_priority (candidate) == 0x78000200); g_assert (nice_candidate_ice_priority (candidate) == 0x78000200);
g_assert (nice_candidate_jingle_priority (candidate) == 1.0); g_assert (nice_candidate_jingle_priority (candidate) == 1.0);
nice_candidate_free (candidate); nice_candidate_free (candidate);
/* test 2 */
/* 2^32*MIN(O,A) + 2*MAX(O,A) + (O>A?1:0)
= 2^32*1 + 2*5000 + 0
= 4294977296 */
g_assert (nice_candidate_pair_priority (1,5000) == 4294977296);
/* 2^32*1 + 2*5000 + 1 = 4294977297 */
g_assert (nice_candidate_pair_priority (5000, 1) == 4294977297);
return 0; return 0;
} }
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
* *
* Contributors: * Contributors:
* Dafydd Harries, Collabora Ltd. * Dafydd Harries, Collabora Ltd.
* Kai Vehmanen, Nokia
* *
* Alternatively, the contents of this file may be used under the terms of the * 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 * the GNU Lesser General Public License Version 2.1 (the "LGPL"), in which
...@@ -44,9 +45,10 @@ int ...@@ -44,9 +45,10 @@ int
main (void) main (void)
{ {
NiceAgent *agent; NiceAgent *agent;
NiceAddress addr = {0,}; NiceAddress addr;
NiceUDPSocketFactory factory; NiceUDPSocketFactory factory;
memset (&addr, 0, sizeof (addr));
g_type_init (); g_type_init ();
nice_udp_fake_socket_factory_init (&factory); nice_udp_fake_socket_factory_init (&factory);
...@@ -69,7 +71,7 @@ main (void) ...@@ -69,7 +71,7 @@ main (void)
candidates = nice_agent_get_local_candidates (agent, 1, 1); candidates = nice_agent_get_local_candidates (agent, 1, 1);
candidate = candidates->data; candidate = candidates->data;
g_slist_free (candidates); g_slist_free (candidates);
sock = &(candidate->sock); sock = candidate->sockptr;
nice_udp_fake_socket_push_recv (sock, &addr, 7, "\x80lalala"); nice_udp_fake_socket_push_recv (sock, &addr, 7, "\x80lalala");
len = nice_agent_recv (agent, candidate->stream_id, len = nice_agent_recv (agent, candidate->stream_id,
candidate->component_id, 1024, buf); candidate->component_id, 1024, buf);
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
* *
* Contributors: * Contributors:
* Dafydd Harries, Collabora Ltd. * Dafydd Harries, Collabora Ltd.
* Kai Vehmanen, Nokia
* *
* Alternatively, the contents of this file may be used under the terms of the * 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 * the GNU Lesser General Public License Version 2.1 (the "LGPL"), in which
...@@ -66,7 +67,7 @@ static gboolean ...@@ -66,7 +67,7 @@ static gboolean
fd_is_readable (guint fd) fd_is_readable (guint fd)
{ {
fd_set fds; fd_set fds;
struct timeval timeout = {0,}; struct timeval timeout = { 0, 0 };
FD_ZERO (&fds); FD_ZERO (&fds);
FD_SET (fd, &fds); FD_SET (fd, &fds);
...@@ -101,7 +102,7 @@ send_connectivity_check ( ...@@ -101,7 +102,7 @@ send_connectivity_check (
candidates = nice_agent_get_local_candidates (agent, 1, 1); candidates = nice_agent_get_local_candidates (agent, 1, 1);
g_assert (g_slist_length (candidates) > 0); g_assert (g_slist_length (candidates) > 0);
local = candidates->data; local = candidates->data;
g_assert (local->id == 1); g_assert (strncmp (local->foundation, "1", 1) == 0);
g_slist_free (candidates); g_slist_free (candidates);
} }
...@@ -114,7 +115,7 @@ send_connectivity_check ( ...@@ -114,7 +115,7 @@ send_connectivity_check (
g_slist_free (candidates); g_slist_free (candidates);
} }
sock = &local->sock; sock = local->sockptr;
username = g_strconcat (local->username, remote->username, NULL); username = g_strconcat (local->username, remote->username, NULL);
...@@ -135,11 +136,12 @@ send_connectivity_check ( ...@@ -135,11 +136,12 @@ send_connectivity_check (
{ {
StunMessage *msg; StunMessage *msg;
NiceAddress addr = {0,}; NiceAddress addr;
gchar packed[1024]; gchar packed[1024];
gchar *dump; gchar *dump;
guint len; guint len;
memset (&addr, 0, sizeof (addr));
len = nice_udp_fake_socket_pop_send (sock, &addr, 1024, packed); len = nice_udp_fake_socket_pop_send (sock, &addr, 1024, packed);
g_assert (nice_address_equal (&addr, remote_addr)); g_assert (nice_address_equal (&addr, remote_addr));
msg = stun_message_unpack (len, packed); msg = stun_message_unpack (len, packed);
...@@ -154,11 +156,12 @@ send_connectivity_check ( ...@@ -154,11 +156,12 @@ send_connectivity_check (
{ {
StunMessage *msg; StunMessage *msg;
NiceAddress addr = {0,}; NiceAddress addr;
gchar packed[1024]; gchar packed[1024];
gchar *dump; gchar *dump;
guint len; guint len;
memset (&addr, 0, sizeof (addr));
len = nice_udp_fake_socket_pop_send (sock, &addr, 1024, packed); len = nice_udp_fake_socket_pop_send (sock, &addr, 1024, packed);
g_assert (nice_address_equal (&addr, remote_addr)); g_assert (nice_address_equal (&addr, remote_addr));
msg = stun_message_unpack (len, packed); msg = stun_message_unpack (len, packed);
...@@ -179,9 +182,11 @@ main (void) ...@@ -179,9 +182,11 @@ main (void)
{ {
NiceUDPSocketFactory factory; NiceUDPSocketFactory factory;
NiceAgent *agent; NiceAgent *agent;
NiceAddress local_addr = {0,}; NiceAddress local_addr;
NiceAddress remote_addr = {0,}; NiceAddress remote_addr;
memset (&local_addr, 0, sizeof (local_addr));
memset (&remote_addr, 0, sizeof (remote_addr));
g_type_init (); g_type_init ();
/* set up */ /* set up */
...@@ -221,7 +226,7 @@ main (void) ...@@ -221,7 +226,7 @@ main (void)
candidates = nice_agent_get_local_candidates (agent, 1, 1); candidates = nice_agent_get_local_candidates (agent, 1, 1);
candidate = candidates->data; candidate = candidates->data;
sock = &candidate->sock; sock = candidate->sockptr;
g_slist_free (candidates); g_slist_free (candidates);
} }
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
* *
* Contributors: * Contributors:
* Dafydd Harries, Collabora Ltd. * Dafydd Harries, Collabora Ltd.
* Kai Vehmanen, Nokia
* *
* Alternatively, the contents of this file may be used under the terms of the * 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 * the GNU Lesser General Public License Version 2.1 (the "LGPL"), in which
...@@ -47,12 +48,13 @@ test_stun_no_password ( ...@@ -47,12 +48,13 @@ test_stun_no_password (
NiceAddress from, NiceAddress from,
NiceUDPSocket *sock) NiceUDPSocket *sock)
{ {
NiceAddress to = {0,}; NiceAddress to;
guint len; guint len;
gchar buf[1024]; gchar buf[1024];
guint packed_len; guint packed_len;
gchar *packed; gchar *packed;
memset (&to, 0, sizeof (to));
memset (buf, '\0', 1024); memset (buf, '\0', 1024);
{ {
...@@ -97,12 +99,13 @@ test_stun_invalid_password ( ...@@ -97,12 +99,13 @@ test_stun_invalid_password (
NiceAddress from, NiceAddress from,
NiceUDPSocket *sock) NiceUDPSocket *sock)
{ {
NiceAddress to = {0,}; NiceAddress to;
guint len; guint len;
gchar buf[1024]; gchar buf[1024];
guint packed_len; guint packed_len;
gchar *packed; gchar *packed;
memset (&to, 0, sizeof (to));
memset (buf, '\0', 1024); memset (buf, '\0', 1024);
{ {
...@@ -149,13 +152,14 @@ test_stun_valid_password ( ...@@ -149,13 +152,14 @@ test_stun_valid_password (
NiceCandidate *candidate, NiceCandidate *candidate,
NiceUDPSocket *sock) NiceUDPSocket *sock)
{ {
NiceAddress to = {0,}; NiceAddress to;
guint len; guint len;
guint packed_len; guint packed_len;
gchar buf[1024]; gchar buf[1024];
gchar *packed; gchar *packed;
gchar *username; gchar *username;
memset (&to, 0, sizeof (to));
memset (buf, '\0', 1024); memset (buf, '\0', 1024);
username = g_strconcat (candidate->username, "username", NULL); username = g_strconcat (candidate->username, "username", NULL);
...@@ -207,13 +211,15 @@ int ...@@ -207,13 +211,15 @@ int
main (void) main (void)
{ {
NiceAgent *agent; NiceAgent *agent;
NiceAddress local_addr = {0,}; NiceAddress local_addr;
NiceAddress remote_addr = {0,}; NiceAddress remote_addr;
NiceCandidate *candidate; NiceCandidate *candidate;
NiceUDPSocketFactory factory; NiceUDPSocketFactory factory;
NiceUDPSocket *sock; NiceUDPSocket *sock;
GSList *candidates; GSList *candidates;
memset (&local_addr, 0, sizeof (local_addr));
memset (&remote_addr, 0, sizeof (remote_addr));
g_type_init (); g_type_init ();
nice_udp_fake_socket_factory_init (&factory); nice_udp_fake_socket_factory_init (&factory);
...@@ -231,7 +237,7 @@ main (void) ...@@ -231,7 +237,7 @@ main (void)
candidates = nice_agent_get_local_candidates (agent, 1, 1); candidates = nice_agent_get_local_candidates (agent, 1, 1);
candidate = candidates->data; candidate = candidates->data;
sock = &(candidate->sock); sock = candidate->sockptr;
g_slist_free (candidates); g_slist_free (candidates);
/* run tests */ /* run tests */
......
...@@ -39,16 +39,19 @@ ...@@ -39,16 +39,19 @@
#include "udp-fake.h" #include "udp-fake.h"
#include "agent.h" #include "agent.h"
#include "agent-priv.h"
gint gint
main (void) main (void)
{ {
NiceAgent *agent; NiceAgent *agent;
NiceAddress addr_local = {0,}, addr_remote = {0,}; NiceAddress addr_local, addr_remote;
NiceCandidate *candidate; NiceCandidate *candidate;
NiceUDPSocketFactory factory; NiceUDPSocketFactory factory;
GSList *candidates; GSList *candidates;
memset (&addr_local, 0, sizeof (addr_local));
memset (&addr_remote, 0, sizeof (addr_remote));
g_type_init (); g_type_init ();
nice_udp_fake_socket_factory_init (&factory); nice_udp_fake_socket_factory_init (&factory);
...@@ -78,7 +81,7 @@ main (void) ...@@ -78,7 +81,7 @@ main (void)
/* fake socket manager uses incremental port numbers starting at 1 */ /* fake socket manager uses incremental port numbers starting at 1 */
addr_local.port = 1; addr_local.port = 1;
g_assert (nice_address_equal (&(candidate->addr), &addr_local)); g_assert (nice_address_equal (&(candidate->addr), &addr_local));
g_assert (candidate->id == 1); g_assert (strncmp (candidate->foundation, "1", 1) == 0);
g_slist_free (candidates); g_slist_free (candidates);
/* add remote candidate */ /* add remote candidate */
......
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