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
This commit is contained in:
Roger Dingledine 2003-02-06 23:48:35 +00:00
parent ceafe12ed6
commit 0bc8dc1314
6 changed files with 35 additions and 18 deletions

View File

@ -546,7 +546,7 @@ void circuit_about_to_close_connection(connection_t *conn) {
memset(&cell, 0, sizeof(cell_t)); memset(&cell, 0, sizeof(cell_t));
cell.command = CELL_DATA; cell.command = CELL_DATA;
cell.length = TOPIC_HEADER_SIZE; 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; *cell.payload = TOPIC_COMMAND_END;
if(conn == circ->p_conn) { if(conn == circ->p_conn) {

View File

@ -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); 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.payload = TOPIC_COMMAND_DATA;
cell.length += TOPIC_HEADER_SIZE; cell.length += TOPIC_HEADER_SIZE;
cell.command = CELL_DATA; cell.command = CELL_DATA;
@ -673,7 +673,7 @@ int connection_consider_sending_sendme(connection_t *conn, int edge_type) {
return 0; return 0;
} }
*(uint32_t *)cell.payload = conn->topic_id; *(uint16_t *)(cell.payload+2) = htons(conn->topic_id);
*cell.payload = TOPIC_COMMAND_SENDME; *cell.payload = TOPIC_COMMAND_SENDME;
cell.length += TOPIC_HEADER_SIZE; cell.length += TOPIC_HEADER_SIZE;
cell.command = CELL_DATA; cell.command = CELL_DATA;

View File

@ -336,10 +336,9 @@ int ap_handshake_send_begin(connection_t *ap_conn, circuit_t *circ) {
/* deliver the dest_addr in a data cell */ /* deliver the dest_addr in a data cell */
cell.command = CELL_DATA; cell.command = CELL_DATA;
cell.aci = circ->n_aci; 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 */ /* FIXME check for collisions */
cell.payload[0] = 0; ap_conn->topic_id = ntohs(*(uint16_t *)(cell.payload+2));
ap_conn->topic_id = *(uint32_t *)cell.payload;
cell.payload[0] = TOPIC_COMMAND_BEGIN; cell.payload[0] = TOPIC_COMMAND_BEGIN;
snprintf(cell.payload+4, CELL_PAYLOAD_SIZE-4, "%s,%d", ap_conn->dest_addr, ap_conn->dest_port); 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; 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); assert(cell && circ);
topic_command = *cell->payload; topic_command = *cell->payload;
*cell->payload = 0; topic_id = ntohs(*(uint16_t *)(cell->payload+2));
topic_id = *(uint32_t *)cell->payload;
log(LOG_DEBUG,"connection_ap_process_data_cell(): command %d topic %d", topic_command, topic_id); log(LOG_DEBUG,"connection_ap_process_data_cell(): command %d topic %d", topic_command, topic_id);
num_seen++; num_seen++;
log(LOG_DEBUG,"connection_exit_process_data_cell(): Now seen %d data cells here.", num_seen); log(LOG_DEBUG,"connection_exit_process_data_cell(): Now seen %d data cells here.", num_seen);

View File

@ -88,7 +88,7 @@ int connection_exit_send_connected(connection_t *conn) {
memset(&cell, 0, sizeof(cell_t)); memset(&cell, 0, sizeof(cell_t));
cell.aci = circ->p_aci; cell.aci = circ->p_aci;
cell.command = CELL_DATA; 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.payload = TOPIC_COMMAND_CONNECTED;
cell.length = TOPIC_HEADER_SIZE; cell.length = TOPIC_HEADER_SIZE;
log(LOG_INFO,"connection_exit_send_connected(): passing back cell (aci %d).",circ->p_aci); 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; 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->address = strdup(cell->payload + TOPIC_HEADER_SIZE);
n_conn->port = atoi(comma+1); 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; circ->n_conn = n_conn;
/* send it off to the gethostbyname farm */ /* 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."); log(LOG_DEBUG,"connection_exit_begin_conn(): Couldn't queue resolve request.");
connection_remove(n_conn); connection_remove(n_conn);
connection_free(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); assert(cell && circ);
topic_command = *cell->payload; topic_command = *cell->payload;
*cell->payload = 0; topic_id = ntohs(*(uint16_t *)(cell->payload+2));
topic_id = *(uint32_t *)cell->payload;
log(LOG_DEBUG,"connection_exit_process_data_cell(): command %d topic %d", topic_command, topic_id); log(LOG_DEBUG,"connection_exit_process_data_cell(): command %d topic %d", topic_command, topic_id);
num_seen++; num_seen++;
log(LOG_DEBUG,"connection_exit_process_data_cell(): Now seen %d data cells here.", num_seen); log(LOG_DEBUG,"connection_exit_process_data_cell(): Now seen %d data cells here.", num_seen);

View File

@ -339,10 +339,30 @@ static int dns_master_to_tor(int from, int to) {
return 0; return 0;
} }
int dns_tor_to_master(char *address) { int dns_tor_to_master(connection_t *exitconn) {
connection_t *conn; connection_t *conn;
unsigned char len; 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); conn = connection_get_by_type(CONN_TYPE_DNSMASTER);
if(!conn) { if(!conn) {
log(LOG_ERR,"dns_tor_to_master(): dns master nowhere to be found!"); 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; return -1;
} }
len = strlen(address); len = strlen(exitconn->address);
if(connection_write_to_buf(&len, 1, conn) < 0) { if(connection_write_to_buf(&len, 1, conn) < 0) {
log(LOG_DEBUG,"dns_tor_to_master(): Couldn't write length."); log(LOG_DEBUG,"dns_tor_to_master(): Couldn't write length.");
return -1; 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."); log(LOG_DEBUG,"dns_tor_to_master(): Couldn't write address.");
return -1; return -1;
} }

View File

@ -259,7 +259,7 @@ struct connection_t {
/* used by exit and ap: */ /* used by exit and ap: */
uint32_t topic_id; uint16_t topic_id;
struct connection_t *next_topic; struct connection_t *next_topic;
int n_receive_topicwindow; int n_receive_topicwindow;
int p_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_finished_flushing(connection_t *conn);
int connection_dns_process_inbuf(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); int dns_master_start(void);
/********************************* main.c ***************************/ /********************************* main.c ***************************/