[or-cvs] router->is_trusted_dir implies router->dir_port>0

Roger Dingledine arma at seul.org
Wed Jun 16 21:08:32 UTC 2004


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 or.h router.c routerlist.c 
Log Message:
router->is_trusted_dir implies router->dir_port>0
and add some infrastructure for fetching running-routers list


Index: directory.c
===================================================================
RCS file: /home/or/cvsroot/src/or/directory.c,v
retrieving revision 1.108
retrieving revision 1.109
diff -u -d -r1.108 -r1.109
--- directory.c	2 Jun 2004 20:00:57 -0000	1.108
+++ directory.c	16 Jun 2004 21:08:29 -0000	1.109
@@ -66,7 +66,7 @@
 
   for(i=0; i < smartlist_len(rl->routers); i++) {
     router = smartlist_get(rl->routers, i);
-    if(router->dir_port > 0)
+    if(router->is_trusted_dir)
       directory_initiate_command(router, purpose, payload, payload_len);
   }
 }
@@ -123,6 +123,8 @@
     return;
   }
 
+  tor_assert(router->dir_port);
+
   conn = connection_new(CONN_TYPE_DIR);
 
   /* set up conn so it's got all the data we need to remember */
@@ -183,7 +185,8 @@
  */
 static void directory_send_command(connection_t *conn, int purpose,
                                    const char *payload, int payload_len) {
-  char fetchstring[] = "GET / HTTP/1.0\r\n\r\n";
+  char fetchwholedir[] = "GET / HTTP/1.0\r\n\r\n";
+  char fetchrunninglist[] = "GET /running-routers HTTP/1.0\r\n\r\n";
   char tmp[8192];
 
   tor_assert(conn && conn->type == CONN_TYPE_DIR);
@@ -191,7 +194,11 @@
   switch(purpose) {
     case DIR_PURPOSE_FETCH_DIR:
       tor_assert(payload == NULL);
-      connection_write_to_buf(fetchstring, strlen(fetchstring), conn);
+      connection_write_to_buf(fetchwholedir, strlen(fetchwholedir), conn);
+      break;
+    case DIR_PURPOSE_FETCH_RUNNING_LIST:
+      tor_assert(payload == NULL);
+      connection_write_to_buf(fetchrunninglist, strlen(fetchrunninglist), conn);
       break;
     case DIR_PURPOSE_UPLOAD_DIR:
       tor_assert(payload);
@@ -344,6 +351,19 @@
       directory_has_arrived(); /* do things we've been waiting to do */
     }
 
+    if(conn->purpose == DIR_PURPOSE_FETCH_RUNNING_LIST) {
+      /* just update our list of running routers, if this list is new info */
+      log_fn(LOG_INFO,"Received running-routers list (size %d):\n%s", body_len, body);
+      if(status_code != 200) {
+        log_fn(LOG_WARN,"Received http status code %d from dirserver. Failing.",
+               status_code);
+        free(body); free(headers);
+        connection_mark_for_close(conn);
+        return -1;
+      }
+      /* XXX008 hand 'body' to something that parses a running-routers list. */
+    }
+
     if(conn->purpose == DIR_PURPOSE_UPLOAD_DIR) {
       switch(status_code) {
         case 200:
@@ -466,6 +486,16 @@
     return 0;
   }
 
+  if(!strcmp(url,"/running-routers")) { /* running-routers fetch */
+    dlen = dirserv_get_runningrouters(&cp);
+
+    snprintf(tmp, sizeof(tmp), "HTTP/1.0 200 OK\r\nContent-Length: %d\r\nContent-Type: text/plain\r\n\r\n",
+             (int)dlen);
+    connection_write_to_buf(tmp, strlen(tmp), conn);
+    connection_write_to_buf(cp, strlen(cp), conn);
+    return 0;
+  }
+
   if(!strncmp(url,rend_fetch_url,strlen(rend_fetch_url))) {
     /* rendezvous descriptor fetch */
     const char *descp;

Index: dirserv.c
===================================================================
RCS file: /home/or/cvsroot/src/or/dirserv.c,v
retrieving revision 1.52
retrieving revision 1.53
diff -u -d -r1.52 -r1.53
--- dirserv.c	20 May 2004 05:10:30 -0000	1.52
+++ dirserv.c	16 Jun 2004 21:08:29 -0000	1.53
@@ -618,6 +618,14 @@
   return the_directory_len;
 }
 
+/** Set *<b>rr</b> to the most recently generated encoded signed
+ * running-routers list, generating a new one as necessary. */
+size_t dirserv_get_runningrouters(const char **rr)
+{
+  /* XXX008 fill in this function */
+  return 0;
+}
+
 /*
   Local Variables:
   mode:c

Index: or.h
===================================================================
RCS file: /home/or/cvsroot/src/or/or.h,v
retrieving revision 1.367
retrieving revision 1.368
diff -u -d -r1.367 -r1.368
--- or.h	16 Jun 2004 00:49:27 -0000	1.367
+++ or.h	16 Jun 2004 21:08:29 -0000	1.368
@@ -241,20 +241,23 @@
 #define _DIR_PURPOSE_MIN 1
 /** Purpose for connection to directory server: download a directory. */
 #define DIR_PURPOSE_FETCH_DIR 1
+/** Purpose for connection to directory server: download just the list
+ * of running routers. */
+#define DIR_PURPOSE_FETCH_RUNNING_LIST 2
 /** Purpose for connection to directory server: download a rendezvous
  * descriptor. */
-#define DIR_PURPOSE_FETCH_RENDDESC 2
+#define DIR_PURPOSE_FETCH_RENDDESC 3
 /** Purpose for connection to directory server: set after a rendezvous
  * descriptor is downloaded. */
-#define DIR_PURPOSE_HAS_FETCHED_RENDDESC 3
+#define DIR_PURPOSE_HAS_FETCHED_RENDDESC 4
 /** Purpose for connection to directory server: upload a server descriptor. */
-#define DIR_PURPOSE_UPLOAD_DIR 4
+#define DIR_PURPOSE_UPLOAD_DIR 5
 /** Purpose for connection to directory server: upload a rendezvous
  * descriptor. */
-#define DIR_PURPOSE_UPLOAD_RENDDESC 5
+#define DIR_PURPOSE_UPLOAD_RENDDESC 6
 /** Purpose for connection at a directory server. */
-#define DIR_PURPOSE_SERVER 6
-#define _DIR_PURPOSE_MAX 6
+#define DIR_PURPOSE_SERVER 7
+#define _DIR_PURPOSE_MAX 7
 
 /** Circuit state: I'm the OP, still haven't done all my handshakes. */
 #define CIRCUIT_STATE_BUILDING 0
@@ -1107,11 +1110,12 @@
 int dirserv_add_descriptor(const char **desc);
 int dirserv_init_from_directory_string(const char *dir);
 void dirserv_free_descriptors();
+void dirserv_remove_old_servers(void);
 int dirserv_dump_directory_to_string(char *s, unsigned int maxlen,
                                      crypto_pk_env_t *private_key);
 void directory_set_dirty(void);
 size_t dirserv_get_directory(const char **cp);
-void dirserv_remove_old_servers(void);
+size_t dirserv_get_runningrouters(const char **rr);
 
 /********************************* dns.c ***************************/
 

Index: router.c
===================================================================
RCS file: /home/or/cvsroot/src/or/router.c,v
retrieving revision 1.47
retrieving revision 1.48
diff -u -d -r1.47 -r1.48
--- router.c	5 Jun 2004 01:56:54 -0000	1.47
+++ router.c	16 Jun 2004 21:08:29 -0000	1.48
@@ -533,6 +533,7 @@
     router->or_port,
     router->socks_port,
     router->dir_port,
+    /* XXX008 only use dir_port here if authoritative server, else use opt line below */
     router->platform,
     published,
     (int) router->bandwidthrate,

Index: routerlist.c
===================================================================
RCS file: /home/or/cvsroot/src/or/routerlist.c,v
retrieving revision 1.84
retrieving revision 1.85
diff -u -d -r1.84 -r1.85
--- routerlist.c	2 Jun 2004 20:00:57 -0000	1.84
+++ routerlist.c	16 Jun 2004 21:08:29 -0000	1.85
@@ -58,7 +58,7 @@
   return choice;
 }
 
-/** Pick a random running router with a positive dir_port from our
+/** Pick a random running router that's a trusted dirserver from our
  * routerlist. */
 static routerinfo_t *router_pick_directory_server_impl(void) {
   int i;
@@ -72,8 +72,10 @@
   sl = smartlist_create();
   for(i=0;i< smartlist_len(routerlist->routers); i++) {
     router = smartlist_get(routerlist->routers, i);
-    if(router->dir_port > 0 && router->is_running && router->is_trusted_dir)
+    if(router->is_running && router->is_trusted_dir) {
+      tor_assert(router->dir_port > 0);
       smartlist_add(sl, router);
+    }
   }
 
   router = smartlist_choose(sl);
@@ -87,7 +89,8 @@
    * so we cycle through the list again. */
   for(i=0; i < smartlist_len(routerlist->routers); i++) {
     router = smartlist_get(routerlist->routers, i);
-    if(router->dir_port > 0 && router->is_trusted_dir) {
+    if(router->is_trusted_dir) {
+      tor_assert(router->dir_port > 0);
       router->is_running = 1;
       dirserver = router;
     }



More information about the tor-commits mailing list