Browse Source

only count bytes transmitted to/from non-local IPs

svn:r2041
Roger Dingledine 20 years ago
parent
commit
d37850bb98
3 changed files with 10 additions and 11 deletions
  1. 6 2
      src/or/connection.c
  2. 2 7
      src/or/main.c
  3. 2 2
      src/or/rephist.c

+ 6 - 2
src/or/connection.c

@@ -711,7 +711,7 @@ int connection_handle_read(connection_t *conn) {
   if(connection_read_to_buf(conn) < 0) {
     /* There's a read error; kill the connection.*/
     connection_close_immediate(conn); /* Don't flush; connection is dead. */
-    conn->has_sent_end = 1;
+    conn->has_sent_end = 1; /* XXX have we already sent the end? really? */
     connection_mark_for_close(conn);
     if(conn->type == CONN_TYPE_DIR &&
        conn->state == DIR_CONN_STATE_CONNECTING) {
@@ -781,6 +781,10 @@ static int connection_read_to_buf(connection_t *conn) {
       return -1;
   }
 
+  if(result > 0 && !is_local_IP(conn->addr)) { /* remember it */
+    rep_hist_note_bytes_read(result, time(NULL));
+  }
+
   connection_bucket_decrement(conn, result);
   return 0;
 }
@@ -900,7 +904,7 @@ int connection_handle_write(connection_t *conn) {
     }
   }
 
-  if(result > 0) { /* remember it */
+  if(result > 0 && !is_local_IP(conn->addr)) { /* remember it */
     rep_hist_note_bytes_written(result, now);
   }
 

+ 2 - 7
src/or/main.c

@@ -390,7 +390,7 @@ static void run_connection_housekeeping(int i, time_t now) {
   }
 }
 
-#define MIN_BW_TO_PUBLISH_DESC 5000 /* 5000 bytes sustained */
+#define MIN_BW_TO_PUBLISH_DESC 5000 /* 5000 bytes/s sustained */
 #define MIN_UPTIME_TO_PUBLISH_DESC (30*60) /* half an hour */
 
 /** Decide if we're a server or just a client. We are a server if:
@@ -542,7 +542,6 @@ static void run_scheduled_events(time_t now) {
 static int prepare_for_poll(void) {
   static long current_second = 0; /* from previous calls to gettimeofday */
   connection_t *conn;
-  int bytes_read;
   struct timeval now;
   int i;
 
@@ -550,12 +549,8 @@ static int prepare_for_poll(void) {
 
   /* Check how much bandwidth we've consumed, and increment the token
    * buckets. */
-  bytes_read = stats_prev_global_read_bucket - global_read_bucket;
-  stats_n_bytes_read += bytes_read;
+  stats_n_bytes_read += stats_prev_global_read_bucket - global_read_bucket;
   connection_bucket_refill(&now);
-  if (bytes_read > 0) {
-    rep_hist_note_bytes_read(bytes_read, now.tv_sec);
-  }
   stats_prev_global_read_bucket = global_read_bucket;
 
   if(now.tv_sec > current_second) { /* the second has rolled over. check more stuff. */

+ 2 - 2
src/or/rephist.c

@@ -295,7 +295,7 @@ void write_rep_history(const char *filename)
  * Add num_bytes to the current running total for <b>when</b>.
  *
  * <b>when</b> can go back to time, but it's safe to ignore calls
- * earlier that the latest <b>when</b> you've heard of.
+ * earlier than the latest <b>when</b> you've heard of.
  */
 void rep_hist_note_bytes_written(int num_bytes, time_t when) {
 /* Maybe a circular array for recent seconds, and step to a new point
@@ -327,7 +327,7 @@ int rep_hist_bandwidth_assess(time_t when) {
 /* To get a handle on space complexity, I promise I will call this
  * function at most every options.DirFetchPostPeriod seconds. So in
  * rep_hist_note_bytes_foo() above, you could keep a running max sum
- * for the current period, and when the period ends you can tuck it away
+ * for the current period, and when the period ends you can tuck its max away
  * in a circular array of more managable size. We lose a bit of precision,
  * but this is all guesswork anyway.
  */