aboutsummaryrefslogtreecommitdiff
path: root/src/feature
diff options
context:
space:
mode:
authorTaylor Yu <catalyst@torproject.org>2018-12-15 22:14:46 -0600
committerNick Mathewson <nickm@torproject.org>2018-12-21 14:15:35 -0500
commit936c93e562deaba62f0d32f7e7fda770c5604318 (patch)
tree66320e5dcffecd423cf3d73fba17f2a5c1c243a4 /src/feature
parent9d29abb34e005f4e836976a4c00115a1e8977071 (diff)
downloadtor-936c93e562deaba62f0d32f7e7fda770c5604318.tar.gz
tor-936c93e562deaba62f0d32f7e7fda770c5604318.zip
Hook up control_event_bootstrap() to btrack_orconn
Replace a few invocations of control_event_bootstrap() with calls from the bootstrap tracker subsystem. This mostly leaves behavior unchanged. The actual behavior changes come in the next commit. Part of ticket 27167.
Diffstat (limited to 'src/feature')
-rw-r--r--src/feature/control/btrack_orconn.c13
-rw-r--r--src/feature/control/btrack_orconn_cevent.c102
-rw-r--r--src/feature/control/btrack_orconn_cevent.h17
-rw-r--r--src/feature/control/control.h1
-rw-r--r--src/feature/control/control_bootstrap.c11
-rw-r--r--src/feature/nodelist/nodelist.c1
6 files changed, 129 insertions, 16 deletions
diff --git a/src/feature/control/btrack_orconn.c b/src/feature/control/btrack_orconn.c
index 28f8509fe2..0fbf521000 100644
--- a/src/feature/control/btrack_orconn.c
+++ b/src/feature/control/btrack_orconn.c
@@ -27,6 +27,10 @@
* might be a one-hop circuit for directory lookups, or it might be a
* connection for an application circuit because we already have
* enough directory info to build an application circuit.
+ *
+ * We call functions in btrack_orconn_cevent.c to generate the actual
+ * controller events, because some of the state decoding we need to do
+ * is complicated.
**/
#include <stdbool.h>
@@ -38,6 +42,7 @@
#include "core/or/ocirc_event.h"
#include "core/or/orconn_event.h"
#include "feature/control/btrack_orconn.h"
+#include "feature/control/btrack_orconn_cevent.h"
#include "feature/control/btrack_orconn_maps.h"
#include "lib/log/log.h"
@@ -86,9 +91,10 @@ bto_update_bests(const bt_orconn_t *bto)
{
tor_assert(bto->is_orig);
- bto_update_best(bto, &best_any, "ANY");
- if (!bto->is_onehop)
- bto_update_best(bto, &best_ap, "AP");
+ if (bto_update_best(bto, &best_any, "ANY"))
+ bto_cevent_anyconn(bto);
+ if (!bto->is_onehop && bto_update_best(bto, &best_ap, "AP"))
+ bto_cevent_apconn(bto);
}
/** Reset cached "best" values */
@@ -196,4 +202,5 @@ btrack_orconn_fini(void)
{
bto_clear_maps();
bto_reset_bests();
+ bto_cevent_reset();
}
diff --git a/src/feature/control/btrack_orconn_cevent.c b/src/feature/control/btrack_orconn_cevent.c
new file mode 100644
index 0000000000..fbbd34aca5
--- /dev/null
+++ b/src/feature/control/btrack_orconn_cevent.c
@@ -0,0 +1,102 @@
+/* Copyright (c) 2007-2018, The Tor Project, Inc. */
+/* See LICENSE for licensing information */
+
+/**
+ * \file btrack_orconn_cevent.c
+ * \brief Emit bootstrap status events for OR connections
+ **/
+
+#include <stdbool.h>
+
+#include "core/or/or.h"
+
+#define BTRACK_ORCONN_PRIVATE
+
+#include "core/or/orconn_event.h"
+#include "feature/control/btrack_orconn.h"
+#include "feature/control/btrack_orconn_cevent.h"
+#include "feature/control/control.h"
+
+/**
+ * Have we completed our first OR connection?
+ *
+ * Block display of application circuit progress until we do, to avoid
+ * some misleading behavior of jumping to high progress.
+ **/
+static bool bto_first_orconn = false;
+
+/**
+ * Emit control events when we have updated our idea of the best state
+ * that any OR connection has reached.
+ **/
+void
+bto_cevent_anyconn(const bt_orconn_t *bto)
+{
+ switch (bto->state) {
+ case OR_CONN_STATE_CONNECTING:
+ case OR_CONN_STATE_PROXY_HANDSHAKING:
+ /* XXX This isn't quite right, because this isn't necessarily a
+ directory server we're talking to, but we'll improve the
+ bootstrap tags and messages later */
+ control_event_bootstrap(BOOTSTRAP_STATUS_CONN_DIR, 0);
+ break;
+ case OR_CONN_STATE_TLS_HANDSHAKING:
+ /* Here we should report a connection completed (TCP or proxied),
+ if we had the states */
+ break;
+ case OR_CONN_STATE_TLS_CLIENT_RENEGOTIATING:
+ case OR_CONN_STATE_OR_HANDSHAKING_V2:
+ case OR_CONN_STATE_OR_HANDSHAKING_V3:
+ /* XXX Again, this isn't quite right, because it's not necessarily
+ a directory server we're talking to. */
+ control_event_bootstrap(BOOTSTRAP_STATUS_HANDSHAKE_DIR, 0);
+ break;
+ case OR_CONN_STATE_OPEN:
+ /* Unblock directory progress display */
+ control_event_boot_first_orconn();
+ /* Unblock apconn progress display */
+ bto_first_orconn = true;
+ break;
+ default:
+ break;
+ }
+}
+
+/**
+ * Emit control events when we have updated our idea of the best state
+ * that any application circuit OR connection has reached.
+ **/
+void
+bto_cevent_apconn(const bt_orconn_t *bto)
+{
+ if (!bto_first_orconn)
+ return;
+
+ switch (bto->state) {
+ case OR_CONN_STATE_CONNECTING:
+ case OR_CONN_STATE_PROXY_HANDSHAKING:
+ control_event_bootstrap(BOOTSTRAP_STATUS_CONN_OR, 0);
+ break;
+ case OR_CONN_STATE_TLS_HANDSHAKING:
+ /* Here we should report a connection completed (TCP or proxied) */
+ break;
+ case OR_CONN_STATE_TLS_CLIENT_RENEGOTIATING:
+ case OR_CONN_STATE_OR_HANDSHAKING_V2:
+ case OR_CONN_STATE_OR_HANDSHAKING_V3:
+ control_event_bootstrap(BOOTSTRAP_STATUS_HANDSHAKE_OR, 0);
+ break;
+ case OR_CONN_STATE_OPEN:
+ /* XXX Not quite right, because it implictly reports the next
+ state, but we'll improve it later. */
+ control_event_bootstrap(BOOTSTRAP_STATUS_CIRCUIT_CREATE, 0);
+ default:
+ break;
+ }
+}
+
+/** Forget that we completed our first OR connection */
+void
+bto_cevent_reset(void)
+{
+ bto_first_orconn = false;
+}
diff --git a/src/feature/control/btrack_orconn_cevent.h b/src/feature/control/btrack_orconn_cevent.h
new file mode 100644
index 0000000000..165ff69cdb
--- /dev/null
+++ b/src/feature/control/btrack_orconn_cevent.h
@@ -0,0 +1,17 @@
+/* Copyright (c) 2007-2018, The Tor Project, Inc. */
+/* See LICENSE for licensing information */
+
+/**
+ * \file btrack_orconn_cevent.h
+ * \brief Header file for btrack_orconn_cevent.c
+ **/
+
+#ifndef TOR_BTRACK_ORCONN_CEVENT_H
+
+#include "feature/control/btrack_orconn.h"
+
+void bto_cevent_anyconn(const bt_orconn_t *);
+void bto_cevent_apconn(const bt_orconn_t *);
+void bto_cevent_reset(void);
+
+#endif /* defined(TOR_BTRACK_ORCONN_CEVENT_H) */
diff --git a/src/feature/control/control.h b/src/feature/control/control.h
index 68c9a6bed1..8180c4b603 100644
--- a/src/feature/control/control.h
+++ b/src/feature/control/control.h
@@ -52,7 +52,6 @@ typedef enum {
BOOTSTRAP_STATUS_UNDEF=-1,
BOOTSTRAP_STATUS_STARTING=0,
BOOTSTRAP_STATUS_CONN_DIR=5,
- BOOTSTRAP_STATUS_HANDSHAKE=-2,
BOOTSTRAP_STATUS_HANDSHAKE_DIR=10,
BOOTSTRAP_STATUS_ONEHOP_CREATE=15,
BOOTSTRAP_STATUS_REQUESTING_STATUS=20,
diff --git a/src/feature/control/control_bootstrap.c b/src/feature/control/control_bootstrap.c
index 0756e208e0..0478f0783d 100644
--- a/src/feature/control/control_bootstrap.c
+++ b/src/feature/control/control_bootstrap.c
@@ -34,7 +34,6 @@ static const struct {
{ BOOTSTRAP_STATUS_UNDEF, "undef", "Undefined" },
{ BOOTSTRAP_STATUS_STARTING, "starting", "Starting" },
{ BOOTSTRAP_STATUS_CONN_DIR, "conn_dir", "Connecting to directory server" },
- { BOOTSTRAP_STATUS_HANDSHAKE, "status_handshake", "Finishing handshake" },
{ BOOTSTRAP_STATUS_HANDSHAKE_DIR, "handshake_dir",
"Finishing handshake with directory server" },
{ BOOTSTRAP_STATUS_ONEHOP_CREATE, "onehop_create",
@@ -151,16 +150,6 @@ control_event_bootstrap(bootstrap_status_t status, int progress)
if (bootstrap_percent == BOOTSTRAP_STATUS_DONE)
return; /* already bootstrapped; nothing to be done here. */
- /* special case for handshaking status, since our TLS handshaking code
- * can't distinguish what the connection is going to be for. */
- if (status == BOOTSTRAP_STATUS_HANDSHAKE) {
- if (bootstrap_percent < BOOTSTRAP_STATUS_CONN_OR) {
- status = BOOTSTRAP_STATUS_HANDSHAKE_DIR;
- } else {
- status = BOOTSTRAP_STATUS_HANDSHAKE_OR;
- }
- }
-
if (status <= bootstrap_percent) {
/* If there's no new progress, return early. */
if (!progress || progress <= bootstrap_percent)
diff --git a/src/feature/nodelist/nodelist.c b/src/feature/nodelist/nodelist.c
index f93ecd5bfe..e1d5e4d3fa 100644
--- a/src/feature/nodelist/nodelist.c
+++ b/src/feature/nodelist/nodelist.c
@@ -2633,7 +2633,6 @@ update_router_have_minimum_dir_info(void)
/* If paths have just become available in this update. */
if (res && !have_min_dir_info) {
control_event_client_status(LOG_NOTICE, "ENOUGH_DIR_INFO");
- control_event_boot_dir(BOOTSTRAP_STATUS_CONN_OR, 0);
log_info(LD_DIR,
"We now have enough directory information to build circuits.");
}