aboutsummaryrefslogtreecommitdiff
path: root/src/or/config.c
diff options
context:
space:
mode:
authorRoger Dingledine <arma@torproject.org>2007-05-04 09:20:13 +0000
committerRoger Dingledine <arma@torproject.org>2007-05-04 09:20:13 +0000
commitb1d93df038d687c706cfcdfd72254457eefd3322 (patch)
tree39528b9441e6b01cb271691ed5d67c971001116b /src/or/config.c
parentdc795203aa0b5ced09e84cb221c6988d934f51c5 (diff)
downloadtor-b1d93df038d687c706cfcdfd72254457eefd3322.tar
tor-b1d93df038d687c706cfcdfd72254457eefd3322.tar.gz
if you're using relaybandwidthrate and relaybandwidthburst, make
sure that's reflected in your router descriptor. svn:r10114
Diffstat (limited to 'src/or/config.c')
-rw-r--r--src/or/config.c44
1 files changed, 32 insertions, 12 deletions
diff --git a/src/or/config.c b/src/or/config.c
index 6755ebf60..e3929169e 100644
--- a/src/or/config.c
+++ b/src/or/config.c
@@ -2275,6 +2275,24 @@ validate_ports_csv(smartlist_t *sl, const char *name, char **msg)
return 0;
}
+/** If <b>value</b> exceeds ROUTER_MAX_DECLARED_BANDWIDTH, write
+ * a complaint into *<b>msg</b> using string <b>desc</b>, and return -1.
+ * Else return 0.
+ */
+static int
+ensure_bandwidth_cap(uint64_t value, const char *desc, char **msg)
+{
+ int r;
+ char buf[1024];
+ if (value > ROUTER_MAX_DECLARED_BANDWIDTH) {
+ r = tor_snprintf(buf, sizeof(buf), "%s must be at most %d",
+ desc, ROUTER_MAX_DECLARED_BANDWIDTH);
+ *msg = tor_strdup(r >= 0 ? buf : "internal error");
+ return -1;
+ }
+ return 0;
+}
+
/** Lowest allowable value for RendPostPeriod; if this is too low, hidden
* services can overload the directory system. */
#define MIN_REND_POST_PERIOD (10*60)
@@ -2644,20 +2662,22 @@ options_validate(or_options_t *old_options, or_options_t *options,
if (options->KeepalivePeriod < 1)
REJECT("KeepalivePeriod option must be positive.");
- if (options->BandwidthRate > ROUTER_MAX_DECLARED_BANDWIDTH) {
- r = tor_snprintf(buf, sizeof(buf),
- "BandwidthRate must be at most %d",
- ROUTER_MAX_DECLARED_BANDWIDTH);
- *msg = tor_strdup(r >= 0 ? buf : "internal error");
+ if (ensure_bandwidth_cap(options->BandwidthRate,
+ "BandwidthRate", msg) < 0)
return -1;
- }
- if (options->BandwidthBurst > ROUTER_MAX_DECLARED_BANDWIDTH) {
- r = tor_snprintf(buf, sizeof(buf),
- "BandwidthBurst must be at most %d",
- ROUTER_MAX_DECLARED_BANDWIDTH);
- *msg = tor_strdup(r >= 0 ? buf : "internal error");
+ if (ensure_bandwidth_cap(options->BandwidthBurst,
+ "BandwidthBurst", msg) < 0)
return -1;
- }
+ if (ensure_bandwidth_cap(options->MaxAdvertisedBandwidth,
+ "MaxAdvertisedBandwidth", msg) < 0)
+ return -1;
+ if (ensure_bandwidth_cap(options->RelayBandwidthRate,
+ "RelayBandwidthRate", msg) < 0)
+ return -1;
+ if (ensure_bandwidth_cap(options->RelayBandwidthBurst,
+ "RelayBandwidthBurst", msg) < 0)
+ return -1;
+
if (server_mode(options)) {
if (options->BandwidthRate < ROUTER_REQUIRED_MIN_BANDWIDTH*2) {
r = tor_snprintf(buf, sizeof(buf),