Changeset 5861


Ignore:
Timestamp:
Aug 16, 2018 2:56:52 AM (6 years ago)
Author:
nanang
Message:

Fix #2138:

  • Updated ICE STUN & host candidates generation to be more forgiving on errors, i.e: continue gathering candidates using any available data instead of returning error.
  • Added more logs for debugging.
Location:
pjproject/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjnath/src/pjnath/ice_strans.c

    r5833 r5861  
    518518        return status; 
    519519 
    520     /* Start STUN Binding resolution and add srflx candidate 
    521      * only if server is set 
     520    /* Start STUN Binding resolution and add srflx candidate only if server 
     521     * is set. When any error occur during STUN Binding resolution, let's 
     522     * just skip it and generate host candidates. 
    522523     */ 
    523     if (stun_cfg->server.slen) { 
     524    while (stun_cfg->server.slen) { 
    524525        pj_stun_sock_info stun_sock_info; 
    525526 
     
    539540        if (status != PJ_SUCCESS) { 
    540541            ///sess_dec_ref(ice_st); 
     542            PJ_PERROR(5,(ice_st->obj_name, status, 
     543                         "Comp %d: srflx candidate (tpid=%d) failed in " 
     544                         "pj_stun_sock_start()", 
     545                         comp->comp_id, cand->transport_id)); 
    541546            pj_log_pop_indent(); 
    542             return status; 
     547            break; 
    543548        } 
    544549 
     
    547552        if (status != PJ_SUCCESS) { 
    548553            ///sess_dec_ref(ice_st); 
     554            PJ_PERROR(5,(ice_st->obj_name, status, 
     555                         "Comp %d: srflx candidate (tpid=%d) failed in " 
     556                         "pj_stun_sock_get_info()", 
     557                         comp->comp_id, cand->transport_id)); 
    549558            pj_log_pop_indent(); 
    550             return status; 
     559            break; 
    551560        } 
    552561 
     
    568577 
    569578        pj_log_pop_indent(); 
     579 
     580        /* Not really a loop, just trying to avoid complex 'if' blocks */ 
     581        break; 
    570582    } 
    571583 
     
    575587    if (stun_cfg->max_host_cands) { 
    576588        pj_stun_sock_info stun_sock_info; 
    577         unsigned i; 
     589        unsigned i, cand_cnt = 0; 
    578590 
    579591        /* Enumerate addresses */ 
    580592        status = pj_stun_sock_get_info(comp->stun[idx].sock, &stun_sock_info); 
    581         if (status != PJ_SUCCESS) 
     593        if (status != PJ_SUCCESS) { 
     594            PJ_PERROR(4,(ice_st->obj_name, status, 
     595                         "Failed in querying STUN socket info")); 
    582596            return status; 
    583  
    584         for (i=0; i<stun_sock_info.alias_cnt && 
    585                   i<stun_cfg->max_host_cands; ++i) 
     597        } 
     598 
     599        for (i = 0; i < stun_sock_info.alias_cnt && 
     600                    cand_cnt < stun_cfg->max_host_cands; ++i) 
    586601        { 
    587602            unsigned j; 
     
    614629            } 
    615630 
    616             /* Ignore IPv6 link-local address */ 
    617             if (stun_cfg->af == pj_AF_INET6()) { 
     631            /* Ignore IPv6 link-local address, unless it is the default 
     632             * address (first alias). 
     633             */ 
     634            if (stun_cfg->af == pj_AF_INET6() && i != 0) { 
    618635                const pj_in6_addr *a = &addr->ipv6.sin6_addr; 
    619636                if (a->s6_addr[0] == 0xFE && (a->s6_addr[1] & 0xC0) == 0x80) 
     
    651668            } else { 
    652669                comp->cand_cnt+=1; 
     670                cand_cnt++; 
    653671            } 
    654672             
     
    676694    } 
    677695 
    678     return PJ_SUCCESS; 
     696    return status; 
    679697} 
    680698 
  • pjproject/trunk/pjnath/src/pjnath/stun_sock.c

    r5678 r5861  
    427427                                    stun_sock, &dns_srv_resolver_cb,  
    428428                                    &stun_sock->q); 
     429        if (status != PJ_SUCCESS) { 
     430            PJ_PERROR(4,(stun_sock->obj_name, status, 
     431                         "Failed in pj_dns_srv_resolve()")); 
     432        } 
    429433 
    430434        /* Processing will resume when the DNS SRV callback is called */ 
     
    441445 
    442446            if (status != PJ_SUCCESS) { 
     447                PJ_PERROR(4,(stun_sock->obj_name, status, 
     448                             "Failed in pj_getaddrinfo()")); 
    443449                pj_grp_lock_release(stun_sock->grp_lock); 
    444450                return status; 
     
    452458        /* Start sending Binding request */ 
    453459        status = get_mapped_addr(stun_sock); 
     460        if (status != PJ_SUCCESS) { 
     461            PJ_PERROR(4,(stun_sock->obj_name, status, 
     462                         "Failed in sending Binding request")); 
     463        } 
    454464    } 
    455465 
     
    667677        status = pj_gethostip(stun_sock->af, &def_addr); 
    668678        if (status != PJ_SUCCESS) { 
     679            PJ_PERROR(4,(stun_sock->obj_name, status, 
     680                         "Failed in getting default address for STUN info")); 
    669681            pj_grp_lock_release(stun_sock->grp_lock); 
    670682            return status; 
     
    678690                                      info->aliases); 
    679691        if (status != PJ_SUCCESS) { 
    680             pj_grp_lock_release(stun_sock->grp_lock); 
    681             return status; 
     692            /* If enumeration fails, just return the default address */ 
     693            PJ_PERROR(4,(stun_sock->obj_name, status, 
     694                         "Failed in enumerating interfaces for STUN info, " 
     695                         "returning default address only")); 
     696            info->alias_cnt = 1; 
     697            pj_sockaddr_cp(&info->aliases[0], &def_addr); 
    682698        } 
    683699 
  • pjproject/trunk/pjsip/src/pjsua-lib/pjsua_media.c

    r5843 r5861  
    928928 
    929929            /* Configure STUN server */ 
    930             if (pj_sockaddr_has_addr(&pjsua_var.stun_srv) && 
    931                 pjsua_media_acc_is_using_stun(call_med->call->acc_id)) 
     930            if (pjsua_media_acc_is_using_stun(call_med->call->acc_id) && 
     931                pj_sockaddr_has_addr(&pjsua_var.stun_srv) && 
     932                pjsua_var.stun_srv.addr.sa_family == ice_cfg.stun_tp[i].af) 
    932933            { 
    933934                ice_cfg.stun_tp[i].server = pj_str(stunip); 
Note: See TracChangeset for help on using the changeset viewer.