From 1d6824b116658d2490aaa1a5d1662e3857e86d3f Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Mon, 17 Feb 2014 15:54:59 +0000 Subject: - secretsharing api test for single peer - fixed wrong endianess conversion --- src/secretsharing/test_secretsharing_api.c | 74 +++++++++++++++++++++++++++++- 1 file changed, 72 insertions(+), 2 deletions(-) (limited to 'src/secretsharing/test_secretsharing_api.c') diff --git a/src/secretsharing/test_secretsharing_api.c b/src/secretsharing/test_secretsharing_api.c index a6f3cb127..d131805e7 100644 --- a/src/secretsharing/test_secretsharing_api.c +++ b/src/secretsharing/test_secretsharing_api.c @@ -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 @@ -24,10 +24,80 @@ */ #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; } -- cgit v1.2.3