1 /* Copyright (c) 2007-2019, The Tor Project, Inc. */
2 /* See LICENSE for licensing information */
5 * \file btrack_orconn_cevent.c
6 * \brief Emit bootstrap status events for OR connections
8 * We do some decoding of the raw OR_CONN_STATE_* values. For
9 * example, OR_CONN_STATE_CONNECTING means the first TCP connect()
10 * completing, regardless of whether it's directly to a relay instead
16 #include "core/or/or.h"
18 #define BTRACK_ORCONN_PRIVATE
20 #include "core/or/orconn_event.h"
21 #include "feature/control/btrack_orconn.h"
22 #include "feature/control/btrack_orconn_cevent.h"
23 #include "feature/control/control_events.h"
26 * Have we completed our first OR connection?
28 * Block display of application circuit progress until we do, to avoid
29 * some misleading behavior of jumping to high progress.
31 static bool bto_first_orconn
= false;
33 /** Is the ORCONN using a pluggable transport? */
35 using_pt(const bt_orconn_t
*bto
)
37 return bto
->proxy_type
== PROXY_PLUGGABLE
;
40 /** Is the ORCONN using a non-PT proxy? */
42 using_proxy(const bt_orconn_t
*bto
)
44 switch (bto
->proxy_type
) {
55 * Emit control events when we have updated our idea of the best state
56 * that any OR connection has reached.
58 * Do some decoding of the ORCONN states depending on whether a PT or
62 bto_cevent_anyconn(const bt_orconn_t
*bto
)
65 case OR_CONN_STATE_CONNECTING
:
66 /* Exactly what kind of thing we're connecting to isn't
67 * information we directly get from the states in connection_or.c,
68 * so decode it here. */
70 control_event_bootstrap(BOOTSTRAP_STATUS_CONN_PT
, 0);
71 else if (using_proxy(bto
))
72 control_event_bootstrap(BOOTSTRAP_STATUS_CONN_PROXY
, 0);
74 control_event_bootstrap(BOOTSTRAP_STATUS_CONN
, 0);
76 case OR_CONN_STATE_PROXY_HANDSHAKING
:
77 /* Similarly, starting a proxy handshake means the TCP connect()
78 * succeeded to the proxy. Let's be specific about what kind of
81 control_event_bootstrap(BOOTSTRAP_STATUS_CONN_DONE_PT
, 0);
82 else if (using_proxy(bto
))
83 control_event_bootstrap(BOOTSTRAP_STATUS_CONN_DONE_PROXY
, 0);
85 case OR_CONN_STATE_TLS_HANDSHAKING
:
86 control_event_bootstrap(BOOTSTRAP_STATUS_CONN_DONE
, 0);
88 case OR_CONN_STATE_TLS_CLIENT_RENEGOTIATING
:
89 case OR_CONN_STATE_OR_HANDSHAKING_V2
:
90 case OR_CONN_STATE_OR_HANDSHAKING_V3
:
91 control_event_bootstrap(BOOTSTRAP_STATUS_HANDSHAKE
, 0);
93 case OR_CONN_STATE_OPEN
:
94 control_event_bootstrap(BOOTSTRAP_STATUS_HANDSHAKE_DONE
, 0);
95 /* Unblock directory progress display */
96 control_event_boot_first_orconn();
97 /* Unblock apconn progress display */
98 bto_first_orconn
= true;
106 * Emit control events when we have updated our idea of the best state
107 * that any application circuit OR connection has reached.
109 * Do some decoding of the ORCONN states depending on whether a PT or
113 bto_cevent_apconn(const bt_orconn_t
*bto
)
115 if (!bto_first_orconn
)
118 switch (bto
->state
) {
119 case OR_CONN_STATE_CONNECTING
:
120 /* Exactly what kind of thing we're connecting to isn't
121 * information we directly get from the states in connection_or.c,
122 * so decode it here. */
124 control_event_bootstrap(BOOTSTRAP_STATUS_AP_CONN_PT
, 0);
125 else if (using_proxy(bto
))
126 control_event_bootstrap(BOOTSTRAP_STATUS_AP_CONN_PROXY
, 0);
128 control_event_bootstrap(BOOTSTRAP_STATUS_AP_CONN
, 0);
130 case OR_CONN_STATE_PROXY_HANDSHAKING
:
131 /* Similarly, starting a proxy handshake means the TCP connect()
132 * succeeded to the proxy. Let's be specific about what kind of
135 control_event_bootstrap(BOOTSTRAP_STATUS_AP_CONN_DONE_PT
, 0);
136 else if (using_proxy(bto
))
137 control_event_bootstrap(BOOTSTRAP_STATUS_AP_CONN_DONE_PROXY
, 0);
139 case OR_CONN_STATE_TLS_HANDSHAKING
:
140 control_event_bootstrap(BOOTSTRAP_STATUS_AP_CONN_DONE
, 0);
142 case OR_CONN_STATE_TLS_CLIENT_RENEGOTIATING
:
143 case OR_CONN_STATE_OR_HANDSHAKING_V2
:
144 case OR_CONN_STATE_OR_HANDSHAKING_V3
:
145 control_event_bootstrap(BOOTSTRAP_STATUS_AP_HANDSHAKE
, 0);
147 case OR_CONN_STATE_OPEN
:
148 control_event_bootstrap(BOOTSTRAP_STATUS_AP_HANDSHAKE_DONE
, 0);
154 /** Forget that we completed our first OR connection */
156 bto_cevent_reset(void)
158 bto_first_orconn
= false;