Browse Source

Merge branch '1and1-redis-onekey-concept-master'

changes/94/11294/1
Richard Fuchs 9 years ago
parent
commit
458d359379
13 changed files with 1185 additions and 114 deletions
  1. +6
    -1
      README.md
  2. +2
    -0
      daemon/Makefile
  3. +7
    -2
      daemon/call.c
  4. +5
    -2
      daemon/call.h
  5. +19
    -5
      daemon/call_interfaces.c
  6. +8
    -0
      daemon/main.c
  7. +7
    -2
      daemon/media_socket.c
  8. +1058
    -93
      daemon/redis.c
  9. +1
    -9
      daemon/redis.h
  10. +48
    -0
      daemon/str.c
  11. +1
    -0
      debian/control
  12. +1
    -0
      debian/ngcp-rtpengine-daemon.init
  13. +22
    -0
      lib/str.h

+ 6
- 1
README.md View File

@ -175,7 +175,8 @@ option and which are reproduced below:
-w, --redis-write=[PW@]IP:PORT/INT Connect to Redis write database -w, --redis-write=[PW@]IP:PORT/INT Connect to Redis write database
-k, --subscribe-keyspace Subscription keyspace list -k, --subscribe-keyspace Subscription keyspace list
--redis-num-threads=INT Number of Redis restore threads --redis-num-threads=INT Number of Redis restore threads
--redis-expires=INT Expire time in seconds for redis keys
--redis-expires=INT Expire time in seconds for redis keys
--redis-multikey Use multiple redis keys for storing the call (old behaviour) DEPRECATED
-q, --no-redis-required Start even if can't connect to redis databases -q, --no-redis-required Start even if can't connect to redis databases
-b, --b2b-url=STRING XMLRPC URL of B2B UA -b, --b2b-url=STRING XMLRPC URL of B2B UA
-L, --log-level=INT Mask log priorities above this level -L, --log-level=INT Mask log priorities above this level
@ -426,6 +427,10 @@ The options are described in more detail below.
Expire time in seconds for redis keys. Default is 86400. Expire time in seconds for redis keys. Default is 86400.
* --redis-multikey
Use multiple redis keys for storing the call (old behaviour) DEPRECATED
* -q, --no-redis-required * -q, --no-redis-required
When this paramter is present or NO_REDIS_REQUIRED='yes' or '1' in config file, rtpengine starts even When this paramter is present or NO_REDIS_REQUIRED='yes' or '1' in config file, rtpengine starts even
if there is no initial connection to redis databases(either to -r or to -w or to both redis). if there is no initial connection to redis databases(either to -r or to -w or to both redis).


+ 2
- 0
daemon/Makefile View File

@ -8,6 +8,7 @@ CFLAGS+= `pkg-config --cflags zlib`
CFLAGS+= `pkg-config --cflags openssl` CFLAGS+= `pkg-config --cflags openssl`
CFLAGS+= `pkg-config --cflags libevent_pthreads` CFLAGS+= `pkg-config --cflags libevent_pthreads`
CFLAGS+= `pcre-config --cflags` CFLAGS+= `pcre-config --cflags`
CFLAGS+= `pkg-config --cflags json-glib-1.0`
CFLAGS+= -I. -I../kernel-module/ -I../lib/ CFLAGS+= -I. -I../kernel-module/ -I../lib/
CFLAGS+= -D_GNU_SOURCE CFLAGS+= -D_GNU_SOURCE
@ -30,6 +31,7 @@ LDFLAGS+= -lpcap
LDFLAGS+= `pcre-config --libs` LDFLAGS+= `pcre-config --libs`
LDFLAGS+= `xmlrpc-c-config client --libs` LDFLAGS+= `xmlrpc-c-config client --libs`
LDFLAGS+= -lhiredis LDFLAGS+= -lhiredis
LDFLAGS+= `pkg-config --libs json-glib-1.0`
include ../lib/lib.Makefile include ../lib/lib.Makefile


+ 7
- 2
daemon/call.c View File

@ -594,8 +594,13 @@ static void callmaster_timer(void *ptr) {
rwlock_unlock_r(&sfd->call->master_lock); rwlock_unlock_r(&sfd->call->master_lock);
if (update)
redis_update(ps->call, m->conf.redis_write);
if (update) {
if (m->conf.redis_multikey) {
redis_update(ps->call, m->conf.redis_write);
} else {
redis_update_onekey(ps->call, m->conf.redis_write);
}
}
next: next:
g_hash_table_remove(hlp.addr_sfd, &ep); g_hash_table_remove(hlp.addr_sfd, &ep);


+ 5
- 2
daemon/call.h View File

@ -5,7 +5,8 @@
/* XXX split everything into call_signalling.[ch] and call_packets.[ch] or w/e */ /* XXX split everything into call_signalling.[ch] and call_packets.[ch] or w/e */
#include <glib-object.h>
#include <json-glib/json-glib.h>
#include <sys/types.h> #include <sys/types.h>
#include <glib.h> #include <glib.h>
@ -443,6 +444,7 @@ struct call {
unsigned int foreign_call; // created_via_redis_notify call unsigned int foreign_call; // created_via_redis_notify call
struct recording *recording; struct recording *recording;
JsonReader *root_reader;
}; };
struct callmaster_config { struct callmaster_config {
@ -460,7 +462,8 @@ struct callmaster_config {
struct event_base *redis_notify_event_base; struct event_base *redis_notify_event_base;
GQueue *redis_subscribed_keyspaces; GQueue *redis_subscribed_keyspaces;
struct redisAsyncContext *redis_notify_async_context; struct redisAsyncContext *redis_notify_async_context;
unsigned int redis_expires_secs;
unsigned int redis_expires_secs;
unsigned int redis_multikey;
char *b2b_url; char *b2b_url;
unsigned char default_tos; unsigned char default_tos;
enum xmlrpc_format fmt; enum xmlrpc_format fmt;


+ 19
- 5
daemon/call_interfaces.c View File

@ -186,7 +186,11 @@ static str *call_update_lookup_udp(char **out, struct callmaster *m, enum call_o
sp.index, sp.index, out[RE_UDP_COOKIE], SAF_UDP); sp.index, sp.index, out[RE_UDP_COOKIE], SAF_UDP);
rwlock_unlock_w(&c->master_lock); rwlock_unlock_w(&c->master_lock);
redis_update(c, m->conf.redis_write);
if (m->conf.redis_multikey) {
redis_update(c, m->conf.redis_write);
} else {
redis_update_onekey(c, m->conf.redis_write);
}
gettimeofday(&(monologue->started), NULL); gettimeofday(&(monologue->started), NULL);
@ -334,7 +338,11 @@ out2:
rwlock_unlock_w(&c->master_lock); rwlock_unlock_w(&c->master_lock);
streams_free(&s); streams_free(&s);
redis_update(c, m->conf.redis_write);
if (m->conf.redis_multikey) {
redis_update(c, m->conf.redis_write);
} else {
redis_update_onekey(c, m->conf.redis_write);
}
ilog(LOG_INFO, "Returning to SIP proxy: "STR_FORMAT"", STR_FMT0(ret)); ilog(LOG_INFO, "Returning to SIP proxy: "STR_FORMAT"", STR_FMT0(ret));
obj_put(c); obj_put(c);
@ -764,10 +772,16 @@ static const char *call_offer_answer_ng(bencode_item_t *input, struct callmaster
} }
rwlock_unlock_w(&call->master_lock); rwlock_unlock_w(&call->master_lock);
if (!flags.no_redis_update)
redis_update(call, m->conf.redis_write);
else
if (!flags.no_redis_update) {
if (m->conf.redis_multikey) {
redis_update(call, m->conf.redis_write);
} else {
redis_update_onekey(call,m->conf.redis_write);
}
} else {
ilog(LOG_DEBUG, "Not updating Redis due to present no-redis-update flag"); ilog(LOG_DEBUG, "Not updating Redis due to present no-redis-update flag");
}
obj_put(call); obj_put(call);
gettimeofday(&(monologue->started), NULL); gettimeofday(&(monologue->started), NULL);


+ 8
- 0
daemon/main.c View File

@ -62,6 +62,7 @@ static unsigned int timeout;
static unsigned int silent_timeout; static unsigned int silent_timeout;
static unsigned int final_timeout; static unsigned int final_timeout;
static unsigned int redis_expires = 86400; static unsigned int redis_expires = 86400;
static unsigned int redis_multikey = 0;
static int port_min = 30000; static int port_min = 30000;
static int port_max = 40000; static int port_max = 40000;
static int max_sessions = -1; static int max_sessions = -1;
@ -298,6 +299,7 @@ static void options(int *argc, char ***argv) {
{ "redis-write",'w', 0, G_OPTION_ARG_STRING, &redisps_write, "Connect to Redis write database", "[PW@]IP:PORT/INT" }, { "redis-write",'w', 0, G_OPTION_ARG_STRING, &redisps_write, "Connect to Redis write database", "[PW@]IP:PORT/INT" },
{ "redis-num-threads", 0, 0, G_OPTION_ARG_INT, &redis_num_threads, "Number of Redis restore threads", "INT" }, { "redis-num-threads", 0, 0, G_OPTION_ARG_INT, &redis_num_threads, "Number of Redis restore threads", "INT" },
{ "redis-expires", 0, 0, G_OPTION_ARG_INT, &redis_expires, "Expire time in seconds for redis keys", "INT" }, { "redis-expires", 0, 0, G_OPTION_ARG_INT, &redis_expires, "Expire time in seconds for redis keys", "INT" },
{ "redis-multikey", 0, 0, G_OPTION_ARG_NONE, &redis_multikey, "Use multiple redis keys for storing the call (old behaviour) DEPRECATED", NULL },
{ "no-redis-required", 'q', 0, G_OPTION_ARG_NONE, &no_redis_required, "Start no matter of redis connection state", NULL }, { "no-redis-required", 'q', 0, G_OPTION_ARG_NONE, &no_redis_required, "Start no matter of redis connection state", NULL },
{ "b2b-url", 'b', 0, G_OPTION_ARG_STRING, &b2b_url, "XMLRPC URL of B2B UA" , "STRING" }, { "b2b-url", 'b', 0, G_OPTION_ARG_STRING, &b2b_url, "XMLRPC URL of B2B UA" , "STRING" },
{ "log-facility",0, 0, G_OPTION_ARG_STRING, &log_facility_s, "Syslog facility to use for logging", "daemon|local0|...|local7"}, { "log-facility",0, 0, G_OPTION_ARG_STRING, &log_facility_s, "Syslog facility to use for logging", "daemon|local0|...|local7"},
@ -502,6 +504,11 @@ static void init_everything() {
#if !GLIB_CHECK_VERSION(2,32,0) #if !GLIB_CHECK_VERSION(2,32,0)
g_thread_init(NULL); g_thread_init(NULL);
#endif #endif
#if !(GLIB_CHECK_VERSION(2,36,0))
g_type_init();
#endif
if (!_log_stderr) if (!_log_stderr)
openlog("rtpengine", LOG_PID | LOG_NDELAY, _log_facility); openlog("rtpengine", LOG_PID | LOG_NDELAY, _log_facility);
signals(); signals();
@ -621,6 +628,7 @@ no_kernel:
} }
mc.redis_expires_secs = redis_expires; mc.redis_expires_secs = redis_expires;
mc.redis_multikey = redis_multikey;
ctx->m->conf = mc; ctx->m->conf = mc;


+ 7
- 2
daemon/media_socket.c View File

@ -1471,8 +1471,13 @@ static void stream_fd_readable(int fd, void *p, uintptr_t u) {
out: out:
ca = sfd->call ? : NULL; ca = sfd->call ? : NULL;
if (ca && update)
redis_update(ca, ca->callmaster->conf.redis_write);
if (ca && update) {
if (ca->callmaster->conf.redis_multikey) {
redis_update(ca, ca->callmaster->conf.redis_write);
} else {
redis_update_onekey(ca, ca->callmaster->conf.redis_write);
}
}
done: done:
log_info_clear(); log_info_clear();
} }


+ 1058
- 93
daemon/redis.c
File diff suppressed because it is too large
View File


+ 1
- 9
daemon/redis.h View File

@ -91,23 +91,15 @@ INLINE gboolean g_hash_table_insert_check(GHashTable *h, gpointer k, gpointer v)
#endif #endif
#define rlog(l, x...) ilog(l | LOG_FLAG_RESTORE, x) #define rlog(l, x...) ilog(l | LOG_FLAG_RESTORE, x)
#define REDIS_FMT(x) (x)->len, (x)->str
void redis_notify_loop(void *d); void redis_notify_loop(void *d);
struct redis *redis_new(const endpoint_t *, int, const char *, enum redis_role, int no_redis_required); struct redis *redis_new(const endpoint_t *, int, const char *, enum redis_role, int no_redis_required);
int redis_restore(struct callmaster *, struct redis *); int redis_restore(struct callmaster *, struct redis *);
void redis_update(struct call *, struct redis *); void redis_update(struct call *, struct redis *);
void redis_update_onekey(struct call *c, struct redis *r);
void redis_delete(struct call *, struct redis *); void redis_delete(struct call *, struct redis *);
void redis_wipe(struct redis *); void redis_wipe(struct redis *);
int redis_notify_event_base_action(struct callmaster *cm, enum event_base_action); int redis_notify_event_base_action(struct callmaster *cm, enum event_base_action);


+ 48
- 0
daemon/str.c View File

@ -48,3 +48,51 @@ char *rand_hex_str(char *rand_str, int num_bytes) {
} }
return rand_str; return rand_str;
} }
static const char *hex_chars = "0123456789abcdef";
int str_uri_encode_len(char *out, const char *in, int len) {
const char *end = in + len;
char *ori_out = out;
while (in < end) {
if (*in < ' ' || *in > '~' || *in == '%' || *in == '\\' || *in == '\'' || *in == '"') {
*(out++) = '%';
*(out++) = hex_chars[(*((unsigned char *) in)) >> 4];
*(out++) = hex_chars[(*((unsigned char *) in)) & 0xf];
in++;
continue;
}
*(out++) = *(in++);
}
*out = 0;
return out - ori_out;
}
int str_uri_decode_len(char **out, const char *in, int in_len) {
const char *end = in + in_len;
*out = malloc(in_len + 1);
char *outp = *out;
while (in < end) {
if (*in != '%') {
*(outp++) = (*in++);
continue;
}
if (end - in < 3 || !g_ascii_isxdigit(in[1]) || !g_ascii_isxdigit(in[2])) {
free(*out);
*out = NULL;
return -1;
}
unsigned char c = g_ascii_xdigit_value(in[1]) << 4 | g_ascii_xdigit_value(in[2]);
*(outp++) = c;
in += 3;
}
*outp = 0;
return outp - *out;
}

+ 1
- 0
debian/control View File

@ -13,6 +13,7 @@ Build-Depends: debhelper (>= 5),
libevent-dev (>= 2.0), libevent-dev (>= 2.0),
libglib2.0-dev (>= 2.30), libglib2.0-dev (>= 2.30),
libhiredis-dev, libhiredis-dev,
libjson-glib-dev,
libpcap0.8-dev | libpcap-dev, libpcap0.8-dev | libpcap-dev,
libpcre3-dev, libpcre3-dev,
libssl-dev (>= 1.0.1), libssl-dev (>= 1.0.1),


+ 1
- 0
debian/ngcp-rtpengine-daemon.init View File

@ -74,6 +74,7 @@ fi
[ -z "$REDIS_WRITE_AUTH_PW" ] || export RTPENGINE_REDIS_WRITE_AUTH_PW="$REDIS_WRITE_AUTH_PW" [ -z "$REDIS_WRITE_AUTH_PW" ] || export RTPENGINE_REDIS_WRITE_AUTH_PW="$REDIS_WRITE_AUTH_PW"
[ -z "$REDIS_NUM_THREADS" ] || OPTIONS="$OPTIONS --redis-num-threads=$REDIS_NUM_THREADS" [ -z "$REDIS_NUM_THREADS" ] || OPTIONS="$OPTIONS --redis-num-threads=$REDIS_NUM_THREADS"
[ -z "$REDIS_EXPIRES" ] || OPTIONS="$OPTIONS --redis-expires=$REDIS_EXPIRES" [ -z "$REDIS_EXPIRES" ] || OPTIONS="$OPTIONS --redis-expires=$REDIS_EXPIRES"
[ -z "$REDIS_MULTIKEY" ] || OPTIONS="$OPTIONS --redis-multikey=$REDIS_MULTIKEY"
[ -z "$NO_REDIS_REQUIRED" -o \( "$NO_REDIS_REQUIRED" != "1" -a "$NO_REDIS_REQUIRED" != "yes" \) ] || OPTIONS="$OPTIONS --no-redis-required" [ -z "$NO_REDIS_REQUIRED" -o \( "$NO_REDIS_REQUIRED" != "1" -a "$NO_REDIS_REQUIRED" != "yes" \) ] || OPTIONS="$OPTIONS --no-redis-required"
[ -z "$B2B_URL" ] || OPTIONS="$OPTIONS --b2b-url=$B2B_URL" [ -z "$B2B_URL" ] || OPTIONS="$OPTIONS --b2b-url=$B2B_URL"
[ -z "$NO_FALLBACK" -o \( "$NO_FALLBACK" != "1" -a "$NO_FALLBACK" != "yes" \) ] || OPTIONS="$OPTIONS --no-fallback" [ -z "$NO_FALLBACK" -o \( "$NO_FALLBACK" != "1" -a "$NO_FALLBACK" != "yes" \) ] || OPTIONS="$OPTIONS --no-fallback"


+ 22
- 0
lib/str.h View File

@ -56,6 +56,8 @@ INLINE str *str_dup(const str *s);
INLINE str *str_chunk_insert(GStringChunk *c, const str *s); INLINE str *str_chunk_insert(GStringChunk *c, const str *s);
/* shifts pointer by len chars and decrements len. returns -1 if buffer too short, 0 otherwise */ /* shifts pointer by len chars and decrements len. returns -1 if buffer too short, 0 otherwise */
INLINE int str_shift(str *s, int len); INLINE int str_shift(str *s, int len);
/* eats the supplied string from the beginning of s. returns -1 if string head doesn't match */
INLINE int str_shift_cmp(str *s, const char *);
/* binary compares str object with memory chunk of equal size */ /* binary compares str object with memory chunk of equal size */
INLINE int str_memcmp(const str *s, void *m); INLINE int str_memcmp(const str *s, void *m);
/* locate a substring within a string, returns character index or -1 */ /* locate a substring within a string, returns character index or -1 */
@ -85,6 +87,12 @@ gboolean str_equal(gconstpointer a, gconstpointer b);
/* destroy function, frees a slice-alloc'd str */ /* destroy function, frees a slice-alloc'd str */
void str_slice_free(void *); void str_slice_free(void *);
/* saves "in" into "out" pseudo-URI encoded. "out" point to a buffer with sufficient length. returns length */
int str_uri_encode_len(char *out, const char *in, int in_len);
INLINE int str_uri_encode(char *out, const str *in);
/* reverse of the above. stores newly allocated buffer in *out. returns length */
int str_uri_decode_len(char **out, const char *in, int in_len);
@ -105,6 +113,16 @@ INLINE int str_shift(str *s, int len) {
s->len -= len; s->len -= len;
return 0; return 0;
} }
INLINE int str_shift_cmp(str *s, const char *t) {
int len = strlen(t);
if (s->len < len)
return -1;
if (memcmp(s->s, t, len))
return -1;
s->s += len;
s->len -= len;
return 0;
}
INLINE char *str_chr(const str *s, int c) { INLINE char *str_chr(const str *s, int c) {
return memchr(s->s, c, s->len); return memchr(s->s, c, s->len);
} }
@ -292,6 +310,10 @@ INLINE int str_token(str *new_token, str *ori_and_remainder, int sep) {
return 0; return 0;
} }
INLINE int str_uri_encode(char *out, const str *in) {
return str_uri_encode_len(out, in->s, in->len);
}
/* Generates a hex string representing n random bytes. len(rand_str) = 2*num_bytes + 1 */ /* Generates a hex string representing n random bytes. len(rand_str) = 2*num_bytes + 1 */
char *rand_hex_str(char *rand_str, int num_bytes); char *rand_hex_str(char *rand_str, int num_bytes);


Loading…
Cancel
Save