From ceafe12ed67528ce4dd656f43bccb7c7a9f7317f Mon Sep 17 00:00:00 2001 From: Roger Dingledine Date: Thu, 6 Feb 2003 08:00:49 +0000 Subject: [PATCH] make reusing circuits work (and be the default) performance is better, but not by much. not sure why yet. svn:r153 --- src/or/circuit.c | 22 ++++++++++++++++++++++ src/or/connection.c | 3 ++- src/or/connection_ap.c | 24 ++++++++++++++++-------- src/or/connection_exit.c | 3 +++ src/or/dns.c | 9 ++++++--- src/or/or.h | 1 + 6 files changed, 50 insertions(+), 12 deletions(-) diff --git a/src/or/circuit.c b/src/or/circuit.c index 6949356bf0..7ac467080a 100644 --- a/src/or/circuit.c +++ b/src/or/circuit.c @@ -252,13 +252,32 @@ circuit_t *circuit_get_by_conn(connection_t *conn) { return NULL; } +circuit_t *circuit_get_by_edge_type(char edge_type) { + circuit_t *circ; + + for(circ=global_circuitlist;circ;circ = circ->next) { + if(edge_type == EDGE_AP && circ->n_conn && circ->n_conn->type == CONN_TYPE_OR) { + log(LOG_DEBUG,"circuit_get_by_edge_type(): Choosing n_aci %d.", circ->n_aci); + return circ; + } + if(edge_type == EDGE_EXIT && circ->p_conn && circ->p_conn->type == CONN_TYPE_OR) { + return circ; + } + log(LOG_DEBUG,"circuit_get_by_edge_type(): Skipping p_aci %d / n_aci %d.", circ->p_aci, circ->n_aci); + } + return NULL; +} + int circuit_deliver_data_cell_from_edge(cell_t *cell, circuit_t *circ, char edge_type) { int cell_direction; + static int numsent_ap=0, numsent_exit=0; log(LOG_DEBUG,"circuit_deliver_data_cell_from_edge(): called, edge_type %d.", edge_type); if(edge_type == EDGE_AP) { /* i'm the AP */ cell_direction = CELL_DIRECTION_OUT; + numsent_ap++; + log(LOG_DEBUG,"circuit_deliver_data_cell_from_edge(): now sent %d data cells from ap", numsent_ap); if(circ->p_receive_circwindow <= 0) { log(LOG_DEBUG,"circuit_deliver_data_cell_from_edge(): window 0, queueing for later."); circ->data_queue = data_queue_add(circ->data_queue, cell); @@ -267,6 +286,8 @@ int circuit_deliver_data_cell_from_edge(cell_t *cell, circuit_t *circ, char edge circ->p_receive_circwindow--; } else { /* i'm the exit */ cell_direction = CELL_DIRECTION_IN; + numsent_exit++; + log(LOG_DEBUG,"circuit_deliver_data_cell_from_edge(): now sent %d data cells from exit", numsent_exit); if(circ->n_receive_circwindow <= 0) { log(LOG_DEBUG,"circuit_deliver_data_cell_from_edge(): window 0, queueing for later."); circ->data_queue = data_queue_add(circ->data_queue, cell); @@ -491,6 +512,7 @@ int circuit_consider_sending_sendme(circuit_t *circ, int edge_type) { void circuit_close(circuit_t *circ) { connection_t *conn; + assert(circ); circuit_remove(circ); for(conn=circ->n_conn; conn; conn=conn->next_topic) { connection_send_destroy(circ->n_aci, circ->n_conn); diff --git a/src/or/connection.c b/src/or/connection.c index f7965cdd2f..7b4ad843b5 100644 --- a/src/or/connection.c +++ b/src/or/connection.c @@ -622,7 +622,7 @@ repeat_connection_package_raw_inbuf: cell.length += TOPIC_HEADER_SIZE; cell.command = CELL_DATA; - if(circ->n_conn == conn) { /* send it backward. we're an exit. */ + if(conn->type == CONN_TYPE_EXIT) { cell.aci = circ->p_aci; if(circuit_deliver_data_cell_from_edge(&cell, circ, EDGE_EXIT) < 0) { log(LOG_DEBUG,"connection_package_raw_inbuf(): circuit_deliver_data_cell_from_edge (backward) failed. Closing."); @@ -637,6 +637,7 @@ repeat_connection_package_raw_inbuf: } log(LOG_DEBUG,"connection_package_raw_inbuf(): receive_topicwindow at exit is %d",conn->n_receive_topicwindow); } else { /* send it forward. we're an AP */ + assert(conn->type == CONN_TYPE_AP); cell.aci = circ->n_aci; if(circuit_deliver_data_cell_from_edge(&cell, circ, EDGE_AP) < 0) { log(LOG_DEBUG,"connection_package_raw_inbuf(): circuit_deliver_data_cell_from_edge (forward) failed. Closing."); diff --git a/src/or/connection_ap.c b/src/or/connection_ap.c index 978a9dd029..a47fb44360 100644 --- a/src/or/connection_ap.c +++ b/src/or/connection_ap.c @@ -123,20 +123,24 @@ int ap_handshake_process_socks(connection_t *conn) { } /* find the circuit that we should use, if there is one. */ - circ = NULL; /* FIXME don't reuse circs, at least for me. */ + circ = circuit_get_by_edge_type(EDGE_AP); /* now we're all ready to make an onion or send a begin */ - if(circ) { - if(circ->state == CIRCUIT_STATE_OPEN) { - if(ap_handshake_send_begin(conn, circ) < 0) { - circuit_close(circ); - return -1; - } + if(circ && circ->state == CIRCUIT_STATE_OPEN) { + /* add it into the linked list of topics on this circuit */ + log(LOG_DEBUG,"ap_handshake_process_socks(): attaching new conn to circ. n_aci %d.", circ->n_aci); + conn->next_topic = circ->p_conn; + circ->p_conn = conn; + + if(ap_handshake_send_begin(conn, circ) < 0) { + circuit_close(circ); + return -1; } } else { if(ap_handshake_create_onion(conn) < 0) { - circuit_close(circ); + if(circ) + circuit_close(circ); return -1; } } @@ -370,6 +374,7 @@ int connection_ap_process_data_cell(cell_t *cell, circuit_t *circ) { connection_t *conn; int topic_command; int topic_id; + static int num_seen=0; /* an incoming data cell has arrived */ @@ -379,6 +384,9 @@ int connection_ap_process_data_cell(cell_t *cell, circuit_t *circ) { *cell->payload = 0; topic_id = *(uint32_t *)cell->payload; 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); + circuit_consider_sending_sendme(circ, EDGE_AP); diff --git a/src/or/connection_exit.c b/src/or/connection_exit.c index 871b789ef4..8d3f9ceea9 100644 --- a/src/or/connection_exit.c +++ b/src/or/connection_exit.c @@ -164,6 +164,7 @@ int connection_exit_process_data_cell(cell_t *cell, circuit_t *circ) { connection_t *conn; int topic_command; int topic_id; + static num_seen=0; /* an outgoing data cell has arrived */ @@ -173,6 +174,8 @@ int connection_exit_process_data_cell(cell_t *cell, circuit_t *circ) { *cell->payload = 0; topic_id = *(uint32_t *)cell->payload; 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); circuit_consider_sending_sendme(circ, EDGE_EXIT); diff --git a/src/or/dns.c b/src/or/dns.c index d730159578..1bfaaee266 100644 --- a/src/or/dns.c +++ b/src/or/dns.c @@ -55,6 +55,9 @@ int connection_dns_process_inbuf(connection_t *conn) { assert(conn->inbuf); + if(conn->inbuf_datalen <= 0) + return 0; + /* peek into the inbuf, so we can check if it's all here */ length = *conn->inbuf; /* warning: abstraction violation :( */ assert(length < 240); @@ -231,7 +234,7 @@ int dns_read_block(int fd, char *string, unsigned char *len) { } string[*len] = 0; /* null terminate it, just in case */ - log(LOG_INFO,"dns_read_block(): Read '%s', len %u.",string,*len); // XXX make silent +// log(LOG_INFO,"dns_read_block(): Read '%s', len %u.",string,*len); return 0; } @@ -267,7 +270,7 @@ static int dns_read_tor_question(int index) { &slave_data[index].question_len) < 0) return -1; - log(LOG_INFO,"dns_read_tor_question(): Read question '%s'",slave_data[index].question); +// log(LOG_INFO,"dns_read_tor_question(): Read question '%s'",slave_data[index].question); return 0; } @@ -358,7 +361,7 @@ int dns_tor_to_master(char *address) { return -1; } - log(LOG_DEBUG,"dns_tor_to_master(): submitted '%s'", address); +// log(LOG_DEBUG,"dns_tor_to_master(): submitted '%s'", address); return 0; } diff --git a/src/or/or.h b/src/or/or.h index 746d4c898a..f4a1797f12 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -454,6 +454,7 @@ aci_t get_unique_aci_by_addr_port(uint32_t addr, uint16_t port, int aci_type); circuit_t *circuit_get_by_aci_conn(aci_t aci, connection_t *conn); circuit_t *circuit_get_by_conn(connection_t *conn); +circuit_t *circuit_get_by_edge_type(char edge_type); circuit_t *circuit_enumerate_by_naddr_nport(circuit_t *start, uint32_t naddr, uint16_t nport); int circuit_deliver_data_cell_from_edge(cell_t *cell, circuit_t *circ, char edge_type);