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

[or-cvs] r11817: Turn all "Is DirPort nonzero? Because if it is, we must be a (in tor/trunk: . src/or)



Author: nickm
Date: 2007-10-09 16:44:47 -0400 (Tue, 09 Oct 2007)
New Revision: 11817

Modified:
   tor/trunk/
   tor/trunk/ChangeLog
   tor/trunk/src/or/connection_edge.c
   tor/trunk/src/or/control.c
   tor/trunk/src/or/directory.c
   tor/trunk/src/or/main.c
   tor/trunk/src/or/networkstatus.c
   tor/trunk/src/or/or.h
   tor/trunk/src/or/router.c
   tor/trunk/src/or/routerlist.c
   tor/trunk/src/or/routerparse.c
Log:
 r15598@catbus:  nickm | 2007-10-09 16:37:35 -0400
 Turn all "Is DirPort nonzero? Because if it is, we must be a directory" logic into calls to dirserver_mode().



Property changes on: tor/trunk
___________________________________________________________________
 svk:merge ticket from /tor/trunk [r15598] on 8246c3cf-6607-4228-993b-4d95d33730f1

Modified: tor/trunk/ChangeLog
===================================================================
--- tor/trunk/ChangeLog	2007-10-09 20:44:45 UTC (rev 11816)
+++ tor/trunk/ChangeLog	2007-10-09 20:44:47 UTC (rev 11817)
@@ -60,6 +60,7 @@
       caches will no longer need to hold authority opinions; thus, the
       rationale for keeping the types separate is now gone.
     - Make the code used to reschedule and reattempt downloads more uniform.
+    - Turn all 'Are we a directory?' logic into a call to dirserver_mode().
 
 
 Changes in version 0.2.0.7-alpha - 2007-09-21

Modified: tor/trunk/src/or/connection_edge.c
===================================================================
--- tor/trunk/src/or/connection_edge.c	2007-10-09 20:44:45 UTC (rev 11816)
+++ tor/trunk/src/or/connection_edge.c	2007-10-09 20:44:47 UTC (rev 11817)
@@ -2283,8 +2283,7 @@
     }
   } else if (rh.command == RELAY_COMMAND_BEGIN_DIR) {
     or_options_t *options = get_options();
-    port = options->DirPort; /* not actually used to open a connection */
-    if (!port || circ->purpose != CIRCUIT_PURPOSE_OR) {
+    if (!dirserver_mode(options) || circ->purpose != CIRCUIT_PURPOSE_OR) {
       end_payload[0] = END_STREAM_REASON_NOTDIRECTORY;
       relay_send_command_from_edge(rh.stream_id, circ, RELAY_COMMAND_END,
                                    end_payload, 1, NULL);

Modified: tor/trunk/src/or/control.c
===================================================================
--- tor/trunk/src/or/control.c	2007-10-09 20:44:45 UTC (rev 11816)
+++ tor/trunk/src/or/control.c	2007-10-09 20:44:47 UTC (rev 11817)
@@ -1381,7 +1381,7 @@
     tor_free(url);
     smartlist_free(descs);
   } else if (!strcmpstart(question, "dir/status/")) {
-    if (get_options()->DirPort) {
+    if (dirserver_mode(get_options())) {
       size_t len=0;
       char *cp;
       smartlist_t *status_list = smartlist_create();

Modified: tor/trunk/src/or/directory.c
===================================================================
--- tor/trunk/src/or/directory.c	2007-10-09 20:44:45 UTC (rev 11816)
+++ tor/trunk/src/or/directory.c	2007-10-09 20:44:47 UTC (rev 11817)
@@ -272,7 +272,7 @@
 {
   routerstatus_t *rs = NULL;
   or_options_t *options = get_options();
-  int prefer_authority = server_mode(options) && options->DirPort != 0;
+  int prefer_authority = dirserver_mode(options);
   int get_via_tor = purpose_needs_anonymity(dir_purpose, router_purpose);
   authority_type_t type;
 
@@ -2753,7 +2753,7 @@
 {
   char digest[DIGEST_LEN];
   time_t now = time(NULL);
-  int server = server_mode(get_options()) && get_options()->DirPort;
+  int server = dirserver_mode(get_options());
   if (!was_descriptor_digests)
     return; /* FFFF should implement this someday */
   SMARTLIST_FOREACH(failed, const char *, cp,

Modified: tor/trunk/src/or/main.c
===================================================================
--- tor/trunk/src/or/main.c	2007-10-09 20:44:45 UTC (rev 11816)
+++ tor/trunk/src/or/main.c	2007-10-09 20:44:47 UTC (rev 11817)
@@ -937,7 +937,7 @@
    * (if we've passed our internal checks). */
   if (time_to_fetch_directory < now) {
     /* Only caches actually need to fetch directories now. */
-    if (options->DirPort && !authdir_mode_v1(options)) {
+    if (dirserver_mode(options) && !authdir_mode_v1(options)) {
       /* XXX020 actually, we should only do this if we want to advertise
        * our dirport. not simply if we configured one. -RD */
       if (any_trusted_dir_is_v1_authority() &&
@@ -951,7 +951,7 @@
   }
 
   /* Caches need to fetch running_routers; directory clients don't. */
-  if (options->DirPort && time_to_fetch_running_routers < now) {
+  if (dirserver_mode(options) && time_to_fetch_running_routers < now) {
     if (!authdir_mode_v1(options) && !should_delay_dir_fetches(options)) {
       directory_get_from_dirserver(DIR_PURPOSE_FETCH_RUNNING_LIST,
                                    ROUTER_PURPOSE_GENERAL, NULL, 1);

Modified: tor/trunk/src/or/networkstatus.c
===================================================================
--- tor/trunk/src/or/networkstatus.c	2007-10-09 20:44:45 UTC (rev 11816)
+++ tor/trunk/src/or/networkstatus.c	2007-10-09 20:44:47 UTC (rev 11817)
@@ -234,7 +234,7 @@
     tor_free(fn);
   }
 
-  if (get_options()->DirPort)
+  if (dirserver_mode(get_options()))
     dirserv_set_cached_networkstatus_v2(s,
                                         ns->identity_digest,
                                         ns->published_on);
@@ -290,7 +290,7 @@
       !(trusted_dir->type & V2_AUTHORITY)) {
     log_info(LD_DIR, "Network status was signed, but not by an authoritative "
              "directory we recognize.");
-    if (!get_options()->DirPort) {
+    if (!dirserver_mode(get_options())) {
       networkstatus_free(ns);
       return 0;
     }
@@ -345,7 +345,7 @@
   }
 
   if (!trusted_dir) {
-    if (!skewed && get_options()->DirPort) {
+    if (!skewed && dirserver_mode(get_options())) {
       /* We got a non-trusted networkstatus, and we're a directory cache.
        * This means that we asked an authority, and it told us about another
        * authority we didn't recognize. */
@@ -459,7 +459,7 @@
       unlink(fname);
     }
     tor_free(fname);
-    if (get_options()->DirPort) {
+    if (dirserver_mode(get_options())) {
       dirserv_set_cached_networkstatus_v2(NULL, ns->identity_digest, 0);
     }
     networkstatus_free(ns);
@@ -857,7 +857,7 @@
     const networkstatus_vote_t *c = current_consensus;
     time_t start;
     long interval;
-    if (options->DirPort) {
+    if (dirserver_mode(options)) {
       start = c->valid_after + 120; /*XXXX020 make this a macro. */
       /* XXXX020 too much magic. */
       interval = (c->fresh_until - c->valid_after) / 2;
@@ -895,7 +895,7 @@
   or_options_t *options = get_options();
   if (should_delay_dir_fetches(options))
     return;
-  if (options->DirPort)
+  if (dirserver_mode(options))
     update_networkstatus_cache_downloads(now);
   else
     update_networkstatus_client_downloads(now);
@@ -1019,7 +1019,7 @@
     write_str_to_file(filename, consensus, 0);
   }
 
-  if (get_options()->DirPort)
+  if (dirserver_mode(get_options()))
     dirserv_set_cached_networkstatus_v3(consensus, c->valid_after);
 
   return 0;
@@ -1317,7 +1317,7 @@
                  other_digest != conflict) {
         if (!warned) {
           char *d;
-          int should_warn = options->DirPort && authdir_mode(options);
+          int should_warn = authdir_mode(options);
           char fp1[HEX_DIGEST_LEN+1];
           char fp2[HEX_DIGEST_LEN+1];
           base16_encode(fp1, sizeof(fp1), other_digest, DIGEST_LEN);

Modified: tor/trunk/src/or/or.h
===================================================================
--- tor/trunk/src/or/or.h	2007-10-09 20:44:45 UTC (rev 11816)
+++ tor/trunk/src/or/or.h	2007-10-09 20:44:47 UTC (rev 11817)
@@ -3413,6 +3413,7 @@
 int authdir_mode_bridge(or_options_t *options);
 int authdir_mode_any_nonbridge(or_options_t *options);
 int clique_mode(or_options_t *options);
+int dirserver_mode(or_options_t *options);
 int server_mode(or_options_t *options);
 int advertised_server_mode(void);
 int proxy_mode(or_options_t *options);

Modified: tor/trunk/src/or/router.c
===================================================================
--- tor/trunk/src/or/router.c	2007-10-09 20:44:45 UTC (rev 11816)
+++ tor/trunk/src/or/router.c	2007-10-09 20:44:47 UTC (rev 11817)
@@ -854,6 +854,14 @@
   return (options->ORPort != 0 || options->ORListenAddress);
 }
 
+/** Return true iff we are trying to be a directory server */
+int
+dirserver_mode(or_options_t *options)
+{
+  if (options->ClientOnly) return 0;
+  return options->DirPort != 0;
+}
+
 /** Remember if we've advertised ourselves to the dirservers. */
 static int server_is_advertised=0;
 
@@ -879,7 +887,10 @@
 int
 proxy_mode(or_options_t *options)
 {
-  return (options->SocksPort != 0 || options->SocksListenAddress);
+  return (options->SocksPort != 0 || options->SocksListenAddress ||
+          options->TransPort != 0 || options->TransListenAddress ||
+          options->NatdPort != 0 || options->NatdListenAddress ||
+          options->DNSPort != 0 || options->DNSListenAddress);
 }
 
 /** Decide if we're a publishable server. We are a publishable server if:

Modified: tor/trunk/src/or/routerlist.c
===================================================================
--- tor/trunk/src/or/routerlist.c	2007-10-09 20:44:45 UTC (rev 11816)
+++ tor/trunk/src/or/routerlist.c	2007-10-09 20:44:47 UTC (rev 11817)
@@ -2196,6 +2196,8 @@
   return r;
 }
 
+#define should_cache_old_descriptors() dirserver_mode(get_options())
+
 /** If we're a directory cache and routerlist <b>rl</b> doesn't have
  * a copy of router <b>ri</b> yet, add it to the list of old (not
  * recommended but still served) descriptors. Else free it. */
@@ -2209,7 +2211,7 @@
   }
   tor_assert(ri->routerlist_index == -1);
 
-  if (get_options()->DirPort &&
+  if (should_cache_old_descriptors() &&
       ri->purpose == ROUTER_PURPOSE_GENERAL &&
       !sdmap_get(rl->desc_digest_map,
                  ri->cache_info.signed_descriptor_digest)) {
@@ -2254,7 +2256,7 @@
   router_dir_info_changed();
   tor_assert(ri_tmp == ri);
 
-  if (make_old && get_options()->DirPort &&
+  if (make_old && should_cache_old_descriptors() &&
       ri->purpose == ROUTER_PURPOSE_GENERAL) {
     signed_descriptor_t *sd;
     sd = signed_descriptor_from_routerinfo(ri);
@@ -2379,7 +2381,7 @@
               &ri_new->cache_info);
   }
 
-  if (get_options()->DirPort &&
+  if (should_cache_old_descriptors() &&
       ri_old->purpose == ROUTER_PURPOSE_GENERAL) {
     signed_descriptor_t *sd = signed_descriptor_from_routerinfo(ri_old);
     smartlist_add(rl->old_routers, sd);
@@ -2566,7 +2568,7 @@
       *msg = "Router descriptor is not referenced by any network-status.";
 
       /* Only journal this desc if we'll be serving it. */
-      if (!from_cache && get_options()->DirPort)
+      if (!from_cache && should_cache_old_descriptors())
         signed_desc_append_to_journal(&router->cache_info,
                                       router_get_store(routerlist, router),
                                       router->purpose);
@@ -2596,7 +2598,7 @@
       log_debug(LD_DIR, "Skipping not-new descriptor for router '%s'",
                 router->nickname);
       /* Only journal this desc if we'll be serving it. */
-      if (!from_cache && get_options()->DirPort)
+      if (!from_cache && should_cache_old_descriptors())
         signed_desc_append_to_journal(&router->cache_info,
                                       router_get_store(routerlist, router),
                                       router->purpose);
@@ -3568,7 +3570,7 @@
   or_options_t *options = get_options();
   const smartlist_t *networkstatus_list = networkstatus_get_v2_list();
 
-  if (options->DirPort) {
+  if (dirserver_mode(options)) {
     log_warn(LD_BUG,
              "Called router_descriptor_client_downloads() on a dir mirror?");
   }
@@ -3599,7 +3601,7 @@
   or_options_t *options = get_options();
 
   n_downloadable = smartlist_len(downloadable);
-  if (!options->DirPort) {
+  if (!dirserver_mode(options)) {
     if (n_downloadable >= MAX_DL_TO_DELAY) {
       log_debug(LD_DIR,
              "There are enough downloadable routerdescs to launch requests.");
@@ -3663,7 +3665,7 @@
   or_options_t *options = get_options();
   const smartlist_t *networkstatus_list = networkstatus_get_v2_list();
 
-  if (!options->DirPort) {
+  if (! dirserver_mode(options)) {
     log_warn(LD_BUG, "Called update_router_descriptor_cache_downloads() "
              "on a non-dir-mirror?");
   }
@@ -3800,9 +3802,10 @@
   digestmap_t *map = NULL;
   smartlist_t *downloadable = smartlist_create();
   int authdir = authdir_mode(options);
+  int dirserver = dirserver_mode(options);
   networkstatus_vote_t *consensus = networkstatus_get_latest_consensus();
 
-  if (!options->DirPort) {
+  if (!dirserver) {
     if (rep_hist_circbuilding_dormant(now))
       return;
   }
@@ -3819,7 +3822,7 @@
         continue; /* We have it already. */
       if (authdir && dirserv_would_reject_router(rs))
         continue; /* We would throw it out immediately. */
-      if (!options->DirPort && !client_would_use_router(rs, now, options))
+      if (!dirserver && !client_would_use_router(rs, now, options))
         continue; /* We would never use it ourself. */
       if (digestmap_get(map, rs->descriptor_digest))
         continue; /* We have an in-progress download. */
@@ -3839,7 +3842,7 @@
   or_options_t *options = get_options();
   if (should_delay_dir_fetches(options))
     return;
-  if (options->DirPort) {
+  if (dirserver_mode(options)) {
     update_router_descriptor_cache_downloads(now);
     update_consensus_router_descriptor_downloads(now); /*XXXX020 clients too*/
   } else {
@@ -3888,12 +3891,12 @@
         smartlist_add(wanted, ri->cache_info.extra_info_digest);
       }
     });
-  if (options->DirPort) {
+  if (dirserver_mode(options)) {
     SMARTLIST_FOREACH(rl->old_routers, signed_descriptor_t *, sd, {
         if (should_download_extrainfo(sd, rl, pending, now)) {
           smartlist_add(wanted, sd->extra_info_digest);
         }
-      });
+    });
   }
   digestmap_free(pending, NULL);
 

Modified: tor/trunk/src/or/routerparse.c
===================================================================
--- tor/trunk/src/or/routerparse.c	2007-10-09 20:44:45 UTC (rev 11816)
+++ tor/trunk/src/or/routerparse.c	2007-10-09 20:44:47 UTC (rev 11817)
@@ -670,7 +670,7 @@
 
   /* Now that we know the signature is okay, and we have a
    * publication time, cache the directory. */
-  if (get_options()->DirPort && !authdir_mode_v1(get_options()))
+  if (dirserver_mode(get_options()) && !authdir_mode_v1(get_options()))
     dirserv_set_cached_directory(str, published_on, 0);
 
   r = 0;