浏览代码

Simplify calls to routerset_equal

The routerset_equal function explicitly handles NULL inputs, so
there's no need to check inputs for NULL before calling it.

Also fix a bug in routerset_equal where a non-NULL routerset with no
entries didn't get counted as equal to a NULL routerset.  This was
untriggerable, I think, but potentially annoying down the road.
Nick Mathewson 14 年之前
父节点
当前提交
128582cc1f
共有 2 个文件被更改,包括 12 次插入13 次删除
  1. 5 9
      src/or/config.c
  2. 7 4
      src/or/routerlist.c

+ 5 - 9
src/or/config.c

@@ -1260,15 +1260,11 @@ options_act(or_options_t *old_options)
   /* Check for transitions that need action. */
   /* Check for transitions that need action. */
   if (old_options) {
   if (old_options) {
     if ((options->UseEntryGuards && !old_options->UseEntryGuards) ||
     if ((options->UseEntryGuards && !old_options->UseEntryGuards) ||
-        (options->ExcludeNodes &&
-         !routerset_equal(old_options->ExcludeNodes,options->ExcludeNodes)) ||
-        (options->ExcludeExitNodes &&
-         !routerset_equal(old_options->ExcludeExitNodes,
-                          options->ExcludeExitNodes)) ||
-        (options->EntryNodes &&
-         !routerset_equal(old_options->EntryNodes, options->EntryNodes)) ||
-        (options->ExitNodes &&
-         !routerset_equal(old_options->ExitNodes, options->ExitNodes)) ||
+        !routerset_equal(old_options->ExcludeNodes,options->ExcludeNodes) ||
+        !routerset_equal(old_options->ExcludeExitNodes,
+                         options->ExcludeExitNodes) ||
+        !routerset_equal(old_options->EntryNodes, options->EntryNodes) ||
+        !routerset_equal(old_options->ExitNodes, options->ExitNodes) ||
         options->StrictNodes != old_options->StrictNodes) {
         options->StrictNodes != old_options->StrictNodes) {
       log_info(LD_CIRC,
       log_info(LD_CIRC,
                "Changed to using entry guards, or changed preferred or "
                "Changed to using entry guards, or changed preferred or "

+ 7 - 4
src/or/routerlist.c

@@ -5473,14 +5473,12 @@ routerset_needs_geoip(const routerset_t *set)
   return set && smartlist_len(set->country_names);
   return set && smartlist_len(set->country_names);
 }
 }
 
 
-#if 0
 /** Return true iff there are no entries in <b>set</b>. */
 /** Return true iff there are no entries in <b>set</b>. */
 static int
 static int
 routerset_is_empty(const routerset_t *set)
 routerset_is_empty(const routerset_t *set)
 {
 {
   return !set || smartlist_len(set->list) == 0;
   return !set || smartlist_len(set->list) == 0;
 }
 }
-#endif
 
 
 /** Helper.  Return true iff <b>set</b> contains a router based on the other
 /** Helper.  Return true iff <b>set</b> contains a router based on the other
  * provided fields.  Return higher values for more specific subentries: a
  * provided fields.  Return higher values for more specific subentries: a
@@ -5659,10 +5657,15 @@ routerset_to_string(const routerset_t *set)
 int
 int
 routerset_equal(const routerset_t *old, const routerset_t *new)
 routerset_equal(const routerset_t *old, const routerset_t *new)
 {
 {
-  if (old == NULL && new == NULL)
+  if (routerset_is_empty(old) && routerset_is_empty(new)) {
+    /* Two empty sets are equal */
     return 1;
     return 1;
-  else if (old == NULL || new == NULL)
+  } else if (routerset_is_empty(old) || routerset_is_empty(new)) {
+    /* An empty set is equal to nothing else. */
     return 0;
     return 0;
+  }
+  tor_assert(old != NULL);
+  tor_assert(new != NULL);
 
 
   if (smartlist_len(old->list) != smartlist_len(new->list))
   if (smartlist_len(old->list) != smartlist_len(new->list))
     return 0;
     return 0;