Skip to content

Make priority unique at candidate creation time

The idea of this patch series is to determine the candidate priority in a deterministic way, at creation time, instead of relying on functions (ensure_unique_priority, ensure_unique_prflx_priority) that provide a priority depending on the context of other candidates.

The priority uniqueness is obtained by the local preference field (16 bits), used to compute the priority value.

  • local candidates have a local preference that depends on their local IP address position in a fixed list.
  • server-reflexive and peer-reflexive pairs have the local preference of their local base address (computed by the rule of the previous point), the priority uniqueness with other local candidates will come from the type preference field --another field of the priority value--- that is different.
  • relayed candidates uniqueness is obtained by taking into account their "turn server number", from the list of configured turn servers, and their base address just like server-reflexive.

To satisfy the third point, we must fit this information (turn server number and ip address position) in a 16 bits fields, taking into account the other information already packed into it. The challenge came from the ms-ice local preference, that uses:

/* 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

According to these values that must be packed in the local preference, 4 bits are reserved for the transport preference, and 3 bits for the direction preference, it gives 9 bit remaining to encode the turn server number, and the IP address number. (I'm not sure if these value for MS-ICE compat have a particular meaning, but they clearly waste a lot of bits, just to store 4 different states, but anyway let's try to maintain compatibility).

So in the 9 free bits remaining, I choose to encode the IP address number on 6 bits (hence the maximum number of IP address of 63), and the number of TURN servers on 3 bits (the maximum TURN servers is 7).

Edited by Fabrice Bellet

Merge request reports