agent-priv.h 10.2 KB
Newer Older
1 2 3
/*
 * This file is part of the Nice GLib ICE library.
 *
4 5 6
 * (C) 2006-2009 Collabora Ltd.
 *  Contact: Youness Alaoui
 * (C) 2006-2009 Nokia Corporation. All rights reserved.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
 *  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.
26
 *   Youness Alaoui, Collabora Ltd.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
 *   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 */

Youness Alaoui's avatar
Youness Alaoui committed
45 46 47 48 49 50 51

#ifdef HAVE_CONFIG_H
# include <config.h>
#else
#define NICEAPI_EXPORT
#endif

52 53 54
#include <glib.h>

#include "agent.h"
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84

/**
 * NiceInputMessageIter:
 * @message: index of the message currently being written into
 * @buffer: index of the buffer currently being written into
 * @offset: byte offset into the buffer
 *
 * Iterator for sequentially writing into an array of #NiceInputMessages,
 * tracking the current write position (i.e. the index of the next byte to be
 * written).
 *
 * If @message is equal to the number of messages in the associated
 * #NiceInputMessage array, and @buffer and @offset are zero, the iterator is at
 * the end of the messages array, and the array is (presumably) full.
 *
 * Since: 0.1.5
 */
typedef struct {
  guint message;
  guint buffer;
  gsize offset;
} NiceInputMessageIter;

void
nice_input_message_iter_reset (NiceInputMessageIter *iter);
gboolean
nice_input_message_iter_is_at_end (NiceInputMessageIter *iter,
    NiceInputMessage *messages, guint n_messages);
guint
nice_input_message_iter_get_n_valid_messages (NiceInputMessageIter *iter);
85 86 87
gboolean
nice_input_message_iter_compare (const NiceInputMessageIter *a,
    const NiceInputMessageIter *b);
88 89


90
#include "socket.h"
91 92 93
#include "candidate.h"
#include "stream.h"
#include "conncheck.h"
94
#include "component.h"
95
#include "random.h"
96
#include "stun/stunagent.h"
97 98
#include "stun/usages/turn.h"
#include "stun/usages/ice.h"
99

Youness Alaoui's avatar
Youness Alaoui committed
100
#ifdef HAVE_GUPNP
101
#include <libgupnp-igd/gupnp-simple-igd-thread.h>
Youness Alaoui's avatar
Youness Alaoui committed
102 103
#endif

104 105 106
/* XXX: starting from ICE ID-18, Ta SHOULD now be set according
 *      to session bandwidth -> this is not yet implemented in NICE */

Kai Vehmanen's avatar
Kai Vehmanen committed
107
#define NICE_AGENT_TIMER_TA_DEFAULT 20      /* timer Ta, msecs (impl. defined) */
108
#define NICE_AGENT_TIMER_TR_DEFAULT 25000   /* timer Tr, msecs (impl. defined) */
109 110
#define NICE_AGENT_TIMER_TR_MIN     15000   /* timer Tr, msecs (ICE ID-19) */
#define NICE_AGENT_MAX_CONNECTIVITY_CHECKS_DEFAULT 100 /* see spec 5.7.3 (ID-19) */
111

112 113
#define NICE_AGENT_KEEPALIVE_DEFAULT_TIMEOUT 200 /* Start at 200ms, then doube 6 times for a total of 25.4s */

114

115
/* An upper limit to size of STUN packets handled (based on Ethernet
116 117 118 119 120
 * MTU and estimated typical sizes of ICE STUN packet */
#define MAX_STUN_DATAGRAM_PAYLOAD    1300

struct _NiceAgent
{
121
  GObject parent;                 /* gobject pointer */
122

123 124 125 126 127 128 129 130 131 132 133 134
  gboolean full_mode;             /* property: full-mode */
  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 *proxy_ip;                /* property: Proxy server IP */
  guint proxy_port;               /* property: Proxy server port */
  NiceProxyType proxy_type;       /* property: Proxy type */
  gchar *proxy_username;          /* property: Proxy username */
  gchar *proxy_password;          /* property: Proxy password */
  gboolean controlling_mode;      /* property: controlling-mode */
  guint timer_ta;                 /* property: timer Ta */
  guint max_conn_checks;          /* property: max connectivity checks */
135
  gboolean force_relay;           /* property: force relay */
136
  gboolean turn_short_term;       /* property: turn short term credentials */
137

138
  GSList *local_addresses;        /* list of NiceAddresses for local
139
				     interfaces */
140 141 142 143 144 145
  GSList *streams;                /* list of Stream objects */
  GMainContext *main_context;     /* main context pointer */
  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 */
146
  GSList *triggered_check_queue;  /* pairs in the triggered check list */
147 148 149 150 151 152
  guint discovery_unsched_items;  /* number of discovery items unscheduled */
  GSource *discovery_timer_source; /* source of discovery timer */
  GSource *conncheck_timer_source; /* source of conncheck timer */
  GSource *keepalive_timer_source; /* source of keepalive timer */
  GSList *refresh_list;         /* list of CandidateRefresh items */
  guint64 tie_breaker;            /* tie breaker (ICE sect 5.2
153
				     "Determining Role" ID-19) */
154
  NiceCompatibility compatibility; /* property: Compatibility mode */
155
  gboolean media_after_tick;       /* Received media after keepalive tick */
Youness Alaoui's avatar
Youness Alaoui committed
156
#ifdef HAVE_GUPNP
157
  GUPnPSimpleIgdThread* upnp;	   /* GUPnP Single IGD agent */
Youness Alaoui's avatar
Youness Alaoui committed
158 159
  gboolean upnp_enabled;           /* whether UPnP discovery is enabled */
  guint upnp_timeout;              /* UPnP discovery timeout */
160
  GSList *upnp_mapping;            /* NiceAddresses of cands being mapped */
Youness Alaoui's avatar
Youness Alaoui committed
161 162
  GSource *upnp_timer_source;      /* source of upnp timeout timer */
#endif
163
  gchar *software_attribute;       /* SOFTWARE attribute */
164
  gboolean keepalive_conncheck;    /* property: keepalive_conncheck */
165 166

  GQueue pending_signals;
167
  guint16 rfc4571_expecting_length;
Youness Alaoui's avatar
Youness Alaoui committed
168 169
  gboolean use_ice_udp;
  gboolean use_ice_tcp;
170 171 172 173 174 175 176 177
  /* XXX: add pointer to internal data struct for ABI-safe extensions */
};

gboolean
agent_find_component (
  NiceAgent *agent,
  guint stream_id,
  guint component_id,
178
  NiceStream **stream,
179
  NiceComponent **component) G_GNUC_WARN_UNUSED_RESULT;
180

181
NiceStream *agent_find_stream (NiceAgent *agent, guint stream_id);
182

183
void agent_gathering_done (NiceAgent *agent);
184 185
void agent_signal_gathering_done (NiceAgent *agent);

186 187
void agent_lock (void);
void agent_unlock (void);
188
void agent_unlock_and_emit (NiceAgent *agent);
189

190 191 192 193
void agent_signal_new_selected_pair (
  NiceAgent *agent,
  guint stream_id,
  guint component_id,
194 195
  NiceCandidate *lcandidate,
  NiceCandidate *rcandidate);
196 197 198 199 200 201 202 203 204 205 206

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);

207 208
void agent_signal_new_remote_candidate (NiceAgent *agent, NiceCandidate *candidate);

209
void agent_signal_initial_binding_request_received (NiceAgent *agent, NiceStream *stream);
210

211
guint64 agent_candidate_pair_priority (NiceAgent *agent, NiceCandidate *local, NiceCandidate *remote);
212

213 214
void agent_timeout_add_with_context (NiceAgent *agent, GSource **out,
    const gchar *name, guint interval, GSourceFunc function, gpointer data);
215

216 217 218 219
StunUsageIceCompatibility agent_to_ice_compatibility (NiceAgent *agent);
StunUsageTurnCompatibility agent_to_turn_compatibility (NiceAgent *agent);
NiceTurnSocketCompatibility agent_to_turn_socket_compatibility (NiceAgent *agent);

220 221 222
void agent_remove_local_candidate (NiceAgent *agent,
    NiceCandidate *candidate);

223 224
void nice_agent_init_stun_agent (NiceAgent *agent, StunAgent *stun_agent);

225 226
void _priv_set_socket_tos (NiceAgent *agent, NiceSocket *sock, gint tos);

227 228
void _tcp_sock_is_writable (NiceSocket *sock, gpointer user_data);

229 230 231 232 233 234
gboolean
component_io_cb (
  GSocket *gsocket,
  GIOCondition condition,
  gpointer data);

235 236 237 238
gsize
memcpy_buffer_to_input_message (NiceInputMessage *message,
    const guint8 *buffer, gsize buffer_length);
guint8 *
239
compact_input_message (const NiceInputMessage *message, gsize *buffer_length);
240

241 242 243
guint8 *
compact_output_message (const NiceOutputMessage *message, gsize *buffer_length);

244 245 246
gsize
output_message_get_size (const NiceOutputMessage *message);

247 248 249
gssize agent_socket_send (NiceSocket *sock, const NiceAddress *addr, gsize len,
    const gchar *buf);

250 251 252 253 254 255 256 257 258 259 260 261 262 263 264

guint32
nice_candidate_jingle_priority (NiceCandidate *candidate);

guint32
nice_candidate_msn_priority (NiceCandidate *candidate);

guint32
nice_candidate_ice_priority_full (guint type_pref, guint local_pref,
    guint component_id);

guint32
nice_candidate_ice_priority (const NiceCandidate *candidate,
    gboolean reliable, gboolean nat_assisted);

265 266 267 268
guint32
nice_candidate_ms_ice_priority (const NiceCandidate *candidate,
    gboolean reliable, gboolean nat_assisted);

269 270 271
guint64
nice_candidate_pair_priority (guint32 o_prio, guint32 a_prio);

272 273 274 275 276 277 278 279 280 281
/*
 * nice_debug_init:
 *
 * Initialize the debugging system. Uses the NICE_DEBUG environment variable
 * to set the appropriate debugging flags
 */
void nice_debug_init (void);


#ifdef NDEBUG
282
static inline gboolean nice_debug_is_enabled (void) { return FALSE; }
283
static inline gboolean nice_debug_is_verbose (void) { return FALSE; }
284
static inline void nice_debug (const char *fmt, ...) { }
285
static inline void nice_debug_verbose (const char *fmt, ...) { }
286 287
#else
gboolean nice_debug_is_enabled (void);
288
gboolean nice_debug_is_verbose (void);
289
void nice_debug (const char *fmt, ...) G_GNUC_PRINTF (1, 2);
290
void nice_debug_verbose (const char *fmt, ...) G_GNUC_PRINTF (1, 2);
291
#endif
292

293
#endif /*_NICE_AGENT_PRIV_H */