[tor-commits] [tor/master] prop224: Use the service config object when configuring

nickm at torproject.org nickm at torproject.org
Thu Jul 13 21:26:47 UTC 2017


commit 3eeebd1b0ca43bc2523fb39349078277a40d4116
Author: David Goulet <dgoulet at torproject.org>
Date:   Wed Jul 12 13:52:19 2017 -0400

    prop224: Use the service config object when configuring
    
    Both configuration function now takes the service config object instead of the
    service itself.
    
    Signed-off-by: David Goulet <dgoulet at torproject.org>
---
 src/or/hs_config.c   | 13 ++++---------
 src/or/rendservice.c | 26 ++++++++++++--------------
 src/or/rendservice.h |  2 +-
 3 files changed, 17 insertions(+), 24 deletions(-)

diff --git a/src/or/hs_config.c b/src/or/hs_config.c
index c29315f..7e0124b 100644
--- a/src/or/hs_config.c
+++ b/src/or/hs_config.c
@@ -236,18 +236,13 @@ config_validate_service(const hs_service_config_t *config)
  * Return 0 on success else a negative value. */
 static int
 config_service_v3(const config_line_t *line_,
-                  const or_options_t *options,
-                  hs_service_t *service)
+                  hs_service_config_t *config)
 {
-  (void) options;
   int have_num_ip = 0;
   const char *dup_opt_seen = NULL;
   const config_line_t *line;
-  hs_service_config_t *config;
-
-  tor_assert(service);
 
-  config = &service->config;
+  tor_assert(config);
 
   for (line = line_; line; line = line->next) {
     int ok = 0;
@@ -489,10 +484,10 @@ config_service(const config_line_t *line, const or_options_t *options,
    * directory line, the function knows that it has to stop parsing. */
   switch (service->version) {
   case HS_VERSION_TWO:
-    ret = rend_config_service(line->next, options, service);
+    ret = rend_config_service(line->next, options, &service->config);
     break;
   case HS_VERSION_THREE:
-    ret = config_service_v3(line->next, options, service);
+    ret = config_service_v3(line->next, &service->config);
     break;
   default:
     /* We do validate before if we support the parsed version. */
diff --git a/src/or/rendservice.c b/src/or/rendservice.c
index 67da760..67de636 100644
--- a/src/or/rendservice.c
+++ b/src/or/rendservice.c
@@ -622,14 +622,12 @@ rend_service_prune_list(void)
  * object which so we have to copy the parsed values to a rend service object
  * which is version 2 specific. */
 static void
-service_shadow_copy(rend_service_t *service, hs_service_t *hs_service)
+service_config_shadow_copy(rend_service_t *service,
+                           hs_service_config_t *config)
 {
-  hs_service_config_t *config;
-
   tor_assert(service);
-  tor_assert(hs_service);
+  tor_assert(config);
 
-  config = &hs_service->config;
   service->directory = tor_strdup(config->directory_path);
   service->dir_group_readable = config->dir_group_readable;
   service->allow_unknown_ports = config->allow_unknown_ports;
@@ -638,19 +636,19 @@ service_shadow_copy(rend_service_t *service, hs_service_t *hs_service)
   service->n_intro_points_wanted = config->num_intro_points;
   /* Switching ownership of the ports to the rend service object. */
   smartlist_add_all(service->ports, config->ports);
-  smartlist_free(hs_service->config.ports);
-  hs_service->config.ports = NULL;
+  smartlist_free(config->ports);
+  config->ports = NULL;
 }
 
 /* Parse the hidden service configuration starting at <b>line_</b> using the
- * already configured generic service in <b>hs_service</b>. This function will
- * translate the service object to a rend_service_t and add it to the
- * temporary list if valid. If <b>validate_only</b> is set, parse, warn and
- * return as normal but don't actually add the service to the list. */
+ * already configured generic service configuration in <b>config</b>. This
+ * function will translate the config object to a rend_service_t and add it to
+ * the temporary list if valid. If <b>validate_only</b> is set, parse, warn
+ * and return as normal but don't actually add the service to the list. */
 int
 rend_config_service(const config_line_t *line_,
                     const or_options_t *options,
-                    hs_service_t *hs_service)
+                    hs_service_config_t *config)
 {
   const config_line_t *line;
   rend_service_t *service = NULL;
@@ -658,7 +656,7 @@ rend_config_service(const config_line_t *line_,
   /* line_ can be NULL which would mean that the service configuration only
    * have one line that is the directory directive. */
   tor_assert(options);
-  tor_assert(hs_service);
+  tor_assert(config);
 
   /* Use the staging service list so that we can check then do the pruning
    * process using the main list at the end. */
@@ -672,7 +670,7 @@ rend_config_service(const config_line_t *line_,
   service->ports = smartlist_new();
   /* From the hs_service object which has been used to load the generic
    * options, we'll copy over the useful data to the rend_service_t object. */
-  service_shadow_copy(service, hs_service);
+  service_config_shadow_copy(service, config);
 
   for (line = line_; line; line = line->next) {
     if (!strcasecmp(line->key, "HiddenServiceDir")) {
diff --git a/src/or/rendservice.h b/src/or/rendservice.h
index 20e827d..ffed21d 100644
--- a/src/or/rendservice.h
+++ b/src/or/rendservice.h
@@ -143,7 +143,7 @@ STATIC void rend_service_prune_list_impl_(void);
 int num_rend_services(void);
 int rend_config_service(const config_line_t *line_,
                         const or_options_t *options,
-                        hs_service_t *hs_service);
+                        hs_service_config_t *config);
 void rend_service_prune_list(void);
 void rend_service_free_staging_list(void);
 int rend_service_load_all_keys(const smartlist_t *service_list);





More information about the tor-commits mailing list