[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] r12286: Implement (but do not enable) link connection version negoti (in tor/trunk: . doc src/common src/or)
Author: nickm
Date: 2007-10-30 17:46:02 -0400 (Tue, 30 Oct 2007)
New Revision: 12286
Modified:
tor/trunk/
tor/trunk/doc/TODO
tor/trunk/src/common/tortls.c
tor/trunk/src/common/tortls.h
tor/trunk/src/or/command.c
tor/trunk/src/or/connection_or.c
tor/trunk/src/or/or.h
Log:
r16285@catbus: nickm | 2007-10-30 17:43:25 -0400
Implement (but do not enable) link connection version negotiation
Property changes on: tor/trunk
___________________________________________________________________
svk:merge ticket from /tor/trunk [r16285] on 8246c3cf-6607-4228-993b-4d95d33730f1
Modified: tor/trunk/doc/TODO
===================================================================
--- tor/trunk/doc/TODO 2007-10-30 18:31:30 UTC (rev 12285)
+++ tor/trunk/doc/TODO 2007-10-30 21:46:02 UTC (rev 12286)
@@ -43,7 +43,7 @@
- 105 only
- Need to get a finished proposal 105
o "Pick a version" function
- - Have a 'waiting_for_version' state.
+ o Have a 'waiting_for_version' state.
o Store version in or_connection_t.
o Generate netinfo cells
o Accept netinfo cells
@@ -52,7 +52,7 @@
o Set it when we get a match for a routerinfo we have.
- Don't extend a circuit over a noncanonical connection with
mismatched address.
- - Version negotiation: send a version cell and enter
+ o Version negotiation: send a version cell and enter
waiting-for-version; when version cell arrives, pick version
and send netinfo and be "open".
o On netinfo, warn if there's skew from a server.
Modified: tor/trunk/src/common/tortls.c
===================================================================
--- tor/trunk/src/common/tortls.c 2007-10-30 18:31:30 UTC (rev 12285)
+++ tor/trunk/src/common/tortls.c 2007-10-30 21:46:02 UTC (rev 12286)
@@ -888,3 +888,10 @@
tls_log_errors(LOG_WARN, NULL);
}
+/**DOCDOC */
+int
+tor_tls_used_v1_handshake(tor_tls_t *tls)
+{
+ (void)tls;
+ return 1;
+}
Modified: tor/trunk/src/common/tortls.h
===================================================================
--- tor/trunk/src/common/tortls.h 2007-10-30 18:31:30 UTC (rev 12285)
+++ tor/trunk/src/common/tortls.h 2007-10-30 21:46:02 UTC (rev 12286)
@@ -64,6 +64,8 @@
void tor_tls_get_n_raw_bytes(tor_tls_t *tls,
size_t *n_read, size_t *n_written);
+int tor_tls_used_v1_handshake(tor_tls_t *tls);
+
/* Log and abort if there are unhandled TLS errors in OpenSSL's error stack.
*/
#define check_no_tls_errors() _check_no_tls_errors(__FILE__,__LINE__)
Modified: tor/trunk/src/or/command.c
===================================================================
--- tor/trunk/src/or/command.c 2007-10-30 18:31:30 UTC (rev 12285)
+++ tor/trunk/src/or/command.c 2007-10-30 21:46:02 UTC (rev 12286)
@@ -395,7 +395,8 @@
uint16_t versionslen;
int highest_supported_version = 0;
const char *cp, *end;
- if (conn->link_proto != 0) {
+ if (conn->link_proto != 0 ||
+ conn->_base.state != OR_CONN_STATE_WAITING_FOR_VERSIONS) {
log_fn(LOG_PROTOCOL_WARN, LD_OR,
"Received a VERSIONS cell on a connection with its version "
"already set to %d; dropping", (int) conn->link_proto);
@@ -412,13 +413,18 @@
highest_supported_version = v;
}
}
- if (!versionslen) {
+ if (!highest_supported_version) {
log_fn(LOG_PROTOCOL_WARN, LD_OR,
"Couldn't find a version in common; defaulting to v1.");
/*XXXX020 or just break the connection?*/
conn->link_proto = 1;
return;
}
+ conn->link_proto = highest_supported_version;
+ conn->_base.state = OR_CONN_STATE_OPEN;
+
+ if (highest_supported_version >= 2)
+ connection_or_send_netinfo(conn);
}
/** Process a 'netinfo' cell. DOCDOC say more. */
@@ -433,9 +439,9 @@
uint8_t n_other_addrs;
time_t now = time(NULL);
- /*XXXX020 reject duplicat netinfos. */
+ /*XXXX020 reject duplicate netinfos. */
- if (conn->link_proto < 2) {
+ if (conn->link_proto < 2 || conn->_base.state != OR_CONN_STATE_OPEN) {
log_fn(LOG_PROTOCOL_WARN, LD_OR,
"Received a NETINFO cell on %s connection; dropping.",
conn->link_proto == 0 ? "non-versioned" : "a v1");
Modified: tor/trunk/src/or/connection_or.c
===================================================================
--- tor/trunk/src/or/connection_or.c 2007-10-30 18:31:30 UTC (rev 12285)
+++ tor/trunk/src/or/connection_or.c 2007-10-30 21:46:02 UTC (rev 12286)
@@ -16,6 +16,7 @@
static int connection_tls_finish_handshake(or_connection_t *conn);
static int connection_or_process_cells_from_inbuf(or_connection_t *conn);
+static int connection_or_send_versions(or_connection_t *conn);
/**************************************************************/
@@ -732,8 +733,25 @@
}
directory_set_dirty();
+
+ if (tor_tls_used_v1_handshake(conn->tls)) {
+ conn->link_proto = 1;
+ return connection_or_set_state_open(conn);
+ } else {
+ /*XXXX020 actually, we'll need to send some kind of authentication. */
+ conn->_base.state = OR_CONN_STATE_WAITING_FOR_VERSIONS;
+ return connection_or_send_versions(conn);
+ }
+}
+
+/**DOCDOC*/
+int
+connection_or_set_state_open(or_connection_t *conn)
+{
+ int started_here = connection_or_nonopen_was_started_here(conn);
conn->_base.state = OR_CONN_STATE_OPEN;
control_event_or_conn_status(conn, OR_CONN_EVENT_CONNECTED, 0);
+
if (started_here) {
rep_hist_note_connect_succeeded(conn->identity_digest, time(NULL));
if (entry_guard_register_connect_status(conn->identity_digest, 1,
@@ -746,7 +764,6 @@
connection_watch_events(TO_CONN(conn), EV_READ);
circuit_n_conn_done(conn, 1); /* send the pending creates, if any. */
- conn->link_proto = 1; /* Version negotiation not yet enabled.XXX020 */
return 0;
}
@@ -850,10 +867,12 @@
}
connection_or_write_cell_to_buf(&cell, conn);
+
+ return 0;
}
/** DOCDOC */
-static int
+int
connection_or_send_netinfo(or_connection_t *conn)
{
cell_t cell;
@@ -881,7 +900,5 @@
connection_or_write_cell_to_buf(&cell, conn);
- /*XXXX020 remove these once we send netinfo and versions cells. */
- (void) connection_or_send_netinfo;
- (void) connection_or_send_versions;
+ return 0;
}
Modified: tor/trunk/src/or/or.h
===================================================================
--- tor/trunk/src/or/or.h 2007-10-30 18:31:30 UTC (rev 12285)
+++ tor/trunk/src/or/or.h 2007-10-30 21:46:02 UTC (rev 12286)
@@ -236,9 +236,12 @@
#define OR_CONN_STATE_PROXY_READING 3
/** State for a connection to an OR: SSL is handshaking, not done yet. */
#define OR_CONN_STATE_HANDSHAKING 4
+/** State for a connection to an OR: We sent a VERSIONS cell and want one back
+ */
+#define OR_CONN_STATE_WAITING_FOR_VERSIONS 5
/** State for a connection to an OR: Ready to send/receive cells. */
-#define OR_CONN_STATE_OPEN 5
-#define _OR_CONN_STATE_MAX 5
+#define OR_CONN_STATE_OPEN 6
+#define _OR_CONN_STATE_MAX 6
#define _EXIT_CONN_STATE_MIN 1
/** State for an exit connection: waiting for response from dns farm. */
@@ -2717,10 +2720,12 @@
int connection_tls_start_handshake(or_connection_t *conn, int receiving);
int connection_tls_continue_handshake(or_connection_t *conn);
+int connection_or_set_state_open(or_connection_t *conn);
void connection_or_write_cell_to_buf(const cell_t *cell,
or_connection_t *conn);
int connection_or_send_destroy(uint16_t circ_id, or_connection_t *conn,
int reason);
+int connection_or_send_netinfo(or_connection_t *conn);
void cell_pack(packed_cell_t *dest, const cell_t *src);