| 1 | /* librist. SPDX-License-Identifier: BSD-2-Clause |
| 2 | * |
| 3 | * NACK routing peer-selection predicate. Kept in a small standalone |
| 4 | * header so the comparison can be unit-tested in isolation, without |
| 5 | * constructing full peer objects or starting receiver threads. |
| 6 | */ |
| 7 | |
| 8 | #ifndef RIST_NACK_SELECT_H |
| 9 | #define RIST_NACK_SELECT_H |
| 10 | |
| 11 | #include <stdbool.h> |
| 12 | #include <stdint.h> |
| 13 | |
| 14 | /* Decide whether a candidate retransmission peer should replace the |
| 15 | * current best choice for receiving a NACK group. |
| 16 | * |
| 17 | * Selection key, highest precedence first: |
| 18 | * 1. higher recovery_priority wins; |
| 19 | * 2. on equal priority, lower RTT wins. |
| 20 | * |
| 21 | * With the default recovery_priority of 0 on every peer this collapses |
| 22 | * to "lowest RTT wins", matching the historical behaviour. */ |
| 23 | static inline bool rist_nack_peer_preferred(uint32_t cand_priority, |
| 24 | uint64_t cand_rtt, |
| 25 | uint32_t best_priority, |
| 26 | uint64_t best_rtt) |
| 27 | { |
| 28 | return cand_priority > best_priority || |
| 29 | (cand_priority == best_priority && cand_rtt < best_rtt); |
| 30 | } |
| 31 | |
| 32 | #endif /* RIST_NACK_SELECT_H */ |