aboutsummaryrefslogtreecommitdiff
path: root/src/or/control.c
diff options
context:
space:
mode:
authorAndrea Shepard <andrea@torproject.org>2015-05-15 19:44:13 +0000
committerAndrea Shepard <andrea@torproject.org>2015-05-17 13:42:57 +0000
commit4cbc9c53131573a8edcbe1748b5ed220959db0b6 (patch)
tree3140f06b61b0095c1a726fade7b8d5bd49dd47ac /src/or/control.c
parentdce9e915c77ccf42e74a5cccca309e8085738d75 (diff)
downloadtor-4cbc9c53131573a8edcbe1748b5ed220959db0b6.tar.gz
tor-4cbc9c53131573a8edcbe1748b5ed220959db0b6.zip
Add GETINFO network-liveness to control protocol
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 a64822e5a2..c76ade06d5 100644
--- a/src/or/control.c
+++ b/src/or/control.c
@@ -179,6 +179,9 @@ static int write_stream_target_to_buf(entry_connection_t *conn, char *buf,
static void orconn_target_get_name(char *buf, size_t len,
or_connection_t *conn);
+static int get_cached_network_liveness(void);
+static void set_cached_network_liveness(int liveness);
+
/** Given a control event code for a message event, return the corresponding
* log severity. */
static INLINE int
@@ -2207,6 +2210,24 @@ getinfo_helper_onions(control_connection_t *control_conn,
return 0;
}
+/** Implementation helper for GETINFO: answers queries about network
+ * liveness. */
+static int
+getinfo_helper_liveness(control_connection_t *control_conn,
+ const char *question, char **answer,
+ const char **errmsg)
+{
+ if (strcmp(question, "network-liveness") == 0) {
+ if (get_cached_network_liveness()) {
+ *answer = tor_strdup("up");
+ } else {
+ *answer = tor_strdup("down");
+ }
+ }
+
+ 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
@@ -2291,6 +2312,8 @@ static const getinfo_item_t getinfo_items[] = {
"Information about and from the ns consensus."),
ITEM("network-status", dir,
"Brief summary of router status (v1 directory format)"),
+ ITEM("network-liveness", liveness,
+ "Current opinion on whether the network is live"),
ITEM("circuit-status", events, "List of current circuits originating here."),
ITEM("stream-status", events,"List of current streams."),
ITEM("orconn-status", events, "A list of current OR connections."),