Changeset 1111 for pjproject/trunk/pjnath/src/pjnath/ice_session.c
- Timestamp:
- Mar 28, 2007 3:49:48 PM (17 years ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjnath/src/pjnath/ice_session.c
r1110 r1111 17 17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 18 */ 19 #include <pjnath/ice .h>19 #include <pjnath/ice_session.h> 20 20 #include <pjnath/errno.h> 21 21 #include <pj/addr_resolv.h> … … 40 40 }; 41 41 42 /* String names for pj_ice_ check_state */42 /* String names for pj_ice_sess_check_state */ 43 43 static const char *check_state_name[] = 44 44 { … … 66 66 typedef struct stun_data 67 67 { 68 pj_ice *ice;68 pj_ice_sess *ice; 69 69 unsigned lcand_id; 70 pj_ice_ cand *lcand;70 pj_ice_sess_cand *lcand; 71 71 } stun_data; 72 72 73 73 typedef struct timer_data 74 74 { 75 pj_ice *ice;76 pj_ice_ checklist *clist;75 pj_ice_sess *ice; 76 pj_ice_sess_checklist *clist; 77 77 } timer_data; 78 78 79 79 80 80 81 static void destroy_ice(pj_ice *ice,81 static void destroy_ice(pj_ice_sess *ice, 82 82 pj_status_t reason); 83 83 static pj_status_t start_periodic_check(pj_timer_heap_t *th, … … 133 133 PJ_DEF(const char*) pj_ice_get_cand_type_name(pj_ice_cand_type type) 134 134 { 135 PJ_ASSERT_RETURN(type <= PJ_ICE_CAND_TYPE_RELAYED, "???"); 135 136 return cand_type_names[type]; 136 137 } 137 138 138 139 140 /* Get the prefix for the foundation */ 141 static 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 */ 155 PJ_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 139 169 /* 140 * Create ICE s tream session.170 * Create ICE session. 141 171 */ 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)172 PJ_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) 150 180 { 151 181 pj_pool_t *pool; 152 pj_ice *ice;153 char tmp[ 32];182 pj_ice_sess *ice; 183 char tmp[64]; 154 184 pj_str_t s; 155 185 unsigned i; … … 162 192 163 193 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); 165 195 ice->pool = pool; 166 196 ice->role = role; … … 181 211 ice->comp_cnt = comp_cnt; 182 212 for (i=0; i<comp_cnt; ++i) { 183 pj_ice_ comp *comp;213 pj_ice_sess_comp *comp; 184 214 comp = &ice->comp[i]; 185 215 comp->valid_check = NULL; … … 187 217 188 218 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()); 190 220 s = pj_str(tmp); 191 221 local_ufrag = &s; … … 194 224 195 225 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()); 197 227 s = pj_str(tmp); 198 228 local_passwd = &s; … … 204 234 *p_ice = ice; 205 235 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"))); 208 241 209 242 return PJ_SUCCESS; … … 214 247 * Destroy 215 248 */ 216 static void destroy_ice(pj_ice *ice,249 static void destroy_ice(pj_ice_sess *ice, 217 250 pj_status_t reason) 218 251 { … … 248 281 249 282 250 PJ_DEF(pj_status_t) pj_ice_destroy(pj_ice *ice) 251 { 283 /* 284 * Destroy 285 */ 286 PJ_DEF(pj_status_t) pj_ice_sess_destroy(pj_ice_sess *ice) 287 { 288 PJ_ASSERT_RETURN(ice, PJ_EINVAL); 252 289 destroy_ice(ice, PJ_SUCCESS); 253 290 return PJ_SUCCESS; … … 256 293 257 294 /* Find component by ID */ 258 static pj_ice_ comp *find_comp(const pj_ice*ice, unsigned comp_id)295 static pj_ice_sess_comp *find_comp(const pj_ice_sess *ice, unsigned comp_id) 259 296 { 260 297 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 */ 265 303 static pj_status_t stun_auth_get_auth(void *user_data, 266 304 pj_pool_t *pool, … … 290 328 pj_stun_session *sess = (pj_stun_session *)user_data; 291 329 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; 293 331 294 332 PJ_UNUSED_ARG(pool); 295 333 realm->slen = nonce->slen = 0; 296 334 297 if (PJ_STUN_IS_ RESPONSE(msg->hdr.type) ||335 if (PJ_STUN_IS_SUCCESS_RESPONSE(msg->hdr.type) || 298 336 PJ_STUN_IS_ERROR_RESPONSE(msg->hdr.type)) 299 337 { … … 325 363 pj_stun_session *sess = (pj_stun_session *)user_data; 326 364 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; 328 366 329 367 PJ_UNUSED_ARG(realm); 330 368 PJ_UNUSED_ARG(pool); 331 369 332 if (PJ_STUN_IS_ RESPONSE(msg->hdr.type) ||370 if (PJ_STUN_IS_SUCCESS_RESPONSE(msg->hdr.type) || 333 371 PJ_STUN_IS_ERROR_RESPONSE(msg->hdr.type)) 334 372 { … … 379 417 pj_uint32_t comp_id) 380 418 { 381 staticpj_uint32_t type_pref[] =419 pj_uint32_t type_pref[] = 382 420 { 383 421 PJ_ICE_HOST_PREF, … … 396 434 * Add ICE candidate 397 435 */ 398 PJ_DEF(pj_status_t) pj_ice_ add_cand(pj_ice*ice,399 400 401 402 403 404 405 406 407 408 { 409 pj_ice_ cand *lcand;436 PJ_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; 410 448 pj_stun_session_cb sess_cb; 411 449 pj_stun_auth_cred auth_cred; … … 437 475 else 438 476 pj_bzero(&lcand->rel_addr, sizeof(lcand->rel_addr)); 477 439 478 440 479 /* Init STUN callbacks */ … … 498 537 499 538 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 */ 540 PJ_DEF(pj_status_t) pj_ice_sess_find_default_cand(pj_ice_sess *ice, 541 unsigned comp_id, 542 int *cand_id) 503 543 { 504 544 unsigned i; … … 513 553 /* First find in valid list if we have nominated pair */ 514 554 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]; 516 556 517 557 if (check->lcand->comp_id == comp_id) { … … 524 564 /* If there's no nominated pair, find relayed candidate */ 525 565 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]; 527 567 if (lcand->comp_id==comp_id && 528 568 lcand->type == PJ_ICE_CAND_TYPE_RELAYED) … … 536 576 /* If there's no relayed candidate, find reflexive candidate */ 537 577 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]; 539 579 if (lcand->comp_id==comp_id && 540 580 (lcand->type == PJ_ICE_CAND_TYPE_SRFLX || … … 549 589 /* Otherwise return host candidate */ 550 590 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]; 552 592 if (lcand->comp_id==comp_id && 553 593 lcand->type == PJ_ICE_CAND_TYPE_HOST) … … 575 615 #endif 576 616 577 static pj_uint64_t CALC_CHECK_PRIO(const pj_ice *ice,578 const pj_ice_ cand *lcand,579 const pj_ice_ cand *rcand)617 static 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) 580 620 { 581 621 pj_uint32_t O, A; 582 622 583 if (ice->role == PJ_ICE_ ROLE_CONTROLLING) {623 if (ice->role == PJ_ICE_SESS_ROLE_CONTROLLING) { 584 624 O = lcand->prio; 585 625 A = rcand->prio; … … 594 634 595 635 static 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; 601 641 char laddr[CHECK_NAME_LEN]; 602 642 int len; … … 627 667 628 668 #if PJ_LOG_MAX_LEVEL >= 4 629 static void dump_checklist(const char *title, const pj_ice *ice,630 const pj_ice_ checklist *clist)669 static void dump_checklist(const char *title, const pj_ice_sess *ice, 670 const pj_ice_sess_checklist *clist) 631 671 { 632 672 unsigned i; … … 635 675 LOG4((ice->obj_name, "%s", title)); 636 676 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]; 638 678 LOG4((ice->obj_name, " %s (%s, state=%s)", 639 679 dump_check(buffer, sizeof(buffer), clist, c), … … 647 687 #endif 648 688 649 static void check_set_state(pj_ice *ice, pj_ice_check *check,650 pj_ice_ check_state st,689 static void check_set_state(pj_ice_sess *ice, pj_ice_sess_check *check, 690 pj_ice_sess_check_state st, 651 691 pj_status_t err_code) 652 692 { 653 693 char buf[CHECK_NAME_LEN]; 654 694 655 pj_assert(check->state < PJ_ICE_ CHECK_STATE_SUCCEEDED);695 pj_assert(check->state < PJ_ICE_SESS_CHECK_STATE_SUCCEEDED); 656 696 657 697 LOG5((ice->obj_name, "Check %s: state changed from %s to %s", … … 663 703 } 664 704 665 static void clist_set_state(pj_ice *ice, pj_ice_checklist *clist,666 pj_ice_ checklist_state st)705 static void clist_set_state(pj_ice_sess *ice, pj_ice_sess_checklist *clist, 706 pj_ice_sess_checklist_state st) 667 707 { 668 708 if (clist->state != st) { … … 675 715 676 716 /* Sort checklist based on priority */ 677 static void sort_checklist(pj_ice_ checklist *clist)717 static void sort_checklist(pj_ice_sess_checklist *clist) 678 718 { 679 719 unsigned i; … … 688 728 689 729 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)); 693 733 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)); 696 737 } 697 738 } … … 727 768 * is sorted. 728 769 */ 729 static void prune_checklist(pj_ice *ice, pj_ice_checklist *clist)770 static void prune_checklist(pj_ice_sess *ice, pj_ice_sess_checklist *clist) 730 771 { 731 772 unsigned i; … … 742 783 */ 743 784 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; 746 787 const pj_sockaddr *liaddr; 747 788 unsigned j; … … 753 794 754 795 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; 757 798 const pj_sockaddr *ljaddr; 758 799 … … 784 825 785 826 /* This function is called when ICE processing completes */ 786 static void on_ice_complete(pj_ice *ice, pj_status_t status)827 static void on_ice_complete(pj_ice_sess *ice, pj_status_t status) 787 828 { 788 829 if (!ice->is_complete) { … … 807 848 808 849 /* This function is called when one check completes */ 809 static pj_bool_t on_check_complete(pj_ice *ice,810 pj_ice_ check *check)850 static pj_bool_t on_check_complete(pj_ice_sess *ice, 851 pj_ice_sess_check *check) 811 852 { 812 853 unsigned i; 813 854 814 pj_assert(check->state >= PJ_ICE_ CHECK_STATE_SUCCEEDED);855 pj_assert(check->state >= PJ_ICE_SESS_CHECK_STATE_SUCCEEDED); 815 856 816 857 /* If there is at least one nominated pair in the valid list: … … 824 865 */ 825 866 if (check->err_code==PJ_SUCCESS && check->nominated) { 826 pj_ice_ comp *comp;867 pj_ice_sess_comp *comp; 827 868 char buf[CHECK_NAME_LEN]; 828 869 … … 831 872 832 873 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]; 834 875 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) { 836 877 /* Just fail Frozen/Waiting check */ 837 878 LOG5((ice->obj_name, … … 839 880 dump_check(buf, sizeof(buf), &ice->clist, c), 840 881 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, 842 883 PJ_ECANCELLED); 843 884 844 } else if (c->state == PJ_ICE_ CHECK_STATE_IN_PROGRESS) {885 } else if (c->state == PJ_ICE_SESS_CHECK_STATE_IN_PROGRESS) { 845 886 /* State is IN_PROGRESS, cancel transaction */ 846 887 if (c->tdata) { … … 851 892 c->tdata, PJ_FALSE, 0); 852 893 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, 854 895 PJ_ECANCELLED); 855 896 } … … 917 958 */ 918 959 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) { 921 962 break; 922 963 } … … 935 976 936 977 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 */ 979 PJ_DEF(pj_status_t) 980 pj_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; 944 987 char buf[128]; 945 988 pj_str_t username; … … 975 1018 ice->rcand_cnt = 0; 976 1019 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]; 978 1021 979 1022 /* Ignore candidate which has no matching component ID */ 980 pj_assert(rcand[i].comp_id > 0);981 1023 if (rcand[i].comp_id==0 || rcand[i].comp_id > ice->comp_cnt) { 982 1024 continue; 983 1025 } 984 1026 985 pj_memcpy(cn, &rcand[i], sizeof(pj_ice_ cand));1027 pj_memcpy(cn, &rcand[i], sizeof(pj_ice_sess_cand)); 986 1028 pj_strdup(ice->pool, &cn->foundation, &rcand[i].foundation); 987 1029 ice->rcand_cnt++; … … 993 1035 for (j=0; j<ice->rcand_cnt; ++j) { 994 1036 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]; 998 1040 999 1041 if (clist->count > PJ_ICE_MAX_CHECKS) { … … 1015 1057 chk->lcand = lcand; 1016 1058 chk->rcand = rcand; 1017 chk->state = PJ_ICE_ CHECK_STATE_FROZEN;1059 chk->state = PJ_ICE_SESS_CHECK_STATE_FROZEN; 1018 1060 1019 1061 chk->prio = CALC_CHECK_PRIO(ice, lcand, rcand); … … 1049 1091 1050 1092 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 */ 1051 1097 struct req_data 1052 1098 { 1053 pj_ice 1054 pj_ice_ checklist*clist;1055 unsigned ckid;1099 pj_ice_sess *ice; 1100 pj_ice_sess_checklist *clist; 1101 unsigned ckid; 1056 1102 }; 1057 1103 1104 1058 1105 /* Perform check on the specified candidate pair */ 1059 static pj_status_t perform_check(pj_ice *ice, pj_ice_checklist *clist, 1106 static pj_status_t perform_check(pj_ice_sess *ice, 1107 pj_ice_sess_checklist *clist, 1060 1108 unsigned check_id) 1061 1109 { 1062 pj_ice_ comp *comp;1110 pj_ice_sess_comp *comp; 1063 1111 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; 1067 1115 pj_uint32_t prio; 1068 1116 char buffer[128]; … … 1101 1149 1102 1150 /* 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) { 1104 1152 pj_stun_msg_add_empty_attr(check->tdata->pool, check->tdata->msg, 1105 1153 PJ_STUN_ATTR_USE_CANDIDATE); … … 1120 1168 } 1121 1169 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); 1123 1172 return PJ_SUCCESS; 1124 1173 } … … 1132 1181 { 1133 1182 timer_data *td; 1134 pj_ice *ice;1135 pj_ice_ checklist *clist;1183 pj_ice_sess *ice; 1184 pj_ice_sess_checklist *clist; 1136 1185 unsigned i, start_count=0; 1137 1186 pj_status_t status; … … 1147 1196 1148 1197 /* 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); 1150 1199 1151 1200 LOG5((ice->obj_name, "Starting checklist periodic check")); … … 1155 1204 */ 1156 1205 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) { 1160 1209 status = perform_check(ice, clist, i); 1161 1210 if (status != PJ_SUCCESS) { … … 1174 1223 if (start_count==0) { 1175 1224 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) { 1179 1228 status = perform_check(ice, clist, i); 1180 1229 if (status != PJ_SUCCESS) { … … 1193 1242 */ 1194 1243 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); 1196 1245 1197 1246 } else { … … 1210 1259 1211 1260 /* Start ICE check */ 1212 PJ_DEF(pj_status_t) pj_ice_s tart_check(pj_ice*ice)1213 { 1214 pj_ice_ checklist *clist;1215 const pj_ice_ cand *cand0;1261 PJ_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; 1216 1265 unsigned i; 1217 1266 … … 1225 1274 1226 1275 /* 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; 1228 1277 cand0 = clist->checks[0].lcand; 1229 1278 … … 1233 1282 */ 1234 1283 for (i=1; i<clist->count; ++i) { 1235 const pj_ice_ cand *cand1;1284 const pj_ice_sess_cand *cand1; 1236 1285 1237 1286 cand1 = clist->checks[i].lcand; … … 1240 1289 pj_strcmp(&cand0->foundation, &cand1->foundation)!=0) 1241 1290 { 1242 clist->checks[i].state = PJ_ICE_ CHECK_STATE_WAITING;1291 clist->checks[i].state = PJ_ICE_SESS_CHECK_STATE_WAITING; 1243 1292 } 1244 1293 } … … 1251 1300 ////////////////////////////////////////////////////////////////////////////// 1252 1301 1302 /* Callback called by STUN session to send the STUN message. 1303 * STUN session also doesn't have a transport, remember?! 1304 */ 1253 1305 static pj_status_t on_stun_send_msg(pj_stun_session *sess, 1254 1306 const void *pkt, … … 1271 1323 { 1272 1324 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; 1277 1329 pj_stun_xor_mapped_addr_attr *xaddr; 1278 1330 char buffer[CHECK_NAME_LEN]; … … 1303 1355 1304 1356 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); 1306 1358 on_check_complete(ice, check); 1307 1359 pj_mutex_unlock(ice->mutex); … … 1321 1373 pj_stun_msg_find_attr(response, PJ_STUN_ATTR_XOR_MAPPED_ADDR,0); 1322 1374 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, 1324 1376 PJNATH_ESTUNNOMAPPEDADDR); 1325 1377 on_check_complete(ice, check); … … 1344 1396 if (lcand == NULL) { 1345 1397 unsigned cand_id; 1346 char buf[32];1347 1398 pj_str_t foundation; 1348 1399 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); 1352 1402 1353 1403 /* 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, 1355 1405 PJ_ICE_CAND_TYPE_PRFLX, 1356 1406 65535, &foundation, … … 1358 1408 sizeof(pj_sockaddr_in), &cand_id); 1359 1409 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); 1361 1412 on_check_complete(ice, check); 1362 1413 pj_mutex_unlock(ice->mutex); … … 1373 1424 new_check->rcand = check->rcand; 1374 1425 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; 1376 1427 new_check->nominated = check->nominated; 1377 1428 new_check->err_code = PJ_SUCCESS; … … 1384 1435 * succeeded. 1385 1436 */ 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); 1387 1439 1388 1440 /* Inform about check completion. … … 1404 1456 1405 1457 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 && 1409 1461 c->lcand->comp_id != lcand->comp_id && 1410 1462 pj_strcmp(&c->lcand->foundation, &lcand->foundation)==0) 1411 1463 { 1412 1464 /* 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, 1414 1466 PJ_SUCCESS); 1415 1467 unfrozen = PJ_TRUE; … … 1453 1505 { 1454 1506 stun_data *sd; 1455 pj_ice *ice;1507 pj_ice_sess *ice; 1456 1508 pj_stun_priority_attr *ap; 1457 1509 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; 1461 1513 unsigned i; 1462 1514 pj_stun_tx_data *tdata; … … 1574 1626 */ 1575 1627 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]; 1577 1629 if (c->lcand == lcand && c->rcand == rcand) 1578 1630 break; … … 1593 1645 */ 1594 1646 if (i != ice->clist.count) { 1595 pj_ice_ check *c = &ice->clist.checks[i];1647 pj_ice_sess_check *c = &ice->clist.checks[i]; 1596 1648 1597 1649 /* If USE-CANDIDATE is present, set nominated flag … … 1600 1652 c->nominated = ((uc != NULL) || c->nominated); 1601 1653 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) 1604 1656 { 1605 1657 LOG5((ice->obj_name, "Performing triggered check for check %d",i)); 1606 1658 perform_check(ice, &ice->clist, i); 1607 1659 1608 } else if (c->state == PJ_ICE_ CHECK_STATE_IN_PROGRESS) {1660 } else if (c->state == PJ_ICE_SESS_CHECK_STATE_IN_PROGRESS) { 1609 1661 /* Should retransmit here, but how?? 1610 1662 * TODO … … 1612 1664 LOG5((ice->obj_name, "Triggered check for check %d not performed " 1613 1665 "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) { 1615 1667 /* Check complete for this component. 1616 1668 * Note this may end ICE process. … … 1637 1689 else if (ice->clist.count < PJ_ICE_MAX_CHECKS) { 1638 1690 1639 pj_ice_ check *c = &ice->clist.checks[ice->clist.count];1691 pj_ice_sess_check *c = &ice->clist.checks[ice->clist.count]; 1640 1692 1641 1693 c->lcand = lcand; 1642 1694 c->rcand = rcand; 1643 1695 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; 1645 1697 c->nominated = (uc != NULL); 1646 1698 c->err_code = PJ_SUCCESS; … … 1680 1732 1681 1733 1682 PJ_DEF(pj_status_t) pj_ice_se nd_data( pj_ice*ice,1734 PJ_DEF(pj_status_t) pj_ice_sess_send_data( pj_ice_sess *ice, 1683 1735 unsigned comp_id, 1684 1736 const void *data, … … 1686 1738 { 1687 1739 pj_status_t status = PJ_SUCCESS; 1688 pj_ice_ comp *comp;1740 pj_ice_sess_comp *comp; 1689 1741 unsigned cand_id; 1690 1742 … … 1715 1767 1716 1768 1717 PJ_DEF(pj_status_t) pj_ice_ on_rx_pkt( pj_ice*ice,1769 PJ_DEF(pj_status_t) pj_ice_sess_on_rx_pkt( pj_ice_sess *ice, 1718 1770 unsigned comp_id, 1719 1771 unsigned cand_id, … … 1724 1776 { 1725 1777 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; 1728 1780 pj_status_t stun_status; 1729 1781
Note: See TracChangeset
for help on using the changeset viewer.