summaryrefslogtreecommitdiff
path: root/src/or/connection.c
diff options
context:
space:
mode:
authorArlo Breault <arlolra@gmail.com>2015-12-08 11:32:29 -0800
committerNick Mathewson <nickm@torproject.org>2015-12-10 19:54:11 -0500
commitd68b7fd4422f6ea1cad18a26b6a46b61bc182285 (patch)
tree609f9f452b3d1c03e3bbb2a1411f2ae60ed6968c /src/or/connection.c
parentd015c70a118e43577a3821433970c4367cc8982f (diff)
downloadtor-d68b7fd4422f6ea1cad18a26b6a46b61bc182285.tar.gz
tor-d68b7fd4422f6ea1cad18a26b6a46b61bc182285.zip
Refactor clock skew warning code to avoid duplication
Diffstat (limited to 'src/or/connection.c')
-rw-r--r--src/or/connection.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/or/connection.c b/src/or/connection.c
index 4e39832709..7b8cc6ba39 100644
--- a/src/or/connection.c
+++ b/src/or/connection.c
@@ -5018,3 +5018,33 @@ connection_free_all(void)
#endif
}
+/** Log a warning, and possibly emit a control event, that <b>received</b> came
+ * at a skewed time. <b>trusted</b> indicates that the <b>source</b> was one
+ * that we had more faith in and therefore the warning level should have higher
+ * severity.
+ */
+void
+clock_skew_warning(const connection_t *conn, long apparent_skew, int trusted,
+ log_domain_mask_t domain, const char *received,
+ const char *source)
+{
+ char dbuf[64];
+ char *ext_source = NULL;
+ format_time_interval(dbuf, sizeof(dbuf), apparent_skew);
+ if (conn)
+ tor_asprintf(&ext_source, "%s:%s:%d", source, conn->address, conn->port);
+ else
+ ext_source = tor_strdup(source);
+ log_fn(trusted ? LOG_WARN : LOG_INFO, domain,
+ "Received %s with skewed time (%s): "
+ "It seems that our clock is %s by %s, or that theirs is %s%s. "
+ "Tor requires an accurate clock to work: please check your time, "
+ "timezone, and date settings.", received, ext_source,
+ apparent_skew > 0 ? "ahead" : "behind", dbuf,
+ apparent_skew > 0 ? "behind" : "ahead",
+ (!conn || trusted) ? "" : ", or they are sending us the wrong time");
+ if (trusted)
+ control_event_general_status(LOG_WARN, "CLOCK_SKEW SKEW=%ld SOURCE=%s",
+ apparent_skew, ext_source);
+ tor_free(ext_source);
+}