diff options
author | Roger Dingledine <arma@torproject.org> | 2008-06-07 05:27:34 +0000 |
---|---|---|
committer | Roger Dingledine <arma@torproject.org> | 2008-06-07 05:27:34 +0000 |
commit | 5aeb89447ef1683477f2ac22c91cba5f6444557d (patch) | |
tree | 27dc2a94cd2b6d3e63f9a1049d3d78af7953128e /src/or/control.c | |
parent | 9b626988a67647a60a420d81a95a889ea31ac666 (diff) | |
download | tor-5aeb89447ef1683477f2ac22c91cba5f6444557d.tar tor-5aeb89447ef1683477f2ac22c91cba5f6444557d.tar.gz |
infrastructure for the 'bootstrap status event' feature, so we can
tell the controller how we're doing at bootstrapping, and it can
tell the user.
svn:r15008
Diffstat (limited to 'src/or/control.c')
-rw-r--r-- | src/or/control.c | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/src/or/control.c b/src/or/control.c index 878f0d2f0..edfa1c775 100644 --- a/src/or/control.c +++ b/src/or/control.c @@ -3823,3 +3823,94 @@ init_cookie_authentication(int enabled) return 0; } +/** Convert the name of a bootstrapping phase <b>s</b> into a string + * suitable for display by the controller. */ +static const char * +bootstrap_status_to_string(bootstrap_status_t s) +{ + switch (s) { + case BOOTSTRAP_STATUS_STARTING: + return "Starting"; + case BOOTSTRAP_STATUS_CONN_DIR: + return "Connecting to directory mirror"; + case BOOTSTRAP_STATUS_HANDSHAKE: + return "Finishing handshake"; + case BOOTSTRAP_STATUS_HANDSHAKE_DIR: + return "Finishing handshake with directory mirror"; + case BOOTSTRAP_STATUS_ONEHOP_CREATE: + return "Establishing one-hop circuit for dir info"; + case BOOTSTRAP_STATUS_REQUESTING_STATUS: + return "Asking for networkstatus consensus"; + case BOOTSTRAP_STATUS_LOADING_STATUS: + return "Loading networkstatus consensus"; + case BOOTSTRAP_STATUS_LOADING_KEYS: + return "Loading authority key certs"; + case BOOTSTRAP_STATUS_REQUESTING_DESCRIPTORS: + return "Asking for relay descriptors"; + case BOOTSTRAP_STATUS_LOADING_DESCRIPTORS: + return "Loading relay descriptors"; + case BOOTSTRAP_STATUS_CONN_OR: + return "Connecting to entry guard"; + case BOOTSTRAP_STATUS_HANDSHAKE_OR: + return "Finishing handshake with entry guard"; + case BOOTSTRAP_STATUS_CIRCUIT_CREATE: + return "Establishing circuits"; + case BOOTSTRAP_STATUS_DONE: + return "Done!"; + default: + log_warn(LD_BUG, "Unrecognized bootstrap status code %d", s); + return "unknown"; + } +} + +/** Called when Tor has made progress at bootstrapping its directory + * information and initial circuits. <b>status</b> is the new status, + * that is, what task we will be doing next. <b>percent</b> is zero if + * we just started this task, else it represents progress on the task. + */ +int +control_event_bootstrap(bootstrap_status_t status, int percent) +{ + static int last_percent = 0; + + if (last_percent == 100) + return 0; /* already bootstrapped; nothing to be done here. */ + + /* special case for handshaking status, since our tls handshaking code + * can't distinguish what the connection is going to be for. */ + if (status == BOOTSTRAP_STATUS_HANDSHAKE) { + if (last_percent < BOOTSTRAP_STATUS_HANDSHAKE_OR) { + status = BOOTSTRAP_STATUS_HANDSHAKE_DIR; + } else { + status = BOOTSTRAP_STATUS_HANDSHAKE_OR; + } + } + +#if 0 + if (status <= last_percent) + switch (status) { + case BOOTSTRAP_STATUS_CONN_DIR: + case BOOTSTRAP_STATUS_ONEHOP_CREATE: + case BOOTSTRAP_STATUS_HANDSHAKE_DIR: + case BOOTSTRAP_STATUS_REQUESTING_STATUS: + case BOOTSTRAP_STATUS_REQUESTING_DESCRIPTORS: + boring = 1; + break; + default: ; + } + + if (!boring) +#endif + if (status > last_percent || (percent && percent > last_percent)) + log_notice(LD_CONTROL, "Bootstrapped %d%% (last %d): %s.", + status, last_percent, bootstrap_status_to_string(status)); + + /* ... This is where we tell the controller ... */ + + if (percent > last_percent) /* incremental progress within a milestone */ + last_percent = percent; + if (status > last_percent) /* new milestone reached */ + last_percent = status ; + return 0; +} + |