Commit 82539c8d authored by Youness Alaoui's avatar Youness Alaoui

Add support sending the correct channelbind/set-active-candidate/options when...

Add support sending the correct channelbind/set-active-candidate/options when we want to get a lock on a peer
parent b226ca68
...@@ -308,11 +308,33 @@ socket_send ( ...@@ -308,11 +308,33 @@ socket_send (
turn_priv *priv = (turn_priv *) sock->priv; turn_priv *priv = (turn_priv *) sock->priv;
StunMessage msg; StunMessage msg;
uint8_t buffer[STUN_MAX_MESSAGE_SIZE]; uint8_t buffer[STUN_MAX_MESSAGE_SIZE];
size_t stun_len; size_t msg_len;
struct sockaddr_storage sa; struct sockaddr_storage sa;
GList *i = priv->channels;
ChannelBinding *binding = NULL;
for (; i; i = i->next) {
ChannelBinding *b = i->data;
if (nice_address_equal (&b->peer, to)) {
binding = b;
break;
}
}
nice_address_copy_to_sockaddr (to, (struct sockaddr *)&sa); nice_address_copy_to_sockaddr (to, (struct sockaddr *)&sa);
if (binding) {
if (priv->compatibility == NICE_UDP_TURN_SOCKET_COMPATIBILITY_DRAFT9 &&
len + sizeof(uint32_t) <= sizeof(buffer)) {
uint16_t len16 = (uint16_t) len;
memcpy (buffer, &binding->channel, sizeof(uint16_t));
memcpy (buffer + sizeof(uint16_t), &len16,sizeof(uint16_t));
memcpy (buffer + sizeof(uint32_t), buf, len);
msg_len = len + sizeof(uint32_t);
} else {
goto send;
}
} else {
if (priv->compatibility == NICE_UDP_TURN_SOCKET_COMPATIBILITY_DRAFT9) { if (priv->compatibility == NICE_UDP_TURN_SOCKET_COMPATIBILITY_DRAFT9) {
if (!stun_agent_init_indication (&priv->agent, &msg, if (!stun_agent_init_indication (&priv->agent, &msg,
buffer, sizeof(buffer), STUN_IND_SEND)) buffer, sizeof(buffer), STUN_IND_SEND))
...@@ -328,28 +350,32 @@ socket_send ( ...@@ -328,28 +350,32 @@ socket_send (
if (stun_message_append32 (&msg, STUN_ATTRIBUTE_MAGIC_COOKIE, if (stun_message_append32 (&msg, STUN_ATTRIBUTE_MAGIC_COOKIE,
TURN_MAGIC_COOKIE) != 0) TURN_MAGIC_COOKIE) != 0)
goto send; goto send;
if (priv->username != NULL && priv->username_len > 0) { if (priv->username != NULL && priv->username_len > 0) {
if (stun_message_append_bytes (&msg, STUN_ATTRIBUTE_USERNAME, if (stun_message_append_bytes (&msg, STUN_ATTRIBUTE_USERNAME,
priv->username, priv->username_len) != 0) priv->username, priv->username_len) != 0)
goto send; goto send;
} }
if (stun_message_append_addr (&msg, STUN_ATTRIBUTE_DESTINATION_ADDRESS, if (stun_message_append_addr (&msg, STUN_ATTRIBUTE_DESTINATION_ADDRESS,
(struct sockaddr *)&sa, sizeof(sa)) != 0) (struct sockaddr *)&sa, sizeof(sa)) != 0)
goto send; goto send;
}
if (priv->compatibility == NICE_UDP_TURN_SOCKET_COMPATIBILITY_GOOGLE &&
priv->current_binding &&
nice_address_equal (&priv->current_binding->peer, to)) {
stun_message_append32 (&msg, STUN_ATTRIBUTE_OPTIONS, 1);
}
}
if (stun_message_append_bytes (&msg, STUN_ATTRIBUTE_DATA, buf, len) != 0) if (stun_message_append_bytes (&msg, STUN_ATTRIBUTE_DATA, buf, len) != 0)
goto send; goto send;
stun_len = stun_agent_finish_message (&priv->agent, &msg, msg_len = stun_agent_finish_message (&priv->agent, &msg,
priv->password, priv->password_len); priv->password, priv->password_len);
}
if (stun_len > 0) { if (msg_len > 0) {
nice_udp_socket_send (priv->udp_socket, &priv->server_addr, nice_udp_socket_send (priv->udp_socket, &priv->server_addr,
stun_len, (gchar *)buffer); msg_len, (gchar *)buffer);
return TRUE; return TRUE;
} }
send: send:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment