Merge branch 'maint-0.4.8'
[tor.git] / src / core / or / conflux.h
blobe01b3233178431df734f50f99285299283d44c1e
1 /* Copyright (c) 2019-2021, The Tor Project, Inc. */
2 /* See LICENSE for licensing information */
4 /**
5 * \file conflux.h
6 * \brief Public APIs for conflux multipath support
7 **/
9 #ifndef TOR_CONFLUX_H
10 #define TOR_CONFLUX_H
12 #include "core/or/circuit_st.h"
13 #include "core/or/conflux_st.h"
15 typedef struct conflux_t conflux_t;
16 typedef struct conflux_leg_t conflux_leg_t;
18 /** Helpers to iterate over legs with better semantic. */
19 #define CONFLUX_FOR_EACH_LEG_BEGIN(cfx, var) \
20 SMARTLIST_FOREACH_BEGIN(cfx->legs, conflux_leg_t *, var)
21 #define CONFLUX_FOR_EACH_LEG_END(var) \
22 SMARTLIST_FOREACH_END(var)
24 /** Helper: Return the number of legs a conflux object has. */
25 #define CONFLUX_NUM_LEGS(cfx) (smartlist_len(cfx->legs))
27 /** A cell for the out-of-order queue.
28 * XXX: Consider trying to use packed_cell_t instead here? */
29 typedef struct {
30 /**
31 * Absolute sequence number of this cell, computed from the
32 * relative sequence number of the conflux cell. */
33 uint64_t seq;
35 /**
36 * Heap index of this cell, for use in in the conflux_t ooo_q heap.
38 int heap_idx;
40 /** The cell here is always guaranteed to have removed its
41 * extra conflux sequence number, for ease of processing */
42 cell_t cell;
43 } conflux_cell_t;
45 size_t conflux_handle_oom(size_t bytes_to_remove);
46 uint64_t conflux_get_total_bytes_allocation(void);
47 uint64_t conflux_get_circ_bytes_allocation(const circuit_t *circ);
49 void conflux_update_rtt(conflux_t *cfx, circuit_t *circ, uint64_t rtt_usec);
51 circuit_t *conflux_decide_circ_for_send(conflux_t *cfx,
52 circuit_t *orig_circ,
53 uint8_t relay_command);
54 circuit_t *conflux_decide_next_circ(conflux_t *cfx);
56 int conflux_process_switch_command(circuit_t *in_circ,
57 crypt_path_t *layer_hint, cell_t *cell,
58 relay_header_t *rh);
59 bool conflux_should_multiplex(int relay_command);
60 bool conflux_process_cell(conflux_t *cfx, circuit_t *in_circ,
61 crypt_path_t *layer_hint,
62 cell_t *cell);
63 conflux_cell_t *conflux_dequeue_cell(conflux_t *cfx);
64 void conflux_note_cell_sent(conflux_t *cfx, circuit_t *circ,
65 uint8_t relay_command);
67 /* Private section starts. */
68 #ifdef TOR_CONFLUX_PRIVATE
70 const struct congestion_control_t *circuit_ccontrol(const circuit_t *);
71 conflux_leg_t *conflux_get_leg(conflux_t *cfx, const circuit_t *circ);
72 uint64_t conflux_get_max_seq_recv(const conflux_t *cfx);
73 uint64_t conflux_get_max_seq_sent(const conflux_t *cfx);
76 * Unit tests declaractions.
78 #ifdef TOR_UNIT_TESTS
80 #endif /* defined(TOR_UNIT_TESTS) */
82 #endif /* defined(TOR_CONFLUX_PRIVATE) */
84 #endif /* !defined(TOR_CONFLUX_H) */