[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] tor now tolerates down dirservers better
Update of /home/or/cvsroot/src/or
In directory moria.mit.edu:/home2/arma/work/onion/cvs/src/or
Modified Files:
connection.c directory.c or.h routerlist.c
Log Message:
tor now tolerates down dirservers better
Index: connection.c
===================================================================
RCS file: /home/or/cvsroot/src/or/connection.c,v
retrieving revision 1.236
retrieving revision 1.237
diff -u -d -r1.236 -r1.237
--- connection.c 12 Jul 2004 18:19:55 -0000 1.236
+++ connection.c 12 Jul 2004 20:39:40 -0000 1.237
@@ -709,16 +709,20 @@
}
if(connection_read_to_buf(conn) < 0) {
+ /* There's a read error; kill the connection.*/
+ connection_close_immediate(conn); /* Don't flush; connection is dead. */
+ conn->has_sent_end = 1;
+ connection_mark_for_close(conn);
if(conn->type == CONN_TYPE_DIR &&
conn->state == DIR_CONN_STATE_CONNECTING) {
/* it's a directory server and connecting failed: forget about this router */
/* XXX I suspect pollerr may make Windows not get to this point. :( */
router_mark_as_down(conn->identity_digest);
+ if(conn->purpose == DIR_PURPOSE_FETCH_DIR && !all_directory_servers_down()) {
+ log_fn(LOG_INFO,"Giving up on dirserver %s; trying another.", conn->nickname);
+ directory_get_from_dirserver(DIR_PURPOSE_FETCH_DIR, NULL, 0);
+ }
}
- /* There's a read error; kill the connection.*/
- connection_close_immediate(conn); /* Don't flush; connection is dead. */
- conn->has_sent_end = 1;
- connection_mark_for_close(conn);
return -1;
}
if(connection_process_inbuf(conn) < 0) {
Index: directory.c
===================================================================
RCS file: /home/or/cvsroot/src/or/directory.c,v
retrieving revision 1.113
retrieving revision 1.114
diff -u -d -r1.113 -r1.114
--- directory.c 2 Jul 2004 23:40:03 -0000 1.113
+++ directory.c 12 Jul 2004 20:39:40 -0000 1.114
@@ -150,6 +150,10 @@
switch(connection_connect(conn, conn->address, conn->addr, conn->port)) {
case -1:
router_mark_as_down(conn->identity_digest); /* don't try him again */
+ if(purpose == DIR_PURPOSE_FETCH_DIR && !all_directory_servers_down) {
+ log_fn(LOG_INFO,"Giving up on dirserver %s; trying another.", conn->nickname);
+ directory_get_from_dirserver(purpose, payload, payload_len);
+ }
connection_free(conn);
return;
case 1:
Index: or.h
===================================================================
RCS file: /home/or/cvsroot/src/or/or.h,v
retrieving revision 1.376
retrieving revision 1.377
diff -u -d -r1.376 -r1.377
--- or.h 12 Jul 2004 18:02:54 -0000 1.376
+++ or.h 12 Jul 2004 20:39:40 -0000 1.377
@@ -1348,6 +1348,7 @@
/********************************* routerlist.c ***************************/
routerinfo_t *router_pick_directory_server(void);
+int all_directory_servers_down(void);
struct smartlist_t;
void add_nickname_list_to_smartlist(struct smartlist_t *sl, const char *list);
void router_add_running_routers_to_smartlist(struct smartlist_t *sl);
Index: routerlist.c
===================================================================
RCS file: /home/or/cvsroot/src/or/routerlist.c,v
retrieving revision 1.95
retrieving revision 1.96
diff -u -d -r1.95 -r1.96
--- routerlist.c 12 Jul 2004 18:19:55 -0000 1.95
+++ routerlist.c 12 Jul 2004 20:39:40 -0000 1.96
@@ -62,7 +62,7 @@
* routerlist. */
static routerinfo_t *router_pick_directory_server_impl(void) {
int i;
- routerinfo_t *router, *dirserver=NULL;
+ routerinfo_t *router;
smartlist_t *sl;
if(!routerlist)
@@ -87,17 +87,38 @@
/* No running dir servers found? go through and mark them all as up,
* so we cycle through the list again. */
+ sl = smartlist_create();
for(i=0; i < smartlist_len(routerlist->routers); i++) {
router = smartlist_get(routerlist->routers, i);
if(router->is_trusted_dir) {
tor_assert(router->dir_port > 0);
router->is_running = 1;
- dirserver = router;
+ smartlist_add(sl, router);
}
}
- if(!dirserver)
+ router = smartlist_choose(sl);
+ smartlist_free(sl);
+ if(!router)
log_fn(LOG_WARN,"No dirservers in directory! Returning NULL.");
- return dirserver;
+ return router;
+}
+
+/** Return 0 if \exists an authoritative dirserver that's currently
+ * thought to be running, else return 1.
+ */
+int all_directory_servers_down(void) {
+ int i;
+ routerinfo_t *router;
+ if(!routerlist)
+ return 1; /* if no dirservers, I guess they're all down */
+ for(i=0;i< smartlist_len(routerlist->routers); i++) {
+ router = smartlist_get(routerlist->routers, i);
+ if(router->is_running && router->is_trusted_dir) {
+ tor_assert(router->dir_port > 0);
+ return 0;
+ }
+ }
+ return 1;
}
/** Given a comma-and-whitespace separated list of nicknames, see which