Просмотр исходного кода

Add GETINFO network-liveness to control protocol

Andrea Shepard 9 лет назад
Родитель
Сommit
4cbc9c5313
1 измененных файлов с 23 добавлено и 0 удалено
  1. 23 0
      src/or/control.c

+ 23 - 0
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."),