commit a47fdaf9a0563de4b1fff4df8aca69d9a225dd1e
Merge: a2a8ade 22810d7
Author: Nick Mathewson <nickm(a)torproject.org>
Date: Fri Feb 25 12:12:44 2011 -0500
Merge branch 'bug1074_launch_conn_on_skew'
Fixed conflict on rename of router_get_by_digest->router_get_by_id_digest
Conflicts:
src/or/command.c
changes/launch_authcon_on_skew | 7 ++++++
src/or/command.c | 42 +++++++++++++++++++++++++++++++--------
2 files changed, 40 insertions(+), 9 deletions(-)
diff --combined src/or/command.c
index 4b70dee,e026997..a13f9ec
--- a/src/or/command.c
+++ b/src/or/command.c
@@@ -25,7 -25,6 +25,7 @@@
#include "control.h"
#include "cpuworker.h"
#include "hibernate.h"
+#include "nodelist.h"
#include "onion.h"
#include "relay.h"
#include "router.h"
@@@ -45,6 -44,13 +45,13 @@@ uint64_t stats_n_destroy_cells_processe
uint64_t stats_n_versions_cells_processed = 0;
/** How many CELL_NETINFO cells have we received, ever? */
uint64_t stats_n_netinfo_cells_processed = 0;
+ /** Have we received a NETINFO cell from a trusted dir, ever? Used
+ * to decide what to do about time skew.
+ * 0 == No, and and we haven't tried asking an authority yet
+ * 1 == No, we've launched a query but haven't heard back yet
+ * 2 == Yes
+ **/
+ static int received_netinfo_from_trusted_dir = 0;
/* These are the main functions for processing cells */
static void command_process_create_cell(cell_t *cell, or_connection_t *conn);
@@@ -268,18 -274,15 +275,18 @@@ command_process_create_cell(cell_t *cel
}
if (circuit_id_in_use_on_orconn(cell->circ_id, conn)) {
- routerinfo_t *router = router_get_by_digest(conn->identity_digest);
+ const node_t *node = node_get_by_id(conn->identity_digest);
log_fn(LOG_PROTOCOL_WARN, LD_PROTOCOL,
"Received CREATE cell (circID %d) for known circ. "
"Dropping (age %d).",
cell->circ_id, (int)(time(NULL) - conn->_base.timestamp_created));
- if (router)
+ if (node) {
+ char *p = esc_for_log(node_get_platform(node));
log_fn(LOG_PROTOCOL_WARN, LD_PROTOCOL,
"Details: nickname \"%s\", platform %s.",
- router->nickname, escaped(router->platform));
+ node_get_nickname(node), p);
+ tor_free(p);
+ }
return;
}
@@@ -621,17 -624,16 +628,16 @@@ command_process_netinfo_cell(cell_t *ce
}
/* Act on apparent skew. */
- /** Warn when we get a netinfo skew with at least this value. */
+ /** Warn when we get a netinfo skew with at least this value.
+ Ignore if we've already received skew info from a trusted dir */
#define NETINFO_NOTICE_SKEW 3600
if (labs(apparent_skew) > NETINFO_NOTICE_SKEW &&
- router_get_by_id_digest(conn->identity_digest)) {
- router_get_by_digest(conn->identity_digest) &&
++ router_get_by_id_digest(conn->identity_digest) &&
+ received_netinfo_from_trusted_dir != 2) {
char dbuf[64];
- int severity;
- /*XXXX be smarter about when everybody says we are skewed. */
- if (router_digest_is_trusted_dir(conn->identity_digest))
- severity = LOG_WARN;
- else
- severity = LOG_INFO;
+
+ int severity = router_digest_is_trusted_dir(conn->identity_digest) ?
+ LOG_WARN : LOG_INFO;
format_time_interval(dbuf, sizeof(dbuf), apparent_skew);
log_fn(severity, LD_GENERAL, "Received NETINFO cell with skewed time from "
"server at %s:%d. It seems that our clock is %s by %s, or "
@@@ -640,13 -642,31 +646,31 @@@
conn->_base.address, (int)conn->_base.port,
apparent_skew>0 ? "ahead" : "behind", dbuf,
apparent_skew>0 ? "behind" : "ahead");
- if (severity == LOG_WARN) /* only tell the controller if an authority */
+ if (severity == LOG_WARN) { /* only tell the controller if an authority */
control_event_general_status(LOG_WARN,
"CLOCK_SKEW SKEW=%ld SOURCE=OR:%s:%d",
apparent_skew,
conn->_base.address, conn->_base.port);
+ received_netinfo_from_trusted_dir = 2;
+ /* Connect to a trusted dir to trigger a NETINFO cell
+ * only if we haven't already */
+ } else if (received_netinfo_from_trusted_dir == 0) {
+ routerstatus_t *any_trusted_dir =
+ router_pick_trusteddirserver(NO_AUTHORITY, 0);
+ tor_addr_t trusted_dir_addr;
+ tor_addr_from_ipv4h(&trusted_dir_addr, any_trusted_dir->addr);
+ connection_or_connect(&trusted_dir_addr,
+ any_trusted_dir->or_port,
+ any_trusted_dir->identity_digest);
+ received_netinfo_from_trusted_dir = 1;
+ }
}
+ /* Note that we received a good netinfo cell from a trusted directory */
+ if (router_digest_is_trusted_dir(conn->identity_digest) &&
+ labs(apparent_skew) <= NETINFO_NOTICE_SKEW)
+ received_netinfo_from_trusted_dir = 2;
+
/* XXX maybe act on my_apparent_addr, if the source is sufficiently
* trustworthy. */