Ignore:
Timestamp:
Jun 6, 2008 2:47:10 PM (16 years ago)
Author:
bennylp
Message:

Major major modifications related to ticket #485 (support for TURN-07):

  • Added STUN socket transport pj_stun_sock
  • Integration of TURN-07 to ICE
  • Major refactoring in ICE stream transport to make it simpler
  • Major modification (i.e. API change) in almost everywhere else
  • Much more elaborate STUN, TURN, and ICE tests in pjnath-test
File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjnath/include/pjnath/turn_sock.h

    r1913 r1988  
    1717 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA  
    1818 */ 
    19 #ifndef __PJNATH_turn_sock_H__ 
    20 #define __PJNATH_turn_sock_H__ 
     19#ifndef __PJNATH_TURN_SOCK_H__ 
     20#define __PJNATH_TURN_SOCK_H__ 
    2121 
    2222/** 
     
    3232/* **************************************************************************/ 
    3333/** 
    34  * @defgroup PJNATH_TURN_UDP TURN TCP client 
    35  * @brief TURN relay using TCP client as transport protocol 
    36  * @ingroup PJNATH_STUN 
     34 * @defgroup PJNATH_TURN_SOCK TURN client transport 
     35 * @brief Client transport utilizing TURN relay 
     36 * @ingroup PJNATH_TURN 
    3737 * @{ 
     38 * 
     39 * The TURN relay client transport can be used to relay data from the client 
     40 * to peer via a TURN relay. The application establishes TURN connection to 
     41 * the TURN server using UDP or TCP as the transport, then creates a relay 
     42 * address in the TURN server to be advertised to remote peer(s) as the  
     43 * transport address. When application sends data to a remote address via 
     44 * this transport, the data will be sent via the TURN relay, and vice versa. 
    3845 */ 
    3946 
    4047 
    4148/**  
    42  * Opaque declaration for TURN TCP client. 
     49 * Opaque declaration for TURN client. 
    4350 */ 
    4451typedef struct pj_turn_sock pj_turn_sock; 
    4552 
    46  
     53/** 
     54 * This structure contains callbacks that will be called by the TURN 
     55 * transport. 
     56 */ 
    4757typedef struct pj_turn_sock_cb 
    4858{ 
    4959    /** 
    50      * Notification when incoming data has been received, either through 
    51      * Data indication or ChannelData message from the TURN server. 
     60     * Notification when incoming data has been received from the remote 
     61     * peer via the TURN server. The data reported in this callback will 
     62     * be the exact data as sent by the peer (e.g. the TURN encapsulation 
     63     * such as Data Indication or ChannelData will be removed before this 
     64     * function is called). 
    5265     * 
    53      * This callback is mandatory. 
     66     * @param turn_sock     The TURN client transport. 
     67     * @param data          The data as received from the peer.     
     68     * @param data_len      Length of the data. 
     69     * @param peer_addr     The peer address. 
     70     * @param addr_len      The length of the peer address. 
    5471     */ 
    5572    void (*on_rx_data)(pj_turn_sock *turn_sock, 
    56                        const pj_uint8_t *pkt, 
     73                       void *pkt, 
    5774                       unsigned pkt_len, 
    5875                       const pj_sockaddr_t *peer_addr, 
     
    6178    /** 
    6279     * Notification when TURN session state has changed. Application should 
    63      * implement this callback to know that the TURN session is no longer 
    64      * available. 
     80     * implement this callback to monitor the progress of the TURN session. 
     81     * 
     82     * @param turn_sock     The TURN client transport. 
     83     * @param old_state     Previous state. 
     84     * @param new_state     Current state. 
    6585     */ 
    66     void (*on_state)(pj_turn_sock *turn_sock, pj_turn_state_t old_state, 
     86    void (*on_state)(pj_turn_sock *turn_sock,  
     87                     pj_turn_state_t old_state, 
    6788                     pj_turn_state_t new_state); 
    6889 
     
    7192 
    7293/** 
    73  * Create. 
     94 * Create a TURN transport instance with the specified address family and 
     95 * connection type. Once TURN transport instance is created, application 
     96 * must call pj_turn_sock_alloc() to allocate a relay address in the TURN 
     97 * server. 
     98 * 
     99 * @param cfg           The STUN configuration which contains among other 
     100 *                      things the ioqueue and timer heap instance for 
     101 *                      the operation of this transport. 
     102 * @param af            Address family of the client connection. Currently 
     103 *                      pj_AF_INET() and pj_AF_INET6() are supported. 
     104 * @param conn_type     Connection type to the TURN server. Both TCP and 
     105 *                      UDP are supported. 
     106 * @param cb            Callback to receive events from the TURN transport. 
     107 * @param options       Option flags, currently this value must be zero. 
     108 * @param user_data     Arbitrary application data to be associated with 
     109 *                      this transport. 
     110 * @param p_turn_sock   Pointer to receive the created instance of the 
     111 *                      TURN transport. 
     112 * 
     113 * @return              PJ_SUCCESS if the operation has been successful, 
     114 *                      or the appropriate error code on failure. 
    74115 */ 
    75116PJ_DECL(pj_status_t) pj_turn_sock_create(pj_stun_config *cfg, 
     
    82123 
    83124/** 
    84  * Destroy. 
     125 * Destroy the TURN transport instance. This will gracefully close the 
     126 * connection between the client and the TURN server. Although this 
     127 * function will return immediately, the TURN socket deletion may continue 
     128 * in the background and the application may still get state changes 
     129 * notifications from this transport. 
     130 * 
     131 * @param turn_sock     The TURN transport instance. 
    85132 */ 
    86133PJ_DECL(void) pj_turn_sock_destroy(pj_turn_sock *turn_sock); 
    87134 
    88 /** 
    89  * Set user data. 
     135 
     136/** 
     137 * Associate a user data with this TURN transport. The user data may then 
     138 * be retrieved later with #pj_turn_sock_get_user_data(). 
     139 * 
     140 * @param turn_sock     The TURN transport instance. 
     141 * @param user_data     Arbitrary data. 
     142 * 
     143 * @return              PJ_SUCCESS if the operation has been successful, 
     144 *                      or the appropriate error code on failure. 
    90145 */ 
    91146PJ_DECL(pj_status_t) pj_turn_sock_set_user_data(pj_turn_sock *turn_sock, 
    92                                                void *user_data); 
    93  
    94 /** 
    95  * Get user data. 
     147                                                void *user_data); 
     148 
     149/** 
     150 * Retrieve the previously assigned user data associated with this TURN 
     151 * transport. 
     152 * 
     153 * @param turn_sock     The TURN transport instance. 
     154 * 
     155 * @return              The user/application data. 
    96156 */ 
    97157PJ_DECL(void*) pj_turn_sock_get_user_data(pj_turn_sock *turn_sock); 
     
    99159 
    100160/** 
    101  * Get info. 
     161 * Get the TURN transport info. The transport info contains, among other 
     162 * things, the allocated relay address. 
     163 * 
     164 * @param turn_sock     The TURN transport instance. 
     165 * @param info          Pointer to be filled with TURN transport info. 
     166 * 
     167 * @return              PJ_SUCCESS if the operation has been successful, 
     168 *                      or the appropriate error code on failure. 
    102169 */ 
    103170PJ_DECL(pj_status_t) pj_turn_sock_get_info(pj_turn_sock *turn_sock, 
    104                                           pj_turn_session_info *info); 
    105  
    106 /** 
    107  * Initialize. 
    108  */ 
    109 PJ_DECL(pj_status_t) pj_turn_sock_init(pj_turn_sock *turn_sock, 
    110                                        const pj_str_t *domain, 
    111                                        int default_port, 
    112                                        pj_dns_resolver *resolver, 
    113                                        const pj_stun_auth_cred *cred, 
    114                                        const pj_turn_alloc_param *param); 
    115  
    116 /** 
    117  * Send packet. 
     171                                           pj_turn_session_info *info); 
     172 
     173/** 
     174 * Acquire the internal mutex of the TURN transport. Application may need 
     175 * to call this function to synchronize access to other objects alongside  
     176 * the TURN transport, to avoid deadlock. 
     177 * 
     178 * @param turn_sock     The TURN transport instance. 
     179 * 
     180 * @return              PJ_SUCCESS if the operation has been successful, 
     181 *                      or the appropriate error code on failure. 
     182 */ 
     183PJ_DECL(pj_status_t) pj_turn_sock_lock(pj_turn_sock *turn_sock); 
     184 
     185 
     186/** 
     187 * Release the internal mutex previously held with pj_turn_sock_lock(). 
     188 * 
     189 * @param turn_sock     The TURN transport instance. 
     190 * 
     191 * @return              PJ_SUCCESS if the operation has been successful, 
     192 *                      or the appropriate error code on failure. 
     193 */ 
     194PJ_DECL(pj_status_t) pj_turn_sock_unlock(pj_turn_sock *turn_sock); 
     195 
     196 
     197/** 
     198 * Set STUN message logging for this TURN session.  
     199 * See #pj_stun_session_set_log(). 
     200 * 
     201 * @param turn_sock     The TURN transport instance. 
     202 * @param flags         Bitmask combination of #pj_stun_sess_msg_log_flag 
     203 */ 
     204PJ_DECL(void) pj_turn_sock_set_log(pj_turn_sock *turn_sock, 
     205                                   unsigned flags); 
     206 
     207/** 
     208 * Allocate a relay address/resource in the TURN server. This function 
     209 * will resolve the TURN server using DNS SRV (if desired) and send TURN 
     210 * \a Allocate request using the specified credential to allocate a relay 
     211 * address in the server. This function completes asynchronously, and 
     212 * application will be notified when the allocation process has been 
     213 * successful in the \a on_state() callback when the state is set to 
     214 * PJ_TURN_STATE_READY. If the allocation fails, the state will be set 
     215 * to PJ_TURN_STATE_DEALLOCATING or greater. 
     216 * 
     217 * @param turn_sock     The TURN transport instance. 
     218 * @param domain        The domain, hostname, or IP address of the TURN 
     219 *                      server. When this parameter contains domain name, 
     220 *                      the \a resolver parameter must be set to activate 
     221 *                      DNS SRV resolution. 
     222 * @param default_port  The default TURN port number to use when DNS SRV 
     223 *                      resolution is not used. If DNS SRV resolution is 
     224 *                      used, the server port number will be set from the 
     225 *                      DNS SRV records. 
     226 * @param resolver      If this parameter is not NULL, then the \a domain 
     227 *                      parameter will be first resolved with DNS SRV and 
     228 *                      then fallback to using DNS A/AAAA resolution when 
     229 *                      DNS SRV resolution fails. If this parameter is 
     230 *                      NULL, the \a domain parameter will be resolved as 
     231 *                      hostname. 
     232 * @param cred          The STUN credential to be used for the TURN server. 
     233 * @param param         Optional TURN allocation parameter. 
     234 * 
     235 * @return              PJ_SUCCESS if the operation has been successfully 
     236 *                      queued, or the appropriate error code on failure. 
     237 *                      When this function returns PJ_SUCCESS, the final 
     238 *                      result of the allocation process will be notified 
     239 *                      to application in \a on_state() callback. 
     240 *                       
     241 */ 
     242PJ_DECL(pj_status_t) pj_turn_sock_alloc(pj_turn_sock *turn_sock, 
     243                                        const pj_str_t *domain, 
     244                                        int default_port, 
     245                                        pj_dns_resolver *resolver, 
     246                                        const pj_stun_auth_cred *cred, 
     247                                        const pj_turn_alloc_param *param); 
     248 
     249/** 
     250 * Send a data to the specified peer address via the TURN relay. This  
     251 * function will encapsulate the data as STUN Send Indication or TURN 
     252 * ChannelData packet and send the message to the TURN server. The TURN 
     253 * server then will send the data to the peer. 
     254 * 
     255 * The allocation (pj_turn_sock_alloc()) must have been successfully 
     256 * created before application can relay any data. 
     257 * 
     258 * @param turn_sock     The TURN transport instance. 
     259 * @param pkt           The data/packet to be sent to peer. 
     260 * @param pkt_len       Length of the data. 
     261 * @param peer_addr     The remote peer address (the ultimate destination 
     262 *                      of the data, and not the TURN server address). 
     263 * @param addr_len      Length of the address. 
     264 * 
     265 * @return              PJ_SUCCESS if the operation has been successful, 
     266 *                      or the appropriate error code on failure. 
    118267 */  
    119268PJ_DECL(pj_status_t) pj_turn_sock_sendto(pj_turn_sock *turn_sock, 
    120269                                        const pj_uint8_t *pkt, 
    121270                                        unsigned pkt_len, 
    122                                         const pj_sockaddr_t *addr, 
     271                                        const pj_sockaddr_t *peer_addr, 
    123272                                        unsigned addr_len); 
    124273 
    125274/** 
    126  * Bind a peer address to a channel number. 
     275 * Optionally establish channel binding for the specified a peer address. 
     276 * This function will assign a unique channel number for the peer address 
     277 * and request channel binding to the TURN server for this address. When 
     278 * a channel has been bound to a peer, the TURN transport and TURN server 
     279 * will exchange data using ChannelData encapsulation format, which has 
     280 * lower bandwidth overhead than Send Indication (the default format used 
     281 * when peer address is not bound to a channel). 
     282 * 
     283 * @param turn_sock     The TURN transport instance. 
     284 * @param peer          The remote peer address. 
     285 * @param addr_len      Length of the address. 
     286 * 
     287 * @return              PJ_SUCCESS if the operation has been successful, 
     288 *                      or the appropriate error code on failure. 
    127289 */ 
    128290PJ_DECL(pj_status_t) pj_turn_sock_bind_channel(pj_turn_sock *turn_sock, 
    129                                               const pj_sockaddr_t *peer, 
    130                                               unsigned addr_len); 
     291                                               const pj_sockaddr_t *peer, 
     292                                               unsigned addr_len); 
    131293 
    132294 
     
    139301 
    140302 
    141 #endif  /* __PJNATH_turn_sock_H__ */ 
    142  
     303#endif  /* __PJNATH_TURN_SOCK_H__ */ 
     304 
Note: See TracChangeset for help on using the changeset viewer.