-adding missing break statements
[oweals/gnunet.git] / src / psycstore / test_psycstore.c
index 2daf8d1016f3d58c68157006c9e6458cb55d7384..05cb92dce2fb4dfb2a4309c6cc6000a4a470a302 100644 (file)
  */
 
 #include "platform.h"
-#include "gnunet_common.h"
 #include "gnunet_util_lib.h"
-#include "gnunet_psycstore_service.h"
+#include "gnunet_common.h"
 #include "gnunet_testing_lib.h"
-
-#define ASSERT(x) do { if (! (x)) { printf ("Error at %s:%d\n", __FILE__, __LINE__); cleanup (); return; } } while (0)
-#define ASSERRT(x) do { if (! (x)) { printf ("Error at %s:%d\n", __FILE__, __LINE__); cleanup (); return GNUNET_SYSERR; } } while (0)
+#include "gnunet_psycstore_service.h"
 
 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
 
@@ -59,11 +56,11 @@ static struct GNUNET_PSYCSTORE_OperationHandle *op;
  */
 static GNUNET_SCHEDULER_TaskIdentifier end_badly_task;
 
-static struct GNUNET_CRYPTO_EccPrivateKey *channel_key;
-static struct GNUNET_CRYPTO_EccPrivateKey *slave_key;
+static struct GNUNET_CRYPTO_EddsaPrivateKey *channel_key;
+static struct GNUNET_CRYPTO_EddsaPrivateKey *slave_key;
 
-static struct GNUNET_CRYPTO_EccPublicSignKey channel_pub_key;
-static struct GNUNET_CRYPTO_EccPublicSignKey slave_pub_key;
+static struct GNUNET_CRYPTO_EddsaPublicKey channel_pub_key;
+static struct GNUNET_CRYPTO_EddsaPublicKey slave_pub_key;
 
 static struct FragmentClosure
 {
@@ -161,7 +158,7 @@ state_reset_result (void *cls, int64_t result, const char *err_msg)
 {
   op = NULL;
   GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "state_reset_result:\t%d\n", result);
-  ASSERT (GNUNET_OK == result);
+  GNUNET_assert (GNUNET_OK == result);
 
   op = GNUNET_PSYCSTORE_state_reset (h, &channel_pub_key,
                                      &state_reset_result, cls);
@@ -191,7 +188,7 @@ state_result (void *cls, const char *name, const void *value, size_t value_size)
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "  variable %s differs\nReceived: %.*s\nExpected: %.*s\n",
                 name, value_size, value, val_size, val);
-    ASSERRT (0);
+    GNUNET_assert (0);
     return GNUNET_SYSERR;
   }
 }
@@ -203,7 +200,7 @@ state_get_prefix_result (void *cls, int64_t result, const char *err_msg)
   struct StateClosure *scls = cls;
   op = NULL;
   GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "state_get_prefix_result:\t%d\n", result);
-  ASSERT (GNUNET_OK == result && 2 == scls->n);
+  GNUNET_assert (GNUNET_OK == result && 2 == scls->n);
 
   op = GNUNET_PSYCSTORE_state_reset (h, &channel_pub_key,
                                      &state_reset_result, cls);
@@ -215,7 +212,7 @@ state_get_result (void *cls, int64_t result, const char *err_msg)
 {
   op = NULL;
   GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "state_get_result:\t%d\n", result);
-  ASSERT (GNUNET_OK == result);
+  GNUNET_assert (GNUNET_OK == result);
 
   scls.n = 0;
 
@@ -234,17 +231,23 @@ state_get_result (void *cls, int64_t result, const char *err_msg)
 
 
 void
-counters_slave_result (void *cls, uint64_t max_state_msg_id)
+counters_result (void *cls, int status, uint64_t max_fragment_id,
+                 uint64_t max_message_id, uint64_t max_group_generation,
+                 uint64_t max_state_message_id)
 {
   struct FragmentClosure *fcls = cls;
   int result = 0;
   op = NULL;
 
-  if (max_state_msg_id == GNUNET_ntohll (fcls->msg[0]->message_id))
+  if (GNUNET_OK == status
+      && max_fragment_id == GNUNET_ntohll (fcls->msg[2]->fragment_id)
+      && max_message_id == GNUNET_ntohll (fcls->msg[2]->message_id)
+      && max_group_generation == GNUNET_ntohll (fcls->msg[2]->group_generation)
+      && max_state_message_id == GNUNET_ntohll (fcls->msg[0]->message_id))
     result = 1;
 
-  GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "counters_get_slave:\t%d\n", result);
-  ASSERT (result == 1);
+  GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "counters_get:\t%d\n", result);
+  GNUNET_assert (result == 1);
 
   scls.n = 0;
   scls.name[0] = "_bar";
@@ -261,10 +264,10 @@ state_modify_result (void *cls, int64_t result, const char *err_msg)
 {
   op = NULL;
   GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "state_modify_result:\t%d\n", result);
-  ASSERT (GNUNET_OK == result);
+  GNUNET_assert (GNUNET_OK == result);
 
-  op = GNUNET_PSYCSTORE_counters_get_slave (h, &channel_pub_key,
-                                            &counters_slave_result, cls);
+  op = GNUNET_PSYCSTORE_counters_get (h, &channel_pub_key,
+                                      &counters_result, cls);
 }
 
 
@@ -274,7 +277,7 @@ state_sync_result (void *cls, int64_t result, const char *err_msg)
   struct FragmentClosure *fcls = cls;
   op = NULL;
   GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "state_sync_result:\t%d\n", result);
-  ASSERT (GNUNET_OK == result);
+  GNUNET_assert (GNUNET_OK == result);
 
   modifiers[0] = (struct GNUNET_ENV_Modifier) {
     .oper = '=',
@@ -295,41 +298,6 @@ state_sync_result (void *cls, int64_t result, const char *err_msg)
 }
 
 
-void
-counters_master_result (void *cls, uint64_t fragment_id, uint64_t message_id,
-                        uint64_t group_generation)
-{
-  struct FragmentClosure *fcls = cls;
-  int result = 0;
-  op = NULL;
-
-  if (fragment_id == GNUNET_ntohll (fcls->msg[2]->fragment_id) &&
-      message_id == GNUNET_ntohll (fcls->msg[2]->message_id) &&
-      group_generation == GNUNET_ntohll (fcls->msg[2]->group_generation))
-    result = 1;
-
-  GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "counters_get_master:\t%d\n", result);
-  ASSERT (result == 1);
-
-  modifiers[0] = (struct GNUNET_ENV_Modifier) {
-    .oper = '=',
-    .name = "_sync_foo",
-    .value = "three two one",
-    .value_size = sizeof ("three two one") - 1
-  };
-  modifiers[1] = (struct GNUNET_ENV_Modifier) {
-    .oper = '=',
-    .name = "_sync_bar",
-    .value = "ten eleven twelve",
-    .value_size = sizeof ("ten eleven twelve") - 1
-  };
-
-  op = GNUNET_PSYCSTORE_state_sync (h, &channel_pub_key,
-                                    GNUNET_ntohll (fcls->msg[0]->message_id) + 1,
-                                    2, modifiers, state_sync_result, fcls);
-}
-
-
 int
 fragment_result (void *cls,
                  struct GNUNET_MULTICAST_MessageHeader *msg,
@@ -350,7 +318,7 @@ fragment_result (void *cls,
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "  fragment %llu differs\n",
                 GNUNET_ntohll (msg->fragment_id));
-    ASSERRT (0);
+    GNUNET_assert (0);
     return GNUNET_SYSERR;
   }
 }
@@ -362,10 +330,26 @@ message_get_result (void *cls, int64_t result, const char *err_msg)
   struct FragmentClosure *fcls = cls;
   op = NULL;
   GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "message_get:\t%d\n", result);
-  ASSERT (result > 0 && fcls->n && fcls->n_expected);
+  GNUNET_assert (result > 0 && fcls->n && fcls->n_expected);
+
+
+
+  modifiers[0] = (struct GNUNET_ENV_Modifier) {
+    .oper = '=',
+    .name = "_sync_foo",
+    .value = "three two one",
+    .value_size = sizeof ("three two one") - 1
+  };
+  modifiers[1] = (struct GNUNET_ENV_Modifier) {
+    .oper = '=',
+    .name = "_sync_bar",
+    .value = "ten eleven twelve",
+    .value_size = sizeof ("ten eleven twelve") - 1
+  };
 
-  op = GNUNET_PSYCSTORE_counters_get_master (h, &channel_pub_key,
-                                             &counters_master_result, fcls);
+  op = GNUNET_PSYCSTORE_state_sync (h, &channel_pub_key,
+                                    GNUNET_ntohll (fcls->msg[0]->message_id) + 1,
+                                    2, modifiers, state_sync_result, fcls);
 }
 
 
@@ -375,7 +359,7 @@ message_get_fragment_result (void *cls, int64_t result, const char *err_msg)
   struct FragmentClosure *fcls = cls;
   op = NULL;
   GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "message_get_fragment:\t%d\n", result);
-  ASSERT (result > 0 && fcls->n && fcls->n_expected);
+  GNUNET_assert (result > 0 && fcls->n && fcls->n_expected);
 
   fcls->n = 0;
   fcls->n_expected = 3;
@@ -392,7 +376,7 @@ fragment_get_result (void *cls, int64_t result, const char *err_msg)
   struct FragmentClosure *fcls = cls;
   op = NULL;
   GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "fragment_get:\t%d\n", result);
-  ASSERT (result > 0 && fcls->n && fcls->n_expected);
+  GNUNET_assert (result > 0 && fcls->n && fcls->n_expected);
 
   fcls->n = 1;
   fcls->n_expected = 2;
@@ -411,7 +395,7 @@ fragment_store_result (void *cls, int64_t result, const char *err_msg)
 {
   op = NULL;
   GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "fragment_store:\t%d\n", result);
-  ASSERT (GNUNET_OK == result);
+  GNUNET_assert (GNUNET_OK == result);
 
   if ((intptr_t) cls == GNUNET_YES)
   {
@@ -430,12 +414,12 @@ membership_test_result (void *cls, int64_t result, const char *err_msg)
 {
   op = NULL;
   GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "membership_test:\t%d\n", result);
-  ASSERT (GNUNET_OK == result);
+  GNUNET_assert (GNUNET_OK == result);
 
   struct GNUNET_MULTICAST_MessageHeader *msg;
   fcls.flags[0] = GNUNET_PSYCSTORE_MESSAGE_STATE;
   fcls.msg[0] = msg = GNUNET_malloc (sizeof (*msg) + sizeof (channel_pub_key));
-  ASSERT (msg != NULL);
+  GNUNET_assert (msg != NULL);
 
   msg->header.type = htons (GNUNET_MESSAGE_TYPE_MULTICAST_MESSAGE);
   msg->header.size = htons (sizeof (*msg) + sizeof (channel_pub_key));
@@ -454,7 +438,8 @@ membership_test_result (void *cls, int64_t result, const char *err_msg)
                              - sizeof (msg->hop_counter)
                              - sizeof (msg->signature));
   msg->purpose.purpose = htonl (234);
-  GNUNET_CRYPTO_ecc_sign (slave_key, &msg->purpose, &msg->signature);
+  GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_eddsa_sign (slave_key, &msg->purpose,
+                                                      &msg->signature));
 
   op = GNUNET_PSYCSTORE_fragment_store (h, &channel_pub_key, msg, fcls.flags[0],
                                         &fragment_store_result, GNUNET_NO);
@@ -483,7 +468,7 @@ membership_store_result (void *cls, int64_t result, const char *err_msg)
 {
   op = NULL;
   GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "membership_store:\t%d\n", result);
-  ASSERT (GNUNET_OK == result);
+  GNUNET_assert (GNUNET_OK == result);
 
   op = GNUNET_PSYCSTORE_membership_test (h, &channel_pub_key, &slave_pub_key,
                                          4, 1,
@@ -502,21 +487,21 @@ static void
 run (void *cls, char *const *args, const char *cfgfile,
      const struct GNUNET_CONFIGURATION_Handle *cfg)
 #else
-  run (void *cls,
-       const struct GNUNET_CONFIGURATION_Handle *cfg,
-       struct GNUNET_TESTING_Peer *peer)
+run (void *cls,
+     const struct GNUNET_CONFIGURATION_Handle *cfg,
+     struct GNUNET_TESTING_Peer *peer)
 #endif
 {
-  end_badly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
-                                                 &end_badly, NULL);
+  end_badly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
+
   h = GNUNET_PSYCSTORE_connect (cfg);
-  ASSERT (NULL != h);
+  GNUNET_assert (NULL != h);
 
-  channel_key = GNUNET_CRYPTO_ecc_key_create ();
-  slave_key = GNUNET_CRYPTO_ecc_key_create ();
+  channel_key = GNUNET_CRYPTO_eddsa_key_create ();
+  slave_key = GNUNET_CRYPTO_eddsa_key_create ();
 
-  GNUNET_CRYPTO_ecc_key_get_public_for_signature (channel_key, &channel_pub_key);
-  GNUNET_CRYPTO_ecc_key_get_public_for_signature (slave_key, &slave_pub_key);
+  GNUNET_CRYPTO_eddsa_key_get_public (channel_key, &channel_pub_key);
+  GNUNET_CRYPTO_eddsa_key_get_public (slave_key, &slave_pub_key);
 
   op = GNUNET_PSYCSTORE_membership_store (h, &channel_pub_key, &slave_pub_key,
                                           GNUNET_YES, 4, 2, 1,