gnunet_peer_lib.h (3393B)
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 #if !defined (__GNUNET_UTIL_LIB_H_INSIDE__) 22 #error "Only <gnunet_util_lib.h> can be included directly." 23 #endif 24 25 /** 26 * @addtogroup libgnunetutil 27 * Multi-function utilities library for GNUnet programs 28 * @{ 29 * 30 * @author Christian Grothoff 31 * 32 * @file 33 * Helper library for interning of peer identifiers 34 * 35 * @defgroup peer Peer library 36 * Helper library for interning of peer identifiers 37 * @{ 38 */ 39 40 #ifndef GNUNET_PEER_LIB_H 41 #define GNUNET_PEER_LIB_H 42 43 44 #include "gnunet_util_lib.h" 45 46 #ifdef __cplusplus 47 extern "C" 48 { 49 #if 0 /* keep Emacsens' auto-indent happy */ 50 } 51 #endif 52 #endif 53 54 /** 55 * A GNUNET_PEER_Id is simply a shorter version of a "struct 56 * GNUNET_PeerIdentifier" that can be used inside of a GNUnet peer to 57 * save memory when the same identifier needs to be used over and over 58 * again. 59 */ 60 typedef unsigned int GNUNET_PEER_Id; 61 62 63 /** 64 * Search for a peer identity. The reference counter is not changed. 65 * 66 * @param pid identity to find 67 * @return the interned identity or 0. 68 */ 69 GNUNET_PEER_Id 70 GNUNET_PEER_search (const struct GNUNET_PeerIdentity *pid); 71 72 73 /** 74 * Intern an peer identity. If the identity is already known, its 75 * reference counter will be increased by one. 76 * 77 * @param pid identity to intern 78 * @return the interned identity. 79 */ 80 GNUNET_PEER_Id 81 GNUNET_PEER_intern (const struct GNUNET_PeerIdentity *pid); 82 83 84 /** 85 * Change the reference counter of an interned PID. 86 * 87 * @param id identity to change the RC of 88 * @param delta how much to change the RC 89 */ 90 void 91 GNUNET_PEER_change_rc (GNUNET_PEER_Id id, int delta); 92 93 94 /** 95 * Decrement multiple RCs of peer identities by one. 96 * 97 * @param ids array of PIDs to decrement the RCs of 98 * @param count size of the @a ids array 99 */ 100 void 101 GNUNET_PEER_decrement_rcs (const GNUNET_PEER_Id *ids, 102 unsigned int count); 103 104 105 /** 106 * Convert an interned PID to a normal peer identity. 107 * 108 * @param id interned PID to convert 109 * @param pid where to write the normal peer identity 110 */ 111 void 112 GNUNET_PEER_resolve (GNUNET_PEER_Id id, 113 struct GNUNET_PeerIdentity *pid); 114 115 116 /** 117 * Convert an interned PID to a normal peer identity. 118 * 119 * @param id interned PID to convert 120 * @return pointer to peer identity, valid as long @a id is valid 121 */ 122 const struct GNUNET_PeerIdentity * 123 GNUNET_PEER_resolve2 (GNUNET_PEER_Id id); 124 125 126 #if 0 /* keep Emacsens' auto-indent happy */ 127 { 128 #endif 129 #ifdef __cplusplus 130 } 131 #endif 132 133 /* ifndef GNUNET_PEER_LIB_H */ 134 #endif 135 136 /** @} */ /* end of group */ 137 138 /** @} */ /* end of group addition */ 139 140 /* end of gnunet_peer_lib.h */