Changeset 1988 for pjproject/trunk/pjnath/include/pjnath/turn_session.h
- Timestamp:
- Jun 6, 2008 2:47:10 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjnath/include/pjnath/turn_session.h
r1914 r1988 30 30 PJ_BEGIN_DECL 31 31 32 /** 33 * @defgroup PJNATH_TURN TURN Client Library 34 */ 35 36 32 37 /* **************************************************************************/ 33 38 /** 34 * @defgroup PJNATH_TURN_SESSION T URN client session39 * @defgroup PJNATH_TURN_SESSION Transport independent TURN client session 35 40 * @brief Transport independent TURN client session 36 * @ingroup PJNATH_ STUN41 * @ingroup PJNATH_TURN 37 42 * @{ 43 * 44 * This module describes the transport independent TURN client session. This 45 * interface is provided for implementors of a TURN client transport, and 46 * application usually will want to use \ref PJNATH_TURN_SOCK instead. 47 * 48 * The transport independent TURN client session is created to facilitate 49 * the creation of different types of transports between the client and the 50 * TURN server. 38 51 */ 39 52 … … 42 55 */ 43 56 typedef struct pj_turn_session pj_turn_session; 44 45 46 #define PJ_TURN_INVALID_CHANNEL 0xFFFF47 #define PJ_TURN_CHANNEL_MIN 0x400048 #define PJ_TURN_CHANNEL_MAX 0xFFFE /* inclusive */49 #define PJ_TURN_NO_TIMEOUT ((long)0x7FFFFFFF)50 #define PJ_TURN_MAX_PKT_LEN 300051 #define PJ_TURN_PERM_TIMEOUT 300 /* Must be greater than REFRESH_SEC_BEFORE */52 #define PJ_TURN_CHANNEL_TIMEOUT 600 /* Must be greater than REFRESH_SEC_BEFORE */53 #define PJ_TURN_REFRESH_SEC_BEFORE 6054 #define PJ_TURN_KEEP_ALIVE_SEC 1555 #define PJ_TURN_PEER_HTABLE_SIZE 856 57 57 58 … … 134 135 135 136 136 /* ChannelData header */ 137 #pragma pack(1) 138 139 /** 140 * This structure ChannelData header. All the fields are in network byte 141 * order when it's on the wire. 142 */ 137 143 typedef struct pj_turn_channel_data 138 144 { 139 pj_uint16_t ch_number; 140 pj_uint16_t length; 145 pj_uint16_t ch_number; /**< Channel number. */ 146 pj_uint16_t length; /**< Payload length. */ 141 147 } pj_turn_channel_data; 142 148 149 150 #pragma pack() 143 151 144 152 … … 152 160 * needs to send outgoing message. Since the TURN session doesn't 153 161 * have a socket on its own, this callback must be implemented. 162 * 163 * @param sess The TURN session. 164 * @param pkt The packet/data to be sent. 165 * @param pkt_len Length of the packet/data. 166 * @param dst_addr Destination address of the packet. 167 * @param addr_len Length of the destination address. 168 * 169 * @return The callback should return the status of the 170 * send operation. 154 171 */ 155 172 pj_status_t (*on_send_pkt)(pj_turn_session *sess, … … 157 174 unsigned pkt_len, 158 175 const pj_sockaddr_t *dst_addr, 159 unsigned dst_addr_len);176 unsigned addr_len); 160 177 161 178 /** … … 163 180 * a channel number. 164 181 * 165 * This callback is optional. 182 * This callback is optional since the nature of this callback is 183 * for information only. 184 * 185 * @param sess The TURN session. 186 * @param peer_addr The peer address. 187 * @param addr_len Length of the peer address. 188 * @param ch_num The channel number associated with this peer address. 166 189 */ 167 190 void (*on_channel_bound)(pj_turn_session *sess, … … 174 197 * Data indication or ChannelData message from the TURN server. 175 198 * 176 * This callback is optional. 199 * @param sess The TURN session. 200 * @param pkt The data/payload of the Data Indication or ChannelData 201 * packet. 202 * @param pkt_len Length of the data/payload. 203 * @param peer_addr Peer address where this payload was received by 204 * the TURN server. 205 * @param addr_len Length of the peer address. 177 206 */ 178 207 void (*on_rx_data)(pj_turn_session *sess, 179 const pj_uint8_t*pkt,208 void *pkt, 180 209 unsigned pkt_len, 181 210 const pj_sockaddr_t *peer_addr, … … 186 215 * implement this callback at least to know that the TURN session is 187 216 * going to be destroyed. 188 */ 189 void (*on_state)(pj_turn_session *sess, pj_turn_state_t old_state, 217 * 218 * @param sess The TURN session. 219 * @param old_state The previous state of the session. 220 * @param new_state The current state of the session. 221 */ 222 void (*on_state)(pj_turn_session *sess, 223 pj_turn_state_t old_state, 190 224 pj_turn_state_t new_state); 191 225 … … 194 228 195 229 /** 196 * Allocate parameter. 230 * Allocation parameter, which can be given when application calls 231 * pj_turn_session_alloc() to allocate relay address in the TURN server. 232 * Application should call pj_turn_alloc_param_default() to initialize 233 * this structure with the default values. 197 234 */ 198 235 typedef struct pj_turn_alloc_param 199 236 { 237 /** 238 * The requested BANDWIDTH. Default is zero to not request any 239 * specific bandwidth. 240 */ 200 241 int bandwidth; 242 243 /** 244 * The requested LIFETIME. Default is zero to not request any 245 * explicit allocation lifetime. 246 */ 201 247 int lifetime; 248 249 /** 250 * If set to non-zero, the TURN session will periodically send blank 251 * Send Indication every PJ_TURN_KEEP_ALIVE_SEC to refresh local 252 * NAT bindings. Default is zero. 253 */ 202 254 int ka_interval; 255 203 256 } pj_turn_alloc_param; 204 257 205 258 206 259 /** 207 * T URN session info.260 * This structure describes TURN session info. 208 261 */ 209 262 typedef struct pj_turn_session_info … … 215 268 216 269 /** 270 * Last error (if session was terminated because of error) 271 */ 272 pj_status_t last_status; 273 274 /** 217 275 * Type of connection to the TURN server. 218 276 */ 219 pj_turn_tp_type tp_type; 277 pj_turn_tp_type conn_type; 278 279 /** 280 * The selected TURN server address. 281 */ 282 pj_sockaddr server; 283 284 /** 285 * Mapped address, as reported by the TURN server. 286 */ 287 pj_sockaddr mapped_addr; 220 288 221 289 /** … … 225 293 226 294 /** 227 * The selected TURN server address.228 */229 pj_sockaddr server;230 231 /**232 295 * Current seconds before allocation expires. 233 296 */ … … 238 301 239 302 /** 240 * Create default pj_turn_alloc_param. 303 * Initialize pj_turn_alloc_param with the default values. 304 * 305 * @param prm The TURN allocation parameter to be initialized. 241 306 */ 242 307 PJ_DECL(void) pj_turn_alloc_param_default(pj_turn_alloc_param *prm); 243 308 309 244 310 /** 245 311 * Duplicate pj_turn_alloc_param. 312 * 313 * @param pool Pool to allocate memory (currently not used) 314 * @param dst Destination parameter. 315 * @param src Source parameter. 246 316 */ 247 317 PJ_DECL(void) pj_turn_alloc_param_copy(pj_pool_t *pool, … … 250 320 251 321 /** 252 * Get TURN state name. 322 * Get string representation for the given TURN state. 323 * 324 * @param state The TURN session state. 325 * 326 * @return The state name as NULL terminated string. 253 327 */ 254 328 PJ_DECL(const char*) pj_turn_state_name(pj_turn_state_t state); … … 256 330 257 331 /** 258 * Create TURN client session. 259 */ 260 PJ_DECL(pj_status_t) pj_turn_session_create(pj_stun_config *cfg, 332 * Create a TURN session instance with the specified address family and 333 * connection type. Once TURN session instance is created, application 334 * must call pj_turn_session_alloc() to allocate a relay address in the TURN 335 * server. 336 * 337 * @param cfg The STUN configuration which contains among other 338 * things the ioqueue and timer heap instance for 339 * the operation of this session. 340 * @param name Optional name to identify this session in the log. 341 * @param af Address family of the client connection. Currently 342 * pj_AF_INET() and pj_AF_INET6() are supported. 343 * @param conn_type Connection type to the TURN server. 344 * @param cb Callback to receive events from the TURN session. 345 * @param options Option flags, currently this value must be zero. 346 * @param user_data Arbitrary application data to be associated with 347 * this transport. 348 * @param p_sess Pointer to receive the created instance of the 349 * TURN session. 350 * 351 * @return PJ_SUCCESS if the operation has been successful, 352 * or the appropriate error code on failure. 353 */ 354 PJ_DECL(pj_status_t) pj_turn_session_create(const pj_stun_config *cfg, 261 355 const char *name, 262 356 int af, 263 357 pj_turn_tp_type conn_type, 264 358 const pj_turn_session_cb *cb, 359 unsigned options, 265 360 void *user_data, 266 unsigned options,267 361 pj_turn_session **p_sess); 268 362 269 270 /** 271 * Shutdown TURN client session. 363 /** 364 * Shutdown TURN client session. This will gracefully deallocate and 365 * destroy the client session. 366 * 367 * @param sess The TURN client session. 368 * 369 * @return PJ_SUCCESS if the operation has been successful, 370 * or the appropriate error code on failure. 272 371 */ 273 372 PJ_DECL(pj_status_t) pj_turn_session_shutdown(pj_turn_session *sess); … … 275 374 276 375 /** 277 * Forcefully destroy the TURN session. 376 * Forcefully destroy the TURN session. This will destroy the session 377 * immediately. If there is an active allocation, the server will not 378 * be notified about the client destruction. 379 * 380 * @param sess The TURN client session. 381 * 382 * @return PJ_SUCCESS if the operation has been successful, 383 * or the appropriate error code on failure. 278 384 */ 279 385 PJ_DECL(pj_status_t) pj_turn_session_destroy(pj_turn_session *sess); … … 281 387 282 388 /** 283 * Get TURN session info. 389 * Get the information about this TURN session and the allocation, if 390 * any. 391 * 392 * @param sess The TURN client session. 393 * @param info The structure to be initialized with the TURN 394 * session info. 395 * 396 * @return PJ_SUCCESS if the operation has been successful, 397 * or the appropriate error code on failure. 284 398 */ 285 399 PJ_DECL(pj_status_t) pj_turn_session_get_info(pj_turn_session *sess, … … 287 401 288 402 /** 289 * Re-assign user data. 403 * Associate a user data with this TURN session. The user data may then 404 * be retrieved later with pj_turn_session_get_user_data(). 405 * 406 * @param sess The TURN client session. 407 * @param user_data Arbitrary data. 408 * 409 * @return PJ_SUCCESS if the operation has been successful, 410 * or the appropriate error code on failure. 290 411 */ 291 412 PJ_DECL(pj_status_t) pj_turn_session_set_user_data(pj_turn_session *sess, … … 293 414 294 415 /** 295 * Retrieve user data. 416 * Retrieve the previously assigned user data associated with this TURN 417 * session. 418 * 419 * @param sess The TURN client session. 420 * 421 * @return The user/application data. 296 422 */ 297 423 PJ_DECL(void*) pj_turn_session_get_user_data(pj_turn_session *sess); 298 424 299 /** 300 * Set the server or domain name of the server. 425 426 /** 427 * Configure message logging. By default all flags are enabled. 428 * 429 * @param sess The TURN client session. 430 * @param flags Bitmask combination of #pj_stun_sess_msg_log_flag 431 */ 432 PJ_DECL(void) pj_turn_session_set_log(pj_turn_session *sess, 433 unsigned flags); 434 435 436 /** 437 * Set the server or domain name of the server. Before the application 438 * can send Allocate request (with pj_turn_session_alloc()), it must first 439 * resolve the server address(es) using this function. This function will 440 * resolve the TURN server using DNS SRV resolution if the \a resolver 441 * is set. The server resolution process will complete asynchronously, 442 * and application will be notified in \a on_state() callback with the 443 * session state set to PJ_TURN_STATE_RESOLVED. 444 * 445 * Application may call with pj_turn_session_alloc() before the server 446 * resolution completes. In this case, the operation will be queued by 447 * the session, and it will be sent once the server resolution completes. 448 * 449 * @param sess The TURN client session. 450 * @param domain The domain, hostname, or IP address of the TURN 451 * server. When this parameter contains domain name, 452 * the \a resolver parameter must be set to activate 453 * DNS SRV resolution. 454 * @param default_port The default TURN port number to use when DNS SRV 455 * resolution is not used. If DNS SRV resolution is 456 * used, the server port number will be set from the 457 * DNS SRV records. 458 * @param resolver If this parameter is not NULL, then the \a domain 459 * parameter will be first resolved with DNS SRV and 460 * then fallback to using DNS A/AAAA resolution when 461 * DNS SRV resolution fails. If this parameter is 462 * NULL, the \a domain parameter will be resolved as 463 * hostname. 464 * 465 * @return PJ_SUCCESS if the operation has been successfully 466 * queued, or the appropriate error code on failure. 467 * When this function returns PJ_SUCCESS, the final 468 * result of the resolution process will be notified 469 * to application in \a on_state() callback. 301 470 */ 302 471 PJ_DECL(pj_status_t) pj_turn_session_set_server(pj_turn_session *sess, … … 307 476 308 477 /** 309 * Set credential to be used by the session. 478 * Set credential to be used to authenticate against TURN server. 479 * Application must call this function before sending Allocate request 480 * with pj_turn_session_alloc(). 481 * 482 * @param sess The TURN client session 483 * @param cred STUN credential to be used. 484 * 485 * @return PJ_SUCCESS if the operation has been successful, 486 * or the appropriate error code on failure. 310 487 */ 311 488 PJ_DECL(pj_status_t) pj_turn_session_set_credential(pj_turn_session *sess, … … 314 491 315 492 /** 316 * Create TURN allocation. 493 * Allocate a relay address/resource in the TURN server by sending TURN 494 * Allocate request. Application must first initiate the server resolution 495 * process with pj_turn_session_set_server() and set the credential to be 496 * used with pj_turn_session_set_credential() before calling this function. 497 * 498 * This function will complete asynchronously, and the application will be 499 * notified about the allocation result in \a on_state() callback. The 500 * TURN session state will move to PJ_TURN_STATE_READY if allocation is 501 * successful, and PJ_TURN_STATE_DEALLOCATING or greater state if allocation 502 * has failed. 503 * 504 * Once allocation has been successful, the TURN session will keep this 505 * allocation alive until the session is destroyed, by sending periodic 506 * allocation refresh to the TURN server. 507 * 508 * @param sess The TURN client session. 509 * @param param Optional TURN allocation parameter. 510 * 511 * @return PJ_SUCCESS if the operation has been successfully 512 * initiated or the appropriate error code on failure. 317 513 */ 318 514 PJ_DECL(pj_status_t) pj_turn_session_alloc(pj_turn_session *sess, … … 321 517 322 518 /** 323 * Relay data to the specified peer through the session. 519 * Send a data to the specified peer address via the TURN relay. This 520 * function will encapsulate the data as STUN Send Indication or TURN 521 * ChannelData packet and send the message to the TURN server. The TURN 522 * server then will send the data to the peer. 523 * 524 * The allocation (pj_turn_session_alloc()) must have been successfully 525 * created before application can relay any data. 526 * 527 * Since TURN session is transport independent, this function will 528 * ultimately call \a on_send_pkt() callback to request the application 529 * to actually send the packet containing the data to the TURN server. 530 * 531 * @param sess The TURN client session. 532 * @param pkt The data/packet to be sent to peer. 533 * @param pkt_len Length of the data. 534 * @param peer_addr The remote peer address (the ultimate destination 535 * of the data, and not the TURN server address). 536 * @param addr_len Length of the address. 537 * 538 * @return PJ_SUCCESS if the operation has been successful, 539 * or the appropriate error code on failure. 324 540 */ 325 541 PJ_DECL(pj_status_t) pj_turn_session_sendto(pj_turn_session *sess, 326 542 const pj_uint8_t *pkt, 327 543 unsigned pkt_len, 328 const pj_sockaddr_t * addr,544 const pj_sockaddr_t *peer_addr, 329 545 unsigned addr_len); 330 546 331 547 /** 332 * Bind a peer address to a channel number. 548 * Optionally establish channel binding for the specified a peer address. 549 * This function will assign a unique channel number for the peer address 550 * and request channel binding to the TURN server for this address. When 551 * a channel has been bound to a peer, the TURN client and TURN server 552 * will exchange data using ChannelData encapsulation format, which has 553 * lower bandwidth overhead than Send Indication (the default format used 554 * when peer address is not bound to a channel). 555 * 556 * This function will complete asynchronously, and application will be 557 * notified about the result in \a on_channel_bound() callback. 558 * 559 * @param sess The TURN client session. 560 * @param peer The remote peer address. 561 * @param addr_len Length of the address. 562 * 563 * @return PJ_SUCCESS if the operation has been successfully 564 * initiated, or the appropriate error code on failure. 333 565 */ 334 566 PJ_DECL(pj_status_t) pj_turn_session_bind_channel(pj_turn_session *sess, … … 337 569 338 570 /** 339 * Notify TURN client session upon receiving a packet from server. 340 * The packet maybe a STUN packet or ChannelData packet. 571 * Notify TURN client session upon receiving a packet from server. Since 572 * the TURN session is transport independent, it does not read packet from 573 * any sockets, and rather relies on application giving it packets that 574 * are received from the TURN server. The session then processes this packet 575 * and decides whether it is part of TURN protocol exchange or if it is a 576 * data to be reported back to user, which in this case it will call the 577 * \a on_rx_data() callback. 578 * 579 * @param sess The TURN client session. 580 * @param pkt The packet as received from the TURN server. This 581 * should contain either STUN encapsulated message or 582 * a ChannelData packet. 583 * @param pkt_len The length of the packet. 584 * 585 * @return The function may return non-PJ_SUCCESS if it receives 586 * non-STUN and non-ChannelData packet, or if the 587 * \a on_rx_data() returns non-PJ_SUCCESS; 341 588 */ 342 589 PJ_DECL(pj_status_t) pj_turn_session_on_rx_pkt(pj_turn_session *sess, 343 const pj_uint8_t *pkt, 344 unsigned pkt_len, 345 pj_bool_t is_datagram); 590 void *pkt, 591 unsigned pkt_len); 346 592 347 593
Note: See TracChangeset
for help on using the changeset viewer.