Browse Source

Rate-limit warnings related to unrecognized MyFamily elements.

svn:r5204
Nick Mathewson 20 years ago
parent
commit
5cf758764e
3 changed files with 34 additions and 8 deletions
  1. 2 1
      src/or/main.c
  2. 2 1
      src/or/or.h
  3. 30 6
      src/or/router.c

+ 2 - 1
src/or/main.c

@@ -926,6 +926,7 @@ do_hup(void)
   if (accounting_is_enabled(options))
     accounting_record_bandwidth_usage(time(NULL));
 
+  router_reset_warnings();
   routerlist_reset_warnings();
   addressmap_clear_transient();
   /* first, reload config variables, in case they've changed */
@@ -1382,7 +1383,7 @@ tor_free_all(int postfork)
   connection_free_all();
   if (!postfork) {
     config_free_all();
-    router_free_all_keys();
+    router_free_all();
   }
   tor_tls_free_all();
   /* stuff in main.c */

+ 2 - 1
src/or/or.h

@@ -2055,7 +2055,8 @@ int router_dump_router_to_string(char *s, size_t maxlen, routerinfo_t *router,
                                  crypto_pk_env_t *ident_key);
 int is_legal_nickname(const char *s);
 int is_legal_nickname_or_hexdigest(const char *s);
-void router_free_all_keys(void);
+void router_reset_warnings(void);
+void router_free_all(void);
 
 /********************************* routerlist.c ***************************/
 

+ 30 - 6
src/or/router.c

@@ -756,6 +756,9 @@ router_get_my_descriptor(void)
   return desc_routerinfo->signed_descriptor;
 }
 
+/*DOCDOC*/
+static smartlist_t *warned_nonexistent_family = NULL;
+
 /** If <b>force</b> is true, or our descriptor is out-of-date, rebuild
  * a fresh routerinfo and signed server descriptor for this OR.
  * Return 0 on success, -1 on error.
@@ -810,6 +813,8 @@ router_rebuild_descriptor(int force)
   if (authdir_mode(options))
     ri->is_verified = ri->is_named = 1; /* believe in yourself */
   if (options->MyFamily) {
+    if (!warned_nonexistent_family)
+      warned_nonexistent_family = smartlist_create();
     smartlist_t *family = smartlist_create();
     ri->declared_family = smartlist_create();
     smartlist_split_string(family, options->MyFamily, ",",
@@ -822,9 +827,12 @@ router_rebuild_descriptor(int force)
        else
          member = router_get_by_nickname(name, 1);
        if (!member) {
-         log_fn(LOG_WARN, "I have no descriptor for the router named \"%s\" "
-                "in my declared family; I'll use the nickname verbatim, but "
-                "this may confuse clients.", name);
+         if (!smartlist_string_isin(warned_nonexistent_family, name)) {
+           log_fn(LOG_WARN, "I have no descriptor for the router named \"%s\" "
+                  "in my declared family; I'll use the nickname as is, but "
+                  "this may confuse clients.", name);
+           smartlist_add(warned_nonexistent_family, tor_strdup(name));
+         }
          smartlist_add(ri->declared_family, name);
          name = NULL;
        } else {
@@ -833,6 +841,8 @@ router_rebuild_descriptor(int force)
          base16_encode(fp+1,HEX_DIGEST_LEN+1,
                        member->identity_digest, DIGEST_LEN);
          smartlist_add(ri->declared_family, fp);
+         if (smartlist_string_isin(warned_nonexistent_family, name))
+           smartlist_string_remove(warned_nonexistent_family, name);
        }
        tor_free(name);
      });
@@ -1135,9 +1145,20 @@ is_legal_nickname_or_hexdigest(const char *s)
   return len == HEX_DIGEST_LEN+1 && strspn(s+1,HEX_CHARACTERS)==len-1;
 }
 
-/** Release all resources held in router keys. */
+/** Forget that we have issued any router-related warnings, so that we'll
+ * warn again if we see the same errors. */
+void
+router_reset_warnings(void)
+{
+  if (warned_nonexistent_family) {
+    SMARTLIST_FOREACH(warned_nonexistent_family, char *, cp, tor_free(cp));
+    smartlist_clear(warned_nonexistent_family);
+  }
+}
+
+/** Release all static resources held in router.c */
 void
-router_free_all_keys(void)
+router_free_all(void)
 {
   if (onionkey)
     crypto_free_pk_env(onionkey);
@@ -1149,5 +1170,8 @@ router_free_all_keys(void)
     tor_mutex_free(key_lock);
   if (desc_routerinfo)
     routerinfo_free(desc_routerinfo);
+  if (warned_nonexistent_family) {
+    SMARTLIST_FOREACH(warned_nonexistent_family, char *, cp, tor_free(cp));
+    smartlist_free(warned_nonexistent_family);
+  }
 }
-