From bbcf5c99e1620f90d4dc5871cf565253253f0acc Mon Sep 17 00:00:00 2001 From: Oleg Moskalenko Date: Thu, 31 Jul 2014 00:54:31 -0700 Subject: [PATCH] Imported Upstream version 4.1.1.1 --- ChangeLog | 10 +++-- README.turnserver | 4 ++ README.turnutils | 2 +- man/man1/turnserver.1 | 4 ++ man/man1/turnutils.1 | 2 +- rpm/CentOS7.pre.build.sh | 35 +++++++++++++++ rpm/build.settings.sh | 2 +- rpm/turnserver.spec | 4 +- src/apps/relay/netengine.c | 75 +++++++++++++++++++++++++++++++++ src/apps/relay/ns_ioalib_impl.h | 7 +++ src/apps/relay/turncli.c | 13 ++++++ src/ns_turn_defs.h | 2 +- src/server/ns_turn_server.c | 14 +++++- src/server/ns_turn_server.h | 8 +++- 14 files changed, 171 insertions(+), 11 deletions(-) create mode 100755 rpm/CentOS7.pre.build.sh diff --git a/ChangeLog b/ChangeLog index bc1e6f46..fbc89432 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,8 @@ -06/25/2014 Oleg Moskalenko +07/29/2014 Oleg Moskalenko +Version 4.1.1.1 'Vitari': + - Forceful session concellation (TODO). + +07/22/2014 Oleg Moskalenko Version 4.1.0.2 'Vitari': - SSODA (double allocation) draft support added. - DB "driver" abstraction and MongoDB support (by Federico Pinna). @@ -10,12 +14,12 @@ Version 4.1.0.2 'Vitari': - some crash conditions fixed. - working on compilation warnings. -06/13/2014 Oleg Moskalenko +06/21/2014 Oleg Moskalenko Version 4.0.1.3 'Severard': - Redis DB connection status fixed (Issue 129). - Logfile reset on SIGHUP (Gustavo Garcia suggestion). - - Log reset CLi command. + - Log reset CLI command. - Some error code corrections: * "Mobility forbidden" error changed, to value 405. * "Wrong credentials" situation is now treated as error 441. diff --git a/README.turnserver b/README.turnserver index 63c8dd11..043c08e1 100644 --- a/README.turnserver +++ b/README.turnserver @@ -100,6 +100,7 @@ User database settings: "postgresql://username:password@hostname:port/databasename" (for 9.x or newer Postgres). + See the INSTALL file for more explanations and examples. Also, see http://www.PostgreSQL.org for full PostgreSQL documentation. @@ -111,6 +112,7 @@ User database settings: The connection string format is like that: "host= dbname= user= password= connect_timeout=" + See the INSTALL file for more explanations and examples. Also, see http://www.mysql.org or http://mariadb.org @@ -123,6 +125,7 @@ User database settings: The connection string format is like that: "mongodb://username:password@host:port/database?options" + See the INSTALL file for more explanations and examples. Also, see http://docs.mongodb.org/manual/ @@ -135,6 +138,7 @@ User database settings: The connection string format is like that: "ip= dbname= password= connect_timeout=" + See the INSTALL file for more explanations and examples. Also, see http://redis.io for full Redis documentation. diff --git a/README.turnutils b/README.turnutils index e1e1901f..beb3e8d5 100644 --- a/README.turnutils +++ b/README.turnutils @@ -115,7 +115,7 @@ Flags: -B Random disconnect after a few initial packets. --Z Dual allocation. +-Z Dual allocation (SSODA draft support). Options with required values: diff --git a/man/man1/turnserver.1 b/man/man1/turnserver.1 index 60ff5ec3..7ccca41f 100644 --- a/man/man1/turnserver.1 +++ b/man/man1/turnserver.1 @@ -154,6 +154,7 @@ Or: .PP "postgresql://username:password@hostname:port/databasename" (for 9.x or newer Postgres). +.PP See the INSTALL file for more explanations and examples. .PP Also, see http://www.PostgreSQL.org for full PostgreSQL documentation. @@ -169,6 +170,7 @@ The connection string format is like that: .RS .PP "host= dbname= user= password= connect_timeout=" +.PP See the INSTALL file for more explanations and examples. .PP Also, see http://www.mysql.org or http://mariadb.org @@ -185,6 +187,7 @@ The connection string format is like that: .RS .PP "mongodb://username:password@host:port/database?\fIoptions\fP" +.PP See the INSTALL file for more explanations and examples. .PP Also, see http://docs.mongodb.org/manual/ @@ -201,6 +204,7 @@ The connection string format is like that: .RS .PP "ip= dbname= password= connect_timeout=" +.PP See the INSTALL file for more explanations and examples. .PP Also, see http://redis.io for full Redis documentation. diff --git a/man/man1/turnutils.1 b/man/man1/turnutils.1 index 1d1ceae0..9e745393 100644 --- a/man/man1/turnutils.1 +++ b/man/man1/turnutils.1 @@ -174,7 +174,7 @@ Random disconnect after a few initial packets. .TP .B \fB\-Z\fP -Dual allocation. +Dual allocation (SSODA draft support). .TP .B Options with required values: diff --git a/rpm/CentOS7.pre.build.sh b/rpm/CentOS7.pre.build.sh new file mode 100755 index 00000000..82996859 --- /dev/null +++ b/rpm/CentOS7.pre.build.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +# CentOS7 preparation script. + +CPWD=`pwd` + +. ./common.pre.build.sh + +cd ${CPWD} + +EPELRPM=epel-release-6-8.noarch.rpm + +# Common packs + +PACKS="libevent-devel mariadb-devel" +sudo yum -y install ${PACKS} +ER=$? +if ! [ ${ER} -eq 0 ] ; then + echo "Cannot install package(s) ${PACKS}" + cd ${CPWD} + exit -1 +fi + +# EPEL (for hiredis) + +cd ${CPWD} +./epel.install.sh + +# Platform file + +echo "CentOS7" > ${BUILDDIR}/platform + +cp ${CPWD}/epel.install.sh ${BUILDDIR}/install.sh + +cd ${CPWD} diff --git a/rpm/build.settings.sh b/rpm/build.settings.sh index 2a19a88d..77f1f2c4 100755 --- a/rpm/build.settings.sh +++ b/rpm/build.settings.sh @@ -2,7 +2,7 @@ # Common settings script. -TURNVERSION=4.1.0.2 +TURNVERSION=4.1.1.1 BUILDDIR=~/rpmbuild ARCH=`uname -p` TURNSERVER_SVN_URL=http://coturn.googlecode.com/svn diff --git a/rpm/turnserver.spec b/rpm/turnserver.spec index 01b42f96..cfb2201b 100644 --- a/rpm/turnserver.spec +++ b/rpm/turnserver.spec @@ -1,5 +1,5 @@ Name: turnserver -Version: 4.1.0.2 +Version: 4.1.1.1 Release: 0%{dist} Summary: Coturn TURN Server @@ -293,6 +293,8 @@ fi %{_includedir}/turn/client/TurnMsgLib.h %changelog +* Tue Jul 29 2014 Oleg Moskalenko + - Sync to 4.1.1.1 * Tue Jul 22 2014 Oleg Moskalenko - Sync to 4.1.0.2 * Wed Jun 25 2014 Oleg Moskalenko diff --git a/src/apps/relay/netengine.c b/src/apps/relay/netengine.c index 8f7f7e1d..5f857c79 100644 --- a/src/apps/relay/netengine.c +++ b/src/apps/relay/netengine.c @@ -610,12 +610,87 @@ static int send_socket_to_relay(turnserver_id id, u64bits cid, stun_tid *tid, io return ret; } +int send_session_cancellation_to_relay(turnsession_id sid) +{ + int ret = 0; + + struct message_to_relay sm; + ns_bzero(&sm,sizeof(struct message_to_relay)); + sm.t = RMT_CANCEL_SESSION; + + turnserver_id id = (turnserver_id)(sid / TURN_SESSION_ID_FACTOR); + + struct relay_server *rs = NULL; + if(id>=TURNSERVER_ID_BOUNDARY_BETWEEN_TCP_AND_UDP) { + size_t dest = id-TURNSERVER_ID_BOUNDARY_BETWEEN_TCP_AND_UDP; + if(dest >= get_real_udp_relay_servers_number()) { + TURN_LOG_FUNC( + TURN_LOG_LEVEL_ERROR, + "%s: Too large UDP relay number: %d, total=%d\n", + __FUNCTION__,(int)dest,(int)get_real_udp_relay_servers_number()); + ret = -1; + goto err; + } + rs = udp_relay_servers[dest]; + if(!rs) { + TURN_LOG_FUNC( + TURN_LOG_LEVEL_ERROR, + "%s: Wrong UDP relay number: %d, total=%d\n", + __FUNCTION__,(int)dest,(int)get_real_udp_relay_servers_number()); + ret = -1; + goto err; + } + } else { + size_t dest = id; + if(dest >= get_real_general_relay_servers_number()) { + TURN_LOG_FUNC( + TURN_LOG_LEVEL_ERROR, + "%s: Too large general relay number: %d, total=%d\n", + __FUNCTION__,(int)dest,(int)get_real_general_relay_servers_number()); + ret = -1; + goto err; + } + rs = general_relay_servers[dest]; + if(!rs) { + TURN_LOG_FUNC( + TURN_LOG_LEVEL_ERROR, + "%s: Wrong general relay number: %d, total=%d\n", + __FUNCTION__,(int)dest,(int)get_real_general_relay_servers_number()); + ret = -1; + goto err; + } + } + + sm.relay_server = rs; + sm.m.csm.id = sid; + + { + struct evbuffer *output = bufferevent_get_output(rs->out_buf); + if(output) { + evbuffer_add(output,&sm,sizeof(struct message_to_relay)); + } else { + TURN_LOG_FUNC( + TURN_LOG_LEVEL_ERROR, + "%s: Empty output buffer\n", + __FUNCTION__); + ret = -1; + } + } + + err: + return ret; +} + static int handle_relay_message(relay_server_handle rs, struct message_to_relay *sm) { if(rs && sm) { switch (sm->t) { + case RMT_CANCEL_SESSION: { + turn_cancel_session(&(rs->server),sm->m.csm.id); + } + break; case RMT_SOCKET: { if (sm->m.sm.s->defer_nbh) { diff --git a/src/apps/relay/ns_ioalib_impl.h b/src/apps/relay/ns_ioalib_impl.h index dd161c9c..9a3d8a27 100644 --- a/src/apps/relay/ns_ioalib_impl.h +++ b/src/apps/relay/ns_ioalib_impl.h @@ -94,6 +94,10 @@ struct cb_socket_message { int can_resume; }; +struct cancelled_session_message { + turnsession_id id; +}; + struct relay_server { turnserver_id id; super_memory_t* sm; @@ -113,6 +117,7 @@ struct message_to_relay { union { struct socket_message sm; struct cb_socket_message cb_sm; + struct cancelled_session_message csm; } m; }; @@ -281,6 +286,8 @@ int set_raw_socket_tos_options(evutil_socket_t fd, int family); int set_socket_options_fd(evutil_socket_t fd, int tcp, int family); int set_socket_options(ioa_socket_handle s); +int send_session_cancellation_to_relay(turnsession_id sid); + ///////////////////////// SUPER MEMORY //////// #define allocate_super_memory_engine(e,size) allocate_super_memory_engine_func(e, size, __FILE__, __FUNCTION__, __LINE__) diff --git a/src/apps/relay/turncli.c b/src/apps/relay/turncli.c index ee711f69..6b3a2306 100644 --- a/src/apps/relay/turncli.c +++ b/src/apps/relay/turncli.c @@ -139,6 +139,8 @@ static const char *CLI_HELP_STR[] = " atas ip[:port] - add a TLS alternate server reference", " dtas ip[:port] - delete a TLS alternate server reference", "", + " cs - cancel session, forcefully" + "", NULL}; static const char *CLI_GREETING_STR[] = { @@ -552,6 +554,14 @@ static int print_session(ur_map_key_type key, ur_map_value_type value, void *arg return 0; } +static void cancel_session(struct cli_session* cs, const char* ssid) +{ + if(cs && cs->ts && ssid && *ssid) { + turnsession_id sid = strtoull(ssid,NULL,10); + send_session_cancellation_to_relay(sid); + } +} + static void print_sessions(struct cli_session* cs, const char* pn, int exact_match, int print_users) { if(cs && cs->ts && pn) { @@ -1035,6 +1045,9 @@ static int run_cli_input(struct cli_session* cs, const char *buf0, unsigned int } else if(strstr(cmd,"ps") == cmd) { print_sessions(cs,cmd+2,1,0); type_cli_cursor(cs); + } else if(strstr(cmd,"cs ") == cmd) { + cancel_session(cs,cmd+3); + type_cli_cursor(cs); } else if(strstr(cmd,"lr") == cmd) { log_reset(cs); type_cli_cursor(cs); diff --git a/src/ns_turn_defs.h b/src/ns_turn_defs.h index 704ec927..a4befb83 100644 --- a/src/ns_turn_defs.h +++ b/src/ns_turn_defs.h @@ -31,7 +31,7 @@ #ifndef __IOADEFS__ #define __IOADEFS__ -#define TURN_SERVER_VERSION "4.1.0.2" +#define TURN_SERVER_VERSION "4.1.1.1" #define TURN_SERVER_VERSION_NAME "Vitari" #define TURN_SOFTWARE "Coturn-" TURN_SERVER_VERSION " '" TURN_SERVER_VERSION_NAME "'" diff --git a/src/server/ns_turn_server.c b/src/server/ns_turn_server.c index cc4ea85e..deb6cf5d 100644 --- a/src/server/ns_turn_server.c +++ b/src/server/ns_turn_server.c @@ -673,14 +673,13 @@ static void put_session_into_map(ts_ur_super_session *ss) if(ss && ss->server) { turn_turnserver* server = (turn_turnserver*)(ss->server); if(!(ss->id)) { - ss->id = (turnsession_id)((turnsession_id)server->id * 1000000000000000LL); + ss->id = (turnsession_id)((turnsession_id)server->id * TURN_SESSION_ID_FACTOR); ss->id += ++(server->session_id_counter); ss->start_time = server->ctime; } ur_map_put(server->sessions_map, (ur_map_key_type)(ss->id), (ur_map_value_type)ss); put_session_into_mobile_map(ss); } - } static void delete_session_from_mobile_map(ts_ur_super_session *ss) @@ -716,6 +715,17 @@ static ts_ur_super_session* get_session_from_map(turn_turnserver* server, turnse return ss; } +void turn_cancel_session(turn_turnserver *server, turnsession_id sid) +{ + if(server) { + ts_ur_super_session* ts = get_session_from_map(server, sid); + if(ts) { + TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO, "Session %018llu to be forcefully canceled\n",(unsigned long long)sid); + shutdown_client_connection(server, ts, 0, "Forceful shutdown"); + } + } +} + static ts_ur_super_session* get_session_from_mobile_map(turn_turnserver* server, mobile_id_t mid) { ts_ur_super_session *ss = NULL; diff --git a/src/server/ns_turn_server.h b/src/server/ns_turn_server.h index 88134652..feaad20d 100644 --- a/src/server/ns_turn_server.h +++ b/src/server/ns_turn_server.h @@ -38,6 +38,9 @@ extern "C" { #endif +//////////// defines ////////////// + +#define TURN_SESSION_ID_FACTOR (1000000000000000LL) //////////// ALTERNATE-SERVER ///////////// @@ -67,7 +70,8 @@ enum _MESSAGE_TO_RELAY_TYPE { RMT_UNKNOWN = 0, RMT_SOCKET, RMT_CB_SOCKET, - RMT_MOBILE_SOCKET + RMT_MOBILE_SOCKET, + RMT_CANCEL_SESSION }; typedef enum _MESSAGE_TO_RELAY_TYPE MESSAGE_TO_RELAY_TYPE; @@ -209,6 +213,8 @@ int report_turn_session_info(turn_turnserver *server, ts_ur_super_session *ss, i turn_time_t get_turn_server_time(turn_turnserver *server); +void turn_cancel_session(turn_turnserver *server, turnsession_id sid); + /////////////////////////////////////////// #ifdef __cplusplus