start to fix psycstore mysql
[oweals/gnunet.git] / src / psycstore / test_psycstore.c
index 125e64f5825298808eabeaac15b8027dc8e393fe..f9a7ce9cac88dd68de1bf402e14e8ab651f5d285 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * This file is part of GNUnet
- * (C) 2013 Christian Grothoff (and other contributing authors)
+ * Copyright (C) 2013 GNUnet e.V.
  *
  * GNUnet is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published
@@ -14,8 +14,8 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with GNUnet; see the file COPYING.  If not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
  */
 
 /**
@@ -54,7 +54,7 @@ static struct GNUNET_PSYCSTORE_OperationHandle *op;
 /**
  * Handle for task for timeout termination.
  */
-static GNUNET_SCHEDULER_TaskIdentifier end_badly_task;
+static struct GNUNET_SCHEDULER_Task *end_badly_task;
 
 static struct GNUNET_CRYPTO_EddsaPrivateKey *channel_key;
 static struct GNUNET_CRYPTO_EcdsaPrivateKey *slave_key;
@@ -77,7 +77,7 @@ struct StateClosure {
   size_t value_size[16];
 } scls;
 
-static struct GNUNET_ENV_Modifier modifiers[16];
+static struct GNUNET_PSYC_Modifier modifiers[16];
 
 /**
  * Clean up all resources used.
@@ -113,10 +113,9 @@ cleanup ()
  * Terminate the testcase (failure).
  *
  * @param cls NULL
- * @param tc scheduler context
  */
 static void
-end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+end_badly (void *cls)
 {
   res = 1;
   cleanup ();
@@ -127,10 +126,9 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
  * Terminate the testcase (success).
  *
  * @param cls NULL
- * @param tc scheduler context
  */
 static void
-end_normally (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+end_normally (void *cls)
 {
   res = 0;
   cleanup ();
@@ -143,21 +141,26 @@ end_normally (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 static void
 end ()
 {
-  if (end_badly_task != GNUNET_SCHEDULER_NO_TASK)
+  if (NULL != end_badly_task)
   {
     GNUNET_SCHEDULER_cancel (end_badly_task);
-    end_badly_task = GNUNET_SCHEDULER_NO_TASK;
+    end_badly_task = NULL;
   }
   GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS,
                                &end_normally, NULL);
 }
 
 
-void
-state_reset_result (void *cls, int64_t result, const char *err_msg)
+static void
+state_reset_result (void *cls,
+                    int64_t result,
+                    const char *err_msg,
+                    uint16_t err_msg_size)
 {
   op = NULL;
-  GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "state_reset_result:\t%d\n", result);
+  GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+              "state_reset_result:\t%d\n",
+              (int) result);
   GNUNET_assert (GNUNET_OK == result);
 
   op = GNUNET_PSYCSTORE_state_reset (h, &channel_pub_key,
@@ -169,7 +172,10 @@ state_reset_result (void *cls, int64_t result, const char *err_msg)
 
 
 static int
-state_result (void *cls, const char *name, const void *value, size_t value_size)
+state_result (void *cls,
+              const char *name,
+              const void *value,
+              uint32_t value_size)
 {
   struct StateClosure *scls = cls;
   const char *nam = scls->name[scls->n];
@@ -180,7 +186,9 @@ state_result (void *cls, const char *name, const void *value, size_t value_size)
       && 0 == memcmp (value, val, val_size)
       && 0 == strcmp (name, nam))
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "  variable %s matches\n", name);
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "  variable %s matches\n",
+                name);
     return GNUNET_YES;
   }
   else
@@ -194,8 +202,9 @@ state_result (void *cls, const char *name, const void *value, size_t value_size)
 }
 
 
-void
-state_get_prefix_result (void *cls, int64_t result, const char *err_msg)
+static void
+state_get_prefix_result (void *cls, int64_t result,
+                         const char *err_msg, uint16_t err_msg_size)
 {
   struct StateClosure *scls = cls;
   op = NULL;
@@ -207,8 +216,9 @@ state_get_prefix_result (void *cls, int64_t result, const char *err_msg)
 }
 
 
-void
-state_get_result (void *cls, int64_t result, const char *err_msg)
+static void
+state_get_result (void *cls, int64_t result,
+                  const char *err_msg, uint16_t err_msg_size)
 {
   op = NULL;
   GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "state_get_result:\t%d\n", result);
@@ -221,8 +231,8 @@ state_get_result (void *cls, int64_t result, const char *err_msg)
   scls.value_size[0] = sizeof ("ten eleven twelve") - 1;
 
   scls.name[1] = "_sync_foo";
-  scls.value[1] = "one two three";
-  scls.value_size[1] = sizeof ("one two three") - 1;
+  scls.value[1] = "three two one";
+  scls.value_size[1] = sizeof ("three two one") - 1;
 
   op = GNUNET_PSYCSTORE_state_get_prefix (h, &channel_pub_key, "_sync",
                                           &state_result,
@@ -230,7 +240,7 @@ state_get_result (void *cls, int64_t result, const char *err_msg)
 }
 
 
-void
+static void
 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)
@@ -250,17 +260,18 @@ counters_result (void *cls, int status, uint64_t max_fragment_id,
   GNUNET_assert (result == 1);
 
   scls.n = 0;
-  scls.name[0] = "_bar";
-  scls.value[0] = "four five six";
-  scls.value_size[0] = sizeof ("four five six") - 1;
+  scls.name[0] = "_sync_bar";
+  scls.value[0] = "ten eleven twelve";
+  scls.value_size[0] = sizeof ("ten eleven twelve") - 1;
 
-  op = GNUNET_PSYCSTORE_state_get (h, &channel_pub_key, "_bar_x_yy_zzz",
+  op = GNUNET_PSYCSTORE_state_get (h, &channel_pub_key, "_sync_bar_x_yy_zzz",
                                    &state_result, &state_get_result, &scls);
 }
 
 
-void
-state_modify_result (void *cls, int64_t result, const char *err_msg)
+static void
+state_modify_result (void *cls, int64_t result,
+                     const char *err_msg, uint16_t err_msg_size)
 {
   op = NULL;
   GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "state_modify_result:\t%d\n", result);
@@ -271,34 +282,22 @@ state_modify_result (void *cls, int64_t result, const char *err_msg)
 }
 
 
-void
-state_sync_result (void *cls, int64_t result, const char *err_msg)
+static void
+state_sync_result (void *cls, int64_t result,
+                   const char *err_msg, uint16_t err_msg_size)
 {
   struct FragmentClosure *fcls = cls;
   op = NULL;
   GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "state_sync_result:\t%d\n", result);
   GNUNET_assert (GNUNET_OK == result);
 
-  modifiers[0] = (struct GNUNET_ENV_Modifier) {
-    .oper = '=',
-    .name = "_sync_foo",
-    .value = "one two three",
-    .value_size = sizeof ("one two three") - 1
-  };
-  modifiers[1] = (struct GNUNET_ENV_Modifier) {
-    .oper = '=',
-    .name = "_bar",
-    .value = "four five six",
-    .value_size = sizeof ("four five six") - 1
-  };
-
   op = GNUNET_PSYCSTORE_state_modify (h, &channel_pub_key,
-                                      GNUNET_ntohll (fcls->msg[0]->message_id), 0,
-                                      2, modifiers, state_modify_result, fcls);
+                                      GNUNET_ntohll (fcls->msg[0]->message_id),
+                                      0, state_modify_result, fcls);
 }
 
 
-int
+static int
 fragment_result (void *cls,
                  struct GNUNET_MULTICAST_MessageHeader *msg,
                  enum GNUNET_PSYCSTORE_MessageFlags flags)
@@ -327,21 +326,22 @@ fragment_result (void *cls,
 }
 
 
-void
-message_get_latest_result (void *cls, int64_t result, const char *err_msg)
+static void
+message_get_latest_result (void *cls, int64_t result,
+                           const char *err_msg, uint16_t err_msg_size)
 {
   struct FragmentClosure *fcls = cls;
   op = NULL;
   GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "message_get_latest:\t%d\n", result);
   GNUNET_assert (0 < result && fcls->n == fcls->n_expected);
 
-  modifiers[0] = (struct GNUNET_ENV_Modifier) {
+  modifiers[0] = (struct GNUNET_PSYC_Modifier) {
     .oper = '=',
     .name = "_sync_foo",
     .value = "three two one",
     .value_size = sizeof ("three two one") - 1
   };
-  modifiers[1] = (struct GNUNET_ENV_Modifier) {
+  modifiers[1] = (struct GNUNET_PSYC_Modifier) {
     .oper = '=',
     .name = "_sync_bar",
     .value = "ten eleven twelve",
@@ -350,12 +350,14 @@ message_get_latest_result (void *cls, int64_t result, const char *err_msg)
 
   op = GNUNET_PSYCSTORE_state_sync (h, &channel_pub_key,
                                     GNUNET_ntohll (fcls->msg[0]->message_id) + 1,
+                                    GNUNET_ntohll (fcls->msg[0]->message_id) + 2,
                                     2, modifiers, state_sync_result, fcls);
 }
 
 
-void
-message_get_result (void *cls, int64_t result, const char *err_msg)
+static void
+message_get_result (void *cls, int64_t result,
+                    const char *err_msg, uint16_t err_msg_size)
 {
   struct FragmentClosure *fcls = cls;
   op = NULL;
@@ -365,13 +367,14 @@ message_get_result (void *cls, int64_t result, const char *err_msg)
   fcls->n = 0;
   fcls->n_expected = 3;
   op = GNUNET_PSYCSTORE_message_get_latest (h, &channel_pub_key, &slave_pub_key,
-                                            1, &fragment_result,
+                                            1, "", &fragment_result,
                                             &message_get_latest_result, fcls);
 }
 
 
-void
-message_get_fragment_result (void *cls, int64_t result, const char *err_msg)
+static void
+message_get_fragment_result (void *cls, int64_t result,
+                             const char *err_msg, uint16_t err_msg_size)
 {
   struct FragmentClosure *fcls = cls;
   op = NULL;
@@ -382,14 +385,15 @@ message_get_fragment_result (void *cls, int64_t result, const char *err_msg)
   fcls->n_expected = 3;
   uint64_t message_id = GNUNET_ntohll (fcls->msg[0]->message_id);
   op = GNUNET_PSYCSTORE_message_get (h, &channel_pub_key, &slave_pub_key,
-                                     message_id, message_id,
+                                     message_id, message_id, 0, "",
                                      &fragment_result,
                                      &message_get_result, fcls);
 }
 
 
-void
-fragment_get_latest_result (void *cls, int64_t result, const char *err_msg)
+static void
+fragment_get_latest_result (void *cls, int64_t result,
+                            const char *err_msg, uint16_t err_msg_size)
 {
   struct FragmentClosure *fcls = cls;
   op = NULL;
@@ -406,12 +410,15 @@ fragment_get_latest_result (void *cls, int64_t result, const char *err_msg)
 }
 
 
-void
-fragment_get_result (void *cls, int64_t result, const char *err_msg)
+static void
+fragment_get_result (void *cls, int64_t result,
+                     const char *err_msg, uint16_t err_msg_size)
 {
   struct FragmentClosure *fcls = cls;
   op = NULL;
-  GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "fragment_get:\t%d\n", result);
+  GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+              "fragment_get:\t%d\n",
+              (int) result);
   GNUNET_assert (0 < result && fcls->n == fcls->n_expected);
 
   fcls->n = 0;
@@ -423,8 +430,9 @@ fragment_get_result (void *cls, int64_t result, const char *err_msg)
 }
 
 
-void
-fragment_store_result (void *cls, int64_t result, const char *err_msg)
+static void
+fragment_store_result (void *cls, int64_t result,
+                       const char *err_msg, uint16_t err_msg_size)
 {
   op = NULL;
   GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "fragment_store:\t%d\n", result);
@@ -443,7 +451,7 @@ fragment_store_result (void *cls, int64_t result, const char *err_msg)
 }
 
 
-void
+static void
 fragment_store ()
 {
   struct GNUNET_MULTICAST_MessageHeader *msg;
@@ -461,7 +469,7 @@ fragment_store ()
   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));
+  GNUNET_memcpy (&msg[1], &channel_pub_key, sizeof (channel_pub_key));
 
   msg->purpose.size = htonl (ntohs (msg->header.size)
                              - sizeof (msg->header)
@@ -476,7 +484,7 @@ fragment_store ()
 
   fcls.flags[1] = GNUNET_PSYCSTORE_MESSAGE_STATE_APPLIED;
   fcls.msg[1] = msg = GNUNET_malloc (sizeof (*msg) + sizeof (channel_pub_key));
-  memcpy (msg, fcls.msg[0], sizeof (*msg) + sizeof (channel_pub_key));
+  GNUNET_memcpy (msg, fcls.msg[0], sizeof (*msg) + sizeof (channel_pub_key));
   msg->fragment_id = GNUNET_htonll (INT64_MAX - 4);
   msg->fragment_offset = GNUNET_htonll (1024);
 
@@ -485,7 +493,7 @@ fragment_store ()
 
   fcls.flags[2] = GNUNET_PSYCSTORE_MESSAGE_STATE_HASH;
   fcls.msg[2] = msg = GNUNET_malloc (sizeof (*msg) + sizeof (channel_pub_key));
-  memcpy (msg, fcls.msg[1], sizeof (*msg) + sizeof (channel_pub_key));
+  GNUNET_memcpy (msg, fcls.msg[1], sizeof (*msg) + sizeof (channel_pub_key));
   msg->fragment_id = GNUNET_htonll (INT64_MAX);
   msg->fragment_offset = GNUNET_htonll (16384);
 
@@ -494,8 +502,9 @@ fragment_store ()
 }
 
 
-void
-membership_test_result (void *cls, int64_t result, const char *err_msg)
+static void
+membership_test_result (void *cls, int64_t result,
+                        const char *err_msg, uint16_t err_msg_size)
 {
   op = NULL;
   GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "membership_test:\t%d\n", result);
@@ -505,8 +514,9 @@ membership_test_result (void *cls, int64_t result, const char *err_msg)
 }
 
 
-void
-membership_store_result (void *cls, int64_t result, const char *err_msg)
+static void
+membership_store_result (void *cls, int64_t result,
+                         const char *err_msg, uint16_t err_msg_size)
 {
   op = NULL;
   GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "membership_store:\t%d\n", result);
@@ -517,6 +527,7 @@ membership_store_result (void *cls, int64_t result, const char *err_msg)
                                          &membership_test_result, NULL);
 }
 
+
 /**
  * Main function of the test, run from scheduler.
  *