summaryrefslogtreecommitdiff
path: root/src/or
diff options
context:
space:
mode:
Diffstat (limited to 'src/or')
-rw-r--r--src/or/dirvote.c10
-rw-r--r--src/or/shared_random.c48
-rw-r--r--src/or/shared_random.h9
3 files changed, 47 insertions, 20 deletions
diff --git a/src/or/dirvote.c b/src/or/dirvote.c
index 4ebea3262c..4fbd6b339f 100644
--- a/src/or/dirvote.c
+++ b/src/or/dirvote.c
@@ -1341,8 +1341,16 @@ networkstatus_compute_consensus(smartlist_t *votes,
}
if (consensus_method >= MIN_METHOD_FOR_SHARED_RANDOM) {
+ int num_dirauth = get_n_authorities(V3_DIRINFO);
+ /* Default value of this is 2/3 of the total number of authorities. For
+ * instance, if we have 9 dirauth, the default value is 6. The following
+ * calculation will round it down. */
+ int32_t num_srv_agreements =
+ dirvote_get_intermediate_param_value(param_list,
+ "AuthDirNumSRVAgreements",
+ (num_dirauth * 2) / 3);
/* Add the shared random value. */
- char *srv_lines = sr_get_string_for_consensus(votes);
+ char *srv_lines = sr_get_string_for_consensus(votes, num_srv_agreements);
if (srv_lines != NULL) {
smartlist_add(chunks, srv_lines);
}
diff --git a/src/or/shared_random.c b/src/or/shared_random.c
index 79151255fa..5cdf3d0287 100644
--- a/src/or/shared_random.c
+++ b/src/or/shared_random.c
@@ -105,6 +105,12 @@ static const char current_srv_str[] = "shared-rand-current-value";
static const char commit_ns_str[] = "shared-rand-commit";
static const char sr_flag_ns_str[] = "shared-rand-participate";
+/* The value of the consensus param AuthDirNumSRVAgreements found in the
+ * vote. This is set once the consensus creation subsystem requests the
+ * SRV(s) that should be put in the consensus. We use this value to decide
+ * if we keep or not an SRV. */
+static int32_t num_srv_agreements_from_vote;
+
/* Return a heap allocated copy of the SRV <b>orig</b>. */
STATIC sr_srv_t *
srv_dup(const sr_srv_t *orig)
@@ -737,18 +743,6 @@ save_commit_to_state(sr_commit_t *commit)
}
}
-/* Return the number of required participants of the SR protocol. This is based
- * on a consensus params. */
-static int
-get_n_voters_for_srv_agreement(void)
-{
- int num_dirauths = get_n_authorities(V3_DIRINFO);
- /* If the params is not found, default value should always be the maximum
- * number of trusted authorities. Let's not take any chances. */
- return networkstatus_get_param(NULL, "AuthDirNumSRVAgreements",
- num_dirauths, 1, num_dirauths);
-}
-
/* Return 1 if we should we keep an SRV voted by <b>n_agreements</b> auths.
* Return 0 if we should ignore it. */
static int
@@ -769,11 +763,9 @@ should_keep_srv(int n_agreements)
* to keep it. */
if (sr_state_srv_is_fresh()) {
/* Check if we have super majority for this new SRV value. */
- int num_required_agreements = get_n_voters_for_srv_agreement();
-
- if (n_agreements < num_required_agreements) {
+ if (n_agreements < num_srv_agreements_from_vote) {
log_notice(LD_DIR, "SR: New SRV didn't reach agreement [%d/%d]!",
- n_agreements, num_required_agreements);
+ n_agreements, num_srv_agreements_from_vote);
return 0;
}
}
@@ -1253,9 +1245,14 @@ sr_get_string_for_vote(void)
*
* This is called when a consensus (any flavor) is bring created thus it
* should NEVER change the state nor the state should be changed in between
- * consensus creation. */
+ * consensus creation.
+ *
+ * <b>num_srv_agreements</b> is taken from the votes thus the voted value
+ * that should be used.
+ * */
char *
-sr_get_string_for_consensus(const smartlist_t *votes)
+sr_get_string_for_consensus(const smartlist_t *votes,
+ int32_t num_srv_agreements)
{
char *srv_str;
const or_options_t *options = get_options();
@@ -1269,6 +1266,9 @@ sr_get_string_for_consensus(const smartlist_t *votes)
goto end;
}
+ /* Set the global value of AuthDirNumSRVAgreements found in the votes. */
+ num_srv_agreements_from_vote = num_srv_agreements;
+
/* Check the votes and figure out if SRVs should be included in the final
* consensus. */
sr_srv_t *prev_srv = get_majority_srv_from_votes(votes, 0);
@@ -1340,3 +1340,15 @@ sr_save_and_cleanup(void)
sr_state_save();
sr_cleanup();
}
+
+#ifdef TOR_UNIT_TESTS
+
+/* Set the global value of number of SRV agreements so the test can play
+ * along by calling specific functions that don't parse the votes prior for
+ * the AuthDirNumSRVAgreements value. */
+void set_num_srv_agreements(int32_t value)
+{
+ num_srv_agreements_from_vote = value;
+}
+
+#endif /* TOR_UNIT_TESTS */
diff --git a/src/or/shared_random.h b/src/or/shared_random.h
index 6d68ad79bc..3922f33e34 100644
--- a/src/or/shared_random.h
+++ b/src/or/shared_random.h
@@ -112,7 +112,8 @@ void sr_handle_received_commits(smartlist_t *commits,
sr_commit_t *sr_parse_commit(const smartlist_t *args);
sr_srv_t *sr_parse_srv(const smartlist_t *args);
char *sr_get_string_for_vote(void);
-char *sr_get_string_for_consensus(const smartlist_t *votes);
+char *sr_get_string_for_consensus(const smartlist_t *votes,
+ int32_t num_srv_agreements);
void sr_commit_free(sr_commit_t *commit);
void sr_srv_encode(char *dst, size_t dst_len, const sr_srv_t *srv);
@@ -156,4 +157,10 @@ STATIC void save_commit_during_reveal_phase(const sr_commit_t *commit);
#endif /* SHARED_RANDOM_PRIVATE */
+#ifdef TOR_UNIT_TESTS
+
+void set_num_srv_agreements(int32_t value);
+
+#endif /* TOR_UNIT_TESTS */
+
#endif /* TOR_SHARED_RANDOM_H */