Commit 833c1aa4 authored by Olivier Crête's avatar Olivier Crête

candidate: Hide the internal implementation from API

This is slightly an API break, but it should never have been public.
parent 620eec94
This diff is collapsed.
/*
* This file is part of the Nice GLib ICE library.
*
* (C) 2006-2020 Collabora Ltd.
* Contact: Youness Alaoui
* Contact: Olivier Crete
* (C) 2006-2009 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.
* Youness Alaoui, 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 __LIBNICE_CANDIDATE_PRIV_H__
#define __LIBNICE_CANDIDATE_PRIV_H__
#include <glib.h>
#include <glib-object.h>
#include "candidate.h"
#include "socket/socket.h"
G_BEGIN_DECLS
/* Constants for determining candidate priorities */
#define NICE_CANDIDATE_TYPE_PREF_HOST 120
#define NICE_CANDIDATE_TYPE_PREF_PEER_REFLEXIVE 110
#define NICE_CANDIDATE_TYPE_PREF_NAT_ASSISTED 105
#define NICE_CANDIDATE_TYPE_PREF_SERVER_REFLEXIVE 100
#define NICE_CANDIDATE_TYPE_PREF_RELAYED_UDP 30
#define NICE_CANDIDATE_TYPE_PREF_RELAYED 20
/* Priority preference constants for MS-ICE compatibility */
#define NICE_CANDIDATE_TRANSPORT_MS_PREF_UDP 15
#define NICE_CANDIDATE_TRANSPORT_MS_PREF_TCP 6
#define NICE_CANDIDATE_DIRECTION_MS_PREF_PASSIVE 2
#define NICE_CANDIDATE_DIRECTION_MS_PREF_ACTIVE 5
typedef struct _NiceCandidateImpl NiceCandidateImpl;
typedef struct _TurnServer TurnServer;
/**
* TurnServer:
* @ref_count: Reference count for the structure.
* @server: The #NiceAddress of the TURN server
* @username: The TURN username
* @password: The TURN password
* @decoded_username: The base64 decoded TURN username
* @decoded_password: The base64 decoded TURN password
* @decoded_username_len: The length of @decoded_username
* @decoded_password_len: The length of @decoded_password
* @type: The #NiceRelayType of the server
* @preference: A unique identifier used to compute priority
*
* A structure to store the TURN relay settings
*/
struct _TurnServer
{
gint ref_count;
NiceAddress server;
gchar *username;
gchar *password;
guint8 *decoded_username;
guint8 *decoded_password;
gsize decoded_username_len;
gsize decoded_password_len;
NiceRelayType type;
guint preference;
};
/**
* NiceCandidateImpl:
* @c: The #NiceCandidate
* @turn: The #TurnServer settings if the candidate is
* of type %NICE_CANDIDATE_TYPE_RELAYED
* @sockptr: The underlying socket
* @keepalive_next_tick: The timestamp for the next keepalive
*
* A structure to represent an ICE candidate
*/
struct _NiceCandidateImpl
{
NiceCandidate c;
TurnServer *turn;
NiceSocket *sockptr;
guint64 keepalive_next_tick; /* next tick timestamp */
};
G_END_DECLS
#endif /* __LIBNICE_CANDIDATE_H__ */
\ No newline at end of file
......@@ -53,6 +53,7 @@
#include "agent.h"
#include "component.h"
#include "interfaces.h"
#include "candidate-priv.h"
G_DEFINE_BOXED_TYPE (NiceCandidate, nice_candidate, nice_candidate_copy,
nice_candidate_free);
......@@ -65,17 +66,17 @@ G_DEFINE_BOXED_TYPE (NiceCandidate, nice_candidate, nice_candidate_copy,
NICEAPI_EXPORT NiceCandidate *
nice_candidate_new (NiceCandidateType type)
{
NiceCandidate *candidate;
NiceCandidateImpl *c;
candidate = g_slice_new0 (NiceCandidate);
candidate->type = type;
return candidate;
c = g_slice_new0 (NiceCandidateImpl);
c->c.type = type;
return (NiceCandidate *) c;
}
NICEAPI_EXPORT void
nice_candidate_free (NiceCandidate *candidate)
{
NiceCandidateImpl *c = (NiceCandidateImpl *) candidate;
/* better way of checking if socket is allocated? */
if (candidate->username)
......@@ -84,10 +85,10 @@ nice_candidate_free (NiceCandidate *candidate)
if (candidate->password)
g_free (candidate->password);
if (candidate->turn)
turn_server_unref (candidate->turn);
if (c->turn)
turn_server_unref (c->turn);
g_slice_free (NiceCandidate, candidate);
g_slice_free (NiceCandidateImpl, c);
}
......@@ -199,6 +200,7 @@ nice_candidate_ip_local_preference (const NiceCandidate *candidate)
static guint16
nice_candidate_ice_local_preference (const NiceCandidate *candidate)
{
const NiceCandidateImpl *c = (NiceCandidateImpl *) candidate;
guint direction_preference = 0;
guint turn_preference = 0;
......@@ -235,8 +237,8 @@ nice_candidate_ice_local_preference (const NiceCandidate *candidate)
* creation time.
*/
if (candidate->type == NICE_CANDIDATE_TYPE_RELAYED) {
g_assert (candidate->turn);
turn_preference = candidate->turn->preference;
g_assert (c->turn);
turn_preference = c->turn->preference;
}
return nice_candidate_ice_local_preference_full (direction_preference,
......@@ -267,6 +269,7 @@ nice_candidate_ms_ice_local_preference_full (guint transport_preference,
static guint32
nice_candidate_ms_ice_local_preference (const NiceCandidate *candidate)
{
const NiceCandidateImpl *c = (NiceCandidateImpl *) candidate;
guint transport_preference = 0;
guint direction_preference = 0;
guint turn_preference = 0;
......@@ -292,8 +295,8 @@ nice_candidate_ms_ice_local_preference (const NiceCandidate *candidate)
* creation time.
*/
if (candidate->type == NICE_CANDIDATE_TYPE_RELAYED) {
g_assert (candidate->turn);
turn_preference = candidate->turn->preference;
g_assert (c->turn);
turn_preference = c->turn->preference;
}
return nice_candidate_ms_ice_local_preference_full(transport_preference,
......@@ -305,6 +308,7 @@ static guint8
nice_candidate_ice_type_preference (const NiceCandidate *candidate,
gboolean reliable, gboolean nat_assisted)
{
const NiceCandidateImpl *c = (NiceCandidateImpl *) candidate;
guint8 type_preference;
switch (candidate->type)
......@@ -322,7 +326,7 @@ nice_candidate_ice_type_preference (const NiceCandidate *candidate,
type_preference = NICE_CANDIDATE_TYPE_PREF_SERVER_REFLEXIVE;
break;
case NICE_CANDIDATE_TYPE_RELAYED:
if (candidate->turn->type == NICE_RELAY_TYPE_TURN_UDP)
if (c->turn->type == NICE_RELAY_TYPE_TURN_UDP)
type_preference = NICE_CANDIDATE_TYPE_PREF_RELAYED_UDP;
else
type_preference = NICE_CANDIDATE_TYPE_PREF_RELAYED;
......@@ -400,18 +404,19 @@ nice_candidate_pair_priority_to_string (guint64 prio, gchar *string)
NICEAPI_EXPORT NiceCandidate *
nice_candidate_copy (const NiceCandidate *candidate)
{
NiceCandidate *copy;
const NiceCandidateImpl *c = (NiceCandidateImpl *)candidate;
NiceCandidateImpl *copy;
g_return_val_if_fail (candidate != NULL, NULL);
g_return_val_if_fail (c != NULL, NULL);
copy = nice_candidate_new (candidate->type);
memcpy (copy, candidate, sizeof(NiceCandidate));
copy = (NiceCandidateImpl *) nice_candidate_new (candidate->type);
memcpy (copy, candidate, sizeof(NiceCandidateImpl));
copy->turn = NULL;
copy->username = g_strdup (copy->username);
copy->password = g_strdup (copy->password);
copy->c.username = g_strdup (copy->c.username);
copy->c.password = g_strdup (copy->c.password);
return copy;
return (NiceCandidate *) copy;
}
NICEAPI_EXPORT gboolean
......
......@@ -59,19 +59,6 @@
G_BEGIN_DECLS
/* Constants for determining candidate priorities */
#define NICE_CANDIDATE_TYPE_PREF_HOST 120
#define NICE_CANDIDATE_TYPE_PREF_PEER_REFLEXIVE 110
#define NICE_CANDIDATE_TYPE_PREF_NAT_ASSISTED 105
#define NICE_CANDIDATE_TYPE_PREF_SERVER_REFLEXIVE 100
#define NICE_CANDIDATE_TYPE_PREF_RELAYED_UDP 30
#define NICE_CANDIDATE_TYPE_PREF_RELAYED 20
/* Priority preference constants for MS-ICE compatibility */
#define NICE_CANDIDATE_TRANSPORT_MS_PREF_UDP 15
#define NICE_CANDIDATE_TRANSPORT_MS_PREF_TCP 6
#define NICE_CANDIDATE_DIRECTION_MS_PREF_PASSIVE 2
#define NICE_CANDIDATE_DIRECTION_MS_PREF_ACTIVE 5
/* Max foundation size '1*32ice-char' plus terminating NULL, ICE ID-19 */
/**
......@@ -150,37 +137,6 @@ typedef enum {
typedef struct _NiceCandidate NiceCandidate;
typedef struct _TurnServer TurnServer;
/**
* TurnServer:
* @ref_count: Reference count for the structure.
* @server: The #NiceAddress of the TURN server
* @username: The TURN username
* @password: The TURN password
* @decoded_username: The base64 decoded TURN username
* @decoded_password: The base64 decoded TURN password
* @decoded_username_len: The length of @decoded_username
* @decoded_password_len: The length of @decoded_password
* @type: The #NiceRelayType of the server
* @preference: A unique identifier used to compute priority
*
* A structure to store the TURN relay settings
*/
struct _TurnServer
{
gint ref_count;
NiceAddress server;
gchar *username;
gchar *password;
guint8 *decoded_username;
guint8 *decoded_password;
gsize decoded_username_len;
gsize decoded_password_len;
NiceRelayType type;
guint preference;
};
/**
* NiceCandidate:
......@@ -196,10 +152,6 @@ struct _TurnServer
* by nice_agent_set_local_credentials() or nice_agent_set_remote_credentials())
* @password: The candidate-specific password to use (overrides the one set
* by nice_agent_set_local_credentials() or nice_agent_set_remote_credentials())
* @turn: The #TurnServer settings if the candidate is
* of type %NICE_CANDIDATE_TYPE_RELAYED
* @sockptr: The underlying socket
* @keepalive_next_tick: The timestamp for the next keepalive
*
* A structure to represent an ICE candidate
<note>
......@@ -223,9 +175,6 @@ struct _NiceCandidate
gchar foundation[NICE_CANDIDATE_MAX_FOUNDATION];
gchar *username; /* pointer to a nul-terminated username string */
gchar *password; /* pointer to a nul-terminated password string */
TurnServer *turn;
gpointer sockptr;
guint64 keepalive_next_tick; /* next tick timestamp */
};
/**
......
......@@ -177,7 +177,7 @@ nice_component_remove_socket (NiceAgent *agent, NiceComponent *cmp,
conn_check_prune_socket (agent, stream, cmp, nsocket);
for (i = cmp->local_candidates; i;) {
NiceCandidate *candidate = i->data;
NiceCandidateImpl *candidate = (NiceCandidateImpl *) i->data;
GSList *next = i->next;
if (!nice_socket_is_based_on (candidate->sockptr, nsocket)) {
......@@ -194,12 +194,11 @@ nice_component_remove_socket (NiceAgent *agent, NiceComponent *cmp,
refresh_prune_candidate (agent, candidate);
if (candidate->sockptr != nsocket && stream) {
discovery_prune_socket (agent, candidate->sockptr);
conn_check_prune_socket (agent, stream, cmp,
candidate->sockptr);
conn_check_prune_socket (agent, stream, cmp, candidate->sockptr);
nice_component_detach_socket (cmp, candidate->sockptr);
}
agent_remove_local_candidate (agent, candidate);
nice_candidate_free (candidate);
agent_remove_local_candidate (agent, (NiceCandidate *) candidate);
nice_candidate_free ((NiceCandidate *) candidate);
cmp->local_candidates = g_slist_delete_link (cmp->local_candidates, i);
i = next;
......@@ -209,7 +208,7 @@ nice_component_remove_socket (NiceAgent *agent, NiceComponent *cmp,
* peer-reflexive remote candidate
*/
for (i = cmp->remote_candidates; i;) {
NiceCandidate *candidate = i->data;
NiceCandidateImpl *candidate = i->data;
GSList *next = i->next;
if (candidate->sockptr != nsocket) {
......@@ -226,7 +225,7 @@ nice_component_remove_socket (NiceAgent *agent, NiceComponent *cmp,
if (stream)
conn_check_prune_socket (agent, stream, cmp, candidate->sockptr);
nice_candidate_free (candidate);
nice_candidate_free ((NiceCandidate *) candidate);
cmp->remote_candidates = g_slist_delete_link (cmp->remote_candidates, i);
i = next;
......@@ -236,16 +235,16 @@ nice_component_remove_socket (NiceAgent *agent, NiceComponent *cmp,
}
static gboolean
on_candidate_refreshes_pruned (NiceAgent *agent, NiceCandidate *candidate)
on_candidate_refreshes_pruned (NiceAgent *agent, NiceCandidateImpl *candidate)
{
NiceComponent *component;
if (agent_find_component (agent, candidate->stream_id,
candidate->component_id, NULL, &component)) {
if (agent_find_component (agent, candidate->c.stream_id,
candidate->c.component_id, NULL, &component)) {
nice_component_detach_socket (component, candidate->sockptr);
}
nice_candidate_free (candidate);
nice_candidate_free ((NiceCandidate *) candidate);
return G_SOURCE_REMOVE;
}
......@@ -263,10 +262,10 @@ nice_component_clean_turn_servers (NiceAgent *agent, NiceComponent *cmp)
cmp->turn_servers = NULL;
for (i = cmp->local_candidates; i;) {
NiceCandidate *candidate = i->data;
NiceCandidateImpl *candidate = i->data;
GSList *next = i->next;
if (candidate->type != NICE_CANDIDATE_TYPE_RELAYED) {
if (candidate->c.type != NICE_CANDIDATE_TYPE_RELAYED) {
i = next;
continue;
}
......@@ -290,7 +289,7 @@ nice_component_clean_turn_servers (NiceAgent *agent, NiceComponent *cmp)
cmp->selected_pair.priority = 0;
cmp->turn_candidate = candidate;
} else {
agent_remove_local_candidate (agent, candidate);
agent_remove_local_candidate (agent, (NiceCandidate *) candidate);
relay_candidates = g_slist_append(relay_candidates, candidate);
}
cmp->local_candidates = g_slist_delete_link (cmp->local_candidates, i);
......@@ -298,7 +297,7 @@ nice_component_clean_turn_servers (NiceAgent *agent, NiceComponent *cmp)
}
for (i = relay_candidates; i; i = i->next) {
NiceCandidate * candidate = i->data;
NiceCandidateImpl * candidate = i->data;
discovery_prune_socket (agent, candidate->sockptr);
if (stream) {
......@@ -350,7 +349,7 @@ nice_component_close (NiceAgent *agent, NiceComponent *cmp)
cmp->restart_candidate = NULL;
if (cmp->turn_candidate)
nice_candidate_free (cmp->turn_candidate),
nice_candidate_free ((NiceCandidate *) cmp->turn_candidate),
cmp->turn_candidate = NULL;
while (cmp->local_candidates) {
......@@ -405,23 +404,24 @@ nice_component_find_pair (NiceComponent *cmp, NiceAgent *agent, const gchar *lfo
CandidatePair result = { 0, };
for (i = cmp->local_candidates; i; i = i->next) {
NiceCandidate *candidate = i->data;
if (strncmp (candidate->foundation, lfoundation, NICE_CANDIDATE_MAX_FOUNDATION) == 0) {
NiceCandidateImpl *candidate = i->data;
if (strncmp (candidate->c.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) {
NiceCandidateImpl *candidate = i->data;
if (strncmp (candidate->c.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);
result.priority = agent_candidate_pair_priority (agent,
(NiceCandidate *) result.local, (NiceCandidate *) result.remote);
if (pair)
*pair = result;
return TRUE;
......@@ -446,7 +446,7 @@ nice_component_restart (NiceComponent *cmp)
/* note: do not remove the remote candidate that is
* currently part of the 'selected pair', see ICE
* 9.1.1.1. "ICE Restarts" (ID-19) */
if (candidate == cmp->selected_pair.remote) {
if (candidate == (NiceCandidate *) cmp->selected_pair.remote) {
if (cmp->restart_candidate)
nice_candidate_free (cmp->restart_candidate);
cmp->restart_candidate = candidate;
......@@ -483,8 +483,8 @@ nice_component_update_selected_pair (NiceAgent *agent, NiceComponent *component,
nice_candidate_pair_priority_to_string (pair->priority, priority);
nice_debug ("setting SELECTED PAIR for component %u: %s:%s (prio:%s).",
component->id, pair->local->foundation,
pair->remote->foundation, priority);
component->id, pair->local->c.foundation,
pair->remote->c.foundation, priority);
if (component->selected_pair.local &&
component->selected_pair.local == component->turn_candidate) {
......@@ -505,7 +505,8 @@ nice_component_update_selected_pair (NiceAgent *agent, NiceComponent *component,
component->selected_pair.priority = pair->priority;
component->selected_pair.stun_priority = pair->stun_priority;
nice_component_add_valid_candidate (agent, component, pair->remote);
nice_component_add_valid_candidate (agent, component,
(NiceCandidate *) pair->remote);
}
/*
......@@ -538,7 +539,7 @@ nice_component_find_remote_candidate (NiceComponent *component, const NiceAddres
* this candidate.
*/
NiceCandidate *
NiceCandidateImpl *
nice_component_set_selected_remote_candidate (NiceComponent *component,
NiceAgent *agent, NiceCandidate *candidate)
{
......@@ -581,8 +582,8 @@ nice_component_set_selected_remote_candidate (NiceComponent *component,
nice_component_clear_selected_pair (component);
component->selected_pair.local = local;
component->selected_pair.remote = remote;
component->selected_pair.local = (NiceCandidateImpl *) local;
component->selected_pair.remote = (NiceCandidateImpl *) remote;
component->selected_pair.priority = priority;
/* Get into fallback mode where packets from any source is accepted once
......@@ -590,7 +591,7 @@ nice_component_set_selected_remote_candidate (NiceComponent *component,
*/
component->fallback_mode = TRUE;
return local;
return (NiceCandidateImpl *) local;
}
static gint
......@@ -1631,8 +1632,8 @@ nice_component_get_sockets (NiceComponent *component)
GSList *item;
for (item = component->local_candidates; item; item = item->next) {
NiceCandidate *cand = item->data;
NiceSocket *nicesock = cand->sockptr;
NiceCandidateImpl *c = item->data;
NiceSocket *nicesock = c->sockptr;
if (nicesock->fileno && !g_ptr_array_find (array, nicesock->fileno, NULL))
g_ptr_array_add (array, g_object_ref (nicesock->fileno));
......
......@@ -46,7 +46,7 @@ typedef struct _NiceComponent NiceComponent;
#include "agent.h"
#include "agent-priv.h"
#include "candidate.h"
#include "candidate-priv.h"
#include "stun/stunagent.h"
#include "stun/usages/timer.h"
#include "pseudotcp.h"
......@@ -80,8 +80,8 @@ struct _CandidatePairKeepalive
struct _CandidatePair
{
NiceCandidate *local;
NiceCandidate *remote;
NiceCandidateImpl *local;
NiceCandidateImpl *remote;
guint64 priority; /* candidate pair priority */
guint32 stun_priority;
CandidatePairKeepalive keepalive;
......@@ -168,7 +168,7 @@ struct _NiceComponent {
see ICE 11.1. "Sending Media" (ID-19) */
gboolean fallback_mode; /* in this case, accepts packets from all, ignore candidate validation */
NiceCandidate *restart_candidate; /* for storing active remote candidate during a restart */
NiceCandidate *turn_candidate; /* for storing active turn candidate if turn servers have been cleared */
NiceCandidateImpl *turn_candidate; /* for storing active turn candidate if turn servers have been cleared */
/* I/O handling. The main context must always be non-NULL, and is used for all
* socket recv() operations. All io_callback emissions are invoked in this
* context too.
......@@ -253,7 +253,7 @@ NiceCandidate *
nice_component_find_remote_candidate (NiceComponent *component,
const NiceAddress *addr, NiceCandidateTransport transport);
NiceCandidate *
NiceCandidateImpl *
nice_component_set_selected_remote_candidate (NiceComponent *component,
NiceAgent *agent, NiceCandidate *candidate);
......
This diff is collapsed.
......@@ -225,6 +225,7 @@ static gboolean refresh_remove_async (NiceAgent *agent, gpointer pointer)
gsize password_len;
size_t buffer_len = 0;
CandidateRefresh *cand = (CandidateRefresh *) pointer;
NiceCandidateImpl *c = (NiceCandidateImpl *) cand->candidate;
StunUsageTurnCompatibility turn_compat = agent_to_turn_compatibility (agent);
nice_debug ("Agent %p : Sending request to remove TURN allocation "
......@@ -240,17 +241,17 @@ static gboolean refresh_remove_async (NiceAgent *agent, gpointer pointer)
g_source_unref (cand->destroy_source);
cand->destroy_source = NULL;
username = (uint8_t *)cand->candidate->turn->username;
username_len = (size_t) strlen (cand->candidate->turn->username);
password = (uint8_t *)cand->candidate->turn->password;
password_len = (size_t) strlen (cand->candidate->turn->password);
username = (uint8_t *)c->turn->username;
username_len = (size_t) strlen (c->turn->username);
password = (uint8_t *)c->turn->password;
password_len = (size_t) strlen (c->turn->password);
if (turn_compat == STUN_USAGE_TURN_COMPATIBILITY_MSN ||
turn_compat == STUN_USAGE_TURN_COMPATIBILITY_OC2007) {
username = cand->candidate->turn->decoded_username;
password = cand->candidate->turn->decoded_password;
username_len = cand->candidate->turn->decoded_username_len;
password_len = cand->candidate->turn->decoded_password_len;
username = c->turn->decoded_username;
password = c->turn->decoded_password;
username_len = c->turn->decoded_username_len;
password_len = c->turn->decoded_password_len;
}
buffer_len = stun_usage_turn_create_refresh (&cand->stun_agent,
......@@ -366,7 +367,7 @@ void refresh_prune_stream_async (NiceAgent *agent, NiceStream *stream,
* situations when an error is detected in socket communication that prevents
* sending more requests to the server.
*/
void refresh_prune_candidate (NiceAgent *agent, NiceCandidate *candidate)
void refresh_prune_candidate (NiceAgent *agent, NiceCandidateImpl *candidate)
{
GSList *i;
......@@ -387,8 +388,8 @@ void refresh_prune_candidate (NiceAgent *agent, NiceCandidate *candidate)
* closes the associated port allocations on TURN server. Invokes 'function'
* when the process finishes.
*/
void refresh_prune_candidate_async (NiceAgent *agent, NiceCandidate *candidate,
NiceTimeoutLockedCallback function)
void refresh_prune_candidate_async (NiceAgent *agent,
NiceCandidateImpl *candidate, NiceTimeoutLockedCallback function)
{
GSList *refreshes = NULL;
GSList *i;
......@@ -485,37 +486,38 @@ priv_compare_turn_servers (TurnServer *turn1, TurnServer *turn2)
static void priv_assign_foundation (NiceAgent *agent, NiceCandidate *candidate)
{
GSList *i, *j, *k;
NiceCandidateImpl *c = (NiceCandidateImpl *) candidate;
for (i = agent->streams; i; i = i->next) {
NiceStream *stream = i->data;
for (j = stream->components; j; j = j->next) {
NiceComponent *component = j->data;
for (k = component->local_candidates; k; k = k->next) {
NiceCandidate *n = k->data;
NiceCandidateImpl *n = k->data;
/* note: candidate must not on the local candidate list */
g_assert (candidate != n);
g_assert (c != n);
if (candidate->type == n->type &&
candidate->transport == n->transport &&
nice_address_equal_no_port (&candidate->base_addr, &n->base_addr) &&
if (candidate->type == n->c.type &&
candidate->transport == n->c.transport &&
nice_address_equal_no_port (&candidate->base_addr, &n->c.base_addr) &&
(candidate->type != NICE_CANDIDATE_TYPE_RELAYED ||
priv_compare_turn_servers (candidate->turn, n->turn)) &&
priv_compare_turn_servers (c->turn, n->turn)) &&
!(agent->compatibility == NICE_COMPATIBILITY_GOOGLE &&
n->type == NICE_CANDIDATE_TYPE_RELAYED)) {
n->c.type == NICE_CANDIDATE_TYPE_RELAYED)) {
/* note: currently only one STUN server per stream at a
* time is supported, so there is no need to check
* for candidates that would otherwise share the
* foundation, but have different STUN servers */
g_strlcpy (candidate->foundation, n->foundation,
g_strlcpy (candidate->foundation, n->c.foundation,
NICE_CANDIDATE_MAX_FOUNDATION);
if (n->username) {
if (n->c.username) {
g_free (candidate->username);
candidate->username = g_strdup (n->username);
candidate->username = g_strdup (n->c.username);
}
if (n->password) {
if (n->c.password) {
g_free (candidate->password);
candidate->password = g_strdup (n->password);
candidate->password = g_strdup (n->c.password);
}
return;
}
......@@ -673,9 +675,10 @@ HostCandidateResult discovery_add_local_host_candidate (
NiceAddress *address,
NiceCandidateTransport transport,
gboolean accept_duplicate,
NiceCandidate **outcandidate)
NiceCandidateImpl **outcandidate)
{
NiceCandidate *candidate;
NiceCandidateImpl *c;
NiceComponent *component;
NiceStream *stream;
NiceSocket *nicesock = NULL;
......@@ -686,6 +689,7 @@ HostCandidateResult discovery_add_local_host_candidate (
return res;
candidate = nice_candidate_new (NICE_CANDIDATE_TYPE_HOST);
c = (NiceCandidateImpl *) candidate;
candidate->transport = transport;
candidate->stream_id = stream_id;
candidate->component_id = component_id;
......@@ -727,7 +731,7 @@ HostCandidateResult discovery_add_local_host_candidate (
goto errors;
}
candidate->sockptr = nicesock;
c->sockptr = nicesock;
candidate->addr = nicesock->addr;
candidate->base_addr = nicesock->addr;
......@@ -745,7 +749,7 @@ HostCandidateResult discovery_add_local_host_candidate (
_priv_set_socket_tos (agent, nicesock, stream->tos);
nice_component_attach_socket (component, nicesock);
*outcandidate = candidate;
*outcandidate = c;
return HOST_CANDIDATE_SUCCESS;
......@@ -773,6 +777,7 @@ discovery_add_server_reflexive_candidate (
gboolean nat_assisted)
{
NiceCandidate *candidate;
NiceCandidateImpl *c;
NiceComponent *component;
NiceStream *stream;
gboolean result = FALSE;
......@@ -781,13 +786,14 @@ discovery_add_server_reflexive_candidate (
return NULL;
candidate = nice_candidate_new (NICE_CANDIDATE_TYPE_SERVER_REFLEXIVE);
c = (NiceCandidateImpl *) candidate;
candidate->transport = transport;
candidate->stream_id = stream_id;
candidate->component_id = component_id;
candidate->addr = *address;
/* step: link to the base candidate+socket */
candidate->sockptr = base_socket;
c->sockptr = base_socket;
candidate->base_addr = base_socket->addr;
if (agent->compatibility == NICE_COMPATIBILITY_GOOGLE) {
......@@ -859,7 +865,7 @@ discovery_discover_tcp_server_reflexive_candidates (
component_id,
address,
c->transport,
c->sockptr,
((NiceCandidateImpl *) c)->sockptr,
FALSE);
}
}
......@@ -871,7 +877,7 @@ discovery_discover_tcp_server_reflexive_candidates (
*
* @return pointer to the created candidate, or NULL on error
*/
NiceCandidate*
NiceCandidateImpl *
discovery_add_relay_candidate (
NiceAgent *agent,
guint stream_id,
......@@ -882,6 +888,7 @@ discovery_add_relay_candidate (
TurnServer *turn)
{
NiceCandidate *candidate;
NiceCandidateImpl *c;
NiceComponent *component;
NiceStream *stream;
NiceSocket *relay_socket = NULL;
......@@ -890,11 +897,12 @@ discovery_add_relay_candidate (
return NULL;
candidate = nice_candidate_new (NICE_CANDIDATE_TYPE_RELAYED);
c = (NiceCandidateImpl *) candidate;
candidate->transport = transport;
candidate->stream_id = stream_id;
candidate->component_id = component_id;
candidate->addr = *address;
candidate->turn = turn_server_ref (turn);
c->turn = turn_server_ref (turn);
/* step: link to the base candidate+socket */
relay_socket = nice_udp_turn_socket_new (agent->main_context, address,
......@@ -904,7 +912,7 @@ discovery_add_relay_candidate (
if (!relay_socket)
goto errors;
candidate->sockptr = relay_socket;
c->sockptr = relay_socket;
candidate->base_addr = base_socket->addr;
if (agent->compatibility == NICE_COMPATIBILITY_GOOGLE) {
......@@ -936,7 +944,7 @@ discovery_add_relay_candidate (
nice_component_attach_socket (component, relay_socket);
agent_signal_new_candidate (agent, candidate);
return candidate;
return c;
errors:
nice_candidate_free (candidate);
......@@ -963,6 +971,7 @@ discovery_add_peer_reflexive_candidate (
NiceCandidate *remote)
{
NiceCandidate *candidate;
NiceCandidateImpl *c;
NiceComponent *component;
NiceStream *stream;
gboolean result;
......@@ -971,6 +980,7 @@ discovery_add_peer_reflexive_candidate (
return NULL;
candidate = nice_candidate_new (NICE_CANDIDATE_TYPE_PEER_REFLEXIVE);
c = (NiceCandidateImpl *) candidate;
if (local)
candidate->transport = local->transport;
else if (remote)
......@@ -985,7 +995,7 @@ discovery_add_peer_reflexive_candidate (
candidate->stream_id = stream_id;
candidate->component_id = component_id;
candidate->addr = *address;
candidate->sockptr = base_socket;
c->sockptr = base_socket;
candidate->base_addr = base_socket->addr;
/* We don't ensure priority uniqueness in this case, since the
* discovered candidate receives the same priority than its
......@@ -1058,8 +1068,10 @@ NiceCandidate *discovery_learn_remote_peer_reflexive_candidate (
NiceCandidate *remote)
{
NiceCandidate *candidate;
NiceCandidateImpl *c;
candidate = nice_candidate_new (NICE_CANDIDATE_TYPE_PEER_REFLEXIVE);
c = (NiceCandidateImpl *) candidate;
candidate->addr = *remote_address;
candidate->base_addr = *remote_address;
......@@ -1074,7 +1086,7 @@ NiceCandidate *discovery_learn_remote_peer_reflexive_candidate (
else
candidate->transport = NICE_CANDIDATE_TRANSPORT_TCP_ACTIVE;
}
candidate->sockptr = nicesock;
c->sockptr = nicesock;
candidate->stream_id = stream->id;
candidate->component_id = component->id;
......
......@@ -43,6 +43,7 @@
#include "stream.h"
#include "agent.h"
#include "candidate-priv.h"
typedef struct
{
......@@ -67,7 +68,7 @@ typedef struct
{
NiceSocket *nicesock; /* existing socket to use */
NiceAddress server; /* STUN/TURN server address */
NiceCandidate *candidate; /* candidate to refresh */
NiceCandidateImpl *candidate; /* candidate to refresh */
guint stream_id;
guint component_id;
StunAgent stun_agent;
......@@ -90,8 +91,8 @@ void refresh_prune_agent_async (NiceAgent *agent,
NiceTimeoutLockedCallback function, gpointer user_data);
void refresh_prune_stream_async (NiceAgent *agent, NiceStream *stream,
NiceTimeoutLockedCallback function);
void refresh_prune_candidate (NiceAgent *agent, NiceCandidate *candidate);
void refresh_prune_candidate_async (NiceAgent *agent, NiceCandidate *candidate,
void refresh_prune_candidate (NiceAgent *agent, NiceCandidateImpl *candidate);
void refresh_prune_candidate_async (NiceAgent *agent, NiceCandidateImpl *cand,
NiceTimeoutLockedCallback function);
......@@ -116,9 +117,9 @@ discovery_add_local_host_candidate (
NiceAddress *address,
NiceCandidateTransport transport,
gboolean accept_duplicate,
NiceCandidate **candidate);
NiceCandidateImpl **candidate);
NiceCandidate*
NiceCandidateImpl*
discovery_add_relay_candidate (
NiceAgent *agent,
guint stream_id,
......
......@@ -88,7 +88,6 @@ NiceAgentClass
NiceCandidate
NiceCandidateType
NiceCandidateTransport
TurnServer
NiceRelayType
NICE_CANDIDATE_MAX_FOUNDATION
NICE_CANDIDATE_MAX_TURN_SERVERS
......@@ -120,6 +119,7 @@ NICE_CANDIDATE_DIRECTION_MS_PREF_ACTIVE
NICE_CANDIDATE_DIRECTION_MS_PREF_PASSIVE
NICE_CANDIDATE_TRANSPORT_MS_PREF_TCP
NICE_CANDIDATE_TRANSPORT_MS_PREF_UDP
TurnServer
</SECTION>
<SECTION>
......
......@@ -8,6 +8,7 @@ ignore_headers = [
'agent-priv.h',
'iostream.h',
'inputstream.h',
'candidate-priv.h',
'outputstream.h',
'gstnice.h',
'gstnicesrc.h',
......
......@@ -41,6 +41,7 @@
#endif
#include "agent.h"
#include "candidate-priv.h"
#include "socket/socket.h"
......@@ -223,7 +224,7 @@ static void set_candidates (NiceAgent *from, guint from_stream,
*/
for (item1 = cands; item1; item1 = item1->next) {
NiceCandidate *cand = item1->data;
NiceCandidateImpl *cand = item1->data;
NiceSocket *nicesock = cand->sockptr;
g_assert (nicesock);
......
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