- clean up gns rest api
[oweals/gnunet.git] / src / psycstore / test_plugin_psycstore.c
index 1a44a20d6e1e35bf127cfbfd325bd36b570ac405..7f5a6fb368bd48c5bf062c571eba49b3d9baf8b0 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * This file is part of GNUnet
- * (C) 2013 Christian Grothoff (and other contributing authors)
+ * Copyright (C) 2013 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
@@ -51,10 +51,10 @@ static int ok;
 static const char *plugin_name;
 
 static struct GNUNET_CRYPTO_EddsaPrivateKey *channel_key;
-static struct GNUNET_CRYPTO_EddsaPrivateKey *slave_key;
+static struct GNUNET_CRYPTO_EcdsaPrivateKey *slave_key;
 
 static struct GNUNET_CRYPTO_EddsaPublicKey channel_pub_key;
-static struct GNUNET_CRYPTO_EddsaPublicKey slave_pub_key;
+static struct GNUNET_CRYPTO_EcdsaPublicKey slave_pub_key;
 
 /**
  * Function called when the service shuts down.  Unloads our psycstore
@@ -175,11 +175,11 @@ run (void *cls, char *const *args, const char *cfgfile,
   /* Store & test membership */
 
   channel_key = GNUNET_CRYPTO_eddsa_key_create ();
-  slave_key = GNUNET_CRYPTO_eddsa_key_create ();
+  slave_key = GNUNET_CRYPTO_ecdsa_key_create ();
 
   GNUNET_CRYPTO_eddsa_key_get_public (channel_key,
                                                   &channel_pub_key);
-  GNUNET_CRYPTO_eddsa_key_get_public (slave_key, &slave_pub_key);
+  GNUNET_CRYPTO_ecdsa_key_get_public (slave_key, &slave_pub_key);
 
   GNUNET_assert (GNUNET_OK == db->membership_store (db->cls, &channel_pub_key,
                                                     &slave_pub_key, GNUNET_YES,
@@ -204,11 +204,17 @@ run (void *cls, char *const *args, const char *cfgfile,
   msg->header.type = htons (GNUNET_MESSAGE_TYPE_MULTICAST_MESSAGE);
   msg->header.size = htons (sizeof (*msg) + sizeof (channel_pub_key));
 
+  uint64_t fragment_id = INT64_MAX - 1;
+  msg->fragment_id = GNUNET_htonll (fragment_id);
+
+  uint64_t message_id = INT64_MAX - 10;
+  msg->message_id = GNUNET_htonll (message_id);
+
+  uint64_t group_generation = INT64_MAX - 3;
+  msg->group_generation = GNUNET_htonll (group_generation);
+
   msg->hop_counter = htonl (9);
-  msg->fragment_id = GNUNET_htonll (INT64_MAX - 1);
   msg->fragment_offset = GNUNET_htonll (0);
-  msg->message_id = GNUNET_htonll (INT64_MAX - 10);
-  msg->group_generation = GNUNET_htonll (INT64_MAX - 3);
   msg->flags = htonl (GNUNET_MULTICAST_MESSAGE_LAST_FRAGMENT);
 
   memcpy (&msg[1], &channel_pub_key, sizeof (channel_pub_key));
@@ -218,21 +224,27 @@ run (void *cls, char *const *args, const char *cfgfile,
                              - sizeof (msg->hop_counter)
                              - sizeof (msg->signature));
   msg->purpose.purpose = htonl (234);
-  GNUNET_CRYPTO_eddsa_sign (slave_key, &msg->purpose, &msg->signature);
+  GNUNET_assert (GNUNET_OK ==
+                 GNUNET_CRYPTO_eddsa_sign (channel_key, &msg->purpose, &msg->signature));
 
   struct FragmentClosure fcls = { 0 };
   fcls.n = 0;
   fcls.msg[0] = msg;
   fcls.flags[0] = GNUNET_PSYCSTORE_MESSAGE_STATE;
 
-  GNUNET_assert (GNUNET_OK == db->fragment_store (db->cls, &channel_pub_key, msg,
-                                           fcls.flags[0]));
+  GNUNET_assert (
+    GNUNET_OK == db->fragment_store (db->cls, &channel_pub_key, msg,
+                                     fcls.flags[0]));
 
-  GNUNET_assert (GNUNET_OK == db->fragment_get (db->cls, &channel_pub_key,
-                                         GNUNET_ntohll (msg->fragment_id),
-                                         fragment_cb, &fcls));
+  uint64_t ret_frags = 0;
+  GNUNET_assert (
+    GNUNET_OK == db->fragment_get (db->cls, &channel_pub_key,
+                                   fragment_id, fragment_id,
+                                   &ret_frags, fragment_cb, &fcls));
   GNUNET_assert (fcls.n == 1);
 
+  // FIXME: test fragment_get_latest and message_get_latest
+
   fcls.n = 0;
 
   GNUNET_assert (
@@ -250,9 +262,10 @@ run (void *cls, char *const *args, const char *cfgfile,
   fcls.n = 0;
   fcls.flags[0] |= GNUNET_PSYCSTORE_MESSAGE_STATE_APPLIED;
 
-  GNUNET_assert (GNUNET_OK == db->fragment_get (db->cls, &channel_pub_key,
-                                                GNUNET_ntohll (msg->fragment_id),
-                                                fragment_cb, &fcls));
+  GNUNET_assert (
+    GNUNET_OK == db->fragment_get (db->cls, &channel_pub_key,
+                                   fragment_id, fragment_id,
+                                   &ret_frags, fragment_cb, &fcls));
   GNUNET_assert (fcls.n == 1);
 
   struct GNUNET_MULTICAST_MessageHeader *msg1
@@ -270,15 +283,17 @@ run (void *cls, char *const *args, const char *cfgfile,
   GNUNET_assert (GNUNET_OK == db->fragment_store (db->cls, &channel_pub_key, msg1,
                                                   fcls.flags[1]));
 
-  uint64_t retfrags = 0;
-  GNUNET_assert (GNUNET_OK == db->message_get (db->cls, &channel_pub_key,
-                                               GNUNET_ntohll (msg->message_id),
-                                               &retfrags, fragment_cb, &fcls));
-  GNUNET_assert (fcls.n == 2 && retfrags == 2);
+  GNUNET_assert (
+    GNUNET_OK == db->message_get (db->cls, &channel_pub_key,
+                                  message_id, message_id,
+                                  &ret_frags, fragment_cb, &fcls));
+  GNUNET_assert (fcls.n == 2 && ret_frags == 2);
 
   /* Message counters */
 
-  uint64_t fragment_id = 0, message_id = 0, group_generation = 0;
+  fragment_id = 0;
+  message_id = 0;
+  group_generation = 0;
   GNUNET_assert (
     GNUNET_OK == db->counters_message_get (db->cls, &channel_pub_key,
                                            &fragment_id, &message_id,