summaryrefslogtreecommitdiff
path: root/src/or/control.c
diff options
context:
space:
mode:
authorAndrea Shepard <andrea@torproject.org>2015-05-06 12:37:13 +0000
committerAndrea Shepard <andrea@torproject.org>2015-05-17 13:42:57 +0000
commitdce9e915c77ccf42e74a5cccca309e8085738d75 (patch)
tree73256809d1c90d2431b357617ec1136a5eeb5272 /src/or/control.c
parent411049d0d44963b8d9ec6f96c8dc62a106d6cc30 (diff)
downloadtor-dce9e915c77ccf42e74a5cccca309e8085738d75.tar.gz
tor-dce9e915c77ccf42e74a5cccca309e8085738d75.zip
Implement EVENT_NETWORK_LIVENESS
Diffstat (limited to 'src/or/control.c')
-rw-r--r--src/or/control.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/or/control.c b/src/or/control.c
index 950e9891e0..a64822e5a2 100644
--- a/src/or/control.c
+++ b/src/or/control.c
@@ -959,6 +959,7 @@ static const struct control_event_t control_event_table[] = {
{ EVENT_TRANSPORT_LAUNCHED, "TRANSPORT_LAUNCHED" },
{ EVENT_HS_DESC, "HS_DESC" },
{ EVENT_HS_DESC_CONTENT, "HS_DESC_CONTENT" },
+ { EVENT_NETWORK_LIVENESS, "NETWORK_LIVENESS" },
{ 0, NULL },
};
@@ -4992,6 +4993,52 @@ control_event_or_authdir_new_descriptor(const char *action,
return 0;
}
+/** Cached liveness for network liveness events and GETINFO
+ */
+
+static int network_is_live = 0;
+
+static int
+get_cached_network_liveness(void)
+{
+ return network_is_live;
+}
+
+static void
+set_cached_network_liveness(int liveness)
+{
+ network_is_live = liveness;
+}
+
+/** The network liveness has changed; this is called from circuitstats.c
+ * whenever we receive a cell, or when timeout expires and we assume the
+ * network is down. */
+int
+control_event_network_liveness_update(int liveness)
+{
+ if (liveness > 0) {
+ if (get_cached_network_liveness() <= 0) {
+ /* Update cached liveness */
+ set_cached_network_liveness(1);
+ log_debug(LD_CONTROL, "Sending NETWORK_LIVENESS UP");
+ send_control_event_string(EVENT_NETWORK_LIVENESS, ALL_FORMATS,
+ "650 NETWORK_LIVENESS UP\r\n");
+ }
+ /* else was already live, no-op */
+ } else {
+ if (get_cached_network_liveness() > 0) {
+ /* Update cached liveness */
+ set_cached_network_liveness(0);
+ log_debug(LD_CONTROL, "Sending NETWORK_LIVENESS DOWN");
+ send_control_event_string(EVENT_NETWORK_LIVENESS, ALL_FORMATS,
+ "650 NETWORK_LIVENESS DOWN\r\n");
+ }
+ /* else was already dead, no-op */
+ }
+
+ return 0;
+}
+
/** Helper function for NS-style events. Constructs and sends an event
* of type <b>event</b> with string <b>event_string</b> out of the set of
* networkstatuses <b>statuses</b>. Currently it is used for NS events