header
[oweals/gnunet.git] / src / include / gnunet_peer_lib.h
1 /*
2      This file is part of GNUnet.
3      (C) 2006, 2009 Christian Grothoff (and other contributing authors)
4
5      GNUnet is free software; you can redistribute it and/or modify
6      it under the terms of the GNU General Public License as published
7      by the Free Software Foundation; either version 3, or (at your
8      option) any later version.
9
10      GNUnet is distributed in the hope that it will be useful, but
11      WITHOUT ANY WARRANTY; without even the implied warranty of
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13      General Public License for more details.
14
15      You should have received a copy of the GNU General Public License
16      along with GNUnet; see the file COPYING.  If not, write to the
17      Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18      Boston, MA 02111-1307, USA.
19 */
20
21 /**
22  * @file include/gnunet_peer_lib.h
23  * @brief helper library for interning of peer identifiers
24  * @author Christian Grothoff
25  */
26
27 #ifndef GNUNET_PEER_LIB_H
28 #define GNUNET_PEER_LIB_H
29
30 #include "gnunet_util_lib.h"
31
32 #ifdef __cplusplus
33 extern "C"
34 {
35 #if 0                           /* keep Emacsens' auto-indent happy */
36 }
37 #endif
38 #endif
39
40 /**
41  * A GNUNET_PEER_Id is simply a shorter
42  * version of a "struct GNUNET_PeerIdentifier"
43  * that can be used inside of a GNUnet peer
44  * to save memory when the same identifier
45  * needs to be used over and over again.
46  */
47 typedef unsigned int GNUNET_PEER_Id;
48
49
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  */
56 GNUNET_PEER_Id
57 GNUNET_PEER_search (const struct GNUNET_PeerIdentity *pid);
58
59
60 /**
61  * Intern an peer identity.  If the identity is already known, its
62  * reference counter will be increased by one.
63  *
64  * @param pid identity to intern
65  * @return the interned identity.
66  */
67 GNUNET_PEER_Id
68 GNUNET_PEER_intern (const struct GNUNET_PeerIdentity *pid);
69
70
71 /**
72  * Change the reference counter of an interned PID.
73  *
74  * @param id identity to change the RC of
75  * @param delta how much to change the RC
76  */
77 void
78 GNUNET_PEER_change_rc (GNUNET_PEER_Id id, int delta);
79
80
81 /**
82  * Decrement multiple RCs of peer identities by one.
83  *
84  * @param ids array of PIDs to decrement the RCs of
85  * @param count size of the ids array
86  */
87 void
88 GNUNET_PEER_decrement_rcs (const GNUNET_PEER_Id *ids, unsigned int count);
89
90
91 /**
92  * Convert an interned PID to a normal peer identity.
93  *
94  * @param id interned PID to convert
95  * @param pid where to write the normal peer identity
96  */
97 void
98 GNUNET_PEER_resolve (GNUNET_PEER_Id id, struct GNUNET_PeerIdentity *pid);
99
100
101 /**
102  * Convert an interned PID to a normal peer identity.
103  *
104  * @param id interned PID to convert
105  * @return pointer to peer identity, valid as long 'id' is valid
106  */
107 const struct GNUNET_PeerIdentity *
108 GNUNET_PEER_resolve2 (GNUNET_PEER_Id id);
109
110
111 #if 0                           /* keep Emacsens' auto-indent happy */
112 {
113 #endif
114 #ifdef __cplusplus
115 }
116 #endif
117
118
119 /* ifndef GNUNET_PEER_LIB_H */
120 #endif
121 /* end of gnunet_peer_lib.h */