[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [tor/master] prop224: Add a init/free_all function for the whole subsystem
commit 765ed5dac160b28fb658560e8f39d1d7ab3d1c75
Author: David Goulet <dgoulet@xxxxxxxxxxxxxx>
Date: Mon Jan 16 13:29:03 2017 -0500
prop224: Add a init/free_all function for the whole subsystem
Introduces hs_init() located in hs_common.c which initialize the entire HS v3
subsystem. This is done _prior_ to the options being loaded because we need to
allocate global data structure before we load the configuration.
The hs_free_all() is added to release everything from tor_free_all().
Note that both functions do NOT handle v2 service subsystem but does handle
the common interface that both v2 and v3 needs such as the cache and
circuitmap.
Signed-off-by: David Goulet <dgoulet@xxxxxxxxxxxxxx>
---
src/or/hs_common.c | 22 ++++++++++++++++++++++
src/or/hs_common.h | 3 +++
src/or/hs_service.c | 7 +++++++
src/or/hs_service.h | 1 +
src/or/main.c | 10 +++-------
5 files changed, 36 insertions(+), 7 deletions(-)
diff --git a/src/or/hs_common.c b/src/or/hs_common.c
index 4250812..b524296 100644
--- a/src/or/hs_common.c
+++ b/src/or/hs_common.c
@@ -15,7 +15,9 @@
#include "config.h"
#include "networkstatus.h"
+#include "hs_cache.h"
#include "hs_common.h"
+#include "hs_service.h"
#include "rendcommon.h"
/* Make sure that the directory for <b>service</b> is private, using the config
@@ -344,3 +346,23 @@ rend_data_get_pk_digest(const rend_data_t *rend_data, size_t *len_out)
}
}
+/* Initialize the entire HS subsytem. This is called in tor_init() before any
+ * torrc options are loaded. Only for >= v3. */
+void
+hs_init(void)
+{
+ hs_circuitmap_init();
+ hs_service_init();
+ hs_cache_init();
+}
+
+/* Release and cleanup all memory of the HS subsystem (all version). This is
+ * called by tor_free_all(). */
+void
+hs_free_all(void)
+{
+ hs_circuitmap_free_all();
+ hs_service_free_all();
+ hs_cache_free_all();
+}
+
diff --git a/src/or/hs_common.h b/src/or/hs_common.h
index abc44c0..8016535 100644
--- a/src/or/hs_common.h
+++ b/src/or/hs_common.h
@@ -58,6 +58,9 @@ typedef enum {
HS_AUTH_KEY_TYPE_ED25519 = 2,
} hs_auth_key_type_t;
+void hs_init(void);
+void hs_free_all(void);
+
int hs_check_service_private_dir(const char *username, const char *path,
unsigned int dir_group_readable,
unsigned int create);
diff --git a/src/or/hs_service.c b/src/or/hs_service.c
index c62aa8b..16ffc48 100644
--- a/src/or/hs_service.c
+++ b/src/or/hs_service.c
@@ -97,6 +97,13 @@ hs_service_free(hs_service_t *service)
tor_free(service);
}
+/* Initialize the service HS subsystem. */
+void
+hs_service_init(void)
+{
+ return;
+}
+
/* Release all global the storage of hidden service subsystem. */
void
hs_service_free_all(void)
diff --git a/src/or/hs_service.h b/src/or/hs_service.h
index d29a478..ec47cb7 100644
--- a/src/or/hs_service.h
+++ b/src/or/hs_service.h
@@ -193,6 +193,7 @@ typedef struct hs_service_t {
/* API */
int hs_service_config_all(const or_options_t *options, int validate_only);
+void hs_service_init(void);
void hs_service_free_all(void);
void hs_service_free(hs_service_t *service);
diff --git a/src/or/main.c b/src/or/main.c
index 8c269fd..204b3f3 100644
--- a/src/or/main.c
+++ b/src/or/main.c
@@ -2499,9 +2499,6 @@ do_main_loop(void)
}
}
- /* Initialize relay-side HS circuitmap */
- hs_circuitmap_init();
-
/* set up once-a-second callback. */
if (! second_timer) {
struct timeval one_second;
@@ -3014,9 +3011,10 @@ tor_init(int argc, char *argv[])
rep_hist_init();
/* Initialize the service cache. */
rend_cache_init();
- hs_cache_init();
addressmap_init(); /* Init the client dns cache. Do it always, since it's
* cheap. */
+ /* Initialize the HS subsystem. */
+ hs_init();
{
/* We search for the "quiet" option first, since it decides whether we
@@ -3216,10 +3214,8 @@ tor_free_all(int postfork)
networkstatus_free_all();
addressmap_free_all();
dirserv_free_all();
- hs_service_free_all();
rend_cache_free_all();
rend_service_authorization_free_all();
- hs_cache_free_all();
rep_hist_free_all();
dns_free_all();
clear_pending_onions();
@@ -3232,7 +3228,6 @@ tor_free_all(int postfork)
connection_edge_free_all();
scheduler_free_all();
nodelist_free_all();
- hs_circuitmap_free_all();
microdesc_free_all();
routerparse_free_all();
ext_orport_free_all();
@@ -3241,6 +3236,7 @@ tor_free_all(int postfork)
protover_free_all();
bridges_free_all();
consdiffmgr_free_all();
+ hs_free_all();
if (!postfork) {
config_free_all();
or_state_free_all();
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits