tor  0.4.2.1-alpha-dev
btrack_orconn_cevent.c
Go to the documentation of this file.
1 /* Copyright (c) 2007-2019, The Tor Project, Inc. */
2 /* See LICENSE for licensing information */
3 
14 #include <stdbool.h>
15 
16 #include "core/or/or.h"
17 
18 #define BTRACK_ORCONN_PRIVATE
19 
20 #include "core/or/orconn_event.h"
24 
31 static bool bto_first_orconn = false;
32 
34 static bool
35 using_pt(const bt_orconn_t *bto)
36 {
37  return bto->proxy_type == PROXY_PLUGGABLE;
38 }
39 
41 static bool
42 using_proxy(const bt_orconn_t *bto)
43 {
44  switch (bto->proxy_type) {
45  case PROXY_CONNECT:
46  case PROXY_SOCKS4:
47  case PROXY_SOCKS5:
48  return true;
49  default:
50  return false;
51  }
52 }
53 
61 void
62 bto_cevent_anyconn(const bt_orconn_t *bto)
63 {
64  switch (bto->state) {
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. */
69  if (using_pt(bto))
70  control_event_bootstrap(BOOTSTRAP_STATUS_CONN_PT, 0);
71  else if (using_proxy(bto))
72  control_event_bootstrap(BOOTSTRAP_STATUS_CONN_PROXY, 0);
73  else
74  control_event_bootstrap(BOOTSTRAP_STATUS_CONN, 0);
75  break;
77  /* Similarly, starting a proxy handshake means the TCP connect()
78  * succeeded to the proxy. Let's be specific about what kind of
79  * proxy. */
80  if (using_pt(bto))
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);
84  break;
86  control_event_bootstrap(BOOTSTRAP_STATUS_CONN_DONE, 0);
87  break;
91  control_event_bootstrap(BOOTSTRAP_STATUS_HANDSHAKE, 0);
92  break;
93  case OR_CONN_STATE_OPEN:
94  control_event_bootstrap(BOOTSTRAP_STATUS_HANDSHAKE_DONE, 0);
95  /* Unblock directory progress display */
97  /* Unblock apconn progress display */
98  bto_first_orconn = true;
99  break;
100  default:
101  break;
102  }
103 }
104 
112 void
113 bto_cevent_apconn(const bt_orconn_t *bto)
114 {
115  if (!bto_first_orconn)
116  return;
117 
118  switch (bto->state) {
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. */
123  if (using_pt(bto))
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);
127  else
128  control_event_bootstrap(BOOTSTRAP_STATUS_AP_CONN, 0);
129  break;
131  /* Similarly, starting a proxy handshake means the TCP connect()
132  * succeeded to the proxy. Let's be specific about what kind of
133  * proxy. */
134  if (using_pt(bto))
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);
138  break;
140  control_event_bootstrap(BOOTSTRAP_STATUS_AP_CONN_DONE, 0);
141  break;
145  control_event_bootstrap(BOOTSTRAP_STATUS_AP_HANDSHAKE, 0);
146  break;
147  case OR_CONN_STATE_OPEN:
148  control_event_bootstrap(BOOTSTRAP_STATUS_AP_HANDSHAKE_DONE, 0);
149  default:
150  break;
151  }
152 }
153 
155 void
157 {
158  bto_first_orconn = false;
159 }
Header file for btrack_orconn_cevent.c.
#define OR_CONN_STATE_TLS_HANDSHAKING
Definition: orconn_event.h:36
void bto_cevent_apconn(const bt_orconn_t *bto)
static bool using_proxy(const bt_orconn_t *bto)
static bool bto_first_orconn
Header file for orconn_event.c.
void control_event_bootstrap(bootstrap_status_t status, int progress)
#define OR_CONN_STATE_TLS_CLIENT_RENEGOTIATING
Definition: orconn_event.h:39
Master header file for Tor-specific functionality.
#define OR_CONN_STATE_OPEN
Definition: orconn_event.h:53
Header file for btrack_orconn.c.
#define OR_CONN_STATE_PROXY_HANDSHAKING
Definition: orconn_event.h:33
void bto_cevent_reset(void)
static bool using_pt(const bt_orconn_t *bto)
#define OR_CONN_STATE_OR_HANDSHAKING_V2
Definition: orconn_event.h:47
void bto_cevent_anyconn(const bt_orconn_t *bto)
void control_event_boot_first_orconn(void)
#define OR_CONN_STATE_OR_HANDSHAKING_V3
Definition: orconn_event.h:51
#define OR_CONN_STATE_CONNECTING
Definition: orconn_event.h:31
Header file for control_events.c.