[or-cvs] r9586: Tweak stream_bw patch: Remove a couple of redundant checks, (in tor/trunk: . doc/spec src/or)

nickm at seul.org nickm at seul.org
Wed Feb 14 16:46:56 UTC 2007


Author: nickm
Date: 2007-02-14 11:46:55 -0500 (Wed, 14 Feb 2007)
New Revision: 9586

Modified:
   tor/trunk/
   tor/trunk/ChangeLog
   tor/trunk/doc/spec/control-spec.txt
   tor/trunk/src/or/connection.c
   tor/trunk/src/or/control.c
   tor/trunk/src/or/or.h
Log:
 r11813 at catbus:  nickm | 2007-02-14 11:42:58 -0500
 Tweak stream_bw patch: Remove a couple of redundant checks, save 8 bytes per edge connection, fix spelling in the changelog; expand spec.



Property changes on: tor/trunk
___________________________________________________________________
 svk:merge ticket from /tor/trunk [r11813] on 8246c3cf-6607-4228-993b-4d95d33730f1

Modified: tor/trunk/ChangeLog
===================================================================
--- tor/trunk/ChangeLog	2007-02-14 16:46:49 UTC (rev 9585)
+++ tor/trunk/ChangeLog	2007-02-14 16:46:55 UTC (rev 9586)
@@ -45,7 +45,7 @@
       control protocol.  We're planning to remove support for it during
       the next development series, so it's good to give people some
       advance warning.
-    - Add STREAM_BW events to reprot per-entry-stream bandwidth use. (Patch
+    - Add STREAM_BW events to report per-entry-stream bandwidth use. (Patch
       from Robert Hogan.)
 
   o Minor features:

Modified: tor/trunk/doc/spec/control-spec.txt
===================================================================
--- tor/trunk/doc/spec/control-spec.txt	2007-02-14 16:46:49 UTC (rev 9585)
+++ tor/trunk/doc/spec/control-spec.txt	2007-02-14 16:46:55 UTC (rev 9586)
@@ -1271,16 +1271,20 @@
 
   [First added in 0.1.2.3-alpha]
 
-4.1.13. Bandwidth used on a stream
+4.1.13. Bandwidth used on an application stream
 
   The syntax is:
      "650" SP "STREAM_BW" SP StreamID SP BytesRead SP BytesWritten
      BytesRead = 1*DIGIT
      BytesWritten = 1*DIGIT
 
-  The number of bytes read and written since the last read or write event
-  on a stream.
+  BytesRead and BytesWritten are the number of bytes read and written since
+  the last STREAM_BW event on a stream.  These events are generated about
+  once per second per stream; No event is generated for streams that have not
+  read or written.
 
+  These events apply only to streams entering Tor (such as on a SOCKSPort,
+  TransPort, or so on).  They are not generated for exiting streams.
 
 5. Implementation notes
 

Modified: tor/trunk/src/or/connection.c
===================================================================
--- tor/trunk/src/or/connection.c	2007-02-14 16:46:49 UTC (rev 9585)
+++ tor/trunk/src/or/connection.c	2007-02-14 16:46:55 UTC (rev 9586)
@@ -1571,11 +1571,9 @@
     *max_to_read = at_most - n_read;
   }
 
-  if (CONN_IS_EDGE(conn)) {
-    if (conn->type == CONN_TYPE_AP) {
-        edge_connection_t *edge_conn = TO_EDGE_CONN(conn);
-        edge_conn->n_read += n_read;
-    }
+  if (conn->type == CONN_TYPE_AP) {
+    edge_connection_t *edge_conn = TO_EDGE_CONN(conn);
+    edge_conn->n_read += n_read;
   }
 
   if (connection_is_rate_limited(conn)) {
@@ -1774,11 +1772,9 @@
     n_written = (size_t) result;
   }
 
-  if (CONN_IS_EDGE(conn)) {
-    if (conn->type == CONN_TYPE_AP) {
-      edge_connection_t *edge_conn = TO_EDGE_CONN(conn);
-      edge_conn->n_written += n_written;
-    }
+  if (conn->type == CONN_TYPE_AP) {
+    edge_connection_t *edge_conn = TO_EDGE_CONN(conn);
+    edge_conn->n_written += n_written;
   }
 
   if (connection_is_rate_limited(conn)) {

Modified: tor/trunk/src/or/control.c
===================================================================
--- tor/trunk/src/or/control.c	2007-02-14 16:46:49 UTC (rev 9585)
+++ tor/trunk/src/or/control.c	2007-02-14 16:46:55 UTC (rev 9586)
@@ -126,9 +126,10 @@
  * has interest in without having to walk over the global connection
  * list to find out.
  **/
-static uint32_t global_event_mask0 = 0;
-static uint32_t global_event_mask1long = 0;
-static uint32_t global_event_mask1short = 0;
+typedef uint32_t event_mask_t;
+static event_mask_t global_event_mask0 = 0;
+static event_mask_t global_event_mask1long = 0;
+static event_mask_t global_event_mask1short = 0;
 
 /** True iff we have disabled log messages from being sent to the controller */
 static int disable_log_messages = 0;
@@ -276,6 +277,11 @@
 {
   connection_t **conns;
   int n_conns, i;
+  event_mask_t old_mask, new_mask;
+  old_mask = global_event_mask0;
+  old_mask |= global_event_mask1short;
+  old_mask |= global_event_mask1long;
+
   global_event_mask0 = 0;
   global_event_mask1short = 0;
   global_event_mask1long = 0;
@@ -293,7 +299,25 @@
     }
   }
 
+  new_mask = global_event_mask0;
+  new_mask |= global_event_mask1short;
+  new_mask |= global_event_mask1long;
+
+  /* Handle the aftermath.  Set up the log callback to tell us only what
+   * we want to hear...*/
   control_adjust_event_log_severity();
+
+  /* ...then, if we've started logging stream bw, clear the appropriate
+   * fields. */
+  if (! (old_mask & EVENT_STREAM_BANDWIDTH_USED) &&
+      (new_mask & EVENT_STREAM_BANDWIDTH_USED)) {
+    for (i = 0; i < n_conns; ++i) {
+      if (conns[i]->type == CONN_TYPE_AP) {
+        edge_connection_t *conn = TO_EDGE_CONN(conns[i]);
+        conn->n_written = conn->n_read = 0;
+      }
+    }
+  }
 }
 
 /** Adjust the log severities that result in control_event_logmsg being called
@@ -3416,12 +3440,11 @@
 /** A second or more has elapsed: tell any interested control
  * connections how much bandwidth streams have used. */
 int
-control_event_stream_bandwidth_used()
+control_event_stream_bandwidth_used(void)
 {
   connection_t **carray;
   edge_connection_t *conn;
   int n, i;
-  uint32_t justread, justwritten;
 
   if (EVENT_IS_INTERESTING1(EVENT_STREAM_BANDWIDTH_USED)) {
 
@@ -3431,20 +3454,16 @@
         if (carray[i]->type != CONN_TYPE_AP)
           continue;
         conn = TO_EDGE_CONN(carray[i]);
-        if (conn->p_read == conn->n_read && conn->p_written == conn->n_written)
+        if (!conn->n_read && !conn->n_written)
           continue;
 
-        justread = conn->n_read - conn->p_read;
-        conn->p_read = conn->n_read;
-        justwritten = conn->n_written - conn->p_written;
-        conn->p_written = conn->n_written;
-
         send_control1_event(EVENT_STREAM_BANDWIDTH_USED, ALL_NAMES,
                             "650 STREAM_BW %lu %lu %lu\r\n",
                             (unsigned long)conn->global_identifier,
-                            (unsigned long)justread,
-                            (unsigned long)justwritten);
+                            (unsigned long)conn->n_read,
+                            (unsigned long)conn->n_written);
 
+        conn->n_written = conn->n_read = 0;
     }
   }
 

Modified: tor/trunk/src/or/or.h
===================================================================
--- tor/trunk/src/or/or.h	2007-02-14 16:46:49 UTC (rev 9585)
+++ tor/trunk/src/or/or.h	2007-02-14 16:46:55 UTC (rev 9586)
@@ -838,13 +838,11 @@
   /* XXXX NM This can get re-used after 2**32 streams */
   uint32_t global_identifier;
 
-  /** Bytes read */
+  /** Bytes read since last call to control_event_stream_bandwidth_used() */
   uint32_t n_read;
-  uint32_t p_read;
 
-  /** Bytes written */
+  /** Bytes written since last call to control_event_stream_bandwidth_used() */
   uint32_t n_written;
-  uint32_t p_written;
 
   /** Exit only: a dirserv connection that is tunneled over this connection
    * using a socketpair. */



More information about the tor-commits mailing list