This is an automated email from the git hooks/post-receive script.
ahf pushed a commit to branch main in repository tor.
commit a1794ef687593793b36dfe7aecb06b35321f332b Author: Mike Perry mikeperry-git@torproject.org AuthorDate: Wed Dec 14 21:03:32 2022 +0000
Prop#329 Headers: Header files for conflux --- src/core/or/conflux.h | 84 +++++++++++++++++++++++++ src/core/or/conflux_st.h | 157 +++++++++++++++++++++++++++++++++++++++++++++++ src/core/or/include.am | 2 + 3 files changed, 243 insertions(+)
diff --git a/src/core/or/conflux.h b/src/core/or/conflux.h new file mode 100644 index 0000000000..e01b323317 --- /dev/null +++ b/src/core/or/conflux.h @@ -0,0 +1,84 @@ +/* Copyright (c) 2019-2021, The Tor Project, Inc. */ +/* See LICENSE for licensing information */ + +/** + * \file conflux.h + * \brief Public APIs for conflux multipath support + **/ + +#ifndef TOR_CONFLUX_H +#define TOR_CONFLUX_H + +#include "core/or/circuit_st.h" +#include "core/or/conflux_st.h" + +typedef struct conflux_t conflux_t; +typedef struct conflux_leg_t conflux_leg_t; + +/** Helpers to iterate over legs with better semantic. */ +#define CONFLUX_FOR_EACH_LEG_BEGIN(cfx, var) \ + SMARTLIST_FOREACH_BEGIN(cfx->legs, conflux_leg_t *, var) +#define CONFLUX_FOR_EACH_LEG_END(var) \ + SMARTLIST_FOREACH_END(var) + +/** Helper: Return the number of legs a conflux object has. */ +#define CONFLUX_NUM_LEGS(cfx) (smartlist_len(cfx->legs)) + +/** A cell for the out-of-order queue. + * XXX: Consider trying to use packed_cell_t instead here? */ +typedef struct { + /** + * Absolute sequence number of this cell, computed from the + * relative sequence number of the conflux cell. */ + uint64_t seq; + + /** + * Heap index of this cell, for use in in the conflux_t ooo_q heap. + */ + int heap_idx; + + /** The cell here is always guaranteed to have removed its + * extra conflux sequence number, for ease of processing */ + cell_t cell; +} conflux_cell_t; + +size_t conflux_handle_oom(size_t bytes_to_remove); +uint64_t conflux_get_total_bytes_allocation(void); +uint64_t conflux_get_circ_bytes_allocation(const circuit_t *circ); + +void conflux_update_rtt(conflux_t *cfx, circuit_t *circ, uint64_t rtt_usec); + +circuit_t *conflux_decide_circ_for_send(conflux_t *cfx, + circuit_t *orig_circ, + uint8_t relay_command); +circuit_t *conflux_decide_next_circ(conflux_t *cfx); + +int conflux_process_switch_command(circuit_t *in_circ, + crypt_path_t *layer_hint, cell_t *cell, + relay_header_t *rh); +bool conflux_should_multiplex(int relay_command); +bool conflux_process_cell(conflux_t *cfx, circuit_t *in_circ, + crypt_path_t *layer_hint, + cell_t *cell); +conflux_cell_t *conflux_dequeue_cell(conflux_t *cfx); +void conflux_note_cell_sent(conflux_t *cfx, circuit_t *circ, + uint8_t relay_command); + +/* Private section starts. */ +#ifdef TOR_CONFLUX_PRIVATE + +const struct congestion_control_t *circuit_ccontrol(const circuit_t *); +conflux_leg_t *conflux_get_leg(conflux_t *cfx, const circuit_t *circ); +uint64_t conflux_get_max_seq_recv(const conflux_t *cfx); +uint64_t conflux_get_max_seq_sent(const conflux_t *cfx); + +/* + * Unit tests declaractions. + */ +#ifdef TOR_UNIT_TESTS + +#endif /* defined(TOR_UNIT_TESTS) */ + +#endif /* defined(TOR_CONFLUX_PRIVATE) */ + +#endif /* !defined(TOR_CONFLUX_H) */ diff --git a/src/core/or/conflux_st.h b/src/core/or/conflux_st.h new file mode 100644 index 0000000000..dae4845cb6 --- /dev/null +++ b/src/core/or/conflux_st.h @@ -0,0 +1,157 @@ +/* Copyright (c) 2019-2021, The Tor Project, Inc. */ +/* See LICENSE for licensing information */ + +/** + * \file conflux_st.h + * \brief Structure definitions for conflux multipath + **/ + +#ifndef CONFLUX_ST_H +#define CONFLUX_ST_H + +#include "core/or/circuit_st.h" +#include "core/or/cell_st.h" +#include "lib/defs/digest_sizes.h" + +/** +* Specifies which conflux alg is in use. +*/ +typedef enum { + CONFLUX_ALG_MINRTT = 0, + CONFLUX_ALG_LOWRTT = 1, + CONFLUX_ALG_CWNDRTT = 2, + CONFLUX_ALG_MAXRATE = 3, + CONFLUX_ALG_HIGHRATE = 4 +} conflux_alg_t; + +/** + * Maximum number of linked circuits. + * + * We want to experiment with 3 guards, so we need at least 3 here. + * + * However, we need 1 more than this, to support using a test circuit to probe + * for a faster path, for applications that *require* a specific latency target + * (like VoIP). + * + * We may also want to raise this for traffic analysis defense evaluation. + */ +#define CONFLUX_MAX_CIRCS 4 + +/** XXX: Cached consensus params+scheduling alg */ +struct conflux_params_t { + conflux_alg_t alg; +}; + +struct conflux_leg_t { + /** + * For computing ooo_q insertion sequence numbers: Highest absolute + * sequence number recieved on each leg, before delivery. + * + * As a reciever, this allows us to compute the absolute sequence number + * of a cell for delivery or insertion into the ooo_q. When a SWITCH cell + * is recieved on a leg, the absolute sequence number of that cell is + * the relative sequence number in that cell, plus the absolute sequence + * number of that leg from this array. The leg's sequence number + * is then updated to this value immediately. + * + * In this way, we are able to assign absolute sequence numbers to cells + * immediately, regardless of how many legs or leg switches have ocurred, + * and regardless of the delivery status of each cell versus if it must be + * queued. + */ + uint64_t last_seq_recv; + + /** + * For relative sequencing: Highest absolute sequence number sent on each + * circuit. The overall absolute current sent sequence number is the highest + * of these values. + * + * As a sender, this allows us to compute a relative sequence number when + * switching legs. When switching legs, the sender looks up its current + * absolute sequence number as the maximum of all legs. The sender then + * compares that to the current sequence number on the leg it is about to + * send on, and then computes the relative sequence number as the difference + * between the overall absolute sequence number and the sequence number + * from the sending leg. + * + * In this way, we can use much smaller relative sequence numbers on the + * wire, as opposed to larger absolute values, at the expense of this + * bookkeeping overhead on each end. + */ + uint64_t last_seq_sent; + + /** + * Current round-trip of the circuit, in usec. + * + * XXX: In theory, we could use the congestion control RTTs directly off the + * circs, but congestion control code has assumptions about the RTT being 0 + * at the start of the circuit, which will *not* be the case here, because we + * get an RTT off the link circuit. */ + uint64_t circ_rtts_usec; + + /** Exit side only: When was the LINKED cell sent? Used for RTT measurement + * that sets circ_rtts_usec when the LINKED_ACK is received. */ + uint64_t linked_sent_usec; + + /** Circuit of this leg. */ + circuit_t *circ; +}; + +/** Fields for conflux multipath support */ +struct conflux_t { + /** Cached parameters for this circuit */ + struct conflux_params_t params; + + /** + * List of all linked conflux_leg_t for this set. Once a leg is in that list, + * it can be used to transmit data. */ + smartlist_t *legs; + + /** + * Out-of-order priority queue of conflux_cell_t *, heapified + * on conflux_cell_t.seq number (lowest at top of heap). + * + * XXX: We are most likely to insert cells at either the head or the tail. + * Verify that is fast-path wrt smartlist priority queues, and not a memmove + * nightmare. If so, we may need a real linked list, or a packed_cell_t list. + */ + smartlist_t *ooo_q; + + /** + * Absolute sequence number of cells delivered to streams since start. + * (ie: this is updated *after* dequeue from the ooo_q priority queue). */ + uint64_t last_seq_delivered; + + /** + * The estimated remaining number of cells we can send on this circuit + * before we are allowed to switch legs. */ + uint64_t cells_until_switch; + + /** Current circuit leg. Only use this with conflux_get_circ_for_leg() for + * bounds checking. */ + struct conflux_leg_t *curr_leg; + + /** Previous circuit leg. Only use this with conflux_get_circ_for_leg() for + * bounds checking. */ + struct conflux_leg_t *prev_leg; + + /** The nonce that joins these */ + uint8_t nonce[DIGEST256_LEN]; + + /** Indicate if this conflux set is in full teardown. We mark it at the first + * close in case of a total teardown so we avoid recursive calls of circuit + * mark for close. */ + bool in_full_teardown; + + /** Number of leg launch that we've done for this set. We keep this value + * because there is a maximum allowed in order to avoid side channel(s). */ + unsigned int num_leg_launch; + + /** + * PolicyHint: Predicted ports/protocol shorthand.. + * + * XXX: This might be redundant to the circuit's exitpolicy. + */ +}; + +#endif /* !defined(CONFLUX_ST_H) */ diff --git a/src/core/or/include.am b/src/core/or/include.am index b08f8509cc..9a4841e937 100644 --- a/src/core/or/include.am +++ b/src/core/or/include.am @@ -108,6 +108,8 @@ noinst_HEADERS += \ src/core/or/congestion_control_vegas.h \ src/core/or/congestion_control_nola.h \ src/core/or/congestion_control_westwood.h \ + src/core/or/conflux.h \ + src/core/or/conflux_st.h \ src/core/or/server_port_cfg_st.h \ src/core/or/socks_request_st.h \ src/core/or/status.h \