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, const struct GNUNET_FS_ProgressInfo *info)
98 ns_printer (void *cls, const char *name, const struct GNUNET_HashCode * id)
100 struct GNUNET_CRYPTO_HashAsciiEncoded enc;
102 GNUNET_CRYPTO_hash_to_enc (id, &enc);
103 FPRINTF (stdout, "%s (%s)\n", name, (const char *) &enc);
108 pseudo_printer (void *cls, const struct GNUNET_HashCode * pseudonym,
109 const char *name, const char *unique_name,
110 const struct GNUNET_CONTAINER_MetaData *md, int rating)
116 /* While we get a name from the caller, it might be NULL.
117 * GNUNET_PSEUDONYM_get_info () never returns NULL.
119 getinfo_result = GNUNET_PSEUDONYM_get_info (cfg, pseudonym,
120 NULL, NULL, &id, NULL);
121 if (getinfo_result != GNUNET_OK)
126 unique_id = GNUNET_PSEUDONYM_name_uniquify (cfg, pseudonym, id, NULL);
128 FPRINTF (stdout, "%s (%d):\n", unique_id, rating);
129 GNUNET_CONTAINER_meta_data_iterate (md, &EXTRACTOR_meta_data_print, stdout);
130 FPRINTF (stdout, "%s", "\n");
131 GNUNET_free (unique_id);
137 post_advertising (void *cls, const struct GNUNET_FS_Uri *uri, const char *emsg)
139 struct GNUNET_HashCode nsid;
145 FPRINTF (stderr, "%s", emsg);
150 if (GNUNET_OK != GNUNET_FS_namespace_delete (ns, GNUNET_NO))
153 if (NULL != rating_change)
156 while ((*set != '\0') && (*set != ':'))
160 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Invalid argument `%s'\n"),
166 delta = strtol (&set[1], NULL, /* no error handling yet */
168 if (GNUNET_OK == GNUNET_PSEUDONYM_name_to_id (cfg, rating_change, &nsid))
170 (void) GNUNET_PSEUDONYM_rank (cfg, &nsid, delta);
174 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
175 ("Namespace `%s' unknown. Make sure you specify its numeric suffix, if any.\n"),
179 GNUNET_free (rating_change);
180 rating_change = NULL;
182 if (0 != print_local_only)
184 GNUNET_FS_namespace_list (h, &ns_printer, NULL);
186 else if (0 == no_remote_printing)
188 GNUNET_PSEUDONYM_list_all (cfg, &pseudo_printer, NULL);
195 * Main function that will be run by the scheduler.
198 * @param args remaining command-line arguments
199 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
200 * @param c configuration
203 run (void *cls, char *const *args, const char *cfgfile,
204 const struct GNUNET_CONFIGURATION_Handle *c)
209 h = GNUNET_FS_start (cfg, "gnunet-pseudonym", &progress_cb, NULL,
210 GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
211 if (NULL != delete_ns)
213 ns = GNUNET_FS_namespace_create (h, delete_ns);
220 if (GNUNET_OK != GNUNET_FS_namespace_delete (ns, GNUNET_YES))
225 if (NULL != create_ns)
227 ns = GNUNET_FS_namespace_create (h, create_ns);
234 if (NULL != root_identifier)
239 ksk_uri = GNUNET_FS_uri_parse ("gnunet://fs/ksk/namespace", &emsg);
240 GNUNET_assert (NULL == emsg);
242 GNUNET_FS_namespace_advertise (h, ksk_uri, ns, adv_metadata, &bo,
243 root_identifier, &post_advertising,
250 FPRINTF (stderr, _("Option `%s' ignored\n"), "-k");
256 if (root_identifier != NULL)
257 FPRINTF (stderr, _("Option `%s' ignored\n"), "-r");
259 FPRINTF (stderr, _("Option `%s' ignored\n"), "-k");
262 post_advertising (NULL, NULL, NULL);
267 * The main function to manipulate GNUnet pseudonyms (and publish
270 * @param argc number of arguments from the command line
271 * @param argv command line arguments
272 * @return 0 ok, 1 on error
275 main (int argc, char *const *argv)
277 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
278 {'a', "anonymity", "LEVEL",
279 gettext_noop ("set the desired LEVEL of sender-anonymity"),
280 1, &GNUNET_GETOPT_set_uint, &bo.anonymity_level},
281 {'C', "create", "NAME",
282 gettext_noop ("create or advertise namespace NAME"),
283 1, &GNUNET_GETOPT_set_string, &create_ns},
284 {'D', "delete", "NAME",
285 gettext_noop ("delete namespace NAME "),
286 1, &GNUNET_GETOPT_set_string, &delete_ns},
287 {'k', "keyword", "VALUE",
288 gettext_noop ("add an additional keyword for the advertisment"
289 " (this option can be specified multiple times)"),
290 1, &GNUNET_FS_getopt_set_keywords, &ksk_uri},
291 {'m', "meta", "TYPE:VALUE",
292 gettext_noop ("set the meta-data for the given TYPE to the given VALUE"),
293 1, &GNUNET_FS_getopt_set_metadata, &adv_metadata},
294 {'o', "only-local", NULL,
295 gettext_noop ("print names of local namespaces"),
296 0, &GNUNET_GETOPT_set_one, &print_local_only},
297 {'p', "priority", "PRIORITY",
298 gettext_noop ("use the given PRIORITY for the advertisments"),
299 1, &GNUNET_GETOPT_set_uint, &bo.content_priority},
301 gettext_noop ("do not print names of remote namespaces"),
302 0, &GNUNET_GETOPT_set_one, &no_remote_printing},
303 {'r', "replication", "LEVEL",
304 gettext_noop ("set the desired replication LEVEL"),
305 1, &GNUNET_GETOPT_set_uint, &bo.replication_level},
307 gettext_noop ("specify ID of the root of the namespace"),
308 1, &GNUNET_GETOPT_set_string, &root_identifier},
309 {'s', "set-rating", "ID:VALUE",
310 gettext_noop ("change rating of namespace ID by VALUE"),
311 1, &GNUNET_GETOPT_set_string, &rating_change},
312 GNUNET_GETOPT_OPTION_END
315 GNUNET_FS_year_to_time (GNUNET_FS_get_current_year () + 2);
317 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
321 GNUNET_PROGRAM_run (argc, argv, "gnunet-pseudonym [OPTIONS]",
322 gettext_noop ("Manage GNUnet pseudonyms."),
323 options, &run, NULL)) ? ret : 1;
326 /* end of gnunet-pseudonym.c */