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

[or-cvs] r10086: Add code to upload extrainfos to authorities running 0.2.0.0 (in tor/trunk: . doc src/or)



Author: nickm
Date: 2007-05-01 16:13:49 -0400 (Tue, 01 May 2007)
New Revision: 10086

Modified:
   tor/trunk/
   tor/trunk/doc/TODO
   tor/trunk/src/or/config.c
   tor/trunk/src/or/directory.c
   tor/trunk/src/or/or.h
   tor/trunk/src/or/rendservice.c
   tor/trunk/src/or/router.c
   tor/trunk/src/or/routerlist.c
   tor/trunk/src/or/routerparse.c
Log:
 r12619@catbus:  nickm | 2007-05-01 16:13:42 -0400
 Add code to upload extrainfos to authorities running 0.2.0.0-alpha-dev (r10070) or later.



Property changes on: tor/trunk
___________________________________________________________________
 svk:merge ticket from /tor/trunk [r12619] on 8246c3cf-6607-4228-993b-4d95d33730f1

Modified: tor/trunk/doc/TODO
===================================================================
--- tor/trunk/doc/TODO	2007-05-01 13:48:49 UTC (rev 10085)
+++ tor/trunk/doc/TODO	2007-05-01 20:13:49 UTC (rev 10086)
@@ -75,7 +75,10 @@
         o Implement directory-protocol side.
         o Implement storage in memory
         o Implement cache on disk.
-      - Have routers upload extra-info documents.
+      o Have routers upload extra-info documents to authorities running
+        version 0.2.0.0-alpha-dev (r10070) or later.
+        . Implement, but make it option-controlled.
+        - Make it always-on once it seems to work.
       - Implement option to download and cache extra-info documents.
       - Drop bandwidth history from router-descriptors
     - 105: Version negotiation for the Tor protocol (finalize by Jun 1)

Modified: tor/trunk/src/or/config.c
===================================================================
--- tor/trunk/src/or/config.c	2007-05-01 13:48:49 UTC (rev 10085)
+++ tor/trunk/src/or/config.c	2007-05-01 20:13:49 UTC (rev 10086)
@@ -261,6 +261,10 @@
   VAR("__AllDirActionsPrivate",BOOL,   AllDirActionsPrivate, "0"),
   VAR("__DisablePredictedCircuits",BOOL,DisablePredictedCircuits,"0"),
   VAR("__LeaveStreamsUnattached", BOOL,LeaveStreamsUnattached, "0"),
+
+  /* XXXX020 Testing only. This will become "always on" once we confirm
+   * that it works. */
+  VAR("_UploadExtraInfo", BOOL, _UploadExtraInfo, "0"),
   { NULL, CONFIG_TYPE_OBSOLETE, 0, NULL }
 };
 #undef VAR

Modified: tor/trunk/src/or/directory.c
===================================================================
--- tor/trunk/src/or/directory.c	2007-05-01 13:48:49 UTC (rev 10085)
+++ tor/trunk/src/or/directory.c	2007-05-01 20:13:49 UTC (rev 10086)
@@ -87,10 +87,12 @@
  * connection purpose 'purpose' and uploading the payload 'payload'
  * (length 'payload_len').  The purpose should be one of
  * 'DIR_PURPOSE_UPLOAD_DIR' or 'DIR_PURPOSE_UPLOAD_RENDDESC'.
+ *
+ * DOCDOC extrainfo_len is in addition to payload_len.
  */
 void
 directory_post_to_dirservers(uint8_t purpose, const char *payload,
-                             size_t payload_len)
+                             size_t payload_len, size_t extrainfo_len)
 {
   smartlist_t *dirservers;
   int post_via_tor;
@@ -106,6 +108,9 @@
   SMARTLIST_FOREACH(dirservers, trusted_dir_server_t *, ds,
     {
       routerstatus_t *rs = &(ds->fake_status.status);
+      local_routerstatus_t *lrs = router_get_combined_status_by_digest(
+                                                ds->digest);
+      size_t upload_len = payload_len;
       if (post_to_hidserv_only && !ds->is_hidserv_authority)
         continue;
       if (!post_to_hidserv_only &&
@@ -113,10 +118,17 @@
         continue;
       if (purpose == DIR_PURPOSE_UPLOAD_DIR)
         ds->has_accepted_serverdesc = 0;
+      if (extrainfo_len && lrs &&
+          lrs->status.version_supports_extrainfo_upload) {
+        upload_len += extrainfo_len;
+        /* XXXX020 Disable this once it's tested. */
+        log_notice(LD_DIR, "I am going to try to upload an extrainfo. How "
+                   "exciting! (length %d)", (int) extrainfo_len);
+      }
       post_via_tor = purpose_is_private(purpose) ||
               !fascist_firewall_allows_address_dir(ds->addr, ds->dir_port);
       directory_initiate_command_routerstatus(rs, purpose, post_via_tor,
-                                              NULL, payload, payload_len);
+                                              NULL, payload, upload_len);
     });
 }
 

Modified: tor/trunk/src/or/or.h
===================================================================
--- tor/trunk/src/or/or.h	2007-05-01 13:48:49 UTC (rev 10085)
+++ tor/trunk/src/or/or.h	2007-05-01 20:13:49 UTC (rev 10086)
@@ -1191,6 +1191,8 @@
   unsigned int version_known:1;
   /** True iff this router is a version that supports BEGIN_DIR cells. */
   unsigned int version_supports_begindir:1;
+  /** True iff this router is a version that we can post extrainfo docs to. */
+  unsigned int version_supports_extrainfo_upload:1;
 
   /** True if we, as a directory mirror, want to download the corresponding
    * routerinfo from the authority who gave us this routerstatus.  (That is,
@@ -1878,6 +1880,9 @@
                                 * with weird characters. */
  /** If true, we try resolving hostnames with weird characters. */
   int ServerDNSAllowNonRFC953Hostnames;
+
+  /*XXXX020 remove me once no longer needed */
+  int _UploadExtraInfo;
 } or_options_t;
 
 /** Persistent state for an onion router, as saved to disk. */
@@ -2483,7 +2488,7 @@
 /********************************* directory.c ***************************/
 
 void directory_post_to_dirservers(uint8_t purpose, const char *payload,
-                                  size_t payload_len);
+                                  size_t payload_len, size_t extrainfo_len);
 void directory_get_from_dirserver(uint8_t purpose, const char *resource,
                                   int retry_if_no_servers);
 void directory_initiate_command_routerstatus(routerstatus_t *status,

Modified: tor/trunk/src/or/rendservice.c
===================================================================
--- tor/trunk/src/or/rendservice.c	2007-05-01 13:48:49 UTC (rev 10085)
+++ tor/trunk/src/or/rendservice.c	2007-05-01 20:13:49 UTC (rev 10086)
@@ -947,7 +947,7 @@
   }
 
   /* Post it to the dirservers */
-  directory_post_to_dirservers(DIR_PURPOSE_UPLOAD_RENDDESC, desc, desc_len);
+  directory_post_to_dirservers(DIR_PURPOSE_UPLOAD_RENDDESC, desc, desc_len, 0);
   tor_free(desc);
 
   service->desc_is_dirty = 0;

Modified: tor/trunk/src/or/router.c
===================================================================
--- tor/trunk/src/or/router.c	2007-05-01 13:48:49 UTC (rev 10085)
+++ tor/trunk/src/or/router.c	2007-05-01 20:13:49 UTC (rev 10086)
@@ -726,19 +726,38 @@
 void
 router_upload_dir_desc_to_dirservers(int force)
 {
-  const char *s;
+  routerinfo_t *ri;
+  extrainfo_t *ei;
+  char *msg;
+  size_t desc_len, extra_len = 0, total_len;
+  int post_extra;
 
-  s = router_get_my_descriptor();
-  if (!s) {
+  ri = router_get_my_routerinfo();
+  if (!ri) {
     log_info(LD_GENERAL, "No descriptor; skipping upload");
     return;
   }
+  ei = router_get_my_extrainfo();
+  post_extra = ei && get_options()->_UploadExtraInfo;
   if (!get_options()->PublishServerDescriptor)
     return;
   if (!force && !desc_needs_upload)
     return;
   desc_needs_upload = 0;
-  directory_post_to_dirservers(DIR_PURPOSE_UPLOAD_DIR, s, strlen(s));
+
+  desc_len = ri->cache_info.signed_descriptor_len;
+  extra_len = (ei && post_extra) ? ei->cache_info.signed_descriptor_len : 0;
+  total_len = desc_len + extra_len + 1;
+  msg = tor_malloc(total_len);
+  memcpy(msg, ri->cache_info.signed_descriptor_body, desc_len);
+  if (ei && post_extra) {
+    memcpy(msg+desc_len, ei->cache_info.signed_descriptor_body, extra_len);
+  }
+  msg[desc_len+extra_len] = 0;
+
+  directory_post_to_dirservers(DIR_PURPOSE_UPLOAD_DIR, msg, desc_len,
+                               extra_len);
+  tor_free(msg);
 }
 
 /** OR only: Check whether my exit policy says to allow connection to

Modified: tor/trunk/src/or/routerlist.c
===================================================================
--- tor/trunk/src/or/routerlist.c	2007-05-01 13:48:49 UTC (rev 10085)
+++ tor/trunk/src/or/routerlist.c	2007-05-01 20:13:49 UTC (rev 10086)
@@ -3797,6 +3797,7 @@
     int n_v2_dir=0, n_fast=0, n_stable=0, n_exit=0, n_guard=0, n_bad_exit=0;
     int n_bad_directory=0;
     int n_version_known=0, n_supports_begindir=0;
+    int n_supports_extrainfo_upload=0;
     int n_desc_digests=0, highest_count=0;
     const char *the_name = NULL;
     local_routerstatus_t *rs_out, *rs_old;
@@ -3890,6 +3891,8 @@
         ++n_version_known;
       if (rs->version_supports_begindir)
         ++n_supports_begindir;
+      if (rs->version_supports_extrainfo_upload)
+        ++n_supports_extrainfo_upload;
     }
     /* Go over the descriptor digests and figure out which descriptor we
      * want. */
@@ -3945,6 +3948,8 @@
     rs_out->status.version_known = n_version_known > 0;
     rs_out->status.version_supports_begindir =
       n_supports_begindir > n_version_known/2;
+    rs_out->status.version_supports_extrainfo_upload =
+      n_supports_extrainfo_upload > n_version_known/2;
     if (!rs_old || memcmp(rs_old, rs_out, sizeof(local_routerstatus_t)))
       smartlist_add(changed_list, rs_out);
   }

Modified: tor/trunk/src/or/routerparse.c
===================================================================
--- tor/trunk/src/or/routerparse.c	2007-05-01 13:48:49 UTC (rev 10085)
+++ tor/trunk/src/or/routerparse.c	2007-05-01 20:13:49 UTC (rev 10086)
@@ -1271,9 +1271,12 @@
     rs->version_known = 1;
     if (strcmpstart(tok->args[0], "Tor ")) {
       rs->version_supports_begindir = 1;
+      rs->version_supports_extrainfo_upload = 1;
     } else {
       rs->version_supports_begindir =
         tor_version_as_new_as(tok->args[0], "0.1.2.2-alpha");
+      rs->version_supports_begindir =
+        tor_version_as_new_as(tok->args[0], "0.2.0.0-alpha-dev (r10070)");
     }
   }