From: Andrea Shepard Date: Fri, 15 May 2015 19:44:13 +0000 (+0000) Subject: Add GETINFO network-liveness to control protocol X-Git-Tag: tor-0.2.7.2-alpha~151^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4cbc9c53131573a8edcbe1748b5ed220959db0b6;p=thirdparty%2Ftor.git Add GETINFO network-liveness to control protocol --- 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 q and store the newly-allocated answer in * *a. 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."),