[or-cvs] [tor/master 24/28] Be more proactive about closing unused circuits.

nickm at torproject.org nickm at torproject.org
Tue Jun 29 23:07:14 UTC 2010


Author: Mike Perry <mikeperry-git at fscked.org>
Date: Tue, 15 Jun 2010 14:46:01 -0700
Subject: Be more proactive about closing unused circuits.
Commit: 82922ea45a24e7f79ac4c1ddf4d9de02c604546d

We need to ensure that we close timeout measurement circuits. While
we're at it, we should close really old circuits of certain types that
aren't in use, and log really old circuits of other types.
---
 src/or/circuituse.c |   30 ++++++++++++++++++++----------
 src/or/or.h         |    3 +++
 2 files changed, 23 insertions(+), 10 deletions(-)

diff --git a/src/or/circuituse.c b/src/or/circuituse.c
index 5027eb5..0187448 100644
--- a/src/or/circuituse.c
+++ b/src/or/circuituse.c
@@ -717,17 +717,27 @@ circuit_expire_old_circuits_clientside(time_t now)
                 circ->n_circ_id, (int)(now - circ->timestamp_dirty),
                 circ->purpose);
       circuit_mark_for_close(circ, END_CIRC_REASON_FINISHED);
-    // XXX: Do we ever mark non-dirty odd-purpose circuits for close?
-    // XXX: See irc backlog. Want to log for those circuits not mentioned.
-    //      But remember to add flag. this is called 1x/sec
-    } else if (!circ->timestamp_dirty &&
-               circ->state == CIRCUIT_STATE_OPEN &&
-               circ->purpose == CIRCUIT_PURPOSE_C_GENERAL) {
+    } else if (!circ->timestamp_dirty && circ->state == CIRCUIT_STATE_OPEN) {
       if (circ->timestamp_created < cutoff) {
-        log_debug(LD_CIRC,
-                  "Closing circuit that has been unused for %d seconds.",
-                  (int)(now - circ->timestamp_created));
-        circuit_mark_for_close(circ, END_CIRC_REASON_FINISHED);
+        if (circ->purpose == CIRCUIT_PURPOSE_C_GENERAL ||
+                circ->purpose == CIRCUIT_PURPOSE_C_MEASURE_TIMEOUT ||
+                circ->purpose == CIRCUIT_PURPOSE_S_ESTABLISH_INTRO ||
+                circ->purpose == CIRCUIT_PURPOSE_TESTING ||
+                (circ->purpose >= CIRCUIT_PURPOSE_C_INTRODUCING &&
+                circ->purpose <= CIRCUIT_PURPOSE_C_REND_READY_INTRO_ACKED) ||
+                circ->purpose == CIRCUIT_PURPOSE_S_CONNECT_REND) {
+          log_debug(LD_CIRC,
+                    "Closing circuit that has been unused for %d seconds.",
+                    (int)(now - circ->timestamp_created));
+          circuit_mark_for_close(circ, END_CIRC_REASON_FINISHED);
+        } else if (!TO_ORIGIN_CIRCUIT(circ)->is_ancient) {
+          log_notice(LD_CIRC,
+                     "Ancient non-dirty circuit %d is still around after "
+                     "%ld seconds.",
+                     TO_ORIGIN_CIRCUIT(circ)->global_identifier,
+                     now - circ->timestamp_created);
+          TO_ORIGIN_CIRCUIT(circ)->is_ancient = 1;
+        }
       }
     }
   }
diff --git a/src/or/or.h b/src/or/or.h
index e1483e6..cd68415 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -2157,6 +2157,9 @@ typedef struct origin_circuit_t {
    * to the specification? */
   unsigned int remaining_relay_early_cells : 4;
 
+  /** Set if this circuit insanely old and if we already informed the user */
+  unsigned int is_ancient : 1;
+
   /** What commands were sent over this circuit that decremented the
    * RELAY_EARLY counter? This is for debugging task 878. */
   uint8_t relay_early_commands[MAX_RELAY_EARLY_CELLS_PER_CIRCUIT];
-- 
1.7.1




More information about the tor-commits mailing list