From 04bb8c804677f1ba1aa0212e34c19869c853a1e4 Mon Sep 17 00:00:00 2001
From: Roger Dingledine <arma@torproject.org>
Date: Sat, 15 May 2004 07:21:25 +0000
Subject: [PATCH] bugfix: if a circuit if borderline too old, then count it as
 too old.

bugfix: we were retrying the same circuit after getting a resolve
failure. so of course the next two tries would fail too. now we try
a new circuit each time (at most three times).


svn:r1867
---
 src/or/circuituse.c |  2 +-
 src/or/or.h         |  2 --
 src/or/relay.c      | 11 ++++++++++-
 3 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/src/or/circuituse.c b/src/or/circuituse.c
index 1374f0a50c..35bfb968d3 100644
--- a/src/or/circuituse.c
+++ b/src/or/circuituse.c
@@ -56,7 +56,7 @@ static int circuit_is_acceptable(circuit_t *circ,
 
   if(purpose == CIRCUIT_PURPOSE_C_GENERAL)
     if(circ->timestamp_dirty &&
-       circ->timestamp_dirty+options.NewCircuitPeriod < now)
+       circ->timestamp_dirty+options.NewCircuitPeriod <= now)
       return 0;
 
   if(conn) {
diff --git a/src/or/or.h b/src/or/or.h
index a8eeca897e..924131cf73 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -1149,8 +1149,6 @@ extern unsigned long stats_n_relay_cells_delivered;
 
 int circuit_receive_relay_cell(cell_t *cell, circuit_t *circ,
                                int cell_direction);
-int circuit_package_relay_cell(cell_t *cell, circuit_t *circ,
-                               int cell_direction, crypt_path_t *layer_hint);
 
 void relay_header_pack(char *dest, const relay_header_t *src);
 void relay_header_unpack(relay_header_t *dest, const char *src);
diff --git a/src/or/relay.c b/src/or/relay.c
index 444b940101..47a3c67d6c 100644
--- a/src/or/relay.c
+++ b/src/or/relay.c
@@ -10,6 +10,8 @@
 
 #include "or.h"
 
+extern or_options_t options; /* command-line and config-file options */
+
 static int relay_crypt(circuit_t *circ, cell_t *cell, int cell_direction,
                 crypt_path_t **layer_hint, char *recognized);
 static connection_t *relay_lookup_conn(circuit_t *circ, cell_t *cell, int cell_direction);
@@ -281,7 +283,7 @@ static int relay_crypt(circuit_t *circ, cell_t *cell, int cell_direction,
  *  - Encrypt it to the right layer
  *  - connection_or_write_cell_to_buf to the right conn
  */
-int
+static int
 circuit_package_relay_cell(cell_t *cell, circuit_t *circ,
                            int cell_direction,
                            crypt_path_t *layer_hint)
@@ -509,8 +511,15 @@ connection_edge_process_relay_cell_not_open(
       if (client_dns_incr_failures(conn->socks_request->address)
           < MAX_RESOLVE_FAILURES) {
         /* We haven't retried too many times; reattach the connection. */
+        log_fn(LOG_INFO,"Resolve of '%s' failed, trying again.",
+               conn->socks_request->address);
+        circuit_log_path(LOG_INFO,circ);
         conn->state = AP_CONN_STATE_CIRCUIT_WAIT;
         circuit_detach_stream(circ,conn);
+        tor_assert(circ->timestamp_dirty);
+        circ->timestamp_dirty -= options.NewCircuitPeriod;
+        /* make sure not to expire/retry the stream quite yet */
+        conn->timestamp_lastread = time(NULL);
         if(connection_ap_handshake_attach_circuit(conn) >= 0)
           return 0;
         /* else, conn will get closed below */
-- 
GitLab