mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2025-02-25 07:07:52 +01:00
Replace magic constants for wide_circ_ids with inline function calls
This commit is contained in:
parent
8e8c0674c4
commit
076654ce84
5 changed files with 28 additions and 20 deletions
|
@ -1049,9 +1049,8 @@ fetch_var_cell_from_buf(buf_t *buf, var_cell_t **out, int linkproto)
|
|||
uint8_t command;
|
||||
uint16_t length;
|
||||
const int wide_circ_ids = linkproto >= MIN_LINK_PROTO_FOR_WIDE_CIRC_IDS;
|
||||
const int circ_id_len = wide_circ_ids ? 4 : 2;
|
||||
const unsigned header_len = wide_circ_ids ? VAR_CELL_MAX_HEADER_SIZE :
|
||||
VAR_CELL_MAX_HEADER_SIZE - 2;
|
||||
const int circ_id_len = get_circ_id_size(wide_circ_ids);
|
||||
const unsigned header_len = get_var_cell_header_size(wide_circ_ids);
|
||||
check();
|
||||
*out = NULL;
|
||||
if (buf->datalen < header_len)
|
||||
|
@ -1132,9 +1131,8 @@ fetch_var_cell_from_evbuffer(struct evbuffer *buf, var_cell_t **out,
|
|||
var_cell_t *cell;
|
||||
int result = 0;
|
||||
const int wide_circ_ids = linkproto >= MIN_LINK_PROTO_FOR_WIDE_CIRC_IDS;
|
||||
const int circ_id_len = wide_circ_ids ? 4 : 2;
|
||||
const unsigned header_len = wide_circ_ids ? VAR_CELL_MAX_HEADER_SIZE :
|
||||
VAR_CELL_MAX_HEADER_SIZE - 2;
|
||||
const int circ_id_len = get_circ_id_size(wide_circ_ids);
|
||||
const unsigned header_len = get_var_cell_header_size(wide_circ_ids);
|
||||
|
||||
*out = NULL;
|
||||
buf_len = evbuffer_get_length(buf);
|
||||
|
|
|
@ -600,8 +600,7 @@ channel_tls_write_packed_cell_method(channel_t *chan,
|
|||
packed_cell_t *packed_cell)
|
||||
{
|
||||
channel_tls_t *tlschan = BASE_CHAN_TO_TLS(chan);
|
||||
size_t cell_network_size = (chan->wide_circ_ids) ?
|
||||
CELL_MAX_NETWORK_SIZE : CELL_MAX_NETWORK_SIZE - 2;
|
||||
size_t cell_network_size = get_cell_network_size(chan->wide_circ_ids);
|
||||
|
||||
tor_assert(tlschan);
|
||||
tor_assert(packed_cell);
|
||||
|
|
|
@ -2166,8 +2166,7 @@ connection_bucket_read_limit(connection_t *conn, time_t now)
|
|||
or_connection_t *or_conn = TO_OR_CONN(conn);
|
||||
if (conn->state == OR_CONN_STATE_OPEN)
|
||||
conn_bucket = or_conn->read_bucket;
|
||||
base = or_conn->wide_circ_ids ? CELL_MAX_NETWORK_SIZE :
|
||||
CELL_MAX_NETWORK_SIZE - 2;
|
||||
base = get_cell_network_size(or_conn->wide_circ_ids);
|
||||
}
|
||||
|
||||
if (!connection_is_rate_limited(conn)) {
|
||||
|
@ -2205,8 +2204,7 @@ connection_bucket_write_limit(connection_t *conn, time_t now)
|
|||
if (or_conn->write_bucket < conn_bucket)
|
||||
conn_bucket = or_conn->write_bucket >= 0 ?
|
||||
or_conn->write_bucket : 0;
|
||||
base = or_conn->wide_circ_ids ? CELL_MAX_NETWORK_SIZE :
|
||||
CELL_MAX_NETWORK_SIZE - 2;
|
||||
base = get_cell_network_size(or_conn->wide_circ_ids);
|
||||
}
|
||||
|
||||
if (connection_counts_as_relayed_traffic(conn, now) &&
|
||||
|
|
|
@ -521,8 +521,7 @@ connection_or_flushed_some(or_connection_t *conn)
|
|||
{
|
||||
size_t datalen, temp;
|
||||
ssize_t n, flushed;
|
||||
size_t cell_network_size = conn->wide_circ_ids ? CELL_MAX_NETWORK_SIZE :
|
||||
CELL_MAX_NETWORK_SIZE - 2;
|
||||
size_t cell_network_size = get_cell_network_size(conn->wide_circ_ids);
|
||||
|
||||
/* If we're under the low water mark, add cells until we're just over the
|
||||
* high water mark. */
|
||||
|
@ -1764,8 +1763,7 @@ or_handshake_state_record_cell(or_connection_t *conn,
|
|||
const cell_t *cell,
|
||||
int incoming)
|
||||
{
|
||||
size_t cell_network_size = conn->wide_circ_ids ? CELL_MAX_NETWORK_SIZE :
|
||||
CELL_MAX_NETWORK_SIZE - 2;
|
||||
size_t cell_network_size = get_cell_network_size(conn->wide_circ_ids);
|
||||
crypto_digest_t *d, **dptr;
|
||||
packed_cell_t packed;
|
||||
if (incoming) {
|
||||
|
@ -1857,8 +1855,7 @@ void
|
|||
connection_or_write_cell_to_buf(const cell_t *cell, or_connection_t *conn)
|
||||
{
|
||||
packed_cell_t networkcell;
|
||||
size_t cell_network_size = (conn->wide_circ_ids) ?
|
||||
CELL_MAX_NETWORK_SIZE : CELL_MAX_NETWORK_SIZE - 2;
|
||||
size_t cell_network_size = get_cell_network_size(conn->wide_circ_ids);
|
||||
|
||||
tor_assert(cell);
|
||||
tor_assert(conn);
|
||||
|
@ -1948,8 +1945,7 @@ connection_or_process_cells_from_inbuf(or_connection_t *conn)
|
|||
var_cell_free(var_cell);
|
||||
} else {
|
||||
const int wide_circ_ids = conn->wide_circ_ids;
|
||||
const size_t cell_network_size = wide_circ_ids ? CELL_MAX_NETWORK_SIZE :
|
||||
CELL_MAX_NETWORK_SIZE - 2;
|
||||
size_t cell_network_size = get_cell_network_size(conn->wide_circ_ids);
|
||||
char buf[CELL_MAX_NETWORK_SIZE];
|
||||
cell_t cell;
|
||||
if (connection_get_inbuf_len(TO_CONN(conn))
|
||||
|
|
17
src/or/or.h
17
src/or/or.h
|
@ -869,6 +869,23 @@ typedef enum {
|
|||
/** Maximum length of a header on a variable-length cell. */
|
||||
#define VAR_CELL_MAX_HEADER_SIZE 7
|
||||
|
||||
static int get_cell_network_size(int wide_circ_ids);
|
||||
static INLINE int get_cell_network_size(int wide_circ_ids)
|
||||
{
|
||||
return wide_circ_ids ? CELL_MAX_NETWORK_SIZE : CELL_MAX_NETWORK_SIZE - 2;
|
||||
}
|
||||
static int get_var_cell_header_size(int wide_circ_ids);
|
||||
static INLINE int get_var_cell_header_size(int wide_circ_ids)
|
||||
{
|
||||
return wide_circ_ids ? VAR_CELL_MAX_HEADER_SIZE :
|
||||
VAR_CELL_MAX_HEADER_SIZE - 2;
|
||||
}
|
||||
static int get_circ_id_size(int wide_circ_ids);
|
||||
static INLINE int get_circ_id_size(int wide_circ_ids)
|
||||
{
|
||||
return wide_circ_ids ? 4 : 2;
|
||||
}
|
||||
|
||||
/** Number of bytes in a relay cell's header (not including general cell
|
||||
* header). */
|
||||
#define RELAY_HEADER_SIZE (1+2+2+4+2)
|
||||
|
|
Loading…
Add table
Reference in a new issue