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 char *create_ns;
36 static char *delete_ns;
41 static struct GNUNET_FS_Uri *ksk_uri;
46 static int print_local_only;
51 static struct GNUNET_CONTAINER_MetaData *adv_metadata;
54 * Our block options (-p, -r, -a).
56 static struct GNUNET_FS_BlockOptions bo = { { 0LL }, 1, 365, 1 };
61 static int no_remote_printing;
66 static char *root_identifier;
71 static char *rating_change;
74 * Handle to fs service.
76 static struct GNUNET_FS_Handle *h;
79 * Namespace we are looking at.
81 static struct GNUNET_FS_Namespace *ns;
86 static const struct GNUNET_CONFIGURATION_Handle *cfg;
91 progress_cb (void *cls,
92 const struct GNUNET_FS_ProgressInfo *info)
99 ns_printer (void *cls,
101 const GNUNET_HashCode *id)
103 struct GNUNET_CRYPTO_HashAsciiEncoded enc;
105 GNUNET_CRYPTO_hash_to_enc (id, &enc);
114 pseudo_printer (void *cls,
115 const GNUNET_HashCode *
118 GNUNET_CONTAINER_MetaData * md,
123 id = GNUNET_PSEUDONYM_id_to_name (cfg,
134 GNUNET_CONTAINER_meta_data_iterate (md,
135 &EXTRACTOR_meta_data_print,
137 fprintf (stdout, "\n");
144 post_advertising (void *cls,
145 const struct GNUNET_FS_Uri *uri,
148 GNUNET_HashCode nsid;
154 fprintf (stderr, "%s", emsg);
160 GNUNET_FS_namespace_delete (ns,
164 if (NULL != rating_change)
167 while ((*set != '\0') && (*set != ':'))
171 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
172 _("Invalid argument `%s'\n"),
178 delta = strtol (&set[1], NULL, /* no error handling yet */
181 GNUNET_PSEUDONYM_name_to_id (cfg,
185 (void) GNUNET_PSEUDONYM_rank (cfg,
191 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
192 _("Namespace `%s' unknown.\n"),
196 GNUNET_free (rating_change);
197 rating_change = NULL;
199 if (0 != print_local_only)
201 GNUNET_FS_namespace_list (h,
205 else if (0 == no_remote_printing)
207 GNUNET_PSEUDONYM_list_all (cfg,
216 * Main function that will be run by the scheduler.
219 * @param args remaining command-line arguments
220 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
221 * @param c configuration
227 const struct GNUNET_CONFIGURATION_Handle *c)
232 h = GNUNET_FS_start (cfg,
236 GNUNET_FS_FLAGS_NONE,
237 GNUNET_FS_OPTIONS_END);
238 if (NULL != delete_ns)
240 ns = GNUNET_FS_namespace_create (h, delete_ns);
248 GNUNET_FS_namespace_delete (ns,
254 if (NULL != create_ns)
256 ns = GNUNET_FS_namespace_create (h, create_ns);
263 if (NULL != root_identifier)
268 ksk_uri = GNUNET_FS_uri_parse ("gnunet://fs/ksk/namespace", &emsg);
269 GNUNET_assert (NULL == emsg);
271 GNUNET_FS_namespace_advertise (h,
284 fprintf (stderr, _("Option `%s' ignored\n"), "-k");
290 if (root_identifier != NULL)
291 fprintf (stderr, _("Option `%s' ignored\n"), "-r");
293 fprintf (stderr, _("Option `%s' ignored\n"), "-k");
296 post_advertising (NULL, NULL, NULL);
301 * The main function to manipulate GNUnet pseudonyms (and publish
304 * @param argc number of arguments from the command line
305 * @param argv command line arguments
306 * @return 0 ok, 1 on error
309 main (int argc, char *const *argv)
311 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
312 {'a', "anonymity", "LEVEL",
313 gettext_noop ("set the desired LEVEL of sender-anonymity"),
314 1, &GNUNET_GETOPT_set_uint, &bo.anonymity_level},
315 {'C', "create", "NAME",
317 ("create or advertise namespace NAME"),
318 1, &GNUNET_GETOPT_set_string, &create_ns},
319 {'D', "delete", "NAME",
321 ("delete namespace NAME "),
322 1, &GNUNET_GETOPT_set_string, &delete_ns},
323 {'k', "keyword", "VALUE",
325 ("add an additional keyword for the advertisment"
326 " (this option can be specified multiple times)"),
327 1, &GNUNET_FS_getopt_set_keywords, &ksk_uri},
328 {'m', "meta", "TYPE:VALUE",
329 gettext_noop ("set the meta-data for the given TYPE to the given VALUE"),
330 1, &GNUNET_FS_getopt_set_metadata, &adv_metadata},
331 {'o', "only-local", NULL,
332 gettext_noop ("print names of local namespaces"),
333 0, &GNUNET_GETOPT_set_one, &print_local_only},
334 {'p', "priority", "PRIORITY",
335 gettext_noop ("use the given PRIORITY for the advertisments"),
336 1, &GNUNET_GETOPT_set_uint, &bo.content_priority},
338 gettext_noop ("do not print names of remote namespaces"),
339 0, &GNUNET_GETOPT_set_one, &no_remote_printing},
340 {'r', "replication", "LEVEL",
341 gettext_noop ("set the desired replication LEVEL"),
342 1, &GNUNET_GETOPT_set_uint, &bo.replication_level},
345 ("specify ID of the root of the namespace"),
346 1, &GNUNET_GETOPT_set_string, &root_identifier},
347 {'s', "set-rating", "ID:VALUE",
349 ("change rating of namespace ID by VALUE"),
350 1, &GNUNET_GETOPT_set_string, &rating_change},
351 GNUNET_GETOPT_OPTION_END
353 bo.expiration_time = GNUNET_FS_year_to_time (GNUNET_FS_get_current_year () + 2);
355 GNUNET_PROGRAM_run (argc,
357 "gnunet-pseudonym [OPTIONS]",
359 ("Manage GNUnet pseudonyms."),
360 options, &run, NULL)) ? ret : 1;
363 /* end of gnunet-pseudonym.c */