[or-cvs] Change version parsing logic: a version is "obsolete" if it...

Nick Mathewson nickm at seul.org
Tue Mar 1 01:45:01 UTC 2005


Update of /home/or/cvsroot/tor/src/or
In directory moria.mit.edu:/tmp/cvs-serv24830/src/or

Modified Files:
	routerparse.c test.c 
Log Message:
Change version parsing logic: a version is "obsolete" if it is not recommended and (1) there is a newer recommended version in the same series, or (2) there are no recommended versions in the same series, but there are some recommended versions in a newer series.  A version is "new" if it is newer than any recommended version in the same series.

Index: routerparse.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/routerparse.c,v
retrieving revision 1.101
retrieving revision 1.102
diff -u -d -r1.101 -r1.102
--- routerparse.c	25 Feb 2005 20:46:13 -0000	1.101
+++ routerparse.c	1 Mar 2005 01:44:57 -0000	1.102
@@ -142,6 +142,7 @@
 static crypto_pk_env_t *find_dir_signing_key(const char *str);
 /* static */ int is_obsolete_version(const char *myversion,
                                      const char *versionlist);
+static int tor_version_same_series(tor_version_t *a, tor_version_t *b);
 
 /** Set <b>digest</b> to the SHA-1 digest of the hash of the directory in
  * <b>s</b>.  Return 0 on success, nonzero on failure.
@@ -199,6 +200,12 @@
 
 /** Return 1 if <b>myversion</b> is not in <b>versionlist</b>, and if at least
  * one version of Tor on <b>versionlist</b> is newer than <b>myversion</b>.
+
+ * Return 1 if no version from the same series as <b>myversion</b> is
+ * in <b>versionlist</b> (and <b>myversion</b> is not the newest
+ * version), or if a newer version from the same series is in
+ * <b>versionlist</b>.
+ *
  * Otherwise return 0.
  * (versionlist is a comma-separated list of version strings,
  * optionally prefixed with "Tor".  Versions that can't be parsed are
@@ -207,9 +214,11 @@
                            const char *versionlist) {
   const char *vl;
   tor_version_t mine, other;
-  int found_newer = 0, r, ret;
+  int found_newer = 0, found_newer_in_series = 0, found_any_in_series = 0,
+    r, ret, same;
   static int warned_too_new=0;
   smartlist_t *version_sl;
+  int XXXpath;
 
   vl = versionlist;
 
@@ -229,26 +238,63 @@
     if (tor_version_parse(cp, &other)) {
       /* Couldn't parse other; it can't be a match. */
     } else {
+      same = tor_version_same_series(&mine, &other);
+      if (same)
+        found_any_in_series = 1;
       r = tor_version_compare(&mine, &other);
       if (r==0) {
         ret = 0;
         goto done;
       } else if (r<0) {
         found_newer = 1;
+        if (same)
+          found_newer_in_series = 1;
       }
     }
   });
 
-  if (!found_newer) {
-    if (!warned_too_new) {
-      log(LOG_WARN, "This version of Tor (%s) is newer than any on the recommended list (%s)",
-             myversion, versionlist);
-      warned_too_new=1;
+  /* We didn't find the listed version. Is it new or old? */
+
+  if (found_any_in_series) {
+    if (!found_newer_in_series) {
+      /* We belong to a series with recommended members, and we are newer than
+       * any recommended member. We're probably okay. */
+      if (!warned_too_new) {
+        log(LOG_WARN, "This version of Tor (%s) is newer than any in the same series on the reccomended list (%s)",
+            myversion, versionlist);
+        warned_too_new = 1;
+      }
+      ret = 0;
+      XXXpath = 1;
+    } else {
+      /* We found a newer one in the same series; we're obsolete. */
+      ret = 1;
+      XXXpath = 2;
     }
-    ret = 0;
   } else {
-    ret = 1;
+    if (found_newer) {
+      /* We belong to a series with no recommended members, and
+       * a newer series is recommended. We're obsolete. */
+      ret = 1;
+      XXXpath = 3;
+    } else {
+      /* We belong to a series with no recommended members, and it's
+       * newer than any recommended series. We're probably okay. */
+      if (!warned_too_new) {
+        log(LOG_WARN, "This version of Tor (%s) is newer than any on the reccomended list (%s)",
+            myversion, versionlist);
+        warned_too_new = 1;
+      }
+      ret = 0;
+      XXXpath = 4;
+    }
   }
+  /*
+  log_fn(LOG_DEBUG,
+         "Decided that %s is %sobsolete relative to %s: %d, %d, %d\n",
+         myversion, ret?"":"not ", versionlist, found_newer,
+         found_any_in_series, found_newer_in_series);
+  */
 
  done:
   SMARTLIST_FOREACH(version_sl, char *, version, tor_free(version));
@@ -1486,13 +1532,16 @@
 {
   char *eos=NULL, *cp=NULL;
   /* Format is:
-   *   NUM dot NUM dot NUM [ ( pre | rc | dot ) NUM [ -cvs ] ]
+   *   "Tor " ? NUM dot NUM dot NUM [ ( pre | rc | dot ) NUM [ -cvs ] ]
    */
   tor_assert(s);
   tor_assert(out);
 
   memset(out, 0, sizeof(tor_version_t));
 
+  if (!strcasecmpstart(s, "Tor "))
+    cp += 4;
+
   /* Get major. */
   out->major = strtol(s,&eos,10);
   if (!eos || eos==s || *eos != '.') return -1;
@@ -1571,3 +1620,12 @@
   }
 }
 
+static int
+tor_version_same_series(tor_version_t *a, tor_version_t *b)
+{
+  tor_assert(a);
+  tor_assert(b);
+  return ((a->major == b->major) &&
+          (a->minor == b->minor) &&
+          (a->micro == b->micro));
+}

Index: test.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/test.c,v
retrieving revision 1.169
retrieving revision 1.170
diff -u -d -r1.169 -r1.170
--- test.c	22 Feb 2005 08:18:36 -0000	1.169
+++ test.c	1 Mar 2005 01:44:57 -0000	1.170
@@ -1239,11 +1239,22 @@
   test_eq(1, is_obsolete_version("0.0.1", "0.0.2,Tor 0.0.3"));
   test_eq(1, is_obsolete_version("0.0.1", "0.0.3,BetterTor 0.0.1"));
   test_eq(0, is_obsolete_version("0.0.2", "Tor 0.0.2,Tor 0.0.3"));
-  test_eq(1, is_obsolete_version("0.0.2", "Tor 0.0.2pre1,Tor 0.0.3"));
+  test_eq(0, is_obsolete_version("0.0.2", "Tor 0.0.2pre1,Tor 0.0.3"));
+  test_eq(1, is_obsolete_version("0.0.2", "Tor 0.0.2.1,Tor 0.0.3"));
   test_eq(0, is_obsolete_version("0.1.0", "Tor 0.0.2,Tor 0.0.3"));
   test_eq(0, is_obsolete_version("0.0.7rc2", "0.0.7,Tor 0.0.7rc2,Tor 0.0.8"));
   test_eq(0, is_obsolete_version("0.0.5", "0.0.5-cvs"));
   test_eq(0, is_obsolete_version("0.0.5.1-cvs", "0.0.5"));
+  /* Not on list, but newer than any in same series. */
+  test_eq(0, is_obsolete_version("0.1.0.3", "Tor 0.1.0.2,Tor 0.0.9.5,Tor 0.1.1.0"));
+  /* Series newer than any on list. */
+  test_eq(0, is_obsolete_version("0.1.1.3", "Tor 0.1.0.2,Tor 0.0.9.5,Tor 0.1.1.0"));
+  /* Series older than any on list. */
+  test_eq(1, is_obsolete_version("0.0.1.3", "Tor 0.1.0.2,Tor 0.0.9.5,Tor 0.1.1.0"));
+  /* Not on list, not newer than any on same series. */
+  test_eq(1, is_obsolete_version("0.1.0.1", "Tor 0.1.0.2,Tor 0.0.9.5,Tor 0.1.1.0"));
+  /* On list, not newer than any on same series. */
+  test_eq(1, is_obsolete_version("0.1.0.1", "Tor 0.1.0.2,Tor 0.0.9.5,Tor 0.1.1.0"));
 
   test_eq(0, tor_version_as_new_as("Tor 0.0.5", "0.0.9pre1-cvs"));
   test_eq(1, tor_version_as_new_as(



More information about the tor-commits mailing list