Commit ceafe12e authored by Roger Dingledine's avatar Roger Dingledine
Browse files

make reusing circuits work (and be the default)

performance is better, but not by much. not sure why yet.


svn:r153
parent c35373a2
......@@ -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);
......
......@@ -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.");
......
......@@ -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);
......
......@@ -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);
......
......@@ -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;
}
......
......@@ -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);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment