Skip to content

Instantly share code, notes, and snippets.

@alessandrod
Last active March 23, 2016 00:31
Show Gist options
  • Save alessandrod/c520bbda3dfca6ed930c to your computer and use it in GitHub Desktop.
Save alessandrod/c520bbda3dfca6ed930c to your computer and use it in GitHub Desktop.
diff --git a/agent/conncheck.c b/agent/conncheck.c
index 057fc81..b02754a 100644
--- a/agent/conncheck.c
+++ b/agent/conncheck.c
@@ -2768,14 +2768,31 @@ static gboolean priv_map_reply_to_relay_request (NiceAgent *agent, StunMessage *
agent->compatibility == NICE_COMPATIBILITY_OC2007R2) &&
stun_message_get_class (resp) == STUN_ERROR &&
stun_message_find_error (resp, &code) ==
- STUN_MESSAGE_RETURN_SUCCESS &&
- recv_realm != NULL && recv_realm_len > 0) {
+ STUN_MESSAGE_RETURN_SUCCESS) {
+ nice_debug ("Agent %p : TURN ERROR %d", agent, code);
- if (code == 438 ||
+ if (code == 437 ||
+ code == 438 ||
(code == 401 &&
!(recv_realm_len == sent_realm_len &&
sent_realm != NULL &&
memcmp (sent_realm, recv_realm, sent_realm_len) == 0))) {
+ if (code == 437 && d->turn_retries < 3) {
+ /* retry up to three times on Allocation Mismatch errors */
+ NiceAddress addr = d->nicesock->addr;
+ NiceSocket *new_socket;
+
+ /* FIXME: this ignores nice_agent_set_port_range */
+ nice_address_set_port (&addr, 0);
+
+ new_socket = nice_udp_bsd_socket_new (&addr);
+ if (new_socket) {
+ _priv_set_socket_tos (agent, new_socket, d->stream->tos);
+ component_attach_socket (d->component, new_socket);
+ d->nicesock = new_socket;
+ d->turn_retries += 1;
+ }
+ }
d->stun_resp_msg = *resp;
memcpy (d->stun_resp_buffer, resp->buffer,
stun_message_length (resp));
diff --git a/agent/discovery.h b/agent/discovery.h
index c22ea6a..148b8c2 100644
--- a/agent/discovery.h
+++ b/agent/discovery.h
@@ -56,6 +56,7 @@ typedef struct
Stream *stream;
Component *component;
TurnServer *turn;
+ gint turn_retries;
StunAgent stun_agent;
StunTimer timer;
uint8_t stun_buffer[STUN_MAX_MESSAGE_SIZE_IPV6];
diff --git a/stun/stunagent.c b/stun/stunagent.c
index 2abcc29..0abae3d 100644
--- a/stun/stunagent.c
+++ b/stun/stunagent.c
@@ -301,7 +301,7 @@ StunValidationStatus stun_agent_validate (StunAgent *agent, StunMessage *msg,
} else if (!(stun_message_get_class (msg) == STUN_ERROR &&
stun_message_find_error (msg, &error_code) ==
STUN_MESSAGE_RETURN_SUCCESS &&
- (error_code == 400 || error_code == 401))) {
+ (error_code == 400 || error_code == 401 || error_code == 437))) {
stun_debug ("STUN auth error: No message integrity attribute!");
return STUN_VALIDATION_UNAUTHORIZED;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment