2 This file is part of GNUnet.
3 (C) 2001, 2002, 2004, 2005, 2006, 2007, 2009, 2010 Christian Grothoff (and other contributing authors)
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.
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.
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.
21 * @file fs/gnunet-pseudonym.c
22 * @brief manage GNUnet namespaces / pseudonyms
23 * @author Christian Grothoff
26 #include "gnunet_fs_service.h"
31 static unsigned int anonymity;
36 static char *create_ns;
41 static char *delete_ns;
46 static struct GNUNET_FS_Uri *ksk_uri;
51 static int print_local_only;
56 static struct GNUNET_CONTAINER_MetaData *adv_metadata;
61 static unsigned int priority = 365;
66 static int no_remote_printing;
71 static char *root_identifier;
76 static char *rating_change;
79 * Handle to fs service.
81 static struct GNUNET_FS_Handle *h;
84 * Namespace we are looking at.
86 static struct GNUNET_FS_Namespace *ns;
91 static const struct GNUNET_CONFIGURATION_Handle *cfg;
96 progress_cb (void *cls,
97 const struct GNUNET_FS_ProgressInfo *info)
104 ns_printer (void *cls,
106 const GNUNET_HashCode *id)
108 struct GNUNET_CRYPTO_HashAsciiEncoded enc;
110 GNUNET_CRYPTO_hash_to_enc (id, &enc);
119 pseudo_printer (void *cls,
120 const GNUNET_HashCode *
123 GNUNET_CONTAINER_MetaData * md,
128 id = GNUNET_PSEUDONYM_id_to_name (cfg,
139 GNUNET_CONTAINER_meta_data_iterate (md,
140 &EXTRACTOR_meta_data_print,
142 fprintf (stdout, "\n");
149 post_advertising (void *cls,
150 const struct GNUNET_FS_Uri *uri,
153 GNUNET_HashCode nsid;
159 fprintf (stderr, "%s", emsg);
165 GNUNET_FS_namespace_delete (ns,
169 if (NULL != rating_change)
172 while ((*set != '\0') && (*set != ':'))
176 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
177 _("Invalid argument `%s'\n"),
183 delta = strtol (&set[1], NULL, /* no error handling yet */
186 GNUNET_PSEUDONYM_name_to_id (cfg,
190 (void) GNUNET_PSEUDONYM_rank (cfg,
196 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
197 _("Namespace `%s' unknown.\n"),
201 GNUNET_free (rating_change);
202 rating_change = NULL;
204 if (0 != print_local_only)
206 GNUNET_FS_namespace_list (h,
210 else if (0 == no_remote_printing)
212 GNUNET_PSEUDONYM_list_all (cfg,
221 * Main function that will be run by the scheduler.
224 * @param sched the scheduler to use
225 * @param args remaining command-line arguments
226 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
227 * @param c configuration
231 struct GNUNET_SCHEDULER_Handle *sched,
234 const struct GNUNET_CONFIGURATION_Handle *c)
236 struct GNUNET_TIME_Absolute expiration;
240 h = GNUNET_FS_start (sched,
245 GNUNET_FS_FLAGS_NONE,
246 GNUNET_FS_OPTIONS_END);
247 if (NULL != delete_ns)
249 ns = GNUNET_FS_namespace_create (h, delete_ns);
257 GNUNET_FS_namespace_delete (ns,
263 if (NULL != create_ns)
265 ns = GNUNET_FS_namespace_create (h, create_ns);
272 if (NULL != root_identifier)
274 expiration = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_YEARS);
278 ksk_uri = GNUNET_FS_uri_parse ("gnunet://fs/ksk/namespace", &emsg);
279 GNUNET_assert (NULL == emsg);
281 GNUNET_FS_namespace_advertise (h,
296 fprintf (stderr, _("Option `%s' ignored\n"), "-k");
302 if (root_identifier != NULL)
303 fprintf (stderr, _("Option `%s' ignored\n"), "-r");
305 fprintf (stderr, _("Option `%s' ignored\n"), "-k");
308 post_advertising (NULL, NULL, NULL);
313 * The main function to inspect GNUnet directories.
315 * @param argc number of arguments from the command line
316 * @param argv command line arguments
317 * @return 0 ok, 1 on error
320 main (int argc, char *const *argv)
322 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
323 {'a', "anonymity", "LEVEL",
324 gettext_noop ("set the desired LEVEL of sender-anonymity"),
325 1, &GNUNET_GETOPT_set_uint, &anonymity},
326 {'C', "create", "NAME",
328 ("create or advertise namespace NAME"),
329 1, &GNUNET_GETOPT_set_string, &create_ns},
330 {'D', "delete", "NAME",
332 ("delete namespace NAME "),
333 1, &GNUNET_GETOPT_set_string, &delete_ns},
334 {'k', "keyword", "VALUE",
336 ("add an additional keyword for the advertisment"
337 " (this option can be specified multiple times)"),
338 1, &GNUNET_FS_getopt_set_keywords, &ksk_uri},
339 {'m', "meta", "TYPE:VALUE",
340 gettext_noop ("set the meta-data for the given TYPE to the given VALUE"),
341 1, &GNUNET_FS_getopt_set_metadata, &adv_metadata},
342 {'o', "only-local", NULL,
343 gettext_noop ("print names of local namespaces"),
344 0, &GNUNET_GETOPT_set_one, &print_local_only},
345 {'p', "priority", "PRIORITY",
346 gettext_noop ("use the given PRIORITY for the advertisments"),
347 1, &GNUNET_GETOPT_set_uint, &priority},
349 gettext_noop ("do not print names of remote namespaces"),
350 0, &GNUNET_GETOPT_set_one, &no_remote_printing},
353 ("specify ID of the root of the namespace"),
354 1, &GNUNET_GETOPT_set_string, &root_identifier},
355 {'s', "set-rating", "ID:VALUE",
357 ("change rating of namespace ID by VALUE"),
358 1, &GNUNET_GETOPT_set_string, &rating_change},
359 GNUNET_GETOPT_OPTION_END
362 GNUNET_PROGRAM_run (argc,
366 ("Manage GNUnet pseudonyms."),
367 options, &run, NULL)) ? ret : 1;
370 /* end of gnunet-pseudonym.c */