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)
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);
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);
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)) {
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) &&
{
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. */
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) {
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);
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))
/** 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)