From f8ed0188d5c640ec9caf4ad4e744a5e301b5d813 Mon Sep 17 00:00:00 2001 From: Youness Alaoui Date: Wed, 9 Apr 2014 19:47:54 -0400 Subject: [PATCH] Add support for MS-ICE2 candidate priorization for OC2007R2 compatibility --- agent/agent-priv.h | 4 +++ agent/candidate.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++----- agent/candidate.h | 8 +++++- agent/conncheck.c | 5 +++- agent/discovery.c | 15 +++++++++++ 5 files changed, 100 insertions(+), 9 deletions(-) diff --git a/agent/agent-priv.h b/agent/agent-priv.h index 4e99aba..086b81b 100644 --- a/agent/agent-priv.h +++ b/agent/agent-priv.h @@ -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); diff --git a/agent/candidate.c b/agent/candidate.c index 6874042..ad3fe8c 100644 --- a/agent/candidate.c +++ b/agent/candidate.c @@ -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); diff --git a/agent/candidate.h b/agent/candidate.h index 07dd2d1..b63f7b3 100644 --- a/agent/candidate.h +++ b/agent/candidate.h @@ -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: diff --git a/agent/conncheck.c b/agent/conncheck.c index c35a05d..a9ac439 100644 --- a/agent/conncheck.c +++ b/agent/conncheck.c @@ -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); diff --git a/agent/discovery.c b/agent/discovery.c index b84a36b..e39c2f9 100644 --- a/agent/discovery.c +++ b/agent/discovery.c @@ -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); -- 2.7.4