Ignore:
Timestamp:
Apr 14, 2008 1:48:39 AM (16 years ago)
Author:
bennylp
Message:

More ticket #485: huge changeset to integrate TURN with ICE and PJSUA-LIB/pjsua. Still experimental

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/branches/projects/ice-turn07/pjnath/src/pjnath/ice_session.c

    r1913 r1926  
    102102 
    103103 
     104/* This is the data that will be attached as token to outgoing 
     105 * STUN messages. 
     106 */ 
     107struct msg_data 
     108{ 
     109    pj_bool_t                        is_request; 
     110 
     111    union data { 
     112        struct request_data { 
     113            pj_ice_sess             *ice; 
     114            pj_ice_sess_checklist   *clist; 
     115            unsigned                 ckid; 
     116        } req; 
     117 
     118        struct response_data { 
     119            unsigned                 cand_id; 
     120        } res; 
     121    } data; 
     122}; 
     123 
     124 
    104125/* Forward declarations */ 
    105126static void destroy_ice(pj_ice_sess *ice, 
     
    13461367} 
    13471368 
    1348  
    1349 /* This is the data that will be attached as user data to outgoing 
    1350  * STUN requests, and it will be given back when we receive completion 
    1351  * status of the request. 
    1352  */ 
    1353 struct req_data 
    1354 { 
    1355     pj_ice_sess             *ice; 
    1356     pj_ice_sess_checklist   *clist; 
    1357     unsigned                 ckid; 
    1358 }; 
    1359  
    1360  
    13611369/* Perform check on the specified candidate pair */ 
    13621370static pj_status_t perform_check(pj_ice_sess *ice,  
     
    13651373{ 
    13661374    pj_ice_sess_comp *comp; 
    1367     struct req_data *rd; 
     1375    struct msg_data *msg_data; 
    13681376    pj_ice_sess_check *check; 
    13691377    const pj_ice_sess_cand *lcand; 
     
    13931401     * completes and on_stun_request_complete() callback is called. 
    13941402     */ 
    1395     rd = PJ_POOL_ZALLOC_T(check->tdata->pool, struct req_data); 
    1396     rd->ice = ice; 
    1397     rd->clist = clist; 
    1398     rd->ckid = check_id; 
     1403    msg_data = PJ_POOL_ZALLOC_T(check->tdata->pool, struct msg_data); 
     1404    msg_data->is_request = PJ_TRUE; 
     1405    msg_data->data.req.ice = ice; 
     1406    msg_data->data.req.clist = clist; 
     1407    msg_data->data.req.ckid = check_id; 
    13991408 
    14001409    /* Add PRIORITY */ 
     
    14281437 
    14291438    /* Initiate STUN transaction to send the request */ 
    1430     status = pj_stun_session_send_msg(comp->stun_sess, (void*)rd, PJ_FALSE,  
     1439    status = pj_stun_session_send_msg(comp->stun_sess, msg_data, PJ_FALSE,  
    14311440                                      PJ_TRUE, &rcand->addr,  
    14321441                                      sizeof(pj_sockaddr_in), check->tdata); 
     
    16561665    stun_data *sd = (stun_data*) pj_stun_session_get_user_data(sess); 
    16571666    pj_ice_sess *ice = sd->ice; 
    1658  
    1659     PJ_UNUSED_ARG(token); 
    1660  
    1661     return (*ice->cb.on_tx_pkt)(ice, sd->comp_id,  
    1662                                 pkt, pkt_size,  
    1663                                 dst_addr, addr_len); 
     1667    struct msg_data *msg_data = (struct msg_data*) token; 
     1668    unsigned cand_id; 
     1669     
     1670    if (msg_data->is_request) { 
     1671        pj_ice_sess_checklist *clist = msg_data->data.req.clist; 
     1672        pj_ice_sess_cand *lcand = clist->checks[msg_data->data.req.ckid].lcand; 
     1673 
     1674        cand_id = lcand - ice->lcand; 
     1675         
     1676    } else { 
     1677        cand_id = msg_data->data.res.cand_id; 
     1678    } 
     1679 
     1680    return (*ice->cb.on_tx_pkt)(ice, sd->comp_id, cand_id, 
     1681                                pkt, pkt_size, dst_addr, addr_len); 
    16641682} 
    16651683 
     
    16741692                                     unsigned src_addr_len) 
    16751693{ 
    1676     struct req_data *rd = (struct req_data*) token; 
     1694    struct msg_data *msg_data = (struct msg_data*) token; 
    16771695    pj_ice_sess *ice; 
    16781696    pj_ice_sess_check *check, *new_check; 
     
    16851703    PJ_UNUSED_ARG(src_addr_len); 
    16861704 
    1687     ice = rd->ice; 
    1688     check = &rd->clist->checks[rd->ckid]; 
    1689     clist = rd->clist; 
     1705    pj_assert(msg_data->is_request); 
     1706 
     1707    ice = msg_data->data.req.ice; 
     1708    clist = msg_data->data.req.clist; 
     1709    check = &clist->checks[msg_data->data.req.ckid]; 
     1710     
    16901711 
    16911712    /* Mark STUN transaction as complete */ 
     
    17401761            LOG4((ice->obj_name, "Resending check because of role conflict")); 
    17411762            check_set_state(ice, check, PJ_ICE_SESS_CHECK_STATE_WAITING, 0); 
    1742             perform_check(ice, clist, rd->ckid); 
     1763            perform_check(ice, clist, msg_data->data.req.ckid); 
    17431764            pj_mutex_unlock(ice->mutex); 
    17441765            return; 
     
    19191940{ 
    19201941    stun_data *sd; 
     1942    unsigned *param_cand_id; 
    19211943    const pj_stun_msg *msg = rdata->msg; 
     1944    struct msg_data *msg_data; 
    19221945    pj_ice_sess *ice; 
    19231946    pj_stun_priority_attr *prio_attr; 
     
    19301953    PJ_UNUSED_ARG(pkt); 
    19311954    PJ_UNUSED_ARG(pkt_len); 
    1932     PJ_UNUSED_ARG(token); 
     1955     
     1956    /* 
     1957     * Note about candidate ID parameter: 
     1958     *  This parameter is given by us by user, and it cannot be used to 
     1959     *  distinguish local and server reflexive candidate. Just about the 
     1960     *  only thing that we can do with it is to return it back to user 
     1961     *  in the on_tx_pkt(). The user needs this information to determine 
     1962     *  whether to send packet using local socket or the relay. 
     1963     */ 
     1964    param_cand_id = (unsigned*)token; 
    19331965 
    19341966    /* Reject any requests except Binding request */ 
     
    20352067    } 
    20362068 
     2069    /* Add XOR-MAPPED-ADDRESS attribute */ 
    20372070    status = pj_stun_msg_add_sockaddr_attr(tdata->pool, tdata->msg,  
    20382071                                           PJ_STUN_ATTR_XOR_MAPPED_ADDR, 
    20392072                                           PJ_TRUE, src_addr, src_addr_len); 
    20402073 
    2041     status = pj_stun_session_send_msg(sess, NULL, PJ_TRUE, PJ_TRUE, 
     2074    /* Create a msg_data to be associated with this response */ 
     2075    msg_data = PJ_POOL_ZALLOC_T(tdata->pool, struct msg_data); 
     2076    msg_data->is_request = PJ_FALSE; 
     2077    msg_data->data.res.cand_id = *param_cand_id; 
     2078 
     2079    /* Send the response */ 
     2080    status = pj_stun_session_send_msg(sess, msg_data, PJ_TRUE, PJ_TRUE, 
    20422081                                      src_addr, src_addr_len, tdata); 
    20432082 
     
    20912130    pj_ice_sess_cand *rcand; 
    20922131    unsigned i; 
    2093     pj_bool_t is_relayed; 
    20942132 
    20952133    comp = find_comp(ice, rcheck->comp_id); 
     
    21712209     * Create candidate pair for this request.  
    21722210     */ 
    2173     /* First check if the source address is the source address of the  
    2174      * STUN relay, to determine if local candidate is relayed candidate. 
    2175      */ 
    2176     PJ_TODO(DETERMINE_IF_REQUEST_COMES_FROM_RELAYED_CANDIDATE); 
    2177     is_relayed = PJ_FALSE; 
    21782211 
    21792212    /*  
     
    23102343    pj_status_t status = PJ_SUCCESS; 
    23112344    pj_ice_sess_comp *comp; 
     2345    unsigned cand_id; 
    23122346 
    23132347    PJ_ASSERT_RETURN(ice && comp_id, PJ_EINVAL); 
     
    23332367    } 
    23342368 
    2335     status = (*ice->cb.on_tx_pkt)(ice, comp_id, data, data_len,  
     2369    cand_id = comp->valid_check->lcand - ice->lcand; 
     2370 
     2371    status = (*ice->cb.on_tx_pkt)(ice, comp_id, cand_id, data, data_len,  
    23362372                                  &comp->valid_check->rcand->addr,  
    23372373                                  sizeof(pj_sockaddr_in)); 
     
    23452381PJ_DEF(pj_status_t) pj_ice_sess_on_rx_pkt(pj_ice_sess *ice, 
    23462382                                          unsigned comp_id, 
     2383                                          unsigned cand_id, 
    23472384                                          void *pkt, 
    23482385                                          pj_size_t pkt_size, 
     
    23682405    if (stun_status == PJ_SUCCESS) { 
    23692406        status = pj_stun_session_on_rx_pkt(comp->stun_sess, pkt, pkt_size, 
    2370                                            PJ_STUN_IS_DATAGRAM, NULL, 
     2407                                           PJ_STUN_IS_DATAGRAM, &cand_id, 
    23712408                                           NULL, src_addr, src_addr_len); 
    23722409        if (status != PJ_SUCCESS) { 
Note: See TracChangeset for help on using the changeset viewer.