mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-28 06:13:31 +01:00
Add GETINFO network-liveness to control protocol
This commit is contained in:
parent
dce9e915c7
commit
4cbc9c5313
@ -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."),
|
||||
|
Loading…
Reference in New Issue
Block a user