From: Bart Polot Date: Wed, 22 Jun 2011 08:39:54 +0000 (+0000) Subject: Added search function for PEER_id given a PeerIdentity X-Git-Tag: initial-import-from-subversion-38251~18062 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=a36de9cd81b02e4454ffcfa10c709419700c590d;p=oweals%2Fgnunet.git Added search function for PEER_id given a PeerIdentity --- diff --git a/src/include/gnunet_peer_lib.h b/src/include/gnunet_peer_lib.h index 036eea1dc..b6cba7d32 100644 --- a/src/include/gnunet_peer_lib.h +++ b/src/include/gnunet_peer_lib.h @@ -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. diff --git a/src/util/peer.c b/src/util/peer.c index e013c22e9..96ac271c0 100644 --- a/src/util/peer.c +++ b/src/util/peer.c @@ -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.