Ignore:
Timestamp:
Mar 8, 2008 12:54:04 AM (16 years ago)
Author:
bennylp
Message:

More work on ticket #485: more TURN-07 work

File:
1 edited

Legend:

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

    r1812 r1850  
    3434#define PJTURN_NO_TIMEOUT           ((long)0x7FFFFFFF) 
    3535#define PJTURN_MAX_PKT_LEN          3000 
     36#define PJTURN_PERM_TIMEOUT         300 
     37#define PJTURN_CHANNEL_TIMEOUT      600 
    3638 
    3739/** Transport types */ 
     
    4143}; 
    4244 
     45/**  
     46 * Get transport type name string. 
     47 */ 
     48PJ_DECL(const char*) pjturn_tp_type_name(int tp_type); 
    4349 
    4450/** 
     
    5561        /** Transport/relay address */ 
    5662        pj_sockaddr         addr; 
    57     } key; 
    58  
    59     /** Pool for this resource. */ 
    60     pj_pool_t       *pool; 
    61  
    62     /** Mutex */ 
    63     pj_lock_t       *lock; 
     63    } hkey; 
    6464 
    6565    /** Allocation who requested or reserved this resource. */ 
    6666    pjturn_allocation *allocation; 
    6767 
    68     /** Time when this resource times out */ 
    69     pj_time_val     timeout; 
    70  
    7168    /** Username used in credential */ 
    7269    pj_str_t        user; 
     
    7572    pj_str_t        realm; 
    7673 
    77     /** Transport/relay socket */ 
    78     pj_sock_t       sock; 
     74    /** Lifetime, in seconds. */ 
     75    unsigned        lifetime; 
     76 
     77    /** Relay/allocation expiration time */ 
     78    pj_time_val     expiry; 
     79 
     80    /** Timeout timer entry */ 
     81    pj_timer_entry  timer; 
     82 
     83    /** Transport. */ 
     84    struct { 
     85        /** Transport/relay socket */ 
     86        pj_sock_t           sock; 
     87 
     88        /** Transport/relay ioqueue */ 
     89        pj_ioqueue_key_t    *key; 
     90 
     91        /** Read operation key. */ 
     92        pj_ioqueue_op_key_t read_key; 
     93 
     94        /** The incoming packet buffer */ 
     95        char                rx_pkt[PJTURN_MAX_PKT_LEN]; 
     96 
     97        /** Source address of the packet. */ 
     98        pj_sockaddr         src_addr; 
     99 
     100        /** Source address length */ 
     101        int                 src_addr_len; 
     102 
     103        /** The outgoing packet buffer. This must be 3wbit aligned. */ 
     104        char                tx_pkt[PJTURN_MAX_PKT_LEN+4]; 
     105    } tp; 
    79106}; 
    80107 
     
    105132 
    106133    /** Requested IP */ 
    107     pj_sockaddr         addr; 
     134    char                addr[PJ_INET6_ADDRSTRLEN]; 
    108135 
    109136    /** Requested bandwidth */ 
     
    128155{ 
    129156    /** Hash table key to identify client. */ 
    130     pjturn_allocation_key key; 
     157    pjturn_allocation_key hkey; 
    131158 
    132159    /** Pool for this allocation. */ 
    133160    pj_pool_t           *pool; 
    134161 
     162    /** Object name for logging identification */ 
     163    char                *obj_name; 
     164 
     165    /** Client info (IP address and port) */ 
     166    char                info[80]; 
     167 
    135168    /** Mutex */ 
    136169    pj_lock_t           *lock; 
     
    148181    pjturn_relay_res    *resv; 
    149182 
    150 }; 
     183    /** Requested bandwidth */ 
     184    unsigned            bandwidth; 
     185 
     186    /** STUN session for this client */ 
     187    pj_stun_session     *sess; 
     188 
     189    /** Peer hash table (keyed by peer address) */ 
     190    pj_hash_table_t     *peer_table; 
     191 
     192    /** Channel hash table (keyed by channel number) */ 
     193    pj_hash_table_t     *ch_table; 
     194}; 
     195 
     196 
     197/** 
     198 * This structure describes the hash table key to lookup TURN 
     199 * permission. 
     200 */ 
     201typedef struct pjturn_permission_key 
     202{ 
     203    /** Peer address. */ 
     204    pj_sockaddr         peer_addr; 
     205 
     206} pjturn_permission_key; 
    151207 
    152208 
     
    157213{ 
    158214    /** Hash table key */ 
    159     struct { 
    160         /** Transport type. */ 
    161         pj_uint16_t             tp_type; 
    162  
    163         /** Transport socket. If TCP is used, the value will be the actual 
    164          *  TCP socket. If UDP is used, the value will be the relay address 
    165          */ 
    166         pj_sock_t               sock; 
    167  
    168         /** Peer address. */ 
    169         pj_sockaddr             peer_addr; 
    170     } key; 
    171  
    172     /** Pool for this permission. */ 
    173     pj_pool_t           *pool; 
    174  
    175     /** Mutex */ 
    176     pj_lock_t           *lock; 
     215    pjturn_permission_key hkey; 
     216 
     217    /** Transport socket. If TCP is used, the value will be the actual 
     218     *  TCP socket. If UDP is used, the value will be the relay address 
     219     */ 
     220    pj_sock_t           sock; 
    177221 
    178222    /** TURN allocation that owns this permission/channel */ 
     
    184228    pj_uint16_t         channel; 
    185229 
    186     /** Permission timeout. */ 
    187     pj_time_val         timeout; 
    188 }; 
    189  
    190 /** 
    191  * Handle incoming packet. 
    192  */ 
    193 PJ_DECL(void) pjturn_allocation_on_rx_pkt(pjturn_allocation *alloc, 
    194                                           pjturn_pkt *pkt); 
    195  
     230    /** Permission expiration time. */ 
     231    pj_time_val         expiry; 
     232}; 
     233 
     234/** 
     235 * Create new allocation. 
     236 */ 
     237PJ_DECL(pj_status_t) pjturn_allocation_create(pjturn_listener *listener, 
     238                                              const pj_sockaddr_t *src_addr, 
     239                                              unsigned src_addr_len, 
     240                                              const pj_stun_msg *msg, 
     241                                              const pjturn_allocation_req *req, 
     242                                              pjturn_allocation **p_alloc); 
     243/** 
     244 * Destroy allocation. 
     245 */ 
     246PJ_DECL(void) pjturn_allocation_destroy(pjturn_allocation *alloc); 
     247 
     248/** 
     249 * Create relay. 
     250 */ 
     251PJ_DECL(pj_status_t) pjturn_allocation_create_relay(pjturn_srv *srv, 
     252                                                    pjturn_allocation *alloc, 
     253                                                    const pj_stun_msg *msg, 
     254                                                    const pjturn_allocation_req *req, 
     255                                                    pjturn_relay_res *relay); 
     256 
     257/** 
     258 * Handle incoming packet from client. 
     259 */ 
     260PJ_DECL(void) pjturn_allocation_on_rx_client_pkt(pjturn_allocation *alloc, 
     261                                                 pjturn_pkt *pkt); 
    196262 
    197263/****************************************************************************/ 
     
    251317    pjturn_listener         *listener; 
    252318 
    253     /** Packet buffer. */ 
     319    /** Packet buffer (must be 32bit aligned). */ 
    254320    pj_uint8_t              pkt[PJTURN_MAX_PKT_LEN]; 
    255321 
     
    358424        pj_hash_table_t *res; 
    359425 
    360         /** Permission hash table, indexed by transport type, socket handle, 
    361          *  and peer address. 
    362          */ 
    363         pj_hash_table_t *peer; 
    364  
    365426    } tables; 
    366427 
     
    408469 
    409470/** 
     471 * Register an allocation. 
     472 */ 
     473PJ_DECL(pj_status_t) pjturn_srv_register_allocation(pjturn_srv *srv, 
     474                                                    pjturn_allocation *alloc); 
     475 
     476/** 
     477 * Unregister an allocation. 
     478 */ 
     479PJ_DECL(pj_status_t) pjturn_srv_unregister_allocation(pjturn_srv *srv, 
     480                                                      pjturn_allocation *alloc); 
     481 
     482/** 
    410483 * This callback is called by UDP listener on incoming packet. 
    411484 */ 
Note: See TracChangeset for help on using the changeset viewer.