Refactor rend_client_refetch_v2_renddesc()
/* Randomly iterate over the replicas until a descriptor can be fetched
* from one of the consecutive nodes, or no options are left. */
tries_left = REND_NUMBER_OF_NON_CONSECUTIVE_REPLICAS;
for (i = 0; i < REND_NUMBER_OF_NON_CONSECUTIVE_REPLICAS; i++)
replicas_left_to_try[i] = i;
while (tries_left > 0) {
int rand = crypto_rand_int(tries_left);
int chosen_replica = replicas_left_to_try[rand];
replicas_left_to_try[rand] = replicas_left_to_try[--tries_left];
[...]
Wow.
I don't know if there are bugs in there or not. I'm not even sure what it's trying to do. And since REND_NUMBER_OF_NON_CONSECUTIVE_REPLICAS is just 2, this sure could get simpler.
It looks like it chooses one of two replicas to start, and then once it's picked those, it picks one of the three relays at that replica? Is that the same distribution as "pick one of the six hsdirs uniformly at random"?