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

[or-cvs] [tor/master 5/6] Add a node_get_by_hex_id().



Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date: Thu, 21 Oct 2010 11:18:16 -0400
Subject: Add a node_get_by_hex_id().
Commit: bd1a69422190625c31013c2b7b73031e080722ab

---
 src/or/nodelist.c |   52 +++++++++++++++++++++++++++++++++-------------------
 src/or/nodelist.h |    1 +
 2 files changed, 34 insertions(+), 19 deletions(-)

diff --git a/src/or/nodelist.c b/src/or/nodelist.c
index a8df308..34482e6 100644
--- a/src/or/nodelist.c
+++ b/src/or/nodelist.c
@@ -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;
 
diff --git a/src/or/nodelist.h b/src/or/nodelist.h
index 23f4a16..d85d3eb 100644
--- a/src/or/nodelist.h
+++ b/src/or/nodelist.h
@@ -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);
-- 
1.7.1