diff options
author | David Goulet <dgoulet@torproject.org> | 2017-02-02 15:26:04 -0500 |
---|---|---|
committer | David Goulet <dgoulet@torproject.org> | 2017-07-13 16:50:09 -0400 |
commit | 09b12c40947ea496c0bfaeeafba7540925c17a32 (patch) | |
tree | 09c14cfb32abe77ae3e0b2dad7b9a28cf93571e7 /src/or | |
parent | 418059dd96f5f427eceffff1daeb2a2f6c4adbeb (diff) | |
download | tor-09b12c40947ea496c0bfaeeafba7540925c17a32.tar.gz tor-09b12c40947ea496c0bfaeeafba7540925c17a32.zip |
test: Add v3 service load keys and accessors
Signed-off-by: David Goulet <dgoulet@torproject.org>
Diffstat (limited to 'src/or')
-rw-r--r-- | src/or/hs_service.c | 27 | ||||
-rw-r--r-- | src/or/hs_service.h | 14 |
2 files changed, 33 insertions, 8 deletions
diff --git a/src/or/hs_service.c b/src/or/hs_service.c index 854ce9e541..bfce7804ab 100644 --- a/src/or/hs_service.c +++ b/src/or/hs_service.c @@ -57,11 +57,6 @@ hs_service_ht_hash(const hs_service_t *service) sizeof(service->keys.identity_pk.pubkey)); } -/* For the service global hash map, we define a specific type for it which - * will make it safe to use and specific to some controlled parameters such as - * the hashing function and how to compare services. */ -typedef HT_HEAD(hs_service_ht, hs_service_t) hs_service_ht; - /* This is _the_ global hash map of hidden services which indexed the service * contained in it by master public identity key which is roughly the onion * address of the service. */ @@ -82,7 +77,7 @@ HT_GENERATE2(hs_service_ht, hs_service_t, hs_service_node, * if found else NULL. It is also possible to set a directory path in the * search query. If pk is NULL, then it will be set to zero indicating the * hash table to compare the directory path instead. */ -static hs_service_t * +STATIC hs_service_t * find_service(hs_service_ht *map, const ed25519_public_key_t *pk) { hs_service_t dummy_service = {0}; @@ -95,7 +90,7 @@ find_service(hs_service_ht *map, const ed25519_public_key_t *pk) /* Register the given service in the given map. If the service already exists * in the map, -1 is returned. On success, 0 is returned and the service * ownership has been transfered to the global map. */ -static int +STATIC int register_service(hs_service_ht *map, hs_service_t *service) { tor_assert(map); @@ -113,7 +108,7 @@ register_service(hs_service_ht *map, hs_service_t *service) /* Remove a given service from the given map. If service is NULL or the * service key is unset, return gracefully. */ -static void +STATIC void remove_service(hs_service_ht *map, hs_service_t *service) { hs_service_t *elm; @@ -804,5 +799,21 @@ get_hs_service_staging_list_size(void) return smartlist_len(hs_service_staging_list); } +STATIC hs_service_ht * +get_hs_service_map(void) +{ + return hs_service_map; +} + +STATIC hs_service_t * +get_first_service(void) +{ + hs_service_t **obj = HT_START(hs_service_ht, hs_service_map); + if (obj == NULL) { + return NULL; + } + return *obj; +} + #endif /* TOR_UNIT_TESTS */ diff --git a/src/or/hs_service.h b/src/or/hs_service.h index cd154d3fe9..a98884f6bc 100644 --- a/src/or/hs_service.h +++ b/src/or/hs_service.h @@ -200,6 +200,11 @@ typedef struct hs_service_t { } hs_service_t; +/* For the service global hash map, we define a specific type for it which + * will make it safe to use and specific to some controlled parameters such as + * the hashing function and how to compare services. */ +typedef HT_HEAD(hs_service_ht, hs_service_t) hs_service_ht; + /* API */ /* Global initializer and cleanup function. */ @@ -228,8 +233,17 @@ get_establish_intro_payload(uint8_t *buf, size_t buf_len, #ifdef TOR_UNIT_TESTS +/* Useful getters for unit tests. */ STATIC unsigned int get_hs_service_map_size(void); STATIC int get_hs_service_staging_list_size(void); +STATIC hs_service_ht *get_hs_service_map(void); +STATIC hs_service_t *get_first_service(void); + +/* Service accessors. */ +STATIC hs_service_t *find_service(hs_service_ht *map, + const ed25519_public_key_t *pk); +STATIC void remove_service(hs_service_ht *map, hs_service_t *service); +STATIC int register_service(hs_service_ht *map, hs_service_t *service); #endif /* TOR_UNIT_TESTS */ |