aboutsummaryrefslogtreecommitdiff
path: root/src/or
diff options
context:
space:
mode:
authorMatthew Finkel <Matthew.Finkel@gmail.com>2015-02-08 06:51:51 +0000
committerNick Mathewson <nickm@torproject.org>2015-12-18 13:14:09 -0500
commit997f779a7f05540e5f564b4d121706c4a7069fb2 (patch)
tree178b3ebdea0f52d9bb0a67a632bd70b20d852f33 /src/or
parente0bd6cdef25d7cdcff18d2bce7865aa7acc1f2b8 (diff)
downloadtor-997f779a7f05540e5f564b4d121706c4a7069fb2.tar.gz
tor-997f779a7f05540e5f564b4d121706c4a7069fb2.zip
Add new DirCache configuration option
This will give relay operators the ability of disabling the caching of directory data. In general, this should not be necessary, but on some lower-resource systems it may beneficial.
Diffstat (limited to 'src/or')
-rw-r--r--src/or/config.c61
-rw-r--r--src/or/config.h2
-rw-r--r--src/or/or.h4
-rw-r--r--src/or/router.c4
4 files changed, 70 insertions, 1 deletions
diff --git a/src/or/config.c b/src/or/config.c
index 9ec47d2459..f9cab9f670 100644
--- a/src/or/config.c
+++ b/src/or/config.c
@@ -222,6 +222,7 @@ static config_var_t option_vars_[] = {
V(DirPortFrontPage, FILENAME, NULL),
VAR("DirReqStatistics", BOOL, DirReqStatistics_option, "1"),
VAR("DirAuthority", LINELIST, DirAuthorities, NULL),
+ V(DirCache, BOOL, "1"),
V(DirAuthorityFallbackRate, DOUBLE, "1.0"),
V(DisableAllSwap, BOOL, "0"),
V(DisableDebuggerAttachment, BOOL, "1"),
@@ -3457,6 +3458,24 @@ options_validate(or_options_t *old_options, or_options_t *options,
REJECT("AccountingRule must be 'sum' or 'max'");
}
+ if (options->DirPort_set && !options->DirCache) {
+ REJECT("DirPort configured but DirCache disabled. DirPort requires "
+ "DirCache.");
+ }
+
+ if (options->BridgeRelay && !options->DirCache) {
+ REJECT("We're a bridge but DirCache is disabled. BridgeRelay requires "
+ "DirCache.");
+ }
+
+ if (server_mode(options)) {
+ char *msg = NULL;
+ if (have_enough_mem_for_dircache(options, 0, &msg)) {
+ log_warn(LD_CONFIG, "%s", msg);
+ tor_free(msg);
+ }
+ }
+
if (options->HTTPProxy) { /* parse it now */
if (tor_addr_port_lookup(options->HTTPProxy,
&options->HTTPProxyAddr, &options->HTTPProxyPort) < 0)
@@ -4065,6 +4084,48 @@ compute_real_max_mem_in_queues(const uint64_t val, int log_guess)
}
}
+/* If we have less than 300 MB suggest disabling dircache */
+#define DIRCACHE_MIN_MB_BANDWIDTH 300
+#define DIRCACHE_MIN_BANDWIDTH (DIRCACHE_MIN_MB_BANDWIDTH*ONE_MEGABYTE)
+#define STRINGIFY(val) #val
+
+/** Create a warning message for emitting if we are a dircache but may not have
+ * enough system memory, or if we are not a dircache but probably should be.
+ * Return -1 when a message is returned in *msg*, else return 0. */
+STATIC int
+have_enough_mem_for_dircache(const or_options_t *options, size_t total_mem,
+ char **msg)
+{
+ *msg = NULL;
+ if (total_mem == 0) {
+ if (get_total_system_memory(&total_mem) < 0)
+ total_mem = options->MaxMemInQueues;
+ }
+ if (options->DirCache) {
+ if (total_mem < DIRCACHE_MIN_BANDWIDTH) {
+ if (options->BridgeRelay) {
+ *msg = strdup("Running a Bridge with less than "
+ STRINGIFY(DIRCACHE_MIN_MB_BANDWIDTH) " MB of memory is "
+ "not recommended.");
+ } else {
+ *msg = strdup("Being a directory cache (default) with less than "
+ STRINGIFY(DIRCACHE_MIN_MB_BANDWIDTH) " MB of memory is "
+ "not recommended and may consume most of the available "
+ "resources, consider disabling this functionality by "
+ "setting the DirCache option to 0.");
+ }
+ }
+ } else {
+ if (total_mem >= DIRCACHE_MIN_BANDWIDTH) {
+ *msg = strdup("DirCache is disabled and we are configured as a "
+ "relay. This may disqualify us from becoming a guard in the "
+ "future.");
+ }
+ }
+ return *msg == NULL ? 0 : -1;
+}
+#undef STRINGIFY
+
/** Helper: return true iff s1 and s2 are both NULL, or both non-NULL
* equal strings. */
static int
diff --git a/src/or/config.h b/src/or/config.h
index bfdd1694eb..6e08f9d178 100644
--- a/src/or/config.h
+++ b/src/or/config.h
@@ -158,6 +158,8 @@ STATIC int parse_dir_authority_line(const char *line,
dirinfo_type_t required_type,
int validate_only);
STATIC int parse_dir_fallback_line(const char *line, int validate_only);
+STATIC int have_enough_mem_for_dircache(const or_options_t *options,
+ size_t total_mem, char **msg);
#endif
#endif
diff --git a/src/or/or.h b/src/or/or.h
index 3cb1e7d7ef..89c539817f 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -3969,6 +3969,10 @@ typedef struct {
/** Should we fetch our dir info at the start of the consensus period? */
int FetchDirInfoExtraEarly;
+ int DirCache; /**< Cache all directory documents and accept requests via
+ * tunnelled dir conns from clients. If 1, enabled (default);
+ * If 0, disabled. */
+
char *VirtualAddrNetworkIPv4; /**< Address and mask to hand out for virtual
* MAPADDRESS requests for IPv4 addresses */
char *VirtualAddrNetworkIPv6; /**< Address and mask to hand out for virtual
diff --git a/src/or/router.c b/src/or/router.c
index 1927cfd38b..5e4f855410 100644
--- a/src/or/router.c
+++ b/src/or/router.c
@@ -1176,7 +1176,9 @@ router_should_be_directory_server(const or_options_t *options, int dir_port)
int
dir_server_mode(const or_options_t *options)
{
- return (server_mode(options) || options->DirPort_set) &&
+ if (!options->DirCache)
+ return 0;
+ return (server_mode(options) || options->DirPort_set) &&
router_should_be_directory_server(options, 0);
}