Changeset 1099 for pjproject/trunk
- Timestamp:
- Mar 23, 2007 7:09:54 PM (18 years ago)
- Location:
- pjproject/trunk
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjmedia/src/pjmedia/transport_ice.c
r1098 r1099 20 20 #include <pjnath/errno.h> 21 21 #include <pj/assert.h> 22 #include <pj/log.h> 22 23 23 24 struct transport_ice … … 26 27 pj_ice_st *ice_st; 27 28 28 void *stream; 29 void (*rtp_cb)(void*, 30 const void*, 31 pj_ssize_t); 32 void (*rtcp_cb)(void*, 33 const void*, 34 pj_ssize_t); 29 pj_time_val start_ice; 30 31 void *stream; 32 pj_sockaddr_in remote_rtp; 33 pj_sockaddr_in remote_rtcp; 34 35 void (*rtp_cb)(void*, 36 const void*, 37 pj_ssize_t); 38 void (*rtcp_cb)(void*, 39 const void*, 40 pj_ssize_t); 35 41 }; 36 42 … … 69 75 const pj_sockaddr_t *src_addr, 70 76 unsigned src_addr_len); 71 static void ice_on_stun_srv_resolved(pj_ice_st *ice_st,72 pj_status_t status);73 static void ice_on_interface_status(pj_ice_st *ice_st,74 void *notify_data,75 pj_status_t status,76 int itf_id);77 77 static void ice_on_ice_complete(pj_ice_st *ice_st, 78 78 pj_status_t status); … … 108 108 pj_bzero(&ice_st_cb, sizeof(ice_st_cb)); 109 109 ice_st_cb.on_ice_complete = &ice_on_ice_complete; 110 ice_st_cb.on_interface_status = &ice_on_interface_status;111 110 ice_st_cb.on_rx_data = &ice_on_rx_data; 112 ice_st_cb.on_stun_srv_resolved = &ice_on_stun_srv_resolved;113 111 114 112 /* Create ICE */ … … 388 386 } 389 387 388 /* Mark start time */ 389 pj_gettimeofday(&tp_ice->start_ice); 390 390 391 /* Start ICE */ 391 392 return pj_ice_st_start_ice(tp_ice->ice_st, &uname, &pass, cand_cnt, cand); … … 455 456 tp_ice->rtcp_cb = rtcp_cb; 456 457 457 PJ_UNUSED_ARG(rem_addr); 458 PJ_UNUSED_ARG(rem_rtcp); 459 PJ_UNUSED_ARG(addr_len); 458 pj_memcpy(&tp_ice->remote_rtp, rem_addr, addr_len); 459 pj_memcpy(&tp_ice->remote_rtcp, rem_rtcp, addr_len); 460 460 461 461 return PJ_SUCCESS; … … 481 481 { 482 482 struct transport_ice *tp_ice = (struct transport_ice*)tp; 483 return pj_ice_st_send_data(tp_ice->ice_st, 1, pkt, size); 483 if (tp_ice->ice_st->ice) { 484 return pj_ice_st_send_data(tp_ice->ice_st, 1, pkt, size); 485 } else { 486 return pj_ice_st_sendto(tp_ice->ice_st, 1, 0, 487 pkt, size, &tp_ice->remote_rtp, 488 sizeof(pj_sockaddr_in)); 489 } 484 490 } 485 491 … … 521 527 522 528 523 static void ice_on_stun_srv_resolved(pj_ice_st *ice_st,524 pj_status_t status)525 {526 struct transport_ice *tp_ice = (struct transport_ice*) ice_st->user_data;527 }528 529 530 static void ice_on_interface_status(pj_ice_st *ice_st,531 void *notify_data,532 pj_status_t status,533 int itf_id)534 {535 struct transport_ice *tp_ice = (struct transport_ice*) ice_st->user_data;536 }537 538 539 529 static void ice_on_ice_complete(pj_ice_st *ice_st, 540 530 pj_status_t status) 541 531 { 542 532 struct transport_ice *tp_ice = (struct transport_ice*) ice_st->user_data; 543 } 544 545 533 pj_time_val end_ice; 534 pj_ice_cand *lcand, *rcand; 535 pj_ice_check *check; 536 char src_addr[32]; 537 char dst_addr[32]; 538 539 if (status != PJ_SUCCESS) { 540 char errmsg[PJ_ERR_MSG_SIZE]; 541 pj_strerror(status, errmsg, sizeof(errmsg)); 542 PJ_LOG(1,(ice_st->obj_name, "ICE negotiation failed: %s", errmsg)); 543 return; 544 } 545 546 pj_gettimeofday(&end_ice); 547 PJ_TIME_VAL_SUB(end_ice, tp_ice->start_ice); 548 549 check = &ice_st->ice->clist.checks[ice_st->ice->valid_list[0]]; 550 551 lcand = check->lcand; 552 rcand = check->rcand; 553 554 pj_ansi_strcpy(src_addr, pj_inet_ntoa(lcand->addr.ipv4.sin_addr)); 555 pj_ansi_strcpy(dst_addr, pj_inet_ntoa(rcand->addr.ipv4.sin_addr)); 556 557 PJ_LOG(3,(ice_st->obj_name, 558 "ICE negotiation completed in %d.%03ds. Sending from " 559 "%s:%d to %s:%d", 560 (int)end_ice.sec, (int)end_ice.msec, 561 src_addr, pj_ntohs(lcand->addr.ipv4.sin_port), 562 dst_addr, pj_ntohs(rcand->addr.ipv4.sin_port))); 563 } 564 565 -
pjproject/trunk/pjnath/include/pjnath/errno.h
r1097 r1099 134 134 */ 135 135 #define PJNATH_ESTUNTSXFAILED (PJNATH_ERRNO_START+126)/* 370126 */ 136 /** 137 * @hideinitializer 138 * STUN mapped address attribute not found 139 */ 140 #define PJNATH_ESTUNNOMAPPEDADDR (PJNATH_ERRNO_START+127)/* 370127 */ 136 141 137 142 -
pjproject/trunk/pjnath/include/pjnath/ice_stream_transport.h
r1098 r1099 49 49 const pj_sockaddr_t *src_addr, 50 50 unsigned src_addr_len); 51 52 void (*on_stun_srv_resolved)(pj_ice_st *ice_st,53 pj_status_t status);54 void (*on_interface_status)(pj_ice_st *ice_st,55 void *notify_data,56 pj_status_t status,57 int itf_id);58 51 void (*on_ice_complete)(pj_ice_st *ice_st, 59 52 pj_status_t status); … … 86 79 pj_sockaddr src_addr; 87 80 int src_addr_len; 81 pj_stun_session *stun_sess; 88 82 } pj_ice_st_interface; 89 83 … … 134 128 pj_uint16_t local_pref, 135 129 const pj_sockaddr_in *addr, 136 unsigned *p_itf_id, 137 pj_bool_t notify, 138 void *notify_data); 130 unsigned *p_itf_id); 139 131 PJ_DECL(pj_status_t) pj_ice_st_add_all_host_interfaces(pj_ice_st *ice_st, 140 132 unsigned comp_id, 141 unsigned port, 142 pj_bool_t notify, 143 void *notify_data); 133 unsigned port); 144 134 PJ_DECL(pj_status_t) pj_ice_st_add_stun_interface(pj_ice_st *ice_st, 145 135 unsigned comp_id, 146 136 unsigned local_port, 147 pj_bool_t notify, 148 void *notify_data); 137 unsigned *p_itf_id); 149 138 PJ_DECL(pj_status_t) pj_ice_st_add_relay_interface(pj_ice_st *ice_st, 150 139 unsigned comp_id, … … 172 161 const void *data, 173 162 pj_size_t data_len); 163 PJ_DECL(pj_status_t) pj_ice_st_sendto(pj_ice_st *ice_st, 164 unsigned comp_id, 165 unsigned itf_id, 166 const void *data, 167 pj_size_t data_len, 168 const pj_sockaddr_t *dst_addr, 169 int dst_addr_len); 174 170 175 171 -
pjproject/trunk/pjnath/src/pjnath/ice.c
r1098 r1099 57 57 }; 58 58 59 const pj_str_t host_foundation = {"host", 4};60 const pj_str_t mapped_foundation = {"srfx", 4};61 const pj_str_t relayed_foundation = {"rlyd", 4};62 const pj_str_t peer_mapped_foundation = {"peer", 4};63 64 59 #define CHECK_NAME_LEN 128 65 60 #define LOG(expr) PJ_LOG(4,expr) … … 1432 1427 if (i == ice->lcand_cnt) { 1433 1428 unsigned cand_id; 1429 char buf[32]; 1430 pj_str_t foundation; 1431 1432 pj_ansi_snprintf(buf, sizeof(buf), "P%x", 1433 lcand->base_addr.ipv4.sin_addr.s_addr); 1434 foundation = pj_str(buf); 1434 1435 1435 1436 /* Add new peer reflexive candidate */ 1436 1437 status = pj_ice_add_cand(ice, lcand->comp_id, 1437 1438 PJ_ICE_CAND_TYPE_PRFLX, 1438 65535, & peer_mapped_foundation,1439 65535, &foundation, 1439 1440 &xaddr->sockaddr, &lcand->base_addr, NULL, 1440 1441 sizeof(pj_sockaddr_in), &cand_id); -
pjproject/trunk/pjnath/src/pjnath/ice_stream_transport.c
r1098 r1099 48 48 static void destroy_ice_st(pj_ice_st *ice_st, pj_status_t reason); 49 49 50 /* STUN session callback */ 51 static pj_status_t stun_on_send_msg(pj_stun_session *sess, 52 const void *pkt, 53 pj_size_t pkt_size, 54 const pj_sockaddr_t *dst_addr, 55 unsigned addr_len); 56 static void stun_on_request_complete(pj_stun_session *sess, 57 pj_status_t status, 58 pj_stun_tx_data *tdata, 59 const pj_stun_msg *response); 60 61 /* Utility: print error */ 50 62 static void ice_st_perror(pj_ice_st *ice_st, const char *title, 51 63 pj_status_t status) … … 161 173 pj_ice_st_interface *is = (pj_ice_st_interface*) 162 174 pj_ioqueue_get_user_data(key); 175 pj_ice_st *ice_st = is->ice_st; 163 176 pj_ssize_t pkt_size; 164 177 pj_status_t status; … … 169 182 * packets to the ICE session. Otherwise just drop the packet. 170 183 */ 171 if (i s->ice_st->ice) {172 status = pj_ice_on_rx_pkt(i s->ice_st->ice,184 if (ice_st->ice) { 185 status = pj_ice_on_rx_pkt(ice_st->ice, 173 186 is->comp_id, is->cand_id, 174 187 is->pkt, bytes_read, 175 188 &is->src_addr, is->src_addr_len); 189 } else if (is->stun_sess) { 190 status = pj_stun_msg_check(is->pkt, bytes_read, PJ_STUN_IS_DATAGRAM); 191 if (status == PJ_SUCCESS) { 192 status = pj_stun_session_on_rx_pkt(is->stun_sess, is->pkt, 193 bytes_read, 194 PJ_STUN_IS_DATAGRAM, NULL, 195 &is->src_addr, 196 is->src_addr_len); 197 } else { 198 (*ice_st->cb.on_rx_data)(ice_st, is->comp_id, is->cand_id, 199 is->pkt, bytes_read, 200 &is->src_addr, is->src_addr_len); 201 202 } 203 } else { 204 (*ice_st->cb.on_rx_data)(ice_st, is->comp_id, is->cand_id, 205 is->pkt, bytes_read, 206 &is->src_addr, is->src_addr_len); 176 207 } 177 208 … … 196 227 static void destroy_ice_interface(pj_ice_st_interface *is) 197 228 { 229 if (is->stun_sess) { 230 pj_stun_session_destroy(is->stun_sess); 231 is->stun_sess = NULL; 232 } 233 198 234 if (is->key) { 199 235 pj_ioqueue_unregister(is->key); … … 345 381 /* Add interface */ 346 382 static void add_interface(pj_ice_st *ice_st, pj_ice_st_interface *is, 347 unsigned *p_itf_id, pj_bool_t notify, 348 void *notify_data) 383 unsigned *p_itf_id) 349 384 { 350 385 unsigned itf_id; … … 355 390 if (p_itf_id) 356 391 *p_itf_id = itf_id; 357 358 if (notify && ice_st->cb.on_interface_status) {359 (*ice_st->cb.on_interface_status)(ice_st, notify_data,360 PJ_SUCCESS, itf_id);361 }362 392 } 363 393 … … 369 399 pj_uint16_t local_pref, 370 400 const pj_sockaddr_in *addr, 371 unsigned *p_itf_id, 372 pj_bool_t notify, 373 void *notify_data) 401 unsigned *p_itf_id) 374 402 { 375 403 pj_ice_st_interface *is; … … 395 423 396 424 /* Store this interface */ 397 add_interface(ice_st, is, p_itf_id , notify, notify_data);425 add_interface(ice_st, is, p_itf_id); 398 426 399 427 /* Set interface status to SUCCESS */ … … 408 436 PJ_DEF(pj_status_t) pj_ice_st_add_all_host_interfaces(pj_ice_st *ice_st, 409 437 unsigned comp_id, 410 unsigned port, 411 pj_bool_t notify, 412 void *notify_data) 438 unsigned port) 413 439 { 414 440 pj_sockaddr_in addr; … … 424 450 return status; 425 451 426 return pj_ice_st_add_host_interface(ice_st, comp_id, 65535, &addr, 427 NULL, notify, notify_data); 452 return pj_ice_st_add_host_interface(ice_st, comp_id, 65535, &addr, NULL); 428 453 } 429 454 … … 434 459 unsigned comp_id, 435 460 unsigned local_port, 436 pj_bool_t notify, 437 void *notify_data) 438 { 439 /* Yeah, TODO */ 440 PJ_UNUSED_ARG(ice_st); 441 PJ_UNUSED_ARG(comp_id); 442 PJ_UNUSED_ARG(local_port); 443 PJ_UNUSED_ARG(notify); 444 PJ_UNUSED_ARG(notify_data); 445 return -1; 461 unsigned *p_itf_id) 462 { 463 pj_ice_st_interface *is; 464 pj_sockaddr_in local_addr; 465 pj_stun_session_cb sess_cb; 466 pj_stun_tx_data *tdata; 467 pj_status_t status; 468 469 PJ_ASSERT_RETURN(ice_st && comp_id, PJ_EINVAL); 470 471 /* STUN server must have been configured */ 472 PJ_ASSERT_RETURN(ice_st->stun_srv.sin_family != 0, PJ_EINVALIDOP); 473 474 475 /* Create interface */ 476 pj_sockaddr_in_init(&local_addr, NULL, (pj_uint16_t)local_port); 477 status = create_ice_interface(ice_st, PJ_ICE_CAND_TYPE_SRFLX, comp_id, 478 65535, &local_addr, &is); 479 if (status != PJ_SUCCESS) 480 return status; 481 482 /* Create STUN session */ 483 pj_bzero(&sess_cb, sizeof(sess_cb)); 484 sess_cb.on_request_complete = &stun_on_request_complete; 485 sess_cb.on_send_msg = &stun_on_send_msg; 486 status = pj_stun_session_create(&ice_st->stun_cfg, ice_st->obj_name, 487 &sess_cb, PJ_FALSE, &is->stun_sess); 488 if (status != PJ_SUCCESS) 489 goto on_error; 490 491 /* Associate interface with STUN session */ 492 pj_stun_session_set_user_data(is->stun_sess, (void*)is); 493 494 /* Create and send STUN binding request */ 495 status = pj_stun_session_create_req(is->stun_sess, 496 PJ_STUN_BINDING_REQUEST, &tdata); 497 if (status != PJ_SUCCESS) 498 goto on_error; 499 500 status = pj_stun_session_send_msg(is->stun_sess, PJ_FALSE, 501 &ice_st->stun_srv, 502 sizeof(pj_sockaddr_in), tdata); 503 if (status != PJ_SUCCESS) 504 goto on_error; 505 506 /* Mark interface as pending */ 507 is->status = PJ_EPENDING; 508 509 add_interface(ice_st, is, p_itf_id); 510 511 return PJ_SUCCESS; 512 513 on_error: 514 destroy_ice_interface(is); 515 return status; 446 516 } 447 517 … … 625 695 626 696 /* 697 * Send packet using non-ICE means (e.g. when ICE was not negotiated). 698 */ 699 PJ_DEF(pj_status_t) pj_ice_st_sendto( pj_ice_st *ice_st, 700 unsigned comp_id, 701 unsigned itf_id, 702 const void *data, 703 pj_size_t data_len, 704 const pj_sockaddr_t *dst_addr, 705 int dst_addr_len) 706 { 707 pj_ssize_t pkt_size; 708 pj_ice_st_interface *is = ice_st->itfs[itf_id]; 709 pj_status_t status; 710 711 pkt_size = data_len; 712 status = pj_ioqueue_sendto(is->key, &is->write_op, 713 data, &pkt_size, 0, 714 dst_addr, dst_addr_len); 715 716 return (status==PJ_SUCCESS||status==PJ_EPENDING) ? PJ_SUCCESS : status; 717 } 718 719 /* 627 720 * Callback called by ICE session when ICE processing is complete, either 628 721 * successfully or with failure. … … 688 781 } 689 782 690 783 /* 784 * Callback called by STUN session to send outgoing packet. 785 */ 786 static pj_status_t stun_on_send_msg(pj_stun_session *sess, 787 const void *pkt, 788 pj_size_t size, 789 const pj_sockaddr_t *dst_addr, 790 unsigned dst_addr_len) 791 { 792 pj_ice_st_interface *is; 793 pj_ssize_t pkt_size; 794 pj_status_t status; 795 796 is = (pj_ice_st_interface*) pj_stun_session_get_user_data(sess); 797 pkt_size = size; 798 status = pj_ioqueue_sendto(is->key, &is->write_op, 799 pkt, &pkt_size, 0, 800 dst_addr, dst_addr_len); 801 802 return (status==PJ_SUCCESS||status==PJ_EPENDING) ? PJ_SUCCESS : status; 803 } 804 805 /* 806 * Callback sent by STUN session when outgoing STUN request has 807 * completed. 808 */ 809 static void stun_on_request_complete(pj_stun_session *sess, 810 pj_status_t status, 811 pj_stun_tx_data *tdata, 812 const pj_stun_msg *response) 813 { 814 pj_ice_st_interface *is; 815 pj_stun_xor_mapped_addr_attr *xa; 816 pj_stun_mapped_addr_attr *ma; 817 pj_sockaddr *mapped_addr; 818 819 PJ_UNUSED_ARG(tdata); 820 821 is = (pj_ice_st_interface*) pj_stun_session_get_user_data(sess); 822 if (status != PJ_SUCCESS) { 823 is->status = status; 824 ice_st_perror(is->ice_st, "STUN Binding request failed", is->status); 825 return; 826 } 827 828 xa = (pj_stun_xor_mapped_addr_attr*) 829 pj_stun_msg_find_attr(response, PJ_STUN_ATTR_XOR_MAPPED_ADDR, 0); 830 ma = (pj_stun_mapped_addr_attr*) 831 pj_stun_msg_find_attr(response, PJ_STUN_ATTR_MAPPED_ADDR, 0); 832 833 if (xa) 834 mapped_addr = &xa->sockaddr; 835 else if (ma) 836 mapped_addr = &ma->sockaddr; 837 else { 838 is->status = PJNATH_ESTUNNOMAPPEDADDR; 839 ice_st_perror(is->ice_st, "STUN Binding request failed", is->status); 840 return; 841 } 842 843 PJ_LOG(4,(is->ice_st->obj_name, 844 "STUN mapped address: %s:%d", 845 pj_inet_ntoa(mapped_addr->ipv4.sin_addr), 846 (int)pj_ntohs(mapped_addr->ipv4.sin_port))); 847 pj_memcpy(&is->addr, mapped_addr, sizeof(pj_sockaddr_in)); 848 is->status = PJ_SUCCESS; 849 850 } 851 -
pjproject/trunk/pjnath/src/pjnath/stun_session.c
r1089 r1099 281 281 282 282 /* Create and add USERNAME attribute */ 283 status = pj_stun_msg_add_string_attr(pool, msg, 284 PJ_STUN_ATTR_USERNAME, 285 &username); 286 PJ_ASSERT_RETURN(status==PJ_SUCCESS, status); 283 if (username.slen) { 284 status = pj_stun_msg_add_string_attr(pool, msg, 285 PJ_STUN_ATTR_USERNAME, 286 &username); 287 PJ_ASSERT_RETURN(status==PJ_SUCCESS, status); 288 } 287 289 288 290 /* Add REALM only when long term credential is used */ … … 302 304 303 305 /* Add MESSAGE-INTEGRITY attribute */ 304 status = pj_stun_msg_add_msgint_attr(pool, msg); 305 PJ_ASSERT_RETURN(status==PJ_SUCCESS, status); 306 if (username.slen) { 307 status = pj_stun_msg_add_msgint_attr(pool, msg); 308 PJ_ASSERT_RETURN(status==PJ_SUCCESS, status); 309 } 306 310 307 311 -
pjproject/trunk/pjsip/src/pjsua-lib/pjsua_acc.c
r998 r1099 944 944 acc = &pjsua_var.acc[acc_id]; 945 945 946 /* If force_contact is configured, then use use it */ 947 if (acc->cfg.force_contact.slen) { 948 *contact = acc->cfg.force_contact; 949 return PJ_SUCCESS; 950 } 951 946 952 /* If route-set is configured for the account, then URI is the 947 953 * first entry of the route-set. … … 1038 1044 acc = &pjsua_var.acc[acc_id]; 1039 1045 1046 /* If force_contact is configured, then use use it */ 1047 if (acc->cfg.force_contact.slen) { 1048 *contact = acc->cfg.force_contact; 1049 return PJ_SUCCESS; 1050 } 1051 1040 1052 /* If Record-Route is present, then URI is the top Record-Route. */ 1041 1053 if (rdata->msg_info.record_route) { -
pjproject/trunk/pjsip/src/pjsua-lib/pjsua_core.c
r1098 r1099 676 676 pjsua_var.stun_srv.ipv4.sin_addr = *(pj_in_addr*)he.h_addr; 677 677 pjsua_var.stun_srv.ipv4.sin_port = pj_htons((pj_uint16_t)3478); 678 679 PJ_LOG(4,(THIS_FILE, 680 "STUN server %.*s resolved, address is %s:%d", 681 (int)pjsua_var.ua_cfg.stun_srv.slen, 682 pjsua_var.ua_cfg.stun_srv.ptr, 683 pj_inet_ntoa(pjsua_var.stun_srv.ipv4.sin_addr), 684 (int)pj_ntohs(pjsua_var.stun_srv.ipv4.sin_port))); 678 685 } 679 686 } -
pjproject/trunk/pjsip/src/pjsua-lib/pjsua_media.c
r1098 r1099 572 572 573 573 /* Add host candidates for RTP */ 574 status = pj_ice_st_add_all_host_interfaces(ice_st, 1, 0, 575 PJ_FALSE, NULL); 574 status = pj_ice_st_add_all_host_interfaces(ice_st, 1, 0); 576 575 if (status != PJ_SUCCESS) { 577 576 pjsua_perror(THIS_FILE, "Error adding ICE host candidates", … … 593 592 594 593 /* Add STUN server reflexive candidate for RTP */ 595 status = pj_ice_st_add_stun_interface(ice_st, 1, 0, 596 PJ_FALSE, NULL); 594 status = pj_ice_st_add_stun_interface(ice_st, 1, 0, NULL); 597 595 if (status != PJ_SUCCESS) { 598 596 pjsua_perror(THIS_FILE, "Error adding ICE address",
Note: See TracChangeset
for help on using the changeset viewer.