Permalink
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
125 lines (116 sloc) 5.22 KB
# Author: Robert Annessi <robert.annessi@nt.tuwien.ac.at>
# License: GPLv2 (2013-2015)
diff -urN tor-0.2.3.25/src/or/circuitbuild.c tor-0.2.3.25.findpath/src/or/circuitbuild.c
--- tor-0.2.3.25/src/or/circuitbuild.c 2012-11-19 22:24:38.000000000 +0100
+++ tor-0.2.3.25.findpath/src/or/circuitbuild.c 2013-07-22 06:04:20.313574646 +0200
@@ -124,7 +124,6 @@
static int circuit_deliver_create_cell(circuit_t *circ,
uint8_t cell_type, const char *payload);
-static int onion_pick_cpath_exit(origin_circuit_t *circ, extend_info_t *exit);
static crypt_path_t *onion_next_hop_in_cpath(crypt_path_t *cpath);
static int onion_extend_cpath(origin_circuit_t *circ);
static int count_acceptable_nodes(smartlist_t *routers);
@@ -1720,7 +1719,7 @@
* digests for others; if <b>verbose_names</b> is true, use $DIGEST=Name style
* names.
*/
-static char *
+char *
circuit_list_path_impl(origin_circuit_t *circ, int verbose, int verbose_names)
{
crypt_path_t *hop;
@@ -1867,7 +1866,7 @@
/** Pick all the entries in our cpath. Stop and return 0 when we're
* happy, or return -1 if an error occurs. */
-static int
+int
onion_populate_cpath(origin_circuit_t *circ)
{
int r;
@@ -3532,7 +3531,7 @@
/** Decide a suitable length for circ's cpath, and pick an exit
* router (or use <b>exit</b> if provided). Store these in the
* cpath. Return 0 if ok, -1 if circuit should be closed. */
-static int
+int
onion_pick_cpath_exit(origin_circuit_t *circ, extend_info_t *exit)
{
cpath_build_state_t *state = circ->build_state;
diff -urN tor-0.2.3.25/src/or/circuitbuild.h tor-0.2.3.25.findpath/src/or/circuitbuild.h
--- tor-0.2.3.25/src/or/circuitbuild.h 2012-11-19 22:24:38.000000000 +0100
+++ tor-0.2.3.25.findpath/src/or/circuitbuild.h 2013-07-22 06:04:20.313574646 +0200
@@ -27,11 +27,14 @@
unsigned marked_for_removal : 1;
} transport_t;
+char *circuit_list_path_impl(origin_circuit_t *circ, int verbose,
+ int verbose_names);
char *circuit_list_path(origin_circuit_t *circ, int verbose);
char *circuit_list_path_for_controller(origin_circuit_t *circ);
void circuit_log_path(int severity, unsigned int domain,
origin_circuit_t *circ);
void circuit_rep_hist_note_result(origin_circuit_t *circ);
+int onion_populate_cpath(origin_circuit_t *circ);
origin_circuit_t *origin_circuit_init(uint8_t purpose, int flags);
origin_circuit_t *circuit_establish_circuit(uint8_t purpose,
extend_info_t *exit,
@@ -53,6 +56,7 @@
int circuit_all_predicted_ports_handled(time_t now, int *need_uptime,
int *need_capacity);
+int onion_pick_cpath_exit(origin_circuit_t *circ, extend_info_t *exit);
int circuit_append_new_exit(origin_circuit_t *circ, extend_info_t *info);
int circuit_extend_to_new_exit(origin_circuit_t *circ, extend_info_t *info);
void onion_append_to_cpath(crypt_path_t **head_ptr, crypt_path_t *new_hop);
diff -urN tor-0.2.3.25/src/or/circuituse.c tor-0.2.3.25.findpath/src/or/circuituse.c
--- tor-0.2.3.25/src/or/circuituse.c 2012-11-19 22:24:38.000000000 +0100
+++ tor-0.2.3.25.findpath/src/or/circuituse.c 2013-07-22 06:39:02.462544201 +0200
@@ -1271,7 +1271,7 @@
/** Don't retry launching a new circuit if we try this many times with no
* success. */
-#define MAX_CIRCUIT_FAILURES 5
+#define MAX_CIRCUIT_FAILURES 1000
/** Launch a new circuit; see circuit_launch_by_extend_info() for
* details on arguments. */
diff -urN tor-0.2.3.25/src/or/control.c tor-0.2.3.25.findpath/src/or/control.c
--- tor-0.2.3.25/src/or/control.c 2012-11-19 22:24:38.000000000 +0100
+++ tor-0.2.3.25.findpath/src/or/control.c 2013-07-24 04:33:34.226477659 +0200
@@ -2391,6 +2391,31 @@
return strchr(s, '=') && s[0] != '$';
}
+/** Called when we get a FINDPATH message. Find a path but do not establish
+ * a circuit. */
+static int
+handle_control_findpath(control_connection_t *conn)
+{
+ origin_circuit_t *circ = NULL;
+ char *vpath;
+
+ // Find a path. (see circuit_establish_circuit())
+ circ = origin_circuit_init(CIRCUIT_PURPOSE_C_GENERAL, CIRCLAUNCH_NEED_CAPACITY);
+ if (onion_pick_cpath_exit(circ, NULL) < 0 ||
+ onion_populate_cpath(circ) < 0) {
+ circuit_mark_for_close(TO_CIRCUIT(circ), END_CIRC_REASON_NOPATH);
+ connection_write_str_to_buf("551 Couldn't find a path.\r\n", conn);
+ } else {
+ vpath = circuit_list_path_impl(circ, 1, 1);
+ circuit_mark_for_close(TO_CIRCUIT(circ), END_CIRC_REASON_NONE);
+ circuit_reset_failure_count(0);
+ router_set_status(circ->cpath->extend_info->identity_digest, 1);
+ connection_printf_to_buf(conn, "250 PATH %s \r\n", vpath);
+ tor_free(vpath);
+ }
+ return 0;
+}
+
/** Called when we get an EXTENDCIRCUIT message. Try to extend the listed
* circuit, and report success or failure. */
static int
@@ -3404,6 +3429,9 @@
} else if (!strcasecmp(conn->incoming_cmd, "EXTENDCIRCUIT")) {
if (handle_control_extendcircuit(conn, cmd_data_len, args))
return -1;
+ } else if (!strcasecmp(conn->incoming_cmd, "FINDPATH")) {
+ if (handle_control_findpath(conn))
+ return -1;
} else if (!strcasecmp(conn->incoming_cmd, "SETCIRCUITPURPOSE")) {
if (handle_control_setcircuitpurpose(conn, cmd_data_len, args))
return -1;