Added search function for PEER_id given a PeerIdentity
authorBart Polot <bart@net.in.tum.de>
Wed, 22 Jun 2011 08:39:54 +0000 (08:39 +0000)
committerBart Polot <bart@net.in.tum.de>
Wed, 22 Jun 2011 08:39:54 +0000 (08:39 +0000)
src/include/gnunet_peer_lib.h
src/util/peer.c

index 036eea1dc6409bc4bb836aa5c3ee02dc56fa325f..b6cba7d32d0cea3609583206cf01bc9067dc492d 100644 (file)
@@ -47,6 +47,15 @@ extern "C"
 typedef unsigned int GNUNET_PEER_Id;
 
 
+/**
+ * Search for a peer identity. The reference counter is not changed.
+ *
+ * @param pid identity to find
+ * @return the interned identity or 0.
+ */
+GNUNET_PEER_Id GNUNET_PEER_search (const struct GNUNET_PeerIdentity *pid);
+
+
 /**
  * Intern an peer identity.  If the identity is already known, its
  * reference counter will be increased by one.
index e013c22e9ecd129fae995c6bdf3ceb15f8719bec..96ac271c0097cb7f3e80d04a912b4276be8a1fd4 100644 (file)
@@ -72,6 +72,35 @@ static unsigned int size;
 static unsigned int free_list_start;
 
 
+/**
+ * Search for a peer identity. The reference counter is not changed.
+ *
+ * @param pid identity to find
+ * @return the interned identity or 0.
+ */
+GNUNET_PEER_Id
+GNUNET_PEER_search (const struct GNUNET_PeerIdentity *pid)
+{
+  struct PeerEntry *e;
+  long off;
+
+  if (pid == NULL)
+    return 0;
+  if (NULL == map)
+    return 0;
+  off = (long) GNUNET_CONTAINER_multihashmap_get (map, &pid->hashPubKey);
+  e = (off == 0) ? NULL : &table[off];
+  if (e != NULL)
+    {
+      GNUNET_assert (e->rc > 0);
+      return e->pid;
+    }
+  else
+    {
+      return 0;
+    }
+}
+
 /**
  * Intern an peer identity.  If the identity is already known, its
  * reference counter will be increased by one.