summaryrefslogtreecommitdiff
path: root/src/or/control.c
diff options
context:
space:
mode:
authorDavid Goulet <dgoulet@torproject.org>2017-01-09 11:33:05 -0500
committerDavid Goulet <dgoulet@torproject.org>2017-01-09 11:33:05 -0500
commit8a33abcd65ebebf268750612d52684659f8df71d (patch)
treed2b9ec09c3e9a20f7e2d3996142a3ef200beb9b0 /src/or/control.c
parent655ffeadd53833d96a25a70261b31c60d6f0ac6d (diff)
downloadtor-8a33abcd65ebebf268750612d52684659f8df71d.tar.gz
tor-8a33abcd65ebebf268750612d52684659f8df71d.zip
control: Add GETINFO command for the shared random values
Add the "sr/current" and "sr/previous" keys for the GETINFO command in order to get through the control port the shared random values from the consensus. Closes #19925 Signed-off-by: David Goulet <dgoulet@torproject.org>
Diffstat (limited to 'src/or/control.c')
-rw-r--r--src/or/control.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/or/control.c b/src/or/control.c
index 248c780cce..9f342f1fbd 100644
--- a/src/or/control.c
+++ b/src/or/control.c
@@ -71,6 +71,7 @@
#include "router.h"
#include "routerlist.h"
#include "routerparse.h"
+#include "shared_random.h"
#ifndef _WIN32
#include <pwd.h>
@@ -2870,6 +2871,26 @@ getinfo_helper_liveness(control_connection_t *control_conn,
return 0;
}
+/** Implementation helper for GETINFO: answers queries about shared random
+ * value. */
+static int
+getinfo_helper_sr(control_connection_t *control_conn,
+ const char *question, char **answer,
+ const char **errmsg)
+{
+ (void) control_conn;
+ (void) errmsg;
+
+ if (!strcmp(question, "sr/current")) {
+ *answer = sr_get_current_for_control();
+ } else if(!strcmp(question, "sr/previous")) {
+ *answer = sr_get_previous_for_control();
+ }
+ /* Else statement here is unrecognized key so do nothing. */
+
+ return 0;
+}
+
/** Callback function for GETINFO: on a given control connection, try to
* answer the question <b>q</b> and store the newly-allocated answer in
* *<b>a</b>. If an internal error occurs, return -1 and optionally set
@@ -3062,6 +3083,8 @@ static const getinfo_item_t getinfo_items[] = {
"Onion services owned by the current control connection."),
ITEM("onions/detached", onions,
"Onion services detached from the control connection."),
+ ITEM("sr/current", sr, "Get current shared random value."),
+ ITEM("sr/previous", sr, "Get previous shared random value."),
{ NULL, NULL, NULL, 0 }
};