[or-cvs] When a client asks for an old-style directory and our write...
arma at seul.org
arma at seul.org
Sat Feb 11 23:15:42 UTC 2006
Update of /home2/or/cvsroot/tor/src/or
In directory moria:/home/arma/work/onion/cvs/tor/src/or
Modified Files:
connection.c directory.c or.h
Log Message:
When a client asks for an old-style directory and our write bucket
is empty, don't give it to him. This way small servers can continue
to serve the directory *sometimes*, without getting overloaded.
Index: connection.c
===================================================================
RCS file: /home2/or/cvsroot/tor/src/or/connection.c,v
retrieving revision 1.439
retrieving revision 1.440
diff -u -p -d -r1.439 -r1.440
--- connection.c 9 Feb 2006 05:46:48 -0000 1.439
+++ connection.c 11 Feb 2006 23:15:39 -0000 1.440
@@ -1036,6 +1036,13 @@ connection_bucket_write_limit(connection
return at_most;
}
+/** Return 1 if the global write bucket has no bytes in it,
+ * or return 0 if it does. */
+int global_write_bucket_empty(void)
+{
+ return global_write_bucket <= 0;
+}
+
/** We just read num_read onto conn. Decrement buckets appropriately. */
static void
connection_read_bucket_decrement(connection_t *conn, int num_read)
Index: directory.c
===================================================================
RCS file: /home2/or/cvsroot/tor/src/or/directory.c,v
retrieving revision 1.350
retrieving revision 1.351
diff -u -p -d -r1.350 -r1.351
--- directory.c 9 Feb 2006 05:46:48 -0000 1.350
+++ directory.c 11 Feb 2006 23:15:40 -0000 1.351
@@ -1387,10 +1387,6 @@ directory_handle_command_get(connection_
int deflated = !strcmp(url,"/tor/dir.z");
dlen = dirserv_get_directory(&cp, deflated);
- note_request(url, dlen);
-
- tor_free(url);
-
if (dlen == 0) {
notice(LD_DIRSERV,"Client asked for the mirrored directory, but we "
"don't have a good one yet. Sending 503 Dir not available.");
@@ -1398,9 +1394,21 @@ directory_handle_command_get(connection_
/* try to get a new one now */
if (!already_fetching_directory(DIR_PURPOSE_FETCH_DIR))
directory_get_from_dirserver(DIR_PURPOSE_FETCH_DIR, NULL, 1);
+ tor_free(url);
+ return 0;
+ }
+
+ if (global_write_bucket_empty()) {
+ info(LD_DIRSERV,
+ "Client asked for the mirrored directory, but we've been "
+ "writing too many bytes lately. Sending 503 Dir busy.");
+ write_http_status_line(conn, 503, "Directory busy, try again later");
+ tor_free(url);
return 0;
}
+ note_request(url, dlen);
+
debug(LD_DIRSERV,"Dumping %sdirectory to client.",
deflated?"deflated ":"");
format_rfc1123_time(date, time(NULL));
Index: or.h
===================================================================
RCS file: /home2/or/cvsroot/tor/src/or/or.h,v
retrieving revision 1.789
retrieving revision 1.790
diff -u -p -d -r1.789 -r1.790
--- or.h 9 Feb 2006 05:46:49 -0000 1.789
+++ or.h 11 Feb 2006 23:15:40 -0000 1.790
@@ -1635,6 +1635,7 @@ int retry_all_listeners(int force, smart
smartlist_t *new_conns);
int connection_bucket_write_limit(connection_t *conn);
+int global_write_bucket_empty(void);
void connection_bucket_init(void);
void connection_bucket_refill(struct timeval *now);
More information about the tor-commits
mailing list