Skip to content

Commit

Permalink
Fix wrong ICE candidate priority calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
lherman-cs committed Jul 16, 2020
1 parent 01f5160 commit ab547a2
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/source/Ice/IceAgent.c
Original file line number Diff line number Diff line change
Expand Up @@ -2445,7 +2445,15 @@ UINT32 computeCandidatePriority(PIceCandidate pIceCandidate)
localPreference = ICE_PRIORITY_LOCAL_PREFERENCE;
}

return (2 ^ 24) * (typePreference) + (2 ^ 8) * (localPreference) + 255;
// Reference: https://tools.ietf.org/html/rfc5245#section-4.1.2.1
// priority = (2^24)*(type preference) +
// (2^8)*(local preference) +
// (2^0)*(256 - component ID)
//
// Since type preference <= 126 and local preference <= 65535, the maximum possible
// priority is (2^24) * (126) + (2^8) * (65535) + 255 = 2130706431. So, it's safe
// to use UINT32 since 2130706431 < 2 ^ 32.
return (1 << 24) * (typePreference) + (1 << 8) * (localPreference) + 255;
}

UINT64 computeCandidatePairPriority(PIceCandidatePair pIceCandidatePair, BOOL isLocalControlling)
Expand Down

0 comments on commit ab547a2

Please sign in to comment.