2 This file is part of GNUnet.
3 (C) 2001-2013 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"
27 #include "gnunet_identity_service.h"
33 static char *advertise_ns;
38 static struct GNUNET_FS_Uri *ksk_uri;
43 static struct GNUNET_CONTAINER_MetaData *adv_metadata;
46 * Our block options (-p, -r, -a).
48 static struct GNUNET_FS_BlockOptions bo = { {0LL}, 1, 365, 1 };
53 static int no_remote_printing;
58 static char *root_identifier;
63 static char *rating_change;
66 * Handle to fs service.
68 static struct GNUNET_FS_Handle *h;
73 static const struct GNUNET_CONFIGURATION_Handle *cfg;
76 * Handle to identity service.
78 static struct GNUNET_IDENTITY_Handle *identity;
83 static struct GNUNET_IDENTITY_Ego *namespace;
88 static struct GNUNET_FS_Uri *sks_uri;
91 * Global return value.
97 * Progress callback given to FS.
100 * @param info progress information, unused
103 progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
110 * Output information about a pseudonym.
113 * @param pseudonym hash code of public key of pseudonym
114 * @param name name of the pseudonym (might be NULL)
115 * @param unique_name unique name of the pseudonym (might be NULL)
116 * @param md meta data known about the pseudonym
117 * @param rating the local rating of the pseudonym
118 * @return GNUNET_OK to continue iteration, GNUNET_SYSERR to abort
121 pseudo_printer (void *cls,
122 const struct GNUNET_CRYPTO_EccPublicKey *pseudonym,
124 const char *unique_name,
125 const struct GNUNET_CONTAINER_MetaData *md,
132 /* While we get a name from the caller, it might be NULL.
133 * GNUNET_FS_pseudonym_get_info () never returns NULL.
135 getinfo_result = GNUNET_FS_pseudonym_get_info (cfg, pseudonym,
136 NULL, NULL, &id, NULL);
137 if (GNUNET_OK != getinfo_result)
142 unique_id = GNUNET_FS_pseudonym_name_uniquify (cfg, pseudonym, id, NULL);
147 GNUNET_CONTAINER_meta_data_iterate (md, &EXTRACTOR_meta_data_print, stdout);
151 GNUNET_free (unique_id);
157 * Function called once advertising is finished.
159 * @param cls closure (NULL)
160 * @param uri the advertised URI
161 * @param emsg error message, NULL on success
164 post_advertising (void *cls,
165 const struct GNUNET_FS_Uri *uri,
170 FPRINTF (stderr, "%s", emsg);
174 GNUNET_IDENTITY_disconnect (identity);
179 * Function called by identity service with known pseudonyms.
181 * @param cls closure, NULL
182 * @param ego ego handle
183 * @param ctx context for application to store data for this ego
184 * (during the lifetime of this process, initially NULL)
185 * @param name name assigned by the user for this ego,
186 * NULL if the user just deleted the ego and it
187 * must thus no longer be used
190 identity_cb (void *cls,
191 struct GNUNET_IDENTITY_Ego *ego,
196 struct GNUNET_CRYPTO_EccPublicKey pub;
200 if (NULL == namespace)
205 if (NULL != root_identifier)
210 ksk_uri = GNUNET_FS_uri_parse ("gnunet://fs/ksk/namespace", &emsg);
211 GNUNET_assert (NULL == emsg);
213 GNUNET_IDENTITY_ego_get_public_key (namespace,
215 sks_uri = GNUNET_FS_uri_sks_create (&pub,
217 GNUNET_FS_publish_ksk (h, ksk_uri, adv_metadata, sks_uri,
219 GNUNET_FS_PUBLISH_OPTION_NONE,
220 &post_advertising, NULL);
221 GNUNET_FS_uri_destroy (sks_uri);
227 FPRINTF (stderr, _("Option `%s' ignored\n"), "-k");
228 if (NULL != advertise_ns)
229 FPRINTF (stderr, _("Option `%s' ignored\n"), "-A");
233 if (0 == strcmp (name, advertise_ns))
239 * Main function that will be run by the scheduler.
242 * @param args remaining command-line arguments
243 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
244 * @param c configuration
247 run (void *cls, char *const *args, const char *cfgfile,
248 const struct GNUNET_CONFIGURATION_Handle *c)
250 struct GNUNET_CRYPTO_EccPublicKey nsid;
255 h = GNUNET_FS_start (cfg, "gnunet-pseudonym", &progress_cb, NULL,
256 GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
257 if (NULL != rating_change)
260 while ((*set != '\0') && (*set != ':'))
264 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
265 _("Invalid argument `%s'\n"),
271 delta = strtol (&set[1], NULL, /* no error handling yet */
273 if (GNUNET_OK == GNUNET_FS_pseudonym_name_to_id (cfg, rating_change, &nsid))
275 (void) GNUNET_FS_pseudonym_rank (cfg, &nsid, delta);
279 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
280 ("Namespace `%s' unknown. Make sure you specify its numeric suffix, if any.\n"),
284 GNUNET_free (rating_change);
285 rating_change = NULL;
287 if (0 == no_remote_printing)
288 GNUNET_FS_pseudonym_list_all (cfg, &pseudo_printer, NULL);
290 if (NULL != advertise_ns)
291 identity = GNUNET_IDENTITY_connect (cfg,
298 * The main function to manipulate GNUnet pseudonyms (and publish
301 * @param argc number of arguments from the command line
302 * @param argv command line arguments
303 * @return 0 ok, 1 on error
306 main (int argc, char *const *argv)
308 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
309 {'a', "anonymity", "LEVEL",
310 gettext_noop ("set the desired LEVEL of sender-anonymity"),
311 1, &GNUNET_GETOPT_set_uint, &bo.anonymity_level},
312 {'A', "advertise", "NAME",
313 gettext_noop ("advertise namespace NAME"),
314 1, &GNUNET_GETOPT_set_string, &advertise_ns},
315 {'k', "keyword", "VALUE",
316 gettext_noop ("add an additional keyword for the advertisment"
317 " (this option can be specified multiple times)"),
318 1, &GNUNET_FS_getopt_set_keywords, &ksk_uri},
319 {'m', "meta", "TYPE:VALUE",
320 gettext_noop ("set the meta-data for the given TYPE to the given VALUE"),
321 1, &GNUNET_FS_getopt_set_metadata, &adv_metadata},
322 {'p', "priority", "PRIORITY",
323 gettext_noop ("use the given PRIORITY for the advertisments"),
324 1, &GNUNET_GETOPT_set_uint, &bo.content_priority},
326 gettext_noop ("do not print names of remote namespaces"),
327 0, &GNUNET_GETOPT_set_one, &no_remote_printing},
328 {'r', "replication", "LEVEL",
329 gettext_noop ("set the desired replication LEVEL"),
330 1, &GNUNET_GETOPT_set_uint, &bo.replication_level},
332 gettext_noop ("specify ID of the root of the namespace"),
333 1, &GNUNET_GETOPT_set_string, &root_identifier},
334 {'s', "set-rating", "ID:VALUE",
335 gettext_noop ("change rating of namespace ID by VALUE"),
336 1, &GNUNET_GETOPT_set_string, &rating_change},
337 GNUNET_GETOPT_OPTION_END
340 GNUNET_FS_year_to_time (GNUNET_FS_get_current_year () + 2);
342 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
346 GNUNET_PROGRAM_run (argc, argv, "gnunet-pseudonym [OPTIONS]",
347 gettext_noop ("Manage GNUnet pseudonyms."),
348 options, &run, NULL)) ? ret : 1;
349 GNUNET_free ((void*) argv);
353 /* end of gnunet-pseudonym.c */