Ignore:
Timestamp:
Apr 9, 2008 9:38:12 AM (16 years ago)
Author:
bennylp
Message:

More ticket #485: huge changeset to support TURN TCP. Please see ticket #485 for the details

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjnath/src/pjturn-srv/turn.h

    r1879 r1913  
    2323#include <pjnath.h> 
    2424 
    25 typedef struct pj_turn_relay_res            pj_turn_relay_res; 
     25typedef struct pj_turn_relay_res    pj_turn_relay_res; 
    2626typedef struct pj_turn_listener     pj_turn_listener; 
    27 typedef struct pj_turn_permission    pj_turn_permission; 
    28 typedef struct pj_turn_allocation    pj_turn_allocation; 
     27typedef struct pj_turn_transport    pj_turn_transport; 
     28typedef struct pj_turn_permission   pj_turn_permission; 
     29typedef struct pj_turn_allocation   pj_turn_allocation; 
    2930typedef struct pj_turn_srv          pj_turn_srv; 
    3031typedef struct pj_turn_pkt          pj_turn_pkt; 
     
    133134    pj_lock_t           *lock; 
    134135 
    135     /** TURN listener. */ 
    136     pj_turn_listener    *listener; 
    137  
    138     /** Client socket, if connection to client is using TCP. */ 
    139     pj_sock_t           clt_sock; 
     136    /** Server instance. */ 
     137    pj_turn_srv         *server; 
     138 
     139    /** Transport to send/receive packets to/from client. */ 
     140    pj_turn_transport   *transport; 
    140141 
    141142    /** The relay resource for this allocation. */ 
     
    181182    /** Hash table key */ 
    182183    pj_turn_permission_key hkey; 
    183  
    184     /** Transport socket. If TCP is used, the value will be the actual 
    185      *  TCP socket. If UDP is used, the value will be the relay address 
    186      */ 
    187     pj_sock_t           sock; 
    188184 
    189185    /** TURN allocation that owns this permission/channel */ 
     
    202198 * Create new allocation. 
    203199 */ 
    204 PJ_DECL(pj_status_t) pj_turn_allocation_create(pj_turn_listener *listener, 
    205                                               const pj_sockaddr_t *src_addr, 
    206                                               unsigned src_addr_len, 
    207                                               const pj_stun_rx_data *rdata, 
    208                                               pj_stun_session *srv_sess, 
    209                                               pj_turn_allocation **p_alloc); 
     200PJ_DECL(pj_status_t) pj_turn_allocation_create(pj_turn_transport *transport, 
     201                                               const pj_sockaddr_t *src_addr, 
     202                                               unsigned src_addr_len, 
     203                                               const pj_stun_rx_data *rdata, 
     204                                               pj_stun_session *srv_sess, 
     205                                               pj_turn_allocation **p_alloc); 
    210206/** 
    211207 * Destroy allocation. 
     
    218214 */ 
    219215PJ_DECL(void) pj_turn_allocation_on_rx_client_pkt(pj_turn_allocation *alloc, 
    220                                                  pj_turn_pkt *pkt); 
     216                                                  pj_turn_pkt *pkt); 
     217 
     218/** 
     219 * Handle transport closure. 
     220 */ 
     221PJ_DECL(void) pj_turn_allocation_on_transport_closed(pj_turn_allocation *alloc, 
     222                                                     pj_turn_transport *tp); 
    221223 
    222224/****************************************************************************/ 
     
    258260    unsigned            flags; 
    259261 
     262    /** Destroy handler */ 
     263    pj_status_t         (*destroy)(pj_turn_listener*); 
     264}; 
     265 
     266 
     267/** 
     268 * This structure describes TURN transport socket which is used to send and 
     269 * receive packets towards client. 
     270 */ 
     271struct pj_turn_transport 
     272{ 
     273    /** Object name/identification */ 
     274    char                *obj_name; 
     275 
     276    /** Slightly longer info about this listener */ 
     277    char                *info; 
     278 
     279    /** Listener instance */ 
     280    pj_turn_listener    *listener; 
     281 
    260282    /** Sendto handler */ 
    261     pj_status_t         (*sendto)(pj_turn_listener *listener, 
     283    pj_status_t         (*sendto)(pj_turn_transport *tp, 
    262284                                  const void *packet, 
    263285                                  pj_size_t size, 
     
    266288                                  int addr_len); 
    267289 
    268     /** Destroy handler */ 
    269     pj_status_t         (*destroy)(pj_turn_listener*); 
     290    /** Addref handler */ 
     291    void                (*add_ref)(pj_turn_transport *tp, 
     292                                   pj_turn_allocation *alloc); 
     293 
     294    /** Decref handler */ 
     295    void                (*dec_ref)(pj_turn_transport *tp, 
     296                                   pj_turn_allocation *alloc); 
     297 
    270298}; 
    271299 
     
    279307    pj_pool_t               *pool; 
    280308 
    281     /** Listener that owns this. */ 
    282     pj_turn_listener        *listener; 
     309    /** Transport where the packet was received. */ 
     310    pj_turn_transport       *transport; 
    283311 
    284312    /** Packet buffer (must be 32bit aligned). */ 
     
    300328 
    301329/** 
    302  * Create a new listener on the specified port. 
     330 * Create a UDP listener on the specified port. 
    303331 */ 
    304332PJ_DECL(pj_status_t) pj_turn_listener_create_udp(pj_turn_srv *srv, 
    305                                                 int af, 
    306                                                 const pj_str_t *bound_addr, 
    307                                                 unsigned port, 
    308                                                 unsigned concurrency_cnt, 
    309                                                 unsigned flags, 
    310                                                 pj_turn_listener **p_listener); 
    311  
    312 /** 
    313  * Send packet with this listener. 
    314  */ 
    315 PJ_DECL(pj_status_t) pj_turn_listener_sendto(pj_turn_listener *listener, 
    316                                             const void *packet, 
    317                                             pj_size_t size, 
    318                                             unsigned flag, 
    319                                             const pj_sockaddr_t *addr, 
    320                                             int addr_len); 
     333                                                 int af, 
     334                                                 const pj_str_t *bound_addr, 
     335                                                 unsigned port, 
     336                                                 unsigned concurrency_cnt, 
     337                                                 unsigned flags, 
     338                                                 pj_turn_listener **p_lis); 
     339 
     340/** 
     341 * Create a TCP listener on the specified port. 
     342 */ 
     343PJ_DECL(pj_status_t) pj_turn_listener_create_tcp(pj_turn_srv *srv, 
     344                                                 int af, 
     345                                                 const pj_str_t *bound_addr, 
     346                                                 unsigned port, 
     347                                                 unsigned concurrency_cnt, 
     348                                                 unsigned flags, 
     349                                                 pj_turn_listener **p_lis); 
    321350 
    322351/** 
     
    324353 */ 
    325354PJ_DECL(pj_status_t) pj_turn_listener_destroy(pj_turn_listener *listener); 
     355 
     356 
     357/** 
     358 * Add a reference to a transport. 
     359 */ 
     360PJ_DECL(void) pj_turn_transport_add_ref(pj_turn_transport *transport, 
     361                                        pj_turn_allocation *alloc); 
     362 
     363 
     364/** 
     365 * Decrement transport reference counter. 
     366 */ 
     367PJ_DECL(void) pj_turn_transport_dec_ref(pj_turn_transport *transport, 
     368                                        pj_turn_allocation *alloc); 
     369 
    326370 
    327371 
     
    361405        pj_turn_listener **listener; 
    362406 
    363         /** Array of STUN sessions, one for each listeners. */ 
    364         pj_stun_session **stun_sess; 
     407        /** STUN session to handle initial Allocate request. */ 
     408        pj_stun_session *stun_sess; 
    365409 
    366410        /** Number of worker threads. */ 
     
    457501 */ 
    458502PJ_DECL(void) pj_turn_srv_on_rx_pkt(pj_turn_srv *srv,  
    459                                    pj_turn_pkt *pkt); 
     503                                    pj_turn_pkt *pkt); 
    460504 
    461505 
Note: See TracChangeset for help on using the changeset viewer.