diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/fs/Makefile.am | 23 | ||||
-rw-r--r-- | src/fs/fs_pseudonym.c | 756 | ||||
-rw-r--r-- | src/fs/gnunet-pseudonym.c | 353 | ||||
-rw-r--r-- | src/fs/test_pseudonym.c | 223 | ||||
-rw-r--r-- | src/include/gnunet_fs_service.h | 174 |
5 files changed, 0 insertions, 1529 deletions
diff --git a/src/fs/Makefile.am b/src/fs/Makefile.am index ce70ff751..30a14e2c2 100644 --- a/src/fs/Makefile.am +++ b/src/fs/Makefile.am | |||
@@ -36,7 +36,6 @@ libgnunetfs_la_SOURCES = \ | |||
36 | fs_file_information.c \ | 36 | fs_file_information.c \ |
37 | fs_getopt.c \ | 37 | fs_getopt.c \ |
38 | fs_list_indexed.c \ | 38 | fs_list_indexed.c \ |
39 | fs_pseudonym.c \ | ||
40 | fs_publish.c \ | 39 | fs_publish.c \ |
41 | fs_publish_ksk.c \ | 40 | fs_publish_ksk.c \ |
42 | fs_publish_ublock.c fs_publish_ublock.h \ | 41 | fs_publish_ublock.c fs_publish_ublock.h \ |
@@ -80,7 +79,6 @@ bin_PROGRAMS = \ | |||
80 | gnunet-directory \ | 79 | gnunet-directory \ |
81 | gnunet-download \ | 80 | gnunet-download \ |
82 | gnunet-publish \ | 81 | gnunet-publish \ |
83 | gnunet-pseudonym \ | ||
84 | gnunet-search \ | 82 | gnunet-search \ |
85 | gnunet-fs \ | 83 | gnunet-fs \ |
86 | gnunet-unindex | 84 | gnunet-unindex |
@@ -153,17 +151,6 @@ gnunet_helper_fs_publish_LDADD = \ | |||
153 | gnunet_helper_fs_publish_DEPENDENCIES = \ | 151 | gnunet_helper_fs_publish_DEPENDENCIES = \ |
154 | libgnunetfs.la | 152 | libgnunetfs.la |
155 | 153 | ||
156 | gnunet_pseudonym_SOURCES = \ | ||
157 | gnunet-pseudonym.c | ||
158 | gnunet_pseudonym_LDADD = \ | ||
159 | $(top_builddir)/src/identity/libgnunetidentity.la \ | ||
160 | $(top_builddir)/src/fs/libgnunetfs.la \ | ||
161 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
162 | -lextractor \ | ||
163 | $(GN_LIBINTL) | ||
164 | gnunet_pseudonym_DEPENDENCIES = \ | ||
165 | libgnunetfs.la | ||
166 | |||
167 | gnunet_search_SOURCES = \ | 154 | gnunet_search_SOURCES = \ |
168 | gnunet-search.c | 155 | gnunet-search.c |
169 | gnunet_search_LDADD = \ | 156 | gnunet_search_LDADD = \ |
@@ -256,7 +243,6 @@ check_PROGRAMS = \ | |||
256 | test_fs_list_indexed \ | 243 | test_fs_list_indexed \ |
257 | test_fs_namespace \ | 244 | test_fs_namespace \ |
258 | test_fs_namespace_list_updateable \ | 245 | test_fs_namespace_list_updateable \ |
259 | test_pseudonym \ | ||
260 | test_fs_publish \ | 246 | test_fs_publish \ |
261 | test_fs_publish_persistence \ | 247 | test_fs_publish_persistence \ |
262 | test_fs_search \ | 248 | test_fs_search \ |
@@ -303,7 +289,6 @@ TESTS = \ | |||
303 | test_fs_list_indexed \ | 289 | test_fs_list_indexed \ |
304 | test_fs_namespace \ | 290 | test_fs_namespace \ |
305 | test_fs_namespace_list_updateable \ | 291 | test_fs_namespace_list_updateable \ |
306 | test_pseudonym \ | ||
307 | test_fs_publish \ | 292 | test_fs_publish \ |
308 | test_fs_publish_persistence \ | 293 | test_fs_publish_persistence \ |
309 | test_fs_search \ | 294 | test_fs_search \ |
@@ -324,14 +309,6 @@ TESTS = \ | |||
324 | endif | 309 | endif |
325 | 310 | ||
326 | 311 | ||
327 | test_pseudonym_SOURCES = \ | ||
328 | test_pseudonym.c | ||
329 | test_pseudonym_LDADD = \ | ||
330 | -lgcrypt \ | ||
331 | $(top_builddir)/src/fs/libgnunetfs.la \ | ||
332 | $(top_builddir)/src/util/libgnunetutil.la | ||
333 | |||
334 | |||
335 | test_fs_directory_SOURCES = \ | 312 | test_fs_directory_SOURCES = \ |
336 | test_fs_directory.c | 313 | test_fs_directory.c |
337 | test_fs_directory_LDADD = \ | 314 | test_fs_directory_LDADD = \ |
diff --git a/src/fs/fs_pseudonym.c b/src/fs/fs_pseudonym.c deleted file mode 100644 index 2600e51eb..000000000 --- a/src/fs/fs_pseudonym.c +++ /dev/null | |||
@@ -1,756 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | (C) 2003-2013 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 | * @file fs/fs_pseudonym.c | ||
22 | * @brief pseudonym functions; these functions are about namespaces | ||
23 | * managed by other users; we might want to eliminate this | ||
24 | * entire API and instead manage pseudonyms only via GNS | ||
25 | * @author Christian Grothoff | ||
26 | */ | ||
27 | #include "platform.h" | ||
28 | #include "gnunet_util_lib.h" | ||
29 | #include "gnunet_fs_service.h" | ||
30 | |||
31 | |||
32 | #define LOG(kind,...) GNUNET_log_from (kind, "util", __VA_ARGS__) | ||
33 | |||
34 | #define LOG_STRERROR(kind,syscall) GNUNET_log_from_strerror (kind, "util", syscall) | ||
35 | |||
36 | #define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file (kind, "util", syscall, filename) | ||
37 | |||
38 | |||
39 | /** | ||
40 | * Name of the directory which stores meta data for pseudonym | ||
41 | */ | ||
42 | #define PS_METADATA_DIR DIR_SEPARATOR_STR "data" DIR_SEPARATOR_STR "pseudonym" DIR_SEPARATOR_STR "metadata" DIR_SEPARATOR_STR | ||
43 | |||
44 | /** | ||
45 | * Name of the directory which stores names for pseudonyms | ||
46 | */ | ||
47 | #define PS_NAMES_DIR DIR_SEPARATOR_STR "data" DIR_SEPARATOR_STR "pseudonym" DIR_SEPARATOR_STR "names" DIR_SEPARATOR_STR | ||
48 | |||
49 | |||
50 | /** | ||
51 | * Configuration section we use. | ||
52 | */ | ||
53 | #define GNUNET_CLIENT_SERVICE_NAME "fs" | ||
54 | |||
55 | |||
56 | /* ************************* Disk operations (pseudonym data mgmt) **************** */ | ||
57 | |||
58 | /** | ||
59 | * Registered callbacks for discovery of pseudonyms. | ||
60 | */ | ||
61 | struct GNUNET_FS_Pseudonym_DiscoveryHandle | ||
62 | { | ||
63 | /** | ||
64 | * This is a doubly linked list. | ||
65 | */ | ||
66 | struct GNUNET_FS_Pseudonym_DiscoveryHandle *next; | ||
67 | |||
68 | /** | ||
69 | * This is a doubly linked list. | ||
70 | */ | ||
71 | struct GNUNET_FS_Pseudonym_DiscoveryHandle *prev; | ||
72 | |||
73 | /** | ||
74 | * Function to call each time a pseudonym is discovered. | ||
75 | */ | ||
76 | GNUNET_FS_PseudonymIterator callback; | ||
77 | |||
78 | /** | ||
79 | * Closure for callback. | ||
80 | */ | ||
81 | void *callback_cls; | ||
82 | }; | ||
83 | |||
84 | |||
85 | /** | ||
86 | * Head of the linked list of functions to call when | ||
87 | * new pseudonyms are added. | ||
88 | */ | ||
89 | static struct GNUNET_FS_Pseudonym_DiscoveryHandle *disco_head; | ||
90 | |||
91 | /** | ||
92 | * Tail of the linked list of functions to call when | ||
93 | * new pseudonyms are added. | ||
94 | */ | ||
95 | static struct GNUNET_FS_Pseudonym_DiscoveryHandle *disco_tail; | ||
96 | |||
97 | |||
98 | /** | ||
99 | * Internal notification about new tracked URI. | ||
100 | * | ||
101 | * @param pseudonym public key of the pseudonym | ||
102 | * @param md meta data to be written | ||
103 | * @param rating rating of pseudonym | ||
104 | */ | ||
105 | static void | ||
106 | internal_notify (const struct GNUNET_CRYPTO_EccPublicKey *pseudonym, | ||
107 | const struct GNUNET_CONTAINER_MetaData *md, int rating) | ||
108 | { | ||
109 | struct GNUNET_FS_Pseudonym_DiscoveryHandle *pos; | ||
110 | |||
111 | for (pos = disco_head; NULL != pos; pos = pos->next) | ||
112 | pos->callback (pos->callback_cls, pseudonym, NULL, NULL, md, rating); | ||
113 | } | ||
114 | |||
115 | |||
116 | /** | ||
117 | * Register callback to be invoked whenever we discover | ||
118 | * a new pseudonym. | ||
119 | * Will immediately call provided iterator callback for all | ||
120 | * already discovered pseudonyms. | ||
121 | * | ||
122 | * @param cfg configuration to use | ||
123 | * @param iterator iterator over pseudonym | ||
124 | * @param iterator_cls point to a closure | ||
125 | * @return registration handle | ||
126 | */ | ||
127 | struct GNUNET_FS_Pseudonym_DiscoveryHandle * | ||
128 | GNUNET_FS_pseudonym_discovery_callback_register (const struct | ||
129 | GNUNET_CONFIGURATION_Handle *cfg, | ||
130 | GNUNET_FS_PseudonymIterator iterator, | ||
131 | void *iterator_cls) | ||
132 | { | ||
133 | struct GNUNET_FS_Pseudonym_DiscoveryHandle *dh; | ||
134 | |||
135 | dh = GNUNET_new (struct GNUNET_FS_Pseudonym_DiscoveryHandle); | ||
136 | dh->callback = iterator; | ||
137 | dh->callback_cls = iterator_cls; | ||
138 | GNUNET_CONTAINER_DLL_insert (disco_head, disco_tail, dh); | ||
139 | GNUNET_FS_pseudonym_list_all (cfg, iterator, iterator_cls); | ||
140 | return dh; | ||
141 | } | ||
142 | |||
143 | |||
144 | /** | ||
145 | * Unregister pseudonym discovery callback. | ||
146 | * | ||
147 | * @param dh registration to unregister | ||
148 | */ | ||
149 | void | ||
150 | GNUNET_FS_pseudonym_discovery_callback_unregister (struct GNUNET_FS_Pseudonym_DiscoveryHandle *dh) | ||
151 | { | ||
152 | GNUNET_CONTAINER_DLL_remove (disco_head, disco_tail, dh); | ||
153 | GNUNET_free (dh); | ||
154 | } | ||
155 | |||
156 | |||
157 | /** | ||
158 | * Get the filename (or directory name) for the given | ||
159 | * pseudonym identifier and directory prefix. | ||
160 | * | ||
161 | * @param cfg configuration to use | ||
162 | * @param prefix path components to append to the private directory name | ||
163 | * @param pseudonym the pseudonym, can be NULL | ||
164 | * @return filename of the pseudonym (if pseudonym != NULL) or directory with the data (if pseudonym == NULL) | ||
165 | */ | ||
166 | static char * | ||
167 | get_data_filename (const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
168 | const char *prefix, | ||
169 | const struct GNUNET_CRYPTO_EccPublicKey *pseudonym) | ||
170 | { | ||
171 | struct GNUNET_CRYPTO_HashAsciiEncoded enc; | ||
172 | struct GNUNET_HashCode psid; | ||
173 | |||
174 | if (NULL != pseudonym) | ||
175 | { | ||
176 | GNUNET_CRYPTO_hash (pseudonym, | ||
177 | sizeof (struct GNUNET_CRYPTO_EccPublicKey), | ||
178 | &psid); | ||
179 | GNUNET_CRYPTO_hash_to_enc (&psid, &enc); | ||
180 | } | ||
181 | return GNUNET_DISK_get_home_filename (cfg, | ||
182 | GNUNET_CLIENT_SERVICE_NAME, prefix, | ||
183 | (NULL == pseudonym) | ||
184 | ? NULL | ||
185 | : (const char *) &enc, | ||
186 | NULL); | ||
187 | } | ||
188 | |||
189 | |||
190 | /** | ||
191 | * Get the filename (or directory name) for the given | ||
192 | * hash code and directory prefix. | ||
193 | * | ||
194 | * @param cfg configuration to use | ||
195 | * @param prefix path components to append to the private directory name | ||
196 | * @param hc some hash code | ||
197 | * @return filename of the pseudonym (if hc != NULL) or directory with the data (if hc == NULL) | ||
198 | */ | ||
199 | static char * | ||
200 | get_data_filename_hash (const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
201 | const char *prefix, | ||
202 | const struct GNUNET_HashCode *hc) | ||
203 | { | ||
204 | struct GNUNET_CRYPTO_HashAsciiEncoded enc; | ||
205 | |||
206 | if (NULL != hc) | ||
207 | GNUNET_CRYPTO_hash_to_enc (hc, &enc); | ||
208 | return GNUNET_DISK_get_home_filename (cfg, | ||
209 | GNUNET_CLIENT_SERVICE_NAME, prefix, | ||
210 | (NULL == hc) | ||
211 | ? NULL | ||
212 | : (const char *) &enc, | ||
213 | NULL); | ||
214 | } | ||
215 | |||
216 | |||
217 | /** | ||
218 | * Set the pseudonym metadata, rank and name. | ||
219 | * Writes the pseudonym infomation into a file | ||
220 | * | ||
221 | * @param cfg overall configuration | ||
222 | * @param pseudonym id of the pseudonym | ||
223 | * @param name name to set. Must be the non-unique version of it. | ||
224 | * May be NULL, in which case it erases pseudonym's name! | ||
225 | * @param md metadata to set | ||
226 | * May be NULL, in which case it erases pseudonym's metadata! | ||
227 | * @param rank rank to assign | ||
228 | * @return GNUNET_OK on success, GNUNET_SYSERR on failure | ||
229 | */ | ||
230 | int | ||
231 | GNUNET_FS_pseudonym_set_info (const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
232 | const struct GNUNET_CRYPTO_EccPublicKey *pseudonym, | ||
233 | const char *name, | ||
234 | const struct GNUNET_CONTAINER_MetaData *md, | ||
235 | int32_t rank) | ||
236 | { | ||
237 | char *fn; | ||
238 | struct GNUNET_BIO_WriteHandle *fileW; | ||
239 | |||
240 | fn = get_data_filename (cfg, PS_METADATA_DIR, pseudonym); | ||
241 | if (NULL == (fileW = GNUNET_BIO_write_open (fn))) | ||
242 | { | ||
243 | GNUNET_free (fn); | ||
244 | return GNUNET_SYSERR; | ||
245 | } | ||
246 | if ((GNUNET_OK != GNUNET_BIO_write (fileW, pseudonym, | ||
247 | sizeof (struct GNUNET_CRYPTO_EccPublicKey))) || | ||
248 | (GNUNET_OK != GNUNET_BIO_write_int32 (fileW, rank)) || | ||
249 | (GNUNET_OK != GNUNET_BIO_write_string (fileW, name)) || | ||
250 | (GNUNET_OK != GNUNET_BIO_write_meta_data (fileW, md))) | ||
251 | { | ||
252 | (void) GNUNET_BIO_write_close (fileW); | ||
253 | GNUNET_break (GNUNET_OK == GNUNET_DISK_directory_remove (fn)); | ||
254 | GNUNET_free (fn); | ||
255 | return GNUNET_SYSERR; | ||
256 | } | ||
257 | if (GNUNET_OK != GNUNET_BIO_write_close (fileW)) | ||
258 | { | ||
259 | GNUNET_break (GNUNET_OK == GNUNET_DISK_directory_remove (fn)); | ||
260 | GNUNET_free (fn); | ||
261 | return GNUNET_SYSERR; | ||
262 | } | ||
263 | GNUNET_free (fn); | ||
264 | /* create entry for pseudonym name in names */ | ||
265 | if (NULL != name) | ||
266 | GNUNET_free_non_null (GNUNET_FS_pseudonym_name_uniquify (cfg, pseudonym, | ||
267 | name, NULL)); | ||
268 | return GNUNET_OK; | ||
269 | } | ||
270 | |||
271 | |||
272 | /** | ||
273 | * Read pseudonym infomation from a file | ||
274 | * | ||
275 | * @param cfg configuration to use | ||
276 | * @param pseudonym hash code of a pseudonym | ||
277 | * @param meta meta data to be read from a file | ||
278 | * @param rank rank of a pseudonym | ||
279 | * @param ns_name name of a pseudonym | ||
280 | * @return GNUNET_OK on success, GNUNET_SYSERR on error | ||
281 | */ | ||
282 | static int | ||
283 | read_info (const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
284 | const struct GNUNET_CRYPTO_EccPublicKey *pseudonym, | ||
285 | struct GNUNET_CONTAINER_MetaData **meta, | ||
286 | int32_t *rank, | ||
287 | char **ns_name) | ||
288 | { | ||
289 | struct GNUNET_CRYPTO_EccPublicKey pd; | ||
290 | char *fn; | ||
291 | char *emsg; | ||
292 | struct GNUNET_BIO_ReadHandle *fileR; | ||
293 | |||
294 | fn = get_data_filename (cfg, PS_METADATA_DIR, pseudonym); | ||
295 | if (GNUNET_YES != | ||
296 | GNUNET_DISK_file_test (fn)) | ||
297 | { | ||
298 | GNUNET_free (fn); | ||
299 | return GNUNET_SYSERR; | ||
300 | } | ||
301 | if (NULL == (fileR = GNUNET_BIO_read_open (fn))) | ||
302 | { | ||
303 | GNUNET_free (fn); | ||
304 | return GNUNET_SYSERR; | ||
305 | } | ||
306 | emsg = NULL; | ||
307 | *ns_name = NULL; | ||
308 | if ( (GNUNET_OK != GNUNET_BIO_read (fileR, "pseudonym", &pd, sizeof (pd))) || | ||
309 | (0 != memcmp (&pd, pseudonym, sizeof (pd))) || | ||
310 | (GNUNET_OK != GNUNET_BIO_read_int32 (fileR, rank)) || | ||
311 | (GNUNET_OK != | ||
312 | GNUNET_BIO_read_string (fileR, "Read string error!", ns_name, 200)) || | ||
313 | (GNUNET_OK != | ||
314 | GNUNET_BIO_read_meta_data (fileR, "Read meta data error!", meta)) ) | ||
315 | { | ||
316 | (void) GNUNET_BIO_read_close (fileR, &emsg); | ||
317 | GNUNET_free_non_null (emsg); | ||
318 | GNUNET_free_non_null (*ns_name); | ||
319 | *ns_name = NULL; | ||
320 | GNUNET_break (GNUNET_OK == GNUNET_DISK_directory_remove (fn)); | ||
321 | GNUNET_free (fn); | ||
322 | return GNUNET_SYSERR; | ||
323 | } | ||
324 | if (GNUNET_OK != GNUNET_BIO_read_close (fileR, &emsg)) | ||
325 | { | ||
326 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
327 | _("Failed to parse metadata about pseudonym from file `%s': %s\n"), fn, | ||
328 | emsg); | ||
329 | GNUNET_break (GNUNET_OK == GNUNET_DISK_directory_remove (fn)); | ||
330 | GNUNET_CONTAINER_meta_data_destroy (*meta); | ||
331 | *meta = NULL; | ||
332 | GNUNET_free_non_null (*ns_name); | ||
333 | *ns_name = NULL; | ||
334 | GNUNET_free_non_null (emsg); | ||
335 | GNUNET_free (fn); | ||
336 | return GNUNET_SYSERR; | ||
337 | } | ||
338 | GNUNET_free (fn); | ||
339 | return GNUNET_OK; | ||
340 | } | ||
341 | |||
342 | |||
343 | /** | ||
344 | * Return unique variant of the namespace name. Use it after | ||
345 | * GNUNET_FS_pseudonym_get_info() to make sure that name is unique. | ||
346 | * | ||
347 | * @param cfg configuration | ||
348 | * @param pseudonym public key of the pseudonym | ||
349 | * @param name name to uniquify | ||
350 | * @param suffix if not NULL, filled with the suffix value | ||
351 | * @return NULL on failure (should never happen), name on success. | ||
352 | * Free the name with GNUNET_free(). | ||
353 | */ | ||
354 | char * | ||
355 | GNUNET_FS_pseudonym_name_uniquify (const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
356 | const struct GNUNET_CRYPTO_EccPublicKey *pseudonym, | ||
357 | const char *name, | ||
358 | unsigned int *suffix) | ||
359 | { | ||
360 | struct GNUNET_HashCode nh; | ||
361 | struct GNUNET_CRYPTO_EccPublicKey pi; | ||
362 | uint64_t len; | ||
363 | char *fn; | ||
364 | struct GNUNET_DISK_FileHandle *fh; | ||
365 | unsigned int i; | ||
366 | unsigned int idx; | ||
367 | char *ret; | ||
368 | struct stat sbuf; | ||
369 | |||
370 | GNUNET_CRYPTO_hash (name, strlen (name), &nh); | ||
371 | fn = get_data_filename_hash (cfg, PS_NAMES_DIR, &nh); | ||
372 | len = 0; | ||
373 | if (0 == STAT (fn, &sbuf)) | ||
374 | GNUNET_break (GNUNET_OK == GNUNET_DISK_file_size (fn, &len, GNUNET_YES, GNUNET_YES)); | ||
375 | fh = GNUNET_DISK_file_open (fn, | ||
376 | GNUNET_DISK_OPEN_CREATE | | ||
377 | GNUNET_DISK_OPEN_READWRITE, | ||
378 | GNUNET_DISK_PERM_USER_READ | | ||
379 | GNUNET_DISK_PERM_USER_WRITE); | ||
380 | i = 0; | ||
381 | idx = -1; | ||
382 | while ((len >= sizeof (struct GNUNET_CRYPTO_EccPublicKey)) && | ||
383 | (sizeof (struct GNUNET_CRYPTO_EccPublicKey) == | ||
384 | GNUNET_DISK_file_read (fh, &pi, sizeof (struct GNUNET_CRYPTO_EccPublicKey)))) | ||
385 | { | ||
386 | if (0 == memcmp (&pi, pseudonym, sizeof (struct GNUNET_CRYPTO_EccPublicKey))) | ||
387 | { | ||
388 | idx = i; | ||
389 | break; | ||
390 | } | ||
391 | i++; | ||
392 | len -= sizeof (struct GNUNET_HashCode); | ||
393 | } | ||
394 | if (-1 == idx) | ||
395 | { | ||
396 | idx = i; | ||
397 | if (sizeof (struct GNUNET_CRYPTO_EccPublicKey) != | ||
398 | GNUNET_DISK_file_write (fh, pseudonym, | ||
399 | sizeof (struct GNUNET_CRYPTO_EccPublicKey))) | ||
400 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "write", fn); | ||
401 | } | ||
402 | GNUNET_DISK_file_close (fh); | ||
403 | ret = GNUNET_malloc (strlen (name) + 32); | ||
404 | GNUNET_snprintf (ret, strlen (name) + 32, "%s-%u", name, idx); | ||
405 | if (suffix != NULL) | ||
406 | *suffix = idx; | ||
407 | GNUNET_free (fn); | ||
408 | return ret; | ||
409 | } | ||
410 | |||
411 | |||
412 | /** | ||
413 | * Get namespace name, metadata and rank | ||
414 | * This is a wrapper around internal read_info() call, and ensures that | ||
415 | * returned data is not invalid (not NULL). | ||
416 | * | ||
417 | * @param cfg configuration | ||
418 | * @param pseudonym public key of the pseudonym | ||
419 | * @param ret_meta a location to store metadata pointer. NULL, if metadata | ||
420 | * is not needed. Destroy with GNUNET_CONTAINER_meta_data_destroy(). | ||
421 | * @param ret_rank a location to store rank. NULL, if rank not needed. | ||
422 | * @param ret_name a location to store human-readable name. Name is not unique. | ||
423 | * NULL, if name is not needed. Free with GNUNET_free(). | ||
424 | * @param name_is_a_dup is set to GNUNET_YES, if ret_name was filled with | ||
425 | * a duplicate of a "no-name" placeholder | ||
426 | * @return GNUNET_OK on success. GNUENT_SYSERR if the data was | ||
427 | * unobtainable (in that case ret_* are filled with placeholders - | ||
428 | * empty metadata container, rank -1 and a "no-name" name). | ||
429 | */ | ||
430 | int | ||
431 | GNUNET_FS_pseudonym_get_info (const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
432 | const struct GNUNET_CRYPTO_EccPublicKey *pseudonym, | ||
433 | struct GNUNET_CONTAINER_MetaData **ret_meta, | ||
434 | int32_t *ret_rank, | ||
435 | char **ret_name, | ||
436 | int *name_is_a_dup) | ||
437 | { | ||
438 | struct GNUNET_CONTAINER_MetaData *meta; | ||
439 | char *name; | ||
440 | int32_t rank = -1; | ||
441 | |||
442 | meta = NULL; | ||
443 | name = NULL; | ||
444 | if (GNUNET_OK == read_info (cfg, pseudonym, &meta, &rank, &name)) | ||
445 | { | ||
446 | if ((meta != NULL) && (name == NULL)) | ||
447 | name = | ||
448 | GNUNET_CONTAINER_meta_data_get_first_by_types (meta, | ||
449 | EXTRACTOR_METATYPE_TITLE, | ||
450 | EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME, | ||
451 | EXTRACTOR_METATYPE_FILENAME, | ||
452 | EXTRACTOR_METATYPE_DESCRIPTION, | ||
453 | EXTRACTOR_METATYPE_SUBJECT, | ||
454 | EXTRACTOR_METATYPE_PUBLISHER, | ||
455 | EXTRACTOR_METATYPE_AUTHOR_NAME, | ||
456 | EXTRACTOR_METATYPE_COMMENT, | ||
457 | EXTRACTOR_METATYPE_SUMMARY, | ||
458 | -1); | ||
459 | if (ret_name != NULL) | ||
460 | { | ||
461 | if (name == NULL) | ||
462 | { | ||
463 | name = GNUNET_strdup (_("no-name")); | ||
464 | if (name_is_a_dup != NULL) | ||
465 | *name_is_a_dup = GNUNET_YES; | ||
466 | } | ||
467 | else if (name_is_a_dup != NULL) | ||
468 | *name_is_a_dup = GNUNET_NO; | ||
469 | *ret_name = name; | ||
470 | } | ||
471 | else if (name != NULL) | ||
472 | GNUNET_free (name); | ||
473 | |||
474 | if (ret_meta != NULL) | ||
475 | { | ||
476 | if (meta == NULL) | ||
477 | meta = GNUNET_CONTAINER_meta_data_create (); | ||
478 | *ret_meta = meta; | ||
479 | } | ||
480 | else if (meta != NULL) | ||
481 | GNUNET_CONTAINER_meta_data_destroy (meta); | ||
482 | |||
483 | if (ret_rank != NULL) | ||
484 | *ret_rank = rank; | ||
485 | |||
486 | return GNUNET_OK; | ||
487 | } | ||
488 | if (ret_name != NULL) | ||
489 | *ret_name = GNUNET_strdup (_("no-name")); | ||
490 | if (ret_meta != NULL) | ||
491 | *ret_meta = GNUNET_CONTAINER_meta_data_create (); | ||
492 | if (ret_rank != NULL) | ||
493 | *ret_rank = -1; | ||
494 | if (name_is_a_dup != NULL) | ||
495 | *name_is_a_dup = GNUNET_YES; | ||
496 | return GNUNET_SYSERR; | ||
497 | } | ||
498 | |||
499 | |||
500 | /** | ||
501 | * Get the namespace ID belonging to the given namespace name. | ||
502 | * | ||
503 | * @param cfg configuration to use | ||
504 | * @param ns_uname unique (!) human-readable name for the namespace | ||
505 | * @param pseudonym set to public key of pseudonym based on 'ns_uname' | ||
506 | * @return GNUNET_OK on success, GNUNET_SYSERR on failure | ||
507 | */ | ||
508 | int | ||
509 | GNUNET_FS_pseudonym_name_to_id (const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
510 | const char *ns_uname, | ||
511 | struct GNUNET_CRYPTO_EccPublicKey *pseudonym) | ||
512 | { | ||
513 | size_t slen; | ||
514 | uint64_t len; | ||
515 | unsigned int idx; | ||
516 | char *name; | ||
517 | struct GNUNET_HashCode nh; | ||
518 | char *fn; | ||
519 | struct GNUNET_DISK_FileHandle *fh; | ||
520 | |||
521 | idx = -1; | ||
522 | slen = strlen (ns_uname); | ||
523 | while ((slen > 0) && (1 != SSCANF (&ns_uname[slen - 1], "-%u", &idx))) | ||
524 | slen--; | ||
525 | if (0 == slen) | ||
526 | return GNUNET_SYSERR; | ||
527 | name = GNUNET_strdup (ns_uname); | ||
528 | name[slen - 1] = '\0'; | ||
529 | |||
530 | GNUNET_CRYPTO_hash (name, strlen (name), &nh); | ||
531 | GNUNET_free (name); | ||
532 | fn = get_data_filename_hash (cfg, PS_NAMES_DIR, &nh); | ||
533 | |||
534 | if ((GNUNET_OK != GNUNET_DISK_file_test (fn) || | ||
535 | (GNUNET_OK != GNUNET_DISK_file_size (fn, &len, GNUNET_YES, GNUNET_YES))) || | ||
536 | ((idx + 1) * sizeof (struct GNUNET_CRYPTO_EccPublicKey) > len)) | ||
537 | { | ||
538 | GNUNET_free (fn); | ||
539 | return GNUNET_SYSERR; | ||
540 | } | ||
541 | fh = GNUNET_DISK_file_open (fn, | ||
542 | GNUNET_DISK_OPEN_CREATE | | ||
543 | GNUNET_DISK_OPEN_READWRITE, | ||
544 | GNUNET_DISK_PERM_USER_READ | | ||
545 | GNUNET_DISK_PERM_USER_WRITE); | ||
546 | GNUNET_free (fn); | ||
547 | if (GNUNET_SYSERR == | ||
548 | GNUNET_DISK_file_seek (fh, idx * sizeof (struct GNUNET_CRYPTO_EccPublicKey), | ||
549 | GNUNET_DISK_SEEK_SET)) | ||
550 | { | ||
551 | GNUNET_DISK_file_close (fh); | ||
552 | return GNUNET_SYSERR; | ||
553 | } | ||
554 | if (sizeof (struct GNUNET_CRYPTO_EccPublicKey) != | ||
555 | GNUNET_DISK_file_read (fh, pseudonym, | ||
556 | sizeof (struct GNUNET_CRYPTO_EccPublicKey))) | ||
557 | { | ||
558 | GNUNET_DISK_file_close (fh); | ||
559 | return GNUNET_SYSERR; | ||
560 | } | ||
561 | GNUNET_DISK_file_close (fh); | ||
562 | return GNUNET_OK; | ||
563 | } | ||
564 | |||
565 | |||
566 | /** | ||
567 | * struct used to list the pseudonym | ||
568 | */ | ||
569 | struct ListPseudonymClosure | ||
570 | { | ||
571 | |||
572 | /** | ||
573 | * iterator over pseudonym | ||
574 | */ | ||
575 | GNUNET_FS_PseudonymIterator iterator; | ||
576 | |||
577 | /** | ||
578 | * Closure for iterator. | ||
579 | */ | ||
580 | void *iterator_cls; | ||
581 | |||
582 | /** | ||
583 | * Configuration to use. | ||
584 | */ | ||
585 | const struct GNUNET_CONFIGURATION_Handle *cfg; | ||
586 | }; | ||
587 | |||
588 | |||
589 | |||
590 | /** | ||
591 | * Helper function to list all available pseudonyms | ||
592 | * | ||
593 | * @param cls point to a struct ListPseudonymClosure | ||
594 | * @param fullname name of pseudonym | ||
595 | */ | ||
596 | static int | ||
597 | list_pseudonym_helper (void *cls, const char *fullname) | ||
598 | { | ||
599 | struct ListPseudonymClosure *lpc = cls; | ||
600 | struct GNUNET_CRYPTO_EccPublicKey pd; | ||
601 | char *emsg; | ||
602 | struct GNUNET_BIO_ReadHandle *fileR; | ||
603 | int32_t rank; | ||
604 | char *ns_name; | ||
605 | struct GNUNET_CONTAINER_MetaData *meta; | ||
606 | int ret; | ||
607 | char *name_unique; | ||
608 | |||
609 | if (NULL == (fileR = GNUNET_BIO_read_open (fullname))) | ||
610 | return GNUNET_SYSERR; | ||
611 | emsg = NULL; | ||
612 | ns_name = NULL; | ||
613 | if ( (GNUNET_OK != GNUNET_BIO_read (fileR, "pseudonym", &pd, sizeof (pd))) || | ||
614 | (GNUNET_OK != GNUNET_BIO_read_int32 (fileR, &rank)) || | ||
615 | (GNUNET_OK != | ||
616 | GNUNET_BIO_read_string (fileR, "Read string error!", &ns_name, 200)) || | ||
617 | (GNUNET_OK != | ||
618 | GNUNET_BIO_read_meta_data (fileR, "Read meta data error!", &meta)) ) | ||
619 | { | ||
620 | (void) GNUNET_BIO_read_close (fileR, &emsg); | ||
621 | GNUNET_free_non_null (emsg); | ||
622 | GNUNET_free_non_null (ns_name); | ||
623 | GNUNET_break (GNUNET_OK == GNUNET_DISK_directory_remove (fullname)); | ||
624 | return GNUNET_SYSERR; | ||
625 | } | ||
626 | if (NULL == ns_name) | ||
627 | ns_name = GNUNET_strdup (_("no-name")); | ||
628 | if (GNUNET_OK != GNUNET_BIO_read_close (fileR, &emsg)) | ||
629 | { | ||
630 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
631 | _("Failed to parse metadata about pseudonym from file `%s': %s\n"), fullname, | ||
632 | emsg); | ||
633 | GNUNET_break (GNUNET_OK == GNUNET_DISK_directory_remove (fullname)); | ||
634 | GNUNET_CONTAINER_meta_data_destroy (meta); | ||
635 | GNUNET_free (ns_name); | ||
636 | GNUNET_free_non_null (emsg); | ||
637 | return GNUNET_SYSERR; | ||
638 | } | ||
639 | ret = GNUNET_OK; | ||
640 | name_unique = GNUNET_FS_pseudonym_name_uniquify (lpc->cfg, &pd, ns_name, NULL); | ||
641 | if (NULL != lpc->iterator) | ||
642 | ret = lpc->iterator (lpc->iterator_cls, &pd, ns_name, name_unique, meta, rank); | ||
643 | GNUNET_free (ns_name); | ||
644 | GNUNET_free_non_null (name_unique); | ||
645 | GNUNET_CONTAINER_meta_data_destroy (meta); | ||
646 | return ret; | ||
647 | } | ||
648 | |||
649 | |||
650 | /** | ||
651 | * List all available pseudonyms. | ||
652 | * | ||
653 | * @param cfg overall configuration | ||
654 | * @param iterator function to call for each pseudonym | ||
655 | * @param iterator_cls closure for iterator | ||
656 | * @return number of pseudonyms found | ||
657 | */ | ||
658 | int | ||
659 | GNUNET_FS_pseudonym_list_all (const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
660 | GNUNET_FS_PseudonymIterator iterator, | ||
661 | void *iterator_cls) | ||
662 | { | ||
663 | struct ListPseudonymClosure cls; | ||
664 | char *fn; | ||
665 | int ret; | ||
666 | |||
667 | cls.iterator = iterator; | ||
668 | cls.iterator_cls = iterator_cls; | ||
669 | cls.cfg = cfg; | ||
670 | fn = get_data_filename (cfg, PS_METADATA_DIR, NULL); | ||
671 | GNUNET_assert (fn != NULL); | ||
672 | GNUNET_DISK_directory_create (fn); | ||
673 | ret = GNUNET_DISK_directory_scan (fn, &list_pseudonym_helper, &cls); | ||
674 | GNUNET_free (fn); | ||
675 | return ret; | ||
676 | } | ||
677 | |||
678 | |||
679 | /** | ||
680 | * Change the rank of a pseudonym. | ||
681 | * | ||
682 | * @param cfg overall configuration | ||
683 | * @param pseudonym the pseudonym | ||
684 | * @param delta by how much should the rating be changed? | ||
685 | * @return new rating of the pseudonym | ||
686 | */ | ||
687 | int | ||
688 | GNUNET_FS_pseudonym_rank (const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
689 | const struct GNUNET_CRYPTO_EccPublicKey *pseudonym, | ||
690 | int32_t delta) | ||
691 | { | ||
692 | struct GNUNET_CONTAINER_MetaData *meta; | ||
693 | int ret; | ||
694 | int32_t rank; | ||
695 | char *name; | ||
696 | |||
697 | name = NULL; | ||
698 | ret = read_info (cfg, pseudonym, &meta, &rank, &name); | ||
699 | if (ret == GNUNET_SYSERR) | ||
700 | { | ||
701 | rank = 0; | ||
702 | meta = GNUNET_CONTAINER_meta_data_create (); | ||
703 | } | ||
704 | rank += delta; | ||
705 | GNUNET_FS_pseudonym_set_info (cfg, pseudonym, name, meta, rank); | ||
706 | GNUNET_CONTAINER_meta_data_destroy (meta); | ||
707 | GNUNET_free_non_null (name); | ||
708 | return rank; | ||
709 | } | ||
710 | |||
711 | |||
712 | /** | ||
713 | * Add a pseudonym to the set of known pseudonyms. | ||
714 | * For all pseudonym advertisements that we discover | ||
715 | * FS should automatically call this function. | ||
716 | * | ||
717 | * @param cfg overall configuration | ||
718 | * @param pseudonym the pseudonym to add | ||
719 | * @param meta metadata for the pseudonym | ||
720 | * @return GNUNET_OK on success, GNUNET_SYSERR on failure | ||
721 | */ | ||
722 | int | ||
723 | GNUNET_FS_pseudonym_add (const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
724 | const struct GNUNET_CRYPTO_EccPublicKey *pseudonym, | ||
725 | const struct GNUNET_CONTAINER_MetaData *meta) | ||
726 | { | ||
727 | char *name; | ||
728 | int32_t rank; | ||
729 | struct GNUNET_CONTAINER_MetaData *old; | ||
730 | char *fn; | ||
731 | struct stat sbuf; | ||
732 | int ret; | ||
733 | |||
734 | rank = 0; | ||
735 | fn = get_data_filename (cfg, PS_METADATA_DIR, pseudonym); | ||
736 | GNUNET_assert (fn != NULL); | ||
737 | |||
738 | if ((0 == STAT (fn, &sbuf)) && | ||
739 | (GNUNET_OK == read_info (cfg, pseudonym, &old, &rank, &name))) | ||
740 | { | ||
741 | GNUNET_CONTAINER_meta_data_merge (old, meta); | ||
742 | ret = GNUNET_FS_pseudonym_set_info (cfg, pseudonym, name, old, rank); | ||
743 | GNUNET_CONTAINER_meta_data_destroy (old); | ||
744 | GNUNET_free_non_null (name); | ||
745 | } | ||
746 | else | ||
747 | { | ||
748 | ret = GNUNET_FS_pseudonym_set_info (cfg, pseudonym, NULL, meta, rank); | ||
749 | } | ||
750 | GNUNET_free (fn); | ||
751 | internal_notify (pseudonym, meta, rank); | ||
752 | return ret; | ||
753 | } | ||
754 | |||
755 | |||
756 | /* end of fs_pseudonym.c */ | ||
diff --git a/src/fs/gnunet-pseudonym.c b/src/fs/gnunet-pseudonym.c deleted file mode 100644 index a9c6be623..000000000 --- a/src/fs/gnunet-pseudonym.c +++ /dev/null | |||
@@ -1,353 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2001-2013 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 | * @file fs/gnunet-pseudonym.c | ||
22 | * @brief manage GNUnet namespaces / pseudonyms | ||
23 | * @author Christian Grothoff | ||
24 | */ | ||
25 | #include "platform.h" | ||
26 | #include "gnunet_fs_service.h" | ||
27 | #include "gnunet_identity_service.h" | ||
28 | |||
29 | |||
30 | /** | ||
31 | * -A option | ||
32 | */ | ||
33 | static char *advertise_ns; | ||
34 | |||
35 | /** | ||
36 | * -k option | ||
37 | */ | ||
38 | static struct GNUNET_FS_Uri *ksk_uri; | ||
39 | |||
40 | /** | ||
41 | * -m option. | ||
42 | */ | ||
43 | static struct GNUNET_CONTAINER_MetaData *adv_metadata; | ||
44 | |||
45 | /** | ||
46 | * Our block options (-p, -r, -a). | ||
47 | */ | ||
48 | static struct GNUNET_FS_BlockOptions bo = { {0LL}, 1, 365, 1 }; | ||
49 | |||
50 | /** | ||
51 | * -q option given. | ||
52 | */ | ||
53 | static int no_remote_printing; | ||
54 | |||
55 | /** | ||
56 | * -r option. | ||
57 | */ | ||
58 | static char *root_identifier; | ||
59 | |||
60 | /** | ||
61 | * -s option. | ||
62 | */ | ||
63 | static char *rating_change; | ||
64 | |||
65 | /** | ||
66 | * Handle to fs service. | ||
67 | */ | ||
68 | static struct GNUNET_FS_Handle *h; | ||
69 | |||
70 | /** | ||
71 | * Our configuration. | ||
72 | */ | ||
73 | static const struct GNUNET_CONFIGURATION_Handle *cfg; | ||
74 | |||
75 | /** | ||
76 | * Handle to identity service. | ||
77 | */ | ||
78 | static struct GNUNET_IDENTITY_Handle *identity; | ||
79 | |||
80 | /** | ||
81 | * Target namespace. | ||
82 | */ | ||
83 | static struct GNUNET_IDENTITY_Ego *namespace; | ||
84 | |||
85 | /** | ||
86 | * URI to advertise. | ||
87 | */ | ||
88 | static struct GNUNET_FS_Uri *sks_uri; | ||
89 | |||
90 | /** | ||
91 | * Global return value. | ||
92 | */ | ||
93 | static int ret; | ||
94 | |||
95 | |||
96 | /** | ||
97 | * Progress callback given to FS. | ||
98 | * | ||
99 | * @param cls unused | ||
100 | * @param info progress information, unused | ||
101 | */ | ||
102 | static void * | ||
103 | progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info) | ||
104 | { | ||
105 | return NULL; | ||
106 | } | ||
107 | |||
108 | |||
109 | /** | ||
110 | * Output information about a pseudonym. | ||
111 | * | ||
112 | * @param cls closure | ||
113 | * @param pseudonym hash code of public key of pseudonym | ||
114 | * @param name name of the pseudonym (might be NULL) | ||
115 | * @param unique_name unique name of the pseudonym (might be NULL) | ||
116 | * @param md meta data known about the pseudonym | ||
117 | * @param rating the local rating of the pseudonym | ||
118 | * @return GNUNET_OK to continue iteration, GNUNET_SYSERR to abort | ||
119 | */ | ||
120 | static int | ||
121 | pseudo_printer (void *cls, | ||
122 | const struct GNUNET_CRYPTO_EccPublicKey *pseudonym, | ||
123 | const char *name, | ||
124 | const char *unique_name, | ||
125 | const struct GNUNET_CONTAINER_MetaData *md, | ||
126 | int32_t rating) | ||
127 | { | ||
128 | char *id; | ||
129 | char *unique_id; | ||
130 | int getinfo_result; | ||
131 | |||
132 | /* While we get a name from the caller, it might be NULL. | ||
133 | * GNUNET_FS_pseudonym_get_info () never returns NULL. | ||
134 | */ | ||
135 | getinfo_result = GNUNET_FS_pseudonym_get_info (cfg, pseudonym, | ||
136 | NULL, NULL, &id, NULL); | ||
137 | if (GNUNET_OK != getinfo_result) | ||
138 | { | ||
139 | GNUNET_break (0); | ||
140 | return GNUNET_OK; | ||
141 | } | ||
142 | unique_id = GNUNET_FS_pseudonym_name_uniquify (cfg, pseudonym, id, NULL); | ||
143 | GNUNET_free (id); | ||
144 | FPRINTF (stdout, | ||
145 | "%s (%d):\n", | ||
146 | unique_id, rating); | ||
147 | GNUNET_CONTAINER_meta_data_iterate (md, &EXTRACTOR_meta_data_print, stdout); | ||
148 | FPRINTF (stdout, | ||
149 | "%s", | ||
150 | "\n"); | ||
151 | GNUNET_free (unique_id); | ||
152 | return GNUNET_OK; | ||
153 | } | ||
154 | |||
155 | |||
156 | /** | ||
157 | * Function called once advertising is finished. | ||
158 | * | ||
159 | * @param cls closure (NULL) | ||
160 | * @param uri the advertised URI | ||
161 | * @param emsg error message, NULL on success | ||
162 | */ | ||
163 | static void | ||
164 | post_advertising (void *cls, | ||
165 | const struct GNUNET_FS_Uri *uri, | ||
166 | const char *emsg) | ||
167 | { | ||
168 | if (emsg != NULL) | ||
169 | { | ||
170 | FPRINTF (stderr, "%s", emsg); | ||
171 | ret = 1; | ||
172 | } | ||
173 | GNUNET_FS_stop (h); | ||
174 | GNUNET_IDENTITY_disconnect (identity); | ||
175 | } | ||
176 | |||
177 | |||
178 | /** | ||
179 | * Function called by identity service with known pseudonyms. | ||
180 | * | ||
181 | * @param cls closure, NULL | ||
182 | * @param ego ego handle | ||
183 | * @param ctx context for application to store data for this ego | ||
184 | * (during the lifetime of this process, initially NULL) | ||
185 | * @param name name assigned by the user for this ego, | ||
186 | * NULL if the user just deleted the ego and it | ||
187 | * must thus no longer be used | ||
188 | */ | ||
189 | static void | ||
190 | identity_cb (void *cls, | ||
191 | struct GNUNET_IDENTITY_Ego *ego, | ||
192 | void **ctx, | ||
193 | const char *name) | ||
194 | { | ||
195 | char *emsg; | ||
196 | struct GNUNET_CRYPTO_EccPublicKey pub; | ||
197 | |||
198 | if (NULL == ego) | ||
199 | { | ||
200 | if (NULL == namespace) | ||
201 | { | ||
202 | ret = 1; | ||
203 | return; | ||
204 | } | ||
205 | if (NULL != root_identifier) | ||
206 | { | ||
207 | if (NULL == ksk_uri) | ||
208 | { | ||
209 | emsg = NULL; | ||
210 | ksk_uri = GNUNET_FS_uri_parse ("gnunet://fs/ksk/namespace", &emsg); | ||
211 | GNUNET_assert (NULL == emsg); | ||
212 | } | ||
213 | GNUNET_IDENTITY_ego_get_public_key (namespace, | ||
214 | &pub); | ||
215 | sks_uri = GNUNET_FS_uri_sks_create (&pub, | ||
216 | root_identifier); | ||
217 | GNUNET_FS_publish_ksk (h, ksk_uri, adv_metadata, sks_uri, | ||
218 | &bo, | ||
219 | GNUNET_FS_PUBLISH_OPTION_NONE, | ||
220 | &post_advertising, NULL); | ||
221 | GNUNET_FS_uri_destroy (sks_uri); | ||
222 | return; | ||
223 | } | ||
224 | else | ||
225 | { | ||
226 | if (NULL != ksk_uri) | ||
227 | FPRINTF (stderr, _("Option `%s' ignored\n"), "-k"); | ||
228 | if (NULL != advertise_ns) | ||
229 | FPRINTF (stderr, _("Option `%s' ignored\n"), "-A"); | ||
230 | } | ||
231 | return; | ||
232 | } | ||
233 | if (0 == strcmp (name, advertise_ns)) | ||
234 | namespace = ego; | ||
235 | } | ||
236 | |||
237 | |||
238 | /** | ||
239 | * Main function that will be run by the scheduler. | ||
240 | * | ||
241 | * @param cls closure | ||
242 | * @param args remaining command-line arguments | ||
243 | * @param cfgfile name of the configuration file used (for saving, can be NULL!) | ||
244 | * @param c configuration | ||
245 | */ | ||
246 | static void | ||
247 | run (void *cls, char *const *args, const char *cfgfile, | ||
248 | const struct GNUNET_CONFIGURATION_Handle *c) | ||
249 | { | ||
250 | struct GNUNET_CRYPTO_EccPublicKey nsid; | ||
251 | char *set; | ||
252 | int delta; | ||
253 | |||
254 | cfg = c; | ||
255 | h = GNUNET_FS_start (cfg, "gnunet-pseudonym", &progress_cb, NULL, | ||
256 | GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); | ||
257 | if (NULL != rating_change) | ||
258 | { | ||
259 | set = rating_change; | ||
260 | while ((*set != '\0') && (*set != ':')) | ||
261 | set++; | ||
262 | if (*set != ':') | ||
263 | { | ||
264 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
265 | _("Invalid argument `%s'\n"), | ||
266 | rating_change); | ||
267 | } | ||
268 | else | ||
269 | { | ||
270 | *set = '\0'; | ||
271 | delta = strtol (&set[1], NULL, /* no error handling yet */ | ||
272 | 10); | ||
273 | if (GNUNET_OK == GNUNET_FS_pseudonym_name_to_id (cfg, rating_change, &nsid)) | ||
274 | { | ||
275 | (void) GNUNET_FS_pseudonym_rank (cfg, &nsid, delta); | ||
276 | } | ||
277 | else | ||
278 | { | ||
279 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
280 | ("Namespace `%s' unknown. Make sure you specify its numeric suffix, if any.\n"), | ||
281 | rating_change); | ||
282 | } | ||
283 | } | ||
284 | GNUNET_free (rating_change); | ||
285 | rating_change = NULL; | ||
286 | } | ||
287 | if (0 == no_remote_printing) | ||
288 | GNUNET_FS_pseudonym_list_all (cfg, &pseudo_printer, NULL); | ||
289 | |||
290 | if (NULL != advertise_ns) | ||
291 | identity = GNUNET_IDENTITY_connect (cfg, | ||
292 | &identity_cb, | ||
293 | NULL); | ||
294 | } | ||
295 | |||
296 | |||
297 | /** | ||
298 | * The main function to manipulate GNUnet pseudonyms (and publish | ||
299 | * to namespaces). | ||
300 | * | ||
301 | * @param argc number of arguments from the command line | ||
302 | * @param argv command line arguments | ||
303 | * @return 0 ok, 1 on error | ||
304 | */ | ||
305 | int | ||
306 | main (int argc, char *const *argv) | ||
307 | { | ||
308 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
309 | {'a', "anonymity", "LEVEL", | ||
310 | gettext_noop ("set the desired LEVEL of sender-anonymity"), | ||
311 | 1, &GNUNET_GETOPT_set_uint, &bo.anonymity_level}, | ||
312 | {'A', "advertise", "NAME", | ||
313 | gettext_noop ("advertise namespace NAME"), | ||
314 | 1, &GNUNET_GETOPT_set_string, &advertise_ns}, | ||
315 | {'k', "keyword", "VALUE", | ||
316 | gettext_noop ("add an additional keyword for the advertisment" | ||
317 | " (this option can be specified multiple times)"), | ||
318 | 1, &GNUNET_FS_getopt_set_keywords, &ksk_uri}, | ||
319 | {'m', "meta", "TYPE:VALUE", | ||
320 | gettext_noop ("set the meta-data for the given TYPE to the given VALUE"), | ||
321 | 1, &GNUNET_FS_getopt_set_metadata, &adv_metadata}, | ||
322 | {'p', "priority", "PRIORITY", | ||
323 | gettext_noop ("use the given PRIORITY for the advertisments"), | ||
324 | 1, &GNUNET_GETOPT_set_uint, &bo.content_priority}, | ||
325 | {'q', "quiet", NULL, | ||
326 | gettext_noop ("do not print names of remote namespaces"), | ||
327 | 0, &GNUNET_GETOPT_set_one, &no_remote_printing}, | ||
328 | {'r', "replication", "LEVEL", | ||
329 | gettext_noop ("set the desired replication LEVEL"), | ||
330 | 1, &GNUNET_GETOPT_set_uint, &bo.replication_level}, | ||
331 | {'R', "root", "ID", | ||
332 | gettext_noop ("specify ID of the root of the namespace"), | ||
333 | 1, &GNUNET_GETOPT_set_string, &root_identifier}, | ||
334 | {'s', "set-rating", "ID:VALUE", | ||
335 | gettext_noop ("change rating of namespace ID by VALUE"), | ||
336 | 1, &GNUNET_GETOPT_set_string, &rating_change}, | ||
337 | GNUNET_GETOPT_OPTION_END | ||
338 | }; | ||
339 | bo.expiration_time = | ||
340 | GNUNET_FS_year_to_time (GNUNET_FS_get_current_year () + 2); | ||
341 | |||
342 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) | ||
343 | return 2; | ||
344 | |||
345 | ret = (GNUNET_OK == | ||
346 | GNUNET_PROGRAM_run (argc, argv, "gnunet-pseudonym [OPTIONS]", | ||
347 | gettext_noop ("Manage GNUnet pseudonyms."), | ||
348 | options, &run, NULL)) ? ret : 1; | ||
349 | GNUNET_free ((void*) argv); | ||
350 | return ret; | ||
351 | } | ||
352 | |||
353 | /* end of gnunet-pseudonym.c */ | ||
diff --git a/src/fs/test_pseudonym.c b/src/fs/test_pseudonym.c deleted file mode 100644 index 56b9d9637..000000000 --- a/src/fs/test_pseudonym.c +++ /dev/null | |||
@@ -1,223 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2005--2013 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 fs/test_pseudonym.c | ||
23 | * @brief testcase for fs_pseudonym.c | ||
24 | * @author Christian Grothoff | ||
25 | */ | ||
26 | #include "platform.h" | ||
27 | #include "gnunet_common.h" | ||
28 | #include "gnunet_util_lib.h" | ||
29 | #include "gnunet_fs_service.h" | ||
30 | #include "gnunet_signatures.h" | ||
31 | |||
32 | #define CHECK(a) do { if (!(a)) { ok = GNUNET_NO; GNUNET_break(0); goto FAILURE; } } while (0) | ||
33 | |||
34 | static struct GNUNET_CONTAINER_MetaData *meta; | ||
35 | |||
36 | static struct GNUNET_CRYPTO_EccPublicKey id1; | ||
37 | |||
38 | |||
39 | static int | ||
40 | iter (void *cls, | ||
41 | const struct GNUNET_CRYPTO_EccPublicKey *pseudonym, | ||
42 | const char *name, const char *unique_name, | ||
43 | const struct GNUNET_CONTAINER_MetaData *md, int32_t rating) | ||
44 | { | ||
45 | int *ok = cls; | ||
46 | |||
47 | if ((0 == memcmp (pseudonym, &id1, sizeof (struct GNUNET_CRYPTO_EccPublicKey))) && | ||
48 | (!GNUNET_CONTAINER_meta_data_test_equal (md, meta))) | ||
49 | { | ||
50 | *ok = GNUNET_NO; | ||
51 | GNUNET_break (0); | ||
52 | } | ||
53 | return GNUNET_OK; | ||
54 | } | ||
55 | |||
56 | |||
57 | static int | ||
58 | noti_callback (void *cls, const struct GNUNET_CRYPTO_EccPublicKey *pseudonym, | ||
59 | const char *name, const char *unique_name, | ||
60 | const struct GNUNET_CONTAINER_MetaData *md, int32_t rating) | ||
61 | { | ||
62 | int *ret = cls; | ||
63 | |||
64 | (*ret)++; | ||
65 | return GNUNET_OK; | ||
66 | } | ||
67 | |||
68 | |||
69 | static int | ||
70 | fake_noti_callback (void *cls, | ||
71 | const struct GNUNET_CRYPTO_EccPublicKey * pseudonym, | ||
72 | const char *name, const char *unique_name, | ||
73 | const struct GNUNET_CONTAINER_MetaData *md, int32_t rating) | ||
74 | { | ||
75 | int *ret = cls; | ||
76 | |||
77 | (*ret)++; | ||
78 | return GNUNET_OK; | ||
79 | } | ||
80 | |||
81 | |||
82 | static void | ||
83 | create_pseu (struct GNUNET_CRYPTO_EccPublicKey *pseu) | ||
84 | { | ||
85 | struct GNUNET_CRYPTO_EccPrivateKey *ph; | ||
86 | |||
87 | ph = GNUNET_CRYPTO_ecc_key_create (); | ||
88 | GNUNET_CRYPTO_ecc_key_get_public (ph, pseu); | ||
89 | GNUNET_free (ph); | ||
90 | } | ||
91 | |||
92 | |||
93 | /** | ||
94 | * Testcase for meta data / ranking IO routines. | ||
95 | */ | ||
96 | static int | ||
97 | test_io () | ||
98 | { | ||
99 | int ok; | ||
100 | struct GNUNET_CRYPTO_EccPublicKey rid1; | ||
101 | struct GNUNET_CRYPTO_EccPublicKey id2; | ||
102 | struct GNUNET_CRYPTO_EccPublicKey rid2; | ||
103 | struct GNUNET_CRYPTO_EccPublicKey fid; | ||
104 | struct GNUNET_CRYPTO_EccPublicKey id3; | ||
105 | int old; | ||
106 | int newVal; | ||
107 | struct GNUNET_CONFIGURATION_Handle *cfg; | ||
108 | char *name1; | ||
109 | char *name2; | ||
110 | char *name3; | ||
111 | char *name1_unique; | ||
112 | char *name2_unique; | ||
113 | char *noname; | ||
114 | int noname_is_a_dup; | ||
115 | int notiCount, fakenotiCount; | ||
116 | static char m[1024 * 1024 * 10]; | ||
117 | struct GNUNET_FS_Pseudonym_DiscoveryHandle *dh1; | ||
118 | struct GNUNET_FS_Pseudonym_DiscoveryHandle *dh2; | ||
119 | |||
120 | memset (m, 'b', sizeof (m)); | ||
121 | m[sizeof (m) - 1] = '\0'; | ||
122 | GNUNET_log_setup ("test-pseudonym", "WARNING", NULL); | ||
123 | ok = GNUNET_YES; | ||
124 | (void) GNUNET_DISK_directory_remove ("/tmp/gnunet-pseudonym-test"); | ||
125 | cfg = GNUNET_CONFIGURATION_create (); | ||
126 | if (-1 == GNUNET_CONFIGURATION_parse (cfg, "test_pseudonym_data.conf")) | ||
127 | { | ||
128 | GNUNET_CONFIGURATION_destroy (cfg); | ||
129 | GNUNET_break (0); | ||
130 | return -1; | ||
131 | } | ||
132 | notiCount = 0; | ||
133 | fakenotiCount = 0; | ||
134 | dh1 = GNUNET_FS_pseudonym_discovery_callback_register (cfg, &fake_noti_callback, | ||
135 | &fakenotiCount); | ||
136 | dh2 = GNUNET_FS_pseudonym_discovery_callback_register (cfg, ¬i_callback, | ||
137 | ¬iCount); | ||
138 | GNUNET_FS_pseudonym_discovery_callback_unregister (dh1); | ||
139 | |||
140 | /* ACTUAL TEST CODE */ | ||
141 | old = GNUNET_FS_pseudonym_list_all (cfg, NULL, NULL); | ||
142 | meta = GNUNET_CONTAINER_meta_data_create (); | ||
143 | GNUNET_CONTAINER_meta_data_insert (meta, "<test>", EXTRACTOR_METATYPE_TITLE, | ||
144 | EXTRACTOR_METAFORMAT_UTF8, "text/plain", | ||
145 | "test", strlen ("test") + 1); | ||
146 | create_pseu (&id1); | ||
147 | GNUNET_FS_pseudonym_add (cfg, &id1, meta); | ||
148 | CHECK (notiCount == 1); | ||
149 | GNUNET_FS_pseudonym_add (cfg, &id1, meta); | ||
150 | CHECK (notiCount == 2); | ||
151 | newVal = GNUNET_FS_pseudonym_list_all (cfg, &iter, &ok); | ||
152 | CHECK (old < newVal); | ||
153 | old = newVal; | ||
154 | create_pseu (&id2); | ||
155 | GNUNET_FS_pseudonym_add (cfg, &id2, meta); | ||
156 | CHECK (notiCount == 3); | ||
157 | newVal = GNUNET_FS_pseudonym_list_all (cfg, &iter, &ok); | ||
158 | CHECK (old < newVal); | ||
159 | GNUNET_assert (GNUNET_OK == | ||
160 | GNUNET_CONTAINER_meta_data_insert (meta, "<test>", | ||
161 | EXTRACTOR_METATYPE_COMMENT, | ||
162 | EXTRACTOR_METAFORMAT_UTF8, | ||
163 | "text/plain", m, | ||
164 | strlen (m) + 1)); | ||
165 | create_pseu (&id3); | ||
166 | GNUNET_FS_pseudonym_add (cfg, &id3, meta); | ||
167 | GNUNET_FS_pseudonym_get_info (cfg, &id3, NULL, NULL, &name3, NULL); | ||
168 | CHECK (name3 != NULL); | ||
169 | GNUNET_FS_pseudonym_get_info (cfg, &id2, NULL, NULL, &name2, NULL); | ||
170 | CHECK (name2 != NULL); | ||
171 | GNUNET_FS_pseudonym_get_info (cfg, &id1, NULL, NULL, &name1, NULL); | ||
172 | CHECK (name1 != NULL); | ||
173 | CHECK (0 == strcmp (name1, name2)); | ||
174 | name1_unique = GNUNET_FS_pseudonym_name_uniquify (cfg, &id1, name1, NULL); | ||
175 | name2_unique = GNUNET_FS_pseudonym_name_uniquify (cfg, &id2, name2, NULL); | ||
176 | CHECK (0 != strcmp (name1_unique, name2_unique)); | ||
177 | CHECK (GNUNET_SYSERR == GNUNET_FS_pseudonym_name_to_id (cfg, "fake", &rid2)); | ||
178 | CHECK (GNUNET_SYSERR == GNUNET_FS_pseudonym_name_to_id (cfg, name2, &rid2)); | ||
179 | CHECK (GNUNET_SYSERR == GNUNET_FS_pseudonym_name_to_id (cfg, name1, &rid1)); | ||
180 | CHECK (GNUNET_OK == GNUNET_FS_pseudonym_name_to_id (cfg, name2_unique, &rid2)); | ||
181 | CHECK (GNUNET_OK == GNUNET_FS_pseudonym_name_to_id (cfg, name1_unique, &rid1)); | ||
182 | CHECK (0 == memcmp (&id1, &rid1, sizeof (struct GNUNET_CRYPTO_EccPublicKey))); | ||
183 | CHECK (0 == memcmp (&id2, &rid2, sizeof (struct GNUNET_CRYPTO_EccPublicKey))); | ||
184 | |||
185 | create_pseu (&fid); | ||
186 | GNUNET_log_skip (1, GNUNET_NO); | ||
187 | CHECK (0 == GNUNET_FS_pseudonym_rank (cfg, &fid, 0)); | ||
188 | GNUNET_log_skip (0, GNUNET_NO); | ||
189 | CHECK (GNUNET_OK == GNUNET_FS_pseudonym_get_info (cfg, &fid, NULL, NULL, &noname, &noname_is_a_dup)); | ||
190 | CHECK (noname != NULL); | ||
191 | CHECK (noname_is_a_dup == GNUNET_YES); | ||
192 | CHECK (0 == GNUNET_FS_pseudonym_rank (cfg, &id1, 0)); | ||
193 | CHECK (5 == GNUNET_FS_pseudonym_rank (cfg, &id1, 5)); | ||
194 | CHECK (-5 == GNUNET_FS_pseudonym_rank (cfg, &id1, -10)); | ||
195 | CHECK (0 == GNUNET_FS_pseudonym_rank (cfg, &id1, 5)); | ||
196 | GNUNET_free (name1); | ||
197 | GNUNET_free (name2); | ||
198 | GNUNET_free (name1_unique); | ||
199 | GNUNET_free (name2_unique); | ||
200 | GNUNET_free (name3); | ||
201 | GNUNET_free (noname); | ||
202 | /* END OF TEST CODE */ | ||
203 | FAILURE: | ||
204 | GNUNET_FS_pseudonym_discovery_callback_unregister (dh2); | ||
205 | GNUNET_CONTAINER_meta_data_destroy (meta); | ||
206 | GNUNET_CONFIGURATION_destroy (cfg); | ||
207 | return (ok == GNUNET_YES) ? 0 : 1; | ||
208 | } | ||
209 | |||
210 | |||
211 | int | ||
212 | main (int argc, char *argv[]) | ||
213 | { | ||
214 | GNUNET_log_setup ("test-pseudonym", "WARNING", NULL); | ||
215 | if (0 != test_io ()) | ||
216 | return 1; | ||
217 | GNUNET_break (GNUNET_OK == | ||
218 | GNUNET_DISK_directory_remove ("/tmp/gnunet-pseudonym-test")); | ||
219 | return 0; | ||
220 | } | ||
221 | |||
222 | |||
223 | /* end of test_pseudoynm.c */ | ||
diff --git a/src/include/gnunet_fs_service.h b/src/include/gnunet_fs_service.h index a49d8fb98..d60044732 100644 --- a/src/include/gnunet_fs_service.h +++ b/src/include/gnunet_fs_service.h | |||
@@ -93,180 +93,6 @@ typedef int (*GNUNET_FS_KeywordIterator) (void *cls, const char *keyword, | |||
93 | 93 | ||
94 | 94 | ||
95 | /** | 95 | /** |
96 | * Iterator over all known pseudonyms. | ||
97 | * | ||
98 | * @param cls closure | ||
99 | * @param pseudonym public key of pseudonym | ||
100 | * @param name name of the pseudonym (might be NULL) | ||
101 | * @param unique_name unique name of the pseudonym (might be NULL) | ||
102 | * @param md meta data known about the pseudonym | ||
103 | * @param rating the local rating of the pseudonym | ||
104 | * @return #GNUNET_OK to continue iteration, #GNUNET_SYSERR to abort | ||
105 | */ | ||
106 | typedef int (*GNUNET_FS_PseudonymIterator) (void *cls, | ||
107 | const struct GNUNET_CRYPTO_EccPublicKey *pseudonym, | ||
108 | const char *name, | ||
109 | const char *unique_name, | ||
110 | const struct GNUNET_CONTAINER_MetaData *md, | ||
111 | int32_t rating); | ||
112 | |||
113 | |||
114 | /** | ||
115 | * Change the rank of a pseudonym. | ||
116 | * | ||
117 | * @param cfg overall configuration | ||
118 | * @param pseudonym identity of the pseudonym | ||
119 | * @param delta by how much should the rating be changed? | ||
120 | * @return new rating of the pseudonym | ||
121 | */ | ||
122 | int | ||
123 | GNUNET_FS_pseudonym_rank (const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
124 | const struct GNUNET_CRYPTO_EccPublicKey *pseudonym, | ||
125 | int32_t delta); | ||
126 | |||
127 | |||
128 | /** | ||
129 | * Add a pseudonym to the set of known pseudonyms. | ||
130 | * For all pseudonym advertisements that we discover | ||
131 | * FS should automatically call this function. | ||
132 | * | ||
133 | * @param cfg overall configuration | ||
134 | * @param pseudonym the pseudonym identifier | ||
135 | * @param meta metadata for the pseudonym | ||
136 | * @return GNUNET_OK on success, GNUNET_SYSERR on failure | ||
137 | */ | ||
138 | int | ||
139 | GNUNET_FS_pseudonym_add (const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
140 | const struct GNUNET_CRYPTO_EccPublicKey *pseudonym, | ||
141 | const struct GNUNET_CONTAINER_MetaData *meta); | ||
142 | |||
143 | |||
144 | /** | ||
145 | * List all known pseudonyms. | ||
146 | * | ||
147 | * @param cfg overall configuration | ||
148 | * @param iterator function to call for each pseudonym | ||
149 | * @param iterator_cls closure for iterator | ||
150 | * @return number of pseudonyms found | ||
151 | */ | ||
152 | int | ||
153 | GNUNET_FS_pseudonym_list_all (const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
154 | GNUNET_FS_PseudonymIterator iterator, | ||
155 | void *iterator_cls); | ||
156 | |||
157 | |||
158 | /** | ||
159 | * Handle for a discovery callback registration. | ||
160 | */ | ||
161 | struct GNUNET_FS_Pseudonym_DiscoveryHandle; | ||
162 | |||
163 | |||
164 | /** | ||
165 | * Register callback to be invoked whenever we discover | ||
166 | * a new pseudonym. | ||
167 | * | ||
168 | * @param cfg our configuration | ||
169 | * @param iterator function to invoke on discovery | ||
170 | * @param iterator_cls closure for iterator | ||
171 | * @return registration handle | ||
172 | */ | ||
173 | struct GNUNET_FS_Pseudonym_DiscoveryHandle * | ||
174 | GNUNET_FS_pseudonym_discovery_callback_register (const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
175 | GNUNET_FS_PseudonymIterator iterator, | ||
176 | void *iterator_cls); | ||
177 | |||
178 | |||
179 | /** | ||
180 | * Unregister pseudonym discovery callback. | ||
181 | * | ||
182 | * @param dh registration to unregister | ||
183 | */ | ||
184 | void | ||
185 | GNUNET_FS_pseudonym_discovery_callback_unregister (struct GNUNET_FS_Pseudonym_DiscoveryHandle *dh); | ||
186 | |||
187 | |||
188 | /** | ||
189 | * Return unique variant of the pseudonym name. Use after | ||
190 | * GNUNET_FS_pseudonym_id_to_name() to make sure that name is unique. | ||
191 | * | ||
192 | * @param cfg configuration | ||
193 | * @param pseudonym cryptographic ID of the pseudonym | ||
194 | * @param name name to uniquify | ||
195 | * @param suffix if not NULL, filled with the suffix value | ||
196 | * @return NULL on failure (should never happen), name on success. | ||
197 | * Free the name with GNUNET_free(). | ||
198 | */ | ||
199 | char * | ||
200 | GNUNET_FS_pseudonym_name_uniquify (const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
201 | const struct GNUNET_CRYPTO_EccPublicKey *pseudonym, | ||
202 | const char *name, | ||
203 | unsigned int *suffix); | ||
204 | |||
205 | |||
206 | /** | ||
207 | * Get pseudonym name, metadata and rank. This is a wrapper around | ||
208 | * internal read_info() call, and ensures that returned data is not | ||
209 | * invalid (not NULL). Writing back information returned by this | ||
210 | * function will give a name "no-name" to pseudonyms that have no | ||
211 | * name. This side-effect is unavoidable, but hardly harmful. | ||
212 | * | ||
213 | * @param cfg configuration | ||
214 | * @param pseudonym cryptographic ID of the pseudonym | ||
215 | * @param ret_meta a location to store metadata pointer. NULL, if metadata | ||
216 | * is not needed. Destroy with GNUNET_CONTAINER_meta_data_destroy(). | ||
217 | * @param ret_rank a location to store rank. NULL, if rank not needed. | ||
218 | * @param ret_name a location to store human-readable name. Name is not unique. | ||
219 | * NULL, if name is not needed. Free with GNUNET_free(). | ||
220 | * @param name_is_a_dup is set to #GNUNET_YES, if ret_name was filled with | ||
221 | * a duplicate of a "no-name" placeholder | ||
222 | * @return #GNUNET_OK on success. #GNUENT_SYSERR if the data was | ||
223 | * unobtainable (in that case ret_* are filled with placeholders - | ||
224 | * empty metadata container, rank -1 and a "no-name" name). | ||
225 | */ | ||
226 | int | ||
227 | GNUNET_FS_pseudonym_get_info (const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
228 | const struct GNUNET_CRYPTO_EccPublicKey *pseudonym, | ||
229 | struct GNUNET_CONTAINER_MetaData **ret_meta, | ||
230 | int32_t *ret_rank, | ||
231 | char **ret_name, | ||
232 | int *name_is_a_dup); | ||
233 | |||
234 | |||
235 | /** | ||
236 | * Get the pseudonym ID belonging to the given pseudonym name. | ||
237 | * | ||
238 | * @param cfg configuration to use | ||
239 | * @param ns_uname unique (!) human-readable name for the pseudonym | ||
240 | * @param pseudonym set to pseudonym ID based on 'ns_uname' | ||
241 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure | ||
242 | */ | ||
243 | int | ||
244 | GNUNET_FS_pseudonym_name_to_id (const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
245 | const char *ns_uname, | ||
246 | struct GNUNET_CRYPTO_EccPublicKey *pseudonym); | ||
247 | |||
248 | |||
249 | /** | ||
250 | * Set the pseudonym metadata, rank and name. | ||
251 | * | ||
252 | * @param cfg overall configuration | ||
253 | * @param pseudonym id of the pseudonym | ||
254 | * @param name name to set. Must be the non-unique version of it. | ||
255 | * May be NULL, in which case it erases pseudonym's name! | ||
256 | * @param md metadata to set | ||
257 | * May be NULL, in which case it erases pseudonym's metadata! | ||
258 | * @param rank rank to assign | ||
259 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure | ||
260 | */ | ||
261 | int | ||
262 | GNUNET_FS_pseudonym_set_info (const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
263 | const struct GNUNET_CRYPTO_EccPublicKey *pseudonym, | ||
264 | const char *name, | ||
265 | const struct GNUNET_CONTAINER_MetaData *md, | ||
266 | int32_t rank); | ||
267 | |||
268 | |||
269 | /** | ||
270 | * Get a unique key from a URI. This is for putting URIs | 96 | * Get a unique key from a URI. This is for putting URIs |
271 | * into HashMaps. The key may change between FS implementations. | 97 | * into HashMaps. The key may change between FS implementations. |
272 | * | 98 | * |