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

[or-cvs] r10136: Change the PublishServerDescriptor config option from a bool (tor/trunk/src/or)



Author: arma
Date: 2007-05-08 05:09:26 -0400 (Tue, 08 May 2007)
New Revision: 10136

Modified:
   tor/trunk/src/or/config.c
   tor/trunk/src/or/or.h
   tor/trunk/src/or/router.c
Log:
Change the PublishServerDescriptor config option from a boolean
into a string: "v1", "v2", bridge", "". Continue to support
"0" and "1".


Modified: tor/trunk/src/or/config.c
===================================================================
--- tor/trunk/src/or/config.c	2007-05-07 19:33:03 UTC (rev 10135)
+++ tor/trunk/src/or/config.c	2007-05-08 09:09:26 UTC (rev 10136)
@@ -210,7 +210,7 @@
   VAR("PidFile",             STRING,   PidFile,              NULL),
   VAR("PreferTunneledDirConns", BOOL,  PreferTunneledDirConns, "0"),
   VAR("ProtocolWarnings",    BOOL,     ProtocolWarnings,     "0"),
-  VAR("PublishServerDescriptor",BOOL,  PublishServerDescriptor,"1"),
+  VAR("PublishServerDescriptor",STRING,PublishServerDescriptor,"v2"),
   VAR("PublishHidServDescriptors",BOOL,PublishHidServDescriptors, "1"),
   VAR("ReachableAddresses",  LINELIST, ReachableAddresses,   NULL),
   VAR("ReachableDirAddresses",LINELIST,ReachableDirAddresses,NULL),
@@ -450,7 +450,7 @@
     "and servers." },
   { "ORListenAddress", "Bind to this address to listen for connections from "
     "clients and servers, instead of the default 0.0.0.0:ORPort." },
-  { "PublishServerDescriptors", "Set to 0 in order to keep the server from "
+  { "PublishServerDescriptors", "Set to \"\" to keep the server from "
     "uploading info to the directory authorities." },
   /*{ "RedirectExit", "When an outgoing connection tries to connect to a "
    *"given address, redirect it to another address instead." },
@@ -1915,7 +1915,7 @@
 
   tor_inet_ntoa(&in,tmpbuf,sizeof(tmpbuf));
   if (is_internal_IP(ntohl(in.s_addr), 0) &&
-      options->PublishServerDescriptor) {
+      options->_PublishServerDescriptor != NO_AUTHORITY) {
     /* make sure we're ok with publishing an internal IP */
     if (!options->DirServers) {
       /* if they are using the default dirservers, disallow internal IPs
@@ -2294,6 +2294,30 @@
   return 0;
 }
 
+/** Parse an authority type from <b>string</b> and write it to *<b>auth</b>.
+ * If <b>compatible</b> is non-zero, treat "1" as "v2" and treat "0" as "".
+ * Return 0 on success or -1 if not a recognized authority type.
+ */
+static int
+parse_authority_type_from_string(const char *string, authority_type_t *auth,
+                                 int compatible)
+{
+  tor_assert(auth);
+  if (!strcasecmp(string, "v1"))
+    *auth = V1_AUTHORITY;
+  else if (!strcasecmp(string, "v2") || (compatible && !strcmp(string, "1")))
+    *auth = V2_AUTHORITY;
+  else if (!strcasecmp(string, "bridge"))
+    *auth = BRIDGE_AUTHORITY;
+  else if (!strcasecmp(string, "hidserv"))
+    *auth = HIDSERV_AUTHORITY;
+  else if (!strcasecmp(string, "") || (compatible && !strcmp(string, "0")))
+    *auth = NO_AUTHORITY;
+  else
+    return -1;
+  return 0;
+}
+
 /** Lowest allowable value for RendPostPeriod; if this is too low, hidden
  * services can overload the directory system. */
 #define MIN_REND_POST_PERIOD (10*60)
@@ -2435,7 +2459,8 @@
   if (options->NoPublish) {
     log(LOG_WARN, LD_CONFIG,
         "NoPublish is obsolete. Use PublishServerDescriptor instead.");
-    options->PublishServerDescriptor = 0;
+    tor_free(options->PublishServerDescriptor);
+    options->PublishServerDescriptor = tor_strdup("");
   }
 
   if (authdir_mode(options)) {
@@ -2642,6 +2667,15 @@
       });
   }
 
+  if (parse_authority_type_from_string(options->PublishServerDescriptor,
+                               &options->_PublishServerDescriptor, 1) < 0) {
+    r = tor_snprintf(buf, sizeof(buf),
+        "Unrecognized value '%s' for PublishServerDescriptor",
+        options->PublishServerDescriptor);
+    *msg = tor_strdup(r >= 0 ? buf : "internal error");
+    return -1;
+  }
+
 #if 0
   if (options->SocksPort >= 1 &&
       (options->PathlenCoinWeight < 0.0 || options->PathlenCoinWeight >= 1.0))
@@ -2910,8 +2944,8 @@
       old_options->DirPort != new_options->DirPort ||
       old_options->ClientOnly != new_options->ClientOnly ||
       old_options->NoPublish != new_options->NoPublish ||
-      old_options->PublishServerDescriptor !=
-        new_options->PublishServerDescriptor ||
+      old_options->_PublishServerDescriptor !=
+        new_options->_PublishServerDescriptor ||
       old_options->BandwidthRate != new_options->BandwidthRate ||
       old_options->BandwidthBurst != new_options->BandwidthBurst ||
       !opt_streq(old_options->ContactInfo, new_options->ContactInfo) ||

Modified: tor/trunk/src/or/or.h
===================================================================
--- tor/trunk/src/or/or.h	2007-05-07 19:33:03 UTC (rev 10135)
+++ tor/trunk/src/or/or.h	2007-05-08 09:09:26 UTC (rev 10136)
@@ -1308,6 +1308,11 @@
   time_t expires;
 } authority_cert_t;
 
+typedef enum {
+  NO_AUTHORITY=0, V1_AUTHORITY, V2_AUTHORITY,
+  HIDSERV_AUTHORITY, BRIDGE_AUTHORITY
+} authority_type_t;
+
 #define CRYPT_PATH_MAGIC 0x70127012u
 
 /** Holds accounting information for a single step in the layered encryption
@@ -1683,8 +1688,9 @@
   char *RendExcludeNodes; /**< Comma-separated list of nicknames not to use
                            * as introduction points. */
 
-  smartlist_t *AllowInvalidNodes; /**< List of "entry", "middle", "exit" */
-  int _AllowInvalid; /**< Bitmask; derived from AllowInvalidNodes; */
+  /** List of "entry", "middle", "exit", "introduction", "rendezvous". */
+  smartlist_t *AllowInvalidNodes;
+  int _AllowInvalid; /**< Bitmask; derived from AllowInvalidNodes. */
   config_line_t *ExitPolicy; /**< Lists of exit policy components. */
   int ExitPolicyRejectPrivate; /**< Should we not exit to local addresses? */
   config_line_t *SocksPolicy; /**< Lists of socks policy components */
@@ -1740,9 +1746,15 @@
   int AvoidDiskWrites; /**< Boolean: should we never cache things to disk?
                         * Not used yet. */
   int ClientOnly; /**< Boolean: should we never evolve into a server role? */
-  int NoPublish; /**< Boolean: should we never publish a descriptor? */
-  int PublishServerDescriptor; /**< Do we publish our descriptor as normal? */
-  int PublishHidServDescriptors; /**< and our hidden service descriptors? */
+  /** Boolean: should we never publish a descriptor? Deprecated. */
+  int NoPublish;
+  /** To what authority types do we publish our descriptor? Choices are
+   * "v1", "v2", "bridge", or "". */
+  char *PublishServerDescriptor;
+  /** An authority type, derived from PublishServerDescriptor. */
+  authority_type_t _PublishServerDescriptor;
+  /** Boolean: do we publish hidden service descriptors to the HS auths? */
+  int PublishHidServDescriptors;
   int FetchServerDescriptors; /**< Do we fetch server descriptors as normal? */
   int FetchHidServDescriptors; /** and hidden service descriptors? */
   int FetchUselessDescriptors; /**< Do we fetch non-running descriptors too? */
@@ -2497,9 +2509,6 @@
 
 /********************************* directory.c ***************************/
 
-typedef enum {
-  V1_AUTHORITY, V2_AUTHORITY, HIDSERV_AUTHORITY, BRIDGE_AUTHORITY
-} authority_type_t;
 void directory_post_to_dirservers(uint8_t purpose, authority_type_t type,
                                   const char *payload,
                                   size_t payload_len, size_t extrainfo_len);

Modified: tor/trunk/src/or/router.c
===================================================================
--- tor/trunk/src/or/router.c	2007-05-07 19:33:03 UTC (rev 10135)
+++ tor/trunk/src/or/router.c	2007-05-08 09:09:26 UTC (rev 10136)
@@ -528,7 +528,7 @@
     routerinfo_t *me = router_get_my_routerinfo();
     log_notice(LD_OR,"Self-testing indicates your ORPort is reachable from "
                "the outside. Excellent.%s",
-               get_options()->PublishServerDescriptor ?
+               get_options()->_PublishServerDescriptor != NO_AUTHORITY ?
                  " Publishing server descriptor." : "");
     can_reach_or_port = 1;
     mark_my_descriptor_dirty();
@@ -676,7 +676,7 @@
 /** Decide if we're a publishable server. We are a publishable server if:
  * - We don't have the ClientOnly option set
  * and
- * - We have the PublishServerDescriptor option set
+ * - We have the PublishServerDescriptor option set to non-empty
  * and
  * - We have ORPort set
  * and
@@ -690,7 +690,7 @@
 
   if (options->ClientOnly)
     return 0;
-  if (!options->PublishServerDescriptor)
+  if (options->_PublishServerDescriptor == NO_AUTHORITY)
     return 0;
   if (!server_mode(options))
     return 0;
@@ -771,7 +771,7 @@
     return;
   }
   ei = router_get_my_extrainfo();
-  if (!get_options()->PublishServerDescriptor)
+  if (get_options()->_PublishServerDescriptor == NO_AUTHORITY)
     return;
   if (!force && !desc_needs_upload)
     return;