Commit f8ed0188 authored by Youness Alaoui's avatar Youness Alaoui Committed by Olivier Crête

Add support for MS-ICE2 candidate priorization for OC2007R2 compatibility

parent 6263028e
......@@ -247,6 +247,10 @@ guint32
nice_candidate_ice_priority (const NiceCandidate *candidate,
gboolean reliable, gboolean nat_assisted);
guint32
nice_candidate_ms_ice_priority (const NiceCandidate *candidate,
gboolean reliable, gboolean nat_assisted);
guint64
nice_candidate_pair_priority (guint32 o_prio, guint32 a_prio);
......
......@@ -134,7 +134,7 @@ nice_candidate_ice_priority_full (
}
static guint32
nice_candidate_ice_local_priority_full (guint direction_preference,
nice_candidate_ice_local_preference_full (guint direction_preference,
guint other_preference)
{
return (0x2000 * direction_preference +
......@@ -142,7 +142,7 @@ nice_candidate_ice_local_priority_full (guint direction_preference,
}
static guint16
nice_candidate_ice_local_priority (const NiceCandidate *candidate)
nice_candidate_ice_local_preference (const NiceCandidate *candidate)
{
guint direction_preference;
......@@ -175,15 +175,50 @@ nice_candidate_ice_local_priority (const NiceCandidate *candidate)
break;
}
return nice_candidate_ice_local_priority_full (direction_preference, 1);
return nice_candidate_ice_local_preference_full (direction_preference, 1);
}
guint32
nice_candidate_ice_priority (const NiceCandidate *candidate,
static guint32
nice_candidate_ms_ice_local_preference_full (guint transport_preference,
guint direction_preference, guint other_preference)
{
return 0x1000 * transport_preference +
0x200 * direction_preference +
0x1 * other_preference;
}
static guint32
nice_candidate_ms_ice_local_preference (const NiceCandidate *candidate)
{
guint8 transport_preference = 0;
guint8 direction_preference = 0;
switch (candidate->transport)
{
case NICE_CANDIDATE_TRANSPORT_TCP_SO:
case NICE_CANDIDATE_TRANSPORT_TCP_ACTIVE:
transport_preference = NICE_CANDIDATE_TRANSPORT_MS_PREF_TCP;
direction_preference = NICE_CANDIDATE_DIRECTION_MS_PREF_ACTIVE;
break;
case NICE_CANDIDATE_TRANSPORT_TCP_PASSIVE:
transport_preference = NICE_CANDIDATE_TRANSPORT_MS_PREF_TCP;
direction_preference = NICE_CANDIDATE_DIRECTION_MS_PREF_PASSIVE;
break;
case NICE_CANDIDATE_TRANSPORT_UDP:
default:
transport_preference = NICE_CANDIDATE_TRANSPORT_MS_PREF_UDP;
break;
}
return nice_candidate_ms_ice_local_preference_full(transport_preference,
direction_preference, 0);
}
static guint8
nice_candidate_ice_type_preference (const NiceCandidate *candidate,
gboolean reliable, gboolean nat_assisted)
{
guint8 type_preference;
guint16 local_preference;
switch (candidate->type)
{
......@@ -211,7 +246,35 @@ nice_candidate_ice_priority (const NiceCandidate *candidate,
(!reliable && candidate->transport != NICE_CANDIDATE_TRANSPORT_UDP)) {
type_preference = type_preference / 2;
}
local_preference = nice_candidate_ice_local_priority (candidate);
return type_preference;
}
guint32
nice_candidate_ice_priority (const NiceCandidate *candidate,
gboolean reliable, gboolean nat_assisted)
{
guint8 type_preference;
guint16 local_preference;
type_preference = nice_candidate_ice_type_preference (candidate, reliable,
nat_assisted);
local_preference = nice_candidate_ice_local_preference (candidate);
return nice_candidate_ice_priority_full (type_preference, local_preference,
candidate->component_id);
}
guint32
nice_candidate_ms_ice_priority (const NiceCandidate *candidate,
gboolean reliable, gboolean nat_assisted)
{
guint8 type_preference;
guint16 local_preference;
type_preference = nice_candidate_ice_type_preference (candidate, reliable,
nat_assisted);
local_preference = nice_candidate_ms_ice_local_preference (candidate);
return nice_candidate_ice_priority_full (type_preference, local_preference,
candidate->component_id);
......
......@@ -56,7 +56,7 @@
G_BEGIN_DECLS
/* Constants for determining candidate priorities */
#define NICE_CANDIDATE_TYPE_PREF_HOST 120
#define NICE_CANDIDATE_TYPE_PREF_PEER_REFLEXIVE 110
#define NICE_CANDIDATE_TYPE_PREF_NAT_ASSISTED 105
......@@ -64,6 +64,12 @@ G_BEGIN_DECLS
#define NICE_CANDIDATE_TYPE_PREF_UDP_TUNNELED 75
#define NICE_CANDIDATE_TYPE_PREF_RELAYED 10
/* Priority preference constants for MS-ICE compatibility */
#define NICE_CANDIDATE_TRANSPORT_MS_PREF_UDP 15
#define NICE_CANDIDATE_TRANSPORT_MS_PREF_TCP 6
#define NICE_CANDIDATE_DIRECTION_MS_PREF_PASSIVE 2
#define NICE_CANDIDATE_DIRECTION_MS_PREF_ACTIVE 5
/* Max foundation size '1*32ice-char' plus terminating NULL, ICE ID-19 */
/**
* NICE_CANDIDATE_MAX_FOUNDATION:
......
......@@ -1712,8 +1712,11 @@ int conn_check_send (NiceAgent *agent, CandidateCheckPair *pair)
if (agent->compatibility == NICE_COMPATIBILITY_GOOGLE) {
priority = nice_candidate_jingle_priority (candidate_priority);
} else if (agent->compatibility == NICE_COMPATIBILITY_MSN ||
agent->compatibility == NICE_COMPATIBILITY_OC2007) {
agent->compatibility == NICE_COMPATIBILITY_OC2007) {
priority = nice_candidate_msn_priority (candidate_priority);
} else if (agent->compatibility == NICE_COMPATIBILITY_OC2007R2) {
priority = nice_candidate_ms_ice_priority (candidate_priority,
agent->reliable, FALSE);
} else {
priority = nice_candidate_ice_priority (candidate_priority,
agent->reliable, FALSE);
......
......@@ -485,6 +485,9 @@ NiceCandidate *discovery_add_local_host_candidate (
} else if (agent->compatibility == NICE_COMPATIBILITY_MSN ||
agent->compatibility == NICE_COMPATIBILITY_OC2007) {
candidate->priority = nice_candidate_msn_priority (candidate);
} else if (agent->compatibility == NICE_COMPATIBILITY_OC2007R2) {
candidate->priority = nice_candidate_ms_ice_priority (candidate,
agent->reliable, FALSE);
} else {
candidate->priority = nice_candidate_ice_priority (candidate,
agent->reliable, FALSE);
......@@ -557,6 +560,9 @@ discovery_add_server_reflexive_candidate (
} else if (agent->compatibility == NICE_COMPATIBILITY_MSN ||
agent->compatibility == NICE_COMPATIBILITY_OC2007) {
candidate->priority = nice_candidate_msn_priority (candidate);
} else if (agent->compatibility == NICE_COMPATIBILITY_OC2007R2) {
candidate->priority = nice_candidate_ms_ice_priority (candidate,
agent->reliable, nat_assisted);
} else {
candidate->priority = nice_candidate_ice_priority (candidate,
agent->reliable, nat_assisted);
......@@ -618,6 +624,9 @@ discovery_add_relay_candidate (
} else if (agent->compatibility == NICE_COMPATIBILITY_MSN ||
agent->compatibility == NICE_COMPATIBILITY_OC2007) {
candidate->priority = nice_candidate_msn_priority (candidate);
} else if (agent->compatibility == NICE_COMPATIBILITY_OC2007R2) {
candidate->priority = nice_candidate_ms_ice_priority (candidate,
agent->reliable, FALSE);
} else {
candidate->priority = nice_candidate_ice_priority (candidate,
agent->reliable, FALSE);
......@@ -695,6 +704,9 @@ discovery_add_peer_reflexive_candidate (
} else if (agent->compatibility == NICE_COMPATIBILITY_MSN ||
agent->compatibility == NICE_COMPATIBILITY_OC2007) {
candidate->priority = nice_candidate_msn_priority (candidate);
} else if (agent->compatibility == NICE_COMPATIBILITY_OC2007R2) {
candidate->priority = nice_candidate_ms_ice_priority (candidate,
agent->reliable, FALSE);
} else {
candidate->priority = nice_candidate_ice_priority (candidate,
agent->reliable, FALSE);
......@@ -796,6 +808,9 @@ NiceCandidate *discovery_learn_remote_peer_reflexive_candidate (
} else if (agent->compatibility == NICE_COMPATIBILITY_MSN ||
agent->compatibility == NICE_COMPATIBILITY_OC2007) {
candidate->priority = nice_candidate_msn_priority (candidate);
} else if (agent->compatibility == NICE_COMPATIBILITY_OC2007R2) {
candidate->priority = nice_candidate_ms_ice_priority (candidate,
agent->reliable, FALSE);
} else {
candidate->priority = nice_candidate_ice_priority (candidate,
agent->reliable, FALSE);
......
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