- begin work on enhanced multipart receiving
[oweals/gnunet.git] / src / revocation / gnunet-revocation.c
index 1859722d8163d43744e3189eeb668a7460941526..59f47ab9752d236977aeeb685e37244cd8fbd344 100644 (file)
@@ -153,14 +153,24 @@ print_revocation_result (void *cls,
   switch (is_valid)
   {
   case GNUNET_YES:
-    FPRINTF (stdout,
-             _("Key for ego `%s' is still valid, revocation failed (!)\n"),
-             test_ego);
+    if (NULL != revoke_ego)
+      FPRINTF (stdout,
+               _("Key for ego `%s' is still valid, revocation failed (!)\n"),
+               revoke_ego);
+    else
+      FPRINTF (stdout,
+               "%s",
+               _("Revocation failed (!)\n"));
     break;
   case GNUNET_NO:
-    FPRINTF (stdout,
-             _("Key for ego `%s' has been successfully revoked\n"),
-             test_ego);
+    if (NULL != revoke_ego)
+      FPRINTF (stdout,
+               _("Key for ego `%s' has been successfully revoked\n"),
+               revoke_ego);
+    else
+      FPRINTF (stdout,
+               "%s",
+               _("Revocation successful.\n"));
     break;
   case GNUNET_SYSERR:
     FPRINTF (stdout,
@@ -183,12 +193,12 @@ struct RevocationData
   /**
    * Public key.
    */
-  struct GNUNET_CRYPTO_EccPublicSignKey key;
+  struct GNUNET_CRYPTO_EcdsaPublicKey key;
 
   /**
    * Revocation signature data.
    */
-  struct GNUNET_CRYPTO_EccSignature sig;
+  struct GNUNET_CRYPTO_EcdsaSignature sig;
 
   /**
    * Proof of work (in NBO).
@@ -224,15 +234,10 @@ calculate_pow (void *cls,
 {
   struct RevocationData *rd = cls;
 
+  /* store temporary results */
   if ( (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason)) ||
        (0 == (rd->pow % 128) ) )
   {
-    if (0 == (rd->pow % 128 * 1024))
-    {
-      if (0 == (rd->pow % (1024 * 128 * 80)))
-        fprintf (stderr, "\n");
-      fprintf (stderr, ".");
-    }
     if ( (NULL != filename) &&
          (sizeof (struct RevocationData) ==
           GNUNET_DISK_fn_write (filename,
@@ -244,11 +249,21 @@ calculate_pow (void *cls,
                                 "write",
                                 filename);
   }
+  /* display progress estimate */
+  if ( (0 == ((1 << matching_bits) / 100 / 50)) ||
+       (0 == (rd->pow % ((1 << matching_bits) / 100 / 50))) )
+    FPRINTF (stderr, "%s", ".");
+  if ( (0 != rd->pow) &&
+       ( (0 == ((1 << matching_bits) / 100)) ||
+         (0 == (rd->pow % ((1 << matching_bits) / 100))) ) )
+    FPRINTF (stderr, " - @ %3u%% (estimate)\n",
+             (unsigned int) (rd->pow * 100) / (1 << matching_bits));
   if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
   {
     GNUNET_free (rd);
     return;
   }
+  /* actually do POW calculation */
   rd->pow++;
   if (GNUNET_OK ==
       GNUNET_REVOCATION_check_pow (&rd->key,
@@ -256,10 +271,10 @@ calculate_pow (void *cls,
                                    (unsigned int) matching_bits))
   {
     if ( (NULL != filename) &&
-         (sizeof (struct RevocationData) ==
+         (sizeof (struct RevocationData) !=
           GNUNET_DISK_fn_write (filename,
-                                &rd,
-                                sizeof (rd),
+                                rd,
+                                sizeof (struct RevocationData),
                                 GNUNET_DISK_PERM_USER_READ |
                                 GNUNET_DISK_PERM_USER_WRITE)) )
       GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
@@ -269,6 +284,7 @@ calculate_pow (void *cls,
       perform_revocation (rd);
     else
     {
+      FPRINTF (stderr, "%s", "\n");
       FPRINTF (stderr,
                _("Revocation certificate for `%s' stored in `%s'\n"),
                revoke_ego,
@@ -276,6 +292,7 @@ calculate_pow (void *cls,
       GNUNET_SCHEDULER_shutdown ();
     }
     GNUNET_free (rd);
+    return;
   }
   GNUNET_SCHEDULER_add_now (&calculate_pow,
                             rd);
@@ -293,14 +310,14 @@ ego_callback (void *cls,
               const struct GNUNET_IDENTITY_Ego *ego)
 {
   struct RevocationData *rd;
-  struct GNUNET_CRYPTO_EccPublicSignKey key;
+  struct GNUNET_CRYPTO_EcdsaPublicKey key;
 
   el = NULL;
   if (NULL == ego)
   {
     FPRINTF (stdout,
              _("Ego `%s' not found.\n"),
-             test_ego);
+             revoke_ego);
     GNUNET_SCHEDULER_shutdown ();
     return;
   }
@@ -312,12 +329,12 @@ ego_callback (void *cls,
         GNUNET_DISK_file_test (filename)) &&
        (sizeof (struct RevocationData) ==
         GNUNET_DISK_fn_read (filename,
-                             &rd,
-                             sizeof (rd))) )
+                             rd,
+                             sizeof (struct RevocationData))) )
   {
     if (0 != memcmp (&rd->key,
                      &key,
-                     sizeof (struct GNUNET_CRYPTO_EccPublicSignKey)))
+                     sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)))
     {
       fprintf (stderr,
                _("Error: revocation certificate in `%s' is not for `%s'\n"),
@@ -340,8 +357,11 @@ ego_callback (void *cls,
   {
     FPRINTF (stderr,
              "%s",
-             _("Revocation certificate ready, initiating revocation\n"));
-    perform_revocation (rd);
+             _("Revocation certificate ready\n"));
+    if (perform)
+      perform_revocation (rd);
+    else
+      GNUNET_SCHEDULER_shutdown ();
     GNUNET_free (rd);
     return;
   }
@@ -367,14 +387,14 @@ run (void *cls,
      const char *cfgfile,
      const struct GNUNET_CONFIGURATION_Handle *c)
 {
-  struct GNUNET_CRYPTO_EccPublicSignKey pk;
+  struct GNUNET_CRYPTO_EcdsaPublicKey pk;
   struct RevocationData rd;
 
   cfg = c;
   if (NULL != test_ego)
   {
     if (GNUNET_OK !=
-        GNUNET_CRYPTO_ecc_public_sign_key_from_string (test_ego,
+        GNUNET_CRYPTO_ecdsa_public_key_from_string (test_ego,
                                                        strlen (test_ego),
                                                        &pk))
     {
@@ -409,6 +429,13 @@ run (void *cls,
   }
   if (NULL != revoke_ego)
   {
+    if ( !perform && (NULL == filename) )
+    {
+        FPRINTF (stderr,
+                 "%s",
+                 _("No filename to store revocation certificate given.\n"));
+        return;
+    }
     /* main code here */
     el = GNUNET_IDENTITY_ego_lookup (cfg,
                                      revoke_ego,
@@ -432,10 +459,23 @@ run (void *cls,
                filename);
       return;
     }
-    perform_revocation (&rd);
     GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
                                   &do_shutdown,
                                   NULL);
+    if (GNUNET_YES !=
+        GNUNET_REVOCATION_check_pow (&rd.key,
+                                     rd.pow,
+                                     (unsigned int) matching_bits))
+    {
+      struct RevocationData *cp = GNUNET_new (struct RevocationData);
+
+      *cp = rd;
+      GNUNET_SCHEDULER_add_now (&calculate_pow,
+                                cp);
+      return;
+
+    }
+    perform_revocation (&rd);
     return;
   }
   FPRINTF (stderr,
@@ -459,10 +499,10 @@ main (int argc, char *const *argv)
      gettext_noop ("use NAME for the name of the revocation file"),
      1, &GNUNET_GETOPT_set_string, &filename},
     {'R', "revoke", "NAME",
-     gettext_noop ("revoke the private key associated with the ego NAME "),
+     gettext_noop ("revoke the private key associated for the the private key associated with the ego NAME "),
      1, &GNUNET_GETOPT_set_string, &revoke_ego},
     {'p', "perform", NULL,
-     gettext_noop ("actually perform the revocation revocation file, otherwise we just do the precomputation"),
+     gettext_noop ("actually perform revocation, otherwise we just do the precomputation"),
      0, &GNUNET_GETOPT_set_one, &perform},
     {'t', "test", "KEY",
      gettext_noop ("test if the public key KEY has been revoked"),