[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] mark all dirservers up at boot; mark a dirserver down if di...



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 routers.c 
Log Message:
mark all dirservers up at boot; mark a dirserver down if dir fetch fails


Index: connection.c
===================================================================
RCS file: /home/or/cvsroot/src/or/connection.c,v
retrieving revision 1.112
retrieving revision 1.113
diff -u -d -r1.112 -r1.113
--- connection.c	30 Sep 2003 19:25:16 -0000	1.112
+++ connection.c	30 Sep 2003 21:27:16 -0000	1.113
@@ -329,13 +329,12 @@
        conn->state == DIR_CONN_STATE_CONNECTING_UPLOAD)) {
        /* 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_forget_router(conn->addr,conn->port); 
-         /* FIXME i don't think router_forget_router works. */
+       router_mark_as_down(conn->nickname);
     }
     return -1;
   }
   if(connection_process_inbuf(conn) < 0) {
-    //log_fn(LOG_DEBUG,"connection_process_inbuf returned %d.",retval);
+//    log_fn(LOG_DEBUG,"connection_process_inbuf returned -1.");
     return -1;
   }
   return 0;

Index: directory.c
===================================================================
RCS file: /home/or/cvsroot/src/or/directory.c,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -d -r1.40 -r1.41
--- directory.c	30 Sep 2003 08:18:08 -0000	1.40
+++ directory.c	30 Sep 2003 21:27:16 -0000	1.41
@@ -21,8 +21,11 @@
 void directory_initiate_command(routerinfo_t *router, int command) {
   connection_t *conn;
 
-  if(!router) /* i guess they didn't have one in mind for me to use */
+  if(!router) { /* i guess they didn't have one in mind for me to use */
+    log_fn(LOG_WARNING,"No running dirservers known. This is really bad.");
+    /* XXX never again will a directory fetch work. Should we exit here, or what? */
     return;
+  }
 
 #if 0 /* there's no problem with parallel get/posts now. whichever 'get' ends
          last is the directory. */
@@ -43,6 +46,7 @@
   conn->addr = router->addr;
   conn->port = router->dir_port;
   conn->address = strdup(router->address);
+  conn->nickname = strdup(router->nickname);
   if (router->identity_pkey)
     conn->identity_pkey = crypto_pk_dup_key(router->identity_pkey);
   else {
@@ -58,7 +62,7 @@
 
   switch(connection_connect(conn, router->address, router->addr, router->dir_port)) {
     case -1:
-      router_forget_router(conn->addr, conn->port); /* XXX don't try him again */
+      router_mark_as_down(conn->nickname); /* don't try him again */
       connection_free(conn);
       return;
     case 0:
@@ -237,7 +241,7 @@
       if (getsockopt(conn->s, SOL_SOCKET, SO_ERROR, (void*)&e, &len) < 0)  { /* not yet */
         if(!ERRNO_CONN_EINPROGRESS(errno)) {
           log_fn(LOG_DEBUG,"in-progress connect failed. Removing.");
-          router_forget_router(conn->addr, conn->port); /* don't try him again */
+          router_mark_as_down(conn->nickname); /* don't try him again */
           return -1;
         } else {
           return 0; /* no change, see if next time is better */

Index: or.h
===================================================================
RCS file: /home/or/cvsroot/src/or/or.h,v
retrieving revision 1.148
retrieving revision 1.149
diff -u -d -r1.148 -r1.149
--- or.h	30 Sep 2003 19:27:54 -0000	1.148
+++ or.h	30 Sep 2003 21:27:16 -0000	1.149
@@ -671,12 +671,10 @@
 void router_upload_desc_to_dirservers(void);
 routerinfo_t *router_get_by_addr_port(uint32_t addr, uint16_t port);
 routerinfo_t *router_get_by_link_pk(crypto_pk_env_t *pk);
-#if 0
-routerinfo_t *router_get_by_identity_pk(crypto_pk_env_t *pk);
-#endif
+routerinfo_t *router_get_by_nickname(char *nickname);
 void router_get_directory(directory_t **pdirectory);
 int router_is_me(uint32_t addr, uint16_t port);
-void router_forget_router(uint32_t addr, uint16_t port);
+void router_mark_as_down(char *nickname);
 int router_get_list_from_file(char *routerfile);
 int router_get_router_hash(char *s, char *digest);
 int router_get_dir_hash(char *s, char *digest);

Index: routers.c
===================================================================
RCS file: /home/or/cvsroot/src/or/routers.c,v
retrieving revision 1.62
retrieving revision 1.63
diff -u -d -r1.62 -r1.63
--- routers.c	30 Sep 2003 20:36:20 -0000	1.62
+++ routers.c	30 Sep 2003 21:27:16 -0000	1.63
@@ -90,7 +90,7 @@
 }
 
 routerinfo_t *router_pick_directory_server(void) {
-  /* currently, pick the first router with a positive dir_port */
+  /* pick the first running router with a positive dir_port */
   int i;
   routerinfo_t *router;
   
@@ -99,7 +99,7 @@
 
   for(i=0;i<directory->n_routers;i++) {
     router = directory->routers[i];
-    if(router->dir_port > 0)
+    if(router->dir_port > 0 && router->is_running)
       return router;
   }
 
@@ -131,7 +131,6 @@
     if ((router->addr == addr) && (router->or_port == port))
       return router;
   }
-
   return NULL;
 }
 
@@ -147,12 +146,10 @@
     if (0 == crypto_pk_cmp_keys(router->link_pkey, pk))
       return router;
   }
-  
   return NULL;
 }
 
-#if 0 
-routerinfo_t *router_get_by_identity_pk(crypto_pk_env_t *pk) 
+routerinfo_t *router_get_by_nickname(char *nickname)
 {
   int i;
   routerinfo_t *router;
@@ -161,14 +158,11 @@
 
   for(i=0;i<directory->n_routers;i++) {
     router = directory->routers[i];
-    /* XXX Should this really be a separate link key? */
-    if (0 == crypto_pk_cmp_keys(router->identity_pkey, pk))
+    if (0 == strcmp(router->nickname, nickname))
       return router;
   }
-  
   return NULL;
 }
-#endif
 
 void router_get_directory(directory_t **pdirectory) {
   *pdirectory = directory;
@@ -238,27 +232,12 @@
   free(directory);
 }
 
-void router_forget_router(uint32_t addr, uint16_t port) {
-  int i;
-  routerinfo_t *router;
-
-  router = router_get_by_addr_port(addr,port);
+void router_mark_as_down(char *nickname) {
+  routerinfo_t *router = router_get_by_nickname(nickname);
   if(!router) /* we don't seem to know about him in the first place */
     return;
-
-  /* now walk down router_array until we get to router */
-  for(i=0;i<directory->n_routers;i++)
-    if(directory->routers[i] == router)
-      break;
-
-  assert(i != directory->n_routers); /* if so then router_get_by_addr_port should have returned null */
-
-//  free(router); /* don't actually free; we'll free it when we free the whole thing */
-
-//  log(LOG_DEBUG,"router_forget_router(): Forgot about router %d:%d",addr,port);
-  for(; i<directory->n_routers-1;i++)
-    directory->routers[i] = directory->routers[i+1];
-  /* XXX bug, we're not decrementing n_routers here? needs more attention. -RD */
+  log_fn(LOG_DEBUG,"Marking %s as down.",router->nickname);
+  router->is_running = 0;
 }
 
 /* load the router list */
@@ -769,6 +748,8 @@
           break;
         }
       }
+    } else {
+      router->is_running = 1; /* start out assuming all dirservers are up */
     }
     rarray[rarray_len++] = router;
     log_fn(LOG_DEBUG,"just added router #%d.",rarray_len);