From 02102b75a9664460555ae0947350582293465abd Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Tue, 9 Dec 2014 21:45:03 +0000 Subject: -running at scale... --- src/scalarproduct/gnunet-scalarproduct.c | 19 +++++++++----- src/scalarproduct/perf_scalarproduct.sh | 43 ++++++++++++++++++++++++++++++++ src/scalarproduct/scalarproduct_api.c | 38 ++++++++++++++++++++++++++++ src/scalarproduct/test_scalarproduct.sh | 2 +- 4 files changed, 95 insertions(+), 7 deletions(-) create mode 100755 src/scalarproduct/perf_scalarproduct.sh diff --git a/src/scalarproduct/gnunet-scalarproduct.c b/src/scalarproduct/gnunet-scalarproduct.c index b3b954211..be56a44f0 100644 --- a/src/scalarproduct/gnunet-scalarproduct.c +++ b/src/scalarproduct/gnunet-scalarproduct.c @@ -243,13 +243,20 @@ run (void *cls, input_peer_id); return; } - + if ( ('\'' == *begin) && + ('\'' == begin[strlen(begin)-1]) ) + { + begin[strlen(begin)-1] = '\0'; + if (strlen (begin) > 0) + begin++; + } for (end = begin; 0 != *end; end++) if (*end == ';') element_count++; - if (0 == element_count) { + if (0 == element_count) + { LOG (GNUNET_ERROR_TYPE_ERROR, - _("Need elements to compute the vectorproduct, got none.\n")); + _("Need elements to compute the scalarproduct, got none.\n")); return; } @@ -276,9 +283,8 @@ run (void *cls, GNUNET_free (elements); return; } - - /* read the element's key */ *separator = 0; + /* read the element's key */ GNUNET_CRYPTO_hash (begin, strlen (begin), &element.key); @@ -316,7 +322,8 @@ run (void *cls, &responder_callback, NULL))) ) ) { - GNUNET_break (0); + fprintf (stderr, + _("Failed to initiate computation, were all keys unique?\n")); GNUNET_free (elements); return; } diff --git a/src/scalarproduct/perf_scalarproduct.sh b/src/scalarproduct/perf_scalarproduct.sh new file mode 100755 index 000000000..35a6d872c --- /dev/null +++ b/src/scalarproduct/perf_scalarproduct.sh @@ -0,0 +1,43 @@ +#!/bin/bash +# compute a simple scalar product +# payload for this test: +SIZE=1000 +INPUTALICE="-k CCC -e '" +INPUTBOB="-k CCC -e '" +for X in `seq 1 $SIZE` +do + INPUTALICE="${INPUTALICE}A${X},$X;" + INPUTBOB="${INPUTBOB}A${X},$X;" +done +INPUTALICE="${INPUTALICE}BC,-20000;RO,1000;FL,100;LOL,24;'" +INPUTBOB="${INPUTBOB}AB,10;RO,3;FL,3;LOL,-1;'" + +# necessary to make the testing prefix deterministic, so we can access the config files +PREFIX=/tmp/test-scalarproduct`date +%H%M%S` + +# where can we find the peers config files? +CFGALICE="-c $PREFIX/0/config" +CFGBOB="-c $PREFIX/1/config" + +# launch two peers in line topology non-interactively +# +# interactive mode would terminate the test immediately +# because the rest of the script is already in stdin, +# thus redirecting stdin does not suffice) +GNUNET_FORCE_LOG=';;;;ERROR' +GNUNET_TESTING_PREFIX=$PREFIX ../testbed/gnunet-testbed-profiler -n -c test_scalarproduct.conf -p 2 & +PID=$! +# sleep 1 is too short on most systems, 2 works on most, 5 seems to be safe +echo "Waiting for peers to start..." +sleep 5 +# get Bob's peer ID, necessary for Alice +PEERIDBOB=`gnunet-peerinfo -qs $CFGBOB` + +echo "Running problem of size $SIZE" +gnunet-scalarproduct $CFGBOB $INPUTBOB & +time RESULT=`gnunet-scalarproduct $CFGALICE $INPUTALICE -p $PEERIDBOB` + +echo "Terminating testbed..." +# terminate the testbed +kill $PID + diff --git a/src/scalarproduct/scalarproduct_api.c b/src/scalarproduct/scalarproduct_api.c index cd63030bd..7c03150a3 100644 --- a/src/scalarproduct/scalarproduct_api.c +++ b/src/scalarproduct/scalarproduct_api.c @@ -267,6 +267,40 @@ process_status_message (struct GNUNET_SCALARPRODUCT_ComputationHandle *h, } +/** + * Check if the keys for all given elements are unique. + * + * @param elements elements to check + * @param element_count size of the @a elements array + * @return #GNUNET_OK if all keys are unique + */ +static int +check_unique (const struct GNUNET_SCALARPRODUCT_Element *elements, + uint32_t element_count) +{ + struct GNUNET_CONTAINER_MultiHashMap *map; + uint32_t i; + int ok; + + ok = GNUNET_OK; + map = GNUNET_CONTAINER_multihashmap_create (2 * element_count, + GNUNET_YES); + for (i=0;icont_status = cont; h->cont_cls = cont_cls; @@ -433,6 +469,8 @@ GNUNET_SCALARPRODUCT_start_computation (const struct GNUNET_CONFIGURATION_Handle uint32_t size; uint32_t possible; + if (GNUNET_SYSERR == check_unique (elements, element_count)) + return NULL; h = GNUNET_new (struct GNUNET_SCALARPRODUCT_ComputationHandle); h->client = GNUNET_CLIENT_connect ("scalarproduct-alice", cfg); if (NULL == h->client) diff --git a/src/scalarproduct/test_scalarproduct.sh b/src/scalarproduct/test_scalarproduct.sh index 562a4f68f..dd9bb80a5 100755 --- a/src/scalarproduct/test_scalarproduct.sh +++ b/src/scalarproduct/test_scalarproduct.sh @@ -17,7 +17,7 @@ CFGBOB="-c $PREFIX/1/config" # interactive mode would terminate the test immediately # because the rest of the script is already in stdin, # thus redirecting stdin does not suffice) -GNUNET_FORCE_LOG='scalarproduct*;;;;DEBUG' +# GNUNET_FORCE_LOG='scalarproduct*;;;;DEBUG' GNUNET_TESTING_PREFIX=$PREFIX ../testbed/gnunet-testbed-profiler -n -c test_scalarproduct.conf -p 2 & PID=$! # sleep 1 is too short on most systems, 2 works on most, 5 seems to be safe -- cgit v1.2.3