Implemented link padding and receiver token buckets
Each socket reads at most 'bandwidth' bytes per second sustained, but
can handle bursts of up to 10*bandwidth bytes.
Cells are now sent out at evenly-spaced intervals, with padding sent
out otherwise. Set Linkpadding=0 in the rc file to send cells as soon
as they're available (and to never send padding cells).
Added license/copyrights statements at the top of most files.
router->min and router->max have been merged into a single 'bandwidth'
value. We should make the routerinfo_t reflect this (want to do that,
Mat?)
As the bandwidth increases, and we want to stop sleeping more and more
frequently to send a single cell, cpu usage goes up. At 128kB/s we're
pretty much calling poll with a timeout of 1ms or even 0ms. The current
code takes a timeout of 0-9ms and makes it 10ms. prepare_for_poll()
handles everything that should have happened in the past, so as long as
our buffers don't get too full in that 10ms, we're ok.
Speaking of too full, if you run three servers at 100kB/s with -l debug,
it spends too much time printing debugging messages to be able to keep
up with the cells. The outbuf ultimately fills up and it kills that
connection. If you run with -l err, it works fine up through 500kB/s and
probably beyond. Down the road we'll want to teach it to recognize when
an outbuf is getting full, and back off.
svn:r50
2002-07-16 03:12:15 +02:00
|
|
|
/* Copyright 2001,2002 Roger Dingledine, Matej Pfajfar. */
|
|
|
|
/* See LICENSE for licensing information */
|
|
|
|
/* $Id$ */
|
2002-06-27 00:45:49 +02:00
|
|
|
|
|
|
|
#include "or.h"
|
|
|
|
|
2003-04-16 08:18:31 +02:00
|
|
|
extern or_options_t options; /* command-line and config-file options */
|
|
|
|
|
2002-06-27 00:45:49 +02:00
|
|
|
/********* START VARIABLES **********/
|
|
|
|
|
2002-07-05 08:27:23 +02:00
|
|
|
static circuit_t *global_circuitlist=NULL;
|
2002-06-27 00:45:49 +02:00
|
|
|
|
2002-09-22 00:41:48 +02:00
|
|
|
char *circuit_state_to_string[] = {
|
|
|
|
"receiving the onion", /* 0 */
|
2002-11-27 05:08:20 +01:00
|
|
|
"waiting to process create", /* 1 */
|
|
|
|
"connecting to firsthop", /* 2 */
|
|
|
|
"open" /* 3 */
|
2002-09-22 00:41:48 +02:00
|
|
|
};
|
|
|
|
|
2002-06-27 00:45:49 +02:00
|
|
|
/********* END VARIABLES ************/
|
|
|
|
|
|
|
|
void circuit_add(circuit_t *circ) {
|
|
|
|
|
|
|
|
if(!global_circuitlist) { /* first one */
|
|
|
|
global_circuitlist = circ;
|
|
|
|
circ->next = NULL;
|
|
|
|
} else {
|
|
|
|
circ->next = global_circuitlist;
|
|
|
|
global_circuitlist = circ;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void circuit_remove(circuit_t *circ) {
|
|
|
|
circuit_t *tmpcirc;
|
|
|
|
|
2002-07-05 08:27:23 +02:00
|
|
|
assert(circ && global_circuitlist);
|
2002-06-27 00:45:49 +02:00
|
|
|
|
|
|
|
if(global_circuitlist == circ) {
|
|
|
|
global_circuitlist = global_circuitlist->next;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(tmpcirc = global_circuitlist;tmpcirc->next;tmpcirc = tmpcirc->next) {
|
|
|
|
if(tmpcirc->next == circ) {
|
|
|
|
tmpcirc->next = circ->next;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
circuit_t *circuit_new(aci_t p_aci, connection_t *p_conn) {
|
|
|
|
circuit_t *circ;
|
2003-04-16 08:18:31 +02:00
|
|
|
struct timeval now;
|
|
|
|
|
2003-04-16 19:04:58 +02:00
|
|
|
my_gettimeofday(&now);
|
2002-06-27 00:45:49 +02:00
|
|
|
|
|
|
|
circ = (circuit_t *)malloc(sizeof(circuit_t));
|
|
|
|
if(!circ)
|
|
|
|
return NULL;
|
|
|
|
memset(circ,0,sizeof(circuit_t)); /* zero it out */
|
|
|
|
|
2003-04-16 08:18:31 +02:00
|
|
|
circ->timestamp_created = now.tv_sec;
|
|
|
|
|
2002-06-27 00:45:49 +02:00
|
|
|
circ->p_aci = p_aci;
|
|
|
|
circ->p_conn = p_conn;
|
|
|
|
|
2002-11-27 05:08:20 +01:00
|
|
|
circ->state = CIRCUIT_STATE_ONION_WAIT;
|
2002-06-27 00:45:49 +02:00
|
|
|
|
|
|
|
/* ACIs */
|
|
|
|
circ->p_aci = p_aci;
|
2002-07-05 08:27:23 +02:00
|
|
|
/* circ->n_aci remains 0 because we haven't identified the next hop yet */
|
2002-06-27 00:45:49 +02:00
|
|
|
|
major overhaul: dns slave subsystem, topics
on startup, it forks off a master dns handler, which forks off dns
slaves (like the apache model). slaves as spawned as load increases,
and then reused. excess slaves are not ever killed, currently.
implemented topics. each topic has a receive window in each direction
at each edge of the circuit, and sends sendme's at the data level, as
per before. each circuit also has receive windows in each direction at
each hop; an edge sends a circuit-level sendme as soon as enough data
cells have arrived (regardless of whether the data cells were flushed
to the exit conns). removed the 'connected' cell type, since it's now
a topic command within data cells.
at the edge of the circuit, there can be multiple connections associated
with a single circuit. you find them via the linked list conn->next_topic.
currently each new ap connection starts its own circuit, so we ought
to see comparable performance to what we had before. but that's only
because i haven't written the code to reattach to old circuits. please
try to break it as-is, and then i'll make it reuse the same circuit and
we'll try to break that.
svn:r152
2003-01-26 10:02:24 +01:00
|
|
|
circ->n_receive_circwindow = CIRCWINDOW_START;
|
|
|
|
circ->p_receive_circwindow = CIRCWINDOW_START;
|
2002-07-18 08:37:58 +02:00
|
|
|
|
2002-06-27 00:45:49 +02:00
|
|
|
circuit_add(circ);
|
|
|
|
|
|
|
|
return circ;
|
|
|
|
}
|
|
|
|
|
|
|
|
void circuit_free(circuit_t *circ) {
|
2003-05-01 08:42:29 +02:00
|
|
|
struct relay_queue_t *tmpd;
|
2002-08-22 09:30:03 +02:00
|
|
|
|
|
|
|
if (circ->n_crypto)
|
|
|
|
crypto_free_cipher_env(circ->n_crypto);
|
|
|
|
if (circ->p_crypto)
|
|
|
|
crypto_free_cipher_env(circ->p_crypto);
|
2002-06-27 00:45:49 +02:00
|
|
|
|
|
|
|
if(circ->onion)
|
|
|
|
free(circ->onion);
|
2003-05-02 00:55:51 +02:00
|
|
|
circuit_free_cpath(circ->cpath);
|
2003-05-01 08:42:29 +02:00
|
|
|
while(circ->relay_queue) {
|
|
|
|
tmpd = circ->relay_queue;
|
|
|
|
circ->relay_queue = tmpd->next;
|
major overhaul: dns slave subsystem, topics
on startup, it forks off a master dns handler, which forks off dns
slaves (like the apache model). slaves as spawned as load increases,
and then reused. excess slaves are not ever killed, currently.
implemented topics. each topic has a receive window in each direction
at each edge of the circuit, and sends sendme's at the data level, as
per before. each circuit also has receive windows in each direction at
each hop; an edge sends a circuit-level sendme as soon as enough data
cells have arrived (regardless of whether the data cells were flushed
to the exit conns). removed the 'connected' cell type, since it's now
a topic command within data cells.
at the edge of the circuit, there can be multiple connections associated
with a single circuit. you find them via the linked list conn->next_topic.
currently each new ap connection starts its own circuit, so we ought
to see comparable performance to what we had before. but that's only
because i haven't written the code to reattach to old circuits. please
try to break it as-is, and then i'll make it reuse the same circuit and
we'll try to break that.
svn:r152
2003-01-26 10:02:24 +01:00
|
|
|
free(tmpd->cell);
|
|
|
|
free(tmpd);
|
|
|
|
}
|
2002-06-27 00:45:49 +02:00
|
|
|
|
|
|
|
free(circ);
|
Integrated onion proxy into or/
The 'or' process can now be told (by the global_role variable) what
roles this server should play -- connect to all ORs, listen for ORs,
listen for OPs, listen for APs, or any combination.
* everything in /src/op/ is now obsolete.
* connection_ap.c now handles all interactions with application proxies
* "port" is now or_port, op_port, ap_port. But routers are still always
referenced (say, in conn_get_by_addr_port()) by addr / or_port. We
should make routers.c actually read these new ports (currently I've
kludged it so op_port = or_port+10, ap_port=or_port+20)
* circuits currently know if they're at the beginning of the path because
circ->cpath is set. They use this instead for crypts (both ways),
if it's set.
* I still obey the "send a 0 back to the AP when you're ready" protocol,
but I think we should phase it out. I can simply not read from the AP
socket until I'm ready.
I need to do a lot of cleanup work here, but the code appears to work, so
now's a good time for a checkin.
svn:r22
2002-07-02 11:36:58 +02:00
|
|
|
}
|
|
|
|
|
2003-05-02 00:55:51 +02:00
|
|
|
void circuit_free_cpath(crypt_path_t *cpath) {
|
|
|
|
crypt_path_t *victim, *head=cpath;
|
Integrated onion proxy into or/
The 'or' process can now be told (by the global_role variable) what
roles this server should play -- connect to all ORs, listen for ORs,
listen for OPs, listen for APs, or any combination.
* everything in /src/op/ is now obsolete.
* connection_ap.c now handles all interactions with application proxies
* "port" is now or_port, op_port, ap_port. But routers are still always
referenced (say, in conn_get_by_addr_port()) by addr / or_port. We
should make routers.c actually read these new ports (currently I've
kludged it so op_port = or_port+10, ap_port=or_port+20)
* circuits currently know if they're at the beginning of the path because
circ->cpath is set. They use this instead for crypts (both ways),
if it's set.
* I still obey the "send a 0 back to the AP when you're ready" protocol,
but I think we should phase it out. I can simply not read from the AP
socket until I'm ready.
I need to do a lot of cleanup work here, but the code appears to work, so
now's a good time for a checkin.
svn:r22
2002-07-02 11:36:58 +02:00
|
|
|
|
2003-05-02 00:55:51 +02:00
|
|
|
if(!cpath)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* it's a doubly linked list, so we have to notice when we've
|
|
|
|
* gone through it once. */
|
|
|
|
while(cpath->next && cpath->next != head) {
|
|
|
|
victim = cpath;
|
|
|
|
cpath = victim->next;
|
|
|
|
circuit_free_cpath_node(victim);
|
|
|
|
}
|
|
|
|
|
|
|
|
circuit_free_cpath_node(cpath);
|
|
|
|
}
|
2002-06-27 00:45:49 +02:00
|
|
|
|
2003-05-02 00:55:51 +02:00
|
|
|
void circuit_free_cpath_node(crypt_path_t *victim) {
|
|
|
|
if(victim->f_crypto)
|
|
|
|
crypto_free_cipher_env(victim->f_crypto);
|
|
|
|
if(victim->b_crypto)
|
|
|
|
crypto_free_cipher_env(victim->b_crypto);
|
|
|
|
free(victim);
|
2002-06-27 00:45:49 +02:00
|
|
|
}
|
|
|
|
|
2002-12-30 09:51:41 +01:00
|
|
|
/* return 0 if can't get a unique aci. */
|
2002-06-27 00:45:49 +02:00
|
|
|
aci_t get_unique_aci_by_addr_port(uint32_t addr, uint16_t port, int aci_type) {
|
|
|
|
aci_t test_aci;
|
|
|
|
connection_t *conn;
|
|
|
|
|
2002-12-30 09:51:41 +01:00
|
|
|
try_again:
|
2002-06-27 00:45:49 +02:00
|
|
|
log(LOG_DEBUG,"get_unique_aci_by_addr_port() trying to get a unique aci");
|
|
|
|
|
2003-04-17 19:10:41 +02:00
|
|
|
if (CRYPTO_PSEUDO_RAND_INT(test_aci))
|
|
|
|
return -1;
|
2002-06-27 00:45:49 +02:00
|
|
|
|
2003-03-11 22:38:38 +01:00
|
|
|
if(aci_type == ACI_TYPE_LOWER && test_aci >= (1<<15))
|
|
|
|
test_aci -= (1<<15);
|
|
|
|
if(aci_type == ACI_TYPE_HIGHER && test_aci < (1<<15))
|
|
|
|
test_aci += (1<<15);
|
Integrated onion proxy into or/
The 'or' process can now be told (by the global_role variable) what
roles this server should play -- connect to all ORs, listen for ORs,
listen for OPs, listen for APs, or any combination.
* everything in /src/op/ is now obsolete.
* connection_ap.c now handles all interactions with application proxies
* "port" is now or_port, op_port, ap_port. But routers are still always
referenced (say, in conn_get_by_addr_port()) by addr / or_port. We
should make routers.c actually read these new ports (currently I've
kludged it so op_port = or_port+10, ap_port=or_port+20)
* circuits currently know if they're at the beginning of the path because
circ->cpath is set. They use this instead for crypts (both ways),
if it's set.
* I still obey the "send a 0 back to the AP when you're ready" protocol,
but I think we should phase it out. I can simply not read from the AP
socket until I'm ready.
I need to do a lot of cleanup work here, but the code appears to work, so
now's a good time for a checkin.
svn:r22
2002-07-02 11:36:58 +02:00
|
|
|
/* if aci_type == ACI_BOTH, don't filter any of it */
|
2002-06-27 00:45:49 +02:00
|
|
|
|
|
|
|
if(test_aci == 0)
|
2002-12-30 09:51:41 +01:00
|
|
|
goto try_again;
|
2002-06-27 00:45:49 +02:00
|
|
|
|
2002-07-08 10:59:15 +02:00
|
|
|
conn = connection_exact_get_by_addr_port(addr,port);
|
2002-06-27 00:45:49 +02:00
|
|
|
if(!conn) /* there can't be a conflict -- no connection of that sort yet */
|
|
|
|
return test_aci;
|
|
|
|
|
|
|
|
if(circuit_get_by_aci_conn(test_aci, conn))
|
2002-12-30 09:51:41 +01:00
|
|
|
goto try_again;
|
2002-06-27 00:45:49 +02:00
|
|
|
|
|
|
|
return test_aci;
|
|
|
|
}
|
|
|
|
|
2003-04-16 18:19:27 +02:00
|
|
|
int circuit_init(circuit_t *circ, int aci_type, onion_layer_t *layer) {
|
2002-08-22 09:30:03 +02:00
|
|
|
unsigned char iv[16];
|
2002-06-27 00:45:49 +02:00
|
|
|
unsigned char digest1[20];
|
|
|
|
unsigned char digest2[20];
|
2002-11-27 05:08:20 +01:00
|
|
|
struct timeval start, end;
|
2003-04-17 01:21:44 +02:00
|
|
|
long time_passed;
|
2002-11-27 05:08:20 +01:00
|
|
|
|
2002-12-03 23:18:23 +01:00
|
|
|
assert(circ && circ->onion);
|
2002-06-27 00:45:49 +02:00
|
|
|
|
|
|
|
log(LOG_DEBUG,"circuit_init(): starting");
|
2003-04-16 18:19:27 +02:00
|
|
|
circ->n_port = layer->port;
|
2002-12-03 23:18:23 +01:00
|
|
|
log(LOG_DEBUG,"circuit_init(): Set port to %u.",circ->n_port);
|
2003-04-16 18:19:27 +02:00
|
|
|
circ->n_addr = layer->addr;
|
2002-06-27 00:45:49 +02:00
|
|
|
circ->state = CIRCUIT_STATE_OPEN;
|
|
|
|
|
|
|
|
log(LOG_DEBUG,"circuit_init(): aci_type = %u.",aci_type);
|
|
|
|
|
2003-04-16 19:04:58 +02:00
|
|
|
my_gettimeofday(&start);
|
2002-11-27 05:08:20 +01:00
|
|
|
|
2002-06-27 00:45:49 +02:00
|
|
|
circ->n_aci = get_unique_aci_by_addr_port(circ->n_addr, circ->n_port, aci_type);
|
2002-12-30 09:51:41 +01:00
|
|
|
if(!circ->n_aci) {
|
|
|
|
log(LOG_ERR,"circuit_init(): failed to get unique aci.");
|
|
|
|
return -1;
|
|
|
|
}
|
2002-06-27 00:45:49 +02:00
|
|
|
|
2003-04-16 19:04:58 +02:00
|
|
|
my_gettimeofday(&end);
|
2002-11-27 05:08:20 +01:00
|
|
|
|
2003-04-16 19:11:56 +02:00
|
|
|
time_passed = tv_udiff(&start, &end);
|
|
|
|
if (time_passed > 1000) {/* more than 1ms */
|
2002-11-27 05:08:20 +01:00
|
|
|
log(LOG_NOTICE,"circuit_init(): get_unique_aci just took %d us!",time_passed);
|
|
|
|
}
|
|
|
|
|
2002-06-27 00:45:49 +02:00
|
|
|
log(LOG_DEBUG,"circuit_init(): Chosen ACI %u.",circ->n_aci);
|
|
|
|
|
|
|
|
/* keys */
|
2002-12-03 23:18:23 +01:00
|
|
|
memset(iv, 0, 16);
|
2003-04-16 18:19:27 +02:00
|
|
|
crypto_SHA_digest(layer->keyseed,16,digest1);
|
2002-08-22 09:30:03 +02:00
|
|
|
crypto_SHA_digest(digest1,20,digest2);
|
|
|
|
crypto_SHA_digest(digest2,20,digest1);
|
2002-06-27 00:45:49 +02:00
|
|
|
log(LOG_DEBUG,"circuit_init(): Computed keys.");
|
|
|
|
|
2003-04-16 18:19:27 +02:00
|
|
|
if (!(circ->p_crypto =
|
|
|
|
crypto_create_init_cipher(DEFAULT_CIPHER,digest2,iv,1))) {
|
2002-06-27 00:45:49 +02:00
|
|
|
log(LOG_ERR,"Cipher initialization failed (ACI %u).",circ->n_aci);
|
|
|
|
return -1;
|
|
|
|
}
|
2002-08-22 09:30:03 +02:00
|
|
|
|
2003-04-16 18:19:27 +02:00
|
|
|
if (!(circ->n_crypto =
|
|
|
|
crypto_create_init_cipher(DEFAULT_CIPHER,digest1,iv,0))) {
|
2002-06-27 00:45:49 +02:00
|
|
|
log(LOG_ERR,"Cipher initialization failed (ACI %u).",circ->n_aci);
|
|
|
|
return -1;
|
|
|
|
}
|
2002-08-22 09:30:03 +02:00
|
|
|
|
2002-06-27 00:45:49 +02:00
|
|
|
log(LOG_DEBUG,"circuit_init(): Cipher initialization complete.");
|
|
|
|
|
2003-04-16 18:19:27 +02:00
|
|
|
circ->expire = layer->expire;
|
2002-06-27 00:45:49 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-09-24 12:43:57 +02:00
|
|
|
circuit_t *circuit_enumerate_by_naddr_nport(circuit_t *circ, uint32_t naddr, uint16_t nport) {
|
Integrated onion proxy into or/
The 'or' process can now be told (by the global_role variable) what
roles this server should play -- connect to all ORs, listen for ORs,
listen for OPs, listen for APs, or any combination.
* everything in /src/op/ is now obsolete.
* connection_ap.c now handles all interactions with application proxies
* "port" is now or_port, op_port, ap_port. But routers are still always
referenced (say, in conn_get_by_addr_port()) by addr / or_port. We
should make routers.c actually read these new ports (currently I've
kludged it so op_port = or_port+10, ap_port=or_port+20)
* circuits currently know if they're at the beginning of the path because
circ->cpath is set. They use this instead for crypts (both ways),
if it's set.
* I still obey the "send a 0 back to the AP when you're ready" protocol,
but I think we should phase it out. I can simply not read from the AP
socket until I'm ready.
I need to do a lot of cleanup work here, but the code appears to work, so
now's a good time for a checkin.
svn:r22
2002-07-02 11:36:58 +02:00
|
|
|
|
2002-09-24 12:43:57 +02:00
|
|
|
if(!circ) /* use circ if it's defined, else start from the beginning */
|
|
|
|
circ = global_circuitlist;
|
|
|
|
else
|
|
|
|
circ = circ->next;
|
|
|
|
|
major overhaul: dns slave subsystem, topics
on startup, it forks off a master dns handler, which forks off dns
slaves (like the apache model). slaves as spawned as load increases,
and then reused. excess slaves are not ever killed, currently.
implemented topics. each topic has a receive window in each direction
at each edge of the circuit, and sends sendme's at the data level, as
per before. each circuit also has receive windows in each direction at
each hop; an edge sends a circuit-level sendme as soon as enough data
cells have arrived (regardless of whether the data cells were flushed
to the exit conns). removed the 'connected' cell type, since it's now
a topic command within data cells.
at the edge of the circuit, there can be multiple connections associated
with a single circuit. you find them via the linked list conn->next_topic.
currently each new ap connection starts its own circuit, so we ought
to see comparable performance to what we had before. but that's only
because i haven't written the code to reattach to old circuits. please
try to break it as-is, and then i'll make it reuse the same circuit and
we'll try to break that.
svn:r152
2003-01-26 10:02:24 +01:00
|
|
|
for( ; circ; circ = circ->next) {
|
Integrated onion proxy into or/
The 'or' process can now be told (by the global_role variable) what
roles this server should play -- connect to all ORs, listen for ORs,
listen for OPs, listen for APs, or any combination.
* everything in /src/op/ is now obsolete.
* connection_ap.c now handles all interactions with application proxies
* "port" is now or_port, op_port, ap_port. But routers are still always
referenced (say, in conn_get_by_addr_port()) by addr / or_port. We
should make routers.c actually read these new ports (currently I've
kludged it so op_port = or_port+10, ap_port=or_port+20)
* circuits currently know if they're at the beginning of the path because
circ->cpath is set. They use this instead for crypts (both ways),
if it's set.
* I still obey the "send a 0 back to the AP when you're ready" protocol,
but I think we should phase it out. I can simply not read from the AP
socket until I'm ready.
I need to do a lot of cleanup work here, but the code appears to work, so
now's a good time for a checkin.
svn:r22
2002-07-02 11:36:58 +02:00
|
|
|
if(circ->n_addr == naddr && circ->n_port == nport)
|
|
|
|
return circ;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2002-06-27 00:45:49 +02:00
|
|
|
circuit_t *circuit_get_by_aci_conn(aci_t aci, connection_t *conn) {
|
|
|
|
circuit_t *circ;
|
major overhaul: dns slave subsystem, topics
on startup, it forks off a master dns handler, which forks off dns
slaves (like the apache model). slaves as spawned as load increases,
and then reused. excess slaves are not ever killed, currently.
implemented topics. each topic has a receive window in each direction
at each edge of the circuit, and sends sendme's at the data level, as
per before. each circuit also has receive windows in each direction at
each hop; an edge sends a circuit-level sendme as soon as enough data
cells have arrived (regardless of whether the data cells were flushed
to the exit conns). removed the 'connected' cell type, since it's now
a topic command within data cells.
at the edge of the circuit, there can be multiple connections associated
with a single circuit. you find them via the linked list conn->next_topic.
currently each new ap connection starts its own circuit, so we ought
to see comparable performance to what we had before. but that's only
because i haven't written the code to reattach to old circuits. please
try to break it as-is, and then i'll make it reuse the same circuit and
we'll try to break that.
svn:r152
2003-01-26 10:02:24 +01:00
|
|
|
connection_t *tmpconn;
|
2002-06-27 00:45:49 +02:00
|
|
|
|
|
|
|
for(circ=global_circuitlist;circ;circ = circ->next) {
|
major overhaul: dns slave subsystem, topics
on startup, it forks off a master dns handler, which forks off dns
slaves (like the apache model). slaves as spawned as load increases,
and then reused. excess slaves are not ever killed, currently.
implemented topics. each topic has a receive window in each direction
at each edge of the circuit, and sends sendme's at the data level, as
per before. each circuit also has receive windows in each direction at
each hop; an edge sends a circuit-level sendme as soon as enough data
cells have arrived (regardless of whether the data cells were flushed
to the exit conns). removed the 'connected' cell type, since it's now
a topic command within data cells.
at the edge of the circuit, there can be multiple connections associated
with a single circuit. you find them via the linked list conn->next_topic.
currently each new ap connection starts its own circuit, so we ought
to see comparable performance to what we had before. but that's only
because i haven't written the code to reattach to old circuits. please
try to break it as-is, and then i'll make it reuse the same circuit and
we'll try to break that.
svn:r152
2003-01-26 10:02:24 +01:00
|
|
|
if(circ->p_aci == aci) {
|
2003-05-01 08:42:29 +02:00
|
|
|
for(tmpconn = circ->p_conn; tmpconn; tmpconn = tmpconn->next_stream) {
|
major overhaul: dns slave subsystem, topics
on startup, it forks off a master dns handler, which forks off dns
slaves (like the apache model). slaves as spawned as load increases,
and then reused. excess slaves are not ever killed, currently.
implemented topics. each topic has a receive window in each direction
at each edge of the circuit, and sends sendme's at the data level, as
per before. each circuit also has receive windows in each direction at
each hop; an edge sends a circuit-level sendme as soon as enough data
cells have arrived (regardless of whether the data cells were flushed
to the exit conns). removed the 'connected' cell type, since it's now
a topic command within data cells.
at the edge of the circuit, there can be multiple connections associated
with a single circuit. you find them via the linked list conn->next_topic.
currently each new ap connection starts its own circuit, so we ought
to see comparable performance to what we had before. but that's only
because i haven't written the code to reattach to old circuits. please
try to break it as-is, and then i'll make it reuse the same circuit and
we'll try to break that.
svn:r152
2003-01-26 10:02:24 +01:00
|
|
|
if(tmpconn == conn)
|
|
|
|
return circ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(circ->n_aci == aci) {
|
2003-05-01 08:42:29 +02:00
|
|
|
for(tmpconn = circ->n_conn; tmpconn; tmpconn = tmpconn->next_stream) {
|
major overhaul: dns slave subsystem, topics
on startup, it forks off a master dns handler, which forks off dns
slaves (like the apache model). slaves as spawned as load increases,
and then reused. excess slaves are not ever killed, currently.
implemented topics. each topic has a receive window in each direction
at each edge of the circuit, and sends sendme's at the data level, as
per before. each circuit also has receive windows in each direction at
each hop; an edge sends a circuit-level sendme as soon as enough data
cells have arrived (regardless of whether the data cells were flushed
to the exit conns). removed the 'connected' cell type, since it's now
a topic command within data cells.
at the edge of the circuit, there can be multiple connections associated
with a single circuit. you find them via the linked list conn->next_topic.
currently each new ap connection starts its own circuit, so we ought
to see comparable performance to what we had before. but that's only
because i haven't written the code to reattach to old circuits. please
try to break it as-is, and then i'll make it reuse the same circuit and
we'll try to break that.
svn:r152
2003-01-26 10:02:24 +01:00
|
|
|
if(tmpconn == conn)
|
|
|
|
return circ;
|
|
|
|
}
|
|
|
|
}
|
2002-06-27 00:45:49 +02:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
circuit_t *circuit_get_by_conn(connection_t *conn) {
|
|
|
|
circuit_t *circ;
|
major overhaul: dns slave subsystem, topics
on startup, it forks off a master dns handler, which forks off dns
slaves (like the apache model). slaves as spawned as load increases,
and then reused. excess slaves are not ever killed, currently.
implemented topics. each topic has a receive window in each direction
at each edge of the circuit, and sends sendme's at the data level, as
per before. each circuit also has receive windows in each direction at
each hop; an edge sends a circuit-level sendme as soon as enough data
cells have arrived (regardless of whether the data cells were flushed
to the exit conns). removed the 'connected' cell type, since it's now
a topic command within data cells.
at the edge of the circuit, there can be multiple connections associated
with a single circuit. you find them via the linked list conn->next_topic.
currently each new ap connection starts its own circuit, so we ought
to see comparable performance to what we had before. but that's only
because i haven't written the code to reattach to old circuits. please
try to break it as-is, and then i'll make it reuse the same circuit and
we'll try to break that.
svn:r152
2003-01-26 10:02:24 +01:00
|
|
|
connection_t *tmpconn;
|
2002-06-27 00:45:49 +02:00
|
|
|
|
|
|
|
for(circ=global_circuitlist;circ;circ = circ->next) {
|
2003-05-01 08:42:29 +02:00
|
|
|
for(tmpconn = circ->p_conn; tmpconn; tmpconn=tmpconn->next_stream)
|
major overhaul: dns slave subsystem, topics
on startup, it forks off a master dns handler, which forks off dns
slaves (like the apache model). slaves as spawned as load increases,
and then reused. excess slaves are not ever killed, currently.
implemented topics. each topic has a receive window in each direction
at each edge of the circuit, and sends sendme's at the data level, as
per before. each circuit also has receive windows in each direction at
each hop; an edge sends a circuit-level sendme as soon as enough data
cells have arrived (regardless of whether the data cells were flushed
to the exit conns). removed the 'connected' cell type, since it's now
a topic command within data cells.
at the edge of the circuit, there can be multiple connections associated
with a single circuit. you find them via the linked list conn->next_topic.
currently each new ap connection starts its own circuit, so we ought
to see comparable performance to what we had before. but that's only
because i haven't written the code to reattach to old circuits. please
try to break it as-is, and then i'll make it reuse the same circuit and
we'll try to break that.
svn:r152
2003-01-26 10:02:24 +01:00
|
|
|
if(tmpconn == conn)
|
|
|
|
return circ;
|
2003-05-01 08:42:29 +02:00
|
|
|
for(tmpconn = circ->n_conn; tmpconn; tmpconn=tmpconn->next_stream)
|
major overhaul: dns slave subsystem, topics
on startup, it forks off a master dns handler, which forks off dns
slaves (like the apache model). slaves as spawned as load increases,
and then reused. excess slaves are not ever killed, currently.
implemented topics. each topic has a receive window in each direction
at each edge of the circuit, and sends sendme's at the data level, as
per before. each circuit also has receive windows in each direction at
each hop; an edge sends a circuit-level sendme as soon as enough data
cells have arrived (regardless of whether the data cells were flushed
to the exit conns). removed the 'connected' cell type, since it's now
a topic command within data cells.
at the edge of the circuit, there can be multiple connections associated
with a single circuit. you find them via the linked list conn->next_topic.
currently each new ap connection starts its own circuit, so we ought
to see comparable performance to what we had before. but that's only
because i haven't written the code to reattach to old circuits. please
try to break it as-is, and then i'll make it reuse the same circuit and
we'll try to break that.
svn:r152
2003-01-26 10:02:24 +01:00
|
|
|
if(tmpconn == conn)
|
|
|
|
return circ;
|
2002-06-27 00:45:49 +02:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2003-05-02 00:55:51 +02:00
|
|
|
circuit_t *circuit_get_newest_ap(void) {
|
2003-04-16 08:18:31 +02:00
|
|
|
circuit_t *circ, *bestcirc=NULL;
|
2003-02-06 09:00:49 +01:00
|
|
|
|
|
|
|
for(circ=global_circuitlist;circ;circ = circ->next) {
|
2003-05-02 00:55:51 +02:00
|
|
|
if(!circ->p_conn || circ->p_conn->type == CONN_TYPE_AP) {
|
2003-04-20 23:56:44 +02:00
|
|
|
if(circ->state == CIRCUIT_STATE_OPEN && (!bestcirc ||
|
|
|
|
bestcirc->timestamp_created < circ->timestamp_created)) {
|
2003-05-02 00:55:51 +02:00
|
|
|
log(LOG_DEBUG,"circuit_get_newest_ap(): Choosing n_aci %d.", circ->n_aci);
|
2003-04-20 23:56:44 +02:00
|
|
|
assert(circ->n_aci);
|
2003-04-16 08:18:31 +02:00
|
|
|
bestcirc = circ;
|
|
|
|
}
|
2003-02-06 09:00:49 +01:00
|
|
|
}
|
|
|
|
}
|
2003-04-16 08:18:31 +02:00
|
|
|
return bestcirc;
|
2003-02-06 09:00:49 +01:00
|
|
|
}
|
|
|
|
|
2003-05-02 23:29:25 +02:00
|
|
|
int circuit_deliver_relay_cell_from_edge(cell_t *cell, circuit_t *circ,
|
|
|
|
char edge_type, crypt_path_t *layer_hint) {
|
major overhaul: dns slave subsystem, topics
on startup, it forks off a master dns handler, which forks off dns
slaves (like the apache model). slaves as spawned as load increases,
and then reused. excess slaves are not ever killed, currently.
implemented topics. each topic has a receive window in each direction
at each edge of the circuit, and sends sendme's at the data level, as
per before. each circuit also has receive windows in each direction at
each hop; an edge sends a circuit-level sendme as soon as enough data
cells have arrived (regardless of whether the data cells were flushed
to the exit conns). removed the 'connected' cell type, since it's now
a topic command within data cells.
at the edge of the circuit, there can be multiple connections associated
with a single circuit. you find them via the linked list conn->next_topic.
currently each new ap connection starts its own circuit, so we ought
to see comparable performance to what we had before. but that's only
because i haven't written the code to reattach to old circuits. please
try to break it as-is, and then i'll make it reuse the same circuit and
we'll try to break that.
svn:r152
2003-01-26 10:02:24 +01:00
|
|
|
int cell_direction;
|
2003-02-06 09:00:49 +01:00
|
|
|
static int numsent_ap=0, numsent_exit=0;
|
major overhaul: dns slave subsystem, topics
on startup, it forks off a master dns handler, which forks off dns
slaves (like the apache model). slaves as spawned as load increases,
and then reused. excess slaves are not ever killed, currently.
implemented topics. each topic has a receive window in each direction
at each edge of the circuit, and sends sendme's at the data level, as
per before. each circuit also has receive windows in each direction at
each hop; an edge sends a circuit-level sendme as soon as enough data
cells have arrived (regardless of whether the data cells were flushed
to the exit conns). removed the 'connected' cell type, since it's now
a topic command within data cells.
at the edge of the circuit, there can be multiple connections associated
with a single circuit. you find them via the linked list conn->next_topic.
currently each new ap connection starts its own circuit, so we ought
to see comparable performance to what we had before. but that's only
because i haven't written the code to reattach to old circuits. please
try to break it as-is, and then i'll make it reuse the same circuit and
we'll try to break that.
svn:r152
2003-01-26 10:02:24 +01:00
|
|
|
|
2003-05-01 08:42:29 +02:00
|
|
|
log(LOG_DEBUG,"circuit_deliver_relay_cell_from_edge(): called, edge_type %d.", edge_type);
|
2002-06-27 00:45:49 +02:00
|
|
|
|
major overhaul: dns slave subsystem, topics
on startup, it forks off a master dns handler, which forks off dns
slaves (like the apache model). slaves as spawned as load increases,
and then reused. excess slaves are not ever killed, currently.
implemented topics. each topic has a receive window in each direction
at each edge of the circuit, and sends sendme's at the data level, as
per before. each circuit also has receive windows in each direction at
each hop; an edge sends a circuit-level sendme as soon as enough data
cells have arrived (regardless of whether the data cells were flushed
to the exit conns). removed the 'connected' cell type, since it's now
a topic command within data cells.
at the edge of the circuit, there can be multiple connections associated
with a single circuit. you find them via the linked list conn->next_topic.
currently each new ap connection starts its own circuit, so we ought
to see comparable performance to what we had before. but that's only
because i haven't written the code to reattach to old circuits. please
try to break it as-is, and then i'll make it reuse the same circuit and
we'll try to break that.
svn:r152
2003-01-26 10:02:24 +01:00
|
|
|
if(edge_type == EDGE_AP) { /* i'm the AP */
|
|
|
|
cell_direction = CELL_DIRECTION_OUT;
|
2003-02-06 09:00:49 +01:00
|
|
|
numsent_ap++;
|
2003-05-01 08:42:29 +02:00
|
|
|
log(LOG_DEBUG,"circuit_deliver_relay_cell_from_edge(): now sent %d relay cells from ap", numsent_ap);
|
major overhaul: dns slave subsystem, topics
on startup, it forks off a master dns handler, which forks off dns
slaves (like the apache model). slaves as spawned as load increases,
and then reused. excess slaves are not ever killed, currently.
implemented topics. each topic has a receive window in each direction
at each edge of the circuit, and sends sendme's at the data level, as
per before. each circuit also has receive windows in each direction at
each hop; an edge sends a circuit-level sendme as soon as enough data
cells have arrived (regardless of whether the data cells were flushed
to the exit conns). removed the 'connected' cell type, since it's now
a topic command within data cells.
at the edge of the circuit, there can be multiple connections associated
with a single circuit. you find them via the linked list conn->next_topic.
currently each new ap connection starts its own circuit, so we ought
to see comparable performance to what we had before. but that's only
because i haven't written the code to reattach to old circuits. please
try to break it as-is, and then i'll make it reuse the same circuit and
we'll try to break that.
svn:r152
2003-01-26 10:02:24 +01:00
|
|
|
if(circ->p_receive_circwindow <= 0) {
|
2003-05-01 08:42:29 +02:00
|
|
|
log(LOG_DEBUG,"circuit_deliver_relay_cell_from_edge(): pwindow 0, queueing for later.");
|
2003-05-02 23:29:25 +02:00
|
|
|
circ->relay_queue = relay_queue_add(circ->relay_queue, cell, layer_hint);
|
major overhaul: dns slave subsystem, topics
on startup, it forks off a master dns handler, which forks off dns
slaves (like the apache model). slaves as spawned as load increases,
and then reused. excess slaves are not ever killed, currently.
implemented topics. each topic has a receive window in each direction
at each edge of the circuit, and sends sendme's at the data level, as
per before. each circuit also has receive windows in each direction at
each hop; an edge sends a circuit-level sendme as soon as enough data
cells have arrived (regardless of whether the data cells were flushed
to the exit conns). removed the 'connected' cell type, since it's now
a topic command within data cells.
at the edge of the circuit, there can be multiple connections associated
with a single circuit. you find them via the linked list conn->next_topic.
currently each new ap connection starts its own circuit, so we ought
to see comparable performance to what we had before. but that's only
because i haven't written the code to reattach to old circuits. please
try to break it as-is, and then i'll make it reuse the same circuit and
we'll try to break that.
svn:r152
2003-01-26 10:02:24 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
circ->p_receive_circwindow--;
|
2003-05-01 08:42:29 +02:00
|
|
|
// log(LOG_INFO,"circuit_deliver_relay_cell_from_edge(): p_receive_circwindow now %d.",circ->p_receive_circwindow);
|
major overhaul: dns slave subsystem, topics
on startup, it forks off a master dns handler, which forks off dns
slaves (like the apache model). slaves as spawned as load increases,
and then reused. excess slaves are not ever killed, currently.
implemented topics. each topic has a receive window in each direction
at each edge of the circuit, and sends sendme's at the data level, as
per before. each circuit also has receive windows in each direction at
each hop; an edge sends a circuit-level sendme as soon as enough data
cells have arrived (regardless of whether the data cells were flushed
to the exit conns). removed the 'connected' cell type, since it's now
a topic command within data cells.
at the edge of the circuit, there can be multiple connections associated
with a single circuit. you find them via the linked list conn->next_topic.
currently each new ap connection starts its own circuit, so we ought
to see comparable performance to what we had before. but that's only
because i haven't written the code to reattach to old circuits. please
try to break it as-is, and then i'll make it reuse the same circuit and
we'll try to break that.
svn:r152
2003-01-26 10:02:24 +01:00
|
|
|
} else { /* i'm the exit */
|
|
|
|
cell_direction = CELL_DIRECTION_IN;
|
2003-02-06 09:00:49 +01:00
|
|
|
numsent_exit++;
|
2003-05-01 08:42:29 +02:00
|
|
|
log(LOG_DEBUG,"circuit_deliver_relay_cell_from_edge(): now sent %d relay cells from exit", numsent_exit);
|
major overhaul: dns slave subsystem, topics
on startup, it forks off a master dns handler, which forks off dns
slaves (like the apache model). slaves as spawned as load increases,
and then reused. excess slaves are not ever killed, currently.
implemented topics. each topic has a receive window in each direction
at each edge of the circuit, and sends sendme's at the data level, as
per before. each circuit also has receive windows in each direction at
each hop; an edge sends a circuit-level sendme as soon as enough data
cells have arrived (regardless of whether the data cells were flushed
to the exit conns). removed the 'connected' cell type, since it's now
a topic command within data cells.
at the edge of the circuit, there can be multiple connections associated
with a single circuit. you find them via the linked list conn->next_topic.
currently each new ap connection starts its own circuit, so we ought
to see comparable performance to what we had before. but that's only
because i haven't written the code to reattach to old circuits. please
try to break it as-is, and then i'll make it reuse the same circuit and
we'll try to break that.
svn:r152
2003-01-26 10:02:24 +01:00
|
|
|
if(circ->n_receive_circwindow <= 0) {
|
2003-05-01 08:42:29 +02:00
|
|
|
log(LOG_DEBUG,"circuit_deliver_relay_cell_from_edge(): nwindow 0, queueing for later.");
|
2003-05-02 23:29:25 +02:00
|
|
|
circ->relay_queue = relay_queue_add(circ->relay_queue, cell, layer_hint);
|
major overhaul: dns slave subsystem, topics
on startup, it forks off a master dns handler, which forks off dns
slaves (like the apache model). slaves as spawned as load increases,
and then reused. excess slaves are not ever killed, currently.
implemented topics. each topic has a receive window in each direction
at each edge of the circuit, and sends sendme's at the data level, as
per before. each circuit also has receive windows in each direction at
each hop; an edge sends a circuit-level sendme as soon as enough data
cells have arrived (regardless of whether the data cells were flushed
to the exit conns). removed the 'connected' cell type, since it's now
a topic command within data cells.
at the edge of the circuit, there can be multiple connections associated
with a single circuit. you find them via the linked list conn->next_topic.
currently each new ap connection starts its own circuit, so we ought
to see comparable performance to what we had before. but that's only
because i haven't written the code to reattach to old circuits. please
try to break it as-is, and then i'll make it reuse the same circuit and
we'll try to break that.
svn:r152
2003-01-26 10:02:24 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
circ->n_receive_circwindow--;
|
|
|
|
}
|
|
|
|
|
2003-05-02 23:29:25 +02:00
|
|
|
if(circuit_deliver_relay_cell(cell, circ, cell_direction, layer_hint) < 0) {
|
major overhaul: dns slave subsystem, topics
on startup, it forks off a master dns handler, which forks off dns
slaves (like the apache model). slaves as spawned as load increases,
and then reused. excess slaves are not ever killed, currently.
implemented topics. each topic has a receive window in each direction
at each edge of the circuit, and sends sendme's at the data level, as
per before. each circuit also has receive windows in each direction at
each hop; an edge sends a circuit-level sendme as soon as enough data
cells have arrived (regardless of whether the data cells were flushed
to the exit conns). removed the 'connected' cell type, since it's now
a topic command within data cells.
at the edge of the circuit, there can be multiple connections associated
with a single circuit. you find them via the linked list conn->next_topic.
currently each new ap connection starts its own circuit, so we ought
to see comparable performance to what we had before. but that's only
because i haven't written the code to reattach to old circuits. please
try to break it as-is, and then i'll make it reuse the same circuit and
we'll try to break that.
svn:r152
2003-01-26 10:02:24 +01:00
|
|
|
return -1;
|
|
|
|
}
|
2003-02-18 02:35:55 +01:00
|
|
|
|
major overhaul: dns slave subsystem, topics
on startup, it forks off a master dns handler, which forks off dns
slaves (like the apache model). slaves as spawned as load increases,
and then reused. excess slaves are not ever killed, currently.
implemented topics. each topic has a receive window in each direction
at each edge of the circuit, and sends sendme's at the data level, as
per before. each circuit also has receive windows in each direction at
each hop; an edge sends a circuit-level sendme as soon as enough data
cells have arrived (regardless of whether the data cells were flushed
to the exit conns). removed the 'connected' cell type, since it's now
a topic command within data cells.
at the edge of the circuit, there can be multiple connections associated
with a single circuit. you find them via the linked list conn->next_topic.
currently each new ap connection starts its own circuit, so we ought
to see comparable performance to what we had before. but that's only
because i haven't written the code to reattach to old circuits. please
try to break it as-is, and then i'll make it reuse the same circuit and
we'll try to break that.
svn:r152
2003-01-26 10:02:24 +01:00
|
|
|
circuit_consider_stop_edge_reading(circ, edge_type); /* has window reached 0? */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-05-02 23:29:25 +02:00
|
|
|
int circuit_deliver_relay_cell(cell_t *cell, circuit_t *circ,
|
|
|
|
int cell_direction, crypt_path_t *layer_hint) {
|
|
|
|
connection_t *conn=NULL;
|
|
|
|
char recognized=0;
|
|
|
|
char buf[256];
|
major overhaul: dns slave subsystem, topics
on startup, it forks off a master dns handler, which forks off dns
slaves (like the apache model). slaves as spawned as load increases,
and then reused. excess slaves are not ever killed, currently.
implemented topics. each topic has a receive window in each direction
at each edge of the circuit, and sends sendme's at the data level, as
per before. each circuit also has receive windows in each direction at
each hop; an edge sends a circuit-level sendme as soon as enough data
cells have arrived (regardless of whether the data cells were flushed
to the exit conns). removed the 'connected' cell type, since it's now
a topic command within data cells.
at the edge of the circuit, there can be multiple connections associated
with a single circuit. you find them via the linked list conn->next_topic.
currently each new ap connection starts its own circuit, so we ought
to see comparable performance to what we had before. but that's only
because i haven't written the code to reattach to old circuits. please
try to break it as-is, and then i'll make it reuse the same circuit and
we'll try to break that.
svn:r152
2003-01-26 10:02:24 +01:00
|
|
|
|
|
|
|
assert(cell && circ);
|
|
|
|
assert(cell_direction == CELL_DIRECTION_OUT || cell_direction == CELL_DIRECTION_IN);
|
|
|
|
|
2003-05-02 23:29:25 +02:00
|
|
|
buf[0] = cell->length;
|
|
|
|
memcpy(buf+1, cell->payload, CELL_PAYLOAD_SIZE);
|
2002-06-27 00:45:49 +02:00
|
|
|
|
2003-05-02 23:29:25 +02:00
|
|
|
log(LOG_DEBUG,"circuit_deliver_relay_cell(): streamid %d before crypt.", *(int*)(cell->payload+1));
|
|
|
|
|
|
|
|
if(relay_crypt(circ, buf, 1+CELL_PAYLOAD_SIZE, cell_direction, layer_hint, &recognized, &conn) < 0) {
|
|
|
|
log(LOG_DEBUG,"circuit_deliver_relay_cell(): relay crypt failed. Dropping connection.");
|
2002-06-27 00:45:49 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2003-05-02 23:29:25 +02:00
|
|
|
cell->length = buf[0];
|
|
|
|
memcpy(cell->payload, buf+1, CELL_PAYLOAD_SIZE);
|
|
|
|
|
|
|
|
if(recognized) {
|
|
|
|
if(cell_direction == CELL_DIRECTION_OUT) {
|
|
|
|
log(LOG_DEBUG,"circuit_deliver_relay_cell(): Sending to exit.");
|
|
|
|
return connection_edge_process_relay_cell(cell, circ, conn, EDGE_EXIT);
|
|
|
|
}
|
|
|
|
if(cell_direction == CELL_DIRECTION_IN) {
|
|
|
|
log(LOG_DEBUG,"circuit_deliver_relay_cell(): Sending to AP.");
|
|
|
|
return connection_edge_process_relay_cell(cell, circ, conn, EDGE_AP);
|
|
|
|
}
|
2002-06-27 00:45:49 +02:00
|
|
|
}
|
2003-05-02 23:29:25 +02:00
|
|
|
|
|
|
|
/* not recognized. pass it on. */
|
|
|
|
if(cell_direction == CELL_DIRECTION_OUT)
|
|
|
|
conn = circ->n_conn;
|
|
|
|
else
|
|
|
|
conn = circ->p_conn;
|
|
|
|
|
|
|
|
if(!conn || !connection_speaks_cells(conn)) {
|
|
|
|
log(LOG_INFO,"circuit_deliver_relay_cell(): Didn't recognize cell (%d), but circ stops here! Dropping.", *(int *)(cell->payload+1));
|
|
|
|
return 0;
|
Integrated onion proxy into or/
The 'or' process can now be told (by the global_role variable) what
roles this server should play -- connect to all ORs, listen for ORs,
listen for OPs, listen for APs, or any combination.
* everything in /src/op/ is now obsolete.
* connection_ap.c now handles all interactions with application proxies
* "port" is now or_port, op_port, ap_port. But routers are still always
referenced (say, in conn_get_by_addr_port()) by addr / or_port. We
should make routers.c actually read these new ports (currently I've
kludged it so op_port = or_port+10, ap_port=or_port+20)
* circuits currently know if they're at the beginning of the path because
circ->cpath is set. They use this instead for crypts (both ways),
if it's set.
* I still obey the "send a 0 back to the AP when you're ready" protocol,
but I think we should phase it out. I can simply not read from the AP
socket until I'm ready.
I need to do a lot of cleanup work here, but the code appears to work, so
now's a good time for a checkin.
svn:r22
2002-07-02 11:36:58 +02:00
|
|
|
}
|
2003-05-02 23:29:25 +02:00
|
|
|
|
Integrated onion proxy into or/
The 'or' process can now be told (by the global_role variable) what
roles this server should play -- connect to all ORs, listen for ORs,
listen for OPs, listen for APs, or any combination.
* everything in /src/op/ is now obsolete.
* connection_ap.c now handles all interactions with application proxies
* "port" is now or_port, op_port, ap_port. But routers are still always
referenced (say, in conn_get_by_addr_port()) by addr / or_port. We
should make routers.c actually read these new ports (currently I've
kludged it so op_port = or_port+10, ap_port=or_port+20)
* circuits currently know if they're at the beginning of the path because
circ->cpath is set. They use this instead for crypts (both ways),
if it's set.
* I still obey the "send a 0 back to the AP when you're ready" protocol,
but I think we should phase it out. I can simply not read from the AP
socket until I'm ready.
I need to do a lot of cleanup work here, but the code appears to work, so
now's a good time for a checkin.
svn:r22
2002-07-02 11:36:58 +02:00
|
|
|
return connection_write_cell_to_buf(cell, conn);
|
2002-06-27 00:45:49 +02:00
|
|
|
}
|
|
|
|
|
2003-05-02 23:29:25 +02:00
|
|
|
int relay_crypt(circuit_t *circ, char *in, int inlen, char cell_direction,
|
|
|
|
crypt_path_t *layer_hint, char *recognized, connection_t **conn) {
|
Integrated onion proxy into or/
The 'or' process can now be told (by the global_role variable) what
roles this server should play -- connect to all ORs, listen for ORs,
listen for OPs, listen for APs, or any combination.
* everything in /src/op/ is now obsolete.
* connection_ap.c now handles all interactions with application proxies
* "port" is now or_port, op_port, ap_port. But routers are still always
referenced (say, in conn_get_by_addr_port()) by addr / or_port. We
should make routers.c actually read these new ports (currently I've
kludged it so op_port = or_port+10, ap_port=or_port+20)
* circuits currently know if they're at the beginning of the path because
circ->cpath is set. They use this instead for crypts (both ways),
if it's set.
* I still obey the "send a 0 back to the AP when you're ready" protocol,
but I think we should phase it out. I can simply not read from the AP
socket until I'm ready.
I need to do a lot of cleanup work here, but the code appears to work, so
now's a good time for a checkin.
svn:r22
2002-07-02 11:36:58 +02:00
|
|
|
crypt_path_t *thishop;
|
2003-05-02 23:29:25 +02:00
|
|
|
char out[256];
|
2002-06-27 00:45:49 +02:00
|
|
|
|
2003-05-02 23:29:25 +02:00
|
|
|
assert(circ && in && recognized && conn);
|
2002-06-27 00:45:49 +02:00
|
|
|
|
2003-05-02 23:29:25 +02:00
|
|
|
assert(inlen < 256);
|
2002-06-27 00:45:49 +02:00
|
|
|
|
2003-03-05 21:03:05 +01:00
|
|
|
if(cell_direction == CELL_DIRECTION_IN) {
|
Integrated onion proxy into or/
The 'or' process can now be told (by the global_role variable) what
roles this server should play -- connect to all ORs, listen for ORs,
listen for OPs, listen for APs, or any combination.
* everything in /src/op/ is now obsolete.
* connection_ap.c now handles all interactions with application proxies
* "port" is now or_port, op_port, ap_port. But routers are still always
referenced (say, in conn_get_by_addr_port()) by addr / or_port. We
should make routers.c actually read these new ports (currently I've
kludged it so op_port = or_port+10, ap_port=or_port+20)
* circuits currently know if they're at the beginning of the path because
circ->cpath is set. They use this instead for crypts (both ways),
if it's set.
* I still obey the "send a 0 back to the AP when you're ready" protocol,
but I think we should phase it out. I can simply not read from the AP
socket until I'm ready.
I need to do a lot of cleanup work here, but the code appears to work, so
now's a good time for a checkin.
svn:r22
2002-07-02 11:36:58 +02:00
|
|
|
if(circ->cpath) { /* we're at the beginning of the circuit. We'll want to do layered crypts. */
|
2003-05-02 00:55:51 +02:00
|
|
|
thishop = circ->cpath;
|
2003-05-02 23:29:25 +02:00
|
|
|
do { /* Remember: cpath is in forward order, that is, first hop first. */
|
2003-05-02 00:55:51 +02:00
|
|
|
assert(thishop);
|
2003-05-02 23:29:25 +02:00
|
|
|
|
major overhaul: dns slave subsystem, topics
on startup, it forks off a master dns handler, which forks off dns
slaves (like the apache model). slaves as spawned as load increases,
and then reused. excess slaves are not ever killed, currently.
implemented topics. each topic has a receive window in each direction
at each edge of the circuit, and sends sendme's at the data level, as
per before. each circuit also has receive windows in each direction at
each hop; an edge sends a circuit-level sendme as soon as enough data
cells have arrived (regardless of whether the data cells were flushed
to the exit conns). removed the 'connected' cell type, since it's now
a topic command within data cells.
at the edge of the circuit, there can be multiple connections associated
with a single circuit. you find them via the linked list conn->next_topic.
currently each new ap connection starts its own circuit, so we ought
to see comparable performance to what we had before. but that's only
because i haven't written the code to reattach to old circuits. please
try to break it as-is, and then i'll make it reuse the same circuit and
we'll try to break that.
svn:r152
2003-01-26 10:02:24 +01:00
|
|
|
/* decrypt */
|
|
|
|
if(crypto_cipher_decrypt(thishop->b_crypto, in, inlen, out)) {
|
|
|
|
log(LOG_ERR,"Error performing decryption:%s",crypto_perror());
|
Integrated onion proxy into or/
The 'or' process can now be told (by the global_role variable) what
roles this server should play -- connect to all ORs, listen for ORs,
listen for OPs, listen for APs, or any combination.
* everything in /src/op/ is now obsolete.
* connection_ap.c now handles all interactions with application proxies
* "port" is now or_port, op_port, ap_port. But routers are still always
referenced (say, in conn_get_by_addr_port()) by addr / or_port. We
should make routers.c actually read these new ports (currently I've
kludged it so op_port = or_port+10, ap_port=or_port+20)
* circuits currently know if they're at the beginning of the path because
circ->cpath is set. They use this instead for crypts (both ways),
if it's set.
* I still obey the "send a 0 back to the AP when you're ready" protocol,
but I think we should phase it out. I can simply not read from the AP
socket until I'm ready.
I need to do a lot of cleanup work here, but the code appears to work, so
now's a good time for a checkin.
svn:r22
2002-07-02 11:36:58 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
memcpy(in,out,inlen);
|
2003-05-02 23:29:25 +02:00
|
|
|
|
|
|
|
if( (*recognized = relay_check_recognized(circ, cell_direction, in+2, conn)))
|
|
|
|
return 0;
|
|
|
|
|
2003-05-02 00:55:51 +02:00
|
|
|
thishop = thishop->next;
|
|
|
|
} while(thishop != circ->cpath);
|
2003-05-02 23:29:25 +02:00
|
|
|
log(LOG_INFO,"relay_crypt(): in-cell at OP not recognized. Killing circuit.");
|
|
|
|
return -1;
|
Integrated onion proxy into or/
The 'or' process can now be told (by the global_role variable) what
roles this server should play -- connect to all ORs, listen for ORs,
listen for OPs, listen for APs, or any combination.
* everything in /src/op/ is now obsolete.
* connection_ap.c now handles all interactions with application proxies
* "port" is now or_port, op_port, ap_port. But routers are still always
referenced (say, in conn_get_by_addr_port()) by addr / or_port. We
should make routers.c actually read these new ports (currently I've
kludged it so op_port = or_port+10, ap_port=or_port+20)
* circuits currently know if they're at the beginning of the path because
circ->cpath is set. They use this instead for crypts (both ways),
if it's set.
* I still obey the "send a 0 back to the AP when you're ready" protocol,
but I think we should phase it out. I can simply not read from the AP
socket until I'm ready.
I need to do a lot of cleanup work here, but the code appears to work, so
now's a good time for a checkin.
svn:r22
2002-07-02 11:36:58 +02:00
|
|
|
} else { /* we're in the middle. Just one crypt. */
|
2003-05-02 23:29:25 +02:00
|
|
|
|
|
|
|
if(crypto_cipher_encrypt(circ->p_crypto, in, inlen, out)) {
|
Integrated onion proxy into or/
The 'or' process can now be told (by the global_role variable) what
roles this server should play -- connect to all ORs, listen for ORs,
listen for OPs, listen for APs, or any combination.
* everything in /src/op/ is now obsolete.
* connection_ap.c now handles all interactions with application proxies
* "port" is now or_port, op_port, ap_port. But routers are still always
referenced (say, in conn_get_by_addr_port()) by addr / or_port. We
should make routers.c actually read these new ports (currently I've
kludged it so op_port = or_port+10, ap_port=or_port+20)
* circuits currently know if they're at the beginning of the path because
circ->cpath is set. They use this instead for crypts (both ways),
if it's set.
* I still obey the "send a 0 back to the AP when you're ready" protocol,
but I think we should phase it out. I can simply not read from the AP
socket until I'm ready.
I need to do a lot of cleanup work here, but the code appears to work, so
now's a good time for a checkin.
svn:r22
2002-07-02 11:36:58 +02:00
|
|
|
log(LOG_ERR,"circuit_encrypt(): Encryption failed for ACI : %u (%s).",
|
2002-08-22 09:30:03 +02:00
|
|
|
circ->p_aci, crypto_perror());
|
Integrated onion proxy into or/
The 'or' process can now be told (by the global_role variable) what
roles this server should play -- connect to all ORs, listen for ORs,
listen for OPs, listen for APs, or any combination.
* everything in /src/op/ is now obsolete.
* connection_ap.c now handles all interactions with application proxies
* "port" is now or_port, op_port, ap_port. But routers are still always
referenced (say, in conn_get_by_addr_port()) by addr / or_port. We
should make routers.c actually read these new ports (currently I've
kludged it so op_port = or_port+10, ap_port=or_port+20)
* circuits currently know if they're at the beginning of the path because
circ->cpath is set. They use this instead for crypts (both ways),
if it's set.
* I still obey the "send a 0 back to the AP when you're ready" protocol,
but I think we should phase it out. I can simply not read from the AP
socket until I'm ready.
I need to do a lot of cleanup work here, but the code appears to work, so
now's a good time for a checkin.
svn:r22
2002-07-02 11:36:58 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
memcpy(in,out,inlen);
|
2003-05-02 23:29:25 +02:00
|
|
|
|
|
|
|
/* don't check for recognized. only the OP can recognize a stream on the way back. */
|
|
|
|
|
2002-06-27 00:45:49 +02:00
|
|
|
}
|
2003-03-05 21:03:05 +01:00
|
|
|
} else if(cell_direction == CELL_DIRECTION_OUT) {
|
Integrated onion proxy into or/
The 'or' process can now be told (by the global_role variable) what
roles this server should play -- connect to all ORs, listen for ORs,
listen for OPs, listen for APs, or any combination.
* everything in /src/op/ is now obsolete.
* connection_ap.c now handles all interactions with application proxies
* "port" is now or_port, op_port, ap_port. But routers are still always
referenced (say, in conn_get_by_addr_port()) by addr / or_port. We
should make routers.c actually read these new ports (currently I've
kludged it so op_port = or_port+10, ap_port=or_port+20)
* circuits currently know if they're at the beginning of the path because
circ->cpath is set. They use this instead for crypts (both ways),
if it's set.
* I still obey the "send a 0 back to the AP when you're ready" protocol,
but I think we should phase it out. I can simply not read from the AP
socket until I'm ready.
I need to do a lot of cleanup work here, but the code appears to work, so
now's a good time for a checkin.
svn:r22
2002-07-02 11:36:58 +02:00
|
|
|
if(circ->cpath) { /* we're at the beginning of the circuit. We'll want to do layered crypts. */
|
2003-05-02 23:29:25 +02:00
|
|
|
|
|
|
|
thishop = layer_hint; /* we already know which layer, from when we package_raw_inbuf'ed */
|
2003-05-02 00:55:51 +02:00
|
|
|
/* moving from last to first hop */
|
|
|
|
do {
|
|
|
|
assert(thishop);
|
2003-05-02 23:29:25 +02:00
|
|
|
|
Integrated onion proxy into or/
The 'or' process can now be told (by the global_role variable) what
roles this server should play -- connect to all ORs, listen for ORs,
listen for OPs, listen for APs, or any combination.
* everything in /src/op/ is now obsolete.
* connection_ap.c now handles all interactions with application proxies
* "port" is now or_port, op_port, ap_port. But routers are still always
referenced (say, in conn_get_by_addr_port()) by addr / or_port. We
should make routers.c actually read these new ports (currently I've
kludged it so op_port = or_port+10, ap_port=or_port+20)
* circuits currently know if they're at the beginning of the path because
circ->cpath is set. They use this instead for crypts (both ways),
if it's set.
* I still obey the "send a 0 back to the AP when you're ready" protocol,
but I think we should phase it out. I can simply not read from the AP
socket until I'm ready.
I need to do a lot of cleanup work here, but the code appears to work, so
now's a good time for a checkin.
svn:r22
2002-07-02 11:36:58 +02:00
|
|
|
/* encrypt */
|
2003-05-02 23:29:25 +02:00
|
|
|
if(crypto_cipher_encrypt(thishop->f_crypto, in, inlen, out)) {
|
major overhaul: dns slave subsystem, topics
on startup, it forks off a master dns handler, which forks off dns
slaves (like the apache model). slaves as spawned as load increases,
and then reused. excess slaves are not ever killed, currently.
implemented topics. each topic has a receive window in each direction
at each edge of the circuit, and sends sendme's at the data level, as
per before. each circuit also has receive windows in each direction at
each hop; an edge sends a circuit-level sendme as soon as enough data
cells have arrived (regardless of whether the data cells were flushed
to the exit conns). removed the 'connected' cell type, since it's now
a topic command within data cells.
at the edge of the circuit, there can be multiple connections associated
with a single circuit. you find them via the linked list conn->next_topic.
currently each new ap connection starts its own circuit, so we ought
to see comparable performance to what we had before. but that's only
because i haven't written the code to reattach to old circuits. please
try to break it as-is, and then i'll make it reuse the same circuit and
we'll try to break that.
svn:r152
2003-01-26 10:02:24 +01:00
|
|
|
log(LOG_ERR,"Error performing encryption:%s",crypto_perror());
|
Integrated onion proxy into or/
The 'or' process can now be told (by the global_role variable) what
roles this server should play -- connect to all ORs, listen for ORs,
listen for OPs, listen for APs, or any combination.
* everything in /src/op/ is now obsolete.
* connection_ap.c now handles all interactions with application proxies
* "port" is now or_port, op_port, ap_port. But routers are still always
referenced (say, in conn_get_by_addr_port()) by addr / or_port. We
should make routers.c actually read these new ports (currently I've
kludged it so op_port = or_port+10, ap_port=or_port+20)
* circuits currently know if they're at the beginning of the path because
circ->cpath is set. They use this instead for crypts (both ways),
if it's set.
* I still obey the "send a 0 back to the AP when you're ready" protocol,
but I think we should phase it out. I can simply not read from the AP
socket until I'm ready.
I need to do a lot of cleanup work here, but the code appears to work, so
now's a good time for a checkin.
svn:r22
2002-07-02 11:36:58 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
memcpy(in,out,inlen);
|
2003-05-02 23:29:25 +02:00
|
|
|
|
2003-05-02 00:55:51 +02:00
|
|
|
thishop = thishop->prev;
|
|
|
|
} while(thishop != circ->cpath->prev);
|
Integrated onion proxy into or/
The 'or' process can now be told (by the global_role variable) what
roles this server should play -- connect to all ORs, listen for ORs,
listen for OPs, listen for APs, or any combination.
* everything in /src/op/ is now obsolete.
* connection_ap.c now handles all interactions with application proxies
* "port" is now or_port, op_port, ap_port. But routers are still always
referenced (say, in conn_get_by_addr_port()) by addr / or_port. We
should make routers.c actually read these new ports (currently I've
kludged it so op_port = or_port+10, ap_port=or_port+20)
* circuits currently know if they're at the beginning of the path because
circ->cpath is set. They use this instead for crypts (both ways),
if it's set.
* I still obey the "send a 0 back to the AP when you're ready" protocol,
but I think we should phase it out. I can simply not read from the AP
socket until I'm ready.
I need to do a lot of cleanup work here, but the code appears to work, so
now's a good time for a checkin.
svn:r22
2002-07-02 11:36:58 +02:00
|
|
|
} else { /* we're in the middle. Just one crypt. */
|
2003-05-02 23:29:25 +02:00
|
|
|
|
2002-08-22 09:30:03 +02:00
|
|
|
if(crypto_cipher_decrypt(circ->n_crypto,in, inlen, out)) {
|
Integrated onion proxy into or/
The 'or' process can now be told (by the global_role variable) what
roles this server should play -- connect to all ORs, listen for ORs,
listen for OPs, listen for APs, or any combination.
* everything in /src/op/ is now obsolete.
* connection_ap.c now handles all interactions with application proxies
* "port" is now or_port, op_port, ap_port. But routers are still always
referenced (say, in conn_get_by_addr_port()) by addr / or_port. We
should make routers.c actually read these new ports (currently I've
kludged it so op_port = or_port+10, ap_port=or_port+20)
* circuits currently know if they're at the beginning of the path because
circ->cpath is set. They use this instead for crypts (both ways),
if it's set.
* I still obey the "send a 0 back to the AP when you're ready" protocol,
but I think we should phase it out. I can simply not read from the AP
socket until I'm ready.
I need to do a lot of cleanup work here, but the code appears to work, so
now's a good time for a checkin.
svn:r22
2002-07-02 11:36:58 +02:00
|
|
|
log(LOG_ERR,"circuit_crypt(): Decryption failed for ACI : %u (%s).",
|
2002-08-22 09:30:03 +02:00
|
|
|
circ->n_aci, crypto_perror());
|
Integrated onion proxy into or/
The 'or' process can now be told (by the global_role variable) what
roles this server should play -- connect to all ORs, listen for ORs,
listen for OPs, listen for APs, or any combination.
* everything in /src/op/ is now obsolete.
* connection_ap.c now handles all interactions with application proxies
* "port" is now or_port, op_port, ap_port. But routers are still always
referenced (say, in conn_get_by_addr_port()) by addr / or_port. We
should make routers.c actually read these new ports (currently I've
kludged it so op_port = or_port+10, ap_port=or_port+20)
* circuits currently know if they're at the beginning of the path because
circ->cpath is set. They use this instead for crypts (both ways),
if it's set.
* I still obey the "send a 0 back to the AP when you're ready" protocol,
but I think we should phase it out. I can simply not read from the AP
socket until I'm ready.
I need to do a lot of cleanup work here, but the code appears to work, so
now's a good time for a checkin.
svn:r22
2002-07-02 11:36:58 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
memcpy(in,out,inlen);
|
2003-05-02 23:29:25 +02:00
|
|
|
|
|
|
|
if( (*recognized = relay_check_recognized(circ, cell_direction, in+2, conn)))
|
|
|
|
return 0;
|
|
|
|
|
2002-06-27 00:45:49 +02:00
|
|
|
}
|
major overhaul: dns slave subsystem, topics
on startup, it forks off a master dns handler, which forks off dns
slaves (like the apache model). slaves as spawned as load increases,
and then reused. excess slaves are not ever killed, currently.
implemented topics. each topic has a receive window in each direction
at each edge of the circuit, and sends sendme's at the data level, as
per before. each circuit also has receive windows in each direction at
each hop; an edge sends a circuit-level sendme as soon as enough data
cells have arrived (regardless of whether the data cells were flushed
to the exit conns). removed the 'connected' cell type, since it's now
a topic command within data cells.
at the edge of the circuit, there can be multiple connections associated
with a single circuit. you find them via the linked list conn->next_topic.
currently each new ap connection starts its own circuit, so we ought
to see comparable performance to what we had before. but that's only
because i haven't written the code to reattach to old circuits. please
try to break it as-is, and then i'll make it reuse the same circuit and
we'll try to break that.
svn:r152
2003-01-26 10:02:24 +01:00
|
|
|
} else {
|
|
|
|
log(LOG_ERR,"circuit_crypt(): unknown cell direction %d.", cell_direction);
|
|
|
|
assert(0);
|
2002-06-27 00:45:49 +02:00
|
|
|
}
|
|
|
|
|
major overhaul: dns slave subsystem, topics
on startup, it forks off a master dns handler, which forks off dns
slaves (like the apache model). slaves as spawned as load increases,
and then reused. excess slaves are not ever killed, currently.
implemented topics. each topic has a receive window in each direction
at each edge of the circuit, and sends sendme's at the data level, as
per before. each circuit also has receive windows in each direction at
each hop; an edge sends a circuit-level sendme as soon as enough data
cells have arrived (regardless of whether the data cells were flushed
to the exit conns). removed the 'connected' cell type, since it's now
a topic command within data cells.
at the edge of the circuit, there can be multiple connections associated
with a single circuit. you find them via the linked list conn->next_topic.
currently each new ap connection starts its own circuit, so we ought
to see comparable performance to what we had before. but that's only
because i haven't written the code to reattach to old circuits. please
try to break it as-is, and then i'll make it reuse the same circuit and
we'll try to break that.
svn:r152
2003-01-26 10:02:24 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-05-02 23:29:25 +02:00
|
|
|
int relay_check_recognized(circuit_t *circ, int cell_direction, char *stream, connection_t **conn) {
|
|
|
|
/* FIXME can optimize by passing thishop in */
|
|
|
|
connection_t *tmpconn;
|
|
|
|
|
|
|
|
log(LOG_DEBUG,"relay_check_recognized(): entering");
|
|
|
|
if(!memcmp(stream,ZERO_STREAM,STREAM_ID_SIZE))
|
|
|
|
return 1; /* the zero stream is always recognized */
|
|
|
|
|
|
|
|
if(cell_direction == CELL_DIRECTION_OUT)
|
|
|
|
tmpconn = circ->n_conn;
|
|
|
|
else
|
|
|
|
tmpconn = circ->p_conn;
|
|
|
|
|
|
|
|
log(LOG_DEBUG,"relay_check_recognized(): not the zero stream.");
|
|
|
|
if(!tmpconn)
|
|
|
|
return 0; /* no conns? don't recognize it */
|
|
|
|
|
|
|
|
while(tmpconn && tmpconn->type == CONN_TYPE_OR) {
|
|
|
|
log(LOG_DEBUG,"relay_check_recognized(): skipping over an OR conn");
|
|
|
|
tmpconn = tmpconn->next_stream;
|
|
|
|
}
|
|
|
|
|
|
|
|
for( ; tmpconn; tmpconn=tmpconn->next_stream) {
|
|
|
|
if(!memcmp(stream,tmpconn->stream_id, STREAM_ID_SIZE)) {
|
|
|
|
log(LOG_DEBUG,"relay_check_recognized(): recognized stream %d.", *(int*)stream);
|
|
|
|
*conn = tmpconn;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
log(LOG_DEBUG,"relay_check_recognized(): considered stream %d, not it.",*(int*)tmpconn->stream_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
log(LOG_DEBUG,"relay_check_recognized(): Didn't recognize. Giving up.");
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
major overhaul: dns slave subsystem, topics
on startup, it forks off a master dns handler, which forks off dns
slaves (like the apache model). slaves as spawned as load increases,
and then reused. excess slaves are not ever killed, currently.
implemented topics. each topic has a receive window in each direction
at each edge of the circuit, and sends sendme's at the data level, as
per before. each circuit also has receive windows in each direction at
each hop; an edge sends a circuit-level sendme as soon as enough data
cells have arrived (regardless of whether the data cells were flushed
to the exit conns). removed the 'connected' cell type, since it's now
a topic command within data cells.
at the edge of the circuit, there can be multiple connections associated
with a single circuit. you find them via the linked list conn->next_topic.
currently each new ap connection starts its own circuit, so we ought
to see comparable performance to what we had before. but that's only
because i haven't written the code to reattach to old circuits. please
try to break it as-is, and then i'll make it reuse the same circuit and
we'll try to break that.
svn:r152
2003-01-26 10:02:24 +01:00
|
|
|
void circuit_resume_edge_reading(circuit_t *circ, int edge_type) {
|
|
|
|
connection_t *conn;
|
2003-05-01 08:42:29 +02:00
|
|
|
struct relay_queue_t *tmpd;
|
major overhaul: dns slave subsystem, topics
on startup, it forks off a master dns handler, which forks off dns
slaves (like the apache model). slaves as spawned as load increases,
and then reused. excess slaves are not ever killed, currently.
implemented topics. each topic has a receive window in each direction
at each edge of the circuit, and sends sendme's at the data level, as
per before. each circuit also has receive windows in each direction at
each hop; an edge sends a circuit-level sendme as soon as enough data
cells have arrived (regardless of whether the data cells were flushed
to the exit conns). removed the 'connected' cell type, since it's now
a topic command within data cells.
at the edge of the circuit, there can be multiple connections associated
with a single circuit. you find them via the linked list conn->next_topic.
currently each new ap connection starts its own circuit, so we ought
to see comparable performance to what we had before. but that's only
because i haven't written the code to reattach to old circuits. please
try to break it as-is, and then i'll make it reuse the same circuit and
we'll try to break that.
svn:r152
2003-01-26 10:02:24 +01:00
|
|
|
|
|
|
|
assert(edge_type == EDGE_EXIT || edge_type == EDGE_AP);
|
|
|
|
|
|
|
|
/* first, send the queue waiting at circ onto the circuit */
|
2003-05-01 08:42:29 +02:00
|
|
|
while(circ->relay_queue) {
|
|
|
|
assert(circ->relay_queue->cell);
|
2003-02-18 02:35:55 +01:00
|
|
|
if(edge_type == EDGE_EXIT) {
|
|
|
|
circ->n_receive_circwindow--;
|
|
|
|
assert(circ->n_receive_circwindow >= 0);
|
|
|
|
|
2003-05-02 23:29:25 +02:00
|
|
|
if(circuit_deliver_relay_cell(circ->relay_queue->cell, circ, CELL_DIRECTION_IN, circ->relay_queue->layer_hint) < 0) {
|
major overhaul: dns slave subsystem, topics
on startup, it forks off a master dns handler, which forks off dns
slaves (like the apache model). slaves as spawned as load increases,
and then reused. excess slaves are not ever killed, currently.
implemented topics. each topic has a receive window in each direction
at each edge of the circuit, and sends sendme's at the data level, as
per before. each circuit also has receive windows in each direction at
each hop; an edge sends a circuit-level sendme as soon as enough data
cells have arrived (regardless of whether the data cells were flushed
to the exit conns). removed the 'connected' cell type, since it's now
a topic command within data cells.
at the edge of the circuit, there can be multiple connections associated
with a single circuit. you find them via the linked list conn->next_topic.
currently each new ap connection starts its own circuit, so we ought
to see comparable performance to what we had before. but that's only
because i haven't written the code to reattach to old circuits. please
try to break it as-is, and then i'll make it reuse the same circuit and
we'll try to break that.
svn:r152
2003-01-26 10:02:24 +01:00
|
|
|
circuit_close(circ);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else { /* ap */
|
|
|
|
circ->p_receive_circwindow--;
|
|
|
|
assert(circ->p_receive_circwindow >= 0);
|
2003-02-18 02:35:55 +01:00
|
|
|
|
2003-05-02 23:29:25 +02:00
|
|
|
if(circuit_deliver_relay_cell(circ->relay_queue->cell, circ, CELL_DIRECTION_OUT, circ->relay_queue->layer_hint) < 0) {
|
major overhaul: dns slave subsystem, topics
on startup, it forks off a master dns handler, which forks off dns
slaves (like the apache model). slaves as spawned as load increases,
and then reused. excess slaves are not ever killed, currently.
implemented topics. each topic has a receive window in each direction
at each edge of the circuit, and sends sendme's at the data level, as
per before. each circuit also has receive windows in each direction at
each hop; an edge sends a circuit-level sendme as soon as enough data
cells have arrived (regardless of whether the data cells were flushed
to the exit conns). removed the 'connected' cell type, since it's now
a topic command within data cells.
at the edge of the circuit, there can be multiple connections associated
with a single circuit. you find them via the linked list conn->next_topic.
currently each new ap connection starts its own circuit, so we ought
to see comparable performance to what we had before. but that's only
because i haven't written the code to reattach to old circuits. please
try to break it as-is, and then i'll make it reuse the same circuit and
we'll try to break that.
svn:r152
2003-01-26 10:02:24 +01:00
|
|
|
circuit_close(circ);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2003-05-01 08:42:29 +02:00
|
|
|
tmpd = circ->relay_queue;
|
|
|
|
circ->relay_queue = tmpd->next;
|
major overhaul: dns slave subsystem, topics
on startup, it forks off a master dns handler, which forks off dns
slaves (like the apache model). slaves as spawned as load increases,
and then reused. excess slaves are not ever killed, currently.
implemented topics. each topic has a receive window in each direction
at each edge of the circuit, and sends sendme's at the data level, as
per before. each circuit also has receive windows in each direction at
each hop; an edge sends a circuit-level sendme as soon as enough data
cells have arrived (regardless of whether the data cells were flushed
to the exit conns). removed the 'connected' cell type, since it's now
a topic command within data cells.
at the edge of the circuit, there can be multiple connections associated
with a single circuit. you find them via the linked list conn->next_topic.
currently each new ap connection starts its own circuit, so we ought
to see comparable performance to what we had before. but that's only
because i haven't written the code to reattach to old circuits. please
try to break it as-is, and then i'll make it reuse the same circuit and
we'll try to break that.
svn:r152
2003-01-26 10:02:24 +01:00
|
|
|
free(tmpd->cell);
|
|
|
|
free(tmpd);
|
|
|
|
|
|
|
|
if(circuit_consider_stop_edge_reading(circ, edge_type))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-02-18 02:35:55 +01:00
|
|
|
if(edge_type == EDGE_EXIT)
|
|
|
|
conn = circ->n_conn;
|
|
|
|
else
|
|
|
|
conn = circ->p_conn;
|
|
|
|
|
2003-05-01 08:42:29 +02:00
|
|
|
for( ; conn; conn=conn->next_stream) {
|
|
|
|
if((edge_type == EDGE_EXIT && conn->n_receive_streamwindow > 0) ||
|
|
|
|
(edge_type == EDGE_AP && conn->p_receive_streamwindow > 0)) {
|
major overhaul: dns slave subsystem, topics
on startup, it forks off a master dns handler, which forks off dns
slaves (like the apache model). slaves as spawned as load increases,
and then reused. excess slaves are not ever killed, currently.
implemented topics. each topic has a receive window in each direction
at each edge of the circuit, and sends sendme's at the data level, as
per before. each circuit also has receive windows in each direction at
each hop; an edge sends a circuit-level sendme as soon as enough data
cells have arrived (regardless of whether the data cells were flushed
to the exit conns). removed the 'connected' cell type, since it's now
a topic command within data cells.
at the edge of the circuit, there can be multiple connections associated
with a single circuit. you find them via the linked list conn->next_topic.
currently each new ap connection starts its own circuit, so we ought
to see comparable performance to what we had before. but that's only
because i haven't written the code to reattach to old circuits. please
try to break it as-is, and then i'll make it reuse the same circuit and
we'll try to break that.
svn:r152
2003-01-26 10:02:24 +01:00
|
|
|
connection_start_reading(conn);
|
|
|
|
connection_package_raw_inbuf(conn); /* handle whatever might still be on the inbuf */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
circuit_consider_stop_edge_reading(circ, edge_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* returns 1 if the window is empty, else 0. If it's empty, tell edge conns to stop reading. */
|
|
|
|
int circuit_consider_stop_edge_reading(circuit_t *circ, int edge_type) {
|
|
|
|
connection_t *conn = NULL;
|
|
|
|
|
|
|
|
assert(edge_type == EDGE_EXIT || edge_type == EDGE_AP);
|
|
|
|
|
2003-02-18 02:35:55 +01:00
|
|
|
if(edge_type == EDGE_EXIT && circ->n_receive_circwindow <= 0)
|
|
|
|
conn = circ->n_conn;
|
|
|
|
else if(edge_type == EDGE_AP && circ->p_receive_circwindow <= 0)
|
|
|
|
conn = circ->p_conn;
|
major overhaul: dns slave subsystem, topics
on startup, it forks off a master dns handler, which forks off dns
slaves (like the apache model). slaves as spawned as load increases,
and then reused. excess slaves are not ever killed, currently.
implemented topics. each topic has a receive window in each direction
at each edge of the circuit, and sends sendme's at the data level, as
per before. each circuit also has receive windows in each direction at
each hop; an edge sends a circuit-level sendme as soon as enough data
cells have arrived (regardless of whether the data cells were flushed
to the exit conns). removed the 'connected' cell type, since it's now
a topic command within data cells.
at the edge of the circuit, there can be multiple connections associated
with a single circuit. you find them via the linked list conn->next_topic.
currently each new ap connection starts its own circuit, so we ought
to see comparable performance to what we had before. but that's only
because i haven't written the code to reattach to old circuits. please
try to break it as-is, and then i'll make it reuse the same circuit and
we'll try to break that.
svn:r152
2003-01-26 10:02:24 +01:00
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
|
2003-05-01 08:42:29 +02:00
|
|
|
for( ; conn; conn=conn->next_stream)
|
major overhaul: dns slave subsystem, topics
on startup, it forks off a master dns handler, which forks off dns
slaves (like the apache model). slaves as spawned as load increases,
and then reused. excess slaves are not ever killed, currently.
implemented topics. each topic has a receive window in each direction
at each edge of the circuit, and sends sendme's at the data level, as
per before. each circuit also has receive windows in each direction at
each hop; an edge sends a circuit-level sendme as soon as enough data
cells have arrived (regardless of whether the data cells were flushed
to the exit conns). removed the 'connected' cell type, since it's now
a topic command within data cells.
at the edge of the circuit, there can be multiple connections associated
with a single circuit. you find them via the linked list conn->next_topic.
currently each new ap connection starts its own circuit, so we ought
to see comparable performance to what we had before. but that's only
because i haven't written the code to reattach to old circuits. please
try to break it as-is, and then i'll make it reuse the same circuit and
we'll try to break that.
svn:r152
2003-01-26 10:02:24 +01:00
|
|
|
connection_stop_reading(conn);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int circuit_consider_sending_sendme(circuit_t *circ, int edge_type) {
|
|
|
|
cell_t sendme;
|
2002-06-27 00:45:49 +02:00
|
|
|
|
major overhaul: dns slave subsystem, topics
on startup, it forks off a master dns handler, which forks off dns
slaves (like the apache model). slaves as spawned as load increases,
and then reused. excess slaves are not ever killed, currently.
implemented topics. each topic has a receive window in each direction
at each edge of the circuit, and sends sendme's at the data level, as
per before. each circuit also has receive windows in each direction at
each hop; an edge sends a circuit-level sendme as soon as enough data
cells have arrived (regardless of whether the data cells were flushed
to the exit conns). removed the 'connected' cell type, since it's now
a topic command within data cells.
at the edge of the circuit, there can be multiple connections associated
with a single circuit. you find them via the linked list conn->next_topic.
currently each new ap connection starts its own circuit, so we ought
to see comparable performance to what we had before. but that's only
because i haven't written the code to reattach to old circuits. please
try to break it as-is, and then i'll make it reuse the same circuit and
we'll try to break that.
svn:r152
2003-01-26 10:02:24 +01:00
|
|
|
assert(circ);
|
|
|
|
|
2003-03-11 22:38:38 +01:00
|
|
|
memset(&sendme, 0, sizeof(cell_t));
|
major overhaul: dns slave subsystem, topics
on startup, it forks off a master dns handler, which forks off dns
slaves (like the apache model). slaves as spawned as load increases,
and then reused. excess slaves are not ever killed, currently.
implemented topics. each topic has a receive window in each direction
at each edge of the circuit, and sends sendme's at the data level, as
per before. each circuit also has receive windows in each direction at
each hop; an edge sends a circuit-level sendme as soon as enough data
cells have arrived (regardless of whether the data cells were flushed
to the exit conns). removed the 'connected' cell type, since it's now
a topic command within data cells.
at the edge of the circuit, there can be multiple connections associated
with a single circuit. you find them via the linked list conn->next_topic.
currently each new ap connection starts its own circuit, so we ought
to see comparable performance to what we had before. but that's only
because i haven't written the code to reattach to old circuits. please
try to break it as-is, and then i'll make it reuse the same circuit and
we'll try to break that.
svn:r152
2003-01-26 10:02:24 +01:00
|
|
|
sendme.command = CELL_SENDME;
|
|
|
|
sendme.length = CIRCWINDOW_INCREMENT;
|
|
|
|
|
|
|
|
if(edge_type == EDGE_AP) { /* i'm the AP */
|
2003-02-18 02:35:55 +01:00
|
|
|
while(circ->n_receive_circwindow < CIRCWINDOW_START-CIRCWINDOW_INCREMENT) {
|
2003-03-10 23:30:05 +01:00
|
|
|
log(LOG_DEBUG,"circuit_consider_sending_sendme(): n_receive_circwindow %d, Queueing sendme forward.", circ->n_receive_circwindow);
|
major overhaul: dns slave subsystem, topics
on startup, it forks off a master dns handler, which forks off dns
slaves (like the apache model). slaves as spawned as load increases,
and then reused. excess slaves are not ever killed, currently.
implemented topics. each topic has a receive window in each direction
at each edge of the circuit, and sends sendme's at the data level, as
per before. each circuit also has receive windows in each direction at
each hop; an edge sends a circuit-level sendme as soon as enough data
cells have arrived (regardless of whether the data cells were flushed
to the exit conns). removed the 'connected' cell type, since it's now
a topic command within data cells.
at the edge of the circuit, there can be multiple connections associated
with a single circuit. you find them via the linked list conn->next_topic.
currently each new ap connection starts its own circuit, so we ought
to see comparable performance to what we had before. but that's only
because i haven't written the code to reattach to old circuits. please
try to break it as-is, and then i'll make it reuse the same circuit and
we'll try to break that.
svn:r152
2003-01-26 10:02:24 +01:00
|
|
|
circ->n_receive_circwindow += CIRCWINDOW_INCREMENT;
|
|
|
|
sendme.aci = circ->n_aci;
|
2003-02-18 02:35:55 +01:00
|
|
|
if(connection_write_cell_to_buf(&sendme, circ->n_conn) < 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
major overhaul: dns slave subsystem, topics
on startup, it forks off a master dns handler, which forks off dns
slaves (like the apache model). slaves as spawned as load increases,
and then reused. excess slaves are not ever killed, currently.
implemented topics. each topic has a receive window in each direction
at each edge of the circuit, and sends sendme's at the data level, as
per before. each circuit also has receive windows in each direction at
each hop; an edge sends a circuit-level sendme as soon as enough data
cells have arrived (regardless of whether the data cells were flushed
to the exit conns). removed the 'connected' cell type, since it's now
a topic command within data cells.
at the edge of the circuit, there can be multiple connections associated
with a single circuit. you find them via the linked list conn->next_topic.
currently each new ap connection starts its own circuit, so we ought
to see comparable performance to what we had before. but that's only
because i haven't written the code to reattach to old circuits. please
try to break it as-is, and then i'll make it reuse the same circuit and
we'll try to break that.
svn:r152
2003-01-26 10:02:24 +01:00
|
|
|
}
|
|
|
|
} else if(edge_type == EDGE_EXIT) { /* i'm the exit */
|
2003-02-18 02:35:55 +01:00
|
|
|
while(circ->p_receive_circwindow < CIRCWINDOW_START-CIRCWINDOW_INCREMENT) {
|
2003-03-10 23:30:05 +01:00
|
|
|
log(LOG_DEBUG,"circuit_consider_sending_sendme(): p_receive_circwindow %d, Queueing sendme back.", circ->p_receive_circwindow);
|
major overhaul: dns slave subsystem, topics
on startup, it forks off a master dns handler, which forks off dns
slaves (like the apache model). slaves as spawned as load increases,
and then reused. excess slaves are not ever killed, currently.
implemented topics. each topic has a receive window in each direction
at each edge of the circuit, and sends sendme's at the data level, as
per before. each circuit also has receive windows in each direction at
each hop; an edge sends a circuit-level sendme as soon as enough data
cells have arrived (regardless of whether the data cells were flushed
to the exit conns). removed the 'connected' cell type, since it's now
a topic command within data cells.
at the edge of the circuit, there can be multiple connections associated
with a single circuit. you find them via the linked list conn->next_topic.
currently each new ap connection starts its own circuit, so we ought
to see comparable performance to what we had before. but that's only
because i haven't written the code to reattach to old circuits. please
try to break it as-is, and then i'll make it reuse the same circuit and
we'll try to break that.
svn:r152
2003-01-26 10:02:24 +01:00
|
|
|
circ->p_receive_circwindow += CIRCWINDOW_INCREMENT;
|
|
|
|
sendme.aci = circ->p_aci;
|
2003-02-18 02:35:55 +01:00
|
|
|
if(connection_write_cell_to_buf(&sendme, circ->p_conn) < 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
major overhaul: dns slave subsystem, topics
on startup, it forks off a master dns handler, which forks off dns
slaves (like the apache model). slaves as spawned as load increases,
and then reused. excess slaves are not ever killed, currently.
implemented topics. each topic has a receive window in each direction
at each edge of the circuit, and sends sendme's at the data level, as
per before. each circuit also has receive windows in each direction at
each hop; an edge sends a circuit-level sendme as soon as enough data
cells have arrived (regardless of whether the data cells were flushed
to the exit conns). removed the 'connected' cell type, since it's now
a topic command within data cells.
at the edge of the circuit, there can be multiple connections associated
with a single circuit. you find them via the linked list conn->next_topic.
currently each new ap connection starts its own circuit, so we ought
to see comparable performance to what we had before. but that's only
because i haven't written the code to reattach to old circuits. please
try to break it as-is, and then i'll make it reuse the same circuit and
we'll try to break that.
svn:r152
2003-01-26 10:02:24 +01:00
|
|
|
}
|
|
|
|
}
|
2002-06-27 00:45:49 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void circuit_close(circuit_t *circ) {
|
major overhaul: dns slave subsystem, topics
on startup, it forks off a master dns handler, which forks off dns
slaves (like the apache model). slaves as spawned as load increases,
and then reused. excess slaves are not ever killed, currently.
implemented topics. each topic has a receive window in each direction
at each edge of the circuit, and sends sendme's at the data level, as
per before. each circuit also has receive windows in each direction at
each hop; an edge sends a circuit-level sendme as soon as enough data
cells have arrived (regardless of whether the data cells were flushed
to the exit conns). removed the 'connected' cell type, since it's now
a topic command within data cells.
at the edge of the circuit, there can be multiple connections associated
with a single circuit. you find them via the linked list conn->next_topic.
currently each new ap connection starts its own circuit, so we ought
to see comparable performance to what we had before. but that's only
because i haven't written the code to reattach to old circuits. please
try to break it as-is, and then i'll make it reuse the same circuit and
we'll try to break that.
svn:r152
2003-01-26 10:02:24 +01:00
|
|
|
connection_t *conn;
|
2003-04-17 01:21:44 +02:00
|
|
|
circuit_t *youngest=NULL;
|
major overhaul: dns slave subsystem, topics
on startup, it forks off a master dns handler, which forks off dns
slaves (like the apache model). slaves as spawned as load increases,
and then reused. excess slaves are not ever killed, currently.
implemented topics. each topic has a receive window in each direction
at each edge of the circuit, and sends sendme's at the data level, as
per before. each circuit also has receive windows in each direction at
each hop; an edge sends a circuit-level sendme as soon as enough data
cells have arrived (regardless of whether the data cells were flushed
to the exit conns). removed the 'connected' cell type, since it's now
a topic command within data cells.
at the edge of the circuit, there can be multiple connections associated
with a single circuit. you find them via the linked list conn->next_topic.
currently each new ap connection starts its own circuit, so we ought
to see comparable performance to what we had before. but that's only
because i haven't written the code to reattach to old circuits. please
try to break it as-is, and then i'll make it reuse the same circuit and
we'll try to break that.
svn:r152
2003-01-26 10:02:24 +01:00
|
|
|
|
2003-02-06 09:00:49 +01:00
|
|
|
assert(circ);
|
2003-04-20 21:47:33 +02:00
|
|
|
if(options.APPort) {
|
2003-05-02 00:55:51 +02:00
|
|
|
youngest = circuit_get_newest_ap();
|
2003-04-20 21:47:33 +02:00
|
|
|
log(LOG_DEBUG,"circuit_close(): youngest %d, circ %d.",youngest,circ);
|
|
|
|
}
|
2002-06-27 00:45:49 +02:00
|
|
|
circuit_remove(circ);
|
2003-05-01 08:42:29 +02:00
|
|
|
for(conn=circ->n_conn; conn; conn=conn->next_stream) {
|
Integrated onion proxy into or/
The 'or' process can now be told (by the global_role variable) what
roles this server should play -- connect to all ORs, listen for ORs,
listen for OPs, listen for APs, or any combination.
* everything in /src/op/ is now obsolete.
* connection_ap.c now handles all interactions with application proxies
* "port" is now or_port, op_port, ap_port. But routers are still always
referenced (say, in conn_get_by_addr_port()) by addr / or_port. We
should make routers.c actually read these new ports (currently I've
kludged it so op_port = or_port+10, ap_port=or_port+20)
* circuits currently know if they're at the beginning of the path because
circ->cpath is set. They use this instead for crypts (both ways),
if it's set.
* I still obey the "send a 0 back to the AP when you're ready" protocol,
but I think we should phase it out. I can simply not read from the AP
socket until I'm ready.
I need to do a lot of cleanup work here, but the code appears to work, so
now's a good time for a checkin.
svn:r22
2002-07-02 11:36:58 +02:00
|
|
|
connection_send_destroy(circ->n_aci, circ->n_conn);
|
major overhaul: dns slave subsystem, topics
on startup, it forks off a master dns handler, which forks off dns
slaves (like the apache model). slaves as spawned as load increases,
and then reused. excess slaves are not ever killed, currently.
implemented topics. each topic has a receive window in each direction
at each edge of the circuit, and sends sendme's at the data level, as
per before. each circuit also has receive windows in each direction at
each hop; an edge sends a circuit-level sendme as soon as enough data
cells have arrived (regardless of whether the data cells were flushed
to the exit conns). removed the 'connected' cell type, since it's now
a topic command within data cells.
at the edge of the circuit, there can be multiple connections associated
with a single circuit. you find them via the linked list conn->next_topic.
currently each new ap connection starts its own circuit, so we ought
to see comparable performance to what we had before. but that's only
because i haven't written the code to reattach to old circuits. please
try to break it as-is, and then i'll make it reuse the same circuit and
we'll try to break that.
svn:r152
2003-01-26 10:02:24 +01:00
|
|
|
}
|
2003-05-01 08:42:29 +02:00
|
|
|
for(conn=circ->p_conn; conn; conn=conn->next_stream) {
|
Integrated onion proxy into or/
The 'or' process can now be told (by the global_role variable) what
roles this server should play -- connect to all ORs, listen for ORs,
listen for OPs, listen for APs, or any combination.
* everything in /src/op/ is now obsolete.
* connection_ap.c now handles all interactions with application proxies
* "port" is now or_port, op_port, ap_port. But routers are still always
referenced (say, in conn_get_by_addr_port()) by addr / or_port. We
should make routers.c actually read these new ports (currently I've
kludged it so op_port = or_port+10, ap_port=or_port+20)
* circuits currently know if they're at the beginning of the path because
circ->cpath is set. They use this instead for crypts (both ways),
if it's set.
* I still obey the "send a 0 back to the AP when you're ready" protocol,
but I think we should phase it out. I can simply not read from the AP
socket until I'm ready.
I need to do a lot of cleanup work here, but the code appears to work, so
now's a good time for a checkin.
svn:r22
2002-07-02 11:36:58 +02:00
|
|
|
connection_send_destroy(circ->p_aci, circ->p_conn);
|
major overhaul: dns slave subsystem, topics
on startup, it forks off a master dns handler, which forks off dns
slaves (like the apache model). slaves as spawned as load increases,
and then reused. excess slaves are not ever killed, currently.
implemented topics. each topic has a receive window in each direction
at each edge of the circuit, and sends sendme's at the data level, as
per before. each circuit also has receive windows in each direction at
each hop; an edge sends a circuit-level sendme as soon as enough data
cells have arrived (regardless of whether the data cells were flushed
to the exit conns). removed the 'connected' cell type, since it's now
a topic command within data cells.
at the edge of the circuit, there can be multiple connections associated
with a single circuit. you find them via the linked list conn->next_topic.
currently each new ap connection starts its own circuit, so we ought
to see comparable performance to what we had before. but that's only
because i haven't written the code to reattach to old circuits. please
try to break it as-is, and then i'll make it reuse the same circuit and
we'll try to break that.
svn:r152
2003-01-26 10:02:24 +01:00
|
|
|
}
|
2003-04-16 08:18:31 +02:00
|
|
|
if(options.APPort && youngest == circ) { /* check this after we've sent the destroys, to reduce races */
|
|
|
|
/* our current circuit just died. Launch another one pronto. */
|
|
|
|
log(LOG_INFO,"circuit_close(): Youngest circuit dying. Launching a replacement.");
|
|
|
|
circuit_launch_new(1);
|
|
|
|
}
|
2002-06-27 00:45:49 +02:00
|
|
|
circuit_free(circ);
|
|
|
|
}
|
|
|
|
|
|
|
|
void circuit_about_to_close_connection(connection_t *conn) {
|
|
|
|
/* send destroys for all circuits using conn */
|
|
|
|
/* currently, we assume it's too late to flush conn's buf here.
|
|
|
|
* down the road, maybe we'll consider that eof doesn't mean can't-write
|
|
|
|
*/
|
|
|
|
circuit_t *circ;
|
2003-04-20 23:56:44 +02:00
|
|
|
connection_t *prevconn;
|
major overhaul: dns slave subsystem, topics
on startup, it forks off a master dns handler, which forks off dns
slaves (like the apache model). slaves as spawned as load increases,
and then reused. excess slaves are not ever killed, currently.
implemented topics. each topic has a receive window in each direction
at each edge of the circuit, and sends sendme's at the data level, as
per before. each circuit also has receive windows in each direction at
each hop; an edge sends a circuit-level sendme as soon as enough data
cells have arrived (regardless of whether the data cells were flushed
to the exit conns). removed the 'connected' cell type, since it's now
a topic command within data cells.
at the edge of the circuit, there can be multiple connections associated
with a single circuit. you find them via the linked list conn->next_topic.
currently each new ap connection starts its own circuit, so we ought
to see comparable performance to what we had before. but that's only
because i haven't written the code to reattach to old circuits. please
try to break it as-is, and then i'll make it reuse the same circuit and
we'll try to break that.
svn:r152
2003-01-26 10:02:24 +01:00
|
|
|
|
|
|
|
if(!connection_speaks_cells(conn)) {
|
|
|
|
/* it's an edge conn. need to remove it from the linked list of
|
2003-05-01 08:42:29 +02:00
|
|
|
* conn's for this circuit. Send an 'end' relay command.
|
major overhaul: dns slave subsystem, topics
on startup, it forks off a master dns handler, which forks off dns
slaves (like the apache model). slaves as spawned as load increases,
and then reused. excess slaves are not ever killed, currently.
implemented topics. each topic has a receive window in each direction
at each edge of the circuit, and sends sendme's at the data level, as
per before. each circuit also has receive windows in each direction at
each hop; an edge sends a circuit-level sendme as soon as enough data
cells have arrived (regardless of whether the data cells were flushed
to the exit conns). removed the 'connected' cell type, since it's now
a topic command within data cells.
at the edge of the circuit, there can be multiple connections associated
with a single circuit. you find them via the linked list conn->next_topic.
currently each new ap connection starts its own circuit, so we ought
to see comparable performance to what we had before. but that's only
because i haven't written the code to reattach to old circuits. please
try to break it as-is, and then i'll make it reuse the same circuit and
we'll try to break that.
svn:r152
2003-01-26 10:02:24 +01:00
|
|
|
* But don't kill the circuit.
|
|
|
|
*/
|
|
|
|
|
|
|
|
circ = circuit_get_by_conn(conn);
|
|
|
|
if(!circ)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(conn == circ->p_conn) {
|
2003-05-01 08:42:29 +02:00
|
|
|
circ->p_conn = conn->next_stream;
|
major overhaul: dns slave subsystem, topics
on startup, it forks off a master dns handler, which forks off dns
slaves (like the apache model). slaves as spawned as load increases,
and then reused. excess slaves are not ever killed, currently.
implemented topics. each topic has a receive window in each direction
at each edge of the circuit, and sends sendme's at the data level, as
per before. each circuit also has receive windows in each direction at
each hop; an edge sends a circuit-level sendme as soon as enough data
cells have arrived (regardless of whether the data cells were flushed
to the exit conns). removed the 'connected' cell type, since it's now
a topic command within data cells.
at the edge of the circuit, there can be multiple connections associated
with a single circuit. you find them via the linked list conn->next_topic.
currently each new ap connection starts its own circuit, so we ought
to see comparable performance to what we had before. but that's only
because i haven't written the code to reattach to old circuits. please
try to break it as-is, and then i'll make it reuse the same circuit and
we'll try to break that.
svn:r152
2003-01-26 10:02:24 +01:00
|
|
|
goto send_end;
|
|
|
|
}
|
|
|
|
if(conn == circ->n_conn) {
|
2003-05-01 08:42:29 +02:00
|
|
|
circ->n_conn = conn->next_stream;
|
major overhaul: dns slave subsystem, topics
on startup, it forks off a master dns handler, which forks off dns
slaves (like the apache model). slaves as spawned as load increases,
and then reused. excess slaves are not ever killed, currently.
implemented topics. each topic has a receive window in each direction
at each edge of the circuit, and sends sendme's at the data level, as
per before. each circuit also has receive windows in each direction at
each hop; an edge sends a circuit-level sendme as soon as enough data
cells have arrived (regardless of whether the data cells were flushed
to the exit conns). removed the 'connected' cell type, since it's now
a topic command within data cells.
at the edge of the circuit, there can be multiple connections associated
with a single circuit. you find them via the linked list conn->next_topic.
currently each new ap connection starts its own circuit, so we ought
to see comparable performance to what we had before. but that's only
because i haven't written the code to reattach to old circuits. please
try to break it as-is, and then i'll make it reuse the same circuit and
we'll try to break that.
svn:r152
2003-01-26 10:02:24 +01:00
|
|
|
goto send_end;
|
|
|
|
}
|
2003-05-01 08:42:29 +02:00
|
|
|
for(prevconn = circ->p_conn; prevconn->next_stream && prevconn->next_stream != conn; prevconn = prevconn->next_stream) ;
|
|
|
|
if(prevconn->next_stream) {
|
|
|
|
prevconn->next_stream = conn->next_stream;
|
major overhaul: dns slave subsystem, topics
on startup, it forks off a master dns handler, which forks off dns
slaves (like the apache model). slaves as spawned as load increases,
and then reused. excess slaves are not ever killed, currently.
implemented topics. each topic has a receive window in each direction
at each edge of the circuit, and sends sendme's at the data level, as
per before. each circuit also has receive windows in each direction at
each hop; an edge sends a circuit-level sendme as soon as enough data
cells have arrived (regardless of whether the data cells were flushed
to the exit conns). removed the 'connected' cell type, since it's now
a topic command within data cells.
at the edge of the circuit, there can be multiple connections associated
with a single circuit. you find them via the linked list conn->next_topic.
currently each new ap connection starts its own circuit, so we ought
to see comparable performance to what we had before. but that's only
because i haven't written the code to reattach to old circuits. please
try to break it as-is, and then i'll make it reuse the same circuit and
we'll try to break that.
svn:r152
2003-01-26 10:02:24 +01:00
|
|
|
goto send_end;
|
|
|
|
}
|
2003-05-01 08:42:29 +02:00
|
|
|
for(prevconn = circ->n_conn; prevconn->next_stream && prevconn->next_stream != conn; prevconn = prevconn->next_stream) ;
|
|
|
|
if(prevconn->next_stream) {
|
|
|
|
prevconn->next_stream = conn->next_stream;
|
major overhaul: dns slave subsystem, topics
on startup, it forks off a master dns handler, which forks off dns
slaves (like the apache model). slaves as spawned as load increases,
and then reused. excess slaves are not ever killed, currently.
implemented topics. each topic has a receive window in each direction
at each edge of the circuit, and sends sendme's at the data level, as
per before. each circuit also has receive windows in each direction at
each hop; an edge sends a circuit-level sendme as soon as enough data
cells have arrived (regardless of whether the data cells were flushed
to the exit conns). removed the 'connected' cell type, since it's now
a topic command within data cells.
at the edge of the circuit, there can be multiple connections associated
with a single circuit. you find them via the linked list conn->next_topic.
currently each new ap connection starts its own circuit, so we ought
to see comparable performance to what we had before. but that's only
because i haven't written the code to reattach to old circuits. please
try to break it as-is, and then i'll make it reuse the same circuit and
we'll try to break that.
svn:r152
2003-01-26 10:02:24 +01:00
|
|
|
goto send_end;
|
|
|
|
}
|
|
|
|
log(LOG_ERR,"circuit_about_to_close_connection(): edge conn not in circuit's list?");
|
|
|
|
assert(0); /* should never get here */
|
|
|
|
send_end:
|
2003-05-01 08:42:29 +02:00
|
|
|
if(connection_edge_send_command(conn, circ, RELAY_COMMAND_END) < 0) {
|
2003-04-12 00:11:11 +02:00
|
|
|
log(LOG_DEBUG,"circuit_about_to_close_connection(): sending end failed. Closing.");
|
major overhaul: dns slave subsystem, topics
on startup, it forks off a master dns handler, which forks off dns
slaves (like the apache model). slaves as spawned as load increases,
and then reused. excess slaves are not ever killed, currently.
implemented topics. each topic has a receive window in each direction
at each edge of the circuit, and sends sendme's at the data level, as
per before. each circuit also has receive windows in each direction at
each hop; an edge sends a circuit-level sendme as soon as enough data
cells have arrived (regardless of whether the data cells were flushed
to the exit conns). removed the 'connected' cell type, since it's now
a topic command within data cells.
at the edge of the circuit, there can be multiple connections associated
with a single circuit. you find them via the linked list conn->next_topic.
currently each new ap connection starts its own circuit, so we ought
to see comparable performance to what we had before. but that's only
because i haven't written the code to reattach to old circuits. please
try to break it as-is, and then i'll make it reuse the same circuit and
we'll try to break that.
svn:r152
2003-01-26 10:02:24 +01:00
|
|
|
circuit_close(circ);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2002-06-27 00:45:49 +02:00
|
|
|
|
2003-04-20 21:47:33 +02:00
|
|
|
/* this connection speaks cells. We must close all the circuits on it. */
|
2002-06-27 00:45:49 +02:00
|
|
|
while((circ = circuit_get_by_conn(conn))) {
|
|
|
|
if(circ->n_conn == conn) /* it's closing in front of us */
|
2003-04-20 21:47:33 +02:00
|
|
|
circ->n_conn = NULL;
|
2002-06-27 00:45:49 +02:00
|
|
|
if(circ->p_conn == conn) /* it's closing behind us */
|
2003-04-20 21:47:33 +02:00
|
|
|
circ->p_conn = NULL;
|
|
|
|
circuit_close(circ);
|
2002-06-27 00:45:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
major overhaul: dns slave subsystem, topics
on startup, it forks off a master dns handler, which forks off dns
slaves (like the apache model). slaves as spawned as load increases,
and then reused. excess slaves are not ever killed, currently.
implemented topics. each topic has a receive window in each direction
at each edge of the circuit, and sends sendme's at the data level, as
per before. each circuit also has receive windows in each direction at
each hop; an edge sends a circuit-level sendme as soon as enough data
cells have arrived (regardless of whether the data cells were flushed
to the exit conns). removed the 'connected' cell type, since it's now
a topic command within data cells.
at the edge of the circuit, there can be multiple connections associated
with a single circuit. you find them via the linked list conn->next_topic.
currently each new ap connection starts its own circuit, so we ought
to see comparable performance to what we had before. but that's only
because i haven't written the code to reattach to old circuits. please
try to break it as-is, and then i'll make it reuse the same circuit and
we'll try to break that.
svn:r152
2003-01-26 10:02:24 +01:00
|
|
|
/* FIXME this now leaves some out */
|
2002-09-22 00:41:48 +02:00
|
|
|
void circuit_dump_by_conn(connection_t *conn) {
|
|
|
|
circuit_t *circ;
|
major overhaul: dns slave subsystem, topics
on startup, it forks off a master dns handler, which forks off dns
slaves (like the apache model). slaves as spawned as load increases,
and then reused. excess slaves are not ever killed, currently.
implemented topics. each topic has a receive window in each direction
at each edge of the circuit, and sends sendme's at the data level, as
per before. each circuit also has receive windows in each direction at
each hop; an edge sends a circuit-level sendme as soon as enough data
cells have arrived (regardless of whether the data cells were flushed
to the exit conns). removed the 'connected' cell type, since it's now
a topic command within data cells.
at the edge of the circuit, there can be multiple connections associated
with a single circuit. you find them via the linked list conn->next_topic.
currently each new ap connection starts its own circuit, so we ought
to see comparable performance to what we had before. but that's only
because i haven't written the code to reattach to old circuits. please
try to break it as-is, and then i'll make it reuse the same circuit and
we'll try to break that.
svn:r152
2003-01-26 10:02:24 +01:00
|
|
|
connection_t *tmpconn;
|
2002-09-22 00:41:48 +02:00
|
|
|
|
|
|
|
for(circ=global_circuitlist;circ;circ = circ->next) {
|
2003-05-01 08:42:29 +02:00
|
|
|
for(tmpconn=circ->p_conn; tmpconn; tmpconn=tmpconn->next_stream) {
|
major overhaul: dns slave subsystem, topics
on startup, it forks off a master dns handler, which forks off dns
slaves (like the apache model). slaves as spawned as load increases,
and then reused. excess slaves are not ever killed, currently.
implemented topics. each topic has a receive window in each direction
at each edge of the circuit, and sends sendme's at the data level, as
per before. each circuit also has receive windows in each direction at
each hop; an edge sends a circuit-level sendme as soon as enough data
cells have arrived (regardless of whether the data cells were flushed
to the exit conns). removed the 'connected' cell type, since it's now
a topic command within data cells.
at the edge of the circuit, there can be multiple connections associated
with a single circuit. you find them via the linked list conn->next_topic.
currently each new ap connection starts its own circuit, so we ought
to see comparable performance to what we had before. but that's only
because i haven't written the code to reattach to old circuits. please
try to break it as-is, and then i'll make it reuse the same circuit and
we'll try to break that.
svn:r152
2003-01-26 10:02:24 +01:00
|
|
|
if(tmpconn == conn) {
|
|
|
|
printf("Conn %d has App-ward circuit: aci %d (other side %d), state %d (%s)\n",
|
|
|
|
conn->poll_index, circ->p_aci, circ->n_aci, circ->state, circuit_state_to_string[circ->state]);
|
|
|
|
}
|
2002-09-22 00:41:48 +02:00
|
|
|
}
|
2003-05-01 08:42:29 +02:00
|
|
|
for(tmpconn=circ->n_conn; tmpconn; tmpconn=tmpconn->next_stream) {
|
major overhaul: dns slave subsystem, topics
on startup, it forks off a master dns handler, which forks off dns
slaves (like the apache model). slaves as spawned as load increases,
and then reused. excess slaves are not ever killed, currently.
implemented topics. each topic has a receive window in each direction
at each edge of the circuit, and sends sendme's at the data level, as
per before. each circuit also has receive windows in each direction at
each hop; an edge sends a circuit-level sendme as soon as enough data
cells have arrived (regardless of whether the data cells were flushed
to the exit conns). removed the 'connected' cell type, since it's now
a topic command within data cells.
at the edge of the circuit, there can be multiple connections associated
with a single circuit. you find them via the linked list conn->next_topic.
currently each new ap connection starts its own circuit, so we ought
to see comparable performance to what we had before. but that's only
because i haven't written the code to reattach to old circuits. please
try to break it as-is, and then i'll make it reuse the same circuit and
we'll try to break that.
svn:r152
2003-01-26 10:02:24 +01:00
|
|
|
if(tmpconn == conn) {
|
|
|
|
printf("Conn %d has Exit-ward circuit: aci %d (other side %d), state %d (%s)\n",
|
|
|
|
conn->poll_index, circ->n_aci, circ->p_aci, circ->state, circuit_state_to_string[circ->state]);
|
|
|
|
}
|
2002-09-22 00:41:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-04-16 08:18:31 +02:00
|
|
|
void circuit_expire_unused_circuits(void) {
|
|
|
|
circuit_t *circ, *tmpcirc;
|
|
|
|
circuit_t *youngest;
|
|
|
|
|
2003-05-02 00:55:51 +02:00
|
|
|
youngest = circuit_get_newest_ap();
|
2003-04-16 08:18:31 +02:00
|
|
|
|
|
|
|
circ = global_circuitlist;
|
|
|
|
while(circ) {
|
|
|
|
tmpcirc = circ;
|
|
|
|
circ = circ->next;
|
2003-04-18 20:47:49 +02:00
|
|
|
if(tmpcirc != youngest && !tmpcirc->p_conn) {
|
2003-04-16 08:18:31 +02:00
|
|
|
log(LOG_DEBUG,"circuit_expire_unused_circuits(): Closing n_aci %d",tmpcirc->n_aci);
|
|
|
|
circuit_close(tmpcirc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* failure_status code: negative means reset failures to 0. Other values mean
|
|
|
|
* add that value to the current number of failures, then if we don't have too
|
|
|
|
* many failures on record, try to make a new circuit.
|
|
|
|
*/
|
|
|
|
void circuit_launch_new(int failure_status) {
|
|
|
|
static int failures=0;
|
|
|
|
|
2003-04-20 21:47:33 +02:00
|
|
|
if(!options.APPort) /* we're not an application proxy. no need for circuits. */
|
|
|
|
return;
|
|
|
|
|
2003-04-16 08:18:31 +02:00
|
|
|
if(failure_status == -1) { /* I was called because a circuit succeeded */
|
|
|
|
failures = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
failures += failure_status;
|
|
|
|
|
|
|
|
retry_circuit:
|
|
|
|
|
|
|
|
if(failures > 5) {
|
|
|
|
log(LOG_INFO,"circuit_launch_new(): Giving up, %d failures.", failures);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(circuit_create_onion() < 0) {
|
|
|
|
failures++;
|
|
|
|
goto retry_circuit;
|
|
|
|
}
|
|
|
|
|
|
|
|
failures = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int circuit_create_onion(void) {
|
|
|
|
int routelen; /* length of the route */
|
|
|
|
unsigned int *route; /* hops in the route as an array of indexes into rarray */
|
|
|
|
unsigned char *onion; /* holds the onion */
|
|
|
|
int onionlen; /* onion length in host order */
|
2003-05-02 00:55:51 +02:00
|
|
|
crypt_path_t *cpath; /* defines the crypt operations that need to be performed on incoming/outgoing data */
|
2003-04-16 08:18:31 +02:00
|
|
|
|
|
|
|
/* choose a route */
|
|
|
|
route = (unsigned int *)router_new_route(&routelen);
|
|
|
|
if (!route) {
|
|
|
|
log(LOG_ERR,"circuit_create_onion(): Error choosing a route through the OR network.");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
log(LOG_DEBUG,"circuit_create_onion(): Chosen a route of length %u : ",routelen);
|
|
|
|
|
|
|
|
/* create an onion and calculate crypto keys */
|
2003-05-02 00:55:51 +02:00
|
|
|
onion = router_create_onion(route,routelen,&onionlen, &cpath);
|
2003-04-16 08:18:31 +02:00
|
|
|
if (!onion) {
|
|
|
|
log(LOG_ERR,"circuit_create_onion(): Error creating an onion.");
|
|
|
|
free(route);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
log(LOG_DEBUG,"circuit_create_onion(): Created an onion of size %u bytes.",onionlen);
|
2003-05-02 00:55:51 +02:00
|
|
|
// log(LOG_DEBUG,"circuit_create_onion(): Crypt path :");
|
2003-04-16 08:18:31 +02:00
|
|
|
|
|
|
|
return circuit_establish_circuit(route, routelen, onion, onionlen, cpath);
|
|
|
|
}
|
|
|
|
|
|
|
|
int circuit_establish_circuit(unsigned int *route, int routelen, char *onion,
|
2003-05-02 00:55:51 +02:00
|
|
|
int onionlen, crypt_path_t *cpath) {
|
2003-04-16 08:18:31 +02:00
|
|
|
routerinfo_t *firsthop;
|
|
|
|
connection_t *n_conn;
|
|
|
|
circuit_t *circ;
|
|
|
|
|
|
|
|
/* now see if we're already connected to the first OR in 'route' */
|
|
|
|
firsthop = router_get_first_in_route(route, routelen);
|
|
|
|
assert(firsthop); /* should always be defined */
|
|
|
|
free(route); /* we don't need it anymore */
|
|
|
|
|
|
|
|
circ = circuit_new(0, NULL); /* sets circ->p_aci and circ->p_conn */
|
|
|
|
circ->state = CIRCUIT_STATE_OR_WAIT;
|
|
|
|
circ->onion = onion;
|
|
|
|
circ->onionlen = onionlen;
|
|
|
|
circ->cpath = cpath;
|
|
|
|
|
|
|
|
log(LOG_DEBUG,"circuit_establish_circuit(): Looking for firsthop '%s:%u'",
|
|
|
|
firsthop->address,firsthop->or_port);
|
|
|
|
n_conn = connection_twin_get_by_addr_port(firsthop->addr,firsthop->or_port);
|
|
|
|
if(!n_conn || n_conn->state != OR_CONN_STATE_OPEN) { /* not currently connected */
|
|
|
|
circ->n_addr = firsthop->addr;
|
|
|
|
circ->n_port = firsthop->or_port;
|
|
|
|
if(options.ORPort) { /* we would be connected if he were up. but he's not. */
|
|
|
|
log(LOG_DEBUG,"circuit_establish_circuit(): Route's firsthop isn't connected.");
|
|
|
|
circuit_close(circ);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!n_conn) { /* launch the connection */
|
|
|
|
n_conn = connection_or_connect_as_op(firsthop);
|
|
|
|
if(!n_conn) { /* connect failed, forget the whole thing */
|
|
|
|
log(LOG_DEBUG,"circuit_establish_circuit(): connect to firsthop failed. Closing.");
|
|
|
|
circuit_close(circ);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0; /* return success. The onion/circuit/etc will be taken care of automatically
|
|
|
|
* (may already have been) whenever n_conn reaches OR_CONN_STATE_OPEN.
|
|
|
|
*/
|
|
|
|
} else { /* it (or a twin) is already open. use it. */
|
|
|
|
circ->n_addr = n_conn->addr;
|
|
|
|
circ->n_port = n_conn->port;
|
|
|
|
return circuit_send_onion(n_conn, circ);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* find circuits that are waiting on me, if any, and get them to send the onion */
|
|
|
|
void circuit_n_conn_open(connection_t *or_conn) {
|
|
|
|
circuit_t *circ;
|
|
|
|
|
|
|
|
log(LOG_DEBUG,"circuit_n_conn_open(): Starting.");
|
|
|
|
circ = circuit_enumerate_by_naddr_nport(NULL, or_conn->addr, or_conn->port);
|
|
|
|
for(;;) {
|
|
|
|
if(!circ)
|
|
|
|
return;
|
|
|
|
|
|
|
|
log(LOG_DEBUG,"circuit_n_conn_open(): Found circ, sending onion.");
|
|
|
|
if(circuit_send_onion(or_conn, circ) < 0) {
|
|
|
|
log(LOG_DEBUG,"circuit_n_conn_open(): circuit marked for closing.");
|
|
|
|
circuit_close(circ);
|
|
|
|
return; /* FIXME will want to try the other circuits too? */
|
|
|
|
}
|
|
|
|
circ = circuit_enumerate_by_naddr_nport(circ, or_conn->addr, or_conn->port);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int circuit_send_onion(connection_t *n_conn, circuit_t *circ) {
|
|
|
|
cell_t cell;
|
|
|
|
int tmpbuflen, dataleft;
|
|
|
|
char *tmpbuf;
|
|
|
|
|
|
|
|
circ->n_aci = get_unique_aci_by_addr_port(circ->n_addr, circ->n_port, ACI_TYPE_BOTH);
|
|
|
|
circ->n_conn = n_conn;
|
|
|
|
log(LOG_DEBUG,"circuit_send_onion(): n_conn is %s:%u",n_conn->address,n_conn->port);
|
|
|
|
|
|
|
|
/* deliver the onion as one or more create cells */
|
|
|
|
cell.command = CELL_CREATE;
|
|
|
|
cell.aci = circ->n_aci;
|
|
|
|
|
|
|
|
tmpbuflen = circ->onionlen+4;
|
|
|
|
tmpbuf = malloc(tmpbuflen);
|
|
|
|
if(!tmpbuf)
|
|
|
|
return -1;
|
|
|
|
*(uint32_t*)tmpbuf = htonl(circ->onionlen);
|
|
|
|
memcpy(tmpbuf+4, circ->onion, circ->onionlen);
|
|
|
|
|
|
|
|
dataleft = tmpbuflen;
|
|
|
|
while(dataleft) {
|
|
|
|
cell.command = CELL_CREATE;
|
|
|
|
cell.aci = circ->n_aci;
|
|
|
|
log(LOG_DEBUG,"circuit_send_onion(): Sending a create cell for the onion...");
|
|
|
|
if(dataleft >= CELL_PAYLOAD_SIZE) {
|
|
|
|
cell.length = CELL_PAYLOAD_SIZE;
|
|
|
|
memcpy(cell.payload, tmpbuf + tmpbuflen - dataleft, CELL_PAYLOAD_SIZE);
|
|
|
|
connection_write_cell_to_buf(&cell, n_conn);
|
|
|
|
dataleft -= CELL_PAYLOAD_SIZE;
|
|
|
|
} else { /* last cell */
|
|
|
|
cell.length = dataleft;
|
|
|
|
memcpy(cell.payload, tmpbuf + tmpbuflen - dataleft, dataleft);
|
|
|
|
/* fill extra space with 0 bytes */
|
|
|
|
memset(cell.payload + dataleft, 0, CELL_PAYLOAD_SIZE - dataleft);
|
|
|
|
connection_write_cell_to_buf(&cell, n_conn);
|
|
|
|
dataleft = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(tmpbuf);
|
|
|
|
|
|
|
|
circ->state = CIRCUIT_STATE_OPEN;
|
|
|
|
/* FIXME should set circ->expire to something here */
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-04-07 04:12:02 +02:00
|
|
|
/*
|
|
|
|
Local Variables:
|
|
|
|
mode:c
|
|
|
|
indent-tabs-mode:nil
|
|
|
|
c-basic-offset:2
|
|
|
|
End:
|
|
|
|
*/
|