- Timestamp:
- Apr 14, 2008 1:48:39 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/branches/projects/ice-turn07/pjnath/src/pjnath/ice_session.c
r1913 r1926 102 102 103 103 104 /* This is the data that will be attached as token to outgoing 105 * STUN messages. 106 */ 107 struct 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 104 125 /* Forward declarations */ 105 126 static void destroy_ice(pj_ice_sess *ice, … … 1346 1367 } 1347 1368 1348 1349 /* This is the data that will be attached as user data to outgoing1350 * STUN requests, and it will be given back when we receive completion1351 * status of the request.1352 */1353 struct req_data1354 {1355 pj_ice_sess *ice;1356 pj_ice_sess_checklist *clist;1357 unsigned ckid;1358 };1359 1360 1361 1369 /* Perform check on the specified candidate pair */ 1362 1370 static pj_status_t perform_check(pj_ice_sess *ice, … … 1365 1373 { 1366 1374 pj_ice_sess_comp *comp; 1367 struct req_data *rd;1375 struct msg_data *msg_data; 1368 1376 pj_ice_sess_check *check; 1369 1377 const pj_ice_sess_cand *lcand; … … 1393 1401 * completes and on_stun_request_complete() callback is called. 1394 1402 */ 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; 1399 1408 1400 1409 /* Add PRIORITY */ … … 1428 1437 1429 1438 /* 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, 1431 1440 PJ_TRUE, &rcand->addr, 1432 1441 sizeof(pj_sockaddr_in), check->tdata); … … 1656 1665 stun_data *sd = (stun_data*) pj_stun_session_get_user_data(sess); 1657 1666 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); 1664 1682 } 1665 1683 … … 1674 1692 unsigned src_addr_len) 1675 1693 { 1676 struct req_data *rd = (struct req_data*) token;1694 struct msg_data *msg_data = (struct msg_data*) token; 1677 1695 pj_ice_sess *ice; 1678 1696 pj_ice_sess_check *check, *new_check; … … 1685 1703 PJ_UNUSED_ARG(src_addr_len); 1686 1704 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 1690 1711 1691 1712 /* Mark STUN transaction as complete */ … … 1740 1761 LOG4((ice->obj_name, "Resending check because of role conflict")); 1741 1762 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); 1743 1764 pj_mutex_unlock(ice->mutex); 1744 1765 return; … … 1919 1940 { 1920 1941 stun_data *sd; 1942 unsigned *param_cand_id; 1921 1943 const pj_stun_msg *msg = rdata->msg; 1944 struct msg_data *msg_data; 1922 1945 pj_ice_sess *ice; 1923 1946 pj_stun_priority_attr *prio_attr; … … 1930 1953 PJ_UNUSED_ARG(pkt); 1931 1954 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; 1933 1965 1934 1966 /* Reject any requests except Binding request */ … … 2035 2067 } 2036 2068 2069 /* Add XOR-MAPPED-ADDRESS attribute */ 2037 2070 status = pj_stun_msg_add_sockaddr_attr(tdata->pool, tdata->msg, 2038 2071 PJ_STUN_ATTR_XOR_MAPPED_ADDR, 2039 2072 PJ_TRUE, src_addr, src_addr_len); 2040 2073 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, 2042 2081 src_addr, src_addr_len, tdata); 2043 2082 … … 2091 2130 pj_ice_sess_cand *rcand; 2092 2131 unsigned i; 2093 pj_bool_t is_relayed;2094 2132 2095 2133 comp = find_comp(ice, rcheck->comp_id); … … 2171 2209 * Create candidate pair for this request. 2172 2210 */ 2173 /* First check if the source address is the source address of the2174 * 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;2178 2211 2179 2212 /* … … 2310 2343 pj_status_t status = PJ_SUCCESS; 2311 2344 pj_ice_sess_comp *comp; 2345 unsigned cand_id; 2312 2346 2313 2347 PJ_ASSERT_RETURN(ice && comp_id, PJ_EINVAL); … … 2333 2367 } 2334 2368 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, 2336 2372 &comp->valid_check->rcand->addr, 2337 2373 sizeof(pj_sockaddr_in)); … … 2345 2381 PJ_DEF(pj_status_t) pj_ice_sess_on_rx_pkt(pj_ice_sess *ice, 2346 2382 unsigned comp_id, 2383 unsigned cand_id, 2347 2384 void *pkt, 2348 2385 pj_size_t pkt_size, … … 2368 2405 if (stun_status == PJ_SUCCESS) { 2369 2406 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, 2371 2408 NULL, src_addr, src_addr_len); 2372 2409 if (status != PJ_SUCCESS) {
Note: See TracChangeset
for help on using the changeset viewer.