[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] Merge remote-tracking branch 'public/bug10169_024' into bug10169_025_v2



commit bb375442141b4a5b301212394ce3e106cb34daf2
Merge: c8d41da 46118d7
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date:   Tue Mar 4 11:00:02 2014 -0500

    Merge remote-tracking branch 'public/bug10169_024' into bug10169_025_v2
    
    Conflicts:
    	src/common/compat_libevent.h
    	src/or/relay.c

 src/common/compat_libevent.c |   30 ++++++++++++++++++++++++++++++
 src/common/compat_libevent.h |    1 +
 src/or/buffers.c             |    2 +-
 src/or/circuitlist.c         |    8 +++++---
 src/or/relay.c               |    3 ++-
 5 files changed, 39 insertions(+), 5 deletions(-)

diff --cc src/common/compat_libevent.c
index b7987bc,835d3b8..61cbe91
--- a/src/common/compat_libevent.c
+++ b/src/common/compat_libevent.c
@@@ -661,15 -651,35 +661,45 @@@ tor_gettimeofday_cache_clear(void
  {
    cached_time_hires.tv_sec = 0;
  }
 +
 +#ifdef TOR_UNIT_TESTS
 +/** For testing: force-update the cached time to a given value. */
 +void
 +tor_gettimeofday_cache_set(const struct timeval *tv)
 +{
 +  tor_assert(tv);
 +  memcpy(&cached_time_hires, tv, sizeof(*tv));
 +}
 +#endif
  #endif
  
+ /**
+  * As tor_gettimeofday_cached, but can never move backwards in time.
+  *
+  * The returned value may diverge from wall-clock time, since wall-clock time
+  * can trivially be adjusted backwards, and this can't.  Don't mix wall-clock
+  * time with these values in the same calculation.
+  *
+  * Depending on implementation, this function may or may not "smooth out" huge
+  * jumps forward in wall-clock time.  It may or may not keep its results
+  * advancing forward (as opposed to stalling) if the wall-clock time goes
+  * backwards.  The current implementation does neither of of these.
+  *
+  * This function is not thread-safe; do not call it outside the main thread.
+  *
+  * In future versions of Tor, this may return a time does not have its
+  * origin at the Unix epoch.
+  */
+ void
+ tor_gettimeofday_cached_monotonic(struct timeval *tv)
+ {
+   struct timeval last_tv = { 0, 0 };
+ 
+   tor_gettimeofday_cached(tv);
+   if (timercmp(tv, &last_tv, <)) {
+     memcpy(tv, &last_tv, sizeof(struct timeval));
+   } else {
+     memcpy(&last_tv, tv, sizeof(struct timeval));
+   }
+ }
+ 
diff --cc src/common/compat_libevent.h
index 17e0523,b5f6445..f0d1828
--- a/src/common/compat_libevent.h
+++ b/src/common/compat_libevent.h
@@@ -91,9 -90,7 +91,10 @@@ int tor_add_bufferevent_to_rate_limit_g
  
  void tor_gettimeofday_cached(struct timeval *tv);
  void tor_gettimeofday_cache_clear(void);
 +#ifdef TOR_UNIT_TESTS
 +void tor_gettimeofday_cache_set(const struct timeval *tv);
 +#endif
+ void tor_gettimeofday_cached_monotonic(struct timeval *tv);
  
  #endif
  
diff --cc src/or/relay.c
index dbc1710,857b7e9..93e1ddd
--- a/src/or/relay.c
+++ b/src/or/relay.c
@@@ -2148,12 -2151,40 +2148,13 @@@ cell_queue_append_packed_copy(circuit_
  {
    struct timeval now;
    packed_cell_t *copy = packed_cell_copy(cell, wide_circ_ids);
 +  (void)circ;
 +  (void)exitward;
 +  (void)use_stats;
-   tor_gettimeofday_cached(&now);
+   tor_gettimeofday_cached_monotonic(&now);
+ 
    copy->inserted_time = (uint32_t)tv_to_msec(&now);
  
 -  /* Remember the time when this cell was put in the queue. */
 -  /*XXXX This may be obsoleted by inserted_time */
 -  if (get_options()->CellStatistics) {
 -    uint32_t added;
 -    insertion_time_queue_t *it_queue = queue->insertion_times;
 -    if (!it_pool)
 -      it_pool = mp_pool_new(sizeof(insertion_time_elem_t), 1024);
 -
 -#define SECONDS_IN_A_DAY 86400L
 -    added = (uint32_t)(((now.tv_sec % SECONDS_IN_A_DAY) * 100L)
 -            + ((uint32_t)now.tv_usec / (uint32_t)10000L));
 -    if (!it_queue) {
 -      it_queue = tor_malloc_zero(sizeof(insertion_time_queue_t));
 -      queue->insertion_times = it_queue;
 -    }
 -    if (it_queue->last && it_queue->last->insertion_time == added) {
 -      it_queue->last->counter++;
 -    } else {
 -      insertion_time_elem_t *elem = mp_pool_get(it_pool);
 -      elem->next = NULL;
 -      elem->insertion_time = added;
 -      elem->counter = 1;
 -      if (it_queue->last) {
 -        it_queue->last->next = elem;
 -        it_queue->last = elem;
 -      } else {
 -        it_queue->first = it_queue->last = elem;
 -      }
 -    }
 -  }
    cell_queue_append(queue, copy);
  }
  



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits