aboutsummaryrefslogtreecommitdiff
path: root/src/revocation/gnunet-revocation.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-10-06 22:00:14 +0000
committerChristian Grothoff <christian@grothoff.org>2013-10-06 22:00:14 +0000
commit9f7e7d369a842fe1621bc4b9af64ac3e5f609bde (patch)
treece8a877ecca413cc82013786c49ecb64920d34a4 /src/revocation/gnunet-revocation.c
parentba414944bc487d03442a05a8d6415ce8d536ddd0 (diff)
downloadgnunet-9f7e7d369a842fe1621bc4b9af64ac3e5f609bde.tar.gz
gnunet-9f7e7d369a842fe1621bc4b9af64ac3e5f609bde.zip
-finishing revocation command line tool
Diffstat (limited to 'src/revocation/gnunet-revocation.c')
-rw-r--r--src/revocation/gnunet-revocation.c73
1 files changed, 53 insertions, 20 deletions
diff --git a/src/revocation/gnunet-revocation.c b/src/revocation/gnunet-revocation.c
index 1859722d8..5f97a7112 100644
--- a/src/revocation/gnunet-revocation.c
+++ b/src/revocation/gnunet-revocation.c
@@ -153,14 +153,24 @@ print_revocation_result (void *cls,
153 switch (is_valid) 153 switch (is_valid)
154 { 154 {
155 case GNUNET_YES: 155 case GNUNET_YES:
156 FPRINTF (stdout, 156 if (NULL != revoke_ego)
157 _("Key for ego `%s' is still valid, revocation failed (!)\n"), 157 FPRINTF (stdout,
158 test_ego); 158 _("Key for ego `%s' is still valid, revocation failed (!)\n"),
159 revoke_ego);
160 else
161 FPRINTF (stdout,
162 "%s",
163 _("Revocation failed (!)\n"));
159 break; 164 break;
160 case GNUNET_NO: 165 case GNUNET_NO:
161 FPRINTF (stdout, 166 if (NULL != revoke_ego)
162 _("Key for ego `%s' has been successfully revoked\n"), 167 FPRINTF (stdout,
163 test_ego); 168 _("Key for ego `%s' has been successfully revoked\n"),
169 revoke_ego);
170 else
171 FPRINTF (stdout,
172 "%s",
173 _("Revocation successful.\n"));
164 break; 174 break;
165 case GNUNET_SYSERR: 175 case GNUNET_SYSERR:
166 FPRINTF (stdout, 176 FPRINTF (stdout,
@@ -224,15 +234,10 @@ calculate_pow (void *cls,
224{ 234{
225 struct RevocationData *rd = cls; 235 struct RevocationData *rd = cls;
226 236
237 /* store temporary results */
227 if ( (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason)) || 238 if ( (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason)) ||
228 (0 == (rd->pow % 128) ) ) 239 (0 == (rd->pow % 128) ) )
229 { 240 {
230 if (0 == (rd->pow % 128 * 1024))
231 {
232 if (0 == (rd->pow % (1024 * 128 * 80)))
233 fprintf (stderr, "\n");
234 fprintf (stderr, ".");
235 }
236 if ( (NULL != filename) && 241 if ( (NULL != filename) &&
237 (sizeof (struct RevocationData) == 242 (sizeof (struct RevocationData) ==
238 GNUNET_DISK_fn_write (filename, 243 GNUNET_DISK_fn_write (filename,
@@ -244,11 +249,21 @@ calculate_pow (void *cls,
244 "write", 249 "write",
245 filename); 250 filename);
246 } 251 }
252 /* display progress estimate */
253 if ( (0 == ((1 << matching_bits) / 100 / 50)) ||
254 (0 == (rd->pow % ((1 << matching_bits) / 100 / 50))) )
255 FPRINTF (stderr, "%s", ".");
256 if ( (0 != rd->pow) &&
257 ( (0 == ((1 << matching_bits) / 100)) ||
258 (0 == (rd->pow % ((1 << matching_bits) / 100))) ) )
259 FPRINTF (stderr, " - @ %3u%% (estimate)\n",
260 (unsigned int) (rd->pow * 100) / (1 << matching_bits));
247 if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason)) 261 if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
248 { 262 {
249 GNUNET_free (rd); 263 GNUNET_free (rd);
250 return; 264 return;
251 } 265 }
266 /* actually do POW calculation */
252 rd->pow++; 267 rd->pow++;
253 if (GNUNET_OK == 268 if (GNUNET_OK ==
254 GNUNET_REVOCATION_check_pow (&rd->key, 269 GNUNET_REVOCATION_check_pow (&rd->key,
@@ -256,10 +271,10 @@ calculate_pow (void *cls,
256 (unsigned int) matching_bits)) 271 (unsigned int) matching_bits))
257 { 272 {
258 if ( (NULL != filename) && 273 if ( (NULL != filename) &&
259 (sizeof (struct RevocationData) == 274 (sizeof (struct RevocationData) !=
260 GNUNET_DISK_fn_write (filename, 275 GNUNET_DISK_fn_write (filename,
261 &rd, 276 rd,
262 sizeof (rd), 277 sizeof (struct RevocationData),
263 GNUNET_DISK_PERM_USER_READ | 278 GNUNET_DISK_PERM_USER_READ |
264 GNUNET_DISK_PERM_USER_WRITE)) ) 279 GNUNET_DISK_PERM_USER_WRITE)) )
265 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, 280 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
@@ -269,6 +284,7 @@ calculate_pow (void *cls,
269 perform_revocation (rd); 284 perform_revocation (rd);
270 else 285 else
271 { 286 {
287 FPRINTF (stderr, "%s", "\n");
272 FPRINTF (stderr, 288 FPRINTF (stderr,
273 _("Revocation certificate for `%s' stored in `%s'\n"), 289 _("Revocation certificate for `%s' stored in `%s'\n"),
274 revoke_ego, 290 revoke_ego,
@@ -276,6 +292,7 @@ calculate_pow (void *cls,
276 GNUNET_SCHEDULER_shutdown (); 292 GNUNET_SCHEDULER_shutdown ();
277 } 293 }
278 GNUNET_free (rd); 294 GNUNET_free (rd);
295 return;
279 } 296 }
280 GNUNET_SCHEDULER_add_now (&calculate_pow, 297 GNUNET_SCHEDULER_add_now (&calculate_pow,
281 rd); 298 rd);
@@ -312,8 +329,8 @@ ego_callback (void *cls,
312 GNUNET_DISK_file_test (filename)) && 329 GNUNET_DISK_file_test (filename)) &&
313 (sizeof (struct RevocationData) == 330 (sizeof (struct RevocationData) ==
314 GNUNET_DISK_fn_read (filename, 331 GNUNET_DISK_fn_read (filename,
315 &rd, 332 rd,
316 sizeof (rd))) ) 333 sizeof (struct RevocationData))) )
317 { 334 {
318 if (0 != memcmp (&rd->key, 335 if (0 != memcmp (&rd->key,
319 &key, 336 &key,
@@ -340,8 +357,11 @@ ego_callback (void *cls,
340 { 357 {
341 FPRINTF (stderr, 358 FPRINTF (stderr,
342 "%s", 359 "%s",
343 _("Revocation certificate ready, initiating revocation\n")); 360 _("Revocation certificate ready\n"));
344 perform_revocation (rd); 361 if (perform)
362 perform_revocation (rd);
363 else
364 GNUNET_SCHEDULER_shutdown ();
345 GNUNET_free (rd); 365 GNUNET_free (rd);
346 return; 366 return;
347 } 367 }
@@ -432,10 +452,23 @@ run (void *cls,
432 filename); 452 filename);
433 return; 453 return;
434 } 454 }
435 perform_revocation (&rd);
436 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 455 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
437 &do_shutdown, 456 &do_shutdown,
438 NULL); 457 NULL);
458 if (GNUNET_YES !=
459 GNUNET_REVOCATION_check_pow (&rd.key,
460 rd.pow,
461 (unsigned int) matching_bits))
462 {
463 struct RevocationData *cp = GNUNET_new (struct RevocationData);
464
465 *cp = rd;
466 GNUNET_SCHEDULER_add_now (&calculate_pow,
467 cp);
468 return;
469
470 }
471 perform_revocation (&rd);
439 return; 472 return;
440 } 473 }
441 FPRINTF (stderr, 474 FPRINTF (stderr,