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

Add a node_get_by_hex_id().

parent f3214023
Loading
Loading
Loading
Loading
+33 −19
Changes for src/or/nodelist.c: 33 added lines, 19 removed lines.
Original line number Diff line number Diff line
@@ -400,31 +400,18 @@ nodelist_get_list(void)
  return the_nodelist->nodes;
}

/** Given a nickname (possibly verbose, possibly a hexadecimal digest), return
 * the corresponding node_t, or NULL if none exists.  Warn the user if
 * <b>warn_if_unnamed</b> is set, and they have specified a router by
 * nickname, but the Named flag isn't set for that router. */
/** Given a hex-encoded nickname of the format DIGEST, $DIGEST, $DIGEST=name,
 * or $DIGEST~name, return the node with the matching identity digest and
 * nickname (if any).  Return NULL if no such node exists, or if <b>hex_id</b>
 * is not well-formed. */
const node_t *
node_get_by_nickname(const char *nickname, int warn_if_unnamed)
node_get_by_hex_id(const char *hex_id)
{
  char digest_buf[DIGEST_LEN];
  char nn_buf[MAX_NICKNAME_LEN+1];
  char nn_char='\0';

  if (!the_nodelist)
    return NULL;

  /* ???? NM Naming authorities had an additional weird behavior here where
     they would treat their own namings as slightly authoritative in a
     strange and inconsistent way.  I think that this way is better, but we
     could get the old behavior back if we wanted to by adding a function
     to look in the fp_by_name table in fingerprint_list, and using this
     function to override the name-to-digest lookup below if we are a
     naming server.  -NM
   */

  /* Handle these cases: DIGEST, $DIGEST, $DIGEST=name, $DIGEST~name. */
  if (hex_digest_nickname_decode(nickname, digest_buf, &nn_char, nn_buf)==0) {
  if (hex_digest_nickname_decode(hex_id, digest_buf, &nn_char, nn_buf)==0) {
    const node_t *node = node_get_by_id(digest_buf);
    if (!node)
      return NULL;
@@ -442,6 +429,33 @@ node_get_by_nickname(const char *nickname, int warn_if_unnamed)
    return node;
  }

  return NULL;
}

/** Given a nickname (possibly verbose, possibly a hexadecimal digest), return
 * the corresponding node_t, or NULL if none exists.  Warn the user if
 * <b>warn_if_unnamed</b> is set, and they have specified a router by
 * nickname, but the Named flag isn't set for that router. */
const node_t *
node_get_by_nickname(const char *nickname, int warn_if_unnamed)
{
  const node_t *node;
  if (!the_nodelist)
    return NULL;

  /* ???? NM Naming authorities had an additional weird behavior here where
     they would treat their own namings as slightly authoritative in a
     strange and inconsistent way.  I think that this way is better, but we
     could get the old behavior back if we wanted to by adding a function
     to look in the fp_by_name table in fingerprint_list, and using this
     function to override the name-to-digest lookup below if we are a
     naming server.  -NM
   */

  /* Handle these cases: DIGEST, $DIGEST, $DIGEST=name, $DIGEST~name. */
  if ((node = node_get_by_hex_id(nickname)) != NULL)
      return node;

  if (!strcasecmp(nickname, UNNAMED_ROUTER_NICKNAME))
    return NULL;

+1 −0
Changes for src/or/nodelist.h: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@

node_t *node_get_mutable_by_id(const char *identity_digest);
const node_t *node_get_by_id(const char *identity_digest);
const node_t *node_get_by_hex_id(const char *identity_digest);
node_t *nodelist_add_routerinfo(routerinfo_t *ri);
node_t *nodelist_add_microdesc(microdesc_t *md);
void nodelist_set_consensus(networkstatus_t *ns);