- secretsharing api test for single peer
authorFlorian Dold <florian.dold@gmail.com>
Mon, 17 Feb 2014 15:54:59 +0000 (15:54 +0000)
committerFlorian Dold <florian.dold@gmail.com>
Mon, 17 Feb 2014 15:54:59 +0000 (15:54 +0000)
- fixed wrong endianess conversion

src/secretsharing/gnunet-service-secretsharing.c
src/secretsharing/secretsharing_api.c
src/secretsharing/secretsharing_common.c
src/secretsharing/test_secretsharing_api.c

index 435c10b2baa8398f2017bc6d843a3c4c75bef055..1778b6ca0363f171ea391f407beae9098bfe86bb 100644 (file)
@@ -786,6 +786,9 @@ keygen_round2_conclude (void *cls)
 
   GNUNET_assert (GNUNET_OK == GNUNET_SECRETSHARING_share_write (share, NULL, 0, &share_size));
 
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "writing share of size %u\n",
+              (unsigned int) share_size);
+
   ev = GNUNET_MQ_msg_extra (m, share_size,
                             GNUNET_MESSAGE_TYPE_SECRETSHARING_CLIENT_SECRET_READY);
 
index d46d24e9d70aee2cae4ee95180be8e732ab3e5a5..6e347f6da9e44dfef058ccdc55ece3d67d4d213c 100644 (file)
@@ -144,6 +144,9 @@ handle_secret_ready (void *cls, const struct GNUNET_MessageHeader *msg)
   const struct GNUNET_SECRETSHARING_SecretReadyMessage *m = (const void *) msg;
   size_t share_size;
 
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "got secret ready message of size %u\n",
+       ntohs (m->header.size));
+
   share_size = ntohs (m->header.size) - sizeof *m;
 
   share = GNUNET_SECRETSHARING_share_read (&m[1], share_size, NULL);
index 7fe8f46660daddad0a94349695c172bba7ae9cef..2f5b3f583da39dc89b64df879dd1827e815491a2 100644 (file)
@@ -62,7 +62,7 @@ GNUNET_SECRETSHARING_share_read (const void *data, size_t len, size_t *readlen)
   p += n;
 
   n = share->num_peers * sizeof (struct GNUNET_SECRETSHARING_FieldElement);
-  share->sigmas= GNUNET_malloc (n);
+  share->sigmas = GNUNET_malloc (n);
   memcpy (share->sigmas, p, n);
   p += n;
 
@@ -94,7 +94,7 @@ GNUNET_SECRETSHARING_share_write (const struct GNUNET_SECRETSHARING_Share *share
   char *p;
   int n;
 
-  payload_size = ntohs (share->num_peers) * 
+  payload_size = share->num_peers * 
       (sizeof (uint16_t) + sizeof (struct GNUNET_SECRETSHARING_FieldElement) + 
        sizeof (struct GNUNET_PeerIdentity));
 
index a6f3cb1272d69be7c43ef7bbc77ac595d1ec1a95..d131805e753acbe874b4f5ffc4fa58e71c2637d6 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     (C) 2013 Christian Grothoff (and other contributing authors)
+     (C) 2014 Christian Grothoff (and other contributing authors)
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
  */
 #include "platform.h"
 #include "gnunet_util_lib.h"
+#include "gnunet_testing_lib.h"
+#include "gnunet_secretsharing_service.h"
+
+
+static int success;
+
+static struct GNUNET_SECRETSHARING_Session *keygen;
+
+
+static void secret_ready_cb (void *cls,
+                             struct GNUNET_SECRETSHARING_Share *my_share,
+                             struct GNUNET_SECRETSHARING_PublicKey *public_key,
+                             unsigned int num_ready_peers,
+                             struct GNUNET_PeerIdentity *ready_peers)
+{
+  keygen = NULL;
+  if (num_ready_peers == 1)
+    success = 1;
+  // FIXME: check that our share is valid, which we can do as there's only
+  // one peer.
+  GNUNET_SCHEDULER_shutdown ();
+}
+
+static void
+handle_shutdown (void *cls,
+                 const struct GNUNET_SCHEDULER_TaskContext * tc)
+{
+  if (NULL != keygen)
+  {
+    GNUNET_SECRETSHARING_session_destroy (keygen);
+    keygen = NULL;
+  }
+}
+
+static void
+run (void *cls,
+     const struct GNUNET_CONFIGURATION_Handle *cfg,
+     struct GNUNET_TESTING_Peer *peer)
+{
+  struct GNUNET_HashCode session_id; 
+  struct GNUNET_TIME_Absolute start;
+  struct GNUNET_TIME_Absolute deadline;
+
+  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
+                                handle_shutdown, NULL);
+
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO, "testing secretsharing api\n");
+
+  GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &session_id);
+
+  start = GNUNET_TIME_absolute_get ();
+  deadline = GNUNET_TIME_absolute_add (start, GNUNET_TIME_UNIT_SECONDS);
+
+  keygen = GNUNET_SECRETSHARING_create_session (cfg,
+                                                0, NULL, /* only the local peer */
+                                                &session_id,
+                                                start, deadline,
+                                                1,
+                                                secret_ready_cb, NULL);
+
+
+}
+
 
 int
 main (int argc, char **argv)
 {
-  return 0;
+
+  int ret;
+  ret = GNUNET_TESTING_peer_run ("test_secretsharing_api",
+                                 "test_secretsharing.conf",
+                                 &run, NULL);
+  if (0 != ret)
+    return ret;
+  return (GNUNET_YES == success) ? 0 : 1;
 }