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

[tor-commits] [tor/master] Remove generic_buffer_*() functions as needless.



commit 46ef4487d3914cac1aba148ec58ff271bda3c636
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date:   Tue Aug 2 13:40:19 2016 -0400

    Remove generic_buffer_*() functions as needless.
    
    These functions were there so that we could abstract the differences
    between evbuffer and buf_t.  But with the bufferevent removal, this
    no longer serves a purpose.
---
 src/or/buffers.c         |  4 +--
 src/or/buffers.h         | 13 ++------
 src/or/connection.c      |  4 +--
 src/or/connection_edge.c |  2 +-
 src/or/or.h              |  6 ++--
 src/or/relay.c           | 14 ++++-----
 src/test/test_buffers.c  | 81 ++++++++++++++++++++++++------------------------
 src/test/test_oom.c      |  6 ++--
 8 files changed, 60 insertions(+), 70 deletions(-)

diff --git a/src/or/buffers.c b/src/or/buffers.c
index 0afa3e6..8574450 100644
--- a/src/or/buffers.c
+++ b/src/or/buffers.c
@@ -1978,8 +1978,8 @@ write_to_buf_zlib(buf_t *buf, tor_zlib_state_t *state,
 
 /** Set *<b>output</b> to contain a copy of the data in *<b>input</b> */
 int
-buf_set_to_copy(generic_buffer_t **output,
-                const generic_buffer_t *input)
+buf_set_to_copy(buf_t **output,
+                const buf_t *input)
 {
   if (*output)
     buf_free(*output);
diff --git a/src/or/buffers.h b/src/or/buffers.h
index 3629fc3..275867c 100644
--- a/src/or/buffers.h
+++ b/src/or/buffers.h
@@ -56,17 +56,8 @@ int peek_buf_has_control0_command(buf_t *buf);
 
 int fetch_ext_or_command_from_buf(buf_t *buf, ext_or_cmd_t **out);
 
-#define generic_buffer_new() buf_new()
-#define generic_buffer_len(b) buf_datalen((b))
-#define generic_buffer_add(b,dat,len) write_to_buf((dat),(len),(b))
-#define generic_buffer_get(b,buf,buflen) fetch_from_buf((buf),(buflen),(b))
-#define generic_buffer_clear(b) buf_clear((b))
-#define generic_buffer_free(b) buf_free((b))
-#define generic_buffer_fetch_ext_or_cmd(b, out) \
-  fetch_ext_or_command_from_buf((b), (out))
-
-int buf_set_to_copy(generic_buffer_t **output,
-                    const generic_buffer_t *input);
+int buf_set_to_copy(buf_t **output,
+                    const buf_t *input);
 
 void assert_buf_ok(buf_t *buf);
 
diff --git a/src/or/connection.c b/src/or/connection.c
index ac00a1b..40fc2bc 100644
--- a/src/or/connection.c
+++ b/src/or/connection.c
@@ -549,10 +549,10 @@ connection_free_(connection_t *conn)
     if (entry_conn->socks_request)
       socks_request_free(entry_conn->socks_request);
     if (entry_conn->pending_optimistic_data) {
-      generic_buffer_free(entry_conn->pending_optimistic_data);
+      buf_free(entry_conn->pending_optimistic_data);
     }
     if (entry_conn->sending_optimistic_data) {
-      generic_buffer_free(entry_conn->sending_optimistic_data);
+      buf_free(entry_conn->sending_optimistic_data);
     }
   }
   if (CONN_IS_EDGE(conn)) {
diff --git a/src/or/connection_edge.c b/src/or/connection_edge.c
index 4fb195f..2ac82bb 100644
--- a/src/or/connection_edge.c
+++ b/src/or/connection_edge.c
@@ -2340,7 +2340,7 @@ connection_ap_handshake_send_begin(entry_connection_t *ap_conn)
     log_info(LD_APP, "Sending up to %ld + %ld bytes of queued-up data",
              (long)connection_get_inbuf_len(base_conn),
              ap_conn->sending_optimistic_data ?
-             (long)generic_buffer_len(ap_conn->sending_optimistic_data) : 0);
+             (long)buf_datalen(ap_conn->sending_optimistic_data) : 0);
     if (connection_edge_package_raw_inbuf(edge_conn, 1, NULL) < 0) {
       connection_mark_for_close(base_conn);
     }
diff --git a/src/or/or.h b/src/or/or.h
index 3ca9ea2..1bac43c 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -1132,7 +1132,7 @@ typedef struct {
 typedef struct buf_t buf_t;
 typedef struct socks_request_t socks_request_t;
 
-#define generic_buffer_t buf_t
+#define buf_t buf_t
 
 typedef struct entry_port_cfg_t {
   /* Client port types (socks, dns, trans, natd) only: */
@@ -1619,11 +1619,11 @@ typedef struct entry_connection_t {
   /** For AP connections only: buffer for data that we have sent
    * optimistically, which we might need to re-send if we have to
    * retry this connection. */
-  generic_buffer_t *pending_optimistic_data;
+  buf_t *pending_optimistic_data;
   /* For AP connections only: buffer for data that we previously sent
   * optimistically which we are currently re-sending as we retry this
   * connection. */
-  generic_buffer_t *sending_optimistic_data;
+  buf_t *sending_optimistic_data;
 
   /** If this is a DNSPort connection, this field holds the pending DNS
    * request that we're going to try to answer.  */
diff --git a/src/or/relay.c b/src/or/relay.c
index cfb0016..d82ed87 100644
--- a/src/or/relay.c
+++ b/src/or/relay.c
@@ -1374,7 +1374,7 @@ connection_edge_process_relay_cell_not_open(
     /* This is definitely a success, so forget about any pending data we
      * had sent. */
     if (entry_conn->pending_optimistic_data) {
-      generic_buffer_free(entry_conn->pending_optimistic_data);
+      buf_free(entry_conn->pending_optimistic_data);
       entry_conn->pending_optimistic_data = NULL;
     }
 
@@ -1876,7 +1876,7 @@ connection_edge_package_raw_inbuf(edge_connection_t *conn, int package_partial,
     entry_conn->sending_optimistic_data != NULL;
 
   if (PREDICT_UNLIKELY(sending_from_optimistic)) {
-    bytes_to_process = generic_buffer_len(entry_conn->sending_optimistic_data);
+    bytes_to_process = buf_datalen(entry_conn->sending_optimistic_data);
     if (PREDICT_UNLIKELY(!bytes_to_process)) {
       log_warn(LD_BUG, "sending_optimistic_data was non-NULL but empty");
       bytes_to_process = connection_get_inbuf_len(TO_CONN(conn));
@@ -1904,9 +1904,9 @@ connection_edge_package_raw_inbuf(edge_connection_t *conn, int package_partial,
     /* XXXX We could be more efficient here by sometimes packing
      * previously-sent optimistic data in the same cell with data
      * from the inbuf. */
-    generic_buffer_get(entry_conn->sending_optimistic_data, payload, length);
-    if (!generic_buffer_len(entry_conn->sending_optimistic_data)) {
-        generic_buffer_free(entry_conn->sending_optimistic_data);
+    fetch_from_buf(payload, length, entry_conn->sending_optimistic_data);
+    if (!buf_datalen(entry_conn->sending_optimistic_data)) {
+        buf_free(entry_conn->sending_optimistic_data);
         entry_conn->sending_optimistic_data = NULL;
     }
   } else {
@@ -1921,8 +1921,8 @@ connection_edge_package_raw_inbuf(edge_connection_t *conn, int package_partial,
     /* This is new optimistic data; remember it in case we need to detach and
        retry */
     if (!entry_conn->pending_optimistic_data)
-      entry_conn->pending_optimistic_data = generic_buffer_new();
-    generic_buffer_add(entry_conn->pending_optimistic_data, payload, length);
+      entry_conn->pending_optimistic_data = buf_new();
+    write_to_buf(payload, length, entry_conn->pending_optimistic_data);
   }
 
   if (connection_edge_send_command(conn, RELAY_COMMAND_DATA,
diff --git a/src/test/test_buffers.c b/src/test/test_buffers.c
index a8a2d95..4977b0e 100644
--- a/src/test/test_buffers.c
+++ b/src/test/test_buffers.c
@@ -303,42 +303,42 @@ test_buffer_pullup(void *arg)
 static void
 test_buffer_copy(void *arg)
 {
-  generic_buffer_t *buf=NULL, *buf2=NULL;
+  buf_t *buf=NULL, *buf2=NULL;
   const char *s;
   size_t len;
   char b[256];
   int i;
   (void)arg;
 
-  buf = generic_buffer_new();
+  buf = buf_new();
   tt_assert(buf);
 
   /* Copy an empty buffer. */
   tt_int_op(0, OP_EQ, buf_set_to_copy(&buf2, buf));
   tt_assert(buf2);
-  tt_int_op(0, OP_EQ, generic_buffer_len(buf2));
+  tt_int_op(0, OP_EQ, buf_datalen(buf2));
 
   /* Now try with a short buffer. */
   s = "And now comes an act of enormous enormance!";
   len = strlen(s);
-  generic_buffer_add(buf, s, len);
-  tt_int_op(len, OP_EQ, generic_buffer_len(buf));
+  write_to_buf(s, len, buf);
+  tt_int_op(len, OP_EQ, buf_datalen(buf));
   /* Add junk to buf2 so we can test replacing.*/
-  generic_buffer_add(buf2, "BLARG", 5);
+  write_to_buf("BLARG", 5, buf2);
   tt_int_op(0, OP_EQ, buf_set_to_copy(&buf2, buf));
-  tt_int_op(len, OP_EQ, generic_buffer_len(buf2));
-  generic_buffer_get(buf2, b, len);
+  tt_int_op(len, OP_EQ, buf_datalen(buf2));
+  fetch_from_buf(b, len, buf2);
   tt_mem_op(b, OP_EQ, s, len);
   /* Now free buf2 and retry so we can test allocating */
-  generic_buffer_free(buf2);
+  buf_free(buf2);
   buf2 = NULL;
   tt_int_op(0, OP_EQ, buf_set_to_copy(&buf2, buf));
-  tt_int_op(len, OP_EQ, generic_buffer_len(buf2));
-  generic_buffer_get(buf2, b, len);
+  tt_int_op(len, OP_EQ, buf_datalen(buf2));
+  fetch_from_buf(b, len, buf2);
   tt_mem_op(b, OP_EQ, s, len);
   /* Clear buf for next test */
-  generic_buffer_get(buf, b, len);
-  tt_int_op(generic_buffer_len(buf),OP_EQ,0);
+  fetch_from_buf(b, len, buf);
+  tt_int_op(buf_datalen(buf),OP_EQ,0);
 
   /* Okay, now let's try a bigger buffer. */
   s = "Quis autem vel eum iure reprehenderit qui in ea voluptate velit "
@@ -347,95 +347,94 @@ test_buffer_copy(void *arg)
   len = strlen(s);
   for (i = 0; i < 256; ++i) {
     b[0]=i;
-    generic_buffer_add(buf, b, 1);
-    generic_buffer_add(buf, s, len);
+    write_to_buf(b, 1, buf);
+    write_to_buf(s, len, buf);
   }
   tt_int_op(0, OP_EQ, buf_set_to_copy(&buf2, buf));
-  tt_int_op(generic_buffer_len(buf2), OP_EQ, generic_buffer_len(buf));
+  tt_int_op(buf_datalen(buf2), OP_EQ, buf_datalen(buf));
   for (i = 0; i < 256; ++i) {
-    generic_buffer_get(buf2, b, len+1);
+    fetch_from_buf(b, len+1, buf2);
     tt_int_op((unsigned char)b[0],OP_EQ,i);
     tt_mem_op(b+1, OP_EQ, s, len);
   }
 
  done:
   if (buf)
-    generic_buffer_free(buf);
+    buf_free(buf);
   if (buf2)
-    generic_buffer_free(buf2);
+    buf_free(buf2);
 }
 
 static void
 test_buffer_ext_or_cmd(void *arg)
 {
   ext_or_cmd_t *cmd = NULL;
-  generic_buffer_t *buf = generic_buffer_new();
+  buf_t *buf = buf_new();
   char *tmp = NULL;
   (void) arg;
 
   /* Empty -- should give "not there. */
-  tt_int_op(0, OP_EQ, generic_buffer_fetch_ext_or_cmd(buf, &cmd));
+  tt_int_op(0, OP_EQ, fetch_ext_or_command_from_buf(buf, &cmd));
   tt_ptr_op(NULL, OP_EQ, cmd);
 
   /* Three bytes: shouldn't work. */
-  generic_buffer_add(buf, "\x00\x20\x00", 3);
-  tt_int_op(0, OP_EQ, generic_buffer_fetch_ext_or_cmd(buf, &cmd));
+  write_to_buf("\x00\x20\x00", 3, buf);
+  tt_int_op(0, OP_EQ, fetch_ext_or_command_from_buf(buf, &cmd));
   tt_ptr_op(NULL, OP_EQ, cmd);
-  tt_int_op(3, OP_EQ, generic_buffer_len(buf));
+  tt_int_op(3, OP_EQ, buf_datalen(buf));
 
   /* 0020 0000: That's a nil command. It should work. */
-  generic_buffer_add(buf, "\x00", 1);
-  tt_int_op(1, OP_EQ, generic_buffer_fetch_ext_or_cmd(buf, &cmd));
+  write_to_buf("\x00", 1, buf);
+  tt_int_op(1, OP_EQ, fetch_ext_or_command_from_buf(buf, &cmd));
   tt_ptr_op(NULL, OP_NE, cmd);
   tt_int_op(0x20, OP_EQ, cmd->cmd);
   tt_int_op(0, OP_EQ, cmd->len);
-  tt_int_op(0, OP_EQ, generic_buffer_len(buf));
+  tt_int_op(0, OP_EQ, buf_datalen(buf));
   ext_or_cmd_free(cmd);
   cmd = NULL;
 
   /* Now try a length-6 command with one byte missing. */
-  generic_buffer_add(buf, "\x10\x21\x00\x06""abcde", 9);
-  tt_int_op(0, OP_EQ, generic_buffer_fetch_ext_or_cmd(buf, &cmd));
+  write_to_buf("\x10\x21\x00\x06""abcde", 9, buf);
+  tt_int_op(0, OP_EQ, fetch_ext_or_command_from_buf(buf, &cmd));
   tt_ptr_op(NULL, OP_EQ, cmd);
-  generic_buffer_add(buf, "f", 1);
-  tt_int_op(1, OP_EQ, generic_buffer_fetch_ext_or_cmd(buf, &cmd));
+  write_to_buf("f", 1, buf);
+  tt_int_op(1, OP_EQ, fetch_ext_or_command_from_buf(buf, &cmd));
   tt_ptr_op(NULL, OP_NE, cmd);
   tt_int_op(0x1021, OP_EQ, cmd->cmd);
   tt_int_op(6, OP_EQ, cmd->len);
   tt_mem_op("abcdef", OP_EQ, cmd->body, 6);
-  tt_int_op(0, OP_EQ, generic_buffer_len(buf));
+  tt_int_op(0, OP_EQ, buf_datalen(buf));
   ext_or_cmd_free(cmd);
   cmd = NULL;
 
   /* Now try a length-10 command with 4 extra bytes. */
-  generic_buffer_add(buf, "\xff\xff\x00\x0a"
-                     "loremipsum\x10\x00\xff\xff", 18);
-  tt_int_op(1, OP_EQ, generic_buffer_fetch_ext_or_cmd(buf, &cmd));
+  write_to_buf("\xff\xff\x00\x0aloremipsum\x10\x00\xff\xff", 18, buf);
+  tt_int_op(1, OP_EQ, fetch_ext_or_command_from_buf(buf, &cmd));
   tt_ptr_op(NULL, OP_NE, cmd);
   tt_int_op(0xffff, OP_EQ, cmd->cmd);
   tt_int_op(10, OP_EQ, cmd->len);
   tt_mem_op("loremipsum", OP_EQ, cmd->body, 10);
-  tt_int_op(4, OP_EQ, generic_buffer_len(buf));
+  tt_int_op(4, OP_EQ, buf_datalen(buf));
   ext_or_cmd_free(cmd);
   cmd = NULL;
 
   /* Finally, let's try a maximum-length command. We already have the header
    * waiting. */
-  tt_int_op(0, OP_EQ, generic_buffer_fetch_ext_or_cmd(buf, &cmd));
+  tt_int_op(0, OP_EQ, fetch_ext_or_command_from_buf(buf, &cmd));
   tmp = tor_malloc_zero(65535);
-  generic_buffer_add(buf, tmp, 65535);
-  tt_int_op(1, OP_EQ, generic_buffer_fetch_ext_or_cmd(buf, &cmd));
+  write_to_buf(tmp, 65535, buf);
+  tt_int_op(1, OP_EQ, fetch_ext_or_command_from_buf(buf, &cmd));
   tt_ptr_op(NULL, OP_NE, cmd);
   tt_int_op(0x1000, OP_EQ, cmd->cmd);
   tt_int_op(0xffff, OP_EQ, cmd->len);
   tt_mem_op(tmp, OP_EQ, cmd->body, 65535);
-  tt_int_op(0, OP_EQ, generic_buffer_len(buf));
+  tt_int_op(0, OP_EQ, buf_datalen(buf));
   ext_or_cmd_free(cmd);
   cmd = NULL;
 
  done:
   ext_or_cmd_free(cmd);
-  generic_buffer_free(buf);
+  buf_free(buf);
   tor_free(tmp);
 }
 
diff --git a/src/test/test_oom.c b/src/test/test_oom.c
index 59dfbc0..6da8687 100644
--- a/src/test/test_oom.c
+++ b/src/test/test_oom.c
@@ -77,14 +77,14 @@ dummy_origin_circuit_new(int n_cells)
 }
 
 static void
-add_bytes_to_buf(generic_buffer_t *buf, size_t n_bytes)
+add_bytes_to_buf(buf_t *buf, size_t n_bytes)
 {
   char b[3000];
 
   while (n_bytes) {
     size_t this_add = n_bytes > sizeof(b) ? sizeof(b) : n_bytes;
     crypto_rand(b, this_add);
-    generic_buffer_add(buf, b, this_add);
+    write_to_buf(b, this_add, buf);
     n_bytes -= this_add;
   }
 }
@@ -94,7 +94,7 @@ dummy_edge_conn_new(circuit_t *circ,
                     int type, size_t in_bytes, size_t out_bytes)
 {
   edge_connection_t *conn;
-  generic_buffer_t *inbuf, *outbuf;
+  buf_t *inbuf, *outbuf;
 
   if (type == CONN_TYPE_EXIT)
     conn = edge_connection_new(type, AF_INET);



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