Ticket #961: fix_961.patch

File fix_961.patch, 3.1 KB (added by chobe, 4 years ago)
  • src/or/config.c

    From 9be177aa7f46d432641558ebffb9e3b2672b9895 Mon Sep 17 00:00:00 2001
    From: Scott Griffy <scottgriffy@gmail.com>
    Date: Thu, 4 Sep 2014 19:56:52 -0700
    Subject: [PATCH] fix for 961, add AccoutingRule to check sum or max of in/out
    
    ---
     src/or/config.c    |    1 +
     src/or/hibernate.c |   21 +++++++++++++++++----
     src/or/or.h        |    4 ++++
     3 files changed, 22 insertions(+), 4 deletions(-)
    
    diff --git a/src/or/config.c b/src/or/config.c
    index 7800ec1..2cc5075 100644
    a b static config_abbrev_t option_abbrevs_[] = { 
    129129static config_var_t option_vars_[] = {
    130130  OBSOLETE("AccountingMaxKB"),
    131131  V(AccountingMax,               MEMUNIT,  "0 bytes"),
     132  V(AccountingRule,              STRING,  "max"),
    132133  V(AccountingStart,             STRING,   NULL),
    133134  V(Address,                     STRING,   NULL),
    134135  V(AllowDotExit,                BOOL,     "0"),
  • src/or/hibernate.c

    diff --git a/src/or/hibernate.c b/src/or/hibernate.c
    index c433ac1..16e943b 100644
    a b read_bandwidth_usage(void) 
    707707  return 0;
    708708}
    709709
     710/** Return true iff the we have hit the given limit according
     711 * to the configured "AccountingRule" */
     712static int
     713check_reached_limit(int limit)
     714{
     715 
     716  if (strcmp(get_options()->AccountingRule, "sum") == 0)
     717    return n_bytes_read_in_interval+n_bytes_written_in_interval >= limit;
     718  else
     719  if (strcmp(get_options()->AccountingRule, "max") != 0)
     720    log_info(LD_GENERAL, "Weird AccountingRule given, defaulting to 'max'");
     721  return n_bytes_read_in_interval >= limit
     722    || n_bytes_written_in_interval >= limit;
     723}
     724
    710725/** Return true iff we have sent/received all the bytes we are willing
    711726 * to send/receive this interval. */
    712727static int
    hibernate_hard_limit_reached(void) 
    715730  uint64_t hard_limit = get_options()->AccountingMax;
    716731  if (!hard_limit)
    717732    return 0;
    718   return n_bytes_read_in_interval >= hard_limit
    719     || n_bytes_written_in_interval >= hard_limit;
     733  return check_reached_limit(hard_limit);
    720734}
    721735
    722736/** Return true iff we have sent/received almost all the bytes we are willing
    hibernate_soft_limit_reached(void) 
    747761
    748762  if (!soft_limit)
    749763    return 0;
    750   return n_bytes_read_in_interval >= soft_limit
    751     || n_bytes_written_in_interval >= soft_limit;
     764  return check_reached_limit(soft_limit);
    752765}
    753766
    754767/** Called when we get a SIGINT, or when bandwidth soft limit is
  • src/or/or.h

    diff --git a/src/or/or.h b/src/or/or.h
    index 3683607..6d98c99 100644
    a b typedef struct { 
    37903790  uint64_t AccountingMax; /**< How many bytes do we allow per accounting
    37913791                           * interval before hibernation?  0 for "never
    37923792                           * hibernate." */
     3793  char *AccountingRule; /**< How do we determine when our AccountingMax
     3794                         * has been reached?
     3795                         * "max" for when in or out reaches AccountingMax
     3796                         * "sum for when in plus out reaches AccountingMax */
    37933797
    37943798  /** Base64-encoded hash of accepted passwords for the control system. */
    37953799  config_line_t *HashedControlPassword;