Skip to content

Commit

Permalink
MongoDB support: initial checkin
Browse files Browse the repository at this point in the history
  • Loading branch information
mom040267 committed Jul 11, 2014
1 parent 48537e9 commit 5c3b773
Show file tree
Hide file tree
Showing 22 changed files with 4,285 additions and 2,495 deletions.
67 changes: 47 additions & 20 deletions INSTALL
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,13 @@ do not allows that, then after the installation, you may have to adjust the
system-wide shared library search path by using "ldconfig -n <libdirname>"
(Linux), "ldconfig -m <libdirname>" (BSD) or "crle -u -l <libdirname>"
(Solaris). Your system must be able to find the libevent2, openssl and
(optionally) PostgreSQL and/or MySQL (MariaDB) and/or Redis shared libraries,
either with the help of the system-wide library search configuration or by
using LD_LIBRARY_PATH. "make install" will make a non-garantied effort to add
automatically PREFIX/lib and /usr/local/lib to the libraries search path,
but if you have some libraries in different non-default directories
you will have to add them manually to the search path, or you
will have to adjust LD_LIBRARY_PATH.
(optionally) PostgreSQL and/or MySQL (MariaDB) and/or MongoDB and/or Redis
shared libraries, either with the help of the system-wide library search
configuration or by using LD_LIBRARY_PATH. "make install" will make a
non-garantied effort to add automatically PREFIX/lib and /usr/local/lib to
the libraries search path, but if you have some libraries in different
non-default directories you will have to add them manually to the search
path, or you will have to adjust LD_LIBRARY_PATH.

V. PLATFORMS

Expand Down Expand Up @@ -277,8 +277,8 @@ VII. WHICH EXTRA LIBRARIES AND UTILITIES YOU NEED
In addition to common *NIX OS services and libraries, to compile this code,
OpenSSL (version 1.0.0a or better recommended) and libevent2 (version 2.0.5
or better) are required, the PostgreSQL C client development setup is
optional, the MySQL (MariaDB) C client development setup is optional, and the
Hiredis development files for Redis database access are optional.
optional, the MySQL (MariaDB) C client development setup is optional, the MongoDB
C Driver and the Hiredis development files for Redis database access are optional.
For fully functional build, the extra set of libraries must be installed
in full version (the development headers and the libraries to link with).
For runtime, only runtime setup is required. If the build is modified for
Expand All @@ -290,6 +290,7 @@ libraries can be downloaded from their web sites:
- http://www.libevent.org (required);
- http://www.postgresql.org (optional);
- http://www.mysql.org (or http://mariadb.org) (optional);
- https://github.com/mongodb/mongo-c-driver (optional);
- http://redis.io (optional).

The installations are pretty straightforward - the usual
Expand Down Expand Up @@ -352,6 +353,11 @@ installation:
- you have to install gcc first:
$ sudo yum install gcc

- mongo-c-driver packages are not available. MongoDB support
will not be compiled, unless you install it "manually" before
the TURN server compilation. Refer to https://github.com/mongodb/mongo-c-driver
for installation instructions of the driver.

- hiredis packages are not available, so do not issue the
hiredis installation commands. Redis support will not be
compiled, unless you install it "manually" before the TURN
Expand Down Expand Up @@ -381,7 +387,7 @@ like this:
Dynamic library paths:

You may also have to adjust the turn server start script, add PostgreSQL
and/or MySQL and/or Redis runtime library path to LD_LIBRARY_PATH.
and/or MySQL and/or MongoDB and/or Redis runtime library path to LD_LIBRARY_PATH.
Or you may find that it would be more convenient to adjust the
system-wide shared library search path by using commands:

Expand Down Expand Up @@ -412,17 +418,17 @@ absolute paths or @rpath/... .

See also the next section.

NOTE: See "PostgreSQL setup" and "MySQL setup" and "Redis setup" sections
below for more database setup information.
NOTE: See "PostgreSQL setup" and "MySQL setup" and "MongoDB setup" and
"Redis setup" sections below for more database setup information.

NOTE: If you do not install PostgreSQL or MySQL or Redis then you will
NOTE: If you do not install PostgreSQL or MySQL or MongoDB or Redis then you will
be limited to flat files for user database. It will work great for
smaller user databases (like 100 users) but for larger systems you
will need PostgreSQL or MySQL or Redis.
will need PostgreSQL or MySQL or MongoDB or Redis.

NOTE: To run PostgreSQL or MySQL or Redis server on the same system,
NOTE: To run PostgreSQL or MySQL or MongoDB or Redis server on the same system,
you will also have to install a corresponding PostgreSQL or MySQL or
Redis server package. The DB C development packages only provide
MongoDB or Redis server package. The DB C development packages only provide
development libraries, and client libraries only provide client
access utilities and runtime libraries. The server packages may
include everything - client, C development and server runtime.
Expand Down Expand Up @@ -892,7 +898,28 @@ Or in the turnserver.conf file:

mysql-userdb="host=localhost dbname=turn user=turn password=turn connect_timeout=30"

XVI. Redis setup
XVI. MongoDB setup

The MongoDB setup is well documented on their site http://docs.mongodb.org/manual/.

If the TURN server was compiled with MongoDB support (mongo-c-driver is the C client
library for MongoDB), then we can use the TURN server database parameter
--mongo-userdb. The value of this parameter is a connection string
for the MongoDB database. The format of the connection string is described at
http://hergert.me/docs/mongo-c-driver/mongoc_uri.html:

"mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]"

So, an example of the MongoDB database parameter in the TURN server command
line would be:

--mongo-userdb="mongodb://localhost:27017/turndb"

Or in the turnserver.conf file:

mongo-userdb="mongodb://localhost:27017/turndb"

XVII. Redis setup

The Redis setup is well documented on their site http://redis.io.
The TURN Server Redis database schema description can be found
Expand Down Expand Up @@ -961,20 +988,20 @@ Redis TURN admin commands:
$ bin/turnadmin -A -N "host=localhost dbname=0 user=turn password=turn" -u gorst -r north.gov -p hero
$ bin/turnadmin -A -N "host=localhost dbname=0 user=turn password=turn" -u ninefingers -r north.gov -p youhavetoberealistic

XV. Performance tuning
XVIII. Performance tuning

This topic is covered in the wiki page:

http://code.google.com/p/coturn/wiki/turn_performance_and_load_balance

XVI. TURN Server setup
XIX. TURN Server setup

Read the project wiki pages: http://code.google.com/p/coturn/w/list

Also, check the project from page links to the TURN/WebRTC configuration examples.
It may give you an idea how it can be done.

XVI. Management interface
XX. Management interface

You have a telnet interface (enabled by default) to access the turnserver process,
to view its state, to gather some statistical information, and to make some changes
Expand Down
7 changes: 5 additions & 2 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@ IMPL_DEPS = ${COMMON_DEPS} ${IMPL_HEADERS} ${IMPL_MODS}
HIREDIS_HEADERS = src/apps/common/hiredis_libevent2.h
HIREDIS_MODS = src/apps/common/hiredis_libevent2.c

SERVERAPP_HEADERS = src/apps/relay/userdb.h src/apps/relay/tls_listener.h src/apps/relay/mainrelay.h src/apps/relay/turncli.h src/apps/relay/dtls_listener.h src/apps/relay/libtelnet.h ${HIREDIS_HEADERS}
SERVERAPP_MODS = src/apps/relay/mainrelay.c src/apps/relay/netengine.c src/apps/relay/libtelnet.c src/apps/relay/turncli.c src/apps/relay/userdb.c src/apps/relay/tls_listener.c src/apps/relay/dtls_listener.c ${HIREDIS_MODS}
USERDB_HEADERS = src/apps/relay/dbdrivers/dbdriver.h src/apps/relay/dbdrivers/dbd_pgsql.h src/apps/relay/dbdrivers/dbd_mysql.h src/apps/relay/dbdrivers/dbd_mongo.h src/apps/relay/dbdrivers/dbd_redis.h
USERDB_MODS = src/apps/relay/dbdrivers/dbdriver.c src/apps/relay/dbdrivers/dbd_pgsql.c src/apps/relay/dbdrivers/dbd_mysql.c src/apps/relay/dbdrivers/dbd_mongo.c src/apps/relay/dbdrivers/dbd_redis.c

SERVERAPP_HEADERS = src/apps/relay/userdb.h src/apps/relay/tls_listener.h src/apps/relay/mainrelay.h src/apps/relay/turncli.h src/apps/relay/dtls_listener.h src/apps/relay/libtelnet.h ${HIREDIS_HEADERS} ${USERDB_HEADERS}
SERVERAPP_MODS = src/apps/relay/mainrelay.c src/apps/relay/netengine.c src/apps/relay/libtelnet.c src/apps/relay/turncli.c src/apps/relay/userdb.c src/apps/relay/tls_listener.c src/apps/relay/dtls_listener.c ${HIREDIS_MODS} ${USERDB_MODS}
SERVERAPP_DEPS = ${SERVERTURN_MODS} ${SERVERTURN_DEPS} ${SERVERAPP_MODS} ${SERVERAPP_HEADERS} ${COMMON_DEPS} ${IMPL_DEPS} lib/libturnclient.a

TURN_BUILD_RESULTS = bin/turnutils_stunclient bin/turnutils_rfc5769check bin/turnutils_uclient bin/turnserver bin/turnutils_peer lib/libturnclient.a include/turn/ns_turn_defs.h
Expand Down
2 changes: 2 additions & 0 deletions README.turnadmin
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ Options with required values:
See the --psql-userdb option in the turnserver section.
-M, --mysql-userdb MySQL user database connection string.
See the --mysql-userdb option in the turnserver section.
-J, --mongo-userdb MongoDB user database connection string.
See the --mysql-mongo option in the turnserver section.
-N, --redis-userdb Redis user database connection string.
See the --redis-userdb option in the turnserver section.
-u, --user User name.
Expand Down
25 changes: 19 additions & 6 deletions README.turnserver
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ turnserver - a TURN relay server implementation.

SYNOPSIS

$ turnserver [-n | -c <config-file> ] [flags] [ --userdb=<userdb-file> | --psql-userdb=<db-conn-string> | --mysql-userdb=<db-conn-string> | --redis-userdb=<db-conn-string> ] [-z | --no-auth | -a | --lt-cred-mech ] [options]
$ turnserver [-n | -c <config-file> ] [flags] [ --userdb=<userdb-file> | --psql-userdb=<db-conn-string> | --mysql-userdb=<db-conn-string> | --mongo-userdb=<db-conn-string> | --redis-userdb=<db-conn-string> ] [-z | --no-auth | -a | --lt-cred-mech ] [options]
$ turnserver -h

DESCRIPTION
Expand Down Expand Up @@ -113,6 +113,17 @@ User database settings:
Also, see http://www.mysql.org or http://mariadb.org
for full MySQL documentation.

-J, --mongo-userdb User database connection string for MongoDB.
This database can be used for long-term and short-term credentials mechanisms,
and it can store the secret value for secret-based timed authentication in TURN RESP API.
The connection string format is like that:

"mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]"
See the INSTALL file for more explanations and examples.

Also, see http://docs.mongodb.org/manual/
for full MongoDB documentation.

-N, --redis-userdb User database connection string for Redis.
This database can be used for long-term and short-term credentials mechanisms,
and it can store the secret value for secret-based timed authentication in TURN RESP API.
Expand All @@ -138,9 +149,9 @@ Flags:

-a, --lt-cred-mech Use long-term credentials mechanism (this one you need for WebRTC usage).
This option can be used with either flat file user database or
PostgreSQL DB or MySQL DB or Redis for user keys storage.
PostgreSQL DB or MySQL DB or MongoDB or Redis for user keys storage.
-A, --st-cred-mech Use the short-term credentials mechanism. This option requires
a PostgreSQL or MySQL or Redis DB for short term passwords storage.
a PostgreSQL or MySQL or MongoDB or Redis DB for short term passwords storage.

-z, --no-auth Do not use any credentials mechanism, allow anonymous access.
Opposite to -a and -A options. This is default option when no
Expand Down Expand Up @@ -461,7 +472,7 @@ Options with required values:
no Redis stats DB used). This database keeps allocations status information, and it can
be also used for publishing and delivering traffic and allocation event notifications.
This database option can be used independently of --redis-userdb option,
and actually Redis can be used for status/statistics and MySQL or PostgreSQL can
and actually Redis can be used for status/statistics and MySQL or MongoDB or PostgreSQL can
be used for the user database.
The connection string has the same parameters as redis-userdb connection string.

Expand Down Expand Up @@ -533,7 +544,7 @@ for that you have a number of options:

b) userdb config file.

c) a database table (PostgreSQL or MySQL). You will have to set keys with
c) a database table (PostgreSQL or MySQL or MongoDB). You will have to set keys with
turnadmin utility (see docs and wiki for turnadmin). You cannot use open passwords
in the database.

Expand Down Expand Up @@ -717,7 +728,9 @@ turndb/testredisdbsetup.sh as an example.
can be administered separately, and each realm can have its own set of users and its own
performance options (max-bps, user-quota, total-quota).

7) Of course, the turnserver can be used in non-secure mode, when users are allowed to establish
7) If you use MongoDB, the database will be setup for you automatically.

8) Of course, the turnserver can be used in non-secure mode, when users are allowed to establish
sessions anonymously. But in most cases (like WebRTC) that will not work.

For the status and statistics database, there are two choices:
Expand Down
56 changes: 56 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ cleanup() {
rm -rf ${PQ_TMPCPROGB}
rm -rf ${MYSQL_TMPCPROGC}
rm -rf ${MYSQL_TMPCPROGB}
rm -rf ${MONGO_TMPCPROGC}
rm -rf ${MONGO_TMPCPROGB}
rm -rf ${D_TMPCPROGC}
rm -rf ${D_TMPCPROGB}
rm -rf ${E_TMPCPROGC}
Expand Down Expand Up @@ -124,6 +126,30 @@ testlibmysql() {
fi
}

testlibmongoc() {
for inc in ${PREFIX}/libmongoc-1.0 ${PREFIX}/libbson-1.0 /usr/local/include/libmongoc-1.0 /usr/local/include/libbson-1.0 /usr/libmongoc-1.0 -I/usr/libbson-1.0
do
if [ -d ${inc} ] ; then
MONGO_CFLAGS="${MONGO_CFLAGS} -I${inc}"
fi
done
MONGO_LIBS="-lmongoc-1.0 -lbson-1.0"
${CC} ${MONGO_TMPCPROGC} -o ${MONGO_TMPCPROGB} ${OSCFLAGS} ${DBCFLAGS} ${DBLIBS} ${MONGO_CFLAGS} ${MONGO_LIBS} ${OSLIBS} 2>>/dev/null
ER=$?
if ! [ ${ER} -eq 0 ] ; then
${ECHO_CMD}
${ECHO_CMD} "MONGODB DEVELOPMENT LIBRARIES (libmongoc-1.0 and libbson-1.0) AND/OR HEADER (mongoc.h)"
${ECHO_CMD} " ARE NOT INSTALLED PROPERLY ON THIS SYSTEM."
${ECHO_CMD} " THAT'S OK BUT THE TURN SERVER IS BUILDING WITHOUT MONGODB SUPPORT."
${ECHO_CMD}
return 0
else
DBCFLAGS="${DBCFLAGS} ${MONGO_CFLAGS}"
DBLIBS="${DBLIBS} ${MONGO_LIBS}"
return 1
fi
}

testlib() {
testlibraw l${1}
}
Expand Down Expand Up @@ -666,6 +692,19 @@ int main(int argc, char** argv) {
}
!

MONGO_TMPCPROG=__test__ccomp__libmongoc__$$
MONGO_TMPCPROGC=${TMPDIR}/${MONGO_TMPCPROG}.c
MONGO_TMPCPROGB=${TMPDIR}/${MONGO_TMPCPROG}

cat > ${MONGO_TMPCPROGC} <<!
#include <mongoc.h>
int main(int argc, char** argv) {
return (argc+
(int)(mongoc_client_new("mongodb://localhost:27017")!=0)+
(int)(argv[0][0]));
}
!

##########################
# What is our compiler ?
##########################
Expand Down Expand Up @@ -940,6 +979,23 @@ else
TURN_NO_MYSQL="-DTURN_NO_MYSQL"
fi

###########################
# Test MongoDB
###########################

if [ -z "${TURN_NO_MONGO}" ] ; then

testlibmongoc
ER=$?
if ! [ ${ER} -eq 0 ] ; then
${ECHO_CMD} "MongoDB found."
else
TURN_NO_MYSQL="-DTURN_NO_MONGO"
fi
else
TURN_NO_MYSQL="-DTURN_NO_MONGO"
fi

###########################
# Test Redis
###########################
Expand Down
14 changes: 11 additions & 3 deletions examples/etc/turnserver.conf
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,14 @@
# Uncomment to use long-term credential mechanism.
# By default no credentials mechanism is used (any user allowed).
# This option can be used with either flat file user database or
# PostgreSQL DB or MySQL DB or Redis DB for user keys storage.
# PostgreSQL DB or MySQL DB or MongoDB or Redis DB for user keys storage.
#
#lt-cred-mech

# Uncomment to use short-term credential mechanism.
# By default no credentials mechanism is used (any user allowed).
# For short-term credential mechanism you have to use PostgreSQL or
# MySQL or Redis database for user password storage.
# MySQL or MongoDB or Redis database for user password storage.
#
#st-cred-mech

Expand Down Expand Up @@ -241,7 +241,7 @@
# 'Dynamic' user accounts database file name.
# Only users for long-term mechanism can be stored in a flat file,
# short-term mechanism will not work with option, the short-term
# mechanism required PostgreSQL or MySQL or Redis database.
# mechanism required PostgreSQL or MySQL or MongoDB or Redis database.
# 'Dynamic' long-term user accounts are dynamically checked by the turnserver process,
# so that they can be changed while the turnserver is running.
#
Expand All @@ -268,6 +268,14 @@
#
#mysql-userdb="host=<host> dbname=<database-name> user=<database-user> password=<database-user-password> port=<port> connect_timeout=<seconds>"

# MongoDB database connection string in the case that we are using MongoDB
# as the user database.
# This database can be used for long-term and short-term credential mechanisms
# and it can store the secret value for secret-based timed authentication in TURN RESP API.
# Use string format is described at http://hergert.me/docs/mongo-c-driver/mongoc_uri.html
#
#mongo-userdb="mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]"

# Redis database connection string in the case that we are using Redis
# as the user database.
# This database can be used for long-term and short-term credential mechanisms
Expand Down
2 changes: 1 addition & 1 deletion postinstall.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ service, you have to:

b) For user accounts settings, if using the turnserver
with authentication: create and edit /etc/turnuserdb.conf
file, or set up PostgreSQL or MySQL or Redis database for user accounts.
file, or set up PostgreSQL or MySQL or MongoDB or Redis database for user accounts.
Use /usr/local/etc/turnuserdb.conf.default as example for flat file DB,
or use /usr/local/share/turnserver/schema.sql as SQL database schema,
or use /usr/local/share/turnserver/schema.userdb.redis as Redis
Expand Down
Loading

0 comments on commit 5c3b773

Please sign in to comment.