Changeset 1140 for pjproject/trunk/pjnath/src/pjnath/ice_strans.c
- Timestamp:
- Apr 3, 2007 6:01:27 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjnath/src/pjnath/ice_strans.c
r1126 r1140 24 24 #include <pj/log.h> 25 25 #include <pj/pool.h> 26 #include <pj/rand.h> 26 27 #include <pj/string.h> 28 29 30 #if 0 31 # define TRACE_PKT(expr) PJ_LOG(5,expr) 32 #else 33 # define TRACE_PKT(expr) 34 #endif 27 35 28 36 … … 31 39 static void on_ice_complete(pj_ice_sess *ice, pj_status_t status); 32 40 static pj_status_t ice_tx_pkt(pj_ice_sess *ice, 33 unsigned comp_id, unsigned cand_id,41 unsigned comp_id, 34 42 const void *pkt, pj_size_t size, 35 43 const pj_sockaddr_t *dst_addr, … … 85 93 86 94 if (name == NULL) 87 name = "ic est%p";95 name = "icstr%p"; 88 96 89 97 pool = pj_pool_create(stun_cfg->pf, name, 4000, 4000, NULL); … … 243 251 pj_ice_strans_comp *comp; 244 252 int retry, addr_len; 253 struct { 254 pj_uint32_t a1, a2, a3; 255 } tsx_id; 245 256 pj_status_t status; 246 257 … … 251 262 comp->sock = PJ_INVALID_SOCKET; 252 263 comp->last_status = PJ_SUCCESS; 264 265 /* Create transaction ID for STUN keep alives */ 266 tsx_id.a1 = 0; 267 tsx_id.a2 = comp_id; 268 tsx_id.a3 = (pj_uint32_t) ice_st; 269 pj_memcpy(comp->ka_tsx_id, &tsx_id, sizeof(comp->ka_tsx_id)); 253 270 254 271 /* Create socket */ … … 438 455 * The process below is just a workaround. 439 456 */ 440 if (ice_st->ice) { 441 PJ_TODO(DISTINGUISH_BETWEEN_LOCAL_AND_RELAY); 442 status = pj_ice_sess_on_rx_pkt(ice_st->ice, comp->comp_id, 443 comp->cand_list[0].ice_cand_id, 444 comp->pkt, bytes_read, 445 &comp->src_addr, comp->src_addr_len); 446 } else if (comp->stun_sess) { 447 status = pj_stun_msg_check(comp->pkt, bytes_read, 448 PJ_STUN_IS_DATAGRAM); 449 if (status == PJ_SUCCESS) { 457 status = pj_stun_msg_check(comp->pkt, bytes_read, 458 PJ_STUN_IS_DATAGRAM); 459 460 if (status == PJ_SUCCESS) { 461 if (ice_st->ice==NULL || 462 pj_memcmp(comp->pkt+8, comp->ka_tsx_id, 12) == 0) 463 { 450 464 status = pj_stun_session_on_rx_pkt(comp->stun_sess, comp->pkt, 451 465 bytes_read, … … 454 468 comp->src_addr_len); 455 469 } else { 456 (*ice_st->cb.on_rx_data)(ice_st, comp->comp_id, 457 comp->pkt, bytes_read, 458 &comp->src_addr, comp->src_addr_len); 459 470 PJ_TODO(DISTINGUISH_BETWEEN_LOCAL_AND_RELAY); 471 472 TRACE_PKT((comp->ice_st->obj_name, 473 "Component %d RX packet from %s:%d", 474 comp->comp_id, 475 pj_inet_ntoa(comp->src_addr.ipv4.sin_addr), 476 (int)pj_ntohs(comp->src_addr.ipv4.sin_port))); 477 478 status = pj_ice_sess_on_rx_pkt(ice_st->ice, comp->comp_id, 479 comp->pkt, bytes_read, 480 &comp->src_addr, 481 comp->src_addr_len); 460 482 } 461 483 } else { … … 528 550 /* Create STUN binding request */ 529 551 status = pj_stun_session_create_req(comp->stun_sess, 530 PJ_STUN_BINDING_REQUEST, &tdata); 552 PJ_STUN_BINDING_REQUEST, 553 comp->ka_tsx_id, &tdata); 531 554 if (status != PJ_SUCCESS) 532 555 continue; … … 555 578 return; 556 579 557 delay.sec = 20; 558 delay.msec = 0; 580 delay.sec = PJ_ICE_ST_KEEP_ALIVE_MIN; 581 delay.msec = pj_rand() % (PJ_ICE_ST_KEEP_ALIVE_MAX_RAND * 1000); 582 pj_time_val_normalize(&delay); 559 583 560 584 ice_st->ka_timer.cb = &ka_timer_cb; … … 617 641 /* Create STUN binding request */ 618 642 status = pj_stun_session_create_req(comp->stun_sess, 619 PJ_STUN_BINDING_REQUEST, &tdata); 643 PJ_STUN_BINDING_REQUEST, 644 comp->ka_tsx_id, 645 &tdata); 620 646 if (status != PJ_SUCCESS) 621 647 return status; … … 945 971 */ 946 972 static pj_status_t ice_tx_pkt(pj_ice_sess *ice, 947 unsigned comp_id, unsigned cand_id,973 unsigned comp_id, 948 974 const void *pkt, pj_size_t size, 949 975 const pj_sockaddr_t *dst_addr, … … 959 985 PJ_ASSERT_RETURN(comp_id && comp_id <= ice_st->comp_cnt, PJ_EINVAL); 960 986 comp = ice_st->comp[comp_id-1]; 987 988 TRACE_PKT((comp->ice_st->obj_name, 989 "Component %d TX packet to %s:%d", 990 comp_id, 991 pj_inet_ntoa(((pj_sockaddr_in*)dst_addr)->sin_addr), 992 (int)pj_ntohs(((pj_sockaddr_in*)dst_addr)->sin_port))); 961 993 962 994 pkt_size = size; … … 1027 1059 if (cand == NULL) { 1028 1060 /* This is keep-alive */ 1061 if (status != PJ_SUCCESS) { 1062 ice_st_perror(comp->ice_st, "STUN keep-alive request failed", 1063 status); 1064 } 1029 1065 return; 1030 1066 }
Note: See TracChangeset
for help on using the changeset viewer.