summaryrefslogtreecommitdiff
path: root/src/or/hs_common.c
diff options
context:
space:
mode:
authorGeorge Kadianakis <desnacked@riseup.net>2017-06-01 14:07:53 +0300
committerDavid Goulet <dgoulet@torproject.org>2017-08-24 13:03:28 -0400
commit0f6633abb29743d920c27e8d7888dba4d83217b5 (patch)
tree05f761e71346d1a392a9cb286da4a3cbd8f2faff /src/or/hs_common.c
parent5c9cd912eece244f90ecf31712722dc6b993f6da (diff)
downloadtor-0f6633abb29743d920c27e8d7888dba4d83217b5.tar.gz
tor-0f6633abb29743d920c27e8d7888dba4d83217b5.zip
prop224: Refactor pick_hsdir() to be used by both v2 and v3.
Also refactor rendclient.c to use the new hs_pick_hdsir() func. Signed-off-by: David Goulet <dgoulet@torproject.org>
Diffstat (limited to 'src/or/hs_common.c')
-rw-r--r--src/or/hs_common.c29
1 files changed, 14 insertions, 15 deletions
diff --git a/src/or/hs_common.c b/src/or/hs_common.c
index dbd3848332..bc44265d53 100644
--- a/src/or/hs_common.c
+++ b/src/or/hs_common.c
@@ -21,6 +21,7 @@
#include "hs_service.h"
#include "rendcommon.h"
#include "rendservice.h"
+#include "routerset.h"
#include "router.h"
#include "routerset.h"
#include "shared_random.h"
@@ -1491,35 +1492,33 @@ hs_purge_last_hid_serv_requests(void)
/***********************************************************************/
-/** This returns a good valid hs dir that should be used for the given
- * descriptor id.
+/** Given the list of responsible HSDirs in <b>responsible_dirs</b>, pick the
+ * one that we should use to fetch a descriptor right now. Take into account
+ * previous failed attempts at fetching this descriptor from HSDirs using the
+ * string identifier <b>req_key_str</b>.
+ *
+ * Steals ownership of <b>responsible_dirs</b>.
*
- * Return NULL on error else the hsdir node pointer. */
+ * Return the routerstatus of the chosen HSDir if successful, otherwise return
+ * NULL if no HSDirs are worth trying right now. */
routerstatus_t *
-pick_hsdir(const char *desc_id, const char *desc_id_base32)
+hs_pick_hsdir(smartlist_t *responsible_dirs, const char *req_key_str)
{
- smartlist_t *responsible_dirs = smartlist_new();
smartlist_t *usable_responsible_dirs = smartlist_new();
const or_options_t *options = get_options();
routerstatus_t *hs_dir;
time_t now = time(NULL);
int excluded_some;
- tor_assert(desc_id);
- tor_assert(desc_id_base32);
-
- /* Determine responsible dirs. Even if we can't get all we want, work with
- * the ones we have. If it's empty, we'll notice below. */
- hid_serv_get_responsible_directories(responsible_dirs, desc_id);
+ tor_assert(req_key_str);
- /* Clean request history first. */
+ /* Clean outdated request history first. */
hs_clean_last_hid_serv_requests(now);
/* Only select those hidden service directories to which we did not send a
* request recently and for which we have a router descriptor here. */
SMARTLIST_FOREACH_BEGIN(responsible_dirs, routerstatus_t *, dir) {
- time_t last = hs_lookup_last_hid_serv_request(dir, desc_id_base32,
- 0, 0);
+ time_t last = hs_lookup_last_hid_serv_request(dir, req_key_str, 0, 0);
const node_t *node = node_get_by_id(dir->identity_digest);
if (last + hs_hsdir_requery_period(options) >= now ||
!node || !node_has_descriptor(node)) {
@@ -1553,7 +1552,7 @@ pick_hsdir(const char *desc_id, const char *desc_id_base32)
} else {
/* Remember that we are requesting a descriptor from this hidden service
* directory now. */
- hs_lookup_last_hid_serv_request(hs_dir, desc_id_base32, now, 1);
+ hs_lookup_last_hid_serv_request(hs_dir, req_key_str, now, 1);
}
return hs_dir;