Ignore:
Timestamp:
Apr 5, 2007 10:28:01 PM (17 years ago)
Author:
bennylp
Message:

Respond to early check with proper credential

File:
1 edited

Legend:

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

    r1152 r1154  
    6161static const char *role_names[] =  
    6262{ 
     63    "Unknown", 
    6364    "Controlled", 
    6465    "Controlling" 
     
    851852 * is sorted. 
    852853 */ 
    853 static void prune_checklist(pj_ice_sess *ice, pj_ice_sess_checklist *clist) 
     854static pj_status_t prune_checklist(pj_ice_sess *ice,  
     855                                   pj_ice_sess_checklist *clist) 
    854856{ 
    855857    unsigned i; 
     
    865867     * candidate pairs, called the check list for that media stream.     
    866868     */ 
     869    /* First replace SRFLX candidates with their base */ 
     870    for (i=0; i<clist->count; ++i) { 
     871        pj_ice_sess_cand *srflx = clist->checks[i].lcand; 
     872 
     873        if (clist->checks[i].lcand->type == PJ_ICE_CAND_TYPE_SRFLX) { 
     874            /* Find the base for this candidate */ 
     875            unsigned j; 
     876            for (j=0; j<ice->lcand_cnt; ++j) { 
     877                pj_ice_sess_cand *host = &ice->lcand[j]; 
     878 
     879                if (host->type != PJ_ICE_CAND_TYPE_HOST) 
     880                    continue; 
     881 
     882                if (sockaddr_cmp(&srflx->base_addr, &host->addr) == 0) { 
     883                    /* Replace this SRFLX with its BASE */ 
     884                    clist->checks[i].lcand = host; 
     885                    break; 
     886                } 
     887            } 
     888 
     889            if (j==ice->lcand_cnt) { 
     890                /* Host candidate not found this this srflx! */ 
     891                LOG4((ice->obj_name,  
     892                      "Base candidate %s:%d not found for srflx candidate %d", 
     893                      pj_inet_ntoa(srflx->base_addr.ipv4.sin_addr), 
     894                      pj_ntohs(srflx->base_addr.ipv4.sin_port), 
     895                      GET_LCAND_ID(clist->checks[i].lcand))); 
     896                return PJNATH_EICENOHOSTCAND; 
     897            } 
     898        } 
     899    } 
     900 
     901    /* Next remove a pair if its local and remote candidates are identical 
     902     * to the local and remote candidates of a pair higher up on the priority 
     903     * list 
     904     */ 
    867905    for (i=0; i<clist->count; ++i) { 
    868906        pj_ice_sess_cand *licand = clist->checks[i].lcand; 
    869907        pj_ice_sess_cand *ricand = clist->checks[i].rcand; 
    870         const pj_sockaddr *liaddr; 
    871908        unsigned j; 
    872  
    873         if (licand->type == PJ_ICE_CAND_TYPE_SRFLX) 
    874             liaddr = &licand->base_addr; 
    875         else 
    876             liaddr = &licand->addr; 
    877909 
    878910        for (j=i+1; j<clist->count;) { 
    879911            pj_ice_sess_cand *ljcand = clist->checks[j].lcand; 
    880912            pj_ice_sess_cand *rjcand = clist->checks[j].rcand; 
    881             const pj_sockaddr *ljaddr; 
    882  
    883             if (ljcand->type == PJ_ICE_CAND_TYPE_SRFLX) 
    884                 ljaddr = &ljcand->base_addr; 
    885             else 
    886                 ljaddr = &ljcand->addr; 
    887  
    888             if (ricand == rjcand &&  
    889                 sockaddr_cmp(liaddr, ljaddr) == SOCKADDR_EQUAL) 
    890             { 
     913 
     914            if ((licand == ljcand) && (ricand == rjcand)) { 
    891915                /* Found duplicate, remove it */ 
    892916                char buf[CHECK_NAME_LEN]; 
     
    905929        } 
    906930    } 
     931 
     932    return PJ_SUCCESS; 
    907933} 
    908934 
     
    11251151    timer_data *td; 
    11261152    unsigned i, j; 
     1153    pj_status_t status; 
    11271154 
    11281155    PJ_ASSERT_RETURN(ice && rem_ufrag && rem_passwd && rcand_cnt && rcand, 
     
    11751202            pj_ice_sess_check *chk = &clist->checks[clist->count]; 
    11761203 
    1177             if (clist->count > PJ_ICE_MAX_CHECKS) { 
     1204            if (clist->count >= PJ_ICE_MAX_CHECKS) { 
    11781205                pj_mutex_unlock(ice->mutex); 
    11791206                return PJ_ETOOMANY; 
     
    11841211             * and have the same IP address version.  
    11851212             */ 
    1186             if (lcand->comp_id != rcand->comp_id || 
    1187                 lcand->addr.addr.sa_family != rcand->addr.addr.sa_family) 
     1213            if ((lcand->comp_id != rcand->comp_id) || 
     1214                (lcand->addr.addr.sa_family != rcand->addr.addr.sa_family)) 
    11881215            { 
    11891216                continue; 
     
    12051232 
    12061233    /* Prune the checklist */ 
    1207     prune_checklist(ice, clist); 
     1234    status = prune_checklist(ice, clist); 
     1235    if (status != PJ_SUCCESS) { 
     1236        pj_mutex_unlock(ice->mutex); 
     1237        return status; 
     1238    } 
    12081239 
    12091240    /* Init timer entry in the checklist. Initially the timer ID is FALSE 
     
    14661497    /* Pickup the first pair for component 1. */ 
    14671498    for (i=0; i<clist->count; ++i) { 
    1468         if (clist->checks[0].lcand->comp_id == 1) 
     1499        if (clist->checks[i].lcand->comp_id == 1) 
    14691500            break; 
    14701501    } 
     
    18871918    } 
    18881919 
     1920    /* Handle the case when request comes before answer is received. 
     1921     * We need to put credential in the response, and since we haven't 
     1922     * got the response, copy the username from the request. 
     1923     */ 
     1924    if (ice->rcand_cnt == 0) { 
     1925        pj_stun_string_attr *uname_attr; 
     1926 
     1927        uname_attr = (pj_stun_string_attr*) 
     1928                     pj_stun_msg_find_attr(msg, PJ_STUN_ATTR_USERNAME, 0); 
     1929        pj_assert(uname_attr != NULL); 
     1930        pj_strdup(ice->pool, &ice->rx_uname, &uname_attr->value); 
     1931    } 
    18891932 
    18901933    /*  
     
    20902133             */ 
    20912134            pj_bool_t complete; 
     2135            unsigned j; 
     2136 
     2137            /* If this check is nominated, scan the valid_list for the 
     2138             * same check and update the nominated flag. A controlled  
     2139             * agent might have finished the check earlier. 
     2140             */ 
     2141            if (rcheck->use_candidate) { 
     2142                for (j=0; j<ice->valid_list.count; ++j) { 
     2143                    pj_ice_sess_check *vc = &ice->valid_list.checks[j]; 
     2144                    if (vc->lcand == c->lcand && vc->rcand == c->rcand) { 
     2145                        vc->nominated = PJ_TRUE; 
     2146                    } 
     2147                } 
     2148            } 
    20922149 
    20932150            LOG5((ice->obj_name, "Triggered check for check %d not performed " 
     
    22082265                                           PJ_STUN_IS_DATAGRAM, 
    22092266                                           NULL, src_addr, src_addr_len); 
     2267        if (status != PJ_SUCCESS) { 
     2268            char errmsg[PJ_ERR_MSG_SIZE]; 
     2269            pj_strerror(status, errmsg, sizeof(errmsg)); 
     2270            LOG4((ice->obj_name, "Error processing incoming message: %s", 
     2271                  errmsg)); 
     2272        } 
    22102273    } else { 
    22112274        (*ice->cb.on_rx_data)(ice, comp_id, pkt, pkt_size,  
Note: See TracChangeset for help on using the changeset viewer.