diff options
author | Roger Dingledine <arma@torproject.org> | 2003-02-06 23:48:35 +0000 |
---|---|---|
committer | Roger Dingledine <arma@torproject.org> | 2003-02-06 23:48:35 +0000 |
commit | 0bc8dc1314652e8b5ccaa89a98c1a9922422ae1d (patch) | |
tree | cc6ef22f079992904f06f7e7149f8af450e4592c /src | |
parent | ceafe12ed67528ce4dd656f43bccb7c7a9f7317f (diff) | |
download | tor-0bc8dc1314652e8b5ccaa89a98c1a9922422ae1d.tar tor-0bc8dc1314652e8b5ccaa89a98c1a9922422ae1d.tar.gz |
fix endian issues for topics -- they might work on bsd now
(they wouldn't have before)
alternate code which bypasses the dns farm, so we can compare speed
svn:r154
Diffstat (limited to 'src')
-rw-r--r-- | src/or/circuit.c | 2 | ||||
-rw-r--r-- | src/or/connection.c | 4 | ||||
-rw-r--r-- | src/or/connection_ap.c | 8 | ||||
-rw-r--r-- | src/or/connection_exit.c | 9 | ||||
-rw-r--r-- | src/or/dns.c | 26 | ||||
-rw-r--r-- | src/or/or.h | 4 |
6 files changed, 35 insertions, 18 deletions
diff --git a/src/or/circuit.c b/src/or/circuit.c index 7ac467080..bdb168820 100644 --- a/src/or/circuit.c +++ b/src/or/circuit.c @@ -546,7 +546,7 @@ void circuit_about_to_close_connection(connection_t *conn) { memset(&cell, 0, sizeof(cell_t)); cell.command = CELL_DATA; cell.length = TOPIC_HEADER_SIZE; - *(uint32_t *)cell.payload = conn->topic_id; + *(uint16_t *)(cell.payload+2) = htons(conn->topic_id); *cell.payload = TOPIC_COMMAND_END; if(conn == circ->p_conn) { diff --git a/src/or/connection.c b/src/or/connection.c index 7b4ad843b..fd16c195c 100644 --- a/src/or/connection.c +++ b/src/or/connection.c @@ -617,7 +617,7 @@ repeat_connection_package_raw_inbuf: log(LOG_DEBUG,"connection_package_raw_inbuf(): Packaging %d bytes (%d waiting).",cell.length, amount_to_process); - *(uint32_t *)cell.payload = conn->topic_id; + *(uint16_t *)(cell.payload+2) = htons(conn->topic_id); *cell.payload = TOPIC_COMMAND_DATA; cell.length += TOPIC_HEADER_SIZE; cell.command = CELL_DATA; @@ -673,7 +673,7 @@ int connection_consider_sending_sendme(connection_t *conn, int edge_type) { return 0; } - *(uint32_t *)cell.payload = conn->topic_id; + *(uint16_t *)(cell.payload+2) = htons(conn->topic_id); *cell.payload = TOPIC_COMMAND_SENDME; cell.length += TOPIC_HEADER_SIZE; cell.command = CELL_DATA; diff --git a/src/or/connection_ap.c b/src/or/connection_ap.c index a47fb4436..2173d0998 100644 --- a/src/or/connection_ap.c +++ b/src/or/connection_ap.c @@ -336,10 +336,9 @@ int ap_handshake_send_begin(connection_t *ap_conn, circuit_t *circ) { /* deliver the dest_addr in a data cell */ cell.command = CELL_DATA; cell.aci = circ->n_aci; - crypto_pseudo_rand(3, cell.payload+1); /* byte 0 is blank, bytes 1-3 are random */ + crypto_pseudo_rand(2, cell.payload+2); /* bytes 0-1 is blank, bytes 2-3 are random */ /* FIXME check for collisions */ - cell.payload[0] = 0; - ap_conn->topic_id = *(uint32_t *)cell.payload; + ap_conn->topic_id = ntohs(*(uint16_t *)(cell.payload+2)); cell.payload[0] = TOPIC_COMMAND_BEGIN; snprintf(cell.payload+4, CELL_PAYLOAD_SIZE-4, "%s,%d", ap_conn->dest_addr, ap_conn->dest_port); cell.length = strlen(cell.payload+TOPIC_HEADER_SIZE)+1+TOPIC_HEADER_SIZE; @@ -381,8 +380,7 @@ int connection_ap_process_data_cell(cell_t *cell, circuit_t *circ) { assert(cell && circ); topic_command = *cell->payload; - *cell->payload = 0; - topic_id = *(uint32_t *)cell->payload; + topic_id = ntohs(*(uint16_t *)(cell->payload+2)); log(LOG_DEBUG,"connection_ap_process_data_cell(): command %d topic %d", topic_command, topic_id); num_seen++; log(LOG_DEBUG,"connection_exit_process_data_cell(): Now seen %d data cells here.", num_seen); diff --git a/src/or/connection_exit.c b/src/or/connection_exit.c index 8d3f9ceea..d741042c1 100644 --- a/src/or/connection_exit.c +++ b/src/or/connection_exit.c @@ -88,7 +88,7 @@ int connection_exit_send_connected(connection_t *conn) { memset(&cell, 0, sizeof(cell_t)); cell.aci = circ->p_aci; cell.command = CELL_DATA; - *(uint32_t *)cell.payload = conn->topic_id; + *(uint16_t *)(cell.payload+2) = htons(conn->topic_id); *cell.payload = TOPIC_COMMAND_CONNECTED; cell.length = TOPIC_HEADER_SIZE; log(LOG_INFO,"connection_exit_send_connected(): passing back cell (aci %d).",circ->p_aci); @@ -129,7 +129,7 @@ int connection_exit_begin_conn(cell_t *cell, circuit_t *circ) { } cell->payload[0] = 0; - n_conn->topic_id = *(uint32_t *)(cell->payload); + n_conn->topic_id = ntohs(*(uint16_t *)(cell->payload+2)); n_conn->address = strdup(cell->payload + TOPIC_HEADER_SIZE); n_conn->port = atoi(comma+1); @@ -150,7 +150,7 @@ int connection_exit_begin_conn(cell_t *cell, circuit_t *circ) { circ->n_conn = n_conn; /* send it off to the gethostbyname farm */ - if(dns_tor_to_master(n_conn->address) < 0) { + if(dns_tor_to_master(n_conn) < 0) { log(LOG_DEBUG,"connection_exit_begin_conn(): Couldn't queue resolve request."); connection_remove(n_conn); connection_free(n_conn); @@ -171,8 +171,7 @@ int connection_exit_process_data_cell(cell_t *cell, circuit_t *circ) { assert(cell && circ); topic_command = *cell->payload; - *cell->payload = 0; - topic_id = *(uint32_t *)cell->payload; + topic_id = ntohs(*(uint16_t *)(cell->payload+2)); log(LOG_DEBUG,"connection_exit_process_data_cell(): command %d topic %d", topic_command, topic_id); num_seen++; log(LOG_DEBUG,"connection_exit_process_data_cell(): Now seen %d data cells here.", num_seen); diff --git a/src/or/dns.c b/src/or/dns.c index 1bfaaee26..6ba43358b 100644 --- a/src/or/dns.c +++ b/src/or/dns.c @@ -339,10 +339,30 @@ static int dns_master_to_tor(int from, int to) { return 0; } -int dns_tor_to_master(char *address) { +int dns_tor_to_master(connection_t *exitconn) { connection_t *conn; unsigned char len; +#ifdef DO_DNS_DIRECTLY + /* new version which does it all right here */ + struct hostent *rent; + rent = gethostbyname(exitconn->address); + if (!rent) { + return -1; + } + + memcpy((char *)&exitconn->addr, rent->h_addr, rent->h_length); + exitconn->addr = ntohl(exitconn->addr); /* get it back to host order */ + + if(connection_exit_connect(exitconn) < 0) { + exitconn->marked_for_close = 1; + } + return 0; +#endif + + + + /* old version which actually uses the dns farm */ conn = connection_get_by_type(CONN_TYPE_DNSMASTER); if(!conn) { log(LOG_ERR,"dns_tor_to_master(): dns master nowhere to be found!"); @@ -350,13 +370,13 @@ int dns_tor_to_master(char *address) { return -1; } - len = strlen(address); + len = strlen(exitconn->address); if(connection_write_to_buf(&len, 1, conn) < 0) { log(LOG_DEBUG,"dns_tor_to_master(): Couldn't write length."); return -1; } - if(connection_write_to_buf(address, len, conn) < 0) { + if(connection_write_to_buf(exitconn->address, len, conn) < 0) { log(LOG_DEBUG,"dns_tor_to_master(): Couldn't write address."); return -1; } diff --git a/src/or/or.h b/src/or/or.h index f4a1797f1..8d5d84219 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -259,7 +259,7 @@ struct connection_t { /* used by exit and ap: */ - uint32_t topic_id; + uint16_t topic_id; struct connection_t *next_topic; int n_receive_topicwindow; int p_receive_topicwindow; @@ -650,7 +650,7 @@ int connection_dir_handle_listener_read(connection_t *conn); int connection_dns_finished_flushing(connection_t *conn); int connection_dns_process_inbuf(connection_t *conn); -int dns_tor_to_master(char *address); +int dns_tor_to_master(connection_t *exitconn); int dns_master_start(void); /********************************* main.c ***************************/ |