[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[or-cvs] make reusing circuits work (and be the default)
Update of /home/or/cvsroot/src/or
In directory moria.mit.edu:/home/arma/work/onion/cvs/src/or
Modified Files:
circuit.c connection.c connection_ap.c connection_exit.c dns.c
or.h
Log Message:
make reusing circuits work (and be the default)
performance is better, but not by much. not sure why yet.
Index: circuit.c
===================================================================
RCS file: /home/or/cvsroot/src/or/circuit.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- circuit.c 26 Jan 2003 09:02:24 -0000 1.21
+++ circuit.c 6 Feb 2003 08:00:49 -0000 1.22
@@ -252,13 +252,32 @@
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 @@
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 @@
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);
Index: connection.c
===================================================================
RCS file: /home/or/cvsroot/src/or/connection.c,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -d -r1.33 -r1.34
--- connection.c 26 Jan 2003 09:02:24 -0000 1.33
+++ connection.c 6 Feb 2003 08:00:49 -0000 1.34
@@ -622,7 +622,7 @@
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 @@
}
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.");
Index: connection_ap.c
===================================================================
RCS file: /home/or/cvsroot/src/or/connection_ap.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- connection_ap.c 26 Jan 2003 09:02:24 -0000 1.22
+++ connection_ap.c 6 Feb 2003 08:00:49 -0000 1.23
@@ -123,20 +123,24 @@
}
/* 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 @@
connection_t *conn;
int topic_command;
int topic_id;
+ static int num_seen=0;
/* an incoming data cell has arrived */
@@ -379,6 +384,9 @@
*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);
Index: connection_exit.c
===================================================================
RCS file: /home/or/cvsroot/src/or/connection_exit.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- connection_exit.c 26 Jan 2003 09:02:24 -0000 1.16
+++ connection_exit.c 6 Feb 2003 08:00:49 -0000 1.17
@@ -164,6 +164,7 @@
connection_t *conn;
int topic_command;
int topic_id;
+ static num_seen=0;
/* an outgoing data cell has arrived */
@@ -173,6 +174,8 @@
*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);
Index: dns.c
===================================================================
RCS file: /home/or/cvsroot/src/or/dns.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- dns.c 26 Jan 2003 09:02:24 -0000 1.1
+++ dns.c 6 Feb 2003 08:00:49 -0000 1.2
@@ -55,6 +55,9 @@
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 @@
}
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 @@
&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 @@
return -1;
}
- log(LOG_DEBUG,"dns_tor_to_master(): submitted '%s'", address);
+// log(LOG_DEBUG,"dns_tor_to_master(): submitted '%s'", address);
return 0;
}
Index: or.h
===================================================================
RCS file: /home/or/cvsroot/src/or/or.h,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -d -r1.42 -r1.43
--- or.h 26 Jan 2003 09:02:24 -0000 1.42
+++ or.h 6 Feb 2003 08:00:49 -0000 1.43
@@ -454,6 +454,7 @@
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);