summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTaylor Yu <catalyst@torproject.org>2018-08-28 14:31:51 -0500
committerTaylor Yu <catalyst@torproject.org>2018-09-10 13:18:32 -0500
commit15c24d669f86715c3c24d1a50b377bd8ac65b0a7 (patch)
tree3635e4e5982ef7d2953b22fd19bb0c7b14baf2ed /src
parente2988e044dc3d8d14b70ff606edd3494aff6bc05 (diff)
downloadtor-15c24d669f86715c3c24d1a50b377bd8ac65b0a7.tar.gz
tor-15c24d669f86715c3c24d1a50b377bd8ac65b0a7.zip
Refactor control_event_bootstrap() somewhat
Move the mostly-invariant part of control_event_boostrap() into a helper control_event_bootstrap_core(). The helper doesn't modify any state beyond doing logging and control port notifications.
Diffstat (limited to 'src')
-rw-r--r--src/feature/control/control.c36
1 files changed, 25 insertions, 11 deletions
diff --git a/src/feature/control/control.c b/src/feature/control/control.c
index 3de5fa9e13..4395cbd2c9 100644
--- a/src/feature/control/control.c
+++ b/src/feature/control/control.c
@@ -7095,6 +7095,29 @@ static int bootstrap_problems = 0;
*/
#define BOOTSTRAP_PCT_INCREMENT 5
+/** Do the actual logging and notifications for
+ * control_event_bootstrap(). Doesn't change any state beyond that.
+ */
+static void
+control_event_bootstrap_core(int loglevel, bootstrap_status_t status,
+ int progress)
+{
+ char buf[BOOTSTRAP_MSG_LEN];
+ const char *tag, *summary;
+
+ bootstrap_status_to_string(status, &tag, &summary);
+
+ tor_log(loglevel, LD_CONTROL,
+ "Bootstrapped %d%%: %s", progress ? progress : status, summary);
+ tor_snprintf(buf, sizeof(buf),
+ "BOOTSTRAP PROGRESS=%d TAG=%s SUMMARY=\"%s\"",
+ progress ? progress : status, tag, summary);
+ tor_snprintf(last_sent_bootstrap_message,
+ sizeof(last_sent_bootstrap_message),
+ "NOTICE %s", buf);
+ control_event_client_status(LOG_NOTICE, "%s", buf);
+}
+
/** Called when Tor has made progress at bootstrapping its directory
* information and initial circuits.
*
@@ -7105,8 +7128,6 @@ static int bootstrap_problems = 0;
void
control_event_bootstrap(bootstrap_status_t status, int progress)
{
- const char *tag, *summary;
- char buf[BOOTSTRAP_MSG_LEN];
int loglevel = LOG_NOTICE;
if (bootstrap_percent == BOOTSTRAP_STATUS_DONE)
@@ -7131,15 +7152,8 @@ control_event_bootstrap(bootstrap_status_t status, int progress)
loglevel = LOG_INFO;
}
- tor_log(loglevel, LD_CONTROL,
- "Bootstrapped %d%%: %s", progress ? progress : status, summary);
- tor_snprintf(buf, sizeof(buf),
- "BOOTSTRAP PROGRESS=%d TAG=%s SUMMARY=\"%s\"",
- progress ? progress : status, tag, summary);
- tor_snprintf(last_sent_bootstrap_message,
- sizeof(last_sent_bootstrap_message),
- "NOTICE %s", buf);
- control_event_client_status(LOG_NOTICE, "%s", buf);
+ control_event_bootstrap_core(loglevel, status, progress);
+
if (status > bootstrap_percent) {
bootstrap_percent = status; /* new milestone reached */
}