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

[or-cvs] r8620: bugfix and cleanups re: entry guards. (tor/trunk/src/or)



Author: arma
Date: 2006-10-06 19:37:07 -0400 (Fri, 06 Oct 2006)
New Revision: 8620

Modified:
   tor/trunk/src/or/circuitbuild.c
   tor/trunk/src/or/circuituse.c
   tor/trunk/src/or/connection.c
   tor/trunk/src/or/connection_or.c
   tor/trunk/src/or/or.h
Log:
bugfix and cleanups re: entry guards.


Modified: tor/trunk/src/or/circuitbuild.c
===================================================================
--- tor/trunk/src/or/circuitbuild.c	2006-10-06 22:41:04 UTC (rev 8619)
+++ tor/trunk/src/or/circuitbuild.c	2006-10-06 23:37:07 UTC (rev 8620)
@@ -1772,11 +1772,11 @@
 
 /** Check whether the entry guard <b>e</b> is usable, given the directory
  * authorities' opinion about the rouer (stored in <b>ri</b>) and the user's
- * configuration (in <b>options</b>).  Set <b>e</b>-&gt;bad_since
- * accordingly. Return true iff the entry guard's status changs.*/
+ * configuration (in <b>options</b>). Set <b>e</b>-&gt;bad_since
+ * accordingly. Return true iff the entry guard's status changes. */
 static int
 entry_guard_set_status(entry_guard_t *e, routerinfo_t *ri,
-                       or_options_t *options)
+                       time_t now, or_options_t *options)
 {
   const char *reason = NULL;
   char buf[HEX_DIGEST_LEN+1];
@@ -1798,16 +1798,16 @@
   if (reason && ! e->bad_since) {
     /* Router is newly bad. */
     base16_encode(buf, sizeof(buf), e->identity, DIGEST_LEN);
-    log_info(LD_CIRC, "Entry guard %s (%s) is %s: marking as unusable",
+    log_info(LD_CIRC, "Entry guard %s (%s) is %s: marking as unusable.",
              e->nickname, buf, reason);
 
-    e->bad_since = time(NULL);
+    e->bad_since = now;
     changed = 1;
   } else if (!reason && e->bad_since) {
     /* 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: "
-             "marking as ok", e->nickname, buf);
+             "marking as ok.", e->nickname, buf);
 
     e->bad_since = 0;
     changed = 1;
@@ -1841,8 +1841,8 @@
  * - Listed as either up or never yet contacted;
  * - Present in the routerlist;
  * - Listed as 'stable' or 'fast' by the current dirserver concensus,
- *   if demanded by <b>need_uptime</b> or <b>need_capacity</b>; and
- * - Allowed by our current ReachableAddresses config option.
+ *   if demanded by <b>need_uptime</b> or <b>need_capacity</b>;
+ * - Allowed by our current ReachableAddresses config option; and
  * - Currently thought to be reachable by us (unless assume_reachable
  *   is true).
  */
@@ -1987,7 +1987,7 @@
 }
 
 /** How long (in seconds) do we allow an entry guard to be nonfunctional,
- * unlisted, excuded, or otherwise nonusable before we give up on it? */
+ * unlisted, excluded, or otherwise nonusable before we give up on it? */
 #define ENTRY_GUARD_REMOVE_AFTER (30*24*60*60)
 
 /** Remove all entry guards that have been down or unlisted for so
@@ -2047,7 +2047,7 @@
   SMARTLIST_FOREACH(entry_guards, entry_guard_t *, entry,
     {
       routerinfo_t *r = router_get_by_digest(entry->identity);
-      if (entry_guard_set_status(entry, r, options))
+      if (entry_guard_set_status(entry, r, now, options))
         changed = 1;
 
       log_info(LD_CIRC, "Summary: Entry '%s' is %s, %s and %s.",
@@ -2074,7 +2074,8 @@
  * Return 0 normally, or -1 if we want to tear down the new connection.
  */
 int
-entry_guard_register_connect_status(const char *digest, int succeeded)
+entry_guard_register_connect_status(const char *digest, int succeeded,
+                                    time_t now)
 {
   int changed = 0;
   int refuse_conn = 0;
@@ -2105,7 +2106,7 @@
       log_info(LD_CIRC, "Entry guard '%s' (%s) is now reachable again. Good.",
                entry->nickname, buf);
       entry->unreachable_since = 0;
-      entry->last_attempted = time(NULL);
+      entry->last_attempted = now;
       changed = 1;
     }
     if (!entry->made_contact) {
@@ -2127,6 +2128,7 @@
     } else if (!entry->unreachable_since) {
       log_info(LD_CIRC, "Unable to connect to entry guard '%s' (%s). "
                "Marking as unreachable.", entry->nickname, buf);
+      entry->unreachable_since = entry->last_attempted = now;
       changed = 1;
     } else {
       char tbuf[ISO_TIME_LEN+1];
@@ -2134,7 +2136,7 @@
       log_debug(LD_CIRC, "Failed to connect to unreachable entry guard "
                 "'%s' (%s).  It has been unreachable since %s.",
                 entry->nickname, buf, tbuf);
-      entry->last_attempted = time(NULL);
+      entry->last_attempted = now;
     }
   }
 

Modified: tor/trunk/src/or/circuituse.c
===================================================================
--- tor/trunk/src/or/circuituse.c	2006-10-06 22:41:04 UTC (rev 8619)
+++ tor/trunk/src/or/circuituse.c	2006-10-06 23:37:07 UTC (rev 8620)
@@ -740,7 +740,8 @@
                "(%s:%d). I'm going to try to rotate to a better connection.",
                n_conn->_base.address, n_conn->_base.port);
       n_conn->_base.or_is_obsolete = 1;
-      entry_guard_register_connect_status(n_conn->identity_digest, 0);
+      entry_guard_register_connect_status(n_conn->identity_digest, 0,
+                                          time(NULL));
     }
   }
 

Modified: tor/trunk/src/or/connection.c
===================================================================
--- tor/trunk/src/or/connection.c	2006-10-06 22:41:04 UTC (rev 8619)
+++ tor/trunk/src/or/connection.c	2006-10-06 23:37:07 UTC (rev 8620)
@@ -398,6 +398,7 @@
   dir_connection_t *dir_conn;
   or_connection_t *or_conn;
   edge_connection_t *edge_conn;
+  time_t now = time(NULL);
 
   assert(conn->marked_for_close);
 
@@ -427,8 +428,8 @@
       /* Remember why we're closing this connection. */
       if (conn->state != OR_CONN_STATE_OPEN) {
         if (connection_or_nonopen_was_started_here(or_conn)) {
-          rep_hist_note_connect_failed(or_conn->identity_digest, time(NULL));
-          entry_guard_register_connect_status(or_conn->identity_digest, 0);
+          rep_hist_note_connect_failed(or_conn->identity_digest, now);
+          entry_guard_register_connect_status(or_conn->identity_digest,0,now);
           router_set_status(or_conn->identity_digest, 0);
           control_event_or_conn_status(or_conn, OR_CONN_EVENT_FAILED);
         }
@@ -442,10 +443,10 @@
          * flushing still get noted as dead, not disconnected.  But this is an
          * improvement. -NM
          */
-        rep_hist_note_disconnect(or_conn->identity_digest, time(NULL));
+        rep_hist_note_disconnect(or_conn->identity_digest, now);
         control_event_or_conn_status(or_conn, OR_CONN_EVENT_CLOSED);
       } else if (or_conn->identity_digest) {
-        rep_hist_note_connection_died(or_conn->identity_digest, time(NULL));
+        rep_hist_note_connection_died(or_conn->identity_digest, now);
         control_event_or_conn_status(or_conn, OR_CONN_EVENT_CLOSED);
       }
       break;

Modified: tor/trunk/src/or/connection_or.c
===================================================================
--- tor/trunk/src/or/connection_or.c	2006-10-06 22:41:04 UTC (rev 8619)
+++ tor/trunk/src/or/connection_or.c	2006-10-06 23:37:07 UTC (rev 8620)
@@ -448,7 +448,8 @@
        * an https proxy, our https proxy is down. Don't blame the
        * Tor server. */
       if (!options->HttpsProxy) {
-        entry_guard_register_connect_status(conn->identity_digest, 0);
+        entry_guard_register_connect_status(conn->identity_digest, 0,
+                                            time(NULL));
         router_set_status(conn->identity_digest, 0);
       }
       control_event_or_conn_status(conn, OR_CONN_EVENT_FAILED);
@@ -622,7 +623,7 @@
              "Identity key not as expected for router at %s:%d: wanted %s "
              "but got %s",
              conn->_base.address, conn->_base.port, expected, seen);
-      entry_guard_register_connect_status(conn->identity_digest, 0);
+      entry_guard_register_connect_status(conn->identity_digest, 0, time(NULL));
       router_set_status(conn->identity_digest, 0);
       control_event_or_conn_status(conn, OR_CONN_EVENT_FAILED);
       as_advertised = 0;
@@ -684,7 +685,8 @@
   control_event_or_conn_status(conn, OR_CONN_EVENT_CONNECTED);
   if (started_here) {
     rep_hist_note_connect_succeeded(conn->identity_digest, time(NULL));
-    if (entry_guard_register_connect_status(conn->identity_digest, 1) < 0) {
+    if (entry_guard_register_connect_status(conn->identity_digest, 1,
+                                            time(NULL)) < 0) {
       /* pending circs get closed in circuit_about_to_close_connection() */
       return -1;
     }

Modified: tor/trunk/src/or/or.h
===================================================================
--- tor/trunk/src/or/or.h	2006-10-06 22:41:04 UTC (rev 8619)
+++ tor/trunk/src/or/or.h	2006-10-06 23:37:07 UTC (rev 8620)
@@ -1723,7 +1723,8 @@
 const char *build_state_get_exit_nickname(cpath_build_state_t *state);
 
 void entry_guards_compute_status(void);
-int entry_guard_register_connect_status(const char *digest, int succeeded);
+int entry_guard_register_connect_status(const char *digest, int succeeded,
+                                        time_t now);
 void entry_nodes_should_be_added(void);
 void entry_guards_prepend_from_config(void);
 void entry_guards_update_state(or_state_t *state);