Skip to main content

priority

Function priority 

Source
pub fn priority(
    type_preference: u8,
    local_preference: u16,
    component: ComponentId,
) -> Priority
Expand description

§5.1.2.1’s formula, exactly as it is printed:

priority = (2^24)*(type preference) +
           (2^8)*(local preference) +
           (2^0)*(256 - component ID)

The ordering this produces is the only thing that makes two independent implementations agree on which pair wins, so it is written once and every caller goes through it.

type_preference is held to §5.1.2.1’s 0..=126; a larger value would put the result past 2^31 − 1, which Priority does not hold. The result is clamped up to Priority::MIN for the one input that yields zero — a relayed candidate (preference 0) that is also the 65536th of its type (local preference 0) for component 256 — because §5.1.2 requires a priority to be “a positive integer”.