Changeset 1879
- Timestamp:
- Mar 20, 2008 4:32:06 PM (17 years ago)
- Location:
- pjproject/trunk/pjnath/src
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjnath/src/pjnath/stun_session.c
r1877 r1879 268 268 *notify_user = PJ_TRUE; 269 269 270 if (response==NULL) 271 return PJ_SUCCESS; 272 270 273 if (sess->auth_type != PJ_STUN_AUTH_LONG_TERM) 271 274 return PJ_SUCCESS; -
pjproject/trunk/pjnath/src/pjnath/turn_session.c
r1877 r1879 189 189 sess->ka_interval = PJ_TURN_KEEP_ALIVE_SEC; 190 190 sess->user_data = user_data; 191 sess->next_ch = PJ_TURN_CHANNEL_MIN; 191 192 192 193 /* Copy callback */ … … 326 327 /* Send REFRESH with LIFETIME=0 */ 327 328 can_destroy = PJ_FALSE; 328 se ss->pending_destroy = PJ_TRUE;329 send_refresh(sess, 0); 329 330 break; 330 331 case PJ_TURN_STATE_DEALLOCATING: … … 779 780 pj_stun_msg_add_uint_attr(tdata->pool, tdata->msg, 780 781 PJ_STUN_ATTR_CHANNEL_NUMBER, 781 PJ_STUN_SET_CH_NB( sess->next_ch));782 PJ_STUN_SET_CH_NB(ch_num)); 782 783 783 784 /* Add PEER-ADDRESS attribute */ … … 1024 1025 1025 1026 /* Save relayed address */ 1026 pj_memcpy(&sess->relay_addr, &raddr_attr->sockaddr, sizeof(pj_sockaddr)); 1027 if (raddr_attr) { 1028 /* If we already have relay address, check if the relay address 1029 * in the response matches our relay address. 1030 */ 1031 if (pj_sockaddr_has_addr(&sess->relay_addr)) { 1032 if (pj_sockaddr_cmp(&sess->relay_addr, &raddr_attr->sockaddr)) { 1033 on_session_fail(sess, method, PJNATH_EINSTUNMSG, 1034 pj_cstr(&s, "Error: different RELAY-ADDRESS is" 1035 "returned by server")); 1036 return; 1037 } 1038 } else { 1039 /* Otherwise save the relayed address */ 1040 pj_memcpy(&sess->relay_addr, &raddr_attr->sockaddr, 1041 sizeof(pj_sockaddr)); 1042 } 1043 } 1027 1044 1028 1045 /* Success */ … … 1181 1198 pj_stun_data_attr *data_attr; 1182 1199 1200 PJ_UNUSED_ARG(pkt); 1201 PJ_UNUSED_ARG(pkt_len); 1183 1202 PJ_UNUSED_ARG(src_addr); 1184 1203 PJ_UNUSED_ARG(src_addr_len); … … 1210 1229 /* Notify application */ 1211 1230 if (sess->cb.on_rx_data) { 1212 (*sess->cb.on_rx_data)(sess, pkt, pkt_len,1231 (*sess->cb.on_rx_data)(sess, data_attr->data, data_attr->length, 1213 1232 &peer_attr->sockaddr, 1214 1233 pj_sockaddr_get_len(&peer_attr->sockaddr)); … … 1299 1318 1300 1319 if (bind_channel) { 1320 pj_uint32_t hval = 0; 1301 1321 /* Register by channel number */ 1302 1322 pj_assert(peer->ch_id != PJ_TURN_INVALID_CHANNEL && peer->bound); 1303 pj_assert(pj_hash_get(sess->peer_table, &peer->ch_id, 1304 sizeof(peer->ch_id), NULL)==0); 1305 1306 pj_hash_set(sess->pool, sess->peer_table, &peer->ch_id, 1307 sizeof(peer->ch_id), 0, peer); 1323 1324 if (pj_hash_get(sess->peer_table, &peer->ch_id, 1325 sizeof(peer->ch_id), &hval)==0) { 1326 pj_hash_set(sess->pool, sess->peer_table, &peer->ch_id, 1327 sizeof(peer->ch_id), hval, peer); 1328 } 1308 1329 } 1309 1330 } … … 1406 1427 delay.msec = 0; 1407 1428 1429 sess->timer.id = TIMER_KEEP_ALIVE; 1408 1430 pj_timer_heap_schedule(sess->timer_heap, &sess->timer, &delay); 1409 1431 } … … 1415 1437 pj_lock_release(sess->lock); 1416 1438 do_destroy(sess); 1417 } 1418 } 1419 1439 } else { 1440 pj_assert(!"Unknown timer event"); 1441 pj_lock_release(sess->lock); 1442 } 1443 } 1444 -
pjproject/trunk/pjnath/src/pjnath/turn_udp.c
r1869 r1879 20 20 #include <pj/assert.h> 21 21 #include <pj/errno.h> 22 #include <pj/lock.h> 22 23 #include <pj/log.h> 23 24 #include <pj/pool.h> 24 25 #include <pj/ioqueue.h> 26 27 enum 28 { 29 TIMER_NONE, 30 TIMER_DESTROY 31 }; 25 32 26 33 struct pj_turn_udp … … 30 37 pj_turn_udp_cb cb; 31 38 void *user_data; 39 40 pj_lock_t *lock; 41 42 pj_bool_t destroy_request; 43 pj_timer_heap_t *timer_heap; 44 pj_timer_entry timer; 32 45 33 46 pj_sock_t sock; … … 65 78 66 79 80 static void destroy(pj_turn_udp *udp_rel); 81 static void timer_cb(pj_timer_heap_t *th, pj_timer_entry *e); 82 83 67 84 /* 68 85 * Create. … … 92 109 if (cb) { 93 110 pj_memcpy(&udp_rel->cb, cb, sizeof(*cb)); 111 } 112 113 /* Create lock */ 114 status = pj_lock_create_recursive_mutex(pool, pool->obj_name, 115 &udp_rel->lock); 116 if (status != PJ_SUCCESS) { 117 destroy(udp_rel); 118 return status; 119 } 120 121 /* Init timer */ 122 udp_rel->timer_heap = cfg->timer_heap; 123 pj_timer_entry_init(&udp_rel->timer, TIMER_NONE, udp_rel, &timer_cb); 124 125 /* Init socket */ 126 status = pj_sock_socket(af, pj_SOCK_DGRAM(), 0, &udp_rel->sock); 127 if (status != PJ_SUCCESS) { 128 destroy(udp_rel); 129 return status; 130 } 131 132 /* Bind to any */ 133 pj_sockaddr_init(af, &udp_rel->src_addr, NULL, 0); 134 status = pj_sock_bind(udp_rel->sock, &udp_rel->src_addr, 135 pj_sockaddr_get_len(&udp_rel->src_addr)); 136 if (status != PJ_SUCCESS) { 137 destroy(udp_rel); 138 return status; 139 } 140 141 /* Register to ioqeuue */ 142 pj_bzero(&ioq_cb, sizeof(ioq_cb)); 143 ioq_cb.on_read_complete = &on_read_complete; 144 status = pj_ioqueue_register_sock(udp_rel->pool, cfg->ioqueue, 145 udp_rel->sock, udp_rel, 146 &ioq_cb, &udp_rel->key); 147 if (status != PJ_SUCCESS) { 148 destroy(udp_rel); 149 return status; 94 150 } 95 151 … … 103 159 &sess_cb, udp_rel, 0, &udp_rel->sess); 104 160 if (status != PJ_SUCCESS) { 105 pj_turn_udp_destroy(udp_rel); 106 return status; 107 } 108 109 /* Init socket */ 110 status = pj_sock_socket(af, pj_SOCK_DGRAM(), 0, &udp_rel->sock); 111 if (status != PJ_SUCCESS) { 112 pj_turn_udp_destroy(udp_rel); 113 return status; 114 } 115 116 /* Bind to any */ 117 pj_sockaddr_init(af, &udp_rel->src_addr, NULL, 0); 118 status = pj_sock_bind(udp_rel->sock, &udp_rel->src_addr, 119 pj_sockaddr_get_len(&udp_rel->src_addr)); 120 if (status != PJ_SUCCESS) { 121 pj_turn_udp_destroy(udp_rel); 122 return status; 123 } 124 125 /* Register to ioqeuue */ 126 pj_bzero(&ioq_cb, sizeof(ioq_cb)); 127 ioq_cb.on_read_complete = &on_read_complete; 128 status = pj_ioqueue_register_sock(udp_rel->pool, cfg->ioqueue, 129 udp_rel->sock, udp_rel, 130 &ioq_cb, &udp_rel->key); 131 if (status != PJ_SUCCESS) { 132 pj_turn_udp_destroy(udp_rel); 161 destroy(udp_rel); 133 162 return status; 134 163 } … … 145 174 * Destroy. 146 175 */ 147 PJ_DEF(void) pj_turn_udp_destroy(pj_turn_udp *udp_rel) 148 { 176 static void destroy(pj_turn_udp *udp_rel) 177 { 178 if (udp_rel->lock) { 179 pj_lock_acquire(udp_rel->lock); 180 } 181 149 182 if (udp_rel->sess) { 183 pj_turn_session_set_user_data(udp_rel->sess, NULL); 150 184 pj_turn_session_destroy(udp_rel->sess); 151 185 udp_rel->sess = NULL; 186 } 187 188 if (udp_rel->key) { 189 pj_ioqueue_unregister(udp_rel->key); 190 udp_rel->key = NULL; 191 udp_rel->sock = 0; 192 } else if (udp_rel->sock) { 193 pj_sock_close(udp_rel->sock); 194 udp_rel->sock = 0; 195 } 196 197 if (udp_rel->lock) { 198 pj_lock_release(udp_rel->lock); 199 pj_lock_destroy(udp_rel->lock); 200 udp_rel->lock = NULL; 152 201 } 153 202 … … 158 207 } 159 208 } 209 210 PJ_DEF(void) pj_turn_udp_destroy(pj_turn_udp *udp_rel) 211 { 212 pj_lock_acquire(udp_rel->lock); 213 udp_rel->destroy_request = PJ_TRUE; 214 215 if (udp_rel->sess) { 216 pj_turn_session_destroy(udp_rel->sess); 217 /* This will ultimately call our state callback, and when 218 * session state is DESTROYING we will schedule a timer to 219 * destroy ourselves. 220 */ 221 pj_lock_release(udp_rel->lock); 222 } else { 223 pj_lock_release(udp_rel->lock); 224 destroy(udp_rel); 225 } 226 227 } 228 229 /* Timer callback */ 230 static void timer_cb(pj_timer_heap_t *th, pj_timer_entry *e) 231 { 232 pj_turn_udp *udp_rel = (pj_turn_udp*)e->user_data; 233 int eid = e->id; 234 235 PJ_UNUSED_ARG(th); 236 237 e->id = TIMER_NONE; 238 239 switch (eid) { 240 case TIMER_DESTROY: 241 destroy(udp_rel); 242 break; 243 default: 244 pj_assert(!"Invalid timer id"); 245 break; 246 } 247 } 248 160 249 161 250 /* … … 272 361 273 362 udp_rel = (pj_turn_udp*) pj_ioqueue_get_user_data(key); 363 pj_lock_acquire(udp_rel->lock); 274 364 275 365 do { … … 301 391 ++retry < MAX_RETRY); 302 392 393 pj_lock_release(udp_rel->lock); 303 394 } 304 395 … … 317 408 pj_ssize_t len = pkt_len; 318 409 410 if (udp_rel == NULL) { 411 /* We've been destroyed */ 412 pj_assert(!"We should shutdown gracefully"); 413 return PJ_EINVALIDOP; 414 } 415 319 416 return pj_sock_sendto(udp_rel->sock, pkt, &len, 0, 320 417 dst_addr, dst_addr_len); … … 348 445 pj_turn_udp *udp_rel = (pj_turn_udp*) 349 446 pj_turn_session_get_user_data(sess); 447 if (udp_rel == NULL) { 448 /* We've been destroyed */ 449 return; 450 } 451 350 452 if (udp_rel->cb.on_rx_data) { 351 453 (*udp_rel->cb.on_rx_data)(udp_rel, pkt, pkt_len, … … 364 466 pj_turn_udp *udp_rel = (pj_turn_udp*) 365 467 pj_turn_session_get_user_data(sess); 468 if (udp_rel == NULL) { 469 /* We've been destroyed */ 470 return; 471 } 472 366 473 if (udp_rel->cb.on_state) { 367 474 (*udp_rel->cb.on_state)(udp_rel, old_state, new_state); 368 475 } 369 476 370 if (new_state > PJ_TURN_STATE_READY) { 371 udp_rel->sess = NULL; 372 } 373 } 374 375 477 if (new_state >= PJ_TURN_STATE_DESTROYING && udp_rel->sess) { 478 if (udp_rel->destroy_request) { 479 pj_time_val delay = {0, 0}; 480 481 pj_turn_session_set_user_data(udp_rel->sess, NULL); 482 483 udp_rel->timer.id = TIMER_DESTROY; 484 pj_timer_heap_schedule(udp_rel->timer_heap, &udp_rel->timer, 485 &delay); 486 } else { 487 udp_rel->sess = NULL; 488 } 489 } 490 } 491 492 -
pjproject/trunk/pjnath/src/pjturn-client/client_main.c
r1869 r1879 62 62 char *user_name; 63 63 char *password; 64 char *nonce;65 64 pj_bool_t use_fingerprint; 66 65 } o; … … 136 135 137 136 CHECK( pj_gethostip(pj_AF_INET(), &g.peer[i].addr) ); 138 pj_sockaddr_set_port(&g.peer[ 0].addr, port);137 pj_sockaddr_set_port(&g.peer[i].addr, port); 139 138 140 139 } … … 266 265 cred.data.static_cred.data_type = 0; 267 266 cred.data.static_cred.data = pj_str(o.password); 268 cred.data.static_cred.nonce = pj_str(o.nonce);267 //cred.data.static_cred.nonce = pj_str(o.nonce); 269 268 } else { 270 269 PJ_LOG(2,(THIS_FILE, "Warning: no credential is set")); … … 287 286 if (g.udp_rel) { 288 287 pj_turn_udp_destroy(g.udp_rel); 289 g.udp_rel = NULL;290 288 } 291 289 } … … 310 308 pj_turn_state_t new_state) 311 309 { 310 PJ_LOG(3,(THIS_FILE, "State %s --> %s", pj_turn_state_name(old_state), 311 pj_turn_state_name(new_state))); 312 312 313 if (new_state == PJ_TURN_STATE_READY) { 313 314 pj_turn_session_info info; 314 315 pj_turn_udp_get_info(udp_rel, &info); 315 316 pj_memcpy(&g.relay_addr, &info.relay_addr, sizeof(pj_sockaddr)); 317 } else if (new_state > PJ_TURN_STATE_READY && g.udp_rel) { 318 PJ_LOG(3,(THIS_FILE, "Relay shutting down..")); 319 g.udp_rel = NULL; 316 320 } 317 321 } … … 380 384 relay_addr); 381 385 puts("| | 0 Send data to relay address |"); 382 puts("| AAllocate relay +--------------------------------+ ");383 puts("| S[01]Send data to peer 0/1 | PEER-1 |");384 puts("| B[01]BindChannel to peer 0/1 | |");385 printf("| XDelete allocation | Address: %-21s |\n",386 puts("| a Allocate relay +--------------------------------+ "); 387 puts("| s,ss Send data to peer 0/1 | PEER-1 |"); 388 puts("| b,bb BindChannel to peer 0/1 | |"); 389 printf("| x Delete allocation | Address: %-21s |\n", 386 390 peer1_addr); 387 391 puts("+-----------------------------------+ |"); … … 406 410 407 411 switch (input[0]) { 408 case ' A':412 case 'a': 409 413 create_relay(); 410 414 break; 411 case ' S':415 case 's': 412 416 if (g.udp_rel == NULL) { 413 417 puts("Error: no relay"); 414 418 continue; 415 419 } 416 if (input[1] != '0' && input[1] != '1') {417 p uts("Usage: S0 or S1");418 continue;419 }420 peer = &g.peer[input[1]-'0']; 420 if (input[1]!='s') 421 peer = &g.peer[0]; 422 else 423 peer = &g.peer[1]; 424 421 425 strcpy(input, "Hello from client"); 422 426 status = pj_turn_udp_sendto(g.udp_rel, input, strlen(input)+1, … … 426 430 my_perror("turn_udp_sendto() failed", status); 427 431 break; 428 case ' B':432 case 'b': 429 433 if (g.udp_rel == NULL) { 430 434 puts("Error: no relay"); 431 435 continue; 432 436 } 433 if (input[1] != '0' && input[1] != '1') {434 p uts("Usage: B0 or B1");435 continue;436 }437 peer = &g.peer[input[1]-'0']; 437 if (input[1]!='b') 438 peer = &g.peer[0]; 439 else 440 peer = &g.peer[1]; 441 438 442 status = pj_turn_udp_bind_channel(g.udp_rel, &peer->addr, 439 443 pj_sockaddr_get_len(&peer->addr)); … … 441 445 my_perror("turn_udp_bind_channel() failed", status); 442 446 break; 443 case ' X':447 case 'x': 444 448 if (g.udp_rel == NULL) { 445 449 puts("Error: no relay"); … … 450 454 case '0': 451 455 case '1': 452 peer = &g.peer[input[ 1]-'0'];456 peer = &g.peer[input[0]-'0']; 453 457 sprintf(input, "Hello from peer%d", input[0]-'0'); 454 458 len = strlen(input)+1; … … 474 478 puts(" --username, -u Set username of the credential"); 475 479 puts(" --password, -p Set password of the credential"); 476 puts(" --nonce, -N Set NONCE");477 480 puts(" --fingerprint, -F Use fingerprint for outgoing requests"); 478 481 puts(" --help, -h"); … … 485 488 { "username", 1, 0, 'u'}, 486 489 { "password", 1, 0, 'p'}, 487 { "nonce", 1, 0, 'N'},488 490 { "fingerprint",0, 0, 'F'}, 489 491 { "data", 1, 0, 'D'}, … … 505 507 o.password = pj_optarg; 506 508 break; 507 case 'N':508 o.nonce = pj_optarg;509 break;510 509 case 'h': 511 510 usage(); … … 538 537 goto on_return; 539 538 540 if ((status=create_relay()) != 0)541 goto on_return;539 //if ((status=create_relay()) != 0) 540 // goto on_return; 542 541 543 542 console_main(); -
pjproject/trunk/pjnath/src/pjturn-srv/allocation.c
r1877 r1879 669 669 if (status != PJ_SUCCESS) { 670 670 /* Unable to allocate port */ 671 PJ_LOG(4,(THIS_FILE, " bind() failed: err %d",671 PJ_LOG(4,(THIS_FILE, "Unable to allocate relay, giving up: err %d", 672 672 status)); 673 673 pj_sock_close(relay->tp.sock); … … 689 689 pj_sockaddr_copy_addr(&relay->hkey.addr, &alloc->listener->addr); 690 690 } 691 if (!pj_sockaddr_has_addr(&relay->hkey.addr)) { 692 pj_sockaddr tmp_addr; 693 pj_gethostip(af, &tmp_addr); 694 pj_sockaddr_copy_addr(&relay->hkey.addr, &tmp_addr); 695 } 691 696 692 697 /* Init ioqueue */ … … 752 757 } 753 758 754 /* Add LIFETIME. */ 755 pj_stun_msg_add_uint_attr(tdata->pool, tdata->msg, 756 PJ_STUN_ATTR_LIFETIME, interval); 757 758 /* Add BANDWIDTH */ 759 pj_stun_msg_add_uint_attr(tdata->pool, tdata->msg, 760 PJ_STUN_ATTR_BANDWIDTH, 761 alloc->bandwidth); 759 /* Add LIFETIME if this is not ChannelBind. */ 760 if (PJ_STUN_GET_METHOD(tdata->msg->hdr.type)!=PJ_STUN_CHANNEL_BIND_METHOD){ 761 pj_stun_msg_add_uint_attr(tdata->pool, tdata->msg, 762 PJ_STUN_ATTR_LIFETIME, interval); 763 764 /* Add BANDWIDTH if lifetime is not zero */ 765 if (interval != 0) { 766 pj_stun_msg_add_uint_attr(tdata->pool, tdata->msg, 767 PJ_STUN_ATTR_BANDWIDTH, 768 alloc->bandwidth); 769 } 770 } 762 771 763 772 status = pj_stun_session_send_msg(alloc->sess, PJ_TRUE, … … 774 783 /* Create new permission */ 775 784 static pj_turn_permission *create_permission(pj_turn_allocation *alloc, 776 const pj_sockaddr_t *peer_addr,777 unsigned addr_len)785 const pj_sockaddr_t *peer_addr, 786 unsigned addr_len) 778 787 { 779 788 pj_turn_permission *perm; … … 795 804 perm->expiry.sec += PJ_TURN_PERM_TIMEOUT; 796 805 806 /* Register to hash table */ 807 pj_hash_set(alloc->pool, alloc->peer_table, &perm->hkey.peer_addr, 808 pj_sockaddr_get_len(&perm->hkey.peer_addr), 0, perm); 809 797 810 return perm; 798 811 } … … 805 818 806 819 pj_gettimeofday(&now); 807 if (PJ_TIME_VAL_ LT(perm->expiry, now)) {820 if (PJ_TIME_VAL_GT(perm->expiry, now)) { 808 821 /* Permission has not expired */ 809 822 return perm; … … 811 824 812 825 /* Remove from permission hash table */ 813 pj_hash_set(NULL, alloc->peer_table, &perm->hkey , sizeof(perm->hkey),814 826 pj_hash_set(NULL, alloc->peer_table, &perm->hkey.peer_addr, 827 pj_sockaddr_get_len(&perm->hkey.peer_addr), 0, NULL); 815 828 816 829 /* Remove from channel hash table, if assigned a channel number */ … … 829 842 unsigned addr_len) 830 843 { 831 pj_turn_permission_key key;832 844 pj_turn_permission *perm; 833 845 834 pj_bzero(&key, sizeof(key));835 pj_memcpy(&key, peer_addr, addr_len);836 837 846 /* Lookup in peer hash table */ 838 perm = (pj_turn_permission*) pj_hash_get(alloc->peer_table, &key,839 sizeof(key), NULL);840 return check_permission_expiry(perm);847 perm = (pj_turn_permission*) pj_hash_get(alloc->peer_table, peer_addr, 848 addr_len, NULL); 849 return perm ? check_permission_expiry(perm) : NULL; 841 850 } 842 851 … … 850 859 851 860 /* Lookup in peer hash table */ 852 perm = (pj_turn_permission*) pj_hash_get(alloc-> peer_table, &chnum16,861 perm = (pj_turn_permission*) pj_hash_get(alloc->ch_table, &chnum16, 853 862 sizeof(chnum16), NULL); 854 return check_permission_expiry(perm);863 return perm ? check_permission_expiry(perm) : NULL; 855 864 } 856 865 … … 931 940 /* Discard */ 932 941 PJ_LOG(4,(alloc->obj_name, 933 "ChannelData from %s discarded: not found",934 alloc->info ));942 "ChannelData from %s discarded: ch#0x%x not found", 943 alloc->info, pj_ntohs(cd->ch_number))); 935 944 goto on_return; 936 945 } … … 992 1001 993 1002 /* Copy data */ 994 pj_memcpy(rel->tp. rx_pkt+sizeof(pj_turn_channel_data), pkt, len);1003 pj_memcpy(rel->tp.tx_pkt+sizeof(pj_turn_channel_data), pkt, len); 995 1004 996 1005 /* Send to client */ … … 1010 1019 return; 1011 1020 } 1021 1022 pj_stun_msg_add_sockaddr_attr(tdata->pool, tdata->msg, 1023 PJ_STUN_ATTR_PEER_ADDR, PJ_TRUE, 1024 src_addr, pj_sockaddr_get_len(src_addr)); 1025 pj_stun_msg_add_binary_attr(tdata->pool, tdata->msg, 1026 PJ_STUN_ATTR_DATA, 1027 (const pj_uint8_t*)pkt, len); 1028 1029 pj_stun_session_send_msg(alloc->sess, PJ_FALSE, 1030 &alloc->hkey.clt_addr, 1031 pj_sockaddr_get_len(&alloc->hkey.clt_addr), 1032 tdata); 1012 1033 } 1013 1034 } … … 1187 1208 refresh_permission(p1); 1188 1209 1210 /* Send response */ 1211 send_reply_ok(alloc, rdata); 1212 1189 1213 /* Done */ 1190 1214 return PJ_SUCCESS; … … 1212 1236 /* Assign channel number to permission */ 1213 1237 p2->channel = PJ_STUN_GET_CH_NB(ch_attr->value); 1238 1239 /* Register to hash table */ 1240 pj_assert(sizeof(p2->channel==2)); 1241 pj_hash_set(alloc->pool, alloc->ch_table, &p2->channel, 1242 sizeof(p2->channel), 0, p2); 1214 1243 1215 1244 /* Update */ -
pjproject/trunk/pjnath/src/pjturn-srv/auth.c
r1877 r1879 114 114 * PJ_FALSE, 438 (Stale Nonce) response will be created. 115 115 */ 116 PJ_DEF(pj_ status_t) pj_turn_verify_nonce(const pj_stun_msg *msg,117 118 119 120 116 PJ_DEF(pj_bool_t) pj_turn_verify_nonce(const pj_stun_msg *msg, 117 void *user_data, 118 const pj_str_t *realm, 119 const pj_str_t *username, 120 const pj_str_t *nonce) 121 121 { 122 122 PJ_UNUSED_ARG(msg); … … 128 128 return PJ_FALSE; 129 129 130 return PJ_ SUCCESS;130 return PJ_TRUE; 131 131 } 132 132 -
pjproject/trunk/pjnath/src/pjturn-srv/auth.h
r1877 r1879 106 106 * NONCE can be accepted. 107 107 */ 108 PJ_DECL(pj_ status_t) pj_turn_verify_nonce(const pj_stun_msg *msg,109 110 111 112 108 PJ_DECL(pj_bool_t) pj_turn_verify_nonce(const pj_stun_msg *msg, 109 void *user_data, 110 const pj_str_t *realm, 111 const pj_str_t *username, 112 const pj_str_t *nonce); 113 113 114 114 #endif /* __PJ_TURN_SRV_AUTH_H__ */ -
pjproject/trunk/pjnath/src/pjturn-srv/main.c
r1869 r1879 22 22 #define REALM "pjsip.org" 23 23 24 static pj_caching_pool g_cp; 25 24 26 int err(const char *title, pj_status_t status) 25 27 { … … 31 33 } 32 34 35 static void dump_status(pj_turn_srv *srv) 36 { 37 char addr[80]; 38 pj_hash_iterator_t itbuf, *it; 39 pj_time_val now; 40 unsigned i; 41 42 for (i=0; i<srv->core.lis_cnt; ++i) { 43 pj_turn_listener *lis = srv->core.listener[i]; 44 printf("Server address : %s\n", lis->info); 45 } 46 47 printf("Worker threads : %d\n", srv->core.thread_cnt); 48 printf("Total mem usage: %d.%03dMB\n", g_cp.used_size / 1000000, 49 (g_cp.used_size % 1000000)/1000); 50 printf("UDP port range : %u %u %u (next/min/max)\n", srv->ports.next_udp, 51 srv->ports.min_udp, srv->ports.max_udp); 52 printf("TCP port range : %u %u %u (next/min/max)\n", srv->ports.next_tcp, 53 srv->ports.min_tcp, srv->ports.max_tcp); 54 printf("Clients # : %u\n", pj_hash_count(srv->tables.alloc)); 55 56 puts(""); 57 58 if (pj_hash_count(srv->tables.alloc)==0) { 59 return; 60 } 61 62 puts("# Client addr. Alloc addr. Username Lftm Expy #prm #chl"); 63 puts("------------------------------------------------------------------------------"); 64 65 pj_gettimeofday(&now); 66 67 it = pj_hash_first(srv->tables.alloc, &itbuf); 68 i=1; 69 while (it) { 70 pj_turn_allocation *alloc = (pj_turn_allocation*) 71 pj_hash_this(srv->tables.alloc, it); 72 printf("%-3d %-22s %-22s %-8.*s %-4d %-4d %-4d %-4d\n", 73 i, 74 alloc->info, 75 pj_sockaddr_print(&alloc->relay.hkey.addr, addr, sizeof(addr), 3), 76 (int)alloc->cred.data.static_cred.username.slen, 77 (int)alloc->cred.data.static_cred.username.ptr, 78 alloc->relay.lifetime, 79 alloc->relay.expiry.sec - now.sec, 80 pj_hash_count(alloc->peer_table), 81 pj_hash_count(alloc->ch_table)); 82 it = pj_hash_next(srv->tables.alloc, it); 83 ++i; 84 } 85 } 86 87 static void menu(void) 88 { 89 puts(""); 90 puts("Menu:"); 91 puts(" d Dump status"); 92 puts(" q Quit"); 93 printf(">> "); 94 } 95 96 static void console_main(pj_turn_srv *srv) 97 { 98 pj_bool_t quit = PJ_FALSE; 99 100 while (!quit) { 101 char line[10]; 102 103 menu(); 104 105 fgets(line, sizeof(line), stdin); 106 107 switch (line[0]) { 108 case 'd': 109 dump_status(srv); 110 break; 111 case 'q': 112 quit = PJ_TRUE; 113 break; 114 } 115 } 116 } 117 33 118 int main() 34 119 { 35 pj_caching_pool cp;36 120 pj_turn_srv *srv; 37 121 pj_turn_listener *listener; … … 45 129 pjnath_init(); 46 130 47 pj_caching_pool_init(& cp, NULL, 0);131 pj_caching_pool_init(&g_cp, NULL, 0); 48 132 49 133 pj_turn_auth_init(REALM); 50 134 51 status = pj_turn_srv_create(& cp.factory, &srv);135 status = pj_turn_srv_create(&g_cp.factory, &srv); 52 136 if (status != PJ_SUCCESS) 53 137 return err("Error creating server", status); … … 63 147 64 148 puts("Server is running"); 65 puts("Press <ENTER> to quit");66 149 67 { 68 char line[10]; 69 fgets(line, sizeof(line), stdin); 70 } 150 console_main(srv); 71 151 72 152 pj_turn_srv_destroy(srv); 73 pj_caching_pool_destroy(& cp);153 pj_caching_pool_destroy(&g_cp); 74 154 pj_shutdown(); 75 155 -
pjproject/trunk/pjnath/src/pjturn-srv/server.c
r1877 r1879 136 136 /* Init ports settings */ 137 137 srv->ports.min_udp = srv->ports.next_udp = MIN_PORT; 138 srv->ports.max_ tcp = MAX_PORT;138 srv->ports.max_udp = MAX_PORT; 139 139 srv->ports.min_tcp = srv->ports.next_tcp = MIN_PORT; 140 140 srv->ports.max_tcp = MAX_PORT; … … 266 266 } 267 267 268 /* Destroy all allocations FIRST */ 269 if (srv->tables.alloc) { 270 it = pj_hash_first(srv->tables.alloc, &itbuf); 271 while (it != NULL) { 272 pj_turn_allocation *alloc = (pj_turn_allocation*) 273 pj_hash_this(srv->tables.alloc, it); 274 pj_hash_iterator_t *next = pj_hash_next(srv->tables.alloc, it); 275 pj_turn_allocation_destroy(alloc); 276 it = next; 277 } 278 } 279 268 280 /* Destroy all listeners and STUN sessions associated with them. */ 269 281 for (i=0; i<srv->core.lis_cnt; ++i) { … … 277 289 } 278 290 } 279 280 /* Destroy all allocations */281 if (srv->tables.alloc) {282 it = pj_hash_first(srv->tables.alloc, &itbuf);283 while (it != NULL) {284 pj_turn_allocation *alloc = (pj_turn_allocation*)285 pj_hash_this(srv->tables.alloc, it);286 pj_turn_allocation_destroy(alloc);287 it = pj_hash_next(srv->tables.alloc, it);288 }289 }290 291 291 292 292 /* Destroy hash tables (well, sort of) */ -
pjproject/trunk/pjnath/src/pjturn-srv/turn.h
r1877 r1879 191 191 192 192 /** Optional channel number, or PJ_TURN_INVALID_CHANNEL if channel number 193 * is not requested for this permission. 193 * is not requested for this permission. 194 194 */ 195 195 pj_uint16_t channel;
Note: See TracChangeset
for help on using the changeset viewer.