[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] PredictedCircsRelevanceTime: limit how long we predict a port will be used



commit 898154f71779a614e2fd100fb45a788b75207efb
Author: unixninja92 <charlesvt@xxxxxxxxx>
Date:   Sat Sep 14 21:40:19 2013 +0200

    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(-)

diff --git a/changes/ticket9176 b/changes/ticket9176
new file mode 100644
index 0000000..bee3d2f
--- /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 5ce7bad..460bf3e 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 bd038f7..5ca63e6 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 13404ba..309e597 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. */



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits