Refactor and add comments to new_route_len()
(function in src/or/circuitbuild.c)
At the moment, this function is kind of scary and it should be refactored and heavily documented to avoid future confusion. (This ticket exists because two different developers at different time span over a week expressed concerns about the behavior of HS and this function).
Bit of info on
new_route_len(), this function is called to possibly extend a circuit with an extra hop that matches specific purpose(s). Right now it's testing the given purpose if it is not ESTABLISH_INTRO and TESTING, it will extend it to 4 hops (with exit information).
However, there are other purposes that do NOT need 4 hops. Fortunately, it seems that there are no code paths that end up calling this function with exit info and a purpose that should not be extended (investigated by special, sysrqb, asn and me). But, we all agree that this is very fragile thus the purpose condition in this function should be applied on only purposes that need 4 hops.
Furthermore, add more comments to make sure no more confusion happens with that fairly important function.