[or-cvs] clean up some file-scope-global directory variables
Roger Dingledine
arma at seul.org
Sun Dec 14 05:25:25 UTC 2003
Update of /home/or/cvsroot/src/or
In directory moria.mit.edu:/home2/arma/work/onion/cvs/src/or
Modified Files:
directory.c dirserv.c
Log Message:
clean up some file-scope-global directory variables
Index: directory.c
===================================================================
RCS file: /home/or/cvsroot/src/or/directory.c,v
retrieving revision 1.52
retrieving revision 1.53
diff -u -d -r1.52 -r1.53
--- directory.c 13 Dec 2003 22:52:27 -0000 1.52
+++ directory.c 14 Dec 2003 05:25:23 -0000 1.53
@@ -13,10 +13,6 @@
static char fetchstring[] = "GET / HTTP/1.0\r\n\r\n";
static char answerstring[] = "HTTP/1.0 200 OK\r\n\r\n";
-/* XXX the_directory is the same name as a different variable in·
- * dirserv.c, are you crazy?? */
-static char the_directory[MAX_DIR_SIZE+1];
-static int directorylen=0;
/********* END VARIABLES ************/
@@ -98,15 +94,17 @@
}
int connection_dir_process_inbuf(connection_t *conn) {
+ char directory[MAX_DIR_SIZE+1];
+ int directorylen=0;
assert(conn && conn->type == CONN_TYPE_DIR);
if(conn->inbuf_reached_eof) {
switch(conn->state) {
case DIR_CONN_STATE_CLIENT_READING_FETCH:
- /* kill it, but first process the_directory and learn about new routers. */
+ /* kill it, but first fetch/process the directory to learn about new routers. */
switch(fetch_from_buf_http(conn->inbuf,
- NULL, 0, the_directory, MAX_DIR_SIZE)) {
+ NULL, 0, directory, MAX_DIR_SIZE)) {
case -1: /* overflow */
log_fn(LOG_WARN,"'fetch' response too large. Failing.");
return -1;
@@ -116,13 +114,13 @@
/* case 1, fall through */
}
/* XXX check headers, at least make sure returned 2xx */
- directorylen = strlen(the_directory);
- log_fn(LOG_INFO,"Received directory (size %d):\n%s", directorylen, the_directory);
+ directorylen = strlen(directory);
+ log_fn(LOG_INFO,"Received directory (size %d):\n%s", directorylen, directory);
if(directorylen == 0) {
log_fn(LOG_INFO,"Empty directory. Ignoring.");
return -1;
}
- if(router_set_routerlist_from_directory(the_directory, conn->identity_pkey) < 0){
+ if(router_set_routerlist_from_directory(directory, conn->identity_pkey) < 0){
log_fn(LOG_INFO,"...but parsing failed. Ignoring.");
} else {
log_fn(LOG_INFO,"updated routers.");
Index: dirserv.c
===================================================================
RCS file: /home/or/cvsroot/src/or/dirserv.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- dirserv.c 13 Dec 2003 22:52:27 -0000 1.20
+++ dirserv.c 14 Dec 2003 05:25:23 -0000 1.21
@@ -10,10 +10,6 @@
extern or_options_t options; /* command-line and config-file options */
static int the_directory_is_dirty = 1;
-/* XXX the_directory is the same name as a different variable in
- * directory.c, are you crazy?? */
-static char *the_directory = NULL;
-static int the_directory_len = -1;
static int list_running_servers(char **nicknames_out);
@@ -108,7 +104,7 @@
free(fingerprint_list_tmp[i].fingerprint);
}
return -1;
-}
+}
/* return 1 if router's identity and nickname match,
* -1 if they don't match, 0 if the nickname is not known. */
@@ -272,7 +268,7 @@
desc_ent_ptr = &descriptor_list[n_descriptors++];
/* XXX check if n_descriptors is too big */
}
-
+
(*desc_ent_ptr) = tor_malloc(sizeof(descriptor_entry_t));
(*desc_ent_ptr)->nickname = tor_strdup(ri->nickname);
(*desc_ent_ptr)->published = ri->published_on;
@@ -281,8 +277,8 @@
strncpy((*desc_ent_ptr)->descriptor, start, desc_len);
(*desc_ent_ptr)->descriptor[desc_len] = '\0';
*desc = end;
- the_directory_is_dirty = 1;
-
+ directory_set_dirty();
+
routerinfo_free(ri);
return 0;
err:
@@ -378,7 +374,7 @@
free(cp);
i = strlen(s);
cp = s+i;
-
+
for (i = 0; i < n_descriptors; ++i) {
strncat(cp, descriptor_list[i]->descriptor, descriptor_list[i]->desc_len);
cp += descriptor_list[i]->desc_len;
@@ -391,7 +387,7 @@
strncat(s, "directory-signature\n", maxlen-i);
i = strlen(s);
cp = s + i;
-
+
if (router_get_dir_hash(s,digest)) {
log_fn(LOG_WARN,"couldn't compute digest");
return -1;
@@ -403,10 +399,10 @@
log(LOG_DEBUG,"generated directory digest begins with %02x:%02x:%02x:%02x",
((int)digest[0])&0xff,((int)digest[1])&0xff,
((int)digest[2])&0xff,((int)digest[3])&0xff);
-
+
strncpy(cp,
"-----BEGIN SIGNATURE-----\n", maxlen-i);
-
+
i = strlen(s);
cp = s+i;
if (base64_encode(cp, maxlen-i, signature, 128) < 0) {
@@ -426,6 +422,9 @@
return 0;
}
+static char *the_directory = NULL;
+static int the_directory_len = -1;
+
size_t dirserv_get_directory(const char **directory)
{
char *new_directory;
More information about the tor-commits
mailing list