From 9124a167ed9229060647f86a0e08a1f4f2958d50 Mon Sep 17 00:00:00 2001 From: Oleg Moskalenko Date: Sat, 27 Aug 2016 17:09:05 -0700 Subject: [PATCH] read_timeout support --- ChangeLog | 3 ++- INSTALL | 6 +++--- README.turnserver | 2 +- examples/etc/turnserver.conf | 2 +- .../scripts/longtermsecuredb/secure_relay_with_db_mysql.sh | 4 ++-- .../longtermsecuredb/secure_relay_with_db_mysql_ssl.sh | 4 ++-- man/man1/turnserver.1 | 2 +- src/apps/relay/dbdrivers/dbd_mysql.c | 5 +++++ src/apps/relay/mainrelay.c | 2 +- 9 files changed, 18 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4b077b7..ac1ae23 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,7 +1,8 @@ 08/27/2016 Oleg Moskalenko Version 4.5.0.5 'dan Eider': - Typos in the text fixed. - - LibreSSL compatibility fixed. + - LibreSSL compatibility fixed. + - "read_timeout" option support for MySQL. 08/20/2016 Oleg Moskalenko Version 4.5.0.4 'dan Eider': diff --git a/INSTALL b/INSTALL index 0326a16..7e2cf99 100644 --- a/INSTALL +++ b/INSTALL @@ -1006,18 +1006,18 @@ have such a feature as "connection string", the TURN server parses the connection string and converts it into MySQL database connection parameter. The format of the MySQL connection string is: -"host= dbname= user= password= port= connect_timeout=" +"host= dbname= user= password= port= connect_timeout= read_timeout=" (all parameters are optional) So, an example of the MySQL database parameter in the TURN server command line would be: ---mysql-userdb="host=localhost dbname=coturn user=turn password=turn connect_timeout=30" +--mysql-userdb="host=localhost dbname=coturn user=turn password=turn connect_timeout=30 read_timeout=30" Or in the turnserver.conf file: -mysql-userdb="host=localhost dbname=coturn user=turn password=turn connect_timeout=30" +mysql-userdb="host=localhost dbname=coturn user=turn password=turn connect_timeout=30 read_timeout=30" If you have to use a secure MySQL connection (SSL) then you have to use also the optional connection string parameters for the secure communications: diff --git a/README.turnserver b/README.turnserver index 776b90f..48f998e 100644 --- a/README.turnserver +++ b/README.turnserver @@ -108,7 +108,7 @@ User database settings: secret-based timed authentication in TURN RESP API. The connection string format is like that: - "host= dbname= user= password= connect_timeout=" + "host= dbname= user= password= connect_timeout= read_timeout=" See the INSTALL file for more explanations and examples. diff --git a/examples/etc/turnserver.conf b/examples/etc/turnserver.conf index f35fa03..b5742fb 100644 --- a/examples/etc/turnserver.conf +++ b/examples/etc/turnserver.conf @@ -274,7 +274,7 @@ # # Use string format as below (space separated parameters, all optional): # -#mysql-userdb="host= dbname= user= password= port= connect_timeout=" +#mysql-userdb="host= dbname= user= password= port= connect_timeout= read_timeout=" # MongoDB database connection string in the case that we are using MongoDB # as the user database. diff --git a/examples/scripts/longtermsecuredb/secure_relay_with_db_mysql.sh b/examples/scripts/longtermsecuredb/secure_relay_with_db_mysql.sh index e486c5f..1a30e04 100755 --- a/examples/scripts/longtermsecuredb/secure_relay_with_db_mysql.sh +++ b/examples/scripts/longtermsecuredb/secure_relay_with_db_mysql.sh @@ -15,7 +15,7 @@ # 3) use 3 relay threads (-m 3) # 4) use min UDP relay port 32355 and max UDP relay port 65535 # 5) "-r north.gov" means "use authentication realm north.gov" -# 6) --mysql-userdb="host=localhost dbname=coturn user=turn password=turn connect_timeout=30" +# 6) --mysql-userdb="host=localhost dbname=coturn user=turn password=turn connect_timeout=30 read_timeout=30" # means that local MySQL database "coturn" will be used, with database user "turn" and # database user password "turn", and connection timeout 30 seconds. # 7) "--cert=example_turn_server_cert.pem" sets the OpenSSL certificate file name. @@ -32,4 +32,4 @@ fi export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/local/lib/:/usr/local/mysql/lib/ export DYLD_LIBRARY_PATH=${DYLD_LIBRARY_PATH}:/usr/local/lib/:/usr/local/mysql/lib/ -PATH="./bin/:../bin/:../../bin/:${PATH}" turnserver --server-name="blackdow.carleon.gov" -v --syslog -a -L 127.0.0.1 -L ::1 -E 127.0.0.1 -E ::1 --max-bps=3000000 -f -m 3 --min-port=32355 --max-port=65535 -r north.gov --mysql-userdb="host=localhost dbname=coturn user=turn password=turn connect_timeout=30" --cert=turn_server_cert.pem --pkey=turn_server_pkey.pem --log-file=stdout --cipher-list=ALL --oauth $@ +PATH="./bin/:../bin/:../../bin/:${PATH}" turnserver --server-name="blackdow.carleon.gov" -v --syslog -a -L 127.0.0.1 -L ::1 -E 127.0.0.1 -E ::1 --max-bps=3000000 -f -m 3 --min-port=32355 --max-port=65535 -r north.gov --mysql-userdb="host=localhost dbname=coturn user=turn password=turn connect_timeout=30 read_timeout=30" --cert=turn_server_cert.pem --pkey=turn_server_pkey.pem --log-file=stdout --cipher-list=ALL --oauth $@ diff --git a/examples/scripts/longtermsecuredb/secure_relay_with_db_mysql_ssl.sh b/examples/scripts/longtermsecuredb/secure_relay_with_db_mysql_ssl.sh index 95d4ceb..31085df 100755 --- a/examples/scripts/longtermsecuredb/secure_relay_with_db_mysql_ssl.sh +++ b/examples/scripts/longtermsecuredb/secure_relay_with_db_mysql_ssl.sh @@ -15,7 +15,7 @@ # 3) use 3 relay threads (-m 3) # 4) use min UDP relay port 32355 and max UDP relay port 65535 # 5) "-r north.gov" means "use authentication realm north.gov" -# 6) --mysql-userdb="host=localhost dbname=coturn user=turn password=turn cipher=DHE-RSA-AES256-SHA connect_timeout=30" +# 6) --mysql-userdb="host=localhost dbname=coturn user=turn password=turn cipher=DHE-RSA-AES256-SHA connect_timeout=30 read_timeout=30" # means that local MySQL database "coturn" will be used, with database user "turn" and # database user password "turn", and with SSL connection with cipher DHE-RSA-AES256-SHA, # and connection timeout 30 seconds. @@ -33,4 +33,4 @@ fi export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/local/lib/:/usr/local/mysql/lib/ export DYLD_LIBRARY_PATH=${DYLD_LIBRARY_PATH}:/usr/local/lib/:/usr/local/mysql/lib/ -PATH="./bin/:../bin/:../../bin/:${PATH}" turnserver --server-name="blackdow.carleon.gov" -v --syslog -a -L 127.0.0.1 -L ::1 -E 127.0.0.1 -E ::1 --max-bps=3000000 -f -m 3 --min-port=32355 --max-port=65535 -r north.gov --mysql-userdb="host=localhost dbname=coturn user=turn password=turn cipher=DHE-RSA-AES256-SHA connect_timeout=30" --cert=turn_server_cert.pem --pkey=turn_server_pkey.pem --log-file=stdout --cipher-list=ALL --oauth $@ +PATH="./bin/:../bin/:../../bin/:${PATH}" turnserver --server-name="blackdow.carleon.gov" -v --syslog -a -L 127.0.0.1 -L ::1 -E 127.0.0.1 -E ::1 --max-bps=3000000 -f -m 3 --min-port=32355 --max-port=65535 -r north.gov --mysql-userdb="host=localhost dbname=coturn user=turn password=turn cipher=DHE-RSA-AES256-SHA connect_timeout=30 read_timeout=30" --cert=turn_server_cert.pem --pkey=turn_server_pkey.pem --log-file=stdout --cipher-list=ALL --oauth $@ diff --git a/man/man1/turnserver.1 b/man/man1/turnserver.1 index 145d9bd..79ae91c 100644 --- a/man/man1/turnserver.1 +++ b/man/man1/turnserver.1 @@ -166,7 +166,7 @@ secret\-based timed authentication in TURN RESP API. The connection string format is like that: .RS .PP -"host= dbname= user= password= connect_timeout=" +"host= dbname= user= password= connect_timeout= read_timeout=" .PP See the INSTALL file for more explanations and examples. .PP diff --git a/src/apps/relay/dbdrivers/dbd_mysql.c b/src/apps/relay/dbdrivers/dbd_mysql.c index 2e5543d..f9eaa71 100644 --- a/src/apps/relay/dbdrivers/dbd_mysql.c +++ b/src/apps/relay/dbdrivers/dbd_mysql.c @@ -46,6 +46,7 @@ struct _Myconninfo { char *password; unsigned int port; unsigned int connect_timeout; + unsigned int read_timeout; /* SSL ==>> */ char *key; char *ca; @@ -139,6 +140,8 @@ static Myconninfo *MyconninfoParse(char *userdb, char **errmsg) { co->connect_timeout = (unsigned int)atoi(seq+1); else if(!strcmp(s,"timeout")) co->connect_timeout = (unsigned int)atoi(seq+1); + else if(!strcmp(s,"read_timeout")) + co->read_timeout = (unsigned int)atoi(seq+1); else if(!strcmp(s,"key")) co->key = turn_strdup(seq+1); else if(!strcmp(s,"ssl-key")) @@ -226,6 +229,8 @@ static MYSQL *get_mydb_connection(void) { } else { if(co->connect_timeout) mysql_options(mydbconnection,MYSQL_OPT_CONNECT_TIMEOUT,&(co->connect_timeout)); + if(co->read_timeout) + mysql_options(mydbconnection,MYSQL_OPT_READ_TIMEOUT,&(co->read_timeout)); if(co->ca || co->capath || co->cert || co->cipher || co->key) { mysql_ssl_set(mydbconnection, co->key, co->cert, co->ca, co->capath, co->cipher); } diff --git a/src/apps/relay/mainrelay.c b/src/apps/relay/mainrelay.c index 7f81638..0c839ef 100644 --- a/src/apps/relay/mainrelay.c +++ b/src/apps/relay/mainrelay.c @@ -462,7 +462,7 @@ static char Usage[] = "Usage: turnserver [options]\n" " This database can be used for long-term credentials mechanism users,\n" " and it can store the secret value(s) for secret-based timed authentication in TURN RESP API.\n" " The connection string my be space-separated list of parameters:\n" -" \"host= dbname= user= \\\n password= port= connect_timeout=\".\n\n" +" \"host= dbname= user= \\\n password= port= connect_timeout= read_timeout=\".\n\n" " The connection string parameters for the secure communications (SSL):\n" " ca, capath, cert, key, cipher\n" " (see http://dev.mysql.com/doc/refman/5.1/en/ssl-options.html for the\n"