]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Merge remote-tracking branch 'public/bug10169_024' into bug10169_025_v2
authorNick Mathewson <nickm@torproject.org>
Tue, 4 Mar 2014 16:00:02 +0000 (11:00 -0500)
committerNick Mathewson <nickm@torproject.org>
Tue, 4 Mar 2014 16:00:02 +0000 (11:00 -0500)
Conflicts:
src/common/compat_libevent.h
src/or/relay.c

1  2 
src/common/compat_libevent.c
src/common/compat_libevent.h
src/or/buffers.c
src/or/circuitlist.c
src/or/relay.c

index b7987bc99afa27899610ccc9b40c99845c1f6325,835d3b83d7995a03de28d8157098c2e9224158ea..61cbe91488b8deaabebdaf172c08f31372b6deb1
@@@ -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));
+   }
+ }
index 17e05237891090b03b9cbaae4bdc120ef9458368,b5f6445471a55addce68a2759c5d922120c8607a..f0d1828b7bf98d03861cb88cbf7b11b538b66d20
@@@ -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
  
Simple merge
Simple merge
diff --cc src/or/relay.c
index dbc171059471b2d80a6c76a1ca51ea10dd2a60c3,857b7e9d3010947886ec3b3823c738adceeb9902..93e1ddd201f772ba7bb878ee4e10edf596b9218a
@@@ -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);
-   tor_gettimeofday_cached(&now);
 +  (void)circ;
 +  (void)exitward;
 +  (void)use_stats;
+   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);
  }