refactored tri-state to bools (#1709)

refactored random tri-state to use two random booleans for clarity
This commit is contained in:
redraincatching 2025-07-01 11:41:22 +01:00 committed by GitHub
parent 16f801f646
commit a3a7450104
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -655,14 +655,14 @@ beg_allocate:
}
if (dual_allocation && !mobility) {
// TODO: This could be reworked
// it's using t as a tri-state to determine whether to add the requested address family field
// it should be two seperate bools for readability purposes though.
uint8_t t = ((uint8_t)turn_random()) % 3;
if (t) {
uint8_t rand = (uint8_t)turn_random();
bool add_requested_family = rand & 0x01;
bool use_ipv4 = rand & 0x03;
if (add_requested_family) {
uint8_t field[4];
field[0] = (t == 1) ? (uint8_t)STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_IPV4
: (uint8_t)STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_IPV6;
field[0] = (use_ipv4) ? (uint8_t)STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_IPV4
: (uint8_t)STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_IPV6;
field[1] = 0;
field[2] = 0;
field[3] = 0;