]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Store service descriptors in the service descriptor cache
authorDonncha O'Cearbhaill <donncha@donncha.is>
Wed, 29 Jul 2015 13:20:51 +0000 (15:20 +0200)
committerDonncha O'Cearbhaill <donncha@donncha.is>
Tue, 25 Aug 2015 15:30:11 +0000 (17:30 +0200)
Service descriptors are now generated regardless of the the
PublishHidServDescriptors option. The generated descriptors are stored
in the service descriptor cache.

The PublishHidServDescriptors = 1 option now prevents descriptor
publication to the HSDirs rather than descriptor generation.

src/or/rendcommon.c
src/or/rendservice.c
src/test/test.c

index 22599e9830bb42f24e0654ac4e7de480081ba233..1e040847cf62d39ef6048494162d8a348f1b97de 100644 (file)
@@ -11,6 +11,7 @@
 #include "or.h"
 #include "circuitbuild.h"
 #include "config.h"
+#include "control.h"
 #include "rendclient.h"
 #include "rendcommon.h"
 #include "rendmid.h"
@@ -461,6 +462,7 @@ rend_encode_v2_descriptors(smartlist_t *descs_out,
                            smartlist_t *client_cookies)
 {
   char service_id[DIGEST_LEN];
+  char service_id_base32[REND_SERVICE_ID_LEN_BASE32+1];
   uint32_t time_period;
   char *ipos_base64 = NULL, *ipos = NULL, *ipos_encrypted = NULL,
        *descriptor_cookie = NULL;
@@ -655,6 +657,11 @@ rend_encode_v2_descriptors(smartlist_t *descs_out,
       goto err;
     }
     smartlist_add(descs_out, enc);
+    /* Add the uploaded descriptor to the local service's descriptor cache */
+    rend_cache_store_v2_desc_as_service(enc->desc_str);
+    base32_encode(service_id_base32, sizeof(service_id_base32),
+          service_id, REND_SERVICE_ID_LEN);
+    control_event_hs_descriptor_created(service_id_base32, desc_id_base32);
   }
 
   log_info(LD_REND, "Successfully encoded a v2 descriptor and "
index dd8713b04341b355275e3c757a585a419a103340..75d859d2eec24a9ab1725a736fa79656aeba662c 100644 (file)
@@ -3215,8 +3215,6 @@ upload_service_descriptor(rend_service_t *service)
 
   rendpostperiod = get_options()->RendPostPeriod;
 
-  /* Upload descriptor? */
-  if (get_options()->PublishHidServDescriptors) {
   networkstatus_t *c = networkstatus_get_latest_consensus();
   if (c && smartlist_len(c->routerstatus_list) > 0) {
     int seconds_valid, i, j, num_descs;
@@ -3258,12 +3256,14 @@ upload_service_descriptor(rend_service_t *service)
         smartlist_free(client_cookies);
         return;
       }
-      /* Post the current descriptors to the hidden service directories. */
       rend_get_service_id(service->desc->pk, serviceid);
-      log_info(LD_REND, "Launching upload for hidden service %s",
-                   serviceid);
-      directory_post_to_hs_dir(service->desc, descs, NULL, serviceid,
-                               seconds_valid);
+      if (get_options()->PublishHidServDescriptors) {
+        /* Post the current descriptors to the hidden service directories. */
+        log_info(LD_REND, "Launching upload for hidden service %s",
+                     serviceid);
+        directory_post_to_hs_dir(service->desc, descs, NULL, serviceid,
+                                 seconds_valid);
+      }
       /* Free memory for descriptors. */
       for (i = 0; i < smartlist_len(descs); i++)
         rend_encoded_v2_service_descriptor_free(smartlist_get(descs, i));
@@ -3291,8 +3291,10 @@ upload_service_descriptor(rend_service_t *service)
           smartlist_free(client_cookies);
           return;
         }
-        directory_post_to_hs_dir(service->desc, descs, NULL, serviceid,
-                                 seconds_valid);
+        if (get_options()->PublishHidServDescriptors) {
+          directory_post_to_hs_dir(service->desc, descs, NULL, serviceid,
+                                   seconds_valid);
+        }
         /* Free memory for descriptors. */
         for (i = 0; i < smartlist_len(descs); i++)
           rend_encoded_v2_service_descriptor_free(smartlist_get(descs, i));
@@ -3302,8 +3304,11 @@ upload_service_descriptor(rend_service_t *service)
     smartlist_free(descs);
     smartlist_free(client_cookies);
     uploaded = 1;
-    log_info(LD_REND, "Successfully uploaded v2 rend descriptors!");
-  }
+    if (get_options()->PublishHidServDescriptors) {
+      log_info(LD_REND, "Successfully uploaded v2 rend descriptors!");
+    } else {
+      log_info(LD_REND, "Successfully stored created v2 rend descriptors!");
+    }
   }
 
   /* If not uploaded, try again in one minute. */
index 7ad849f49e2ea4c4919b65718a602702f2005c6a..683a3b4736e97238692ca9d1467cb66fb94bd5b3 100644 (file)
@@ -47,6 +47,7 @@ double fabs(double x);
 #include "connection_edge.h"
 #include "geoip.h"
 #include "rendcommon.h"
+#include "rendcache.h"
 #include "test.h"
 #include "torgzip.h"
 #include "memarea.h"
@@ -494,6 +495,9 @@ test_rend_fns(void *arg)
   tt_str_op(address6,OP_EQ, "abcdefghijklmnop");
   tt_assert(BAD_HOSTNAME == parse_extended_hostname(address7));
 
+  /* Initialize the service cache. */
+  rend_cache_init();
+
   pk1 = pk_generate(0);
   pk2 = pk_generate(1);
   generated = tor_malloc_zero(sizeof(rend_service_descriptor_t));