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

[or-cvs] r8520: Improvement to last entry guards patch: track when we last a (in tor/trunk: . src/common src/or)



Author: nickm
Date: 2006-09-28 19:57:49 -0400 (Thu, 28 Sep 2006)
New Revision: 8520

Modified:
   tor/trunk/
   tor/trunk/src/common/util.c
   tor/trunk/src/or/circuitbuild.c
Log:
 r8974@Kushana:  nickm | 2006-09-28 17:05:59 -0400
 Improvement to last entry guards patch: track when we last attempted to connect to a node in our state file along with how long it has been unreachable.  Also clarify behavior of parse_iso_time() when it gets extra characters.



Property changes on: tor/trunk
___________________________________________________________________
 svk:merge ticket from /tor/trunk [r8974] on c95137ef-5f19-0410-b913-86e773d04f59

Modified: tor/trunk/src/common/util.c
===================================================================
--- tor/trunk/src/common/util.c	2006-09-28 23:57:44 UTC (rev 8519)
+++ tor/trunk/src/common/util.c	2006-09-28 23:57:49 UTC (rev 8520)
@@ -910,6 +910,10 @@
   strftime(buf, ISO_TIME_LEN+1, "%Y-%m-%d %H:%M:%S", tor_gmtime_r(&t, &tm));
 }
 
+/** Given an ISO-formatted UTC time value (after the epoch) in <b>cp</b>,
+ * parse it and store its value in *<b>t</b>.  Return 0 on success, -1 on
+ * failure.  Ignore extraneous stuff in <b>cp</b> separated by whitespace from
+ * the end of the time string. */
 int
 parse_iso_time(const char *cp, time_t *t)
 {

Modified: tor/trunk/src/or/circuitbuild.c
===================================================================
--- tor/trunk/src/or/circuitbuild.c	2006-09-28 23:57:44 UTC (rev 8519)
+++ tor/trunk/src/or/circuitbuild.c	2006-09-28 23:57:49 UTC (rev 8520)
@@ -2275,6 +2275,7 @@
         break;
     } else {
       time_t when;
+      time_t last_try = 0;
       if (!node) {
         *msg = tor_strdup("Unable to parse entry nodes: "
                "EntryGuardDownSince/UnlistedSince without EntryGuard");
@@ -2285,10 +2286,16 @@
                           "Bad time in EntryGuardDownSince/UnlistedSince");
         break;
       }
-      if (!strcasecmp(line->key, "EntryGuardDownSince"))
+      if (strlen(line->value) >= ISO_TIME_LEN+ISO_TIME_LEN+1) {
+        /* ignore failure */
+        parse_iso_time(line->value+ISO_TIME_LEN+1, &last_try);
+      }
+      if (!strcasecmp(line->key, "EntryGuardDownSince")) {
         node->unreachable_since = when;
-      else
+        node->last_attempted = last_try;
+      } else {
         node->bad_since = when;
+      }
     }
   }
 
@@ -2348,8 +2355,12 @@
       if (e->unreachable_since) {
         *next = line = tor_malloc_zero(sizeof(config_line_t));
         line->key = tor_strdup("EntryGuardDownSince");
-        line->value = tor_malloc(ISO_TIME_LEN+1);
+        line->value = tor_malloc(ISO_TIME_LEN+1+ISO_TIME_LEN+1);
         format_iso_time(line->value, e->unreachable_since);
+        if (e->last_attempted) {
+          line->value[ISO_TIME_LEN] = ' ';
+          format_iso_time(line->value+ISO_TIME_LEN+1, e->last_attempted);
+        }
         next = &(line->next);
       }
       if (e->bad_since) {