Commit ceac39aa authored by Nick Mathewson's avatar Nick Mathewson 🐘
Browse files

r12697@catbus: nickm | 2007-05-09 00:15:40 -0400

 Change authority_type_t to a set of flags; use it more consistently.


svn:r10144
parent 66f9240e
Loading
Loading
Loading
Loading
+2 −1
Changes for src/or/circuitbuild.c: 2 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -1740,7 +1740,8 @@ extend_info_from_router(routerinfo_t *r)
 * It's a general purpose router unless it's on our bridges list.
 */
static uint8_t
get_router_purpose_from_digest(char *digest) {
get_router_purpose_from_digest(char *digest)
{
  (void)digest;
  return ROUTER_PURPOSE_GENERAL; /* XXX020 */
}
+35 −31
Changes for src/or/config.c: 35 added lines, 31 removed lines.
Original line number Diff line number Diff line
@@ -211,7 +211,7 @@ static config_var_t _option_vars[] = {
  VAR("PidFile",             STRING,   PidFile,              NULL),
  VAR("PreferTunneledDirConns", BOOL,  PreferTunneledDirConns, "0"),
  VAR("ProtocolWarnings",    BOOL,     ProtocolWarnings,     "0"),
  VAR("PublishServerDescriptor",STRING,PublishServerDescriptor,"v2"),
  VAR("PublishServerDescriptor", CSV,  PublishServerDescriptor,"v1,v2"),
  VAR("PublishHidServDescriptors",BOOL,PublishHidServDescriptors, "1"),
  VAR("ReachableAddresses",  LINELIST, ReachableAddresses,   NULL),
  VAR("ReachableDirAddresses",LINELIST,ReachableDirAddresses,NULL),
@@ -1929,7 +1929,7 @@ resolve_my_address(int warn_severity, or_options_t *options,

  tor_inet_ntoa(&in,tmpbuf,sizeof(tmpbuf));
  if (is_internal_IP(ntohl(in.s_addr), 0) &&
      options->_PublishServerDescriptor != NO_AUTHORITY) {
      options->_PublishServerDescriptor) {
    /* make sure we're ok with publishing an internal IP */
    if (!options->DirServers) {
      /* if they are using the default dirservers, disallow internal IPs
@@ -2308,27 +2308,33 @@ ensure_bandwidth_cap(uint64_t value, const char *desc, char **msg)
  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.
/** Parse an authority type from <b>list</b> and write it to *<b>auth</b>.  If
 * <b>compatible</b> is non-zero, treat "1" as "v1,v2" and treat "0" as "".
 * Return 0 on success or -(idx of first bad member) if not a recognized
 * authority type.
 */
static int
parse_authority_type_from_string(const char *string, authority_type_t *auth,
parse_authority_type_from_list(smartlist_t *list, authority_type_t *auth,
                               int compatible)
{
  tor_assert(auth);
  *auth = 0;
  SMARTLIST_FOREACH(list, const char *, string, {
    if (!strcasecmp(string, "v1"))
    *auth = V1_AUTHORITY;
  else if (!strcasecmp(string, "v2") || (compatible && !strcmp(string, "1")))
    *auth = V2_AUTHORITY;
      *auth |= V1_AUTHORITY;
    else if (compatible && !strcmp(string, "1"))
      *auth |= V1_AUTHORITY | V2_AUTHORITY;
    else if (!strcasecmp(string, "v2"))
      *auth |= V2_AUTHORITY;
    else if (!strcasecmp(string, "bridge"))
    *auth = BRIDGE_AUTHORITY;
      *auth |= BRIDGE_AUTHORITY;
    else if (!strcasecmp(string, "hidserv"))
    *auth = HIDSERV_AUTHORITY;
      *auth |= HIDSERV_AUTHORITY;
    else if (!strcasecmp(string, "") || (compatible && !strcmp(string, "0")))
    *auth = NO_AUTHORITY;
      /* no authority */;
    else
    return -1;
      return - string_sl_idx;
    });
  return 0;
}

@@ -2473,8 +2479,9 @@ options_validate(or_options_t *old_options, or_options_t *options,
  if (options->NoPublish) {
    log(LOG_WARN, LD_CONFIG,
        "NoPublish is obsolete. Use PublishServerDescriptor instead.");
    tor_free(options->PublishServerDescriptor);
    options->PublishServerDescriptor = tor_strdup("");
    SMARTLIST_FOREACH(options->PublishServerDescriptor, char *, s,
                      tor_free(s));
    smartlist_clear(options->PublishServerDescriptor);
  }

  if (authdir_mode(options)) {
@@ -2681,11 +2688,11 @@ options_validate(or_options_t *old_options, or_options_t *options,
      });
  }

  if (parse_authority_type_from_string(options->PublishServerDescriptor,
                               &options->_PublishServerDescriptor, 1) < 0) {
  if ((i = parse_authority_type_from_list(options->PublishServerDescriptor,
                               &options->_PublishServerDescriptor, 1) < 0)) {
    r = tor_snprintf(buf, sizeof(buf),
        "Unrecognized value '%s' for PublishServerDescriptor",
        options->PublishServerDescriptor);
                  (char*)smartlist_get(options->PublishServerDescriptor, -i));
    *msg = tor_strdup(r >= 0 ? buf : "internal error");
    return -1;
  }
@@ -3564,9 +3571,8 @@ parse_dir_server_line(const char *line, int validate_only)
  char *addrport=NULL, *address=NULL, *nickname=NULL, *fingerprint=NULL;
  uint16_t dir_port = 0, or_port = 0;
  char digest[DIGEST_LEN];
  int is_v1_authority = 0, is_hidserv_authority = 0,
    is_not_hidserv_authority = 0, is_v2_authority = 1,
    is_bridge_authority = 0;
  authority_type_t type = V2_AUTHORITY;
  int is_not_hidserv_authority = 0, is_not_v2_authority = 0;

  items = smartlist_create();
  smartlist_split_string(items, line, NULL,
@@ -3586,15 +3592,15 @@ parse_dir_server_line(const char *line, int validate_only)
    if (TOR_ISDIGIT(flag[0]))
      break;
    if (!strcasecmp(flag, "v1")) {
      is_v1_authority = is_hidserv_authority = 1;
      type |= (V1_AUTHORITY | HIDSERV_AUTHORITY);
    } else if (!strcasecmp(flag, "hs")) {
      is_hidserv_authority = 1;
      type |= HIDSERV_AUTHORITY;
    } else if (!strcasecmp(flag, "no-hs")) {
      is_not_hidserv_authority = 1;
    } else if (!strcasecmp(flag, "bridge")) {
      is_bridge_authority = 1;
      type |= BRIDGE_AUTHORITY;
    } else if (!strcasecmp(flag, "no-v2")) {
      is_v2_authority = 0;
      is_not_v2_authority = 1;
    } else if (!strcasecmpstart(flag, "orport=")) {
      int ok;
      char *portstring = flag + strlen("orport=");
@@ -3609,9 +3615,10 @@ parse_dir_server_line(const char *line, int validate_only)
    tor_free(flag);
    smartlist_del_keeporder(items, 0);
  }

  if (is_not_hidserv_authority)
    is_hidserv_authority = 0;
    type &= ~HIDSERV_AUTHORITY;
  if (is_not_v2_authority)
    type &= ~V2_AUTHORITY;

  if (smartlist_len(items) < 2) {
    log_warn(LD_CONFIG, "Too few arguments to DirServer line.");
@@ -3642,10 +3649,7 @@ parse_dir_server_line(const char *line, int validate_only)
    log_debug(LD_DIR, "Trusted dirserver at %s:%d (%s)", address,
              (int)dir_port,
              (char*)smartlist_get(items,0));
    add_trusted_dir_server(nickname, address, dir_port, or_port, digest,
                           is_v1_authority, is_v2_authority,
                           is_bridge_authority, is_hidserv_authority);

    add_trusted_dir_server(nickname, address, dir_port, or_port, digest, type);
  }

  r = 0;
+25 −19
Changes for src/or/directory.c: 25 added lines, 19 removed lines.
Original line number Diff line number Diff line
@@ -83,17 +83,27 @@ purpose_is_private(uint8_t purpose)
  return 1;
}

/** Return a static string describing <b>auth</b>. */
const char *
/** Return a newly allocated string describing <b>auth</b>. */
char *
authority_type_to_string(authority_type_t auth)
{
  switch(auth) {
    case V1_AUTHORITY: return "V1";
    case V2_AUTHORITY: return "V2";
    case BRIDGE_AUTHORITY: return "Bridge";
    case HIDSERV_AUTHORITY: return "Hidden service";
    case NO_AUTHORITY: default: return "[Unexpected authority type]";
  char *result;
  smartlist_t *lst = smartlist_create();
  if (auth & V1_AUTHORITY)
    smartlist_add(lst, (void*)"V1");
  if (auth & V2_AUTHORITY)
    smartlist_add(lst, (void*)"V2");
  if (auth & BRIDGE_AUTHORITY)
    smartlist_add(lst, (void*)"Bridge");
  if (auth & HIDSERV_AUTHORITY)
    smartlist_add(lst, (void*)"Hidden service");
  if (smartlist_len(lst)) {
    result = smartlist_join_strings(lst, ", ", 0, NULL);
  } else {
    result = tor_strdup("[Not an authority]");
  }
  smartlist_free(lst);
  return result;
}

/** Start a connection to every suitable directory server, using
@@ -124,16 +134,11 @@ directory_post_to_dirservers(uint8_t purpose, authority_type_t type,
      local_routerstatus_t *lrs = router_get_combined_status_by_digest(
                                                ds->digest);
      int new_enough;

      size_t upload_len = payload_len;
      if (type == HIDSERV_AUTHORITY && !ds->is_hidserv_authority)
        continue;
      if (type == BRIDGE_AUTHORITY && !ds->is_bridge_authority)
        continue;
      if (type == V1_AUTHORITY && !ds->is_v1_authority)
        continue;
      if (type == V2_AUTHORITY && !ds->is_v2_authority)

      if ((type & ds->type) == 0)
        continue;

      found = 1; /* at least one authority of this type was listed */
      if (purpose == DIR_PURPOSE_UPLOAD_DIR)
        ds->has_accepted_serverdesc = 0;
@@ -152,9 +157,10 @@ directory_post_to_dirservers(uint8_t purpose, authority_type_t type,
                                              NULL, payload, upload_len);
    });
  if (!found) {
    char *s = authority_type_to_string(type);
    log_warn(LD_DIR, "Publishing server descriptor to directory authorities "
             "of type '%s', but no authorities of that type listed!",
             authority_type_to_string(type));
             "of type '%s', but no authorities of that type listed!", s);
    tor_free(s);
  }
}

@@ -1234,7 +1240,7 @@ connection_dir_client_reached_eof(dir_connection_t *conn)
          ds->has_accepted_serverdesc = 1;
          servers = router_get_trusted_dir_servers();
          SMARTLIST_FOREACH(servers, trusted_dir_server_t *, d, {
              if ((d->is_v1_authority || d->is_v2_authority) &&
              if ((d->type & (V1_AUTHORITY|V2_AUTHORITY)) &&
                  !d->has_accepted_serverdesc) {
                all_done = 0;
                break;
+1 −1
Changes for src/or/dirserv.c: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -1840,7 +1840,7 @@ dirserv_get_networkstatus_v2_fingerprints(smartlist_t *result,
    } else {
      SMARTLIST_FOREACH(router_get_trusted_dir_servers(),
                  trusted_dir_server_t *, ds,
                  if (ds->is_v2_authority)
                  if (ds->type & V2_AUTHORITY)
                    smartlist_add(result, tor_memdup(ds->digest, DIGEST_LEN)));
    }
    smartlist_sort_digests(result);
+13 −19
Changes for src/or/or.h: 13 added lines, 19 removed lines.
Original line number Diff line number Diff line
@@ -1311,9 +1311,13 @@ typedef struct authority_cert_t {
  time_t expires;
} authority_cert_t;

/** DOCDOC */
typedef enum {
  NO_AUTHORITY=0, V1_AUTHORITY, V2_AUTHORITY,
  HIDSERV_AUTHORITY, BRIDGE_AUTHORITY
  NO_AUTHORITY      = 0,
  V1_AUTHORITY      = 1 << 0,
  V2_AUTHORITY      = 1 << 1,
  HIDSERV_AUTHORITY = 1 << 2,
  BRIDGE_AUTHORITY  = 1 << 3,
} authority_type_t;

#define CRYPT_PATH_MAGIC 0x70127012u
@@ -1757,7 +1761,7 @@ typedef struct {
  int NoPublish;
  /** To what authority types do we publish our descriptor? Choices are
   * "v1", "v2", "bridge", or "". */
  char *PublishServerDescriptor;
  smartlist_t *PublishServerDescriptor;
  /** An authority type, derived from PublishServerDescriptor. */
  authority_type_t _PublishServerDescriptor;
  /** Boolean: do we publish hidden service descriptors to the HS auths? */
@@ -2519,7 +2523,7 @@ int assign_to_cpuworker(connection_t *cpuworker, uint8_t question_type,

/********************************* directory.c ***************************/

const char *authority_type_to_string(authority_type_t auth);
char *authority_type_to_string(authority_type_t auth);
void directory_post_to_dirservers(uint8_t purpose, authority_type_t type,
                                  const char *payload,
                                  size_t payload_len, size_t extrainfo_len);
@@ -3029,20 +3033,14 @@ typedef struct trusted_dir_server_t {
  uint16_t or_port; /**< OR port: Used for tunneling connections. */
  char digest[DIGEST_LEN]; /**< Digest of identity key. */
  unsigned int is_running:1; /**< True iff we think this server is running. */
  /** True iff this server is an authority for the older ("v1") directory
   * protocol. */
  unsigned int is_v1_authority:1;
  /** True iff this server is an authority for the newer ("v2") directory
   * protocol. */
  unsigned int is_v2_authority:1;
  /** True iff this server is an authority for bridge relays. */
  unsigned int is_bridge_authority:1;
  /** True iff this server is an authority for hidden services. */
  unsigned int is_hidserv_authority:1;

  /** True iff this server has accepted the most recent server descriptor
   * we tried to upload to it. */
  unsigned int has_accepted_serverdesc:1;

  /** DOCDOC */
  authority_type_t type;

  int n_networkstatus_failures; /**< How many times have we asked for this
                                 * server's network-status unsuccessfully? */
  local_routerstatus_t fake_status; /**< Used when we need to pass this trusted
@@ -3137,9 +3135,7 @@ int router_exit_policy_rejects_all(routerinfo_t *router);

void add_trusted_dir_server(const char *nickname, const char *address,
                            uint16_t dir_port, uint16_t or_port,
                            const char *digest, int is_v1_authority,
                            int is_v2_authority, int is_bridge_authority,
                            int is_hidserv_authority);
                            const char *digest, authority_type_t type);
void clear_trusted_dir_servers(void);
int any_trusted_dir_is_v1_authority(void);
networkstatus_t *networkstatus_get_by_digest(const char *digest);
@@ -3237,7 +3233,5 @@ void authority_cert_free(authority_cert_t *cert);
authority_cert_t *authority_cert_parse_from_string(const char *s,
                                                   char **end_of_string);



#endif
Loading