From 4064deedf4ee722ba8adab7fd3030cea3e20297e Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Tue, 16 Jul 2013 15:09:28 +0000 Subject: -towards testing identity service --- src/identity/Makefile.am | 8 +- src/identity/gnunet-identity.c | 4 + src/identity/gnunet-service-identity.c | 5 + src/identity/identity.conf.in | 36 +----- src/identity/identity_api.c | 2 +- src/identity/test_identity.c | 203 +++++++++++++++++++++++++++++++++ src/identity/test_identity.conf | 5 + 7 files changed, 228 insertions(+), 35 deletions(-) create mode 100644 src/identity/test_identity.c create mode 100644 src/identity/test_identity.conf diff --git a/src/identity/Makefile.am b/src/identity/Makefile.am index 1b7767fe1..e68debbc1 100644 --- a/src/identity/Makefile.am +++ b/src/identity/Makefile.am @@ -56,16 +56,16 @@ gnunet_service_identity_DEPENDENCIES = \ if HAVE_TESTING check_PROGRAMS = \ - test_identity_api + test_identity endif if ENABLE_TEST_RUN TESTS = $(check_PROGRAMS) endif -test_identity_api_SOURCES = \ - test_identity_api.c -test_identity_api_LDADD = \ +test_identity_SOURCES = \ + test_identity.c +test_identity_LDADD = \ $(top_builddir)/src/identity/libgnunetidentity.la \ $(top_builddir)/src/testing/libgnunettesting.la \ $(top_builddir)/src/util/libgnunetutil.la diff --git a/src/identity/gnunet-identity.c b/src/identity/gnunet-identity.c index 15cb17d1b..c590ab701 100644 --- a/src/identity/gnunet-identity.c +++ b/src/identity/gnunet-identity.c @@ -21,6 +21,10 @@ * @file identity/gnunet-identity.c * @brief IDENTITY management command line tool * @author Christian Grothoff + * + * Todo: + * - add options to get/set default egos + * - print short hashes of egos when printing */ #include "platform.h" #include "gnunet_util_lib.h" diff --git a/src/identity/gnunet-service-identity.c b/src/identity/gnunet-service-identity.c index 45c088e44..84da12c2a 100644 --- a/src/identity/gnunet-service-identity.c +++ b/src/identity/gnunet-service-identity.c @@ -25,6 +25,11 @@ * * The purpose of this service is to manage private keys that * represent the various egos/pseudonyms/identities of a GNUnet user. + * + * Todo: + * - testcases + * - auto-initialze default egos; maybe trigger default + * initializations (such as gnunet-gns-import.sh?) */ #include "platform.h" #include "gnunet_util_lib.h" diff --git a/src/identity/identity.conf.in b/src/identity/identity.conf.in index 64e07945e..737614119 100644 --- a/src/identity/identity.conf.in +++ b/src/identity/identity.conf.in @@ -1,39 +1,15 @@ -[nse] +[identity] AUTOSTART = YES -@JAVAPORT@PORT = 2097 +@UNIXONLY@PORT = 2108 HOSTNAME = localhost HOME = $SERVICEHOME -BINARY = gnunet-service-nse +BINARY = gnunet-service-identity ACCEPT_FROM = 127.0.0.1; ACCEPT_FROM6 = ::1; -UNIXPATH = /tmp/test-nse-service-nse.unix +UNIXPATH = /tmp/gnunet-service-identity.unix UNIX_MATCH_UID = NO UNIX_MATCH_GID = YES -PROOFFILE = $SERVICEHOME/.nse-proof -# The directory where the NSE services logs timestamps everytime -# a size estime flooding message is received -# This option is only used for benchmarking, not in production. -HISTOGRAM_DIR = $SERVICEHOME - -# How 'slowly' should the proof-of-work be constructed (delay -# between rounds); sane values between 0 and ~1000. -# It should rarely make sense to change this value. -# Only systems with slow CPUs where 5ms is a long time might -# want it to be reduced. -WORKDELAY = 5 ms - -# Note: changing any of the values below will make this peer -# completely incompatible with other peers! - -# How often do peers exchange network size messages? -# Note that all peers MUST use the same interval. -# DO NOT CHANGE THIS VALUE, doing so will break the protocol! -INTERVAL = 1 h - -# 2^22 hash operations take about 2-3h on a modern i7 (single-core) -# for SCRYPT; with 2ms/op and 5ms workdelay, we can expect -# the POW calculation to be done by a high-end peer in about 6h -# DO NOT CHANGE THIS VALUE, doing so will break the protocol! -WORKBITS = 22 +# Directory where we store information about our egos +EGODIR = $SERVICEHOME/egos/ diff --git a/src/identity/identity_api.c b/src/identity/identity_api.c index 169a7a2ac..4b4c8c3a1 100644 --- a/src/identity/identity_api.c +++ b/src/identity/identity_api.c @@ -862,7 +862,7 @@ GNUNET_IDENTITY_delete (struct GNUNET_IDENTITY_Handle *id, * @param op operation to cancel */ void -GNUNET_IDENITY_cancel (struct GNUNET_IDENTITY_Operation *op) +GNUNET_IDENTITY_cancel (struct GNUNET_IDENTITY_Operation *op) { struct GNUNET_IDENTITY_Handle *h = op->h; diff --git a/src/identity/test_identity.c b/src/identity/test_identity.c new file mode 100644 index 000000000..3712da3bd --- /dev/null +++ b/src/identity/test_identity.c @@ -0,0 +1,203 @@ +/* + This file is part of GNUnet. + (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 + by the Free Software Foundation; either version 3, or (at your + option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + 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. +*/ + +/** + * @file identity/test_identity.c + * @brief testcase for identity service + * @author Christian Grothoff + */ +#include "platform.h" +#include "gnunet_common.h" +#include "gnunet_util_lib.h" +#include "gnunet_identity_service.h" +#include "gnunet_testing_lib.h" + + +#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) + + +/** + * Return value from 'main'. + */ +static int res; + +/** + * Handle to identity service. + */ +static struct GNUNET_IDENTITY_Handle *h; + +/** + * Handle to identity operation. + */ +static struct GNUNET_IDENTITY_Operation *op; + +/** + * Handle for task for timeout termination. + */ +static GNUNET_SCHEDULER_TaskIdentifier endbadly_task; + + +/** + * Clean up all resources used. + */ +static void +cleanup () +{ + if (NULL != h) + { + GNUNET_IDENTITY_disconnect (h); + h = NULL; + } + if (NULL != op) + { + GNUNET_IDENTITY_cancel (op); + op = NULL; + } + GNUNET_SCHEDULER_shutdown (); +} + + +/** + * Termiante the testcase (failure). + * + * @param cls NULL + * @param tc scheduler context + */ +static void +endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) +{ + cleanup (); + res = 1; +} + + +/** + * Termiante the testcase (success). + * + * @param cls NULL + * @param tc scheduler context + */ +static void +end_normally (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) +{ + cleanup (); + res = 0; +} + + +/** + * Finish the testcase (successfully). + */ +static void +end () +{ + if (endbadly_task != GNUNET_SCHEDULER_NO_TASK) + { + GNUNET_SCHEDULER_cancel (endbadly_task); + endbadly_task = GNUNET_SCHEDULER_NO_TASK; + } + GNUNET_SCHEDULER_add_now (&end, NULL); +} + + +/** + * Called with events about egos. + * + * @param cls NULL + * @param ego ego handle + * @param ego_ctx context for application to store data for this ego + * (during the lifetime of this process, initially NULL) + * @param identifier identifier assigned by the user for this ego, + * NULL if the user just deleted the ego and it + * must thus no longer be used + */ +static void +notification_cb (void *cls, + struct GNUNET_IDENTITY_Ego *ego, + void **ctx, + const char *identifier) +{ +} + + +/** + * Called with events about created ego. + * + * @param cls NULL + * @param ego ego handle + * @param ego_ctx context for application to store data for this ego + * (during the lifetime of this process, initially NULL) + * @param identifier identifier assigned by the user for this ego, + * NULL if the user just deleted the ego and it + * must thus no longer be used + */ +static void +create_cb (void *cls, + struct GNUNET_IDENTITY_Ego *ego, + void **ctx, + const char *identifier) +{ + op = NULL; + end (); /* yepee */ +} + + + +/** + * Main function of the test, run from scheduler. + * + * @param cls NULL + * @param cfg configuration we use (also to connect to identity service) + * @param peer handle to access more of the peer (not used) + */ +static void +run (void *cls, + const struct GNUNET_CONFIGURATION_Handle *cfg, + struct GNUNET_TESTING_Peer *peer) +{ + endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, + &endbadly, NULL); + h = GNUNET_IDENTITY_connect (cfg, ¬ification_cb, NULL); + op = GNUNET_IDENTITY_create (h, + "test-id", + &create_cb, + NULL); + +} + + + + +int +main (int argc, char *argv[]) +{ + res = 1; + if (0 != + GNUNET_TESTING_service_run ("test-identity", + "identity", + "test_identity.conf", + &run, + NULL)) + return 1; + return res; +} + + +/* end of test_identity.c */ diff --git a/src/identity/test_identity.conf b/src/identity/test_identity.conf new file mode 100644 index 000000000..3f57af93e --- /dev/null +++ b/src/identity/test_identity.conf @@ -0,0 +1,5 @@ +[arm] +PORT = 12000 +DEFAULTSERVICES = identity +UNIXPATH = /tmp/gnunet-p1-service-arm.sock + -- cgit v1.2.3