I want to change the Tor relay selection in the SOURCE CODE, I want to tell Tor to select my selected relays in each time it needs to build a circuit instead of randomly selected relays. I know that I can force Tor to select some given relays by modifying Torrc (tor configuration file), but this is not what I want, I need to change the source code, I could not find where in the source code does the relay selection.

  • Why do you need to change this in the source code specifically? Jan 10, 2014 at 0:23
  • This is a research study.
    – MOH
    Jan 10, 2014 at 1:27

1 Answer 1


Functions for node selection and circuit construction can be found in routerlist.c and circuitbuild.c files in src/or directory. Possibly the most relevant ones are the following:

The list may not be exhaustive but should be a good point to start.

In many cases, debug logs can be very helpful for finding responsible code:

[debug] onion_extend_cpath(): Path is 1 long; we want 3
[debug] choose_good_middle_server(): Contemplating intermediate hop: random choice.
[debug] compute_weighted_bandwidths(): Generated weighted bandwidths for rule weight as middle node based on weights Wg=0.378600 Wm=1.000000 We=0.000000 Wd=0.088800 with total bw 0
[debug] extend_info_from_node(): using for Torlol2
[debug] onion_extend_cpath(): Chose router $D12BDD8E7C1C3EDBBDB2FCFF173D8314C8B1E620~Torlol2 at for hop 2 (exit is yahyaoui)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.