aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2013-02-09 00:56:53 -0500
committerNick Mathewson <nickm@torproject.org>2013-02-09 00:56:53 -0500
commit076654ce8423d2b8ab7285b22c13d4002942bd8b (patch)
tree2e4eef960efa18ca461a8f846acd8f921746441a /src
parent8e8c0674c4729a6aa39ded658e800baa654fe289 (diff)
downloadtor-076654ce8423d2b8ab7285b22c13d4002942bd8b.tar
tor-076654ce8423d2b8ab7285b22c13d4002942bd8b.tar.gz
Replace magic constants for wide_circ_ids with inline function calls
Diffstat (limited to 'src')
-rw-r--r--src/or/buffers.c10
-rw-r--r--src/or/channeltls.c3
-rw-r--r--src/or/connection.c6
-rw-r--r--src/or/connection_or.c12
-rw-r--r--src/or/or.h17
5 files changed, 28 insertions, 20 deletions
diff --git a/src/or/buffers.c b/src/or/buffers.c
index b6a21950e..0e9bb9954 100644
--- a/src/or/buffers.c
+++ b/src/or/buffers.c
@@ -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);
diff --git a/src/or/channeltls.c b/src/or/channeltls.c
index ed56e1ad1..a699d3c7d 100644
--- a/src/or/channeltls.c
+++ b/src/or/channeltls.c
@@ -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);
diff --git a/src/or/connection.c b/src/or/connection.c
index b89e03cd9..cd81970b5 100644
--- a/src/or/connection.c
+++ b/src/or/connection.c
@@ -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) &&
diff --git a/src/or/connection_or.c b/src/or/connection_or.c
index 63bdd9a5e..4da43670c 100644
--- a/src/or/connection_or.c
+++ b/src/or/connection_or.c
@@ -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))
diff --git a/src/or/or.h b/src/or/or.h
index 736438e6e..356953b43 100644
--- a/src/or/or.h
+++ b/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)