summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2004-10-13 20:05:57 +0000
committerNick Mathewson <nickm@torproject.org>2004-10-13 20:05:57 +0000
commite0cce8fba8dcefa8745a4ba768f911c09d9d7573 (patch)
tree289c0e8cd459725788e1234bae539b69b9a9ce28
parent30dd1c87a5ac1ebe7756bb48f7c94cb7f20de1da (diff)
downloadtor-e0cce8fba8dcefa8745a4ba768f911c09d9d7573.tar.gz
tor-e0cce8fba8dcefa8745a4ba768f911c09d9d7573.zip
Unify tests for "did I originate this nonopen OR connection?"
svn:r2468
-rw-r--r--src/or/connection.c8
-rw-r--r--src/or/connection_or.c17
-rw-r--r--src/or/or.h1
3 files changed, 14 insertions, 12 deletions
diff --git a/src/or/connection.c b/src/or/connection.c
index 5f5313788f..53ab7b0833 100644
--- a/src/or/connection.c
+++ b/src/or/connection.c
@@ -192,13 +192,7 @@ void connection_about_to_close_connection(connection_t *conn)
case CONN_TYPE_OR:
/* Remember why we're closing this connection. */
if (conn->state != OR_CONN_STATE_OPEN) {
- /* XXX Nick: this still isn't right, because it might be
- * dying even though we didn't initiate the connect. Can
- * you look at this more? -RD XXXX008 -NM*/
- /* XXX We only set conn->nickname when we initiate the connection, or
- * when the handshake is complete; so conn->nickname is a good test
- * for "we initiated the connection", right? -NM */
- if(conn->nickname)
+ if(connection_or_nonopen_was_started_here(conn))
rep_hist_note_connect_failed(conn->identity_digest, time(NULL));
} else if (0) { // XXX reason == CLOSE_REASON_UNUSED_OR_CONN) {
rep_hist_note_disconnect(conn->identity_digest, time(NULL));
diff --git a/src/or/connection_or.c b/src/or/connection_or.c
index acff78b188..ccbb3f54cb 100644
--- a/src/or/connection_or.c
+++ b/src/or/connection_or.c
@@ -300,10 +300,17 @@ int connection_tls_continue_handshake(connection_t *conn) {
return 0;
}
-static int digest_is_zero(const char *id) {
- char ZERO_DIGEST[DIGEST_LEN];
- memset(ZERO_DIGEST, 0, DIGEST_LEN);
- return !memcmp(ZERO_DIGEST, id, DIGEST_LEN);
+static char ZERO_DIGEST[] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
+
+int connection_or_nonopen_was_started_here(connection_t *conn)
+{
+ tor_assert(sizeof(ZERO_DIGEST) == DIGEST_LEN);
+ tor_assert(conn->type == CONN_TYPE_OR);
+
+ if (!memcmp(ZERO_DIGEST, conn->identity_digest, DIGEST_LEN))
+ return 0;
+ else
+ return 1;
}
/** The tls handshake is finished.
@@ -371,7 +378,7 @@ connection_tls_finish_handshake(connection_t *conn) {
return -1;
}
- if (!digest_is_zero(conn->identity_digest)) {
+ if (connection_or_nonopen_was_started_here(conn)) {
/* I initiated this connection. */
if (strcasecmp(conn->nickname, nickname)) {
log_fn(options.DirPort ? LOG_WARN : LOG_INFO,
diff --git a/src/or/or.h b/src/or/or.h
index 0c614d86a1..db128a09a1 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -1110,6 +1110,7 @@ int connection_state_is_connecting(connection_t *conn);
int connection_send_destroy(uint16_t circ_id, connection_t *conn);
void assert_connection_ok(connection_t *conn, time_t now);
+int connection_or_nonopen_was_started_here(connection_t *conn);
/********************************* connection_edge.c ***************************/