diff --git a/src/common/util.c b/src/common/util.c index 99ac776dcb..6c6ce088ca 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -910,6 +910,10 @@ format_iso_time(char *buf, time_t t) strftime(buf, ISO_TIME_LEN+1, "%Y-%m-%d %H:%M:%S", tor_gmtime_r(&t, &tm)); } +/** Given an ISO-formatted UTC time value (after the epoch) in cp, + * parse it and store its value in *t. Return 0 on success, -1 on + * failure. Ignore extraneous stuff in cp separated by whitespace from + * the end of the time string. */ int parse_iso_time(const char *cp, time_t *t) { diff --git a/src/or/circuitbuild.c b/src/or/circuitbuild.c index ed9ce5a762..6e36e1dabe 100644 --- a/src/or/circuitbuild.c +++ b/src/or/circuitbuild.c @@ -2275,6 +2275,7 @@ entry_guards_parse_state(or_state_t *state, int set, char **msg) break; } else { time_t when; + time_t last_try = 0; if (!node) { *msg = tor_strdup("Unable to parse entry nodes: " "EntryGuardDownSince/UnlistedSince without EntryGuard"); @@ -2285,10 +2286,16 @@ entry_guards_parse_state(or_state_t *state, int set, char **msg) "Bad time in EntryGuardDownSince/UnlistedSince"); break; } - if (!strcasecmp(line->key, "EntryGuardDownSince")) + if (strlen(line->value) >= ISO_TIME_LEN+ISO_TIME_LEN+1) { + /* ignore failure */ + parse_iso_time(line->value+ISO_TIME_LEN+1, &last_try); + } + if (!strcasecmp(line->key, "EntryGuardDownSince")) { node->unreachable_since = when; - else + node->last_attempted = last_try; + } else { node->bad_since = when; + } } } @@ -2348,8 +2355,12 @@ entry_guards_update_state(or_state_t *state) if (e->unreachable_since) { *next = line = tor_malloc_zero(sizeof(config_line_t)); line->key = tor_strdup("EntryGuardDownSince"); - line->value = tor_malloc(ISO_TIME_LEN+1); + line->value = tor_malloc(ISO_TIME_LEN+1+ISO_TIME_LEN+1); format_iso_time(line->value, e->unreachable_since); + if (e->last_attempted) { + line->value[ISO_TIME_LEN] = ' '; + format_iso_time(line->value+ISO_TIME_LEN+1, e->last_attempted); + } next = &(line->next); } if (e->bad_since) {