Commit a63d21ef authored by Andrey Skryabin's avatar Andrey Skryabin

conncheck: NOMINATION STUN attribute support

Attribute is proposed here: https://tools.ietf.org/html/draft-thatcher-ice-renomination-00
WebRTC supports this attribute: controlling side provides attribute value increased by one
each time selected pair is changed:
https://chromium.googlesource.com/external/webrtc/+/3c7d599750405bc734e1d5adbf1b54265b725a9d/p2p/base/p2ptransportchannel.cc#1821
parent 5496500b
Pipeline #7730 passed with stage
in 1 minute and 2 seconds
......@@ -4257,6 +4257,51 @@ gboolean conn_check_handle_inbound_stun (NiceAgent *agent, NiceStream *stream,
"probably a keepalive.", agent);
}
/* RENOMINATION attribute support */
while (!agent->controlling_mode && agent->compatibility == NICE_COMPATIBILITY_RFC5245) {
uint32_t nom_value = 0;
uint16_t nom_len = 0;
const void *value = stun_message_find (&req, STUN_ATTRIBUTE_NOMINATION, &nom_len);
if (nom_len == 0) {
break;
}
if (nom_len == 4) {
memcpy (&nom_value, value, 4);
nom_value = ntohl (nom_value);
} else {
nice_debug ("Agent %p : received NOMINATION attr with incorrect octet length %u, expected 4 bytes",
agent, nom_len);
break;
}
if (nice_debug_is_enabled ()) {
gchar remote_str[INET6_ADDRSTRLEN];
nice_address_to_string(&remote_candidate->addr, remote_str);
nice_debug ("Agent %p : received NOMINATION attr for remote candidate [%s]:%u, value is %u",
agent, remote_str, nice_address_get_port (&remote_candidate->addr), nom_value);
}
/*
* If another pair is SELECTED, change this pair's priority to be greater than
* selected pair's priority so this pair gets SELECTED!
*/
if (component->selected_pair.priority &&
component->selected_pair.remote && component->selected_pair.remote != remote_candidate &&
component->selected_pair.local && component->selected_pair.local != local_candidate) {
for (i = stream->conncheck_list; i; i = i->next) {
CandidateCheckPair *pair = i->data;
if (pair->local == local_candidate && pair->remote == remote_candidate) {
if (pair->valid) {
pair->priority = component->selected_pair.priority + 1;
}
break;
}
}
}
priv_mark_pair_nominated (agent, stream, component, local_candidate, remote_candidate);
break;
}
return TRUE;
}
......
......@@ -309,8 +309,10 @@ typedef enum
/* 0x8051-0x8053 */ /* reserved */
STUN_ATTRIBUTE_CANDIDATE_IDENTIFIER=0x8054, /* MS-ICE2 */
/* 0x8055-0x806F */ /* reserved */
STUN_ATTRIBUTE_MS_IMPLEMENTATION_VERSION=0x8070 /* MS-ICE2 */
/* 0x8071-0xFFFF */ /* reserved */
STUN_ATTRIBUTE_MS_IMPLEMENTATION_VERSION=0x8070, /* MS-ICE2 */
/* 0x8071-0xC000 */ /* reserved */
STUN_ATTRIBUTE_NOMINATION=0xC001 /* https://tools.ietf.org/html/draft-thatcher-ice-renomination-00 */
/* 0xC002-0xFFFF */ /* reserved */
} StunAttribute;
......
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