diff options
author | David Goulet <dgoulet@torproject.org> | 2017-01-16 13:29:03 -0500 |
---|---|---|
committer | David Goulet <dgoulet@torproject.org> | 2017-07-13 16:49:08 -0400 |
commit | 765ed5dac160b28fb658560e8f39d1d7ab3d1c75 (patch) | |
tree | 6f101ed5f4b399c3c0c2faf5056c3ff600895fcf | |
parent | 02e2edeb33224461d1fbb879722c0948171b9688 (diff) | |
download | tor-765ed5dac160b28fb658560e8f39d1d7ab3d1c75.tar.gz tor-765ed5dac160b28fb658560e8f39d1d7ab3d1c75.zip |
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@torproject.org>
-rw-r--r-- | src/or/hs_common.c | 22 | ||||
-rw-r--r-- | src/or/hs_common.h | 3 | ||||
-rw-r--r-- | src/or/hs_service.c | 7 | ||||
-rw-r--r-- | src/or/hs_service.h | 1 | ||||
-rw-r--r-- | 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 42508126f8..b524296159 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 abc44c09d1..8016535ca9 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 c62aa8b075..16ffc4885c 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 d29a4782cd..ec47cb72ae 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 8c269fd934..204b3f3356 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(); |