diff options
Diffstat (limited to 'src/fs/gnunet-pseudonym.c')
-rw-r--r-- | src/fs/gnunet-pseudonym.c | 267 |
1 files changed, 113 insertions, 154 deletions
diff --git a/src/fs/gnunet-pseudonym.c b/src/fs/gnunet-pseudonym.c index df67571a0..742111c4e 100644 --- a/src/fs/gnunet-pseudonym.c +++ b/src/fs/gnunet-pseudonym.c | |||
@@ -53,12 +53,12 @@ static struct GNUNET_CONTAINER_MetaData *adv_metadata; | |||
53 | /** | 53 | /** |
54 | * Our block options (-p, -r, -a). | 54 | * Our block options (-p, -r, -a). |
55 | */ | 55 | */ |
56 | static struct GNUNET_FS_BlockOptions bo = { { 0LL }, 1, 365, 1 }; | 56 | static struct GNUNET_FS_BlockOptions bo = { {0LL}, 1, 365, 1 }; |
57 | 57 | ||
58 | /** | 58 | /** |
59 | * -q option given. | 59 | * -q option given. |
60 | */ | 60 | */ |
61 | static int no_remote_printing; | 61 | static int no_remote_printing; |
62 | 62 | ||
63 | /** | 63 | /** |
64 | * -r option. | 64 | * -r option. |
@@ -87,53 +87,39 @@ static const struct GNUNET_CONFIGURATION_Handle *cfg; | |||
87 | 87 | ||
88 | static int ret; | 88 | static int ret; |
89 | 89 | ||
90 | static void* | 90 | static void * |
91 | progress_cb (void *cls, | 91 | progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info) |
92 | const struct GNUNET_FS_ProgressInfo *info) | ||
93 | { | 92 | { |
94 | return NULL; | 93 | return NULL; |
95 | } | 94 | } |
96 | 95 | ||
97 | 96 | ||
98 | static void | 97 | static void |
99 | ns_printer (void *cls, | 98 | ns_printer (void *cls, const char *name, const GNUNET_HashCode * id) |
100 | const char *name, | ||
101 | const GNUNET_HashCode *id) | ||
102 | { | 99 | { |
103 | struct GNUNET_CRYPTO_HashAsciiEncoded enc; | 100 | struct GNUNET_CRYPTO_HashAsciiEncoded enc; |
104 | 101 | ||
105 | GNUNET_CRYPTO_hash_to_enc (id, &enc); | 102 | GNUNET_CRYPTO_hash_to_enc (id, &enc); |
106 | fprintf (stdout, | 103 | fprintf (stdout, "%s (%s)\n", name, (const char *) &enc); |
107 | "%s (%s)\n", | ||
108 | name, | ||
109 | (const char*) &enc); | ||
110 | } | 104 | } |
111 | 105 | ||
112 | 106 | ||
113 | static int | 107 | static int |
114 | pseudo_printer (void *cls, | 108 | pseudo_printer (void *cls, |
115 | const GNUNET_HashCode * | 109 | const GNUNET_HashCode * |
116 | pseudonym, | 110 | pseudonym, |
117 | const struct | 111 | const struct GNUNET_CONTAINER_MetaData *md, int rating) |
118 | GNUNET_CONTAINER_MetaData * md, | ||
119 | int rating) | ||
120 | { | 112 | { |
121 | char *id; | 113 | char *id; |
122 | 114 | ||
123 | id = GNUNET_PSEUDONYM_id_to_name (cfg, | 115 | id = GNUNET_PSEUDONYM_id_to_name (cfg, pseudonym); |
124 | pseudonym); | ||
125 | if (id == NULL) | 116 | if (id == NULL) |
126 | { | 117 | { |
127 | GNUNET_break (0); | 118 | GNUNET_break (0); |
128 | return GNUNET_OK; | 119 | return GNUNET_OK; |
129 | } | 120 | } |
130 | fprintf (stdout, | 121 | fprintf (stdout, "%s (%d):\n", id, rating); |
131 | "%s (%d):\n", | 122 | GNUNET_CONTAINER_meta_data_iterate (md, &EXTRACTOR_meta_data_print, stdout); |
132 | id, | ||
133 | rating); | ||
134 | GNUNET_CONTAINER_meta_data_iterate (md, | ||
135 | &EXTRACTOR_meta_data_print, | ||
136 | stdout); | ||
137 | fprintf (stdout, "\n"); | 123 | fprintf (stdout, "\n"); |
138 | GNUNET_free (id); | 124 | GNUNET_free (id); |
139 | return GNUNET_OK; | 125 | return GNUNET_OK; |
@@ -141,73 +127,58 @@ pseudo_printer (void *cls, | |||
141 | 127 | ||
142 | 128 | ||
143 | static void | 129 | static void |
144 | post_advertising (void *cls, | 130 | post_advertising (void *cls, const struct GNUNET_FS_Uri *uri, const char *emsg) |
145 | const struct GNUNET_FS_Uri *uri, | ||
146 | const char *emsg) | ||
147 | { | 131 | { |
148 | GNUNET_HashCode nsid; | 132 | GNUNET_HashCode nsid; |
149 | char *set; | 133 | char *set; |
150 | int delta; | 134 | int delta; |
151 | 135 | ||
152 | if (emsg != NULL) | 136 | if (emsg != NULL) |
153 | { | 137 | { |
154 | fprintf (stderr, "%s", emsg); | 138 | fprintf (stderr, "%s", emsg); |
155 | ret = 1; | 139 | ret = 1; |
156 | } | 140 | } |
157 | if (ns != NULL) | 141 | if (ns != NULL) |
142 | { | ||
143 | if (GNUNET_OK != GNUNET_FS_namespace_delete (ns, GNUNET_NO)) | ||
144 | ret = 1; | ||
145 | } | ||
146 | if (NULL != rating_change) | ||
147 | { | ||
148 | set = rating_change; | ||
149 | while ((*set != '\0') && (*set != ':')) | ||
150 | set++; | ||
151 | if (*set != ':') | ||
158 | { | 152 | { |
159 | if (GNUNET_OK != | 153 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
160 | GNUNET_FS_namespace_delete (ns, | 154 | _("Invalid argument `%s'\n"), rating_change); |
161 | GNUNET_NO)) | ||
162 | ret = 1; | ||
163 | } | 155 | } |
164 | if (NULL != rating_change) | 156 | else |
165 | { | 157 | { |
166 | set = rating_change; | 158 | *set = '\0'; |
167 | while ((*set != '\0') && (*set != ':')) | 159 | delta = strtol (&set[1], NULL, /* no error handling yet */ |
168 | set++; | 160 | 10); |
169 | if (*set != ':') | 161 | if (GNUNET_OK == GNUNET_PSEUDONYM_name_to_id (cfg, rating_change, &nsid)) |
170 | { | 162 | { |
171 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 163 | (void) GNUNET_PSEUDONYM_rank (cfg, &nsid, delta); |
172 | _("Invalid argument `%s'\n"), | 164 | } |
173 | rating_change); | ||
174 | } | ||
175 | else | 165 | else |
176 | { | 166 | { |
177 | *set = '\0'; | 167 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
178 | delta = strtol (&set[1], NULL, /* no error handling yet */ | 168 | _("Namespace `%s' unknown.\n"), rating_change); |
179 | 10); | 169 | } |
180 | if (GNUNET_OK == | ||
181 | GNUNET_PSEUDONYM_name_to_id (cfg, | ||
182 | rating_change, | ||
183 | &nsid)) | ||
184 | { | ||
185 | (void) GNUNET_PSEUDONYM_rank (cfg, | ||
186 | &nsid, | ||
187 | delta); | ||
188 | } | ||
189 | else | ||
190 | { | ||
191 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
192 | _("Namespace `%s' unknown.\n"), | ||
193 | rating_change); | ||
194 | } | ||
195 | } | ||
196 | GNUNET_free (rating_change); | ||
197 | rating_change = NULL; | ||
198 | } | 170 | } |
171 | GNUNET_free (rating_change); | ||
172 | rating_change = NULL; | ||
173 | } | ||
199 | if (0 != print_local_only) | 174 | if (0 != print_local_only) |
200 | { | 175 | { |
201 | GNUNET_FS_namespace_list (h, | 176 | GNUNET_FS_namespace_list (h, &ns_printer, NULL); |
202 | &ns_printer, | 177 | } |
203 | NULL); | ||
204 | } | ||
205 | else if (0 == no_remote_printing) | 178 | else if (0 == no_remote_printing) |
206 | { | 179 | { |
207 | GNUNET_PSEUDONYM_list_all (cfg, | 180 | GNUNET_PSEUDONYM_list_all (cfg, &pseudo_printer, NULL); |
208 | &pseudo_printer, | 181 | } |
209 | NULL); | ||
210 | } | ||
211 | GNUNET_FS_stop (h); | 182 | GNUNET_FS_stop (h); |
212 | } | 183 | } |
213 | 184 | ||
@@ -223,76 +194,70 @@ post_advertising (void *cls, | |||
223 | static void | 194 | static void |
224 | run (void *cls, | 195 | run (void *cls, |
225 | char *const *args, | 196 | char *const *args, |
226 | const char *cfgfile, | 197 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c) |
227 | const struct GNUNET_CONFIGURATION_Handle *c) | ||
228 | { | 198 | { |
229 | char *emsg; | 199 | char *emsg; |
230 | 200 | ||
231 | cfg = c; | 201 | cfg = c; |
232 | h = GNUNET_FS_start (cfg, | 202 | h = GNUNET_FS_start (cfg, |
233 | "gnunet-pseudonym", | 203 | "gnunet-pseudonym", |
234 | &progress_cb, | 204 | &progress_cb, |
235 | NULL, | 205 | NULL, GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); |
236 | GNUNET_FS_FLAGS_NONE, | ||
237 | GNUNET_FS_OPTIONS_END); | ||
238 | if (NULL != delete_ns) | 206 | if (NULL != delete_ns) |
207 | { | ||
208 | ns = GNUNET_FS_namespace_create (h, delete_ns); | ||
209 | if (ns == NULL) | ||
239 | { | 210 | { |
240 | ns = GNUNET_FS_namespace_create (h, delete_ns); | 211 | ret = 1; |
241 | if (ns == NULL) | 212 | } |
242 | { | 213 | else |
243 | ret = 1; | 214 | { |
244 | } | 215 | if (GNUNET_OK != GNUNET_FS_namespace_delete (ns, GNUNET_YES)) |
245 | else | 216 | ret = 1; |
246 | { | 217 | ns = NULL; |
247 | if (GNUNET_OK != | ||
248 | GNUNET_FS_namespace_delete (ns, | ||
249 | GNUNET_YES)) | ||
250 | ret = 1; | ||
251 | ns = NULL; | ||
252 | } | ||
253 | } | 218 | } |
219 | } | ||
254 | if (NULL != create_ns) | 220 | if (NULL != create_ns) |
221 | { | ||
222 | ns = GNUNET_FS_namespace_create (h, create_ns); | ||
223 | if (ns == NULL) | ||
224 | { | ||
225 | ret = 1; | ||
226 | } | ||
227 | else | ||
255 | { | 228 | { |
256 | ns = GNUNET_FS_namespace_create (h, create_ns); | 229 | if (NULL != root_identifier) |
257 | if (ns == NULL) | 230 | { |
258 | { | 231 | if (ksk_uri == NULL) |
259 | ret = 1; | 232 | { |
260 | } | 233 | emsg = NULL; |
234 | ksk_uri = GNUNET_FS_uri_parse ("gnunet://fs/ksk/namespace", &emsg); | ||
235 | GNUNET_assert (NULL == emsg); | ||
236 | } | ||
237 | GNUNET_FS_namespace_advertise (h, | ||
238 | ksk_uri, | ||
239 | ns, | ||
240 | adv_metadata, | ||
241 | &bo, | ||
242 | root_identifier, | ||
243 | &post_advertising, NULL); | ||
244 | return; | ||
245 | } | ||
261 | else | 246 | else |
262 | { | 247 | { |
263 | if (NULL != root_identifier) | 248 | if (ksk_uri != NULL) |
264 | { | 249 | fprintf (stderr, _("Option `%s' ignored\n"), "-k"); |
265 | if (ksk_uri == NULL) | 250 | } |
266 | { | ||
267 | emsg = NULL; | ||
268 | ksk_uri = GNUNET_FS_uri_parse ("gnunet://fs/ksk/namespace", &emsg); | ||
269 | GNUNET_assert (NULL == emsg); | ||
270 | } | ||
271 | GNUNET_FS_namespace_advertise (h, | ||
272 | ksk_uri, | ||
273 | ns, | ||
274 | adv_metadata, | ||
275 | &bo, | ||
276 | root_identifier, | ||
277 | &post_advertising, | ||
278 | NULL); | ||
279 | return; | ||
280 | } | ||
281 | else | ||
282 | { | ||
283 | if (ksk_uri != NULL) | ||
284 | fprintf (stderr, _("Option `%s' ignored\n"), "-k"); | ||
285 | } | ||
286 | } | ||
287 | } | 251 | } |
252 | } | ||
288 | else | 253 | else |
289 | { | 254 | { |
290 | if (root_identifier != NULL) | 255 | if (root_identifier != NULL) |
291 | fprintf (stderr, _("Option `%s' ignored\n"), "-r"); | 256 | fprintf (stderr, _("Option `%s' ignored\n"), "-r"); |
292 | if (ksk_uri != NULL) | 257 | if (ksk_uri != NULL) |
293 | fprintf (stderr, _("Option `%s' ignored\n"), "-k"); | 258 | fprintf (stderr, _("Option `%s' ignored\n"), "-k"); |
294 | } | 259 | } |
295 | 260 | ||
296 | post_advertising (NULL, NULL, NULL); | 261 | post_advertising (NULL, NULL, NULL); |
297 | } | 262 | } |
298 | 263 | ||
@@ -313,12 +278,10 @@ main (int argc, char *const *argv) | |||
313 | gettext_noop ("set the desired LEVEL of sender-anonymity"), | 278 | gettext_noop ("set the desired LEVEL of sender-anonymity"), |
314 | 1, &GNUNET_GETOPT_set_uint, &bo.anonymity_level}, | 279 | 1, &GNUNET_GETOPT_set_uint, &bo.anonymity_level}, |
315 | {'C', "create", "NAME", | 280 | {'C', "create", "NAME", |
316 | gettext_noop | 281 | gettext_noop ("create or advertise namespace NAME"), |
317 | ("create or advertise namespace NAME"), | ||
318 | 1, &GNUNET_GETOPT_set_string, &create_ns}, | 282 | 1, &GNUNET_GETOPT_set_string, &create_ns}, |
319 | {'D', "delete", "NAME", | 283 | {'D', "delete", "NAME", |
320 | gettext_noop | 284 | gettext_noop ("delete namespace NAME "), |
321 | ("delete namespace NAME "), | ||
322 | 1, &GNUNET_GETOPT_set_string, &delete_ns}, | 285 | 1, &GNUNET_GETOPT_set_string, &delete_ns}, |
323 | {'k', "keyword", "VALUE", | 286 | {'k', "keyword", "VALUE", |
324 | gettext_noop | 287 | gettext_noop |
@@ -341,22 +304,18 @@ main (int argc, char *const *argv) | |||
341 | gettext_noop ("set the desired replication LEVEL"), | 304 | gettext_noop ("set the desired replication LEVEL"), |
342 | 1, &GNUNET_GETOPT_set_uint, &bo.replication_level}, | 305 | 1, &GNUNET_GETOPT_set_uint, &bo.replication_level}, |
343 | {'R', "root", "ID", | 306 | {'R', "root", "ID", |
344 | gettext_noop | 307 | gettext_noop ("specify ID of the root of the namespace"), |
345 | ("specify ID of the root of the namespace"), | ||
346 | 1, &GNUNET_GETOPT_set_string, &root_identifier}, | 308 | 1, &GNUNET_GETOPT_set_string, &root_identifier}, |
347 | {'s', "set-rating", "ID:VALUE", | 309 | {'s', "set-rating", "ID:VALUE", |
348 | gettext_noop | 310 | gettext_noop ("change rating of namespace ID by VALUE"), |
349 | ("change rating of namespace ID by VALUE"), | ||
350 | 1, &GNUNET_GETOPT_set_string, &rating_change}, | 311 | 1, &GNUNET_GETOPT_set_string, &rating_change}, |
351 | GNUNET_GETOPT_OPTION_END | 312 | GNUNET_GETOPT_OPTION_END |
352 | }; | 313 | }; |
353 | bo.expiration_time = GNUNET_FS_year_to_time (GNUNET_FS_get_current_year () + 2); | 314 | bo.expiration_time = |
315 | GNUNET_FS_year_to_time (GNUNET_FS_get_current_year () + 2); | ||
354 | return (GNUNET_OK == | 316 | return (GNUNET_OK == |
355 | GNUNET_PROGRAM_run (argc, | 317 | GNUNET_PROGRAM_run (argc, argv, "gnunet-pseudonym [OPTIONS]", |
356 | argv, | 318 | gettext_noop ("Manage GNUnet pseudonyms."), |
357 | "gnunet-pseudonym [OPTIONS]", | ||
358 | gettext_noop | ||
359 | ("Manage GNUnet pseudonyms."), | ||
360 | options, &run, NULL)) ? ret : 1; | 319 | options, &run, NULL)) ? ret : 1; |
361 | } | 320 | } |
362 | 321 | ||