2006-02-09 06:46:49 +01:00
|
|
|
/* Copyright (c) 2001 Matej Pfajfar.
|
|
|
|
* Copyright (c) 2001-2004, Roger Dingledine.
|
2007-12-12 22:09:01 +01:00
|
|
|
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
|
2012-06-05 02:58:17 +02:00
|
|
|
* Copyright (c) 2007-2012, The Tor Project, Inc. */
|
2004-05-13 09:24:49 +02:00
|
|
|
/* See LICENSE for licensing information */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \file circuitbuild.c
|
|
|
|
* \brief The actual details of building circuits.
|
|
|
|
**/
|
|
|
|
|
2009-09-01 08:09:54 +02:00
|
|
|
#define CIRCUIT_PRIVATE
|
2009-08-27 10:46:06 +02:00
|
|
|
|
2009-09-01 08:09:54 +02:00
|
|
|
#include "or.h"
|
2010-07-22 01:21:00 +02:00
|
|
|
#include "circuitbuild.h"
|
2010-07-22 09:46:23 +02:00
|
|
|
#include "circuitlist.h"
|
2010-07-22 10:03:40 +02:00
|
|
|
#include "circuituse.h"
|
2010-07-22 10:22:51 +02:00
|
|
|
#include "config.h"
|
2012-09-12 23:34:50 +02:00
|
|
|
#include "confparse.h"
|
2010-07-22 10:32:52 +02:00
|
|
|
#include "connection.h"
|
2010-07-22 10:43:02 +02:00
|
|
|
#include "connection_edge.h"
|
2010-07-22 10:50:34 +02:00
|
|
|
#include "connection_or.h"
|
2010-07-22 11:35:09 +02:00
|
|
|
#include "control.h"
|
2010-07-22 11:54:50 +02:00
|
|
|
#include "directory.h"
|
2010-07-23 19:58:06 +02:00
|
|
|
#include "main.h"
|
2010-07-23 20:18:55 +02:00
|
|
|
#include "networkstatus.h"
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
#include "nodelist.h"
|
2010-07-23 20:38:25 +02:00
|
|
|
#include "onion.h"
|
2010-07-23 20:51:25 +02:00
|
|
|
#include "policies.h"
|
2011-07-18 02:33:31 +02:00
|
|
|
#include "transports.h"
|
2010-07-23 21:53:11 +02:00
|
|
|
#include "relay.h"
|
2010-07-23 22:57:20 +02:00
|
|
|
#include "rephist.h"
|
2010-07-21 16:17:10 +02:00
|
|
|
#include "router.h"
|
2010-07-21 17:08:11 +02:00
|
|
|
#include "routerlist.h"
|
2010-07-23 23:23:43 +02:00
|
|
|
#include "routerparse.h"
|
2012-09-13 18:46:39 +02:00
|
|
|
#include "routerset.h"
|
2012-09-12 23:58:33 +02:00
|
|
|
#include "statefile.h"
|
2009-09-01 08:09:54 +02:00
|
|
|
#include "crypto.h"
|
2009-12-15 20:32:55 +01:00
|
|
|
#undef log
|
|
|
|
#include <math.h>
|
2009-08-28 08:28:20 +02:00
|
|
|
|
2009-10-11 23:23:47 +02:00
|
|
|
#ifndef MIN
|
|
|
|
#define MIN(a,b) ((a)<(b)?(a):(b))
|
|
|
|
#endif
|
|
|
|
|
2010-05-04 23:42:37 +02:00
|
|
|
#define CBT_BIN_TO_MS(bin) ((bin)*CBT_BIN_WIDTH + (CBT_BIN_WIDTH/2))
|
|
|
|
|
2004-05-13 09:24:49 +02:00
|
|
|
/********* START VARIABLES **********/
|
2009-08-26 02:13:12 +02:00
|
|
|
/** Global list of circuit build times */
|
2012-06-15 15:37:40 +02:00
|
|
|
// XXXX: Add this as a member for entry_guard_t instead of global?
|
2009-09-02 00:40:54 +02:00
|
|
|
// Then we could do per-guard statistics, as guards are likely to
|
|
|
|
// vary in their own latency. The downside of this is that guards
|
|
|
|
// can change frequently, so we'd be building a lot more circuits
|
|
|
|
// most likely.
|
2012-06-15 15:37:40 +02:00
|
|
|
/* XXXX024 Make this static; add accessor functions. */
|
2009-08-27 10:46:06 +02:00
|
|
|
circuit_build_times_t circ_times;
|
2004-05-13 09:24:49 +02:00
|
|
|
|
|
|
|
/** A global list of all circuits at this hop. */
|
|
|
|
extern circuit_t *global_circuitlist;
|
|
|
|
|
2006-01-10 23:42:44 +01:00
|
|
|
/** An entry_guard_t represents our information about a chosen long-term
|
2005-12-28 10:07:31 +01:00
|
|
|
* first hop, known as a "helper" node in the literature. We can't just
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
* use a node_t, since we want to remember these even when we
|
|
|
|
* don't have any directory info. */
|
2005-07-22 19:32:25 +02:00
|
|
|
typedef struct {
|
|
|
|
char nickname[MAX_NICKNAME_LEN+1];
|
|
|
|
char identity[DIGEST_LEN];
|
2007-08-29 19:22:00 +02:00
|
|
|
time_t chosen_on_date; /**< Approximately when was this guard added?
|
|
|
|
* "0" if we don't know. */
|
|
|
|
char *chosen_by_version; /**< What tor version added this guard? NULL
|
|
|
|
* if we don't know. */
|
2007-02-23 19:34:35 +01:00
|
|
|
unsigned int made_contact : 1; /**< 0 if we have never connected to this
|
|
|
|
* router, 1 if we have. */
|
|
|
|
unsigned int can_retry : 1; /**< Should we retry connecting to this entry,
|
|
|
|
* in spite of having it marked as unreachable?*/
|
2012-05-04 05:15:34 +02:00
|
|
|
unsigned int path_bias_notice : 1; /**< Did we alert the user about path bias
|
|
|
|
* for this node already? */
|
|
|
|
unsigned int path_bias_disabled : 1; /**< Have we disabled this node because
|
|
|
|
* of path bias issues? */
|
2006-09-29 01:57:44 +02:00
|
|
|
time_t bad_since; /**< 0 if this guard is currently usable, or the time at
|
|
|
|
* which it was observed to become (according to the
|
|
|
|
* directory or the user configuration) unusable. */
|
|
|
|
time_t unreachable_since; /**< 0 if we can connect to this guard, or the
|
|
|
|
* time at which we first noticed we couldn't
|
|
|
|
* connect to it. */
|
2006-09-29 01:57:52 +02:00
|
|
|
time_t last_attempted; /**< 0 if we can connect to this guard, or the time
|
|
|
|
* at which we last failed to connect to it. */
|
2012-05-04 05:15:34 +02:00
|
|
|
|
|
|
|
unsigned first_hops; /**< Number of first hops this guard has completed */
|
|
|
|
unsigned circuit_successes; /**< Number of successfully built circuits using
|
|
|
|
* this guard as first hop. */
|
2006-01-10 23:42:44 +01:00
|
|
|
} entry_guard_t;
|
2005-07-22 19:32:25 +02:00
|
|
|
|
2011-06-21 18:46:50 +02:00
|
|
|
/** Information about a configured bridge. Currently this just matches the
|
|
|
|
* ones in the torrc file, but one day we may be able to learn about new
|
|
|
|
* bridges on our own, and remember them in the state file. */
|
|
|
|
typedef struct {
|
|
|
|
/** Address of the bridge. */
|
|
|
|
tor_addr_t addr;
|
|
|
|
/** TLS port for the bridge. */
|
|
|
|
uint16_t port;
|
|
|
|
/** Boolean: We are re-parsing our bridge list, and we are going to remove
|
|
|
|
* this one if we don't find it in the list of configured bridges. */
|
|
|
|
unsigned marked_for_removal : 1;
|
|
|
|
/** Expected identity digest, or all zero bytes if we don't know what the
|
|
|
|
* digest should be. */
|
|
|
|
char identity[DIGEST_LEN];
|
|
|
|
|
|
|
|
/** Name of pluggable transport protocol taken from its config line. */
|
|
|
|
char *transport_name;
|
|
|
|
|
|
|
|
/** When should we next try to fetch a descriptor for this bridge? */
|
|
|
|
download_status_t fetch_status;
|
|
|
|
} bridge_info_t;
|
|
|
|
|
2006-01-10 23:42:44 +01:00
|
|
|
/** A list of our chosen entry guards. */
|
|
|
|
static smartlist_t *entry_guards = NULL;
|
|
|
|
/** A value of 1 means that the entry_guards list has changed
|
2005-12-25 00:32:35 +01:00
|
|
|
* and those changes need to be flushed to disk. */
|
2006-01-10 23:42:44 +01:00
|
|
|
static int entry_guards_dirty = 0;
|
2005-07-22 19:32:25 +02:00
|
|
|
|
2009-09-07 05:14:13 +02:00
|
|
|
/** If set, we're running the unit tests: we should avoid clobbering
|
2009-09-16 03:00:48 +02:00
|
|
|
* our state file or accessing get_options() or get_or_state() */
|
2009-09-02 05:27:43 +02:00
|
|
|
static int unit_tests = 0;
|
|
|
|
|
2004-05-13 09:24:49 +02:00
|
|
|
/********* END VARIABLES ************/
|
|
|
|
|
2005-05-03 00:35:18 +02:00
|
|
|
static int circuit_deliver_create_cell(circuit_t *circ,
|
2007-01-30 23:19:41 +01:00
|
|
|
uint8_t cell_type, const char *payload);
|
2006-07-23 09:37:35 +02:00
|
|
|
static int onion_pick_cpath_exit(origin_circuit_t *circ, extend_info_t *exit);
|
2005-03-22 01:42:38 +01:00
|
|
|
static crypt_path_t *onion_next_hop_in_cpath(crypt_path_t *cpath);
|
2006-10-07 08:28:50 +02:00
|
|
|
static int onion_extend_cpath(origin_circuit_t *circ);
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
static int count_acceptable_nodes(smartlist_t *routers);
|
2005-06-29 23:46:55 +02:00
|
|
|
static int onion_append_hop(crypt_path_t **head_ptr, extend_info_t *choice);
|
2005-12-28 10:07:31 +01:00
|
|
|
|
2006-01-10 23:42:44 +01:00
|
|
|
static void entry_guards_changed(void);
|
2012-05-04 05:15:34 +02:00
|
|
|
static entry_guard_t *entry_guard_get_by_id_digest(const char *digest);
|
2004-05-13 09:24:49 +02:00
|
|
|
|
2011-06-21 18:46:50 +02:00
|
|
|
static void bridge_free(bridge_info_t *bridge);
|
2004-05-13 09:24:49 +02:00
|
|
|
|
2012-08-17 01:29:19 +02:00
|
|
|
static int entry_guard_inc_first_hop_count(entry_guard_t *guard);
|
|
|
|
static void pathbias_count_success(origin_circuit_t *circ);
|
|
|
|
|
2011-01-17 07:07:31 +01:00
|
|
|
/**
|
|
|
|
* This function decides if CBT learning should be disabled. It returns
|
|
|
|
* true if one or more of the following four conditions are met:
|
|
|
|
*
|
|
|
|
* 1. If the cbtdisabled consensus parameter is set.
|
|
|
|
* 2. If the torrc option LearnCircuitBuildTimeout is false.
|
|
|
|
* 3. If we are a directory authority
|
|
|
|
* 4. If we fail to write circuit build time history to our state file.
|
|
|
|
*/
|
2010-05-08 20:54:29 +02:00
|
|
|
static int
|
|
|
|
circuit_build_times_disabled(void)
|
|
|
|
{
|
2010-05-13 00:31:22 +02:00
|
|
|
if (unit_tests) {
|
2010-05-08 20:54:29 +02:00
|
|
|
return 0;
|
2010-05-13 00:31:22 +02:00
|
|
|
} else {
|
|
|
|
int consensus_disabled = networkstatus_get_param(NULL, "cbtdisabled",
|
2010-12-30 19:54:13 +01:00
|
|
|
0, 0, 1);
|
2010-05-13 00:31:22 +02:00
|
|
|
int config_disabled = !get_options()->LearnCircuitBuildTimeout;
|
|
|
|
int dirauth_disabled = get_options()->AuthoritativeDir;
|
2011-04-29 02:40:15 +02:00
|
|
|
int state_disabled = did_last_state_file_write_fail() ? 1 : 0;
|
2010-05-13 00:31:22 +02:00
|
|
|
|
|
|
|
if (consensus_disabled || config_disabled || dirauth_disabled ||
|
|
|
|
state_disabled) {
|
2012-06-15 15:57:18 +02:00
|
|
|
log_debug(LD_CIRC,
|
2010-05-13 00:31:22 +02:00
|
|
|
"CircuitBuildTime learning is disabled. "
|
|
|
|
"Consensus=%d, Config=%d, AuthDir=%d, StateFile=%d",
|
|
|
|
consensus_disabled, config_disabled, dirauth_disabled,
|
|
|
|
state_disabled);
|
|
|
|
return 1;
|
|
|
|
} else {
|
2012-06-15 15:57:18 +02:00
|
|
|
log_debug(LD_CIRC,
|
2012-06-12 05:36:38 +02:00
|
|
|
"CircuitBuildTime learning is not disabled. "
|
|
|
|
"Consensus=%d, Config=%d, AuthDir=%d, StateFile=%d",
|
|
|
|
consensus_disabled, config_disabled, dirauth_disabled,
|
|
|
|
state_disabled);
|
2010-05-13 00:31:22 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2010-05-08 20:54:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-17 07:07:31 +01:00
|
|
|
/**
|
|
|
|
* Retrieve and bounds-check the cbtmaxtimeouts consensus paramter.
|
|
|
|
*
|
|
|
|
* Effect: When this many timeouts happen in the last 'cbtrecentcount'
|
|
|
|
* circuit attempts, the client should discard all of its history and
|
|
|
|
* begin learning a fresh timeout value.
|
|
|
|
*/
|
2010-01-22 01:10:02 +01:00
|
|
|
static int32_t
|
|
|
|
circuit_build_times_max_timeouts(void)
|
|
|
|
{
|
2012-06-12 05:36:38 +02:00
|
|
|
int32_t cbt_maxtimeouts;
|
|
|
|
|
|
|
|
cbt_maxtimeouts = networkstatus_get_param(NULL, "cbtmaxtimeouts",
|
2010-12-30 19:54:13 +01:00
|
|
|
CBT_DEFAULT_MAX_RECENT_TIMEOUT_COUNT,
|
|
|
|
CBT_MIN_MAX_RECENT_TIMEOUT_COUNT,
|
|
|
|
CBT_MAX_MAX_RECENT_TIMEOUT_COUNT);
|
2012-06-12 05:36:38 +02:00
|
|
|
|
|
|
|
if (!(get_options()->LearnCircuitBuildTimeout)) {
|
|
|
|
log_debug(LD_BUG,
|
|
|
|
"circuit_build_times_max_timeouts() called, cbtmaxtimeouts is"
|
|
|
|
" %d",
|
|
|
|
cbt_maxtimeouts);
|
|
|
|
}
|
|
|
|
|
|
|
|
return cbt_maxtimeouts;
|
2010-01-22 01:10:02 +01:00
|
|
|
}
|
|
|
|
|
2011-01-17 07:07:31 +01:00
|
|
|
/**
|
|
|
|
* Retrieve and bounds-check the cbtnummodes consensus paramter.
|
|
|
|
*
|
|
|
|
* Effect: This value governs how many modes to use in the weighted
|
|
|
|
* average calculation of Pareto parameter Xm. A value of 3 introduces
|
|
|
|
* some bias (2-5% of CDF) under ideal conditions, but allows for better
|
|
|
|
* performance in the event that a client chooses guard nodes of radically
|
|
|
|
* different performance characteristics.
|
|
|
|
*/
|
2010-06-08 06:17:12 +02:00
|
|
|
static int32_t
|
|
|
|
circuit_build_times_default_num_xm_modes(void)
|
|
|
|
{
|
|
|
|
int32_t num = networkstatus_get_param(NULL, "cbtnummodes",
|
2010-12-30 19:54:13 +01:00
|
|
|
CBT_DEFAULT_NUM_XM_MODES,
|
|
|
|
CBT_MIN_NUM_XM_MODES,
|
|
|
|
CBT_MAX_NUM_XM_MODES);
|
2012-06-12 05:36:38 +02:00
|
|
|
|
|
|
|
if (!(get_options()->LearnCircuitBuildTimeout)) {
|
|
|
|
log_debug(LD_BUG,
|
|
|
|
"circuit_build_times_default_num_xm_modes() called, cbtnummodes"
|
|
|
|
" is %d",
|
|
|
|
num);
|
|
|
|
}
|
|
|
|
|
2010-06-08 06:17:12 +02:00
|
|
|
return num;
|
|
|
|
}
|
|
|
|
|
2011-01-17 07:07:31 +01:00
|
|
|
/**
|
|
|
|
* Retrieve and bounds-check the cbtmincircs consensus paramter.
|
|
|
|
*
|
|
|
|
* Effect: This is the minimum number of circuits to build before
|
|
|
|
* computing a timeout.
|
|
|
|
*/
|
2010-01-22 01:10:02 +01:00
|
|
|
static int32_t
|
|
|
|
circuit_build_times_min_circs_to_observe(void)
|
|
|
|
{
|
|
|
|
int32_t num = networkstatus_get_param(NULL, "cbtmincircs",
|
2010-12-30 19:54:13 +01:00
|
|
|
CBT_DEFAULT_MIN_CIRCUITS_TO_OBSERVE,
|
|
|
|
CBT_MIN_MIN_CIRCUITS_TO_OBSERVE,
|
|
|
|
CBT_MAX_MIN_CIRCUITS_TO_OBSERVE);
|
2012-06-12 05:36:38 +02:00
|
|
|
|
|
|
|
if (!(get_options()->LearnCircuitBuildTimeout)) {
|
|
|
|
log_debug(LD_BUG,
|
|
|
|
"circuit_build_times_min_circs_to_observe() called, cbtmincircs"
|
|
|
|
" is %d",
|
|
|
|
num);
|
|
|
|
}
|
|
|
|
|
2010-01-22 01:10:02 +01:00
|
|
|
return num;
|
|
|
|
}
|
|
|
|
|
2010-09-30 00:01:22 +02:00
|
|
|
/** Return true iff <b>cbt</b> has recorded enough build times that we
|
|
|
|
* want to start acting on the timeout it implies. */
|
|
|
|
int
|
|
|
|
circuit_build_times_enough_to_compute(circuit_build_times_t *cbt)
|
|
|
|
{
|
|
|
|
return cbt->total_build_times >= circuit_build_times_min_circs_to_observe();
|
|
|
|
}
|
|
|
|
|
2011-01-17 07:07:31 +01:00
|
|
|
/**
|
|
|
|
* Retrieve and bounds-check the cbtquantile consensus paramter.
|
|
|
|
*
|
|
|
|
* Effect: This is the position on the quantile curve to use to set the
|
|
|
|
* timeout value. It is a percent (10-99).
|
|
|
|
*/
|
2010-01-22 01:10:02 +01:00
|
|
|
double
|
|
|
|
circuit_build_times_quantile_cutoff(void)
|
|
|
|
{
|
|
|
|
int32_t num = networkstatus_get_param(NULL, "cbtquantile",
|
2010-12-30 19:54:13 +01:00
|
|
|
CBT_DEFAULT_QUANTILE_CUTOFF,
|
|
|
|
CBT_MIN_QUANTILE_CUTOFF,
|
|
|
|
CBT_MAX_QUANTILE_CUTOFF);
|
2012-06-12 05:36:38 +02:00
|
|
|
|
|
|
|
if (!(get_options()->LearnCircuitBuildTimeout)) {
|
|
|
|
log_debug(LD_BUG,
|
|
|
|
"circuit_build_times_quantile_cutoff() called, cbtquantile"
|
|
|
|
" is %d",
|
|
|
|
num);
|
|
|
|
}
|
|
|
|
|
2010-01-22 01:10:02 +01:00
|
|
|
return num/100.0;
|
|
|
|
}
|
|
|
|
|
2012-06-05 01:51:00 +02:00
|
|
|
/* DOCDOC circuit_build_times_get_bw_scale */
|
2010-12-30 19:54:13 +01:00
|
|
|
int
|
|
|
|
circuit_build_times_get_bw_scale(networkstatus_t *ns)
|
|
|
|
{
|
|
|
|
return networkstatus_get_param(ns, "bwweightscale",
|
|
|
|
BW_WEIGHT_SCALE,
|
|
|
|
BW_MIN_WEIGHT_SCALE,
|
|
|
|
BW_MAX_WEIGHT_SCALE);
|
|
|
|
}
|
|
|
|
|
2011-01-17 07:07:31 +01:00
|
|
|
/**
|
|
|
|
* Retrieve and bounds-check the cbtclosequantile consensus paramter.
|
|
|
|
*
|
|
|
|
* Effect: This is the position on the quantile curve to use to set the
|
|
|
|
* timeout value to use to actually close circuits. It is a percent
|
|
|
|
* (0-99).
|
|
|
|
*/
|
2010-06-08 10:01:47 +02:00
|
|
|
static double
|
|
|
|
circuit_build_times_close_quantile(void)
|
|
|
|
{
|
2011-01-15 19:31:23 +01:00
|
|
|
int32_t param;
|
|
|
|
/* Cast is safe - circuit_build_times_quantile_cutoff() is capped */
|
|
|
|
int32_t min = (int)tor_lround(100*circuit_build_times_quantile_cutoff());
|
|
|
|
param = networkstatus_get_param(NULL, "cbtclosequantile",
|
2010-12-30 19:54:13 +01:00
|
|
|
CBT_DEFAULT_CLOSE_QUANTILE,
|
2011-01-15 19:31:23 +01:00
|
|
|
CBT_MIN_CLOSE_QUANTILE,
|
|
|
|
CBT_MAX_CLOSE_QUANTILE);
|
2012-06-12 05:36:38 +02:00
|
|
|
|
|
|
|
if (!(get_options()->LearnCircuitBuildTimeout)) {
|
|
|
|
log_debug(LD_BUG,
|
|
|
|
"circuit_build_times_close_quantile() called, cbtclosequantile"
|
|
|
|
" is %d", param);
|
|
|
|
}
|
|
|
|
|
2011-01-15 19:31:23 +01:00
|
|
|
if (param < min) {
|
|
|
|
log_warn(LD_DIR, "Consensus parameter cbtclosequantile is "
|
|
|
|
"too small, raising to %d", min);
|
|
|
|
param = min;
|
|
|
|
}
|
|
|
|
return param / 100.0;
|
2010-06-08 10:01:47 +02:00
|
|
|
}
|
|
|
|
|
2011-01-17 07:07:31 +01:00
|
|
|
/**
|
|
|
|
* Retrieve and bounds-check the cbttestfreq consensus paramter.
|
|
|
|
*
|
|
|
|
* Effect: Describes how often in seconds to build a test circuit to
|
|
|
|
* gather timeout values. Only applies if less than 'cbtmincircs'
|
|
|
|
* have been recorded.
|
|
|
|
*/
|
2010-01-22 01:10:02 +01:00
|
|
|
static int32_t
|
|
|
|
circuit_build_times_test_frequency(void)
|
|
|
|
{
|
|
|
|
int32_t num = networkstatus_get_param(NULL, "cbttestfreq",
|
2010-12-30 19:54:13 +01:00
|
|
|
CBT_DEFAULT_TEST_FREQUENCY,
|
|
|
|
CBT_MIN_TEST_FREQUENCY,
|
|
|
|
CBT_MAX_TEST_FREQUENCY);
|
2012-06-12 05:36:38 +02:00
|
|
|
|
|
|
|
if (!(get_options()->LearnCircuitBuildTimeout)) {
|
|
|
|
log_debug(LD_BUG,
|
|
|
|
"circuit_build_times_test_frequency() called, cbttestfreq is %d",
|
|
|
|
num);
|
|
|
|
}
|
|
|
|
|
2010-01-22 01:10:02 +01:00
|
|
|
return num;
|
|
|
|
}
|
|
|
|
|
2011-01-17 07:07:31 +01:00
|
|
|
/**
|
2011-05-30 00:52:37 +02:00
|
|
|
* Retrieve and bounds-check the cbtmintimeout consensus parameter.
|
2011-01-17 07:07:31 +01:00
|
|
|
*
|
|
|
|
* Effect: This is the minimum allowed timeout value in milliseconds.
|
|
|
|
* The minimum is to prevent rounding to 0 (we only check once
|
|
|
|
* per second).
|
|
|
|
*/
|
2010-01-22 01:10:02 +01:00
|
|
|
static int32_t
|
|
|
|
circuit_build_times_min_timeout(void)
|
|
|
|
{
|
|
|
|
int32_t num = networkstatus_get_param(NULL, "cbtmintimeout",
|
2010-12-30 19:54:13 +01:00
|
|
|
CBT_DEFAULT_TIMEOUT_MIN_VALUE,
|
|
|
|
CBT_MIN_TIMEOUT_MIN_VALUE,
|
|
|
|
CBT_MAX_TIMEOUT_MIN_VALUE);
|
2012-06-12 05:36:38 +02:00
|
|
|
|
|
|
|
if (!(get_options()->LearnCircuitBuildTimeout)) {
|
|
|
|
log_debug(LD_BUG,
|
|
|
|
"circuit_build_times_min_timeout() called, cbtmintimeout is %d",
|
|
|
|
num);
|
|
|
|
}
|
|
|
|
|
2010-01-22 01:10:02 +01:00
|
|
|
return num;
|
|
|
|
}
|
|
|
|
|
2011-01-17 07:07:31 +01:00
|
|
|
/**
|
|
|
|
* Retrieve and bounds-check the cbtinitialtimeout consensus paramter.
|
|
|
|
*
|
|
|
|
* Effect: This is the timeout value to use before computing a timeout,
|
|
|
|
* in milliseconds.
|
|
|
|
*/
|
2010-01-22 01:10:02 +01:00
|
|
|
int32_t
|
|
|
|
circuit_build_times_initial_timeout(void)
|
|
|
|
{
|
2011-01-15 19:31:23 +01:00
|
|
|
int32_t min = circuit_build_times_min_timeout();
|
|
|
|
int32_t param = networkstatus_get_param(NULL, "cbtinitialtimeout",
|
|
|
|
CBT_DEFAULT_TIMEOUT_INITIAL_VALUE,
|
|
|
|
CBT_MIN_TIMEOUT_INITIAL_VALUE,
|
|
|
|
CBT_MAX_TIMEOUT_INITIAL_VALUE);
|
2012-06-12 05:36:38 +02:00
|
|
|
|
|
|
|
if (!(get_options()->LearnCircuitBuildTimeout)) {
|
|
|
|
log_debug(LD_BUG,
|
|
|
|
"circuit_build_times_initial_timeout() called, "
|
|
|
|
"cbtinitialtimeout is %d",
|
|
|
|
param);
|
|
|
|
}
|
|
|
|
|
2011-01-15 19:31:23 +01:00
|
|
|
if (param < min) {
|
|
|
|
log_warn(LD_DIR, "Consensus parameter cbtinitialtimeout is too small, "
|
|
|
|
"raising to %d", min);
|
|
|
|
param = min;
|
|
|
|
}
|
|
|
|
return param;
|
2010-01-22 01:10:02 +01:00
|
|
|
}
|
|
|
|
|
2011-01-17 07:07:31 +01:00
|
|
|
/**
|
|
|
|
* Retrieve and bounds-check the cbtrecentcount consensus paramter.
|
|
|
|
*
|
|
|
|
* Effect: This is the number of circuit build times to keep track of
|
|
|
|
* for deciding if we hit cbtmaxtimeouts and need to reset our state
|
|
|
|
* and learn a new timeout.
|
|
|
|
*/
|
2010-01-22 01:10:02 +01:00
|
|
|
static int32_t
|
2010-12-30 19:54:13 +01:00
|
|
|
circuit_build_times_recent_circuit_count(networkstatus_t *ns)
|
2010-01-22 01:10:02 +01:00
|
|
|
{
|
2012-06-12 05:36:38 +02:00
|
|
|
int32_t num;
|
|
|
|
num = networkstatus_get_param(ns, "cbtrecentcount",
|
|
|
|
CBT_DEFAULT_RECENT_CIRCUITS,
|
|
|
|
CBT_MIN_RECENT_CIRCUITS,
|
|
|
|
CBT_MAX_RECENT_CIRCUITS);
|
|
|
|
|
|
|
|
if (!(get_options()->LearnCircuitBuildTimeout)) {
|
|
|
|
log_debug(LD_BUG,
|
|
|
|
"circuit_build_times_recent_circuit_count() called, "
|
|
|
|
"cbtrecentcount is %d",
|
|
|
|
num);
|
|
|
|
}
|
|
|
|
|
|
|
|
return num;
|
2010-01-22 01:10:02 +01:00
|
|
|
}
|
|
|
|
|
2010-02-10 21:25:06 +01:00
|
|
|
/**
|
|
|
|
* This function is called when we get a consensus update.
|
|
|
|
*
|
|
|
|
* It checks to see if we have changed any consensus parameters
|
|
|
|
* that require reallocation or discard of previous stats.
|
|
|
|
*/
|
2010-01-22 01:10:02 +01:00
|
|
|
void
|
|
|
|
circuit_build_times_new_consensus_params(circuit_build_times_t *cbt,
|
|
|
|
networkstatus_t *ns)
|
|
|
|
{
|
2012-06-12 20:52:38 +02:00
|
|
|
int32_t num;
|
2010-01-22 01:10:02 +01:00
|
|
|
|
2012-06-12 20:52:38 +02:00
|
|
|
/*
|
|
|
|
* First check if we're doing adaptive timeouts at all; nothing to
|
|
|
|
* update if we aren't.
|
|
|
|
*/
|
2010-01-22 01:10:02 +01:00
|
|
|
|
2012-06-12 20:52:38 +02:00
|
|
|
if (!circuit_build_times_disabled()) {
|
|
|
|
num = circuit_build_times_recent_circuit_count(ns);
|
|
|
|
|
|
|
|
if (num > 0) {
|
|
|
|
if (num != cbt->liveness.num_recent_circs) {
|
|
|
|
int8_t *recent_circs;
|
|
|
|
log_notice(LD_CIRC, "The Tor Directory Consensus has changed how many "
|
|
|
|
"circuits we must track to detect network failures from %d "
|
|
|
|
"to %d.", cbt->liveness.num_recent_circs, num);
|
|
|
|
|
|
|
|
tor_assert(cbt->liveness.timeouts_after_firsthop ||
|
|
|
|
cbt->liveness.num_recent_circs == 0);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Technically this is a circular array that we are reallocating
|
|
|
|
* and memcopying. However, since it only consists of either 1s
|
|
|
|
* or 0s, and is only used in a statistical test to determine when
|
|
|
|
* we should discard our history after a sufficient number of 1's
|
|
|
|
* have been reached, it is fine if order is not preserved or
|
|
|
|
* elements are lost.
|
|
|
|
*
|
|
|
|
* cbtrecentcount should only be changing in cases of severe network
|
|
|
|
* distress anyway, so memory correctness here is paramount over
|
|
|
|
* doing acrobatics to preserve the array.
|
|
|
|
*/
|
|
|
|
recent_circs = tor_malloc_zero(sizeof(int8_t)*num);
|
|
|
|
if (cbt->liveness.timeouts_after_firsthop &&
|
|
|
|
cbt->liveness.num_recent_circs > 0) {
|
|
|
|
memcpy(recent_circs, cbt->liveness.timeouts_after_firsthop,
|
|
|
|
sizeof(int8_t)*MIN(num, cbt->liveness.num_recent_circs));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Adjust the index if it needs it.
|
|
|
|
if (num < cbt->liveness.num_recent_circs) {
|
|
|
|
cbt->liveness.after_firsthop_idx = MIN(num-1,
|
|
|
|
cbt->liveness.after_firsthop_idx);
|
|
|
|
}
|
|
|
|
|
|
|
|
tor_free(cbt->liveness.timeouts_after_firsthop);
|
|
|
|
cbt->liveness.timeouts_after_firsthop = recent_circs;
|
|
|
|
cbt->liveness.num_recent_circs = num;
|
|
|
|
}
|
|
|
|
/* else no change, nothing to do */
|
2012-06-13 04:31:01 +02:00
|
|
|
} else { /* num == 0 */
|
2012-06-12 20:52:38 +02:00
|
|
|
/*
|
|
|
|
* Weird. This probably shouldn't happen, so log a warning, but try
|
|
|
|
* to do something sensible anyway.
|
|
|
|
*/
|
|
|
|
|
|
|
|
log_warn(LD_CIRC,
|
|
|
|
"The cbtrecentcircs consensus parameter came back zero! "
|
|
|
|
"This disables adaptive timeouts since we can't keep track of "
|
|
|
|
"any recent circuits.");
|
|
|
|
|
2012-06-13 04:27:37 +02:00
|
|
|
circuit_build_times_free_timeouts(cbt);
|
2012-06-12 20:52:38 +02:00
|
|
|
}
|
2012-06-13 04:31:01 +02:00
|
|
|
} else {
|
2010-02-10 21:25:06 +01:00
|
|
|
/*
|
2012-06-12 20:52:38 +02:00
|
|
|
* Adaptive timeouts are disabled; this might be because of the
|
|
|
|
* LearnCircuitBuildTimes config parameter, and hence permanent, or
|
|
|
|
* the cbtdisabled consensus parameter, so it may be a new condition.
|
|
|
|
* Treat it like getting num == 0 above and free the circuit history
|
|
|
|
* if we have any.
|
2010-02-10 21:25:06 +01:00
|
|
|
*/
|
2012-06-12 20:52:38 +02:00
|
|
|
|
2012-06-13 04:27:37 +02:00
|
|
|
circuit_build_times_free_timeouts(cbt);
|
2010-01-22 01:10:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-07 05:14:13 +02:00
|
|
|
/** Make a note that we're running unit tests (rather than running Tor
|
|
|
|
* itself), so we avoid clobbering our state file. */
|
2009-09-02 05:27:43 +02:00
|
|
|
void
|
|
|
|
circuitbuild_running_unit_tests(void)
|
|
|
|
{
|
|
|
|
unit_tests = 1;
|
|
|
|
}
|
|
|
|
|
2009-09-18 11:01:39 +02:00
|
|
|
/**
|
|
|
|
* Return the initial default or configured timeout in milliseconds
|
|
|
|
*/
|
|
|
|
static double
|
|
|
|
circuit_build_times_get_initial_timeout(void)
|
|
|
|
{
|
|
|
|
double timeout;
|
2012-06-12 21:11:32 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if we have LearnCircuitBuildTimeout, and if we don't,
|
|
|
|
* always use CircuitBuildTimeout, no questions asked.
|
|
|
|
*/
|
|
|
|
if (get_options()->LearnCircuitBuildTimeout) {
|
|
|
|
if (!unit_tests && get_options()->CircuitBuildTimeout) {
|
|
|
|
timeout = get_options()->CircuitBuildTimeout*1000;
|
|
|
|
if (timeout < circuit_build_times_min_timeout()) {
|
|
|
|
log_warn(LD_CIRC, "Config CircuitBuildTimeout too low. Setting to %ds",
|
|
|
|
circuit_build_times_min_timeout()/1000);
|
|
|
|
timeout = circuit_build_times_min_timeout();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
timeout = circuit_build_times_initial_timeout();
|
2009-09-18 11:01:39 +02:00
|
|
|
}
|
2012-06-13 04:31:01 +02:00
|
|
|
} else {
|
2012-06-12 21:11:32 +02:00
|
|
|
timeout = get_options()->CircuitBuildTimeout*1000;
|
|
|
|
}
|
|
|
|
|
2009-09-18 11:01:39 +02:00
|
|
|
return timeout;
|
|
|
|
}
|
|
|
|
|
2009-09-08 10:31:29 +02:00
|
|
|
/**
|
|
|
|
* Reset the build time state.
|
|
|
|
*
|
2009-09-21 01:50:44 +02:00
|
|
|
* Leave estimated parameters, timeout and network liveness intact
|
2009-09-08 10:31:29 +02:00
|
|
|
* for future use.
|
|
|
|
*/
|
2009-09-02 05:27:43 +02:00
|
|
|
void
|
|
|
|
circuit_build_times_reset(circuit_build_times_t *cbt)
|
|
|
|
{
|
|
|
|
memset(cbt->circuit_build_times, 0, sizeof(cbt->circuit_build_times));
|
|
|
|
cbt->total_build_times = 0;
|
|
|
|
cbt->build_times_idx = 0;
|
2009-09-08 10:31:29 +02:00
|
|
|
cbt->have_computed_timeout = 0;
|
2009-09-02 05:27:43 +02:00
|
|
|
}
|
|
|
|
|
2009-09-08 10:31:29 +02:00
|
|
|
/**
|
|
|
|
* Initialize the buildtimes structure for first use.
|
|
|
|
*
|
2010-09-30 00:01:22 +02:00
|
|
|
* Sets the initial timeout values based on either the config setting,
|
|
|
|
* the consensus param, or the default (CBT_DEFAULT_TIMEOUT_INITIAL_VALUE).
|
2009-09-08 10:31:29 +02:00
|
|
|
*/
|
2009-09-02 05:27:43 +02:00
|
|
|
void
|
|
|
|
circuit_build_times_init(circuit_build_times_t *cbt)
|
|
|
|
{
|
|
|
|
memset(cbt, 0, sizeof(*cbt));
|
2012-06-12 20:52:38 +02:00
|
|
|
/*
|
|
|
|
* Check if we really are using adaptive timeouts, and don't keep
|
|
|
|
* track of this stuff if not.
|
|
|
|
*/
|
|
|
|
if (!circuit_build_times_disabled()) {
|
|
|
|
cbt->liveness.num_recent_circs =
|
2010-12-30 19:54:13 +01:00
|
|
|
circuit_build_times_recent_circuit_count(NULL);
|
2012-06-12 20:52:38 +02:00
|
|
|
cbt->liveness.timeouts_after_firsthop =
|
|
|
|
tor_malloc_zero(sizeof(int8_t)*cbt->liveness.num_recent_circs);
|
2012-06-13 04:31:01 +02:00
|
|
|
} else {
|
2012-06-12 20:52:38 +02:00
|
|
|
cbt->liveness.num_recent_circs = 0;
|
|
|
|
cbt->liveness.timeouts_after_firsthop = NULL;
|
|
|
|
}
|
2010-06-15 07:47:45 +02:00
|
|
|
cbt->close_ms = cbt->timeout_ms = circuit_build_times_get_initial_timeout();
|
2009-12-25 12:42:35 +01:00
|
|
|
control_event_buildtimeout_set(cbt, BUILDTIMEOUT_SET_EVENT_RESET);
|
2009-09-18 11:01:39 +02:00
|
|
|
}
|
2009-09-02 05:27:43 +02:00
|
|
|
|
2012-06-13 04:27:37 +02:00
|
|
|
/**
|
|
|
|
* Free the saved timeouts, if the cbtdisabled consensus parameter got turned
|
|
|
|
* on or something.
|
|
|
|
*/
|
|
|
|
|
2012-06-13 04:38:28 +02:00
|
|
|
void
|
|
|
|
circuit_build_times_free_timeouts(circuit_build_times_t *cbt)
|
|
|
|
{
|
2012-06-13 04:27:37 +02:00
|
|
|
if (!cbt) return;
|
|
|
|
|
|
|
|
if (cbt->liveness.timeouts_after_firsthop) {
|
|
|
|
tor_free(cbt->liveness.timeouts_after_firsthop);
|
|
|
|
}
|
|
|
|
|
|
|
|
cbt->liveness.num_recent_circs = 0;
|
|
|
|
}
|
|
|
|
|
2010-09-29 17:55:11 +02:00
|
|
|
#if 0
|
2009-09-18 11:01:39 +02:00
|
|
|
/**
|
2010-06-15 10:13:49 +02:00
|
|
|
* Rewind our build time history by n positions.
|
2009-09-18 11:01:39 +02:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
circuit_build_times_rewind_history(circuit_build_times_t *cbt, int n)
|
|
|
|
{
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
cbt->build_times_idx -= n;
|
2010-01-22 01:10:02 +01:00
|
|
|
cbt->build_times_idx %= CBT_NCIRCUITS_TO_OBSERVE;
|
2009-09-18 11:01:39 +02:00
|
|
|
|
|
|
|
for (i = 0; i < n; i++) {
|
2010-01-22 01:10:02 +01:00
|
|
|
cbt->circuit_build_times[(i+cbt->build_times_idx)
|
|
|
|
%CBT_NCIRCUITS_TO_OBSERVE]=0;
|
2009-09-18 11:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (cbt->total_build_times > n) {
|
|
|
|
cbt->total_build_times -= n;
|
2009-09-02 05:27:43 +02:00
|
|
|
} else {
|
2009-09-18 11:01:39 +02:00
|
|
|
cbt->total_build_times = 0;
|
2009-09-02 05:27:43 +02:00
|
|
|
}
|
2009-09-18 11:01:39 +02:00
|
|
|
|
|
|
|
log_info(LD_CIRC,
|
|
|
|
"Rewound history by %d places. Current index: %d. "
|
|
|
|
"Total: %d", n, cbt->build_times_idx, cbt->total_build_times);
|
2009-09-02 05:27:43 +02:00
|
|
|
}
|
2010-09-29 17:55:11 +02:00
|
|
|
#endif
|
2009-09-02 05:27:43 +02:00
|
|
|
|
2009-08-27 10:46:06 +02:00
|
|
|
/**
|
2010-06-15 10:13:49 +02:00
|
|
|
* Add a new build time value <b>time</b> to the set of build times. Time
|
2009-10-01 10:15:45 +02:00
|
|
|
* units are milliseconds.
|
2009-08-26 02:13:12 +02:00
|
|
|
*
|
2011-03-16 19:47:27 +01:00
|
|
|
* circuit_build_times <b>cbt</b> is a circular array, so loop around when
|
2009-09-08 10:31:29 +02:00
|
|
|
* array is full.
|
2009-08-26 02:13:12 +02:00
|
|
|
*/
|
|
|
|
int
|
2009-08-28 08:28:20 +02:00
|
|
|
circuit_build_times_add_time(circuit_build_times_t *cbt, build_time_t time)
|
2009-08-26 02:13:12 +02:00
|
|
|
{
|
2010-05-08 00:42:57 +02:00
|
|
|
if (time <= 0 || time > CBT_BUILD_TIME_MAX) {
|
2010-06-02 07:07:54 +02:00
|
|
|
log_warn(LD_BUG, "Circuit build time is too large (%u)."
|
|
|
|
"This is probably a bug.", time);
|
2010-05-08 00:42:57 +02:00
|
|
|
tor_fragile_assert();
|
2009-08-28 08:28:20 +02:00
|
|
|
return -1;
|
2009-08-26 02:13:12 +02:00
|
|
|
}
|
2009-09-01 03:10:27 +02:00
|
|
|
|
2010-05-07 23:43:56 +02:00
|
|
|
log_debug(LD_CIRC, "Adding circuit build time %u", time);
|
2009-09-16 13:55:43 +02:00
|
|
|
|
2009-08-27 10:46:06 +02:00
|
|
|
cbt->circuit_build_times[cbt->build_times_idx] = time;
|
2010-01-22 01:10:02 +01:00
|
|
|
cbt->build_times_idx = (cbt->build_times_idx + 1) % CBT_NCIRCUITS_TO_OBSERVE;
|
|
|
|
if (cbt->total_build_times < CBT_NCIRCUITS_TO_OBSERVE)
|
2009-08-27 10:46:06 +02:00
|
|
|
cbt->total_build_times++;
|
2009-08-26 02:13:12 +02:00
|
|
|
|
2010-01-22 01:10:02 +01:00
|
|
|
if ((cbt->total_build_times % CBT_SAVE_STATE_EVERY) == 0) {
|
2009-09-17 07:42:33 +02:00
|
|
|
/* Save state every n circuit builds */
|
2009-09-02 05:27:43 +02:00
|
|
|
if (!unit_tests && !get_options()->AvoidDiskWrites)
|
2009-09-01 08:09:54 +02:00
|
|
|
or_state_mark_dirty(get_or_state(), 0);
|
|
|
|
}
|
|
|
|
|
2009-08-26 02:13:12 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-09-08 10:31:29 +02:00
|
|
|
* Return maximum circuit build time
|
2009-08-26 02:13:12 +02:00
|
|
|
*/
|
2009-08-28 08:28:20 +02:00
|
|
|
static build_time_t
|
2009-08-27 10:46:06 +02:00
|
|
|
circuit_build_times_max(circuit_build_times_t *cbt)
|
2009-08-26 02:13:12 +02:00
|
|
|
{
|
2009-08-28 08:28:20 +02:00
|
|
|
int i = 0;
|
|
|
|
build_time_t max_build_time = 0;
|
2010-01-22 01:10:02 +01:00
|
|
|
for (i = 0; i < CBT_NCIRCUITS_TO_OBSERVE; i++) {
|
2010-06-03 11:36:43 +02:00
|
|
|
if (cbt->circuit_build_times[i] > max_build_time
|
2010-06-15 10:13:49 +02:00
|
|
|
&& cbt->circuit_build_times[i] != CBT_BUILD_ABANDONED)
|
2009-08-27 10:46:06 +02:00
|
|
|
max_build_time = cbt->circuit_build_times[i];
|
2009-08-26 02:13:12 +02:00
|
|
|
}
|
|
|
|
return max_build_time;
|
|
|
|
}
|
|
|
|
|
2009-09-18 11:01:39 +02:00
|
|
|
#if 0
|
2009-09-08 10:31:29 +02:00
|
|
|
/** Return minimum circuit build time */
|
2009-09-18 11:01:39 +02:00
|
|
|
build_time_t
|
2009-08-27 10:46:06 +02:00
|
|
|
circuit_build_times_min(circuit_build_times_t *cbt)
|
2009-08-26 02:13:12 +02:00
|
|
|
{
|
|
|
|
int i = 0;
|
2010-01-22 01:10:02 +01:00
|
|
|
build_time_t min_build_time = CBT_BUILD_TIME_MAX;
|
|
|
|
for (i = 0; i < CBT_NCIRCUITS_TO_OBSERVE; i++) {
|
2009-08-27 10:46:06 +02:00
|
|
|
if (cbt->circuit_build_times[i] && /* 0 <-> uninitialized */
|
2009-09-07 05:14:13 +02:00
|
|
|
cbt->circuit_build_times[i] < min_build_time)
|
2009-08-27 10:46:06 +02:00
|
|
|
min_build_time = cbt->circuit_build_times[i];
|
|
|
|
}
|
2010-01-22 01:10:02 +01:00
|
|
|
if (min_build_time == CBT_BUILD_TIME_MAX) {
|
|
|
|
log_warn(LD_CIRC, "No build times less than CBT_BUILD_TIME_MAX!");
|
2009-08-26 02:13:12 +02:00
|
|
|
}
|
|
|
|
return min_build_time;
|
|
|
|
}
|
2009-09-18 11:01:39 +02:00
|
|
|
#endif
|
2009-08-26 02:13:12 +02:00
|
|
|
|
2009-09-01 17:07:26 +02:00
|
|
|
/**
|
2009-09-08 10:31:29 +02:00
|
|
|
* Calculate and return a histogram for the set of build times.
|
|
|
|
*
|
|
|
|
* Returns an allocated array of histrogram bins representing
|
2010-01-22 01:10:02 +01:00
|
|
|
* the frequency of index*CBT_BIN_WIDTH millisecond
|
2009-09-08 10:31:29 +02:00
|
|
|
* build times. Also outputs the number of bins in nbins.
|
|
|
|
*
|
|
|
|
* The return value must be freed by the caller.
|
2009-09-01 17:07:26 +02:00
|
|
|
*/
|
|
|
|
static uint32_t *
|
|
|
|
circuit_build_times_create_histogram(circuit_build_times_t *cbt,
|
|
|
|
build_time_t *nbins)
|
|
|
|
{
|
|
|
|
uint32_t *histogram;
|
|
|
|
build_time_t max_build_time = circuit_build_times_max(cbt);
|
|
|
|
int i, c;
|
|
|
|
|
2010-01-22 01:10:02 +01:00
|
|
|
*nbins = 1 + (max_build_time / CBT_BIN_WIDTH);
|
2009-09-01 17:07:26 +02:00
|
|
|
histogram = tor_malloc_zero(*nbins * sizeof(build_time_t));
|
|
|
|
|
|
|
|
// calculate histogram
|
2010-01-22 01:10:02 +01:00
|
|
|
for (i = 0; i < CBT_NCIRCUITS_TO_OBSERVE; i++) {
|
2010-06-03 11:36:43 +02:00
|
|
|
if (cbt->circuit_build_times[i] == 0
|
2010-06-15 10:13:49 +02:00
|
|
|
|| cbt->circuit_build_times[i] == CBT_BUILD_ABANDONED)
|
2010-06-03 11:36:43 +02:00
|
|
|
continue; /* 0 <-> uninitialized */
|
2009-09-01 17:07:26 +02:00
|
|
|
|
2010-01-22 01:10:02 +01:00
|
|
|
c = (cbt->circuit_build_times[i] / CBT_BIN_WIDTH);
|
2009-09-01 17:07:26 +02:00
|
|
|
histogram[c]++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return histogram;
|
|
|
|
}
|
|
|
|
|
2009-09-08 10:31:29 +02:00
|
|
|
/**
|
2010-05-04 23:42:37 +02:00
|
|
|
* Return the Pareto start-of-curve parameter Xm.
|
2009-09-08 10:31:29 +02:00
|
|
|
*
|
2010-05-04 23:42:37 +02:00
|
|
|
* Because we are not a true Pareto curve, we compute this as the
|
2011-04-26 03:01:25 +02:00
|
|
|
* weighted average of the N most frequent build time bins. N is either
|
|
|
|
* 1 if we don't have enough circuit build time data collected, or
|
|
|
|
* determined by the consensus parameter cbtnummodes (default 3).
|
2009-09-08 10:31:29 +02:00
|
|
|
*/
|
2009-09-01 17:07:26 +02:00
|
|
|
static build_time_t
|
2010-05-04 23:42:37 +02:00
|
|
|
circuit_build_times_get_xm(circuit_build_times_t *cbt)
|
2009-09-01 17:07:26 +02:00
|
|
|
{
|
2010-05-04 23:42:37 +02:00
|
|
|
build_time_t i, nbins;
|
2010-06-08 06:17:12 +02:00
|
|
|
build_time_t *nth_max_bin;
|
2010-05-04 23:42:37 +02:00
|
|
|
int32_t bin_counts=0;
|
|
|
|
build_time_t ret = 0;
|
2009-09-01 17:07:26 +02:00
|
|
|
uint32_t *histogram = circuit_build_times_create_histogram(cbt, &nbins);
|
2010-05-04 23:42:37 +02:00
|
|
|
int n=0;
|
2010-06-08 06:17:12 +02:00
|
|
|
int num_modes = circuit_build_times_default_num_xm_modes();
|
2010-05-04 23:42:37 +02:00
|
|
|
|
2011-04-26 03:01:25 +02:00
|
|
|
tor_assert(nbins > 0);
|
|
|
|
tor_assert(num_modes > 0);
|
|
|
|
|
2010-05-04 23:42:37 +02:00
|
|
|
// Only use one mode if < 1000 buildtimes. Not enough data
|
|
|
|
// for multiple.
|
|
|
|
if (cbt->total_build_times < CBT_NCIRCUITS_TO_OBSERVE)
|
|
|
|
num_modes = 1;
|
2009-09-01 17:07:26 +02:00
|
|
|
|
2010-06-08 06:17:12 +02:00
|
|
|
nth_max_bin = (build_time_t*)tor_malloc_zero(num_modes*sizeof(build_time_t));
|
2009-09-01 17:07:26 +02:00
|
|
|
|
2011-04-26 03:01:25 +02:00
|
|
|
/* Determine the N most common build times */
|
2009-09-01 17:07:26 +02:00
|
|
|
for (i = 0; i < nbins; i++) {
|
2010-05-04 23:42:37 +02:00
|
|
|
if (histogram[i] >= histogram[nth_max_bin[0]]) {
|
|
|
|
nth_max_bin[0] = i;
|
2009-09-01 17:07:26 +02:00
|
|
|
}
|
2010-05-04 23:42:37 +02:00
|
|
|
|
|
|
|
for (n = 1; n < num_modes; n++) {
|
|
|
|
if (histogram[i] >= histogram[nth_max_bin[n]] &&
|
|
|
|
(!histogram[nth_max_bin[n-1]]
|
|
|
|
|| histogram[i] < histogram[nth_max_bin[n-1]])) {
|
|
|
|
nth_max_bin[n] = i;
|
|
|
|
}
|
2009-09-01 17:07:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-04 23:42:37 +02:00
|
|
|
for (n = 0; n < num_modes; n++) {
|
|
|
|
bin_counts += histogram[nth_max_bin[n]];
|
|
|
|
ret += CBT_BIN_TO_MS(nth_max_bin[n])*histogram[nth_max_bin[n]];
|
|
|
|
log_info(LD_CIRC, "Xm mode #%d: %u %u", n, CBT_BIN_TO_MS(nth_max_bin[n]),
|
|
|
|
histogram[nth_max_bin[n]]);
|
2009-09-01 17:07:26 +02:00
|
|
|
}
|
|
|
|
|
2011-04-26 03:01:25 +02:00
|
|
|
/* The following assert is safe, because we don't get called when we
|
|
|
|
* haven't observed at least CBT_MIN_MIN_CIRCUITS_TO_OBSERVE circuits. */
|
|
|
|
tor_assert(bin_counts > 0);
|
|
|
|
|
2010-05-04 23:42:37 +02:00
|
|
|
ret /= bin_counts;
|
2009-09-04 22:42:58 +02:00
|
|
|
tor_free(histogram);
|
2010-06-08 06:17:12 +02:00
|
|
|
tor_free(nth_max_bin);
|
2009-09-04 22:42:58 +02:00
|
|
|
|
2010-05-04 23:42:37 +02:00
|
|
|
return ret;
|
2009-09-01 17:07:26 +02:00
|
|
|
}
|
|
|
|
|
2009-08-26 02:13:12 +02:00
|
|
|
/**
|
2009-09-08 10:31:29 +02:00
|
|
|
* Output a histogram of current circuit build times to
|
|
|
|
* the or_state_t state structure.
|
2009-08-26 02:13:12 +02:00
|
|
|
*/
|
|
|
|
void
|
2009-08-27 10:46:06 +02:00
|
|
|
circuit_build_times_update_state(circuit_build_times_t *cbt,
|
2009-09-02 05:27:43 +02:00
|
|
|
or_state_t *state)
|
2009-08-26 02:13:12 +02:00
|
|
|
{
|
2009-09-01 17:07:26 +02:00
|
|
|
uint32_t *histogram;
|
2009-09-02 05:27:43 +02:00
|
|
|
build_time_t i = 0;
|
2009-09-01 17:07:26 +02:00
|
|
|
build_time_t nbins = 0;
|
2009-08-26 02:13:12 +02:00
|
|
|
config_line_t **next, *line;
|
|
|
|
|
2009-09-01 17:07:26 +02:00
|
|
|
histogram = circuit_build_times_create_histogram(cbt, &nbins);
|
2009-08-26 02:13:12 +02:00
|
|
|
// write to state
|
|
|
|
config_free_lines(state->BuildtimeHistogram);
|
|
|
|
next = &state->BuildtimeHistogram;
|
|
|
|
*next = NULL;
|
|
|
|
|
2009-08-27 10:46:06 +02:00
|
|
|
state->TotalBuildTimes = cbt->total_build_times;
|
2010-06-15 10:13:49 +02:00
|
|
|
state->CircuitBuildAbandonedCount = 0;
|
2010-06-07 11:36:43 +02:00
|
|
|
|
|
|
|
for (i = 0; i < CBT_NCIRCUITS_TO_OBSERVE; i++) {
|
2010-06-15 10:13:49 +02:00
|
|
|
if (cbt->circuit_build_times[i] == CBT_BUILD_ABANDONED)
|
|
|
|
state->CircuitBuildAbandonedCount++;
|
2010-06-07 11:36:43 +02:00
|
|
|
}
|
2009-08-26 02:13:12 +02:00
|
|
|
|
2009-09-02 05:27:43 +02:00
|
|
|
for (i = 0; i < nbins; i++) {
|
2009-08-27 10:46:06 +02:00
|
|
|
// compress the histogram by skipping the blanks
|
|
|
|
if (histogram[i] == 0) continue;
|
2009-08-26 02:13:12 +02:00
|
|
|
*next = line = tor_malloc_zero(sizeof(config_line_t));
|
|
|
|
line->key = tor_strdup("CircuitBuildTimeBin");
|
2012-01-11 20:02:59 +01:00
|
|
|
tor_asprintf(&line->value, "%d %d",
|
2010-05-04 23:42:37 +02:00
|
|
|
CBT_BIN_TO_MS(i), histogram[i]);
|
2009-08-26 02:13:12 +02:00
|
|
|
next = &(line->next);
|
|
|
|
}
|
2009-08-28 08:28:20 +02:00
|
|
|
|
2009-09-02 05:27:43 +02:00
|
|
|
if (!unit_tests) {
|
2009-08-28 08:28:20 +02:00
|
|
|
if (!get_options()->AvoidDiskWrites)
|
|
|
|
or_state_mark_dirty(get_or_state(), 0);
|
|
|
|
}
|
2009-08-26 02:13:12 +02:00
|
|
|
|
2009-12-12 08:07:59 +01:00
|
|
|
tor_free(histogram);
|
2009-08-26 02:13:12 +02:00
|
|
|
}
|
|
|
|
|
2009-09-08 10:31:29 +02:00
|
|
|
/**
|
|
|
|
* Shuffle the build times array.
|
|
|
|
*
|
2011-03-16 19:47:27 +01:00
|
|
|
* Adapted from http://en.wikipedia.org/wiki/Fisher-Yates_shuffle
|
2009-09-08 10:31:29 +02:00
|
|
|
*/
|
2009-09-02 05:27:43 +02:00
|
|
|
static void
|
2009-09-29 12:41:23 +02:00
|
|
|
circuit_build_times_shuffle_and_store_array(circuit_build_times_t *cbt,
|
|
|
|
build_time_t *raw_times,
|
2011-01-25 23:27:25 +01:00
|
|
|
uint32_t num_times)
|
2009-09-02 05:27:43 +02:00
|
|
|
{
|
2011-01-25 23:27:25 +01:00
|
|
|
uint32_t n = num_times;
|
2010-01-22 01:10:02 +01:00
|
|
|
if (num_times > CBT_NCIRCUITS_TO_OBSERVE) {
|
2011-01-16 03:14:15 +01:00
|
|
|
log_notice(LD_CIRC, "The number of circuit times that this Tor version "
|
|
|
|
"uses to calculate build times is less than the number stored "
|
|
|
|
"in your state file. Decreasing the circuit time history from "
|
2011-06-01 18:12:01 +02:00
|
|
|
"%lu to %d.", (unsigned long)num_times,
|
|
|
|
CBT_NCIRCUITS_TO_OBSERVE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n > INT_MAX-1) {
|
|
|
|
log_warn(LD_CIRC, "For some insane reasons, you had %lu circuit build "
|
|
|
|
"observations in your state file. That's far too many; probably "
|
|
|
|
"there's a bug here.", (unsigned long)n);
|
|
|
|
n = INT_MAX-1;
|
2009-09-29 12:41:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* This code can only be run on a compact array */
|
|
|
|
while (n-- > 1) {
|
|
|
|
int k = crypto_rand_int(n + 1); /* 0 <= k <= n. */
|
|
|
|
build_time_t tmp = raw_times[k];
|
|
|
|
raw_times[k] = raw_times[n];
|
|
|
|
raw_times[n] = tmp;
|
|
|
|
}
|
|
|
|
|
2010-01-22 01:10:02 +01:00
|
|
|
/* Since the times are now shuffled, take a random CBT_NCIRCUITS_TO_OBSERVE
|
|
|
|
* subset (ie the first CBT_NCIRCUITS_TO_OBSERVE values) */
|
|
|
|
for (n = 0; n < MIN(num_times, CBT_NCIRCUITS_TO_OBSERVE); n++) {
|
2009-09-29 12:41:23 +02:00
|
|
|
circuit_build_times_add_time(cbt, raw_times[n]);
|
|
|
|
}
|
2009-09-02 05:27:43 +02:00
|
|
|
}
|
|
|
|
|
2010-06-07 11:36:43 +02:00
|
|
|
/**
|
|
|
|
* Filter old synthetic timeouts that were created before the
|
2010-06-08 10:01:47 +02:00
|
|
|
* new right-censored Pareto calculation was deployed.
|
|
|
|
*
|
|
|
|
* Once all clients before 0.2.1.13-alpha are gone, this code
|
|
|
|
* will be unused.
|
2010-06-07 11:36:43 +02:00
|
|
|
*/
|
|
|
|
static int
|
|
|
|
circuit_build_times_filter_timeouts(circuit_build_times_t *cbt)
|
|
|
|
{
|
|
|
|
int num_filtered=0, i=0;
|
|
|
|
double timeout_rate = 0;
|
|
|
|
build_time_t max_timeout = 0;
|
|
|
|
|
|
|
|
timeout_rate = circuit_build_times_timeout_rate(cbt);
|
2010-06-08 10:01:47 +02:00
|
|
|
max_timeout = (build_time_t)cbt->close_ms;
|
2010-06-07 11:36:43 +02:00
|
|
|
|
|
|
|
for (i = 0; i < CBT_NCIRCUITS_TO_OBSERVE; i++) {
|
|
|
|
if (cbt->circuit_build_times[i] > max_timeout) {
|
|
|
|
build_time_t replaced = cbt->circuit_build_times[i];
|
|
|
|
num_filtered++;
|
2010-06-15 10:13:49 +02:00
|
|
|
cbt->circuit_build_times[i] = CBT_BUILD_ABANDONED;
|
2010-06-07 11:36:43 +02:00
|
|
|
|
|
|
|
log_debug(LD_CIRC, "Replaced timeout %d with %d", replaced,
|
|
|
|
cbt->circuit_build_times[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
log_info(LD_CIRC,
|
|
|
|
"We had %d timeouts out of %d build times, "
|
|
|
|
"and filtered %d above the max of %u",
|
|
|
|
(int)(cbt->total_build_times*timeout_rate),
|
|
|
|
cbt->total_build_times, num_filtered, max_timeout);
|
|
|
|
|
|
|
|
return num_filtered;
|
|
|
|
}
|
|
|
|
|
2009-09-08 10:31:29 +02:00
|
|
|
/**
|
|
|
|
* Load histogram from <b>state</b>, shuffling the resulting array
|
|
|
|
* after we do so. Use this result to estimate parameters and
|
|
|
|
* calculate the timeout.
|
|
|
|
*
|
2010-08-15 14:22:32 +02:00
|
|
|
* Return -1 on error.
|
2009-09-08 10:31:29 +02:00
|
|
|
*/
|
2009-08-26 02:13:12 +02:00
|
|
|
int
|
2009-08-27 10:46:06 +02:00
|
|
|
circuit_build_times_parse_state(circuit_build_times_t *cbt,
|
2010-08-15 14:22:32 +02:00
|
|
|
or_state_t *state)
|
2009-08-26 02:13:12 +02:00
|
|
|
{
|
2009-09-29 12:41:23 +02:00
|
|
|
int tot_values = 0;
|
|
|
|
uint32_t loaded_cnt = 0, N = 0;
|
2009-08-26 02:13:12 +02:00
|
|
|
config_line_t *line;
|
2010-06-07 11:36:43 +02:00
|
|
|
unsigned int i;
|
2010-05-08 20:54:29 +02:00
|
|
|
build_time_t *loaded_times;
|
2010-08-15 14:22:32 +02:00
|
|
|
int err = 0;
|
2010-08-16 05:46:09 +02:00
|
|
|
circuit_build_times_init(cbt);
|
2009-08-26 02:13:12 +02:00
|
|
|
|
2010-05-08 20:54:29 +02:00
|
|
|
if (circuit_build_times_disabled()) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-06-15 07:47:45 +02:00
|
|
|
/* build_time_t 0 means uninitialized */
|
|
|
|
loaded_times = tor_malloc_zero(sizeof(build_time_t)*state->TotalBuildTimes);
|
2010-05-08 20:54:29 +02:00
|
|
|
|
2009-08-27 10:46:06 +02:00
|
|
|
for (line = state->BuildtimeHistogram; line; line = line->next) {
|
2012-01-18 21:53:30 +01:00
|
|
|
smartlist_t *args = smartlist_new();
|
2009-08-26 02:13:12 +02:00
|
|
|
smartlist_split_string(args, line->value, " ",
|
2009-09-07 05:14:13 +02:00
|
|
|
SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 0);
|
2009-08-27 10:46:06 +02:00
|
|
|
if (smartlist_len(args) < 2) {
|
2010-08-15 14:22:32 +02:00
|
|
|
log_warn(LD_GENERAL, "Unable to parse circuit build times: "
|
|
|
|
"Too few arguments to CircuitBuildTime");
|
|
|
|
err = 1;
|
2009-09-04 22:42:58 +02:00
|
|
|
SMARTLIST_FOREACH(args, char*, cp, tor_free(cp));
|
|
|
|
smartlist_free(args);
|
2009-08-26 02:13:12 +02:00
|
|
|
break;
|
|
|
|
} else {
|
2009-08-27 10:46:06 +02:00
|
|
|
const char *ms_str = smartlist_get(args,0);
|
|
|
|
const char *count_str = smartlist_get(args,1);
|
2009-09-02 05:27:43 +02:00
|
|
|
uint32_t count, k;
|
2009-08-28 08:28:20 +02:00
|
|
|
build_time_t ms;
|
2009-08-27 10:46:06 +02:00
|
|
|
int ok;
|
2009-09-17 00:20:25 +02:00
|
|
|
ms = (build_time_t)tor_parse_ulong(ms_str, 0, 0,
|
2010-01-22 01:10:02 +01:00
|
|
|
CBT_BUILD_TIME_MAX, &ok, NULL);
|
2009-08-27 10:46:06 +02:00
|
|
|
if (!ok) {
|
2010-08-15 14:22:32 +02:00
|
|
|
log_warn(LD_GENERAL, "Unable to parse circuit build times: "
|
|
|
|
"Unparsable bin number");
|
|
|
|
err = 1;
|
2009-09-26 15:38:52 +02:00
|
|
|
SMARTLIST_FOREACH(args, char*, cp, tor_free(cp));
|
|
|
|
smartlist_free(args);
|
2009-08-27 10:46:06 +02:00
|
|
|
break;
|
|
|
|
}
|
2009-09-17 00:20:25 +02:00
|
|
|
count = (uint32_t)tor_parse_ulong(count_str, 0, 0,
|
|
|
|
UINT32_MAX, &ok, NULL);
|
2009-08-27 10:46:06 +02:00
|
|
|
if (!ok) {
|
2010-08-15 14:22:32 +02:00
|
|
|
log_warn(LD_GENERAL, "Unable to parse circuit build times: "
|
|
|
|
"Unparsable bin count");
|
|
|
|
err = 1;
|
2009-09-26 15:38:52 +02:00
|
|
|
SMARTLIST_FOREACH(args, char*, cp, tor_free(cp));
|
|
|
|
smartlist_free(args);
|
2009-08-27 10:46:06 +02:00
|
|
|
break;
|
|
|
|
}
|
2009-09-02 05:27:43 +02:00
|
|
|
|
2010-06-15 10:13:49 +02:00
|
|
|
if (loaded_cnt+count+state->CircuitBuildAbandonedCount
|
2010-06-07 11:36:43 +02:00
|
|
|
> state->TotalBuildTimes) {
|
2009-09-29 12:41:23 +02:00
|
|
|
log_warn(LD_CIRC,
|
|
|
|
"Too many build times in state file. "
|
|
|
|
"Stopping short before %d",
|
|
|
|
loaded_cnt+count);
|
2009-10-10 13:41:44 +02:00
|
|
|
SMARTLIST_FOREACH(args, char*, cp, tor_free(cp));
|
|
|
|
smartlist_free(args);
|
2009-09-29 12:41:23 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-09-02 05:27:43 +02:00
|
|
|
for (k = 0; k < count; k++) {
|
2009-09-29 12:41:23 +02:00
|
|
|
loaded_times[loaded_cnt++] = ms;
|
2009-08-26 02:13:12 +02:00
|
|
|
}
|
2009-09-02 05:27:43 +02:00
|
|
|
N++;
|
2009-09-04 22:42:58 +02:00
|
|
|
SMARTLIST_FOREACH(args, char*, cp, tor_free(cp));
|
|
|
|
smartlist_free(args);
|
2009-08-26 02:13:12 +02:00
|
|
|
}
|
2009-09-29 12:41:23 +02:00
|
|
|
}
|
2009-09-04 22:42:58 +02:00
|
|
|
|
2010-06-07 11:36:43 +02:00
|
|
|
log_info(LD_CIRC,
|
2010-06-15 10:13:49 +02:00
|
|
|
"Adding %d timeouts.", state->CircuitBuildAbandonedCount);
|
|
|
|
for (i=0; i < state->CircuitBuildAbandonedCount; i++) {
|
|
|
|
loaded_times[loaded_cnt++] = CBT_BUILD_ABANDONED;
|
2010-06-07 11:36:43 +02:00
|
|
|
}
|
|
|
|
|
2009-09-29 12:41:23 +02:00
|
|
|
if (loaded_cnt != state->TotalBuildTimes) {
|
|
|
|
log_warn(LD_CIRC,
|
|
|
|
"Corrupt state file? Build times count mismatch. "
|
2010-06-07 11:36:43 +02:00
|
|
|
"Read %d times, but file says %d", loaded_cnt,
|
|
|
|
state->TotalBuildTimes);
|
2010-08-15 14:22:32 +02:00
|
|
|
err = 1;
|
2010-07-06 21:08:13 +02:00
|
|
|
circuit_build_times_reset(cbt);
|
2010-08-15 14:22:32 +02:00
|
|
|
goto done;
|
2009-08-26 02:13:12 +02:00
|
|
|
}
|
2009-09-02 05:27:43 +02:00
|
|
|
|
2009-09-29 12:41:23 +02:00
|
|
|
circuit_build_times_shuffle_and_store_array(cbt, loaded_times, loaded_cnt);
|
2009-09-02 05:27:43 +02:00
|
|
|
|
|
|
|
/* Verify that we didn't overwrite any indexes */
|
2010-01-22 01:10:02 +01:00
|
|
|
for (i=0; i < CBT_NCIRCUITS_TO_OBSERVE; i++) {
|
2009-09-02 05:27:43 +02:00
|
|
|
if (!cbt->circuit_build_times[i])
|
|
|
|
break;
|
|
|
|
tot_values++;
|
|
|
|
}
|
|
|
|
log_info(LD_CIRC,
|
|
|
|
"Loaded %d/%d values from %d lines in circuit time histogram",
|
|
|
|
tot_values, cbt->total_build_times, N);
|
2010-07-06 21:08:13 +02:00
|
|
|
|
|
|
|
if (cbt->total_build_times != tot_values
|
|
|
|
|| cbt->total_build_times > CBT_NCIRCUITS_TO_OBSERVE) {
|
|
|
|
log_warn(LD_CIRC,
|
|
|
|
"Corrupt state file? Shuffled build times mismatch. "
|
|
|
|
"Read %d times, but file says %d", tot_values,
|
|
|
|
state->TotalBuildTimes);
|
2010-08-15 14:22:32 +02:00
|
|
|
err = 1;
|
2010-07-06 21:08:13 +02:00
|
|
|
circuit_build_times_reset(cbt);
|
2010-08-15 14:22:32 +02:00
|
|
|
goto done;
|
2010-07-06 21:08:13 +02:00
|
|
|
}
|
2010-06-07 11:36:43 +02:00
|
|
|
|
2009-08-27 10:46:06 +02:00
|
|
|
circuit_build_times_set_timeout(cbt);
|
2010-06-07 11:36:43 +02:00
|
|
|
|
2010-06-15 10:13:49 +02:00
|
|
|
if (!state->CircuitBuildAbandonedCount && cbt->total_build_times) {
|
2010-06-07 11:36:43 +02:00
|
|
|
circuit_build_times_filter_timeouts(cbt);
|
|
|
|
}
|
|
|
|
|
2010-08-16 00:29:27 +02:00
|
|
|
done:
|
2009-09-29 12:41:23 +02:00
|
|
|
tor_free(loaded_times);
|
2010-08-15 14:22:32 +02:00
|
|
|
return err ? -1 : 0;
|
2009-08-26 02:13:12 +02:00
|
|
|
}
|
|
|
|
|
2009-09-08 10:31:29 +02:00
|
|
|
/**
|
|
|
|
* Estimates the Xm and Alpha parameters using
|
|
|
|
* http://en.wikipedia.org/wiki/Pareto_distribution#Parameter_estimation
|
|
|
|
*
|
|
|
|
* The notable difference is that we use mode instead of min to estimate Xm.
|
|
|
|
* This is because our distribution is frechet-like. We claim this is
|
|
|
|
* an acceptable approximation because we are only concerned with the
|
|
|
|
* accuracy of the CDF of the tail.
|
|
|
|
*/
|
2010-07-06 17:49:50 +02:00
|
|
|
int
|
2009-08-27 10:46:06 +02:00
|
|
|
circuit_build_times_update_alpha(circuit_build_times_t *cbt)
|
|
|
|
{
|
2009-08-28 08:28:20 +02:00
|
|
|
build_time_t *x=cbt->circuit_build_times;
|
2009-08-27 10:46:06 +02:00
|
|
|
double a = 0;
|
2010-06-15 10:13:49 +02:00
|
|
|
int n=0,i=0,abandoned_count=0;
|
2010-06-03 11:36:43 +02:00
|
|
|
build_time_t max_time=0;
|
2009-08-27 10:46:06 +02:00
|
|
|
|
|
|
|
/* http://en.wikipedia.org/wiki/Pareto_distribution#Parameter_estimation */
|
2009-09-01 17:07:26 +02:00
|
|
|
/* We sort of cheat here and make our samples slightly more pareto-like
|
|
|
|
* and less frechet-like. */
|
2010-05-04 23:42:37 +02:00
|
|
|
cbt->Xm = circuit_build_times_get_xm(cbt);
|
2009-08-27 10:46:06 +02:00
|
|
|
|
2010-06-03 11:36:43 +02:00
|
|
|
tor_assert(cbt->Xm > 0);
|
2009-08-27 10:46:06 +02:00
|
|
|
|
2010-01-22 01:10:02 +01:00
|
|
|
for (i=0; i< CBT_NCIRCUITS_TO_OBSERVE; i++) {
|
2009-09-16 03:00:48 +02:00
|
|
|
if (!x[i]) {
|
|
|
|
continue;
|
|
|
|
}
|
2009-09-01 17:07:26 +02:00
|
|
|
|
2009-09-16 03:00:48 +02:00
|
|
|
if (x[i] < cbt->Xm) {
|
2009-12-15 20:32:55 +01:00
|
|
|
a += tor_mathlog(cbt->Xm);
|
2010-06-15 10:13:49 +02:00
|
|
|
} else if (x[i] == CBT_BUILD_ABANDONED) {
|
|
|
|
abandoned_count++;
|
2009-09-16 03:00:48 +02:00
|
|
|
} else {
|
2009-12-15 20:32:55 +01:00
|
|
|
a += tor_mathlog(x[i]);
|
2010-06-03 11:36:43 +02:00
|
|
|
if (x[i] > max_time)
|
|
|
|
max_time = x[i];
|
2009-09-16 03:00:48 +02:00
|
|
|
}
|
2009-08-27 10:46:06 +02:00
|
|
|
n++;
|
|
|
|
}
|
2009-09-01 17:07:26 +02:00
|
|
|
|
2010-07-06 21:08:13 +02:00
|
|
|
/*
|
|
|
|
* We are erring and asserting here because this can only happen
|
|
|
|
* in codepaths other than startup. The startup state parsing code
|
|
|
|
* performs this same check, and resets state if it hits it. If we
|
|
|
|
* hit it at runtime, something serious has gone wrong.
|
|
|
|
*/
|
2009-08-28 08:28:20 +02:00
|
|
|
if (n!=cbt->total_build_times) {
|
2009-09-03 14:44:01 +02:00
|
|
|
log_err(LD_CIRC, "Discrepancy in build times count: %d vs %d", n,
|
2009-08-28 08:28:20 +02:00
|
|
|
cbt->total_build_times);
|
|
|
|
}
|
2009-08-27 10:46:06 +02:00
|
|
|
tor_assert(n==cbt->total_build_times);
|
2009-09-01 17:07:26 +02:00
|
|
|
|
2010-07-06 17:49:50 +02:00
|
|
|
if (max_time <= 0) {
|
|
|
|
/* This can happen if Xm is actually the *maximum* value in the set.
|
|
|
|
* It can also happen if we've abandoned every single circuit somehow.
|
|
|
|
* In either case, tell the caller not to compute a new build timeout. */
|
|
|
|
log_warn(LD_BUG,
|
|
|
|
"Could not determine largest build time (%d). "
|
|
|
|
"Xm is %dms and we've abandoned %d out of %d circuits.", max_time,
|
|
|
|
cbt->Xm, abandoned_count, n);
|
|
|
|
return 0;
|
|
|
|
}
|
2010-06-03 11:36:43 +02:00
|
|
|
|
2010-06-15 10:13:49 +02:00
|
|
|
a += abandoned_count*tor_mathlog(max_time);
|
2010-06-03 11:36:43 +02:00
|
|
|
|
2009-12-15 20:32:55 +01:00
|
|
|
a -= n*tor_mathlog(cbt->Xm);
|
2010-06-07 11:36:43 +02:00
|
|
|
// Estimator comes from Eq #4 in:
|
|
|
|
// "Bayesian estimation based on trimmed samples from Pareto populations"
|
|
|
|
// by Arturo J. Fernández. We are right-censored only.
|
2010-06-15 10:13:49 +02:00
|
|
|
a = (n-abandoned_count)/a;
|
2009-08-27 10:46:06 +02:00
|
|
|
|
|
|
|
cbt->alpha = a;
|
2010-07-06 17:49:50 +02:00
|
|
|
|
|
|
|
return 1;
|
2009-08-27 10:46:06 +02:00
|
|
|
}
|
2009-08-26 02:13:12 +02:00
|
|
|
|
2009-08-27 10:46:06 +02:00
|
|
|
/**
|
|
|
|
* This is the Pareto Quantile Function. It calculates the point x
|
2009-08-28 08:28:20 +02:00
|
|
|
* in the distribution such that F(x) = quantile (ie quantile*100%
|
2009-08-27 10:46:06 +02:00
|
|
|
* of the mass of the density function is below x on the curve).
|
|
|
|
*
|
2009-09-08 10:31:29 +02:00
|
|
|
* We use it to calculate the timeout and also to generate synthetic
|
|
|
|
* values of time for circuits that timeout before completion.
|
2009-08-27 10:46:06 +02:00
|
|
|
*
|
|
|
|
* See http://en.wikipedia.org/wiki/Quantile_function,
|
|
|
|
* http://en.wikipedia.org/wiki/Inverse_transform_sampling and
|
2009-09-03 14:44:01 +02:00
|
|
|
* http://en.wikipedia.org/wiki/Pareto_distribution#Generating_a_
|
|
|
|
* random_sample_from_Pareto_distribution
|
2009-08-27 10:46:06 +02:00
|
|
|
* That's right. I'll cite wikipedia all day long.
|
2009-09-18 10:48:07 +02:00
|
|
|
*
|
|
|
|
* Return value is in milliseconds.
|
2009-08-27 10:46:06 +02:00
|
|
|
*/
|
2009-08-28 08:28:20 +02:00
|
|
|
double
|
2009-08-27 10:46:06 +02:00
|
|
|
circuit_build_times_calculate_timeout(circuit_build_times_t *cbt,
|
|
|
|
double quantile)
|
|
|
|
{
|
2009-09-11 07:12:46 +02:00
|
|
|
double ret;
|
|
|
|
tor_assert(quantile >= 0);
|
|
|
|
tor_assert(1.0-quantile > 0);
|
|
|
|
tor_assert(cbt->Xm > 0);
|
|
|
|
|
|
|
|
ret = cbt->Xm/pow(1.0-quantile,1.0/cbt->alpha);
|
2009-08-28 08:28:20 +02:00
|
|
|
if (ret > INT32_MAX) {
|
|
|
|
ret = INT32_MAX;
|
|
|
|
}
|
|
|
|
tor_assert(ret > 0);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-09-08 10:31:29 +02:00
|
|
|
/** Pareto CDF */
|
2009-08-28 08:28:20 +02:00
|
|
|
double
|
2009-08-28 11:05:02 +02:00
|
|
|
circuit_build_times_cdf(circuit_build_times_t *cbt, double x)
|
2009-08-28 08:28:20 +02:00
|
|
|
{
|
2009-09-11 07:12:46 +02:00
|
|
|
double ret;
|
|
|
|
tor_assert(cbt->Xm > 0);
|
|
|
|
ret = 1.0-pow(cbt->Xm/x,cbt->alpha);
|
2009-08-28 08:28:20 +02:00
|
|
|
tor_assert(0 <= ret && ret <= 1.0);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-09-08 10:31:29 +02:00
|
|
|
/**
|
|
|
|
* Generate a synthetic time using our distribution parameters.
|
|
|
|
*
|
2009-09-18 10:48:07 +02:00
|
|
|
* The return value will be within the [q_lo, q_hi) quantile points
|
2009-09-08 10:31:29 +02:00
|
|
|
* on the CDF.
|
|
|
|
*/
|
2009-08-28 08:28:20 +02:00
|
|
|
build_time_t
|
|
|
|
circuit_build_times_generate_sample(circuit_build_times_t *cbt,
|
|
|
|
double q_lo, double q_hi)
|
|
|
|
{
|
2010-06-23 03:31:31 +02:00
|
|
|
double randval = crypto_rand_double();
|
2009-08-28 08:28:20 +02:00
|
|
|
build_time_t ret;
|
2009-09-11 07:12:46 +02:00
|
|
|
double u;
|
|
|
|
|
2009-09-18 10:48:07 +02:00
|
|
|
/* Generate between [q_lo, q_hi) */
|
2010-06-23 03:31:31 +02:00
|
|
|
/*XXXX This is what nextafter is supposed to be for; we should use it on the
|
|
|
|
* platforms that support it. */
|
2009-09-18 10:48:07 +02:00
|
|
|
q_hi -= 1.0/(INT32_MAX);
|
|
|
|
|
2009-09-11 07:12:46 +02:00
|
|
|
tor_assert(q_lo >= 0);
|
|
|
|
tor_assert(q_hi < 1);
|
2009-09-18 10:48:07 +02:00
|
|
|
tor_assert(q_lo < q_hi);
|
2009-09-11 07:12:46 +02:00
|
|
|
|
2010-06-23 03:31:31 +02:00
|
|
|
u = q_lo + (q_hi-q_lo)*randval;
|
2009-08-28 08:28:20 +02:00
|
|
|
|
|
|
|
tor_assert(0 <= u && u < 1.0);
|
2009-09-17 00:20:25 +02:00
|
|
|
/* circuit_build_times_calculate_timeout returns <= INT32_MAX */
|
2009-12-15 20:32:55 +01:00
|
|
|
ret = (build_time_t)
|
|
|
|
tor_lround(circuit_build_times_calculate_timeout(cbt, u));
|
2009-08-28 08:28:20 +02:00
|
|
|
tor_assert(ret > 0);
|
|
|
|
return ret;
|
2009-08-27 10:46:06 +02:00
|
|
|
}
|
2009-08-26 02:13:12 +02:00
|
|
|
|
2009-09-08 10:31:29 +02:00
|
|
|
/**
|
|
|
|
* Estimate an initial alpha parameter by solving the quantile
|
|
|
|
* function with a quantile point and a specific timeout value.
|
|
|
|
*/
|
2009-08-28 08:28:20 +02:00
|
|
|
void
|
|
|
|
circuit_build_times_initial_alpha(circuit_build_times_t *cbt,
|
2009-09-18 10:48:07 +02:00
|
|
|
double quantile, double timeout_ms)
|
2009-08-28 08:28:20 +02:00
|
|
|
{
|
|
|
|
// Q(u) = Xm/((1-u)^(1/a))
|
|
|
|
// Q(0.8) = Xm/((1-0.8))^(1/a)) = CircBuildTimeout
|
|
|
|
// CircBuildTimeout = Xm/((1-0.8))^(1/a))
|
|
|
|
// CircBuildTimeout = Xm*((1-0.8))^(-1/a))
|
|
|
|
// ln(CircBuildTimeout) = ln(Xm)+ln(((1-0.8)))*(-1/a)
|
|
|
|
// -ln(1-0.8)/(ln(CircBuildTimeout)-ln(Xm))=a
|
2009-10-07 22:05:28 +02:00
|
|
|
tor_assert(quantile >= 0);
|
2009-09-11 07:12:46 +02:00
|
|
|
tor_assert(cbt->Xm > 0);
|
2009-12-15 20:32:55 +01:00
|
|
|
cbt->alpha = tor_mathlog(1.0-quantile)/
|
|
|
|
(tor_mathlog(cbt->Xm)-tor_mathlog(timeout_ms));
|
2009-09-11 07:12:46 +02:00
|
|
|
tor_assert(cbt->alpha > 0);
|
2009-08-28 08:28:20 +02:00
|
|
|
}
|
|
|
|
|
2009-09-01 03:10:27 +02:00
|
|
|
/**
|
|
|
|
* Returns true if we need circuits to be built
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
circuit_build_times_needs_circuits(circuit_build_times_t *cbt)
|
|
|
|
{
|
|
|
|
/* Return true if < MIN_CIRCUITS_TO_OBSERVE */
|
2010-09-30 00:01:22 +02:00
|
|
|
return !circuit_build_times_enough_to_compute(cbt);
|
2009-09-01 03:10:27 +02:00
|
|
|
}
|
|
|
|
|
2009-09-08 10:31:29 +02:00
|
|
|
/**
|
|
|
|
* Returns true if we should build a timeout test circuit
|
|
|
|
* right now.
|
|
|
|
*/
|
2009-09-01 03:10:27 +02:00
|
|
|
int
|
|
|
|
circuit_build_times_needs_circuits_now(circuit_build_times_t *cbt)
|
|
|
|
{
|
|
|
|
return circuit_build_times_needs_circuits(cbt) &&
|
2010-01-22 01:10:02 +01:00
|
|
|
approx_time()-cbt->last_circ_at > circuit_build_times_test_frequency();
|
2009-09-01 03:10:27 +02:00
|
|
|
}
|
|
|
|
|
2009-09-08 10:31:29 +02:00
|
|
|
/**
|
2010-09-30 04:35:40 +02:00
|
|
|
* Called to indicate that the network showed some signs of liveness,
|
2010-09-30 05:51:25 +02:00
|
|
|
* i.e. we received a cell.
|
2010-09-30 04:35:40 +02:00
|
|
|
*
|
|
|
|
* This is used by circuit_build_times_network_check_live() to decide
|
|
|
|
* if we should record the circuit build timeout or not.
|
2009-12-25 12:42:35 +01:00
|
|
|
*
|
|
|
|
* This function is called every time we receive a cell. Avoid
|
|
|
|
* syscalls, events, and other high-intensity work.
|
2009-09-08 10:31:29 +02:00
|
|
|
*/
|
2009-09-01 03:10:27 +02:00
|
|
|
void
|
|
|
|
circuit_build_times_network_is_live(circuit_build_times_t *cbt)
|
|
|
|
{
|
2010-09-29 17:55:11 +02:00
|
|
|
time_t now = approx_time();
|
|
|
|
if (cbt->liveness.nonlive_timeouts > 0) {
|
|
|
|
log_notice(LD_CIRC,
|
|
|
|
"Tor now sees network activity. Restoring circuit build "
|
2010-09-30 05:51:25 +02:00
|
|
|
"timeout recording. Network was down for %d seconds "
|
2010-09-29 17:55:11 +02:00
|
|
|
"during %d circuit attempts.",
|
2010-09-30 05:51:25 +02:00
|
|
|
(int)(now - cbt->liveness.network_last_live),
|
2010-09-29 17:55:11 +02:00
|
|
|
cbt->liveness.nonlive_timeouts);
|
|
|
|
}
|
|
|
|
cbt->liveness.network_last_live = now;
|
2009-09-18 11:01:39 +02:00
|
|
|
cbt->liveness.nonlive_timeouts = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-09-21 01:50:44 +02:00
|
|
|
* Called to indicate that we completed a circuit. Because this circuit
|
|
|
|
* succeeded, it doesn't count as a timeout-after-the-first-hop.
|
2010-09-30 04:35:40 +02:00
|
|
|
*
|
|
|
|
* This is used by circuit_build_times_network_check_changed() to determine
|
|
|
|
* if we had too many recent timeouts and need to reset our learned timeout
|
|
|
|
* to something higher.
|
2009-09-18 11:01:39 +02:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
circuit_build_times_network_circ_success(circuit_build_times_t *cbt)
|
|
|
|
{
|
2012-06-12 20:52:38 +02:00
|
|
|
/* Check for NULLness because we might not be using adaptive timeouts */
|
|
|
|
if (cbt->liveness.timeouts_after_firsthop &&
|
|
|
|
cbt->liveness.num_recent_circs > 0) {
|
|
|
|
cbt->liveness.timeouts_after_firsthop[cbt->liveness.after_firsthop_idx]
|
|
|
|
= 0;
|
|
|
|
cbt->liveness.after_firsthop_idx++;
|
|
|
|
cbt->liveness.after_firsthop_idx %= cbt->liveness.num_recent_circs;
|
|
|
|
}
|
2009-09-18 11:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-06-15 10:13:49 +02:00
|
|
|
* A circuit just timed out. If it failed after the first hop, record it
|
|
|
|
* in our history for later deciding if the network speed has changed.
|
2010-09-30 04:35:40 +02:00
|
|
|
*
|
|
|
|
* This is used by circuit_build_times_network_check_changed() to determine
|
|
|
|
* if we had too many recent timeouts and need to reset our learned timeout
|
|
|
|
* to something higher.
|
2009-09-18 11:01:39 +02:00
|
|
|
*/
|
2009-09-21 01:50:44 +02:00
|
|
|
static void
|
2009-09-18 11:01:39 +02:00
|
|
|
circuit_build_times_network_timeout(circuit_build_times_t *cbt,
|
2010-06-15 10:13:49 +02:00
|
|
|
int did_onehop)
|
|
|
|
{
|
2012-06-12 20:52:38 +02:00
|
|
|
/* Check for NULLness because we might not be using adaptive timeouts */
|
|
|
|
if (cbt->liveness.timeouts_after_firsthop &&
|
|
|
|
cbt->liveness.num_recent_circs > 0) {
|
|
|
|
if (did_onehop) {
|
|
|
|
cbt->liveness.timeouts_after_firsthop[cbt->liveness.after_firsthop_idx]
|
|
|
|
= 1;
|
|
|
|
cbt->liveness.after_firsthop_idx++;
|
|
|
|
cbt->liveness.after_firsthop_idx %= cbt->liveness.num_recent_circs;
|
|
|
|
}
|
2010-06-15 10:13:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A circuit was just forcibly closed. If there has been no recent network
|
|
|
|
* activity at all, but this circuit was launched back when we thought the
|
|
|
|
* network was live, increment the number of "nonlive" circuit timeouts.
|
2010-09-30 04:35:40 +02:00
|
|
|
*
|
|
|
|
* This is used by circuit_build_times_network_check_live() to decide
|
|
|
|
* if we should record the circuit build timeout or not.
|
2010-06-15 10:13:49 +02:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
circuit_build_times_network_close(circuit_build_times_t *cbt,
|
2009-09-18 11:01:39 +02:00
|
|
|
int did_onehop, time_t start_time)
|
|
|
|
{
|
2009-09-21 03:20:10 +02:00
|
|
|
time_t now = time(NULL);
|
|
|
|
/*
|
|
|
|
* Check if this is a timeout that was for a circuit that spent its
|
|
|
|
* entire existence during a time where we have had no network activity.
|
|
|
|
*/
|
2010-09-29 20:49:31 +02:00
|
|
|
if (cbt->liveness.network_last_live < start_time) {
|
2010-06-15 07:47:45 +02:00
|
|
|
if (did_onehop) {
|
2010-06-30 01:55:10 +02:00
|
|
|
char last_live_buf[ISO_TIME_LEN+1];
|
|
|
|
char start_time_buf[ISO_TIME_LEN+1];
|
|
|
|
char now_buf[ISO_TIME_LEN+1];
|
|
|
|
format_local_iso_time(last_live_buf, cbt->liveness.network_last_live);
|
|
|
|
format_local_iso_time(start_time_buf, start_time);
|
|
|
|
format_local_iso_time(now_buf, now);
|
2010-06-15 07:47:45 +02:00
|
|
|
log_warn(LD_BUG,
|
|
|
|
"Circuit somehow completed a hop while the network was "
|
2010-06-30 01:55:10 +02:00
|
|
|
"not live. Network was last live at %s, but circuit launched "
|
|
|
|
"at %s. It's now %s.", last_live_buf, start_time_buf,
|
|
|
|
now_buf);
|
2010-06-15 07:47:45 +02:00
|
|
|
}
|
2009-09-18 11:01:39 +02:00
|
|
|
cbt->liveness.nonlive_timeouts++;
|
2010-09-29 17:55:11 +02:00
|
|
|
if (cbt->liveness.nonlive_timeouts == 1) {
|
|
|
|
log_notice(LD_CIRC,
|
2010-09-30 05:51:25 +02:00
|
|
|
"Tor has not observed any network activity for the past %d "
|
2011-01-16 03:14:15 +01:00
|
|
|
"seconds. Disabling circuit build timeout recording.",
|
2010-09-30 05:51:25 +02:00
|
|
|
(int)(now - cbt->liveness.network_last_live));
|
2010-09-29 17:55:11 +02:00
|
|
|
} else {
|
|
|
|
log_info(LD_CIRC,
|
2010-09-29 20:49:31 +02:00
|
|
|
"Got non-live timeout. Current count is: %d",
|
|
|
|
cbt->liveness.nonlive_timeouts);
|
2010-09-29 17:55:11 +02:00
|
|
|
}
|
2009-09-18 11:01:39 +02:00
|
|
|
}
|
2009-09-01 03:10:27 +02:00
|
|
|
}
|
|
|
|
|
2009-09-08 10:31:29 +02:00
|
|
|
/**
|
2010-09-30 04:35:40 +02:00
|
|
|
* When the network is not live, we do not record circuit build times.
|
|
|
|
*
|
|
|
|
* The network is considered not live if there has been at least one
|
|
|
|
* circuit build that began and ended (had its close_ms measurement
|
2010-09-30 05:51:25 +02:00
|
|
|
* period expire) since we last received a cell.
|
2009-09-18 11:01:39 +02:00
|
|
|
*
|
|
|
|
* Also has the side effect of rewinding the circuit time history
|
|
|
|
* in the case of recent liveness changes.
|
2009-09-08 10:31:29 +02:00
|
|
|
*/
|
2009-09-01 03:10:27 +02:00
|
|
|
int
|
2009-09-18 11:01:39 +02:00
|
|
|
circuit_build_times_network_check_live(circuit_build_times_t *cbt)
|
2009-09-01 03:10:27 +02:00
|
|
|
{
|
2010-09-29 17:55:11 +02:00
|
|
|
if (cbt->liveness.nonlive_timeouts > 0) {
|
2009-09-18 11:01:39 +02:00
|
|
|
return 0;
|
2009-09-02 00:40:54 +02:00
|
|
|
}
|
2009-09-18 11:01:39 +02:00
|
|
|
|
2009-09-01 03:10:27 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2009-09-08 10:31:29 +02:00
|
|
|
/**
|
2009-09-18 11:01:39 +02:00
|
|
|
* Returns true if we have seen more than MAX_RECENT_TIMEOUT_COUNT of
|
2009-09-21 01:50:44 +02:00
|
|
|
* the past RECENT_CIRCUITS time out after the first hop. Used to detect
|
2010-09-30 04:35:40 +02:00
|
|
|
* if the network connection has changed significantly, and if so,
|
|
|
|
* resets our circuit build timeout to the default.
|
2009-09-08 10:31:29 +02:00
|
|
|
*
|
|
|
|
* Also resets the entire timeout history in this case and causes us
|
|
|
|
* to restart the process of building test circuits and estimating a
|
|
|
|
* new timeout.
|
|
|
|
*/
|
2009-09-01 03:10:27 +02:00
|
|
|
int
|
2009-09-18 11:01:39 +02:00
|
|
|
circuit_build_times_network_check_changed(circuit_build_times_t *cbt)
|
2009-09-01 03:10:27 +02:00
|
|
|
{
|
2009-09-18 11:01:39 +02:00
|
|
|
int total_build_times = cbt->total_build_times;
|
|
|
|
int timeout_count=0;
|
2009-09-01 03:10:27 +02:00
|
|
|
int i;
|
|
|
|
|
2012-06-12 20:52:38 +02:00
|
|
|
if (cbt->liveness.timeouts_after_firsthop &&
|
|
|
|
cbt->liveness.num_recent_circs > 0) {
|
|
|
|
/* how many of our recent circuits made it to the first hop but then
|
|
|
|
* timed out? */
|
|
|
|
for (i = 0; i < cbt->liveness.num_recent_circs; i++) {
|
|
|
|
timeout_count += cbt->liveness.timeouts_after_firsthop[i];
|
|
|
|
}
|
2009-09-01 03:10:27 +02:00
|
|
|
}
|
|
|
|
|
2009-10-07 21:49:13 +02:00
|
|
|
/* If 80% of our recent circuits are timing out after the first hop,
|
2009-09-21 01:50:44 +02:00
|
|
|
* we need to re-estimate a new initial alpha and timeout. */
|
2010-01-22 01:10:02 +01:00
|
|
|
if (timeout_count < circuit_build_times_max_timeouts()) {
|
2009-09-01 03:10:27 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-09-18 11:01:39 +02:00
|
|
|
circuit_build_times_reset(cbt);
|
2012-06-12 20:52:38 +02:00
|
|
|
if (cbt->liveness.timeouts_after_firsthop &&
|
|
|
|
cbt->liveness.num_recent_circs > 0) {
|
|
|
|
memset(cbt->liveness.timeouts_after_firsthop, 0,
|
|
|
|
sizeof(*cbt->liveness.timeouts_after_firsthop)*
|
|
|
|
cbt->liveness.num_recent_circs);
|
|
|
|
}
|
2009-09-21 01:50:44 +02:00
|
|
|
cbt->liveness.after_firsthop_idx = 0;
|
2009-09-18 11:01:39 +02:00
|
|
|
|
|
|
|
/* Check to see if this has happened before. If so, double the timeout
|
|
|
|
* to give people on abysmally bad network connections a shot at access */
|
|
|
|
if (cbt->timeout_ms >= circuit_build_times_get_initial_timeout()) {
|
2010-06-15 07:47:45 +02:00
|
|
|
if (cbt->timeout_ms > INT32_MAX/2 || cbt->close_ms > INT32_MAX/2) {
|
|
|
|
log_warn(LD_CIRC, "Insanely large circuit build timeout value. "
|
2011-08-31 02:42:51 +02:00
|
|
|
"(timeout = %fmsec, close = %fmsec)",
|
2010-06-15 07:47:45 +02:00
|
|
|
cbt->timeout_ms, cbt->close_ms);
|
2010-05-11 04:56:27 +02:00
|
|
|
} else {
|
|
|
|
cbt->timeout_ms *= 2;
|
2010-06-15 07:47:45 +02:00
|
|
|
cbt->close_ms *= 2;
|
2010-05-11 04:56:27 +02:00
|
|
|
}
|
2009-09-18 11:01:39 +02:00
|
|
|
} else {
|
2010-06-15 07:47:45 +02:00
|
|
|
cbt->close_ms = cbt->timeout_ms
|
|
|
|
= circuit_build_times_get_initial_timeout();
|
2009-09-14 13:03:57 +02:00
|
|
|
}
|
|
|
|
|
2009-12-25 12:42:35 +01:00
|
|
|
control_event_buildtimeout_set(cbt, BUILDTIMEOUT_SET_EVENT_RESET);
|
|
|
|
|
2009-09-01 03:10:27 +02:00
|
|
|
log_notice(LD_CIRC,
|
2011-01-16 03:14:15 +01:00
|
|
|
"Your network connection speed appears to have changed. Resetting "
|
2009-09-21 01:50:44 +02:00
|
|
|
"timeout to %lds after %d timeouts and %d buildtimes.",
|
2009-12-15 20:32:55 +01:00
|
|
|
tor_lround(cbt->timeout_ms/1000), timeout_count,
|
|
|
|
total_build_times);
|
2009-09-01 03:10:27 +02:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2010-05-07 23:43:56 +02:00
|
|
|
/**
|
|
|
|
* Count the number of timeouts in a set of cbt data.
|
|
|
|
*/
|
|
|
|
double
|
|
|
|
circuit_build_times_timeout_rate(const circuit_build_times_t *cbt)
|
|
|
|
{
|
|
|
|
int i=0,timeouts=0;
|
|
|
|
for (i = 0; i < CBT_NCIRCUITS_TO_OBSERVE; i++) {
|
|
|
|
if (cbt->circuit_build_times[i] >= cbt->timeout_ms) {
|
|
|
|
timeouts++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-15 07:47:45 +02:00
|
|
|
if (!cbt->total_build_times)
|
|
|
|
return 0;
|
|
|
|
|
2010-05-07 23:43:56 +02:00
|
|
|
return ((double)timeouts)/cbt->total_build_times;
|
|
|
|
}
|
|
|
|
|
2010-06-16 03:02:19 +02:00
|
|
|
/**
|
|
|
|
* Count the number of closed circuits in a set of cbt data.
|
|
|
|
*/
|
|
|
|
double
|
|
|
|
circuit_build_times_close_rate(const circuit_build_times_t *cbt)
|
|
|
|
{
|
|
|
|
int i=0,closed=0;
|
|
|
|
for (i = 0; i < CBT_NCIRCUITS_TO_OBSERVE; i++) {
|
|
|
|
if (cbt->circuit_build_times[i] == CBT_BUILD_ABANDONED) {
|
|
|
|
closed++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!cbt->total_build_times)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return ((double)closed)/cbt->total_build_times;
|
|
|
|
}
|
|
|
|
|
2009-08-27 10:46:06 +02:00
|
|
|
/**
|
2009-09-18 11:01:39 +02:00
|
|
|
* Store a timeout as a synthetic value.
|
|
|
|
*
|
|
|
|
* Returns true if the store was successful and we should possibly
|
|
|
|
* update our timeout estimate.
|
2009-08-27 10:46:06 +02:00
|
|
|
*/
|
2009-09-18 11:01:39 +02:00
|
|
|
int
|
2010-06-15 10:13:49 +02:00
|
|
|
circuit_build_times_count_close(circuit_build_times_t *cbt,
|
2009-09-18 11:01:39 +02:00
|
|
|
int did_onehop,
|
|
|
|
time_t start_time)
|
2009-08-27 10:46:06 +02:00
|
|
|
{
|
2010-05-08 20:54:29 +02:00
|
|
|
if (circuit_build_times_disabled()) {
|
2010-06-15 07:47:45 +02:00
|
|
|
cbt->close_ms = cbt->timeout_ms
|
|
|
|
= circuit_build_times_get_initial_timeout();
|
2010-05-08 20:54:29 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-06-15 10:13:49 +02:00
|
|
|
/* Record this force-close to help determine if the network is dead */
|
|
|
|
circuit_build_times_network_close(cbt, did_onehop, start_time);
|
2009-09-18 11:01:39 +02:00
|
|
|
|
2009-09-01 03:10:27 +02:00
|
|
|
/* Only count timeouts if network is live.. */
|
2009-09-18 11:01:39 +02:00
|
|
|
if (!circuit_build_times_network_check_live(cbt)) {
|
|
|
|
return 0;
|
2009-09-01 03:10:27 +02:00
|
|
|
}
|
|
|
|
|
2010-06-15 10:13:49 +02:00
|
|
|
circuit_build_times_add_time(cbt, CBT_BUILD_ABANDONED);
|
|
|
|
return 1;
|
|
|
|
}
|
2009-09-01 03:10:27 +02:00
|
|
|
|
2010-06-15 10:13:49 +02:00
|
|
|
/**
|
|
|
|
* Update timeout counts to determine if we need to expire
|
|
|
|
* our build time history due to excessive timeouts.
|
2010-09-29 20:41:27 +02:00
|
|
|
*
|
|
|
|
* We do not record any actual time values at this stage;
|
|
|
|
* we are only interested in recording the fact that a timeout
|
|
|
|
* happened. We record the time values via
|
|
|
|
* circuit_build_times_count_close() and circuit_build_times_add_time().
|
2010-06-15 10:13:49 +02:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
circuit_build_times_count_timeout(circuit_build_times_t *cbt,
|
|
|
|
int did_onehop)
|
|
|
|
{
|
|
|
|
if (circuit_build_times_disabled()) {
|
|
|
|
cbt->close_ms = cbt->timeout_ms
|
|
|
|
= circuit_build_times_get_initial_timeout();
|
|
|
|
return;
|
2009-08-27 10:46:06 +02:00
|
|
|
}
|
|
|
|
|
2010-09-29 20:41:27 +02:00
|
|
|
/* Register the fact that a timeout just occurred. */
|
2010-06-15 10:13:49 +02:00
|
|
|
circuit_build_times_network_timeout(cbt, did_onehop);
|
2009-09-18 11:01:39 +02:00
|
|
|
|
2010-06-15 10:13:49 +02:00
|
|
|
/* If there are a ton of timeouts, we should reset
|
2010-09-29 20:41:27 +02:00
|
|
|
* the circuit build timeout. */
|
2010-06-15 10:13:49 +02:00
|
|
|
circuit_build_times_network_check_changed(cbt);
|
2009-08-27 10:46:06 +02:00
|
|
|
}
|
|
|
|
|
2009-09-08 10:31:29 +02:00
|
|
|
/**
|
|
|
|
* Estimate a new timeout based on history and set our timeout
|
|
|
|
* variable accordingly.
|
|
|
|
*/
|
2010-05-08 01:19:44 +02:00
|
|
|
static int
|
|
|
|
circuit_build_times_set_timeout_worker(circuit_build_times_t *cbt)
|
2009-08-27 10:46:06 +02:00
|
|
|
{
|
2010-09-29 19:06:31 +02:00
|
|
|
build_time_t max_time;
|
2010-09-30 00:01:22 +02:00
|
|
|
if (!circuit_build_times_enough_to_compute(cbt))
|
2010-05-08 01:19:44 +02:00
|
|
|
return 0;
|
2009-08-27 10:46:06 +02:00
|
|
|
|
2010-07-06 17:49:50 +02:00
|
|
|
if (!circuit_build_times_update_alpha(cbt))
|
|
|
|
return 0;
|
2009-09-18 11:01:39 +02:00
|
|
|
|
2009-09-18 10:48:07 +02:00
|
|
|
cbt->timeout_ms = circuit_build_times_calculate_timeout(cbt,
|
2010-01-22 01:10:02 +01:00
|
|
|
circuit_build_times_quantile_cutoff());
|
2009-08-27 10:46:06 +02:00
|
|
|
|
2010-06-08 10:01:47 +02:00
|
|
|
cbt->close_ms = circuit_build_times_calculate_timeout(cbt,
|
|
|
|
circuit_build_times_close_quantile());
|
|
|
|
|
2010-09-29 19:06:31 +02:00
|
|
|
max_time = circuit_build_times_max(cbt);
|
|
|
|
|
2010-06-08 10:01:47 +02:00
|
|
|
/* Sometimes really fast guard nodes give us such a steep curve
|
|
|
|
* that this ends up being not that much greater than timeout_ms.
|
|
|
|
* Make it be at least 1 min to handle this case. */
|
2010-06-15 07:47:45 +02:00
|
|
|
cbt->close_ms = MAX(cbt->close_ms, circuit_build_times_initial_timeout());
|
2010-06-08 10:01:47 +02:00
|
|
|
|
2010-09-29 19:06:31 +02:00
|
|
|
if (cbt->timeout_ms > max_time) {
|
2011-09-25 00:34:32 +02:00
|
|
|
log_info(LD_CIRC,
|
2010-09-29 19:06:31 +02:00
|
|
|
"Circuit build timeout of %dms is beyond the maximum build "
|
|
|
|
"time we have ever observed. Capping it to %dms.",
|
|
|
|
(int)cbt->timeout_ms, max_time);
|
|
|
|
cbt->timeout_ms = max_time;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (max_time < INT32_MAX/2 && cbt->close_ms > 2*max_time) {
|
2011-01-16 03:14:15 +01:00
|
|
|
log_info(LD_CIRC,
|
2010-09-29 19:06:31 +02:00
|
|
|
"Circuit build measurement period of %dms is more than twice "
|
|
|
|
"the maximum build time we have ever observed. Capping it to "
|
|
|
|
"%dms.", (int)cbt->close_ms, 2*max_time);
|
|
|
|
cbt->close_ms = 2*max_time;
|
|
|
|
}
|
|
|
|
|
2009-09-08 10:31:29 +02:00
|
|
|
cbt->have_computed_timeout = 1;
|
2010-05-08 01:19:44 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Exposed function to compute a new timeout. Dispatches events and
|
|
|
|
* also filters out extremely high timeout values.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
circuit_build_times_set_timeout(circuit_build_times_t *cbt)
|
|
|
|
{
|
2010-05-04 21:56:47 +02:00
|
|
|
long prev_timeout = tor_lround(cbt->timeout_ms/1000);
|
2010-05-07 23:43:56 +02:00
|
|
|
double timeout_rate;
|
2010-05-08 01:19:44 +02:00
|
|
|
|
2012-06-12 21:24:05 +02:00
|
|
|
/*
|
|
|
|
* Just return if we aren't using adaptive timeouts
|
|
|
|
*/
|
|
|
|
if (circuit_build_times_disabled())
|
|
|
|
return;
|
|
|
|
|
2010-05-08 01:19:44 +02:00
|
|
|
if (!circuit_build_times_set_timeout_worker(cbt))
|
|
|
|
return;
|
2009-08-27 10:46:06 +02:00
|
|
|
|
2010-01-22 01:10:02 +01:00
|
|
|
if (cbt->timeout_ms < circuit_build_times_min_timeout()) {
|
2012-08-27 22:37:09 +02:00
|
|
|
log_info(LD_CIRC, "Set buildtimeout to low value %fms. Setting to %dms",
|
2010-01-22 01:10:02 +01:00
|
|
|
cbt->timeout_ms, circuit_build_times_min_timeout());
|
|
|
|
cbt->timeout_ms = circuit_build_times_min_timeout();
|
2010-06-15 07:47:45 +02:00
|
|
|
if (cbt->close_ms < cbt->timeout_ms) {
|
|
|
|
/* This shouldn't happen because of MAX() in timeout_worker above,
|
|
|
|
* but doing it just in case */
|
|
|
|
cbt->close_ms = circuit_build_times_initial_timeout();
|
|
|
|
}
|
2009-09-14 13:03:57 +02:00
|
|
|
}
|
|
|
|
|
2009-12-25 12:42:35 +01:00
|
|
|
control_event_buildtimeout_set(cbt, BUILDTIMEOUT_SET_EVENT_COMPUTED);
|
|
|
|
|
2010-05-07 23:43:56 +02:00
|
|
|
timeout_rate = circuit_build_times_timeout_rate(cbt);
|
2010-05-08 01:19:44 +02:00
|
|
|
|
2010-05-04 21:56:47 +02:00
|
|
|
if (prev_timeout > tor_lround(cbt->timeout_ms/1000)) {
|
2011-09-25 00:34:32 +02:00
|
|
|
log_info(LD_CIRC,
|
2010-06-02 07:07:54 +02:00
|
|
|
"Based on %d circuit times, it looks like we don't need to "
|
2010-05-04 21:56:47 +02:00
|
|
|
"wait so long for circuits to finish. We will now assume a "
|
|
|
|
"circuit is too slow to use after waiting %ld seconds.",
|
|
|
|
cbt->total_build_times,
|
|
|
|
tor_lround(cbt->timeout_ms/1000));
|
|
|
|
log_info(LD_CIRC,
|
2011-08-31 02:42:51 +02:00
|
|
|
"Circuit timeout data: %fms, %fms, Xm: %d, a: %f, r: %f",
|
2010-06-08 10:01:47 +02:00
|
|
|
cbt->timeout_ms, cbt->close_ms, cbt->Xm, cbt->alpha,
|
|
|
|
timeout_rate);
|
2010-05-04 21:56:47 +02:00
|
|
|
} else if (prev_timeout < tor_lround(cbt->timeout_ms/1000)) {
|
2011-09-25 00:34:32 +02:00
|
|
|
log_info(LD_CIRC,
|
2010-06-02 07:07:54 +02:00
|
|
|
"Based on %d circuit times, it looks like we need to wait "
|
|
|
|
"longer for circuits to finish. We will now assume a "
|
2010-05-04 21:56:47 +02:00
|
|
|
"circuit is too slow to use after waiting %ld seconds.",
|
|
|
|
cbt->total_build_times,
|
|
|
|
tor_lround(cbt->timeout_ms/1000));
|
|
|
|
log_info(LD_CIRC,
|
2011-08-31 02:42:51 +02:00
|
|
|
"Circuit timeout data: %fms, %fms, Xm: %d, a: %f, r: %f",
|
2010-06-08 10:01:47 +02:00
|
|
|
cbt->timeout_ms, cbt->close_ms, cbt->Xm, cbt->alpha,
|
|
|
|
timeout_rate);
|
2010-05-04 21:56:47 +02:00
|
|
|
} else {
|
|
|
|
log_info(LD_CIRC,
|
2011-08-31 02:42:51 +02:00
|
|
|
"Set circuit build timeout to %lds (%fms, %fms, Xm: %d, a: %f,"
|
|
|
|
" r: %f) based on %d circuit times",
|
2010-05-04 21:56:47 +02:00
|
|
|
tor_lround(cbt->timeout_ms/1000),
|
2010-06-08 10:01:47 +02:00
|
|
|
cbt->timeout_ms, cbt->close_ms, cbt->Xm, cbt->alpha, timeout_rate,
|
2010-05-04 21:56:47 +02:00
|
|
|
cbt->total_build_times);
|
|
|
|
}
|
2009-08-27 10:46:06 +02:00
|
|
|
}
|
2009-08-26 02:13:12 +02:00
|
|
|
|
2004-05-13 09:24:49 +02:00
|
|
|
/** Iterate over values of circ_id, starting from conn-\>next_circ_id,
|
2006-07-04 05:19:59 +02:00
|
|
|
* and with the high bit specified by conn-\>circ_id_type, until we get
|
|
|
|
* a circ_id that is not in use by any other circuit on that conn.
|
2004-05-13 09:24:49 +02:00
|
|
|
*
|
|
|
|
* Return it, or 0 if can't get a unique circ_id.
|
|
|
|
*/
|
2008-07-23 17:58:30 +02:00
|
|
|
static circid_t
|
2006-07-26 21:07:26 +02:00
|
|
|
get_unique_circ_id_by_conn(or_connection_t *conn)
|
2005-06-11 20:52:12 +02:00
|
|
|
{
|
2008-07-23 17:58:30 +02:00
|
|
|
circid_t test_circ_id;
|
|
|
|
circid_t attempts=0;
|
|
|
|
circid_t high_bit;
|
2004-05-13 09:24:49 +02:00
|
|
|
|
2004-10-17 00:14:52 +02:00
|
|
|
tor_assert(conn);
|
2007-02-12 22:39:33 +01:00
|
|
|
if (conn->circ_id_type == CIRC_ID_TYPE_NEITHER) {
|
2007-03-04 21:11:46 +01:00
|
|
|
log_warn(LD_BUG, "Trying to pick a circuit ID for a connection from "
|
2007-02-12 22:39:33 +01:00
|
|
|
"a client with no identity.");
|
|
|
|
return 0;
|
|
|
|
}
|
2004-11-10 21:14:37 +01:00
|
|
|
high_bit = (conn->circ_id_type == CIRC_ID_TYPE_HIGHER) ? 1<<15 : 0;
|
2004-05-13 09:24:49 +02:00
|
|
|
do {
|
|
|
|
/* Sequentially iterate over test_circ_id=1...1<<15-1 until we find a
|
|
|
|
* circID such that (high_bit|test_circ_id) is not already used. */
|
|
|
|
test_circ_id = conn->next_circ_id++;
|
|
|
|
if (test_circ_id == 0 || test_circ_id >= 1<<15) {
|
|
|
|
test_circ_id = 1;
|
|
|
|
conn->next_circ_id = 2;
|
|
|
|
}
|
2004-11-28 10:05:49 +01:00
|
|
|
if (++attempts > 1<<15) {
|
2004-05-13 09:24:49 +02:00
|
|
|
/* Make sure we don't loop forever if all circ_id's are used. This
|
2005-10-17 10:41:58 +02:00
|
|
|
* matters because it's an external DoS opportunity.
|
2004-05-13 09:24:49 +02:00
|
|
|
*/
|
2006-02-13 09:28:42 +01:00
|
|
|
log_warn(LD_CIRC,"No unused circ IDs. Failing.");
|
2004-05-13 09:24:49 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
test_circ_id |= high_bit;
|
2008-07-23 14:55:55 +02:00
|
|
|
} while (circuit_id_in_use_on_orconn(test_circ_id, conn));
|
2004-05-13 09:24:49 +02:00
|
|
|
return test_circ_id;
|
|
|
|
}
|
|
|
|
|
2006-10-07 21:56:49 +02:00
|
|
|
/** If <b>verbose</b> is false, allocate and return a comma-separated list of
|
2011-07-06 06:48:22 +02:00
|
|
|
* the currently built elements of <b>circ</b>. If <b>verbose</b> is true, also
|
2006-10-07 21:56:49 +02:00
|
|
|
* list information about link status in a more verbose format using spaces.
|
|
|
|
* If <b>verbose_names</b> is false, give nicknames for Named routers and hex
|
2006-10-08 02:33:43 +02:00
|
|
|
* digests for others; if <b>verbose_names</b> is true, use $DIGEST=Name style
|
|
|
|
* names.
|
2004-11-03 19:33:07 +01:00
|
|
|
*/
|
2006-10-07 21:56:49 +02:00
|
|
|
static char *
|
|
|
|
circuit_list_path_impl(origin_circuit_t *circ, int verbose, int verbose_names)
|
2004-11-03 19:33:07 +01:00
|
|
|
{
|
2005-07-22 23:12:10 +02:00
|
|
|
crypt_path_t *hop;
|
2004-11-03 19:33:07 +01:00
|
|
|
smartlist_t *elements;
|
2004-11-23 01:11:36 +01:00
|
|
|
const char *states[] = {"closed", "waiting for keys", "open"};
|
2004-11-03 19:33:07 +01:00
|
|
|
char *s;
|
|
|
|
|
2012-01-18 21:53:30 +01:00
|
|
|
elements = smartlist_new();
|
2004-11-03 19:33:07 +01:00
|
|
|
|
2004-11-23 01:11:36 +01:00
|
|
|
if (verbose) {
|
2005-06-29 23:46:55 +02:00
|
|
|
const char *nickname = build_state_get_exit_nickname(circ->build_state);
|
2012-01-11 19:44:10 +01:00
|
|
|
smartlist_add_asprintf(elements, "%s%s circ (length %d%s%s):",
|
Introduce a notion of 'internal' circs, which are chosen without regard
to the exit policy of the last hop. Intro and rendezvous circs must
be internal circs, to avoid leaking information. Resolve and connect
streams can use internal circs if they want.
New circuit pooling algorithm: make sure to have enough circs around
to satisfy any predicted ports, and also make sure to have 2 internal
circs around if we've required internal circs lately (with high uptime
if we've seen that lately).
Split NewCircuitPeriod config option into NewCircuitPeriod (30 secs),
which describes how often we retry making new circuits if current ones
are dirty, and MaxCircuitDirtiness (10 mins), which describes how long
we're willing to make use of an already-dirty circuit.
Once rendezvous circuits are established, keep using the same circuit as
long as you attach a new stream to it at least every 10 minutes. (So web
browsing doesn't require you to build new rend circs every 30 seconds.)
Cannibalize GENERAL circs to be C_REND, C_INTRO, S_INTRO, and S_REND
circ as necessary, if there are any completed ones lying around when
we try to launch one.
Re-instate the ifdef's to use version-0 style introduce cells, since
there was yet another bug in handling version-1 style. We'll try switching
over again after 0.0.9 is obsolete.
Bugfix: when choosing an exit node for a new non-internal circ, don't take
into account whether it'll be useful for any pending x.onion addresses --
it won't.
Bugfix: we weren't actually publishing the hidden service descriptor when
it became dirty. So we only published it every 20 minutes or so, which
means when you first start your Tor, the hidden service will seem broken.
svn:r3360
2005-01-17 19:13:09 +01:00
|
|
|
circ->build_state->is_internal ? "internal" : "exit",
|
|
|
|
circ->build_state->need_uptime ? " (high-uptime)" : "",
|
2004-11-23 01:11:36 +01:00
|
|
|
circ->build_state->desired_path_len,
|
2011-05-04 03:53:13 +02:00
|
|
|
circ->_base.state == CIRCUIT_STATE_OPEN ? "" : ", last hop ",
|
2006-07-23 09:37:35 +02:00
|
|
|
circ->_base.state == CIRCUIT_STATE_OPEN ? "" :
|
2006-09-30 05:11:13 +02:00
|
|
|
(nickname?nickname:"*unnamed*"));
|
2004-11-23 01:11:36 +01:00
|
|
|
}
|
|
|
|
|
2004-11-23 07:08:08 +01:00
|
|
|
hop = circ->cpath;
|
|
|
|
do {
|
2006-09-30 05:11:13 +02:00
|
|
|
char *elt;
|
2009-03-18 20:30:30 +01:00
|
|
|
const char *id;
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
const node_t *node;
|
2004-11-23 07:08:08 +01:00
|
|
|
if (!hop)
|
|
|
|
break;
|
2004-11-23 01:11:36 +01:00
|
|
|
if (!verbose && hop->state != CPATH_STATE_OPEN)
|
2004-11-03 19:33:07 +01:00
|
|
|
break;
|
2005-06-29 23:46:55 +02:00
|
|
|
if (!hop->extend_info)
|
|
|
|
break;
|
2010-02-24 09:36:15 +01:00
|
|
|
id = hop->extend_info->identity_digest;
|
2006-10-07 21:56:49 +02:00
|
|
|
if (verbose_names) {
|
|
|
|
elt = tor_malloc(MAX_VERBOSE_NICKNAME_LEN+1);
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
if ((node = node_get_by_id(id))) {
|
|
|
|
node_get_verbose_nickname(node, elt);
|
2009-10-27 02:59:34 +01:00
|
|
|
} else if (is_legal_nickname(hop->extend_info->nickname)) {
|
2006-10-07 21:56:49 +02:00
|
|
|
elt[0] = '$';
|
2009-03-18 20:30:30 +01:00
|
|
|
base16_encode(elt+1, HEX_DIGEST_LEN+1, id, DIGEST_LEN);
|
2006-10-07 21:56:49 +02:00
|
|
|
elt[HEX_DIGEST_LEN+1]= '~';
|
|
|
|
strlcpy(elt+HEX_DIGEST_LEN+2,
|
|
|
|
hop->extend_info->nickname, MAX_NICKNAME_LEN+1);
|
|
|
|
} else {
|
|
|
|
elt[0] = '$';
|
2009-03-18 20:30:30 +01:00
|
|
|
base16_encode(elt+1, HEX_DIGEST_LEN+1, id, DIGEST_LEN);
|
2006-10-07 21:56:49 +02:00
|
|
|
}
|
|
|
|
} else { /* ! verbose_names */
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
node = node_get_by_id(id);
|
|
|
|
if (node && node_is_named(node)) {
|
|
|
|
elt = tor_strdup(node_get_nickname(node));
|
2006-10-07 21:56:49 +02:00
|
|
|
} else {
|
|
|
|
elt = tor_malloc(HEX_DIGEST_LEN+2);
|
|
|
|
elt[0] = '$';
|
2009-03-18 20:30:30 +01:00
|
|
|
base16_encode(elt+1, HEX_DIGEST_LEN+1, id, DIGEST_LEN);
|
2006-10-07 21:56:49 +02:00
|
|
|
}
|
2006-09-30 05:11:13 +02:00
|
|
|
}
|
2005-07-14 10:43:19 +02:00
|
|
|
tor_assert(elt);
|
2004-11-23 01:11:36 +01:00
|
|
|
if (verbose) {
|
|
|
|
tor_assert(hop->state <= 2);
|
2012-01-11 20:02:59 +01:00
|
|
|
smartlist_add_asprintf(elements,"%s(%s)",elt,states[hop->state]);
|
2006-09-30 05:11:13 +02:00
|
|
|
tor_free(elt);
|
2004-11-03 19:33:07 +01:00
|
|
|
} else {
|
2006-09-30 05:11:13 +02:00
|
|
|
smartlist_add(elements, elt);
|
2004-11-03 19:33:07 +01:00
|
|
|
}
|
2004-11-23 07:08:08 +01:00
|
|
|
hop = hop->next;
|
|
|
|
} while (hop != circ->cpath);
|
2004-11-03 19:33:07 +01:00
|
|
|
|
2004-11-23 01:11:36 +01:00
|
|
|
s = smartlist_join_strings(elements, verbose?" ":",", 0, NULL);
|
2004-11-03 19:33:07 +01:00
|
|
|
SMARTLIST_FOREACH(elements, char*, cp, tor_free(cp));
|
2004-12-07 08:48:16 +01:00
|
|
|
smartlist_free(elements);
|
2004-11-03 19:33:07 +01:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2006-10-07 21:56:49 +02:00
|
|
|
/** If <b>verbose</b> is false, allocate and return a comma-separated
|
2011-06-24 00:10:11 +02:00
|
|
|
* list of the currently built elements of <b>circ</b>. If
|
2006-10-07 21:56:49 +02:00
|
|
|
* <b>verbose</b> is true, also list information about link status in
|
|
|
|
* a more verbose format using spaces.
|
|
|
|
*/
|
2006-10-03 20:58:40 +02:00
|
|
|
char *
|
2006-10-07 21:56:49 +02:00
|
|
|
circuit_list_path(origin_circuit_t *circ, int verbose)
|
2006-10-03 20:58:40 +02:00
|
|
|
{
|
2006-10-07 21:56:49 +02:00
|
|
|
return circuit_list_path_impl(circ, verbose, 0);
|
|
|
|
}
|
2006-10-03 20:58:40 +02:00
|
|
|
|
2006-10-07 21:56:49 +02:00
|
|
|
/** Allocate and return a comma-separated list of the currently built elements
|
2011-06-24 00:10:11 +02:00
|
|
|
* of <b>circ</b>, giving each as a verbose nickname.
|
2006-10-07 21:56:49 +02:00
|
|
|
*/
|
|
|
|
char *
|
|
|
|
circuit_list_path_for_controller(origin_circuit_t *circ)
|
|
|
|
{
|
|
|
|
return circuit_list_path_impl(circ, 0, 1);
|
2006-10-03 20:58:40 +02:00
|
|
|
}
|
|
|
|
|
2004-05-13 09:24:49 +02:00
|
|
|
/** Log, at severity <b>severity</b>, the nicknames of each router in
|
2011-06-24 00:10:11 +02:00
|
|
|
* <b>circ</b>'s cpath. Also log the length of the cpath, and the intended
|
2004-05-13 09:24:49 +02:00
|
|
|
* exit point.
|
|
|
|
*/
|
2005-06-11 20:52:12 +02:00
|
|
|
void
|
2006-07-23 09:37:35 +02:00
|
|
|
circuit_log_path(int severity, unsigned int domain, origin_circuit_t *circ)
|
2005-06-11 20:52:12 +02:00
|
|
|
{
|
2004-11-23 01:11:36 +01:00
|
|
|
char *s = circuit_list_path(circ,1);
|
2009-12-15 20:32:55 +01:00
|
|
|
tor_log(severity,domain,"%s",s);
|
2004-11-23 01:11:36 +01:00
|
|
|
tor_free(s);
|
2004-05-13 09:24:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Tell the rep(utation)hist(ory) module about the status of the links
|
2011-06-24 00:10:11 +02:00
|
|
|
* in <b>circ</b>. Hops that have become OPEN are marked as successfully
|
2004-05-13 09:24:49 +02:00
|
|
|
* extended; the _first_ hop that isn't open (if any) is marked as
|
|
|
|
* unable to extend.
|
|
|
|
*/
|
2006-10-07 11:13:30 +02:00
|
|
|
/* XXXX Someday we should learn from OR circuits too. */
|
2005-06-11 20:52:12 +02:00
|
|
|
void
|
2006-07-23 09:37:35 +02:00
|
|
|
circuit_rep_hist_note_result(origin_circuit_t *circ)
|
2005-06-11 20:52:12 +02:00
|
|
|
{
|
2005-07-22 23:12:10 +02:00
|
|
|
crypt_path_t *hop;
|
2010-09-29 06:38:32 +02:00
|
|
|
const char *prev_digest = NULL;
|
2004-05-13 09:24:49 +02:00
|
|
|
hop = circ->cpath;
|
2006-10-03 00:13:42 +02:00
|
|
|
if (!hop) /* circuit hasn't started building yet. */
|
2004-05-13 09:24:49 +02:00
|
|
|
return;
|
2004-11-06 06:18:11 +01:00
|
|
|
if (server_mode(get_options())) {
|
2010-09-29 06:38:32 +02:00
|
|
|
const routerinfo_t *me = router_get_my_routerinfo();
|
2006-07-17 08:54:28 +02:00
|
|
|
if (!me)
|
|
|
|
return;
|
2005-11-05 21:15:27 +01:00
|
|
|
prev_digest = me->cache_info.identity_digest;
|
2004-05-13 09:24:49 +02:00
|
|
|
}
|
|
|
|
do {
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
const node_t *node = node_get_by_id(hop->extend_info->identity_digest);
|
|
|
|
if (node) { /* Why do we check this? We know the identity. -NM XXXX */
|
2004-07-13 20:23:40 +02:00
|
|
|
if (prev_digest) {
|
2004-05-13 09:24:49 +02:00
|
|
|
if (hop->state == CPATH_STATE_OPEN)
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
rep_hist_note_extend_succeeded(prev_digest, node->identity);
|
2004-05-13 09:24:49 +02:00
|
|
|
else {
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
rep_hist_note_extend_failed(prev_digest, node->identity);
|
2004-05-13 09:24:49 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
prev_digest = node->identity;
|
2004-05-13 09:24:49 +02:00
|
|
|
} else {
|
2004-07-13 20:23:40 +02:00
|
|
|
prev_digest = NULL;
|
2004-05-13 09:24:49 +02:00
|
|
|
}
|
|
|
|
hop=hop->next;
|
|
|
|
} while (hop!=circ->cpath);
|
|
|
|
}
|
|
|
|
|
2005-03-22 01:42:38 +01:00
|
|
|
/** Pick all the entries in our cpath. Stop and return 0 when we're
|
|
|
|
* happy, or return -1 if an error occurs. */
|
|
|
|
static int
|
2006-07-23 09:37:35 +02:00
|
|
|
onion_populate_cpath(origin_circuit_t *circ)
|
2005-06-11 20:52:12 +02:00
|
|
|
{
|
2005-03-22 01:42:38 +01:00
|
|
|
int r;
|
2010-08-16 00:29:27 +02:00
|
|
|
again:
|
2006-10-07 08:28:50 +02:00
|
|
|
r = onion_extend_cpath(circ);
|
2005-03-22 01:42:38 +01:00
|
|
|
if (r < 0) {
|
2006-02-13 09:28:42 +01:00
|
|
|
log_info(LD_CIRC,"Generating cpath hop failed.");
|
2005-03-22 01:42:38 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (r == 0)
|
|
|
|
goto again;
|
|
|
|
return 0; /* if r == 1 */
|
|
|
|
}
|
|
|
|
|
2006-07-23 09:37:35 +02:00
|
|
|
/** Create and return a new origin circuit. Initialize its purpose and
|
2007-12-23 20:15:22 +01:00
|
|
|
* build-state based on our arguments. The <b>flags</b> argument is a
|
|
|
|
* bitfield of CIRCLAUNCH_* flags. */
|
2006-07-23 09:37:35 +02:00
|
|
|
origin_circuit_t *
|
2007-12-23 20:15:22 +01:00
|
|
|
origin_circuit_init(uint8_t purpose, int flags)
|
2005-06-11 20:52:12 +02:00
|
|
|
{
|
2005-12-14 21:40:40 +01:00
|
|
|
/* sets circ->p_circ_id and circ->p_conn */
|
2006-07-23 09:37:35 +02:00
|
|
|
origin_circuit_t *circ = origin_circuit_new();
|
|
|
|
circuit_set_state(TO_CIRCUIT(circ), CIRCUIT_STATE_OR_WAIT);
|
2005-03-22 01:42:38 +01:00
|
|
|
circ->build_state = tor_malloc_zero(sizeof(cpath_build_state_t));
|
2007-12-23 20:15:22 +01:00
|
|
|
circ->build_state->onehop_tunnel =
|
|
|
|
((flags & CIRCLAUNCH_ONEHOP_TUNNEL) ? 1 : 0);
|
|
|
|
circ->build_state->need_uptime =
|
|
|
|
((flags & CIRCLAUNCH_NEED_UPTIME) ? 1 : 0);
|
|
|
|
circ->build_state->need_capacity =
|
|
|
|
((flags & CIRCLAUNCH_NEED_CAPACITY) ? 1 : 0);
|
|
|
|
circ->build_state->is_internal =
|
|
|
|
((flags & CIRCLAUNCH_IS_INTERNAL) ? 1 : 0);
|
2006-07-23 09:37:35 +02:00
|
|
|
circ->_base.purpose = purpose;
|
2005-03-22 01:42:38 +01:00
|
|
|
return circ;
|
|
|
|
}
|
|
|
|
|
2007-07-29 06:38:21 +02:00
|
|
|
/** Build a new circuit for <b>purpose</b>. If <b>exit</b>
|
2004-05-13 09:24:49 +02:00
|
|
|
* is defined, then use that as your exit router, else choose a suitable
|
|
|
|
* exit node.
|
|
|
|
*
|
|
|
|
* Also launch a connection to the first OR in the chosen path, if
|
|
|
|
* it's not open already.
|
|
|
|
*/
|
2006-07-23 09:37:35 +02:00
|
|
|
origin_circuit_t *
|
2007-12-23 20:15:22 +01:00
|
|
|
circuit_establish_circuit(uint8_t purpose, extend_info_t *exit, int flags)
|
2005-06-11 20:52:12 +02:00
|
|
|
{
|
2006-07-23 09:37:35 +02:00
|
|
|
origin_circuit_t *circ;
|
2006-10-09 17:47:27 +02:00
|
|
|
int err_reason = 0;
|
2004-05-13 09:24:49 +02:00
|
|
|
|
2007-12-23 20:15:22 +01:00
|
|
|
circ = origin_circuit_init(purpose, flags);
|
2004-05-13 09:24:49 +02:00
|
|
|
|
2007-05-08 12:01:33 +02:00
|
|
|
if (onion_pick_cpath_exit(circ, exit) < 0 ||
|
2005-03-22 01:42:38 +01:00
|
|
|
onion_populate_cpath(circ) < 0) {
|
2006-10-17 17:20:00 +02:00
|
|
|
circuit_mark_for_close(TO_CIRCUIT(circ), END_CIRC_REASON_NOPATH);
|
2004-05-13 09:24:49 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2006-10-09 17:47:27 +02:00
|
|
|
control_event_circuit_status(circ, CIRC_EVENT_LAUNCHED, 0);
|
2005-03-22 01:42:38 +01:00
|
|
|
|
2006-10-09 17:47:27 +02:00
|
|
|
if ((err_reason = circuit_handle_first_hop(circ)) < 0) {
|
|
|
|
circuit_mark_for_close(TO_CIRCUIT(circ), -err_reason);
|
2004-05-13 09:24:49 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
2005-03-22 01:42:38 +01:00
|
|
|
return circ;
|
|
|
|
}
|
2004-05-13 09:24:49 +02:00
|
|
|
|
2005-03-22 01:42:38 +01:00
|
|
|
/** Start establishing the first hop of our circuit. Figure out what
|
|
|
|
* OR we should connect to, and if necessary start the connection to
|
|
|
|
* it. If we're already connected, then send the 'create' cell.
|
2006-10-09 17:47:27 +02:00
|
|
|
* Return 0 for ok, -reason if circ should be marked-for-close. */
|
2005-06-11 20:52:12 +02:00
|
|
|
int
|
2006-07-23 09:37:35 +02:00
|
|
|
circuit_handle_first_hop(origin_circuit_t *circ)
|
2005-06-11 20:52:12 +02:00
|
|
|
{
|
2005-06-29 23:46:55 +02:00
|
|
|
crypt_path_t *firsthop;
|
2006-07-26 21:07:26 +02:00
|
|
|
or_connection_t *n_conn;
|
2006-10-09 17:47:27 +02:00
|
|
|
int err_reason = 0;
|
2008-12-15 22:17:53 +01:00
|
|
|
const char *msg = NULL;
|
|
|
|
int should_launch = 0;
|
2004-05-13 09:24:49 +02:00
|
|
|
|
2005-06-29 23:46:55 +02:00
|
|
|
firsthop = onion_next_hop_in_cpath(circ->cpath);
|
2004-08-17 14:09:37 +02:00
|
|
|
tor_assert(firsthop);
|
2005-07-14 10:43:19 +02:00
|
|
|
tor_assert(firsthop->extend_info);
|
2005-03-22 01:42:38 +01:00
|
|
|
|
|
|
|
/* now see if we're already connected to the first OR in 'route' */
|
2008-08-05 22:08:19 +02:00
|
|
|
log_debug(LD_CIRC,"Looking for firsthop '%s:%u'",
|
|
|
|
fmt_addr(&firsthop->extend_info->addr),
|
2006-02-13 09:28:42 +01:00
|
|
|
firsthop->extend_info->port);
|
2008-07-30 15:04:32 +02:00
|
|
|
|
2008-12-24 03:38:04 +01:00
|
|
|
n_conn = connection_or_get_for_extend(firsthop->extend_info->identity_digest,
|
|
|
|
&firsthop->extend_info->addr,
|
|
|
|
&msg,
|
|
|
|
&should_launch);
|
2008-12-15 22:17:53 +01:00
|
|
|
|
2008-12-24 03:38:04 +01:00
|
|
|
if (!n_conn) {
|
2008-12-19 19:51:49 +01:00
|
|
|
/* not currently connected in a useful way. */
|
2011-05-21 05:30:37 +02:00
|
|
|
log_info(LD_CIRC, "Next router is %s: %s",
|
2011-05-16 03:58:46 +02:00
|
|
|
safe_str_client(extend_info_describe(firsthop->extend_info)),
|
|
|
|
msg?msg:"???");
|
2008-07-30 15:04:32 +02:00
|
|
|
circ->_base.n_hop = extend_info_dup(firsthop->extend_info);
|
2004-05-13 09:24:49 +02:00
|
|
|
|
2008-12-15 22:17:53 +01:00
|
|
|
if (should_launch) {
|
2008-06-07 07:27:34 +02:00
|
|
|
if (circ->build_state->onehop_tunnel)
|
|
|
|
control_event_bootstrap(BOOTSTRAP_STATUS_CONN_DIR, 0);
|
2008-08-05 22:08:19 +02:00
|
|
|
n_conn = connection_or_connect(&firsthop->extend_info->addr,
|
2005-06-29 23:46:55 +02:00
|
|
|
firsthop->extend_info->port,
|
|
|
|
firsthop->extend_info->identity_digest);
|
2004-11-28 10:05:49 +01:00
|
|
|
if (!n_conn) { /* connect failed, forget the whole thing */
|
2006-02-13 09:28:42 +01:00
|
|
|
log_info(LD_CIRC,"connect to firsthop failed. Closing.");
|
2006-10-09 17:47:27 +02:00
|
|
|
return -END_CIRC_REASON_CONNECTFAILED;
|
2004-05-13 09:24:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-13 09:28:42 +01:00
|
|
|
log_debug(LD_CIRC,"connecting in progress (or finished). Good.");
|
2005-12-14 21:40:40 +01:00
|
|
|
/* return success. The onion/circuit/etc will be taken care of
|
|
|
|
* automatically (may already have been) whenever n_conn reaches
|
|
|
|
* OR_CONN_STATE_OPEN.
|
2004-05-13 09:24:49 +02:00
|
|
|
*/
|
2005-03-22 01:42:38 +01:00
|
|
|
return 0;
|
2004-08-18 22:35:11 +02:00
|
|
|
} else { /* it's already open. use it. */
|
2008-07-30 15:04:32 +02:00
|
|
|
tor_assert(!circ->_base.n_hop);
|
2006-07-23 09:37:35 +02:00
|
|
|
circ->_base.n_conn = n_conn;
|
2006-02-13 09:28:42 +01:00
|
|
|
log_debug(LD_CIRC,"Conn open. Delivering first onion skin.");
|
2006-10-09 17:47:27 +02:00
|
|
|
if ((err_reason = circuit_send_next_onion_skin(circ)) < 0) {
|
2006-02-13 09:28:42 +01:00
|
|
|
log_info(LD_CIRC,"circuit_send_next_onion_skin failed.");
|
2006-10-09 17:47:27 +02:00
|
|
|
return err_reason;
|
2004-05-13 09:24:49 +02:00
|
|
|
}
|
|
|
|
}
|
2005-03-22 01:42:38 +01:00
|
|
|
return 0;
|
2004-05-13 09:24:49 +02:00
|
|
|
}
|
|
|
|
|
2005-12-28 08:19:55 +01:00
|
|
|
/** Find any circuits that are waiting on <b>or_conn</b> to become
|
|
|
|
* open and get them to send their create cells forward.
|
2004-11-21 08:43:12 +01:00
|
|
|
*
|
|
|
|
* Status is 1 if connect succeeded, or 0 if connect failed.
|
2004-05-13 09:24:49 +02:00
|
|
|
*/
|
2005-06-11 20:52:12 +02:00
|
|
|
void
|
2006-07-26 21:07:26 +02:00
|
|
|
circuit_n_conn_done(or_connection_t *or_conn, int status)
|
2005-06-11 20:52:12 +02:00
|
|
|
{
|
2007-02-05 18:42:40 +01:00
|
|
|
smartlist_t *pending_circs;
|
2006-10-09 17:47:27 +02:00
|
|
|
int err_reason = 0;
|
2004-05-13 09:24:49 +02:00
|
|
|
|
2008-06-20 05:13:16 +02:00
|
|
|
log_debug(LD_CIRC,"or_conn to %s/%s, status=%d",
|
|
|
|
or_conn->nickname ? or_conn->nickname : "NULL",
|
|
|
|
or_conn->_base.address, status);
|
2004-07-13 01:53:16 +02:00
|
|
|
|
2012-01-18 21:53:30 +01:00
|
|
|
pending_circs = smartlist_new();
|
2007-02-05 18:42:40 +01:00
|
|
|
circuit_get_all_pending_on_or_conn(pending_circs, or_conn);
|
|
|
|
|
2008-08-05 01:39:07 +02:00
|
|
|
SMARTLIST_FOREACH_BEGIN(pending_circs, circuit_t *, circ)
|
2007-02-05 18:42:40 +01:00
|
|
|
{
|
2007-06-15 08:01:04 +02:00
|
|
|
/* These checks are redundant wrt get_all_pending_on_or_conn, but I'm
|
2007-02-05 18:42:40 +01:00
|
|
|
* leaving them in in case it's possible for the status of a circuit to
|
|
|
|
* change as we're going down the list. */
|
2008-07-30 15:04:32 +02:00
|
|
|
if (circ->marked_for_close || circ->n_conn || !circ->n_hop ||
|
2007-06-15 08:01:04 +02:00
|
|
|
circ->state != CIRCUIT_STATE_OR_WAIT)
|
2007-02-05 18:42:40 +01:00
|
|
|
continue;
|
2008-07-30 15:04:32 +02:00
|
|
|
|
|
|
|
if (tor_digest_is_zero(circ->n_hop->identity_digest)) {
|
2007-06-15 08:01:04 +02:00
|
|
|
/* Look at addr/port. This is an unkeyed connection. */
|
2008-08-05 22:08:19 +02:00
|
|
|
if (!tor_addr_eq(&circ->n_hop->addr, &or_conn->_base.addr) ||
|
2008-07-30 15:04:32 +02:00
|
|
|
circ->n_hop->port != or_conn->_base.port)
|
2007-06-15 08:01:04 +02:00
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
/* We expected a key. See if it's the right one. */
|
2011-05-10 22:58:38 +02:00
|
|
|
if (tor_memneq(or_conn->identity_digest,
|
2008-07-30 15:04:32 +02:00
|
|
|
circ->n_hop->identity_digest, DIGEST_LEN))
|
2007-06-15 08:01:04 +02:00
|
|
|
continue;
|
|
|
|
}
|
2004-11-28 10:05:49 +01:00
|
|
|
if (!status) { /* or_conn failed; close circ */
|
2006-02-13 09:28:42 +01:00
|
|
|
log_info(LD_CIRC,"or_conn failed. Closing circ.");
|
2006-05-30 08:17:28 +02:00
|
|
|
circuit_mark_for_close(circ, END_CIRC_REASON_OR_CONN_CLOSED);
|
2004-05-13 09:24:49 +02:00
|
|
|
continue;
|
2004-07-02 11:29:01 +02:00
|
|
|
}
|
2006-05-30 07:29:03 +02:00
|
|
|
log_debug(LD_CIRC, "Found circ, sending create cell.");
|
2005-12-03 17:32:29 +01:00
|
|
|
/* circuit_deliver_create_cell will set n_circ_id and add us to
|
|
|
|
* orconn_circuid_circuit_map, so we don't need to call
|
|
|
|
* set_circid_orconn here. */
|
2004-07-02 11:29:01 +02:00
|
|
|
circ->n_conn = or_conn;
|
2008-07-30 15:04:32 +02:00
|
|
|
extend_info_free(circ->n_hop);
|
|
|
|
circ->n_hop = NULL;
|
|
|
|
|
2004-11-28 10:05:49 +01:00
|
|
|
if (CIRCUIT_IS_ORIGIN(circ)) {
|
2006-10-09 17:47:50 +02:00
|
|
|
if ((err_reason =
|
|
|
|
circuit_send_next_onion_skin(TO_ORIGIN_CIRCUIT(circ))) < 0) {
|
2006-02-13 09:28:42 +01:00
|
|
|
log_info(LD_CIRC,
|
|
|
|
"send_next_onion_skin failed; circuit marked for closing.");
|
2006-10-09 17:47:27 +02:00
|
|
|
circuit_mark_for_close(circ, -err_reason);
|
2004-07-02 11:29:01 +02:00
|
|
|
continue;
|
2005-12-14 21:40:40 +01:00
|
|
|
/* XXX could this be bad, eg if next_onion_skin failed because conn
|
|
|
|
* died? */
|
2004-07-02 11:29:01 +02:00
|
|
|
}
|
|
|
|
} else {
|
2004-07-03 01:08:59 +02:00
|
|
|
/* pull the create cell out of circ->onionskin, and send it */
|
2008-02-06 00:20:49 +01:00
|
|
|
tor_assert(circ->n_conn_onionskin);
|
|
|
|
if (circuit_deliver_create_cell(circ,CELL_CREATE,
|
|
|
|
circ->n_conn_onionskin)<0) {
|
2006-01-05 22:23:03 +01:00
|
|
|
circuit_mark_for_close(circ, END_CIRC_REASON_RESOURCELIMIT);
|
2004-07-03 01:08:59 +02:00
|
|
|
continue;
|
|
|
|
}
|
2008-02-06 00:20:49 +01:00
|
|
|
tor_free(circ->n_conn_onionskin);
|
2007-02-05 18:42:40 +01:00
|
|
|
circuit_set_state(circ, CIRCUIT_STATE_OPEN);
|
2004-05-13 09:24:49 +02:00
|
|
|
}
|
2008-07-30 15:04:32 +02:00
|
|
|
}
|
|
|
|
SMARTLIST_FOREACH_END(circ);
|
2006-06-06 05:33:24 +02:00
|
|
|
|
2007-02-05 18:42:40 +01:00
|
|
|
smartlist_free(pending_circs);
|
2004-05-13 09:24:49 +02:00
|
|
|
}
|
|
|
|
|
2005-12-07 23:09:02 +01:00
|
|
|
/** Find a new circid that isn't currently in use on the circ->n_conn
|
|
|
|
* for the outgoing
|
2005-06-11 23:17:38 +02:00
|
|
|
* circuit <b>circ</b>, and deliver a cell of type <b>cell_type</b>
|
|
|
|
* (either CELL_CREATE or CELL_CREATE_FAST) with payload <b>payload</b>
|
|
|
|
* to this circuit.
|
|
|
|
* Return -1 if we failed to find a suitable circid, else return 0.
|
|
|
|
*/
|
2004-07-03 01:08:59 +02:00
|
|
|
static int
|
2006-07-23 09:37:35 +02:00
|
|
|
circuit_deliver_create_cell(circuit_t *circ, uint8_t cell_type,
|
2007-01-30 23:19:41 +01:00
|
|
|
const char *payload)
|
2005-06-11 20:52:12 +02:00
|
|
|
{
|
2004-07-03 01:08:59 +02:00
|
|
|
cell_t cell;
|
2008-07-23 17:58:30 +02:00
|
|
|
circid_t id;
|
2004-07-03 01:08:59 +02:00
|
|
|
|
2004-10-17 00:14:52 +02:00
|
|
|
tor_assert(circ);
|
|
|
|
tor_assert(circ->n_conn);
|
2004-07-03 01:08:59 +02:00
|
|
|
tor_assert(payload);
|
2005-05-03 00:35:18 +02:00
|
|
|
tor_assert(cell_type == CELL_CREATE || cell_type == CELL_CREATE_FAST);
|
2004-07-03 01:08:59 +02:00
|
|
|
|
2005-04-06 07:45:07 +02:00
|
|
|
id = get_unique_circ_id_by_conn(circ->n_conn);
|
|
|
|
if (!id) {
|
2006-02-13 09:28:42 +01:00
|
|
|
log_warn(LD_CIRC,"failed to get unique circID.");
|
2004-07-03 01:08:59 +02:00
|
|
|
return -1;
|
|
|
|
}
|
2006-02-13 09:28:42 +01:00
|
|
|
log_debug(LD_CIRC,"Chosen circID %u.", id);
|
2006-07-23 09:37:35 +02:00
|
|
|
circuit_set_n_circid_orconn(circ, id, circ->n_conn);
|
2004-07-03 01:08:59 +02:00
|
|
|
|
|
|
|
memset(&cell, 0, sizeof(cell_t));
|
2005-05-03 00:35:18 +02:00
|
|
|
cell.command = cell_type;
|
2004-07-03 01:08:59 +02:00
|
|
|
cell.circ_id = circ->n_circ_id;
|
|
|
|
|
|
|
|
memcpy(cell.payload, payload, ONIONSKIN_CHALLENGE_LEN);
|
2010-09-16 21:43:00 +02:00
|
|
|
append_cell_to_circuit_queue(circ, circ->n_conn, &cell,
|
|
|
|
CELL_DIRECTION_OUT, 0);
|
2007-03-20 04:26:51 +01:00
|
|
|
|
2007-12-02 12:24:06 +01:00
|
|
|
if (CIRCUIT_IS_ORIGIN(circ)) {
|
|
|
|
/* mark it so it gets better rate limiting treatment. */
|
|
|
|
circ->n_conn->client_used = time(NULL);
|
|
|
|
}
|
2007-03-20 04:26:51 +01:00
|
|
|
|
2004-07-03 01:08:59 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-09-13 23:24:51 +02:00
|
|
|
/** We've decided to start our reachability testing. If all
|
|
|
|
* is set, log this to the user. Return 1 if we did, or 0 if
|
|
|
|
* we chose not to log anything. */
|
2006-01-17 05:03:23 +01:00
|
|
|
int
|
2005-09-13 23:24:51 +02:00
|
|
|
inform_testing_reachability(void)
|
|
|
|
{
|
|
|
|
char dirbuf[128];
|
2010-09-29 06:38:32 +02:00
|
|
|
const routerinfo_t *me = router_get_my_routerinfo();
|
2005-09-13 23:24:51 +02:00
|
|
|
if (!me)
|
|
|
|
return 0;
|
2009-08-31 22:14:41 +02:00
|
|
|
control_event_server_status(LOG_NOTICE,
|
|
|
|
"CHECKING_REACHABILITY ORADDRESS=%s:%d",
|
|
|
|
me->address, me->or_port);
|
|
|
|
if (me->dir_port) {
|
2005-09-13 23:24:51 +02:00
|
|
|
tor_snprintf(dirbuf, sizeof(dirbuf), " and DirPort %s:%d",
|
|
|
|
me->address, me->dir_port);
|
2009-08-31 22:14:41 +02:00
|
|
|
control_event_server_status(LOG_NOTICE,
|
|
|
|
"CHECKING_REACHABILITY DIRADDRESS=%s:%d",
|
|
|
|
me->address, me->dir_port);
|
|
|
|
}
|
2009-12-15 20:32:55 +01:00
|
|
|
log_notice(LD_OR, "Now checking whether ORPort %s:%d%s %s reachable... "
|
2005-12-10 09:27:01 +01:00
|
|
|
"(this may take up to %d minutes -- look for log "
|
|
|
|
"messages indicating success)",
|
2005-09-13 23:24:51 +02:00
|
|
|
me->address, me->or_port,
|
|
|
|
me->dir_port ? dirbuf : "",
|
2005-12-08 22:12:47 +01:00
|
|
|
me->dir_port ? "are" : "is",
|
|
|
|
TIMEOUT_UNTIL_UNREACHABILITY_COMPLAINT/60);
|
2009-08-31 22:14:41 +02:00
|
|
|
|
2005-09-13 23:24:51 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-09-23 22:13:23 +02:00
|
|
|
/** Return true iff we should send a create_fast cell to start building a given
|
|
|
|
* circuit */
|
2005-12-07 23:09:02 +01:00
|
|
|
static INLINE int
|
2008-09-23 22:13:23 +02:00
|
|
|
should_use_create_fast_for_circuit(origin_circuit_t *circ)
|
2005-12-07 23:09:02 +01:00
|
|
|
{
|
2011-06-14 19:01:38 +02:00
|
|
|
const or_options_t *options = get_options();
|
2008-09-23 22:13:23 +02:00
|
|
|
tor_assert(circ->cpath);
|
|
|
|
tor_assert(circ->cpath->extend_info);
|
|
|
|
|
|
|
|
if (!circ->cpath->extend_info->onion_key)
|
|
|
|
return 1; /* our hand is forced: only a create_fast will work. */
|
|
|
|
if (!options->FastFirstHopPK)
|
|
|
|
return 0; /* we prefer to avoid create_fast */
|
2011-09-28 21:35:27 +02:00
|
|
|
if (public_server_mode(options)) {
|
2007-01-27 20:29:16 +01:00
|
|
|
/* We're a server, and we know an onion key. We can choose.
|
2011-09-28 21:35:27 +02:00
|
|
|
* Prefer to blend our circuit into the other circuits we are
|
|
|
|
* creating on behalf of others. */
|
2007-01-27 20:29:16 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
2005-12-07 23:09:02 +01:00
|
|
|
}
|
|
|
|
|
2010-09-29 20:41:27 +02:00
|
|
|
/** Return true if <b>circ</b> is the type of circuit we want to count
|
|
|
|
* timeouts from. In particular, we want it to have not completed yet
|
|
|
|
* (already completing indicates we cannibalized it), and we want it to
|
|
|
|
* have exactly three hops.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
circuit_timeout_want_to_count_circ(origin_circuit_t *circ)
|
|
|
|
{
|
|
|
|
return !circ->has_opened
|
|
|
|
&& circ->build_state->desired_path_len == DEFAULT_ROUTE_LEN;
|
|
|
|
}
|
|
|
|
|
2004-05-13 09:24:49 +02:00
|
|
|
/** This is the backbone function for building circuits.
|
|
|
|
*
|
|
|
|
* If circ's first hop is closed, then we need to build a create
|
|
|
|
* cell and send it forward.
|
|
|
|
*
|
|
|
|
* Otherwise, we need to build a relay extend cell and send it
|
|
|
|
* forward.
|
|
|
|
*
|
2006-01-05 22:23:03 +01:00
|
|
|
* Return -reason if we want to tear down circ, else return 0.
|
2004-05-13 09:24:49 +02:00
|
|
|
*/
|
2005-06-11 20:52:12 +02:00
|
|
|
int
|
2006-07-23 09:37:35 +02:00
|
|
|
circuit_send_next_onion_skin(origin_circuit_t *circ)
|
2005-06-11 20:52:12 +02:00
|
|
|
{
|
2004-05-13 09:24:49 +02:00
|
|
|
crypt_path_t *hop;
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
const node_t *node;
|
2004-07-01 03:16:59 +02:00
|
|
|
char payload[2+4+DIGEST_LEN+ONIONSKIN_CHALLENGE_LEN];
|
|
|
|
char *onionskin;
|
2004-10-14 04:47:09 +02:00
|
|
|
size_t payload_len;
|
2004-05-13 09:24:49 +02:00
|
|
|
|
2004-10-17 00:14:52 +02:00
|
|
|
tor_assert(circ);
|
2004-05-13 09:24:49 +02:00
|
|
|
|
2004-11-28 10:05:49 +01:00
|
|
|
if (circ->cpath->state == CPATH_STATE_CLOSED) {
|
2005-12-07 23:09:02 +01:00
|
|
|
int fast;
|
2005-05-03 00:35:18 +02:00
|
|
|
uint8_t cell_type;
|
2006-02-13 09:28:42 +01:00
|
|
|
log_debug(LD_CIRC,"First skin; sending create cell.");
|
2008-06-07 07:27:34 +02:00
|
|
|
if (circ->build_state->onehop_tunnel)
|
|
|
|
control_event_bootstrap(BOOTSTRAP_STATUS_ONEHOP_CREATE, 0);
|
|
|
|
else
|
|
|
|
control_event_bootstrap(BOOTSTRAP_STATUS_CIRCUIT_CREATE, 0);
|
2004-05-13 09:24:49 +02:00
|
|
|
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
node = node_get_by_id(circ->_base.n_conn->identity_digest);
|
2008-09-23 22:13:23 +02:00
|
|
|
fast = should_use_create_fast_for_circuit(circ);
|
2007-01-27 20:29:16 +01:00
|
|
|
if (!fast) {
|
2008-09-23 22:13:23 +02:00
|
|
|
/* We are an OR and we know the right onion key: we should
|
2005-05-03 00:35:18 +02:00
|
|
|
* send an old slow create cell.
|
|
|
|
*/
|
|
|
|
cell_type = CELL_CREATE;
|
2005-06-29 23:46:55 +02:00
|
|
|
if (onion_skin_create(circ->cpath->extend_info->onion_key,
|
2005-05-03 00:35:18 +02:00
|
|
|
&(circ->cpath->dh_handshake_state),
|
|
|
|
payload) < 0) {
|
2006-02-13 09:28:42 +01:00
|
|
|
log_warn(LD_CIRC,"onion_skin_create (first hop) failed.");
|
2006-01-05 22:23:03 +01:00
|
|
|
return - END_CIRC_REASON_INTERNAL;
|
2005-05-03 00:35:18 +02:00
|
|
|
}
|
2008-06-02 17:09:35 +02:00
|
|
|
note_request("cell: create", 1);
|
2005-05-03 00:35:18 +02:00
|
|
|
} else {
|
2005-12-08 18:38:32 +01:00
|
|
|
/* We are not an OR, and we're building the first hop of a circuit to a
|
|
|
|
* new OR: we can be speedy and use CREATE_FAST to save an RSA operation
|
|
|
|
* and a DH operation. */
|
2005-05-03 00:35:18 +02:00
|
|
|
cell_type = CELL_CREATE_FAST;
|
|
|
|
memset(payload, 0, sizeof(payload));
|
2010-12-14 01:34:01 +01:00
|
|
|
crypto_rand((char*) circ->cpath->fast_handshake_state,
|
2005-05-03 00:35:18 +02:00
|
|
|
sizeof(circ->cpath->fast_handshake_state));
|
|
|
|
memcpy(payload, circ->cpath->fast_handshake_state,
|
|
|
|
sizeof(circ->cpath->fast_handshake_state));
|
2008-06-02 17:09:35 +02:00
|
|
|
note_request("cell: create fast", 1);
|
2004-05-13 09:24:49 +02:00
|
|
|
}
|
|
|
|
|
2006-07-23 09:37:35 +02:00
|
|
|
if (circuit_deliver_create_cell(TO_CIRCUIT(circ), cell_type, payload) < 0)
|
2006-01-05 22:23:03 +01:00
|
|
|
return - END_CIRC_REASON_RESOURCELIMIT;
|
2004-05-13 09:24:49 +02:00
|
|
|
|
|
|
|
circ->cpath->state = CPATH_STATE_AWAITING_KEYS;
|
2006-07-23 09:37:35 +02:00
|
|
|
circuit_set_state(TO_CIRCUIT(circ), CIRCUIT_STATE_BUILDING);
|
2006-02-13 09:28:42 +01:00
|
|
|
log_info(LD_CIRC,"First hop: finished sending %s cell to '%s'",
|
|
|
|
fast ? "CREATE_FAST" : "CREATE",
|
2011-05-30 21:41:46 +02:00
|
|
|
node ? node_describe(node) : "<unnamed>");
|
2004-05-13 09:24:49 +02:00
|
|
|
} else {
|
|
|
|
tor_assert(circ->cpath->state == CPATH_STATE_OPEN);
|
2006-07-23 09:37:35 +02:00
|
|
|
tor_assert(circ->_base.state == CIRCUIT_STATE_BUILDING);
|
2006-02-13 09:28:42 +01:00
|
|
|
log_debug(LD_CIRC,"starting to send subsequent skin.");
|
2005-06-29 23:46:55 +02:00
|
|
|
hop = onion_next_hop_in_cpath(circ->cpath);
|
|
|
|
if (!hop) {
|
2004-05-13 09:24:49 +02:00
|
|
|
/* done building the circuit. whew. */
|
2006-07-23 09:37:35 +02:00
|
|
|
circuit_set_state(TO_CIRCUIT(circ), CIRCUIT_STATE_OPEN);
|
2010-09-29 20:41:27 +02:00
|
|
|
if (circuit_timeout_want_to_count_circ(circ)) {
|
2009-10-01 10:15:45 +02:00
|
|
|
struct timeval end;
|
|
|
|
long timediff;
|
|
|
|
tor_gettimeofday(&end);
|
2010-10-15 18:35:55 +02:00
|
|
|
timediff = tv_mdiff(&circ->_base.timestamp_created, &end);
|
2010-09-29 20:41:27 +02:00
|
|
|
|
2010-05-08 00:42:57 +02:00
|
|
|
/*
|
|
|
|
* If the circuit build time is much greater than we would have cut
|
|
|
|
* it off at, we probably had a suspend event along this codepath,
|
|
|
|
* and we should discard the value.
|
|
|
|
*/
|
2010-06-08 10:01:47 +02:00
|
|
|
if (timediff < 0 || timediff > 2*circ_times.close_ms+1000) {
|
2010-06-15 07:47:45 +02:00
|
|
|
log_notice(LD_CIRC, "Strange value for circuit build time: %ldmsec. "
|
2011-04-08 19:27:25 +02:00
|
|
|
"Assuming clock jump. Purpose %d (%s)", timediff,
|
|
|
|
circ->_base.purpose,
|
|
|
|
circuit_purpose_to_string(circ->_base.purpose));
|
2010-05-08 20:54:29 +02:00
|
|
|
} else if (!circuit_build_times_disabled()) {
|
2010-09-29 20:41:27 +02:00
|
|
|
/* Only count circuit times if the network is live */
|
2010-06-15 10:13:49 +02:00
|
|
|
if (circuit_build_times_network_check_live(&circ_times)) {
|
|
|
|
circuit_build_times_add_time(&circ_times, (build_time_t)timediff);
|
|
|
|
circuit_build_times_set_timeout(&circ_times);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (circ->_base.purpose != CIRCUIT_PURPOSE_C_MEASURE_TIMEOUT) {
|
|
|
|
circuit_build_times_network_circ_success(&circ_times);
|
|
|
|
}
|
2010-05-08 00:42:57 +02:00
|
|
|
}
|
2009-10-01 10:15:45 +02:00
|
|
|
}
|
2006-02-13 09:28:42 +01:00
|
|
|
log_info(LD_CIRC,"circuit built!");
|
2004-08-18 10:51:04 +02:00
|
|
|
circuit_reset_failure_count(0);
|
2012-08-17 01:29:19 +02:00
|
|
|
|
2012-05-04 05:15:34 +02:00
|
|
|
if (circ->build_state->onehop_tunnel || circ->has_opened) {
|
2008-06-07 07:27:34 +02:00
|
|
|
control_event_bootstrap(BOOTSTRAP_STATUS_REQUESTING_STATUS, 0);
|
2012-05-04 05:15:34 +02:00
|
|
|
}
|
2012-08-17 01:29:19 +02:00
|
|
|
|
2010-09-22 07:52:57 +02:00
|
|
|
if (!can_complete_circuit && !circ->build_state->onehop_tunnel) {
|
2011-06-14 19:01:38 +02:00
|
|
|
const or_options_t *options = get_options();
|
2010-09-22 07:52:57 +02:00
|
|
|
can_complete_circuit=1;
|
2005-09-13 23:24:51 +02:00
|
|
|
/* FFFF Log a count of known routers here */
|
2009-12-15 20:32:55 +01:00
|
|
|
log_notice(LD_GENERAL,
|
2006-03-17 20:25:36 +01:00
|
|
|
"Tor has successfully opened a circuit. "
|
|
|
|
"Looks like client functionality is working.");
|
2008-06-07 07:27:34 +02:00
|
|
|
control_event_bootstrap(BOOTSTRAP_STATUS_DONE, 0);
|
2006-10-23 07:51:46 +02:00
|
|
|
control_event_client_status(LOG_NOTICE, "CIRCUIT_ESTABLISHED");
|
2011-07-11 22:10:24 +02:00
|
|
|
clear_broken_connection_map(1);
|
2005-08-22 07:46:02 +02:00
|
|
|
if (server_mode(options) && !check_whether_orport_reachable()) {
|
2005-09-13 23:24:51 +02:00
|
|
|
inform_testing_reachability();
|
2006-09-15 07:53:00 +02:00
|
|
|
consider_testing_reachability(1, 1);
|
2005-08-22 07:46:02 +02:00
|
|
|
}
|
2004-05-13 09:24:49 +02:00
|
|
|
}
|
2012-08-17 01:29:19 +02:00
|
|
|
|
|
|
|
pathbias_count_success(circ);
|
2004-05-13 09:24:49 +02:00
|
|
|
circuit_rep_hist_note_result(circ);
|
|
|
|
circuit_has_opened(circ); /* do other actions as necessary */
|
2010-06-15 10:13:49 +02:00
|
|
|
|
|
|
|
/* We're done with measurement circuits here. Just close them */
|
|
|
|
if (circ->_base.purpose == CIRCUIT_PURPOSE_C_MEASURE_TIMEOUT)
|
|
|
|
circuit_mark_for_close(TO_CIRCUIT(circ), END_CIRC_REASON_FINISHED);
|
2004-05-13 09:24:49 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-08-05 22:08:19 +02:00
|
|
|
if (tor_addr_family(&hop->extend_info->addr) != AF_INET) {
|
|
|
|
log_warn(LD_BUG, "Trying to extend to a non-IPv4 address.");
|
|
|
|
return - END_CIRC_REASON_INTERNAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
set_uint32(payload, tor_addr_to_ipv4n(&hop->extend_info->addr));
|
2007-01-25 00:42:00 +01:00
|
|
|
set_uint16(payload+4, htons(hop->extend_info->port));
|
2004-07-22 05:47:20 +02:00
|
|
|
|
|
|
|
onionskin = payload+2+4;
|
2005-12-14 21:40:40 +01:00
|
|
|
memcpy(payload+2+4+ONIONSKIN_CHALLENGE_LEN,
|
|
|
|
hop->extend_info->identity_digest, DIGEST_LEN);
|
2004-07-22 05:47:20 +02:00
|
|
|
payload_len = 2+4+ONIONSKIN_CHALLENGE_LEN+DIGEST_LEN;
|
2004-07-01 03:16:59 +02:00
|
|
|
|
2005-06-29 23:46:55 +02:00
|
|
|
if (onion_skin_create(hop->extend_info->onion_key,
|
|
|
|
&(hop->dh_handshake_state), onionskin) < 0) {
|
2006-02-13 09:28:42 +01:00
|
|
|
log_warn(LD_CIRC,"onion_skin_create failed.");
|
2006-01-05 22:23:03 +01:00
|
|
|
return - END_CIRC_REASON_INTERNAL;
|
2004-05-13 09:24:49 +02:00
|
|
|
}
|
|
|
|
|
2007-03-26 16:07:59 +02:00
|
|
|
log_info(LD_CIRC,"Sending extend relay cell.");
|
2008-06-02 17:09:35 +02:00
|
|
|
note_request("cell: extend", 1);
|
2004-05-13 09:24:49 +02:00
|
|
|
/* send it to hop->prev, because it will transfer
|
|
|
|
* it to a create cell and then send to hop */
|
2007-03-24 16:57:51 +01:00
|
|
|
if (relay_send_command_from_edge(0, TO_CIRCUIT(circ),
|
2006-07-23 09:37:35 +02:00
|
|
|
RELAY_COMMAND_EXTEND,
|
2004-11-28 12:39:53 +01:00
|
|
|
payload, payload_len, hop->prev) < 0)
|
2004-05-13 09:24:49 +02:00
|
|
|
return 0; /* circuit is closed */
|
|
|
|
|
|
|
|
hop->state = CPATH_STATE_AWAITING_KEYS;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-01-22 20:20:33 +01:00
|
|
|
/** Our clock just jumped by <b>seconds_elapsed</b>. Assume
|
2005-03-22 01:42:38 +01:00
|
|
|
* something has also gone wrong with our network: notify the user,
|
|
|
|
* and abandon all not-yet-used circuits. */
|
2005-06-11 20:52:12 +02:00
|
|
|
void
|
|
|
|
circuit_note_clock_jumped(int seconds_elapsed)
|
|
|
|
{
|
2006-10-23 12:16:43 +02:00
|
|
|
int severity = server_mode(get_options()) ? LOG_WARN : LOG_NOTICE;
|
2009-12-15 20:32:55 +01:00
|
|
|
tor_log(severity, LD_GENERAL, "Your system clock just jumped %d seconds %s; "
|
2007-01-22 20:20:33 +01:00
|
|
|
"assuming established circuits no longer work.",
|
|
|
|
seconds_elapsed >=0 ? seconds_elapsed : -seconds_elapsed,
|
|
|
|
seconds_elapsed >=0 ? "forward" : "backward");
|
2006-10-23 12:16:43 +02:00
|
|
|
control_event_general_status(LOG_WARN, "CLOCK_JUMPED TIME=%d",
|
|
|
|
seconds_elapsed);
|
2010-09-22 07:52:57 +02:00
|
|
|
can_complete_circuit=0; /* so it'll log when it works again */
|
2006-10-23 12:16:43 +02:00
|
|
|
control_event_client_status(severity, "CIRCUIT_NOT_ESTABLISHED REASON=%s",
|
|
|
|
"CLOCK_JUMPED");
|
2005-03-20 00:58:42 +01:00
|
|
|
circuit_mark_all_unused_circs();
|
2005-12-25 05:37:33 +01:00
|
|
|
circuit_expire_all_dirty_circs();
|
2005-03-20 00:58:42 +01:00
|
|
|
}
|
|
|
|
|
2008-08-20 07:21:43 +02:00
|
|
|
/** Take the 'extend' <b>cell</b>, pull out addr/port plus the onion
|
|
|
|
* skin and identity digest for the next hop. If we're already connected,
|
|
|
|
* pass the onion skin to the next hop using a create cell; otherwise
|
|
|
|
* launch a new OR connection, and <b>circ</b> will notice when the
|
|
|
|
* connection succeeds or fails.
|
|
|
|
*
|
|
|
|
* Return -1 if we want to warn and tear down the circuit, else return 0.
|
2004-05-13 09:24:49 +02:00
|
|
|
*/
|
2005-06-11 20:52:12 +02:00
|
|
|
int
|
|
|
|
circuit_extend(cell_t *cell, circuit_t *circ)
|
|
|
|
{
|
2006-07-26 21:07:26 +02:00
|
|
|
or_connection_t *n_conn;
|
2004-07-01 03:16:59 +02:00
|
|
|
relay_header_t rh;
|
|
|
|
char *onionskin;
|
2004-07-03 01:08:59 +02:00
|
|
|
char *id_digest=NULL;
|
2008-12-15 22:17:53 +01:00
|
|
|
uint32_t n_addr32;
|
2008-07-30 15:04:32 +02:00
|
|
|
uint16_t n_port;
|
2008-12-15 22:17:53 +01:00
|
|
|
tor_addr_t n_addr;
|
|
|
|
const char *msg = NULL;
|
|
|
|
int should_launch = 0;
|
2004-05-13 09:24:49 +02:00
|
|
|
|
2004-11-28 10:05:49 +01:00
|
|
|
if (circ->n_conn) {
|
2006-07-30 06:32:58 +02:00
|
|
|
log_fn(LOG_PROTOCOL_WARN, LD_PROTOCOL,
|
2005-10-24 21:37:45 +02:00
|
|
|
"n_conn already set. Bug/attack. Closing.");
|
2004-05-13 09:24:49 +02:00
|
|
|
return -1;
|
|
|
|
}
|
2009-02-21 20:07:05 +01:00
|
|
|
if (circ->n_hop) {
|
|
|
|
log_fn(LOG_PROTOCOL_WARN, LD_PROTOCOL,
|
|
|
|
"conn to next hop already launched. Bug/attack. Closing.");
|
|
|
|
return -1;
|
|
|
|
}
|
2004-05-13 09:24:49 +02:00
|
|
|
|
2006-07-30 06:32:58 +02:00
|
|
|
if (!server_mode(get_options())) {
|
|
|
|
log_fn(LOG_PROTOCOL_WARN, LD_PROTOCOL,
|
|
|
|
"Got an extend cell, but running as a client. Closing.");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2004-07-01 03:16:59 +02:00
|
|
|
relay_header_unpack(&rh, cell->payload);
|
|
|
|
|
2004-10-17 23:51:20 +02:00
|
|
|
if (rh.length < 4+2+ONIONSKIN_CHALLENGE_LEN+DIGEST_LEN) {
|
2005-12-10 10:36:26 +01:00
|
|
|
log_fn(LOG_PROTOCOL_WARN, LD_PROTOCOL,
|
|
|
|
"Wrong length %d on extend cell. Closing circuit.",
|
|
|
|
rh.length);
|
2004-07-03 01:08:59 +02:00
|
|
|
return -1;
|
2004-07-01 03:16:59 +02:00
|
|
|
}
|
|
|
|
|
2008-12-15 22:17:53 +01:00
|
|
|
n_addr32 = ntohl(get_uint32(cell->payload+RELAY_HEADER_SIZE));
|
2008-07-30 15:04:32 +02:00
|
|
|
n_port = ntohs(get_uint16(cell->payload+RELAY_HEADER_SIZE+4));
|
2010-12-14 01:34:01 +01:00
|
|
|
onionskin = (char*) cell->payload+RELAY_HEADER_SIZE+4+2;
|
2011-01-03 17:57:42 +01:00
|
|
|
id_digest = (char*) cell->payload+RELAY_HEADER_SIZE+4+2+
|
|
|
|
ONIONSKIN_CHALLENGE_LEN;
|
2008-12-15 22:17:53 +01:00
|
|
|
tor_addr_from_ipv4h(&n_addr, n_addr32);
|
2008-07-30 15:04:32 +02:00
|
|
|
|
2009-03-09 01:53:42 +01:00
|
|
|
if (!n_port || !n_addr32) {
|
|
|
|
log_fn(LOG_PROTOCOL_WARN, LD_PROTOCOL,
|
|
|
|
"Client asked me to extend to zero destination port or addr.");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-08-27 17:16:44 +02:00
|
|
|
if (tor_addr_is_internal(&n_addr, 0) &&
|
|
|
|
!get_options()->ExtendAllowPrivateAddresses) {
|
|
|
|
log_fn(LOG_PROTOCOL_WARN, LD_PROTOCOL,
|
|
|
|
"Client asked me to extend to a private address");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-03-09 01:53:42 +01:00
|
|
|
/* Check if they asked us for 0000..0000. We support using
|
2008-08-20 07:21:43 +02:00
|
|
|
* an empty fingerprint for the first hop (e.g. for a bridge relay),
|
|
|
|
* but we don't want to let people send us extend cells for empty
|
|
|
|
* fingerprints -- a) because it opens the user up to a mitm attack,
|
|
|
|
* and b) because it lets an attacker force the relay to hold open a
|
|
|
|
* new TLS connection for each extend request. */
|
|
|
|
if (tor_digest_is_zero(id_digest)) {
|
|
|
|
log_fn(LOG_PROTOCOL_WARN, LD_PROTOCOL,
|
|
|
|
"Client asked me to extend without specifying an id_digest.");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Next, check if we're being asked to connect to the hop that the
|
|
|
|
* extend cell came from. There isn't any reason for that, and it can
|
|
|
|
* assist circular-path attacks. */
|
2011-05-10 22:23:43 +02:00
|
|
|
if (tor_memeq(id_digest, TO_OR_CIRCUIT(circ)->p_conn->identity_digest,
|
2008-08-20 07:21:43 +02:00
|
|
|
DIGEST_LEN)) {
|
|
|
|
log_fn(LOG_PROTOCOL_WARN, LD_PROTOCOL,
|
|
|
|
"Client asked me to extend back to the previous hop.");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2008-12-24 03:38:04 +01:00
|
|
|
n_conn = connection_or_get_for_extend(id_digest,
|
|
|
|
&n_addr,
|
|
|
|
&msg,
|
|
|
|
&should_launch);
|
2004-07-01 03:16:59 +02:00
|
|
|
|
2008-12-24 03:38:04 +01:00
|
|
|
if (!n_conn) {
|
|
|
|
log_debug(LD_CIRC|LD_OR,"Next router (%s:%d): %s",
|
2008-12-15 22:17:53 +01:00
|
|
|
fmt_addr(&n_addr), (int)n_port, msg?msg:"????");
|
2008-07-30 15:04:32 +02:00
|
|
|
|
2012-09-06 17:38:32 +02:00
|
|
|
circ->n_hop = extend_info_new(NULL /*nickname*/,
|
2008-07-30 15:04:32 +02:00
|
|
|
id_digest,
|
|
|
|
NULL /*onion_key*/,
|
2008-12-15 22:17:53 +01:00
|
|
|
&n_addr, n_port);
|
2004-07-02 11:29:01 +02:00
|
|
|
|
2008-02-06 00:20:49 +01:00
|
|
|
circ->n_conn_onionskin = tor_malloc(ONIONSKIN_CHALLENGE_LEN);
|
|
|
|
memcpy(circ->n_conn_onionskin, onionskin, ONIONSKIN_CHALLENGE_LEN);
|
2005-12-03 03:12:37 +01:00
|
|
|
circuit_set_state(circ, CIRCUIT_STATE_OR_WAIT);
|
2004-07-13 01:53:16 +02:00
|
|
|
|
2008-12-15 22:17:53 +01:00
|
|
|
if (should_launch) {
|
2008-07-30 15:04:32 +02:00
|
|
|
/* we should try to open a connection */
|
2008-12-15 22:17:53 +01:00
|
|
|
n_conn = connection_or_connect(&n_addr, n_port, id_digest);
|
2004-11-28 10:05:49 +01:00
|
|
|
if (!n_conn) {
|
2006-02-13 09:28:42 +01:00
|
|
|
log_info(LD_CIRC,"Launching n_conn failed. Closing circuit.");
|
2006-01-05 22:23:03 +01:00
|
|
|
circuit_mark_for_close(circ, END_CIRC_REASON_CONNECTFAILED);
|
2005-10-17 03:29:28 +02:00
|
|
|
return 0;
|
2004-08-08 12:32:36 +02:00
|
|
|
}
|
2006-02-13 09:28:42 +01:00
|
|
|
log_debug(LD_CIRC,"connecting in progress (or finished). Good.");
|
2004-07-03 01:08:59 +02:00
|
|
|
}
|
2005-12-14 21:40:40 +01:00
|
|
|
/* return success. The onion/circuit/etc will be taken care of
|
|
|
|
* automatically (may already have been) whenever n_conn reaches
|
|
|
|
* OR_CONN_STATE_OPEN.
|
2004-07-02 11:29:01 +02:00
|
|
|
*/
|
2004-05-13 09:24:49 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-08-03 19:45:24 +02:00
|
|
|
tor_assert(!circ->n_hop); /* Connection is already established. */
|
2004-05-13 09:24:49 +02:00
|
|
|
circ->n_conn = n_conn;
|
2006-07-26 21:07:37 +02:00
|
|
|
log_debug(LD_CIRC,"n_conn is %s:%u",
|
|
|
|
n_conn->_base.address,n_conn->_base.port);
|
2004-05-13 09:24:49 +02:00
|
|
|
|
2005-05-03 00:35:18 +02:00
|
|
|
if (circuit_deliver_create_cell(circ, CELL_CREATE, onionskin) < 0)
|
2004-05-13 09:24:49 +02:00
|
|
|
return -1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Initialize cpath-\>{f|b}_{crypto|digest} from the key material in
|
|
|
|
* key_data. key_data must contain CPATH_KEY_MATERIAL bytes, which are
|
|
|
|
* used as follows:
|
|
|
|
* - 20 to initialize f_digest
|
|
|
|
* - 20 to initialize b_digest
|
|
|
|
* - 16 to key f_crypto
|
|
|
|
* - 16 to key b_crypto
|
|
|
|
*
|
|
|
|
* (If 'reverse' is true, then f_XX and b_XX are swapped.)
|
|
|
|
*/
|
2005-06-11 20:52:12 +02:00
|
|
|
int
|
2007-01-30 23:19:41 +01:00
|
|
|
circuit_init_cpath_crypto(crypt_path_t *cpath, const char *key_data,
|
|
|
|
int reverse)
|
2004-05-13 09:24:49 +02:00
|
|
|
{
|
2012-01-18 21:53:30 +01:00
|
|
|
crypto_digest_t *tmp_digest;
|
|
|
|
crypto_cipher_t *tmp_crypto;
|
2004-05-13 09:24:49 +02:00
|
|
|
|
2004-10-17 00:14:52 +02:00
|
|
|
tor_assert(cpath);
|
|
|
|
tor_assert(key_data);
|
2004-05-13 09:24:49 +02:00
|
|
|
tor_assert(!(cpath->f_crypto || cpath->b_crypto ||
|
|
|
|
cpath->f_digest || cpath->b_digest));
|
|
|
|
|
2012-01-18 21:53:30 +01:00
|
|
|
cpath->f_digest = crypto_digest_new();
|
2004-05-13 09:24:49 +02:00
|
|
|
crypto_digest_add_bytes(cpath->f_digest, key_data, DIGEST_LEN);
|
2012-01-18 21:53:30 +01:00
|
|
|
cpath->b_digest = crypto_digest_new();
|
2004-05-13 09:24:49 +02:00
|
|
|
crypto_digest_add_bytes(cpath->b_digest, key_data+DIGEST_LEN, DIGEST_LEN);
|
|
|
|
|
|
|
|
if (!(cpath->f_crypto =
|
2012-03-20 20:35:43 +01:00
|
|
|
crypto_cipher_new(key_data+(2*DIGEST_LEN)))) {
|
2007-03-04 21:11:46 +01:00
|
|
|
log_warn(LD_BUG,"Forward cipher initialization failed.");
|
2004-05-13 09:24:49 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (!(cpath->b_crypto =
|
2012-03-20 20:35:43 +01:00
|
|
|
crypto_cipher_new(key_data+(2*DIGEST_LEN)+CIPHER_KEY_LEN))) {
|
2007-03-04 21:11:46 +01:00
|
|
|
log_warn(LD_BUG,"Backward cipher initialization failed.");
|
2004-05-13 09:24:49 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (reverse) {
|
|
|
|
tmp_digest = cpath->f_digest;
|
|
|
|
cpath->f_digest = cpath->b_digest;
|
|
|
|
cpath->b_digest = tmp_digest;
|
|
|
|
tmp_crypto = cpath->f_crypto;
|
|
|
|
cpath->f_crypto = cpath->b_crypto;
|
|
|
|
cpath->b_crypto = tmp_crypto;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-05-04 05:15:34 +02:00
|
|
|
/** The minimum number of first hop completions before we start
|
|
|
|
* thinking about warning about path bias and dropping guards */
|
|
|
|
static int
|
|
|
|
pathbias_get_min_circs(const or_options_t *options)
|
|
|
|
{
|
|
|
|
#define DFLT_PATH_BIAS_MIN_CIRC 20
|
|
|
|
if (options->PathBiasCircThreshold >= 5)
|
|
|
|
return options->PathBiasCircThreshold;
|
|
|
|
else
|
|
|
|
return networkstatus_get_param(NULL, "pb_mincircs",
|
|
|
|
DFLT_PATH_BIAS_MIN_CIRC,
|
|
|
|
5, INT32_MAX);
|
|
|
|
}
|
|
|
|
|
|
|
|
static double
|
|
|
|
pathbias_get_notice_rate(const or_options_t *options)
|
|
|
|
{
|
2012-06-15 06:15:08 +02:00
|
|
|
#define DFLT_PATH_BIAS_NOTICE_PCT 40
|
2012-05-04 05:15:34 +02:00
|
|
|
if (options->PathBiasNoticeRate >= 0.0)
|
|
|
|
return options->PathBiasNoticeRate;
|
|
|
|
else
|
|
|
|
return networkstatus_get_param(NULL, "pb_noticepct",
|
|
|
|
DFLT_PATH_BIAS_NOTICE_PCT, 0, 100)/100.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static double
|
|
|
|
pathbias_get_disable_rate(const or_options_t *options)
|
|
|
|
{
|
2012-06-14 01:37:43 +02:00
|
|
|
// XXX: This needs tuning based on use + experimentation before we set it
|
|
|
|
#define DFLT_PATH_BIAS_DISABLE_PCT 0
|
2012-05-04 05:15:34 +02:00
|
|
|
if (options->PathBiasDisableRate >= 0.0)
|
|
|
|
return options->PathBiasDisableRate;
|
|
|
|
else
|
|
|
|
return networkstatus_get_param(NULL, "pb_disablepct",
|
|
|
|
DFLT_PATH_BIAS_DISABLE_PCT, 0, 100)/100.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
pathbias_get_scale_threshold(const or_options_t *options)
|
|
|
|
{
|
|
|
|
#define DFLT_PATH_BIAS_SCALE_THRESHOLD 200
|
|
|
|
if (options->PathBiasScaleThreshold >= 2)
|
|
|
|
return options->PathBiasScaleThreshold;
|
|
|
|
else
|
|
|
|
return networkstatus_get_param(NULL, "pb_scalecircs",
|
|
|
|
DFLT_PATH_BIAS_SCALE_THRESHOLD, 10,
|
|
|
|
INT32_MAX);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
pathbias_get_scale_factor(const or_options_t *options)
|
|
|
|
{
|
2012-08-24 05:27:41 +02:00
|
|
|
#define DFLT_PATH_BIAS_SCALE_FACTOR 2
|
2012-05-04 05:15:34 +02:00
|
|
|
if (options->PathBiasScaleFactor >= 1)
|
|
|
|
return options->PathBiasScaleFactor;
|
|
|
|
else
|
|
|
|
return networkstatus_get_param(NULL, "pb_scalefactor",
|
2012-08-24 05:27:41 +02:00
|
|
|
DFLT_PATH_BIAS_SCALE_FACTOR, 1, INT32_MAX);
|
2012-05-04 05:15:34 +02:00
|
|
|
}
|
|
|
|
|
2012-08-17 18:10:31 +02:00
|
|
|
static const char *
|
2012-08-17 01:29:19 +02:00
|
|
|
pathbias_state_to_string(path_state_t state)
|
|
|
|
{
|
2012-08-17 18:10:31 +02:00
|
|
|
switch (state) {
|
2012-08-17 01:29:19 +02:00
|
|
|
case PATH_STATE_NEW_CIRC:
|
2012-08-17 18:10:31 +02:00
|
|
|
return "new";
|
2012-08-17 01:29:19 +02:00
|
|
|
case PATH_STATE_DID_FIRST_HOP:
|
2012-08-17 18:10:31 +02:00
|
|
|
return "first hop";
|
2012-08-17 01:29:19 +02:00
|
|
|
case PATH_STATE_SUCCEEDED:
|
|
|
|
return "succeeded";
|
|
|
|
}
|
|
|
|
|
|
|
|
return "unknown";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check our circuit state to see if this is a successful first hop.
|
|
|
|
* If so, record it in the current guard's path bias first_hop count.
|
|
|
|
*
|
|
|
|
* Also check for several potential error cases for bug #6475.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
pathbias_count_first_hop(origin_circuit_t *circ)
|
|
|
|
{
|
|
|
|
#define FIRST_HOP_NOTICE_INTERVAL (600)
|
2012-08-17 18:10:31 +02:00
|
|
|
static ratelim_t first_hop_notice_limit =
|
|
|
|
RATELIM_INIT(FIRST_HOP_NOTICE_INTERVAL);
|
2012-08-17 01:29:19 +02:00
|
|
|
char *rate_msg = NULL;
|
|
|
|
|
2012-08-21 04:03:00 +02:00
|
|
|
/* We can't do path bias accounting without entry guards.
|
|
|
|
* Testing and controller circuits also have no guards. */
|
|
|
|
if (get_options()->UseEntryGuards == 0 ||
|
|
|
|
circ->_base.purpose == CIRCUIT_PURPOSE_TESTING ||
|
|
|
|
circ->_base.purpose == CIRCUIT_PURPOSE_CONTROLLER) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-08-17 01:29:19 +02:00
|
|
|
/* Completely ignore one hop circuits */
|
2012-09-18 22:16:17 +02:00
|
|
|
if (circ->build_state->onehop_tunnel ||
|
|
|
|
circ->build_state->desired_path_len == 1) {
|
2012-09-18 03:25:28 +02:00
|
|
|
/* Check for inconsistency */
|
2012-09-18 22:16:17 +02:00
|
|
|
if (circ->build_state->desired_path_len != 1 ||
|
|
|
|
!circ->build_state->onehop_tunnel) {
|
2012-09-18 03:25:28 +02:00
|
|
|
if ((rate_msg = rate_limit_log(&first_hop_notice_limit,
|
|
|
|
approx_time()))) {
|
2012-09-18 22:21:24 +02:00
|
|
|
log_notice(LD_BUG,
|
2012-09-18 03:25:28 +02:00
|
|
|
"One-hop circuit has length %d. Path state is %s. "
|
|
|
|
"Circuit is a %s currently %s. %s",
|
|
|
|
circ->build_state->desired_path_len,
|
|
|
|
pathbias_state_to_string(circ->path_state),
|
|
|
|
circuit_purpose_to_string(circ->_base.purpose),
|
|
|
|
circuit_state_to_string(circ->_base.state),
|
|
|
|
rate_msg);
|
|
|
|
}
|
|
|
|
tor_fragile_assert();
|
|
|
|
}
|
2012-08-17 01:29:19 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (circ->cpath->state == CPATH_STATE_AWAITING_KEYS) {
|
|
|
|
/* Help track down the real cause of bug #6475: */
|
|
|
|
if (circ->has_opened && circ->path_state != PATH_STATE_DID_FIRST_HOP) {
|
|
|
|
if ((rate_msg = rate_limit_log(&first_hop_notice_limit,
|
|
|
|
approx_time()))) {
|
2012-08-22 03:37:08 +02:00
|
|
|
log_info(LD_BUG,
|
2012-08-17 01:29:19 +02:00
|
|
|
"Opened circuit is in strange path state %s. "
|
|
|
|
"Circuit is a %s currently %s. %s",
|
|
|
|
pathbias_state_to_string(circ->path_state),
|
|
|
|
circuit_purpose_to_string(circ->_base.purpose),
|
|
|
|
circuit_state_to_string(circ->_base.state),
|
|
|
|
rate_msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Don't count cannibalized circs for path bias */
|
|
|
|
if (!circ->has_opened) {
|
|
|
|
entry_guard_t *guard;
|
|
|
|
|
|
|
|
guard = entry_guard_get_by_id_digest(
|
|
|
|
circ->_base.n_conn->identity_digest);
|
|
|
|
if (guard) {
|
|
|
|
if (circ->path_state == PATH_STATE_NEW_CIRC) {
|
|
|
|
circ->path_state = PATH_STATE_DID_FIRST_HOP;
|
|
|
|
|
|
|
|
if (entry_guard_inc_first_hop_count(guard) < 0) {
|
|
|
|
/* Bogus guard; we already warned. */
|
|
|
|
return -END_CIRC_REASON_TORPROTOCOL;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ((rate_msg = rate_limit_log(&first_hop_notice_limit,
|
|
|
|
approx_time()))) {
|
2012-08-22 03:37:08 +02:00
|
|
|
log_info(LD_BUG,
|
2012-08-17 01:29:19 +02:00
|
|
|
"Unopened circuit has strange path state %s. "
|
|
|
|
"Circuit is a %s currently %s. %s",
|
|
|
|
pathbias_state_to_string(circ->path_state),
|
|
|
|
circuit_purpose_to_string(circ->_base.purpose),
|
|
|
|
circuit_state_to_string(circ->_base.state),
|
|
|
|
rate_msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ((rate_msg = rate_limit_log(&first_hop_notice_limit,
|
|
|
|
approx_time()))) {
|
2012-08-22 03:37:08 +02:00
|
|
|
log_info(LD_BUG,
|
2012-08-17 01:29:19 +02:00
|
|
|
"Unopened circuit has no known guard. "
|
|
|
|
"Circuit is a %s currently %s. %s",
|
|
|
|
circuit_purpose_to_string(circ->_base.purpose),
|
|
|
|
circuit_state_to_string(circ->_base.state),
|
|
|
|
rate_msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Help track down the real cause of bug #6475: */
|
|
|
|
if (circ->path_state == PATH_STATE_NEW_CIRC) {
|
|
|
|
if ((rate_msg = rate_limit_log(&first_hop_notice_limit,
|
|
|
|
approx_time()))) {
|
2012-08-22 03:37:08 +02:00
|
|
|
log_info(LD_BUG,
|
2012-08-17 01:29:19 +02:00
|
|
|
"A %s circuit is in cpath state %d (opened: %d). "
|
|
|
|
"Circuit is a %s currently %s. %s",
|
|
|
|
pathbias_state_to_string(circ->path_state),
|
2012-08-17 18:10:31 +02:00
|
|
|
circ->cpath->state, circ->has_opened,
|
2012-08-17 01:29:19 +02:00
|
|
|
circuit_purpose_to_string(circ->_base.purpose),
|
|
|
|
circuit_state_to_string(circ->_base.state),
|
|
|
|
rate_msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check our circuit state to see if this is a successful circuit
|
|
|
|
* completion. If so, record it in the current guard's path bias
|
|
|
|
* success count.
|
|
|
|
*
|
|
|
|
* Also check for several potential error cases for bug #6475.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
pathbias_count_success(origin_circuit_t *circ)
|
|
|
|
{
|
|
|
|
#define SUCCESS_NOTICE_INTERVAL (600)
|
2012-08-17 18:10:31 +02:00
|
|
|
static ratelim_t success_notice_limit =
|
|
|
|
RATELIM_INIT(SUCCESS_NOTICE_INTERVAL);
|
2012-08-17 01:29:19 +02:00
|
|
|
char *rate_msg = NULL;
|
|
|
|
|
2012-08-21 04:03:00 +02:00
|
|
|
/* We can't do path bias accounting without entry guards.
|
|
|
|
* Testing and controller circuits also have no guards. */
|
|
|
|
if (get_options()->UseEntryGuards == 0 ||
|
|
|
|
circ->_base.purpose == CIRCUIT_PURPOSE_TESTING ||
|
|
|
|
circ->_base.purpose == CIRCUIT_PURPOSE_CONTROLLER) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-08-17 01:29:19 +02:00
|
|
|
/* Ignore one hop circuits */
|
2012-09-18 22:16:17 +02:00
|
|
|
if (circ->build_state->onehop_tunnel ||
|
|
|
|
circ->build_state->desired_path_len == 1) {
|
2012-09-18 03:25:28 +02:00
|
|
|
/* Check for consistency */
|
2012-09-18 22:16:17 +02:00
|
|
|
if (circ->build_state->desired_path_len != 1 ||
|
|
|
|
!circ->build_state->onehop_tunnel) {
|
2012-09-18 03:25:28 +02:00
|
|
|
if ((rate_msg = rate_limit_log(&success_notice_limit,
|
|
|
|
approx_time()))) {
|
2012-09-18 22:21:24 +02:00
|
|
|
log_notice(LD_BUG,
|
2012-09-18 03:25:28 +02:00
|
|
|
"One-hop circuit has length %d. Path state is %s. "
|
|
|
|
"Circuit is a %s currently %s. %s",
|
|
|
|
circ->build_state->desired_path_len,
|
|
|
|
pathbias_state_to_string(circ->path_state),
|
|
|
|
circuit_purpose_to_string(circ->_base.purpose),
|
|
|
|
circuit_state_to_string(circ->_base.state),
|
|
|
|
rate_msg);
|
|
|
|
}
|
|
|
|
tor_fragile_assert();
|
|
|
|
}
|
2012-08-17 01:29:19 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Don't count cannibalized/reused circs for path bias */
|
|
|
|
if (!circ->has_opened) {
|
|
|
|
entry_guard_t *guard =
|
|
|
|
entry_guard_get_by_id_digest(circ->_base.n_conn->identity_digest);
|
|
|
|
|
|
|
|
if (guard) {
|
|
|
|
if (circ->path_state == PATH_STATE_DID_FIRST_HOP) {
|
|
|
|
circ->path_state = PATH_STATE_SUCCEEDED;
|
|
|
|
guard->circuit_successes++;
|
|
|
|
|
|
|
|
log_info(LD_PROTOCOL, "Got success count %u/%u for guard %s=%s",
|
|
|
|
guard->circuit_successes, guard->first_hops,
|
|
|
|
guard->nickname, hex_str(guard->identity, DIGEST_LEN));
|
|
|
|
} else {
|
|
|
|
if ((rate_msg = rate_limit_log(&success_notice_limit,
|
|
|
|
approx_time()))) {
|
2012-08-22 03:37:08 +02:00
|
|
|
log_info(LD_BUG,
|
2012-08-17 01:29:19 +02:00
|
|
|
"Succeeded circuit is in strange path state %s. "
|
|
|
|
"Circuit is a %s currently %s. %s",
|
|
|
|
pathbias_state_to_string(circ->path_state),
|
|
|
|
circuit_purpose_to_string(circ->_base.purpose),
|
|
|
|
circuit_state_to_string(circ->_base.state),
|
|
|
|
rate_msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (guard->first_hops < guard->circuit_successes) {
|
2012-08-22 03:37:08 +02:00
|
|
|
log_notice(LD_BUG, "Unexpectedly high circuit_successes (%u/%u) "
|
2012-08-17 01:29:19 +02:00
|
|
|
"for guard %s=%s",
|
|
|
|
guard->circuit_successes, guard->first_hops,
|
|
|
|
guard->nickname, hex_str(guard->identity, DIGEST_LEN));
|
|
|
|
}
|
2012-08-21 04:03:00 +02:00
|
|
|
/* In rare cases, CIRCUIT_PURPOSE_TESTING can get converted to
|
|
|
|
* CIRCUIT_PURPOSE_C_MEASURE_TIMEOUT and have no guards here.
|
|
|
|
* No need to log that case. */
|
|
|
|
} else if (circ->_base.purpose != CIRCUIT_PURPOSE_C_MEASURE_TIMEOUT) {
|
2012-08-17 01:29:19 +02:00
|
|
|
if ((rate_msg = rate_limit_log(&success_notice_limit,
|
|
|
|
approx_time()))) {
|
2012-08-22 03:37:08 +02:00
|
|
|
log_info(LD_BUG,
|
2012-08-17 01:29:19 +02:00
|
|
|
"Completed circuit has no known guard. "
|
|
|
|
"Circuit is a %s currently %s. %s",
|
|
|
|
circuit_purpose_to_string(circ->_base.purpose),
|
|
|
|
circuit_state_to_string(circ->_base.state),
|
|
|
|
rate_msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (circ->path_state != PATH_STATE_SUCCEEDED) {
|
|
|
|
if ((rate_msg = rate_limit_log(&success_notice_limit,
|
|
|
|
approx_time()))) {
|
2012-08-22 03:37:08 +02:00
|
|
|
log_info(LD_BUG,
|
2012-08-17 01:29:19 +02:00
|
|
|
"Opened circuit is in strange path state %s. "
|
|
|
|
"Circuit is a %s currently %s. %s",
|
|
|
|
pathbias_state_to_string(circ->path_state),
|
|
|
|
circuit_purpose_to_string(circ->_base.purpose),
|
|
|
|
circuit_state_to_string(circ->_base.state),
|
|
|
|
rate_msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-04 05:15:34 +02:00
|
|
|
/** Increment the number of times we successfully extended a circuit to
|
|
|
|
* 'guard', first checking if the failure rate is high enough that we should
|
|
|
|
* eliminate the guard. Return -1 if the guard looks no good; return 0 if the
|
|
|
|
* guard looks fine. */
|
|
|
|
static int
|
|
|
|
entry_guard_inc_first_hop_count(entry_guard_t *guard)
|
|
|
|
{
|
|
|
|
const or_options_t *options = get_options();
|
|
|
|
|
|
|
|
entry_guards_changed();
|
|
|
|
|
|
|
|
if (guard->first_hops > (unsigned)pathbias_get_min_circs(options)) {
|
|
|
|
/* Note: We rely on the < comparison here to allow us to set a 0
|
|
|
|
* rate and disable the feature entirely. If refactoring, don't
|
|
|
|
* change to <= */
|
|
|
|
if (guard->circuit_successes/((double)guard->first_hops)
|
|
|
|
< pathbias_get_disable_rate(options)) {
|
|
|
|
|
2012-08-22 03:37:08 +02:00
|
|
|
/* This message is currently disabled by default. */
|
2012-05-04 05:15:34 +02:00
|
|
|
log_warn(LD_PROTOCOL,
|
|
|
|
"Extremely low circuit success rate %u/%u for guard %s=%s. "
|
2012-08-22 03:37:08 +02:00
|
|
|
"This indicates either an overloaded guard, an attack, or "
|
|
|
|
"a bug.",
|
2012-05-04 05:15:34 +02:00
|
|
|
guard->circuit_successes, guard->first_hops, guard->nickname,
|
|
|
|
hex_str(guard->identity, DIGEST_LEN));
|
|
|
|
|
|
|
|
guard->path_bias_disabled = 1;
|
|
|
|
guard->bad_since = approx_time();
|
|
|
|
return -1;
|
|
|
|
} else if (guard->circuit_successes/((double)guard->first_hops)
|
|
|
|
< pathbias_get_notice_rate(options)
|
|
|
|
&& !guard->path_bias_notice) {
|
|
|
|
guard->path_bias_notice = 1;
|
|
|
|
log_notice(LD_PROTOCOL,
|
|
|
|
"Low circuit success rate %u/%u for guard %s=%s.",
|
|
|
|
guard->circuit_successes, guard->first_hops, guard->nickname,
|
|
|
|
hex_str(guard->identity, DIGEST_LEN));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If we get a ton of circuits, just scale everything down */
|
|
|
|
if (guard->first_hops > (unsigned)pathbias_get_scale_threshold(options)) {
|
|
|
|
const int scale_factor = pathbias_get_scale_factor(options);
|
2012-08-24 05:27:41 +02:00
|
|
|
/* For now, only scale if there will be no rounding error...
|
|
|
|
* XXX024: We want to switch to a real moving average for 0.2.4. */
|
|
|
|
if ((guard->first_hops % scale_factor) == 0 &&
|
|
|
|
(guard->circuit_successes % scale_factor) == 0) {
|
|
|
|
log_info(LD_PROTOCOL,
|
|
|
|
"Scaling pathbias counts to (%u/%u)/%d for guard %s=%s",
|
|
|
|
guard->circuit_successes, guard->first_hops,
|
|
|
|
scale_factor, guard->nickname, hex_str(guard->identity,
|
|
|
|
DIGEST_LEN));
|
|
|
|
guard->first_hops /= scale_factor;
|
|
|
|
guard->circuit_successes /= scale_factor;
|
|
|
|
}
|
2012-05-04 05:15:34 +02:00
|
|
|
}
|
|
|
|
guard->first_hops++;
|
2012-08-16 04:59:55 +02:00
|
|
|
log_info(LD_PROTOCOL, "Got success count %u/%u for guard %s=%s",
|
|
|
|
guard->circuit_successes, guard->first_hops, guard->nickname,
|
|
|
|
hex_str(guard->identity, DIGEST_LEN));
|
2012-05-04 05:15:34 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-12-08 18:38:32 +01:00
|
|
|
/** A created or extended cell came back to us on the circuit, and it included
|
|
|
|
* <b>reply</b> as its body. (If <b>reply_type</b> is CELL_CREATED, the body
|
|
|
|
* contains (the second DH key, plus KH). If <b>reply_type</b> is
|
|
|
|
* CELL_CREATED_FAST, the body contains a secret y and a hash H(x|y).)
|
2004-05-13 09:24:49 +02:00
|
|
|
*
|
|
|
|
* Calculate the appropriate keys and digests, make sure KH is
|
|
|
|
* correct, and initialize this hop of the cpath.
|
|
|
|
*
|
2006-01-05 22:23:03 +01:00
|
|
|
* Return - reason if we want to mark circ for close, else return 0.
|
2004-05-13 09:24:49 +02:00
|
|
|
*/
|
2005-06-11 20:52:12 +02:00
|
|
|
int
|
2006-07-23 09:37:35 +02:00
|
|
|
circuit_finish_handshake(origin_circuit_t *circ, uint8_t reply_type,
|
2010-12-14 01:34:01 +01:00
|
|
|
const uint8_t *reply)
|
2005-06-11 20:52:12 +02:00
|
|
|
{
|
2005-05-07 07:55:06 +02:00
|
|
|
char keys[CPATH_KEY_MATERIAL_LEN];
|
2004-05-13 09:24:49 +02:00
|
|
|
crypt_path_t *hop;
|
2012-08-17 01:29:19 +02:00
|
|
|
int rv;
|
|
|
|
|
2012-08-17 18:10:31 +02:00
|
|
|
if ((rv = pathbias_count_first_hop(circ)) < 0)
|
2012-08-17 01:29:19 +02:00
|
|
|
return rv;
|
2004-05-13 09:24:49 +02:00
|
|
|
|
2012-05-04 05:15:34 +02:00
|
|
|
if (circ->cpath->state == CPATH_STATE_AWAITING_KEYS) {
|
2004-05-13 09:24:49 +02:00
|
|
|
hop = circ->cpath;
|
2012-05-04 05:15:34 +02:00
|
|
|
} else {
|
2005-03-22 01:42:38 +01:00
|
|
|
hop = onion_next_hop_in_cpath(circ->cpath);
|
|
|
|
if (!hop) { /* got an extended when we're all done? */
|
2006-02-13 09:28:42 +01:00
|
|
|
log_warn(LD_PROTOCOL,"got extended when circ already built? Closing.");
|
2006-01-05 22:23:03 +01:00
|
|
|
return - END_CIRC_REASON_TORPROTOCOL;
|
2004-05-13 09:24:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
tor_assert(hop->state == CPATH_STATE_AWAITING_KEYS);
|
|
|
|
|
2005-05-03 00:35:18 +02:00
|
|
|
if (reply_type == CELL_CREATED && hop->dh_handshake_state) {
|
2011-01-03 17:57:42 +01:00
|
|
|
if (onion_skin_client_handshake(hop->dh_handshake_state, (char*)reply,keys,
|
2005-05-03 00:35:18 +02:00
|
|
|
DIGEST_LEN*2+CIPHER_KEY_LEN*2) < 0) {
|
2006-02-13 09:28:42 +01:00
|
|
|
log_warn(LD_CIRC,"onion_skin_client_handshake failed.");
|
2006-01-05 22:23:03 +01:00
|
|
|
return -END_CIRC_REASON_TORPROTOCOL;
|
2005-05-03 00:35:18 +02:00
|
|
|
}
|
|
|
|
/* Remember hash of g^xy */
|
|
|
|
memcpy(hop->handshake_digest, reply+DH_KEY_LEN, DIGEST_LEN);
|
|
|
|
} else if (reply_type == CELL_CREATED_FAST && !hop->dh_handshake_state) {
|
2010-12-14 01:34:01 +01:00
|
|
|
if (fast_client_handshake(hop->fast_handshake_state, reply,
|
|
|
|
(uint8_t*)keys,
|
2005-05-03 00:35:18 +02:00
|
|
|
DIGEST_LEN*2+CIPHER_KEY_LEN*2) < 0) {
|
2006-02-13 09:28:42 +01:00
|
|
|
log_warn(LD_CIRC,"fast_client_handshake failed.");
|
2006-01-05 22:23:03 +01:00
|
|
|
return -END_CIRC_REASON_TORPROTOCOL;
|
2005-05-03 00:35:18 +02:00
|
|
|
}
|
|
|
|
memcpy(hop->handshake_digest, reply+DIGEST_LEN, DIGEST_LEN);
|
|
|
|
} else {
|
2006-02-13 09:28:42 +01:00
|
|
|
log_warn(LD_PROTOCOL,"CREATED cell type did not match CREATE cell type.");
|
2006-01-05 22:23:03 +01:00
|
|
|
return -END_CIRC_REASON_TORPROTOCOL;
|
2004-05-13 09:24:49 +02:00
|
|
|
}
|
|
|
|
|
2009-12-12 08:07:59 +01:00
|
|
|
crypto_dh_free(hop->dh_handshake_state); /* don't need it anymore */
|
|
|
|
hop->dh_handshake_state = NULL;
|
|
|
|
|
2005-05-03 00:35:18 +02:00
|
|
|
memset(hop->fast_handshake_state, 0, sizeof(hop->fast_handshake_state));
|
2004-05-13 09:24:49 +02:00
|
|
|
|
|
|
|
if (circuit_init_cpath_crypto(hop, keys, 0)<0) {
|
2006-01-05 22:23:03 +01:00
|
|
|
return -END_CIRC_REASON_TORPROTOCOL;
|
2004-05-13 09:24:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
hop->state = CPATH_STATE_OPEN;
|
2006-02-13 09:28:42 +01:00
|
|
|
log_info(LD_CIRC,"Finished building %scircuit hop:",
|
|
|
|
(reply_type == CELL_CREATED_FAST) ? "fast " : "");
|
2005-10-24 21:37:45 +02:00
|
|
|
circuit_log_path(LOG_INFO,LD_CIRC,circ);
|
2006-10-09 17:47:27 +02:00
|
|
|
control_event_circuit_status(circ, CIRC_EVENT_EXTENDED, 0);
|
2004-11-03 19:33:07 +01:00
|
|
|
|
2004-05-13 09:24:49 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** We received a relay truncated cell on circ.
|
|
|
|
*
|
|
|
|
* Since we don't ask for truncates currently, getting a truncated
|
|
|
|
* means that a connection broke or an extend failed. For now,
|
|
|
|
* just give up: for circ to close, and return 0.
|
|
|
|
*/
|
2005-06-11 20:52:12 +02:00
|
|
|
int
|
2006-07-23 09:37:35 +02:00
|
|
|
circuit_truncated(origin_circuit_t *circ, crypt_path_t *layer)
|
2005-06-11 20:52:12 +02:00
|
|
|
{
|
2004-10-11 03:17:42 +02:00
|
|
|
// crypt_path_t *victim;
|
|
|
|
// connection_t *stream;
|
2004-05-13 09:24:49 +02:00
|
|
|
|
2004-10-17 00:14:52 +02:00
|
|
|
tor_assert(circ);
|
2004-05-13 09:24:49 +02:00
|
|
|
tor_assert(layer);
|
|
|
|
|
|
|
|
/* XXX Since we don't ask for truncates currently, getting a truncated
|
|
|
|
* means that a connection broke or an extend failed. For now,
|
|
|
|
* just give up.
|
|
|
|
*/
|
2007-01-15 22:21:05 +01:00
|
|
|
circuit_mark_for_close(TO_CIRCUIT(circ),
|
2007-01-15 22:13:37 +01:00
|
|
|
END_CIRC_REASON_FLAG_REMOTE|END_CIRC_REASON_OR_CONN_CLOSED);
|
2004-05-13 09:24:49 +02:00
|
|
|
return 0;
|
|
|
|
|
2004-10-11 03:17:42 +02:00
|
|
|
#if 0
|
2004-11-28 10:05:49 +01:00
|
|
|
while (layer->next != circ->cpath) {
|
2004-05-13 09:24:49 +02:00
|
|
|
/* we need to clear out layer->next */
|
|
|
|
victim = layer->next;
|
2006-02-13 09:28:42 +01:00
|
|
|
log_debug(LD_CIRC, "Killing a layer of the cpath.");
|
2004-05-13 09:24:49 +02:00
|
|
|
|
2004-11-28 10:05:49 +01:00
|
|
|
for (stream = circ->p_streams; stream; stream=stream->next_stream) {
|
|
|
|
if (stream->cpath_layer == victim) {
|
2006-10-03 00:13:42 +02:00
|
|
|
log_info(LD_APP, "Marking stream %d for close because of truncate.",
|
|
|
|
stream->stream_id);
|
2004-05-13 09:24:49 +02:00
|
|
|
/* no need to send 'end' relay cells,
|
|
|
|
* because the other side's already dead
|
|
|
|
*/
|
2005-04-03 00:11:24 +02:00
|
|
|
connection_mark_unattached_ap(stream, END_STREAM_REASON_DESTROY);
|
2004-05-13 09:24:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
layer->next = victim->next;
|
|
|
|
circuit_free_cpath_node(victim);
|
|
|
|
}
|
|
|
|
|
2006-02-13 09:28:42 +01:00
|
|
|
log_info(LD_CIRC, "finished");
|
2004-05-13 09:24:49 +02:00
|
|
|
return 0;
|
2004-10-11 03:17:42 +02:00
|
|
|
#endif
|
2004-05-13 09:24:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Given a response payload and keys, initialize, then send a created
|
|
|
|
* cell back.
|
|
|
|
*/
|
2005-06-11 20:52:12 +02:00
|
|
|
int
|
2007-01-30 23:19:41 +01:00
|
|
|
onionskin_answer(or_circuit_t *circ, uint8_t cell_type, const char *payload,
|
|
|
|
const char *keys)
|
2005-06-11 20:52:12 +02:00
|
|
|
{
|
2004-05-13 09:24:49 +02:00
|
|
|
cell_t cell;
|
|
|
|
crypt_path_t *tmp_cpath;
|
|
|
|
|
|
|
|
tmp_cpath = tor_malloc_zero(sizeof(crypt_path_t));
|
2005-03-23 07:21:48 +01:00
|
|
|
tmp_cpath->magic = CRYPT_PATH_MAGIC;
|
2004-05-13 09:24:49 +02:00
|
|
|
|
|
|
|
memset(&cell, 0, sizeof(cell_t));
|
2005-05-03 00:35:18 +02:00
|
|
|
cell.command = cell_type;
|
2004-05-13 09:24:49 +02:00
|
|
|
cell.circ_id = circ->p_circ_id;
|
|
|
|
|
2006-07-23 09:37:35 +02:00
|
|
|
circuit_set_state(TO_CIRCUIT(circ), CIRCUIT_STATE_OPEN);
|
2004-05-13 09:24:49 +02:00
|
|
|
|
2005-05-03 00:35:18 +02:00
|
|
|
memcpy(cell.payload, payload,
|
|
|
|
cell_type == CELL_CREATED ? ONIONSKIN_REPLY_LEN : DIGEST_LEN*2);
|
2004-05-13 09:24:49 +02:00
|
|
|
|
2006-02-13 09:28:42 +01:00
|
|
|
log_debug(LD_CIRC,"init digest forward 0x%.8x, backward 0x%.8x.",
|
2010-09-21 00:40:32 +02:00
|
|
|
(unsigned int)get_uint32(keys),
|
|
|
|
(unsigned int)get_uint32(keys+20));
|
2004-05-13 09:24:49 +02:00
|
|
|
if (circuit_init_cpath_crypto(tmp_cpath, keys, 0)<0) {
|
2006-02-13 09:28:42 +01:00
|
|
|
log_warn(LD_BUG,"Circuit initialization failed");
|
2004-05-13 09:24:49 +02:00
|
|
|
tor_free(tmp_cpath);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
circ->n_digest = tmp_cpath->f_digest;
|
|
|
|
circ->n_crypto = tmp_cpath->f_crypto;
|
|
|
|
circ->p_digest = tmp_cpath->b_digest;
|
|
|
|
circ->p_crypto = tmp_cpath->b_crypto;
|
2005-03-23 07:21:48 +01:00
|
|
|
tmp_cpath->magic = 0;
|
2004-05-13 09:24:49 +02:00
|
|
|
tor_free(tmp_cpath);
|
|
|
|
|
2005-05-03 00:35:18 +02:00
|
|
|
if (cell_type == CELL_CREATED)
|
|
|
|
memcpy(circ->handshake_digest, cell.payload+DH_KEY_LEN, DIGEST_LEN);
|
|
|
|
else
|
|
|
|
memcpy(circ->handshake_digest, cell.payload+DIGEST_LEN, DIGEST_LEN);
|
2004-05-13 09:24:49 +02:00
|
|
|
|
2006-10-01 22:50:11 +02:00
|
|
|
circ->is_first_hop = (cell_type == CELL_CREATED_FAST);
|
|
|
|
|
2007-03-26 16:07:59 +02:00
|
|
|
append_cell_to_circuit_queue(TO_CIRCUIT(circ),
|
2010-09-02 21:26:17 +02:00
|
|
|
circ->p_conn, &cell, CELL_DIRECTION_IN, 0);
|
2011-12-08 00:12:11 +01:00
|
|
|
log_debug(LD_CIRC,"Finished sending '%s' cell.",
|
|
|
|
circ->is_first_hop ? "created_fast" : "created");
|
2004-05-13 09:24:49 +02:00
|
|
|
|
2008-08-05 22:08:19 +02:00
|
|
|
if (!is_local_addr(&circ->p_conn->_base.addr) &&
|
2006-06-07 09:11:42 +02:00
|
|
|
!connection_or_nonopen_was_started_here(circ->p_conn)) {
|
2005-03-31 09:46:59 +02:00
|
|
|
/* record that we could process create cells from a non-local conn
|
|
|
|
* that we didn't initiate; presumably this means that create cells
|
|
|
|
* can reach us too. */
|
2005-03-15 02:44:46 +01:00
|
|
|
router_orport_found_reachable();
|
|
|
|
}
|
|
|
|
|
2004-05-13 09:24:49 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Choose a length for a circuit of purpose <b>purpose</b>.
|
|
|
|
* Default length is 3 + the number of endpoints that would give something
|
|
|
|
* away. If the routerlist <b>routers</b> doesn't have enough routers
|
|
|
|
* to handle the desired path length, return as large a path length as
|
|
|
|
* is feasible, except if it's less than 2, in which case return -1.
|
|
|
|
*/
|
2005-06-11 20:52:12 +02:00
|
|
|
static int
|
2007-02-08 23:07:56 +01:00
|
|
|
new_route_len(uint8_t purpose, extend_info_t *exit,
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
smartlist_t *nodes)
|
2005-06-11 20:52:12 +02:00
|
|
|
{
|
2004-05-13 09:24:49 +02:00
|
|
|
int num_acceptable_routers;
|
|
|
|
int routelen;
|
|
|
|
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
tor_assert(nodes);
|
2004-05-13 09:24:49 +02:00
|
|
|
|
2010-07-20 14:07:44 +02:00
|
|
|
routelen = DEFAULT_ROUTE_LEN;
|
2005-09-10 03:01:40 +02:00
|
|
|
if (exit &&
|
|
|
|
purpose != CIRCUIT_PURPOSE_TESTING &&
|
|
|
|
purpose != CIRCUIT_PURPOSE_S_ESTABLISH_INTRO)
|
|
|
|
routelen++;
|
2008-02-19 20:30:37 +01:00
|
|
|
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
num_acceptable_routers = count_acceptable_nodes(nodes);
|
2004-05-13 09:24:49 +02:00
|
|
|
|
2008-06-08 04:53:32 +02:00
|
|
|
log_debug(LD_CIRC,"Chosen route length %d (%d/%d routers suitable).",
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
routelen, num_acceptable_routers, smartlist_len(nodes));
|
2008-06-07 00:31:36 +02:00
|
|
|
|
2004-11-28 10:05:49 +01:00
|
|
|
if (num_acceptable_routers < 2) {
|
2006-02-13 09:28:42 +01:00
|
|
|
log_info(LD_CIRC,
|
|
|
|
"Not enough acceptable routers (%d). Discarding this circuit.",
|
|
|
|
num_acceptable_routers);
|
2004-05-13 09:24:49 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2004-11-28 10:05:49 +01:00
|
|
|
if (num_acceptable_routers < routelen) {
|
2006-02-13 09:28:42 +01:00
|
|
|
log_info(LD_CIRC,"Not enough routers: cutting routelen from %d to %d.",
|
|
|
|
routelen, num_acceptable_routers);
|
2004-05-13 09:24:49 +02:00
|
|
|
routelen = num_acceptable_routers;
|
|
|
|
}
|
|
|
|
|
|
|
|
return routelen;
|
|
|
|
}
|
|
|
|
|
2010-10-15 20:02:55 +02:00
|
|
|
/** Return a newly allocated list of uint16_t * for each predicted port not
|
|
|
|
* handled by a current circuit. */
|
2004-12-05 08:10:08 +01:00
|
|
|
static smartlist_t *
|
2005-06-11 20:52:12 +02:00
|
|
|
circuit_get_unhandled_ports(time_t now)
|
|
|
|
{
|
2010-10-15 20:02:55 +02:00
|
|
|
smartlist_t *dest = rep_hist_get_predicted_ports(now);
|
2004-12-07 16:29:54 +01:00
|
|
|
circuit_remove_handled_ports(dest);
|
|
|
|
return dest;
|
2004-12-05 08:10:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Return 1 if we already have circuits present or on the way for
|
|
|
|
* all anticipated ports. Return 0 if we should make more.
|
2005-01-12 05:58:23 +01:00
|
|
|
*
|
|
|
|
* If we're returning 0, set need_uptime and need_capacity to
|
|
|
|
* indicate any requirements that the unhandled ports have.
|
2004-12-05 08:10:08 +01:00
|
|
|
*/
|
|
|
|
int
|
2005-01-12 05:58:23 +01:00
|
|
|
circuit_all_predicted_ports_handled(time_t now, int *need_uptime,
|
2005-06-11 20:52:12 +02:00
|
|
|
int *need_capacity)
|
|
|
|
{
|
2005-01-12 05:58:23 +01:00
|
|
|
int i, enough;
|
|
|
|
uint16_t *port;
|
2004-12-05 08:10:08 +01:00
|
|
|
smartlist_t *sl = circuit_get_unhandled_ports(now);
|
2005-01-12 05:58:23 +01:00
|
|
|
smartlist_t *LongLivedServices = get_options()->LongLivedPorts;
|
2005-09-30 00:59:17 +02:00
|
|
|
tor_assert(need_uptime);
|
|
|
|
tor_assert(need_capacity);
|
2010-02-14 23:45:45 +01:00
|
|
|
// Always predict need_capacity
|
|
|
|
*need_capacity = 1;
|
2004-12-05 08:10:08 +01:00
|
|
|
enough = (smartlist_len(sl) == 0);
|
2005-01-12 05:58:23 +01:00
|
|
|
for (i = 0; i < smartlist_len(sl); ++i) {
|
|
|
|
port = smartlist_get(sl, i);
|
|
|
|
if (smartlist_string_num_isin(LongLivedServices, *port))
|
|
|
|
*need_uptime = 1;
|
|
|
|
tor_free(port);
|
|
|
|
}
|
2004-12-05 08:10:08 +01:00
|
|
|
smartlist_free(sl);
|
|
|
|
return enough;
|
|
|
|
}
|
|
|
|
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
/** Return 1 if <b>node</b> can handle one or more of the ports in
|
2004-12-05 08:10:08 +01:00
|
|
|
* <b>needed_ports</b>, else return 0.
|
|
|
|
*/
|
|
|
|
static int
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
node_handles_some_port(const node_t *node, smartlist_t *needed_ports)
|
|
|
|
{ /* XXXX MOVE */
|
2004-12-05 08:10:08 +01:00
|
|
|
int i;
|
|
|
|
uint16_t port;
|
|
|
|
|
|
|
|
for (i = 0; i < smartlist_len(needed_ports); ++i) {
|
2005-03-19 07:57:16 +01:00
|
|
|
addr_policy_result_t r;
|
2010-09-21 00:40:32 +02:00
|
|
|
/* alignment issues aren't a worry for this dereference, since
|
|
|
|
needed_ports is explicitly a smartlist of uint16_t's */
|
2004-12-05 08:10:08 +01:00
|
|
|
port = *(uint16_t *)smartlist_get(needed_ports, i);
|
|
|
|
tor_assert(port);
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
if (node)
|
2011-07-15 18:58:13 +02:00
|
|
|
r = compare_tor_addr_to_node_policy(NULL, port, node);
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
else
|
|
|
|
continue;
|
2005-03-19 07:57:16 +01:00
|
|
|
if (r != ADDR_POLICY_REJECTED && r != ADDR_POLICY_PROBABLY_REJECTED)
|
2004-12-05 08:10:08 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-02-24 08:50:38 +01:00
|
|
|
/** Return true iff <b>conn</b> needs another general circuit to be
|
2007-02-16 21:39:37 +01:00
|
|
|
* built. */
|
2005-01-19 18:59:37 +01:00
|
|
|
static int
|
2005-06-11 20:52:12 +02:00
|
|
|
ap_stream_wants_exit_attention(connection_t *conn)
|
|
|
|
{
|
2011-07-20 18:55:42 +02:00
|
|
|
entry_connection_t *entry;
|
|
|
|
if (conn->type != CONN_TYPE_AP)
|
|
|
|
return 0;
|
|
|
|
entry = TO_ENTRY_CONN(conn);
|
|
|
|
|
2011-09-07 20:18:32 +02:00
|
|
|
if (conn->state == AP_CONN_STATE_CIRCUIT_WAIT &&
|
2005-01-19 18:59:37 +01:00
|
|
|
!conn->marked_for_close &&
|
2011-07-20 18:55:42 +02:00
|
|
|
!(entry->want_onehop) && /* ignore one-hop streams */
|
|
|
|
!(entry->use_begindir) && /* ignore targeted dir fetches */
|
|
|
|
!(entry->chosen_exit_name) && /* ignore defined streams */
|
2006-07-26 21:07:26 +02:00
|
|
|
!connection_edge_is_rendezvous_stream(TO_EDGE_CONN(conn)) &&
|
2011-07-20 18:55:42 +02:00
|
|
|
!circuit_stream_is_being_handled(TO_ENTRY_CONN(conn), 0,
|
2006-07-26 21:07:26 +02:00
|
|
|
MIN_CIRCUITS_HANDLING_STREAM))
|
2005-01-19 18:59:37 +01:00
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-05-13 09:24:49 +02:00
|
|
|
/** Return a pointer to a suitable router to be the exit node for the
|
|
|
|
* general-purpose circuit we're about to build.
|
|
|
|
*
|
|
|
|
* Look through the connection array, and choose a router that maximizes
|
|
|
|
* the number of pending streams that can exit from this router.
|
|
|
|
*
|
|
|
|
* Return NULL if we can't find any suitable routers.
|
|
|
|
*/
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
static const node_t *
|
|
|
|
choose_good_exit_server_general(int need_uptime, int need_capacity)
|
2004-05-13 09:24:49 +02:00
|
|
|
{
|
|
|
|
int *n_supported;
|
|
|
|
int n_pending_connections = 0;
|
2007-05-22 17:49:14 +02:00
|
|
|
smartlist_t *connections;
|
2004-05-13 09:24:49 +02:00
|
|
|
int best_support = -1;
|
|
|
|
int n_best_support=0;
|
2011-06-14 19:01:38 +02:00
|
|
|
const or_options_t *options = get_options();
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
const smartlist_t *the_nodes;
|
|
|
|
const node_t *node=NULL;
|
2004-05-13 09:24:49 +02:00
|
|
|
|
2007-05-22 17:49:14 +02:00
|
|
|
connections = get_connection_array();
|
2004-05-13 09:24:49 +02:00
|
|
|
|
|
|
|
/* Count how many connections are waiting for a circuit to be built.
|
|
|
|
* We use this for log messages now, but in the future we may depend on it.
|
|
|
|
*/
|
2007-05-22 17:49:14 +02:00
|
|
|
SMARTLIST_FOREACH(connections, connection_t *, conn,
|
|
|
|
{
|
|
|
|
if (ap_stream_wants_exit_attention(conn))
|
2004-05-13 09:24:49 +02:00
|
|
|
++n_pending_connections;
|
2007-05-22 17:49:14 +02:00
|
|
|
});
|
2004-12-04 01:25:54 +01:00
|
|
|
// log_fn(LOG_DEBUG, "Choosing exit node; %d connections are pending",
|
|
|
|
// n_pending_connections);
|
2004-05-13 09:24:49 +02:00
|
|
|
/* Now we count, for each of the routers in the directory, how many
|
|
|
|
* of the pending connections could possibly exit from that
|
|
|
|
* router (n_supported[i]). (We can't be sure about cases where we
|
|
|
|
* don't know the IP address of the pending connection.)
|
2008-09-26 21:09:12 +02:00
|
|
|
*
|
|
|
|
* -1 means "Don't use this router at all."
|
2004-05-13 09:24:49 +02:00
|
|
|
*/
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
the_nodes = nodelist_get_list();
|
|
|
|
n_supported = tor_malloc(sizeof(int)*smartlist_len(the_nodes));
|
|
|
|
SMARTLIST_FOREACH_BEGIN(the_nodes, const node_t *, node) {
|
|
|
|
const int i = node_sl_idx;
|
|
|
|
if (router_digest_is_me(node->identity)) {
|
2004-05-13 09:24:49 +02:00
|
|
|
n_supported[i] = -1;
|
2004-12-04 01:25:54 +01:00
|
|
|
// log_fn(LOG_DEBUG,"Skipping node %s -- it's me.", router->nickname);
|
2004-05-13 09:24:49 +02:00
|
|
|
/* XXX there's probably a reverse predecessor attack here, but
|
|
|
|
* it's slow. should we take this out? -RD
|
|
|
|
*/
|
|
|
|
continue;
|
|
|
|
}
|
2011-04-30 13:27:47 +02:00
|
|
|
if (!node_has_descriptor(node)) {
|
|
|
|
n_supported[i] = -1;
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
continue;
|
2011-04-30 13:27:47 +02:00
|
|
|
}
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
if (!node->is_running || node->is_bad_exit) {
|
2004-05-13 09:24:49 +02:00
|
|
|
n_supported[i] = -1;
|
2006-10-12 00:06:01 +02:00
|
|
|
continue; /* skip routers that are known to be down or bad exits */
|
2004-05-13 09:24:49 +02:00
|
|
|
}
|
2012-03-09 20:30:12 +01:00
|
|
|
if (node_get_purpose(node) != ROUTER_PURPOSE_GENERAL) {
|
2012-03-09 20:27:50 +01:00
|
|
|
/* never pick a non-general node as a random exit. */
|
|
|
|
n_supported[i] = -1;
|
|
|
|
continue;
|
|
|
|
}
|
2011-07-07 17:52:13 +02:00
|
|
|
if (routerset_contains_node(options->_ExcludeExitNodesUnion, node)) {
|
2005-01-12 05:58:23 +01:00
|
|
|
n_supported[i] = -1;
|
2011-03-11 10:35:08 +01:00
|
|
|
continue; /* user asked us not to use it, no matter what */
|
|
|
|
}
|
|
|
|
if (options->ExitNodes &&
|
2011-04-27 20:36:30 +02:00
|
|
|
!routerset_contains_node(options->ExitNodes, node)) {
|
2011-03-11 10:35:08 +01:00
|
|
|
n_supported[i] = -1;
|
|
|
|
continue; /* not one of our chosen exit nodes */
|
|
|
|
}
|
|
|
|
|
2011-04-27 20:36:30 +02:00
|
|
|
if (node_is_unreliable(node, need_uptime, need_capacity, 0)) {
|
2005-01-12 05:58:23 +01:00
|
|
|
n_supported[i] = -1;
|
2011-03-28 23:29:59 +02:00
|
|
|
continue; /* skip routers that are not suitable. Don't worry if
|
|
|
|
* this makes us reject all the possible routers: if so,
|
|
|
|
* we'll retry later in this function with need_update and
|
|
|
|
* need_capacity set to 0. */
|
2005-01-12 05:58:23 +01:00
|
|
|
}
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
if (!(node->is_valid || options->_AllowInvalid & ALLOW_INVALID_EXIT)) {
|
2007-01-27 20:40:49 +01:00
|
|
|
/* if it's invalid and we don't want it */
|
2004-07-21 11:35:24 +02:00
|
|
|
n_supported[i] = -1;
|
2006-03-19 02:21:59 +01:00
|
|
|
// log_fn(LOG_DEBUG,"Skipping node %s (index %d) -- invalid router.",
|
2004-12-04 01:25:54 +01:00
|
|
|
// router->nickname, i);
|
2006-03-19 02:21:59 +01:00
|
|
|
continue; /* skip invalid routers */
|
2004-07-21 11:35:24 +02:00
|
|
|
}
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
if (options->ExcludeSingleHopRelays &&
|
|
|
|
node_allows_single_hop_exits(node)) {
|
2008-09-26 21:09:12 +02:00
|
|
|
n_supported[i] = -1;
|
|
|
|
continue;
|
|
|
|
}
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
if (node_exit_policy_rejects_all(node)) {
|
2004-05-13 09:24:49 +02:00
|
|
|
n_supported[i] = -1;
|
2004-12-04 01:25:54 +01:00
|
|
|
// log_fn(LOG_DEBUG,"Skipping node %s (index %d) -- it rejects all.",
|
|
|
|
// router->nickname, i);
|
2004-05-13 09:24:49 +02:00
|
|
|
continue; /* skip routers that reject all */
|
|
|
|
}
|
|
|
|
n_supported[i] = 0;
|
2007-05-22 17:49:14 +02:00
|
|
|
/* iterate over connections */
|
2010-09-29 06:38:32 +02:00
|
|
|
SMARTLIST_FOREACH_BEGIN(connections, connection_t *, conn) {
|
2007-05-22 17:49:14 +02:00
|
|
|
if (!ap_stream_wants_exit_attention(conn))
|
2004-05-13 09:24:49 +02:00
|
|
|
continue; /* Skip everything but APs in CIRCUIT_WAIT */
|
2011-07-20 18:55:42 +02:00
|
|
|
if (connection_ap_can_use_exit(TO_ENTRY_CONN(conn), node)) {
|
2004-07-21 05:16:24 +02:00
|
|
|
++n_supported[i];
|
2004-12-04 01:25:54 +01:00
|
|
|
// log_fn(LOG_DEBUG,"%s is supported. n_supported[%d] now %d.",
|
|
|
|
// router->nickname, i, n_supported[i]);
|
2004-07-21 05:16:24 +02:00
|
|
|
} else {
|
2004-12-04 01:25:54 +01:00
|
|
|
// log_fn(LOG_DEBUG,"%s (index %d) would reject this stream.",
|
|
|
|
// router->nickname, i);
|
2004-07-21 05:16:24 +02:00
|
|
|
}
|
2010-09-29 06:38:32 +02:00
|
|
|
} SMARTLIST_FOREACH_END(conn);
|
2008-10-14 19:05:52 +02:00
|
|
|
if (n_pending_connections > 0 && n_supported[i] == 0) {
|
|
|
|
/* Leave best_support at -1 if that's where it is, so we can
|
|
|
|
* distinguish it later. */
|
|
|
|
continue;
|
|
|
|
}
|
2004-05-13 09:24:49 +02:00
|
|
|
if (n_supported[i] > best_support) {
|
|
|
|
/* If this router is better than previous ones, remember its index
|
|
|
|
* and goodness, and start counting how many routers are this good. */
|
|
|
|
best_support = n_supported[i]; n_best_support=1;
|
2004-12-04 01:25:54 +01:00
|
|
|
// log_fn(LOG_DEBUG,"%s is new best supported option so far.",
|
|
|
|
// router->nickname);
|
2004-05-13 09:24:49 +02:00
|
|
|
} else if (n_supported[i] == best_support) {
|
|
|
|
/* If this router is _as good_ as the best one, just increment the
|
|
|
|
* count of equally good routers.*/
|
|
|
|
++n_best_support;
|
|
|
|
}
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
} SMARTLIST_FOREACH_END(node);
|
2006-02-13 09:28:42 +01:00
|
|
|
log_info(LD_CIRC,
|
|
|
|
"Found %d servers that might support %d/%d pending connections.",
|
|
|
|
n_best_support, best_support >= 0 ? best_support : 0,
|
|
|
|
n_pending_connections);
|
2004-05-13 09:24:49 +02:00
|
|
|
|
|
|
|
/* If any routers definitely support any pending connections, choose one
|
|
|
|
* at random. */
|
|
|
|
if (best_support > 0) {
|
2012-01-18 21:53:30 +01:00
|
|
|
smartlist_t *supporting = smartlist_new();
|
2008-09-25 22:21:35 +02:00
|
|
|
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
SMARTLIST_FOREACH(the_nodes, const node_t *, node, {
|
|
|
|
if (n_supported[node_sl_idx] == best_support)
|
|
|
|
smartlist_add(supporting, (void*)node);
|
|
|
|
});
|
2004-05-13 09:24:49 +02:00
|
|
|
|
2011-04-27 20:36:30 +02:00
|
|
|
node = node_sl_choose_by_bandwidth(supporting, WEIGHT_FOR_EXIT);
|
2008-09-25 22:21:35 +02:00
|
|
|
smartlist_free(supporting);
|
2004-05-13 09:24:49 +02:00
|
|
|
} else {
|
|
|
|
/* Either there are no pending connections, or no routers even seem to
|
2004-12-05 08:10:08 +01:00
|
|
|
* possibly support any of them. Choose a router at random that satisfies
|
|
|
|
* at least one predicted exit port. */
|
|
|
|
|
2010-05-21 04:50:37 +02:00
|
|
|
int attempt;
|
2011-03-11 10:35:08 +01:00
|
|
|
smartlist_t *needed_ports, *supporting;
|
2004-12-05 08:10:08 +01:00
|
|
|
|
2004-05-13 09:24:49 +02:00
|
|
|
if (best_support == -1) {
|
2005-08-27 00:16:32 +02:00
|
|
|
if (need_uptime || need_capacity) {
|
2006-02-13 09:28:42 +01:00
|
|
|
log_info(LD_CIRC,
|
|
|
|
"We couldn't find any live%s%s routers; falling back "
|
|
|
|
"to list of all routers.",
|
|
|
|
need_capacity?", fast":"",
|
|
|
|
need_uptime?", stable":"");
|
2006-11-20 17:07:33 +01:00
|
|
|
tor_free(n_supported);
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
return choose_good_exit_server_general(0, 0);
|
2005-08-27 00:16:32 +02:00
|
|
|
}
|
2009-09-20 03:52:57 +02:00
|
|
|
log_notice(LD_CIRC, "All routers are down or won't exit%s -- "
|
|
|
|
"choosing a doomed exit at random.",
|
|
|
|
options->_ExcludeExitNodesUnion ? " or are Excluded" : "");
|
2004-05-13 09:24:49 +02:00
|
|
|
}
|
2012-01-18 21:53:30 +01:00
|
|
|
supporting = smartlist_new();
|
2007-08-22 05:03:24 +02:00
|
|
|
needed_ports = circuit_get_unhandled_ports(time(NULL));
|
2010-05-21 04:50:37 +02:00
|
|
|
for (attempt = 0; attempt < 2; attempt++) {
|
2004-12-05 08:10:08 +01:00
|
|
|
/* try once to pick only from routers that satisfy a needed port,
|
|
|
|
* then if there are none, pick from any that support exiting. */
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
SMARTLIST_FOREACH_BEGIN(the_nodes, const node_t *, node) {
|
|
|
|
if (n_supported[node_sl_idx] != -1 &&
|
|
|
|
(attempt || node_handles_some_port(node, needed_ports))) {
|
2005-12-14 21:40:40 +01:00
|
|
|
// log_fn(LOG_DEBUG,"Try %d: '%s' is a possibility.",
|
|
|
|
// try, router->nickname);
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
smartlist_add(supporting, (void*)node);
|
2004-12-05 08:10:08 +01:00
|
|
|
}
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
} SMARTLIST_FOREACH_END(node);
|
2004-05-13 09:24:49 +02:00
|
|
|
|
2011-04-27 20:36:30 +02:00
|
|
|
node = node_sl_choose_by_bandwidth(supporting, WEIGHT_FOR_EXIT);
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
if (node)
|
2004-12-05 08:10:08 +01:00
|
|
|
break;
|
2008-09-25 22:21:35 +02:00
|
|
|
smartlist_clear(supporting);
|
2012-05-11 18:52:21 +02:00
|
|
|
/* If we reach this point, we can't actually support any unhandled
|
|
|
|
* predicted ports, so clear all the remaining ones. */
|
|
|
|
if (smartlist_len(needed_ports))
|
|
|
|
rep_hist_remove_predicted_ports(needed_ports);
|
2004-12-05 08:10:08 +01:00
|
|
|
}
|
2004-12-07 16:29:54 +01:00
|
|
|
SMARTLIST_FOREACH(needed_ports, uint16_t *, cp, tor_free(cp));
|
2004-12-05 08:10:08 +01:00
|
|
|
smartlist_free(needed_ports);
|
2008-09-25 22:21:35 +02:00
|
|
|
smartlist_free(supporting);
|
2004-05-13 09:24:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
tor_free(n_supported);
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
if (node) {
|
2011-05-30 21:41:46 +02:00
|
|
|
log_info(LD_CIRC, "Chose exit server '%s'", node_describe(node));
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
return node;
|
2004-05-13 09:24:49 +02:00
|
|
|
}
|
2011-03-11 10:35:08 +01:00
|
|
|
if (options->ExitNodes) {
|
2006-02-13 09:28:42 +01:00
|
|
|
log_warn(LD_CIRC,
|
2011-03-11 10:35:08 +01:00
|
|
|
"No specified %sexit routers seem to be running: "
|
|
|
|
"can't choose an exit.",
|
|
|
|
options->_ExcludeExitNodesUnion ? "non-excluded " : "");
|
2005-10-24 21:37:45 +02:00
|
|
|
}
|
2004-05-13 09:24:49 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Return a pointer to a suitable router to be the exit node for the
|
|
|
|
* circuit of purpose <b>purpose</b> that we're about to build (or NULL
|
|
|
|
* if no router is suitable).
|
|
|
|
*
|
|
|
|
* For general-purpose circuits, pass it off to
|
|
|
|
* choose_good_exit_server_general()
|
|
|
|
*
|
|
|
|
* For client-side rendezvous circuits, choose a random node, weighted
|
|
|
|
* toward the preferences in 'options'.
|
|
|
|
*/
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
static const node_t *
|
|
|
|
choose_good_exit_server(uint8_t purpose,
|
2005-11-24 07:43:39 +01:00
|
|
|
int need_uptime, int need_capacity, int is_internal)
|
2004-05-13 09:24:49 +02:00
|
|
|
{
|
2011-06-14 19:01:38 +02:00
|
|
|
const or_options_t *options = get_options();
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
router_crn_flags_t flags = CRN_NEED_DESC;
|
2008-07-24 11:22:34 +02:00
|
|
|
if (need_uptime)
|
|
|
|
flags |= CRN_NEED_UPTIME;
|
|
|
|
if (need_capacity)
|
|
|
|
flags |= CRN_NEED_CAPACITY;
|
|
|
|
|
2004-11-28 10:05:49 +01:00
|
|
|
switch (purpose) {
|
2004-05-13 09:24:49 +02:00
|
|
|
case CIRCUIT_PURPOSE_C_GENERAL:
|
2008-07-24 11:22:34 +02:00
|
|
|
if (options->_AllowInvalid & ALLOW_INVALID_MIDDLE)
|
|
|
|
flags |= CRN_ALLOW_INVALID;
|
2005-11-24 07:43:39 +01:00
|
|
|
if (is_internal) /* pick it like a middle hop */
|
2009-09-18 04:45:54 +02:00
|
|
|
return router_choose_random_node(NULL, options->ExcludeNodes, flags);
|
2005-11-24 07:43:39 +01:00
|
|
|
else
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
return choose_good_exit_server_general(need_uptime,need_capacity);
|
2004-05-13 09:24:49 +02:00
|
|
|
case CIRCUIT_PURPOSE_C_ESTABLISH_REND:
|
2008-07-24 11:22:34 +02:00
|
|
|
if (options->_AllowInvalid & ALLOW_INVALID_RENDEZVOUS)
|
|
|
|
flags |= CRN_ALLOW_INVALID;
|
2009-09-18 04:45:54 +02:00
|
|
|
return router_choose_random_node(NULL, options->ExcludeNodes, flags);
|
2004-05-13 09:24:49 +02:00
|
|
|
}
|
2007-03-04 21:11:46 +01:00
|
|
|
log_warn(LD_BUG,"Unhandled purpose %d", purpose);
|
2005-04-26 20:52:16 +02:00
|
|
|
tor_fragile_assert();
|
2004-10-17 00:56:46 +02:00
|
|
|
return NULL;
|
2004-05-13 09:24:49 +02:00
|
|
|
}
|
|
|
|
|
2008-09-25 22:21:35 +02:00
|
|
|
/** Log a warning if the user specified an exit for the circuit that
|
|
|
|
* has been excluded from use by ExcludeNodes or ExcludeExitNodes. */
|
|
|
|
static void
|
2009-09-11 15:40:09 +02:00
|
|
|
warn_if_last_router_excluded(origin_circuit_t *circ, const extend_info_t *exit)
|
2008-09-25 22:21:35 +02:00
|
|
|
{
|
2011-06-14 19:01:38 +02:00
|
|
|
const or_options_t *options = get_options();
|
2009-05-27 20:07:41 +02:00
|
|
|
routerset_t *rs = options->ExcludeNodes;
|
|
|
|
const char *description;
|
2009-09-11 15:40:09 +02:00
|
|
|
uint8_t purpose = circ->_base.purpose;
|
|
|
|
|
|
|
|
if (circ->build_state->onehop_tunnel)
|
|
|
|
return;
|
2008-09-25 22:21:35 +02:00
|
|
|
|
2009-05-27 20:07:41 +02:00
|
|
|
switch (purpose)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
case CIRCUIT_PURPOSE_OR:
|
|
|
|
case CIRCUIT_PURPOSE_INTRO_POINT:
|
|
|
|
case CIRCUIT_PURPOSE_REND_POINT_WAITING:
|
|
|
|
case CIRCUIT_PURPOSE_REND_ESTABLISHED:
|
2011-04-08 19:27:25 +02:00
|
|
|
log_warn(LD_BUG, "Called on non-origin circuit (purpose %d, %s)",
|
|
|
|
(int)purpose,
|
|
|
|
circuit_purpose_to_string(purpose));
|
2009-05-27 20:07:41 +02:00
|
|
|
return;
|
|
|
|
case CIRCUIT_PURPOSE_C_GENERAL:
|
2009-09-11 15:40:09 +02:00
|
|
|
if (circ->build_state->is_internal)
|
|
|
|
return;
|
2011-04-08 04:01:23 +02:00
|
|
|
description = "requested exit node";
|
2009-05-27 20:07:41 +02:00
|
|
|
rs = options->_ExcludeExitNodesUnion;
|
|
|
|
break;
|
|
|
|
case CIRCUIT_PURPOSE_C_INTRODUCING:
|
|
|
|
case CIRCUIT_PURPOSE_C_INTRODUCE_ACK_WAIT:
|
|
|
|
case CIRCUIT_PURPOSE_C_INTRODUCE_ACKED:
|
2009-09-11 15:40:09 +02:00
|
|
|
case CIRCUIT_PURPOSE_S_ESTABLISH_INTRO:
|
|
|
|
case CIRCUIT_PURPOSE_S_CONNECT_REND:
|
|
|
|
case CIRCUIT_PURPOSE_S_REND_JOINED:
|
|
|
|
case CIRCUIT_PURPOSE_TESTING:
|
|
|
|
return;
|
2009-05-27 20:07:41 +02:00
|
|
|
case CIRCUIT_PURPOSE_C_ESTABLISH_REND:
|
|
|
|
case CIRCUIT_PURPOSE_C_REND_READY:
|
|
|
|
case CIRCUIT_PURPOSE_C_REND_READY_INTRO_ACKED:
|
|
|
|
case CIRCUIT_PURPOSE_C_REND_JOINED:
|
2011-04-08 04:01:23 +02:00
|
|
|
description = "chosen rendezvous point";
|
2009-05-27 20:07:41 +02:00
|
|
|
break;
|
|
|
|
case CIRCUIT_PURPOSE_CONTROLLER:
|
|
|
|
rs = options->_ExcludeExitNodesUnion;
|
2011-04-08 04:01:23 +02:00
|
|
|
description = "controller-selected circuit target";
|
2009-05-27 20:07:41 +02:00
|
|
|
break;
|
|
|
|
}
|
2008-09-25 22:21:35 +02:00
|
|
|
|
2009-09-11 15:40:09 +02:00
|
|
|
if (routerset_contains_extendinfo(rs, exit)) {
|
2011-04-08 04:01:23 +02:00
|
|
|
/* We should never get here if StrictNodes is set to 1. */
|
2011-04-27 04:48:00 +02:00
|
|
|
if (options->StrictNodes) {
|
|
|
|
log_warn(LD_BUG, "Using %s '%s' which is listed in ExcludeNodes%s, "
|
|
|
|
"even though StrictNodes is set. Please report. "
|
|
|
|
"(Circuit purpose: %s)",
|
2011-05-16 03:58:46 +02:00
|
|
|
description, extend_info_describe(exit),
|
2011-04-27 04:48:00 +02:00
|
|
|
rs==options->ExcludeNodes?"":" or ExcludeExitNodes",
|
|
|
|
circuit_purpose_to_string(purpose));
|
|
|
|
} else {
|
|
|
|
log_warn(LD_CIRC, "Using %s '%s' which is listed in "
|
|
|
|
"ExcludeNodes%s, because no better options were available. To "
|
|
|
|
"prevent this (and possibly break your Tor functionality), "
|
|
|
|
"set the StrictNodes configuration option. "
|
|
|
|
"(Circuit purpose: %s)",
|
2011-05-16 03:58:46 +02:00
|
|
|
description, extend_info_describe(exit),
|
2011-04-27 04:48:00 +02:00
|
|
|
rs==options->ExcludeNodes?"":" or ExcludeExitNodes",
|
|
|
|
circuit_purpose_to_string(purpose));
|
|
|
|
}
|
|
|
|
circuit_log_path(LOG_WARN, LD_CIRC, circ);
|
2009-09-11 15:40:09 +02:00
|
|
|
}
|
2008-09-25 22:21:35 +02:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-03-22 01:42:38 +01:00
|
|
|
/** 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
|
2006-07-23 09:37:35 +02:00
|
|
|
onion_pick_cpath_exit(origin_circuit_t *circ, extend_info_t *exit)
|
2005-06-11 20:52:12 +02:00
|
|
|
{
|
2005-03-22 01:42:38 +01:00
|
|
|
cpath_build_state_t *state = circ->build_state;
|
2004-11-06 06:18:11 +01:00
|
|
|
|
2006-12-13 03:49:45 +01:00
|
|
|
if (state->onehop_tunnel) {
|
|
|
|
log_debug(LD_CIRC, "Launching a one-hop circuit for dir tunnel.");
|
|
|
|
state->desired_path_len = 1;
|
|
|
|
} else {
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
int r = new_route_len(circ->_base.purpose, exit, nodelist_get_list());
|
2006-12-13 03:49:45 +01:00
|
|
|
if (r < 1) /* must be at least 1 */
|
|
|
|
return -1;
|
|
|
|
state->desired_path_len = r;
|
|
|
|
}
|
2005-03-22 01:42:38 +01:00
|
|
|
|
|
|
|
if (exit) { /* the circuit-builder pre-requested one */
|
2009-09-11 15:40:09 +02:00
|
|
|
warn_if_last_router_excluded(circ, exit);
|
2011-05-16 03:58:46 +02:00
|
|
|
log_info(LD_CIRC,"Using requested exit node '%s'",
|
|
|
|
extend_info_describe(exit));
|
2005-06-29 23:46:55 +02:00
|
|
|
exit = extend_info_dup(exit);
|
2004-05-13 09:24:49 +02:00
|
|
|
} else { /* we have to decide one */
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
const node_t *node =
|
|
|
|
choose_good_exit_server(circ->_base.purpose, state->need_uptime,
|
2006-07-23 09:37:35 +02:00
|
|
|
state->need_capacity, state->is_internal);
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
if (!node) {
|
2006-02-13 09:28:42 +01:00
|
|
|
log_warn(LD_CIRC,"failed to choose an exit server");
|
2005-03-22 01:42:38 +01:00
|
|
|
return -1;
|
2004-05-13 09:24:49 +02:00
|
|
|
}
|
2011-11-24 18:29:56 +01:00
|
|
|
exit = extend_info_from_node(node, 0);
|
2010-10-02 01:52:05 +02:00
|
|
|
tor_assert(exit);
|
2004-05-13 09:24:49 +02:00
|
|
|
}
|
2005-06-29 23:46:55 +02:00
|
|
|
state->chosen_exit = exit;
|
2005-03-22 01:42:38 +01:00
|
|
|
return 0;
|
2004-05-13 09:24:49 +02:00
|
|
|
}
|
|
|
|
|
2005-03-22 02:01:15 +01:00
|
|
|
/** Give <b>circ</b> a new exit destination to <b>exit</b>, and add a
|
|
|
|
* hop to the cpath reflecting this. Don't send the next extend cell --
|
|
|
|
* the caller will do this if it wants to.
|
Introduce a notion of 'internal' circs, which are chosen without regard
to the exit policy of the last hop. Intro and rendezvous circs must
be internal circs, to avoid leaking information. Resolve and connect
streams can use internal circs if they want.
New circuit pooling algorithm: make sure to have enough circs around
to satisfy any predicted ports, and also make sure to have 2 internal
circs around if we've required internal circs lately (with high uptime
if we've seen that lately).
Split NewCircuitPeriod config option into NewCircuitPeriod (30 secs),
which describes how often we retry making new circuits if current ones
are dirty, and MaxCircuitDirtiness (10 mins), which describes how long
we're willing to make use of an already-dirty circuit.
Once rendezvous circuits are established, keep using the same circuit as
long as you attach a new stream to it at least every 10 minutes. (So web
browsing doesn't require you to build new rend circs every 30 seconds.)
Cannibalize GENERAL circs to be C_REND, C_INTRO, S_INTRO, and S_REND
circ as necessary, if there are any completed ones lying around when
we try to launch one.
Re-instate the ifdef's to use version-0 style introduce cells, since
there was yet another bug in handling version-1 style. We'll try switching
over again after 0.0.9 is obsolete.
Bugfix: when choosing an exit node for a new non-internal circ, don't take
into account whether it'll be useful for any pending x.onion addresses --
it won't.
Bugfix: we weren't actually publishing the hidden service descriptor when
it became dirty. So we only published it every 20 minutes or so, which
means when you first start your Tor, the hidden service will seem broken.
svn:r3360
2005-01-17 19:13:09 +01:00
|
|
|
*/
|
|
|
|
int
|
2007-05-08 12:01:33 +02:00
|
|
|
circuit_append_new_exit(origin_circuit_t *circ, extend_info_t *exit)
|
2005-06-11 20:52:12 +02:00
|
|
|
{
|
2005-06-29 23:46:55 +02:00
|
|
|
cpath_build_state_t *state;
|
2007-05-08 12:01:33 +02:00
|
|
|
tor_assert(exit);
|
2006-07-23 09:37:35 +02:00
|
|
|
tor_assert(circ);
|
2005-06-29 23:46:55 +02:00
|
|
|
|
|
|
|
state = circ->build_state;
|
|
|
|
tor_assert(state);
|
2009-12-12 08:07:59 +01:00
|
|
|
extend_info_free(state->chosen_exit);
|
2007-05-08 12:01:33 +02:00
|
|
|
state->chosen_exit = extend_info_dup(exit);
|
2005-06-29 23:46:55 +02:00
|
|
|
|
Introduce a notion of 'internal' circs, which are chosen without regard
to the exit policy of the last hop. Intro and rendezvous circs must
be internal circs, to avoid leaking information. Resolve and connect
streams can use internal circs if they want.
New circuit pooling algorithm: make sure to have enough circs around
to satisfy any predicted ports, and also make sure to have 2 internal
circs around if we've required internal circs lately (with high uptime
if we've seen that lately).
Split NewCircuitPeriod config option into NewCircuitPeriod (30 secs),
which describes how often we retry making new circuits if current ones
are dirty, and MaxCircuitDirtiness (10 mins), which describes how long
we're willing to make use of an already-dirty circuit.
Once rendezvous circuits are established, keep using the same circuit as
long as you attach a new stream to it at least every 10 minutes. (So web
browsing doesn't require you to build new rend circs every 30 seconds.)
Cannibalize GENERAL circs to be C_REND, C_INTRO, S_INTRO, and S_REND
circ as necessary, if there are any completed ones lying around when
we try to launch one.
Re-instate the ifdef's to use version-0 style introduce cells, since
there was yet another bug in handling version-1 style. We'll try switching
over again after 0.0.9 is obsolete.
Bugfix: when choosing an exit node for a new non-internal circ, don't take
into account whether it'll be useful for any pending x.onion addresses --
it won't.
Bugfix: we weren't actually publishing the hidden service descriptor when
it became dirty. So we only published it every 20 minutes or so, which
means when you first start your Tor, the hidden service will seem broken.
svn:r3360
2005-01-17 19:13:09 +01:00
|
|
|
++circ->build_state->desired_path_len;
|
2007-05-08 12:01:33 +02:00
|
|
|
onion_append_hop(&circ->cpath, exit);
|
Introduce a notion of 'internal' circs, which are chosen without regard
to the exit policy of the last hop. Intro and rendezvous circs must
be internal circs, to avoid leaking information. Resolve and connect
streams can use internal circs if they want.
New circuit pooling algorithm: make sure to have enough circs around
to satisfy any predicted ports, and also make sure to have 2 internal
circs around if we've required internal circs lately (with high uptime
if we've seen that lately).
Split NewCircuitPeriod config option into NewCircuitPeriod (30 secs),
which describes how often we retry making new circuits if current ones
are dirty, and MaxCircuitDirtiness (10 mins), which describes how long
we're willing to make use of an already-dirty circuit.
Once rendezvous circuits are established, keep using the same circuit as
long as you attach a new stream to it at least every 10 minutes. (So web
browsing doesn't require you to build new rend circs every 30 seconds.)
Cannibalize GENERAL circs to be C_REND, C_INTRO, S_INTRO, and S_REND
circ as necessary, if there are any completed ones lying around when
we try to launch one.
Re-instate the ifdef's to use version-0 style introduce cells, since
there was yet another bug in handling version-1 style. We'll try switching
over again after 0.0.9 is obsolete.
Bugfix: when choosing an exit node for a new non-internal circ, don't take
into account whether it'll be useful for any pending x.onion addresses --
it won't.
Bugfix: we weren't actually publishing the hidden service descriptor when
it became dirty. So we only published it every 20 minutes or so, which
means when you first start your Tor, the hidden service will seem broken.
svn:r3360
2005-01-17 19:13:09 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-12-26 06:52:44 +01:00
|
|
|
/** Take an open <b>circ</b>, and add a new hop at the end, based on
|
|
|
|
* <b>info</b>. Set its state back to CIRCUIT_STATE_BUILDING, and then
|
|
|
|
* send the next extend cell to begin connecting to that hop.
|
|
|
|
*/
|
2005-06-11 20:52:12 +02:00
|
|
|
int
|
2007-05-08 12:01:33 +02:00
|
|
|
circuit_extend_to_new_exit(origin_circuit_t *circ, extend_info_t *exit)
|
2005-06-11 20:52:12 +02:00
|
|
|
{
|
2006-10-09 17:47:27 +02:00
|
|
|
int err_reason = 0;
|
2009-09-11 15:40:09 +02:00
|
|
|
warn_if_last_router_excluded(circ, exit);
|
2007-05-08 12:01:33 +02:00
|
|
|
circuit_append_new_exit(circ, exit);
|
2006-07-23 09:37:35 +02:00
|
|
|
circuit_set_state(TO_CIRCUIT(circ), CIRCUIT_STATE_BUILDING);
|
2006-10-09 17:47:27 +02:00
|
|
|
if ((err_reason = circuit_send_next_onion_skin(circ))<0) {
|
2011-05-16 03:58:46 +02:00
|
|
|
log_warn(LD_CIRC, "Couldn't extend circuit to new point %s.",
|
|
|
|
extend_info_describe(exit));
|
2006-10-09 17:47:27 +02:00
|
|
|
circuit_mark_for_close(TO_CIRCUIT(circ), -err_reason);
|
2005-03-22 02:01:15 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-05-13 09:24:49 +02:00
|
|
|
/** Return the number of routers in <b>routers</b> that are currently up
|
2004-08-18 22:35:11 +02:00
|
|
|
* and available for building circuits through.
|
2004-05-13 09:24:49 +02:00
|
|
|
*/
|
2005-06-11 20:52:12 +02:00
|
|
|
static int
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
count_acceptable_nodes(smartlist_t *nodes)
|
2005-06-11 20:52:12 +02:00
|
|
|
{
|
2004-05-13 09:24:49 +02:00
|
|
|
int num=0;
|
|
|
|
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
SMARTLIST_FOREACH_BEGIN(nodes, const node_t *, node) {
|
|
|
|
// log_debug(LD_CIRC,
|
2006-03-18 02:24:04 +01:00
|
|
|
// "Contemplating whether router %d (%s) is a new option.",
|
|
|
|
// i, r->nickname);
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
if (! node->is_running)
|
2006-03-18 02:24:04 +01:00
|
|
|
// log_debug(LD_CIRC,"Nope, the directory says %d is not running.",i);
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
continue;
|
|
|
|
if (! node->is_valid)
|
2006-03-19 02:21:59 +01:00
|
|
|
// log_debug(LD_CIRC,"Nope, the directory says %d is not valid.",i);
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
continue;
|
|
|
|
if (! node_has_descriptor(node))
|
|
|
|
continue;
|
2006-04-25 09:06:48 +02:00
|
|
|
/* XXX This clause makes us count incorrectly: if AllowInvalidRouters
|
|
|
|
* allows this node in some places, then we're getting an inaccurate
|
|
|
|
* count. For now, be conservative and don't count it. But later we
|
|
|
|
* should try to be smarter. */
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
++num;
|
|
|
|
} SMARTLIST_FOREACH_END(node);
|
|
|
|
|
2006-03-18 02:24:04 +01:00
|
|
|
// log_debug(LD_CIRC,"I like %d. num_acceptable_routers now %d.",i, num);
|
2004-05-13 09:24:49 +02:00
|
|
|
|
|
|
|
return num;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Add <b>new_hop</b> to the end of the doubly-linked-list <b>head_ptr</b>.
|
|
|
|
* This function is used to extend cpath by another hop.
|
|
|
|
*/
|
2005-06-11 20:52:12 +02:00
|
|
|
void
|
|
|
|
onion_append_to_cpath(crypt_path_t **head_ptr, crypt_path_t *new_hop)
|
2004-05-13 09:24:49 +02:00
|
|
|
{
|
|
|
|
if (*head_ptr) {
|
|
|
|
new_hop->next = (*head_ptr);
|
|
|
|
new_hop->prev = (*head_ptr)->prev;
|
|
|
|
(*head_ptr)->prev->next = new_hop;
|
|
|
|
(*head_ptr)->prev = new_hop;
|
|
|
|
} else {
|
|
|
|
*head_ptr = new_hop;
|
|
|
|
new_hop->prev = new_hop->next = new_hop;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-12-26 06:52:44 +01:00
|
|
|
/** A helper function used by onion_extend_cpath(). Use <b>purpose</b>
|
|
|
|
* and <b>state</b> and the cpath <b>head</b> (currently populated only
|
|
|
|
* to length <b>cur_len</b> to decide a suitable middle hop for a
|
|
|
|
* circuit. In particular, make sure we don't pick the exit node or its
|
|
|
|
* family, and make sure we don't duplicate any previous nodes or their
|
|
|
|
* families. */
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
static const node_t *
|
2005-06-11 20:52:12 +02:00
|
|
|
choose_good_middle_server(uint8_t purpose,
|
|
|
|
cpath_build_state_t *state,
|
|
|
|
crypt_path_t *head,
|
|
|
|
int cur_len)
|
2004-08-15 10:15:12 +02:00
|
|
|
{
|
|
|
|
int i;
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
const node_t *r, *choice;
|
2004-08-15 10:15:12 +02:00
|
|
|
crypt_path_t *cpath;
|
2004-12-07 10:18:25 +01:00
|
|
|
smartlist_t *excluded;
|
2011-06-14 19:01:38 +02:00
|
|
|
const or_options_t *options = get_options();
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
router_crn_flags_t flags = CRN_NEED_DESC;
|
2005-09-30 00:59:17 +02:00
|
|
|
tor_assert(_CIRCUIT_PURPOSE_MIN <= purpose &&
|
|
|
|
purpose <= _CIRCUIT_PURPOSE_MAX);
|
2004-08-15 10:15:12 +02:00
|
|
|
|
2006-02-13 09:28:42 +01:00
|
|
|
log_debug(LD_CIRC, "Contemplating intermediate hop: random choice.");
|
2012-01-18 21:53:30 +01:00
|
|
|
excluded = smartlist_new();
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
if ((r = build_state_get_exit_node(state))) {
|
2011-07-11 17:21:47 +02:00
|
|
|
nodelist_add_node_and_family(excluded, r);
|
2004-09-10 23:40:29 +02:00
|
|
|
}
|
2004-08-15 10:15:12 +02:00
|
|
|
for (i = 0, cpath = head; i < cur_len; ++i, cpath=cpath->next) {
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
if ((r = node_get_by_id(cpath->extend_info->identity_digest))) {
|
2011-07-11 17:21:47 +02:00
|
|
|
nodelist_add_node_and_family(excluded, r);
|
2004-09-30 17:40:05 +02:00
|
|
|
}
|
2004-08-15 10:15:12 +02:00
|
|
|
}
|
2008-07-24 11:22:34 +02:00
|
|
|
|
|
|
|
if (state->need_uptime)
|
|
|
|
flags |= CRN_NEED_UPTIME;
|
|
|
|
if (state->need_capacity)
|
|
|
|
flags |= CRN_NEED_CAPACITY;
|
|
|
|
if (options->_AllowInvalid & ALLOW_INVALID_MIDDLE)
|
|
|
|
flags |= CRN_ALLOW_INVALID;
|
2009-09-18 04:45:54 +02:00
|
|
|
choice = router_choose_random_node(excluded, options->ExcludeNodes, flags);
|
2004-08-15 10:15:12 +02:00
|
|
|
smartlist_free(excluded);
|
|
|
|
return choice;
|
|
|
|
}
|
|
|
|
|
2005-07-23 06:12:35 +02:00
|
|
|
/** Pick a good entry server for the circuit to be built according to
|
2005-12-07 05:43:39 +01:00
|
|
|
* <b>state</b>. Don't reuse a chosen exit (if any), don't use this
|
|
|
|
* router (if we're an OR), and respect firewall settings; if we're
|
2007-06-12 11:17:23 +02:00
|
|
|
* configured to use entry guards, return one.
|
2005-07-22 19:32:25 +02:00
|
|
|
*
|
2007-06-12 11:17:23 +02:00
|
|
|
* If <b>state</b> is NULL, we're choosing a router to serve as an entry
|
|
|
|
* guard, not for any particular circuit.
|
2005-07-22 19:32:25 +02:00
|
|
|
*/
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
static const node_t *
|
2005-12-11 13:14:26 +01:00
|
|
|
choose_good_entry_server(uint8_t purpose, cpath_build_state_t *state)
|
2004-08-15 10:15:12 +02:00
|
|
|
{
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
const node_t *choice;
|
2006-01-11 05:14:10 +01:00
|
|
|
smartlist_t *excluded;
|
2011-06-14 19:01:38 +02:00
|
|
|
const or_options_t *options = get_options();
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
router_crn_flags_t flags = CRN_NEED_GUARD|CRN_NEED_DESC;
|
|
|
|
const node_t *node;
|
2004-08-15 10:15:12 +02:00
|
|
|
|
2008-07-11 23:42:09 +02:00
|
|
|
if (state && options->UseEntryGuards &&
|
|
|
|
(purpose != CIRCUIT_PURPOSE_TESTING || options->BridgeRelay)) {
|
2012-06-28 19:43:01 +02:00
|
|
|
/* This request is for an entry server to use for a regular circuit,
|
2010-10-29 21:55:39 +02:00
|
|
|
* and we use entry guard nodes. Just return one of the guard nodes. */
|
2005-12-28 10:07:31 +01:00
|
|
|
return choose_random_entry(state);
|
2005-07-22 19:32:25 +02:00
|
|
|
}
|
|
|
|
|
2012-01-18 21:53:30 +01:00
|
|
|
excluded = smartlist_new();
|
2006-01-11 05:14:10 +01:00
|
|
|
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
if (state && (node = build_state_get_exit_node(state))) {
|
2010-10-29 21:55:39 +02:00
|
|
|
/* Exclude the exit node from the state, if we have one. Also exclude its
|
|
|
|
* family. */
|
2011-07-11 17:21:47 +02:00
|
|
|
nodelist_add_node_and_family(excluded, node);
|
2004-09-10 23:40:29 +02:00
|
|
|
}
|
2006-02-13 22:17:20 +01:00
|
|
|
if (firewall_is_fascist_or()) {
|
2010-10-29 21:55:39 +02:00
|
|
|
/* Exclude all ORs that we can't reach through our firewall */
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
smartlist_t *nodes = nodelist_get_list();
|
2010-10-29 21:55:39 +02:00
|
|
|
SMARTLIST_FOREACH(nodes, const node_t *, node, {
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
if (!fascist_firewall_allows_node(node))
|
|
|
|
smartlist_add(excluded, (void*)node);
|
|
|
|
});
|
2004-08-15 10:15:12 +02:00
|
|
|
}
|
2010-10-29 21:55:39 +02:00
|
|
|
/* and exclude current entry guards and their families, if applicable */
|
2006-06-09 11:02:32 +02:00
|
|
|
if (options->UseEntryGuards && entry_guards) {
|
|
|
|
SMARTLIST_FOREACH(entry_guards, entry_guard_t *, entry,
|
|
|
|
{
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
if ((node = node_get_by_id(entry->identity))) {
|
2011-07-11 17:21:47 +02:00
|
|
|
nodelist_add_node_and_family(excluded, node);
|
2008-12-08 01:04:29 +01:00
|
|
|
}
|
2006-06-09 11:02:32 +02:00
|
|
|
});
|
|
|
|
}
|
2006-10-03 00:13:42 +02:00
|
|
|
|
2008-07-24 11:22:34 +02:00
|
|
|
if (state) {
|
|
|
|
if (state->need_uptime)
|
|
|
|
flags |= CRN_NEED_UPTIME;
|
|
|
|
if (state->need_capacity)
|
|
|
|
flags |= CRN_NEED_CAPACITY;
|
|
|
|
}
|
|
|
|
if (options->_AllowInvalid & ALLOW_INVALID_ENTRY)
|
|
|
|
flags |= CRN_ALLOW_INVALID;
|
|
|
|
|
2009-09-18 04:45:54 +02:00
|
|
|
choice = router_choose_random_node(excluded, options->ExcludeNodes, flags);
|
2004-08-15 10:15:12 +02:00
|
|
|
smartlist_free(excluded);
|
|
|
|
return choice;
|
|
|
|
}
|
|
|
|
|
2005-03-22 01:42:38 +01:00
|
|
|
/** Return the first non-open hop in cpath, or return NULL if all
|
|
|
|
* hops are open. */
|
|
|
|
static crypt_path_t *
|
2005-06-11 20:52:12 +02:00
|
|
|
onion_next_hop_in_cpath(crypt_path_t *cpath)
|
|
|
|
{
|
2005-03-22 01:42:38 +01:00
|
|
|
crypt_path_t *hop = cpath;
|
|
|
|
do {
|
|
|
|
if (hop->state != CPATH_STATE_OPEN)
|
|
|
|
return hop;
|
|
|
|
hop = hop->next;
|
|
|
|
} while (hop != cpath);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2004-05-13 09:24:49 +02:00
|
|
|
/** Choose a suitable next hop in the cpath <b>head_ptr</b>,
|
2005-03-22 01:42:38 +01:00
|
|
|
* based on <b>state</b>. Append the hop info to head_ptr.
|
2004-05-13 09:24:49 +02:00
|
|
|
*/
|
|
|
|
static int
|
2006-10-07 08:28:50 +02:00
|
|
|
onion_extend_cpath(origin_circuit_t *circ)
|
2004-05-13 09:24:49 +02:00
|
|
|
{
|
2006-10-07 08:28:50 +02:00
|
|
|
uint8_t purpose = circ->_base.purpose;
|
|
|
|
cpath_build_state_t *state = circ->build_state;
|
|
|
|
int cur_len = circuit_get_cpath_len(circ);
|
2005-06-29 23:46:55 +02:00
|
|
|
extend_info_t *info = NULL;
|
2004-05-13 09:24:49 +02:00
|
|
|
|
|
|
|
if (cur_len >= state->desired_path_len) {
|
2006-02-13 09:28:42 +01:00
|
|
|
log_debug(LD_CIRC, "Path is complete: %d steps long",
|
|
|
|
state->desired_path_len);
|
2004-05-13 09:24:49 +02:00
|
|
|
return 1;
|
|
|
|
}
|
2005-03-22 01:42:38 +01:00
|
|
|
|
2006-02-13 09:28:42 +01:00
|
|
|
log_debug(LD_CIRC, "Path is %d long; we want %d", cur_len,
|
|
|
|
state->desired_path_len);
|
2004-05-13 09:24:49 +02:00
|
|
|
|
2004-11-28 10:05:49 +01:00
|
|
|
if (cur_len == state->desired_path_len - 1) { /* Picking last node */
|
2005-06-29 23:46:55 +02:00
|
|
|
info = extend_info_dup(state->chosen_exit);
|
2004-11-28 10:05:49 +01:00
|
|
|
} else if (cur_len == 0) { /* picking first node */
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
const node_t *r = choose_good_entry_server(purpose, state);
|
2010-10-02 01:52:05 +02:00
|
|
|
if (r) {
|
2012-08-27 15:03:34 +02:00
|
|
|
/* If we're a client, use the preferred address rather than the
|
|
|
|
primary address, for potentially connecting to an IPv6 OR
|
|
|
|
port. */
|
|
|
|
info = extend_info_from_node(r, server_mode(get_options()) == 0);
|
2010-10-02 01:52:05 +02:00
|
|
|
tor_assert(info);
|
|
|
|
}
|
2004-05-13 09:24:49 +02:00
|
|
|
} else {
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
const node_t *r =
|
2006-10-07 08:28:50 +02:00
|
|
|
choose_good_middle_server(purpose, state, circ->cpath, cur_len);
|
2010-10-02 01:52:05 +02:00
|
|
|
if (r) {
|
2011-11-24 18:29:56 +01:00
|
|
|
info = extend_info_from_node(r, 0);
|
2010-10-02 01:52:05 +02:00
|
|
|
tor_assert(info);
|
|
|
|
}
|
2004-08-15 10:15:12 +02:00
|
|
|
}
|
|
|
|
|
2005-06-29 23:46:55 +02:00
|
|
|
if (!info) {
|
2006-02-13 09:28:42 +01:00
|
|
|
log_warn(LD_CIRC,"Failed to find node for hop %d of our path. Discarding "
|
|
|
|
"this circuit.", cur_len);
|
2004-08-15 10:15:12 +02:00
|
|
|
return -1;
|
2004-05-13 09:24:49 +02:00
|
|
|
}
|
|
|
|
|
2006-02-13 09:28:42 +01:00
|
|
|
log_debug(LD_CIRC,"Chose router %s for hop %d (exit is %s)",
|
2011-05-16 03:58:46 +02:00
|
|
|
extend_info_describe(info),
|
|
|
|
cur_len+1, build_state_get_exit_nickname(state));
|
2004-05-13 09:24:49 +02:00
|
|
|
|
2006-10-07 08:28:50 +02:00
|
|
|
onion_append_hop(&circ->cpath, info);
|
2005-06-29 23:46:55 +02:00
|
|
|
extend_info_free(info);
|
2005-03-22 01:42:38 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Create a new hop, annotate it with information about its
|
|
|
|
* corresponding router <b>choice</b>, and append it to the
|
|
|
|
* end of the cpath <b>head_ptr</b>. */
|
|
|
|
static int
|
2005-06-29 23:46:55 +02:00
|
|
|
onion_append_hop(crypt_path_t **head_ptr, extend_info_t *choice)
|
2005-06-11 20:52:12 +02:00
|
|
|
{
|
2005-03-22 01:42:38 +01:00
|
|
|
crypt_path_t *hop = tor_malloc_zero(sizeof(crypt_path_t));
|
2004-05-13 09:24:49 +02:00
|
|
|
|
|
|
|
/* link hop into the cpath, at the end. */
|
|
|
|
onion_append_to_cpath(head_ptr, hop);
|
|
|
|
|
2005-03-23 07:21:48 +01:00
|
|
|
hop->magic = CRYPT_PATH_MAGIC;
|
2004-05-13 09:24:49 +02:00
|
|
|
hop->state = CPATH_STATE_CLOSED;
|
|
|
|
|
2005-06-29 23:46:55 +02:00
|
|
|
hop->extend_info = extend_info_dup(choice);
|
2004-05-13 09:24:49 +02:00
|
|
|
|
2009-09-15 12:33:33 +02:00
|
|
|
hop->package_window = circuit_initial_package_window();
|
2004-05-13 09:24:49 +02:00
|
|
|
hop->deliver_window = CIRCWINDOW_START;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2005-06-09 21:03:31 +02:00
|
|
|
|
2007-06-12 11:17:23 +02:00
|
|
|
/** Allocate a new extend_info object based on the various arguments. */
|
|
|
|
extend_info_t *
|
2012-09-06 17:38:32 +02:00
|
|
|
extend_info_new(const char *nickname, const char *digest,
|
2012-01-18 21:53:30 +01:00
|
|
|
crypto_pk_t *onion_key,
|
2008-08-05 22:08:19 +02:00
|
|
|
const tor_addr_t *addr, uint16_t port)
|
2007-06-12 11:17:23 +02:00
|
|
|
{
|
|
|
|
extend_info_t *info = tor_malloc_zero(sizeof(extend_info_t));
|
|
|
|
memcpy(info->identity_digest, digest, DIGEST_LEN);
|
2007-08-28 02:00:32 +02:00
|
|
|
if (nickname)
|
|
|
|
strlcpy(info->nickname, nickname, sizeof(info->nickname));
|
2007-06-12 11:17:23 +02:00
|
|
|
if (onion_key)
|
|
|
|
info->onion_key = crypto_pk_dup_key(onion_key);
|
2008-08-05 22:08:19 +02:00
|
|
|
tor_addr_copy(&info->addr, addr);
|
2007-06-12 11:17:23 +02:00
|
|
|
info->port = port;
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
2011-11-24 18:29:56 +01:00
|
|
|
/** Allocate and return a new extend_info that can be used to build a
|
2012-01-26 00:54:59 +01:00
|
|
|
* circuit to or through the node <b>node</b>. Use the primary address
|
2012-08-27 15:03:34 +02:00
|
|
|
* of the node (i.e. its IPv4 address) unless
|
|
|
|
* <b>for_direct_connect</b> is true, in which case the preferred
|
|
|
|
* address is used instead. May return NULL if there is not enough
|
|
|
|
* info about <b>node</b> to extend to it--for example, if there is no
|
|
|
|
* routerinfo_t or microdesc_t.
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
**/
|
|
|
|
extend_info_t *
|
2011-11-24 18:29:56 +01:00
|
|
|
extend_info_from_node(const node_t *node, int for_direct_connect)
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
{
|
2012-08-31 23:02:19 +02:00
|
|
|
tor_addr_port_t ap;
|
|
|
|
|
|
|
|
if (node->ri == NULL && (node->rs == NULL || node->md == NULL))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (for_direct_connect)
|
|
|
|
node_get_pref_orport(node, &ap);
|
|
|
|
else
|
|
|
|
node_get_prim_orport(node, &ap);
|
|
|
|
|
|
|
|
log_debug(LD_CIRC, "using %s:%d for %s",
|
|
|
|
fmt_and_decorate_addr(&ap.addr), ap.port,
|
|
|
|
node->ri ? node->ri->nickname : node->rs->nickname);
|
|
|
|
|
|
|
|
if (node->ri)
|
2012-09-06 17:38:32 +02:00
|
|
|
return extend_info_new(node->ri->nickname,
|
2012-08-31 23:02:19 +02:00
|
|
|
node->identity,
|
|
|
|
node->ri->onion_pkey,
|
|
|
|
&ap.addr,
|
|
|
|
ap.port);
|
|
|
|
else if (node->rs && node->md)
|
2012-09-06 17:38:32 +02:00
|
|
|
return extend_info_new(node->rs->nickname,
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
node->identity,
|
|
|
|
node->md->onion_pkey,
|
2012-08-31 23:02:19 +02:00
|
|
|
&ap.addr,
|
|
|
|
ap.port);
|
|
|
|
else
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2005-06-29 23:46:55 +02:00
|
|
|
/** Release storage held by an extend_info_t struct. */
|
|
|
|
void
|
|
|
|
extend_info_free(extend_info_t *info)
|
|
|
|
{
|
2009-09-28 16:37:01 +02:00
|
|
|
if (!info)
|
|
|
|
return;
|
2012-01-18 21:53:30 +01:00
|
|
|
crypto_pk_free(info->onion_key);
|
2005-06-29 23:46:55 +02:00
|
|
|
tor_free(info);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Allocate and return a new extend_info_t with the same contents as
|
|
|
|
* <b>info</b>. */
|
|
|
|
extend_info_t *
|
|
|
|
extend_info_dup(extend_info_t *info)
|
|
|
|
{
|
|
|
|
extend_info_t *newinfo;
|
|
|
|
tor_assert(info);
|
|
|
|
newinfo = tor_malloc(sizeof(extend_info_t));
|
|
|
|
memcpy(newinfo, info, sizeof(extend_info_t));
|
2007-01-27 20:29:16 +01:00
|
|
|
if (info->onion_key)
|
|
|
|
newinfo->onion_key = crypto_pk_dup_key(info->onion_key);
|
|
|
|
else
|
|
|
|
newinfo->onion_key = NULL;
|
2005-06-29 23:46:55 +02:00
|
|
|
return newinfo;
|
|
|
|
}
|
|
|
|
|
2005-12-26 06:52:44 +01:00
|
|
|
/** Return the routerinfo_t for the chosen exit router in <b>state</b>.
|
|
|
|
* If there is no chosen exit, or if we don't know the routerinfo_t for
|
|
|
|
* the chosen exit, return NULL.
|
2005-06-29 23:46:55 +02:00
|
|
|
*/
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
const node_t *
|
|
|
|
build_state_get_exit_node(cpath_build_state_t *state)
|
2005-06-29 23:46:55 +02:00
|
|
|
{
|
|
|
|
if (!state || !state->chosen_exit)
|
|
|
|
return NULL;
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
return node_get_by_id(state->chosen_exit->identity_digest);
|
2005-06-29 23:46:55 +02:00
|
|
|
}
|
|
|
|
|
2005-12-26 06:52:44 +01:00
|
|
|
/** Return the nickname for the chosen exit router in <b>state</b>. If
|
2005-06-29 23:46:55 +02:00
|
|
|
* there is no chosen exit, or if we don't know the routerinfo_t for the
|
|
|
|
* chosen exit, return NULL.
|
|
|
|
*/
|
|
|
|
const char *
|
|
|
|
build_state_get_exit_nickname(cpath_build_state_t *state)
|
|
|
|
{
|
|
|
|
if (!state || !state->chosen_exit)
|
|
|
|
return NULL;
|
|
|
|
return state->chosen_exit->nickname;
|
|
|
|
}
|
|
|
|
|
2006-09-29 01:57:52 +02:00
|
|
|
/** Check whether the entry guard <b>e</b> is usable, given the directory
|
2007-06-10 02:30:14 +02:00
|
|
|
* authorities' opinion about the router (stored in <b>ri</b>) and the user's
|
2006-10-07 01:37:07 +02:00
|
|
|
* configuration (in <b>options</b>). Set <b>e</b>->bad_since
|
2007-11-26 03:18:57 +01:00
|
|
|
* accordingly. Return true iff the entry guard's status changes.
|
|
|
|
*
|
|
|
|
* If it's not usable, set *<b>reason</b> to a static string explaining why.
|
|
|
|
*/
|
2006-09-29 01:57:44 +02:00
|
|
|
static int
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
entry_guard_set_status(entry_guard_t *e, const node_t *node,
|
2011-06-14 19:01:38 +02:00
|
|
|
time_t now, const or_options_t *options,
|
|
|
|
const char **reason)
|
2006-09-29 01:57:44 +02:00
|
|
|
{
|
|
|
|
char buf[HEX_DIGEST_LEN+1];
|
|
|
|
int changed = 0;
|
|
|
|
|
2007-11-26 03:18:57 +01:00
|
|
|
*reason = NULL;
|
|
|
|
|
2006-09-29 01:57:44 +02:00
|
|
|
/* Do we want to mark this guard as bad? */
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
if (!node)
|
2007-11-26 03:18:57 +01:00
|
|
|
*reason = "unlisted";
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
else if (!node->is_running)
|
2007-11-26 03:18:57 +01:00
|
|
|
*reason = "down";
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
else if (options->UseBridges && (!node->ri ||
|
|
|
|
node->ri->purpose != ROUTER_PURPOSE_BRIDGE))
|
2007-11-26 03:18:57 +01:00
|
|
|
*reason = "not a bridge";
|
2011-06-02 19:05:00 +02:00
|
|
|
else if (options->UseBridges && !node_is_a_configured_bridge(node))
|
2011-06-01 02:43:55 +02:00
|
|
|
*reason = "not a configured bridge";
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
else if (!options->UseBridges && !node->is_possible_guard &&
|
|
|
|
!routerset_contains_node(options->EntryNodes,node))
|
2007-11-26 03:18:57 +01:00
|
|
|
*reason = "not recommended as a guard";
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
else if (routerset_contains_node(options->ExcludeNodes, node))
|
2007-11-26 03:18:57 +01:00
|
|
|
*reason = "excluded";
|
2012-05-04 05:15:34 +02:00
|
|
|
else if (e->path_bias_disabled)
|
|
|
|
*reason = "path-biased";
|
2006-09-29 01:57:44 +02:00
|
|
|
|
2007-11-26 03:18:57 +01:00
|
|
|
if (*reason && ! e->bad_since) {
|
2006-09-29 01:57:44 +02:00
|
|
|
/* Router is newly bad. */
|
|
|
|
base16_encode(buf, sizeof(buf), e->identity, DIGEST_LEN);
|
2006-10-07 01:37:07 +02:00
|
|
|
log_info(LD_CIRC, "Entry guard %s (%s) is %s: marking as unusable.",
|
2007-11-26 03:18:57 +01:00
|
|
|
e->nickname, buf, *reason);
|
2006-09-29 01:57:44 +02:00
|
|
|
|
2006-10-07 01:37:07 +02:00
|
|
|
e->bad_since = now;
|
2006-12-15 23:40:20 +01:00
|
|
|
control_event_guard(e->nickname, e->identity, "BAD");
|
2006-09-29 01:57:44 +02:00
|
|
|
changed = 1;
|
2007-11-26 03:18:57 +01:00
|
|
|
} else if (!*reason && e->bad_since) {
|
2006-09-29 01:57:44 +02:00
|
|
|
/* There's nothing wrong with the router any more. */
|
|
|
|
base16_encode(buf, sizeof(buf), e->identity, DIGEST_LEN);
|
|
|
|
log_info(LD_CIRC, "Entry guard %s (%s) is no longer unusable: "
|
2006-10-07 01:37:07 +02:00
|
|
|
"marking as ok.", e->nickname, buf);
|
2006-09-29 01:57:44 +02:00
|
|
|
|
|
|
|
e->bad_since = 0;
|
2006-12-15 23:40:20 +01:00
|
|
|
control_event_guard(e->nickname, e->identity, "GOOD");
|
2006-09-29 01:57:44 +02:00
|
|
|
changed = 1;
|
|
|
|
}
|
|
|
|
return changed;
|
|
|
|
}
|
|
|
|
|
2007-07-22 02:16:48 +02:00
|
|
|
/** Return true iff enough time has passed since we last tried to connect
|
|
|
|
* to the unreachable guard <b>e</b> that we're willing to try again. */
|
2006-09-29 01:57:44 +02:00
|
|
|
static int
|
|
|
|
entry_is_time_to_retry(entry_guard_t *e, time_t now)
|
|
|
|
{
|
|
|
|
long diff;
|
|
|
|
if (e->last_attempted < e->unreachable_since)
|
|
|
|
return 1;
|
|
|
|
diff = now - e->unreachable_since;
|
|
|
|
if (diff < 6*60*60)
|
|
|
|
return now > (e->last_attempted + 60*60);
|
|
|
|
else if (diff < 3*24*60*60)
|
|
|
|
return now > (e->last_attempted + 4*60*60);
|
|
|
|
else if (diff < 7*24*60*60)
|
|
|
|
return now > (e->last_attempted + 18*60*60);
|
|
|
|
else
|
|
|
|
return now > (e->last_attempted + 36*60*60);
|
|
|
|
}
|
|
|
|
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
/** Return the node corresponding to <b>e</b>, if <b>e</b> is
|
2005-12-28 10:07:31 +01:00
|
|
|
* working well enough that we are willing to use it as an entry
|
2005-12-27 08:23:52 +01:00
|
|
|
* right now. (Else return NULL.) In particular, it must be
|
|
|
|
* - Listed as either up or never yet contacted;
|
|
|
|
* - Present in the routerlist;
|
2009-05-27 23:55:51 +02:00
|
|
|
* - Listed as 'stable' or 'fast' by the current dirserver consensus,
|
2009-09-20 04:59:14 +02:00
|
|
|
* if demanded by <b>need_uptime</b> or <b>need_capacity</b>
|
|
|
|
* (unless it's a configured EntryNode);
|
2007-07-22 02:16:48 +02:00
|
|
|
* - Allowed by our current ReachableORAddresses config option; and
|
2009-09-20 04:59:14 +02:00
|
|
|
* - Currently thought to be reachable by us (unless <b>assume_reachable</b>
|
2006-09-29 01:57:52 +02:00
|
|
|
* is true).
|
2009-09-20 04:59:14 +02:00
|
|
|
*
|
|
|
|
* If the answer is no, set *<b>msg</b> to an explanation of why.
|
2005-12-27 08:23:52 +01:00
|
|
|
*/
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
static INLINE const node_t *
|
2006-09-29 01:57:44 +02:00
|
|
|
entry_is_live(entry_guard_t *e, int need_uptime, int need_capacity,
|
2009-09-20 04:59:14 +02:00
|
|
|
int assume_reachable, const char **msg)
|
2005-12-27 08:23:52 +01:00
|
|
|
{
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
const node_t *node;
|
2011-06-14 19:01:38 +02:00
|
|
|
const or_options_t *options = get_options();
|
2009-09-20 04:59:14 +02:00
|
|
|
tor_assert(msg);
|
|
|
|
|
2012-05-04 05:15:34 +02:00
|
|
|
if (e->path_bias_disabled) {
|
|
|
|
*msg = "path-biased";
|
|
|
|
return NULL;
|
|
|
|
}
|
2009-09-20 04:59:14 +02:00
|
|
|
if (e->bad_since) {
|
|
|
|
*msg = "bad";
|
2006-09-29 01:57:44 +02:00
|
|
|
return NULL;
|
2009-09-20 04:59:14 +02:00
|
|
|
}
|
2007-02-23 19:34:35 +01:00
|
|
|
/* no good if it's unreachable, unless assume_unreachable or can_retry. */
|
2008-06-11 01:00:11 +02:00
|
|
|
if (!assume_reachable && !e->can_retry &&
|
2009-09-20 04:59:14 +02:00
|
|
|
e->unreachable_since && !entry_is_time_to_retry(e, time(NULL))) {
|
|
|
|
*msg = "unreachable";
|
2005-12-27 08:23:52 +01:00
|
|
|
return NULL;
|
2009-09-20 04:59:14 +02:00
|
|
|
}
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
node = node_get_by_id(e->identity);
|
2010-10-05 05:33:50 +02:00
|
|
|
if (!node || !node_has_descriptor(node)) {
|
2009-09-20 04:59:14 +02:00
|
|
|
*msg = "no descriptor";
|
2005-12-27 08:23:52 +01:00
|
|
|
return NULL;
|
2009-09-20 04:59:14 +02:00
|
|
|
}
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
if (get_options()->UseBridges) {
|
|
|
|
if (node_get_purpose(node) != ROUTER_PURPOSE_BRIDGE) {
|
|
|
|
*msg = "not a bridge";
|
|
|
|
return NULL;
|
|
|
|
}
|
2011-06-02 19:05:00 +02:00
|
|
|
if (!node_is_a_configured_bridge(node)) {
|
2011-06-01 02:43:55 +02:00
|
|
|
*msg = "not a configured bridge";
|
|
|
|
return NULL;
|
|
|
|
}
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
} else { /* !get_options()->UseBridges */
|
|
|
|
if (node_get_purpose(node) != ROUTER_PURPOSE_GENERAL) {
|
|
|
|
*msg = "not general-purpose";
|
|
|
|
return NULL;
|
|
|
|
}
|
2009-09-20 04:59:14 +02:00
|
|
|
}
|
2011-07-07 17:52:13 +02:00
|
|
|
if (routerset_contains_node(options->EntryNodes, node)) {
|
2009-09-20 05:00:28 +02:00
|
|
|
/* they asked for it, they get it */
|
|
|
|
need_uptime = need_capacity = 0;
|
|
|
|
}
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
if (node_is_unreliable(node, need_uptime, need_capacity, 0)) {
|
2009-09-20 04:59:14 +02:00
|
|
|
*msg = "not fast/stable";
|
2005-12-27 08:23:52 +01:00
|
|
|
return NULL;
|
2009-09-20 04:59:14 +02:00
|
|
|
}
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
if (!fascist_firewall_allows_node(node)) {
|
2009-09-20 04:59:14 +02:00
|
|
|
*msg = "unreachable by config";
|
2005-12-27 08:23:52 +01:00
|
|
|
return NULL;
|
2009-09-20 04:59:14 +02:00
|
|
|
}
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
return node;
|
2005-12-27 08:23:52 +01:00
|
|
|
}
|
|
|
|
|
2006-01-10 23:42:44 +01:00
|
|
|
/** Return the number of entry guards that we think are usable. */
|
2005-07-22 19:32:25 +02:00
|
|
|
static int
|
2006-01-10 23:42:44 +01:00
|
|
|
num_live_entry_guards(void)
|
2005-07-22 19:32:25 +02:00
|
|
|
{
|
|
|
|
int n = 0;
|
2009-09-20 04:59:14 +02:00
|
|
|
const char *msg;
|
2006-01-10 23:42:44 +01:00
|
|
|
if (! entry_guards)
|
2005-07-23 06:12:35 +02:00
|
|
|
return 0;
|
2006-01-10 23:42:44 +01:00
|
|
|
SMARTLIST_FOREACH(entry_guards, entry_guard_t *, entry,
|
2005-12-27 08:23:52 +01:00
|
|
|
{
|
2009-09-20 04:59:14 +02:00
|
|
|
if (entry_is_live(entry, 0, 1, 0, &msg))
|
2005-12-27 08:23:52 +01:00
|
|
|
++n;
|
|
|
|
});
|
2005-07-22 19:32:25 +02:00
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2007-06-15 20:32:27 +02:00
|
|
|
/** If <b>digest</b> matches the identity of any node in the
|
|
|
|
* entry_guards list, return that node. Else return NULL. */
|
2012-05-04 05:15:34 +02:00
|
|
|
static entry_guard_t *
|
|
|
|
entry_guard_get_by_id_digest(const char *digest)
|
2005-12-27 08:23:52 +01:00
|
|
|
{
|
2006-01-10 23:42:44 +01:00
|
|
|
SMARTLIST_FOREACH(entry_guards, entry_guard_t *, entry,
|
2011-05-10 22:23:43 +02:00
|
|
|
if (tor_memeq(digest, entry->identity, DIGEST_LEN))
|
2007-06-15 20:32:27 +02:00
|
|
|
return entry;
|
2005-12-27 08:23:52 +01:00
|
|
|
);
|
2007-06-15 20:32:27 +02:00
|
|
|
return NULL;
|
2005-12-27 08:23:52 +01:00
|
|
|
}
|
|
|
|
|
2006-09-29 01:57:52 +02:00
|
|
|
/** Dump a description of our list of entry guards to the log at level
|
2006-10-07 02:50:39 +02:00
|
|
|
* <b>severity</b>. */
|
2005-12-31 07:32:57 +01:00
|
|
|
static void
|
2006-01-10 23:42:44 +01:00
|
|
|
log_entry_guards(int severity)
|
2005-12-31 07:32:57 +01:00
|
|
|
{
|
2012-01-18 21:53:30 +01:00
|
|
|
smartlist_t *elements = smartlist_new();
|
2005-12-31 07:32:57 +01:00
|
|
|
char *s;
|
|
|
|
|
2011-05-16 03:58:46 +02:00
|
|
|
SMARTLIST_FOREACH_BEGIN(entry_guards, entry_guard_t *, e)
|
2005-12-31 07:32:57 +01:00
|
|
|
{
|
2009-09-20 04:59:14 +02:00
|
|
|
const char *msg = NULL;
|
|
|
|
if (entry_is_live(e, 0, 1, 0, &msg))
|
2012-01-11 19:44:10 +01:00
|
|
|
smartlist_add_asprintf(elements, "%s [%s] (up %s)",
|
2009-09-20 04:59:14 +02:00
|
|
|
e->nickname,
|
2011-05-16 03:58:46 +02:00
|
|
|
hex_str(e->identity, DIGEST_LEN),
|
2009-09-20 04:59:14 +02:00
|
|
|
e->made_contact ? "made-contact" : "never-contacted");
|
|
|
|
else
|
2012-01-11 19:44:10 +01:00
|
|
|
smartlist_add_asprintf(elements, "%s [%s] (%s, %s)",
|
2011-05-16 03:58:46 +02:00
|
|
|
e->nickname,
|
|
|
|
hex_str(e->identity, DIGEST_LEN),
|
|
|
|
msg,
|
2009-09-20 04:59:14 +02:00
|
|
|
e->made_contact ? "made-contact" : "never-contacted");
|
2011-05-16 03:58:46 +02:00
|
|
|
}
|
|
|
|
SMARTLIST_FOREACH_END(e);
|
2005-12-31 07:32:57 +01:00
|
|
|
|
|
|
|
s = smartlist_join_strings(elements, ",", 0, NULL);
|
|
|
|
SMARTLIST_FOREACH(elements, char*, cp, tor_free(cp));
|
|
|
|
smartlist_free(elements);
|
|
|
|
log_fn(severity,LD_CIRC,"%s",s);
|
|
|
|
tor_free(s);
|
|
|
|
}
|
|
|
|
|
2007-01-24 01:43:52 +01:00
|
|
|
/** Called when one or more guards that we would previously have used for some
|
|
|
|
* purpose are no longer in use because a higher-priority guard has become
|
2009-05-27 23:55:51 +02:00
|
|
|
* usable again. */
|
2006-12-15 23:40:20 +01:00
|
|
|
static void
|
|
|
|
control_event_guard_deferred(void)
|
|
|
|
{
|
2007-01-24 01:43:52 +01:00
|
|
|
/* XXXX We don't actually have a good way to figure out _how many_ entries
|
|
|
|
* are live for some purpose. We need an entry_is_even_slightly_live()
|
|
|
|
* function for this to work right. NumEntryGuards isn't reliable: if we
|
|
|
|
* need guards with weird properties, we can have more than that number
|
|
|
|
* live.
|
|
|
|
**/
|
2006-12-15 23:40:20 +01:00
|
|
|
#if 0
|
|
|
|
int n = 0;
|
2009-09-20 04:59:14 +02:00
|
|
|
const char *msg;
|
2011-06-14 19:01:38 +02:00
|
|
|
const or_options_t *options = get_options();
|
2006-12-15 23:40:20 +01:00
|
|
|
if (!entry_guards)
|
|
|
|
return;
|
|
|
|
SMARTLIST_FOREACH(entry_guards, entry_guard_t *, entry,
|
|
|
|
{
|
2009-09-20 04:59:14 +02:00
|
|
|
if (entry_is_live(entry, 0, 1, 0, &msg)) {
|
2006-12-15 23:40:20 +01:00
|
|
|
if (n++ == options->NumEntryGuards) {
|
|
|
|
control_event_guard(entry->nickname, entry->identity, "DEFERRED");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2006-06-09 11:02:32 +02:00
|
|
|
/** Add a new (preferably stable and fast) router to our
|
2006-01-10 23:42:44 +01:00
|
|
|
* entry_guards list. Return a pointer to the router if we succeed,
|
2005-12-31 07:32:57 +01:00
|
|
|
* or NULL if we can't find any more suitable entries.
|
2005-12-28 10:07:31 +01:00
|
|
|
*
|
2005-12-31 07:32:57 +01:00
|
|
|
* If <b>chosen</b> is defined, use that one, and if it's not
|
2006-01-10 23:42:44 +01:00
|
|
|
* already in our entry_guards list, put it at the *beginning*.
|
2005-12-31 07:32:57 +01:00
|
|
|
* Else, put the one we pick at the end of the list. */
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
static const node_t *
|
Revise code for adding EntryNodes to guards.
Previously, we'd just take all the nodes in EntryNodes, see which
ones were already in the guard list, and add the ones that weren't.
There were some problems there, though:
* We'd add _every_ entry in EntryNodes, and add them in the order
they appeared in the routerlist. This wasn't a problem
until we added the ability to give country-code or IP-range
entries in the EntryNodes set, but now that we did, it is.
(Fix: We now shuffle the entry nodes before adding them; only
add up to 10*NumEntryGuards)
* We didn't screen EntryNodes for the Guard flag. That's okay
if the user has specified two or three entry nodes manually,
but if they have listed a whole subcontinent, we should
restrict ourselves to the entries that are currently guards.
(Fix: separate out the new guard from the new non-guard nodes,
and add the Guards first.)
* We'd prepend new EntryNodes _before_ the already configured
EntryNodes. This could lead to churn.
(Fix: don't prepend these.)
This patch also pre-screens EntryNodes entries for
reachableaddresses/excludenodes, even though we check for that
later. This is important now, since we cap the number of entries
we'll add.
2011-07-11 16:48:46 +02:00
|
|
|
add_an_entry_guard(const node_t *chosen, int reset_status, int prepend)
|
2005-12-27 08:23:52 +01:00
|
|
|
{
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
const node_t *node;
|
2006-01-10 23:42:44 +01:00
|
|
|
entry_guard_t *entry;
|
2005-12-31 07:32:57 +01:00
|
|
|
|
2006-06-09 11:07:59 +02:00
|
|
|
if (chosen) {
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
node = chosen;
|
2012-05-04 05:15:34 +02:00
|
|
|
entry = entry_guard_get_by_id_digest(node->identity);
|
2007-06-15 20:32:27 +02:00
|
|
|
if (entry) {
|
2007-12-24 11:31:39 +01:00
|
|
|
if (reset_status) {
|
2007-06-15 20:32:27 +02:00
|
|
|
entry->bad_since = 0;
|
2007-12-24 11:31:39 +01:00
|
|
|
entry->can_retry = 1;
|
|
|
|
}
|
2006-06-09 11:07:59 +02:00
|
|
|
return NULL;
|
2007-06-15 20:32:27 +02:00
|
|
|
}
|
2006-06-09 11:07:59 +02:00
|
|
|
} else {
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
node = choose_good_entry_server(CIRCUIT_PURPOSE_C_GENERAL, NULL);
|
|
|
|
if (!node)
|
2006-06-09 11:07:59 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
2006-01-10 23:42:44 +01:00
|
|
|
entry = tor_malloc_zero(sizeof(entry_guard_t));
|
2011-05-30 21:41:46 +02:00
|
|
|
log_info(LD_CIRC, "Chose %s as new entry guard.",
|
|
|
|
node_describe(node));
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
strlcpy(entry->nickname, node_get_nickname(node), sizeof(entry->nickname));
|
|
|
|
memcpy(entry->identity, node->identity, DIGEST_LEN);
|
2010-01-19 23:52:52 +01:00
|
|
|
/* Choose expiry time smudged over the past month. The goal here
|
|
|
|
* is to a) spread out when Tor clients rotate their guards, so they
|
|
|
|
* don't all select them on the same day, and b) avoid leaving a
|
|
|
|
* precise timestamp in the state file about when we first picked
|
|
|
|
* this guard. For details, see the Jan 2010 or-dev thread. */
|
|
|
|
entry->chosen_on_date = time(NULL) - crypto_rand_int(3600*24*30);
|
2007-08-29 19:22:00 +02:00
|
|
|
entry->chosen_by_version = tor_strdup(VERSION);
|
Revise code for adding EntryNodes to guards.
Previously, we'd just take all the nodes in EntryNodes, see which
ones were already in the guard list, and add the ones that weren't.
There were some problems there, though:
* We'd add _every_ entry in EntryNodes, and add them in the order
they appeared in the routerlist. This wasn't a problem
until we added the ability to give country-code or IP-range
entries in the EntryNodes set, but now that we did, it is.
(Fix: We now shuffle the entry nodes before adding them; only
add up to 10*NumEntryGuards)
* We didn't screen EntryNodes for the Guard flag. That's okay
if the user has specified two or three entry nodes manually,
but if they have listed a whole subcontinent, we should
restrict ourselves to the entries that are currently guards.
(Fix: separate out the new guard from the new non-guard nodes,
and add the Guards first.)
* We'd prepend new EntryNodes _before_ the already configured
EntryNodes. This could lead to churn.
(Fix: don't prepend these.)
This patch also pre-screens EntryNodes entries for
reachableaddresses/excludenodes, even though we check for that
later. This is important now, since we cap the number of entries
we'll add.
2011-07-11 16:48:46 +02:00
|
|
|
if (prepend)
|
2006-01-10 23:42:44 +01:00
|
|
|
smartlist_insert(entry_guards, 0, entry);
|
Revise code for adding EntryNodes to guards.
Previously, we'd just take all the nodes in EntryNodes, see which
ones were already in the guard list, and add the ones that weren't.
There were some problems there, though:
* We'd add _every_ entry in EntryNodes, and add them in the order
they appeared in the routerlist. This wasn't a problem
until we added the ability to give country-code or IP-range
entries in the EntryNodes set, but now that we did, it is.
(Fix: We now shuffle the entry nodes before adding them; only
add up to 10*NumEntryGuards)
* We didn't screen EntryNodes for the Guard flag. That's okay
if the user has specified two or three entry nodes manually,
but if they have listed a whole subcontinent, we should
restrict ourselves to the entries that are currently guards.
(Fix: separate out the new guard from the new non-guard nodes,
and add the Guards first.)
* We'd prepend new EntryNodes _before_ the already configured
EntryNodes. This could lead to churn.
(Fix: don't prepend these.)
This patch also pre-screens EntryNodes entries for
reachableaddresses/excludenodes, even though we check for that
later. This is important now, since we cap the number of entries
we'll add.
2011-07-11 16:48:46 +02:00
|
|
|
else
|
2006-01-10 23:42:44 +01:00
|
|
|
smartlist_add(entry_guards, entry);
|
2006-12-15 23:40:20 +01:00
|
|
|
control_event_guard(entry->nickname, entry->identity, "NEW");
|
|
|
|
control_event_guard_deferred();
|
2006-01-10 23:42:44 +01:00
|
|
|
log_entry_guards(LOG_INFO);
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
return node;
|
2005-12-27 08:23:52 +01:00
|
|
|
}
|
|
|
|
|
2006-01-10 23:42:44 +01:00
|
|
|
/** If the use of entry guards is configured, choose more entry guards
|
2005-12-26 06:52:44 +01:00
|
|
|
* until we have enough in the list. */
|
2005-07-22 19:32:25 +02:00
|
|
|
static void
|
2011-06-14 19:01:38 +02:00
|
|
|
pick_entry_guards(const or_options_t *options)
|
2005-07-22 19:32:25 +02:00
|
|
|
{
|
2005-08-04 21:56:41 +02:00
|
|
|
int changed = 0;
|
2005-07-22 19:32:25 +02:00
|
|
|
|
2006-01-10 23:42:44 +01:00
|
|
|
tor_assert(entry_guards);
|
2005-07-22 19:32:25 +02:00
|
|
|
|
2006-01-10 23:42:44 +01:00
|
|
|
while (num_live_entry_guards() < options->NumEntryGuards) {
|
Revise code for adding EntryNodes to guards.
Previously, we'd just take all the nodes in EntryNodes, see which
ones were already in the guard list, and add the ones that weren't.
There were some problems there, though:
* We'd add _every_ entry in EntryNodes, and add them in the order
they appeared in the routerlist. This wasn't a problem
until we added the ability to give country-code or IP-range
entries in the EntryNodes set, but now that we did, it is.
(Fix: We now shuffle the entry nodes before adding them; only
add up to 10*NumEntryGuards)
* We didn't screen EntryNodes for the Guard flag. That's okay
if the user has specified two or three entry nodes manually,
but if they have listed a whole subcontinent, we should
restrict ourselves to the entries that are currently guards.
(Fix: separate out the new guard from the new non-guard nodes,
and add the Guards first.)
* We'd prepend new EntryNodes _before_ the already configured
EntryNodes. This could lead to churn.
(Fix: don't prepend these.)
This patch also pre-screens EntryNodes entries for
reachableaddresses/excludenodes, even though we check for that
later. This is important now, since we cap the number of entries
we'll add.
2011-07-11 16:48:46 +02:00
|
|
|
if (!add_an_entry_guard(NULL, 0, 0))
|
2005-12-27 08:23:52 +01:00
|
|
|
break;
|
2005-08-04 21:56:41 +02:00
|
|
|
changed = 1;
|
2005-07-22 19:32:25 +02:00
|
|
|
}
|
2005-08-04 21:56:41 +02:00
|
|
|
if (changed)
|
2006-01-10 23:42:44 +01:00
|
|
|
entry_guards_changed();
|
2005-07-22 19:32:25 +02:00
|
|
|
}
|
|
|
|
|
2006-09-29 01:57:44 +02:00
|
|
|
/** How long (in seconds) do we allow an entry guard to be nonfunctional,
|
2006-10-07 01:37:07 +02:00
|
|
|
* unlisted, excluded, or otherwise nonusable before we give up on it? */
|
2006-09-29 01:57:44 +02:00
|
|
|
#define ENTRY_GUARD_REMOVE_AFTER (30*24*60*60)
|
2005-07-22 19:32:25 +02:00
|
|
|
|
2007-08-29 19:22:00 +02:00
|
|
|
/** Release all storage held by <b>e</b>. */
|
|
|
|
static void
|
|
|
|
entry_guard_free(entry_guard_t *e)
|
|
|
|
{
|
2009-09-28 16:37:01 +02:00
|
|
|
if (!e)
|
|
|
|
return;
|
2007-08-29 19:22:00 +02:00
|
|
|
tor_free(e->chosen_by_version);
|
|
|
|
tor_free(e);
|
|
|
|
}
|
|
|
|
|
2007-10-04 18:21:58 +02:00
|
|
|
/** Remove any entry guard which was selected by an unknown version of Tor,
|
|
|
|
* or which was selected by a version of Tor that's known to select
|
2012-05-16 17:18:21 +02:00
|
|
|
* entry guards badly, or which was selected more 2 months ago. */
|
|
|
|
/* XXXX The "obsolete guards" and "chosen long ago guards" things should
|
|
|
|
* probably be different functions. */
|
2007-08-29 19:22:00 +02:00
|
|
|
static int
|
2010-09-24 04:10:13 +02:00
|
|
|
remove_obsolete_entry_guards(time_t now)
|
2007-08-29 19:22:00 +02:00
|
|
|
{
|
2007-09-01 19:50:29 +02:00
|
|
|
int changed = 0, i;
|
2009-04-11 14:00:18 +02:00
|
|
|
|
2007-08-29 19:22:00 +02:00
|
|
|
for (i = 0; i < smartlist_len(entry_guards); ++i) {
|
|
|
|
entry_guard_t *entry = smartlist_get(entry_guards, i);
|
|
|
|
const char *ver = entry->chosen_by_version;
|
|
|
|
const char *msg = NULL;
|
|
|
|
tor_version_t v;
|
2009-04-11 14:06:27 +02:00
|
|
|
int version_is_bad = 0, date_is_bad = 0;
|
2007-08-29 19:22:00 +02:00
|
|
|
if (!ver) {
|
|
|
|
msg = "does not say what version of Tor it was selected by";
|
2009-04-11 14:06:27 +02:00
|
|
|
version_is_bad = 1;
|
2007-08-29 19:22:00 +02:00
|
|
|
} else if (tor_version_parse(ver, &v)) {
|
|
|
|
msg = "does not seem to be from any recognized version of Tor";
|
2009-04-11 14:06:27 +02:00
|
|
|
version_is_bad = 1;
|
2010-01-19 23:30:52 +01:00
|
|
|
} else {
|
2012-01-11 20:02:59 +01:00
|
|
|
char *tor_ver = NULL;
|
|
|
|
tor_asprintf(&tor_ver, "Tor %s", ver);
|
2010-01-19 23:30:52 +01:00
|
|
|
if ((tor_version_as_new_as(tor_ver, "0.1.0.10-alpha") &&
|
|
|
|
!tor_version_as_new_as(tor_ver, "0.1.2.16-dev")) ||
|
|
|
|
(tor_version_as_new_as(tor_ver, "0.2.0.0-alpha") &&
|
|
|
|
!tor_version_as_new_as(tor_ver, "0.2.0.6-alpha")) ||
|
|
|
|
/* above are bug 440; below are bug 1217 */
|
|
|
|
(tor_version_as_new_as(tor_ver, "0.2.1.3-alpha") &&
|
|
|
|
!tor_version_as_new_as(tor_ver, "0.2.1.23")) ||
|
|
|
|
(tor_version_as_new_as(tor_ver, "0.2.2.0-alpha") &&
|
|
|
|
!tor_version_as_new_as(tor_ver, "0.2.2.7-alpha"))) {
|
|
|
|
msg = "was selected without regard for guard bandwidth";
|
|
|
|
version_is_bad = 1;
|
|
|
|
}
|
|
|
|
tor_free(tor_ver);
|
|
|
|
}
|
2010-01-19 23:52:52 +01:00
|
|
|
if (!version_is_bad && entry->chosen_on_date + 3600*24*60 < now) {
|
|
|
|
/* It's been 2 months since the date listed in our state file. */
|
2009-04-11 14:00:18 +02:00
|
|
|
msg = "was selected several months ago";
|
2009-04-11 14:06:27 +02:00
|
|
|
date_is_bad = 1;
|
2007-08-29 19:22:00 +02:00
|
|
|
}
|
2009-04-11 14:00:18 +02:00
|
|
|
|
2009-04-11 14:06:27 +02:00
|
|
|
if (version_is_bad || date_is_bad) { /* we need to drop it */
|
2007-08-29 19:22:00 +02:00
|
|
|
char dbuf[HEX_DIGEST_LEN+1];
|
2009-04-11 14:06:27 +02:00
|
|
|
tor_assert(msg);
|
2007-08-29 19:22:00 +02:00
|
|
|
base16_encode(dbuf, sizeof(dbuf), entry->identity, DIGEST_LEN);
|
2009-04-11 14:06:27 +02:00
|
|
|
log_fn(version_is_bad ? LOG_NOTICE : LOG_INFO, LD_CIRC,
|
|
|
|
"Entry guard '%s' (%s) %s. (Version=%s.) Replacing it.",
|
|
|
|
entry->nickname, dbuf, msg, ver?escaped(ver):"none");
|
2007-08-29 19:22:00 +02:00
|
|
|
control_event_guard(entry->nickname, entry->identity, "DROPPED");
|
|
|
|
entry_guard_free(entry);
|
|
|
|
smartlist_del_keeporder(entry_guards, i--);
|
|
|
|
log_entry_guards(LOG_INFO);
|
|
|
|
changed = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return changed ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
2006-01-10 23:42:44 +01:00
|
|
|
/** Remove all entry guards that have been down or unlisted for so
|
2005-12-27 08:23:52 +01:00
|
|
|
* long that we don't think they'll come up again. Return 1 if we
|
|
|
|
* removed any, or 0 if we did nothing. */
|
|
|
|
static int
|
2010-09-24 04:10:13 +02:00
|
|
|
remove_dead_entry_guards(time_t now)
|
2005-07-22 19:32:25 +02:00
|
|
|
{
|
|
|
|
char dbuf[HEX_DIGEST_LEN+1];
|
|
|
|
char tbuf[ISO_TIME_LEN+1];
|
|
|
|
int i;
|
2005-12-11 12:56:17 +01:00
|
|
|
int changed = 0;
|
2005-07-22 19:32:25 +02:00
|
|
|
|
2006-01-10 23:42:44 +01:00
|
|
|
for (i = 0; i < smartlist_len(entry_guards); ) {
|
|
|
|
entry_guard_t *entry = smartlist_get(entry_guards, i);
|
2006-09-29 01:57:44 +02:00
|
|
|
if (entry->bad_since &&
|
2012-05-04 05:15:34 +02:00
|
|
|
! entry->path_bias_disabled &&
|
2006-09-29 01:57:44 +02:00
|
|
|
entry->bad_since + ENTRY_GUARD_REMOVE_AFTER < now) {
|
|
|
|
|
2005-12-28 10:07:31 +01:00
|
|
|
base16_encode(dbuf, sizeof(dbuf), entry->identity, DIGEST_LEN);
|
2006-09-29 01:57:44 +02:00
|
|
|
format_local_iso_time(tbuf, entry->bad_since);
|
|
|
|
log_info(LD_CIRC, "Entry guard '%s' (%s) has been down or unlisted "
|
2006-12-15 00:39:14 +01:00
|
|
|
"since %s local time; removing.",
|
2006-09-29 01:57:44 +02:00
|
|
|
entry->nickname, dbuf, tbuf);
|
2006-12-15 23:40:20 +01:00
|
|
|
control_event_guard(entry->nickname, entry->identity, "DROPPED");
|
2007-08-29 19:22:00 +02:00
|
|
|
entry_guard_free(entry);
|
2006-01-10 23:42:44 +01:00
|
|
|
smartlist_del_keeporder(entry_guards, i);
|
|
|
|
log_entry_guards(LOG_INFO);
|
2005-12-13 03:52:38 +01:00
|
|
|
changed = 1;
|
2005-07-22 19:32:25 +02:00
|
|
|
} else
|
|
|
|
++i;
|
|
|
|
}
|
2005-12-27 08:23:52 +01:00
|
|
|
return changed ? 1 : 0;
|
2005-07-22 19:32:25 +02:00
|
|
|
}
|
|
|
|
|
2005-12-25 00:32:35 +01:00
|
|
|
/** A new directory or router-status has arrived; update the down/listed
|
2006-01-10 23:42:44 +01:00
|
|
|
* status of the entry guards.
|
2005-07-23 06:12:35 +02:00
|
|
|
*
|
2005-12-28 10:07:31 +01:00
|
|
|
* An entry is 'down' if the directory lists it as nonrunning.
|
|
|
|
* An entry is 'unlisted' if the directory doesn't include it.
|
2007-11-26 03:18:57 +01:00
|
|
|
*
|
|
|
|
* Don't call this on startup; only on a fresh download. Otherwise we'll
|
|
|
|
* think that things are unlisted.
|
2005-07-23 06:12:35 +02:00
|
|
|
*/
|
2005-07-22 19:32:25 +02:00
|
|
|
void
|
2011-06-14 19:01:38 +02:00
|
|
|
entry_guards_compute_status(const or_options_t *options, time_t now)
|
2005-07-22 19:32:25 +02:00
|
|
|
{
|
|
|
|
int changed = 0;
|
2008-12-29 21:17:20 +01:00
|
|
|
digestmap_t *reasons;
|
2009-09-20 02:56:57 +02:00
|
|
|
|
2006-01-10 23:42:44 +01:00
|
|
|
if (! entry_guards)
|
2005-07-22 19:32:25 +02:00
|
|
|
return;
|
|
|
|
|
2009-09-20 02:56:57 +02:00
|
|
|
if (options->EntryNodes) /* reshuffle the entry guard list if needed */
|
|
|
|
entry_nodes_should_be_added();
|
2005-07-22 19:32:25 +02:00
|
|
|
|
2008-12-29 21:17:20 +01:00
|
|
|
reasons = digestmap_new();
|
|
|
|
SMARTLIST_FOREACH_BEGIN(entry_guards, entry_guard_t *, entry)
|
2005-07-22 19:32:25 +02:00
|
|
|
{
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
const node_t *r = node_get_by_id(entry->identity);
|
2007-11-26 03:18:57 +01:00
|
|
|
const char *reason = NULL;
|
|
|
|
if (entry_guard_set_status(entry, r, now, options, &reason))
|
2006-09-29 01:57:44 +02:00
|
|
|
changed = 1;
|
|
|
|
|
2007-11-26 03:18:57 +01:00
|
|
|
if (entry->bad_since)
|
|
|
|
tor_assert(reason);
|
2008-12-29 21:17:20 +01:00
|
|
|
if (reason)
|
|
|
|
digestmap_set(reasons, entry->identity, (char*)reason);
|
|
|
|
}
|
|
|
|
SMARTLIST_FOREACH_END(entry);
|
2005-07-22 19:32:25 +02:00
|
|
|
|
2010-09-24 04:10:13 +02:00
|
|
|
if (remove_dead_entry_guards(now))
|
2005-12-27 08:23:52 +01:00
|
|
|
changed = 1;
|
2012-05-16 17:28:36 +02:00
|
|
|
if (remove_obsolete_entry_guards(now))
|
|
|
|
changed = 1;
|
2005-12-27 08:23:52 +01:00
|
|
|
|
2005-07-28 21:01:48 +02:00
|
|
|
if (changed) {
|
2008-12-29 21:17:20 +01:00
|
|
|
SMARTLIST_FOREACH_BEGIN(entry_guards, entry_guard_t *, entry) {
|
|
|
|
const char *reason = digestmap_get(reasons, entry->identity);
|
2009-12-21 10:58:03 +01:00
|
|
|
const char *live_msg = "";
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
const node_t *r = entry_is_live(entry, 0, 1, 0, &live_msg);
|
2011-05-16 03:58:46 +02:00
|
|
|
log_info(LD_CIRC, "Summary: Entry %s [%s] is %s, %s%s%s, and %s%s.",
|
2008-03-17 05:07:51 +01:00
|
|
|
entry->nickname,
|
2011-05-16 03:58:46 +02:00
|
|
|
hex_str(entry->identity, DIGEST_LEN),
|
2008-03-17 05:07:51 +01:00
|
|
|
entry->unreachable_since ? "unreachable" : "reachable",
|
2008-06-07 00:31:36 +02:00
|
|
|
entry->bad_since ? "unusable" : "usable",
|
2008-12-29 21:17:20 +01:00
|
|
|
reason ? ", ": "",
|
|
|
|
reason ? reason : "",
|
2009-09-20 04:59:14 +02:00
|
|
|
r ? "live" : "not live / ",
|
|
|
|
r ? "" : live_msg);
|
2008-12-29 21:17:20 +01:00
|
|
|
} SMARTLIST_FOREACH_END(entry);
|
2008-03-17 05:07:51 +01:00
|
|
|
log_info(LD_CIRC, " (%d/%d entry guards are usable/new)",
|
|
|
|
num_live_entry_guards(), smartlist_len(entry_guards));
|
2006-01-10 23:42:44 +01:00
|
|
|
log_entry_guards(LOG_INFO);
|
|
|
|
entry_guards_changed();
|
2005-07-28 21:01:48 +02:00
|
|
|
}
|
2008-12-29 21:17:20 +01:00
|
|
|
|
|
|
|
digestmap_free(reasons, NULL);
|
2005-07-22 19:32:25 +02:00
|
|
|
}
|
|
|
|
|
2005-07-23 06:12:35 +02:00
|
|
|
/** Called when a connection to an OR with the identity digest <b>digest</b>
|
|
|
|
* is established (<b>succeeded</b>==1) or has failed (<b>succeeded</b>==0).
|
2005-12-28 10:07:31 +01:00
|
|
|
* If the OR is an entry, change that entry's up/down status.
|
2005-12-28 08:19:55 +01:00
|
|
|
* Return 0 normally, or -1 if we want to tear down the new connection.
|
2009-02-05 00:27:35 +01:00
|
|
|
*
|
|
|
|
* If <b>mark_relay_status</b>, also call router_set_status() on this
|
|
|
|
* relay.
|
|
|
|
*
|
2012-06-15 15:37:40 +02:00
|
|
|
* XXX024 change succeeded and mark_relay_status into 'int flags'.
|
2005-07-23 06:12:35 +02:00
|
|
|
*/
|
2005-12-28 08:19:55 +01:00
|
|
|
int
|
2006-10-07 01:37:07 +02:00
|
|
|
entry_guard_register_connect_status(const char *digest, int succeeded,
|
2009-02-05 00:27:35 +01:00
|
|
|
int mark_relay_status, time_t now)
|
2005-07-22 19:32:25 +02:00
|
|
|
{
|
2005-12-25 00:32:35 +01:00
|
|
|
int changed = 0;
|
2005-12-28 08:19:55 +01:00
|
|
|
int refuse_conn = 0;
|
2006-09-29 01:57:44 +02:00
|
|
|
int first_contact = 0;
|
|
|
|
entry_guard_t *entry = NULL;
|
|
|
|
int idx = -1;
|
|
|
|
char buf[HEX_DIGEST_LEN+1];
|
2005-12-25 00:32:35 +01:00
|
|
|
|
2006-01-10 23:42:44 +01:00
|
|
|
if (! entry_guards)
|
2005-12-28 08:19:55 +01:00
|
|
|
return 0;
|
2005-07-22 19:32:25 +02:00
|
|
|
|
2012-02-13 01:42:35 +01:00
|
|
|
SMARTLIST_FOREACH_BEGIN(entry_guards, entry_guard_t *, e) {
|
|
|
|
tor_assert(e);
|
|
|
|
if (tor_memeq(e->identity, digest, DIGEST_LEN)) {
|
|
|
|
entry = e;
|
|
|
|
idx = e_sl_idx;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} SMARTLIST_FOREACH_END(e);
|
2005-12-25 00:32:35 +01:00
|
|
|
|
2006-09-29 01:57:44 +02:00
|
|
|
if (!entry)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
base16_encode(buf, sizeof(buf), entry->identity, DIGEST_LEN);
|
|
|
|
|
|
|
|
if (succeeded) {
|
|
|
|
if (entry->unreachable_since) {
|
|
|
|
log_info(LD_CIRC, "Entry guard '%s' (%s) is now reachable again. Good.",
|
|
|
|
entry->nickname, buf);
|
2007-02-23 19:34:35 +01:00
|
|
|
entry->can_retry = 0;
|
2006-09-29 01:57:44 +02:00
|
|
|
entry->unreachable_since = 0;
|
2006-10-07 01:37:07 +02:00
|
|
|
entry->last_attempted = now;
|
2006-12-15 23:40:20 +01:00
|
|
|
control_event_guard(entry->nickname, entry->identity, "UP");
|
2006-09-29 01:57:44 +02:00
|
|
|
changed = 1;
|
|
|
|
}
|
|
|
|
if (!entry->made_contact) {
|
|
|
|
entry->made_contact = 1;
|
|
|
|
first_contact = changed = 1;
|
|
|
|
}
|
|
|
|
} else { /* ! succeeded */
|
|
|
|
if (!entry->made_contact) {
|
|
|
|
/* We've never connected to this one. */
|
|
|
|
log_info(LD_CIRC,
|
|
|
|
"Connection to never-contacted entry guard '%s' (%s) failed. "
|
|
|
|
"Removing from the list. %d/%d entry guards usable/new.",
|
|
|
|
entry->nickname, buf,
|
|
|
|
num_live_entry_guards()-1, smartlist_len(entry_guards)-1);
|
2010-01-11 19:16:50 +01:00
|
|
|
control_event_guard(entry->nickname, entry->identity, "DROPPED");
|
2007-11-15 12:14:08 +01:00
|
|
|
entry_guard_free(entry);
|
2006-09-29 01:57:44 +02:00
|
|
|
smartlist_del_keeporder(entry_guards, idx);
|
|
|
|
log_entry_guards(LOG_INFO);
|
|
|
|
changed = 1;
|
|
|
|
} else if (!entry->unreachable_since) {
|
|
|
|
log_info(LD_CIRC, "Unable to connect to entry guard '%s' (%s). "
|
|
|
|
"Marking as unreachable.", entry->nickname, buf);
|
2006-10-07 01:37:07 +02:00
|
|
|
entry->unreachable_since = entry->last_attempted = now;
|
2006-12-15 23:40:20 +01:00
|
|
|
control_event_guard(entry->nickname, entry->identity, "DOWN");
|
2006-09-29 01:57:44 +02:00
|
|
|
changed = 1;
|
2007-11-15 12:14:08 +01:00
|
|
|
entry->can_retry = 0; /* We gave it an early chance; no good. */
|
2006-09-29 01:57:44 +02:00
|
|
|
} else {
|
|
|
|
char tbuf[ISO_TIME_LEN+1];
|
|
|
|
format_iso_time(tbuf, entry->unreachable_since);
|
|
|
|
log_debug(LD_CIRC, "Failed to connect to unreachable entry guard "
|
|
|
|
"'%s' (%s). It has been unreachable since %s.",
|
|
|
|
entry->nickname, buf, tbuf);
|
2006-10-07 01:37:07 +02:00
|
|
|
entry->last_attempted = now;
|
2007-02-24 07:44:40 +01:00
|
|
|
entry->can_retry = 0; /* We gave it an early chance; no good. */
|
2007-11-15 12:14:08 +01:00
|
|
|
}
|
2006-09-29 01:57:44 +02:00
|
|
|
}
|
|
|
|
|
2009-02-05 00:27:35 +01:00
|
|
|
/* if the caller asked us to, also update the is_running flags for this
|
|
|
|
* relay */
|
|
|
|
if (mark_relay_status)
|
|
|
|
router_set_status(digest, succeeded);
|
|
|
|
|
2006-09-29 01:57:44 +02:00
|
|
|
if (first_contact) {
|
|
|
|
/* We've just added a new long-term entry guard. Perhaps the network just
|
|
|
|
* came back? We should give our earlier entries another try too,
|
|
|
|
* and close this connection so we don't use it before we've given
|
|
|
|
* the others a shot. */
|
2012-07-17 15:33:38 +02:00
|
|
|
SMARTLIST_FOREACH_BEGIN(entry_guards, entry_guard_t *, e) {
|
2006-09-29 01:57:44 +02:00
|
|
|
if (e == entry)
|
|
|
|
break;
|
|
|
|
if (e->made_contact) {
|
2009-09-20 04:59:14 +02:00
|
|
|
const char *msg;
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
const node_t *r = entry_is_live(e, 0, 1, 1, &msg);
|
2007-02-23 19:34:35 +01:00
|
|
|
if (r && e->unreachable_since) {
|
2006-09-29 01:57:44 +02:00
|
|
|
refuse_conn = 1;
|
2007-02-23 19:34:35 +01:00
|
|
|
e->can_retry = 1;
|
2006-09-29 01:57:44 +02:00
|
|
|
}
|
|
|
|
}
|
2012-07-17 15:33:38 +02:00
|
|
|
} SMARTLIST_FOREACH_END(e);
|
2006-09-29 01:57:44 +02:00
|
|
|
if (refuse_conn) {
|
|
|
|
log_info(LD_CIRC,
|
|
|
|
"Connected to new entry guard '%s' (%s). Marking earlier "
|
|
|
|
"entry guards up. %d/%d entry guards usable/new.",
|
|
|
|
entry->nickname, buf,
|
|
|
|
num_live_entry_guards(), smartlist_len(entry_guards));
|
|
|
|
log_entry_guards(LOG_INFO);
|
|
|
|
changed = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-12-25 00:32:35 +01:00
|
|
|
if (changed)
|
2006-01-10 23:42:44 +01:00
|
|
|
entry_guards_changed();
|
2005-12-28 08:19:55 +01:00
|
|
|
return refuse_conn ? -1 : 0;
|
2005-07-22 19:32:25 +02:00
|
|
|
}
|
|
|
|
|
2006-01-10 23:42:44 +01:00
|
|
|
/** When we try to choose an entry guard, should we parse and add
|
2005-12-31 07:32:57 +01:00
|
|
|
* config's EntryNodes first? */
|
|
|
|
static int should_add_entry_nodes = 0;
|
|
|
|
|
2006-09-29 01:57:52 +02:00
|
|
|
/** Called when the value of EntryNodes changes in our configuration. */
|
2005-12-31 07:32:57 +01:00
|
|
|
void
|
|
|
|
entry_nodes_should_be_added(void)
|
|
|
|
{
|
2009-09-20 02:56:57 +02:00
|
|
|
log_info(LD_CIRC, "EntryNodes config option set. Putting configured "
|
|
|
|
"relays at the front of the entry guard list.");
|
2005-12-31 07:32:57 +01:00
|
|
|
should_add_entry_nodes = 1;
|
|
|
|
}
|
|
|
|
|
2011-07-11 23:02:03 +02:00
|
|
|
/** Adjust the entry guards list so that it only contains entries from
|
|
|
|
* EntryNodes, adding new entries from EntryNodes to the list as needed. */
|
2007-02-28 01:23:05 +01:00
|
|
|
static void
|
2011-07-11 23:02:03 +02:00
|
|
|
entry_guards_set_from_config(const or_options_t *options)
|
2005-12-31 07:32:57 +01:00
|
|
|
{
|
Revise code for adding EntryNodes to guards.
Previously, we'd just take all the nodes in EntryNodes, see which
ones were already in the guard list, and add the ones that weren't.
There were some problems there, though:
* We'd add _every_ entry in EntryNodes, and add them in the order
they appeared in the routerlist. This wasn't a problem
until we added the ability to give country-code or IP-range
entries in the EntryNodes set, but now that we did, it is.
(Fix: We now shuffle the entry nodes before adding them; only
add up to 10*NumEntryGuards)
* We didn't screen EntryNodes for the Guard flag. That's okay
if the user has specified two or three entry nodes manually,
but if they have listed a whole subcontinent, we should
restrict ourselves to the entries that are currently guards.
(Fix: separate out the new guard from the new non-guard nodes,
and add the Guards first.)
* We'd prepend new EntryNodes _before_ the already configured
EntryNodes. This could lead to churn.
(Fix: don't prepend these.)
This patch also pre-screens EntryNodes entries for
reachableaddresses/excludenodes, even though we check for that
later. This is important now, since we cap the number of entries
we'll add.
2011-07-11 16:48:46 +02:00
|
|
|
smartlist_t *entry_nodes, *worse_entry_nodes, *entry_fps;
|
2007-06-07 17:07:33 +02:00
|
|
|
smartlist_t *old_entry_guards_on_list, *old_entry_guards_not_on_list;
|
2006-01-10 23:42:44 +01:00
|
|
|
tor_assert(entry_guards);
|
2007-02-28 01:23:05 +01:00
|
|
|
|
|
|
|
should_add_entry_nodes = 0;
|
|
|
|
|
|
|
|
if (!options->EntryNodes) {
|
|
|
|
/* It's possible that a controller set EntryNodes, thus making
|
|
|
|
* should_add_entry_nodes set, then cleared it again, all before the
|
|
|
|
* call to choose_random_entry() that triggered us. If so, just return.
|
|
|
|
*/
|
|
|
|
return;
|
|
|
|
}
|
2006-01-02 12:33:14 +01:00
|
|
|
|
2009-09-20 02:56:57 +02:00
|
|
|
{
|
2008-10-12 05:21:05 +02:00
|
|
|
char *string = routerset_to_string(options->EntryNodes);
|
|
|
|
log_info(LD_CIRC,"Adding configured EntryNodes '%s'.", string);
|
|
|
|
tor_free(string);
|
|
|
|
}
|
2005-12-31 07:32:57 +01:00
|
|
|
|
2012-01-18 21:53:30 +01:00
|
|
|
entry_nodes = smartlist_new();
|
|
|
|
worse_entry_nodes = smartlist_new();
|
|
|
|
entry_fps = smartlist_new();
|
|
|
|
old_entry_guards_on_list = smartlist_new();
|
|
|
|
old_entry_guards_not_on_list = smartlist_new();
|
2007-06-07 17:07:33 +02:00
|
|
|
|
2007-02-13 02:27:55 +01:00
|
|
|
/* Split entry guards into those on the list and those not. */
|
2008-12-29 21:17:20 +01:00
|
|
|
|
2011-04-27 20:36:30 +02:00
|
|
|
routerset_get_all_nodes(entry_nodes, options->EntryNodes,
|
|
|
|
options->ExcludeNodes, 0);
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
SMARTLIST_FOREACH(entry_nodes, const node_t *,node,
|
|
|
|
smartlist_add(entry_fps, (void*)node->identity));
|
2010-10-13 22:07:37 +02:00
|
|
|
|
2007-02-13 02:27:55 +01:00
|
|
|
SMARTLIST_FOREACH(entry_guards, entry_guard_t *, e, {
|
|
|
|
if (smartlist_digest_isin(entry_fps, e->identity))
|
|
|
|
smartlist_add(old_entry_guards_on_list, e);
|
|
|
|
else
|
|
|
|
smartlist_add(old_entry_guards_not_on_list, e);
|
|
|
|
});
|
|
|
|
|
Revise code for adding EntryNodes to guards.
Previously, we'd just take all the nodes in EntryNodes, see which
ones were already in the guard list, and add the ones that weren't.
There were some problems there, though:
* We'd add _every_ entry in EntryNodes, and add them in the order
they appeared in the routerlist. This wasn't a problem
until we added the ability to give country-code or IP-range
entries in the EntryNodes set, but now that we did, it is.
(Fix: We now shuffle the entry nodes before adding them; only
add up to 10*NumEntryGuards)
* We didn't screen EntryNodes for the Guard flag. That's okay
if the user has specified two or three entry nodes manually,
but if they have listed a whole subcontinent, we should
restrict ourselves to the entries that are currently guards.
(Fix: separate out the new guard from the new non-guard nodes,
and add the Guards first.)
* We'd prepend new EntryNodes _before_ the already configured
EntryNodes. This could lead to churn.
(Fix: don't prepend these.)
This patch also pre-screens EntryNodes entries for
reachableaddresses/excludenodes, even though we check for that
later. This is important now, since we cap the number of entries
we'll add.
2011-07-11 16:48:46 +02:00
|
|
|
/* Remove all currently configured guard nodes, excluded nodes, unreachable
|
2011-07-11 23:02:03 +02:00
|
|
|
* nodes, or non-Guard nodes from entry_nodes. */
|
Revise code for adding EntryNodes to guards.
Previously, we'd just take all the nodes in EntryNodes, see which
ones were already in the guard list, and add the ones that weren't.
There were some problems there, though:
* We'd add _every_ entry in EntryNodes, and add them in the order
they appeared in the routerlist. This wasn't a problem
until we added the ability to give country-code or IP-range
entries in the EntryNodes set, but now that we did, it is.
(Fix: We now shuffle the entry nodes before adding them; only
add up to 10*NumEntryGuards)
* We didn't screen EntryNodes for the Guard flag. That's okay
if the user has specified two or three entry nodes manually,
but if they have listed a whole subcontinent, we should
restrict ourselves to the entries that are currently guards.
(Fix: separate out the new guard from the new non-guard nodes,
and add the Guards first.)
* We'd prepend new EntryNodes _before_ the already configured
EntryNodes. This could lead to churn.
(Fix: don't prepend these.)
This patch also pre-screens EntryNodes entries for
reachableaddresses/excludenodes, even though we check for that
later. This is important now, since we cap the number of entries
we'll add.
2011-07-11 16:48:46 +02:00
|
|
|
SMARTLIST_FOREACH_BEGIN(entry_nodes, const node_t *, node) {
|
2012-05-04 05:15:34 +02:00
|
|
|
if (entry_guard_get_by_id_digest(node->identity)) {
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
SMARTLIST_DEL_CURRENT(entry_nodes, node);
|
Revise code for adding EntryNodes to guards.
Previously, we'd just take all the nodes in EntryNodes, see which
ones were already in the guard list, and add the ones that weren't.
There were some problems there, though:
* We'd add _every_ entry in EntryNodes, and add them in the order
they appeared in the routerlist. This wasn't a problem
until we added the ability to give country-code or IP-range
entries in the EntryNodes set, but now that we did, it is.
(Fix: We now shuffle the entry nodes before adding them; only
add up to 10*NumEntryGuards)
* We didn't screen EntryNodes for the Guard flag. That's okay
if the user has specified two or three entry nodes manually,
but if they have listed a whole subcontinent, we should
restrict ourselves to the entries that are currently guards.
(Fix: separate out the new guard from the new non-guard nodes,
and add the Guards first.)
* We'd prepend new EntryNodes _before_ the already configured
EntryNodes. This could lead to churn.
(Fix: don't prepend these.)
This patch also pre-screens EntryNodes entries for
reachableaddresses/excludenodes, even though we check for that
later. This is important now, since we cap the number of entries
we'll add.
2011-07-11 16:48:46 +02:00
|
|
|
continue;
|
|
|
|
} else if (routerset_contains_node(options->ExcludeNodes, node)) {
|
|
|
|
SMARTLIST_DEL_CURRENT(entry_nodes, node);
|
|
|
|
continue;
|
|
|
|
} else if (!fascist_firewall_allows_node(node)) {
|
|
|
|
SMARTLIST_DEL_CURRENT(entry_nodes, node);
|
|
|
|
continue;
|
|
|
|
} else if (! node->is_possible_guard) {
|
|
|
|
smartlist_add(worse_entry_nodes, (node_t*)node);
|
|
|
|
SMARTLIST_DEL_CURRENT(entry_nodes, node);
|
2007-02-13 02:27:55 +01:00
|
|
|
}
|
Revise code for adding EntryNodes to guards.
Previously, we'd just take all the nodes in EntryNodes, see which
ones were already in the guard list, and add the ones that weren't.
There were some problems there, though:
* We'd add _every_ entry in EntryNodes, and add them in the order
they appeared in the routerlist. This wasn't a problem
until we added the ability to give country-code or IP-range
entries in the EntryNodes set, but now that we did, it is.
(Fix: We now shuffle the entry nodes before adding them; only
add up to 10*NumEntryGuards)
* We didn't screen EntryNodes for the Guard flag. That's okay
if the user has specified two or three entry nodes manually,
but if they have listed a whole subcontinent, we should
restrict ourselves to the entries that are currently guards.
(Fix: separate out the new guard from the new non-guard nodes,
and add the Guards first.)
* We'd prepend new EntryNodes _before_ the already configured
EntryNodes. This could lead to churn.
(Fix: don't prepend these.)
This patch also pre-screens EntryNodes entries for
reachableaddresses/excludenodes, even though we check for that
later. This is important now, since we cap the number of entries
we'll add.
2011-07-11 16:48:46 +02:00
|
|
|
} SMARTLIST_FOREACH_END(node);
|
2007-02-13 02:27:55 +01:00
|
|
|
|
|
|
|
/* Now build the new entry_guards list. */
|
|
|
|
smartlist_clear(entry_guards);
|
|
|
|
/* First, the previously configured guards that are in EntryNodes. */
|
|
|
|
smartlist_add_all(entry_guards, old_entry_guards_on_list);
|
2011-07-11 23:02:03 +02:00
|
|
|
/* Next, scramble the rest of EntryNodes, putting the guards first. */
|
Revise code for adding EntryNodes to guards.
Previously, we'd just take all the nodes in EntryNodes, see which
ones were already in the guard list, and add the ones that weren't.
There were some problems there, though:
* We'd add _every_ entry in EntryNodes, and add them in the order
they appeared in the routerlist. This wasn't a problem
until we added the ability to give country-code or IP-range
entries in the EntryNodes set, but now that we did, it is.
(Fix: We now shuffle the entry nodes before adding them; only
add up to 10*NumEntryGuards)
* We didn't screen EntryNodes for the Guard flag. That's okay
if the user has specified two or three entry nodes manually,
but if they have listed a whole subcontinent, we should
restrict ourselves to the entries that are currently guards.
(Fix: separate out the new guard from the new non-guard nodes,
and add the Guards first.)
* We'd prepend new EntryNodes _before_ the already configured
EntryNodes. This could lead to churn.
(Fix: don't prepend these.)
This patch also pre-screens EntryNodes entries for
reachableaddresses/excludenodes, even though we check for that
later. This is important now, since we cap the number of entries
we'll add.
2011-07-11 16:48:46 +02:00
|
|
|
smartlist_shuffle(entry_nodes);
|
|
|
|
smartlist_shuffle(worse_entry_nodes);
|
|
|
|
smartlist_add_all(entry_nodes, worse_entry_nodes);
|
|
|
|
|
2007-02-13 02:27:55 +01:00
|
|
|
/* Next, the rest of EntryNodes */
|
Revise code for adding EntryNodes to guards.
Previously, we'd just take all the nodes in EntryNodes, see which
ones were already in the guard list, and add the ones that weren't.
There were some problems there, though:
* We'd add _every_ entry in EntryNodes, and add them in the order
they appeared in the routerlist. This wasn't a problem
until we added the ability to give country-code or IP-range
entries in the EntryNodes set, but now that we did, it is.
(Fix: We now shuffle the entry nodes before adding them; only
add up to 10*NumEntryGuards)
* We didn't screen EntryNodes for the Guard flag. That's okay
if the user has specified two or three entry nodes manually,
but if they have listed a whole subcontinent, we should
restrict ourselves to the entries that are currently guards.
(Fix: separate out the new guard from the new non-guard nodes,
and add the Guards first.)
* We'd prepend new EntryNodes _before_ the already configured
EntryNodes. This could lead to churn.
(Fix: don't prepend these.)
This patch also pre-screens EntryNodes entries for
reachableaddresses/excludenodes, even though we check for that
later. This is important now, since we cap the number of entries
we'll add.
2011-07-11 16:48:46 +02:00
|
|
|
SMARTLIST_FOREACH_BEGIN(entry_nodes, const node_t *, node) {
|
|
|
|
add_an_entry_guard(node, 0, 0);
|
|
|
|
if (smartlist_len(entry_guards) > options->NumEntryGuards * 10)
|
|
|
|
break;
|
|
|
|
} SMARTLIST_FOREACH_END(node);
|
|
|
|
log_notice(LD_GENERAL, "%d entries in guards", smartlist_len(entry_guards));
|
2011-03-11 10:21:25 +01:00
|
|
|
/* Finally, free the remaining previously configured guards that are not in
|
|
|
|
* EntryNodes. */
|
|
|
|
SMARTLIST_FOREACH(old_entry_guards_not_on_list, entry_guard_t *, e,
|
|
|
|
entry_guard_free(e));
|
2005-12-31 07:32:57 +01:00
|
|
|
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
smartlist_free(entry_nodes);
|
Revise code for adding EntryNodes to guards.
Previously, we'd just take all the nodes in EntryNodes, see which
ones were already in the guard list, and add the ones that weren't.
There were some problems there, though:
* We'd add _every_ entry in EntryNodes, and add them in the order
they appeared in the routerlist. This wasn't a problem
until we added the ability to give country-code or IP-range
entries in the EntryNodes set, but now that we did, it is.
(Fix: We now shuffle the entry nodes before adding them; only
add up to 10*NumEntryGuards)
* We didn't screen EntryNodes for the Guard flag. That's okay
if the user has specified two or three entry nodes manually,
but if they have listed a whole subcontinent, we should
restrict ourselves to the entries that are currently guards.
(Fix: separate out the new guard from the new non-guard nodes,
and add the Guards first.)
* We'd prepend new EntryNodes _before_ the already configured
EntryNodes. This could lead to churn.
(Fix: don't prepend these.)
This patch also pre-screens EntryNodes entries for
reachableaddresses/excludenodes, even though we check for that
later. This is important now, since we cap the number of entries
we'll add.
2011-07-11 16:48:46 +02:00
|
|
|
smartlist_free(worse_entry_nodes);
|
2007-02-13 02:27:55 +01:00
|
|
|
smartlist_free(entry_fps);
|
|
|
|
smartlist_free(old_entry_guards_on_list);
|
|
|
|
smartlist_free(old_entry_guards_not_on_list);
|
|
|
|
entry_guards_changed();
|
2005-12-31 07:32:57 +01:00
|
|
|
}
|
|
|
|
|
2009-09-20 02:56:57 +02:00
|
|
|
/** Return 0 if we're fine adding arbitrary routers out of the
|
|
|
|
* directory to our entry guard list, or return 1 if we have a
|
2011-03-11 10:21:25 +01:00
|
|
|
* list already and we must stick to it.
|
2009-09-20 02:56:57 +02:00
|
|
|
*/
|
2007-12-10 18:16:41 +01:00
|
|
|
int
|
2011-06-14 19:01:38 +02:00
|
|
|
entry_list_is_constrained(const or_options_t *options)
|
2009-09-20 02:56:57 +02:00
|
|
|
{
|
|
|
|
if (options->EntryNodes)
|
|
|
|
return 1;
|
|
|
|
if (options->UseBridges)
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-06-12 11:17:23 +02:00
|
|
|
/** Pick a live (up and listed) entry guard from entry_guards. If
|
|
|
|
* <b>state</b> is non-NULL, this is for a specific circuit --
|
|
|
|
* make sure not to pick this circuit's exit or any node in the
|
|
|
|
* exit's family. If <b>state</b> is NULL, we're looking for a random
|
|
|
|
* guard (likely a bridge). */
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
const node_t *
|
2005-12-28 10:07:31 +01:00
|
|
|
choose_random_entry(cpath_build_state_t *state)
|
2005-07-22 19:32:25 +02:00
|
|
|
{
|
2011-06-14 19:01:38 +02:00
|
|
|
const or_options_t *options = get_options();
|
2012-01-18 21:53:30 +01:00
|
|
|
smartlist_t *live_entry_guards = smartlist_new();
|
|
|
|
smartlist_t *exit_family = smartlist_new();
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
const node_t *chosen_exit =
|
|
|
|
state?build_state_get_exit_node(state) : NULL;
|
|
|
|
const node_t *node = NULL;
|
2007-06-12 11:17:23 +02:00
|
|
|
int need_uptime = state ? state->need_uptime : 0;
|
|
|
|
int need_capacity = state ? state->need_capacity : 0;
|
2009-09-20 02:56:57 +02:00
|
|
|
int preferred_min, consider_exit_family = 0;
|
2005-07-22 19:32:25 +02:00
|
|
|
|
2007-05-25 01:39:04 +02:00
|
|
|
if (chosen_exit) {
|
2011-07-11 17:21:47 +02:00
|
|
|
nodelist_add_node_and_family(exit_family, chosen_exit);
|
2007-11-16 08:37:49 +01:00
|
|
|
consider_exit_family = 1;
|
2007-05-25 01:39:04 +02:00
|
|
|
}
|
2007-05-22 03:01:24 +02:00
|
|
|
|
2006-01-10 23:42:44 +01:00
|
|
|
if (!entry_guards)
|
2012-01-18 21:53:30 +01:00
|
|
|
entry_guards = smartlist_new();
|
2005-12-31 07:32:57 +01:00
|
|
|
|
|
|
|
if (should_add_entry_nodes)
|
2011-07-11 23:02:03 +02:00
|
|
|
entry_guards_set_from_config(options);
|
2005-12-31 07:32:57 +01:00
|
|
|
|
2009-09-20 02:56:57 +02:00
|
|
|
if (!entry_list_is_constrained(options) &&
|
|
|
|
smartlist_len(entry_guards) < options->NumEntryGuards)
|
2010-09-24 04:10:13 +02:00
|
|
|
pick_entry_guards(options);
|
2005-07-22 19:32:25 +02:00
|
|
|
|
|
|
|
retry:
|
2006-01-10 23:42:44 +01:00
|
|
|
smartlist_clear(live_entry_guards);
|
2010-09-29 06:38:32 +02:00
|
|
|
SMARTLIST_FOREACH_BEGIN(entry_guards, entry_guard_t *, entry) {
|
2009-09-20 04:59:14 +02:00
|
|
|
const char *msg;
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
node = entry_is_live(entry, need_uptime, need_capacity, 0, &msg);
|
|
|
|
if (!node)
|
2009-09-20 02:56:57 +02:00
|
|
|
continue; /* down, no point */
|
2011-02-23 00:41:06 +01:00
|
|
|
if (node == chosen_exit)
|
2011-02-22 23:54:25 +01:00
|
|
|
continue; /* don't pick the same node for entry and exit */
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
if (consider_exit_family && smartlist_isin(exit_family, node))
|
2009-09-20 02:56:57 +02:00
|
|
|
continue; /* avoid relays that are family members of our exit */
|
2011-03-11 10:21:25 +01:00
|
|
|
#if 0 /* since EntryNodes is always strict now, this clause is moot */
|
2009-09-20 02:56:57 +02:00
|
|
|
if (options->EntryNodes &&
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
!routerset_contains_node(options->EntryNodes, node)) {
|
2009-09-20 02:56:57 +02:00
|
|
|
/* We've come to the end of our preferred entry nodes. */
|
|
|
|
if (smartlist_len(live_entry_guards))
|
|
|
|
goto choose_and_finish; /* only choose from the ones we like */
|
|
|
|
if (options->StrictNodes) {
|
|
|
|
/* in theory this case should never happen, since
|
2011-07-11 23:02:03 +02:00
|
|
|
* entry_guards_set_from_config() drops unwanted relays */
|
2009-09-20 02:56:57 +02:00
|
|
|
tor_fragile_assert();
|
|
|
|
} else {
|
|
|
|
log_info(LD_CIRC,
|
|
|
|
"No relays from EntryNodes available. Using others.");
|
2007-07-03 00:15:26 +02:00
|
|
|
}
|
2005-12-27 08:23:52 +01:00
|
|
|
}
|
2011-03-11 10:21:25 +01:00
|
|
|
#endif
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
smartlist_add(live_entry_guards, (void*)node);
|
2009-09-20 02:56:57 +02:00
|
|
|
if (!entry->made_contact) {
|
|
|
|
/* Always start with the first not-yet-contacted entry
|
|
|
|
* guard. Otherwise we might add several new ones, pick
|
|
|
|
* the second new one, and now we've expanded our entry
|
|
|
|
* guard list without needing to. */
|
|
|
|
goto choose_and_finish;
|
|
|
|
}
|
|
|
|
if (smartlist_len(live_entry_guards) >= options->NumEntryGuards)
|
2011-09-27 23:35:31 +02:00
|
|
|
goto choose_and_finish; /* we have enough */
|
2010-09-29 06:38:32 +02:00
|
|
|
} SMARTLIST_FOREACH_END(entry);
|
2005-12-27 08:23:52 +01:00
|
|
|
|
2009-09-20 02:56:57 +02:00
|
|
|
if (entry_list_is_constrained(options)) {
|
|
|
|
/* If we prefer the entry nodes we've got, and we have at least
|
|
|
|
* one choice, that's great. Use it. */
|
|
|
|
preferred_min = 1;
|
|
|
|
} else {
|
|
|
|
/* Try to have at least 2 choices available. This way we don't
|
|
|
|
* get stuck with a single live-but-crummy entry and just keep
|
|
|
|
* using him.
|
|
|
|
* (We might get 2 live-but-crummy entry guards, but so be it.) */
|
|
|
|
preferred_min = 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (smartlist_len(live_entry_guards) < preferred_min) {
|
2011-03-11 10:21:25 +01:00
|
|
|
if (!entry_list_is_constrained(options)) {
|
2005-12-31 07:32:57 +01:00
|
|
|
/* still no? try adding a new entry then */
|
2006-10-07 04:55:44 +02:00
|
|
|
/* XXX if guard doesn't imply fast and stable, then we need
|
|
|
|
* to tell add_an_entry_guard below what we want, or it might
|
|
|
|
* be a long time til we get it. -RD */
|
Revise code for adding EntryNodes to guards.
Previously, we'd just take all the nodes in EntryNodes, see which
ones were already in the guard list, and add the ones that weren't.
There were some problems there, though:
* We'd add _every_ entry in EntryNodes, and add them in the order
they appeared in the routerlist. This wasn't a problem
until we added the ability to give country-code or IP-range
entries in the EntryNodes set, but now that we did, it is.
(Fix: We now shuffle the entry nodes before adding them; only
add up to 10*NumEntryGuards)
* We didn't screen EntryNodes for the Guard flag. That's okay
if the user has specified two or three entry nodes manually,
but if they have listed a whole subcontinent, we should
restrict ourselves to the entries that are currently guards.
(Fix: separate out the new guard from the new non-guard nodes,
and add the Guards first.)
* We'd prepend new EntryNodes _before_ the already configured
EntryNodes. This could lead to churn.
(Fix: don't prepend these.)
This patch also pre-screens EntryNodes entries for
reachableaddresses/excludenodes, even though we check for that
later. This is important now, since we cap the number of entries
we'll add.
2011-07-11 16:48:46 +02:00
|
|
|
node = add_an_entry_guard(NULL, 0, 0);
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
if (node) {
|
2006-01-10 23:42:44 +01:00
|
|
|
entry_guards_changed();
|
2008-08-31 08:33:39 +02:00
|
|
|
/* XXX we start over here in case the new node we added shares
|
|
|
|
* a family with our exit node. There's a chance that we'll just
|
|
|
|
* load up on entry guards here, if the network we're using is
|
|
|
|
* one big family. Perhaps we should teach add_an_entry_guard()
|
|
|
|
* to understand nodes-to-avoid-if-possible? -RD */
|
|
|
|
goto retry;
|
2005-12-31 07:32:57 +01:00
|
|
|
}
|
|
|
|
}
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
if (!node && need_uptime) {
|
2006-10-07 04:55:44 +02:00
|
|
|
need_uptime = 0; /* try without that requirement */
|
|
|
|
goto retry;
|
|
|
|
}
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
if (!node && need_capacity) {
|
2006-10-07 04:55:44 +02:00
|
|
|
/* still no? last attempt, try without requiring capacity */
|
|
|
|
need_capacity = 0;
|
|
|
|
goto retry;
|
2005-12-27 08:23:52 +01:00
|
|
|
}
|
2011-04-04 00:20:19 +02:00
|
|
|
#if 0
|
|
|
|
/* Removing this retry logic: if we only allow one exit, and it is in the
|
|
|
|
same family as all our entries, then we are just plain not going to win
|
|
|
|
here. */
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
if (!node && entry_list_is_constrained(options) && consider_exit_family) {
|
2007-11-16 08:37:49 +01:00
|
|
|
/* still no? if we're using bridges or have strictentrynodes
|
|
|
|
* set, and our chosen exit is in the same family as all our
|
|
|
|
* bridges/entry guards, then be flexible about families. */
|
|
|
|
consider_exit_family = 0;
|
|
|
|
goto retry;
|
|
|
|
}
|
2011-04-04 00:20:19 +02:00
|
|
|
#endif
|
2007-06-12 11:17:23 +02:00
|
|
|
/* live_entry_guards may be empty below. Oh well, we tried. */
|
2005-07-22 19:32:25 +02:00
|
|
|
}
|
|
|
|
|
2007-07-03 00:15:26 +02:00
|
|
|
choose_and_finish:
|
2009-09-20 02:56:57 +02:00
|
|
|
if (entry_list_is_constrained(options)) {
|
|
|
|
/* We need to weight by bandwidth, because our bridges or entryguards
|
|
|
|
* were not already selected proportional to their bandwidth. */
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
node = node_sl_choose_by_bandwidth(live_entry_guards, WEIGHT_FOR_GUARD);
|
2009-09-20 02:56:57 +02:00
|
|
|
} else {
|
2008-02-12 23:02:47 +01:00
|
|
|
/* We choose uniformly at random here, because choose_good_entry_server()
|
|
|
|
* already weights its choices by bandwidth, so we don't want to
|
|
|
|
* *double*-weight our guard selection. */
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
node = smartlist_choose(live_entry_guards);
|
2008-02-12 23:02:47 +01:00
|
|
|
}
|
2006-01-10 23:42:44 +01:00
|
|
|
smartlist_free(live_entry_guards);
|
2007-05-22 03:01:24 +02:00
|
|
|
smartlist_free(exit_family);
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
return node;
|
2005-07-22 19:32:25 +02:00
|
|
|
}
|
|
|
|
|
2006-01-10 23:42:44 +01:00
|
|
|
/** Parse <b>state</b> and learn about the entry guards it describes.
|
2005-12-24 21:07:19 +01:00
|
|
|
* If <b>set</b> is true, and there are no errors, replace the global
|
2005-12-28 10:07:31 +01:00
|
|
|
* entry_list with what we find.
|
2006-03-26 08:51:26 +02:00
|
|
|
* On success, return 0. On failure, alloc into *<b>msg</b> a string
|
2005-12-24 21:07:19 +01:00
|
|
|
* describing the error, and return -1.
|
|
|
|
*/
|
2005-07-28 21:01:48 +02:00
|
|
|
int
|
2006-03-26 08:51:26 +02:00
|
|
|
entry_guards_parse_state(or_state_t *state, int set, char **msg)
|
2005-07-28 21:01:48 +02:00
|
|
|
{
|
2006-01-10 23:42:44 +01:00
|
|
|
entry_guard_t *node = NULL;
|
2012-01-18 21:53:30 +01:00
|
|
|
smartlist_t *new_entry_guards = smartlist_new();
|
2005-07-28 21:01:48 +02:00
|
|
|
config_line_t *line;
|
2007-08-18 20:20:42 +02:00
|
|
|
time_t now = time(NULL);
|
2007-08-29 19:22:00 +02:00
|
|
|
const char *state_version = state->TorVersion;
|
|
|
|
digestmap_t *added_by = digestmap_new();
|
2005-07-28 21:01:48 +02:00
|
|
|
|
2006-03-26 08:51:26 +02:00
|
|
|
*msg = NULL;
|
2006-01-10 23:42:44 +01:00
|
|
|
for (line = state->EntryGuards; line; line = line->next) {
|
|
|
|
if (!strcasecmp(line->key, "EntryGuard")) {
|
2012-01-18 21:53:30 +01:00
|
|
|
smartlist_t *args = smartlist_new();
|
2006-01-10 23:42:44 +01:00
|
|
|
node = tor_malloc_zero(sizeof(entry_guard_t));
|
2006-01-11 05:04:42 +01:00
|
|
|
/* all entry guards on disk have been contacted */
|
|
|
|
node->made_contact = 1;
|
2006-01-10 23:42:44 +01:00
|
|
|
smartlist_add(new_entry_guards, node);
|
2005-07-28 21:01:48 +02:00
|
|
|
smartlist_split_string(args, line->value, " ",
|
|
|
|
SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 0);
|
|
|
|
if (smartlist_len(args)<2) {
|
2006-03-26 08:51:26 +02:00
|
|
|
*msg = tor_strdup("Unable to parse entry nodes: "
|
|
|
|
"Too few arguments to EntryGuard");
|
2005-10-25 09:00:03 +02:00
|
|
|
} else if (!is_legal_nickname(smartlist_get(args,0))) {
|
2006-03-26 08:51:26 +02:00
|
|
|
*msg = tor_strdup("Unable to parse entry nodes: "
|
|
|
|
"Bad nickname for EntryGuard");
|
2005-10-25 09:00:03 +02:00
|
|
|
} else {
|
|
|
|
strlcpy(node->nickname, smartlist_get(args,0), MAX_NICKNAME_LEN+1);
|
|
|
|
if (base16_decode(node->identity, DIGEST_LEN, smartlist_get(args,1),
|
|
|
|
strlen(smartlist_get(args,1)))<0) {
|
2006-03-26 08:51:26 +02:00
|
|
|
*msg = tor_strdup("Unable to parse entry nodes: "
|
|
|
|
"Bad hex digest for EntryGuard");
|
2005-10-25 09:00:03 +02:00
|
|
|
}
|
2005-07-28 21:01:48 +02:00
|
|
|
}
|
2005-10-25 09:00:03 +02:00
|
|
|
SMARTLIST_FOREACH(args, char*, cp, tor_free(cp));
|
|
|
|
smartlist_free(args);
|
2006-03-26 08:51:26 +02:00
|
|
|
if (*msg)
|
2005-07-28 21:01:48 +02:00
|
|
|
break;
|
2007-08-29 19:22:00 +02:00
|
|
|
} else if (!strcasecmp(line->key, "EntryGuardDownSince") ||
|
|
|
|
!strcasecmp(line->key, "EntryGuardUnlistedSince")) {
|
2005-07-28 21:01:48 +02:00
|
|
|
time_t when;
|
2006-09-29 01:57:49 +02:00
|
|
|
time_t last_try = 0;
|
2005-07-28 21:01:48 +02:00
|
|
|
if (!node) {
|
2006-03-26 08:51:26 +02:00
|
|
|
*msg = tor_strdup("Unable to parse entry nodes: "
|
|
|
|
"EntryGuardDownSince/UnlistedSince without EntryGuard");
|
2005-07-28 21:01:48 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (parse_iso_time(line->value, &when)<0) {
|
2006-03-26 08:51:26 +02:00
|
|
|
*msg = tor_strdup("Unable to parse entry nodes: "
|
|
|
|
"Bad time in EntryGuardDownSince/UnlistedSince");
|
2005-07-28 21:01:48 +02:00
|
|
|
break;
|
|
|
|
}
|
2007-08-18 20:20:42 +02:00
|
|
|
if (when > now) {
|
|
|
|
/* It's a bad idea to believe info in the future: you can wind
|
|
|
|
* up with timeouts that aren't allowed to happen for years. */
|
|
|
|
continue;
|
|
|
|
}
|
2006-09-29 01:57:49 +02:00
|
|
|
if (strlen(line->value) >= ISO_TIME_LEN+ISO_TIME_LEN+1) {
|
|
|
|
/* ignore failure */
|
2008-01-14 20:00:23 +01:00
|
|
|
(void) parse_iso_time(line->value+ISO_TIME_LEN+1, &last_try);
|
2006-09-29 01:57:49 +02:00
|
|
|
}
|
|
|
|
if (!strcasecmp(line->key, "EntryGuardDownSince")) {
|
2006-09-29 01:57:44 +02:00
|
|
|
node->unreachable_since = when;
|
2006-09-29 01:57:49 +02:00
|
|
|
node->last_attempted = last_try;
|
|
|
|
} else {
|
2006-09-29 01:57:44 +02:00
|
|
|
node->bad_since = when;
|
2006-09-29 01:57:49 +02:00
|
|
|
}
|
2007-08-29 19:22:00 +02:00
|
|
|
} else if (!strcasecmp(line->key, "EntryGuardAddedBy")) {
|
|
|
|
char d[DIGEST_LEN];
|
|
|
|
/* format is digest version date */
|
|
|
|
if (strlen(line->value) < HEX_DIGEST_LEN+1+1+1+ISO_TIME_LEN) {
|
|
|
|
log_warn(LD_BUG, "EntryGuardAddedBy line is not long enough.");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (base16_decode(d, sizeof(d), line->value, HEX_DIGEST_LEN)<0 ||
|
|
|
|
line->value[HEX_DIGEST_LEN] != ' ') {
|
|
|
|
log_warn(LD_BUG, "EntryGuardAddedBy line %s does not begin with "
|
|
|
|
"hex digest", escaped(line->value));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
digestmap_set(added_by, d, tor_strdup(line->value+HEX_DIGEST_LEN+1));
|
2012-05-04 05:15:34 +02:00
|
|
|
} else if (!strcasecmp(line->key, "EntryGuardPathBias")) {
|
|
|
|
const or_options_t *options = get_options();
|
|
|
|
unsigned hop_cnt, success_cnt;
|
|
|
|
|
2012-09-05 19:27:54 +02:00
|
|
|
if (!node) {
|
|
|
|
*msg = tor_strdup("Unable to parse entry nodes: "
|
|
|
|
"EntryGuardPathBias without EntryGuard");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-05-04 05:15:34 +02:00
|
|
|
if (tor_sscanf(line->value, "%u %u", &success_cnt, &hop_cnt) != 2) {
|
|
|
|
log_warn(LD_GENERAL, "Unable to parse guard path bias info: "
|
|
|
|
"Misformated EntryGuardPathBias %s", escaped(line->value));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
node->first_hops = hop_cnt;
|
|
|
|
node->circuit_successes = success_cnt;
|
|
|
|
log_info(LD_GENERAL, "Read %u/%u path bias for node %s",
|
|
|
|
node->circuit_successes, node->first_hops, node->nickname);
|
|
|
|
/* Note: We rely on the < comparison here to allow us to set a 0
|
|
|
|
* rate and disable the feature entirely. If refactoring, don't
|
|
|
|
* change to <= */
|
|
|
|
if (node->circuit_successes/((double)node->first_hops)
|
|
|
|
< pathbias_get_disable_rate(options)) {
|
|
|
|
node->path_bias_disabled = 1;
|
|
|
|
log_info(LD_GENERAL,
|
|
|
|
"Path bias is too high (%u/%u); disabling node %s",
|
|
|
|
node->circuit_successes, node->first_hops, node->nickname);
|
|
|
|
}
|
|
|
|
|
2007-08-29 19:22:00 +02:00
|
|
|
} else {
|
|
|
|
log_warn(LD_BUG, "Unexpected key %s", line->key);
|
2005-07-28 21:01:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-16 17:49:45 +02:00
|
|
|
SMARTLIST_FOREACH_BEGIN(new_entry_guards, entry_guard_t *, e) {
|
2007-08-29 19:22:00 +02:00
|
|
|
char *sp;
|
|
|
|
char *val = digestmap_get(added_by, e->identity);
|
|
|
|
if (val && (sp = strchr(val, ' '))) {
|
|
|
|
time_t when;
|
|
|
|
*sp++ = '\0';
|
|
|
|
if (parse_iso_time(sp, &when)<0) {
|
|
|
|
log_warn(LD_BUG, "Can't read time %s in EntryGuardAddedBy", sp);
|
|
|
|
} else {
|
|
|
|
e->chosen_by_version = tor_strdup(val);
|
|
|
|
e->chosen_on_date = when;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (state_version) {
|
|
|
|
e->chosen_by_version = tor_strdup(state_version);
|
2010-01-19 23:52:52 +01:00
|
|
|
e->chosen_on_date = time(NULL) - crypto_rand_int(3600*24*30);
|
2007-08-29 19:22:00 +02:00
|
|
|
}
|
|
|
|
}
|
2012-07-16 17:49:45 +02:00
|
|
|
if (e->path_bias_disabled && !e->bad_since)
|
|
|
|
e->bad_since = time(NULL);
|
|
|
|
}
|
|
|
|
SMARTLIST_FOREACH_END(e);
|
2007-08-29 19:22:00 +02:00
|
|
|
|
2006-03-26 08:51:26 +02:00
|
|
|
if (*msg || !set) {
|
2007-10-11 04:03:53 +02:00
|
|
|
SMARTLIST_FOREACH(new_entry_guards, entry_guard_t *, e,
|
|
|
|
entry_guard_free(e));
|
2006-01-10 23:42:44 +01:00
|
|
|
smartlist_free(new_entry_guards);
|
2009-04-11 14:00:18 +02:00
|
|
|
} else { /* !err && set */
|
2006-01-10 23:42:44 +01:00
|
|
|
if (entry_guards) {
|
2007-10-11 04:03:53 +02:00
|
|
|
SMARTLIST_FOREACH(entry_guards, entry_guard_t *, e,
|
|
|
|
entry_guard_free(e));
|
2006-01-10 23:42:44 +01:00
|
|
|
smartlist_free(entry_guards);
|
2005-07-28 21:01:48 +02:00
|
|
|
}
|
2006-01-10 23:42:44 +01:00
|
|
|
entry_guards = new_entry_guards;
|
|
|
|
entry_guards_dirty = 0;
|
2012-06-15 15:37:40 +02:00
|
|
|
/* XXX024 hand new_entry_guards to this func, and move it up a
|
2009-04-11 14:00:18 +02:00
|
|
|
* few lines, so we don't have to re-dirty it */
|
2010-09-24 04:10:13 +02:00
|
|
|
if (remove_obsolete_entry_guards(now))
|
2007-08-29 19:22:00 +02:00
|
|
|
entry_guards_dirty = 1;
|
2005-07-28 21:01:48 +02:00
|
|
|
}
|
2007-08-29 19:22:00 +02:00
|
|
|
digestmap_free(added_by, _tor_free);
|
2006-03-26 08:51:26 +02:00
|
|
|
return *msg ? -1 : 0;
|
2005-07-28 21:01:48 +02:00
|
|
|
}
|
|
|
|
|
2006-01-10 23:42:44 +01:00
|
|
|
/** Our list of entry guards has changed, or some element of one
|
2006-12-07 21:11:30 +01:00
|
|
|
* of our entry guards has changed. Write the changes to disk within
|
2006-12-09 20:40:16 +01:00
|
|
|
* the next few minutes.
|
2006-12-07 21:11:30 +01:00
|
|
|
*/
|
2005-07-28 21:01:48 +02:00
|
|
|
static void
|
2006-01-10 23:42:44 +01:00
|
|
|
entry_guards_changed(void)
|
2005-07-28 21:01:48 +02:00
|
|
|
{
|
2006-12-24 03:45:46 +01:00
|
|
|
time_t when;
|
2006-01-10 23:42:44 +01:00
|
|
|
entry_guards_dirty = 1;
|
2005-07-28 21:01:48 +02:00
|
|
|
|
2006-12-07 21:11:30 +01:00
|
|
|
/* or_state_save() will call entry_guards_update_state(). */
|
2006-12-24 03:45:46 +01:00
|
|
|
when = get_options()->AvoidDiskWrites ? time(NULL) + 3600 : time(NULL)+600;
|
|
|
|
or_state_mark_dirty(get_or_state(), when);
|
2005-07-28 21:01:48 +02:00
|
|
|
}
|
|
|
|
|
2006-01-10 23:42:44 +01:00
|
|
|
/** If the entry guard info has not changed, do nothing and return.
|
|
|
|
* Otherwise, free the EntryGuards piece of <b>state</b> and create
|
|
|
|
* a new one out of the global entry_guards list, and then mark
|
2005-12-28 10:07:31 +01:00
|
|
|
* <b>state</b> dirty so it will get saved to disk.
|
2005-12-24 21:07:19 +01:00
|
|
|
*/
|
2005-12-24 23:48:12 +01:00
|
|
|
void
|
2006-01-10 23:42:44 +01:00
|
|
|
entry_guards_update_state(or_state_t *state)
|
2005-07-28 21:01:48 +02:00
|
|
|
{
|
|
|
|
config_line_t **next, *line;
|
2006-01-10 23:42:44 +01:00
|
|
|
if (! entry_guards_dirty)
|
2005-12-24 23:48:12 +01:00
|
|
|
return;
|
2005-07-28 21:01:48 +02:00
|
|
|
|
2006-01-10 23:42:44 +01:00
|
|
|
config_free_lines(state->EntryGuards);
|
|
|
|
next = &state->EntryGuards;
|
2005-07-28 21:01:48 +02:00
|
|
|
*next = NULL;
|
2006-01-10 23:42:44 +01:00
|
|
|
if (!entry_guards)
|
2012-01-18 21:53:30 +01:00
|
|
|
entry_guards = smartlist_new();
|
2012-07-17 15:33:38 +02:00
|
|
|
SMARTLIST_FOREACH_BEGIN(entry_guards, entry_guard_t *, e) {
|
2005-07-28 21:01:48 +02:00
|
|
|
char dbuf[HEX_DIGEST_LEN+1];
|
2005-12-28 10:07:31 +01:00
|
|
|
if (!e->made_contact)
|
2005-12-25 00:32:35 +01:00
|
|
|
continue; /* don't write this one to disk */
|
2005-07-28 21:01:48 +02:00
|
|
|
*next = line = tor_malloc_zero(sizeof(config_line_t));
|
2006-01-10 23:42:44 +01:00
|
|
|
line->key = tor_strdup("EntryGuard");
|
2005-12-28 10:07:31 +01:00
|
|
|
base16_encode(dbuf, sizeof(dbuf), e->identity, DIGEST_LEN);
|
2012-01-11 20:02:59 +01:00
|
|
|
tor_asprintf(&line->value, "%s %s", e->nickname, dbuf);
|
2005-07-28 21:01:48 +02:00
|
|
|
next = &(line->next);
|
2006-09-29 01:57:44 +02:00
|
|
|
if (e->unreachable_since) {
|
2005-07-28 21:01:48 +02:00
|
|
|
*next = line = tor_malloc_zero(sizeof(config_line_t));
|
2006-01-10 23:42:44 +01:00
|
|
|
line->key = tor_strdup("EntryGuardDownSince");
|
2006-09-29 01:57:49 +02:00
|
|
|
line->value = tor_malloc(ISO_TIME_LEN+1+ISO_TIME_LEN+1);
|
2006-09-29 01:57:44 +02:00
|
|
|
format_iso_time(line->value, e->unreachable_since);
|
2006-09-29 01:57:49 +02:00
|
|
|
if (e->last_attempted) {
|
|
|
|
line->value[ISO_TIME_LEN] = ' ';
|
|
|
|
format_iso_time(line->value+ISO_TIME_LEN+1, e->last_attempted);
|
|
|
|
}
|
2005-07-28 21:01:48 +02:00
|
|
|
next = &(line->next);
|
|
|
|
}
|
2006-09-29 01:57:44 +02:00
|
|
|
if (e->bad_since) {
|
2005-07-28 21:01:48 +02:00
|
|
|
*next = line = tor_malloc_zero(sizeof(config_line_t));
|
2006-01-10 23:42:44 +01:00
|
|
|
line->key = tor_strdup("EntryGuardUnlistedSince");
|
2005-07-28 21:01:48 +02:00
|
|
|
line->value = tor_malloc(ISO_TIME_LEN+1);
|
2006-09-29 01:57:44 +02:00
|
|
|
format_iso_time(line->value, e->bad_since);
|
2005-07-28 21:01:48 +02:00
|
|
|
next = &(line->next);
|
|
|
|
}
|
2007-08-29 19:22:00 +02:00
|
|
|
if (e->chosen_on_date && e->chosen_by_version &&
|
|
|
|
!strchr(e->chosen_by_version, ' ')) {
|
|
|
|
char d[HEX_DIGEST_LEN+1];
|
|
|
|
char t[ISO_TIME_LEN+1];
|
|
|
|
*next = line = tor_malloc_zero(sizeof(config_line_t));
|
|
|
|
line->key = tor_strdup("EntryGuardAddedBy");
|
|
|
|
base16_encode(d, sizeof(d), e->identity, DIGEST_LEN);
|
|
|
|
format_iso_time(t, e->chosen_on_date);
|
2012-01-11 20:02:59 +01:00
|
|
|
tor_asprintf(&line->value, "%s %s %s",
|
2007-08-29 19:22:00 +02:00
|
|
|
d, e->chosen_by_version, t);
|
|
|
|
next = &(line->next);
|
|
|
|
}
|
2012-05-04 05:15:34 +02:00
|
|
|
if (e->first_hops) {
|
|
|
|
*next = line = tor_malloc_zero(sizeof(config_line_t));
|
|
|
|
line->key = tor_strdup("EntryGuardPathBias");
|
|
|
|
tor_asprintf(&line->value, "%u %u",
|
|
|
|
e->circuit_successes, e->first_hops);
|
|
|
|
next = &(line->next);
|
|
|
|
}
|
|
|
|
|
2012-07-17 15:33:38 +02:00
|
|
|
} SMARTLIST_FOREACH_END(e);
|
2006-12-24 03:45:46 +01:00
|
|
|
if (!get_options()->AvoidDiskWrites)
|
|
|
|
or_state_mark_dirty(get_or_state(), 0);
|
2006-01-10 23:42:44 +01:00
|
|
|
entry_guards_dirty = 0;
|
2005-07-28 21:01:48 +02:00
|
|
|
}
|
2005-08-04 21:56:41 +02:00
|
|
|
|
2006-01-10 23:42:44 +01:00
|
|
|
/** If <b>question</b> is the string "entry-guards", then dump
|
2005-12-25 00:32:35 +01:00
|
|
|
* to *<b>answer</b> a newly allocated string describing all of
|
2006-01-10 23:42:44 +01:00
|
|
|
* the nodes in the global entry_guards list. See control-spec.txt
|
2005-12-28 10:07:31 +01:00
|
|
|
* for details.
|
|
|
|
* For backward compatibility, we also handle the string "helper-nodes".
|
|
|
|
* */
|
2005-08-04 21:56:41 +02:00
|
|
|
int
|
2006-12-08 05:39:13 +01:00
|
|
|
getinfo_helper_entry_guards(control_connection_t *conn,
|
2010-07-18 17:05:58 +02:00
|
|
|
const char *question, char **answer,
|
|
|
|
const char **errmsg)
|
2005-08-04 21:56:41 +02:00
|
|
|
{
|
2009-05-08 18:12:20 +02:00
|
|
|
(void) conn;
|
2010-07-18 17:05:58 +02:00
|
|
|
(void) errmsg;
|
|
|
|
|
2006-01-10 23:42:44 +01:00
|
|
|
if (!strcmp(question,"entry-guards") ||
|
2005-12-28 10:07:31 +01:00
|
|
|
!strcmp(question,"helper-nodes")) {
|
2012-01-18 21:53:30 +01:00
|
|
|
smartlist_t *sl = smartlist_new();
|
2005-08-04 21:56:41 +02:00
|
|
|
char tbuf[ISO_TIME_LEN+1];
|
2006-10-03 21:00:18 +02:00
|
|
|
char nbuf[MAX_VERBOSE_NICKNAME_LEN+1];
|
2006-01-10 23:42:44 +01:00
|
|
|
if (!entry_guards)
|
2012-01-18 21:53:30 +01:00
|
|
|
entry_guards = smartlist_new();
|
2009-05-08 18:12:20 +02:00
|
|
|
SMARTLIST_FOREACH_BEGIN(entry_guards, entry_guard_t *, e) {
|
2005-08-04 21:56:41 +02:00
|
|
|
const char *status = NULL;
|
|
|
|
time_t when = 0;
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
const node_t *node;
|
2009-05-08 18:12:20 +02:00
|
|
|
|
2005-12-28 10:07:31 +01:00
|
|
|
if (!e->made_contact) {
|
2005-12-25 00:32:35 +01:00
|
|
|
status = "never-connected";
|
2006-09-29 01:57:44 +02:00
|
|
|
} else if (e->bad_since) {
|
|
|
|
when = e->bad_since;
|
|
|
|
status = "unusable";
|
2005-08-04 21:56:41 +02:00
|
|
|
} else {
|
|
|
|
status = "up";
|
|
|
|
}
|
2009-05-08 18:12:20 +02:00
|
|
|
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
node = node_get_by_id(e->identity);
|
|
|
|
if (node) {
|
|
|
|
node_get_verbose_nickname(node, nbuf);
|
2006-10-03 21:00:18 +02:00
|
|
|
} else {
|
2009-05-08 18:12:20 +02:00
|
|
|
nbuf[0] = '$';
|
|
|
|
base16_encode(nbuf+1, sizeof(nbuf)-1, e->identity, DIGEST_LEN);
|
|
|
|
/* e->nickname field is not very reliable if we don't know about
|
|
|
|
* this router any longer; don't include it. */
|
2006-10-03 21:00:18 +02:00
|
|
|
}
|
2009-05-08 18:12:20 +02:00
|
|
|
|
2005-08-04 21:56:41 +02:00
|
|
|
if (when) {
|
|
|
|
format_iso_time(tbuf, when);
|
2012-01-11 20:02:59 +01:00
|
|
|
smartlist_add_asprintf(sl, "%s %s %s\n", nbuf, status, tbuf);
|
2005-08-04 21:56:41 +02:00
|
|
|
} else {
|
2012-01-11 20:02:59 +01:00
|
|
|
smartlist_add_asprintf(sl, "%s %s\n", nbuf, status);
|
2005-08-04 21:56:41 +02:00
|
|
|
}
|
2009-05-08 18:12:20 +02:00
|
|
|
} SMARTLIST_FOREACH_END(e);
|
2005-08-04 21:56:41 +02:00
|
|
|
*answer = smartlist_join_strings(sl, "", 0, NULL);
|
|
|
|
SMARTLIST_FOREACH(sl, char *, c, tor_free(c));
|
|
|
|
smartlist_free(sl);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2005-08-08 23:58:48 +02:00
|
|
|
|
2008-02-09 04:11:10 +01:00
|
|
|
/** A list of configured bridges. Whenever we actually get a descriptor
|
2011-05-15 18:46:26 +02:00
|
|
|
* for one, we add it as an entry guard. Note that the order of bridges
|
|
|
|
* in this list does not necessarily correspond to the order of bridges
|
|
|
|
* in the torrc. */
|
2007-06-10 09:34:21 +02:00
|
|
|
static smartlist_t *bridge_list = NULL;
|
|
|
|
|
2011-05-15 18:46:26 +02:00
|
|
|
/** Mark every entry of the bridge list to be removed on our next call to
|
|
|
|
* sweep_bridge_list unless it has first been un-marked. */
|
|
|
|
void
|
|
|
|
mark_bridge_list(void)
|
|
|
|
{
|
|
|
|
if (!bridge_list)
|
2012-01-18 21:53:30 +01:00
|
|
|
bridge_list = smartlist_new();
|
2011-05-15 18:46:26 +02:00
|
|
|
SMARTLIST_FOREACH(bridge_list, bridge_info_t *, b,
|
|
|
|
b->marked_for_removal = 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Remove every entry of the bridge list that was marked with
|
|
|
|
* mark_bridge_list if it has not subsequently been un-marked. */
|
2007-06-10 09:34:21 +02:00
|
|
|
void
|
2011-05-15 18:46:26 +02:00
|
|
|
sweep_bridge_list(void)
|
|
|
|
{
|
|
|
|
if (!bridge_list)
|
2012-01-18 21:53:30 +01:00
|
|
|
bridge_list = smartlist_new();
|
2011-05-15 18:46:26 +02:00
|
|
|
SMARTLIST_FOREACH_BEGIN(bridge_list, bridge_info_t *, b) {
|
|
|
|
if (b->marked_for_removal) {
|
|
|
|
SMARTLIST_DEL_CURRENT(bridge_list, b);
|
2011-06-21 18:46:50 +02:00
|
|
|
bridge_free(b);
|
2011-05-15 18:46:26 +02:00
|
|
|
}
|
|
|
|
} SMARTLIST_FOREACH_END(b);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Initialize the bridge list to empty, creating it if needed. */
|
|
|
|
static void
|
2007-06-10 09:34:21 +02:00
|
|
|
clear_bridge_list(void)
|
|
|
|
{
|
|
|
|
if (!bridge_list)
|
2012-01-18 21:53:30 +01:00
|
|
|
bridge_list = smartlist_new();
|
2011-06-21 18:46:50 +02:00
|
|
|
SMARTLIST_FOREACH(bridge_list, bridge_info_t *, b, bridge_free(b));
|
2007-06-10 09:34:21 +02:00
|
|
|
smartlist_clear(bridge_list);
|
|
|
|
}
|
|
|
|
|
2011-06-28 05:43:40 +02:00
|
|
|
/** Free the bridge <b>bridge</b>. */
|
2011-06-21 18:46:50 +02:00
|
|
|
static void
|
|
|
|
bridge_free(bridge_info_t *bridge)
|
|
|
|
{
|
|
|
|
if (!bridge)
|
|
|
|
return;
|
|
|
|
|
|
|
|
tor_free(bridge->transport_name);
|
|
|
|
tor_free(bridge);
|
|
|
|
}
|
|
|
|
|
2012-08-24 18:31:09 +02:00
|
|
|
/** If we have a bridge configured whose digest matches <b>digest</b>, or a
|
|
|
|
* bridge with no known digest whose address matches any of the
|
|
|
|
* tor_addr_port_t's in <b>orports</b>, return that bridge. Else return
|
|
|
|
* NULL. */
|
2012-08-23 12:23:00 +02:00
|
|
|
static bridge_info_t *
|
|
|
|
get_configured_bridge_by_orports_digest(const char *digest,
|
|
|
|
const smartlist_t *orports)
|
|
|
|
{
|
|
|
|
if (!bridge_list)
|
|
|
|
return NULL;
|
|
|
|
SMARTLIST_FOREACH_BEGIN(bridge_list, bridge_info_t *, bridge)
|
|
|
|
{
|
|
|
|
if (tor_digest_is_zero(bridge->identity)) {
|
|
|
|
SMARTLIST_FOREACH_BEGIN(orports, tor_addr_port_t *, ap)
|
|
|
|
{
|
|
|
|
if (tor_addr_compare(&bridge->addr, &ap->addr, CMP_EXACT) == 0 &&
|
|
|
|
bridge->port == ap->port)
|
|
|
|
return bridge;
|
|
|
|
}
|
|
|
|
SMARTLIST_FOREACH_END(ap);
|
|
|
|
}
|
|
|
|
if (digest && tor_memeq(bridge->identity, digest, DIGEST_LEN))
|
|
|
|
return bridge;
|
|
|
|
}
|
|
|
|
SMARTLIST_FOREACH_END(bridge);
|
|
|
|
return NULL;
|
|
|
|
}
|
2011-07-13 19:06:07 +02:00
|
|
|
|
2012-08-24 18:31:09 +02:00
|
|
|
/** If we have a bridge configured whose digest matches <b>digest</b>, or a
|
|
|
|
* bridge with no known digest whose address matches <b>addr</b>:<b>/port</b>,
|
|
|
|
* return that bridge. Else return NULL. */
|
2007-07-18 12:06:03 +02:00
|
|
|
static bridge_info_t *
|
2011-05-15 18:46:26 +02:00
|
|
|
get_configured_bridge_by_addr_port_digest(const tor_addr_t *addr,
|
|
|
|
uint16_t port,
|
2010-06-04 02:29:29 +02:00
|
|
|
const char *digest)
|
2007-06-15 08:01:04 +02:00
|
|
|
{
|
2007-12-21 23:58:22 +01:00
|
|
|
if (!bridge_list)
|
|
|
|
return NULL;
|
2008-08-05 22:08:19 +02:00
|
|
|
SMARTLIST_FOREACH_BEGIN(bridge_list, bridge_info_t *, bridge)
|
2007-06-15 08:01:04 +02:00
|
|
|
{
|
|
|
|
if (tor_digest_is_zero(bridge->identity) &&
|
2010-06-04 02:29:29 +02:00
|
|
|
!tor_addr_compare(&bridge->addr, addr, CMP_EXACT) &&
|
|
|
|
bridge->port == port)
|
2007-07-18 12:06:03 +02:00
|
|
|
return bridge;
|
2011-05-18 01:46:47 +02:00
|
|
|
if (digest && tor_memeq(bridge->identity, digest, DIGEST_LEN))
|
2007-07-18 12:06:03 +02:00
|
|
|
return bridge;
|
2008-08-05 22:08:19 +02:00
|
|
|
}
|
|
|
|
SMARTLIST_FOREACH_END(bridge);
|
2007-07-18 12:06:03 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-06-04 02:29:29 +02:00
|
|
|
/** Wrapper around get_configured_bridge_by_addr_port_digest() to look
|
|
|
|
* it up via router descriptor <b>ri</b>. */
|
|
|
|
static bridge_info_t *
|
2010-09-29 06:38:32 +02:00
|
|
|
get_configured_bridge_by_routerinfo(const routerinfo_t *ri)
|
2010-06-04 02:29:29 +02:00
|
|
|
{
|
2012-08-23 12:23:00 +02:00
|
|
|
bridge_info_t *bi = NULL;
|
|
|
|
smartlist_t *orports = router_get_all_orports(ri);
|
|
|
|
bi = get_configured_bridge_by_orports_digest(ri->cache_info.identity_digest,
|
|
|
|
orports);
|
|
|
|
SMARTLIST_FOREACH(orports, tor_addr_port_t *, p, tor_free(p));
|
|
|
|
smartlist_free(orports);
|
|
|
|
return bi;
|
2010-06-04 02:29:29 +02:00
|
|
|
}
|
|
|
|
|
2007-07-22 00:04:18 +02:00
|
|
|
/** Return 1 if <b>ri</b> is one of our known bridges, else 0. */
|
2007-07-18 12:06:03 +02:00
|
|
|
int
|
2010-09-29 06:38:32 +02:00
|
|
|
routerinfo_is_a_configured_bridge(const routerinfo_t *ri)
|
2007-07-18 12:06:03 +02:00
|
|
|
{
|
2010-06-04 02:29:29 +02:00
|
|
|
return get_configured_bridge_by_routerinfo(ri) ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
2011-06-02 19:05:00 +02:00
|
|
|
/** Return 1 if <b>node</b> is one of our configured bridges, else 0. */
|
|
|
|
int
|
|
|
|
node_is_a_configured_bridge(const node_t *node)
|
|
|
|
{
|
2012-08-23 12:23:00 +02:00
|
|
|
int retval = 0;
|
|
|
|
smartlist_t *orports = node_get_all_orports(node);
|
|
|
|
retval = get_configured_bridge_by_orports_digest(node->identity,
|
|
|
|
orports) != NULL;
|
|
|
|
SMARTLIST_FOREACH(orports, tor_addr_port_t *, p, tor_free(p));
|
|
|
|
smartlist_free(orports);
|
2011-11-24 18:29:56 +01:00
|
|
|
return retval;
|
2011-06-02 19:05:00 +02:00
|
|
|
}
|
|
|
|
|
2010-06-04 02:29:29 +02:00
|
|
|
/** We made a connection to a router at <b>addr</b>:<b>port</b>
|
|
|
|
* without knowing its digest. Its digest turned out to be <b>digest</b>.
|
|
|
|
* If it was a bridge, and we still don't know its digest, record it.
|
|
|
|
*/
|
|
|
|
void
|
2011-05-15 18:46:26 +02:00
|
|
|
learned_router_identity(const tor_addr_t *addr, uint16_t port,
|
|
|
|
const char *digest)
|
2010-06-04 02:29:29 +02:00
|
|
|
{
|
|
|
|
bridge_info_t *bridge =
|
|
|
|
get_configured_bridge_by_addr_port_digest(addr, port, digest);
|
|
|
|
if (bridge && tor_digest_is_zero(bridge->identity)) {
|
|
|
|
memcpy(bridge->identity, digest, DIGEST_LEN);
|
|
|
|
log_notice(LD_DIR, "Learned fingerprint %s for bridge %s:%d",
|
|
|
|
hex_str(digest, DIGEST_LEN), fmt_addr(addr), port);
|
|
|
|
}
|
2007-06-15 08:01:04 +02:00
|
|
|
}
|
2007-06-12 11:17:23 +02:00
|
|
|
|
2012-06-05 17:39:31 +02:00
|
|
|
/** Return true if <b>bridge</b> has the same identity digest as
|
|
|
|
* <b>digest</b>. If <b>digest</b> is NULL, it matches
|
|
|
|
* bridges with unspecified identity digests. */
|
2012-06-02 23:21:49 +02:00
|
|
|
static int
|
|
|
|
bridge_has_digest(const bridge_info_t *bridge, const char *digest)
|
|
|
|
{
|
2012-06-05 17:39:31 +02:00
|
|
|
if (digest)
|
|
|
|
return tor_memeq(digest, bridge->identity, DIGEST_LEN);
|
|
|
|
else
|
|
|
|
return tor_digest_is_zero(bridge->identity);
|
2012-06-02 23:21:49 +02:00
|
|
|
}
|
|
|
|
|
2012-06-05 17:39:31 +02:00
|
|
|
/** We are about to add a new bridge at <b>addr</b>:<b>port</b>, with optional
|
|
|
|
* <b>digest</b> and <b>transport_name</b>. Mark for removal any previously
|
|
|
|
* existing bridge with the same address and port, and warn the user as
|
|
|
|
* appropriate.
|
2012-06-02 23:21:49 +02:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
bridge_resolve_conflicts(const tor_addr_t *addr, uint16_t port,
|
|
|
|
const char *digest, const char *transport_name)
|
|
|
|
{
|
2012-06-05 17:39:31 +02:00
|
|
|
/* Iterate the already-registered bridge list:
|
2012-06-02 23:21:49 +02:00
|
|
|
|
2012-06-05 17:39:31 +02:00
|
|
|
If you find a bridge with the same adress and port, mark it for
|
|
|
|
removal. It doesn't make sense to have two active bridges with
|
|
|
|
the same IP:PORT. If the bridge in question has a different
|
|
|
|
digest or transport than <b>digest</b>/<b>transport_name</b>,
|
|
|
|
it's probably a misconfiguration and we should warn the user.
|
2012-06-02 23:21:49 +02:00
|
|
|
*/
|
|
|
|
SMARTLIST_FOREACH_BEGIN(bridge_list, bridge_info_t *, bridge) {
|
|
|
|
if (bridge->marked_for_removal)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (tor_addr_eq(&bridge->addr, addr) && (bridge->port == port)) {
|
|
|
|
|
|
|
|
bridge->marked_for_removal = 1;
|
|
|
|
|
|
|
|
if (!bridge_has_digest(bridge, digest) ||
|
2012-06-05 17:39:31 +02:00
|
|
|
strcmp_opt(bridge->transport_name, transport_name)) {
|
2012-06-02 23:21:49 +02:00
|
|
|
/* warn the user */
|
|
|
|
char *bridge_description_new, *bridge_description_old;
|
|
|
|
tor_asprintf(&bridge_description_new, "%s:%u:%s:%s",
|
|
|
|
fmt_addr(addr), port,
|
|
|
|
digest ? hex_str(digest, DIGEST_LEN) : "",
|
|
|
|
transport_name ? transport_name : "");
|
|
|
|
tor_asprintf(&bridge_description_old, "%s:%u:%s:%s",
|
|
|
|
fmt_addr(&bridge->addr), bridge->port,
|
|
|
|
tor_digest_is_zero(bridge->identity) ?
|
|
|
|
"" : hex_str(bridge->identity,DIGEST_LEN),
|
|
|
|
bridge->transport_name ? bridge->transport_name : "");
|
|
|
|
|
|
|
|
log_warn(LD_GENERAL,"Tried to add bridge '%s', but we found a conflict"
|
|
|
|
" with the already registered bridge '%s'. We will discard"
|
|
|
|
" the old bridge and keep '%s'. If this is not what you"
|
|
|
|
" wanted, please change your configuration file accordingly.",
|
|
|
|
bridge_description_new, bridge_description_old,
|
|
|
|
bridge_description_new);
|
|
|
|
|
|
|
|
tor_free(bridge_description_new);
|
|
|
|
tor_free(bridge_description_old);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} SMARTLIST_FOREACH_END(bridge);
|
|
|
|
}
|
|
|
|
|
2007-06-10 09:34:21 +02:00
|
|
|
/** Remember a new bridge at <b>addr</b>:<b>port</b>. If <b>digest</b>
|
2011-05-15 18:46:26 +02:00
|
|
|
* is set, it tells us the identity key too. If we already had the
|
2011-06-12 16:41:32 +02:00
|
|
|
* bridge in our list, unmark it, and don't actually add anything new.
|
|
|
|
* If <b>transport_name</b> is non-NULL - the bridge is associated with a
|
2011-06-21 18:46:50 +02:00
|
|
|
* pluggable transport - we assign the transport to the bridge. */
|
2007-06-10 09:34:21 +02:00
|
|
|
void
|
2011-05-15 18:46:26 +02:00
|
|
|
bridge_add_from_config(const tor_addr_t *addr, uint16_t port,
|
2011-06-11 23:20:39 +02:00
|
|
|
const char *digest, const char *transport_name)
|
2007-06-10 09:34:21 +02:00
|
|
|
{
|
2011-05-15 18:46:26 +02:00
|
|
|
bridge_info_t *b;
|
|
|
|
|
2012-06-02 23:21:49 +02:00
|
|
|
bridge_resolve_conflicts(addr, port, digest, transport_name);
|
2011-05-15 18:46:26 +02:00
|
|
|
|
|
|
|
b = tor_malloc_zero(sizeof(bridge_info_t));
|
2008-08-05 22:08:19 +02:00
|
|
|
tor_addr_copy(&b->addr, addr);
|
2007-06-10 09:34:21 +02:00
|
|
|
b->port = port;
|
|
|
|
if (digest)
|
|
|
|
memcpy(b->identity, digest, DIGEST_LEN);
|
2011-06-21 18:46:50 +02:00
|
|
|
if (transport_name)
|
|
|
|
b->transport_name = tor_strdup(transport_name);
|
2008-12-31 15:19:57 +01:00
|
|
|
b->fetch_status.schedule = DL_SCHED_BRIDGE;
|
2007-06-10 09:34:21 +02:00
|
|
|
if (!bridge_list)
|
2012-01-18 21:53:30 +01:00
|
|
|
bridge_list = smartlist_new();
|
2011-05-15 18:46:26 +02:00
|
|
|
|
2007-06-10 09:34:21 +02:00
|
|
|
smartlist_add(bridge_list, b);
|
|
|
|
}
|
|
|
|
|
2011-04-04 00:12:26 +02:00
|
|
|
/** Return true iff <b>routerset</b> contains the bridge <b>bridge</b>. */
|
|
|
|
static int
|
|
|
|
routerset_contains_bridge(const routerset_t *routerset,
|
|
|
|
const bridge_info_t *bridge)
|
|
|
|
{
|
|
|
|
int result;
|
|
|
|
extend_info_t *extinfo;
|
|
|
|
tor_assert(bridge);
|
|
|
|
if (!routerset)
|
|
|
|
return 0;
|
|
|
|
|
2012-09-06 17:38:32 +02:00
|
|
|
extinfo = extend_info_new(
|
2011-04-04 00:12:26 +02:00
|
|
|
NULL, bridge->identity, NULL, &bridge->addr, bridge->port);
|
|
|
|
result = routerset_contains_extendinfo(routerset, extinfo);
|
|
|
|
extend_info_free(extinfo);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2007-11-04 01:15:42 +01:00
|
|
|
/** If <b>digest</b> is one of our known bridges, return it. */
|
|
|
|
static bridge_info_t *
|
2008-08-05 22:08:19 +02:00
|
|
|
find_bridge_by_digest(const char *digest)
|
2007-11-04 01:15:42 +01:00
|
|
|
{
|
|
|
|
SMARTLIST_FOREACH(bridge_list, bridge_info_t *, bridge,
|
|
|
|
{
|
2011-05-10 22:23:43 +02:00
|
|
|
if (tor_memeq(bridge->identity, digest, DIGEST_LEN))
|
2007-11-04 01:15:42 +01:00
|
|
|
return bridge;
|
|
|
|
});
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-06-05 01:51:00 +02:00
|
|
|
/* DOCDOC find_transport_name_by_bridge_addrport */
|
2012-05-18 02:07:46 +02:00
|
|
|
const char *
|
|
|
|
find_transport_name_by_bridge_addrport(const tor_addr_t *addr, uint16_t port)
|
|
|
|
{
|
|
|
|
if (!bridge_list)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
SMARTLIST_FOREACH_BEGIN(bridge_list, const bridge_info_t *, bridge) {
|
|
|
|
if (tor_addr_eq(&bridge->addr, addr) &&
|
|
|
|
(bridge->port == port))
|
|
|
|
return bridge->transport_name;
|
|
|
|
} SMARTLIST_FOREACH_END(bridge);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-06-22 23:28:11 +02:00
|
|
|
/** If <b>addr</b> and <b>port</b> match the address and port of a
|
2011-07-03 05:23:07 +02:00
|
|
|
* bridge of ours that uses pluggable transports, place its transport
|
2011-06-22 23:28:11 +02:00
|
|
|
* in <b>transport</b>.
|
2011-06-28 05:43:40 +02:00
|
|
|
*
|
2011-07-03 06:13:41 +02:00
|
|
|
* Return 0 on success (found a transport, or found a bridge with no
|
|
|
|
* transport, or found no bridge); return -1 if we should be using a
|
|
|
|
* transport, but the transport could not be found.
|
2011-06-22 23:28:11 +02:00
|
|
|
*/
|
|
|
|
int
|
2011-06-28 05:43:40 +02:00
|
|
|
find_transport_by_bridge_addrport(const tor_addr_t *addr, uint16_t port,
|
2011-07-03 05:12:32 +02:00
|
|
|
const transport_t **transport)
|
2011-06-12 00:14:11 +02:00
|
|
|
{
|
2011-07-03 06:13:41 +02:00
|
|
|
*transport = NULL;
|
2011-06-22 23:28:11 +02:00
|
|
|
if (!bridge_list)
|
2011-07-03 06:13:41 +02:00
|
|
|
return 0;
|
2011-06-22 23:28:11 +02:00
|
|
|
|
2011-07-03 05:23:07 +02:00
|
|
|
SMARTLIST_FOREACH_BEGIN(bridge_list, const bridge_info_t *, bridge) {
|
|
|
|
if (tor_addr_eq(&bridge->addr, addr) &&
|
|
|
|
(bridge->port == port)) { /* bridge matched */
|
|
|
|
if (bridge->transport_name) { /* it also uses pluggable transports */
|
|
|
|
*transport = transport_get_by_name(bridge->transport_name);
|
|
|
|
if (*transport == NULL) { /* it uses pluggable transports, but
|
|
|
|
the transport could not be found! */
|
|
|
|
return -1;
|
2011-06-22 23:28:11 +02:00
|
|
|
}
|
2011-07-03 05:23:07 +02:00
|
|
|
return 0;
|
|
|
|
} else { /* bridge matched, but it doesn't use transports. */
|
|
|
|
break;
|
2011-06-12 00:14:11 +02:00
|
|
|
}
|
2011-07-03 05:23:07 +02:00
|
|
|
}
|
|
|
|
} SMARTLIST_FOREACH_END(bridge);
|
2011-06-21 18:46:50 +02:00
|
|
|
|
2011-07-03 06:13:41 +02:00
|
|
|
*transport = NULL;
|
|
|
|
return 0;
|
2011-06-12 00:14:11 +02:00
|
|
|
}
|
|
|
|
|
2011-04-29 01:19:04 +02:00
|
|
|
/** We need to ask <b>bridge</b> for its server descriptor. */
|
2007-11-04 01:15:42 +01:00
|
|
|
static void
|
2008-08-05 22:08:19 +02:00
|
|
|
launch_direct_bridge_descriptor_fetch(bridge_info_t *bridge)
|
2007-11-04 01:15:42 +01:00
|
|
|
{
|
2008-08-05 22:08:19 +02:00
|
|
|
char *address;
|
2011-06-14 19:01:38 +02:00
|
|
|
const or_options_t *options = get_options();
|
2008-08-05 22:08:19 +02:00
|
|
|
|
2007-11-04 01:15:42 +01:00
|
|
|
if (connection_get_by_type_addr_port_purpose(
|
2008-08-05 22:08:19 +02:00
|
|
|
CONN_TYPE_DIR, &bridge->addr, bridge->port,
|
2007-11-04 01:15:42 +01:00
|
|
|
DIR_PURPOSE_FETCH_SERVERDESC))
|
|
|
|
return; /* it's already on the way */
|
2008-08-05 22:08:19 +02:00
|
|
|
|
2011-04-04 00:12:26 +02:00
|
|
|
if (routerset_contains_bridge(options->ExcludeNodes, bridge)) {
|
|
|
|
download_status_mark_impossible(&bridge->fetch_status);
|
|
|
|
log_warn(LD_APP, "Not using bridge at %s: it is in ExcludeNodes.",
|
|
|
|
safe_str_client(fmt_addr(&bridge->addr)));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-11-03 17:16:31 +01:00
|
|
|
address = tor_dup_addr(&bridge->addr);
|
|
|
|
|
2008-08-05 22:08:19 +02:00
|
|
|
directory_initiate_command(address, &bridge->addr,
|
2012-09-08 05:21:18 +02:00
|
|
|
bridge->port, 0/*no dirport*/,
|
|
|
|
bridge->identity,
|
2007-11-04 01:15:42 +01:00
|
|
|
DIR_PURPOSE_FETCH_SERVERDESC,
|
|
|
|
ROUTER_PURPOSE_BRIDGE,
|
2012-09-12 16:15:58 +02:00
|
|
|
DIRIND_ONEHOP, "authority.z", NULL, 0, 0);
|
2008-08-05 22:08:19 +02:00
|
|
|
tor_free(address);
|
2007-11-04 01:15:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Fetching the bridge descriptor from the bridge authority returned a
|
|
|
|
* "not found". Fall back to trying a direct fetch. */
|
|
|
|
void
|
2008-08-05 22:08:19 +02:00
|
|
|
retry_bridge_descriptor_fetch_directly(const char *digest)
|
2007-11-04 01:15:42 +01:00
|
|
|
{
|
|
|
|
bridge_info_t *bridge = find_bridge_by_digest(digest);
|
|
|
|
if (!bridge)
|
|
|
|
return; /* not found? oh well. */
|
|
|
|
|
2008-08-05 22:08:19 +02:00
|
|
|
launch_direct_bridge_descriptor_fetch(bridge);
|
2007-11-04 01:15:42 +01:00
|
|
|
}
|
|
|
|
|
2007-06-10 09:34:21 +02:00
|
|
|
/** For each bridge in our list for which we don't currently have a
|
|
|
|
* descriptor, fetch a new copy of its descriptor -- either directly
|
|
|
|
* from the bridge or via a bridge authority. */
|
|
|
|
void
|
2011-06-14 19:01:38 +02:00
|
|
|
fetch_bridge_descriptors(const or_options_t *options, time_t now)
|
2007-06-10 09:34:21 +02:00
|
|
|
{
|
2010-11-08 20:35:02 +01:00
|
|
|
int num_bridge_auths = get_n_authorities(BRIDGE_DIRINFO);
|
2007-07-18 09:13:15 +02:00
|
|
|
int ask_bridge_directly;
|
2007-11-16 08:31:51 +01:00
|
|
|
int can_use_bridge_authority;
|
2007-06-10 09:34:21 +02:00
|
|
|
|
|
|
|
if (!bridge_list)
|
|
|
|
return;
|
|
|
|
|
2011-07-13 19:06:07 +02:00
|
|
|
/* If we still have unconfigured managed proxies, don't go and
|
|
|
|
connect to a bridge. */
|
|
|
|
if (pt_proxies_configuration_pending())
|
|
|
|
return;
|
|
|
|
|
2008-08-05 22:08:19 +02:00
|
|
|
SMARTLIST_FOREACH_BEGIN(bridge_list, bridge_info_t *, bridge)
|
2007-06-10 09:34:21 +02:00
|
|
|
{
|
2008-12-31 15:19:57 +01:00
|
|
|
if (!download_status_is_ready(&bridge->fetch_status, now,
|
2009-01-02 21:46:32 +01:00
|
|
|
IMPOSSIBLE_TO_DOWNLOAD))
|
2007-07-18 12:06:03 +02:00
|
|
|
continue; /* don't bother, no need to retry yet */
|
2011-04-04 00:12:26 +02:00
|
|
|
if (routerset_contains_bridge(options->ExcludeNodes, bridge)) {
|
|
|
|
download_status_mark_impossible(&bridge->fetch_status);
|
|
|
|
log_warn(LD_APP, "Not using bridge at %s: it is in ExcludeNodes.",
|
|
|
|
safe_str_client(fmt_addr(&bridge->addr)));
|
|
|
|
continue;
|
|
|
|
}
|
2007-07-18 12:06:03 +02:00
|
|
|
|
2007-07-22 02:16:48 +02:00
|
|
|
/* schedule another fetch as if this one will fail, in case it does */
|
2008-12-31 15:19:57 +01:00
|
|
|
download_status_failed(&bridge->fetch_status, 0);
|
2007-07-18 12:06:03 +02:00
|
|
|
|
2007-11-16 08:31:51 +01:00
|
|
|
can_use_bridge_authority = !tor_digest_is_zero(bridge->identity) &&
|
|
|
|
num_bridge_auths;
|
|
|
|
ask_bridge_directly = !can_use_bridge_authority ||
|
|
|
|
!options->UpdateBridgesFromAuthority;
|
2007-09-21 08:14:36 +02:00
|
|
|
log_debug(LD_DIR, "ask_bridge_directly=%d (%d, %d, %d)",
|
|
|
|
ask_bridge_directly, tor_digest_is_zero(bridge->identity),
|
|
|
|
!options->UpdateBridgesFromAuthority, !num_bridge_auths);
|
2007-07-18 09:13:15 +02:00
|
|
|
|
|
|
|
if (ask_bridge_directly &&
|
2008-08-05 22:08:19 +02:00
|
|
|
!fascist_firewall_allows_address_or(&bridge->addr, bridge->port)) {
|
2007-07-18 09:13:15 +02:00
|
|
|
log_notice(LD_DIR, "Bridge at '%s:%d' isn't reachable by our "
|
2008-08-05 22:08:19 +02:00
|
|
|
"firewall policy. %s.", fmt_addr(&bridge->addr),
|
|
|
|
bridge->port,
|
2007-11-16 08:31:51 +01:00
|
|
|
can_use_bridge_authority ?
|
|
|
|
"Asking bridge authority instead" : "Skipping");
|
2007-11-16 08:33:57 +01:00
|
|
|
if (can_use_bridge_authority)
|
2007-11-04 01:15:42 +01:00
|
|
|
ask_bridge_directly = 0;
|
|
|
|
else
|
|
|
|
continue;
|
2007-07-18 09:13:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ask_bridge_directly) {
|
2007-11-04 01:15:42 +01:00
|
|
|
/* we need to ask the bridge itself for its descriptor. */
|
2008-08-05 22:08:19 +02:00
|
|
|
launch_direct_bridge_descriptor_fetch(bridge);
|
2007-06-10 09:34:21 +02:00
|
|
|
} else {
|
2007-07-22 02:16:48 +02:00
|
|
|
/* We have a digest and we want to ask an authority. We could
|
|
|
|
* combine all the requests into one, but that may give more
|
|
|
|
* hints to the bridge authority than we want to give. */
|
|
|
|
char resource[10 + HEX_DIGEST_LEN];
|
|
|
|
memcpy(resource, "fp/", 3);
|
|
|
|
base16_encode(resource+3, HEX_DIGEST_LEN+1,
|
|
|
|
bridge->identity, DIGEST_LEN);
|
|
|
|
memcpy(resource+3+HEX_DIGEST_LEN, ".z", 3);
|
|
|
|
log_info(LD_DIR, "Fetching bridge info '%s' from bridge authority.",
|
|
|
|
resource);
|
|
|
|
directory_get_from_dirserver(DIR_PURPOSE_FETCH_SERVERDESC,
|
2007-09-21 08:14:36 +02:00
|
|
|
ROUTER_PURPOSE_BRIDGE, resource, 0);
|
2007-06-10 09:34:21 +02:00
|
|
|
}
|
2008-08-05 22:08:19 +02:00
|
|
|
}
|
|
|
|
SMARTLIST_FOREACH_END(bridge);
|
2007-06-10 09:34:21 +02:00
|
|
|
}
|
|
|
|
|
2011-02-08 09:11:18 +01:00
|
|
|
/** If our <b>bridge</b> is configured to be a different address than
|
2011-03-14 21:34:33 +01:00
|
|
|
* the bridge gives in <b>node</b>, rewrite the routerinfo
|
2011-02-08 09:11:18 +01:00
|
|
|
* we received to use the address we meant to use. Now we handle
|
|
|
|
* multihomed bridges better.
|
|
|
|
*/
|
|
|
|
static void
|
2011-03-14 21:34:33 +01:00
|
|
|
rewrite_node_address_for_bridge(const bridge_info_t *bridge, node_t *node)
|
2011-02-08 09:11:18 +01:00
|
|
|
{
|
2011-03-14 21:34:33 +01:00
|
|
|
/* XXXX move this function. */
|
|
|
|
/* XXXX overridden addresses should really live in the node_t, so that the
|
|
|
|
* routerinfo_t and the microdesc_t can be immutable. But we can only
|
2011-03-14 21:46:43 +01:00
|
|
|
* do that safely if we know that no function that connects to an OR
|
|
|
|
* does so through an address from any source other than node_get_addr().
|
2011-03-14 21:34:33 +01:00
|
|
|
*/
|
2011-02-08 09:11:18 +01:00
|
|
|
tor_addr_t addr;
|
|
|
|
|
2011-03-14 21:34:33 +01:00
|
|
|
if (node->ri) {
|
|
|
|
routerinfo_t *ri = node->ri;
|
|
|
|
tor_addr_from_ipv4h(&addr, ri->addr);
|
|
|
|
|
2011-11-24 18:54:20 +01:00
|
|
|
if ((!tor_addr_compare(&bridge->addr, &addr, CMP_EXACT) &&
|
|
|
|
bridge->port == ri->or_port) ||
|
|
|
|
(!tor_addr_compare(&bridge->addr, &ri->ipv6_addr, CMP_EXACT) &&
|
|
|
|
bridge->port == ri->ipv6_orport)) {
|
2011-03-14 21:34:33 +01:00
|
|
|
/* they match, so no need to do anything */
|
|
|
|
} else {
|
2011-11-24 18:54:20 +01:00
|
|
|
if (tor_addr_family(&bridge->addr) == AF_INET) {
|
|
|
|
ri->addr = tor_addr_to_ipv4h(&bridge->addr);
|
|
|
|
tor_free(ri->address);
|
|
|
|
ri->address = tor_dup_ip(ri->addr);
|
|
|
|
ri->or_port = bridge->port;
|
|
|
|
log_info(LD_DIR,
|
|
|
|
"Adjusted bridge routerinfo for '%s' to match configured "
|
|
|
|
"address %s:%d.",
|
|
|
|
ri->nickname, ri->address, ri->or_port);
|
|
|
|
} else if (tor_addr_family(&bridge->addr) == AF_INET6) {
|
|
|
|
tor_addr_copy(&ri->ipv6_addr, &bridge->addr);
|
|
|
|
ri->ipv6_orport = bridge->port;
|
|
|
|
log_info(LD_DIR,
|
|
|
|
"Adjusted bridge routerinfo for '%s' to match configured "
|
|
|
|
"address %s:%d.",
|
|
|
|
ri->nickname, fmt_addr(&ri->ipv6_addr), ri->ipv6_orport);
|
|
|
|
} else {
|
|
|
|
log_err(LD_BUG, "Address family not supported: %d.",
|
|
|
|
tor_addr_family(&bridge->addr));
|
|
|
|
return;
|
|
|
|
}
|
2011-03-14 21:34:33 +01:00
|
|
|
}
|
2011-11-24 18:54:20 +01:00
|
|
|
|
2012-08-27 15:03:34 +02:00
|
|
|
/* Mark bridge as preferably connected to over IPv6 if its IPv6
|
|
|
|
address is in a Bridge line and ClientPreferIPv6ORPort is
|
|
|
|
set. Unless both is true, a potential IPv6 OR port of this
|
|
|
|
bridge won't get selected.
|
|
|
|
|
|
|
|
XXX ipv6_preferred is never reset (#6757) */
|
|
|
|
if (get_options()->ClientPreferIPv6ORPort == 1 &&
|
|
|
|
tor_addr_family(&bridge->addr) == AF_INET6)
|
|
|
|
node->ipv6_preferred = 1;
|
2011-11-29 15:25:04 +01:00
|
|
|
|
|
|
|
/* XXXipv6 we lack support for falling back to another address for
|
|
|
|
the same relay, warn the user */
|
2012-06-23 21:51:48 +02:00
|
|
|
if (!tor_addr_is_null(&ri->ipv6_addr)) {
|
2011-11-29 15:25:04 +01:00
|
|
|
tor_addr_port_t ap;
|
2012-08-23 12:23:00 +02:00
|
|
|
node_get_pref_orport(node, &ap);
|
2011-11-29 15:25:04 +01:00
|
|
|
log_notice(LD_CONFIG,
|
|
|
|
"Bridge '%s' has both an IPv4 and an IPv6 address. "
|
|
|
|
"Will prefer using its %s address (%s:%d).",
|
|
|
|
ri->nickname,
|
2012-09-18 14:41:14 +02:00
|
|
|
tor_addr_family(&ap.addr) == AF_INET6 ? "IPv6" : "IPv4",
|
2011-11-29 15:25:04 +01:00
|
|
|
fmt_addr(&ap.addr), ap.port);
|
|
|
|
}
|
2011-03-14 21:34:33 +01:00
|
|
|
}
|
|
|
|
if (node->rs) {
|
|
|
|
routerstatus_t *rs = node->rs;
|
|
|
|
tor_addr_from_ipv4h(&addr, rs->addr);
|
2011-02-08 09:11:18 +01:00
|
|
|
|
2011-03-14 21:34:33 +01:00
|
|
|
if (!tor_addr_compare(&bridge->addr, &addr, CMP_EXACT) &&
|
|
|
|
bridge->port == rs->or_port) {
|
|
|
|
/* they match, so no need to do anything */
|
|
|
|
} else {
|
|
|
|
rs->addr = tor_addr_to_ipv4h(&bridge->addr);
|
|
|
|
rs->or_port = bridge->port;
|
|
|
|
log_info(LD_DIR,
|
2011-03-14 22:23:28 +01:00
|
|
|
"Adjusted bridge routerstatus for '%s' to match "
|
|
|
|
"configured address %s:%d.",
|
2011-03-14 21:34:33 +01:00
|
|
|
rs->nickname, fmt_addr(&bridge->addr), rs->or_port);
|
|
|
|
}
|
|
|
|
}
|
2011-02-08 09:11:18 +01:00
|
|
|
}
|
|
|
|
|
2007-06-12 11:17:23 +02:00
|
|
|
/** We just learned a descriptor for a bridge. See if that
|
|
|
|
* digest is in our entry guard list, and add it if not. */
|
|
|
|
void
|
2007-12-24 11:31:39 +01:00
|
|
|
learned_bridge_descriptor(routerinfo_t *ri, int from_cache)
|
2007-06-12 11:17:23 +02:00
|
|
|
{
|
|
|
|
tor_assert(ri);
|
|
|
|
tor_assert(ri->purpose == ROUTER_PURPOSE_BRIDGE);
|
|
|
|
if (get_options()->UseBridges) {
|
2007-06-15 04:12:15 +02:00
|
|
|
int first = !any_bridge_descriptors_known();
|
2010-06-04 02:29:29 +02:00
|
|
|
bridge_info_t *bridge = get_configured_bridge_by_routerinfo(ri);
|
2007-07-18 12:06:03 +02:00
|
|
|
time_t now = time(NULL);
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
router_set_status(ri->cache_info.identity_digest, 1);
|
2007-07-18 12:06:03 +02:00
|
|
|
|
2007-12-22 07:11:49 +01:00
|
|
|
if (bridge) { /* if we actually want to use this one */
|
2011-03-14 21:34:33 +01:00
|
|
|
node_t *node;
|
2007-12-22 07:11:49 +01:00
|
|
|
/* it's here; schedule its re-fetch for a long time from now. */
|
2007-12-24 11:31:39 +01:00
|
|
|
if (!from_cache)
|
2008-12-31 15:19:57 +01:00
|
|
|
download_status_reset(&bridge->fetch_status);
|
2007-07-18 12:06:03 +02:00
|
|
|
|
2011-03-14 21:34:33 +01:00
|
|
|
node = node_get_mutable_by_id(ri->cache_info.identity_digest);
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
tor_assert(node);
|
2011-03-14 21:34:33 +01:00
|
|
|
rewrite_node_address_for_bridge(bridge, node);
|
Revise code for adding EntryNodes to guards.
Previously, we'd just take all the nodes in EntryNodes, see which
ones were already in the guard list, and add the ones that weren't.
There were some problems there, though:
* We'd add _every_ entry in EntryNodes, and add them in the order
they appeared in the routerlist. This wasn't a problem
until we added the ability to give country-code or IP-range
entries in the EntryNodes set, but now that we did, it is.
(Fix: We now shuffle the entry nodes before adding them; only
add up to 10*NumEntryGuards)
* We didn't screen EntryNodes for the Guard flag. That's okay
if the user has specified two or three entry nodes manually,
but if they have listed a whole subcontinent, we should
restrict ourselves to the entries that are currently guards.
(Fix: separate out the new guard from the new non-guard nodes,
and add the Guards first.)
* We'd prepend new EntryNodes _before_ the already configured
EntryNodes. This could lead to churn.
(Fix: don't prepend these.)
This patch also pre-screens EntryNodes entries for
reachableaddresses/excludenodes, even though we check for that
later. This is important now, since we cap the number of entries
we'll add.
2011-07-11 16:48:46 +02:00
|
|
|
add_an_entry_guard(node, 1, 1);
|
2011-02-08 09:11:18 +01:00
|
|
|
|
2011-11-24 17:40:10 +01:00
|
|
|
log_notice(LD_DIR, "new bridge descriptor '%s' (%s): %s", ri->nickname,
|
|
|
|
from_cache ? "cached" : "fresh", router_describe(ri));
|
2010-09-29 00:36:15 +02:00
|
|
|
/* set entry->made_contact so if it goes down we don't drop it from
|
|
|
|
* our entry node list */
|
|
|
|
entry_guard_register_connect_status(ri->cache_info.identity_digest,
|
|
|
|
1, 0, now);
|
2007-12-22 07:11:49 +01:00
|
|
|
if (first)
|
|
|
|
routerlist_retry_directory_downloads(now);
|
|
|
|
}
|
2007-06-12 11:17:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Return 1 if any of our entry guards have descriptors that
|
2007-07-18 12:06:03 +02:00
|
|
|
* are marked with purpose 'bridge' and are running. Else return 0.
|
2007-06-12 11:17:23 +02:00
|
|
|
*
|
|
|
|
* We use this function to decide if we're ready to start building
|
|
|
|
* circuits through our bridges, or if we need to wait until the
|
|
|
|
* directory "server/authority" requests finish. */
|
|
|
|
int
|
|
|
|
any_bridge_descriptors_known(void)
|
|
|
|
{
|
2007-07-29 06:38:21 +02:00
|
|
|
tor_assert(get_options()->UseBridges);
|
2007-06-12 11:17:23 +02:00
|
|
|
return choose_random_entry(NULL)!=NULL ? 1 : 0;
|
2007-07-18 12:06:03 +02:00
|
|
|
}
|
|
|
|
|
2008-06-20 06:34:39 +02:00
|
|
|
/** Return 1 if there are any directory conns fetching bridge descriptors
|
|
|
|
* that aren't marked for close. We use this to guess if we should tell
|
|
|
|
* the controller that we have a problem. */
|
|
|
|
int
|
|
|
|
any_pending_bridge_descriptor_fetches(void)
|
|
|
|
{
|
|
|
|
smartlist_t *conns = get_connection_array();
|
2012-07-17 15:33:38 +02:00
|
|
|
SMARTLIST_FOREACH_BEGIN(conns, connection_t *, conn) {
|
2008-06-20 06:34:39 +02:00
|
|
|
if (conn->type == CONN_TYPE_DIR &&
|
|
|
|
conn->purpose == DIR_PURPOSE_FETCH_SERVERDESC &&
|
|
|
|
TO_DIR_CONN(conn)->router_purpose == ROUTER_PURPOSE_BRIDGE &&
|
|
|
|
!conn->marked_for_close &&
|
2011-03-08 21:17:41 +01:00
|
|
|
conn->linked &&
|
|
|
|
conn->linked_conn && !conn->linked_conn->marked_for_close) {
|
2008-06-20 06:34:39 +02:00
|
|
|
log_debug(LD_DIR, "found one: %s", conn->address);
|
|
|
|
return 1;
|
|
|
|
}
|
2012-07-17 15:33:38 +02:00
|
|
|
} SMARTLIST_FOREACH_END(conn);
|
2008-06-20 06:34:39 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-09-24 04:41:01 +02:00
|
|
|
/** Return 1 if we have at least one descriptor for an entry guard
|
|
|
|
* (bridge or member of EntryNodes) and all descriptors we know are
|
|
|
|
* down. Else return 0. If <b>act</b> is 1, then mark the down guards
|
|
|
|
* up; else just observe and report. */
|
2007-07-29 06:38:21 +02:00
|
|
|
static int
|
2011-06-14 19:01:38 +02:00
|
|
|
entries_retry_helper(const or_options_t *options, int act)
|
2007-07-18 12:06:03 +02:00
|
|
|
{
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
const node_t *node;
|
2007-07-18 12:06:03 +02:00
|
|
|
int any_known = 0;
|
2007-07-29 06:38:21 +02:00
|
|
|
int any_running = 0;
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
int need_bridges = options->UseBridges != 0;
|
2007-06-12 11:17:23 +02:00
|
|
|
if (!entry_guards)
|
2012-01-18 21:53:30 +01:00
|
|
|
entry_guards = smartlist_new();
|
2010-09-29 06:38:32 +02:00
|
|
|
SMARTLIST_FOREACH_BEGIN(entry_guards, entry_guard_t *, e) {
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
node = node_get_by_id(e->identity);
|
|
|
|
if (node && node_has_descriptor(node) &&
|
|
|
|
node_is_bridge(node) == need_bridges) {
|
2007-07-18 12:06:03 +02:00
|
|
|
any_known = 1;
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
if (node->is_running)
|
2010-09-24 04:41:01 +02:00
|
|
|
any_running = 1; /* some entry is both known and running */
|
2010-09-29 04:32:38 +02:00
|
|
|
else if (act) {
|
2010-09-29 05:27:00 +02:00
|
|
|
/* Mark all current connections to this OR as unhealthy, since
|
2010-09-29 04:32:38 +02:00
|
|
|
* otherwise there could be one that started 30 seconds
|
|
|
|
* ago, and in 30 seconds it will time out, causing us to mark
|
|
|
|
* the node down and undermine the retry attempt. We mark even
|
|
|
|
* the established conns, since if the network just came back
|
|
|
|
* we'll want to attach circuits to fresh conns. */
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
connection_or_set_bad_connections(node->identity, 1);
|
2010-09-29 04:32:38 +02:00
|
|
|
|
2010-09-29 05:27:00 +02:00
|
|
|
/* mark this entry node for retry */
|
Initial conversion to use node_t throughout our codebase.
A node_t is an abstraction over routerstatus_t, routerinfo_t, and
microdesc_t. It should try to present a consistent interface to all
of them. There should be a node_t for a server whenever there is
* A routerinfo_t for it in the routerlist
* A routerstatus_t in the current_consensus.
(note that a microdesc_t alone isn't enough to make a node_t exist,
since microdescriptors aren't usable on their own.)
There are three ways to get a node_t right now: looking it up by ID,
looking it up by nickname, and iterating over the whole list of
microdescriptors.
All (or nearly all) functions that are supposed to return "a router"
-- especially those used in building connections and circuits --
should return a node_t, not a routerinfo_t or a routerstatus_t.
A node_t should hold all the *mutable* flags about a node. This
patch moves the is_foo flags from routerinfo_t into node_t. The
flags in routerstatus_t remain, but they get set from the consensus
and should not change.
Some other highlights of this patch are:
* Looking up routerinfo and routerstatus by nickname is now
unified and based on the "look up a node by nickname" function.
This tries to look only at the values from current consensus,
and not get confused by the routerinfo_t->is_named flag, which
could get set for other weird reasons. This changes the
behavior of how authorities (when acting as clients) deal with
nodes that have been listed by nickname.
* I tried not to artificially increase the size of the diff here
by moving functions around. As a result, some functions that
now operate on nodes are now in the wrong file -- they should
get moved to nodelist.c once this refactoring settles down.
This moving should happen as part of a patch that moves
functions AND NOTHING ELSE.
* Some old code is now left around inside #if 0/1 blocks, and
should get removed once I've verified that I don't want it
sitting around to see how we used to do things.
There are still some unimplemented functions: these are flagged
with "UNIMPLEMENTED_NODELIST()." I'll work on filling in the
implementation here, piece by piece.
I wish this patch could have been smaller, but there did not seem to
be any piece of it that was independent from the rest. Moving flags
forces many functions that once returned routerinfo_t * to return
node_t *, which forces their friends to change, and so on.
2010-09-29 21:00:41 +02:00
|
|
|
router_set_status(node->identity, 1);
|
2007-07-29 06:38:21 +02:00
|
|
|
e->can_retry = 1;
|
|
|
|
e->bad_since = 0;
|
|
|
|
}
|
2007-07-18 12:06:03 +02:00
|
|
|
}
|
2010-09-29 06:38:32 +02:00
|
|
|
} SMARTLIST_FOREACH_END(e);
|
2010-09-29 00:36:15 +02:00
|
|
|
log_debug(LD_DIR, "%d: any_known %d, any_running %d",
|
|
|
|
act, any_known, any_running);
|
2007-07-29 06:38:21 +02:00
|
|
|
return any_known && !any_running;
|
|
|
|
}
|
|
|
|
|
2010-09-24 04:41:01 +02:00
|
|
|
/** Do we know any descriptors for our bridges / entrynodes, and are
|
|
|
|
* all the ones we have descriptors for down? */
|
2007-07-29 06:38:21 +02:00
|
|
|
int
|
2011-06-14 19:01:38 +02:00
|
|
|
entries_known_but_down(const or_options_t *options)
|
2007-07-29 06:38:21 +02:00
|
|
|
{
|
2010-09-24 04:41:01 +02:00
|
|
|
tor_assert(entry_list_is_constrained(options));
|
|
|
|
return entries_retry_helper(options, 0);
|
2007-07-29 06:38:21 +02:00
|
|
|
}
|
|
|
|
|
2010-09-29 03:59:31 +02:00
|
|
|
/** Mark all down known bridges / entrynodes up. */
|
2007-07-29 06:38:21 +02:00
|
|
|
void
|
2011-06-14 19:01:38 +02:00
|
|
|
entries_retry_all(const or_options_t *options)
|
2007-07-29 06:38:21 +02:00
|
|
|
{
|
2010-09-24 04:41:01 +02:00
|
|
|
tor_assert(entry_list_is_constrained(options));
|
|
|
|
entries_retry_helper(options, 1);
|
2007-06-12 11:17:23 +02:00
|
|
|
}
|
|
|
|
|
2012-01-27 23:22:31 +01:00
|
|
|
/** Return true if we've ever had a bridge running a Tor version that can't
|
2012-01-26 00:54:59 +01:00
|
|
|
* provide microdescriptors to us. In that case fall back to asking for
|
|
|
|
* full descriptors. Eventually all bridges will support microdescriptors
|
|
|
|
* and we can take this check out; see bug 4013. */
|
|
|
|
int
|
|
|
|
any_bridges_dont_support_microdescriptors(void)
|
|
|
|
{
|
|
|
|
const node_t *node;
|
2012-01-27 23:22:31 +01:00
|
|
|
static int ever_answered_yes = 0;
|
2012-01-26 00:54:59 +01:00
|
|
|
if (!get_options()->UseBridges || !entry_guards)
|
|
|
|
return 0;
|
2012-01-27 23:22:31 +01:00
|
|
|
if (ever_answered_yes)
|
|
|
|
return 1; /* if we ever answer 'yes', always answer 'yes' */
|
2012-01-26 00:54:59 +01:00
|
|
|
SMARTLIST_FOREACH_BEGIN(entry_guards, entry_guard_t *, e) {
|
|
|
|
node = node_get_by_id(e->identity);
|
|
|
|
if (node && node->ri &&
|
|
|
|
node_is_bridge(node) && node_is_a_configured_bridge(node) &&
|
|
|
|
!tor_version_supports_microdescriptors(node->ri->platform)) {
|
|
|
|
/* This is one of our current bridges, and we know enough about
|
|
|
|
* it to know that it won't be able to answer our microdescriptor
|
|
|
|
* questions. */
|
2012-01-27 23:22:31 +01:00
|
|
|
ever_answered_yes = 1;
|
2012-01-26 00:54:59 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
} SMARTLIST_FOREACH_END(e);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-07-17 13:33:38 +02:00
|
|
|
/** Release all storage held by the list of entry guards and related
|
|
|
|
* memory structs. */
|
|
|
|
void
|
|
|
|
entry_guards_free_all(void)
|
|
|
|
{
|
|
|
|
if (entry_guards) {
|
2007-08-29 19:22:00 +02:00
|
|
|
SMARTLIST_FOREACH(entry_guards, entry_guard_t *, e,
|
|
|
|
entry_guard_free(e));
|
2007-07-17 13:33:38 +02:00
|
|
|
smartlist_free(entry_guards);
|
|
|
|
entry_guards = NULL;
|
|
|
|
}
|
|
|
|
clear_bridge_list();
|
|
|
|
smartlist_free(bridge_list);
|
|
|
|
bridge_list = NULL;
|
|
|
|
}
|
|
|
|
|