From 50a50392b7d65409de4416eb604bec6339670a2c Mon Sep 17 00:00:00 2001 From: Sebastian Hahn Date: Tue, 25 Jan 2011 16:45:27 +0100 Subject: Advertise dirport if accountingmax is large enough When we have an effective bandwidthrate configured so that we cannot exceed our bandwidth limit in one accounting interval, don't disable advertising the dirport. Implements ticket 2434. --- src/or/router.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'src/or/router.c') diff --git a/src/or/router.c b/src/or/router.c index a08a2009a7..b2df3834fe 100644 --- a/src/or/router.c +++ b/src/or/router.c @@ -823,9 +823,26 @@ decide_to_advertise_dirport(const or_options_t *options, uint16_t dir_port) * make us choose not to publish. */ if (accounting_is_enabled(options)) { - /* if we might potentially hibernate */ - new_choice = 0; - reason = "AccountingMax enabled"; + /* Don't spend bytes for directory traffic if we could end up hibernating, + * but allow DirPort otherwise. Some people set AccountingMax because + * they're confused or to get statistics. */ + int interval_length = accounting_get_interval_length(); + uint32_t effective_bw = get_effective_bwrate(options); + if (!interval_length) { + log_warn(LD_BUG, "An accounting interval is not allowed to be zero " + "seconds long. Raising to 1."); + interval_length = 1; + } + log_info(LD_GENERAL, "Calculating whether to disable dirport: effective " + "bwrate: %u, AccountingMax: "U64_FORMAT", " + "accounting interval length %d", effective_bw, + U64_PRINTF_ARG(options->AccountingMax), + interval_length); + if (effective_bw >= + options->AccountingMax / interval_length) { + new_choice = 0; + reason = "AccountingMax enabled"; + } #define MIN_BW_TO_ADVERTISE_DIRPORT 51200 } else if (options->BandwidthRate < MIN_BW_TO_ADVERTISE_DIRPORT || (options->RelayBandwidthRate > 0 && -- cgit v1.2.3-54-g00ecf