aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRoger Dingledine <arma@torproject.org>2003-09-28 06:48:20 +0000
committerRoger Dingledine <arma@torproject.org>2003-09-28 06:48:20 +0000
commitc4c66e2c7f1184336d5a9997d049ba4e28137c39 (patch)
tree662e8507c686a12e82050fb6ccece837bcab43f5 /src
parent677707433e562eec675d5e6e487a008364ebea5b (diff)
downloadtor-c4c66e2c7f1184336d5a9997d049ba4e28137c39.tar
tor-c4c66e2c7f1184336d5a9997d049ba4e28137c39.tar.gz
expand the scheduler to address SSL_read()'s pending bytes
svn:r505
Diffstat (limited to 'src')
-rw-r--r--src/or/connection.c5
-rw-r--r--src/or/main.c27
-rw-r--r--src/or/routers.c34
3 files changed, 23 insertions, 43 deletions
diff --git a/src/or/connection.c b/src/or/connection.c
index 20522b848..5c97142e4 100644
--- a/src/or/connection.c
+++ b/src/or/connection.c
@@ -25,7 +25,7 @@ char *conn_type_to_string[] = {
"CPU worker", /* 11 */
};
-char *conn_state_to_string[][15] = {
+char *conn_state_to_string[][_CONN_TYPE_MAX+1] = {
{ NULL }, /* no type associated with 0 */
{ "ready" }, /* op listener, 0 */
{ "awaiting keys", /* op, 0 */
@@ -509,9 +509,6 @@ int connection_read_to_buf(connection_t *conn) {
return 0;
}
}
- if(connection_speaks_cells(conn) && conn->state != OR_CONN_STATE_CONNECTING)
- if(result == at_most)
- return connection_read_to_buf(conn);
return 0;
}
diff --git a/src/or/main.c b/src/or/main.c
index 5421c96ea..9f861b96c 100644
--- a/src/or/main.c
+++ b/src/or/main.c
@@ -261,14 +261,17 @@ void connection_start_writing(connection_t *conn) {
}
static void conn_read(int i) {
- connection_t *conn;
+ connection_t *conn = connection_array[i];
+ /* see http://www.greenend.org.uk/rjk/2001/06/poll.html for
+ * discussion of POLLIN vs POLLHUP */
if(!(poll_array[i].revents & (POLLIN|POLLHUP|POLLERR)))
- return; /* this conn doesn't want to read */
- /* see http://www.greenend.org.uk/rjk/2001/06/poll.html for
- * discussion of POLLIN vs POLLHUP */
+ if(!connection_speaks_cells(conn) ||
+ conn->state != OR_CONN_STATE_OPEN ||
+ !connection_is_reading(conn) ||
+ !tor_tls_get_pending_bytes(conn->tls))
+ return; /* this conn should not read */
- conn = connection_array[i];
log_fn(LOG_DEBUG,"socket %d wants to read.",conn->s);
assert_connection_ok(conn, time(NULL));
@@ -340,8 +343,9 @@ static void check_conn_marked(int i) {
static int prepare_for_poll(void) {
int i;
+ int timeout;
connection_t *conn;
- struct timeval now; //soonest;
+ struct timeval now;
static long current_second = 0; /* from previous calls to gettimeofday */
static long time_to_fetch_directory = 0;
static long time_to_new_circuit = 0;
@@ -350,6 +354,7 @@ static int prepare_for_poll(void) {
circuit_t *circ;
my_gettimeofday(&now);
+ timeout = (1000 - (now.tv_usec / 1000)); /* how many milliseconds til the next second? */
if(now.tv_sec > current_second) { /* the second has rolled over. check more stuff. */
@@ -404,6 +409,8 @@ static int prepare_for_poll(void) {
/* check connections to see whether we should send a keepalive, expire, or wait */
if(!connection_speaks_cells(conn))
continue; /* this conn type doesn't send cells */
+ if(connection_state_is_open(conn) && tor_tls_get_pending_bytes(conn->tls))
+ timeout = 0; /* has pending bytes to read; don't let poll wait. */
if(now.tv_sec >= conn->timestamp_lastwritten + options.KeepalivePeriod) {
if((!options.OnionRouter && !circuit_get_by_conn(conn)) ||
(!connection_state_is_open(conn))) {
@@ -423,7 +430,8 @@ static int prepare_for_poll(void) {
}
}
/* blow away any connections that need to die. can't do this later
- * because we might open up a circuit and not realize it we're about to cull it.
+ * because we might open up a circuit and not realize we're about to cull
+ * the connection it's running over.
*/
for(i=0;i<nfds;i++)
check_conn_marked(i);
@@ -431,7 +439,7 @@ static int prepare_for_poll(void) {
current_second = now.tv_sec; /* remember which second it is, for next time */
}
- return (1000 - (now.tv_usec / 1000)); /* how many milliseconds til the next second? */
+ return timeout;
}
static crypto_pk_env_t *init_key_from_file(const char *fname)
@@ -828,6 +836,7 @@ list_running_servers(char **nicknames_out)
length += strlen(nickname_lst[i]);
}
*nicknames_out = tor_malloc(length);
+ log_fn(LOG_DEBUG,"total length %d malloced.",length);
cp = *nicknames_out;
for (i = 0; i<n; ++i) {
if (i)
@@ -835,6 +844,8 @@ list_running_servers(char **nicknames_out)
strcat(cp, nickname_lst[i]);
while (*cp)
++cp;
+ log_fn(LOG_DEBUG,"end of loop %d, now %d written (nick %s)",
+ i,1+(int)(cp-*nicknames_out),nickname_lst[i]);
}
return 0;
}
diff --git a/src/or/routers.c b/src/or/routers.c
index 9c43cdde3..e8995a854 100644
--- a/src/or/routers.c
+++ b/src/or/routers.c
@@ -260,42 +260,14 @@ void router_forget_router(uint32_t addr, uint16_t port) {
/* load the router list */
int router_get_list_from_file(char *routerfile)
{
- int fd; /* router file */
- struct stat statbuf;
char *string;
- assert(routerfile);
-
- if (strcspn(routerfile,CONFIG_LEGAL_FILENAME_CHARACTERS) != 0) {
- log_fn(LOG_WARNING,"Filename %s contains illegal characters.",routerfile);
+ string = read_file_to_str(routerfile);
+ if(!string) {
+ log_fn(LOG_WARNING,"Failed to load routerfile %s.",routerfile);
return -1;
}
- if(stat(routerfile, &statbuf) < 0) {
- log_fn(LOG_WARNING,"Could not stat %s.",routerfile);
- return -1;
- }
-
- /* open the router list */
- fd = open(routerfile,O_RDONLY,0);
- if (fd<0) {
- log_fn(LOG_WARNING,"Could not open %s.",routerfile);
- return -1;
- }
-
- string = tor_malloc(statbuf.st_size+1);
-
- if(read(fd,string,statbuf.st_size) != statbuf.st_size) {
- log_fn(LOG_WARNING,"Couldn't read all %ld bytes of file '%s'.",
- (long)statbuf.st_size,routerfile);
- free(string);
- close(fd);
- return -1;
- }
- close(fd);
-
- string[statbuf.st_size] = 0; /* null terminate it */
-
if(router_get_list_from_string(string) < 0) {
log_fn(LOG_WARNING,"The routerfile itself was corrupt.");
free(string);