1
/* $Id: main.c 3553 2011-05-05 06:14:19Z nanang $ */
3
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
4
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
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.
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.
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
23
#define REALM "pjsip.org"
24
//#define TURN_PORT PJ_STUN_TURN_PORT
25
#define TURN_PORT 34780
29
static pj_caching_pool g_cp;
31
int err(const char *title, pj_status_t status)
33
char errmsg[PJ_ERR_MSG_SIZE];
34
pj_strerror(status, errmsg, sizeof(errmsg));
36
printf("%s: %s\n", title, errmsg);
40
static void dump_status(pj_turn_srv *srv)
43
pj_hash_iterator_t itbuf, *it;
47
for (i=0; i<srv->core.lis_cnt; ++i) {
48
pj_turn_listener *lis = srv->core.listener[i];
49
printf("Server address : %s\n", lis->info);
52
printf("Worker threads : %d\n", srv->core.thread_cnt);
53
printf("Total mem usage: %u.%03uMB\n", (unsigned)(g_cp.used_size / 1000000),
54
(unsigned)((g_cp.used_size % 1000000)/1000));
55
printf("UDP port range : %u %u %u (next/min/max)\n", srv->ports.next_udp,
56
srv->ports.min_udp, srv->ports.max_udp);
57
printf("TCP port range : %u %u %u (next/min/max)\n", srv->ports.next_tcp,
58
srv->ports.min_tcp, srv->ports.max_tcp);
59
printf("Clients # : %u\n", pj_hash_count(srv->tables.alloc));
63
if (pj_hash_count(srv->tables.alloc)==0) {
67
puts("# Client addr. Alloc addr. Username Lftm Expy #prm #chl");
68
puts("------------------------------------------------------------------------------");
70
pj_gettimeofday(&now);
72
it = pj_hash_first(srv->tables.alloc, &itbuf);
75
pj_turn_allocation *alloc = (pj_turn_allocation*)
76
pj_hash_this(srv->tables.alloc, it);
77
printf("%-3d %-22s %-22s %-8.*s %-4d %-4ld %-4d %-4d\n",
80
pj_sockaddr_print(&alloc->relay.hkey.addr, addr, sizeof(addr), 3),
81
(int)alloc->cred.data.static_cred.username.slen,
82
alloc->cred.data.static_cred.username.ptr,
83
alloc->relay.lifetime,
84
alloc->relay.expiry.sec - now.sec,
85
pj_hash_count(alloc->peer_table),
86
pj_hash_count(alloc->ch_table));
88
it = pj_hash_next(srv->tables.alloc, it);
93
static void menu(void)
97
puts(" d Dump status");
102
static void console_main(pj_turn_srv *srv)
104
pj_bool_t quit = PJ_FALSE;
111
if (fgets(line, sizeof(line), stdin) == NULL)
128
pj_turn_listener *listener;
132
if (status != PJ_SUCCESS)
133
return err("pj_init() error", status);
138
pj_caching_pool_init(&g_cp, NULL, 0);
140
pj_turn_auth_init(REALM);
142
status = pj_turn_srv_create(&g_cp.factory, &srv);
143
if (status != PJ_SUCCESS)
144
return err("Error creating server", status);
146
status = pj_turn_listener_create_udp(srv, pj_AF_INET(), NULL,
147
TURN_PORT, 1, 0, &listener);
148
if (status != PJ_SUCCESS)
149
return err("Error creating UDP listener", status);
152
status = pj_turn_listener_create_tcp(srv, pj_AF_INET(), NULL,
153
TURN_PORT, 1, 0, &listener);
154
if (status != PJ_SUCCESS)
155
return err("Error creating listener", status);
158
status = pj_turn_srv_add_listener(srv, listener);
159
if (status != PJ_SUCCESS)
160
return err("Error adding listener", status);
162
puts("Server is running");
164
pj_log_set_level(LOG_LEVEL);
168
pj_turn_srv_destroy(srv);
169
pj_caching_pool_destroy(&g_cp);