- doc
[oweals/gnunet.git] / src / include / gnunet_pseudonym_lib.h
1 /*
2      This file is part of GNUnet.
3      (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 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 2, 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_pseudonym_lib.h
23  * @brief functions related to pseudonyms
24  * @author Christian Grothoff
25  */
26
27 #ifndef GNUNET_PSEUDONYM_LIB_H
28 #define GNUNET_PSEUDONYM_LIB_H
29
30 #ifdef __cplusplus
31 extern "C"
32 {
33 #if 0                           /* keep Emacsens' auto-indent happy */
34 }
35 #endif
36 #endif
37
38 #include "gnunet_common.h"
39 #include "gnunet_configuration_lib.h"
40 #include "gnunet_container_lib.h"
41
42 /**
43  * Iterator over all known pseudonyms.
44  *
45  * @param cls closure
46  * @param pseudonym hash code of public key of pseudonym
47  * @param name name of the pseudonym (might be NULL)
48  * @param unique_name unique name of the pseudonym (might be NULL)
49  * @param md meta data known about the pseudonym
50  * @param rating the local rating of the pseudonym
51  * @return GNUNET_OK to continue iteration, GNUNET_SYSERR to abort
52  */
53 typedef int (*GNUNET_PSEUDONYM_Iterator) (void *cls,
54                                           const struct GNUNET_HashCode * pseudonym,
55                                           const char *name,
56                                           const char *unique_name,
57                                           const struct GNUNET_CONTAINER_MetaData
58                                           * md, int rating);
59
60 /**
61  * Change the ranking of a pseudonym.
62  *
63  * @param cfg overall configuration
64  * @param nsid id of the pseudonym
65  * @param delta by how much should the rating be changed?
66  * @return new rating of the namespace
67  */
68 int
69 GNUNET_PSEUDONYM_rank (const struct GNUNET_CONFIGURATION_Handle *cfg,
70                        const struct GNUNET_HashCode * nsid, int delta);
71
72 /**
73  * Add a pseudonym to the set of known pseudonyms.
74  * For all pseudonym advertisements that we discover
75  * FS should automatically call this function.
76  *
77  * @param cfg overall configuration
78  * @param id the pseudonym identifier
79  * @param meta metadata for the pseudonym
80  */
81 void
82 GNUNET_PSEUDONYM_add (const struct GNUNET_CONFIGURATION_Handle *cfg,
83                       const struct GNUNET_HashCode * id,
84                       const struct GNUNET_CONTAINER_MetaData *meta);
85
86
87 /**
88  * List all known pseudonyms.
89  *
90  * @param cfg overall configuration
91  * @param iterator function to call for each pseudonym
92  * @param closure closure for iterator
93  * @return number of pseudonyms found
94  */
95 int
96 GNUNET_PSEUDONYM_list_all (const struct GNUNET_CONFIGURATION_Handle *cfg,
97                            GNUNET_PSEUDONYM_Iterator iterator, void *closure);
98
99 /**
100  * Register callback to be invoked whenever we discover
101  * a new pseudonym.
102  */
103 int
104 GNUNET_PSEUDONYM_discovery_callback_register (const struct
105                                               GNUNET_CONFIGURATION_Handle *cfg,
106                                               GNUNET_PSEUDONYM_Iterator
107                                               iterator, void *closure);
108
109 /**
110  * Unregister namespace discovery callback.
111  */
112 int
113 GNUNET_PSEUDONYM_discovery_callback_unregister (GNUNET_PSEUDONYM_Iterator
114                                                 iterator, void *closure);
115
116 /**
117  * Return unique variant of the namespace name.
118  * Use after GNUNET_PSEUDONYM_id_to_name() to make sure
119  * that name is unique.
120  *
121  * @param cfg configuration
122  * @param nsid cryptographic ID of the namespace
123  * @param name name to uniquify
124  * @param suffix if not NULL, filled with the suffix value
125  * @return NULL on failure (should never happen), name on success.
126  *         Free the name with GNUNET_free().
127  */
128 char *
129 GNUNET_PSEUDONYM_name_uniquify (const struct GNUNET_CONFIGURATION_Handle *cfg,
130     const struct GNUNET_HashCode * nsid, const char *name, unsigned int *suffix);
131
132 /**
133  * Get namespace name, metadata and rank
134  * This is a wrapper around internal read_info() call, and ensures that
135  * returned data is not invalid (not NULL).
136  * Writing back information returned by this function will give
137  * a name "no-name" to pseudonyms that have no name. This side-effect is
138  * unavoidable, but hardly harmful.
139  *
140  * @param cfg configuration
141  * @param nsid cryptographic ID of the namespace
142  * @param ret_meta a location to store metadata pointer. NULL, if metadata
143  *        is not needed. Destroy with GNUNET_CONTAINER_meta_data_destroy().
144  * @param ret_rank a location to store rank. NULL, if rank not needed.
145  * @param ret_name a location to store human-readable name. Name is not unique.
146  *        NULL, if name is not needed. Free with GNUNET_free().
147  * @param name_is_a_dup is set to GNUNET_YES, if ret_name was filled with
148  *        a duplicate of a "no-name" placeholder
149  * @return GNUNET_OK on success. GNUENT_SYSERR if the data was
150  *         unobtainable (in that case ret_* are filled with placeholders - 
151  *         empty metadata container, rank -1 and a "no-name" name).
152  */
153 int
154 GNUNET_PSEUDONYM_get_info (const struct GNUNET_CONFIGURATION_Handle *cfg,
155     const struct GNUNET_HashCode * nsid, struct GNUNET_CONTAINER_MetaData **ret_meta,
156     int32_t *ret_rank, char **ret_name, int *name_is_a_dup);
157
158
159 /**
160  * Get the namespace ID belonging to the given namespace name.
161  *
162  * @param cfg configuration to use
163  * @param ns_uname unique (!) human-readable name for the namespace
164  * @param nsid set to namespace ID based on 'ns_uname'
165  * @return GNUNET_OK on success, GNUNET_SYSERR on failure
166  */
167 int
168 GNUNET_PSEUDONYM_name_to_id (const struct GNUNET_CONFIGURATION_Handle *cfg,
169     const char *ns_uname, struct GNUNET_HashCode * nsid);
170
171 /**
172  * Set the pseudonym metadata, rank and name.
173  *
174  * @param cfg overall configuration
175  * @param nsid id of the pseudonym
176  * @param name name to set. Must be the non-unique version of it.
177  *        May be NULL, in which case it erases pseudonym's name!
178  * @param md metadata to set
179  *        May be NULL, in which case it erases pseudonym's metadata!
180  * @param rank rank to assign
181  * @return GNUNET_OK on success, GNUNET_SYSERR on failure
182  */
183 int
184 GNUNET_PSEUDONYM_set_info (const struct GNUNET_CONFIGURATION_Handle *cfg,
185     const struct GNUNET_HashCode * nsid, const char *name,
186     const struct GNUNET_CONTAINER_MetaData *md, int rank);
187
188
189 #if 0                           /* keep Emacsens' auto-indent happy */
190 {
191 #endif
192 #ifdef __cplusplus
193 }
194 #endif
195
196 /* ifndef GNUNET_PSEUDONYM_LIB_H */
197 #endif
198 /* end of gnunet_pseudonym_lib.h */