Skip to content

Commit a3a7450

Browse files
refactored tri-state to bools (coturn#1709)
refactored random tri-state to use two random booleans for clarity
1 parent 16f801f commit a3a7450

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

src/apps/uclient/startuclient.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -655,14 +655,14 @@ static int clnet_allocate(bool verbose, app_ur_conn_info *clnet_info, ioa_addr *
655655
}
656656

657657
if (dual_allocation && !mobility) {
658-
// TODO: This could be reworked
659-
// it's using t as a tri-state to determine whether to add the requested address family field
660-
// it should be two seperate bools for readability purposes though.
661-
uint8_t t = ((uint8_t)turn_random()) % 3;
662-
if (t) {
658+
uint8_t rand = (uint8_t)turn_random();
659+
bool add_requested_family = rand & 0x01;
660+
bool use_ipv4 = rand & 0x03;
661+
662+
if (add_requested_family) {
663663
uint8_t field[4];
664-
field[0] = (t == 1) ? (uint8_t)STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_IPV4
665-
: (uint8_t)STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_IPV6;
664+
field[0] = (use_ipv4) ? (uint8_t)STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_IPV4
665+
: (uint8_t)STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_IPV6;
666666
field[1] = 0;
667667
field[2] = 0;
668668
field[3] = 0;

0 commit comments

Comments
 (0)