]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Bug 40808: Change KISTSchedRunInterval range and default; add KISTSchedRunIntervalClient
authorMike Perry <mikeperry-git@torproject.org>
Tue, 20 Jun 2023 16:29:48 +0000 (16:29 +0000)
committerMike Perry <mikeperry-git@torproject.org>
Tue, 20 Jun 2023 16:29:48 +0000 (16:29 +0000)
src/core/or/scheduler.h
src/core/or/scheduler_kist.c
src/test/test_scheduler.c

index 7d3c6f7390a387074334a5739167bd61cad5cf0b..dab7f37f0e47f8f45cc2ce5a0449290be138219f 100644 (file)
@@ -102,9 +102,9 @@ typedef struct scheduler_t {
  *****************************************************************************/
 
 /* Default interval that KIST runs (in ms). */
-#define KIST_SCHED_RUN_INTERVAL_DEFAULT 10
-/* Minimum interval that KIST runs. This value disables KIST. */
-#define KIST_SCHED_RUN_INTERVAL_MIN 0
+#define KIST_SCHED_RUN_INTERVAL_DEFAULT 2
+/* Minimum interval that KIST runs. */
+#define KIST_SCHED_RUN_INTERVAL_MIN 2
 /* Maximum interval that KIST runs (in ms). */
 #define KIST_SCHED_RUN_INTERVAL_MAX 100
 
index 52bc62f1b4a13817bfedb784e30f4918ef162efa..69804247c8c349fef0c895a7297437c08e16de82 100644 (file)
@@ -13,6 +13,7 @@
 #include "app/config/config.h"
 #include "core/mainloop/connection.h"
 #include "feature/nodelist/networkstatus.h"
+#include "feature/relay/routermode.h"
 #define CHANNEL_OBJECT_PRIVATE
 #include "core/or/channel.h"
 #include "core/or/channeltls.h"
@@ -810,12 +811,19 @@ kist_scheduler_run_interval(void)
 
   log_debug(LD_SCHED, "KISTSchedRunInterval=0, turning to the consensus.");
 
-  /* Will either be the consensus value or the default. Note that 0 can be
-   * returned which means the consensus wants us to NOT use KIST. */
-  return networkstatus_get_param(NULL, "KISTSchedRunInterval",
+  /* Clients and relays have a separate consensus parameter. Clients
+   * need a lower KIST interval, since they have only a couple connections */
+  if (server_mode(get_options())) {
+    return networkstatus_get_param(NULL, "KISTSchedRunInterval",
                                  KIST_SCHED_RUN_INTERVAL_DEFAULT,
                                  KIST_SCHED_RUN_INTERVAL_MIN,
                                  KIST_SCHED_RUN_INTERVAL_MAX);
+  } else {
+    return networkstatus_get_param(NULL, "KISTSchedRunIntervalClient",
+                                 KIST_SCHED_RUN_INTERVAL_DEFAULT,
+                                 KIST_SCHED_RUN_INTERVAL_MIN,
+                                 KIST_SCHED_RUN_INTERVAL_MAX);
+  }
 }
 
 /* Set KISTLite mode that is KIST without kernel support. */
index 7e41a4be25452bbcbd1b0748f83f33b6aca0e0f8..06b3dafce86194cc67722afa695796ed6ff087e8 100644 (file)
@@ -81,8 +81,7 @@ mock_vanilla_networkstatus_get_param(
   (void)default_val;
   (void)min_val;
   (void)max_val;
-  // only support KISTSchedRunInterval right now
-  tor_assert(strcmp(param_name, "KISTSchedRunInterval")==0);
+  (void)param_name;
   return 0;
 }
 
@@ -95,8 +94,7 @@ mock_kist_networkstatus_get_param(
   (void)default_val;
   (void)min_val;
   (void)max_val;
-  // only support KISTSchedRunInterval right now
-  tor_assert(strcmp(param_name, "KISTSchedRunInterval")==0);
+  (void)param_name;
   return 12;
 }
 
@@ -863,7 +861,7 @@ test_scheduler_initfree(void *arg)
   /* We have specified nothing in the torrc and there's no consensus so the
    * KIST scheduler is what should be in use */
   tt_ptr_op(the_scheduler, OP_EQ, get_kist_scheduler());
-  tt_int_op(sched_run_interval, OP_EQ, 10);
+  tt_int_op(sched_run_interval, OP_EQ, KIST_SCHED_RUN_INTERVAL_DEFAULT);
 
   scheduler_free_all();
 
@@ -906,7 +904,7 @@ test_scheduler_can_use_kist(void *arg)
 #else /* HAVE_KIST_SUPPORT */
   tt_int_op(res_should, OP_EQ, 0);
 #endif /* HAVE_KIST_SUPPORT */
-  tt_int_op(res_freq, OP_EQ, 10);
+  tt_int_op(res_freq, OP_EQ, KIST_SCHED_RUN_INTERVAL_DEFAULT);
 
   /* Test defer to consensus, and kist consensus available */
   MOCK(networkstatus_get_param, mock_kist_networkstatus_get_param);