Browse Source

Create compile-time option ("make no-redis") to eliminate all redis-related code from binary

git.mgm/mediaproxy-ng/2.0
Richard Fuchs 15 years ago
parent
commit
0fd9e0dae4
4 changed files with 66 additions and 3 deletions
  1. +19
    -3
      daemon/Makefile
  2. +22
    -0
      daemon/call.c
  3. +11
    -0
      daemon/call.h
  4. +14
    -0
      daemon/main.c

+ 19
- 3
daemon/Makefile View File

@ -1,25 +1,41 @@
REDIS=yes
LIBREDISDIR= libhiredis-v0.10.0-3-gdf203bc LIBREDISDIR= libhiredis-v0.10.0-3-gdf203bc
CC= gcc CC= gcc
CFLAGS= -g -Wall `pkg-config --cflags glib-2.0` `pcre-config --cflags` CFLAGS= -g -Wall `pkg-config --cflags glib-2.0` `pcre-config --cflags`
CFLAGS+= -I/lib/modules/`uname -r`/build/include/ -I../kernel-module/ CFLAGS+= -I/lib/modules/`uname -r`/build/include/ -I../kernel-module/
CFLAGS+= -D_GNU_SOURCE CFLAGS+= -D_GNU_SOURCE
#CFLAGS+= -O2
CFLAGS+= -O2
ifeq ($(REDIS),yes)
CFLAGS+= -I$(LIBREDISDIR) CFLAGS+= -I$(LIBREDISDIR)
else
CFLAGS+= -DNO_REDIS=1
endif
LDFLAGS= `pkg-config --libs glib-2.0` `pcre-config --libs` LDFLAGS= `pkg-config --libs glib-2.0` `pcre-config --libs`
ifeq ($(REDIS),yes)
LDFLAGS+= -L$(LIBREDISDIR) -lhiredis -luuid LDFLAGS+= -L$(LIBREDISDIR) -lhiredis -luuid
endif
SRCS= main.c kernel.c poller.c aux.c control.c streambuf.c call.c control_udp.c redis.c
SRCS= main.c kernel.c poller.c aux.c control.c streambuf.c call.c control_udp.c
ifeq ($(REDIS),yes)
SRCS+= redis.c
endif
OBJS= $(SRCS:.c=.o) OBJS= $(SRCS:.c=.o)
.PHONY: all dep clean tests
.PHONY: all dep clean tests no-redis
all: all:
ifeq ($(REDIS),yes)
make -C $(LIBREDISDIR) static make -C $(LIBREDISDIR) static
endif
make mediaproxy-ng make mediaproxy-ng
no-redis:
make REDIS=no all
tests: tests:
make aux-test poller-test make aux-test poller-test


+ 22
- 0
daemon/call.c View File

@ -8,7 +8,9 @@
#include <arpa/inet.h> #include <arpa/inet.h>
#include <assert.h> #include <assert.h>
#include <errno.h> #include <errno.h>
#ifndef NO_REDIS
#include <hiredis.h> #include <hiredis.h>
#endif
#include <stdlib.h> #include <stdlib.h>
#include "call.h" #include "call.h"
@ -18,7 +20,9 @@
#include "kernel.h" #include "kernel.h"
#include "control.h" #include "control.h"
#include "streambuf.h" #include "streambuf.h"
#ifndef NO_REDIS
#include "redis.h" #include "redis.h"
#endif
@ -193,7 +197,9 @@ static int stream_packet(struct streamrelay *r, char *b, int l, struct sockaddr_
if (pe2->confirmed && pe2->filled) if (pe2->confirmed && pe2->filled)
kernelize(cs); kernelize(cs);
#ifndef NO_REDIS
redis_update(c); redis_update(c);
#endif
} }
skip: skip:
@ -237,6 +243,8 @@ skip:
return -1; return -1;
} }
pe->used = 1;
drop: drop:
r->stats.packets++; r->stats.packets++;
r->stats.bytes += l; r->stats.bytes += l;
@ -760,6 +768,8 @@ static unsigned int call_streams(struct call *c, GQueue *s, const char *tag, int
cs = l->data; cs = l->data;
for (x = 0; x < 2; x++) { for (x = 0; x < 2; x++) {
r = &cs->peers[x].rtps[0]; r = &cs->peers[x].rtps[0];
if (r->up->used)
continue;
if (r->peer.ip != t->ip) if (r->peer.ip != t->ip)
continue; continue;
if (r->peer.port != t->port) if (r->peer.port != t->port)
@ -857,7 +867,9 @@ static void call_destroy(struct call *c) {
struct callstream *s; struct callstream *s;
g_hash_table_remove(m->callhash, c->callid); g_hash_table_remove(m->callhash, c->callid);
#ifndef NO_REDIS
redis_delete(c); redis_delete(c);
#endif
free(c->callid); free(c->callid);
g_hash_table_destroy(c->infohash); g_hash_table_destroy(c->infohash);
@ -957,7 +969,9 @@ char *call_update_udp(const char **o, struct callmaster *m) {
g_queue_clear(&q); g_queue_clear(&q);
#ifndef NO_REDIS
redis_update(c); redis_update(c);
#endif
return streams_print(c->callstreams, 1, 0, o[1], 1); return streams_print(c->callstreams, 1, 0, o[1], 1);
@ -994,7 +1008,9 @@ char *call_lookup_udp(const char **o, struct callmaster *m) {
g_queue_clear(&q); g_queue_clear(&q);
#ifndef NO_REDIS
redis_update(c); redis_update(c);
#endif
return streams_print(c->callstreams, 1, 1, o[1], 1); return streams_print(c->callstreams, 1, 1, o[1], 1);
@ -1016,7 +1032,9 @@ char *call_request(const char **o, struct callmaster *m) {
num = call_streams(c, s, g_hash_table_lookup(c->infohash, "fromtag"), 0); num = call_streams(c, s, g_hash_table_lookup(c->infohash, "fromtag"), 0);
streams_free(s); streams_free(s);
#ifndef NO_REDIS
redis_update(c); redis_update(c);
#endif
return streams_print(c->callstreams, num, 0, NULL, 0); return streams_print(c->callstreams, num, 0, NULL, 0);
} }
@ -1038,7 +1056,9 @@ char *call_lookup(const char **o, struct callmaster *m) {
num = call_streams(c, s, g_hash_table_lookup(c->infohash, "totag"), 1); num = call_streams(c, s, g_hash_table_lookup(c->infohash, "totag"), 1);
streams_free(s); streams_free(s);
#ifndef NO_REDIS
redis_update(c); redis_update(c);
#endif
return streams_print(c->callstreams, num, 1, NULL, 0); return streams_print(c->callstreams, num, 1, NULL, 0);
} }
@ -1135,6 +1155,7 @@ void calls_status(struct callmaster *m, struct control_stream *s) {
#ifndef NO_REDIS
void call_restore(struct callmaster *m, char *uuid, redisReply **hash, GList *streams) { void call_restore(struct callmaster *m, char *uuid, redisReply **hash, GList *streams) {
struct call *c; struct call *c;
struct callstream *cs; struct callstream *cs;
@ -1196,3 +1217,4 @@ void calls_dump_redis(struct callmaster *m) {
g_hash_table_foreach(m->callhash, calls_dump_iterator, NULL); g_hash_table_foreach(m->callhash, calls_dump_iterator, NULL);
mylog(LOG_DEBUG, "Finished dumping all call data to Redis\n"); mylog(LOG_DEBUG, "Finished dumping all call data to Redis\n");
} }
#endif

+ 11
- 0
daemon/call.h View File

@ -6,7 +6,9 @@
#include <sys/types.h> #include <sys/types.h>
#include <glib.h> #include <glib.h>
#ifndef NO_REDIS
#include <hiredis.h> #include <hiredis.h>
#endif
#include "ipt_MEDIAPROXY.h" #include "ipt_MEDIAPROXY.h"
@ -20,7 +22,9 @@ struct peer;
struct callstream; struct callstream;
struct call; struct call;
struct callmaster; struct callmaster;
#ifndef NO_REDIS
struct redis; struct redis;
#endif
@ -50,6 +54,7 @@ struct peer {
int kernelized:1; int kernelized:1;
int filled:1; int filled:1;
int confirmed:1; int confirmed:1;
int used:1;
}; };
struct callstream { struct callstream {
struct peer peers[2]; struct peer peers[2];
@ -62,7 +67,9 @@ struct call {
GQueue *callstreams; GQueue *callstreams;
char *callid; char *callid;
#ifndef NO_REDIS
char redis_uuid[37]; char redis_uuid[37];
#endif
time_t created; time_t created;
char *calling_agent; char *calling_agent;
char *called_agent; char *called_agent;
@ -76,7 +83,9 @@ struct callmaster {
struct mediaproxy_stats stats; struct mediaproxy_stats stats;
struct poller *poller; struct poller *poller;
#ifndef NO_REDIS
struct redis *redis; struct redis *redis;
#endif
int kernelfd; int kernelfd;
unsigned int kernelid; unsigned int kernelid;
u_int32_t ip; u_int32_t ip;
@ -104,8 +113,10 @@ char *call_delete_udp(const char **, struct callmaster *);
void calls_status(struct callmaster *, struct control_stream *); void calls_status(struct callmaster *, struct control_stream *);
#ifndef NO_REDIS
void call_restore(struct callmaster *, char *, redisReply **, GList *); void call_restore(struct callmaster *, char *, redisReply **, GList *);
void calls_dump_redis(struct callmaster *); void calls_dump_redis(struct callmaster *);
#endif


+ 14
- 0
daemon/main.c View File

@ -14,7 +14,9 @@
#include "log.h" #include "log.h"
#include "call.h" #include "call.h"
#include "kernel.h" #include "kernel.h"
#ifndef NO_REDIS
#include "redis.h" #include "redis.h"
#endif
@ -39,9 +41,11 @@ static int timeout;
static int silent_timeout; static int silent_timeout;
static int port_min; static int port_min;
static int port_max; static int port_max;
#ifndef NO_REDIS
static u_int32_t redis_ip; static u_int32_t redis_ip;
static u_int16_t redis_port; static u_int16_t redis_port;
static int redis_db = -1; static int redis_db = -1;
#endif
@ -108,7 +112,9 @@ static void options(int *argc, char ***argv) {
static char *adv_ips; static char *adv_ips;
static char *listenps; static char *listenps;
static char *listenudps; static char *listenudps;
#ifndef NO_REDIS
static char *redisps; static char *redisps;
#endif
static GOptionEntry e[] = { static GOptionEntry e[] = {
{ "table", 't', 0, G_OPTION_ARG_INT, &table, "Kernel table to use", "INT" }, { "table", 't', 0, G_OPTION_ARG_INT, &table, "Kernel table to use", "INT" },
@ -123,8 +129,10 @@ static void options(int *argc, char ***argv) {
{ "foreground", 'f', 0, G_OPTION_ARG_NONE, &foreground, "Don't fork to background", NULL }, { "foreground", 'f', 0, G_OPTION_ARG_NONE, &foreground, "Don't fork to background", NULL },
{ "port-min", 'm', 0, G_OPTION_ARG_INT, &port_min, "Lowest port to use for RTP", "INT" }, { "port-min", 'm', 0, G_OPTION_ARG_INT, &port_min, "Lowest port to use for RTP", "INT" },
{ "port-max", 'M', 0, G_OPTION_ARG_INT, &port_max, "Highest port to use for RTP", "INT" }, { "port-max", 'M', 0, G_OPTION_ARG_INT, &port_max, "Highest port to use for RTP", "INT" },
#ifndef NO_REDIS
{ "redis", 'r', 0, G_OPTION_ARG_STRING, &redisps, "Connect to Redis database", "IP:PORT" }, { "redis", 'r', 0, G_OPTION_ARG_STRING, &redisps, "Connect to Redis database", "IP:PORT" },
{ "redis-db", 'R', 0, G_OPTION_ARG_INT, &redis_db, "Which Redis DB to use", "INT" }, { "redis-db", 'R', 0, G_OPTION_ARG_INT, &redis_db, "Which Redis DB to use", "INT" },
#endif
{ NULL, } { NULL, }
}; };
@ -168,12 +176,14 @@ static void options(int *argc, char ***argv) {
if (silent_timeout <= 0) if (silent_timeout <= 0)
silent_timeout = 3600; silent_timeout = 3600;
#ifndef NO_REDIS
if (redisps) { if (redisps) {
if (parse_ip_port(&redis_ip, &redis_port, redisps) || !redis_ip) if (parse_ip_port(&redis_ip, &redis_port, redisps) || !redis_ip)
die("Invalid IP or port (--redis)\n"); die("Invalid IP or port (--redis)\n");
if (redis_db < 0) if (redis_db < 0)
die("Must specify Redis DB number (--redis-db) when using Redis\n"); die("Must specify Redis DB number (--redis-db) when using Redis\n");
} }
#endif
} }
@ -251,11 +261,13 @@ int main(int argc, char **argv) {
die("Failed to open UDP control connection port\n"); die("Failed to open UDP control connection port\n");
} }
#ifndef NO_REDIS
if (redis_ip) { if (redis_ip) {
m->redis = redis_new(redis_ip, redis_port, redis_db); m->redis = redis_new(redis_ip, redis_port, redis_db);
if (!m->redis) if (!m->redis)
die("Cannot start up without Redis database\n"); die("Cannot start up without Redis database\n");
} }
#endif
mylog(LOG_INFO, "Startup complete"); mylog(LOG_INFO, "Startup complete");
@ -263,10 +275,12 @@ int main(int argc, char **argv) {
daemonize(); daemonize();
wpidfile(); wpidfile();
#ifndef NO_REDIS
if (m->redis) { if (m->redis) {
if (redis_restore(m)) if (redis_restore(m))
die("Refusing to continue without working Redis database\n"); die("Refusing to continue without working Redis database\n");
} }
#endif
for (;;) { for (;;) {
ret = poller_poll(p, 100); ret = poller_poll(p, 100);


Loading…
Cancel
Save