commit 4cbc9c53131573a8edcbe1748b5ed220959db0b6 Author: Andrea Shepard <and...@torproject.org> Date: Fri May 15 19:44:13 2015 +0000
Add GETINFO network-liveness to control protocol --- src/or/control.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/or/control.c b/src/or/control.c index a64822e..c76ade0 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."), _______________________________________________ tor-commits mailing list tor-commits@lists.torproject.org https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits