summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoger Dingledine <arma@torproject.org>2006-10-06 23:37:07 +0000
committerRoger Dingledine <arma@torproject.org>2006-10-06 23:37:07 +0000
commit1cf37f90c4da02335109dad3cd4bb3fcdce81f24 (patch)
tree80e0a99b3e1b48d01ebce2ac02fe697b7a2eab83
parent864069f5c754f291c1c4ce63a7f9dc2bc31d4afe (diff)
downloadtor-1cf37f90c4da02335109dad3cd4bb3fcdce81f24.tar.gz
tor-1cf37f90c4da02335109dad3cd4bb3fcdce81f24.zip
bugfix and cleanups re: entry guards.
svn:r8620
-rw-r--r--src/or/circuitbuild.c28
-rw-r--r--src/or/circuituse.c3
-rw-r--r--src/or/connection.c9
-rw-r--r--src/or/connection_or.c8
-rw-r--r--src/or/or.h3
5 files changed, 29 insertions, 22 deletions
diff --git a/src/or/circuitbuild.c b/src/or/circuitbuild.c
index f9896f3dc1..ee9b0ea516 100644
--- a/src/or/circuitbuild.c
+++ b/src/or/circuitbuild.c
@@ -1772,11 +1772,11 @@ build_state_get_exit_nickname(cpath_build_state_t *state)
/** Check whether the entry guard <b>e</b> is usable, given the directory
* authorities' opinion about the rouer (stored in <b>ri</b>) and the user's
- * configuration (in <b>options</b>). Set <b>e</b>-&gt;bad_since
- * accordingly. Return true iff the entry guard's status changs.*/
+ * configuration (in <b>options</b>). Set <b>e</b>-&gt;bad_since
+ * accordingly. Return true iff the entry guard's status changes. */
static int
entry_guard_set_status(entry_guard_t *e, routerinfo_t *ri,
- or_options_t *options)
+ time_t now, or_options_t *options)
{
const char *reason = NULL;
char buf[HEX_DIGEST_LEN+1];
@@ -1798,16 +1798,16 @@ entry_guard_set_status(entry_guard_t *e, routerinfo_t *ri,
if (reason && ! e->bad_since) {
/* Router is newly bad. */
base16_encode(buf, sizeof(buf), e->identity, DIGEST_LEN);
- log_info(LD_CIRC, "Entry guard %s (%s) is %s: marking as unusable",
+ log_info(LD_CIRC, "Entry guard %s (%s) is %s: marking as unusable.",
e->nickname, buf, reason);
- e->bad_since = time(NULL);
+ e->bad_since = now;
changed = 1;
} else if (!reason && e->bad_since) {
/* There's nothing wrong with the router any more. */
base16_encode(buf, sizeof(buf), e->identity, DIGEST_LEN);
log_info(LD_CIRC, "Entry guard %s (%s) is no longer unusable: "
- "marking as ok", e->nickname, buf);
+ "marking as ok.", e->nickname, buf);
e->bad_since = 0;
changed = 1;
@@ -1841,8 +1841,8 @@ entry_is_time_to_retry(entry_guard_t *e, time_t now)
* - Listed as either up or never yet contacted;
* - Present in the routerlist;
* - Listed as 'stable' or 'fast' by the current dirserver concensus,
- * if demanded by <b>need_uptime</b> or <b>need_capacity</b>; and
- * - Allowed by our current ReachableAddresses config option.
+ * if demanded by <b>need_uptime</b> or <b>need_capacity</b>;
+ * - Allowed by our current ReachableAddresses config option; and
* - Currently thought to be reachable by us (unless assume_reachable
* is true).
*/
@@ -1987,7 +1987,7 @@ entry_guards_free_all(void)
}
/** How long (in seconds) do we allow an entry guard to be nonfunctional,
- * unlisted, excuded, or otherwise nonusable before we give up on it? */
+ * unlisted, excluded, or otherwise nonusable before we give up on it? */
#define ENTRY_GUARD_REMOVE_AFTER (30*24*60*60)
/** Remove all entry guards that have been down or unlisted for so
@@ -2047,7 +2047,7 @@ entry_guards_compute_status(void)
SMARTLIST_FOREACH(entry_guards, entry_guard_t *, entry,
{
routerinfo_t *r = router_get_by_digest(entry->identity);
- if (entry_guard_set_status(entry, r, options))
+ if (entry_guard_set_status(entry, r, now, options))
changed = 1;
log_info(LD_CIRC, "Summary: Entry '%s' is %s, %s and %s.",
@@ -2074,7 +2074,8 @@ entry_guards_compute_status(void)
* Return 0 normally, or -1 if we want to tear down the new connection.
*/
int
-entry_guard_register_connect_status(const char *digest, int succeeded)
+entry_guard_register_connect_status(const char *digest, int succeeded,
+ time_t now)
{
int changed = 0;
int refuse_conn = 0;
@@ -2105,7 +2106,7 @@ entry_guard_register_connect_status(const char *digest, int succeeded)
log_info(LD_CIRC, "Entry guard '%s' (%s) is now reachable again. Good.",
entry->nickname, buf);
entry->unreachable_since = 0;
- entry->last_attempted = time(NULL);
+ entry->last_attempted = now;
changed = 1;
}
if (!entry->made_contact) {
@@ -2127,6 +2128,7 @@ entry_guard_register_connect_status(const char *digest, int succeeded)
} else if (!entry->unreachable_since) {
log_info(LD_CIRC, "Unable to connect to entry guard '%s' (%s). "
"Marking as unreachable.", entry->nickname, buf);
+ entry->unreachable_since = entry->last_attempted = now;
changed = 1;
} else {
char tbuf[ISO_TIME_LEN+1];
@@ -2134,7 +2136,7 @@ entry_guard_register_connect_status(const char *digest, int succeeded)
log_debug(LD_CIRC, "Failed to connect to unreachable entry guard "
"'%s' (%s). It has been unreachable since %s.",
entry->nickname, buf, tbuf);
- entry->last_attempted = time(NULL);
+ entry->last_attempted = now;
}
}
diff --git a/src/or/circuituse.c b/src/or/circuituse.c
index c0c2245694..dceef0af24 100644
--- a/src/or/circuituse.c
+++ b/src/or/circuituse.c
@@ -740,7 +740,8 @@ circuit_build_failed(origin_circuit_t *circ)
"(%s:%d). I'm going to try to rotate to a better connection.",
n_conn->_base.address, n_conn->_base.port);
n_conn->_base.or_is_obsolete = 1;
- entry_guard_register_connect_status(n_conn->identity_digest, 0);
+ entry_guard_register_connect_status(n_conn->identity_digest, 0,
+ time(NULL));
}
}
diff --git a/src/or/connection.c b/src/or/connection.c
index 76e231398d..d60291253e 100644
--- a/src/or/connection.c
+++ b/src/or/connection.c
@@ -398,6 +398,7 @@ connection_about_to_close_connection(connection_t *conn)
dir_connection_t *dir_conn;
or_connection_t *or_conn;
edge_connection_t *edge_conn;
+ time_t now = time(NULL);
assert(conn->marked_for_close);
@@ -427,8 +428,8 @@ connection_about_to_close_connection(connection_t *conn)
/* Remember why we're closing this connection. */
if (conn->state != OR_CONN_STATE_OPEN) {
if (connection_or_nonopen_was_started_here(or_conn)) {
- rep_hist_note_connect_failed(or_conn->identity_digest, time(NULL));
- entry_guard_register_connect_status(or_conn->identity_digest, 0);
+ rep_hist_note_connect_failed(or_conn->identity_digest, now);
+ entry_guard_register_connect_status(or_conn->identity_digest,0,now);
router_set_status(or_conn->identity_digest, 0);
control_event_or_conn_status(or_conn, OR_CONN_EVENT_FAILED);
}
@@ -442,10 +443,10 @@ connection_about_to_close_connection(connection_t *conn)
* flushing still get noted as dead, not disconnected. But this is an
* improvement. -NM
*/
- rep_hist_note_disconnect(or_conn->identity_digest, time(NULL));
+ rep_hist_note_disconnect(or_conn->identity_digest, now);
control_event_or_conn_status(or_conn, OR_CONN_EVENT_CLOSED);
} else if (or_conn->identity_digest) {
- rep_hist_note_connection_died(or_conn->identity_digest, time(NULL));
+ rep_hist_note_connection_died(or_conn->identity_digest, now);
control_event_or_conn_status(or_conn, OR_CONN_EVENT_CLOSED);
}
break;
diff --git a/src/or/connection_or.c b/src/or/connection_or.c
index 7268576182..e8681d9a50 100644
--- a/src/or/connection_or.c
+++ b/src/or/connection_or.c
@@ -448,7 +448,8 @@ connection_or_connect(uint32_t addr, uint16_t port, const char *id_digest)
* an https proxy, our https proxy is down. Don't blame the
* Tor server. */
if (!options->HttpsProxy) {
- entry_guard_register_connect_status(conn->identity_digest, 0);
+ entry_guard_register_connect_status(conn->identity_digest, 0,
+ time(NULL));
router_set_status(conn->identity_digest, 0);
}
control_event_or_conn_status(conn, OR_CONN_EVENT_FAILED);
@@ -622,7 +623,7 @@ connection_or_check_valid_handshake(or_connection_t *conn, char *digest_rcvd)
"Identity key not as expected for router at %s:%d: wanted %s "
"but got %s",
conn->_base.address, conn->_base.port, expected, seen);
- entry_guard_register_connect_status(conn->identity_digest, 0);
+ entry_guard_register_connect_status(conn->identity_digest, 0, time(NULL));
router_set_status(conn->identity_digest, 0);
control_event_or_conn_status(conn, OR_CONN_EVENT_FAILED);
as_advertised = 0;
@@ -684,7 +685,8 @@ connection_tls_finish_handshake(or_connection_t *conn)
control_event_or_conn_status(conn, OR_CONN_EVENT_CONNECTED);
if (started_here) {
rep_hist_note_connect_succeeded(conn->identity_digest, time(NULL));
- if (entry_guard_register_connect_status(conn->identity_digest, 1) < 0) {
+ if (entry_guard_register_connect_status(conn->identity_digest, 1,
+ time(NULL)) < 0) {
/* pending circs get closed in circuit_about_to_close_connection() */
return -1;
}
diff --git a/src/or/or.h b/src/or/or.h
index 75adcb6c85..7a28b47961 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -1723,7 +1723,8 @@ routerinfo_t *build_state_get_exit_router(cpath_build_state_t *state);
const char *build_state_get_exit_nickname(cpath_build_state_t *state);
void entry_guards_compute_status(void);
-int entry_guard_register_connect_status(const char *digest, int succeeded);
+int entry_guard_register_connect_status(const char *digest, int succeeded,
+ time_t now);
void entry_nodes_should_be_added(void);
void entry_guards_prepend_from_config(void);
void entry_guards_update_state(or_state_t *state);