Tor 0.4.9.1-alpha-dev
|
Conflux circuit pool management. More...
#include "core/or/or.h"
#include "app/config/config.h"
#include "core/or/circuitbuild.h"
#include "core/or/circuitlist.h"
#include "core/or/circuitstats.h"
#include "core/or/circuituse.h"
#include "core/or/congestion_control_st.h"
#include "core/or/conflux.h"
#include "core/or/conflux_cell.h"
#include "trunnel/conflux.h"
#include "core/or/conflux_params.h"
#include "core/or/conflux_pool.h"
#include "core/or/conflux_util.h"
#include "core/or/relay.h"
#include "core/or/connection_edge.h"
#include "core/or/edge_connection_st.h"
#include "core/or/crypt_path_st.h"
#include "core/or/or_circuit_st.h"
#include "core/or/origin_circuit_st.h"
#include "core/or/extend_info_st.h"
#include "core/or/conflux_st.h"
#include "feature/nodelist/nodelist.h"
#include "feature/client/bridges.h"
#include "lib/crypt_ops/crypto_rand.h"
#include "lib/crypt_ops/crypto_util.h"
Go to the source code of this file.
Data Structures | |
struct | leg_t |
struct | unlinked_circuits_t |
Macros | |
#define | TOR_CONFLUX_PRIVATE |
#define | CONFLUX_CELL_PRIVATE |
#define | conflux_free(cfx) FREE_AND_NULL(conflux_t, conflux_free_, cfx) |
Enumerations | |
enum | link_circ_err_t { ERR_LINK_CIRC_OK = 0 , ERR_LINK_CIRC_BAD_RTT = 1 , ERR_LINK_CIRC_MISSING_LEG = 2 , ERR_LINK_CIRC_MISSING_SET = 3 , ERR_LINK_CIRC_INVALID_LEG = 4 } |
Functions | |
static const char * | fmt_nonce (const uint8_t *nonce) |
static uint8_t | conflux_choose_algorithm (uint8_t desired_ux) |
static conflux_t * | conflux_new (void) |
static void | conflux_free_ (conflux_t *cfx) |
static void | free_conflux_void_ (void *ptr) |
static leg_t * | leg_new (circuit_t *circ, conflux_cell_link_t *link) |
static void | leg_free (leg_t *leg) |
static unlinked_circuits_t * | unlinked_new (const uint8_t *nonce, bool is_client) |
static void | unlinked_free (unlinked_circuits_t *unlinked) |
static void | unlinked_pool_add (unlinked_circuits_t *unlinked, bool is_client) |
static void | unlinked_pool_del (unlinked_circuits_t *unlinked, bool is_client) |
static unlinked_circuits_t * | unlinked_pool_get (const uint8_t *nonce, bool is_client) |
static void | unlinked_pool_del_and_free (unlinked_circuits_t *unlinked, bool is_client) |
static void | linked_pool_add (conflux_t *cfx, bool is_client) |
static void | linked_pool_del (const uint8_t *nonce, bool is_client) |
static conflux_t * | linked_pool_get (const uint8_t *nonce, bool is_client) |
static void | unlinked_leg_add (unlinked_circuits_t *unlinked, leg_t *leg) |
static leg_t * | leg_find (const unlinked_circuits_t *unlinked, const circuit_t *circ) |
static leg_t * | unlinked_leg_find (const circuit_t *circ, bool is_client) |
static void | unlinked_leg_del_and_free (unlinked_circuits_t *unlinked, const circuit_t *circ) |
static void | validate_circ_has_no_streams (circuit_t *circ) |
static bool | validate_unlinked_legs (unlinked_circuits_t *unlinked) |
static void | cfx_add_leg (conflux_t *cfx, leg_t *leg) |
static bool | cfx_del_leg (conflux_t *cfx, const circuit_t *circ) |
static void | unlinked_close_all_legs (unlinked_circuits_t *unlinked) |
static void | unlinked_close_or_free (unlinked_circuits_t *unlinked) |
static void | conflux_mark_all_for_close (const uint8_t *nonce, bool is_client, int reason) |
static void | free_unlinked_void_ (void *ptr) |
static link_circ_err_t | try_finalize_set (unlinked_circuits_t *unlinked) |
static uint64_t | record_rtt_client (const circuit_t *circ) |
static uint64_t | record_rtt_exit (const circuit_t *circ) |
static bool | record_rtt (const circuit_t *circ, bool is_client) |
static link_circ_err_t | link_circuit (circuit_t *circ) |
STATIC bool | launch_new_set (int num_legs) |
static unlinked_circuits_t * | unlinked_get_or_create (const uint8_t *nonce, bool is_client) |
static extend_info_t * | get_exit_for_nonce (const uint8_t *nonce) |
static uint8_t | get_client_ux (void) |
static bool | launch_leg_is_allowed (const conflux_t *cfx) |
bool | conflux_launch_leg (const uint8_t *nonce) |
void | conflux_add_guards_to_exclude_list (const origin_circuit_t *orig_circ, smartlist_t *excluded) |
void | conflux_add_middles_to_exclude_list (const origin_circuit_t *orig_circ, smartlist_t *excluded) |
static int | count_client_usable_sets (void) |
void | conflux_predict_new (time_t now) |
origin_circuit_t * | conflux_get_circ_for_conn (const entry_connection_t *conn, time_t now) |
static void | unlinked_circuit_closed (circuit_t *circ) |
static void | linked_update_stream_backpointers (circuit_t *circ) |
static void | linked_nullify_streams (circuit_t *circ) |
static void | linked_circuit_closed (circuit_t *circ) |
static void | linked_circuit_free (circuit_t *circ, bool is_client) |
static void | unlinked_circuit_free (circuit_t *circ, bool is_client) |
void | conflux_circuit_has_closed (circuit_t *circ) |
void | conflux_circuit_has_opened (origin_circuit_t *orig_circ) |
void | conflux_process_link (circuit_t *circ, const cell_t *cell, const uint16_t cell_len) |
void | conflux_process_linked (circuit_t *circ, crypt_path_t *layer_hint, const cell_t *cell, const uint16_t cell_len) |
void | conflux_process_linked_ack (circuit_t *circ) |
void | conflux_circuit_about_to_free (circuit_t *circ) |
void | conflux_pool_init (void) |
void | conflux_log_set (int loglevel, const conflux_t *cfx, bool is_client) |
void | conflux_notify_shutdown (void) |
void | conflux_pool_free_all (void) |
Variables | |
static bool | shutting_down = false |
static digest256map_t * | client_linked_pool |
static digest256map_t * | client_unlinked_pool |
static digest256map_t * | server_linked_pool |
static digest256map_t * | server_unlinked_pool |
STATIC uint8_t | DEFAULT_CLIENT_UX = CONFLUX_UX_HIGH_THROUGHPUT |
STATIC uint8_t | DEFAULT_EXIT_UX = CONFLUX_UX_MIN_LATENCY |
Conflux circuit pool management.
Definition in file conflux_pool.c.
#define CONFLUX_CELL_PRIVATE |
Definition at line 10 of file conflux_pool.c.
#define conflux_free | ( | cfx | ) | FREE_AND_NULL(conflux_t, conflux_free_, cfx) |
Wrapper for the free function, set the cfx pointer to NULL after free
Definition at line 207 of file conflux_pool.c.
#define TOR_CONFLUX_PRIVATE |
Definition at line 9 of file conflux_pool.c.
enum link_circ_err_t |
Error code used when linking circuits. Based on those, we decide to relaunch or not.
Definition at line 107 of file conflux_pool.c.
Add up a new leg to the given conflux object.
are, so this option seems better right now)
Definition at line 491 of file conflux_pool.c.
Clean up a circuit from its conflux_t object.
Return true if closing this circuit should tear down the entire set, false otherwise.
Definition at line 556 of file conflux_pool.c.
void conflux_add_guards_to_exclude_list | ( | const origin_circuit_t * | orig_circ, |
smartlist_t * | excluded | ||
) |
Add the identity digest of the guard nodes of all legs of the conflux circuit.
This function checks both pending and linked conflux circuits.
Definition at line 1205 of file conflux_pool.c.
void conflux_add_middles_to_exclude_list | ( | const origin_circuit_t * | orig_circ, |
smartlist_t * | excluded | ||
) |
Add the identity digest of the middle nodes of all legs of the conflux circuit.
This function checks both pending and linked conflux circuits.
XXX: The add guard and middle could be merged since it is the exact same code except for the cpath position and the identity digest vs node_t in the list. We could use an extra param indicating guard or middle.
Definition at line 1273 of file conflux_pool.c.
Referenced by build_middle_exclude_list().
|
static |
Return the conflux algorithm for a desired UX value.
Definition at line 150 of file conflux_pool.c.
void conflux_circuit_about_to_free | ( | circuit_t * | circ | ) |
Called when a circuit is freed.
It is possible a conflux circuit gets freed without being closed (for instance SIGTERM) and so this callback is needed in order to finalize the cleanup.
Definition at line 2071 of file conflux_pool.c.
Referenced by circuit_about_to_free(), and circuit_about_to_free_atexit().
void conflux_circuit_has_closed | ( | circuit_t * | circ | ) |
Circuit has been marked for close.
Definition at line 1702 of file conflux_pool.c.
void conflux_circuit_has_opened | ( | origin_circuit_t * | orig_circ | ) |
Circuit with conflux purpose just opened.
Definition at line 1715 of file conflux_pool.c.
|
static |
Definition at line 185 of file conflux_pool.c.
origin_circuit_t * conflux_get_circ_for_conn | ( | const entry_connection_t * | conn, |
time_t | now | ||
) |
Return the first circuit from the linked pool that will work with the conn. If no such circuit exists, return NULL.
Definition at line 1403 of file conflux_pool.c.
Referenced by circuit_get_best().
bool conflux_launch_leg | ( | const uint8_t * | nonce | ) |
Launch a new conflux leg for the given nonce.
Return true on success else false which teardowns the entire unlinked set if any.
Definition at line 1129 of file conflux_pool.c.
Referenced by launch_new_set().
void conflux_log_set | ( | int | loglevel, |
const conflux_t * | cfx, | ||
bool | is_client | ||
) |
Return a description of all linked and unlinked circuits associated with a conflux set.
For use in rare bug cases that are hard to diagnose.
Definition at line 2114 of file conflux_pool.c.
|
static |
Upon an error condition or a close of an in-use circuit, we must close all linked and unlinked circuits associated with a set. When the last leg of each set is closed, the set is removed from the pool.
Definition at line 679 of file conflux_pool.c.
|
static |
Return a newly allocated conflux_t object.
Definition at line 174 of file conflux_pool.c.
void conflux_notify_shutdown | ( | void | ) |
Conflux needs a notification when tor_shutdown() begins, so that when circuits are freed, new legs are not launched.
This needs a separate notification from conflux_pool_free_all(), because circuits must be freed before that function.
Definition at line 2172 of file conflux_pool.c.
void conflux_pool_free_all | ( | void | ) |
Free and clean up the conflux pool subsystem. This is called by the subsys manager AFTER all circuits have been freed which implies that all objects in the pools aren't referenced anymore.
Definition at line 2192 of file conflux_pool.c.
void conflux_pool_init | ( | void | ) |
Initialize the conflux pool subsystem. This is called by the subsys manager.
Definition at line 2091 of file conflux_pool.c.
void conflux_predict_new | ( | time_t | now | ) |
Determine if we need to launch new conflux circuits for our preemptive pool.
This is called once a second from the mainloop from circuit_predict_and_launch_new().
Definition at line 1358 of file conflux_pool.c.
Referenced by circuit_predict_and_launch_new().
Process a CONFLUX_LINK cell which arrived on the given circuit.
Definition at line 1766 of file conflux_pool.c.
void conflux_process_linked | ( | circuit_t * | circ, |
crypt_path_t * | layer_hint, | ||
const cell_t * | cell, | ||
const uint16_t | cell_len | ||
) |
Process a CONFLUX_LINKED cell which arrived on the given circuit.
Definition at line 1877 of file conflux_pool.c.
void conflux_process_linked_ack | ( | circuit_t * | circ | ) |
Process a CONFLUX_LINKED_ACK cell which arrived on the given circuit.
Definition at line 2024 of file conflux_pool.c.
|
static |
Return the number of unused client linked set.
Definition at line 1329 of file conflux_pool.c.
|
inlinestatic |
Helper: Format at 8 bytes the nonce for logging.
Definition at line 141 of file conflux_pool.c.
Referenced by conflux_log_set().
|
inlinestatic |
Helper: Free function for the digest256map_free().
Definition at line 212 of file conflux_pool.c.
|
inlinestatic |
Helper: Free function taking a void pointer for the digest256map_free.
Definition at line 717 of file conflux_pool.c.
|
static |
Return the currently configured client UX.
Definition at line 1077 of file conflux_pool.c.
|
static |
On the client side, we need to determine if there is already an exit in use for this set, and if so, use that.
Otherwise, we return NULL and the exit is decided by the circuitbuild.c code.
Definition at line 1035 of file conflux_pool.c.
|
static |
Return true iff the given conflux object is allowed to launch a new leg. If the cfx object is NULL, then it is always allowed to launch a new leg.
Definition at line 1094 of file conflux_pool.c.
STATIC bool launch_new_set | ( | int | num_legs | ) |
Launch a brand new set.
Return true if all legs successfully launched or false if one failed.
Definition at line 978 of file conflux_pool.c.
|
inlinestatic |
Return an unlinked leg for the given unlinked object and for the given circuit.
Definition at line 371 of file conflux_pool.c.
Referenced by unlinked_leg_find().
|
static |
Free the given leg object. Passing NULL is safe.
Definition at line 231 of file conflux_pool.c.
Referenced by unlinked_free().
|
static |
Return a newly allocated leg object containing the given circuit and link pointer (no copy).
Definition at line 221 of file conflux_pool.c.
|
static |
Link the given circuit within its unlinked set. This is called when either the LINKED or LINKED_ACK is received depending on which side of the circuit it is.
It attempts to finalize the unlinked set as well which, if successful, puts it in the linked pool.
Definition at line 933 of file conflux_pool.c.
|
static |
The given circuit is already linked to a set and has been closed. Remove it from the set and free the pool if no more legs.
Definition at line 1551 of file conflux_pool.c.
Referenced by conflux_circuit_has_closed().
|
static |
The given circuit is being freed and it is a linked leg. Clean up and free anything that has to do with this circuit.
After this call, the circuit should NOT be referenced anymore anywhere.
Definition at line 1614 of file conflux_pool.c.
Referenced by conflux_circuit_about_to_free().
|
static |
Nullify all streams of the given circuit.
Definition at line 1533 of file conflux_pool.c.
|
static |
Add the given conflux object to the linked conflux set.
Definition at line 324 of file conflux_pool.c.
|
static |
Delete from the linked conflux set the given nonce.
Definition at line 336 of file conflux_pool.c.
|
static |
Return a conflux_t object for the given nonce from the linked set.
Definition at line 348 of file conflux_pool.c.
Referenced by conflux_mark_all_for_close(), and get_exit_for_nonce().
|
static |
Update all stream pointers to point to this circuit. This is used when a linked circuit is closed and we need to update the streams to point to the remaining circuit
Definition at line 1499 of file conflux_pool.c.
|
static |
For the given circuit, record the RTT from when the LINK or LINKED cell was sent that is this function works for either client or Exit.
Return false if the RTT is too high for our standard else true.
Definition at line 901 of file conflux_pool.c.
|
static |
Record the RTT for this client circuit.
Return the RTT value. UINT64_MAX is returned if we couldn't find the initial measurement of when the cell was sent or if the leg is missing.
Definition at line 827 of file conflux_pool.c.
Referenced by record_rtt().
|
static |
Record the RTT for this Exit circuit.
Return the RTT value. UINT64_MAX is returned if we couldn't find the initial measurement of when the cell was sent or if the leg is missing.
Definition at line 866 of file conflux_pool.c.
|
static |
Attempt to finalize the unlinked set to become a linked set and be put in the linked pool.
If this finalized successfully, the given unlinked object is freed.
Definition at line 728 of file conflux_pool.c.
|
static |
The given circuit is conflux pending and has closed. This deletes the leg from the set, attempt to finalize it and relaunch a new leg. If the set is empty after removing this leg, it is deleted.
Definition at line 1444 of file conflux_pool.c.
Referenced by conflux_circuit_has_closed().
|
static |
The given circuit is being freed and it is an unlinked leg. Clean up and free anything that has to do with this circuit.
After this call, the circuit should NOT be referenced anymore anywhere.
Definition at line 1681 of file conflux_pool.c.
Referenced by conflux_circuit_about_to_free().
|
static |
Close the circuit of each legs of the given unlinked object.
Definition at line 614 of file conflux_pool.c.
|
static |
Either closee all legs of the given unlinked set or delete it from the pool and free its memory.
Important: The unlinked object is freed opportunistically when legs are removed until the point none remains. And so, it is only safe to free the object if no more legs exist.
Definition at line 657 of file conflux_pool.c.
Referenced by conflux_mark_all_for_close().
|
static |
Free the given unlinked object.
Definition at line 260 of file conflux_pool.c.
Referenced by unlinked_pool_del_and_free().
|
static |
Definition at line 1001 of file conflux_pool.c.
|
inlinestatic |
Add the given leg to the given unlinked object.
Definition at line 360 of file conflux_pool.c.
|
static |
Definition at line 394 of file conflux_pool.c.
Return the given circuit leg from its unlinked set (if any).
Definition at line 383 of file conflux_pool.c.
Referenced by record_rtt_client(), and unlinked_circuit_free().
|
static |
Return a newly allocated unlinked set object for the given nonce. A new conflux object is also created.
Definition at line 247 of file conflux_pool.c.
|
static |
Add the given unlinked object to the unlinked pool.
Definition at line 278 of file conflux_pool.c.
|
static |
Delete the given unlinked object from the unlinked pool.
Definition at line 290 of file conflux_pool.c.
Referenced by unlinked_pool_del_and_free().
|
static |
Delete from the pool and free the given unlinked object.
Definition at line 315 of file conflux_pool.c.
Referenced by free_unlinked_void_().
|
static |
Return an unlinked object for the given nonce else NULL.
Definition at line 303 of file conflux_pool.c.
Referenced by conflux_mark_all_for_close(), and unlinked_leg_find().
|
static |
Ensure that the given circuit has no attached streams.
This validation function is called at various stages for unlinked circuits, to make sure they have no streams.
Definition at line 416 of file conflux_pool.c.
|
static |
Return true iff the legs in the given unlinked set are valid and coherent to be a linked set.
Definition at line 450 of file conflux_pool.c.
|
static |
The pool of client-side conflux_t that are built, linked, and ready to be used. Indexed by nonce.
Definition at line 50 of file conflux_pool.c.
Referenced by conflux_pool_init(), linked_pool_add(), linked_pool_del(), and linked_pool_get().
|
static |
The pool of origin unlinked_circuits_t indexed by nonce.
Definition at line 53 of file conflux_pool.c.
Referenced by conflux_pool_init(), unlinked_pool_add(), unlinked_pool_del(), and unlinked_pool_get().
STATIC uint8_t DEFAULT_CLIENT_UX = CONFLUX_UX_HIGH_THROUGHPUT |
Definition at line 136 of file conflux_pool.c.
STATIC uint8_t DEFAULT_EXIT_UX = CONFLUX_UX_MIN_LATENCY |
Definition at line 137 of file conflux_pool.c.
|
static |
The pool of relay conflux_t indexed by nonce. We call these "server" because they could be onion-service side too (even though we likely will only implement onion service conflux in Arti). The code is littered with asserts to ensure there are no origin circuits in here for now, too.
Definition at line 59 of file conflux_pool.c.
Referenced by conflux_pool_init(), linked_pool_add(), linked_pool_del(), and linked_pool_get().
|
static |
The pool of relay unlinked_circuits_t indexed by nonce.
Definition at line 62 of file conflux_pool.c.
Referenced by conflux_pool_init(), unlinked_pool_add(), unlinked_pool_del(), and unlinked_pool_get().
|
static |
Definition at line 46 of file conflux_pool.c.