mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-12-06 19:41:15 +01:00
r16279@catbus: nickm | 2007-10-30 11:14:29 -0400
Improved skew reporting: "You are 365 days in the duture" is more useful than "You are 525600 minutes in the future". Also, when we get something that proves we are at least an hour in the past, tell the controller "CLOCK_SKEW MIN_SKEW=-3600" rather than just "CLOCK_SKEW" svn:r12283
This commit is contained in:
@@ -1250,6 +1250,41 @@ parse_http_time(const char *date, struct tm *tm)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** DOCDOC */
|
||||
int
|
||||
format_time_interval(char *out, size_t out_len, long interval)
|
||||
{
|
||||
/* We only report seconds if there's no hours. */
|
||||
long sec = 0, min = 0, hour = 0, day = 0;
|
||||
if (interval < 0)
|
||||
interval = -interval;
|
||||
|
||||
if (interval >= 86400) {
|
||||
day = interval / 86400;
|
||||
interval %= 86400;
|
||||
}
|
||||
if (interval >= 3600) {
|
||||
hour = interval / 3600;
|
||||
interval %= 3600;
|
||||
}
|
||||
if (interval >= 60) {
|
||||
min = interval / 60;
|
||||
interval %= 60;
|
||||
}
|
||||
sec = interval;
|
||||
|
||||
if (day) {
|
||||
return tor_snprintf(out, out_len, "%ld days, %ld hours, %ld minutes",
|
||||
day, hour, min);
|
||||
} else if (hour) {
|
||||
return tor_snprintf(out, out_len, "%ld hours, %ld minutes", hour, min);
|
||||
} else if (min) {
|
||||
return tor_snprintf(out, out_len, "%ld minutes, %ld seconds", min, sec);
|
||||
} else {
|
||||
return tor_snprintf(out, out_len, "%ld seconds", sec);
|
||||
}
|
||||
}
|
||||
|
||||
/* =====
|
||||
* Fuzzy time
|
||||
* ===== */
|
||||
|
||||
@@ -206,6 +206,7 @@ void format_local_iso_time(char *buf, time_t t);
|
||||
void format_iso_time(char *buf, time_t t);
|
||||
int parse_iso_time(const char *buf, time_t *t);
|
||||
int parse_http_time(const char *buf, struct tm *tm);
|
||||
int format_time_interval(char *out, size_t out_len, long interval);
|
||||
/* Fuzzy time. */
|
||||
void ftime_set_maximum_sloppiness(int seconds);
|
||||
void ftime_set_estimated_skew(int seconds);
|
||||
|
||||
Reference in New Issue
Block a user