summaryrefslogtreecommitdiff
path: root/src/or/main.c
diff options
context:
space:
mode:
authorRoger Dingledine <arma@torproject.org>2003-04-16 06:18:31 +0000
committerRoger Dingledine <arma@torproject.org>2003-04-16 06:18:31 +0000
commite1d37ed6abffca3bab3f43794a850709f8c4fe77 (patch)
tree30e05af65785ade5a884855474d74e17c3085c1d /src/or/main.c
parent1fa0fc14876357b7f5d36696166d33dc1159b294 (diff)
downloadtor-e1d37ed6abffca3bab3f43794a850709f8c4fe77.tar.gz
tor-e1d37ed6abffca3bab3f43794a850709f8c4fe77.zip
divorce circuit building from user connections
now we rebuild the circuit periodically (but only if it's been used), and we can further abstract it to do incremental circuit building, etc. svn:r233
Diffstat (limited to 'src/or/main.c')
-rw-r--r--src/or/main.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/or/main.c b/src/or/main.c
index 4466036270..023836d4bf 100644
--- a/src/or/main.c
+++ b/src/or/main.c
@@ -302,8 +302,10 @@ int prepare_for_poll(int *timeout) {
struct timeval now; //soonest;
static long current_second = 0; /* from previous calls to gettimeofday */
static long time_to_fetch_directory = 0;
+ static long time_to_new_circuit = 0;
// int ms_until_conn;
cell_t cell;
+ circuit_t *circ;
if(gettimeofday(&now,NULL) < 0)
return -1;
@@ -321,6 +323,17 @@ int prepare_for_poll(int *timeout) {
}
}
+ if(options.APPort && time_to_new_circuit < now.tv_sec) {
+ circuit_expire_unused_circuits();
+ circuit_launch_new(-1); /* tell it to forget about previous failures */
+ circ = circuit_get_newest_by_edge_type(EDGE_AP);
+ if(!circ || circ->dirty) {
+ log(LOG_INFO,"prepare_for_poll(): Youngest circuit missing or dirty; launching replacement.");
+ circuit_launch_new(0); /* make an onion and lay the circuit */
+ }
+ time_to_new_circuit = now.tv_sec + options.NewCircuitPeriod;
+ }
+
/* do housekeeping for each connection */
for(i=0;i<nfds;i++) {
tmpconn = connection_array[i];
@@ -514,7 +527,7 @@ static void catch(int the_signal) {
}
}
-void dumpstats (void) { /* dump stats to stdout */
+void dumpstats(void) { /* dump stats to stdout */
int i;
connection_t *conn;
struct timeval now;
@@ -638,7 +651,7 @@ void dump_directory_to_string(char *s, int maxlen) {
}
-void daemonize() {
+void daemonize(void) {
/* Fork; parent exits. */
if (fork())
exit(0);