Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions changes/ticket27167
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
o Major features (bootstrap):
- Report the first connection to a relay as the earliest phases of
bootstrap progress, regardless of whether it's a connection for
building application circuits. This allows finer-grained
reporting of early progress than previously possible with the
improvements of ticket 27169. Closes tickets 27167 and 27103.
Addresses ticket 27308.
- Separately report the intermediate stage of having connected to
a proxy or pluggable transport, versus succesfully using that
proxy or pluggable transport to connect to a relay. Closes
tickets 27100 and 28884.
2 changes: 1 addition & 1 deletion doc/tor.1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ GENERAL OPTIONS
The currently recognized domains are: general, crypto, net, config, fs,
protocol, mm, http, app, control, circ, rend, bug, dir, dirserv, or, edge,
acct, hist, handshake, heartbeat, channel, sched, guard, consdiff, dos,
process, and pt.
process, pt, and btrack.
Domain names are case-insensitive. +
+
For example, "`Log [handshake]debug [~net,~mm]info notice stdout`" sends
Expand Down
6 changes: 6 additions & 0 deletions src/app/main/subsystem_list.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
#include "lib/cc/compat_compiler.h"
#include "lib/cc/torint.h"

#include "core/or/ocirc_event_sys.h"
#include "core/or/orconn_event_sys.h"
#include "feature/control/btrack_sys.h"
#include "lib/compress/compress_sys.h"
#include "lib/crypt_ops/crypto_sys.h"
#include "lib/err/torerr_sys.h"
Expand Down Expand Up @@ -35,6 +38,9 @@ const subsys_fns_t *tor_subsystems[] = {
&sys_compress, /* -70 */
&sys_crypto, /* -60 */
&sys_tortls, /* -50 */
&sys_orconn_event, /* -40 */
&sys_ocirc_event, /* -39 */
&sys_btrack, /* -30 */
};

const unsigned n_tor_subsystems = ARRAY_LENGTH(tor_subsystems);
16 changes: 16 additions & 0 deletions src/core/include.am
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ LIBTOR_APP_A_SOURCES = \
src/core/or/connection_or.c \
src/core/or/dos.c \
src/core/or/onion.c \
src/core/or/ocirc_event.c \
src/core/or/orconn_event.c \
src/core/or/policies.c \
src/core/or/protover.c \
src/core/or/protover_rust.c \
Expand All @@ -61,6 +63,11 @@ LIBTOR_APP_A_SOURCES = \
src/feature/client/dnsserv.c \
src/feature/client/entrynodes.c \
src/feature/client/transports.c \
src/feature/control/btrack.c \
src/feature/control/btrack_circuit.c \
src/feature/control/btrack_orconn.c \
src/feature/control/btrack_orconn_cevent.c \
src/feature/control/btrack_orconn_maps.c \
src/feature/control/control.c \
src/feature/control/control_bootstrap.c \
src/feature/control/fmt_serverstatus.c \
Expand Down Expand Up @@ -238,10 +245,14 @@ noinst_HEADERS += \
src/core/or/listener_connection_st.h \
src/core/or/onion.h \
src/core/or/or.h \
src/core/or/orconn_event.h \
src/core/or/orconn_event_sys.h \
src/core/or/or_circuit_st.h \
src/core/or/or_connection_st.h \
src/core/or/or_handshake_certs_st.h \
src/core/or/or_handshake_state_st.h \
src/core/or/ocirc_event.h \
src/core/or/ocirc_event_sys.h \
src/core/or/origin_circuit_st.h \
src/core/or/policies.h \
src/core/or/port_cfg_st.h \
Expand All @@ -268,6 +279,11 @@ noinst_HEADERS += \
src/feature/client/dnsserv.h \
src/feature/client/entrynodes.h \
src/feature/client/transports.h \
src/feature/control/btrack_circuit.h \
src/feature/control/btrack_orconn.h \
src/feature/control/btrack_orconn_cevent.h \
src/feature/control/btrack_orconn_maps.h \
src/feature/control/btrack_sys.h \
src/feature/control/control.h \
src/feature/control/control_connection_st.h \
src/feature/control/fmt_serverstatus.h \
Expand Down
2 changes: 1 addition & 1 deletion src/core/mainloop/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -1875,7 +1875,7 @@ connection_init_accepted_conn(connection_t *conn,
/* Initiate Extended ORPort authentication. */
return connection_ext_or_start_auth(TO_OR_CONN(conn));
case CONN_TYPE_OR:
control_event_or_conn_status(TO_OR_CONN(conn), OR_CONN_EVENT_NEW, 0);
connection_or_event_status(TO_OR_CONN(conn), OR_CONN_EVENT_NEW, 0);
rv = connection_tls_start_handshake(TO_OR_CONN(conn), 1);
if (rv < 0) {
connection_or_close_for_error(TO_OR_CONN(conn), 0);
Expand Down
3 changes: 0 additions & 3 deletions src/core/or/channeltls.c
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,6 @@ channel_tls_listener_describe_transport_method(channel_listener_t *chan_l)
void
channel_tls_handle_state_change_on_orconn(channel_tls_t *chan,
or_connection_t *conn,
uint8_t old_state,
uint8_t state)
{
channel_t *base_chan;
Expand All @@ -959,8 +958,6 @@ channel_tls_handle_state_change_on_orconn(channel_tls_t *chan,
tor_assert(conn);
tor_assert(conn->chan == chan);
tor_assert(chan->conn == conn);
/* Shut the compiler up without triggering -Wtautological-compare */
(void)old_state;

base_chan = TLS_CHAN_TO_BASE(chan);

Expand Down
1 change: 0 additions & 1 deletion src/core/or/channeltls.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ channel_tls_t * channel_tls_from_base(channel_t *chan);
void channel_tls_handle_cell(cell_t *cell, or_connection_t *conn);
void channel_tls_handle_state_change_on_orconn(channel_tls_t *chan,
or_connection_t *conn,
uint8_t old_state,
uint8_t state);
void channel_tls_handle_var_cell(var_cell_t *var_cell,
or_connection_t *conn);
Expand Down
32 changes: 28 additions & 4 deletions src/core/or/circuitbuild.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
**/

#define CIRCUITBUILD_PRIVATE
#define OCIRC_EVENT_PRIVATE

#include "core/or/or.h"
#include "app/config/config.h"
Expand All @@ -46,6 +47,7 @@
#include "core/or/connection_edge.h"
#include "core/or/connection_or.h"
#include "core/or/onion.h"
#include "core/or/ocirc_event.h"
#include "core/or/policies.h"
#include "core/or/relay.h"
#include "feature/client/bridges.h"
Expand Down Expand Up @@ -492,7 +494,7 @@ circuit_establish_circuit(uint8_t purpose, extend_info_t *exit_ei, int flags)
return NULL;
}

control_event_circuit_status(circ, CIRC_EVENT_LAUNCHED, 0);
circuit_event_status(circ, CIRC_EVENT_LAUNCHED, 0);

if ((err_reason = circuit_handle_first_hop(circ)) < 0) {
circuit_mark_for_close(TO_CIRCUIT(circ), -err_reason);
Expand All @@ -508,6 +510,28 @@ origin_circuit_get_guard_state(origin_circuit_t *circ)
return circ->guard_state;
}

/**
* Helper function to publish a channel association message
*
* circuit_handle_first_hop() calls this to notify subscribers about a
* channel launch event, which associates a circuit with a channel.
* This doesn't always correspond to an assignment of the circuit's
* n_chan field, because that seems to be only for fully-open
* channels.
**/
static void
circuit_chan_publish(const origin_circuit_t *circ, const channel_t *chan)
{
ocirc_event_msg_t msg;

msg.type = OCIRC_MSGTYPE_CHAN;
msg.u.chan.gid = circ->global_identifier;
msg.u.chan.chan = chan->global_identifier;
msg.u.chan.onehop = circ->build_state->onehop_tunnel;

ocirc_event_publish(&msg);
}

/** Start establishing the first hop of our circuit. Figure out what
* OR we should connect to, and if necessary start the connection to
* it. If we're already connected, then send the 'create' cell.
Expand Down Expand Up @@ -559,8 +583,6 @@ circuit_handle_first_hop(origin_circuit_t *circ)
circ->base_.n_hop = extend_info_dup(firsthop->extend_info);

if (should_launch) {
if (circ->build_state->onehop_tunnel)
control_event_bootstrap(BOOTSTRAP_STATUS_CONN_DIR, 0);
n_chan = channel_connect_for_circuit(
&firsthop->extend_info->addr,
firsthop->extend_info->port,
Expand All @@ -570,6 +592,7 @@ circuit_handle_first_hop(origin_circuit_t *circ)
log_info(LD_CIRC,"connect to firsthop failed. Closing.");
return -END_CIRC_REASON_CONNECTFAILED;
}
circuit_chan_publish(circ, n_chan);
}

log_debug(LD_CIRC,"connecting in progress (or finished). Good.");
Expand All @@ -581,6 +604,7 @@ circuit_handle_first_hop(origin_circuit_t *circ)
} else { /* it's already open. use it. */
tor_assert(!circ->base_.n_hop);
circ->base_.n_chan = n_chan;
circuit_chan_publish(circ, n_chan);
log_debug(LD_CIRC,"Conn open. Delivering first onion skin.");
if ((err_reason = circuit_send_next_onion_skin(circ)) < 0) {
log_info(LD_CIRC,"circuit_send_next_onion_skin failed.");
Expand Down Expand Up @@ -1416,7 +1440,7 @@ circuit_finish_handshake(origin_circuit_t *circ,
hop->state = CPATH_STATE_OPEN;
log_info(LD_CIRC,"Finished building circuit hop:");
circuit_log_path(LOG_INFO,LD_CIRC,circ);
control_event_circuit_status(circ, CIRC_EVENT_EXTENDED, 0);
circuit_event_status(circ, CIRC_EVENT_EXTENDED, 0);

return 0;
}
Expand Down
57 changes: 56 additions & 1 deletion src/core/or/circuitlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
* logic, which was originally circuit-focused.
**/
#define CIRCUITLIST_PRIVATE
#define OCIRC_EVENT_PRIVATE
#include "lib/cc/torint.h" /* TOR_PRIuSZ */

#include "core/or/or.h"
Expand Down Expand Up @@ -96,6 +97,9 @@
#include "lib/compress/compress_zstd.h"
#include "lib/buf/buffers.h"

#define OCIRC_EVENT_PRIVATE
#include "core/or/ocirc_event.h"

#include "ht.h"

#include "core/or/cpath_build_state_st.h"
Expand Down Expand Up @@ -481,6 +485,56 @@ circuit_set_n_circid_chan(circuit_t *circ, circid_t id,
}
}

/**
* Helper function to publish a message about events on an origin circuit
*
* Publishes a message to subscribers of origin circuit events, and
* sends the control event.
**/
int
circuit_event_status(origin_circuit_t *circ, circuit_status_event_t tp,
int reason_code)
{
ocirc_event_msg_t msg;

tor_assert(circ);

msg.type = OCIRC_MSGTYPE_CEVENT;
msg.u.cevent.gid = circ->global_identifier;
msg.u.cevent.evtype = tp;
msg.u.cevent.reason = reason_code;
msg.u.cevent.onehop = circ->build_state->onehop_tunnel;

ocirc_event_publish(&msg);
return control_event_circuit_status(circ, tp, reason_code);
}

/**
* Helper function to publish a state change message
*
* circuit_set_state() calls this to notify subscribers about a change
* of the state of an origin circuit.
**/
static void
circuit_state_publish(const circuit_t *circ)
{
ocirc_event_msg_t msg;
const origin_circuit_t *ocirc;

if (!CIRCUIT_IS_ORIGIN(circ))
return;
ocirc = CONST_TO_ORIGIN_CIRCUIT(circ);
/* Only inbound OR circuits can be in this state, not origin circuits. */
tor_assert(circ->state != CIRCUIT_STATE_ONIONSKIN_PENDING);

msg.type = OCIRC_MSGTYPE_STATE;
msg.u.state.gid = ocirc->global_identifier;
msg.u.state.state = circ->state;
msg.u.state.onehop = ocirc->build_state->onehop_tunnel;

ocirc_event_publish(&msg);
}

/** Change the state of <b>circ</b> to <b>state</b>, adding it to or removing
* it from lists as appropriate. */
void
Expand Down Expand Up @@ -510,6 +564,7 @@ circuit_set_state(circuit_t *circ, uint8_t state)
if (state == CIRCUIT_STATE_GUARD_WAIT || state == CIRCUIT_STATE_OPEN)
tor_assert(!circ->n_chan_create_cell);
circ->state = state;
circuit_state_publish(circ);
}

/** Append to <b>out</b> all circuits in state CHAN_WAIT waiting for
Expand Down Expand Up @@ -2270,7 +2325,7 @@ circuit_about_to_free(circuit_t *circ)
smartlist_remove(circuits_pending_other_guards, circ);
}
if (CIRCUIT_IS_ORIGIN(circ)) {
control_event_circuit_status(TO_ORIGIN_CIRCUIT(circ),
circuit_event_status(TO_ORIGIN_CIRCUIT(circ),
(circ->state == CIRCUIT_STATE_OPEN ||
circ->state == CIRCUIT_STATE_GUARD_WAIT) ?
CIRC_EVENT_CLOSED:CIRC_EVENT_FAILED,
Expand Down
3 changes: 3 additions & 0 deletions src/core/or/circuitlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include "lib/testsupport/testsupport.h"
#include "feature/hs/hs_ident.h"
#include "core/or/ocirc_event.h"

/** Circuit state: I'm the origin, still haven't done all my handshakes. */
#define CIRCUIT_STATE_BUILDING 0
Expand Down Expand Up @@ -184,6 +185,8 @@ void channel_mark_circid_unusable(channel_t *chan, circid_t id);
void channel_mark_circid_usable(channel_t *chan, circid_t id);
time_t circuit_id_when_marked_unusable_on_channel(circid_t circ_id,
channel_t *chan);
int circuit_event_status(origin_circuit_t *circ, circuit_status_event_t tp,
int reason_code);
void circuit_set_state(circuit_t *circ, uint8_t state);
void circuit_close_all_marked(void);
int32_t circuit_initial_package_window(void);
Expand Down
6 changes: 3 additions & 3 deletions src/core/or/circuitstats.c
Original file line number Diff line number Diff line change
Expand Up @@ -639,9 +639,9 @@ circuit_build_times_rewind_history(circuit_build_times_t *cbt, int n)
void
circuit_build_times_mark_circ_as_measurement_only(origin_circuit_t *circ)
{
control_event_circuit_status(circ,
CIRC_EVENT_FAILED,
END_CIRC_REASON_TIMEOUT);
circuit_event_status(circ,
CIRC_EVENT_FAILED,
END_CIRC_REASON_TIMEOUT);
circuit_change_purpose(TO_CIRCUIT(circ),
CIRCUIT_PURPOSE_C_MEASURE_TIMEOUT);
/* Record this event to check for too many timeouts
Expand Down
2 changes: 1 addition & 1 deletion src/core/or/circuituse.c
Original file line number Diff line number Diff line change
Expand Up @@ -1664,7 +1664,7 @@ circuit_testing_failed(origin_circuit_t *circ, int at_last_hop)
void
circuit_has_opened(origin_circuit_t *circ)
{
control_event_circuit_status(circ, CIRC_EVENT_BUILT, 0);
circuit_event_status(circ, CIRC_EVENT_BUILT, 0);

/* Remember that this circuit has finished building. Now if we start
* it building again later (e.g. by extending it), we will know not
Expand Down
Loading