[or-cvs] r10980: Try to call time(NULL) a little less. (in tor/trunk: . src/or)

nickm at seul.org nickm at seul.org
Mon Jul 30 01:32:13 UTC 2007


Author: nickm
Date: 2007-07-29 21:32:12 -0400 (Sun, 29 Jul 2007)
New Revision: 10980

Modified:
   tor/trunk/
   tor/trunk/src/or/connection.c
   tor/trunk/src/or/main.c
   tor/trunk/src/or/or.h
   tor/trunk/src/or/relay.c
Log:
 r14001 at catbus:  nickm | 2007-07-29 21:31:53 -0400
 Try to call time(NULL) a little less.



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

Modified: tor/trunk/src/or/connection.c
===================================================================
--- tor/trunk/src/or/connection.c	2007-07-30 01:32:07 UTC (rev 10979)
+++ tor/trunk/src/or/connection.c	2007-07-30 01:32:12 UTC (rev 10980)
@@ -1427,7 +1427,7 @@
 
 /** How many bytes at most can we read onto this connection? */
 static int
-connection_bucket_read_limit(connection_t *conn)
+connection_bucket_read_limit(connection_t *conn, time_t now)
 {
   int base = connection_speaks_cells(conn) ?
                CELL_NETWORK_SIZE : RELAY_PAYLOAD_SIZE;
@@ -1446,7 +1446,7 @@
     return conn_bucket>=0 ? conn_bucket : 1<<14;
   }
 
-  if (connection_counts_as_relayed_traffic(conn, time(NULL)) &&
+  if (connection_counts_as_relayed_traffic(conn, now) &&
       global_relayed_read_bucket <= global_read_bucket)
     global_bucket = global_relayed_read_bucket;
 
@@ -1456,7 +1456,7 @@
 
 /** How many bytes at most can we write onto this connection? */
 int
-connection_bucket_write_limit(connection_t *conn)
+connection_bucket_write_limit(connection_t *conn, time_t now)
 {
   int base = connection_speaks_cells(conn) ?
                CELL_NETWORK_SIZE : RELAY_PAYLOAD_SIZE;
@@ -1468,7 +1468,7 @@
     return conn->outbuf_flushlen;
   }
 
-  if (connection_counts_as_relayed_traffic(conn, time(NULL)) &&
+  if (connection_counts_as_relayed_traffic(conn, now) &&
       global_relayed_write_bucket <= global_write_bucket)
     global_bucket = global_relayed_write_bucket;
 
@@ -1632,12 +1632,11 @@
 
 /** A second has rolled over; increment buckets appropriately. */
 void
-connection_bucket_refill(int seconds_elapsed)
+connection_bucket_refill(int seconds_elapsed, time_t now)
 {
   or_options_t *options = get_options();
   smartlist_t *conns = get_connection_array();
   int relayrate, relayburst;
-  time_t now = time(NULL);
 
   if (options->RelayBandwidthRate) {
     relayrate = (int)options->RelayBandwidthRate;
@@ -1847,7 +1846,8 @@
 
   if (at_most == -1) { /* we need to initialize it */
     /* how many bytes are we allowed to read? */
-    at_most = connection_bucket_read_limit(conn);
+    /* XXXX020 too many calls to time(). Do they hurt? */
+    at_most = connection_bucket_read_limit(conn, time(NULL));
   }
 
   bytes_in_buf = buf_capacity(conn->inbuf) - buf_datalen(conn->inbuf);
@@ -2074,7 +2074,7 @@
   }
 
   max_to_write = force ? (int)conn->outbuf_flushlen
-    : connection_bucket_write_limit(conn);
+    : connection_bucket_write_limit(conn, now);
 
   if (connection_speaks_cells(conn) &&
       conn->state > OR_CONN_STATE_PROXY_READING) {

Modified: tor/trunk/src/or/main.c
===================================================================
--- tor/trunk/src/or/main.c	2007-07-30 01:32:07 UTC (rev 10979)
+++ tor/trunk/src/or/main.c	2007-07-30 01:32:12 UTC (rev 10980)
@@ -564,18 +564,20 @@
 {
   connection_t *conn;
   int retval;
+  time_t now;
 
   conn = smartlist_get(connection_array, i);
   if (!conn->marked_for_close)
     return 0; /* nothing to see here, move along */
-  assert_connection_ok(conn, time(NULL));
+  now = time(NULL);
+  assert_connection_ok(conn, now);
   assert_all_pending_dns_resolves_ok();
 
   log_debug(LD_NET,"Cleaning up connection (fd %d).",conn->s);
   if ((conn->s >= 0 || conn->linked_conn) && connection_wants_to_flush(conn)) {
     /* s == -1 means it's an incomplete edge connection, or that the socket
      * has already been closed as unflushable. */
-    int sz = connection_bucket_write_limit(conn);
+    int sz = connection_bucket_write_limit(conn, now);
     if (!conn->hold_open_until_flushed)
       log_info(LD_NET,
                "Conn (addr %s, fd %d, type %s, state %d) marked, but wants "
@@ -1143,7 +1145,7 @@
   control_event_stream_bandwidth_used();
 
   if (seconds_elapsed > 0)
-    connection_bucket_refill(seconds_elapsed);
+    connection_bucket_refill(seconds_elapsed, now.tv_sec);
   stats_prev_global_read_bucket = global_read_bucket;
   stats_prev_global_write_bucket = global_write_bucket;
 

Modified: tor/trunk/src/or/or.h
===================================================================
--- tor/trunk/src/or/or.h	2007-07-30 01:32:07 UTC (rev 10979)
+++ tor/trunk/src/or/or.h	2007-07-30 01:32:12 UTC (rev 10980)
@@ -2422,10 +2422,10 @@
 int retry_all_listeners(smartlist_t *replaced_conns,
                         smartlist_t *new_conns);
 
-int connection_bucket_write_limit(connection_t *conn);
+int connection_bucket_write_limit(connection_t *conn, time_t now);
 int global_write_bucket_low(connection_t *conn, size_t attempt, int priority);
 void connection_bucket_init(void);
-void connection_bucket_refill(int seconds_elapsed);
+void connection_bucket_refill(int seconds_elapsed, time_t now);
 
 int connection_handle_read(connection_t *conn);
 

Modified: tor/trunk/src/or/relay.c
===================================================================
--- tor/trunk/src/or/relay.c	2007-07-30 01:32:07 UTC (rev 10979)
+++ tor/trunk/src/or/relay.c	2007-07-30 01:32:12 UTC (rev 10980)
@@ -507,6 +507,7 @@
 
   if (cell_direction == CELL_DIRECTION_OUT && circ->n_conn) {
     /* if we're using relaybandwidthrate, this conn wants priority */
+    /* XXXX020 the call to time() seems little too frequent */
     circ->n_conn->client_used = time(NULL);
   }
 



More information about the tor-commits mailing list