[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [tor/master] prop224: Only upload descriptor if we have good hash ring and SRV.
commit 1f7b8012ae9b6226e5853751685c98782a48c0c4
Author: George Kadianakis <desnacked@xxxxxxxxxx>
Date: Sun Aug 13 20:16:21 2017 +0300
prop224: Only upload descriptor if we have good hash ring and SRV.
Make sure we have a live consensus (for SRV) and enough descriptors (for
hash ring).
Also fix unittests that broke.
---
src/or/hs_service.c | 11 +++++++++++
src/or/nodelist.c | 4 ++--
src/or/nodelist.h | 2 +-
src/test/test_hs_service.c | 13 +++++++++++--
4 files changed, 25 insertions(+), 5 deletions(-)
diff --git a/src/or/hs_service.c b/src/or/hs_service.c
index 3f6de0ba2..cf5f319f8 100644
--- a/src/or/hs_service.c
+++ b/src/or/hs_service.c
@@ -2288,6 +2288,17 @@ should_service_upload_descriptor(const hs_service_t *service,
goto cannot;
}
+ /* Don't upload desc if we don't have a live consensus */
+ if (!networkstatus_get_live_consensus(now)) {
+ goto cannot;
+ }
+
+ /* Do we know enough router descriptors to have adequate vision of the HSDir
+ hash ring? */
+ if (!router_have_minimum_dir_info()) {
+ goto cannot;
+ }
+
/* Can upload! */
return 1;
cannot:
diff --git a/src/or/nodelist.c b/src/or/nodelist.c
index 0fcaea626..a9b77262c 100644
--- a/src/or/nodelist.c
+++ b/src/or/nodelist.c
@@ -1741,8 +1741,8 @@ static char dir_info_status[512] = "";
* no exits in the consensus."
* To obtain the final weighted bandwidth, we multiply the
* weighted bandwidth fraction for each position (guard, middle, exit). */
-int
-router_have_minimum_dir_info(void)
+MOCK_IMPL(int,
+router_have_minimum_dir_info,(void))
{
static int logged_delay=0;
const char *delay_fetches_msg = NULL;
diff --git a/src/or/nodelist.h b/src/or/nodelist.h
index 405b79d82..06a08a288 100644
--- a/src/or/nodelist.h
+++ b/src/or/nodelist.h
@@ -105,7 +105,7 @@ int addrs_in_same_network_family(const tor_addr_t *a1,
* no exits in the consensus, we wait for enough info to create internal
* paths, and should avoid creating exit paths, as they will simply fail.
* We make sure we create all available circuit types at the same time. */
-int router_have_minimum_dir_info(void);
+MOCK_DECL(int, router_have_minimum_dir_info,(void));
/** Set to CONSENSUS_PATH_EXIT if there is at least one exit node
* in the consensus. We update this flag in compute_frac_paths_available if
diff --git a/src/test/test_hs_service.c b/src/test/test_hs_service.c
index c0dd9fe25..7263e0457 100644
--- a/src/test/test_hs_service.c
+++ b/src/test/test_hs_service.c
@@ -1177,6 +1177,12 @@ test_build_update_descriptors(void *arg)
UNMOCK(hs_overlap_mode_is_active);
}
+static int
+mock_router_have_minimum_dir_info(void)
+{
+ return 1;
+}
+
static void
test_upload_descriptors(void *arg)
{
@@ -1191,7 +1197,6 @@ test_upload_descriptors(void *arg)
MOCK(hs_overlap_mode_is_active, mock_hs_overlap_mode_is_active_true);
MOCK(get_or_state,
get_or_state_replacement);
-
dummy_state = tor_malloc_zero(sizeof(or_state_t));
/* Create a service with no descriptor. It's added to the global map. */
@@ -1229,9 +1234,13 @@ test_upload_descriptors(void *arg)
ip->circuit_established = 1;
service_intro_point_add(service->desc_current->intro_points.map, ip);
+ MOCK(networkstatus_get_live_consensus,
+ mock_networkstatus_get_live_consensus);
+ MOCK(router_have_minimum_dir_info,
+ mock_router_have_minimum_dir_info);
+
setup_full_capture_of_logs(LOG_WARN);
run_upload_descriptor_event(now);
- expect_log_msg_containing("No valid consensus so we can't get the");
teardown_capture_of_logs();
tt_u64_op(service->desc_current->next_upload_time, OP_GE,
now + HS_SERVICE_NEXT_UPLOAD_TIME_MIN);
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits