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
......@@ -61,7 +61,7 @@
#include "socket.h"
#include "stun/usages/turn.h"
#include "candidate.h"
#include "candidate-priv.h"
#include "component.h"
#include "conncheck.h"
#include "discovery.h"
......@@ -2087,7 +2087,7 @@ pseudo_tcp_socket_write_packet (PseudoTcpSocket *psocket,
NiceAddress *addr;
sock = component->selected_pair.local->sockptr;
addr = &component->selected_pair.remote->addr;
addr = &component->selected_pair.remote->c.addr;
if (nice_debug_is_enabled ()) {
gchar tmpbuf[INET6_ADDRSTRLEN];
......@@ -2403,16 +2403,17 @@ void agent_signal_new_selected_pair (NiceAgent *agent, guint stream_id,
{
NiceComponent *component;
NiceStream *stream;
NiceCandidateImpl *lc = (NiceCandidateImpl *) lcandidate;
if (!agent_find_component (agent, stream_id, component_id,
&stream, &component))
return;
if (((NiceSocket *)lcandidate->sockptr)->type == NICE_SOCKET_TYPE_UDP_TURN) {
nice_udp_turn_socket_set_peer (lcandidate->sockptr, &rcandidate->addr);
if (((NiceSocket *)lc->sockptr)->type == NICE_SOCKET_TYPE_UDP_TURN) {
nice_udp_turn_socket_set_peer (lc->sockptr, &rcandidate->addr);
}
if(agent->reliable && !nice_socket_is_reliable (lcandidate->sockptr)) {
if(agent->reliable && !nice_socket_is_reliable (lc->sockptr)) {
if (!component->tcp)
pseudo_tcp_socket_create (agent, stream, component);
process_queued_tcp_packets (agent, stream, component);
......@@ -2468,7 +2469,7 @@ void agent_signal_new_selected_pair (NiceAgent *agent, guint stream_id,
agent_queue_signal (agent, signals[SIGNAL_NEW_SELECTED_PAIR],
stream_id, component_id, lcandidate->foundation, rcandidate->foundation);
if(agent->reliable && nice_socket_is_reliable (lcandidate->sockptr)) {
if(agent->reliable && nice_socket_is_reliable (lc->sockptr)) {
agent_signal_socket_writable (agent, component);
}
}
......@@ -2883,15 +2884,15 @@ nice_agent_set_relay_info(NiceAgent *agent,
stream->gathering = TRUE;
for (i = component->local_candidates; i; i = i->next) {
NiceCandidate *candidate = i->data;
NiceCandidateImpl *c = i->data;
if (candidate->type == NICE_CANDIDATE_TYPE_HOST &&
candidate->transport != NICE_CANDIDATE_TRANSPORT_TCP_PASSIVE &&
nice_address_ip_version (&candidate->addr) ==
if (c->c.type == NICE_CANDIDATE_TYPE_HOST &&
c->c.transport != NICE_CANDIDATE_TRANSPORT_TCP_PASSIVE &&
nice_address_ip_version (&c->c.addr) ==
nice_address_ip_version (&turn->server))
priv_add_new_candidate_discovery_turn (agent,
candidate->sockptr, turn, stream, component_id,
candidate->transport != NICE_CANDIDATE_TRANSPORT_UDP);
c->sockptr, turn, stream, component_id,
c->c.transport != NICE_CANDIDATE_TRANSPORT_UDP);
}
if (agent->discovery_unsched_items)
......@@ -2990,13 +2991,13 @@ static void _upnp_mapped_external_port (GUPnPSimpleIgd *self, gchar *proto,
for (j = stream->components; j; j = j->next) {
NiceComponent *component = j->data;
for (k = component->local_candidates; k; k = k->next) {
NiceCandidate *local_candidate = k->data;
NiceCandidateImpl *local_candidate = k->data;
if (agent->force_relay &&
local_candidate->type != NICE_CANDIDATE_TYPE_RELAYED)
local_candidate->c.type != NICE_CANDIDATE_TYPE_RELAYED)
continue;
if (nice_address_equal (&localaddr, &local_candidate->base_addr)) {
if (nice_address_equal (&localaddr, &local_candidate->c.base_addr)) {
discovery_add_server_reflexive_candidate (
agent,
stream->id,
......@@ -3153,7 +3154,7 @@ nice_agent_gather_candidates (
i && length < NICE_CANDIDATE_MAX_LOCAL_ADDRESSES;
i = i->next, length++) {
NiceAddress *addr = i->data;
NiceCandidate *host_candidate;
NiceCandidateImpl *host_candidate;
#ifdef HAVE_GUPNP
gchar local_ip[NICE_ADDRESS_STRING_LEN];
......@@ -3254,7 +3255,7 @@ nice_agent_gather_candidates (
#ifdef HAVE_GUPNP
if (agent->upnp_enabled && agent->upnp &&
transport != NICE_CANDIDATE_TRANSPORT_TCP_ACTIVE) {
NiceAddress *base_addr = nice_address_dup (&host_candidate->base_addr);
NiceAddress *base_addr = nice_address_dup (&host_candidate->c.base_addr);
nice_debug ("Agent %p: Adding UPnP port %s:%d", agent, local_ip,
nice_address_get_port (base_addr));
gupnp_simple_igd_add_port (GUPNP_SIMPLE_IGD (agent->upnp),
......@@ -3276,7 +3277,7 @@ nice_agent_gather_candidates (
if (nice_address_set_from_string (&stun_server, agent->stun_server_ip)) {
nice_address_set_port (&stun_server, agent->stun_server_port);
if (nice_address_ip_version (&host_candidate->addr) ==
if (nice_address_ip_version (&host_candidate->c.addr) ==
nice_address_ip_version (&stun_server))
priv_add_new_candidate_discovery_stun (agent,
host_candidate->sockptr,
......@@ -3289,7 +3290,7 @@ nice_agent_gather_candidates (
if (agent->full_mode && component &&
transport != NICE_CANDIDATE_TRANSPORT_TCP_PASSIVE) {
GList *item;
int host_ip_version = nice_address_ip_version (&host_candidate->addr);
int host_ip_version = nice_address_ip_version (&host_candidate->c.addr);
for (item = component->turn_servers; item; item = item->next) {
TurnServer *turn = item->data;
......@@ -3303,7 +3304,7 @@ nice_agent_gather_candidates (
turn,
stream,
cid,
host_candidate->transport != NICE_CANDIDATE_TRANSPORT_UDP);
host_candidate->c.transport != NICE_CANDIDATE_TRANSPORT_UDP);
}
}
}
......@@ -3561,8 +3562,8 @@ static void priv_update_pair_foundations (NiceAgent *agent,
agent, pair, pair->foundation);
if (pair->state == NICE_CHECK_SUCCEEDED)
conn_check_unfreeze_related (agent, pair);
if (component->selected_pair.local == pair->local &&
component->selected_pair.remote == pair->remote) {
if ((NiceCandidate *) component->selected_pair.local == pair->local &&
(NiceCandidate *) component->selected_pair.remote == pair->remote) {
gchar priority[NICE_CANDIDATE_PAIR_PRIORITY_MAX_SIZE];
/* the foundation update of the selected pair also implies
......@@ -3625,6 +3626,7 @@ static gboolean priv_add_remote_candidate (
NiceStream *stream;
NiceComponent *component;
NiceCandidate *candidate;
NiceCandidateImpl *c;
CandidateCheckPair *pair;
if (transport == NICE_CANDIDATE_TRANSPORT_UDP &&
......@@ -3640,6 +3642,7 @@ static gboolean priv_add_remote_candidate (
/* step: check whether the candidate already exists */
candidate = nice_component_find_remote_candidate (component, addr, transport);
c = (NiceCandidateImpl *) candidate;
/* If it was a discovered remote peer reflexive candidate, then it should
* be updated according to RFC 5245 section 7.2.1.3 */
......@@ -3650,7 +3653,7 @@ static gboolean priv_add_remote_candidate (
/* The updated candidate is no more peer reflexive, so its
* sockptr can be cleared
*/
candidate->sockptr = NULL;
c->sockptr = NULL;
/* If it got there, the next one will also be ran, so the foundation
* will be set.
*/
......@@ -3710,8 +3713,8 @@ static gboolean priv_add_remote_candidate (
pair = priv_get_highest_priority_nominated_pair (agent,
stream_id, component_id);
if (pair &&
(pair->local != component->selected_pair.local ||
pair->remote != component->selected_pair.remote)) {
(pair->local != (NiceCandidate *) component->selected_pair.local ||
pair->remote != (NiceCandidate *) component->selected_pair.remote)) {
/* If we have (at least) one pair with the nominated flag set, it
* implies that this pair (or another) is set as the selected pair
* for this component. In other words, this is really an *update*
......@@ -4041,11 +4044,11 @@ agent_recv_message_unlocked (
* the socket we do the recv on to the topmost socket
*/
for (cand_i = component->local_candidates; cand_i; cand_i = cand_i->next) {
NiceCandidate *cand = cand_i->data;
NiceCandidateImpl *cand = cand_i->data;
if (cand->type == NICE_CANDIDATE_TYPE_RELAYED &&
cand->stream_id == stream->id &&
cand->component_id == component->id &&
if (cand->c.type == NICE_CANDIDATE_TYPE_RELAYED &&
cand->c.stream_id == stream->id &&
cand->c.component_id == component->id &&
nice_socket_is_based_on(cand->sockptr, nicesock)) {
nice_debug ("Agent %p : Packet received from a TURN socket.",
agent);
......@@ -4268,11 +4271,11 @@ agent_recv_message_unlocked (
is_turn = TRUE;
for (i = component->local_candidates; i; i = i->next) {
NiceCandidate *cand = i->data;
NiceCandidateImpl *cand = i->data;
if (cand->type == NICE_CANDIDATE_TYPE_RELAYED &&
if (cand->c.type == NICE_CANDIDATE_TYPE_RELAYED &&
cand->turn == turn &&
cand->stream_id == stream->id &&
cand->c.stream_id == stream->id &&
nice_socket_is_based_on (cand->sockptr, nicesock)) {
retval = nice_udp_turn_socket_parse_recv_message (cand->sockptr, &nicesock,
message);
......@@ -5073,11 +5076,11 @@ nice_agent_send_messages_nonblocking_internal (
if (component->selected_pair.local != NULL) {
if (nice_debug_is_enabled ()) {
gchar tmpbuf[INET6_ADDRSTRLEN];
nice_address_to_string (&component->selected_pair.remote->addr, tmpbuf);
nice_address_to_string (&component->selected_pair.remote->c.addr, tmpbuf);
nice_debug_verbose ("Agent %p : s%d:%d: sending %u messages to "
"[%s]:%d", agent, stream_id, component_id, n_messages, tmpbuf,
nice_address_get_port (&component->selected_pair.remote->addr));
nice_address_get_port (&component->selected_pair.remote->c.addr));
}
if(agent->reliable &&
......@@ -5104,7 +5107,7 @@ nice_agent_send_messages_nonblocking_internal (
NiceAddress *addr;
sock = component->selected_pair.local->sockptr;
addr = &component->selected_pair.remote->addr;
addr = &component->selected_pair.remote->c.addr;
if (nice_socket_is_reliable (sock)) {
guint i;
......@@ -5849,7 +5852,7 @@ nice_agent_set_selected_pair (
/* step: set the selected pair */
nice_component_update_selected_pair (agent, component, &pair);
agent_signal_new_selected_pair (agent, stream_id, component_id,
pair.local, pair.remote);
(NiceCandidate *) pair.local, (NiceCandidate *) pair.remote);
ret = TRUE;
......@@ -5880,8 +5883,8 @@ nice_agent_get_selected_pair (NiceAgent *agent, guint stream_id,
goto done;
if (component->selected_pair.local && component->selected_pair.remote) {
*local = component->selected_pair.local;
*remote = component->selected_pair.remote;
*local = (NiceCandidate *) component->selected_pair.local;
*remote = (NiceCandidate *) component->selected_pair.remote;
ret = TRUE;
}
......@@ -5918,11 +5921,11 @@ nice_agent_get_selected_socket (NiceAgent *agent, guint stream_id,
if (!component->selected_pair.local || !component->selected_pair.remote)
goto done;
if (component->selected_pair.local->type == NICE_CANDIDATE_TYPE_RELAYED)
if (component->selected_pair.local->c.type == NICE_CANDIDATE_TYPE_RELAYED)
goto done;
/* ICE-TCP requires RFC4571 framing, even if unreliable */
if (component->selected_pair.local->transport != NICE_CANDIDATE_TRANSPORT_UDP)
if (component->selected_pair.local->c.transport != NICE_CANDIDATE_TRANSPORT_UDP)
goto done;
nice_socket = (NiceSocket *)component->selected_pair.local->sockptr;
......@@ -6063,9 +6066,9 @@ nice_agent_set_selected_remote_candidate (
{
NiceComponent *component;
NiceStream *stream;
NiceCandidate *lcandidate = NULL;
NiceCandidateImpl *lcandidate = NULL;
gboolean ret = FALSE;
NiceCandidate *local = NULL, *remote = NULL;
NiceCandidateImpl *local = NULL, *remote = NULL;
guint64 priority;
g_return_val_if_fail (NICE_IS_AGENT (agent), FALSE);
......@@ -6101,7 +6104,7 @@ nice_agent_set_selected_remote_candidate (
stream->id, component->id);
/* Revert back to previous selected pair */
/* FIXME: by doing this, we lose the keepalive tick */
component->selected_pair.local = local;
component->selected_pair.local = (NiceCandidateImpl *) local;
component->selected_pair.remote = remote;
component->selected_pair.priority = priority;
goto done;
......@@ -6122,7 +6125,7 @@ nice_agent_set_selected_remote_candidate (
NICE_COMPONENT_STATE_READY);
agent_signal_new_selected_pair (agent, stream_id, component_id,
lcandidate, candidate);
(NiceCandidate *) lcandidate, candidate);
ret = TRUE;
......@@ -6173,7 +6176,7 @@ nice_agent_set_stream_tos (NiceAgent *agent,
NiceComponent *component = i->data;
for (j = component->local_candidates; j; j = j->next) {
NiceCandidate *local_candidate = j->data;
NiceCandidateImpl *local_candidate = j->data;
_priv_set_socket_tos (agent, local_candidate->sockptr, tos);
}
......
/*
* 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);
......
......@@ -1277,7 +1277,7 @@ static gboolean priv_conn_keepalive_retransmissions_tick_agent_locked (
}
case STUN_USAGE_TIMER_RETURN_RETRANSMIT:
/* Retransmit */
agent_socket_send (pair->local->sockptr, &pair->remote->addr,
agent_socket_send (pair->local->sockptr, &pair->remote->c.addr,
stun_message_length (&pair->keepalive.stun_message),
(gchar *)pair->keepalive.stun_buffer);
......@@ -1416,7 +1416,7 @@ static gboolean priv_conn_keepalive_tick_unlocked (NiceAgent *agent)
CandidatePair *p = &component->selected_pair;
/* Disable keepalive checks on TCP candidates unless explicitly enabled */
if (p->local->transport != NICE_CANDIDATE_TRANSPORT_UDP &&
if (p->local->c.transport != NICE_CANDIDATE_TRANSPORT_UDP &&
!agent->keepalive_conncheck)
continue;
......@@ -1432,11 +1432,12 @@ static gboolean priv_conn_keepalive_tick_unlocked (NiceAgent *agent)
uint8_t uname[NICE_STREAM_MAX_UNAME];
size_t uname_len =
priv_create_username (agent, agent_find_stream (agent, stream->id),
component->id, p->remote, p->local, uname, sizeof (uname),
FALSE);
component->id, (NiceCandidate *) p->remote,
(NiceCandidate *) p->local, uname, sizeof (uname), FALSE);
uint8_t *password = NULL;
size_t password_len = priv_get_password (agent,
agent_find_stream (agent, stream->id), p->remote, &password);
agent_find_stream (agent, stream->id),
(NiceCandidate *) p->remote, &password);
if (p->keepalive.stun_message.buffer != NULL) {
nice_debug ("Agent %p: Keepalive for s%u:c%u still"
......@@ -1447,11 +1448,11 @@ static gboolean priv_conn_keepalive_tick_unlocked (NiceAgent *agent)
if (nice_debug_is_enabled ()) {
gchar tmpbuf[INET6_ADDRSTRLEN];
nice_address_to_string (&p->remote->addr, tmpbuf);
nice_address_to_string (&p->remote->c.addr, tmpbuf);
nice_debug ("Agent %p : Keepalive STUN-CC REQ to '%s:%u', "
"(c-id:%u), username='%.*s' (%" G_GSIZE_FORMAT "), "
"password='%.*s' (%" G_GSIZE_FORMAT "), priority=%08x.",
agent, tmpbuf, nice_address_get_port (&p->remote->addr),
agent, tmpbuf, nice_address_get_port (&p->remote->c.addr),
component->id, (int) uname_len, uname, uname_len,
(int) password_len, password, password_len,
p->stun_priority);
......@@ -1478,7 +1479,7 @@ static gboolean priv_conn_keepalive_tick_unlocked (NiceAgent *agent)
agent->media_after_tick = FALSE;
/* send the conncheck */
agent_socket_send (p->local->sockptr, &p->remote->addr,
agent_socket_send (p->local->sockptr, &p->remote->c.addr,
buf_len, (gchar *)p->keepalive.stun_buffer);
p->keepalive.stream_id = stream->id;
......@@ -1502,22 +1503,22 @@ static gboolean priv_conn_keepalive_tick_unlocked (NiceAgent *agent)
sizeof(p->keepalive.stun_buffer));
if (buf_len > 0) {
agent_socket_send (p->local->sockptr, &p->remote->addr, buf_len,
agent_socket_send (p->local->sockptr, &p->remote->c.addr, buf_len,
(gchar *)p->keepalive.stun_buffer);
p->keepalive.next_tick = now + 1000 * NICE_AGENT_TIMER_TR_DEFAULT;
if (agent->compatibility == NICE_COMPATIBILITY_OC2007R2) {
ms_ice2_legacy_conncheck_send (&p->keepalive.stun_message,
p->local->sockptr, &p->remote->addr);
p->local->sockptr, &p->remote->c.addr);
}
if (nice_debug_is_enabled ()) {
gchar tmpbuf[INET6_ADDRSTRLEN];
nice_address_to_string (&p->local->base_addr, tmpbuf);
nice_address_to_string (&p->local->c.base_addr, tmpbuf);
nice_debug ("Agent %p : resending STUN to keep the "
"selected base address %s:%u alive in s%d/c%d.", agent,
tmpbuf, nice_address_get_port (&p->local->base_addr),
tmpbuf, nice_address_get_port (&p->local->c.base_addr),
stream->id, component->id);
}
......@@ -1555,10 +1556,10 @@ static gboolean priv_conn_keepalive_tick_unlocked (NiceAgent *agent)
&stun_message, stun_buffer, sizeof(stun_buffer));
for (k = component->local_candidates; k; k = k->next) {
NiceCandidate *candidate = (NiceCandidate *) k->data;
if (candidate->type == NICE_CANDIDATE_TYPE_HOST &&
candidate->transport == NICE_CANDIDATE_TRANSPORT_UDP &&
nice_address_ip_version (&candidate->addr) ==
NiceCandidateImpl *candidate = (NiceCandidateImpl *) k->data;
if (candidate->c.type == NICE_CANDIDATE_TYPE_HOST &&
candidate->c.transport == NICE_CANDIDATE_TRANSPORT_UDP &&
nice_address_ip_version (&candidate->c.addr) ==
nice_address_ip_version (&stun_server)) {
if (candidate->keepalive_next_tick) {
......@@ -1571,10 +1572,10 @@ static gboolean priv_conn_keepalive_tick_unlocked (NiceAgent *agent)
/* send the conncheck */
if (nice_debug_is_enabled ()) {
gchar tmpbuf[INET6_ADDRSTRLEN];
nice_address_to_string (&candidate->addr, tmpbuf);
nice_address_to_string (&candidate->c.addr, tmpbuf);
nice_debug ("Agent %p : resending STUN to keep the local "
"candidate %s:%u alive in s%d/c%d.", agent,
tmpbuf, nice_address_get_port (&candidate->addr),
tmpbuf, nice_address_get_port (&candidate->c.addr),
stream->id, component->id);
}
agent_socket_send (candidate->sockptr, &stun_server,
......@@ -1829,6 +1830,7 @@ local_candidate_and_socket_compatible (NiceAgent *agent,
{
gboolean ret = TRUE;
NiceCandidateTransport transport;
NiceCandidateImpl *lc = (NiceCandidateImpl *) lcand;
g_assert (socket);
g_assert (lcand);
......@@ -1839,14 +1841,14 @@ local_candidate_and_socket_compatible (NiceAgent *agent,
* socket is the tcp connect related socket */
if (ret && transport == NICE_CANDIDATE_TRANSPORT_TCP_ACTIVE &&
nice_address_get_port (&lcand->addr) > 0)
ret = (lcand->sockptr == socket);
ret = (lc->sockptr == socket);
} else if (socket->type == NICE_SOCKET_TYPE_UDP_TURN)
/* Socket of type udp-turn will match a unique local candidate
* by its sockptr value. An an udp-turn socket doesn't carry enough
* information when base socket is udp-turn-over-tcp to disambiguate
* between a tcp-act and a tcp-pass local candidate.
*/
ret = (lcand->sockptr == socket);
ret = (lc->sockptr == socket);
return ret;
}
......@@ -2076,8 +2078,8 @@ conn_check_update_selected_pair (NiceAgent *agent, NiceComponent *component,
"(prio:%s).", agent, component->id,
pair->local->foundation, pair->remote->foundation, priority);
cpair.local = pair->local;
cpair.remote = pair->remote;
cpair.local = (NiceCandidateImpl *) pair->local;
cpair.remote = (NiceCandidateImpl *) pair->remote;
cpair.priority = pair->priority;
cpair.stun_priority = pair->stun_priority;
......@@ -2301,8 +2303,8 @@ static void priv_mark_pair_nominated (NiceAgent *agent, NiceStream *stream, Nice
* the agent's list of checks.
*/
static CandidateCheckPair *priv_add_new_check_pair (NiceAgent *agent,
guint stream_id, NiceComponent *component, NiceCandidate *local,
NiceCandidate *remote, NiceCheckState initial_state)
guint stream_id, NiceComponent *component, NiceCandidateImpl *local,
NiceCandidateImpl *remote, NiceCheckState initial_state)
{
NiceStream *stream;
CandidateCheckPair *pair;
......@@ -2311,7 +2313,8 @@ static CandidateCheckPair *priv_add_new_check_pair (NiceAgent *agent,
g_assert (local != NULL);
g_assert (remote != NULL);
priority = agent_candidate_pair_priority (agent, local, remote);
priority = agent_candidate_pair_priority (agent, (NiceCandidate *) local,
(NiceCandidate *) remote);
if (component->selected_pair.priority &&
priority < component->selected_pair.priority) {
......@@ -2330,20 +2333,22 @@ static CandidateCheckPair *priv_add_new_check_pair (NiceAgent *agent,
pair = g_slice_new0 (CandidateCheckPair);
pair->stream_id = stream_id;
pair->component_id = component->id;;
pair->local = local;
pair->remote = remote;
pair->component_id = component->id;
pair->local = (NiceCandidate *) local;
pair->remote = (NiceCandidate *) remote;
/* note: we use the remote sockptr only in the case
* of TCP transport
*/
if (local->transport == NICE_CANDIDATE_TRANSPORT_TCP_PASSIVE &&
remote->type == NICE_CANDIDATE_TYPE_PEER_REFLEXIVE)
pair->sockptr = (NiceSocket *) remote->sockptr;
if (local->c.transport == NICE_CANDIDATE_TRANSPORT_TCP_PASSIVE &&
remote->c.type == NICE_CANDIDATE_TYPE_PEER_REFLEXIVE)
pair->sockptr = remote->sockptr;
else
pair->sockptr = (NiceSocket *) local->sockptr;
g_snprintf (pair->foundation, NICE_CANDIDATE_PAIR_MAX_FOUNDATION, "%s:%s", local->foundation, remote->foundation);
pair->sockptr = local->sockptr;
g_snprintf (pair->foundation, NICE_CANDIDATE_PAIR_MAX_FOUNDATION, "%s:%s",
local->c.foundation, remote->c.foundation);
pair->priority = agent_candidate_pair_priority (agent, local, remote);
pair->priority = agent_candidate_pair_priority (agent,
(NiceCandidate *) local, (NiceCandidate *) remote);
nice_debug ("Agent %p : creating a new pair", agent);
SET_PAIR_STATE (agent, pair, initial_state);
{
......@@ -2355,7 +2360,7 @@ static CandidateCheckPair *priv_add_new_check_pair (NiceAgent *agent,
tmpbuf1, nice_address_get_port (&pair->local->addr),
tmpbuf2, nice_address_get_port (&pair->remote->addr));
}
pair->stun_priority = stun_request_priority (agent, local);
pair->stun_priority = stun_request_priority (agent, (NiceCandidate *) local);
stream->conncheck_list = g_slist_insert_sorted (stream->conncheck_list, pair,
(GCompareFunc)conn_check_compare);
......@@ -2404,8 +2409,8 @@ static CandidateCheckPair *priv_conn_check_add_for_candidate_pair_matched (
{
CandidateCheckPair *pair;
pair = priv_add_new_check_pair (agent, stream_id, component, local, remote,
initial_state);
pair = priv_add_new_check_pair (agent, stream_id, component,
(NiceCandidateImpl *) local, (NiceCandidateImpl *) remote, initial_state);
if (pair) {
if (component->state == NICE_COMPONENT_STATE_CONNECTED ||
component->state == NICE_COMPONENT_STATE_READY) {
......@@ -3169,8 +3174,9 @@ static gboolean priv_schedule_triggered_check (NiceAgent *agent, NiceStream *str
}
for (i = component->local_candidates; i ; i = i->next) {
NiceCandidateImpl *lc = i->data;
local = i->data;
if (local->sockptr == local_socket)
if (lc->sockptr == local_socket)
break;
}
......@@ -3284,14 +3290,14 @@ static int priv_store_pending_check (NiceAgent *agent, NiceComponent *component,
*
* @return created pair, or NULL on fatal (memory allocation) errors
*/
static CandidateCheckPair *priv_add_peer_reflexive_pair (NiceAgent *agent, guint stream_id, NiceComponent *component, NiceCandidate *local_cand, CandidateCheckPair *parent_pair)
static CandidateCheckPair *priv_add_peer_reflexive_pair (NiceAgent *agent, guint stream_id, NiceComponent *component, NiceCandidateImpl *local_cand, CandidateCheckPair *parent_pair)
{
CandidateCheckPair *pair = g_slice_new0 (CandidateCheckPair);
NiceStream *stream = agent_find_stream (agent, stream_id);
pair->stream_id = stream_id;
pair->component_id = component->id;;
pair->local = local_cand;
pair->local = (NiceCandidate *) local_cand;
pair->remote = parent_pair->remote;
pair->sockptr = local_cand->sockptr;
parent_pair->discovered_pair = pair;
......@@ -3308,7 +3314,7 @@ static CandidateCheckPair *priv_add_peer_reflexive_pair (NiceAgent *agent, guint
tmpbuf2, nice_address_get_port (&pair->remote->addr));
}
g_snprintf (pair->foundation, NICE_CANDIDATE_PAIR_MAX_FOUNDATION, "%s:%s",
local_cand->foundation, parent_pair->remote->foundation);
local_cand->c.foundation, parent_pair->remote->foundation);
if (agent->controlling_mode == TRUE)
pair->priority = nice_candidate_pair_priority (pair->local->priority,
......@@ -3466,7 +3472,7 @@ static CandidateCheckPair *priv_process_response_check_for_reflexive(NiceAgent *
"Constructing a Valid Pair") */
if (local_cand)
new_pair = priv_add_peer_reflexive_pair (agent, stream->id, component,
local_cand, p);
(NiceCandidateImpl *) local_cand, p);
/* note: this is same as "adding to VALID LIST" in the spec
text */
if (new_pair)
......@@ -3815,7 +3821,7 @@ priv_calc_turn_timeout (guint lifetime)
static void
priv_add_new_turn_refresh (NiceAgent *agent, CandidateDiscovery *cdisco,
NiceCandidate *relay_cand, guint lifetime)
NiceCandidateImpl *relay_cand, guint lifetime)
{
CandidateRefresh *cand;
......@@ -3974,7 +3980,7 @@ static gboolean priv_map_reply_to_relay_request (NiceAgent *agent, StunMessage *
res == STUN_USAGE_TURN_RETURN_MAPPED_SUCCESS) {
/* case: successful allocate, create a new local candidate */
NiceAddress niceaddr;
NiceCandidate *relay_cand;
NiceCandidateImpl *relay_cand;
nice_address_set_from_sockaddr (&niceaddr, &relayaddr.addr);
......@@ -4422,8 +4428,8 @@ static gboolean conn_check_handle_renomination (NiceAgent *agent, NiceStream *st
* selected pair's priority so this pair gets SELECTED!
*/
if (component->selected_pair.priority &&
component->selected_pair.remote && component->selected_pair.remote != remote_candidate &&
component->selected_pair.local && component->selected_pair.local != local_candidate) {
component->selected_pair.remote && component->selected_pair.remote != (NiceCandidateImpl *) remote_candidate &&
component->selected_pair.local && component->selected_pair.local != (NiceCandidateImpl *) local_candidate) {
for (lst = stream->conncheck_list; lst; lst = lst->next) {
CandidateCheckPair *pair = lst->data;
if (pair->local == local_candidate && pair->remote == remote_candidate) {
......@@ -4851,8 +4857,8 @@ conn_check_prune_socket (NiceAgent *agent, NiceStream *stream, NiceComponent *co
CandidateCheckPair *p = l->data;
GSList *next = l->next;
if ((p->local != NULL && p->local->sockptr == sock) ||
(p->remote != NULL && p->remote->sockptr == sock) ||
if ((p->local != NULL && ((NiceCandidateImpl*) p->local)->sockptr == sock) ||
(p->remote != NULL && ((NiceCandidateImpl*)p->remote)->sockptr == sock) ||
(p->sockptr == sock)) {
nice_debug ("Agent %p : Retransmissions failed, giving up on pair %p",
agent, p);
......
......@@ -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