Path Selection - nskinkel/tor GitHub Wiki

Refactoring

The goal here is to refactor the path selection code to have a more clear interface with the rest of tor, be more isolated from the rest of tor, and to collect all the path selection-related stuff into one place.

Files that deal with path selection (possibly not exhaustive list)

Proposed changes

A note on some design decisions: I'm trying to make path selection as isolated as possible (within reason). With that in mind, the idea is that pathsel will only know about nodes, not cpaths. pathsel will take some args (tbd) and produce a smartlist of nodes. The caller can do what they want with this list; for circuits, that probably will mean calling a new function like cpath_from_smartlist or something.

pathsel.h

  • new-ish (renamed from circuitbuild.c)
    • const smartlist_t *choose_onion_path(XXX)
    • const node_t *choose_new_entry_guard(smartlist_t *nodelist, smartlist_t *current_guards, XXX)
    • const node_t *choose_tor2web_rendezvous_node(XXX)
  • from routerlist.c (rename these maybe too):
    • const node_t *router_choose_random_node(XXX)
    • const node_t *node_sl_choose_by_bandwidth(XXX)

pathsel.c

  • from circuitbuild.c:
    • static const node_t *choose_good_exit(XXX)
    • static int count_acceptable_nodes(smartlist_t *routers)
    • static int circuits_can_use_ntor(XXX)
    • static XXX onion_extend_path(XXX)
    • static int new_route_len(XXX)
    • static int node_handles_some_port(XXX)
    • static const node_t *choose_good_exit_server_general(XXX)
    • static const node_t *choose_rendezvous_node(XXX)
    • static const node_t *choose_good_exit_server(XXX)
    • static void warn_if_last_router_excluded(XXX)
    • onion_choose_path_exit(XXX) (still needed?)
    • static const node_t *choose_good_middle_server(XXX)
    • static const node_t *choose_good_entry_server(XXX)
    • static int onion_extend_path(XXX)
  • from routerlist.c:
    • static const node_t *smartlist_choose_node_by_bandwidth_weight(XXX)

Move:

  • circuitbuild.c
    • ap_stream_wants_exit() -> connection.c
  • routerlist.c
    • choose_array_element_by_weight() -> somewhere else Add:
  • routerlist.c:
    • const smartlist_t *get_scaled_bandwidth_weights(XXX) or something similiar. This should basically do compute_weighted_bandwidths(), scale_array_elements_to_u64(), then return.