aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/include/gnunet_peer_lib.h9
-rw-r--r--src/util/peer.c29
2 files changed, 38 insertions, 0 deletions
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
@@ -48,6 +48,15 @@ typedef unsigned int GNUNET_PEER_Id;
48 48
49 49
50/** 50/**
51 * Search for a peer identity. The reference counter is not changed.
52 *
53 * @param pid identity to find
54 * @return the interned identity or 0.
55 */
56GNUNET_PEER_Id GNUNET_PEER_search (const struct GNUNET_PeerIdentity *pid);
57
58
59/**
51 * Intern an peer identity. If the identity is already known, its 60 * Intern an peer identity. If the identity is already known, its
52 * reference counter will be increased by one. 61 * reference counter will be increased by one.
53 * 62 *
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
@@ -73,6 +73,35 @@ static unsigned int free_list_start;
73 73
74 74
75/** 75/**
76 * Search for a peer identity. The reference counter is not changed.
77 *
78 * @param pid identity to find
79 * @return the interned identity or 0.
80 */
81GNUNET_PEER_Id
82GNUNET_PEER_search (const struct GNUNET_PeerIdentity *pid)
83{
84 struct PeerEntry *e;
85 long off;
86
87 if (pid == NULL)
88 return 0;
89 if (NULL == map)
90 return 0;
91 off = (long) GNUNET_CONTAINER_multihashmap_get (map, &pid->hashPubKey);
92 e = (off == 0) ? NULL : &table[off];
93 if (e != NULL)
94 {
95 GNUNET_assert (e->rc > 0);
96 return e->pid;
97 }
98 else
99 {
100 return 0;
101 }
102}
103
104/**
76 * Intern an peer identity. If the identity is already known, its 105 * Intern an peer identity. If the identity is already known, its
77 * reference counter will be increased by one. 106 * reference counter will be increased by one.
78 * 107 *