create a random but constant "foundation" string for ice candidates

git.mgm/mediaproxy-ng/2.2
Richard Fuchs 13 years ago
parent dc7c4e7fba
commit 1a2e0d75ea

@ -18,6 +18,7 @@
#include "call.h"
#include "kernel.h"
#include "redis.h"
#include "sdp.h"
@ -330,6 +331,7 @@ static void init_everything() {
openlog("mediaproxy-ng", LOG_PID | LOG_NDELAY, LOG_DAEMON);
signals();
resources();
sdp_init();
}
void redis_mod_verify(void *dlh) {

@ -69,6 +69,9 @@ struct sdp_attribute {
static const char ice_chars[] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
static char ice_foundation[17];
static str ice_foundation_str;
@ -656,19 +659,20 @@ strip:
return 0;
}
static void random_string(char *buf, int len) {
while (len--)
*buf++ = ice_chars[random() % strlen(ice_chars)];
}
static void create_random_string(struct call *call, str *s, int len) {
char buf[30];
char *p;
assert(len < sizeof(buf));
if (s->s)
return;
p = buf;
while (len--)
*p++ = ice_chars[random() % strlen(ice_chars)];
call_str_cpy_len(call, s, buf, p - buf);
random_string(buf, len);
call_str_cpy_len(call, s, buf, len);
}
int sdp_replace(struct sdp_chopper *chop, GQueue *sessions, struct call *call,
@ -748,10 +752,14 @@ int sdp_replace(struct sdp_chopper *chop, GQueue *sessions, struct call *call,
if (flags->ice_force) {
copy_up_to_end_of(chop, &media->s);
/* prio = (2^24) * 126 + (2^8) * 65535 + (256 - componentID) */
chopper_append_c(chop, "a=candidate:1 1 UDP 2130706431 ");
chopper_append_c(chop, "a=candidate:");
chopper_append_str(chop, &ice_foundation_str);
chopper_append_c(chop, " 1 UDP 2130706431 ");
insert_ice_address(chop, m, off, flags, 0);
chopper_append_c(chop, " typ host\r\n");
chopper_append_c(chop, "a=candidate:1 2 UDP 2130706430 ");
chopper_append_c(chop, "a=candidate:");
chopper_append_str(chop, &ice_foundation_str);
chopper_append_c(chop, " 2 UDP 2130706430 ");
insert_ice_address(chop, m, off, flags, 1);
chopper_append_c(chop, " typ host\r\n");
}
@ -765,3 +773,9 @@ error:
mylog(LOG_ERROR, "Error rewriting SDP");
return -1;
}
void sdp_init() {
random_string(ice_foundation, sizeof(ice_foundation) - 1);
ice_foundation_str.s = ice_foundation;
ice_foundation_str.len = sizeof(ice_foundation) - 1;
}

@ -28,6 +28,8 @@ struct sdp_chopper {
int str_len;
};
void sdp_init(void);
int sdp_parse(str *body, GQueue *sessions);
int sdp_streams(const GQueue *sessions, GQueue *streams, GHashTable *);
void sdp_free(GQueue *sessions);

Loading…
Cancel
Save