Ticket #12474: 0001-src-or-connection.c-expose-bucket_millis_empty-for-b.patch

File 0001-src-or-connection.c-expose-bucket_millis_empty-for-b.patch, 4.5 KB (added by blueness, 5 years ago)
  • src/or/connection.c

    From aa3d955dffa96b412666a9449de9bbc16767a027 Mon Sep 17 00:00:00 2001
    From: "Anthony G. Basile" <blueness@gentoo.org>
    Date: Thu, 26 Jun 2014 11:15:36 -0400
    Subject: [PATCH] src/or/connection.c: expose bucket_millis_empty for
     bufferevents test
    
    Currently tor fails to build its test when enabled with bufferevents
    because an #ifndef USE_BUFFEREVENTS hides bucket_millis_empty() and
    friends.  This is fine if we don't run tests, but if we do, we need
    these functions in src/or/libtor-testing.a when linking src/test/test.
    
    This patch moves the functions outside the #ifndef and exposes them.
    
    See downstream bug:
    
    	https://bugs.gentoo.org/show_bug.cgi?id=510124
    ---
     src/or/connection.c | 60 ++++++++++++++++++++++++++---------------------------
     1 file changed, 30 insertions(+), 30 deletions(-)
    
    diff --git a/src/or/connection.c b/src/or/connection.c
    index 0b03092..4788bdf 100644
    a b record_num_bytes_transferred(connection_t *conn, 
    26502650}
    26512651#endif
    26522652
    2653 #ifndef USE_BUFFEREVENTS
    2654 /** Last time at which the global or relay buckets were emptied in msec
    2655  * since midnight. */
    2656 static uint32_t global_relayed_read_emptied = 0,
    2657                 global_relayed_write_emptied = 0,
    2658                 global_read_emptied = 0,
    2659                 global_write_emptied = 0;
    2660 
    26612653/** Helper: convert given <b>tvnow</b> time value to milliseconds since
    26622654 * midnight. */
    26632655static uint32_t
    msec_since_midnight(const struct timeval *tvnow) 
    26672659         ((uint32_t)tvnow->tv_usec / (uint32_t)1000L));
    26682660}
    26692661
     2662/** Helper: return the time in milliseconds since <b>last_empty_time</b>
     2663 * when a bucket ran empty that previously had <b>tokens_before</b> tokens
     2664 * now has <b>tokens_after</b> tokens after refilling at timestamp
     2665 * <b>tvnow</b>, capped at <b>milliseconds_elapsed</b> milliseconds since
     2666 * last refilling that bucket.  Return 0 if the bucket has not been empty
     2667 * since the last refill or has not been refilled. */
     2668uint32_t
     2669bucket_millis_empty(int tokens_before, uint32_t last_empty_time,
     2670                    int tokens_after, int milliseconds_elapsed,
     2671                    const struct timeval *tvnow)
     2672{
     2673  uint32_t result = 0, refilled;
     2674  if (tokens_before <= 0 && tokens_after > tokens_before) {
     2675    refilled = msec_since_midnight(tvnow);
     2676    result = (uint32_t)((refilled + 86400L * 1000L - last_empty_time) %
     2677             (86400L * 1000L));
     2678    if (result > (uint32_t)milliseconds_elapsed)
     2679      result = (uint32_t)milliseconds_elapsed;
     2680  }
     2681  return result;
     2682}
     2683
    26702684/** Check if a bucket which had <b>tokens_before</b> tokens and which got
    26712685 * <b>tokens_removed</b> tokens removed at timestamp <b>tvnow</b> has run
    26722686 * out of tokens, and if so, note the milliseconds since midnight in
    connection_buckets_note_empty_ts(uint32_t *timestamp_var, 
    26802694    *timestamp_var = msec_since_midnight(tvnow);
    26812695}
    26822696
     2697#ifndef USE_BUFFEREVENTS
     2698/** Last time at which the global or relay buckets were emptied in msec
     2699 * since midnight. */
     2700static uint32_t global_relayed_read_emptied = 0,
     2701                global_relayed_write_emptied = 0,
     2702                global_read_emptied = 0,
     2703                global_write_emptied = 0;
     2704
    26832705/** We just read <b>num_read</b> and wrote <b>num_written</b> bytes
    26842706 * onto <b>conn</b>. Decrement buckets appropriately. */
    26852707static void
    connection_bucket_refill_helper(int *bucket, int rate, int burst, 
    28382860  }
    28392861}
    28402862
    2841 /** Helper: return the time in milliseconds since <b>last_empty_time</b>
    2842  * when a bucket ran empty that previously had <b>tokens_before</b> tokens
    2843  * now has <b>tokens_after</b> tokens after refilling at timestamp
    2844  * <b>tvnow</b>, capped at <b>milliseconds_elapsed</b> milliseconds since
    2845  * last refilling that bucket.  Return 0 if the bucket has not been empty
    2846  * since the last refill or has not been refilled. */
    2847 uint32_t
    2848 bucket_millis_empty(int tokens_before, uint32_t last_empty_time,
    2849                     int tokens_after, int milliseconds_elapsed,
    2850                     const struct timeval *tvnow)
    2851 {
    2852   uint32_t result = 0, refilled;
    2853   if (tokens_before <= 0 && tokens_after > tokens_before) {
    2854     refilled = msec_since_midnight(tvnow);
    2855     result = (uint32_t)((refilled + 86400L * 1000L - last_empty_time) %
    2856              (86400L * 1000L));
    2857     if (result > (uint32_t)milliseconds_elapsed)
    2858       result = (uint32_t)milliseconds_elapsed;
    2859   }
    2860   return result;
    2861 }
    2862 
    28632863/** Time has passed; increment buckets appropriately. */
    28642864void
    28652865connection_bucket_refill(int milliseconds_elapsed, time_t now)