blob: fe38ff58f0a9a5554776d49a4a0002d164c6bfa3 [file] [log] [blame]
Tristan Matthews0a329cc2013-07-17 13:20:14 -04001/* $Id$ */
2/*
3 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
4 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20#ifndef __PJNATH_ICE_STRANS_H__
21#define __PJNATH_ICE_STRANS_H__
22
23
24/**
25 * @file ice_strans.h
26 * @brief ICE Stream Transport
27 */
28#include <pjnath/ice_session.h>
29#include <pjnath/stun_sock.h>
30#include <pjnath/turn_sock.h>
31#include <pjlib-util/resolver.h>
32#include <pj/ioqueue.h>
33#include <pj/timer.h>
34
35
36PJ_BEGIN_DECL
37
38
39/**
40 * @addtogroup PJNATH_ICE_STREAM_TRANSPORT
41 * @{
42 *
43 * This module describes ICE stream transport, as represented by #pj_ice_strans
44 * structure, and is part of PJNATH - the Open Source NAT traversal helper
45 * library.
46 *
47 * ICE stream transport, as represented by #pj_ice_strans structure, is an ICE
48 * capable class for transporting media streams within a media session.
49 * It consists of one or more transport sockets (typically two for RTP
50 * based communication - one for RTP and one for RTCP), and an
51 * \ref PJNATH_ICE_SESSION for performing connectivity checks among the.
52 * various candidates of the transport addresses.
53 *
54 *
55 * \section ice_strans_using_sec Using the ICE stream transport
56 *
57 * The steps below describe how to use ICE session:
58 *
59 * - initialize a #pj_ice_strans_cfg structure. This contains various
60 * settings for the ICE stream transport, and among other things contains
61 * the STUN and TURN settings.\n\n
62 * - create the instance with #pj_ice_strans_create(). Among other things,
63 * the function needs the following arguments:
64 * - the #pj_ice_strans_cfg structure for the main configurations
65 * - number of components to be supported
66 * - instance of #pj_ice_strans_cb structure to report callbacks to
67 * application.\n\n
68 * - while the #pj_ice_strans_create() call completes immediately, the
69 * initialization will be running in the background to gather the
70 * candidates (for example STUN and TURN candidates, if they are enabled
71 * in the #pj_ice_strans_cfg setting). Application will be notified when
72 * the initialization completes in the \a on_ice_complete callback of
73 * the #pj_ice_strans_cb structure (the \a op argument of this callback
74 * will be PJ_ICE_STRANS_OP_INIT).\n\n
75 * - when media stream is to be started (for example, a call is to be
76 * started), create an ICE session by calling #pj_ice_strans_init_ice().\n\n
77 * - the application now typically will need to communicate local ICE
78 * information to remote host. It can achieve this by using the following
79 * functions to query local ICE information:
80 * - #pj_ice_strans_get_ufrag_pwd()
81 * - #pj_ice_strans_enum_cands()
82 * - #pj_ice_strans_get_def_cand()\n
83 * The application may need to encode the above information as SDP.\n\n
84 * - when the application receives remote ICE information (for example, from
85 * the SDP received from remote), it can now start ICE negotiation, by
86 * calling #pj_ice_strans_start_ice(). This function requires some
87 * information about remote ICE agent such as remote ICE username fragment
88 * and password as well as array of remote candidates.\n\n
89 * - note that the PJNATH library does not work with SDP; application would
90 * need to encode and parse the SDP itself.\n\n
91 * - once ICE negotiation has been started, application will be notified
92 * about the completion in the \a on_ice_complete() callback of the
93 * #pj_ice_strans_cb.\n\n
94 * - at any time, application may send or receive data. However the ICE
95 * stream transport may not be able to send it depending on its current
96 * state. Before ICE negotiation is started, the data will be sent using
97 * default candidate of the component. After negotiation is completed,
98 * data will be sent using the candidate from the successful/nominated
99 * pair. The ICE stream transport may not be able to send data while
100 * negotiation is in progress.\n\n
101 * - application sends data by using #pj_ice_strans_sendto(). Incoming
102 * data will be reported in \a on_rx_data() callback of the
103 * #pj_ice_strans_cb.\n\n
104 * - once the media session has finished (e.g. user hangs up the call),
105 * destroy the ICE session with #pj_ice_strans_stop_ice().\n\n
106 * - at this point, application may destroy the ICE stream transport itself,
107 * or let it run so that it can be reused to create other ICE session.
108 * The benefit of letting the ICE stream transport alive (without any
109 * session active) is to avoid delay with the initialization, howerver
110 * keeping the transport alive means the transport needs to keep the
111 * STUN binding open by using keep-alive and also TURN allocation alive,
112 * and this will consume power which is an important issue for mobile
113 * applications.\n\n
114 */
115
116/** Forward declaration for ICE stream transport. */
117typedef struct pj_ice_strans pj_ice_strans;
118
119/** Transport operation types to be reported on \a on_status() callback */
120typedef enum pj_ice_strans_op
121{
122 /** Initialization (candidate gathering) */
123 PJ_ICE_STRANS_OP_INIT,
124
125 /** Negotiation */
126 PJ_ICE_STRANS_OP_NEGOTIATION,
127
128 /** This operatino is used to report failure in keep-alive operation.
129 * Currently it is only used to report TURN Refresh failure.
130 */
131 PJ_ICE_STRANS_OP_KEEP_ALIVE
132
133} pj_ice_strans_op;
134
135/**
136 * This structure contains callbacks that will be called by the
137 * ICE stream transport.
138 */
139typedef struct pj_ice_strans_cb
140{
141 /**
142 * This callback will be called when the ICE transport receives
143 * incoming packet from the sockets which is not related to ICE
144 * (for example, normal RTP/RTCP packet destined for application).
145 *
146 * @param ice_st The ICE stream transport.
147 * @param comp_id The component ID.
148 * @param pkt The packet.
149 * @param size Size of the packet.
150 * @param src_addr Source address of the packet.
151 * @param src_addr_len Length of the source address.
152 */
153 void (*on_rx_data)(pj_ice_strans *ice_st,
154 unsigned comp_id,
155 void *pkt, pj_size_t size,
156 const pj_sockaddr_t *src_addr,
157 unsigned src_addr_len);
158
159 /**
160 * Callback to report status of various ICE operations.
161 *
162 * @param ice_st The ICE stream transport.
163 * @param op The operation which status is being reported.
164 * @param status Operation status.
165 */
166 void (*on_ice_complete)(pj_ice_strans *ice_st,
167 pj_ice_strans_op op,
168 pj_status_t status);
169
170} pj_ice_strans_cb;
171
172
173/**
174 * This structure describes ICE stream transport configuration. Application
175 * should initialize the structure by calling #pj_ice_strans_cfg_default()
176 * before changing the settings.
177 */
178typedef struct pj_ice_strans_cfg
179{
180 /**
181 * Address family, IPv4 or IPv6. Currently only pj_AF_INET() (IPv4)
182 * is supported, and this is the default value.
183 */
184 int af;
185
186 /**
187 * STUN configuration which contains the timer heap and
188 * ioqueue instance to be used, and STUN retransmission
189 * settings. This setting is mandatory.
190 *
191 * The default value is all zero. Application must initialize
192 * this setting with #pj_stun_config_init().
193 */
194 pj_stun_config stun_cfg;
195
196 /**
197 * DNS resolver to be used to resolve servers. If DNS SRV
198 * resolution is required, the resolver must be set.
199 *
200 * The default value is NULL.
201 */
202 pj_dns_resolver *resolver;
203
204 /**
205 * This contains various STUN session options. Once the ICE stream
206 * transport is created, application may also change the options
207 * with #pj_ice_strans_set_options().
208 */
209 pj_ice_sess_options opt;
210
211 /**
212 * STUN and local transport settings. This specifies the
213 * settings for local UDP socket, which will be resolved
214 * to get the STUN mapped address.
215 */
216 struct {
217 /**
218 * Optional configuration for STUN transport. The default
219 * value will be initialized with #pj_stun_sock_cfg_default().
220 */
221 pj_stun_sock_cfg cfg;
222
223 /**
224 * Maximum number of host candidates to be added. If the
225 * value is zero, no host candidates will be added.
226 *
227 * Default: 64
228 */
229 unsigned max_host_cands;
230
231 /**
232 * Include loopback addresses in the host candidates.
233 *
234 * Default: PJ_FALSE
235 */
236 pj_bool_t loop_addr;
237
238 /**
239 * Specify the STUN server domain or hostname or IP address.
240 * If DNS SRV resolution is required, application must fill
241 * in this setting with the domain name of the STUN server
242 * and set the resolver instance in the \a resolver field.
243 * Otherwise if the \a resolver setting is not set, this
244 * field will be resolved with hostname resolution and in
245 * this case the \a port field must be set.
246 *
247 * The \a port field should also be set even when DNS SRV
248 * resolution is used, in case the DNS SRV resolution fails.
249 *
250 * When this field is empty, STUN mapped address resolution
251 * will not be performed. In this case only ICE host candidates
252 * will be added to the ICE transport, unless if \a no_host_cands
253 * field is set. In this case, both host and srflx candidates
254 * are disabled.
255 *
256 * The default value is empty.
257 */
258 pj_str_t server;
259
260 /**
261 * The port number of the STUN server, when \a server
262 * field specifies a hostname rather than domain name. This
263 * field should also be set even when the \a server
264 * specifies a domain name, to allow DNS SRV resolution
265 * to fallback to DNS A/AAAA resolution when the DNS SRV
266 * resolution fails.
267 *
268 * The default value is PJ_STUN_PORT.
269 */
270 pj_uint16_t port;
271
272 /**
273 * Ignore STUN resolution error and proceed with just local
274 * addresses.
275 *
276 * The default is PJ_FALSE
277 */
278 pj_bool_t ignore_stun_error;
279
280 } stun;
281
282 /**
283 * TURN specific settings.
284 */
285 struct {
286 /**
287 * Optional TURN socket settings. The default values will be
288 * initialized by #pj_turn_sock_cfg_default(). This contains
289 * settings such as QoS.
290 */
291 pj_turn_sock_cfg cfg;
292
293 /**
294 * Specify the TURN server domain or hostname or IP address.
295 * If DNS SRV resolution is required, application must fill
296 * in this setting with the domain name of the TURN server
297 * and set the resolver instance in the \a resolver field.
298 * Otherwise if the \a resolver setting is not set, this
299 * field will be resolved with hostname resolution and in
300 * this case the \a port field must be set.
301 *
302 * The \a port field should also be set even when DNS SRV
303 * resolution is used, in case the DNS SRV resolution fails.
304 *
305 * When this field is empty, relay candidate will not be
306 * created.
307 *
308 * The default value is empty.
309 */
310 pj_str_t server;
311
312 /**
313 * The port number of the TURN server, when \a server
314 * field specifies a hostname rather than domain name. This
315 * field should also be set even when the \a server
316 * specifies a domain name, to allow DNS SRV resolution
317 * to fallback to DNS A/AAAA resolution when the DNS SRV
318 * resolution fails.
319 *
320 * Default is zero.
321 */
322 pj_uint16_t port;
323
324 /**
325 * Type of connection to the TURN server.
326 *
327 * Default is PJ_TURN_TP_UDP.
328 */
329 pj_turn_tp_type conn_type;
330
331 /**
332 * Credential to be used for the TURN session. This setting
333 * is mandatory.
334 *
335 * Default is to have no credential.
336 */
337 pj_stun_auth_cred auth_cred;
338
339 /**
340 * Optional TURN Allocate parameter. The default value will be
341 * initialized by #pj_turn_alloc_param_default().
342 */
343 pj_turn_alloc_param alloc_param;
344
345 } turn;
346
347 /**
348 * Component specific settings, which will override the settings in
349 * the STUN and TURN settings above. For example, setting the QoS
350 * parameters here allows the application to have different QoS
351 * traffic type for RTP and RTCP component.
352 */
353 struct {
354 /**
355 * QoS traffic type to be set on this transport. When application
356 * wants to apply QoS tagging to the transport, it's preferable to
357 * set this field rather than \a qos_param fields since this is
358 * more portable.
359 *
360 * Default value is PJ_QOS_TYPE_BEST_EFFORT.
361 */
362 pj_qos_type qos_type;
363
364 /**
365 * Set the low level QoS parameters to the transport. This is a
366 * lower level operation than setting the \a qos_type field and
367 * may not be supported on all platforms.
368 *
369 * By default all settings in this structure are disabled.
370 */
371 pj_qos_params qos_params;
372
373 /**
374 * Specify target value for socket receive buffer size. It will be
375 * applied using setsockopt(). When it fails to set the specified
376 * size, it will try with lower value until the highest possible is
377 * successfully set.
378 *
379 * When this is set to zero, this component will apply socket receive
380 * buffer size settings specified in STUN and TURN socket config
381 * above, i.e: \a stun::cfg::so_rcvbuf_size and
382 * \a turn::cfg::so_rcvbuf_size. Otherwise, this setting will be
383 * applied to STUN and TURN sockets for this component, overriding
384 * the setting specified in STUN/TURN socket config.
385 *
386 * Default: 0
387 */
388 unsigned so_rcvbuf_size;
389
390 /**
391 * Specify target value for socket send buffer size. It will be
392 * applied using setsockopt(). When it fails to set the specified
393 * size, it will try with lower value until the highest possible is
394 * successfully set.
395 *
396 * When this is set to zero, this component will apply socket send
397 * buffer size settings specified in STUN and TURN socket config
398 * above, i.e: \a stun::cfg::so_sndbuf_size and
399 * \a turn::cfg::so_sndbuf_size. Otherwise, this setting will be
400 * applied to STUN and TURN sockets for this component, overriding
401 * the setting specified in STUN/TURN socket config.
402 *
403 * Default: 0
404 */
405 unsigned so_sndbuf_size;
406
407 } comp[PJ_ICE_MAX_COMP];
408
409} pj_ice_strans_cfg;
410
411
412/**
413 * ICE stream transport's state.
414 */
415typedef enum pj_ice_strans_state
416{
417 /**
418 * ICE stream transport is not created.
419 */
420 PJ_ICE_STRANS_STATE_NULL,
421
422 /**
423 * ICE candidate gathering process is in progress.
424 */
425 PJ_ICE_STRANS_STATE_INIT,
426
427 /**
428 * ICE stream transport initialization/candidate gathering process is
429 * complete, ICE session may be created on this stream transport.
430 */
431 PJ_ICE_STRANS_STATE_READY,
432
433 /**
434 * New session has been created and the session is ready.
435 */
436 PJ_ICE_STRANS_STATE_SESS_READY,
437
438 /**
439 * ICE negotiation is in progress.
440 */
441 PJ_ICE_STRANS_STATE_NEGO,
442
443 /**
444 * ICE negotiation has completed successfully and media is ready
445 * to be used.
446 */
447 PJ_ICE_STRANS_STATE_RUNNING,
448
449 /**
450 * ICE negotiation has completed with failure.
451 */
452 PJ_ICE_STRANS_STATE_FAILED
453
454} pj_ice_strans_state;
455
456
457/**
458 * Initialize ICE transport configuration with default values.
459 *
460 * @param cfg The configuration to be initialized.
461 */
462PJ_DECL(void) pj_ice_strans_cfg_default(pj_ice_strans_cfg *cfg);
463
464
465/**
466 * Copy configuration.
467 *
468 * @param pool Pool.
469 * @param dst Destination.
470 * @param src Source.
471 */
472PJ_DECL(void) pj_ice_strans_cfg_copy(pj_pool_t *pool,
473 pj_ice_strans_cfg *dst,
474 const pj_ice_strans_cfg *src);
475
476
477/**
478 * Create and initialize the ICE stream transport with the specified
479 * parameters.
480 *
481 * @param name Optional name for logging identification.
482 * @param cfg Configuration.
483 * @param comp_cnt Number of components.
484 * @param user_data Arbitrary user data to be associated with this
485 * ICE stream transport.
486 * @param cb Callback.
487 * @param p_ice_st Pointer to receive the ICE stream transport
488 * instance.
489 *
490 * @return PJ_SUCCESS if ICE stream transport is created
491 * successfully.
492 */
493PJ_DECL(pj_status_t) pj_ice_strans_create(const char *name,
494 const pj_ice_strans_cfg *cfg,
495 unsigned comp_cnt,
496 void *user_data,
497 const pj_ice_strans_cb *cb,
498 pj_ice_strans **p_ice_st);
499
500/**
501 * Get ICE session state.
502 *
503 * @param ice_st The ICE stream transport.
504 *
505 * @return ICE session state.
506 */
507PJ_DECL(pj_ice_strans_state) pj_ice_strans_get_state(pj_ice_strans *ice_st);
508
509
510/**
511 * Get string representation of ICE state.
512 *
513 * @param state ICE stream transport state.
514 *
515 * @return String.
516 */
517PJ_DECL(const char*) pj_ice_strans_state_name(pj_ice_strans_state state);
518
519
520/**
521 * Destroy the ICE stream transport. This will destroy the ICE session
522 * inside the ICE stream transport, close all sockets and release all
523 * other resources.
524 *
525 * @param ice_st The ICE stream transport.
526 *
527 * @return PJ_SUCCESS, or the appropriate error code.
528 */
529PJ_DECL(pj_status_t) pj_ice_strans_destroy(pj_ice_strans *ice_st);
530
531
532/**
533 * Get the user data associated with the ICE stream transport.
534 *
535 * @param ice_st The ICE stream transport.
536 *
537 * @return The user data.
538 */
539PJ_DECL(void*) pj_ice_strans_get_user_data(pj_ice_strans *ice_st);
540
541
542/**
543 * Get the value of various options of the ICE stream transport.
544 *
545 * @param ice_st The ICE stream transport.
546 * @param opt The options to be initialized with the values
547 * from the ICE stream transport.
548 *
549 * @return PJ_SUCCESS on success, or the appropriate error.
550 */
551PJ_DECL(pj_status_t) pj_ice_strans_get_options(pj_ice_strans *ice_st,
552 pj_ice_sess_options *opt);
553
554/**
555 * Specify various options for this ICE stream transport. Application
556 * should call #pj_ice_strans_get_options() to initialize the options
557 * with their default values.
558 *
559 * @param ice_st The ICE stream transport.
560 * @param opt Options to be applied to this ICE stream transport.
561 *
562 * @return PJ_SUCCESS on success, or the appropriate error.
563 */
564PJ_DECL(pj_status_t) pj_ice_strans_set_options(pj_ice_strans *ice_st,
565 const pj_ice_sess_options *opt);
566
567
568/**
569 * Initialize the ICE session in the ICE stream transport.
570 * When application is about to send an offer containing ICE capability,
571 * or when it receives an offer containing ICE capability, it must
572 * call this function to initialize the internal ICE session. This would
573 * register all transport address aliases for each component to the ICE
574 * session as candidates. Then application can enumerate all local
575 * candidates by calling #pj_ice_strans_enum_cands(), and encode these
576 * candidates in the SDP to be sent to remote agent.
577 *
578 * @param ice_st The ICE stream transport.
579 * @param role ICE role.
580 * @param local_ufrag Optional local username fragment.
581 * @param local_passwd Optional local password.
582 *
583 * @return PJ_SUCCESS, or the appropriate error code.
584 */
585PJ_DECL(pj_status_t) pj_ice_strans_init_ice(pj_ice_strans *ice_st,
586 pj_ice_sess_role role,
587 const pj_str_t *local_ufrag,
588 const pj_str_t *local_passwd);
589
590/**
591 * Check if the ICE stream transport has the ICE session created. The
592 * ICE session is created with #pj_ice_strans_init_ice().
593 *
594 * @param ice_st The ICE stream transport.
595 *
596 * @return PJ_TRUE if #pj_ice_strans_init_ice() has been
597 * called.
598 */
599PJ_DECL(pj_bool_t) pj_ice_strans_has_sess(pj_ice_strans *ice_st);
600
601
602/**
603 * Check if ICE negotiation is still running.
604 *
605 * @param ice_st The ICE stream transport.
606 *
607 * @return PJ_TRUE if ICE session has been created and ICE
608 * negotiation negotiation is in progress.
609 */
610PJ_DECL(pj_bool_t) pj_ice_strans_sess_is_running(pj_ice_strans *ice_st);
611
612
613/**
614 * Check if ICE negotiation has completed.
615 *
616 * @param ice_st The ICE stream transport.
617 *
618 * @return PJ_TRUE if ICE session has been created and the
619 * negotiation is complete.
620 */
621PJ_DECL(pj_bool_t) pj_ice_strans_sess_is_complete(pj_ice_strans *ice_st);
622
623
624/**
625 * Get the current/running component count. If ICE negotiation has not
626 * been started, the number of components will be equal to the number
627 * when the ICE stream transport was created. Once negotiation been
628 * started, the number of components will be the lowest number of
629 * component between local and remote agents.
630 *
631 * @param ice_st The ICE stream transport.
632 *
633 * @return The running number of components.
634 */
635PJ_DECL(unsigned) pj_ice_strans_get_running_comp_cnt(pj_ice_strans *ice_st);
636
637
638/**
639 * Get the ICE username fragment and password of the ICE session. The
640 * local username fragment and password can only be retrieved once ICE
641 * session has been created with #pj_ice_strans_init_ice(). The remote
642 * username fragment and password can only be retrieved once ICE session
643 * has been started with #pj_ice_strans_start_ice().
644 *
645 * Note that the string returned by this function is only valid throughout
646 * the duration of the ICE session, and the application must not modify
647 * these strings. Once the ICE session has been stopped with
648 * #pj_ice_strans_stop_ice(), the pointer in the string will no longer be
649 * valid.
650 *
651 * @param ice_st The ICE stream transport.
652 * @param loc_ufrag Optional pointer to receive ICE username fragment
653 * of local endpoint from the ICE session.
654 * @param loc_pwd Optional pointer to receive ICE password of local
655 * endpoint from the ICE session.
656 * @param rem_ufrag Optional pointer to receive ICE username fragment
657 * of remote endpoint from the ICE session.
658 * @param rem_pwd Optional pointer to receive ICE password of remote
659 * endpoint from the ICE session.
660 *
661 * @return PJ_SUCCESS if the strings have been retrieved
662 * successfully.
663 */
664PJ_DECL(pj_status_t) pj_ice_strans_get_ufrag_pwd(pj_ice_strans *ice_st,
665 pj_str_t *loc_ufrag,
666 pj_str_t *loc_pwd,
667 pj_str_t *rem_ufrag,
668 pj_str_t *rem_pwd);
669
670
671/**
672 * Get the number of local candidates for the specified component ID.
673 *
674 * @param ice_st The ICE stream transport.
675 * @param comp_id Component ID.
676 *
677 * @return The number of candidates.
678 */
679PJ_DECL(unsigned) pj_ice_strans_get_cands_count(pj_ice_strans *ice_st,
680 unsigned comp_id);
681
682/**
683 * Enumerate the local candidates for the specified component.
684 *
685 * @param ice_st The ICE stream transport.
686 * @param comp_id Component ID.
687 * @param count On input, it specifies the maximum number of
688 * elements. On output, it will be filled with
689 * the number of candidates copied to the
690 * array.
691 * @param cand Array of candidates.
692 *
693 * @return PJ_SUCCESS, or the appropriate error code.
694 */
695PJ_DECL(pj_status_t) pj_ice_strans_enum_cands(pj_ice_strans *ice_st,
696 unsigned comp_id,
697 unsigned *count,
698 pj_ice_sess_cand cand[]);
699
700/**
701 * Get the default candidate for the specified component. When this
702 * function is called before ICE negotiation completes, the default
703 * candidate is selected according to local preference criteria. When
704 * this function is called after ICE negotiation completes, the
705 * default candidate is the candidate that forms the valid pair.
706 *
707 * @param ice_st The ICE stream transport.
708 * @param comp_id Component ID.
709 * @param cand Pointer to receive the default candidate
710 * information.
711 */
712PJ_DECL(pj_status_t) pj_ice_strans_get_def_cand(pj_ice_strans *ice_st,
713 unsigned comp_id,
714 pj_ice_sess_cand *cand);
715
716/**
717 * Get the current ICE role. ICE session must have been initialized
718 * before this function can be called.
719 *
720 * @param ice_st The ICE stream transport.
721 *
722 * @return Current ICE role.
723 */
724PJ_DECL(pj_ice_sess_role) pj_ice_strans_get_role(pj_ice_strans *ice_st);
725
726
727/**
728 * Change session role. This happens for example when ICE session was
729 * created with controlled role when receiving an offer, but it turns out
730 * that the offer contains "a=ice-lite" attribute when the SDP gets
731 * inspected. ICE session must have been initialized before this function
732 * can be called.
733 *
734 * @param ice_st The ICE stream transport.
735 * @param new_role The new role to be set.
736 *
737 * @return PJ_SUCCESS on success, or the appropriate error.
738 */
739PJ_DECL(pj_status_t) pj_ice_strans_change_role(pj_ice_strans *ice_st,
740 pj_ice_sess_role new_role);
741
742
743/**
744 * Start ICE connectivity checks. This function can only be called
745 * after the ICE session has been created in the ICE stream transport
746 * with #pj_ice_strans_init_ice().
747 *
748 * This function must be called once application has received remote
749 * candidate list (typically from the remote SDP). This function pairs
750 * local candidates with remote candidates, and starts ICE connectivity
751 * checks. The ICE session/transport will then notify the application
752 * via the callback when ICE connectivity checks completes, either
753 * successfully or with failure.
754 *
755 * @param ice_st The ICE stream transport.
756 * @param rem_ufrag Remote ufrag, as seen in the SDP received from
757 * the remote agent.
758 * @param rem_passwd Remote password, as seen in the SDP received from
759 * the remote agent.
760 * @param rcand_cnt Number of remote candidates in the array.
761 * @param rcand Remote candidates array.
762 *
763 * @return PJ_SUCCESS, or the appropriate error code.
764 */
765PJ_DECL(pj_status_t) pj_ice_strans_start_ice(pj_ice_strans *ice_st,
766 const pj_str_t *rem_ufrag,
767 const pj_str_t *rem_passwd,
768 unsigned rcand_cnt,
769 const pj_ice_sess_cand rcand[]);
770
771/**
772 * Retrieve the candidate pair that has been nominated and successfully
773 * checked for the specified component. If ICE negotiation is still in
774 * progress or it has failed, this function will return NULL.
775 *
776 * @param ice_st The ICE stream transport.
777 * @param comp_id Component ID.
778 *
779 * @return The valid pair as ICE checklist structure if the
780 * pair exist.
781 */
782PJ_DECL(const pj_ice_sess_check*)
783pj_ice_strans_get_valid_pair(const pj_ice_strans *ice_st,
784 unsigned comp_id);
785
786/**
787 * Stop and destroy the ICE session inside this media transport. Application
788 * needs to call this function once the media session is over (the call has
789 * been disconnected).
790 *
791 * Application MAY reuse this ICE stream transport for subsequent calls.
792 * In this case, it must call #pj_ice_strans_stop_ice() when the call is
793 * disconnected, and reinitialize the ICE stream transport for subsequent
794 * call with #pj_ice_strans_init_ice()/#pj_ice_strans_start_ice(). In this
795 * case, the ICE stream transport will maintain the internal sockets and
796 * continue to send STUN keep-alive packets and TURN Refresh request to
797 * keep the NAT binding/TURN allocation open and to detect change in STUN
798 * mapped address.
799 *
800 * If application does not want to reuse the ICE stream transport for
801 * subsequent calls, it must call #pj_ice_strans_destroy() to destroy the
802 * ICE stream transport altogether.
803 *
804 * @param ice_st The ICE stream transport.
805 *
806 * @return PJ_SUCCESS, or the appropriate error code.
807 */
808PJ_DECL(pj_status_t) pj_ice_strans_stop_ice(pj_ice_strans *ice_st);
809
810
811/**
812 * Send outgoing packet using this transport.
813 * Application can send data (normally RTP or RTCP packets) at any time
814 * by calling this function. This function takes a destination
815 * address as one of the arguments, and this destination address should
816 * be taken from the default transport address of the component (that is
817 * the address in SDP c= and m= lines, or in a=rtcp attribute).
818 * If ICE negotiation is in progress, this function will send the data
819 * to the destination address. Otherwise if ICE negotiation has completed
820 * successfully, this function will send the data to the nominated remote
821 * address, as negotiated by ICE.
822 *
823 * @param ice_st The ICE stream transport.
824 * @param comp_id Component ID.
825 * @param data The data or packet to be sent.
826 * @param data_len Size of data or packet, in bytes.
827 * @param dst_addr The destination address.
828 * @param dst_addr_len Length of destination address.
829 *
830 * @return PJ_SUCCESS if data is sent successfully.
831 */
832PJ_DECL(pj_status_t) pj_ice_strans_sendto(pj_ice_strans *ice_st,
833 unsigned comp_id,
834 const void *data,
835 pj_size_t data_len,
836 const pj_sockaddr_t *dst_addr,
837 int dst_addr_len);
838
839
840/**
841 * @}
842 */
843
844
845PJ_END_DECL
846
847
848
849#endif /* __PJNATH_ICE_STRANS_H__ */
850