~ubuntu-branches/ubuntu/raring/sflphone/raring

« back to all changes in this revision

Viewing changes to sflphone-common/libs/pjproject/pjnath/include/pjnath/ice_strans.h

  • Committer: Package Import Robot
  • Author(s): Francois Marier
  • Date: 2011-11-25 13:24:12 UTC
  • mfrom: (4.1.10 sid)
  • Revision ID: package-import@ubuntu.com-20111125132412-dc4qvhyosk74cd42
Tags: 1.0.1-4
Don't assume that arch:all packages will get built (closes: #649726)

Show diffs side-by-side

added added

removed removed

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