consolidate reclaim attribute lib
[oweals/gnunet.git] / src / include / gnunet_peer_lib.h
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2006, 2009 GNUnet e.V.
4
5      GNUnet is free software: you can redistribute it and/or modify it
6      under the terms of the GNU Affero General Public License as published
7      by the Free Software Foundation, either version 3 of the License,
8      or (at your 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      Affero General Public License for more details.
14
15      You should have received a copy of the GNU Affero General Public License
16      along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18      SPDX-License-Identifier: AGPL3.0-or-later
19  */
20
21 /**
22  * @author Christian Grothoff
23  *
24  * @file
25  * Helper library for interning of peer identifiers
26  *
27  * @defgroup peer  Peer library
28  * Helper library for interning of peer identifiers
29  * @{
30  */
31
32 #ifndef GNUNET_PEER_LIB_H
33 #define GNUNET_PEER_LIB_H
34
35 #include "gnunet_util_lib.h"
36
37 #ifdef __cplusplus
38 extern "C"
39 {
40 #if 0                           /* keep Emacsens' auto-indent happy */
41 }
42 #endif
43 #endif
44
45 /**
46  * A GNUNET_PEER_Id is simply a shorter version of a "struct
47  * GNUNET_PeerIdentifier" that can be used inside of a GNUnet peer to
48  * save memory when the same identifier needs to be used over and over
49  * again.
50  */
51 typedef unsigned int GNUNET_PEER_Id;
52
53
54 /**
55  * Search for a peer identity. The reference counter is not changed.
56  *
57  * @param pid identity to find
58  * @return the interned identity or 0.
59  */
60 GNUNET_PEER_Id
61 GNUNET_PEER_search (const struct GNUNET_PeerIdentity *pid);
62
63
64 /**
65  * Intern an peer identity.  If the identity is already known, its
66  * reference counter will be increased by one.
67  *
68  * @param pid identity to intern
69  * @return the interned identity.
70  */
71 GNUNET_PEER_Id
72 GNUNET_PEER_intern (const struct GNUNET_PeerIdentity *pid);
73
74
75 /**
76  * Change the reference counter of an interned PID.
77  *
78  * @param id identity to change the RC of
79  * @param delta how much to change the RC
80  */
81 void
82 GNUNET_PEER_change_rc (GNUNET_PEER_Id id, int delta);
83
84
85 /**
86  * Decrement multiple RCs of peer identities by one.
87  *
88  * @param ids array of PIDs to decrement the RCs of
89  * @param count size of the @a ids array
90  */
91 void
92 GNUNET_PEER_decrement_rcs (const GNUNET_PEER_Id *ids,
93                            unsigned int count);
94
95
96 /**
97  * Convert an interned PID to a normal peer identity.
98  *
99  * @param id interned PID to convert
100  * @param pid where to write the normal peer identity
101  */
102 void
103 GNUNET_PEER_resolve (GNUNET_PEER_Id id,
104                      struct GNUNET_PeerIdentity *pid);
105
106
107 /**
108  * Convert an interned PID to a normal peer identity.
109  *
110  * @param id interned PID to convert
111  * @return pointer to peer identity, valid as long @a id is valid
112  */
113 const struct GNUNET_PeerIdentity *
114 GNUNET_PEER_resolve2 (GNUNET_PEER_Id id);
115
116
117 #if 0                           /* keep Emacsens' auto-indent happy */
118 {
119 #endif
120 #ifdef __cplusplus
121 }
122 #endif
123
124 /* ifndef GNUNET_PEER_LIB_H */
125 #endif
126
127 /** @} */  /* end of group */
128
129 /* end of gnunet_peer_lib.h */