[or-cvs] Unify tests for "did I originate this nonopen OR connection?"
Nick Mathewson
nickm at seul.org
Wed Oct 13 20:06:00 UTC 2004
Update of /home/or/cvsroot/src/or
In directory moria.mit.edu:/tmp/cvs-serv23862/src/or
Modified Files:
connection.c connection_or.c or.h
Log Message:
Unify tests for "did I originate this nonopen OR connection?"
Index: connection.c
===================================================================
RCS file: /home/or/cvsroot/src/or/connection.c,v
retrieving revision 1.256
retrieving revision 1.257
diff -u -d -r1.256 -r1.257
--- connection.c 13 Oct 2004 19:55:40 -0000 1.256
+++ connection.c 13 Oct 2004 20:05:57 -0000 1.257
@@ -192,13 +192,7 @@
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));
Index: connection_or.c
===================================================================
RCS file: /home/or/cvsroot/src/or/connection_or.c,v
retrieving revision 1.128
retrieving revision 1.129
diff -u -d -r1.128 -r1.129
--- connection_or.c 13 Oct 2004 01:13:37 -0000 1.128
+++ connection_or.c 13 Oct 2004 20:05:57 -0000 1.129
@@ -300,10 +300,17 @@
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 @@
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,
Index: or.h
===================================================================
RCS file: /home/or/cvsroot/src/or/or.h,v
retrieving revision 1.427
retrieving revision 1.428
diff -u -d -r1.427 -r1.428
--- or.h 13 Oct 2004 19:56:42 -0000 1.427
+++ or.h 13 Oct 2004 20:05:57 -0000 1.428
@@ -1110,6 +1110,7 @@
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 ***************************/
More information about the tor-commits
mailing list