Changeset 1114 for pjproject/trunk/pjnath/src/pjnath/ice_strans.c
- Timestamp:
- Mar 29, 2007 9:54:21 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjnath/src/pjnath/ice_strans.c
r1111 r1114 61 61 const pj_stun_msg *response); 62 62 63 /* Keep-alive timer */ 64 static void start_ka_timer(pj_ice_strans *ice_st); 65 static void stop_ka_timer(pj_ice_strans *ice_st); 66 63 67 /* Utility: print error */ 64 68 #if PJ_LOG_MAX_LEVEL >= 3 … … 126 130 } 127 131 132 /* Kill keep-alive timer, if any */ 133 stop_ka_timer(ice_st); 134 128 135 /* Destroy ICE if we have ICE */ 129 136 if (ice_st->ice) { … … 197 204 return PJ_SUCCESS; 198 205 } 199 200 206 201 207 /* Add new candidate */ … … 506 512 507 513 514 /* STUN keep-alive timer callback */ 515 static void ka_timer_cb(pj_timer_heap_t *th, pj_timer_entry *te) 516 { 517 pj_ice_strans *ice_st = (pj_ice_strans*)te->user_data; 518 unsigned i; 519 pj_status_t status; 520 521 PJ_UNUSED_ARG(th); 522 523 ice_st->ka_timer.id = PJ_FALSE; 524 525 for (i=0; i<ice_st->comp_cnt; ++i) { 526 pj_ice_strans_comp *comp = ice_st->comp[i]; 527 pj_stun_tx_data *tdata; 528 unsigned j; 529 530 /* Does this component have STUN server reflexive candidate? */ 531 for (j=0; j<comp->cand_cnt; ++j) { 532 if (comp->cand_list[j].type == PJ_ICE_CAND_TYPE_SRFLX) 533 break; 534 } 535 if (j == comp->cand_cnt) 536 continue; 537 538 /* Create STUN binding request */ 539 status = pj_stun_session_create_req(comp->stun_sess, 540 PJ_STUN_BINDING_REQUEST, &tdata); 541 if (status != PJ_SUCCESS) 542 continue; 543 544 /* tdata->user_data is NULL for keep-alive */ 545 tdata->user_data = NULL; 546 547 /* Send STUN binding request */ 548 PJ_LOG(5,(ice_st->obj_name, "Sending STUN keep-alive")); 549 status = pj_stun_session_send_msg(comp->stun_sess, PJ_FALSE, 550 &ice_st->stun_srv, 551 sizeof(pj_sockaddr_in), tdata); 552 } 553 554 /* Start next timer */ 555 start_ka_timer(ice_st); 556 } 557 558 /* Start STUN keep-alive timer */ 559 static void start_ka_timer(pj_ice_strans *ice_st) 560 { 561 pj_time_val delay; 562 563 /* Skip if timer is already running */ 564 if (ice_st->ka_timer.id != PJ_FALSE) 565 return; 566 567 delay.sec = 20; 568 delay.msec = 0; 569 570 ice_st->ka_timer.cb = &ka_timer_cb; 571 ice_st->ka_timer.user_data = ice_st; 572 573 if (pj_timer_heap_schedule(ice_st->stun_cfg.timer_heap, 574 &ice_st->ka_timer, &delay)==PJ_SUCCESS) 575 { 576 ice_st->ka_timer.id = PJ_TRUE; 577 } 578 } 579 580 581 /* Stop STUN keep-alive timer */ 582 static void stop_ka_timer(pj_ice_strans *ice_st) 583 { 584 /* Skip if timer is already stop */ 585 if (ice_st->ka_timer.id == PJ_FALSE) 586 return; 587 588 pj_timer_heap_cancel(ice_st->stun_cfg.timer_heap, &ice_st->ka_timer); 589 ice_st->ka_timer.id = PJ_FALSE; 590 } 591 508 592 509 593 /* … … 831 915 } 832 916 833 #if 1 834 PJ_UNUSED_ARG(pkt_size); 835 PJ_UNUSED_ARG(status); 836 837 /* Otherwise return error */ 838 return PJNATH_EICEINPROGRESS; 839 #else 840 /* Otherwise send direcly with the socket */ 917 /* Otherwise send direcly with the socket. This is for compatibility 918 * with remote that doesn't support ICE. 919 */ 841 920 pkt_size = data_len; 842 921 status = pj_ioqueue_sendto(comp->key, &comp->write_op, … … 845 924 846 925 return (status==PJ_SUCCESS||status==PJ_EPENDING) ? PJ_SUCCESS : status; 847 #endif848 926 } 849 927 … … 943 1021 comp = (pj_ice_strans_comp*) pj_stun_session_get_user_data(sess); 944 1022 cand = (pj_ice_strans_cand*) tdata->user_data; 1023 1024 if (cand == NULL) { 1025 /* This is keep-alive */ 1026 return; 1027 } 945 1028 946 1029 /* Decrement pending count for this component */ … … 981 1064 comp->default_cand = (cand - comp->cand_list); 982 1065 comp->last_status = PJ_SUCCESS; 983 } 984 1066 1067 /* We have STUN, so we must start the keep-alive timer */ 1068 start_ka_timer(comp->ice_st); 1069 } 1070
Note: See TracChangeset
for help on using the changeset viewer.