performance is better, but not by much. not sure why yet.
svn:r153
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);
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);
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);
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.");
}
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.");
}
/* 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;
}
}
connection_t *conn;
int topic_command;
int topic_id;
+ static int num_seen=0;
/* an incoming data cell has arrived */
*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);
connection_t *conn;
int topic_command;
int topic_id;
+ static num_seen=0;
/* an outgoing data cell has arrived */
*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);
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);
}
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;
}
&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;
}
return -1;
}
- log(LOG_DEBUG,"dns_tor_to_master(): submitted '%s'", address);
+// log(LOG_DEBUG,"dns_tor_to_master(): submitted '%s'", address);
return 0;
}
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);