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) {
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;
}
}
}
- if(result > 0) { /* remember it */
+ if(result > 0 && !is_local_IP(conn->addr)) { /* remember it */
rep_hist_note_bytes_written(result, 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:
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;
/* 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. */
* 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
/* 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.
*/