Skip to content

Rotate dns results - #421

Open
PizieDust wants to merge 1 commit into
mirage:mainfrom
robur-coop:shuffle_ips
Open

Rotate dns results#421
PizieDust wants to merge 1 commit into
mirage:mainfrom
robur-coop:shuffle_ips

Conversation

@PizieDust

@PizieDust PizieDust commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

This PR implements shuffling for IP addresses but doesn't randomize the entire list.

cc @reynir @hannesm @dinosaure

@hannesm

hannesm commented Jul 20, 2026

Copy link
Copy Markdown
Member

"but doesn't randomize the entire list" <- would you mind to explain what "the entire list" is?

Comment thread src/dns.ml
Comment on lines +3477 to +3491
let rotate_list lst =
match lst with
| [] | [_] -> lst
| _ ->
let k = Random.int (List.length lst) in
let rec split k acc = function
| [] -> List.rev acc
| x :: xs as l ->
if k = 0 then
l @ (List.rev acc)
else
split (k - 1) (x :: acc) xs
in
split k [] lst
in

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't quite understand what this "rotate_list" implements. Is this based on some common literature about how to shuffle a list?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No it doesn't really shuffle the list. Just changes where the list starts. I think for DNS round robin it's better to rotate the list, since clients always connect to the first IP in the list. By rotating the list we can be sure all IP's get a fair chance of being picked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants