[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] Replace magic constants for wide_circ_ids with inline function calls



commit 076654ce8423d2b8ab7285b22c13d4002942bd8b
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date:   Sat Feb 9 00:56:53 2013 -0500

    Replace magic constants for wide_circ_ids with inline function calls
---
 src/or/buffers.c       |   10 ++++------
 src/or/channeltls.c    |    3 +--
 src/or/connection.c    |    6 ++----
 src/or/connection_or.c |   12 ++++--------
 src/or/or.h            |   17 +++++++++++++++++
 5 files changed, 28 insertions(+), 20 deletions(-)

diff --git a/src/or/buffers.c b/src/or/buffers.c
index b6a2195..0e9bb99 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 ed56e1a..a699d3c 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 b89e03c..cd81970 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 63bdd9a..4da4367 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 736438e..356953b 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)



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits