conflux.h (2934B)
1 /* Copyright (c) 2019-2021, The Tor Project, Inc. */ 2 /* See LICENSE for licensing information */ 3 4 /** 5 * \file conflux.h 6 * \brief Public APIs for conflux multipath support 7 **/ 8 9 #ifndef TOR_CONFLUX_H 10 #define TOR_CONFLUX_H 11 12 #include "core/or/circuit_st.h" 13 #include "core/or/conflux_st.h" 14 #include "core/or/relay_msg_st.h" 15 16 typedef struct conflux_t conflux_t; 17 typedef struct conflux_leg_t conflux_leg_t; 18 19 /** Helpers to iterate over legs with better semantic. */ 20 #define CONFLUX_FOR_EACH_LEG_BEGIN(cfx, var) \ 21 SMARTLIST_FOREACH_BEGIN(cfx->legs, conflux_leg_t *, var) 22 #define CONFLUX_FOR_EACH_LEG_END(var) \ 23 SMARTLIST_FOREACH_END(var) 24 25 /** Helper: Return the number of legs a conflux object has. */ 26 #define CONFLUX_NUM_LEGS(cfx) (smartlist_len(cfx->legs)) 27 28 /** A relay message for the out-of-order queue. */ 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; 34 35 /** 36 * Heap index of this cell, for use in in the conflux_t ooo_q heap. 37 */ 38 int heap_idx; 39 40 /** The relay message here is always guaranteed to have removed its 41 * extra conflux sequence number, for ease of processing */ 42 relay_msg_t *msg; 43 } conflux_msg_t; 44 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); 48 49 void conflux_update_rtt(conflux_t *cfx, circuit_t *circ, uint64_t rtt_usec); 50 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); 55 56 int conflux_process_switch_command(circuit_t *in_circ, 57 crypt_path_t *layer_hint, 58 const relay_msg_t *msg); 59 bool conflux_should_multiplex(int relay_command); 60 bool conflux_process_relay_msg(conflux_t *cfx, circuit_t *in_circ, 61 crypt_path_t *layer_hint, 62 const relay_msg_t *msg); 63 conflux_msg_t *conflux_dequeue_relay_msg(circuit_t *circ); 64 void conflux_note_cell_sent(conflux_t *cfx, circuit_t *circ, 65 uint8_t relay_command); 66 void conflux_relay_msg_free_(conflux_msg_t *msg); 67 #define conflux_relay_msg_free(msg) \ 68 FREE_AND_NULL(conflux_msg_t, conflux_relay_msg_free_, (msg)) 69 70 /* Private section starts. */ 71 #ifdef TOR_CONFLUX_PRIVATE 72 73 const struct congestion_control_t *circuit_ccontrol(const circuit_t *); 74 conflux_leg_t *conflux_get_leg(conflux_t *cfx, const circuit_t *circ); 75 uint64_t conflux_get_max_seq_recv(const conflux_t *cfx); 76 uint64_t conflux_get_max_seq_sent(const conflux_t *cfx); 77 78 /* 79 * Unit tests declaractions. 80 */ 81 #ifdef TOR_UNIT_TESTS 82 83 #endif /* defined(TOR_UNIT_TESTS) */ 84 85 #endif /* defined(TOR_CONFLUX_PRIVATE) */ 86 87 #endif /* !defined(TOR_CONFLUX_H) */