Browse Source

consensus: Add a generic notification function on new consensus

Some groundwork for the KIST scheduler implementation.

Signed-off-by: David Goulet <dgoulet@torproject.org>
Matt Traudt 6 years ago
parent
commit
91c7bebfa2
4 changed files with 32 additions and 9 deletions
  1. 14 5
      src/or/networkstatus.c
  2. 3 4
      src/or/networkstatus.h
  3. 10 0
      src/or/scheduler.c
  4. 5 0
      src/or/scheduler.h

+ 14 - 5
src/or/networkstatus.c

@@ -61,6 +61,7 @@
 #include "router.h"
 #include "routerlist.h"
 #include "routerparse.h"
+#include "scheduler.h"
 #include "shared_random.h"
 #include "transports.h"
 #include "torcert.h"
@@ -1610,6 +1611,15 @@ notify_control_networkstatus_changed(const networkstatus_t *old_c,
   smartlist_free(changed);
 }
 
+/* Called when the consensus has changed from old_c to new_c. */
+static void
+notify_networkstatus_changed(const networkstatus_t *old_c,
+                             const networkstatus_t *new_c)
+{
+  notify_control_networkstatus_changed(old_c, new_c);
+  scheduler_notify_networkstatus_changed(old_c, new_c);
+}
+
 /** Copy all the ancillary information (like router download status and so on)
  * from <b>old_c</b> to <b>new_c</b>. */
 static void
@@ -1935,8 +1945,7 @@ networkstatus_set_current_consensus(const char *consensus,
   const int is_usable_flavor = flav == usable_consensus_flavor();
 
   if (is_usable_flavor) {
-    notify_control_networkstatus_changed(
-                         networkstatus_get_latest_consensus(), c);
+    notify_networkstatus_changed(networkstatus_get_latest_consensus(), c);
   }
   if (flav == FLAV_NS) {
     if (current_ns_consensus) {
@@ -2387,9 +2396,9 @@ get_net_param_from_list(smartlist_t *net_params, const char *param_name,
  * Make sure the value parsed from the consensus is at least
  * <b>min_val</b> and at most <b>max_val</b> and raise/cap the parsed value
  * if necessary. */
-int32_t
-networkstatus_get_param(const networkstatus_t *ns, const char *param_name,
-                        int32_t default_val, int32_t min_val, int32_t max_val)
+MOCK_IMPL(int32_t,
+networkstatus_get_param, (const networkstatus_t *ns, const char *param_name,
+                        int32_t default_val, int32_t min_val, int32_t max_val))
 {
   if (!ns) /* if they pass in null, go find it ourselves */
     ns = networkstatus_get_latest_consensus();

+ 3 - 4
src/or/networkstatus.h

@@ -114,10 +114,9 @@ void signed_descs_update_status_from_consensus_networkstatus(
 char *networkstatus_getinfo_helper_single(const routerstatus_t *rs);
 char *networkstatus_getinfo_by_purpose(const char *purpose_string, time_t now);
 void networkstatus_dump_bridge_status_to_file(time_t now);
-int32_t networkstatus_get_param(const networkstatus_t *ns,
-                                const char *param_name,
-                                int32_t default_val, int32_t min_val,
-                                int32_t max_val);
+MOCK_DECL(int32_t, networkstatus_get_param,
+          (const networkstatus_t *ns, const char *param_name,
+           int32_t default_val, int32_t min_val, int32_t max_val));
 int32_t networkstatus_get_overridable_param(const networkstatus_t *ns,
                                             int32_t torrc_value,
                                             const char *param_name,

+ 10 - 0
src/or/scheduler.c

@@ -736,3 +736,13 @@ scheduler_set_watermarks(uint32_t lo, uint32_t hi, uint32_t max_flush)
   sched_max_flush_cells = max_flush;
 }
 
+/* XXXFORTOR Temp def of this func to get this commit to compile. Replace with
+ * real func */
+void
+scheduler_notify_networkstatus_changed(const networkstatus_t *old_c,
+                                       const networkstatus_t *new_c)
+{
+  (void) old_c;
+  (void) new_c;
+}
+

+ 5 - 0
src/or/scheduler.h

@@ -37,6 +37,11 @@ void scheduler_touch_channel(channel_t *chan);
 /* Adjust the watermarks from config file*/
 void scheduler_set_watermarks(uint32_t lo, uint32_t hi, uint32_t max_flush);
 
+/* XXXFORTOR Temp def of this func to get this commit to compile. Replace with
+ * real func */
+void scheduler_notify_networkstatus_changed(const networkstatus_t *old_c,
+                                            const networkstatus_t *new_c);
+
 /* Things only scheduler.c and its test suite should see */
 
 #ifdef SCHEDULER_PRIVATE_