summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2007-05-30 07:18:00 +0000
committerNick Mathewson <nickm@torproject.org>2007-05-30 07:18:00 +0000
commit1cb1ebbfe030b0fe7c2d369140a5ae5581af4ce3 (patch)
treeba1add5ef00c47032a7060fbb47d7fd4a8b93bbd
parent8b1e9398a8d2dd3df48a47a98782ac5f46f10f3d (diff)
downloadtor-1cb1ebbfe030b0fe7c2d369140a5ae5581af4ce3.tar.gz
tor-1cb1ebbfe030b0fe7c2d369140a5ae5581af4ce3.zip
r13090@catbus: nickm | 2007-05-30 03:17:57 -0400
If the user makes a torrc that exceeds the bandwidth cap by one byte, let them have it. svn:r10411
-rw-r--r--ChangeLog2
-rw-r--r--src/or/config.c21
2 files changed, 15 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index db3a77a222..75e36c4728 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -119,6 +119,8 @@ Changes in version 0.2.0.1-alpha - 2007-??-??
patterns can be reconfigured with AutomapHostsSuffixes.
- If Tor is invoked from something that isn't a shell (e.g. Vidalia),
now we expand "-f ~/.tor/torrc" correctly. Suggested by Matt Edman.
+ - Treat "2gb" when given in torrc for a bandwidth as meaning 2gb, minus 1
+ byte: the actual maximum declared bandwidth.
o Removed features:
- Removed support for the old binary "version 0" controller protocol.
diff --git a/src/or/config.c b/src/or/config.c
index 961d6887ef..165b2e5340 100644
--- a/src/or/config.c
+++ b/src/or/config.c
@@ -2322,13 +2322,18 @@ validate_ports_csv(smartlist_t *sl, const char *name, char **msg)
* Else return 0.
*/
static int
-ensure_bandwidth_cap(uint64_t value, const char *desc, char **msg)
+ensure_bandwidth_cap(uint64_t *value, const char *desc, char **msg)
{
int r;
char buf[1024];
- if (value > ROUTER_MAX_DECLARED_BANDWIDTH) {
+ if (*value == ROUTER_MAX_DECLARED_BANDWIDTH) {
+ /* This handles an understandable special case where somebody says "2gb"
+ * whereas our actual maximum is 2gb-1 (INT_MAX) */
+ --*value;
+ }
+ if (*value > ROUTER_MAX_DECLARED_BANDWIDTH) {
r = tor_snprintf(buf, sizeof(buf), "%s ("U64_FORMAT") must be at most %d",
- desc, U64_PRINTF_ARG(value),
+ desc, U64_PRINTF_ARG(*value),
ROUTER_MAX_DECLARED_BANDWIDTH);
*msg = tor_strdup(r >= 0 ? buf : "internal error");
return -1;
@@ -2761,19 +2766,19 @@ options_validate(or_options_t *old_options, or_options_t *options,
if (options->KeepalivePeriod < 1)
REJECT("KeepalivePeriod option must be positive.");
- if (ensure_bandwidth_cap(options->BandwidthRate,
+ if (ensure_bandwidth_cap(&options->BandwidthRate,
"BandwidthRate", msg) < 0)
return -1;
- if (ensure_bandwidth_cap(options->BandwidthBurst,
+ if (ensure_bandwidth_cap(&options->BandwidthBurst,
"BandwidthBurst", msg) < 0)
return -1;
- if (ensure_bandwidth_cap(options->MaxAdvertisedBandwidth,
+ if (ensure_bandwidth_cap(&options->MaxAdvertisedBandwidth,
"MaxAdvertisedBandwidth", msg) < 0)
return -1;
- if (ensure_bandwidth_cap(options->RelayBandwidthRate,
+ if (ensure_bandwidth_cap(&options->RelayBandwidthRate,
"RelayBandwidthRate", msg) < 0)
return -1;
- if (ensure_bandwidth_cap(options->RelayBandwidthBurst,
+ if (ensure_bandwidth_cap(&options->RelayBandwidthBurst,
"RelayBandwidthBurst", msg) < 0)
return -1;