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 args remaining command-line arguments
225 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
226 * @param c configuration
232 const struct GNUNET_CONFIGURATION_Handle *c)
234 struct GNUNET_TIME_Absolute expiration;
238 h = GNUNET_FS_start (cfg,
242 GNUNET_FS_FLAGS_NONE,
243 GNUNET_FS_OPTIONS_END);
244 if (NULL != delete_ns)
246 ns = GNUNET_FS_namespace_create (h, delete_ns);
254 GNUNET_FS_namespace_delete (ns,
260 if (NULL != create_ns)
262 ns = GNUNET_FS_namespace_create (h, create_ns);
269 if (NULL != root_identifier)
271 expiration = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_YEARS);
275 ksk_uri = GNUNET_FS_uri_parse ("gnunet://fs/ksk/namespace", &emsg);
276 GNUNET_assert (NULL == emsg);
278 GNUNET_FS_namespace_advertise (h,
293 fprintf (stderr, _("Option `%s' ignored\n"), "-k");
299 if (root_identifier != NULL)
300 fprintf (stderr, _("Option `%s' ignored\n"), "-r");
302 fprintf (stderr, _("Option `%s' ignored\n"), "-k");
305 post_advertising (NULL, NULL, NULL);
310 * The main function to inspect GNUnet directories.
312 * @param argc number of arguments from the command line
313 * @param argv command line arguments
314 * @return 0 ok, 1 on error
317 main (int argc, char *const *argv)
319 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
320 {'a', "anonymity", "LEVEL",
321 gettext_noop ("set the desired LEVEL of sender-anonymity"),
322 1, &GNUNET_GETOPT_set_uint, &anonymity},
323 {'C', "create", "NAME",
325 ("create or advertise namespace NAME"),
326 1, &GNUNET_GETOPT_set_string, &create_ns},
327 {'D', "delete", "NAME",
329 ("delete namespace NAME "),
330 1, &GNUNET_GETOPT_set_string, &delete_ns},
331 {'k', "keyword", "VALUE",
333 ("add an additional keyword for the advertisment"
334 " (this option can be specified multiple times)"),
335 1, &GNUNET_FS_getopt_set_keywords, &ksk_uri},
336 {'m', "meta", "TYPE:VALUE",
337 gettext_noop ("set the meta-data for the given TYPE to the given VALUE"),
338 1, &GNUNET_FS_getopt_set_metadata, &adv_metadata},
339 {'o', "only-local", NULL,
340 gettext_noop ("print names of local namespaces"),
341 0, &GNUNET_GETOPT_set_one, &print_local_only},
342 {'p', "priority", "PRIORITY",
343 gettext_noop ("use the given PRIORITY for the advertisments"),
344 1, &GNUNET_GETOPT_set_uint, &priority},
346 gettext_noop ("do not print names of remote namespaces"),
347 0, &GNUNET_GETOPT_set_one, &no_remote_printing},
350 ("specify ID of the root of the namespace"),
351 1, &GNUNET_GETOPT_set_string, &root_identifier},
352 {'s', "set-rating", "ID:VALUE",
354 ("change rating of namespace ID by VALUE"),
355 1, &GNUNET_GETOPT_set_string, &rating_change},
356 GNUNET_GETOPT_OPTION_END
359 GNUNET_PROGRAM_run (argc,
363 ("Manage GNUnet pseudonyms."),
364 options, &run, NULL)) ? ret : 1;
367 /* end of gnunet-pseudonym.c */