2 * This file is part of the Nice GLib ICE library.
4 * (C) 2006-2009 Collabora Ltd.
5 * Contact: Youness Alaoui
6 * (C) 2006-2009 Nokia Corporation. All rights reserved.
7 * Contact: Kai Vehmanen
9 * The contents of this file are subject to the Mozilla Public License Version
10 * 1.1 (the "License"); you may not use this file except in compliance with
11 * the License. You may obtain a copy of the License at
12 * http://www.mozilla.org/MPL/
14 * Software distributed under the License is distributed on an "AS IS" basis,
15 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
16 * for the specific language governing rights and limitations under the
19 * The Original Code is the Nice GLib ICE library.
21 * The Initial Developers of the Original Code are Collabora Ltd and Nokia
22 * Corporation. All Rights Reserved.
25 * Dafydd Harries, Collabora Ltd.
26 * Youness Alaoui, Collabora Ltd.
29 * Alternatively, the contents of this file may be used under the terms of the
30 * the GNU Lesser General Public License Version 2.1 (the "LGPL"), in which
31 * case the provisions of LGPL are applicable instead of those above. If you
32 * wish to allow use of your version of this file only under the terms of the
33 * LGPL and not to allow others to use your version of this file under the
34 * MPL, indicate your decision by deleting the provisions above and replace
35 * them with the notice and other provisions required by the LGPL. If you do
36 * not delete the provisions above, a recipient may use your version of this
37 * file under either the MPL or the LGPL.
40 #ifndef _NICE_AGENT_PRIV_H
41 #define _NICE_AGENT_PRIV_H
43 /* note: this is a private header part of agent.h */
49 #define NICEAPI_EXPORT
57 * NiceInputMessageIter:
58 * @message: index of the message currently being written into
59 * @buffer: index of the buffer currently being written into
60 * @offset: byte offset into the buffer
62 * Iterator for sequentially writing into an array of #NiceInputMessages,
63 * tracking the current write position (i.e. the index of the next byte to be
66 * If @message is equal to the number of messages in the associated
67 * #NiceInputMessage array, and @buffer and @offset are zero, the iterator is at
68 * the end of the messages array, and the array is (presumably) full.
76 } NiceInputMessageIter;
79 nice_input_message_iter_reset (NiceInputMessageIter *iter);
81 nice_input_message_iter_is_at_end (NiceInputMessageIter *iter,
82 NiceInputMessage *messages, guint n_messages);
84 nice_input_message_iter_get_n_valid_messages (NiceInputMessageIter *iter);
86 nice_input_message_iter_compare (const NiceInputMessageIter *a,
87 const NiceInputMessageIter *b);
91 #include "candidate.h"
93 #include "conncheck.h"
94 #include "component.h"
96 #include "stun/stunagent.h"
97 #include "stun/usages/turn.h"
98 #include "stun/usages/ice.h"
101 #include <libgupnp-igd/gupnp-simple-igd-thread.h>
104 /* XXX: starting from ICE ID-18, Ta SHOULD now be set according
105 * to session bandwidth -> this is not yet implemented in NICE */
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 #define NICE_AGENT_MAX_CONNECTIVITY_CHECKS_DEFAULT 100 /* see RFC 8445 6.1.2.5 */
112 /* An upper limit to size of STUN packets handled (based on Ethernet
113 * MTU and estimated typical sizes of ICE STUN packet */
114 #define MAX_STUN_DATAGRAM_PAYLOAD 1300
116 #define NICE_COMPONENT_MAX_VALID_CANDIDATES 50 /* maximum number of validates remote candidates to keep, the number is arbitrary but hopefully large enough */
118 /* A convenient macro to test if the agent is compatible with RFC5245
119 * or OC2007R2. Specifically these two modes share the support
120 * of the regular or aggressive nomination mode */
121 #define NICE_AGENT_IS_COMPATIBLE_WITH_RFC5245_OR_OC2007R2(obj) \
122 ((obj)->compatibility == NICE_COMPATIBILITY_RFC5245 || \
123 (obj)->compatibility == NICE_COMPATIBILITY_OC2007R2)
127 GObject parent; /* gobject pointer */
129 GMutex agent_mutex; /* Mutex used for thread-safe lib */
131 gboolean full_mode; /* property: full-mode */
132 gchar *stun_server_ip; /* property: STUN server IP */
133 guint stun_server_port; /* property: STUN server port */
134 gchar *proxy_ip; /* property: Proxy server IP */
135 guint proxy_port; /* property: Proxy server port */
136 NiceProxyType proxy_type; /* property: Proxy type */
137 gchar *proxy_username; /* property: Proxy username */
138 gchar *proxy_password; /* property: Proxy password */
139 gboolean saved_controlling_mode;/* property: controlling-mode */
140 guint timer_ta; /* property: timer Ta */
141 guint max_conn_checks; /* property: max connectivity checks */
142 gboolean force_relay; /* property: force relay */
143 guint stun_max_retransmissions; /* property: stun max retransmissions, Rc */
144 guint stun_initial_timeout; /* property: stun initial timeout, RTO */
145 guint stun_reliable_timeout; /* property: stun reliable timeout */
146 NiceNominationMode nomination_mode; /* property: Nomination mode */
147 gboolean support_renomination; /* property: support RENOMINATION STUN attribute */
148 guint idle_timeout; /* property: conncheck timeout before stop */
150 GSList *local_addresses; /* list of NiceAddresses for local
152 GSList *streams; /* list of Stream objects */
153 GSList *pruning_streams; /* list of Streams current being shut down */
154 GMainContext *main_context; /* main context pointer */
155 guint next_candidate_id; /* id of next created candidate */
156 guint next_stream_id; /* id of next created candidate */
157 NiceRNG *rng; /* random number generator */
158 GSList *discovery_list; /* list of CandidateDiscovery items */
159 GSList *triggered_check_queue; /* pairs in the triggered check list */
160 guint discovery_unsched_items; /* number of discovery items unscheduled */
161 GSource *discovery_timer_source; /* source of discovery timer */
162 GSource *conncheck_timer_source; /* source of conncheck timer */
163 GSource *keepalive_timer_source; /* source of keepalive timer */
164 GSList *refresh_list; /* list of CandidateRefresh items */
165 guint64 tie_breaker; /* tie breaker (ICE sect 5.2
166 "Determining Role" ID-19) */
167 NiceCompatibility compatibility; /* property: Compatibility mode */
168 gboolean media_after_tick; /* Received media after keepalive tick */
170 GUPnPSimpleIgdThread* upnp; /* GUPnP Single IGD agent */
171 gboolean upnp_enabled; /* whether UPnP discovery is enabled */
172 guint upnp_timeout; /* UPnP discovery timeout */
173 GSList *upnp_mapping; /* NiceAddresses of cands being mapped */
174 GSource *upnp_timer_source; /* source of upnp timeout timer */
176 gchar *software_attribute; /* SOFTWARE attribute */
177 gboolean reliable; /* property: reliable */
178 gboolean keepalive_conncheck; /* property: keepalive_conncheck */
180 GQueue pending_signals;
181 guint16 rfc4571_expecting_length;
182 gboolean use_ice_udp;
183 gboolean use_ice_tcp;
184 gboolean use_ice_trickle;
186 guint conncheck_ongoing_idle_delay; /* ongoing delay before timer stop */
187 gboolean controlling_mode; /* controlling mode used by the
189 /* XXX: add pointer to internal data struct for ABI-safe extensions */
193 agent_find_component (
198 NiceComponent **component) G_GNUC_WARN_UNUSED_RESULT;
200 NiceStream *agent_find_stream (NiceAgent *agent, guint stream_id);
202 void agent_gathering_done (NiceAgent *agent);
203 void agent_signal_gathering_done (NiceAgent *agent);
205 void agent_lock (NiceAgent *agent);
206 void agent_unlock (NiceAgent *agent);
207 void agent_unlock_and_emit (NiceAgent *agent);
209 void agent_signal_new_selected_pair (
213 NiceCandidate *lcandidate,
214 NiceCandidate *rcandidate);
216 void agent_signal_component_state_change (
220 NiceComponentState state);
222 void agent_signal_new_candidate (
224 NiceCandidate *candidate);
226 void agent_signal_new_remote_candidate (NiceAgent *agent, NiceCandidate *candidate);
228 void agent_signal_initial_binding_request_received (NiceAgent *agent, NiceStream *stream);
230 guint64 agent_candidate_pair_priority (NiceAgent *agent, NiceCandidate *local, NiceCandidate *remote);
232 NiceSocket * agent_create_tcp_turn_socket (NiceAgent *agent,
233 NiceStream *stream, NiceComponent *component, NiceSocket *nicesock,
234 NiceAddress *server, NiceRelayType type, gboolean reliable_tcp);
236 typedef gboolean (*NiceTimeoutLockedCallback)(NiceAgent *agent,
238 void agent_timeout_add_with_context (NiceAgent *agent, GSource **out,
239 const gchar *name, guint interval, NiceTimeoutLockedCallback function,
241 void agent_timeout_add_seconds_with_context (NiceAgent *agent, GSource **out,
242 const gchar *name, guint interval, NiceTimeoutLockedCallback function,
245 StunUsageIceCompatibility agent_to_ice_compatibility (NiceAgent *agent);
246 StunUsageTurnCompatibility agent_to_turn_compatibility (NiceAgent *agent);
247 NiceTurnSocketCompatibility agent_to_turn_socket_compatibility (NiceAgent *agent);
249 void agent_remove_local_candidate (NiceAgent *agent,
250 NiceCandidate *candidate);
252 void nice_agent_init_stun_agent (NiceAgent *agent, StunAgent *stun_agent);
254 void _priv_set_socket_tos (NiceAgent *agent, NiceSocket *sock, gint tos);
256 void _tcp_sock_is_writable (NiceSocket *sock, gpointer user_data);
261 GIOCondition condition,
265 memcpy_buffer_to_input_message (NiceInputMessage *message,
266 const guint8 *buffer, gsize buffer_length);
268 compact_input_message (const NiceInputMessage *message, gsize *buffer_length);
271 compact_output_message (const NiceOutputMessage *message, gsize *buffer_length);
274 output_message_get_size (const NiceOutputMessage *message);
277 input_message_get_size (const NiceInputMessage *message);
279 gssize agent_socket_send (NiceSocket *sock, const NiceAddress *addr, gsize len,
283 nice_candidate_jingle_priority (NiceCandidate *candidate);
286 nice_candidate_msn_priority (NiceCandidate *candidate);
289 nice_candidate_ice_priority_full (guint type_pref, guint local_pref,
293 nice_candidate_ice_priority (const NiceCandidate *candidate,
294 gboolean reliable, gboolean nat_assisted);
297 nice_candidate_ms_ice_priority (const NiceCandidate *candidate,
298 gboolean reliable, gboolean nat_assisted);
301 nice_candidate_pair_priority (guint32 o_prio, guint32 a_prio);
303 #define NICE_CANDIDATE_PAIR_PRIORITY_MAX_SIZE 32
306 nice_candidate_pair_priority_to_string (guint64 prio, gchar *string);
311 * Initialize the debugging system. Uses the NICE_DEBUG environment variable
312 * to set the appropriate debugging flags
314 void nice_debug_init (void);
318 static inline gboolean nice_debug_is_enabled (void) { return FALSE; }
319 static inline gboolean nice_debug_is_verbose (void) { return FALSE; }
320 static inline void nice_debug (const char *fmt, ...) { }
321 static inline void nice_debug_verbose (const char *fmt, ...) { }
323 gboolean nice_debug_is_enabled (void);
324 gboolean nice_debug_is_verbose (void);
325 void nice_debug (const char *fmt, ...) G_GNUC_PRINTF (1, 2);
326 void nice_debug_verbose (const char *fmt, ...) G_GNUC_PRINTF (1, 2);
329 #if !GLIB_CHECK_VERSION(2, 59, 0)
331 #define G_GNUC_FALLTHROUGH __attribute__((fallthrough))
333 #define G_GNUC_FALLTHROUGH
334 #endif /* __GNUC__ */
337 #endif /*_NICE_AGENT_PRIV_H */