summaryrefslogtreecommitdiff
path: root/src/or/config.c
diff options
context:
space:
mode:
authorDavid Goulet <dgoulet@torproject.org>2017-09-14 13:23:43 -0400
committerDavid Goulet <dgoulet@torproject.org>2017-09-15 11:40:59 -0400
commit7cc9621d115303ab71d8cf8e49f5dfe428636145 (patch)
treedb1904c51fdf33bb7184c4c20c413045898e98b4 /src/or/config.c
parent6ff8c86ac663914901b4ea9ce64c20b59bec6011 (diff)
downloadtor-7cc9621d115303ab71d8cf8e49f5dfe428636145.tar.gz
tor-7cc9621d115303ab71d8cf8e49f5dfe428636145.zip
sched: Add Schedulers torrc option
This option is a list of possible scheduler type tor can use ordered by priority. Its default value is "KIST,KISTLite,Vanilla" which means that KIST will be used first and if unavailable will fallback to KISTLite and so on. Signed-off-by: David Goulet <dgoulet@torproject.org>
Diffstat (limited to 'src/or/config.c')
-rw-r--r--src/or/config.c77
1 files changed, 64 insertions, 13 deletions
diff --git a/src/or/config.c b/src/or/config.c
index f332ac97f8..95f27b0717 100644
--- a/src/or/config.c
+++ b/src/or/config.c
@@ -491,6 +491,7 @@ static config_var_t option_vars_[] = {
OBSOLETE("SchedulerMaxFlushCells__"),
V(KISTSchedRunInterval, MSEC_INTERVAL, "0 msec"),
V(KISTSockBufSizeFactor, DOUBLE, "1.0"),
+ V(Schedulers, CSV, "KIST,KISTLite,Vanilla"),
V(ShutdownWaitLength, INTERVAL, "30 seconds"),
OBSOLETE("SocksListenAddress"),
V(SocksPolicy, LINELIST, NULL),
@@ -907,6 +908,10 @@ or_options_free(or_options_t *options)
rs, routerset_free(rs));
smartlist_free(options->NodeFamilySets);
}
+ if (options->SchedulerTypes_) {
+ SMARTLIST_FOREACH(options->SchedulerTypes_, int *, i, tor_free(i));
+ smartlist_free(options->SchedulerTypes_);
+ }
tor_free(options->BridgePassword_AuthDigest_);
tor_free(options->command_arg);
tor_free(options->master_key_fname);
@@ -2888,6 +2893,61 @@ warn_about_relative_paths(or_options_t *options)
}
}
+/* Validate options related to the scheduler. From the Schedulers list, the
+ * SchedulerTypes_ list is created with int values so once we select the
+ * scheduler, which can happen anytime at runtime, we don't have to parse
+ * strings and thus be quick.
+ *
+ * Return 0 on success else -1 and msg is set with an error message. */
+static int
+options_validate_scheduler(or_options_t *options, char **msg)
+{
+ tor_assert(options);
+ tor_assert(msg);
+
+ if (!options->Schedulers || smartlist_len(options->Schedulers) == 0) {
+ REJECT("Empty Schedulers list. Either remove the option so the defaults "
+ "can be used or set at least one value.");
+ }
+ /* Ok, we do have scheduler types, validate them. */
+ options->SchedulerTypes_ = smartlist_new();
+ SMARTLIST_FOREACH_BEGIN(options->Schedulers, const char *, type) {
+ int *sched_type;
+ if (!strcasecmp("KISTLite", type)) {
+ sched_type = tor_malloc_zero(sizeof(int));
+ *sched_type = SCHEDULER_KIST_LITE;
+ smartlist_add(options->SchedulerTypes_, sched_type);
+ } else if (!strcasecmp("KIST", type)) {
+ sched_type = tor_malloc_zero(sizeof(int));
+ *sched_type = SCHEDULER_KIST;
+ smartlist_add(options->SchedulerTypes_, sched_type);
+ } else if (!strcasecmp("Vanilla", type)) {
+ sched_type = tor_malloc_zero(sizeof(int));
+ *sched_type = SCHEDULER_VANILLA;
+ smartlist_add(options->SchedulerTypes_, sched_type);
+ } else {
+ tor_asprintf(msg, "Unknown type %s in option Schedulers. "
+ "Possible values are KIST, KISTLite and Vanilla.",
+ escaped(type));
+ return -1;
+ }
+ } SMARTLIST_FOREACH_END(type);
+
+ if (options->KISTSockBufSizeFactor < 0) {
+ REJECT("KISTSockBufSizeFactor must be at least 0");
+ }
+
+ /* Don't need to validate that the Interval is less than anything because
+ * zero is valid and all negative values are valid. */
+ if (options->KISTSchedRunInterval > KIST_SCHED_RUN_INTERVAL_MAX) {
+ tor_asprintf(msg, "KISTSchedRunInterval must not be more than %d (ms)",
+ KIST_SCHED_RUN_INTERVAL_MAX);
+ return -1;
+ }
+
+ return 0;
+}
+
/* Validate options related to single onion services.
* Modifies some options that are incompatible with single onion services.
* On failure returns -1, and sets *msg to an error string.
@@ -3112,19 +3172,6 @@ options_validate(or_options_t *old_options, or_options_t *options,
routerset_union(options->ExcludeExitNodesUnion_,options->ExcludeNodes);
}
- if (options->KISTSockBufSizeFactor < 0) {
- REJECT("KISTSockBufSizeFactor must be at least 0");
- }
- /* Don't need to validate that the Interval is less than anything because
- * zero is valid and all negative values are valid. */
- if (options->KISTSchedRunInterval > KIST_SCHED_RUN_INTERVAL_MAX) {
- char *buf = tor_calloc(80, sizeof(char));
- tor_snprintf(buf, 80, "KISTSchedRunInterval must not be more than %d (ms)",
- KIST_SCHED_RUN_INTERVAL_MAX);
- *msg = buf;
- return -1;
- }
-
if (options->NodeFamilies) {
options->NodeFamilySets = smartlist_new();
for (cl = options->NodeFamilies; cl; cl = cl->next) {
@@ -4241,6 +4288,10 @@ options_validate(or_options_t *old_options, or_options_t *options,
REJECT("BridgeRelay is 1, ORPort is not set. This is an invalid "
"combination.");
+ if (options_validate_scheduler(options, msg) < 0) {
+ return -1;
+ }
+
return 0;
}