aboutsummaryrefslogtreecommitdiff
path: root/src/or/networkstatus.c
diff options
context:
space:
mode:
authorDavid Goulet <dgoulet@torproject.org>2018-01-31 14:15:02 -0500
committerDavid Goulet <dgoulet@torproject.org>2018-01-31 14:15:02 -0500
commitfbc455cbd224aaf28c613ed92bbaee656291efec (patch)
tree40486321ab7fda0b61fd3da012e42fec3853fa67 /src/or/networkstatus.c
parentc85f78e74c52d19b575618d031e67b64210c14fc (diff)
downloadtor-fbc455cbd224aaf28c613ed92bbaee656291efec.tar.gz
tor-fbc455cbd224aaf28c613ed92bbaee656291efec.zip
ns: Add a before and after consensus has changed notification
In 0.3.2.1-alpha, we've added notify_networkstatus_changed() in order to have a way to notify other subsystems that the consensus just changed. The old and new consensus are passed to it. Before this patch, this was done _before_ the new consensus was set globally (thus NOT accessible by getting the latest consensus). The scheduler notification was assuming that it was set and select_scheduler() is looking at the latest consensus to get the parameters it might needs. This was very wrong because at that point it is still the old consensus set globally. This commit changes the notify_networkstatus_changed() to be the "before" function and adds an "after" notification from which the scheduler subsystem is notified. Fixes #24975
Diffstat (limited to 'src/or/networkstatus.c')
-rw-r--r--src/or/networkstatus.c24
1 files changed, 19 insertions, 5 deletions
diff --git a/src/or/networkstatus.c b/src/or/networkstatus.c
index e0a3e4cdc6..9d9a2b8ad1 100644
--- a/src/or/networkstatus.c
+++ b/src/or/networkstatus.c
@@ -1564,13 +1564,20 @@ notify_control_networkstatus_changed(const networkstatus_t *old_c,
smartlist_free(changed);
}
-/* Called when the consensus has changed from old_c to new_c. */
+/* Called before the consensus changes from old_c to new_c. */
static void
-notify_networkstatus_changed(const networkstatus_t *old_c,
- const networkstatus_t *new_c)
+notify_before_networkstatus_changes(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);
+}
+
+/* Called after a new consensus has been put in the global state. It is safe
+ * to use the consensus getters in this function. */
+static void
+notify_after_networkstatus_changes(void)
+{
+ scheduler_notify_networkstatus_changed();
}
/** Copy all the ancillary information (like router download status and so on)
@@ -1897,8 +1904,11 @@ networkstatus_set_current_consensus(const char *consensus,
const int is_usable_flavor = flav == usable_consensus_flavor();
+ /* Before we switch to the new consensus, notify that we are about to change
+ * it using the old consensus and the new one. */
if (is_usable_flavor) {
- notify_networkstatus_changed(networkstatus_get_latest_consensus(), c);
+ notify_before_networkstatus_changes(networkstatus_get_latest_consensus(),
+ c);
}
if (flav == FLAV_NS) {
if (current_ns_consensus) {
@@ -1941,6 +1951,10 @@ networkstatus_set_current_consensus(const char *consensus,
}
if (is_usable_flavor) {
+ /* Notify that we just changed the consensus so the current global value
+ * can be looked at. */
+ notify_after_networkstatus_changes();
+
/* The "current" consensus has just been set and it is a usable flavor so
* the first thing we need to do is recalculate the voting schedule static
* object so we can use the timings in there needed by some subsystems