1 /* $Id$ */ 2 /* 3 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com) 4 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org> 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 2 of the License, or 9 * (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 */ 20 #ifndef __PJNATH_TEST_SERVER_H__ 21 #define __PJNATH_TEST_SERVER_H__ 22 23 #include <pjnath.h> 24 #include <pjlib-util.h> 25 #include <pjlib.h> 26 27 #define DNS_SERVER_PORT 55533 28 #define STUN_SERVER_PORT 33478 29 #define TURN_SERVER_PORT 33479 30 31 #define TURN_USERNAME "auser" 32 #define TURN_PASSWD "apass" 33 34 #define MAX_TURN_ALLOC 16 35 #define MAX_TURN_PERM 16 36 37 enum test_server_flags 38 { 39 CREATE_DNS_SERVER = (1 << 0), 40 CREATE_A_RECORD_FOR_DOMAIN = (1 << 1), 41 42 CREATE_STUN_SERVER = (1 << 4), 43 CREATE_STUN_SERVER_DNS_SRV = (1 << 5), 44 45 CREATE_TURN_SERVER = (1 << 8), 46 CREATE_TURN_SERVER_DNS_SRV = (1 << 9), 47 48 SERVER_IPV4 = (1 << 12), 49 SERVER_IPV6 = (1 << 13), 50 51 TURN_UDP = (1 << 16), 52 TURN_TCP = (1 << 17), 53 TURN_TLS = (1 << 18) 54 }; 55 56 typedef struct test_server test_server; 57 58 /* TURN allocation */ 59 typedef struct turn_allocation 60 { 61 test_server *test_srv; 62 pj_pool_t *pool; 63 pj_activesock_t *sock; 64 pj_ioqueue_op_key_t send_key; 65 pj_sockaddr client_addr; 66 pj_sockaddr alloc_addr; 67 unsigned perm_cnt; 68 pj_sockaddr perm[MAX_TURN_PERM]; 69 unsigned chnum[MAX_TURN_PERM]; 70 pj_stun_msg *data_ind; 71 } turn_allocation; 72 73 /* 74 * Server installation for testing. 75 * This comprises of DNS server, STUN server, and TURN server. 76 */ 77 struct test_server 78 { 79 pj_pool_t *pool; 80 pj_uint32_t flags; 81 pj_stun_config *stun_cfg; 82 pj_ioqueue_op_key_t send_key; 83 84 pj_dns_server *dns_server; 85 86 pj_activesock_t *stun_sock; 87 88 pj_activesock_t *turn_sock; 89 90 pj_ssl_sock_t *ssl_srv_sock; 91 92 pj_ssl_sock_t *ssl_cl_sock; 93 94 pj_activesock_t *cl_turn_sock; 95 96 pj_sockaddr remote_addr; 97 unsigned turn_alloc_cnt; 98 turn_allocation turn_alloc[MAX_TURN_ALLOC]; 99 pj_bool_t turn_respond_allocate; 100 pj_bool_t turn_respond_refresh; 101 102 struct turn_stat { 103 unsigned rx_allocate_cnt; 104 unsigned rx_refresh_cnt; 105 unsigned rx_send_ind_cnt; 106 } turn_stat; 107 108 pj_str_t domain; 109 pj_str_t username; 110 pj_str_t passwd; 111 112 }; 113 114 115 pj_status_t create_test_server(pj_stun_config *stun_cfg, 116 pj_uint32_t flags, 117 const char *domain, 118 test_server **p_test_srv); 119 void destroy_test_server(test_server *test_srv); 120 void test_server_poll_events(test_server *test_srv); 121 122 123 #endif /* __PJNATH_TEST_SERVER_H__ */ 124 125