handle "use-candidate" properly

2.2
Richard Fuchs 12 years ago
parent cbc1f8c359
commit 0427b4baf4

@ -213,7 +213,7 @@ static int stream_packet(struct streamrelay *r, str *s, struct sockaddr_in6 *fsi
struct streamrelay *p, *p2; struct streamrelay *p, *p2;
struct peer *pe, *pe2; struct peer *pe, *pe2;
struct callstream *cs; struct callstream *cs;
int ret, update = 0; int ret, update = 0, stun_ret = 0;
struct sockaddr_in sin; struct sockaddr_in sin;
struct sockaddr_in6 sin6; struct sockaddr_in6 sin6;
struct msghdr mh; struct msghdr mh;
@ -236,8 +236,13 @@ static int stream_packet(struct streamrelay *r, str *s, struct sockaddr_in6 *fsi
smart_ntop_port(addr, fsin, sizeof(addr)); smart_ntop_port(addr, fsin, sizeof(addr));
if (r->stun && is_stun(s)) { if (r->stun && is_stun(s)) {
if (!stun(s, r, fsin)) stun_ret = stun(s, r, fsin);
if (!stun_ret)
return 0; return 0;
if (stun_ret == 1) /* use candidate */
goto peerinfo2;
else /* not an stun packet */
stun_ret = 0;
} }
if (p->fd.fd == -1) { if (p->fd.fd == -1) {
@ -271,6 +276,7 @@ peerinfo:
pe->codec = "unknown"; pe->codec = "unknown";
} }
peerinfo2:
p2 = &p->up->rtps[p->idx ^ 1]; p2 = &p->up->rtps[p->idx ^ 1];
p->peer.ip46 = fsin->sin6_addr; p->peer.ip46 = fsin->sin6_addr;
p->peer.port = ntohs(fsin->sin6_port); p->peer.port = ntohs(fsin->sin6_port);
@ -284,7 +290,8 @@ peerinfo:
forward: forward:
if (is_addr_unspecified(&r->peer_advertised.ip46) if (is_addr_unspecified(&r->peer_advertised.ip46)
|| !r->peer_advertised.port || !r->fd.fd_family) || !r->peer_advertised.port || !r->fd.fd_family
|| stun_ret)
goto drop; goto drop;
ZERO(mh); ZERO(mh);
@ -1647,6 +1654,8 @@ static str *streams_print(GQueue *s, int num, enum call_opmode opmode, const cha
goto out; goto out;
t = s->head->data; t = s->head->data;
mutex_lock(&t->lock);
if (format == SAF_TCP) if (format == SAF_TCP)
call_stream_address_gstring(o, &t->peers[off], format); call_stream_address_gstring(o, &t->peers[off], format);
@ -1661,6 +1670,8 @@ static str *streams_print(GQueue *s, int num, enum call_opmode opmode, const cha
g_string_append_printf(o, " %c", (af == AF_INET) ? '4' : '6'); g_string_append_printf(o, " %c", (af == AF_INET) ? '4' : '6');
} }
mutex_unlock(&t->lock);
out: out:
g_string_append(o, "\n"); g_string_append(o, "\n");

@ -767,7 +767,9 @@ static int insert_ice_address(struct sdp_chopper *chop, struct streamrelay *sr)
char buf[64]; char buf[64];
int len; int len;
mutex_lock(&sr->up->up->lock);
call_stream_address(buf, sr->up, SAF_ICE, &len); call_stream_address(buf, sr->up, SAF_ICE, &len);
mutex_unlock(&sr->up->up->lock);
chopper_append_dup(chop, buf, len); chopper_append_dup(chop, buf, len);
chopper_append_printf(chop, " %hu", sr->fd.localport); chopper_append_printf(chop, " %hu", sr->fd.localport);
@ -778,7 +780,9 @@ static int insert_ice_address_alt(struct sdp_chopper *chop, struct streamrelay *
char buf[64]; char buf[64];
int len; int len;
mutex_lock(&sr->up->up->lock);
call_stream_address_alt(buf, sr->up, SAF_ICE, &len); call_stream_address_alt(buf, sr->up, SAF_ICE, &len);
mutex_unlock(&sr->up->up->lock);
chopper_append_dup(chop, buf, len); chopper_append_dup(chop, buf, len);
chopper_append_printf(chop, " %hu", sr->fd.localport); chopper_append_printf(chop, " %hu", sr->fd.localport);
@ -794,7 +798,9 @@ static int replace_network_address(struct sdp_chopper *chop, struct network_addr
if (copy_up_to(chop, &address->address_type)) if (copy_up_to(chop, &address->address_type))
return -1; return -1;
mutex_lock(&sr->up->up->lock);
call_stream_address(buf, sr->up, SAF_NG, &len); call_stream_address(buf, sr->up, SAF_NG, &len);
mutex_unlock(&sr->up->up->lock);
chopper_append_dup(chop, buf, len); chopper_append_dup(chop, buf, len);
if (skip_over(chop, &address->address)) if (skip_over(chop, &address->address))
@ -1081,19 +1087,28 @@ int sdp_replace(struct sdp_chopper *chop, GQueue *sessions, struct call *call,
} }
if (do_ice) { if (do_ice) {
/* XXX locking here? */ mutex_lock(&rtp->up->up->lock);
if (!rtp->up->ice_ufrag.s) { if (!rtp->up->ice_ufrag.s) {
create_random_string(call, &rtp->up->ice_ufrag, 8); create_random_string(call, &rtp->up->ice_ufrag, 8);
create_random_string(call, &rtp->up->ice_pwd, 28); create_random_string(call, &rtp->up->ice_pwd, 28);
} }
rtp->stun = 1;
mutex_unlock(&rtp->up->up->lock);
mutex_lock(&rtcp->up->up->lock);
if (rtp->up != rtcp->up && !rtcp->up->ice_ufrag.s) {
/* safe to read */
rtcp->up->ice_ufrag = rtp->up->ice_ufrag;
rtcp->up->ice_pwd = rtp->up->ice_pwd;
}
rtcp->stun = 1;
mutex_unlock(&rtcp->up->up->lock);
chopper_append_c(chop, "a=ice-ufrag:"); chopper_append_c(chop, "a=ice-ufrag:");
chopper_append_str(chop, &rtp->up->ice_ufrag); chopper_append_str(chop, &rtp->up->ice_ufrag);
chopper_append_c(chop, "\r\na=ice-pwd:"); chopper_append_c(chop, "\r\na=ice-pwd:");
chopper_append_str(chop, &rtp->up->ice_pwd); chopper_append_str(chop, &rtp->up->ice_pwd);
chopper_append_c(chop, "\r\n"); chopper_append_c(chop, "\r\n");
rtp->stun = 1;
rtcp->stun = 1;
} }
if (!flags->ice_remove) { if (!flags->ice_remove) {

Loading…
Cancel
Save