]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Merge remote-tracking branch 'origin/maint-0.2.3' into maint-0.2.4
authorNick Mathewson <nickm@torproject.org>
Fri, 15 Nov 2013 20:29:24 +0000 (15:29 -0500)
committerNick Mathewson <nickm@torproject.org>
Fri, 15 Nov 2013 20:29:24 +0000 (15:29 -0500)
Conflicts:
src/or/or.h
src/or/relay.c

Conflicts were simple to resolve.  More fixes were needed for
compilation, including: reinstating the tv_to_msec function, and renaming
*_conn_cells to *_chan_cells.

1  2 
src/common/util.c
src/common/util.h
src/or/circuitlist.c
src/or/or.h
src/or/relay.c

index ae385e1b9401ebd15f072db92eb753b7ba76f573,b16afa13e9f1358a60a5a9bc921b658b388e25f6..5eb0f9a69bc8756a04a0bde631942f3dfd55b6d9
@@@ -1232,6 -1322,6 +1232,18 @@@ tv_mdiff(const struct timeval *start, c
    return mdiff;
  }
  
++/**
++ * Converts timeval to milliseconds.
++ */
++int64_t
++tv_to_msec(const struct timeval *tv)
++{
++  int64_t conv = ((int64_t)tv->tv_sec)*1000L;
++  /* Round ghetto-style */
++  conv += ((int64_t)tv->tv_usec+500)/1000L;
++  return conv;
++}
++
  /** Yield true iff <b>y</b> is a leap-year. */
  #define IS_LEAPYEAR(y) (!(y % 4) && ((y % 100) || !(y % 400)))
  /** Helper: Return the number of leap-days between Jan 1, y1 and Jan 1, y2. */
index 96a02dd77572aeb861e1ccd2c1454a1bac548cff,8977d273c50f5aa6b407dc0b3fa2a32262f47244..73daa6e2a1ffc7a37d50277a73883ac21cfd54c6
@@@ -251,8 -239,11 +251,9 @@@ void base16_encode(char *dest, size_t d
  int base16_decode(char *dest, size_t destlen, const char *src, size_t srclen);
  
  /* Time helpers */
 -double tv_to_double(const struct timeval *tv);
 -int64_t tv_to_msec(const struct timeval *tv);
 -int64_t tv_to_usec(const struct timeval *tv);
  long tv_udiff(const struct timeval *start, const struct timeval *end);
  long tv_mdiff(const struct timeval *start, const struct timeval *end);
++int64_t tv_to_msec(const struct timeval *tv);
  int tor_timegm(const struct tm *tm, time_t *time_out);
  #define RFC1123_TIME_LEN 29
  void format_rfc1123_time(char *buf, time_t t);
index daeaa37b1edec28f1edf613c4a218081ba01729b,6250c11d2efc3a9d3397a0372604f269d190afd2..b0e24a5fee80aad815d1a221fd29e11a2b11bac1
@@@ -1525,10 -1383,41 +1525,41 @@@ n_cells_in_circ_queues(const circuit_t 
    return n;
  }
  
- /** helper to sort a list of circuit_q by total queue lengths, in descending
-  * order. */
+ /**
+  * Return the age of the oldest cell queued on <b>c</b>, in milliseconds.
+  * Return 0 if there are no cells queued on c.  Requires that <b>now</b> be
+  * the current time in milliseconds since the epoch, truncated.
+  *
+  * This function will return incorrect results if the oldest cell queued on
+  * the circuit is older than 2**32 msec (about 49 days) old.
+  */
+ static uint32_t
+ circuit_max_queued_cell_age(const circuit_t *c, uint32_t now)
+ {
+   uint32_t age = 0;
 -  if (c->n_conn_cells.head)
 -    age = now - c->n_conn_cells.head->inserted_time;
++  if (c->n_chan_cells.head)
++    age = now - c->n_chan_cells.head->inserted_time;
+   if (! CIRCUIT_IS_ORIGIN(c)) {
+     const or_circuit_t *orcirc = TO_OR_CIRCUIT((circuit_t*)c);
 -    if (orcirc->p_conn_cells.head) {
 -      uint32_t age2 = now - orcirc->p_conn_cells.head->inserted_time;
++    if (orcirc->p_chan_cells.head) {
++      uint32_t age2 = now - orcirc->p_chan_cells.head->inserted_time;
+       if (age2 > age)
+         return age2;
+     }
+   }
+   return age;
+ }
+ /** Temporary variable for circuits_compare_by_oldest_queued_cell_ This is a
+  * kludge to work around the fact that qsort doesn't provide a way for
+  * comparison functions to take an extra argument. */
+ static uint32_t circcomp_now_tmp;
+ /** Helper to sort a list of circuit_t by age of oldest cell, in descending
+  * order. Requires that circcomp_now_tmp is set correctly. */
  static int
- circuits_compare_by_queue_len_(const void **a_, const void **b_)
+ circuits_compare_by_oldest_queued_cell_(const void **a_, const void **b_)
  {
    const circuit_t *a = *a_;
    const circuit_t *b = *b_;
diff --cc src/or/or.h
index eff5a6d2b47ecda8d6e446a5530d83da76cf7a3b,462239190b0040667df57ecabefc8f686965e436..5318b0fe5d1b2deb8d459365e3d47747dde49202
@@@ -1076,9 -911,14 +1076,14 @@@ typedef struct var_cell_t 
  /** A cell as packed for writing to the network. */
  typedef struct packed_cell_t {
    struct packed_cell_t *next; /**< Next cell queued on this circuit. */
 -  char body[CELL_NETWORK_SIZE]; /**< Cell as packed for network. */
 +  char body[CELL_MAX_NETWORK_SIZE]; /**< Cell as packed for network. */
+   uint32_t inserted_time; /**< Time (in milliseconds since epoch, with high
+                            * bits truncated) when this cell was inserted. */
  } packed_cell_t;
  
+ /* XXXX This next structure may be obsoleted by inserted_time in
+  * packed_cell_t */
  /** Number of cells added to a circuit queue including their insertion
   * time on 10 millisecond detail; used for buffer statistics. */
  typedef struct insertion_time_elem_t {
diff --cc src/or/relay.c
index 29dc36194aaf92edc09c8d93b393b3fd9b7ca51f,a193ad8431f6f3c435c973d8e850f8e4a2d3da07..63119cbf07d1ebffd9af5dc2715d6e7ce2a2d5c1
@@@ -2146,13 -1902,16 +2146,17 @@@ cell_queue_append(cell_queue_t *queue, 
  
  /** Append a newly allocated copy of <b>cell</b> to the end of <b>queue</b> */
  void
 -cell_queue_append_packed_copy(cell_queue_t *queue, const cell_t *cell)
 +cell_queue_append_packed_copy(cell_queue_t *queue, const cell_t *cell,
 +                              int wide_circ_ids)
  {
 -  packed_cell_t *copy = packed_cell_copy(cell);
+   struct timeval now;
 +  packed_cell_t *copy = packed_cell_copy(cell, wide_circ_ids);
+   tor_gettimeofday_cached(&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) {
-     struct timeval now;
      uint32_t added;
      insertion_time_queue_t *it_queue = queue->insertion_times;
      if (!it_pool)