summaryrefslogtreecommitdiff
path: root/src/or/shared_random_state.c
diff options
context:
space:
mode:
authorDavid Goulet <dgoulet@torproject.org>2016-05-03 11:36:09 -0400
committerDavid Goulet <dgoulet@torproject.org>2016-07-01 14:01:41 -0400
commit0c26a6db7e683c23505c1c9187fd538c7b80ce31 (patch)
treea1ad7d2b48935a5f02a0abdf520e4e81a02f1268 /src/or/shared_random_state.c
parentca6ceec112f05ce68097429089ee428010c8b8d0 (diff)
downloadtor-0c26a6db7e683c23505c1c9187fd538c7b80ce31.tar.gz
tor-0c26a6db7e683c23505c1c9187fd538c7b80ce31.zip
prop250: Parse votes and consensus
One of the last piece that parses the votes and consensus in order to update our state and make decision for the SR values. We need to inform the SR subsystem when we set the current consensus because this can be called when loaded from file or downloaded from other authorities or computed. The voting schedule is used for the SR timings since we are bound to the voting system. Signed-off-by: David Goulet <dgoulet@torproject.org> Signed-off-by: George Kadianakis <desnacked@riseup.net>
Diffstat (limited to 'src/or/shared_random_state.c')
-rw-r--r--src/or/shared_random_state.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/or/shared_random_state.c b/src/or/shared_random_state.c
index 87bdfc048f..6dd10d612e 100644
--- a/src/or/shared_random_state.c
+++ b/src/or/shared_random_state.c
@@ -1160,6 +1160,27 @@ sr_state_delete_commits(void)
state_query(SR_STATE_ACTION_DEL_ALL, SR_STATE_OBJ_COMMIT, NULL, NULL);
}
+/* Copy the reveal information from <b>commit</b> into <b>saved_commit</b>.
+ * This <b>saved_commit</b> MUST come from our current SR state. Once modified,
+ * the disk state is updated. */
+void
+sr_state_copy_reveal_info(sr_commit_t *saved_commit, const sr_commit_t *commit)
+{
+ tor_assert(saved_commit);
+ tor_assert(commit);
+
+ saved_commit->reveal_ts = commit->reveal_ts;
+ memcpy(saved_commit->random_number, commit->random_number,
+ sizeof(saved_commit->random_number));
+
+ strlcpy(saved_commit->encoded_reveal, commit->encoded_reveal,
+ sizeof(saved_commit->encoded_reveal));
+ state_query(SR_STATE_ACTION_SAVE, 0, NULL, NULL);
+ log_debug(LD_DIR, "SR: Reveal value learned %s (for commit %s) from %s",
+ saved_commit->encoded_reveal, saved_commit->encoded_commit,
+ saved_commit->rsa_identity_fpr);
+}
+
/* Set the fresh SRV flag from our state. This doesn't need to trigger a
* disk state synchronization so we directly change the state. */
void
@@ -1202,6 +1223,14 @@ sr_state_save(void)
state_query(SR_STATE_ACTION_SAVE, 0, NULL, NULL);
}
+/* Return 1 iff the state has been initialized that is it exists in memory.
+ * Return 0 otherwise. */
+int
+sr_state_is_initialized(void)
+{
+ return sr_state == NULL ? 0 : 1;
+}
+
/* Initialize the disk and memory state.
*
* If save_to_disk is set to 1, the state is immediately saved to disk after