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 2, 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 int start_automate;
41 static int stop_automate;
46 static char *create_ns;
51 static char *delete_ns;
56 static struct GNUNET_FS_Uri *ksk_uri;
61 static int print_local_only;
66 static struct GNUNET_CONTAINER_MetaData *adv_metadata;
71 static unsigned int priority = 365;
76 static int no_remote_printing;
81 static char *root_identifier;
86 static char *rating_change;
89 * Handle to fs service.
91 static struct GNUNET_FS_Handle *h;
94 * Namespace we are looking at.
96 static struct GNUNET_FS_Namespace *ns;
101 static const struct GNUNET_CONFIGURATION_Handle *cfg;
106 progress_cb (void *cls,
107 const struct GNUNET_FS_ProgressInfo *info)
114 ns_printer (void *cls,
116 const GNUNET_HashCode *id)
118 struct GNUNET_CRYPTO_HashAsciiEncoded enc;
120 GNUNET_CRYPTO_hash_to_enc (id, &enc);
129 pseudo_printer (void *cls,
130 const GNUNET_HashCode *
133 GNUNET_CONTAINER_MetaData * md,
138 id = GNUNET_PSEUDONYM_id_to_name (cfg,
149 GNUNET_CONTAINER_meta_data_iterate (md,
150 &EXTRACTOR_meta_data_print,
152 fprintf (stdout, "\n");
159 post_advertising (void *cls,
160 const struct GNUNET_FS_Uri *uri,
163 GNUNET_HashCode nsid;
169 fprintf (stderr, "%s", emsg);
175 GNUNET_FS_namespace_delete (ns,
179 if (0 != stop_automate)
181 GNUNET_break (0); // FIXME: not implemented
183 if (0 != start_automate)
185 GNUNET_break (0); // FIXME: not implemented
187 if (NULL != rating_change)
190 while ((*set != '\0') && (*set != ':'))
194 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
195 _("Invalid argument `%s'\n"),
201 delta = strtol (&set[1], NULL, /* no error handling yet */
204 GNUNET_PSEUDONYM_name_to_id (cfg,
208 (void) GNUNET_PSEUDONYM_rank (cfg,
214 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
215 _("Namespace `%s' unknown.\n"),
219 GNUNET_free (rating_change);
220 rating_change = NULL;
222 if (0 != print_local_only)
224 GNUNET_FS_namespace_list (h,
228 else if (0 == no_remote_printing)
230 GNUNET_PSEUDONYM_list_all (cfg,
239 * Main function that will be run by the scheduler.
242 * @param sched the scheduler to use
243 * @param args remaining command-line arguments
244 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
245 * @param c configuration
249 struct GNUNET_SCHEDULER_Handle *sched,
252 const struct GNUNET_CONFIGURATION_Handle *c)
254 struct GNUNET_TIME_Absolute expiration;
258 h = GNUNET_FS_start (sched,
263 GNUNET_FS_FLAGS_NONE,
264 GNUNET_FS_OPTIONS_END);
265 if (NULL != delete_ns)
267 ns = GNUNET_FS_namespace_create (h, delete_ns);
275 GNUNET_FS_namespace_delete (ns,
281 if (NULL != create_ns)
283 ns = GNUNET_FS_namespace_create (h, create_ns);
290 if (NULL != root_identifier)
292 expiration = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_YEARS);
296 ksk_uri = GNUNET_FS_uri_parse ("gnunet://fs/ksk/namespace", &emsg);
297 GNUNET_assert (NULL == emsg);
299 GNUNET_FS_namespace_advertise (h,
314 fprintf (stderr, _("Option `%s' ignored\n"), "-k");
320 if (root_identifier != NULL)
321 fprintf (stderr, _("Option `%s' ignored\n"), "-r");
323 fprintf (stderr, _("Option `%s' ignored\n"), "-k");
326 post_advertising (NULL, NULL, NULL);
331 * The main function to inspect GNUnet directories.
333 * @param argc number of arguments from the command line
334 * @param argv command line arguments
335 * @return 0 ok, 1 on error
338 main (int argc, char *const *argv)
340 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
341 {'a', "anonymity", "LEVEL",
342 gettext_noop ("set the desired LEVEL of sender-anonymity"),
343 1, &GNUNET_GETOPT_set_uint, &anonymity},
344 {'A', "automate", NULL,
345 gettext_noop ("start a collection"),
346 0, &GNUNET_GETOPT_set_one, &start_automate},
347 {'C', "create", "NAME",
349 ("create or advertise namespace NAME"),
350 1, &GNUNET_GETOPT_set_string, &create_ns},
351 {'D', "delete", "NAME",
353 ("delete namespace NAME "),
354 1, &GNUNET_GETOPT_set_string, &delete_ns},
356 gettext_noop ("end current collection"),
357 0, &GNUNET_GETOPT_set_one, &stop_automate},
358 {'k', "keyword", "VALUE",
360 ("add an additional keyword for the advertisment"
361 " (this option can be specified multiple times)"),
362 1, &GNUNET_FS_getopt_set_keywords, &ksk_uri},
363 {'m', "meta", "TYPE:VALUE",
364 gettext_noop ("set the meta-data for the given TYPE to the given VALUE"),
365 1, &GNUNET_FS_getopt_set_metadata, &adv_metadata},
366 {'o', "only-local", NULL,
367 gettext_noop ("print names of local namespaces"),
368 0, &GNUNET_GETOPT_set_one, &print_local_only},
369 {'p', "priority", "PRIORITY",
370 gettext_noop ("use the given PRIORITY for the advertisments"),
371 1, &GNUNET_GETOPT_set_uint, &priority},
373 gettext_noop ("do not print names of remote namespaces"),
374 0, &GNUNET_GETOPT_set_one, &no_remote_printing},
377 ("specify ID of the root of the namespace"),
378 1, &GNUNET_GETOPT_set_string, &root_identifier},
379 {'s', "set-rating", "ID:VALUE",
381 ("change rating of namespace ID by VALUE"),
382 1, &GNUNET_GETOPT_set_string, &rating_change},
383 GNUNET_GETOPT_OPTION_END
386 GNUNET_PROGRAM_run (argc,
390 ("Manage GNUnet pseudonyms."),
391 options, &run, NULL)) ? ret : 1;
394 /* end of gnunet-pseudonym.c */