[or-cvs] r19213: {tor} log more verbosely when we accept or decline a router descri (tor/trunk/src/or)

arma at seul.org arma at seul.org
Wed Apr 1 13:02:05 UTC 2009


Author: arma
Date: 2009-04-01 09:02:04 -0400 (Wed, 01 Apr 2009)
New Revision: 19213

Modified:
   tor/trunk/src/or/directory.c
   tor/trunk/src/or/dirserv.c
   tor/trunk/src/or/or.h
   tor/trunk/src/or/router.c
   tor/trunk/src/or/test.c
Log:
log more verbosely when we accept or decline a router descriptor,
to help track whether we received them when a relay operator claims
they got sent.


Modified: tor/trunk/src/or/directory.c
===================================================================
--- tor/trunk/src/or/directory.c	2009-04-01 01:11:32 UTC (rev 19212)
+++ tor/trunk/src/or/directory.c	2009-04-01 13:02:04 UTC (rev 19213)
@@ -267,7 +267,7 @@
 
       if (extrainfo_len && router_supports_extrainfo(ds->digest, 1)) {
         upload_len += extrainfo_len;
-        log_info(LD_DIR, "Uploading an extrainfo (length %d)",
+        log_info(LD_DIR, "Uploading an extrainfo too (length %d)",
                  (int) extrainfo_len);
       }
       tor_addr_from_ipv4h(&ds_addr, ds->addr);

Modified: tor/trunk/src/or/dirserv.c
===================================================================
--- tor/trunk/src/or/dirserv.c	2009-04-01 01:11:32 UTC (rev 19212)
+++ tor/trunk/src/or/dirserv.c	2009-04-01 13:02:04 UTC (rev 19213)
@@ -611,7 +611,7 @@
     SMARTLIST_FOREACH(list, routerinfo_t *, ri, {
         msg_out = NULL;
         tor_assert(ri->purpose == purpose);
-        r_tmp = dirserv_add_descriptor(ri, &msg_out);
+        r_tmp = dirserv_add_descriptor(ri, &msg_out, source);
         if (WRA_MORE_SEVERE(r_tmp, r)) {
           r = r_tmp;
           *msg = msg_out;
@@ -652,7 +652,8 @@
 
 /** Examine the parsed server descriptor in <b>ri</b> and maybe insert it into
  * the list of server descriptors. Set *<b>msg</b> to a message that should be
- * passed back to the origin of this descriptor.
+ * passed back to the origin of this descriptor. Use <b>source</b> to produce
+ * better log messages.
  *
  * Return the status of the operation
  *
@@ -660,20 +661,20 @@
  * we re-load the cache.
  */
 was_router_added_t
-dirserv_add_descriptor(routerinfo_t *ri, const char **msg)
+dirserv_add_descriptor(routerinfo_t *ri, const char **msg, const char *source)
 {
   was_router_added_t r;
   routerinfo_t *ri_old;
-  char *desc = NULL;
+  char *desc, *nickname;
   size_t desclen = 0;
 
   /* If it's too big, refuse it now. Otherwise we'll cache it all over the
    * network and it'll clog everything up. */
   if (ri->cache_info.signed_descriptor_len > MAX_DESCRIPTOR_UPLOAD_SIZE) {
-    log_notice(LD_DIR, "Somebody attempted to publish a router descriptor "
-               "with size %d. Either this is an attack, or the "
+    log_notice(LD_DIR, "Somebody attempted to publish a router descriptor '%s'"
+               " (source: %s) with size %d. Either this is an attack, or the "
                "MAX_DESCRIPTOR_UPLOAD_SIZE (%d) constant is too low.",
-               (int)ri->cache_info.signed_descriptor_len,
+               ri->nickname, source, (int)ri->cache_info.signed_descriptor_len,
                MAX_DESCRIPTOR_UPLOAD_SIZE);
     *msg = "Router descriptor was too large";
     control_event_or_authdir_new_descriptor("REJECTED",
@@ -692,8 +693,9 @@
       && router_differences_are_cosmetic(ri_old, ri)
       && !router_is_me(ri)) {
     log_info(LD_DIRSERV,
-             "Not replacing descriptor from '%s'; differences are cosmetic.",
-             ri->nickname);
+             "Not replacing descriptor from '%s' (source: %s); "
+             "differences are cosmetic.",
+             ri->nickname, source);
     *msg = "Not replacing router descriptor; no information has changed since "
       "the last one with this identity.";
     control_event_or_authdir_new_descriptor("DROPPED",
@@ -702,23 +704,24 @@
     routerinfo_free(ri);
     return ROUTER_WAS_NOT_NEW;
   }
-  if (control_event_is_interesting(EVENT_AUTHDIR_NEWDESCS)) {
-    /* Make a copy of desc, since router_add_to_routerlist might free
-     * ri and its associated signed_descriptor_t. */
-    desclen = ri->cache_info.signed_descriptor_len;
-    desc = tor_strndup(ri->cache_info.signed_descriptor_body, desclen);
-  }
 
+  /* Make a copy of desc, since router_add_to_routerlist might free
+   * ri and its associated signed_descriptor_t. */
+  desclen = ri->cache_info.signed_descriptor_len;
+  desc = tor_strndup(ri->cache_info.signed_descriptor_body, desclen);
+  nickname = tor_strdup(ri->nickname);
+
   r = router_add_to_routerlist(ri, msg, 0, 0);
   if (!WRA_WAS_ADDED(r)) {
     /* unless the routerinfo was fine, just out-of-date */
-    if (WRA_WAS_REJECTED(r) && desc)
+    if (WRA_WAS_REJECTED(r))
       control_event_or_authdir_new_descriptor("REJECTED", desc, desclen, *msg);
-    tor_free(desc);
+    log_info(LD_DIRSERV,
+             "Did not add descriptor from '%s' (source: %s): %s.",
+             nickname, source, *msg);
   } else {
     smartlist_t *changed;
-    if (desc)
-      control_event_or_authdir_new_descriptor("ACCEPTED", desc, desclen, *msg);
+    control_event_or_authdir_new_descriptor("ACCEPTED", desc, desclen, *msg);
 
     changed = smartlist_create();
     smartlist_add(changed, ri);
@@ -728,8 +731,12 @@
       *msg =  ri->is_valid ? "Descriptor for valid server accepted" :
         "Descriptor for invalid server accepted";
     }
-    tor_free(desc);
+    log_info(LD_DIRSERV,
+             "Added descriptor from '%s' (source: %s): %s.",
+             nickname, source, *msg);
   }
+  tor_free(desc);
+  tor_free(nickname);
   return r;
 }
 

Modified: tor/trunk/src/or/or.h
===================================================================
--- tor/trunk/src/or/or.h	2009-04-01 01:11:32 UTC (rev 19212)
+++ tor/trunk/src/or/or.h	2009-04-01 13:02:04 UTC (rev 19213)
@@ -3430,7 +3430,8 @@
                                      const char *source,
                                      const char **msg);
 enum was_router_added_t dirserv_add_descriptor(routerinfo_t *ri,
-                                               const char **msg);
+                                               const char **msg,
+                                               const char *source);
 int getinfo_helper_dirserv_unregistered(control_connection_t *conn,
                                         const char *question, char **answer);
 void dirserv_free_descriptors(void);

Modified: tor/trunk/src/or/router.c
===================================================================
--- tor/trunk/src/or/router.c	2009-04-01 01:11:32 UTC (rev 19212)
+++ tor/trunk/src/or/router.c	2009-04-01 13:02:04 UTC (rev 19213)
@@ -560,7 +560,7 @@
         log_err(LD_GENERAL,"Generated a routerinfo we couldn't parse.");
         return -1;
       }
-      if (!WRA_WAS_ADDED(dirserv_add_descriptor(ri, &m))) {
+      if (!WRA_WAS_ADDED(dirserv_add_descriptor(ri, &m, "self"))) {
         log_err(LD_GENERAL,"Unable to add own descriptor to directory: %s",
                 m?m:"<unknown error>");
         return -1;

Modified: tor/trunk/src/or/test.c
===================================================================
--- tor/trunk/src/or/test.c	2009-04-01 01:11:32 UTC (rev 19212)
+++ tor/trunk/src/or/test.c	2009-04-01 13:02:04 UTC (rev 19213)
@@ -3080,9 +3080,9 @@
   r1->cache_info.published_on = time(NULL);
   r2->cache_info.published_on = time(NULL)-3*60*60;
   test_assert(router_dump_router_to_string(buf, 2048, r1, pk2)>0);
-  test_eq(dirserv_add_descriptor(buf,&m), ROUTER_ADDED_NOTIFY_GENERATOR);
+  test_eq(dirserv_add_descriptor(buf,&m,""), ROUTER_ADDED_NOTIFY_GENERATOR);
   test_assert(router_dump_router_to_string(buf, 2048, r2, pk1)>0);
-  test_eq(dirserv_add_descriptor(buf,&m), ROUTER_ADDED_NOTIFY_GENERATOR);
+  test_eq(dirserv_add_descriptor(buf,&m,""), ROUTER_ADDED_NOTIFY_GENERATOR);
   get_options()->Nickname = tor_strdup("DirServer");
   test_assert(!dirserv_dump_directory_to_string(&cp,pk3, 0));
   crypto_pk_get_digest(pk3, d);



More information about the tor-commits mailing list