[or-cvs] r11109: Save a 4 or 8 bytes per connection in or.h (in tor/trunk: . src/or)

nickm at seul.org nickm at seul.org
Tue Aug 14 20:19:52 UTC 2007


Author: nickm
Date: 2007-08-14 16:19:51 -0400 (Tue, 14 Aug 2007)
New Revision: 11109

Modified:
   tor/trunk/
   tor/trunk/src/or/or.h
Log:
 r14019 at Kushana:  nickm | 2007-08-14 15:40:05 -0400
 Save a 4 or 8 bytes per connection in or.h



Property changes on: tor/trunk
___________________________________________________________________
 svk:merge ticket from /tor/trunk [r14019] on c95137ef-5f19-0410-b913-86e773d04f59

Modified: tor/trunk/src/or/or.h
===================================================================
--- tor/trunk/src/or/or.h	2007-08-14 20:19:46 UTC (rev 11108)
+++ tor/trunk/src/or/or.h	2007-08-14 20:19:51 UTC (rev 11109)
@@ -251,6 +251,8 @@
 /** Type for sockets listening for DNS requests. */
 #define CONN_TYPE_AP_DNS_LISTENER 15
 #define _CONN_TYPE_MAX 15
+/* !!!! If _CONN_TYPE_MAX is ever over 15, we must grow the type field in
+ * connection_t. */
 
 #define CONN_IS_EDGE(x) \
   ((x)->type == CONN_TYPE_EXIT || (x)->type == CONN_TYPE_AP)
@@ -391,6 +393,9 @@
 #define EXIT_PURPOSE_RESOLVE 2
 #define _EXIT_PURPOSE_MAX 2
 
+/* !!!! If any connection purpose is ever over over 15, we must grow the type
+ * field in connection_t. */
+
 /** Circuit state: I'm the origin, still haven't done all my handshakes. */
 #define CIRCUIT_STATE_BUILDING 0
 /** Circuit state: Waiting to process the onionskin. */
@@ -756,13 +761,16 @@
   uint32_t magic; /**< For memory debugging: must equal one of
                    * *_CONNECTION_MAGIC. */
 
-  uint8_t type; /**< What kind of connection is this? */
   uint8_t state; /**< Current state of this connection. */
-  uint8_t purpose; /**< Only used for DIR and EXIT types currently. */
+  uint8_t type:4; /**< What kind of connection is this? */
+  uint8_t purpose:4; /**< Only used for DIR and EXIT types currently. */
 
-  /* The next fields are all one-bit booleans. Some are only applicable
-   * to connection subtypes, but we hold them here anyway, to save space.
-   * (Currently, they all fit into a single byte.) */
+  /* The next fields are all one-bit booleans. Some are only applicable to
+   * connection subtypes, but we hold them here anyway, to save space.
+   * (Currently, they all fit into a single byte. If they ever need more than
+   * one byte, we can shave some bits off type, state, and purpose above, none
+   * of which is ever over 31.)
+   */
   unsigned read_blocked_on_bw:1; /**< Boolean: should we start reading again
                             * once the bandwidth throttler allows it? */
   unsigned write_blocked_on_bw:1; /**< Boolean: should we start writing again
@@ -785,6 +793,18 @@
    * stop requiring it. */
   unsigned int chosen_exit_optional:1;
 
+  /* For linked connections:
+   */
+  unsigned int linked:1; /**< True if there is, or has been, a linked_conn. */
+  /** True iff we'd like to be notified about read events from the
+   * linked conn. */
+  unsigned int reading_from_linked_conn:1;
+  /** True iff we're willing to write to the linked conn. */
+  unsigned int writing_to_linked_conn:1;
+  /** True iff we're currently able to read on the linked conn, and our
+   * read_event should be made active with libevent. */
+  unsigned int active_on_link:1;
+
   int s; /**< Our socket; -1 if this connection is closed, or has no
           * socket. */
   int conn_array_index; /**< Index into the global connection array. */
@@ -819,17 +839,6 @@
   /** Annother connection that's connected to this one in lieu of a socket. */
   struct connection_t *linked_conn;
 
-  /* XXXX020 NM move these up to the other 1-bit flags. */
-  unsigned int linked:1; /**< True if there is, or has been, a linked_conn. */
-  /** True iff we'd like to be notified about read events from the
-   * linked conn. */
-  unsigned int reading_from_linked_conn:1;
-  /** True iff we're willing to write to the linked conn. */
-  unsigned int writing_to_linked_conn:1;
-  /** True iff we're currently able to read on the linked conn, and our
-   * read_event should be made active with libevent. */
-  unsigned int active_on_link:1;
-
   /* XXXX020 move this into a subtype!!! */
   struct evdns_server_port *dns_server_port;
 



More information about the tor-commits mailing list