Ignore:
Timestamp:
Mar 28, 2007 3:49:48 PM (17 years ago)
Author:
bennylp
Message:

Updated projects and Makefiles with the new pjnath library

File:
1 moved

Legend:

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

    r1110 r1111  
    1717 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA  
    1818 */ 
    19 #include <pjnath/ice.h> 
     19#include <pjnath/ice_session.h> 
    2020#include <pjnath/errno.h> 
    2121#include <pj/addr_resolv.h> 
     
    4040}; 
    4141 
    42 /* String names for pj_ice_check_state */ 
     42/* String names for pj_ice_sess_check_state */ 
    4343static const char *check_state_name[] =  
    4444{ 
     
    6666typedef struct stun_data 
    6767{ 
    68     pj_ice      *ice; 
     68    pj_ice_sess *ice; 
    6969    unsigned     lcand_id; 
    70     pj_ice_cand *lcand; 
     70    pj_ice_sess_cand    *lcand; 
    7171} stun_data; 
    7272 
    7373typedef struct timer_data 
    7474{ 
    75     pj_ice              *ice; 
    76     pj_ice_checklist    *clist; 
     75    pj_ice_sess         *ice; 
     76    pj_ice_sess_checklist       *clist; 
    7777} timer_data; 
    7878 
    7979 
    8080 
    81 static void destroy_ice(pj_ice *ice, 
     81static void destroy_ice(pj_ice_sess *ice, 
    8282                        pj_status_t reason); 
    8383static pj_status_t start_periodic_check(pj_timer_heap_t *th,  
     
    133133PJ_DEF(const char*) pj_ice_get_cand_type_name(pj_ice_cand_type type) 
    134134{ 
     135    PJ_ASSERT_RETURN(type <= PJ_ICE_CAND_TYPE_RELAYED, "???"); 
    135136    return cand_type_names[type]; 
    136137} 
    137138 
    138139 
     140/* Get the prefix for the foundation */ 
     141static int get_type_prefix(pj_ice_cand_type type) 
     142{ 
     143    switch (type) { 
     144    case PJ_ICE_CAND_TYPE_HOST:     return 'H'; 
     145    case PJ_ICE_CAND_TYPE_SRFLX:    return 'S'; 
     146    case PJ_ICE_CAND_TYPE_PRFLX:    return 'P'; 
     147    case PJ_ICE_CAND_TYPE_RELAYED:  return 'R'; 
     148    default: 
     149        pj_assert(!"Invalid type"); 
     150        return 'U'; 
     151    } 
     152} 
     153 
     154/* Calculate foundation */ 
     155PJ_DEF(void) pj_ice_calc_foundation(pj_pool_t *pool, 
     156                                    pj_str_t *foundation, 
     157                                    pj_ice_cand_type type, 
     158                                    const pj_sockaddr *base_addr) 
     159{ 
     160    char buf[64]; 
     161 
     162    pj_ansi_snprintf(buf, sizeof(buf), "%c%x", 
     163                     get_type_prefix(type), 
     164                     (int)pj_ntohl(base_addr->ipv4.sin_addr.s_addr)); 
     165    pj_strdup2(pool, foundation, buf); 
     166} 
     167 
     168 
    139169/* 
    140  * Create ICE stream session. 
     170 * Create ICE session. 
    141171 */ 
    142 PJ_DEF(pj_status_t) pj_ice_create(pj_stun_config *stun_cfg, 
    143                                   const char *name, 
    144                                   pj_ice_role role, 
    145                                   unsigned comp_cnt, 
    146                                   const pj_ice_cb *cb, 
    147                                   const pj_str_t *local_ufrag, 
    148                                   const pj_str_t *local_passwd, 
    149                                   pj_ice **p_ice) 
     172PJ_DEF(pj_status_t) pj_ice_sess_create(pj_stun_config *stun_cfg, 
     173                                       const char *name, 
     174                                       pj_ice_sess_role role, 
     175                                       unsigned comp_cnt, 
     176                                       const pj_ice_sess_cb *cb, 
     177                                       const pj_str_t *local_ufrag, 
     178                                       const pj_str_t *local_passwd, 
     179                                       pj_ice_sess **p_ice) 
    150180{ 
    151181    pj_pool_t *pool; 
    152     pj_ice *ice; 
    153     char tmp[32]; 
     182    pj_ice_sess *ice; 
     183    char tmp[64]; 
    154184    pj_str_t s; 
    155185    unsigned i; 
     
    162192 
    163193    pool = pj_pool_create(stun_cfg->pf, name, 4000, 4000, NULL); 
    164     ice = PJ_POOL_ZALLOC_T(pool, pj_ice); 
     194    ice = PJ_POOL_ZALLOC_T(pool, pj_ice_sess); 
    165195    ice->pool = pool; 
    166196    ice->role = role; 
     
    181211    ice->comp_cnt = comp_cnt; 
    182212    for (i=0; i<comp_cnt; ++i) { 
    183         pj_ice_comp *comp; 
     213        pj_ice_sess_comp *comp; 
    184214        comp = &ice->comp[i]; 
    185215        comp->valid_check = NULL; 
     
    187217 
    188218    if (local_ufrag == NULL) { 
    189         pj_ansi_snprintf(tmp, sizeof(tmp), "%x", pj_rand()); 
     219        pj_ansi_snprintf(tmp, sizeof(tmp), "%x%x", pj_rand(), pj_rand()); 
    190220        s = pj_str(tmp); 
    191221        local_ufrag = &s; 
     
    194224 
    195225    if (local_passwd == NULL) { 
    196         pj_ansi_snprintf(tmp, sizeof(tmp), "%x", pj_rand()); 
     226        pj_ansi_snprintf(tmp, sizeof(tmp), "%x%x", pj_rand(), pj_rand()); 
    197227        s = pj_str(tmp); 
    198228        local_passwd = &s; 
     
    204234    *p_ice = ice; 
    205235 
    206     LOG4((ice->obj_name, "ICE stream session created, role is %s agent", 
    207          (ice->role==PJ_ICE_ROLE_CONTROLLING ? "controlling" : "controlled"))); 
     236    LOG4((ice->obj_name,  
     237         "ICE session created, comp_cnt=%d, role is %s agent", 
     238         comp_cnt, 
     239         (ice->role==PJ_ICE_SESS_ROLE_CONTROLLING ?  
     240            "controlling":"controlled"))); 
    208241 
    209242    return PJ_SUCCESS; 
     
    214247 * Destroy 
    215248 */ 
    216 static void destroy_ice(pj_ice *ice, 
     249static void destroy_ice(pj_ice_sess *ice, 
    217250                        pj_status_t reason) 
    218251{ 
     
    248281 
    249282 
    250 PJ_DEF(pj_status_t) pj_ice_destroy(pj_ice *ice) 
    251 { 
     283/* 
     284 * Destroy 
     285 */ 
     286PJ_DEF(pj_status_t) pj_ice_sess_destroy(pj_ice_sess *ice) 
     287{ 
     288    PJ_ASSERT_RETURN(ice, PJ_EINVAL); 
    252289    destroy_ice(ice, PJ_SUCCESS); 
    253290    return PJ_SUCCESS; 
     
    256293 
    257294/* Find component by ID */ 
    258 static pj_ice_comp *find_comp(const pj_ice *ice, unsigned comp_id) 
     295static pj_ice_sess_comp *find_comp(const pj_ice_sess *ice, unsigned comp_id) 
    259296{ 
    260297    pj_assert(comp_id > 0 && comp_id <= ice->comp_cnt); 
    261     return (pj_ice_comp*) &ice->comp[comp_id-1]; 
    262 } 
    263  
    264  
     298    return (pj_ice_sess_comp*) &ice->comp[comp_id-1]; 
     299} 
     300 
     301 
     302/* Callback by STUN authentication when it needs to send 401 */ 
    265303static pj_status_t stun_auth_get_auth(void *user_data, 
    266304                                      pj_pool_t *pool, 
     
    290328    pj_stun_session *sess = (pj_stun_session *)user_data; 
    291329    stun_data *sd = (stun_data*) pj_stun_session_get_user_data(sess); 
    292     pj_ice *ice = sd->ice; 
     330    pj_ice_sess *ice = sd->ice; 
    293331 
    294332    PJ_UNUSED_ARG(pool); 
    295333    realm->slen = nonce->slen = 0; 
    296334 
    297     if (PJ_STUN_IS_RESPONSE(msg->hdr.type) || 
     335    if (PJ_STUN_IS_SUCCESS_RESPONSE(msg->hdr.type) || 
    298336        PJ_STUN_IS_ERROR_RESPONSE(msg->hdr.type)) 
    299337    { 
     
    325363    pj_stun_session *sess = (pj_stun_session *)user_data; 
    326364    stun_data *sd = (stun_data*) pj_stun_session_get_user_data(sess); 
    327     pj_ice *ice = sd->ice; 
     365    pj_ice_sess *ice = sd->ice; 
    328366 
    329367    PJ_UNUSED_ARG(realm); 
    330368    PJ_UNUSED_ARG(pool); 
    331369 
    332     if (PJ_STUN_IS_RESPONSE(msg->hdr.type) || 
     370    if (PJ_STUN_IS_SUCCESS_RESPONSE(msg->hdr.type) || 
    333371        PJ_STUN_IS_ERROR_RESPONSE(msg->hdr.type)) 
    334372    { 
     
    379417                                  pj_uint32_t comp_id) 
    380418{ 
    381     static pj_uint32_t type_pref[] = 
     419    pj_uint32_t type_pref[] = 
    382420    { 
    383421        PJ_ICE_HOST_PREF, 
     
    396434 * Add ICE candidate 
    397435 */ 
    398 PJ_DEF(pj_status_t) pj_ice_add_cand(pj_ice *ice, 
    399                                     unsigned comp_id, 
    400                                     pj_ice_cand_type type, 
    401                                     pj_uint16_t local_pref, 
    402                                     const pj_str_t *foundation, 
    403                                     const pj_sockaddr_t *addr, 
    404                                     const pj_sockaddr_t *base_addr, 
    405                                     const pj_sockaddr_t *rel_addr, 
    406                                     int addr_len, 
    407                                     unsigned *p_cand_id) 
    408 { 
    409     pj_ice_cand *lcand; 
     436PJ_DEF(pj_status_t) pj_ice_sess_add_cand(pj_ice_sess *ice, 
     437                                        unsigned comp_id, 
     438                                        pj_ice_cand_type type, 
     439                                        pj_uint16_t local_pref, 
     440                                        const pj_str_t *foundation, 
     441                                        const pj_sockaddr_t *addr, 
     442                                        const pj_sockaddr_t *base_addr, 
     443                                        const pj_sockaddr_t *rel_addr, 
     444                                        int addr_len, 
     445                                        unsigned *p_cand_id) 
     446{ 
     447    pj_ice_sess_cand *lcand; 
    410448    pj_stun_session_cb sess_cb; 
    411449    pj_stun_auth_cred auth_cred; 
     
    437475    else 
    438476        pj_bzero(&lcand->rel_addr, sizeof(lcand->rel_addr)); 
     477 
    439478 
    440479    /* Init STUN callbacks */ 
     
    498537 
    499538 
    500 PJ_DEF(pj_status_t) pj_ice_find_default_cand(pj_ice *ice, 
    501                                              unsigned comp_id, 
    502                                              int *cand_id) 
     539/* Find default candidate ID for the component */ 
     540PJ_DEF(pj_status_t) pj_ice_sess_find_default_cand(pj_ice_sess *ice, 
     541                                                  unsigned comp_id, 
     542                                                  int *cand_id) 
    503543{ 
    504544    unsigned i; 
     
    513553    /* First find in valid list if we have nominated pair */ 
    514554    for (i=0; i<ice->valid_list.count; ++i) { 
    515         pj_ice_check *check = &ice->valid_list.checks[i]; 
     555        pj_ice_sess_check *check = &ice->valid_list.checks[i]; 
    516556         
    517557        if (check->lcand->comp_id == comp_id) { 
     
    524564    /* If there's no nominated pair, find relayed candidate */ 
    525565    for (i=0; i<ice->lcand_cnt; ++i) { 
    526         pj_ice_cand *lcand = &ice->lcand[i]; 
     566        pj_ice_sess_cand *lcand = &ice->lcand[i]; 
    527567        if (lcand->comp_id==comp_id && 
    528568            lcand->type == PJ_ICE_CAND_TYPE_RELAYED)  
     
    536576    /* If there's no relayed candidate, find reflexive candidate */ 
    537577    for (i=0; i<ice->lcand_cnt; ++i) { 
    538         pj_ice_cand *lcand = &ice->lcand[i]; 
     578        pj_ice_sess_cand *lcand = &ice->lcand[i]; 
    539579        if (lcand->comp_id==comp_id && 
    540580            (lcand->type == PJ_ICE_CAND_TYPE_SRFLX || 
     
    549589    /* Otherwise return host candidate */ 
    550590    for (i=0; i<ice->lcand_cnt; ++i) { 
    551         pj_ice_cand *lcand = &ice->lcand[i]; 
     591        pj_ice_sess_cand *lcand = &ice->lcand[i]; 
    552592        if (lcand->comp_id==comp_id && 
    553593            lcand->type == PJ_ICE_CAND_TYPE_HOST)  
     
    575615#endif 
    576616 
    577 static pj_uint64_t CALC_CHECK_PRIO(const pj_ice *ice,  
    578                                    const pj_ice_cand *lcand, 
    579                                    const pj_ice_cand *rcand) 
     617static pj_uint64_t CALC_CHECK_PRIO(const pj_ice_sess *ice,  
     618                                   const pj_ice_sess_cand *lcand, 
     619                                   const pj_ice_sess_cand *rcand) 
    580620{ 
    581621    pj_uint32_t O, A; 
    582622 
    583     if (ice->role == PJ_ICE_ROLE_CONTROLLING) { 
     623    if (ice->role == PJ_ICE_SESS_ROLE_CONTROLLING) { 
    584624        O = lcand->prio;  
    585625        A = rcand->prio; 
     
    594634 
    595635static const char *dump_check(char *buffer, unsigned bufsize, 
    596                               const pj_ice_checklist *clist, 
    597                               const pj_ice_check *check) 
    598 { 
    599     const pj_ice_cand *lcand = check->lcand; 
    600     const pj_ice_cand *rcand = check->rcand; 
     636                              const pj_ice_sess_checklist *clist, 
     637                              const pj_ice_sess_check *check) 
     638{ 
     639    const pj_ice_sess_cand *lcand = check->lcand; 
     640    const pj_ice_sess_cand *rcand = check->rcand; 
    601641    char laddr[CHECK_NAME_LEN]; 
    602642    int len; 
     
    627667 
    628668#if PJ_LOG_MAX_LEVEL >= 4 
    629 static void dump_checklist(const char *title, const pj_ice *ice,  
    630                            const pj_ice_checklist *clist) 
     669static void dump_checklist(const char *title, const pj_ice_sess *ice,  
     670                           const pj_ice_sess_checklist *clist) 
    631671{ 
    632672    unsigned i; 
     
    635675    LOG4((ice->obj_name, "%s", title)); 
    636676    for (i=0; i<clist->count; ++i) { 
    637         const pj_ice_check *c = &clist->checks[i]; 
     677        const pj_ice_sess_check *c = &clist->checks[i]; 
    638678        LOG4((ice->obj_name, " %s (%s, state=%s)", 
    639679             dump_check(buffer, sizeof(buffer), clist, c), 
     
    647687#endif 
    648688 
    649 static void check_set_state(pj_ice *ice, pj_ice_check *check, 
    650                             pj_ice_check_state st,  
     689static void check_set_state(pj_ice_sess *ice, pj_ice_sess_check *check, 
     690                            pj_ice_sess_check_state st,  
    651691                            pj_status_t err_code) 
    652692{ 
    653693    char buf[CHECK_NAME_LEN]; 
    654694 
    655     pj_assert(check->state < PJ_ICE_CHECK_STATE_SUCCEEDED); 
     695    pj_assert(check->state < PJ_ICE_SESS_CHECK_STATE_SUCCEEDED); 
    656696 
    657697    LOG5((ice->obj_name, "Check %s: state changed from %s to %s", 
     
    663703} 
    664704 
    665 static void clist_set_state(pj_ice *ice, pj_ice_checklist *clist, 
    666                             pj_ice_checklist_state st) 
     705static void clist_set_state(pj_ice_sess *ice, pj_ice_sess_checklist *clist, 
     706                            pj_ice_sess_checklist_state st) 
    667707{ 
    668708    if (clist->state != st) { 
     
    675715 
    676716/* Sort checklist based on priority */ 
    677 static void sort_checklist(pj_ice_checklist *clist) 
     717static void sort_checklist(pj_ice_sess_checklist *clist) 
    678718{ 
    679719    unsigned i; 
     
    688728 
    689729        if (highest != i) { 
    690             pj_ice_check tmp; 
    691  
    692             pj_memcpy(&tmp, &clist->checks[i], sizeof(pj_ice_check)); 
     730            pj_ice_sess_check tmp; 
     731 
     732            pj_memcpy(&tmp, &clist->checks[i], sizeof(pj_ice_sess_check)); 
    693733            pj_memcpy(&clist->checks[i], &clist->checks[highest],  
    694                       sizeof(pj_ice_check)); 
    695             pj_memcpy(&clist->checks[highest], &tmp, sizeof(pj_ice_check)); 
     734                      sizeof(pj_ice_sess_check)); 
     735            pj_memcpy(&clist->checks[highest], &tmp,  
     736                      sizeof(pj_ice_sess_check)); 
    696737        } 
    697738    } 
     
    727768 * is sorted. 
    728769 */ 
    729 static void prune_checklist(pj_ice *ice, pj_ice_checklist *clist) 
     770static void prune_checklist(pj_ice_sess *ice, pj_ice_sess_checklist *clist) 
    730771{ 
    731772    unsigned i; 
     
    742783     */ 
    743784    for (i=0; i<clist->count; ++i) { 
    744         pj_ice_cand *licand = clist->checks[i].lcand; 
    745         pj_ice_cand *ricand = clist->checks[i].rcand; 
     785        pj_ice_sess_cand *licand = clist->checks[i].lcand; 
     786        pj_ice_sess_cand *ricand = clist->checks[i].rcand; 
    746787        const pj_sockaddr *liaddr; 
    747788        unsigned j; 
     
    753794 
    754795        for (j=i+1; j<clist->count;) { 
    755             pj_ice_cand *ljcand = clist->checks[j].lcand; 
    756             pj_ice_cand *rjcand = clist->checks[j].rcand; 
     796            pj_ice_sess_cand *ljcand = clist->checks[j].lcand; 
     797            pj_ice_sess_cand *rjcand = clist->checks[j].rcand; 
    757798            const pj_sockaddr *ljaddr; 
    758799 
     
    784825 
    785826/* This function is called when ICE processing completes */ 
    786 static void on_ice_complete(pj_ice *ice, pj_status_t status) 
     827static void on_ice_complete(pj_ice_sess *ice, pj_status_t status) 
    787828{ 
    788829    if (!ice->is_complete) { 
     
    807848 
    808849/* This function is called when one check completes */ 
    809 static pj_bool_t on_check_complete(pj_ice *ice, 
    810                                    pj_ice_check *check) 
     850static pj_bool_t on_check_complete(pj_ice_sess *ice, 
     851                                   pj_ice_sess_check *check) 
    811852{ 
    812853    unsigned i; 
    813854 
    814     pj_assert(check->state >= PJ_ICE_CHECK_STATE_SUCCEEDED); 
     855    pj_assert(check->state >= PJ_ICE_SESS_CHECK_STATE_SUCCEEDED); 
    815856 
    816857    /* If there is at least one nominated pair in the valid list: 
     
    824865     */ 
    825866    if (check->err_code==PJ_SUCCESS && check->nominated) { 
    826         pj_ice_comp *comp; 
     867        pj_ice_sess_comp *comp; 
    827868        char buf[CHECK_NAME_LEN]; 
    828869 
     
    831872 
    832873        for (i=0; i<ice->clist.count; ++i) { 
    833             pj_ice_check *c = &ice->clist.checks[i]; 
     874            pj_ice_sess_check *c = &ice->clist.checks[i]; 
    834875            if (c->lcand->comp_id == check->lcand->comp_id) { 
    835                 if (c->state < PJ_ICE_CHECK_STATE_IN_PROGRESS) { 
     876                if (c->state < PJ_ICE_SESS_CHECK_STATE_IN_PROGRESS) { 
    836877                    /* Just fail Frozen/Waiting check */ 
    837878                    LOG5((ice->obj_name,  
     
    839880                         dump_check(buf, sizeof(buf), &ice->clist, c),  
    840881                         check_state_name[c->state])); 
    841                     check_set_state(ice, c, PJ_ICE_CHECK_STATE_FAILED, 
     882                    check_set_state(ice, c, PJ_ICE_SESS_CHECK_STATE_FAILED, 
    842883                                    PJ_ECANCELLED); 
    843884 
    844                 } else if (c->state == PJ_ICE_CHECK_STATE_IN_PROGRESS) { 
     885                } else if (c->state == PJ_ICE_SESS_CHECK_STATE_IN_PROGRESS) { 
    845886                    /* State is IN_PROGRESS, cancel transaction */ 
    846887                    if (c->tdata) { 
     
    851892                                                   c->tdata, PJ_FALSE, 0); 
    852893                        c->tdata = NULL; 
    853                         check_set_state(ice, c, PJ_ICE_CHECK_STATE_FAILED, 
     894                        check_set_state(ice, c, PJ_ICE_SESS_CHECK_STATE_FAILED, 
    854895                                        PJ_ECANCELLED); 
    855896                    } 
     
    917958     */ 
    918959    for (i=0; i<ice->clist.count; ++i) { 
    919         pj_ice_check *c = &ice->clist.checks[i]; 
    920         if (c->state < PJ_ICE_CHECK_STATE_SUCCEEDED) { 
     960        pj_ice_sess_check *c = &ice->clist.checks[i]; 
     961        if (c->state < PJ_ICE_SESS_CHECK_STATE_SUCCEEDED) { 
    921962            break; 
    922963        } 
     
    935976 
    936977 
    937 PJ_DEF(pj_status_t) pj_ice_create_check_list(pj_ice *ice, 
    938                                              const pj_str_t *rem_ufrag, 
    939                                              const pj_str_t *rem_passwd, 
    940                                              unsigned rcand_cnt, 
    941                                              const pj_ice_cand rcand[]) 
    942 { 
    943     pj_ice_checklist *clist; 
     978/* Create checklist by pairing local candidates with remote candidates */ 
     979PJ_DEF(pj_status_t)  
     980pj_ice_sess_create_check_list(pj_ice_sess *ice, 
     981                              const pj_str_t *rem_ufrag, 
     982                              const pj_str_t *rem_passwd, 
     983                              unsigned rcand_cnt, 
     984                              const pj_ice_sess_cand rcand[]) 
     985{ 
     986    pj_ice_sess_checklist *clist; 
    944987    char buf[128]; 
    945988    pj_str_t username; 
     
    9751018    ice->rcand_cnt = 0; 
    9761019    for (i=0; i<rcand_cnt; ++i) { 
    977         pj_ice_cand *cn = &ice->rcand[ice->rcand_cnt]; 
     1020        pj_ice_sess_cand *cn = &ice->rcand[ice->rcand_cnt]; 
    9781021 
    9791022        /* Ignore candidate which has no matching component ID */ 
    980         pj_assert(rcand[i].comp_id > 0); 
    9811023        if (rcand[i].comp_id==0 || rcand[i].comp_id > ice->comp_cnt) { 
    9821024            continue; 
    9831025        } 
    9841026 
    985         pj_memcpy(cn, &rcand[i], sizeof(pj_ice_cand)); 
     1027        pj_memcpy(cn, &rcand[i], sizeof(pj_ice_sess_cand)); 
    9861028        pj_strdup(ice->pool, &cn->foundation, &rcand[i].foundation); 
    9871029        ice->rcand_cnt++; 
     
    9931035        for (j=0; j<ice->rcand_cnt; ++j) { 
    9941036 
    995             pj_ice_cand *lcand = &ice->lcand[i]; 
    996             pj_ice_cand *rcand = &ice->rcand[j]; 
    997             pj_ice_check *chk = &clist->checks[clist->count]; 
     1037            pj_ice_sess_cand *lcand = &ice->lcand[i]; 
     1038            pj_ice_sess_cand *rcand = &ice->rcand[j]; 
     1039            pj_ice_sess_check *chk = &clist->checks[clist->count]; 
    9981040 
    9991041            if (clist->count > PJ_ICE_MAX_CHECKS) { 
     
    10151057            chk->lcand = lcand; 
    10161058            chk->rcand = rcand; 
    1017             chk->state = PJ_ICE_CHECK_STATE_FROZEN; 
     1059            chk->state = PJ_ICE_SESS_CHECK_STATE_FROZEN; 
    10181060 
    10191061            chk->prio = CALC_CHECK_PRIO(ice, lcand, rcand); 
     
    10491091 
    10501092 
     1093/* This is the data that will be attached as user data to outgoing 
     1094 * STUN requests, and it will be given back when we receive completion 
     1095 * status of the request. 
     1096 */ 
    10511097struct req_data 
    10521098{ 
    1053     pj_ice              *ice; 
    1054     pj_ice_checklist    *clist; 
    1055     unsigned             ckid; 
     1099    pj_ice_sess             *ice; 
     1100    pj_ice_sess_checklist   *clist; 
     1101    unsigned                 ckid; 
    10561102}; 
    10571103 
     1104 
    10581105/* Perform check on the specified candidate pair */ 
    1059 static pj_status_t perform_check(pj_ice *ice, pj_ice_checklist *clist, 
     1106static pj_status_t perform_check(pj_ice_sess *ice,  
     1107                                 pj_ice_sess_checklist *clist, 
    10601108                                 unsigned check_id) 
    10611109{ 
    1062     pj_ice_comp *comp; 
     1110    pj_ice_sess_comp *comp; 
    10631111    struct req_data *rd; 
    1064     pj_ice_check *check; 
    1065     const pj_ice_cand *lcand; 
    1066     const pj_ice_cand *rcand; 
     1112    pj_ice_sess_check *check; 
     1113    const pj_ice_sess_cand *lcand; 
     1114    const pj_ice_sess_cand *rcand; 
    10671115    pj_uint32_t prio; 
    10681116    char buffer[128]; 
     
    11011149 
    11021150    /* Add USE-CANDIDATE and set this check to nominated */ 
    1103     if (ice->role == PJ_ICE_ROLE_CONTROLLING) { 
     1151    if (ice->role == PJ_ICE_SESS_ROLE_CONTROLLING) { 
    11041152        pj_stun_msg_add_empty_attr(check->tdata->pool, check->tdata->msg,  
    11051153                                   PJ_STUN_ATTR_USE_CANDIDATE); 
     
    11201168    } 
    11211169 
    1122     check_set_state(ice, check, PJ_ICE_CHECK_STATE_IN_PROGRESS, PJ_SUCCESS); 
     1170    check_set_state(ice, check, PJ_ICE_SESS_CHECK_STATE_IN_PROGRESS,  
     1171                    PJ_SUCCESS); 
    11231172    return PJ_SUCCESS; 
    11241173} 
     
    11321181{ 
    11331182    timer_data *td; 
    1134     pj_ice *ice; 
    1135     pj_ice_checklist *clist; 
     1183    pj_ice_sess *ice; 
     1184    pj_ice_sess_checklist *clist; 
    11361185    unsigned i, start_count=0; 
    11371186    pj_status_t status; 
     
    11471196 
    11481197    /* Set checklist state to Running */ 
    1149     clist_set_state(ice, clist, PJ_ICE_CHECKLIST_ST_RUNNING); 
     1198    clist_set_state(ice, clist, PJ_ICE_SESS_CHECKLIST_ST_RUNNING); 
    11501199 
    11511200    LOG5((ice->obj_name, "Starting checklist periodic check")); 
     
    11551204     */ 
    11561205    for (i=0; i<clist->count; ++i) { 
    1157         pj_ice_check *check = &clist->checks[i]; 
    1158  
    1159         if (check->state == PJ_ICE_CHECK_STATE_WAITING) { 
     1206        pj_ice_sess_check *check = &clist->checks[i]; 
     1207 
     1208        if (check->state == PJ_ICE_SESS_CHECK_STATE_WAITING) { 
    11601209            status = perform_check(ice, clist, i); 
    11611210            if (status != PJ_SUCCESS) { 
     
    11741223    if (start_count==0) { 
    11751224        for (i=0; i<clist->count; ++i) { 
    1176             pj_ice_check *check = &clist->checks[i]; 
    1177  
    1178             if (check->state == PJ_ICE_CHECK_STATE_FROZEN) { 
     1225            pj_ice_sess_check *check = &clist->checks[i]; 
     1226 
     1227            if (check->state == PJ_ICE_SESS_CHECK_STATE_FROZEN) { 
    11791228                status = perform_check(ice, clist, i); 
    11801229                if (status != PJ_SUCCESS) { 
     
    11931242     */ 
    11941243    if (start_count==0) { 
    1195         clist_set_state(ice, clist, PJ_ICE_CHECKLIST_ST_COMPLETED); 
     1244        clist_set_state(ice, clist, PJ_ICE_SESS_CHECKLIST_ST_COMPLETED); 
    11961245 
    11971246    } else { 
     
    12101259 
    12111260/* Start ICE check */ 
    1212 PJ_DEF(pj_status_t) pj_ice_start_check(pj_ice *ice) 
    1213 { 
    1214     pj_ice_checklist *clist; 
    1215     const pj_ice_cand *cand0; 
     1261PJ_DEF(pj_status_t) pj_ice_sess_start_check(pj_ice_sess *ice) 
     1262{ 
     1263    pj_ice_sess_checklist *clist; 
     1264    const pj_ice_sess_cand *cand0; 
    12161265    unsigned i; 
    12171266 
     
    12251274 
    12261275    /* Pickup the first pair and set the state to Waiting */ 
    1227     clist->checks[0].state = PJ_ICE_CHECK_STATE_WAITING; 
     1276    clist->checks[0].state = PJ_ICE_SESS_CHECK_STATE_WAITING; 
    12281277    cand0 = clist->checks[0].lcand; 
    12291278 
     
    12331282     */ 
    12341283    for (i=1; i<clist->count; ++i) { 
    1235         const pj_ice_cand *cand1; 
     1284        const pj_ice_sess_cand *cand1; 
    12361285 
    12371286        cand1 = clist->checks[i].lcand; 
     
    12401289            pj_strcmp(&cand0->foundation, &cand1->foundation)!=0) 
    12411290        { 
    1242             clist->checks[i].state = PJ_ICE_CHECK_STATE_WAITING; 
     1291            clist->checks[i].state = PJ_ICE_SESS_CHECK_STATE_WAITING; 
    12431292        } 
    12441293    } 
     
    12511300////////////////////////////////////////////////////////////////////////////// 
    12521301 
     1302/* Callback called by STUN session to send the STUN message. 
     1303 * STUN session also doesn't have a transport, remember?! 
     1304 */ 
    12531305static pj_status_t on_stun_send_msg(pj_stun_session *sess, 
    12541306                                    const void *pkt, 
     
    12711323{ 
    12721324    struct req_data *rd = (struct req_data*) tdata->user_data; 
    1273     pj_ice *ice; 
    1274     pj_ice_check *check, *new_check; 
    1275     pj_ice_cand *lcand; 
    1276     pj_ice_checklist *clist; 
     1325    pj_ice_sess *ice; 
     1326    pj_ice_sess_check *check, *new_check; 
     1327    pj_ice_sess_cand *lcand; 
     1328    pj_ice_sess_checklist *clist; 
    12771329    pj_stun_xor_mapped_addr_attr *xaddr; 
    12781330    char buffer[CHECK_NAME_LEN]; 
     
    13031355 
    13041356    if (status != PJ_SUCCESS) { 
    1305         check_set_state(ice, check, PJ_ICE_CHECK_STATE_FAILED, status); 
     1357        check_set_state(ice, check, PJ_ICE_SESS_CHECK_STATE_FAILED, status); 
    13061358        on_check_complete(ice, check); 
    13071359        pj_mutex_unlock(ice->mutex); 
     
    13211373            pj_stun_msg_find_attr(response, PJ_STUN_ATTR_XOR_MAPPED_ADDR,0); 
    13221374    if (!xaddr) { 
    1323         check_set_state(ice, check, PJ_ICE_CHECK_STATE_FAILED,  
     1375        check_set_state(ice, check, PJ_ICE_SESS_CHECK_STATE_FAILED,  
    13241376                        PJNATH_ESTUNNOMAPPEDADDR); 
    13251377        on_check_complete(ice, check); 
     
    13441396    if (lcand == NULL) { 
    13451397        unsigned cand_id; 
    1346         char buf[32]; 
    13471398        pj_str_t foundation; 
    13481399 
    1349         pj_ansi_snprintf(buf, sizeof(buf), "P%x",  
    1350                          lcand->base_addr.ipv4.sin_addr.s_addr); 
    1351         foundation = pj_str(buf); 
     1400        pj_ice_calc_foundation(ice->pool, &foundation, PJ_ICE_CAND_TYPE_PRFLX, 
     1401                               &lcand->base_addr); 
    13521402 
    13531403        /* Add new peer reflexive candidate */ 
    1354         status = pj_ice_add_cand(ice, lcand->comp_id,  
     1404        status = pj_ice_sess_add_cand(ice, lcand->comp_id,  
    13551405                                 PJ_ICE_CAND_TYPE_PRFLX, 
    13561406                                 65535, &foundation, 
     
    13581408                                 sizeof(pj_sockaddr_in), &cand_id); 
    13591409        if (status != PJ_SUCCESS) { 
    1360             check_set_state(ice, check, PJ_ICE_CHECK_STATE_FAILED, status); 
     1410            check_set_state(ice, check, PJ_ICE_SESS_CHECK_STATE_FAILED,  
     1411                            status); 
    13611412            on_check_complete(ice, check); 
    13621413            pj_mutex_unlock(ice->mutex); 
     
    13731424    new_check->rcand = check->rcand; 
    13741425    new_check->prio = CALC_CHECK_PRIO(ice, lcand, check->rcand); 
    1375     new_check->state = PJ_ICE_CHECK_STATE_SUCCEEDED; 
     1426    new_check->state = PJ_ICE_SESS_CHECK_STATE_SUCCEEDED; 
    13761427    new_check->nominated = check->nominated; 
    13771428    new_check->err_code = PJ_SUCCESS; 
     
    13841435     * succeeded.  
    13851436     */ 
    1386     check_set_state(ice, check, PJ_ICE_CHECK_STATE_SUCCEEDED, PJ_SUCCESS); 
     1437    check_set_state(ice, check, PJ_ICE_SESS_CHECK_STATE_SUCCEEDED,  
     1438                    PJ_SUCCESS); 
    13871439 
    13881440    /* Inform about check completion. 
     
    14041456 
    14051457        for (i=0; i<clist->count; ++i)  { 
    1406             pj_ice_check *c = &clist->checks[i]; 
    1407  
    1408             if (c->state == PJ_ICE_CHECK_STATE_FROZEN && 
     1458            pj_ice_sess_check *c = &clist->checks[i]; 
     1459 
     1460            if (c->state == PJ_ICE_SESS_CHECK_STATE_FROZEN && 
    14091461                c->lcand->comp_id != lcand->comp_id && 
    14101462                pj_strcmp(&c->lcand->foundation, &lcand->foundation)==0) 
    14111463            { 
    14121464                /* Unfreeze and start check */ 
    1413                 check_set_state(ice, c, PJ_ICE_CHECK_STATE_WAITING,  
     1465                check_set_state(ice, c, PJ_ICE_SESS_CHECK_STATE_WAITING,  
    14141466                                PJ_SUCCESS); 
    14151467                unfrozen = PJ_TRUE; 
     
    14531505{ 
    14541506    stun_data *sd; 
    1455     pj_ice *ice; 
     1507    pj_ice_sess *ice; 
    14561508    pj_stun_priority_attr *ap; 
    14571509    pj_stun_use_candidate_attr *uc; 
    1458     pj_ice_comp *comp; 
    1459     pj_ice_cand *lcand; 
    1460     pj_ice_cand *rcand; 
     1510    pj_ice_sess_comp *comp; 
     1511    pj_ice_sess_cand *lcand; 
     1512    pj_ice_sess_cand *rcand; 
    14611513    unsigned i; 
    14621514    pj_stun_tx_data *tdata; 
     
    15741626     */ 
    15751627    for (i=0; i<ice->clist.count; ++i) { 
    1576         pj_ice_check *c = &ice->clist.checks[i]; 
     1628        pj_ice_sess_check *c = &ice->clist.checks[i]; 
    15771629        if (c->lcand == lcand && c->rcand == rcand) 
    15781630            break; 
     
    15931645     */ 
    15941646    if (i != ice->clist.count) { 
    1595         pj_ice_check *c = &ice->clist.checks[i]; 
     1647        pj_ice_sess_check *c = &ice->clist.checks[i]; 
    15961648 
    15971649        /* If USE-CANDIDATE is present, set nominated flag  
     
    16001652        c->nominated = ((uc != NULL) || c->nominated); 
    16011653 
    1602         if (c->state == PJ_ICE_CHECK_STATE_FROZEN || 
    1603             c->state == PJ_ICE_CHECK_STATE_WAITING) 
     1654        if (c->state == PJ_ICE_SESS_CHECK_STATE_FROZEN || 
     1655            c->state == PJ_ICE_SESS_CHECK_STATE_WAITING) 
    16041656        { 
    16051657            LOG5((ice->obj_name, "Performing triggered check for check %d",i)); 
    16061658            perform_check(ice, &ice->clist, i); 
    16071659 
    1608         } else if (c->state == PJ_ICE_CHECK_STATE_IN_PROGRESS) { 
     1660        } else if (c->state == PJ_ICE_SESS_CHECK_STATE_IN_PROGRESS) { 
    16091661            /* Should retransmit here, but how?? 
    16101662             * TODO 
     
    16121664            LOG5((ice->obj_name, "Triggered check for check %d not performed " 
    16131665                                "because it's in progress", i)); 
    1614         } else if (c->state == PJ_ICE_CHECK_STATE_SUCCEEDED) { 
     1666        } else if (c->state == PJ_ICE_SESS_CHECK_STATE_SUCCEEDED) { 
    16151667            /* Check complete for this component. 
    16161668             * Note this may end ICE process. 
     
    16371689    else if (ice->clist.count < PJ_ICE_MAX_CHECKS) { 
    16381690 
    1639         pj_ice_check *c = &ice->clist.checks[ice->clist.count]; 
     1691        pj_ice_sess_check *c = &ice->clist.checks[ice->clist.count]; 
    16401692 
    16411693        c->lcand = lcand; 
    16421694        c->rcand = rcand; 
    16431695        c->prio = CALC_CHECK_PRIO(ice, lcand, rcand); 
    1644         c->state = PJ_ICE_CHECK_STATE_WAITING; 
     1696        c->state = PJ_ICE_SESS_CHECK_STATE_WAITING; 
    16451697        c->nominated = (uc != NULL); 
    16461698        c->err_code = PJ_SUCCESS; 
     
    16801732 
    16811733 
    1682 PJ_DEF(pj_status_t) pj_ice_send_data( pj_ice *ice, 
     1734PJ_DEF(pj_status_t) pj_ice_sess_send_data( pj_ice_sess *ice, 
    16831735                                      unsigned comp_id, 
    16841736                                      const void *data, 
     
    16861738{ 
    16871739    pj_status_t status = PJ_SUCCESS; 
    1688     pj_ice_comp *comp; 
     1740    pj_ice_sess_comp *comp; 
    16891741    unsigned cand_id; 
    16901742 
     
    17151767 
    17161768 
    1717 PJ_DEF(pj_status_t) pj_ice_on_rx_pkt( pj_ice *ice, 
     1769PJ_DEF(pj_status_t) pj_ice_sess_on_rx_pkt( pj_ice_sess *ice, 
    17181770                                      unsigned comp_id, 
    17191771                                      unsigned cand_id, 
     
    17241776{ 
    17251777    pj_status_t status = PJ_SUCCESS; 
    1726     pj_ice_comp *comp; 
    1727     pj_ice_cand *lcand; 
     1778    pj_ice_sess_comp *comp; 
     1779    pj_ice_sess_cand *lcand; 
    17281780    pj_status_t stun_status; 
    17291781 
Note: See TracChangeset for help on using the changeset viewer.