[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] r12391: Make VERSIONS variable-length. (in tor/trunk: . doc src/or)
Author: nickm
Date: 2007-11-05 18:34:39 -0500 (Mon, 05 Nov 2007)
New Revision: 12391
Modified:
tor/trunk/
tor/trunk/doc/TODO
tor/trunk/src/or/buffers.c
tor/trunk/src/or/command.c
tor/trunk/src/or/connection_or.c
tor/trunk/src/or/or.h
Log:
r14727@31-33-67: nickm | 2007-11-05 18:34:35 -0500
Make VERSIONS variable-length.
Property changes on: tor/trunk
___________________________________________________________________
svk:merge ticket from /tor/trunk [r14727] on d9e39d38-0f13-419c-a857-e10a0ce2aa0c
Modified: tor/trunk/doc/TODO
===================================================================
--- tor/trunk/doc/TODO 2007-11-05 21:46:35 UTC (rev 12390)
+++ tor/trunk/doc/TODO 2007-11-05 23:34:39 UTC (rev 12391)
@@ -32,7 +32,8 @@
- Variable-length cells
o Add structure
o Add parse logic
- - Make CERT and VERSIONS variable.
+ - Make CERT variable.
+ o Make VERSIONS variable.
- CERT cells
- functions to parse x509 certs
- functions to validate a single x509 cert against a TLS connection
Modified: tor/trunk/src/or/buffers.c
===================================================================
--- tor/trunk/src/or/buffers.c 2007-11-05 21:46:35 UTC (rev 12390)
+++ tor/trunk/src/or/buffers.c 2007-11-05 23:34:39 UTC (rev 12391)
@@ -1015,9 +1015,8 @@
length = ntohs(get_uint16(hdr+3));
if (buf->datalen < (size_t)(VAR_CELL_HEADER_SIZE+length))
return 1;
- result = tor_malloc(sizeof(var_cell_t)+length-1);
+ result = var_cell_new(length);
result->command = command;
- result->payload_len = length;
result->circ_id = ntohs(*(uint16_t*)hdr);
buf_remove_from_front(buf, VAR_CELL_HEADER_SIZE);
Modified: tor/trunk/src/or/command.c
===================================================================
--- tor/trunk/src/or/command.c 2007-11-05 21:46:35 UTC (rev 12390)
+++ tor/trunk/src/or/command.c 2007-11-05 23:34:39 UTC (rev 12391)
@@ -454,7 +454,6 @@
static void
command_process_versions_cell(var_cell_t *cell, or_connection_t *conn)
{
- uint16_t versionslen;
int highest_supported_version = 0;
const char *cp, *end;
if (conn->link_proto != 0 ||
@@ -466,13 +465,10 @@
return;
}
tor_assert(conn->handshake_state);
- versionslen = ntohs(get_uint16(cell->payload));
- end = cell->payload + 2 + versionslen;
- if (end > cell->payload + CELL_PAYLOAD_SIZE)
- end = cell->payload + CELL_PAYLOAD_SIZE; /*XXXX020 warn?*/
- for (cp = cell->payload + 2; cp < end; ++cp) {
- uint8_t v = *cp;
- if (v == 1) {
+ end = cell->payload + cell->payload_len;
+ for (cp = cell->payload; cp+1 < end; ++cp) {
+ uint16_t v = ntohs(get_uint16(cp));
+ if (v == 1 || v == 2) {
if (v > highest_supported_version)
highest_supported_version = v;
}
Modified: tor/trunk/src/or/connection_or.c
===================================================================
--- tor/trunk/src/or/connection_or.c 2007-11-05 21:46:35 UTC (rev 12390)
+++ tor/trunk/src/or/connection_or.c 2007-11-05 23:34:39 UTC (rev 12391)
@@ -149,13 +149,24 @@
/** DOCDOC */
void
-var_cell_pack_header(var_cell_t *cell, char *hdr_out)
+var_cell_pack_header(const var_cell_t *cell, char *hdr_out)
{
*(uint16_t*)(hdr_out) = htons(cell->circ_id);
*(uint8_t*)(hdr_out+2) = cell->command;
set_uint16(hdr_out+3, htons(cell->payload_len));
}
+/* DOCDOC*/
+var_cell_t *
+var_cell_new(uint16_t payload_len)
+{
+ var_cell_t *cell = tor_malloc(sizeof(var_cell_t)+payload_len-1);
+ cell->payload_len = payload_len;
+ cell->command = 0;
+ cell->circ_id = 0;
+ return cell;
+}
+
/** DOCDOC */
void
var_cell_free(var_cell_t *cell)
@@ -841,6 +852,19 @@
connection_write_to_buf(networkcell.body, CELL_NETWORK_SIZE, TO_CONN(conn));
}
+/**DOCDOC*/
+void
+connection_or_write_var_cell_to_buf(const var_cell_t *cell,
+ or_connection_t *conn)
+{
+ char hdr[VAR_CELL_HEADER_SIZE];
+ tor_assert(cell);
+ tor_assert(conn);
+ var_cell_pack_header(cell, hdr);
+ connection_write_to_buf(hdr, sizeof(hdr), TO_CONN(conn));
+ connection_write_to_buf(cell->payload, cell->payload_len, TO_CONN(conn));
+}
+
/** DOCDOC */
static int
connection_fetch_var_cell_from_buf(or_connection_t *conn, var_cell_t **out)
@@ -924,22 +948,21 @@
static int
connection_or_send_versions(or_connection_t *conn)
{
- cell_t cell;
- uint8_t versions[] = { 1 };
+ var_cell_t *cell;
+ uint16_t versions[] = { 1, 2 };
int n_versions = sizeof(versions) / sizeof(uint8_t);
int i;
tor_assert(conn->handshake_state &&
!conn->handshake_state->sent_versions_at);
- memset(&cell, 0, sizeof(cell_t));
- cell.command = CELL_VERSIONS;
- set_uint16(cell.payload, htons(n_versions));
+ /*XXXX020 docdoc 2-byte versions */
+ cell = var_cell_new(n_versions * 2);
+ cell->command = CELL_VERSIONS;
for (i = 0; i < n_versions; ++i) {
- uint8_t v = versions[i];
- tor_assert(v > 0 && v < 128);
- cell.payload[2+i] = v;
+ uint16_t v = versions[i];
+ set_uint16(cell->payload+(2*i), htons(v));
}
- connection_or_write_cell_to_buf(&cell, conn);
+ connection_or_write_var_cell_to_buf(cell, conn);
conn->handshake_state->sent_versions_at = time(NULL);
return 0;
@@ -1054,3 +1077,4 @@
* authenticated. */
return 0;
}
+
Modified: tor/trunk/src/or/or.h
===================================================================
--- tor/trunk/src/or/or.h 2007-11-05 21:46:35 UTC (rev 12390)
+++ tor/trunk/src/or/or.h 2007-11-05 23:34:39 UTC (rev 12391)
@@ -2790,6 +2790,8 @@
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);
+void connection_or_write_var_cell_to_buf(const var_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);
@@ -2799,7 +2801,8 @@
char *hmac_out);
void cell_pack(packed_cell_t *dest, const cell_t *src);
-void var_cell_pack_header(var_cell_t *cell, char *hdr_out);
+void var_cell_pack_header(const var_cell_t *cell, char *hdr_out);
+var_cell_t *var_cell_new(uint16_t payload_len);
void var_cell_free(var_cell_t *cell);
/********************************* control.c ***************************/