From 898154f71779a614e2fd100fb45a788b75207efb Mon Sep 17 00:00:00 2001 From: unixninja92 Date: Sat, 14 Sep 2013 21:40:19 +0200 Subject: [PATCH 1/7] PredictedCircsRelevanceTime: limit how long we predict a port will be used By default, after you've made a connection to port XYZ, we assume you might still want to have an exit ready to connect to XYZ for one hour. This patch lets you lower that interval. Implements ticket 91 --- changes/ticket9176 | 4 ++++ src/or/config.c | 1 + src/or/or.h | 3 +++ src/or/rephist.c | 20 ++++++++++++-------- 4 files changed, 20 insertions(+), 8 deletions(-) create mode 100644 changes/ticket9176 diff --git a/changes/ticket9176 b/changes/ticket9176 new file mode 100644 index 0000000000..bee3d2f343 --- /dev/null +++ b/changes/ticket9176 @@ -0,0 +1,4 @@ + o Minor features: + + - Made PREDICTED_CIRCS_RELEVANCE_TIME configurable from config + file. Implements ticket #9176. Patch by unixninja92. diff --git a/src/or/config.c b/src/or/config.c index 5ce7bad493..460bf3ec41 100644 --- a/src/or/config.c +++ b/src/or/config.c @@ -314,6 +314,7 @@ static config_var_t option_vars_[] = { V(NATDListenAddress, LINELIST, NULL), VPORT(NATDPort, LINELIST, NULL), V(Nickname, STRING, NULL), + V(PredictedCircsRelevanceTime, INTERVAL, "1 hour"), V(WarnUnsafeSocks, BOOL, "1"), OBSOLETE("NoPublish"), VAR("NodeFamily", LINELIST, NodeFamilies, NULL), diff --git a/src/or/or.h b/src/or/or.h index bd038f783c..5ca63e605b 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -3673,6 +3673,9 @@ typedef struct { * a new one? */ int MaxCircuitDirtiness; /**< Never use circs that were first used more than this interval ago. */ + int PredictedCircsRelevanceTime; /** How long after we've seen a request for + * a given port, do we want to continue + * to make connections to the same port? */ uint64_t BandwidthRate; /**< How much bandwidth, on average, are we willing * to use in a second? */ uint64_t BandwidthBurst; /**< How much bandwidth, at maximum, are we willing diff --git a/src/or/rephist.c b/src/or/rephist.c index 13404badf4..309e597551 100644 --- a/src/or/rephist.c +++ b/src/or/rephist.c @@ -1862,22 +1862,20 @@ rep_hist_note_used_port(time_t now, uint16_t port) add_predicted_port(now, port); } -/** For this long after we've seen a request for a given port, assume that - * we'll want to make connections to the same port in the future. */ -#define PREDICTED_CIRCS_RELEVANCE_TIME (60*60) - /** Return a newly allocated pointer to a list of uint16_t * for ports that * are likely to be asked for in the near future. */ smartlist_t * rep_hist_get_predicted_ports(time_t now) { + int predicted_circs_relevance_time; smartlist_t *out = smartlist_new(); tor_assert(predicted_ports_list); + predicted_circs_relevance_time = get_options()->PredictedCircsRelevanceTime; /* clean out obsolete entries */ SMARTLIST_FOREACH_BEGIN(predicted_ports_list, predicted_port_t *, pp) { - if (pp->time + PREDICTED_CIRCS_RELEVANCE_TIME < now) { + if (pp->time + predicted_circs_relevance_time < now) { log_debug(LD_CIRC, "Expiring predicted port %d", pp->port); rephist_total_alloc -= sizeof(predicted_port_t); @@ -1944,14 +1942,17 @@ int rep_hist_get_predicted_internal(time_t now, int *need_uptime, int *need_capacity) { + int predicted_circs_relevance_time; + predicted_circs_relevance_time = get_options()->PredictedCircsRelevanceTime; + if (!predicted_internal_time) { /* initialize it */ predicted_internal_time = now; predicted_internal_uptime_time = now; predicted_internal_capacity_time = now; } - if (predicted_internal_time + PREDICTED_CIRCS_RELEVANCE_TIME < now) + if (predicted_internal_time + predicted_circs_relevance_time < now) return 0; /* too long ago */ - if (predicted_internal_uptime_time + PREDICTED_CIRCS_RELEVANCE_TIME >= now) + if (predicted_internal_uptime_time + predicted_circs_relevance_time >= now) *need_uptime = 1; // Always predict that we need capacity. *need_capacity = 1; @@ -1963,8 +1964,11 @@ rep_hist_get_predicted_internal(time_t now, int *need_uptime, int any_predicted_circuits(time_t now) { + int predicted_circs_relevance_time; + predicted_circs_relevance_time = get_options()->PredictedCircsRelevanceTime; + return smartlist_len(predicted_ports_list) || - predicted_internal_time + PREDICTED_CIRCS_RELEVANCE_TIME >= now; + predicted_internal_time + predicted_circs_relevance_time >= now; } /** Return 1 if we have no need for circuits currently, else return 0. */ From 52fbb9f623505a29975bea971478fc1e65591575 Mon Sep 17 00:00:00 2001 From: unixninja92 Date: Sat, 14 Sep 2013 22:32:59 +0200 Subject: [PATCH 2/7] Added Documentation for PredictedCircsRelevanceTime config file argument. --- doc/tor.1.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/doc/tor.1.txt b/doc/tor.1.txt index a1e1c08ba4..39e52076c8 100644 --- a/doc/tor.1.txt +++ b/doc/tor.1.txt @@ -523,6 +523,10 @@ GENERAL OPTIONS following the Tor specification. Otherwise, they are logged with severity \'info'. (Default: 0) +**PredictedCircsRelevanceTime** __NUM__:: + Set how long we will make connections to a port after seeing a request for + that port. (Default: 1 hour) + **RunAsDaemon** **0**|**1**:: If 1, Tor forks and daemonizes to the background. This option has no effect on Windows; instead you should use the --service command-line option. From 5c310a4fa2c13a52dc3fd39368788c3e75be6cb0 Mon Sep 17 00:00:00 2001 From: unixninja92 Date: Wed, 25 Sep 2013 01:45:00 +0200 Subject: [PATCH 3/7] Added max value to PredictedCircsRelevanceTime. --- src/or/config.c | 12 ++++++++++++ src/or/or.h | 4 ++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/or/config.c b/src/or/config.c index 460bf3ec41..11320746a2 100644 --- a/src/or/config.c +++ b/src/or/config.c @@ -2385,6 +2385,11 @@ compute_publishserverdescriptor(or_options_t *options) * services can overload the directory system. */ #define MIN_REND_POST_PERIOD (10*60) +/** Higest allowable value for PredictedCircsRelevanceTime; if this is + * too high, our selection of exits will decrease for an extended + * period of time to an uncomfortable level .*/ +#define MAX_PREDICTED_CIRCS_RELEVANCE (24*60*60) + /** Highest allowable value for RendPostPeriod. */ #define MAX_DIR_PERIOD (MIN_ONION_KEY_LIFETIME/2) @@ -2832,6 +2837,13 @@ options_validate(or_options_t *old_options, or_options_t *options, options->RendPostPeriod = MAX_DIR_PERIOD; } + if (options->PredictedCircsRelevanceTime > + MAX_PREDICTED_CIRCS_RELEVANCE) { + log_warn(LD_CONFIG, "PredictedCircsRelevanceTime is too large; " + "clipping to %ds.", MAX_PREDICTED_CIRCS_RELEVANCE); + options->PredictedCircsRelevanceTime = MAX_PREDICTED_CIRCS_RELEVANCE; + } + if (options->Tor2webMode && options->LearnCircuitBuildTimeout) { /* LearnCircuitBuildTimeout and Tor2webMode are incompatible in * two ways: diff --git a/src/or/or.h b/src/or/or.h index 5ca63e605b..0df34cd825 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -3673,9 +3673,9 @@ typedef struct { * a new one? */ int MaxCircuitDirtiness; /**< Never use circs that were first used more than this interval ago. */ - int PredictedCircsRelevanceTime; /** How long after we've seen a request for + int PredictedCircsRelevanceTime; /** How long after we've requested a connection for * a given port, do we want to continue - * to make connections to the same port? */ + * to pick exits that support that port? */ uint64_t BandwidthRate; /**< How much bandwidth, on average, are we willing * to use in a second? */ uint64_t BandwidthBurst; /**< How much bandwidth, at maximum, are we willing From d47d147307c8880d3d29fdb2da0b788afbb92556 Mon Sep 17 00:00:00 2001 From: unixninja92 Date: Fri, 20 Sep 2013 08:31:10 -0400 Subject: [PATCH 4/7] More correctly documented PredictedCircsRelevanceTime in tor.1.txt --- doc/tor.1.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/tor.1.txt b/doc/tor.1.txt index 39e52076c8..d9ff4eed9a 100644 --- a/doc/tor.1.txt +++ b/doc/tor.1.txt @@ -524,8 +524,8 @@ GENERAL OPTIONS \'info'. (Default: 0) **PredictedCircsRelevanceTime** __NUM__:: - Set how long we will make connections to a port after seeing a request for - that port. (Default: 1 hour) + Set how long, after having requested a connection to a given port, we will + search for exits that support that port. (Default: 1 hour) **RunAsDaemon** **0**|**1**:: If 1, Tor forks and daemonizes to the background. This option has no effect From 4f03804b080afd78d6242aece1e3aa3d62a00191 Mon Sep 17 00:00:00 2001 From: unixninja92 Date: Wed, 25 Sep 2013 02:05:25 +0200 Subject: [PATCH 5/7] Fixed spacing. --- src/or/config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/or/config.c b/src/or/config.c index 11320746a2..db111b5e26 100644 --- a/src/or/config.c +++ b/src/or/config.c @@ -2837,7 +2837,7 @@ options_validate(or_options_t *old_options, or_options_t *options, options->RendPostPeriod = MAX_DIR_PERIOD; } - if (options->PredictedCircsRelevanceTime > + if (options->PredictedCircsRelevanceTime > MAX_PREDICTED_CIRCS_RELEVANCE) { log_warn(LD_CONFIG, "PredictedCircsRelevanceTime is too large; " "clipping to %ds.", MAX_PREDICTED_CIRCS_RELEVANCE); From 2c25bb413ec44257a8b8692958a348aaa6553c8c Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 5 Mar 2014 14:25:38 -0500 Subject: [PATCH 6/7] Lower the maximum for PrecictedCircsRelevanceTime to one hour --- doc/tor.1.txt | 6 ++++-- src/or/config.c | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/doc/tor.1.txt b/doc/tor.1.txt index d9ff4eed9a..a285dfd5b1 100644 --- a/doc/tor.1.txt +++ b/doc/tor.1.txt @@ -524,8 +524,10 @@ GENERAL OPTIONS \'info'. (Default: 0) **PredictedCircsRelevanceTime** __NUM__:: - Set how long, after having requested a connection to a given port, we will - search for exits that support that port. (Default: 1 hour) + Set how long, after the client has mad an anonymized connection to a + given port, we will try to make sure that we build circuits to + exits that support that port. The maximum value for this option is 1 + hour. (Default: 1 hour) **RunAsDaemon** **0**|**1**:: If 1, Tor forks and daemonizes to the background. This option has no effect diff --git a/src/or/config.c b/src/or/config.c index db111b5e26..0529714194 100644 --- a/src/or/config.c +++ b/src/or/config.c @@ -2388,7 +2388,7 @@ compute_publishserverdescriptor(or_options_t *options) /** Higest allowable value for PredictedCircsRelevanceTime; if this is * too high, our selection of exits will decrease for an extended * period of time to an uncomfortable level .*/ -#define MAX_PREDICTED_CIRCS_RELEVANCE (24*60*60) +#define MAX_PREDICTED_CIRCS_RELEVANCE (60*60) /** Highest allowable value for RendPostPeriod. */ #define MAX_DIR_PERIOD (MIN_ONION_KEY_LIFETIME/2) From 25374d307d5fc0731eb116dc8e9840bfbbff9167 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 5 Mar 2014 14:27:07 -0500 Subject: [PATCH 7/7] Fix wide lines. --- src/or/or.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/or/or.h b/src/or/or.h index 0df34cd825..1f5fce45c1 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -3673,9 +3673,10 @@ typedef struct { * a new one? */ int MaxCircuitDirtiness; /**< Never use circs that were first used more than this interval ago. */ - int PredictedCircsRelevanceTime; /** How long after we've requested a connection for - * a given port, do we want to continue - * to pick exits that support that port? */ + int PredictedCircsRelevanceTime; /** How long after we've requested a + * connection for a given port, do we want + * to continue to pick exits that support + * that port? */ uint64_t BandwidthRate; /**< How much bandwidth, on average, are we willing * to use in a second? */ uint64_t BandwidthBurst; /**< How much bandwidth, at maximum, are we willing