Changeset 2719


Ignore:
Timestamp:
May 20, 2009 5:26:03 PM (15 years ago)
Author:
bennylp
Message:

Bug in ICE (related to ticket #851, but also applies to old code): wrong local candidate selected as the nominated/valid pair, causing us to display wrong default transport address in SDP

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/branches/projects/sipit24/pjnath/src/pjnath/ice_session.c

    r2717 r2719  
    6666}; 
    6767 
    68 typedef enum timer_type 
     68enum timer_type 
    6969{ 
    7070    TIMER_NONE,                 /**< Timer not active                   */ 
     
    10991099{ 
    11001100    pj_ice_sess *ice = (pj_ice_sess*) te->user_data; 
    1101     enum timer_time type = (enum timer_type)te->id; 
     1101    enum timer_type type = (enum timer_type)te->id; 
    11021102 
    11031103    PJ_UNUSED_ARG(th); 
     
    11301130        ice_keep_alive(ice, PJ_TRUE); 
    11311131        break; 
     1132    case TIMER_NONE: 
     1133        /* Nothing to do, just to get rid of gcc warning */ 
     1134        break; 
    11321135    } 
    11331136} 
     
    12261229} 
    12271230 
     1231/* Update valid check and nominated check for the candidate */ 
     1232static void update_comp_check(pj_ice_sess *ice, unsigned comp_id,  
     1233                              pj_ice_sess_check *check) 
     1234{ 
     1235    pj_ice_sess_comp *comp; 
     1236 
     1237    comp = find_comp(ice, comp_id); 
     1238    if (comp->valid_check == NULL) { 
     1239        comp->valid_check = check; 
     1240    } else { 
     1241        if (CMP_CHECK_PRIO(comp->valid_check, check) < 0) 
     1242            comp->valid_check = check; 
     1243    } 
     1244 
     1245    if (check->nominated) { 
     1246        /* Update the nominated check for the component */ 
     1247        if (comp->nominated_check == NULL) { 
     1248            comp->nominated_check = check; 
     1249        } else { 
     1250            if (CMP_CHECK_PRIO(comp->nominated_check, check) < 0) 
     1251                comp->nominated_check = check; 
     1252        } 
     1253    } 
     1254} 
    12281255 
    12291256/* This function is called when one check completes */ 
     
    12591286                check_set_state(ice, c, PJ_ICE_SESS_CHECK_STATE_WAITING, 0); 
    12601287            } 
    1261         } 
    1262  
    1263         /* Update valid check */ 
    1264         if (comp->valid_check == NULL) { 
    1265             comp->valid_check = check; 
    1266         } else { 
    1267             if (CMP_CHECK_PRIO(comp->valid_check, check) < 0) 
    1268                 comp->valid_check = check; 
    12691288        } 
    12701289 
     
    13341353            } 
    13351354        } 
    1336  
    1337         /* Update the nominated check for the component */ 
    1338         if (comp->nominated_check == NULL) { 
    1339             comp->nominated_check = check; 
    1340         } else { 
    1341             if (CMP_CHECK_PRIO(comp->nominated_check, check) < 0) 
    1342                 comp->nominated_check = check; 
    1343         } 
    13441355    } 
    13451356 
     
    18641875     */ 
    18651876    for (i=0; i<ice->comp_cnt; ++i) { 
     1877        unsigned j; 
     1878        const pj_ice_sess_check *vc = ice->comp[i].valid_check; 
     1879 
    18661880        pj_assert(ice->comp[i].nominated_check == NULL); 
    1867         pj_assert(ice->comp[i].valid_check->err_code == PJ_SUCCESS); 
    1868  
    1869         ice->comp[i].valid_check->state = PJ_ICE_SESS_CHECK_STATE_FROZEN; 
    1870         check_set_state(ice, ice->comp[i].valid_check,  
    1871                         PJ_ICE_SESS_CHECK_STATE_WAITING, PJ_SUCCESS); 
     1881        pj_assert(vc->err_code == PJ_SUCCESS); 
     1882 
     1883        for (j=0; j<ice->clist.count; ++j) { 
     1884            pj_ice_sess_check *c = &ice->clist.checks[j]; 
     1885            if (c->lcand->transport_id == vc->lcand->transport_id && 
     1886                c->rcand == vc->rcand) 
     1887            { 
     1888                pj_assert(c->err_code == PJ_SUCCESS); 
     1889                c->state = PJ_ICE_SESS_CHECK_STATE_FROZEN; 
     1890                check_set_state(ice, c, PJ_ICE_SESS_CHECK_STATE_WAITING,  
     1891                                PJ_SUCCESS); 
     1892                break; 
     1893            } 
     1894        } 
    18721895    } 
    18731896 
    18741897    /* And (re)start the periodic check */ 
    18751898    if (!ice->clist.timer.id) { 
    1876         ice->clist.timer.id = PJ_TRUE; 
    1877         delay.sec = delay.msec = 0; 
    1878         status = pj_timer_heap_schedule(ice->stun_cfg.timer_heap,  
    1879                                         &ice->clist.timer, &delay); 
    1880         if (status != PJ_SUCCESS) { 
    1881             ice->clist.timer.id = PJ_FALSE; 
    1882         } 
     1899        pj_timer_heap_cancel(ice->stun_cfg.timer_heap, &ice->clist.timer); 
     1900        ice->clist.timer.id = PJ_FALSE; 
     1901    } 
     1902 
     1903    ice->clist.timer.id = PJ_TRUE; 
     1904    delay.sec = delay.msec = 0; 
     1905    status = pj_timer_heap_schedule(ice->stun_cfg.timer_heap,  
     1906                                    &ice->clist.timer, &delay); 
     1907    if (status != PJ_SUCCESS) { 
     1908        ice->clist.timer.id = PJ_FALSE; 
     1909    } else { 
     1910        LOG5((ice->obj_name, "Periodic timer rescheduled..")); 
    18831911    } 
    18841912 
     
    22542282     */ 
    22552283 
    2256     /* Add pair to valid list */ 
    2257     pj_assert(ice->valid_list.count < PJ_ICE_MAX_CHECKS); 
    2258     new_check = &ice->valid_list.checks[ice->valid_list.count++]; 
    2259     new_check->lcand = lcand; 
    2260     new_check->rcand = check->rcand; 
    2261     new_check->prio = CALC_CHECK_PRIO(ice, lcand, check->rcand); 
    2262     new_check->state = PJ_ICE_SESS_CHECK_STATE_SUCCEEDED; 
    2263     new_check->nominated = check->nominated; 
    2264     new_check->err_code = PJ_SUCCESS; 
     2284    /* Add pair to valid list, if it's not there, otherwise just update 
     2285     * nominated flag 
     2286     */ 
     2287    for (i=0; i<ice->valid_list.count; ++i) { 
     2288        if (ice->valid_list.checks[i].lcand == lcand && 
     2289            ice->valid_list.checks[i].rcand == check->rcand) 
     2290            break; 
     2291    } 
     2292 
     2293    if (i==ice->valid_list.count) { 
     2294        pj_assert(ice->valid_list.count < PJ_ICE_MAX_CHECKS); 
     2295        new_check = &ice->valid_list.checks[ice->valid_list.count++]; 
     2296        new_check->lcand = lcand; 
     2297        new_check->rcand = check->rcand; 
     2298        new_check->prio = CALC_CHECK_PRIO(ice, lcand, check->rcand); 
     2299        new_check->state = PJ_ICE_SESS_CHECK_STATE_SUCCEEDED; 
     2300        new_check->nominated = check->nominated; 
     2301        new_check->err_code = PJ_SUCCESS; 
     2302    } else { 
     2303        new_check = &ice->valid_list.checks[i]; 
     2304        ice->valid_list.checks[i].nominated = check->nominated; 
     2305    } 
    22652306 
    22662307    /* Sort valid_list */ 
    22672308    sort_checklist(&ice->valid_list); 
    22682309 
     2310    /* Update valid check and nominated check for the component */ 
     2311    update_comp_check(ice, new_check->lcand->comp_id, new_check); 
    22692312 
    22702313    /* 7.1.2.2.2.  Updating Pair States 
     
    26342677                for (j=0; j<ice->valid_list.count; ++j) { 
    26352678                    pj_ice_sess_check *vc = &ice->valid_list.checks[j]; 
    2636                     if (vc->lcand == c->lcand && vc->rcand == c->rcand) { 
     2679                    if (vc->lcand->transport_id == c->lcand->transport_id &&  
     2680                        vc->rcand == c->rcand)  
     2681                    { 
     2682                        /* Set nominated flag */ 
    26372683                        vc->nominated = PJ_TRUE; 
     2684 
     2685                        /* Update valid check and nominated check for the component */ 
     2686                        update_comp_check(ice, vc->lcand->comp_id, vc); 
     2687 
     2688                        dump_check(ice->tmp.txt, sizeof(ice->tmp.txt), &ice->valid_list, vc); 
     2689                        LOG5((ice->obj_name, "Valid check %s is nominated", ice->tmp.txt)); 
    26382690                    } 
    26392691                } 
Note: See TracChangeset for help on using the changeset viewer.