diff --git a/contrib/src/pjproject/fix_turn_fallback.patch b/contrib/src/pjproject/fix_turn_fallback.patch index 2a54ee15cd243969f3b1621c9a50e9871263c469..50229dd01ccf7d8bfcd016acfa967cab7b606a0c 100644 --- a/contrib/src/pjproject/fix_turn_fallback.patch +++ b/contrib/src/pjproject/fix_turn_fallback.patch @@ -13,27 +13,41 @@ + continue; + /* Gather remote addresses for this component */ -@@ -2013,4 +2016,21 @@ - if (comp->ice_st->state < PJ_ICE_STRANS_STATE_READY) { -- sess_fail(comp->ice_st, PJ_ICE_STRANS_OP_INIT, -- "TURN allocation failed", info.last_status); -+ PJ_LOG(4,(comp->ice_st->obj_name, -+ "TURN allocation failed, disable the associated candidate")); -+ pj_ice_sess_cand *cand = NULL; -+ unsigned i; -+ /* Wait until initialization completes */ -+ pj_grp_lock_acquire(comp->ice_st->grp_lock); -+ /* Find relayed candidate in the component */ -+ for (i=0; i<comp->cand_cnt; ++i) { -+ if (comp->cand_list[i].type == PJ_ICE_CAND_TYPE_RELAYED && -+ comp->cand_list[i].transport_id == data->transport_id) { -+ cand = &comp->cand_list[i]; -+ break; -+ } -+ } -+ pj_grp_lock_release(comp->ice_st->grp_lock); -+ pj_assert(cand != NULL); -+ // Make session init succeed but disable this TURN server to be used -+ cand->status = PJNATH_ESTUNTIMEDOUT; -+ sess_init_update(comp->ice_st); - } else if (comp->turn[tp_idx].err_cnt > 1) { +@@ -1995,4 +1998,37 @@ + sess_init_update(comp->ice_st); + ++ } else if ((old_state == PJ_TURN_STATE_RESOLVING || old_state == PJ_TURN_STATE_ALLOCATING) && ++ new_state >= PJ_TURN_STATE_DEALLOCATING) ++ { ++ pj_ice_sess_cand *cand = NULL; ++ unsigned i; ++ ++ /* DNS resolution has failed! */ ++ ++comp->turn[tp_idx].err_cnt; ++ ++ /* Unregister ourself from the TURN relay */ ++ pj_turn_sock_set_user_data(turn_sock, NULL); ++ comp->turn[tp_idx].sock = NULL; ++ ++ /* Wait until initialization completes */ ++ pj_grp_lock_acquire(comp->ice_st->grp_lock); ++ ++ /* Find relayed candidate in the component */ ++ for (i=0; i<comp->cand_cnt; ++i) { ++ if (comp->cand_list[i].type == PJ_ICE_CAND_TYPE_RELAYED && ++ comp->cand_list[i].transport_id == data->transport_id) ++ { ++ cand = &comp->cand_list[i]; ++ break; ++ } ++ } ++ pj_assert(cand != NULL); ++ ++ pj_grp_lock_release(comp->ice_st->grp_lock); ++ ++ cand->status = old_state == PJ_TURN_STATE_RESOLVING ? PJ_ERESOLVE : PJ_EINVALIDOP; ++ ++ sess_init_update(comp->ice_st); ++ + } else if (new_state >= PJ_TURN_STATE_DEALLOCATING) { + pj_turn_session_info info;