Changeset 1053 for pjproject/trunk
- Timestamp:
- Mar 10, 2007 11:19:11 AM (18 years ago)
- Location:
- pjproject/trunk/pjlib-util
- Files:
-
- 1 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjlib-util/build/pjlib_util.dsp
r1037 r1053 278 278 # Begin Source File 279 279 280 SOURCE="..\include\pjlib-util\turn_client.h" 281 # End Source File 282 # Begin Source File 283 280 284 SOURCE="..\include\pjlib-util\types.h" 281 285 # End Source File -
pjproject/trunk/pjlib-util/include/pjlib-util.h
r1037 r1053 1 /* $Id */1 /* $Id$ */ 2 2 /* 3 3 * Copyright (C)2003-2007 Benny Prijono <benny@prijono.org> … … 55 55 #include <pjlib-util/stun_session.h> 56 56 #include <pjlib-util/stun_transaction.h> 57 /*#include <pjlib-util/turn_client.h>*/ 57 58 58 59 /* Old STUN */ -
pjproject/trunk/pjlib-util/include/pjlib-util/stun_auth.h
r1037 r1053 17 17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 18 */ 19 #ifndef __PJ _STUN_AUTH_H__20 #define __PJ _STUN_AUTH_H__19 #ifndef __PJLIB_UTIL_STUN_AUTH_H__ 20 #define __PJLIB_UTIL_STUN_AUTH_H__ 21 21 22 22 /** … … 272 272 273 273 274 #endif /* __PJ _STUN_AUTH_H__ */275 274 #endif /* __PJLIB_UTIL_STUN_AUTH_H__ */ 275 -
pjproject/trunk/pjlib-util/include/pjlib-util/stun_endpoint.h
r1034 r1053 17 17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 18 */ 19 #ifndef __PJ _STUN_ENDPOINT_H__20 #define __PJ _STUN_ENDPOINT_H__19 #ifndef __PJLIB_UTIL_STUN_ENDPOINT_H__ 20 #define __PJLIB_UTIL_STUN_ENDPOINT_H__ 21 21 22 22 /** … … 114 114 115 115 116 #endif /* __PJ _STUN_ENDPOINT_H__ */116 #endif /* __PJLIB_UTIL_STUN_ENDPOINT_H__ */ 117 117 -
pjproject/trunk/pjlib-util/include/pjlib-util/stun_msg.h
r1052 r1053 17 17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 18 */ 19 #ifndef __PJ _STUN_MSG_H__20 #define __PJ _STUN_MSG_H__19 #ifndef __PJLIB_UTIL_STUN_MSG_H__ 20 #define __PJLIB_UTIL_STUN_MSG_H__ 21 21 22 22 /** … … 1530 1530 1531 1531 1532 #endif /* __PJ _STUN_MSG_H__ */1533 1532 #endif /* __PJLIB_UTIL_STUN_MSG_H__ */ 1533 -
pjproject/trunk/pjlib-util/include/pjlib-util/stun_session.h
r1052 r1053 56 56 * Callback to be called by the STUN session to send outgoing message. 57 57 * 58 * @param tdata The STUN transmit data containing the original 59 * STUN message 58 * @param sess The STUN session. 60 59 * @param pkt Packet to be sent. 61 60 * @param pkt_size Size of the packet to be sent. 61 * @param dst_addr The destination address. 62 62 * @param addr_len Length of destination address. 63 * @param dst_addr The destination address.64 63 * 65 64 * @return The callback should return the status of the -
pjproject/trunk/pjlib-util/include/pjlib-util/stun_transaction.h
r996 r1053 17 17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 18 */ 19 #ifndef __PJ _STUN_TRANSACTION_H__20 #define __PJ _STUN_TRANSACTION_H__19 #ifndef __PJLIB_UTIL_STUN_TRANSACTION_H__ 20 #define __PJLIB_UTIL_STUN_TRANSACTION_H__ 21 21 22 22 /** … … 214 214 215 215 216 #endif /* __PJ _STUN_TRANSACTION_H__ */217 216 #endif /* __PJLIB_UTIL_STUN_TRANSACTION_H__ */ 217 -
pjproject/trunk/pjlib-util/src/pjlib-util/stun_msg.c
r1052 r1053 406 406 }, 407 407 { 408 /* Unassigned, 0x8025*/408 /* ID 0x8025 is not assigned*/ 409 409 NULL, 410 410 NULL, … … 412 412 }, 413 413 { 414 /* P adding, 0x8026 */414 /* PADDING, 0x8026 */ 415 415 NULL, 416 416 NULL, … … 418 418 }, 419 419 { 420 /* Padding, 0x8027 */420 /* CACHE-TIMEOUT, 0x8027 */ 421 421 NULL, 422 422 NULL, -
pjproject/trunk/pjlib-util/src/pjstun-client/client_main.c
r1052 r1053 22 22 23 23 #define THIS_FILE "client_main.c" 24 #define BANDWIDTH 64 /* -1 to disable */ 25 #define LIFETIME 30 /* -1 to disable */ 26 #define REQ_TRANSPORT -1 /* 0: udp, 1: tcp, -1: disable */ 27 #define REQ_PORT_PROPS -1 /* -1 to disable */ 28 #define REQ_IP NULL /* IP address string */ 29 24 30 25 31 static struct global … … 33 39 pj_thread_t *thread; 34 40 pj_bool_t quit; 35 36 pj_sockaddr_in dst_addr; /**< destinationaddr */41 pj_sockaddr_in peer_addr; 42 pj_sockaddr_in srv_addr; /**< server addr */ 37 43 38 44 } g; … … 40 46 static struct options 41 47 { 42 char * dst_addr;43 char * dst_port;48 char *srv_addr; 49 char *srv_port; 44 50 char *realm; 45 51 char *user_name; … … 61 67 const void *pkt, 62 68 pj_size_t pkt_size, 63 const pj_sockaddr_t * dst_addr,69 const pj_sockaddr_t *srv_addr, 64 70 unsigned addr_len) 65 71 { … … 68 74 69 75 len = pkt_size; 70 status = pj_sock_sendto(g.sock, pkt, &len, 0, dst_addr, addr_len);76 status = pj_sock_sendto(g.sock, pkt, &len, 0, srv_addr, addr_len); 71 77 72 78 if (status != PJ_SUCCESS) … … 142 148 pj_caching_pool_init(&g.cp, &pj_pool_factory_default_policy, 0); 143 149 144 if (o. dst_addr) {150 if (o.srv_addr) { 145 151 pj_str_t s; 146 152 pj_uint16_t port; 147 153 148 if (o. dst_port)149 port = (pj_uint16_t) atoi(o. dst_port);154 if (o.srv_port) 155 port = (pj_uint16_t) atoi(o.srv_port); 150 156 else 151 157 port = PJ_STUN_PORT; 152 158 153 status = pj_sockaddr_in_init(&g. dst_addr, pj_cstr(&s, o.dst_addr), port);159 status = pj_sockaddr_in_init(&g.srv_addr, pj_cstr(&s, o.srv_addr), port); 154 160 if (status != PJ_SUCCESS) { 155 161 my_perror("Invalid address", status); … … 157 163 } 158 164 159 printf("Destination address set to %s:%d\n", o. dst_addr, (int)port);165 printf("Destination address set to %s:%d\n", o.srv_addr, (int)port); 160 166 } else { 161 167 printf("Error: address must be specified\n"); … … 246 252 247 253 rc = pj_stun_session_send_msg(g.sess, PJ_FALSE, 248 &g. dst_addr, sizeof(g.dst_addr),254 &g.srv_addr, sizeof(g.srv_addr), 249 255 tdata); 250 256 if (rc != PJ_SUCCESS) … … 252 258 } 253 259 254 static void send_allocate_request(void) 255 { 256 } 257 258 static void send_sad_request(void) 259 { 260 static void send_allocate_request(pj_bool_t allocate) 261 { 262 pj_stun_tx_data *tdata; 263 pj_status_t rc; 264 265 rc = pj_stun_session_create_req(g.sess, PJ_STUN_ALLOCATE_REQUEST, &tdata); 266 pj_assert(rc == PJ_SUCCESS); 267 268 269 if (BANDWIDTH != -1) { 270 pj_stun_msg_add_uint_attr(tdata->pool, tdata->msg, 271 PJ_STUN_ATTR_BANDWIDTH, BANDWIDTH); 272 } 273 274 if (!allocate) { 275 pj_stun_msg_add_uint_attr(tdata->pool, tdata->msg, 276 PJ_STUN_ATTR_LIFETIME, 0); 277 278 } else { 279 if (LIFETIME != -1) { 280 pj_stun_msg_add_uint_attr(tdata->pool, tdata->msg, 281 PJ_STUN_ATTR_LIFETIME, LIFETIME); 282 } 283 284 if (REQ_TRANSPORT != -1) { 285 pj_stun_msg_add_uint_attr(tdata->pool, tdata->msg, 286 PJ_STUN_ATTR_REQ_TRANSPORT, REQ_TRANSPORT); 287 } 288 289 if (REQ_PORT_PROPS != -1) { 290 pj_stun_msg_add_uint_attr(tdata->pool, tdata->msg, 291 PJ_STUN_ATTR_REQ_PORT_PROPS, REQ_PORT_PROPS); 292 } 293 294 if (REQ_IP != NULL) { 295 pj_sockaddr_in addr; 296 pj_str_t tmp; 297 298 pj_sockaddr_in_init(&addr, pj_cstr(&tmp, REQ_IP), 0); 299 pj_stun_msg_add_ip_addr_attr(tdata->pool, tdata->msg, 300 PJ_STUN_ATTR_REQ_IP, PJ_FALSE, 301 &addr, sizeof(addr)); 302 } 303 } 304 305 rc = pj_stun_session_send_msg(g.sess, PJ_FALSE, 306 &g.srv_addr, sizeof(g.srv_addr), 307 tdata); 308 pj_assert(rc == PJ_SUCCESS); 309 } 310 311 static void send_sad_request(pj_bool_t set) 312 { 313 pj_stun_tx_data *tdata; 314 pj_status_t rc; 315 316 if (g.peer_addr.sin_addr.s_addr == 0 || 317 g.peer_addr.sin_port == 0) 318 { 319 puts("Error: peer address is not set"); 320 return; 321 } 322 323 rc = pj_stun_session_create_req(g.sess, PJ_STUN_ALLOCATE_REQUEST, &tdata); 324 pj_assert(rc == PJ_SUCCESS); 325 326 if (set) { 327 pj_stun_msg_add_ip_addr_attr(tdata->pool, tdata->msg, 328 PJ_STUN_ATTR_REMOTE_ADDR, PJ_FALSE, 329 &g.peer_addr, sizeof(g.peer_addr)); 330 } 331 332 rc = pj_stun_session_send_msg(g.sess, PJ_FALSE, 333 &g.srv_addr, sizeof(g.srv_addr), 334 tdata); 335 pj_assert(rc == PJ_SUCCESS); 260 336 } 261 337 … … 268 344 } 269 345 346 static void set_peer_addr(void) 347 { 348 char ip_addr[64]; 349 pj_str_t tmp; 350 pj_sockaddr_in addr; 351 int port; 352 353 printf("Current peer address: %s:%d\n", 354 pj_inet_ntoa(g.peer_addr.sin_addr), 355 pj_ntohs(g.peer_addr.sin_port)); 356 357 printf("Input peer address in IP:PORT format: "); 358 fflush(stdout); 359 360 if (scanf("%s:%d", ip_addr, &port) != 2) { 361 puts("Error."); 362 return; 363 } 364 365 if (pj_sockaddr_in_init(&addr, pj_cstr(&tmp,ip_addr), (pj_uint16_t)port) != PJ_SUCCESS) { 366 puts("Error: invalid address"); 367 return; 368 } 369 370 g.peer_addr = addr; 371 } 372 270 373 static void menu(void) 271 374 { 272 375 puts("Menu:"); 376 printf(" pr Set peer address (currently %s:%d)\n", 377 pj_inet_ntoa(g.peer_addr.sin_addr), pj_ntohs(g.peer_addr.sin_port)); 378 puts(""); 273 379 puts(" br Send Bind request"); 274 380 puts(" ar Send Allocate request"); 381 puts(" dr Send de-Allocate request"); 275 382 puts(" sr Send Set Active Indication request"); 276 puts(" si Send Send Indication"); 383 puts(" cr Send clear Active Indication request"); 384 puts(" si Send data with Send Indication"); 277 385 puts(" rw Send raw data"); 278 386 puts(" q Quit"); … … 281 389 } 282 390 391 283 392 static void console_main(void) 284 393 { … … 294 403 295 404 } else if (input[0]=='a' && input[1]=='r') { 296 send_allocate_request(); 405 send_allocate_request(PJ_TRUE); 406 407 } else if (input[0]=='d' && input[1]=='r') { 408 send_allocate_request(PJ_FALSE); 297 409 298 410 } else if (input[0]=='s' && input[1]=='r') { 299 send_sad_request(); 411 send_sad_request(PJ_TRUE); 412 413 } else if (input[0]=='c' && input[1]=='r') { 414 send_sad_request(PJ_FALSE); 300 415 301 416 } else if (input[0]=='s' && input[1]=='i') { … … 304 419 } else if (input[0]=='r' && input[1]=='w') { 305 420 send_raw_data(); 421 422 } else if (input[0]=='p' && input[1]=='r') { 423 set_peer_addr(); 306 424 307 425 } else if (input[0]=='q') { … … 374 492 375 493 if ((pos=pj_ansi_strchr(argv[pj_optind], ':')) != NULL) { 376 o. dst_addr = argv[pj_optind];494 o.srv_addr = argv[pj_optind]; 377 495 *pos = '\0'; 378 o. dst_port = pos+1;496 o.srv_port = pos+1; 379 497 } else { 380 o. dst_addr = argv[pj_optind];498 o.srv_addr = argv[pj_optind]; 381 499 } 382 500 -
pjproject/trunk/pjlib-util/src/pjstun-srv-test/turn_usage.c
r1052 r1053 90 90 pj_stun_session *session; 91 91 pj_mutex_t *mutex; 92 93 /* Socket and socket address of the allocated port */ 92 94 int sock_type; 93 94 /* Socket and socket address of the allocated port */95 95 pj_sock_t sock; 96 96 pj_ioqueue_key_t *key; … … 504 504 pj_uint32_t hval); 505 505 506 static const char *get_tp_type(int type) 507 { 508 if (type==0) 509 return "udp"; 510 else if (type==1) 511 return "tcp"; 512 else 513 return "???"; 514 } 515 506 516 507 517 /* … … 576 586 const pj_sockaddr_in *a4 = (const pj_sockaddr_in *)src_addr; 577 587 pj_ansi_snprintf(client->obj_name, sizeof(client->obj_name), 578 "%s:%d", 588 "%s:%s:%d", 589 get_tp_type(tu->type), 579 590 pj_inet_ntoa(a4->sin_addr), 580 591 (int)pj_ntohs(a4->sin_port)); … … 586 597 sess_cb.on_send_msg = &client_sess_on_send_msg; 587 598 sess_cb.on_rx_request = &client_sess_on_rx_request; 588 status = pj_stun_session_create(tu->endpt, "turnc%p", &sess_cb, PJ_FALSE, 599 status = pj_stun_session_create(tu->endpt, client->obj_name, 600 &sess_cb, PJ_FALSE, 589 601 &client->session); 590 602 if (status != PJ_SUCCESS) { … … 599 611 600 612 /* Mutex */ 601 status = pj_mutex_create_recursive(client->pool, pool->obj_name, 613 status = pj_mutex_create_recursive(client->pool, pool->obj_name, 602 614 &client->mutex); 603 615 if (status != PJ_SUCCESS) { … … 693 705 { 694 706 pj_ioqueue_callback client_ioq_cb; 707 int addrlen; 695 708 pj_status_t status; 709 710 /* Update address */ 711 addrlen = sizeof(pj_sockaddr_in); 712 status = pj_sock_getsockname(client->sock, &client->client_addr, 713 &addrlen); 714 if (status != PJ_SUCCESS) { 715 pj_sock_close(client->sock); 716 client->sock = PJ_INVALID_SOCKET; 717 return status; 718 } 696 719 697 720 /* Register to ioqueue */ … … 715 738 client_on_read_complete(client->key, &client->pkt_read_key, 0); 716 739 740 PJ_LOG(4,(THIS_FILE, "TURN client %s: relay allocated on %s:%s:%d", 741 client->obj_name, 742 get_tp_type(client->sock_type), 743 pj_inet_ntoa(client->client_addr.sin_addr), 744 (int)pj_ntohs(client->client_addr.sin_port))); 745 717 746 return PJ_SUCCESS; 718 747 } … … 735 764 } 736 765 737 PJ_LOG(4,(THIS_FILE, "TURN client %s: relay allocation %s:% d destroyed",766 PJ_LOG(4,(THIS_FILE, "TURN client %s: relay allocation %s:%s:%d destroyed", 738 767 client->obj_name, 768 get_tp_type(client->sock_type), 739 769 pj_inet_ntoa(client->client_addr.sin_addr), 740 770 (int)pj_ntohs(client->client_addr.sin_port))); … … 772 802 773 803 PJ_LOG(4,(THIS_FILE, "TURN client %s: peer %s:%s:%d added", 774 client->obj_name, "udp", pj_inet_ntoa(peer_addr->sin_addr), 804 client->obj_name, get_tp_type(client->sock_type), 805 pj_inet_ntoa(peer_addr->sin_addr), 775 806 (int)pj_ntohs(peer_addr->sin_port))); 776 807 … … 825 856 pj_sockaddr_in req_addr; 826 857 int addr_len; 827 unsigned r pp_bits;858 unsigned req_bw, rpp_bits; 828 859 pj_time_val timeout; 829 860 pj_status_t status; … … 849 880 return PJ_SUCCESS; 850 881 } else if (a_bw) { 851 client->bw_kbps = a_bw->value;882 client->bw_kbps = req_bw = a_bw->value; 852 883 } else { 884 req_bw = 0; 853 885 client->bw_kbps = client->tu->max_bw_kbps; 854 886 } … … 900 932 901 933 PJ_LOG(4,(THIS_FILE, "TURN client %s: received initial Allocate " 902 "request, requested type:addr:port=% d:%s:%d, rpp "903 "bits=%d ",904 client->obj_name, client->sock_type,934 "request, requested type:addr:port=%s:%s:%d, rpp " 935 "bits=%d, bw=%dkbps, lifetime=%d", 936 client->obj_name, get_tp_type(client->sock_type), 905 937 pj_inet_ntoa(req_addr.sin_addr), pj_ntohs(req_addr.sin_port), 906 rpp_bits ));938 rpp_bits, client->bw_kbps, client->lifetime)); 907 939 908 940 status = tu_alloc_port(client->tu, client->sock_type, rpp_bits, … … 931 963 /* Otherwise check if the port parameter stays the same */ 932 964 /* TODO */ 933 PJ_LOG(4,(THIS_FILE, "TURN client %s: received Allocate refresh", 934 client->obj_name)); 965 PJ_LOG(4,(THIS_FILE, "TURN client %s: received Allocate refresh, " 966 "lifetime=%d", 967 client->obj_name, client->lifetime)); 935 968 } 936 969 … … 970 1003 971 1004 PJ_LOG(4,(THIS_FILE, "TURN client %s: relay allocated or refreshed, " 972 "internal address is %s:% d",1005 "internal address is %s:%s:%d", 973 1006 client->obj_name, 1007 get_tp_type(client->sock_type), 974 1008 pj_inet_ntoa(req_addr.sin_addr), 975 1009 (int)pj_ntohs(req_addr.sin_port)));
Note: See TracChangeset
for help on using the changeset viewer.