- Timestamp:
- Mar 27, 2007 11:29:27 PM (18 years ago)
- Location:
- pjproject/trunk
- Files:
-
- 4 added
- 2 deleted
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjlib/src/pj/ip_helper_win32.c
r1104 r1110 63 63 /* Now fill out the entries */ 64 64 count = (pTab->dwNumEntries < *p_cnt) ? pTab->dwNumEntries : *p_cnt; 65 *p_cnt = 0; 65 66 for (i=0; i<count; ++i) { 66 ifs[i].s_addr = pTab->table[i].dwAddr; 67 /* Some Windows returns 0.0.0.0! */ 68 if (pTab->table[i].dwAddr == 0) 69 continue; 70 ifs[*p_cnt].s_addr = pTab->table[i].dwAddr; 71 (*p_cnt)++; 67 72 } 68 69 *p_cnt = count;70 73 71 74 return PJ_SUCCESS; -
pjproject/trunk/pjnath/build/pjnath.dsp
r1101 r1110 43 43 # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c 44 44 # ADD CPP /nologo /MD /W4 /GX /O1 /Ob2 /I "../include" /I "../../pjlib/include" /I "../../pjlib-util/include" /D "NDEBUG" /D "WIN32" /D "_MBCS" /D "_LIB" /D PJ_WIN32=1 /D PJ_M_I386=1 /FR /FD /c 45 # SUBTRACT CPP / Z<none> /YX45 # SUBTRACT CPP /YX 46 46 # ADD BASE RSC /l 0x409 /d "NDEBUG" 47 47 # ADD RSC /l 0x409 /d "NDEBUG" … … 152 152 # Begin Source File 153 153 154 SOURCE=..\include\pjnath\stun_doc.h155 # End Source File156 # Begin Source File157 158 154 SOURCE=..\include\pjnath\stun_msg.h 159 155 # End Source File … … 168 164 # Begin Source File 169 165 170 SOURCE=..\include\pjnath\turn_client.h171 # End Source File172 # Begin Source File173 174 166 SOURCE=..\include\pjnath\types.h 175 167 # End Source File -
pjproject/trunk/pjnath/docs
-
Property
svn:ignore
set to
html
latex
-
Property
svn:ignore
set to
-
pjproject/trunk/pjnath/include/pjnath/config.h
r1080 r1110 28 28 /** 29 29 * @defgroup PJNATH_CONFIG Configuration 30 * @ ingroup PJNATH30 * @brief Various compile time settings 31 31 * @{ 32 32 */ … … 35 35 * STUN CLIENT CONFIGURATION 36 36 */ 37 38 /**39 * Maximum number of attributes in the STUN packet (for the old STUN40 * library).41 *42 * Default: 1643 */44 #ifndef PJSTUN_MAX_ATTR45 # define PJSTUN_MAX_ATTR 1646 #endif47 48 37 49 38 /** … … 57 46 #endif 58 47 48 /** 49 * The default initial STUN round-trip time estimation (the RTO value 50 * in RFC 3489-bis), in miliseconds. 51 * This value is used to control the STUN request 52 * retransmit time. The initial value of retransmission interval 53 * would be set to this value, and will be doubled after each 54 * retransmission. 55 */ 56 #ifndef PJ_STUN_RTO_VALUE 57 # define PJ_STUN_RTO_VALUE 100 58 #endif 59 60 61 /** 62 * The STUN transaction timeout value, in miliseconds. 63 * After the last retransmission is sent and if no response is received 64 * after this time, the STUN transaction will be considered to have failed. 65 * 66 * The default value is 1600 miliseconds (as per RFC 3489-bis). 67 */ 68 #ifndef PJ_STUN_TIMEOUT_VALUE 69 # define PJ_STUN_TIMEOUT_VALUE 1600 70 #endif 71 72 73 /** 74 * Maximum number of STUN retransmission count. 75 * 76 * Default: 7 (as per RFC 3489-bis) 77 */ 78 #ifndef PJ_STUN_MAX_RETRANSMIT_COUNT 79 # define PJ_STUN_MAX_RETRANSMIT_COUNT 7 80 #endif 81 82 83 /** 84 * Maximum size of STUN message. 85 */ 86 #ifndef PJ_STUN_MAX_PKT_LEN 87 # define PJ_STUN_MAX_PKT_LEN 512 88 #endif 89 90 91 /** 92 * Default STUN port as defined by RFC 3489. 93 */ 94 #define PJ_STUN_PORT 3478 95 96 97 98 /* ************************************************************************** 99 * ICE CONFIGURATION 100 */ 101 102 /** 103 * Maximum number of ICE candidates. 104 * 105 * Default: 16 106 */ 107 #ifndef PJ_ICE_MAX_CAND 108 # define PJ_ICE_MAX_CAND 16 109 #endif 110 111 112 /** 113 * Maximum number of candidates for each ICE stream transport component. 114 * 115 * Default: 8 116 */ 117 #ifndef PJ_ICE_ST_MAX_CAND 118 # define PJ_ICE_ST_MAX_CAND 8 119 #endif 120 121 122 /** 123 * Maximum number of ICE components. 124 * 125 * Default: 8 126 */ 127 #ifndef PJ_ICE_MAX_COMP 128 # define PJ_ICE_MAX_COMP 8 129 #endif 130 131 132 /** 133 * Maximum number of ICE checks. 134 * 135 * Default: 32 136 */ 137 #ifndef PJ_ICE_MAX_CHECKS 138 # define PJ_ICE_MAX_CHECKS 32 139 #endif 140 141 142 /** 143 * Default timer interval (in miliseconds) for starting ICE periodic checks. 144 * 145 * Default: 20 146 */ 147 #ifndef PJ_ICE_TA_VAL 148 # define PJ_ICE_TA_VAL 20 149 #endif 150 151 59 152 60 153 /** -
pjproject/trunk/pjnath/include/pjnath/errno.h
r1101 r1110 20 20 #define __PJNATH_ERRNO_H__ 21 21 22 /** 23 * @file errno.h 24 * @brief PJNATH specific error codes 25 */ 22 26 23 27 #include <pj/errno.h> … … 25 29 /** 26 30 * @defgroup PJNATH_ERROR NAT Helper Library Error Codes 27 * @ ingroup PJNATH31 * @brief PJNATH specific error code constants 28 32 * @{ 29 33 */ -
pjproject/trunk/pjnath/include/pjnath/ice.h
r1106 r1110 22 22 /** 23 23 * @file ice.h 24 * @brief ICE .24 * @brief ICE session management 25 25 */ 26 26 #include <pjnath/types.h> … … 32 32 * @defgroup PJNATH_ICE Interactive Connectivity Establishment (ICE) 33 33 * @brief Interactive Connectivity Establishment (ICE) 34 * @ingroup PJNATH35 34 */ 36 35 … … 40 39 41 40 /** 42 * @defgroup PJNATH_ICE_S TREAM Transport Independent ICE Media Stream43 * @brief Transport Independent ICE Media Stream41 * @defgroup PJNATH_ICE_SESSION ICE Session 42 * @brief Transport Independent ICE Session 44 43 * @ingroup PJNATH_ICE 45 44 * @{ 45 * 46 * This module describes #pj_ice, a transport independent ICE session, 47 * part of PJNATH - the Open Source NAT helper library. 48 * 49 * An ICE session, represented by #pj_ice structure, is the lowest 50 * abstraction of ICE in PJNATH, and it is used to perform and manage 51 * connectivity checks of transport address candidates <b>within a 52 * single media stream</b> (note: this differs from what is described 53 * in ICE draft, where an ICE session manages the whole media sessions 54 * rather than just a single stream). 55 * 56 * The ICE session described here is independent from any transports, 57 * meaning that the actual network I/O for this session would have to 58 * be performed by the application, or higher layer abstraction. 59 * Using this framework, application would give any incoming packets to 60 * the ICE session, and it would provide the ICE session with a callback 61 * to send outgoing message. 62 * 63 * For higher abstraction of ICE where transport is included, please 64 * see \ref PJNATH_ICE_STREAM_TRANSPORT. 46 65 */ 47 66 … … 51 70 typedef enum pj_ice_cand_type 52 71 { 53 PJ_ICE_CAND_TYPE_HOST, 54 PJ_ICE_CAND_TYPE_SRFLX, 55 PJ_ICE_CAND_TYPE_PRFLX, 56 PJ_ICE_CAND_TYPE_RELAYED 72 PJ_ICE_CAND_TYPE_HOST, /**< ICE host candidate. */ 73 PJ_ICE_CAND_TYPE_SRFLX, /**< ICE server reflexive candidate. */ 74 PJ_ICE_CAND_TYPE_PRFLX, /**< ICE peer reflexive candidate. */ 75 PJ_ICE_CAND_TYPE_RELAYED /**< ICE relayed candidate. */ 57 76 } pj_ice_cand_type; 58 77 59 /** 60 * 78 79 /** 80 * This enumeration describes the default preference for the ICE 81 * candidate types as described by ICE standard. 61 82 */ 62 83 enum pj_ice_type_pref 63 84 { 64 PJ_ICE_HOST_PREF = 126, 65 PJ_ICE_SRFLX_PREF = 100, 66 PJ_ICE_PRFLX_PREF = 110, 67 PJ_ICE_RELAYED_PREF = 0 85 PJ_ICE_HOST_PREF = 126, /**< Preference value for host. */ 86 PJ_ICE_SRFLX_PREF = 100, /**< Preference value for SRFLX. */ 87 PJ_ICE_PRFLX_PREF = 110, /**< Preference value for PRFLX */ 88 PJ_ICE_RELAYED_PREF = 0 /**< Preference value for relay */ 68 89 }; 69 90 91 /** Forward declaration for pj_ice */ 70 92 typedef struct pj_ice pj_ice; 93 94 /** Forward declaration for pj_ice_check */ 71 95 typedef struct pj_ice_check pj_ice_check; 72 96 73 #define PJ_ICE_MAX_CAND 16 74 #define PJ_ICE_MAX_COMP 8 75 #define PJ_ICE_MAX_CHECKS 32 76 #define PJ_ICE_TA_VAL 20 77 78 /** 79 * ICE component97 98 /** 99 * This structure describes ICE component. 100 * A media stream may require multiple components, each of which has 101 * to work for the media stream as a whole to work. For media streams 102 * based on RTP, there are two components per media stream - one for RTP, 103 * and one for RTCP. 80 104 */ 81 105 typedef struct pj_ice_comp 82 106 { 107 /** 108 * The pointer to ICE check which was nominated for this component. 109 * The value will be NULL if a nominated check has not been found 110 * for this component. 111 */ 83 112 pj_ice_check *valid_check; 113 84 114 } pj_ice_comp; 85 115 … … 87 117 /** 88 118 * This structure describes an ICE candidate. 119 * ICE candidate is a transport address that is to be tested by ICE 120 * procedures in order to determine its suitability for usage for 121 * receipt of media. Candidates also have properties - their type 122 * (server reflexive, relayed or host), priority, foundation, and 123 * base. 89 124 */ 90 125 typedef struct pj_ice_cand 91 126 { 127 /** 128 * The component ID of this candidate. Note that component IDs starts 129 * with one for RTP and two for RTCP. In other words, it's not zero 130 * based. 131 */ 92 132 pj_uint32_t comp_id; 133 134 /** 135 * The candidate type, as described in #pj_ice_cand_type enumeration. 136 */ 93 137 pj_ice_cand_type type; 138 139 /** 140 * The foundation string, which is an identifier which value will be 141 * equivalent for two candidates that are of the same type, share the 142 * same base, and come from the same STUN server. The foundation is 143 * used to optimize ICE performance in the Frozen algorithm. 144 */ 94 145 pj_str_t foundation; 146 147 /** 148 * The candidate's priority, a 32-bit unsigned value which value will be 149 * calculated by the ICE session when a candidate is registered to the 150 * ICE session. 151 */ 95 152 pj_uint32_t prio; 153 154 /** 155 * IP address of this candidate. For host candidates, this represents 156 * the local address of the socket. For reflexive candidates, the value 157 * will be the public address allocated in NAT router for the host 158 * candidate and as reported in MAPPED-ADDRESS or XOR-MAPPED-ADDRESS 159 * attribute of STUN Binding request. For relayed candidate, the value 160 * will be the address allocated in the TURN server by STUN Allocate 161 * request. 162 */ 96 163 pj_sockaddr addr; 164 165 /** 166 * Base address of this candidate. "Base" refers to the address an agent 167 * sends from for a particular candidate. For host candidates, the base 168 * is the same as the host candidate itself. For reflexive candidates, 169 * the base is the local IP address of the socket. For relayed candidates, 170 * the base address is the transport address allocated in the TURN server 171 * for this candidate. 172 */ 97 173 pj_sockaddr base_addr; 174 175 /** 176 * Related address, which is used for informational only and is not used 177 * in any way by the ICE session. 178 */ 98 179 pj_sockaddr rel_addr; 180 181 /** 182 * The STUN session to be used to send and receive STUN messages for this 183 * candidate. 184 */ 99 185 pj_stun_session *stun_sess; 186 100 187 } pj_ice_cand; 101 188 189 190 /** 191 * This enumeration describes the state of ICE check. 192 */ 102 193 typedef enum pj_ice_check_state 103 194 { 195 /** 196 * A check for this pair hasn't been performed, and it can't 197 * yet be performed until some other check succeeds, allowing this 198 * pair to unfreeze and move into the Waiting state. 199 */ 104 200 PJ_ICE_CHECK_STATE_FROZEN, 201 202 /** 203 * A check has not been performed for this pair, and can be 204 * performed as soon as it is the highest priority Waiting pair on 205 * the check list. 206 */ 105 207 PJ_ICE_CHECK_STATE_WAITING, 208 209 /** 210 * A check has not been performed for this pair, and can be 211 * performed as soon as it is the highest priority Waiting pair on 212 * the check list. 213 */ 106 214 PJ_ICE_CHECK_STATE_IN_PROGRESS, 215 216 /** 217 * A check has not been performed for this pair, and can be 218 * performed as soon as it is the highest priority Waiting pair on 219 * the check list. 220 */ 107 221 PJ_ICE_CHECK_STATE_SUCCEEDED, 222 223 /** 224 * A check for this pair was already done and failed, either 225 * never producing any response or producing an unrecoverable failure 226 * response. 227 */ 108 228 PJ_ICE_CHECK_STATE_FAILED 229 109 230 } pj_ice_check_state; 110 231 111 232 233 /** 234 * This structure describes an ICE connectivity check. An ICE check 235 * contains a candidate pair, and will involve sending STUN Binding 236 * Request transaction for the purposes of verifying connectivity. 237 * A check is sent from the local candidate to the remote candidate 238 * of a candidate pair. 239 */ 112 240 struct pj_ice_check 113 241 { 242 /** 243 * Pointer to local candidate entry of this check. 244 */ 114 245 pj_ice_cand *lcand; 246 247 /** 248 * Pointer to remote candidate entry of this check. 249 */ 115 250 pj_ice_cand *rcand; 116 251 252 /** 253 * Check priority. 254 */ 117 255 pj_uint64_t prio; 256 257 /** 258 * Connectivity check state. 259 */ 118 260 pj_ice_check_state state; 261 262 /** 263 * STUN transmit data containing STUN Binding request that was sent 264 * as part of this check. The value will only be set when this check 265 * has a pending transaction, and is used to cancel the transaction 266 * when other check has succeeded. 267 */ 119 268 pj_stun_tx_data *tdata; 269 270 /** 271 * Flag to indicate whether this check is nominated. A nominated check 272 * contains USE-CANDIDATE attribute in its STUN Binding request. 273 */ 120 274 pj_bool_t nominated; 275 276 /** 277 * When the check failed, this will contain the failure status of the 278 * STUN transaction. 279 */ 121 280 pj_status_t err_code; 122 281 }; 123 282 124 283 284 /** 285 * This enumeration describes ICE checklist state. 286 */ 125 287 typedef enum pj_ice_checklist_state 126 288 { 289 /** 290 * The checklist is not yet running. 291 */ 127 292 PJ_ICE_CHECKLIST_ST_IDLE, 293 294 /** 295 * In this state, ICE checks are still in progress for this 296 * media stream. 297 */ 128 298 PJ_ICE_CHECKLIST_ST_RUNNING, 299 300 /** 301 * In this state, ICE checks have completed for this media stream, 302 * either successfully or with failure. 303 */ 129 304 PJ_ICE_CHECKLIST_ST_COMPLETED 305 130 306 } pj_ice_checklist_state; 131 307 308 309 /** 310 * This structure represents ICE check list, that is an ordered set of 311 * candidate pairs that an agent will use to generate checks. 312 */ 132 313 typedef struct pj_ice_checklist 133 314 { 315 /** 316 * The checklist state. 317 */ 134 318 pj_ice_checklist_state state; 319 320 /** 321 * Number of candidate pairs (checks). 322 */ 135 323 unsigned count; 324 325 /** 326 * Array of candidate pairs (checks). 327 */ 136 328 pj_ice_check checks[PJ_ICE_MAX_CHECKS]; 329 330 /** 331 * A timer used to perform periodic check for this checklist. 332 */ 137 333 pj_timer_entry timer; 334 138 335 } pj_ice_checklist; 139 336 140 337 141 338 /** 142 * ICE sock callback. 339 * This structure contains callbacks that will be called by the ICE 340 * session. 143 341 */ 144 342 typedef struct pj_ice_cb 145 343 { 344 /** 345 * An optional callback that will be called by the ICE session when 346 * ICE negotiation has completed, successfully or with failure. 347 * 348 * @param ice The ICE session. 349 * @param status Will contain PJ_SUCCESS if ICE negotiation is 350 * successful, or some error code. 351 */ 146 352 void (*on_ice_complete)(pj_ice *ice, pj_status_t status); 353 354 /** 355 * A mandatory callback which will be called by the ICE session when 356 * it needs to send outgoing STUN packet. 357 * 358 * @param ice The ICE session. 359 * @param comp_id ICE component ID. 360 * @param cand_id ICE candidate ID. 361 * @param pkt The STUN packet. 362 * @param size The size of the packet. 363 * @param dst_addr Packet destination address. 364 * @param dst_addr_len Length of destination address. 365 */ 147 366 pj_status_t (*on_tx_pkt)(pj_ice *ice, unsigned comp_id, 148 367 unsigned cand_id, … … 150 369 const pj_sockaddr_t *dst_addr, 151 370 unsigned dst_addr_len); 371 372 /** 373 * A mandatory callback which will be called by the ICE session when 374 * it receives packet which is not part of ICE negotiation. 375 * 376 * @param ice The ICE session. 377 * @param comp_id ICE component ID. 378 * @param pkt The whole packet. 379 * @param size Size of the packet. 380 * @param src_addr Source address where this packet was received 381 * from. 382 * @param src_addr_len The length of source address. 383 */ 152 384 void (*on_rx_data)(pj_ice *ice, unsigned comp_id, 153 385 void *pkt, pj_size_t size, … … 157 389 158 390 391 /** 392 * This enumeration describes ICE role. 393 */ 159 394 typedef enum pj_ice_role 160 395 { 396 /** 397 * The ICE agent is in controlled role. 398 */ 161 399 PJ_ICE_ROLE_CONTROLLED, 400 401 /** 402 * The ICE agent is in controlling role. 403 */ 162 404 PJ_ICE_ROLE_CONTROLLING 405 163 406 } pj_ice_role; 164 407 165 /** 166 * ICE structure. 408 409 /** 410 * This structure describes the ICE session. For this version of PJNATH, 411 * an ICE session corresponds to a single media stream (unlike the ICE 412 * session described in the ICE standard where an ICE session covers the 413 * whole media and may consist of multiple media streams). The decision 414 * to support only a single media session was chosen for simplicity, 415 * while still allowing application to utilize multiple media streams by 416 * creating multiple ICE sessions, one for each media stream. 167 417 */ 168 418 struct pj_ice 169 419 { 170 char obj_name[PJ_MAX_OBJ_NAME]; 171 172 pj_pool_t *pool; 173 void *user_data; 174 pj_mutex_t *mutex; 175 pj_ice_role role; 176 pj_bool_t is_complete; 177 pj_status_t ice_status; 178 pj_ice_cb cb; 179 180 pj_stun_config stun_cfg; 420 char obj_name[PJ_MAX_OBJ_NAME]; /**< Object name. */ 421 422 pj_pool_t *pool; /**< Pool instance. */ 423 void *user_data; /**< App. data. */ 424 pj_mutex_t *mutex; /**< Mutex. */ 425 pj_ice_role role; /**< ICE role. */ 426 pj_bool_t is_complete; /**< Complete? */ 427 pj_status_t ice_status; /**< Error status. */ 428 pj_ice_cb cb; /**< Callback. */ 429 430 pj_stun_config stun_cfg; /**< STUN settings. */ 181 431 182 432 /* STUN credentials */ 183 pj_str_t tx_ufrag; 184 pj_str_t tx_uname; 185 pj_str_t tx_pass; 186 pj_str_t rx_ufrag; 187 pj_str_t rx_uname; 188 pj_str_t rx_pass; 433 pj_str_t tx_ufrag; /**< Remote ufrag. */ 434 pj_str_t tx_uname; /**< Uname for TX. */ 435 pj_str_t tx_pass; /**< Remote password. */ 436 pj_str_t rx_ufrag; /**< Local ufrag. */ 437 pj_str_t rx_uname; /**< Uname for RX */ 438 pj_str_t rx_pass; /**< Local password. */ 189 439 190 440 /* Components */ 191 unsigned comp_cnt; 192 pj_ice_comp comp[PJ_ICE_MAX_COMP]; 441 unsigned comp_cnt; /**< # of components. */ 442 pj_ice_comp comp[PJ_ICE_MAX_COMP]; /**< Component array */ 193 443 194 444 /* Local candidates */ 195 unsigned lcand_cnt; 196 pj_ice_cand lcand[PJ_ICE_MAX_CAND]; 445 unsigned lcand_cnt; /**< # of local cand. */ 446 pj_ice_cand lcand[PJ_ICE_MAX_CAND]; /**< Array of cand. */ 197 447 198 448 /* Remote candidates */ 199 unsigned rcand_cnt; 200 pj_ice_cand rcand[PJ_ICE_MAX_CAND]; 449 unsigned rcand_cnt; /**< # of remote cand. */ 450 pj_ice_cand rcand[PJ_ICE_MAX_CAND]; /**< Array of cand. */ 201 451 202 452 /* Checklist */ 203 pj_ice_checklist clist; 453 pj_ice_checklist clist; /**< Active checklist */ 204 454 205 455 /* Valid list */ 206 pj_ice_checklist valid_list; 456 pj_ice_checklist valid_list; /**< Valid list. */ 207 457 }; 208 458 459 460 /** 461 * This is a utility function to retrieve the string name for the 462 * particular candidate type. 463 * 464 * @param type Candidate type. 465 * 466 * @return The string representation of the candidate type. 467 */ 209 468 PJ_DECL(const char*) pj_ice_get_cand_type_name(pj_ice_cand_type type); 210 469 211 470 471 /** 472 * Create ICE session with the specified role and number of components. 473 * Application would typically need to create an ICE session before 474 * sending an offer or upon receiving one. After the session is created, 475 * application can register candidates to the ICE session by calling 476 * #pj_ice_add_cand() function. 477 * 478 * @param stun_cfg The STUN configuration settings, containing among 479 * other things the timer heap instance to be used 480 * by the ICE session. 481 * @param name Optional name to identify this ICE instance in 482 * the log file. 483 * @param role ICE role. 484 * @param comp_cnt Number of components. 485 * @param cb ICE callback. 486 * @param local_ufrag Optional string to be used as local username to 487 * authenticate incoming STUN binding request. If 488 * the value is NULL, a random string will be 489 * generated. 490 * @param local_passwd Optional string to be used as local password. 491 * @param p_ice Pointer to receive the ICE session instance. 492 * 493 * @return PJ_SUCCESS if ICE session is created successfully. 494 */ 212 495 PJ_DECL(pj_status_t) pj_ice_create(pj_stun_config *stun_cfg, 213 496 const char *name, … … 218 501 const pj_str_t *local_passwd, 219 502 pj_ice **p_ice); 503 504 /** 505 * Destroy ICE session. 506 * 507 * @param ice ICE session instance. 508 * 509 * @return PJ_SUCCESS on success. 510 */ 220 511 PJ_DECL(pj_status_t) pj_ice_destroy(pj_ice *ice); 512 513 514 /** 515 * Add a candidate to this ICE session. 516 * 517 * @param ice ICE session instance. 518 * @param comp_id Component ID of this candidate. 519 * @param type Candidate type. 520 * @param local_pref Local preference for this candidate, which 521 * normally should be set to 65535. 522 * @param foundation Foundation identification. 523 * @param addr The candidate address. 524 * @param base_addr The candidate's base address. 525 * @param rel_addr Optional related address. 526 * @param addr_len Length of addresses. 527 * @param p_cand_id Optional pointer to receive the candidate ID. 528 * 529 * @return PJ_SUCCESS if candidate is successfully added. 530 */ 221 531 PJ_DECL(pj_status_t) pj_ice_add_cand(pj_ice *ice, 222 532 unsigned comp_id, … … 228 538 const pj_sockaddr_t *rel_addr, 229 539 int addr_len, 230 unsigned *cand_id); 231 540 unsigned *p_cand_id); 541 542 /** 543 * Find default candidate for the specified component ID, using this 544 * rule: 545 * - if the component has a successful candidate pair, then the 546 * local candidate of this pair will be returned. 547 * - otherwise a relay, reflexive, or host candidate will be selected 548 * on that specified order. 549 * 550 * @param ice The ICE session instance. 551 * @param comp_id The component ID. 552 * @param p_cand_id Pointer to receive the candidate ID. 553 * 554 * @return PJ_SUCCESS if a candidate has been selected. 555 */ 232 556 PJ_DECL(pj_status_t) pj_ice_find_default_cand(pj_ice *ice, 233 557 unsigned comp_id, 234 int *cand_id); 235 558 int *p_cand_id); 559 560 /** 561 * Pair the local and remote candidates to create check list. Application 562 * typically would call this function after receiving SDP containing ICE 563 * candidates from the remote host (either upon receiving the initial 564 * offer, for UAS, or upon receiving the answer, for UAC). 565 * 566 * Note that ICE connectivity check will not start until application calls 567 * #pj_ice_start_check(). 568 * 569 * @param ice ICE session instance. 570 * @param rem_ufrag Remote ufrag, as seen in the SDP received from 571 * the remote agent. 572 * @param rem_passwd Remote password, as seen in the SDP received from 573 * the remote agent. 574 * @param rem_cand_cnt Number of remote candidates. 575 * @param rem_cand Remote candidate array. Remote candidates are 576 * gathered from the SDP received from the remote 577 * agent. 578 * 579 * @return PJ_SUCCESS or the appropriate error code. 580 */ 236 581 PJ_DECL(pj_status_t) pj_ice_create_check_list(pj_ice *ice, 237 582 const pj_str_t *rem_ufrag, … … 239 584 unsigned rem_cand_cnt, 240 585 const pj_ice_cand rem_cand[]); 586 587 /** 588 * Start ICE periodic check. This function will return immediately, and 589 * application will be notified about the connectivity check status in 590 * #pj_ice_cb callback. 591 * 592 * @param ice The ICE session instance. 593 * 594 * @return PJ_SUCCESS or the appropriate error code. 595 */ 241 596 PJ_DECL(pj_status_t) pj_ice_start_check(pj_ice *ice); 242 597 598 599 /** 600 * Send data using this ICE session. If ICE checks have not produced a 601 * valid check for the specified component ID, this function will return 602 * with failure. Otherwise ICE session will send the packet to remote 603 * destination using the nominated local candidate for the specified 604 * component. 605 * 606 * @param ice The ICE session. 607 * @param comp_id Component ID. 608 * @param data The data or packet to be sent. 609 * @param data_len Size of data or packet, in bytes. 610 * 611 * @return PJ_SUCCESS if data is sent successfully. 612 */ 243 613 PJ_DECL(pj_status_t) pj_ice_send_data(pj_ice *ice, 244 614 unsigned comp_id, 245 615 const void *data, 246 616 pj_size_t data_len); 617 618 /** 619 * Report the arrival of packet to the ICE session. Since ICE session 620 * itself doesn't have any transports, it relies on application or 621 * higher layer component to give incoming packets to the ICE session. 622 * If the packet is not a STUN packet, this packet will be given back 623 * to application via \a on_rx_data() callback in #pj_ice_cb. 624 * 625 * @param ice The ICE session. 626 * @param comp_id Component ID. 627 * @param cand_id Candidate ID. 628 * @param pkt Incoming packet. 629 * @param pkt_size Size of incoming packet. 630 * @param src_addr Source address of the packet. 631 * @param src_addr_len Length of the address. 632 * 633 * @return PJ_SUCCESS or the appropriate error code. 634 */ 247 635 PJ_DECL(pj_status_t) pj_ice_on_rx_pkt(pj_ice *ice, 248 636 unsigned comp_id, -
pjproject/trunk/pjnath/include/pjnath/ice_stream_transport.h
r1106 r1110 22 22 23 23 /** 24 * @file ice_ mt.h25 * @brief ICE Media Transport.24 * @file ice_stream_transport.h 25 * @brief ICE Stream Transport 26 26 */ 27 27 #include <pjnath/ice.h> … … 38 38 * @ingroup PJNATH_ICE 39 39 * @{ 40 */ 41 40 * 41 * This module describes ICE stream transport, as represented by #pj_ice_st 42 * structure, and is part of PJNATH - the Open Source NAT traversal helper 43 * library. 44 * 45 * ICE stream transport, as represented by #pj_ice_st structure, is an ICE 46 * capable component for transporting media within a media stream. 47 * It consists of one or more transport sockets (typically two for RTP 48 * based communication - one for RTP and one for RTCP), and an 49 * \ref PJNATH_ICE_SESSION for performing connectivity checks among the. 50 * various candidates of the transport addresses. 51 * 52 * \section PJNATH_ICE_STREAM_TRANSPORT_USING Using the ICE Stream Transport 53 * 54 * Application may use the ICE stream transport in two ways: 55 * - it can create the ICE stream transports once during application 56 * initialization and keep them alive throughout application lifetime, or 57 * - it can create and destroy the ICE stream transport as needed everytime 58 * a call is made and destroyed. 59 * 60 * Keeping the ICE stream transport alive throughout 61 * application's lifetime is normally preferable, as initializing the 62 * ICE stream transport may incur delay because the ICE stream transport 63 * would need to communicate with the STUN/TURN server to get the 64 * server reflexive and relayed candidates for the transports. 65 * 66 * Regardless of which usage scenario is being used, the ICE stream 67 * transport is capable for restarting the ICE session being used and to 68 * send STUN keep-alives for its STUN server reflexive and relayed 69 * candidates. 70 * 71 * \subsection PJNATH_ICE_ST_TRA_INIT Stream Transport Initialization 72 * 73 * Application creates the ICE stream transport by calling 74 * #pj_ice_st_create() function. 75 * 76 * After the ICE stream transport is created, application may set up the 77 * STUN servers to be used to obtain STUN server reflexive and relayed 78 * candidate, by calling #pj_ice_st_set_stun_domain() or 79 * #pj_ice_st_set_stun_srv(). Then it has to create each component by 80 * calling #pj_ice_st_create_comp(); this would create an actual socket 81 * which listens to the specified local address, and it would also 82 * perform lookup to find various transport address candidates for this 83 * socket. 84 * 85 * \subsection PJNATH_ICE_ST_TRA_INIT_ICE ICE Session Initialization 86 * 87 * When application is about to send an offer containing ICE capability, 88 * or when it receives an offer containing ICE capability, it would 89 * create the ICE session by calling #pj_ice_st_init_ice(). This would 90 * register all transport address aliases for each component to the ICE 91 * session as candidates. After this application can enumerate all local 92 * candidates by calling #pj_ice_st_enum_cands(), and encode these 93 * candidates in the SDP to be sent to remote agent. 94 * 95 * \subsection PJNATH_ICE_ST_TRA_START Starting Connectivity Checks 96 * 97 * Once application receives the SDP from remote, it can start ICE 98 * connectivity checks by calling #pj_ice_st_start_ice(), specifying 99 * the username, password, and candidates of the remote agent. The ICE 100 * session/transport will then notify the application via the callback 101 * when ICE connectivity checks completes, either successfully or with 102 * failure. 103 * 104 * \subsection PJNATH_ICE_ST_TRA_STOP Stopping ICE Session 105 * 106 * Once the call is terminated, application no longer needs to keep the 107 * ICE session, so it should call #pj_ice_st_stop_ice() to destroy the 108 * ICE session within this ICE stream transport. Note that this WILL NOT 109 * destroy the sockets/transports, it only destroys the ICE session 110 * within this ICE stream transport. 111 * 112 * \subsection PJNATH_ICE_ST_TRA_RESTART Restarting ICE Session 113 * 114 * When a new call is made, application can repeat the above 115 * #pj_ice_st_init_ice() to #pj_ice_st_stop_ice() cycle for the new call, 116 * using this same ICE stream transport. 117 * 118 * \subsection PJNATH_ICE_ST_TRA_DESTROY Destroying ICE Stream Transport 119 * 120 * Finally, when the ICE stream transport itself is no longer needed, 121 * for example when the application quits, application should call 122 * #pj_ice_st_destroy() to release back all resources allocated by this 123 * ICE stream transport. 124 * 125 */ 126 127 /** Forward declaration for ICE stream transport. */ 42 128 typedef struct pj_ice_st pj_ice_st; 43 129 130 /** 131 * This structure contains callbacks that will be called by the 132 * ICE stream transport. 133 */ 44 134 typedef struct pj_ice_st_cb 45 135 { 136 /** 137 * This callback will be called when the ICE transport receives 138 * incoming packet from the sockets which is not related to ICE 139 * (for example, normal RTP/RTCP packet destined for application). 140 * 141 * @param ice_st The ICE stream transport. 142 * @param comp_id The component ID. 143 * @param pkt The packet. 144 * @param size Size of the packet. 145 * @param src_addr Source address of the packet. 146 * @param src_addr_len Length of the source address. 147 */ 46 148 void (*on_rx_data)(pj_ice_st *ice_st, 47 149 unsigned comp_id, … … 49 151 const pj_sockaddr_t *src_addr, 50 152 unsigned src_addr_len); 153 154 /** 155 * This callback will be called when ICE checks have completed. 156 * This callback is optional. 157 * 158 * @param ice_st The ICE stream transport. 159 * @param status The ICE connectivity check status. 160 */ 51 161 void (*on_ice_complete)(pj_ice_st *ice_st, 52 162 pj_status_t status); … … 55 165 56 166 57 #ifndef PJ_ICE_ST_MAX_ALIASES 58 # define PJ_ICE_ST_MAX_ALIASES 8 59 #endif 60 167 /** 168 * Various flags that can be specified when creating a component with 169 * #pj_ice_st_create_comp(). These options may be combined together 170 * with bitmask operation. 171 */ 61 172 enum pj_ice_st_option 62 173 { 174 /** 175 * If this option is specified, only a listening socket will be 176 * created for the component, and no candidate will be added to 177 * the component. Application must add the component manually 178 * by inspecting the socket and transport address of the component. 179 */ 63 180 PJ_ICE_ST_OPT_DONT_ADD_CAND = 1, 181 182 /** 183 * If this option is specified, then no STUN reflexive candidate 184 * will be added to the component. 185 */ 64 186 PJ_ICE_ST_OPT_DISABLE_STUN = 2, 187 188 /** 189 * If this option is specified, then no STUN relay candidate 190 * will be added to the component. 191 */ 65 192 PJ_ICE_ST_OPT_DISABLE_RELAY = 4, 193 194 /** 195 * If this option is specified, then when the function fails to 196 * bind the socket to the specified port, it WILL NOT try to 197 * bind the socket to the next available port. 198 * 199 * If this option is NOT specified, then the function will try to 200 * bind the socket to next port+2, repetitively until the socket 201 * is bound successfully. 202 */ 66 203 PJ_ICE_ST_OPT_NO_PORT_RETRY = 8, 67 204 }; 68 205 69 206 207 /** 208 * This structure describes ICE stream transport candidate. A "candidate" 209 * in ICE stream transport can be viewed as alias transport address 210 * for the socket. 211 */ 70 212 typedef struct pj_ice_st_cand 71 213 { 214 /** 215 * Candidate type. 216 */ 72 217 pj_ice_cand_type type; 218 219 /** 220 * Status of this candidate. This status is useful for ICE reflexive 221 * and relay candidate, where the address needs to be resolved 222 * asynchronously by sending STUN request to STUN server. 223 * 224 * The value will be PJ_SUCCESS if candidate address has been resolved 225 * successfully, PJ_EPENDING when the address resolution process is 226 * in progress, or other value when the address resolution has 227 * completed with failure. 228 */ 73 229 pj_status_t status; 230 231 /** 232 * The candidate transport address. 233 */ 74 234 pj_sockaddr addr; 75 int cand_id; 235 236 /** 237 * The ICE session candidate ID after this candidate has been registered 238 * to an ICE session. Before ICE session is created, or after ICE 239 * session has been destroyed, the value will be -1. 240 */ 241 int ice_cand_id; 242 243 /** 244 * Local preference value, which typically is 65535. 245 */ 76 246 pj_uint16_t local_pref; 247 248 /** 249 * Foundation associated with this candidate, which value normally will be 250 * calculated by the function. 251 */ 77 252 pj_str_t foundation; 253 78 254 } pj_ice_st_cand; 79 255 80 256 257 /** 258 * This structure describes an ICE stream transport component. A component 259 * in ICE stream transport typically corresponds to a single socket created 260 * for this component, and bound to a specific transport address. This 261 * component may have multiple alias addresses, for example one alias 262 * address for each interfaces in multi-homed host, another for server 263 * reflexive alias, and another for relayed alias. For each transport 264 * address alias, an ICE stream transport candidate (#pj_ice_st_cand) will 265 * be created, and these candidates will eventually registered to the ICE 266 * session. 267 */ 81 268 typedef struct pj_ice_st_comp 82 269 { 83 pj_ice_st *ice_st; 84 unsigned comp_id; 85 pj_uint32_t options; 86 pj_sock_t sock; 87 88 pj_stun_session *stun_sess; 89 90 pj_sockaddr local_addr; 91 92 unsigned pending_cnt; 93 pj_status_t last_status; 94 95 unsigned cand_cnt; 96 pj_ice_st_cand cand_list[PJ_ICE_ST_MAX_ ALIASES];97 int default_cand; 98 99 pj_ioqueue_key_t *key; 100 pj_uint8_t pkt[1500]; 101 pj_ioqueue_op_key_t read_op; 102 pj_ioqueue_op_key_t write_op; 103 pj_sockaddr src_addr; 104 int src_addr_len; 270 pj_ice_st *ice_st; /**< ICE stream transport. */ 271 unsigned comp_id; /**< Component ID. */ 272 pj_uint32_t options; /**< Option flags. */ 273 pj_sock_t sock; /**< Socket descriptor. */ 274 275 pj_stun_session *stun_sess; /**< STUN session. */ 276 277 pj_sockaddr local_addr; /**< Local/base address. */ 278 279 unsigned pending_cnt; /**< Pending resolution cnt. */ 280 pj_status_t last_status; /**< Last status. */ 281 282 unsigned cand_cnt; /**< # of candidates/aliaes. */ 283 pj_ice_st_cand cand_list[PJ_ICE_ST_MAX_CAND]; /**< Cand array */ 284 int default_cand; /**< Default candidate selected */ 285 286 pj_ioqueue_key_t *key; /**< ioqueue key. */ 287 pj_uint8_t pkt[1500]; /**< Incoming packet buffer. */ 288 pj_ioqueue_op_key_t read_op; /**< ioqueue read operation key */ 289 pj_ioqueue_op_key_t write_op; /**< ioqueue write op. key */ 290 pj_sockaddr src_addr; /**< source packet address buf. */ 291 int src_addr_len; /**< length of src addr. buf. */ 105 292 106 293 } pj_ice_st_comp; 107 294 108 295 296 /** 297 * This structure represents the ICE stream transport. 298 */ 109 299 struct pj_ice_st 110 300 { 111 char obj_name[PJ_MAX_OBJ_NAME]; 112 pj_pool_t *pool; 113 void *user_data; 114 pj_stun_config stun_cfg; 115 pj_ice_st_cb cb; 116 117 pj_ice *ice; 118 119 unsigned comp_cnt; 120 pj_ice_st_comp **comp; 121 122 pj_dns_resolver *resolver; 123 pj_bool_t has_resolver_job; 124 pj_sockaddr_in stun_srv; 125 pj_sockaddr_in turn_srv; 301 char obj_name[PJ_MAX_OBJ_NAME]; /**< Log ID. */ 302 303 pj_pool_t *pool; /**< Pool used by this object. */ 304 void *user_data; /**< Application data. */ 305 pj_stun_config stun_cfg; /**< STUN settings. */ 306 pj_ice_st_cb cb; /**< Application callback. */ 307 308 pj_ice *ice; /**< ICE session. */ 309 310 unsigned comp_cnt; /**< Number of components. */ 311 pj_ice_st_comp **comp; /**< Components array. */ 312 313 pj_dns_resolver *resolver; /**< The resolver instance. */ 314 pj_bool_t has_rjob; /**< Has pending resolve? */ 315 pj_sockaddr_in stun_srv; /**< STUN server address. */ 316 pj_sockaddr_in turn_srv; /**< TURN server address. */ 126 317 }; 127 318 128 319 320 /** 321 * Create the ICE stream transport containing the specified number of 322 * components. After the ICE stream transport is created, application 323 * may initialize the STUN server settings, and after that it has to 324 * initialize each components by calling #pj_ice_st_create_comp() 325 * function. 326 * 327 * @param stun_cfg The STUN settings. 328 * @param name Optional name for logging identification. 329 * @param comp_cnt Number of components. 330 * @param user_data Arbitrary user data to be associated with this 331 * ICE stream transport. 332 * @param cb Callback. 333 * @param p_ice_st Pointer to receive the ICE stream transport 334 * instance. 335 * 336 * @return PJ_SUCCESS if ICE stream transport is created 337 * successfully. 338 */ 129 339 PJ_DECL(pj_status_t) pj_ice_st_create(pj_stun_config *stun_cfg, 130 340 const char *name, … … 133 343 const pj_ice_st_cb *cb, 134 344 pj_ice_st **p_ice_st); 345 346 /** 347 * Destroy the ICE stream transport. This will destroy the ICE session 348 * inside the ICE stream transport, close all sockets and release all 349 * other resources. 350 * 351 * @param ice_st The ICE stream transport. 352 * 353 * @return PJ_SUCCESS, or the appropriate error code. 354 */ 135 355 PJ_DECL(pj_status_t) pj_ice_st_destroy(pj_ice_st *ice_st); 136 356 357 358 /** 359 * Set the domain to be used when resolving the STUN servers. If application 360 * wants to utillize STUN, then STUN server must be specified, either by 361 * calling this function or by calling #pj_ice_st_set_stun_srv(). 362 * 363 * If application calls this function, then the STUN/TURN servers will 364 * be resolved by querying DNS SRV records for the specified domain. 365 * 366 * @param ice_st The ICE stream transport. 367 * @param resolver The resolver instance that will be used to 368 * resolve the STUN/TURN servers. 369 * @param domain The target domain. 370 * 371 * @return PJ_SUCCESS if DNS SRV resolution job can be 372 * started. The resolution process itself will 373 * complete asynchronously. 374 */ 137 375 PJ_DECL(pj_status_t) pj_ice_st_set_stun_domain(pj_ice_st *ice_st, 138 376 pj_dns_resolver *resolver, 139 377 const pj_str_t *domain); 378 379 /** 380 * Set the STUN and TURN server addresses. If application 381 * wants to utillize STUN, then STUN server must be specified, either by 382 * calling this function or by calling #pj_ice_st_set_stun_domain(). 383 * 384 * With this function, the STUN and TURN server addresses will be 385 * assigned immediately, that is no DNS resolution will need to be 386 * performed. 387 * 388 * @param ice_st The ICE stream transport. 389 * @param stun_srv The STUN server address, or NULL if STUN 390 * reflexive candidate is not to be used. 391 * @param turn_srv The TURN server address, or NULL if STUN 392 * relay candidate is not to be used. 393 * 394 * @return PJ_SUCCESS, or the appropriate error code. 395 */ 140 396 PJ_DECL(pj_status_t) pj_ice_st_set_stun_srv(pj_ice_st *ice_st, 141 397 const pj_sockaddr_in *stun_srv, 142 398 const pj_sockaddr_in *turn_srv); 143 399 400 /** 401 * Create and initialize the specified component. This function will 402 * instantiate the socket descriptor for this component, optionally 403 * bind the socket to the specified address (or bind to any address/port 404 * if the \a addr parameter is NULL), and start finding all alias 405 * addresses for this socket. For each alias addresses that if finds, 406 * it will add an ICE stream transport candidate for this component. 407 * 408 * After all components have been initialized, application should poll 409 * the #pj_ice_st_get_comps_status() peridically to check if STUN 410 * server reflexive and relayed candidates have been obtained 411 * successfully. 412 * 413 * @param ice_st The ICE stream transport. 414 * @param comp_id The component ID, which value must be greater than 415 * zero and less than or equal to the number of 416 * components in this ICE stream transport. 417 * @param options Options, see #pj_ice_st_option. 418 * @param addr Local address where socket will be bound to. This 419 * address will be used as follows: 420 * - if the value is NULL, then socket will be bound 421 * to any available port. 422 * - if the value is not NULL, then if the port number 423 * is not zero, it will used as the starting port 424 * where the socket will be bound to. If bind() to 425 * this port fails, this function will try to bind 426 * to port+2, repeatedly until it succeeded. 427 * If application doesn't want this function to 428 * retry binding the socket to other port, it can 429 * specify PJ_ICE_ST_OPT_NO_PORT_RETRY option. 430 * - if the value is not NULL, then if the address 431 * is not INADDR_ANY, this function will bind the 432 * socket to this particular interface only, and 433 * no other host candidates will be added for this 434 * socket. 435 * 436 * 437 * @return PJ_SUCCESS, or the appropriate error code. 438 */ 144 439 PJ_DECL(pj_status_t) pj_ice_st_create_comp(pj_ice_st *ice_st, 145 440 unsigned comp_id, 146 441 pj_uint32_t options, 147 442 const pj_sockaddr_in *addr); 443 444 /** 445 * Manually add a candidate (transport address alias) for the specified 446 * component. Normally application shouldn't need to use this function, 447 * as candidates will be added automatically when component is created 448 * with #pj_ice_st_create_comp(). 449 * 450 * @param ice_st ICE stream transport. 451 * @param comp_id The component ID. 452 * @param type The candidate type. 453 * @param local_pref The local preference for this candidate 454 * (typically the value is 65535). 455 * @param addr The candidate address. 456 * @param set_default Set to non-zero to make this candidate the 457 * default candidate for this component. 458 * 459 * @return PJ_SUCCESS, or the appropriate error code. 460 */ 148 461 PJ_DECL(pj_status_t) pj_ice_st_add_cand(pj_ice_st *ice_st, 149 462 unsigned comp_id, … … 153 466 pj_bool_t set_default); 154 467 468 /** 469 * Get the status of components in the ICE stream transports. Since 470 * some IP address candidates have to be obtained asynchronously (for 471 * example, the STUN reflexive or relay candidate), application can 472 * use this function to know whether the address resolution has 473 * completed. 474 * 475 * @param ice_st The ICE stream transport. 476 * 477 * @return PJ_SUCCESS if all candidates have been resolved 478 * successfully, PJ_EPENDING if transport resolution 479 * is still in progress, or other status on failure. 480 */ 155 481 PJ_DECL(pj_status_t) pj_ice_st_get_comps_status(pj_ice_st *ice_st); 156 482 483 /** 484 * Initialize the ICE session in the ICE stream transport. 485 * 486 * @param ice_st The ICE stream transport. 487 * @param role ICE role. 488 * @param local_ufrag Optional local username fragment. 489 * @param local_passwd Optional local password. 490 * 491 * @return PJ_SUCCESS, or the appropriate error code. 492 */ 157 493 PJ_DECL(pj_status_t) pj_ice_st_init_ice(pj_ice_st *ice_st, 158 494 pj_ice_role role, 159 495 const pj_str_t *local_ufrag, 160 496 const pj_str_t *local_passwd); 497 498 /** 499 * Enumerate the local candidates. This function can only be called 500 * after the ICE session has been created in the ICE stream transport. 501 * 502 * @param ice_st The ICE stream transport. 503 * @param count On input, it specifies the maximum number of 504 * elements. On output, it will be filled with 505 * the number of candidates copied to the 506 * array. 507 * @param cand Array of candidates. 508 * 509 * @return PJ_SUCCESS, or the appropriate error code. 510 */ 161 511 PJ_DECL(pj_status_t) pj_ice_st_enum_cands(pj_ice_st *ice_st, 162 512 unsigned *count, 163 513 pj_ice_cand cand[]); 514 515 /** 516 * Start ICE connectivity checks. This function can only be called 517 * after the ICE session has been created in the ICE stream transport. 518 * 519 * This function will pair the local and remote candidates to create 520 * check list. Once the check list is created and sorted based on the 521 * priority, ICE periodic checks will be started. This function will 522 * return immediately, and application will be notified about the 523 * connectivity check status in the callback. 524 * 525 * @param ice_st The ICE stream transport. 526 * @param rem_ufrag Remote ufrag, as seen in the SDP received from 527 * the remote agent. 528 * @param rem_passwd Remote password, as seen in the SDP received from 529 * the remote agent. 530 * @param rem_cand_cnt Number of remote candidates. 531 * @param rem_cand Remote candidate array. 532 * 533 * @return PJ_SUCCESS, or the appropriate error code. 534 */ 164 535 PJ_DECL(pj_status_t) pj_ice_st_start_ice(pj_ice_st *ice_st, 165 536 const pj_str_t *rem_ufrag, … … 167 538 unsigned rem_cand_cnt, 168 539 const pj_ice_cand rem_cand[]); 540 541 /** 542 * Stop and destroy the ICE session inside this media transport. 543 * 544 * @param ice_st The ICE stream transport. 545 * 546 * @return PJ_SUCCESS, or the appropriate error code. 547 */ 169 548 PJ_DECL(pj_status_t) pj_ice_st_stop_ice(pj_ice_st *ice_st); 170 549 550 551 /** 552 * Send outgoing packet using this transport. If ICE checks have not 553 * produced a valid check for the specified component ID, this function 554 * will return with failure. Otherwise it will send the packet to remote 555 * destination using the nominated local candidate as have been checked 556 * previously. 557 * 558 * @param ice_st The ICE stream transport. 559 * @param comp_id Component ID. 560 * @param data The data or packet to be sent. 561 * @param data_len Size of data or packet, in bytes. 562 * @param dst_addr The destination address. 563 * @param dst_addr_len Length of destination address. 564 * 565 * @return PJ_SUCCESS if data is sent successfully. 566 */ 171 567 PJ_DECL(pj_status_t) pj_ice_st_sendto(pj_ice_st *ice_st, 172 568 unsigned comp_id, -
pjproject/trunk/pjnath/include/pjnath/stun_auth.h
r1089 r1110 34 34 /** 35 35 * @defgroup PJNATH_STUN_AUTH STUN Authentication 36 * @brief STUN authentication helper 36 37 * @ingroup PJNATH_STUN 37 38 * @{ … … 299 300 300 301 301 /* Calculate HMAC-SHA1 key for long term credential, by getting 302 /** 303 * Calculate HMAC-SHA1 key for long term credential, by getting 302 304 * MD5 digest of username, realm, and password. 305 * 306 * @param digest The buffer for the digest. 307 * @param realm The realm of the credential, if long term credential 308 * is to be used. 309 * @param username The username. 310 * @param passwd The clear text password. 303 311 */ 304 312 void pj_stun_calc_md5_key(pj_uint8_t digest[16], -
pjproject/trunk/pjnath/include/pjnath/stun_msg.h
r1101 r1110 40 40 */ 41 41 42 43 /**44 * The default initial STUN round-trip time estimation (the RTO value45 * in RFC 3489-bis), in miliseconds.46 * This value is used to control the STUN request47 * retransmit time. The initial value of retransmission interval48 * would be set to this value, and will be doubled after each49 * retransmission.50 */51 #ifndef PJ_STUN_RTO_VALUE52 # define PJ_STUN_RTO_VALUE 10053 #endif54 55 56 /**57 * The STUN transaction timeout value, in miliseconds.58 * After the last retransmission is sent and if no response is received59 * after this time, the STUN transaction will be considered to have failed.60 *61 * The default value is 1600 miliseconds (as per RFC 3489-bis).62 */63 #ifndef PJ_STUN_TIMEOUT_VALUE64 # define PJ_STUN_TIMEOUT_VALUE 160065 #endif66 67 68 /**69 * Maximum number of STUN retransmission count.70 *71 * Default: 7 (as per RFC 3489-bis)72 */73 #ifndef PJ_STUN_MAX_RETRANSMIT_COUNT74 # define PJ_STUN_MAX_RETRANSMIT_COUNT 775 #endif76 77 78 /**79 * Maximum size of STUN message.80 */81 #ifndef PJ_STUN_MAX_PKT_LEN82 # define PJ_STUN_MAX_PKT_LEN 51283 #endif84 85 86 /**87 * Default STUN port as defined by RFC 3489.88 */89 #define PJ_STUN_PORT 347890 42 91 43 /** -
pjproject/trunk/pjnath/include/pjnath/stun_session.h
r1106 r1110 19 19 #ifndef __PJNATH_STUN_SESSION_H__ 20 20 #define __PJNATH_STUN_SESSION_H__ 21 22 /** 23 * @file stun_session.h 24 * @brief STUN session management for client/server. 25 */ 21 26 22 27 #include <pjnath/stun_msg.h> … … 188 193 * 189 194 * @param sess The STUN session instance. 195 * @param user_data The user data. 190 196 * 191 197 * @return PJ_SUCCESS on success, or the appropriate error code. … … 352 358 * the message via one of the pj_stun_session_cb callback. 353 359 * 354 * @param sess The STUN session instance. 355 * @param packet The packet containing STUN message. 356 * @param pkt_size Size of the packet. 357 * @param options Options, from #pj_stun_decode_options. 358 * @param parsed_len Optional pointer to receive the size of the parsed 359 * STUN message (useful if packet is received via a 360 * stream oriented protocol). 361 * 362 * @return PJ_SUCCESS on success, or the appropriate error code. 360 * @param sess The STUN session instance. 361 * @param packet The packet containing STUN message. 362 * @param pkt_size Size of the packet. 363 * @param options Options, from #pj_stun_decode_options. 364 * @param parsed_len Optional pointer to receive the size of the parsed 365 * STUN message (useful if packet is received via a 366 * stream oriented protocol). 367 * @param src_addr The source address of the packet. 368 * @param src_addr_len Length of the source address. 369 * 370 * @return PJ_SUCCESS on success, or the appropriate error code. 363 371 */ 364 372 PJ_DECL(pj_status_t) pj_stun_session_on_rx_pkt(pj_stun_session *sess, -
pjproject/trunk/pjnath/include/pjnath/stun_transaction.h
r1091 r1110 192 192 * 193 193 * @param tsx The STUN client transaction instance. 194 * @param packet The incoming packet. 195 * @param pkt_size Size of the incoming packet. 196 * @param parsed_len Optional pointer to receive the number of bytes 197 * that have been parsed from the incoming packet 198 * for the STUN message. This is useful if the 199 * STUN transaction is running over stream oriented 200 * socket such as TCP or TLS. 194 * @param msg The incoming STUN message. 201 195 * 202 196 * @return PJ_SUCCESS on success or the appropriate error code. -
pjproject/trunk/pjnath/include/pjnath/types.h
r1101 r1110 29 29 30 30 /** 31 * @defgroup PJNATH NAT Helper Library31 * @defgroup PJNATH NAT Traversal Helper Library 32 32 * @{ 33 33 */ … … 52 52 53 53 /** 54 * @mainpage NAT Helper Library 55 * 56 * \n 57 * \n 58 * \n 59 * This is the documentation of PJNATH, an auxiliary library providing 60 * NAT helper functionalities such as STUN and ICE. 61 * 62 * Please go to the <A HREF="modules.htm"><B>Modules</B></A> page for list 63 * of modules. 64 * 54 * @mainpage PJNATH - Open Source STUN, TURN, and ICE Library 55 * 56 * \n 57 * This is the documentation of PJNATH, an Open Source library providing 58 * NAT traversal helper functionalities by using standard based protocols 59 * such as: 60 * - <b>STUN</b> (Session Traversal Utilities), 61 * - <b>TURN</b> (Obtaining Relay Addresses from STUN) 62 * - <b>ICE</b> (Interactive Connectivity Establishment). 63 * 64 * The following sections will give a short overview about the protocols 65 * supported by this library, and how they are implemented in PJNATH. 66 * 67 * \n 68 69 * \section PJNATH_STUN STUN Protocol Library 70 * 71 * Session Traversal Utilities (STUN, or previously known as Simple 72 * Traversal of User Datagram Protocol (UDP) Through Network Address 73 * Translators (NAT)s), was previously released as IETF standard 74 * <A HREF="http://www.ietf.org/rfc/rfc3489.txt">RFC 3489</A>, but since 75 * then it has been revised into the following: 76 * - <A HREF="http://www.ietf.org/internet-drafts/draft-ietf-behave-rfc3489bis-06.txt"> 77 * <B>draft-ietf-behave-rfc3489bis-06</b></A> for the main STUN 78 * specification, 79 * - <A HREF="http://www.ietf.org/internet-drafts/draft-ietf-behave-turn-03.txt"> 80 * <B>draft-ietf-behave-turn-03</B></A> for TURN usage of STUN, 81 * - and several other drafts explaining other STUN usages. 82 * 83 * The PJNATH library provides facilities to support both the core 84 * <B>STUN-bis</B> specification and the <B>TURN</B> usage of STUN, 85 * as well as other STUN usages. Please see #pj_stun_attr_type for 86 * list of STUN attributes supported by this library. 87 * 88 * 89 * The following are some design principles that have been utilized 90 * when implementing the STUN library in PJNATH: 91 * 92 * - layered architecture, with \ref PJNATH_STUN_MSG as the lowest 93 * layer and \ref PJNATH_STUN_SESSION as the highest abstraction 94 * layer, to accommodate various usage scenario of the library. 95 * 96 * - no transport -- the STUN library is pretty much transport 97 * independent and all sending and receiving functionalities will 98 * have to be implemented by application or higher level 99 * abstraction (such as ICE). This helps facilitating an even 100 * more usage scenarios of the library. 101 * 102 * - common functionalities for both STUN client and server 103 * development. All STUN components can be used to develop both 104 * STUN client and STUN server application, and in fact, in ICE, 105 * both STUN client and server functionality exist in a single 106 * ICE session. 107 * 108 * \n 109 * 110 * \subsection PJNATH_STUN_ARCH STUN Library Organization 111 * 112 113 \verbatim 114 115 +-----------------------------------------------------------------+ 116 | | 117 | A P P L I C A T I O N | 118 | | 119 +-----------------------------------------------------------------+ 120 ^ ^ 121 | | 122 v v 123 +--------+ +-----------------------------------+ +----------+ 124 | | | | | | 125 | Appl- |<-->| S T U N S E S S I O N |<-->| S T U N | 126 | ication| | | | Authen- | 127 | Trans- | +-----------------------------------+ | tication | 128 | port | | | | | 129 | |<-->| S T U N T R A N S A C T I O N | +----------+ 130 | | | | 131 | | +-----------------------------------+ 132 | | | | 133 | | | STUN MESSAGE REPRESENTATION | 134 +--------+ | AND PARSING | 135 +-----------------------------------+ 136 137 \endverbatim 138 139 * The STUN library is organized as follows: 140 * 141 * - the lowest layer of the library is \ref PJNATH_STUN_MSG. This layer 142 * provides STUN message representation, validation, parsing, and 143 * debugging (dump to log) of STUN messages. 144 * 145 * - for client, the next higher layer is \ref PJNATH_STUN_TRANSACTION, 146 * which manages retransmissions of STUN request. 147 * 148 * - \ref PJNATH_STUN_AUTH provides mechanism to verify STUN 149 * credential in incoming STUN messages. 150 * 151 * - for both client and server, the next higher abstraction is 152 * \ref PJNATH_STUN_SESSION, which provides management of incoming 153 * and outgoing messages and association of STUN credential to 154 * a STUN session. 155 * 156 * As mentioned previously, all STUN library components are independent 157 * of any transports. Application gives incoming packet 158 * to the STUN components for processing. and it must supply the STUN 159 * components with callback to send outgoing messages. 160 * 161 * \n 162 * 163 * \section PJNATH_ICE ICE Implementation 164 * 165 * Interactive Connectivity Establishment (ICE) is a standard based 166 * methodology for traversing Network Address Translator (NAT), and 167 * is described in 168 * <A HREF="http://www.ietf.org/internet-drafts/draft-ietf-mmusic-ice-14.txt"> 169 * <B>draft-ietf-mmusic-ice-14.txt</B></A> draft. The PJNATH ICE 170 * implementation is aimed to provide a usable and generic ICE transports 171 * for different types of application, including but not limited to 172 * the usage of ICE in SIP/SDP offer/answer. 173 * 174 * \subsection PJNATH_ICE_ARCH ICE Library Organization 175 * 176 * The ICE library is organized as follows: 177 * 178 * - the lowest layer is \ref PJNATH_ICE_SESSION, which provides 179 * ICE management and negotiation in a transport-independent way. 180 * This layer contains the state machines to perform ICE 181 * negotiation, and provides the most flexibility to control all 182 * aspects of ICE session. This layer normally is only usable for 183 * ICE implementors. 184 * 185 * - higher in the hierarchy is \ref PJNATH_ICE_STREAM_TRANSPORT, 186 * which binds ICE with UDP sockets, and provides STUN binding 187 * and relay/TURN allocation for the sockets. This component can 188 * be directly used by application, although normally application 189 * should use the next higher abstraction below since it provides 190 * SDP translations and better integration with other PJ libraries 191 * such as PJSIP and PJMEDIA. 192 * 193 * - the highest abstraction is ICE media transport, which maintains 194 * ICE stream transport and provides SDP translations to be used 195 * for SIP offer/answer exchanges. 196 */ 197 198 /** 199 * @defgroup PJNATH_STUN STUN Library 200 * @brief Open source STUN library 201 * 202 * This module contains implementation of STUN library in PJNATH - 203 * the open source NAT helper containing STUN and ICE. 65 204 */ 66 205 -
pjproject/trunk/pjnath/src/pjnath/ice.c
r1106 r1110 534 534 } 535 535 536 /* If there's no relayed candidate, find serverreflexive candidate */536 /* If there's no relayed candidate, find reflexive candidate */ 537 537 for (i=0; i<ice->lcand_cnt; ++i) { 538 538 pj_ice_cand *lcand = &ice->lcand[i]; 539 539 if (lcand->comp_id==comp_id && 540 lcand->type == PJ_ICE_CAND_TYPE_SRFLX) 540 (lcand->type == PJ_ICE_CAND_TYPE_SRFLX || 541 lcand->type == PJ_ICE_CAND_TYPE_PRFLX)) 541 542 { 542 543 *cand_id = GET_LCAND_ID(lcand); … … 798 799 799 800 /* Call callback */ 800 (*ice->cb.on_ice_complete)(ice, status); 801 if (ice->cb.on_ice_complete) { 802 (*ice->cb.on_ice_complete)(ice, status); 803 } 801 804 } 802 805 } -
pjproject/trunk/pjnath/src/pjnath/ice_stream_transport.c
r1106 r1110 195 195 PJ_ASSERT_RETURN(ice_st, PJ_EINVAL); 196 196 /* Must not have pending resolver job */ 197 PJ_ASSERT_RETURN(ice_st->has_r esolver_job==PJ_FALSE, PJ_EINVALIDOP);197 PJ_ASSERT_RETURN(ice_st->has_rjob==PJ_FALSE, PJ_EINVALIDOP); 198 198 199 199 if (stun_srv) { … … 241 241 242 242 PJ_ASSERT_RETURN(ice_st && comp && addr, PJ_EINVAL); 243 PJ_ASSERT_RETURN(comp->cand_cnt < PJ_ICE_ST_MAX_ ALIASES, PJ_ETOOMANY);243 PJ_ASSERT_RETURN(comp->cand_cnt < PJ_ICE_ST_MAX_CAND, PJ_ETOOMANY); 244 244 245 245 cand = &comp->cand_list[comp->cand_cnt]; … … 249 249 cand->status = PJ_SUCCESS; 250 250 pj_memcpy(&cand->addr, addr, sizeof(pj_sockaddr_in)); 251 cand-> cand_id = -1;251 cand->ice_cand_id = -1; 252 252 cand->local_pref = local_pref; 253 253 cand->foundation = calc_foundation(ice_st->pool, type, &addr->sin_addr); … … 348 348 /* Socket is bound to INADDR_ANY */ 349 349 unsigned i, ifs_cnt; 350 pj_in_addr ifs[PJ_ICE_ST_MAX_ ALIASES-2];350 pj_in_addr ifs[PJ_ICE_ST_MAX_CAND-2]; 351 351 352 352 /* Reset default candidate */ … … 474 474 PJ_TODO(DISTINGUISH_BETWEEN_LOCAL_AND_RELAY); 475 475 status = pj_ice_on_rx_pkt(ice_st->ice, comp->comp_id, 476 comp->cand_list[0]. cand_id,476 comp->cand_list[0].ice_cand_id, 477 477 comp->pkt, bytes_read, 478 478 &comp->src_addr, comp->src_addr_len); … … 550 550 551 551 /* Bail out if STUN server is still being resolved */ 552 if (ice_st->has_r esolver_job)552 if (ice_st->has_rjob) 553 553 return PJ_EBUSY; 554 554 … … 591 591 cand->type = PJ_ICE_CAND_TYPE_SRFLX; 592 592 cand->status = PJ_EPENDING; 593 cand-> cand_id = -1;593 cand->ice_cand_id = -1; 594 594 cand->local_pref = 65535; 595 595 cand->foundation = calc_foundation(ice_st->pool, PJ_ICE_CAND_TYPE_SRFLX, … … 626 626 627 627 /* Can't add new component while resolver is running */ 628 PJ_ASSERT_RETURN(ice_st->has_r esolver_job == PJ_FALSE, PJ_EBUSY);628 PJ_ASSERT_RETURN(ice_st->has_rjob == PJ_FALSE, PJ_EBUSY); 629 629 630 630 … … 749 749 &cand->addr, &comp->local_addr, NULL, 750 750 sizeof(pj_sockaddr_in), 751 (unsigned*)&cand-> cand_id);751 (unsigned*)&cand->ice_cand_id); 752 752 if (status != PJ_SUCCESS) 753 753 goto on_error; … … 828 828 unsigned j; 829 829 for (j=0; j<ice_st->comp[i]->cand_cnt; ++j) { 830 ice_st->comp[i]->cand_list[j]. cand_id = -1;830 ice_st->comp[i]->cand_list[j].ice_cand_id = -1; 831 831 } 832 832 } … … 859 859 } 860 860 861 #if 1 862 PJ_UNUSED_ARG(pkt_size); 863 PJ_UNUSED_ARG(status); 864 865 /* Otherwise return error */ 866 return PJNATH_EICEINPROGRESS; 867 #else 861 868 /* Otherwise send direcly with the socket */ 862 869 pkt_size = data_len; … … 866 873 867 874 return (status==PJ_SUCCESS||status==PJ_EPENDING) ? PJ_SUCCESS : status; 875 #endif 868 876 } 869 877
Note: See TracChangeset
for help on using the changeset viewer.