Re #1918: Fixed continous looping when trying to resolve STUN server due to lock handling.
Also move the unusable server to the least prioritize to be chosen on the fallback process. git-svn-id: https://svn.pjsip.org/repos/pjproject/trunk@5307 74dad513-b988-da41-8d7b-12977e46ad98
This commit is contained in:
parent
a43bfb036b
commit
6fbf7ce59b
|
@ -2048,6 +2048,10 @@ struct pj_stun_resolve_result
|
|||
*/
|
||||
pj_sockaddr addr;
|
||||
|
||||
/**
|
||||
* The index of the usable STUN server.
|
||||
*/
|
||||
unsigned index;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -435,6 +435,7 @@ struct pjsua_data
|
|||
pj_sockaddr stun_srv; /**< Resolved STUN server address */
|
||||
pj_status_t stun_status; /**< STUN server status. */
|
||||
pjsua_stun_resolve stun_res; /**< List of pending STUN resolution*/
|
||||
unsigned stun_srv_idx; /**< Resolved STUN server index */
|
||||
pj_dns_resolver *resolver; /**< DNS resolver. */
|
||||
|
||||
/* Detected NAT type */
|
||||
|
|
|
@ -1205,6 +1205,7 @@ static void stun_resolve_complete(pjsua_stun_resolve *sess)
|
|||
result.token = sess->token;
|
||||
result.status = sess->status;
|
||||
result.name = sess->srv[sess->idx];
|
||||
result.index = sess->idx;
|
||||
pj_memcpy(&result.addr, &sess->addr, sizeof(result.addr));
|
||||
sess->has_result = PJ_TRUE;
|
||||
|
||||
|
@ -1508,6 +1509,7 @@ static void internal_stun_resolve_cb(const pj_stun_resolve_result *result)
|
|||
pjsua_var.stun_status = result->status;
|
||||
if ((result->status == PJ_SUCCESS) && (pjsua_var.ua_cfg.stun_srv_cnt>0)) {
|
||||
pj_memcpy(&pjsua_var.stun_srv, &result->addr, sizeof(result->addr));
|
||||
pjsua_var.stun_srv_idx = result->index;
|
||||
|
||||
/* Perform NAT type detection if not yet */
|
||||
if (pjsua_var.nat_type == PJ_STUN_NAT_TYPE_UNKNOWN &&
|
||||
|
@ -1554,6 +1556,11 @@ pj_status_t resolve_stun_server(pj_bool_t wait)
|
|||
* result.
|
||||
*/
|
||||
if (wait) {
|
||||
pj_bool_t has_pjsua_lock = PJSUA_LOCK_IS_LOCKED();
|
||||
|
||||
if (has_pjsua_lock)
|
||||
PJSUA_UNLOCK();
|
||||
|
||||
while (pjsua_var.stun_status == PJ_EPENDING) {
|
||||
/* If there is no worker thread or
|
||||
* the function is called from the only worker thread,
|
||||
|
@ -1568,6 +1575,8 @@ pj_status_t resolve_stun_server(pj_bool_t wait)
|
|||
pj_thread_sleep(10);
|
||||
}
|
||||
}
|
||||
if (has_pjsua_lock)
|
||||
PJSUA_LOCK();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -393,11 +393,37 @@ static pj_status_t create_rtp_rtcp_sock(pjsua_call_media *call_med,
|
|||
if (status != PJ_SUCCESS && pjsua_var.ua_cfg.stun_srv_cnt > 1 &&
|
||||
((acc->cfg.media_stun_use & PJSUA_STUN_RETRY_ON_FAILURE)!=0))
|
||||
{
|
||||
PJ_LOG(4,(THIS_FILE, "Failed to get STUN mapped address, "
|
||||
"retrying other STUN servers"));
|
||||
pj_str_t srv =
|
||||
pjsua_var.ua_cfg.stun_srv[pjsua_var.stun_srv_idx];
|
||||
|
||||
PJ_LOG(4,(THIS_FILE, "Failed to get STUN mapped address, "
|
||||
"retrying other STUN servers"));
|
||||
|
||||
if (pjsua_var.stun_srv_idx < pjsua_var.ua_cfg.stun_srv_cnt-1) {
|
||||
PJSUA_LOCK();
|
||||
/* Move the unusable STUN server to the last position
|
||||
* as the least prioritize.
|
||||
*/
|
||||
pj_array_erase(pjsua_var.ua_cfg.stun_srv,
|
||||
sizeof(pj_str_t),
|
||||
pjsua_var.ua_cfg.stun_srv_cnt,
|
||||
pjsua_var.stun_srv_idx);
|
||||
|
||||
pj_array_insert(pjsua_var.ua_cfg.stun_srv,
|
||||
sizeof(pj_str_t),
|
||||
pjsua_var.ua_cfg.stun_srv_cnt-1,
|
||||
pjsua_var.ua_cfg.stun_srv_cnt-1,
|
||||
&srv);
|
||||
|
||||
PJSUA_UNLOCK();
|
||||
}
|
||||
status=pjsua_update_stun_servers(pjsua_var.ua_cfg.stun_srv_cnt,
|
||||
pjsua_var.ua_cfg.stun_srv,
|
||||
PJ_TRUE);
|
||||
PJ_FALSE);
|
||||
|
||||
if (status == PJ_SUCCESS)
|
||||
status = resolve_stun_server(PJ_TRUE);
|
||||
|
||||
if (status == PJ_SUCCESS) {
|
||||
if (pjsua_var.stun_srv.addr.sa_family != 0) {
|
||||
pj_ansi_strcpy(ip_addr,
|
||||
|
|
Loading…
Reference in New Issue