diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-08-06 20:46:22 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-08-06 20:46:22 +0000 |
commit | 303ab4dafbc680b1b362f95df5b12dae831b1593 (patch) | |
tree | 8b2f411b0b31e500ce2988404b2501db03bed945 /src/fs/gnunet-pseudonym.c | |
parent | 1360f8a1e5877a8796dc8e7d0c55d78481382e80 (diff) | |
download | gnunet-303ab4dafbc680b1b362f95df5b12dae831b1593.tar.gz gnunet-303ab4dafbc680b1b362f95df5b12dae831b1593.zip |
-fixing main FS build, updating man page of gnunet-pseudonym
Diffstat (limited to 'src/fs/gnunet-pseudonym.c')
-rw-r--r-- | src/fs/gnunet-pseudonym.c | 260 |
1 files changed, 131 insertions, 129 deletions
diff --git a/src/fs/gnunet-pseudonym.c b/src/fs/gnunet-pseudonym.c index 61975e463..c87679641 100644 --- a/src/fs/gnunet-pseudonym.c +++ b/src/fs/gnunet-pseudonym.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | (C) 2001, 2002, 2004, 2005, 2006, 2007, 2009, 2010 Christian Grothoff (and other contributing authors) | 3 | (C) 2001-2013 Christian Grothoff (and other contributing authors) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 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 | 6 | it under the terms of the GNU General Public License as published |
@@ -24,16 +24,13 @@ | |||
24 | */ | 24 | */ |
25 | #include "platform.h" | 25 | #include "platform.h" |
26 | #include "gnunet_fs_service.h" | 26 | #include "gnunet_fs_service.h" |
27 | #include "gnunet_identity_service.h" | ||
27 | 28 | ||
28 | /** | ||
29 | * -C option | ||
30 | */ | ||
31 | static char *create_ns; | ||
32 | 29 | ||
33 | /** | 30 | /** |
34 | * -D option | 31 | * -A option |
35 | */ | 32 | */ |
36 | static char *delete_ns; | 33 | static char *advertise_ns; |
37 | 34 | ||
38 | /** | 35 | /** |
39 | * -k option | 36 | * -k option |
@@ -41,11 +38,6 @@ static char *delete_ns; | |||
41 | static struct GNUNET_FS_Uri *ksk_uri; | 38 | static struct GNUNET_FS_Uri *ksk_uri; |
42 | 39 | ||
43 | /** | 40 | /** |
44 | * -l option. | ||
45 | */ | ||
46 | static int print_local_only; | ||
47 | |||
48 | /** | ||
49 | * -m option. | 41 | * -m option. |
50 | */ | 42 | */ |
51 | static struct GNUNET_CONTAINER_MetaData *adv_metadata; | 43 | static struct GNUNET_CONTAINER_MetaData *adv_metadata; |
@@ -76,17 +68,37 @@ static char *rating_change; | |||
76 | static struct GNUNET_FS_Handle *h; | 68 | static struct GNUNET_FS_Handle *h; |
77 | 69 | ||
78 | /** | 70 | /** |
79 | * Namespace we are looking at. | 71 | * Our configuration. |
72 | */ | ||
73 | static const struct GNUNET_CONFIGURATION_Handle *cfg; | ||
74 | |||
75 | /** | ||
76 | * Handle to identity service. | ||
80 | */ | 77 | */ |
81 | static struct GNUNET_FS_Namespace *ns; | 78 | static struct GNUNET_IDENTITY_Handle *identity; |
82 | 79 | ||
83 | /** | 80 | /** |
84 | * Our configuration. | 81 | * Target namespace. |
85 | */ | 82 | */ |
86 | static const struct GNUNET_CONFIGURATION_Handle *cfg; | 83 | static struct GNUNET_IDENTITY_Ego *namespace; |
87 | 84 | ||
85 | /** | ||
86 | * URI to advertise. | ||
87 | */ | ||
88 | static struct GNUNET_FS_Uri *sks_uri; | ||
89 | |||
90 | /** | ||
91 | * Global return value. | ||
92 | */ | ||
88 | static int ret; | 93 | static int ret; |
89 | 94 | ||
95 | |||
96 | /** | ||
97 | * Progress callback given to FS. | ||
98 | * | ||
99 | * @param cls unused | ||
100 | * @param info progress information, unused | ||
101 | */ | ||
90 | static void * | 102 | static void * |
91 | progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info) | 103 | progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info) |
92 | { | 104 | { |
@@ -94,20 +106,6 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info) | |||
94 | } | 106 | } |
95 | 107 | ||
96 | 108 | ||
97 | static void | ||
98 | ns_printer (void *cls, const char *name, const struct GNUNET_FS_PseudonymIdentifier *pseudonym) | ||
99 | { | ||
100 | struct GNUNET_CRYPTO_HashAsciiEncoded enc; | ||
101 | struct GNUNET_HashCode hc; | ||
102 | |||
103 | GNUNET_CRYPTO_hash (pseudonym, | ||
104 | sizeof (struct GNUNET_FS_PseudonymIdentifier), | ||
105 | &hc); | ||
106 | GNUNET_CRYPTO_hash_to_enc (&hc, &enc); | ||
107 | FPRINTF (stdout, "%s (%s)\n", name, (const char *) &enc); | ||
108 | } | ||
109 | |||
110 | |||
111 | /** | 109 | /** |
112 | * Output information about a pseudonym. | 110 | * Output information about a pseudonym. |
113 | * | 111 | * |
@@ -121,7 +119,7 @@ ns_printer (void *cls, const char *name, const struct GNUNET_FS_PseudonymIdentif | |||
121 | */ | 119 | */ |
122 | static int | 120 | static int |
123 | pseudo_printer (void *cls, | 121 | pseudo_printer (void *cls, |
124 | const struct GNUNET_FS_PseudonymIdentifier *pseudonym, | 122 | const struct GNUNET_CRYPTO_EccPublicKey *pseudonym, |
125 | const char *name, | 123 | const char *name, |
126 | const char *unique_name, | 124 | const char *unique_name, |
127 | const struct GNUNET_CONTAINER_MetaData *md, | 125 | const struct GNUNET_CONTAINER_MetaData *md, |
@@ -135,77 +133,105 @@ pseudo_printer (void *cls, | |||
135 | * GNUNET_FS_pseudonym_get_info () never returns NULL. | 133 | * GNUNET_FS_pseudonym_get_info () never returns NULL. |
136 | */ | 134 | */ |
137 | getinfo_result = GNUNET_FS_pseudonym_get_info (cfg, pseudonym, | 135 | getinfo_result = GNUNET_FS_pseudonym_get_info (cfg, pseudonym, |
138 | NULL, NULL, &id, NULL); | 136 | NULL, NULL, &id, NULL); |
139 | if (getinfo_result != GNUNET_OK) | 137 | if (GNUNET_OK != getinfo_result) |
140 | { | 138 | { |
141 | GNUNET_break (0); | 139 | GNUNET_break (0); |
142 | return GNUNET_OK; | 140 | return GNUNET_OK; |
143 | } | 141 | } |
144 | unique_id = GNUNET_FS_pseudonym_name_uniquify (cfg, pseudonym, id, NULL); | 142 | unique_id = GNUNET_FS_pseudonym_name_uniquify (cfg, pseudonym, id, NULL); |
145 | GNUNET_free (id); | 143 | GNUNET_free (id); |
146 | FPRINTF (stdout, "%s (%d):\n", unique_id, rating); | 144 | FPRINTF (stdout, |
145 | "%s (%d):\n", | ||
146 | unique_id, rating); | ||
147 | GNUNET_CONTAINER_meta_data_iterate (md, &EXTRACTOR_meta_data_print, stdout); | 147 | GNUNET_CONTAINER_meta_data_iterate (md, &EXTRACTOR_meta_data_print, stdout); |
148 | FPRINTF (stdout, "%s", "\n"); | 148 | FPRINTF (stdout, |
149 | "%s", | ||
150 | "\n"); | ||
149 | GNUNET_free (unique_id); | 151 | GNUNET_free (unique_id); |
150 | return GNUNET_OK; | 152 | return GNUNET_OK; |
151 | } | 153 | } |
152 | 154 | ||
153 | 155 | ||
156 | /** | ||
157 | * Function called once advertising is finished. | ||
158 | * | ||
159 | * @param cls closure (NULL) | ||
160 | * @param uri the advertised URI | ||
161 | * @param emsg error message, NULL on success | ||
162 | */ | ||
154 | static void | 163 | static void |
155 | post_advertising (void *cls, const struct GNUNET_FS_Uri *uri, const char *emsg) | 164 | post_advertising (void *cls, |
165 | const struct GNUNET_FS_Uri *uri, | ||
166 | const char *emsg) | ||
156 | { | 167 | { |
157 | struct GNUNET_FS_PseudonymIdentifier nsid; | ||
158 | char *set; | ||
159 | int delta; | ||
160 | |||
161 | if (emsg != NULL) | 168 | if (emsg != NULL) |
162 | { | 169 | { |
163 | FPRINTF (stderr, "%s", emsg); | 170 | FPRINTF (stderr, "%s", emsg); |
164 | ret = 1; | 171 | ret = 1; |
165 | } | 172 | } |
166 | if (ns != NULL) | 173 | GNUNET_FS_stop (h); |
167 | { | 174 | GNUNET_IDENTITY_disconnect (identity); |
168 | if (GNUNET_OK != GNUNET_FS_namespace_delete (ns, GNUNET_NO)) | 175 | } |
169 | ret = 1; | 176 | |
170 | } | 177 | |
171 | if (NULL != rating_change) | 178 | /** |
179 | * Function called by identity service with known pseudonyms. | ||
180 | * | ||
181 | * @param cls closure, NULL | ||
182 | * @param ego ego handle | ||
183 | * @param ego_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 | ||
188 | */ | ||
189 | static void | ||
190 | identity_cb (void *cls, | ||
191 | struct GNUNET_IDENTITY_Ego *ego, | ||
192 | void **ctx, | ||
193 | const char *name) | ||
194 | { | ||
195 | char *emsg; | ||
196 | struct GNUNET_CRYPTO_EccPublicKey pub; | ||
197 | |||
198 | if (NULL == ego) | ||
172 | { | 199 | { |
173 | set = rating_change; | 200 | if (NULL == namespace) |
174 | while ((*set != '\0') && (*set != ':')) | ||
175 | set++; | ||
176 | if (*set != ':') | ||
177 | { | 201 | { |
178 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Invalid argument `%s'\n"), | 202 | ret = 1; |
179 | rating_change); | 203 | return; |
180 | } | 204 | } |
181 | else | 205 | if (NULL != root_identifier) |
182 | { | 206 | { |
183 | *set = '\0'; | 207 | if (NULL == ksk_uri) |
184 | delta = strtol (&set[1], NULL, /* no error handling yet */ | ||
185 | 10); | ||
186 | if (GNUNET_OK == GNUNET_FS_pseudonym_name_to_id (cfg, rating_change, &nsid)) | ||
187 | { | 208 | { |
188 | (void) GNUNET_FS_pseudonym_rank (cfg, &nsid, delta); | 209 | emsg = NULL; |
189 | } | 210 | ksk_uri = GNUNET_FS_uri_parse ("gnunet://fs/ksk/namespace", &emsg); |
190 | else | 211 | GNUNET_assert (NULL == emsg); |
191 | { | ||
192 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
193 | ("Namespace `%s' unknown. Make sure you specify its numeric suffix, if any.\n"), | ||
194 | rating_change); | ||
195 | } | 212 | } |
213 | GNUNET_IDENTITY_ego_get_public_key (namespace, | ||
214 | &pub); | ||
215 | sks_uri = GNUNET_FS_uri_sks_create (&pub, | ||
216 | root_identifier); | ||
217 | GNUNET_FS_publish_ksk (h, ksk_uri, adv_metadata, sks_uri, | ||
218 | &bo, | ||
219 | GNUNET_FS_PUBLISH_OPTION_NONE, | ||
220 | &post_advertising, NULL); | ||
221 | GNUNET_FS_uri_destroy (sks_uri); | ||
222 | return; | ||
196 | } | 223 | } |
197 | GNUNET_free (rating_change); | 224 | else |
198 | rating_change = NULL; | 225 | { |
199 | } | 226 | if (NULL != ksk_uri) |
200 | if (0 != print_local_only) | 227 | FPRINTF (stderr, _("Option `%s' ignored\n"), "-k"); |
201 | { | 228 | if (NULL != advertise_ns) |
202 | GNUNET_FS_namespace_list (h, &ns_printer, NULL); | 229 | FPRINTF (stderr, _("Option `%s' ignored\n"), "-A"); |
203 | } | 230 | } |
204 | else if (0 == no_remote_printing) | 231 | return; |
205 | { | ||
206 | GNUNET_FS_pseudonym_list_all (cfg, &pseudo_printer, NULL); | ||
207 | } | 232 | } |
208 | GNUNET_FS_stop (h); | 233 | if (0 == strcmp (name, advertise_ns)) |
234 | namespace = ego; | ||
209 | } | 235 | } |
210 | 236 | ||
211 | 237 | ||
@@ -221,68 +247,50 @@ static void | |||
221 | run (void *cls, char *const *args, const char *cfgfile, | 247 | run (void *cls, char *const *args, const char *cfgfile, |
222 | const struct GNUNET_CONFIGURATION_Handle *c) | 248 | const struct GNUNET_CONFIGURATION_Handle *c) |
223 | { | 249 | { |
224 | struct GNUNET_FS_Uri *sks_uri; | 250 | struct GNUNET_CRYPTO_EccPublicKey nsid; |
225 | char *emsg; | 251 | char *set; |
252 | int delta; | ||
226 | 253 | ||
227 | cfg = c; | 254 | cfg = c; |
228 | h = GNUNET_FS_start (cfg, "gnunet-pseudonym", &progress_cb, NULL, | 255 | h = GNUNET_FS_start (cfg, "gnunet-pseudonym", &progress_cb, NULL, |
229 | GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); | 256 | GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); |
230 | if (NULL != delete_ns) | 257 | if (NULL != rating_change) |
231 | { | ||
232 | ns = GNUNET_FS_namespace_create (h, delete_ns); | ||
233 | if (ns == NULL) | ||
234 | { | ||
235 | ret = 1; | ||
236 | } | ||
237 | else | ||
238 | { | ||
239 | if (GNUNET_OK != GNUNET_FS_namespace_delete (ns, GNUNET_YES)) | ||
240 | ret = 1; | ||
241 | ns = NULL; | ||
242 | } | ||
243 | } | ||
244 | if (NULL != create_ns) | ||
245 | { | 258 | { |
246 | ns = GNUNET_FS_namespace_create (h, create_ns); | 259 | set = rating_change; |
247 | if (ns == NULL) | 260 | while ((*set != '\0') && (*set != ':')) |
261 | set++; | ||
262 | if (*set != ':') | ||
248 | { | 263 | { |
249 | ret = 1; | 264 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
265 | _("Invalid argument `%s'\n"), | ||
266 | rating_change); | ||
250 | } | 267 | } |
251 | else | 268 | else |
252 | { | 269 | { |
253 | if (NULL != root_identifier) | 270 | *set = '\0'; |
271 | delta = strtol (&set[1], NULL, /* no error handling yet */ | ||
272 | 10); | ||
273 | if (GNUNET_OK == GNUNET_FS_pseudonym_name_to_id (cfg, rating_change, &nsid)) | ||
254 | { | 274 | { |
255 | if (ksk_uri == NULL) | 275 | (void) GNUNET_FS_pseudonym_rank (cfg, &nsid, delta); |
256 | { | ||
257 | emsg = NULL; | ||
258 | ksk_uri = GNUNET_FS_uri_parse ("gnunet://fs/ksk/namespace", &emsg); | ||
259 | GNUNET_assert (NULL == emsg); | ||
260 | } | ||
261 | sks_uri = GNUNET_FS_uri_sks_create (ns, root_identifier, &emsg); | ||
262 | GNUNET_assert (NULL == emsg); | ||
263 | GNUNET_FS_publish_ksk (h, ksk_uri, adv_metadata, sks_uri, | ||
264 | &bo, | ||
265 | GNUNET_FS_PUBLISH_OPTION_NONE, | ||
266 | &post_advertising, NULL); | ||
267 | GNUNET_FS_uri_destroy (sks_uri); | ||
268 | return; | ||
269 | } | 276 | } |
270 | else | 277 | else |
271 | { | 278 | { |
272 | if (ksk_uri != NULL) | 279 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
273 | FPRINTF (stderr, _("Option `%s' ignored\n"), "-k"); | 280 | ("Namespace `%s' unknown. Make sure you specify its numeric suffix, if any.\n"), |
281 | rating_change); | ||
274 | } | 282 | } |
275 | } | 283 | } |
284 | GNUNET_free (rating_change); | ||
285 | rating_change = NULL; | ||
276 | } | 286 | } |
277 | else | 287 | if (0 == no_remote_printing) |
278 | { | 288 | GNUNET_FS_pseudonym_list_all (cfg, &pseudo_printer, NULL); |
279 | if (root_identifier != NULL) | ||
280 | FPRINTF (stderr, _("Option `%s' ignored\n"), "-r"); | ||
281 | if (ksk_uri != NULL) | ||
282 | FPRINTF (stderr, _("Option `%s' ignored\n"), "-k"); | ||
283 | } | ||
284 | 289 | ||
285 | post_advertising (NULL, NULL, NULL); | 290 | if (NULL != advertise_ns) |
291 | identity = GNUNET_IDENTITY_connect (cfg, | ||
292 | &identity_cb, | ||
293 | NULL); | ||
286 | } | 294 | } |
287 | 295 | ||
288 | 296 | ||
@@ -301,12 +309,9 @@ main (int argc, char *const *argv) | |||
301 | {'a', "anonymity", "LEVEL", | 309 | {'a', "anonymity", "LEVEL", |
302 | gettext_noop ("set the desired LEVEL of sender-anonymity"), | 310 | gettext_noop ("set the desired LEVEL of sender-anonymity"), |
303 | 1, &GNUNET_GETOPT_set_uint, &bo.anonymity_level}, | 311 | 1, &GNUNET_GETOPT_set_uint, &bo.anonymity_level}, |
304 | {'C', "create", "NAME", | 312 | {'A', "advertise", "NAME", |
305 | gettext_noop ("create or advertise namespace NAME"), | 313 | gettext_noop ("advertise namespace NAME"), |
306 | 1, &GNUNET_GETOPT_set_string, &create_ns}, | 314 | 1, &GNUNET_GETOPT_set_string, &advertise_ns}, |
307 | {'D', "delete", "NAME", | ||
308 | gettext_noop ("delete namespace NAME "), | ||
309 | 1, &GNUNET_GETOPT_set_string, &delete_ns}, | ||
310 | {'k', "keyword", "VALUE", | 315 | {'k', "keyword", "VALUE", |
311 | gettext_noop ("add an additional keyword for the advertisment" | 316 | gettext_noop ("add an additional keyword for the advertisment" |
312 | " (this option can be specified multiple times)"), | 317 | " (this option can be specified multiple times)"), |
@@ -314,9 +319,6 @@ main (int argc, char *const *argv) | |||
314 | {'m', "meta", "TYPE:VALUE", | 319 | {'m', "meta", "TYPE:VALUE", |
315 | gettext_noop ("set the meta-data for the given TYPE to the given VALUE"), | 320 | gettext_noop ("set the meta-data for the given TYPE to the given VALUE"), |
316 | 1, &GNUNET_FS_getopt_set_metadata, &adv_metadata}, | 321 | 1, &GNUNET_FS_getopt_set_metadata, &adv_metadata}, |
317 | {'o', "only-local", NULL, | ||
318 | gettext_noop ("print names of local namespaces"), | ||
319 | 0, &GNUNET_GETOPT_set_one, &print_local_only}, | ||
320 | {'p', "priority", "PRIORITY", | 322 | {'p', "priority", "PRIORITY", |
321 | gettext_noop ("use the given PRIORITY for the advertisments"), | 323 | gettext_noop ("use the given PRIORITY for the advertisments"), |
322 | 1, &GNUNET_GETOPT_set_uint, &bo.content_priority}, | 324 | 1, &GNUNET_GETOPT_set_uint, &bo.content_priority}, |