Changeset 6040
- Timestamp:
- Jul 18, 2019 9:51:00 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjnath/src/pjnath/ice_strans.c
r5983 r6040 313 313 static pj_status_t add_update_turn(pj_ice_strans *ice_st, 314 314 pj_ice_strans_comp *comp, 315 unsigned idx) 315 unsigned idx, 316 unsigned max_cand_cnt) 316 317 { 317 318 pj_ice_sess_cand *cand = NULL; … … 322 323 sock_user_data *data; 323 324 unsigned i; 325 pj_bool_t new_cand = PJ_FALSE; 324 326 pj_uint8_t tp_id; 325 327 pj_status_t status; … … 384 386 /* Add relayed candidate with pending status if there's no existing one */ 385 387 if (cand == NULL) { 388 PJ_ASSERT_RETURN(max_cand_cnt > 0, PJ_ETOOSMALL); 389 386 390 cand = &comp->cand_list[comp->cand_cnt]; 387 391 cand->type = PJ_ICE_CAND_TYPE_RELAYED; … … 390 394 cand->transport_id = tp_id; 391 395 cand->comp_id = (pj_uint8_t) comp->comp_id; 396 new_cand = PJ_TRUE; 392 397 } 393 398 … … 421 426 } 422 427 423 /* Commit the relayed candidate. */ 424 comp->cand_cnt++; 428 if (new_cand) { 429 /* Commit the relayed candidate. */ 430 comp->cand_cnt++; 431 } 425 432 426 433 PJ_LOG(4,(ice_st->obj_name, … … 460 467 static pj_status_t add_stun_and_host(pj_ice_strans *ice_st, 461 468 pj_ice_strans_comp *comp, 462 unsigned idx) 469 unsigned idx, 470 unsigned max_cand_cnt) 463 471 { 464 472 pj_ice_sess_cand *cand; … … 469 477 sock_user_data *data; 470 478 pj_status_t status; 479 480 PJ_ASSERT_RETURN(max_cand_cnt > 0, PJ_ETOOSMALL); 471 481 472 482 /* Check if STUN transport or host candidate is configured */ … … 566 576 cand->type, &cand->base_addr); 567 577 comp->cand_cnt++; 578 max_cand_cnt--; 568 579 569 580 /* Set default candidate to srflx */ … … 605 616 const pj_sockaddr *addr = &stun_sock_info.aliases[i]; 606 617 607 /* Leave one candidate for relay */ 608 if (comp->cand_cnt >= PJ_ICE_ST_MAX_CAND-1) { 618 if (max_cand_cnt==0) { 609 619 PJ_LOG(4,(ice_st->obj_name, "Too many host candidates")); 610 620 break; … … 669 679 comp->cand_cnt+=1; 670 680 cand_cnt++; 681 max_cand_cnt--; 671 682 } 672 683 … … 726 737 /* Create STUN transport if configured */ 727 738 for (i=0; i<ice_st->cfg.stun_tp_cnt; ++i) { 728 status = add_stun_and_host(ice_st, comp, i); 739 unsigned max_cand_cnt = PJ_ICE_ST_MAX_CAND - comp->cand_cnt - 740 ice_st->cfg.turn_tp_cnt; 741 742 status = PJ_ETOOSMALL; 743 744 if ((max_cand_cnt > 0) && (max_cand_cnt <= PJ_ICE_ST_MAX_CAND)) 745 status = add_stun_and_host(ice_st, comp, i, max_cand_cnt); 746 729 747 if (status != PJ_SUCCESS) { 730 748 PJ_PERROR(3,(ice_st->obj_name, status, … … 737 755 /* Create TURN relay if configured. */ 738 756 for (i=0; i<ice_st->cfg.turn_tp_cnt; ++i) { 739 status = add_update_turn(ice_st, comp, i); 757 unsigned max_cand_cnt = PJ_ICE_ST_MAX_CAND - comp->cand_cnt; 758 759 status = PJ_ETOOSMALL; 760 761 if ((max_cand_cnt > 0) && (max_cand_cnt <= PJ_ICE_ST_MAX_CAND)) 762 status = add_update_turn(ice_st, comp, i, max_cand_cnt); 763 740 764 if (status != PJ_SUCCESS) { 741 765 PJ_PERROR(3,(ice_st->obj_name, status, 742 766 "Failed creating TURN transport #%d for comp %d", 743 767 i, comp->comp_id)); 768 744 769 //return status; 770 } else if (max_cand_cnt > 0) { 771 max_cand_cnt = PJ_ICE_ST_MAX_CAND - comp->cand_cnt; 745 772 } 746 773 } … … 2245 2272 "Comp %d: TURN allocation failed, retrying", 2246 2273 comp->comp_id)); 2247 add_update_turn(comp->ice_st, comp, tp_idx); 2274 add_update_turn(comp->ice_st, comp, tp_idx, 2275 PJ_ICE_ST_MAX_CAND - comp->cand_cnt); 2248 2276 } 2249 2277 }
Note: See TracChangeset
for help on using the changeset viewer.