/*
* 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
*
* 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.
*/
/**
* @author Christian Grothoff
*/
+#include <inttypes.h>
+
#include "platform.h"
-#include "gnunet_common.h"
#include "gnunet_util_lib.h"
+#include "gnunet_common.h"
#include "gnunet_testing_lib.h"
#include "gnunet_psycstore_service.h"
-#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
-
-#define DEBUG_SERVICE 0
+#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
/**
/**
* 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_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;
static struct FragmentClosure
{
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.
static void
end ()
{
- if (end_badly_task != GNUNET_SCHEDULER_NO_TASK)
+ if (end_badly_task != NULL)
{
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)
+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);
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];
void
-state_get_prefix_result (void *cls, int64_t result, const char *err_msg)
+state_get_prefix_result (void *cls, int64_t result,
+ const char *err_msg, uint16_t err_msg_size)
{
struct StateClosure *scls = cls;
op = NULL;
void
-state_get_result (void *cls, int64_t result, const char *err_msg)
+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);
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,
void
-counters_result (void *cls, uint64_t max_fragment_id, uint64_t max_message_id,
- uint64_t max_group_generation, uint64_t max_state_message_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_fragment_id == GNUNET_ntohll (fcls->msg[2]->fragment_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))
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)
+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);
void
-state_sync_result (void *cls, int64_t result, const char *err_msg)
+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);
}
enum GNUNET_PSYCSTORE_MessageFlags flags)
{
struct FragmentClosure *fcls = cls;
+ GNUNET_assert (fcls->n < fcls->n_expected);
struct GNUNET_MULTICAST_MessageHeader *msg0 = fcls->msg[fcls->n];
uint64_t flags0 = fcls->flags[fcls->n++];
if (flags == flags0 && msg->header.size == msg0->header.size
&& 0 == memcmp (msg, msg0, ntohs (msg->header.size)))
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " fragment %llu matches\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " fragment %" PRIu64 " matches\n",
GNUNET_ntohll (msg->fragment_id));
return GNUNET_YES;
}
else
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, " fragment %llu differs\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ " fragment differs: expected %" PRIu64 ", got %" PRIu64 "\n",
+ GNUNET_ntohll (msg0->fragment_id),
GNUNET_ntohll (msg->fragment_id));
GNUNET_assert (0);
return GNUNET_SYSERR;
void
-message_get_result (void *cls, int64_t result, const char *err_msg)
+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:\t%d\n", result);
- GNUNET_assert (result > 0 && fcls->n && fcls->n_expected);
-
+ 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",
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_fragment_result (void *cls, int64_t result, const char *err_msg)
+message_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, "message_get:\t%d\n", result);
+ GNUNET_assert (0 < result && fcls->n == fcls->n_expected);
+
+ fcls->n = 0;
+ fcls->n_expected = 3;
+ op = GNUNET_PSYCSTORE_message_get_latest (h, &channel_pub_key, &slave_pub_key,
+ 1, "", &fragment_result,
+ &message_get_latest_result, fcls);
+}
+
+
+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;
GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "message_get_fragment:\t%d\n", result);
- GNUNET_assert (result > 0 && fcls->n && fcls->n_expected);
+ GNUNET_assert (0 < result && fcls->n == fcls->n_expected);
fcls->n = 0;
fcls->n_expected = 3;
- op = GNUNET_PSYCSTORE_message_get (h, &channel_pub_key,
- GNUNET_ntohll (fcls->msg[0]->message_id),
+ 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, 0, "",
&fragment_result,
&message_get_result, fcls);
}
void
-fragment_get_result (void *cls, int64_t result, const char *err_msg)
+fragment_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, "fragment_get:\t%d\n", result);
- GNUNET_assert (result > 0 && fcls->n && fcls->n_expected);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "fragment_get_latest:\t%d\n", result);
+ GNUNET_assert (0 < result && fcls->n == fcls->n_expected);
fcls->n = 1;
fcls->n_expected = 2;
- op = GNUNET_PSYCSTORE_message_get_fragment (h, &channel_pub_key,
+ op = GNUNET_PSYCSTORE_message_get_fragment (h, &channel_pub_key, &slave_pub_key,
GNUNET_ntohll (fcls->msg[1]->message_id),
GNUNET_ntohll (fcls->msg[1]->fragment_offset),
&fragment_result,
- &message_get_fragment_result,
- fcls);
+ &message_get_fragment_result, fcls);
+}
+
+
+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_assert (0 < result && fcls->n == fcls->n_expected);
+ fcls->n = 0;
+ fcls->n_expected = 3;
+ op = GNUNET_PSYCSTORE_fragment_get_latest (h, &channel_pub_key,
+ &slave_pub_key, fcls->n_expected,
+ &fragment_result,
+ &fragment_get_latest_result, fcls);
}
void
-fragment_store_result (void *cls, int64_t result, const char *err_msg)
+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);
GNUNET_assert (GNUNET_OK == result);
if ((intptr_t) cls == GNUNET_YES)
- {
+ { /* last fragment */
fcls.n = 0;
fcls.n_expected = 1;
- op = GNUNET_PSYCSTORE_fragment_get (h, &channel_pub_key,
- GNUNET_ntohll (fcls.msg[0]->fragment_id),
+ uint64_t fragment_id = GNUNET_ntohll (fcls.msg[0]->fragment_id);
+ op = GNUNET_PSYCSTORE_fragment_get (h, &channel_pub_key, &slave_pub_key,
+ fragment_id, fragment_id,
&fragment_result,
&fragment_get_result, &fcls);
}
void
-membership_test_result (void *cls, int64_t result, const char *err_msg)
+fragment_store ()
{
- op = NULL;
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "membership_test:\t%d\n", 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));
- sizeof (msg->hop_counter)
- sizeof (msg->signature));
msg->purpose.purpose = htonl (234);
- GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_eddsa_sign (slave_key, &msg->purpose,
- &msg->signature));
+ GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_eddsa_sign (channel_key, &msg->purpose,
+ &msg->signature));
op = GNUNET_PSYCSTORE_fragment_store (h, &channel_pub_key, msg, fcls.flags[0],
&fragment_store_result, GNUNET_NO);
&fragment_store_result, (void *) GNUNET_YES);
}
+
void
-membership_store_result (void *cls, int64_t result, const char *err_msg)
+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);
+ GNUNET_assert (GNUNET_OK == result);
+
+ fragment_store ();
+}
+
+
+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);
GNUNET_assert (GNUNET_OK == result);
op = GNUNET_PSYCSTORE_membership_test (h, &channel_pub_key, &slave_pub_key,
- 4, 1,
+ INT64_MAX - 10, 2,
&membership_test_result, NULL);
}
+
/**
* Main function of the test, run from scheduler.
*
* @param peer handle to access more of the peer (not used)
*/
static void
-#if DEBUG_SERVICE
+#if DEBUG_TEST_PSYCSTORE
run (void *cls, char *const *args, const char *cfgfile,
const struct GNUNET_CONFIGURATION_Handle *cfg)
#else
h = GNUNET_PSYCSTORE_connect (cfg);
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_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);
op = GNUNET_PSYCSTORE_membership_store (h, &channel_pub_key, &slave_pub_key,
- GNUNET_YES, 4, 2, 1,
+ GNUNET_YES, INT64_MAX - 5,
+ INT64_MAX - 10, 2,
&membership_store_result, NULL);
}
main (int argc, char *argv[])
{
res = 1;
-#if DEBUG_SERVICE
+#if DEBUG_TEST_PSYCSTORE
const struct GNUNET_GETOPT_CommandLineOption opts[] = {
GNUNET_GETOPT_OPTION_END
};