浏览代码

Imported Upstream version 4.1.1.1

Oleg Moskalenko 11 年之前
父节点
当前提交
bbcf5c99e1

+ 7 - 3
ChangeLog

@@ -1,4 +1,8 @@
-06/25/2014 Oleg Moskalenko <[email protected]>
+07/29/2014 Oleg Moskalenko <[email protected]>
+Version 4.1.1.1 'Vitari':
+	- Forceful session concellation (TODO).
+	
+07/22/2014 Oleg Moskalenko <[email protected]>
 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 <[email protected]>
+06/21/2014 Oleg Moskalenko <[email protected]>
 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.

+ 4 - 0
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=<host> dbname=<dbname> user=<db-user> password=<db-user-password> connect_timeout=<seconds>"
+
 		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=<ip-addr> dbname=<db-number> password=<db-password> connect_timeout=<seconds>"
+
 		See the INSTALL file for more explanations and examples.
 		
 		Also, see http://redis.io for full Redis documentation.

+ 1 - 1
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:  
 

+ 4 - 0
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=<host> dbname=<dbname> user=<db\-user> password=<db\-user\-password> connect_timeout=<seconds>"
+.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=<ip\-addr> dbname=<db\-number> password=<db\-password> connect_timeout=<seconds>"
+.PP
 See the INSTALL file for more explanations and examples.
 .PP
 Also, see http://redis.io for full Redis documentation.

+ 1 - 1
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:

+ 35 - 0
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}

+ 1 - 1
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

+ 3 - 1
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 <[email protected]>
+  - Sync to 4.1.1.1
 * Tue Jul 22 2014 Oleg Moskalenko <[email protected]>
   - Sync to 4.1.0.2
 * Wed Jun 25 2014 Oleg Moskalenko <[email protected]>

+ 75 - 0
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) {

+ 7 - 0
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__)

+ 13 - 0
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 <session-id> - 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);

+ 1 - 1
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 "'"
 

+ 12 - 2
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;

+ 7 - 1
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