diff options
author | Christian Grothoff <christian@grothoff.org> | 2014-12-09 21:45:03 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2014-12-09 21:45:03 +0000 |
commit | 02102b75a9664460555ae0947350582293465abd (patch) | |
tree | 6afbd835d361722977b9aa8f241fdb175c6c8c6e /src | |
parent | e0f0366f920a4681be3ceb60bb86ecc82d14ce54 (diff) | |
download | gnunet-02102b75a9664460555ae0947350582293465abd.tar.gz gnunet-02102b75a9664460555ae0947350582293465abd.zip |
-running at scale...
Diffstat (limited to 'src')
-rw-r--r-- | src/scalarproduct/gnunet-scalarproduct.c | 19 | ||||
-rwxr-xr-x | src/scalarproduct/perf_scalarproduct.sh | 43 | ||||
-rw-r--r-- | src/scalarproduct/scalarproduct_api.c | 38 | ||||
-rwxr-xr-x | src/scalarproduct/test_scalarproduct.sh | 2 |
4 files changed, 95 insertions, 7 deletions
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, | |||
243 | input_peer_id); | 243 | input_peer_id); |
244 | return; | 244 | return; |
245 | } | 245 | } |
246 | 246 | if ( ('\'' == *begin) && | |
247 | ('\'' == begin[strlen(begin)-1]) ) | ||
248 | { | ||
249 | begin[strlen(begin)-1] = '\0'; | ||
250 | if (strlen (begin) > 0) | ||
251 | begin++; | ||
252 | } | ||
247 | for (end = begin; 0 != *end; end++) | 253 | for (end = begin; 0 != *end; end++) |
248 | if (*end == ';') | 254 | if (*end == ';') |
249 | element_count++; | 255 | element_count++; |
250 | if (0 == element_count) { | 256 | if (0 == element_count) |
257 | { | ||
251 | LOG (GNUNET_ERROR_TYPE_ERROR, | 258 | LOG (GNUNET_ERROR_TYPE_ERROR, |
252 | _("Need elements to compute the vectorproduct, got none.\n")); | 259 | _("Need elements to compute the scalarproduct, got none.\n")); |
253 | return; | 260 | return; |
254 | } | 261 | } |
255 | 262 | ||
@@ -276,9 +283,8 @@ run (void *cls, | |||
276 | GNUNET_free (elements); | 283 | GNUNET_free (elements); |
277 | return; | 284 | return; |
278 | } | 285 | } |
279 | |||
280 | /* read the element's key */ | ||
281 | *separator = 0; | 286 | *separator = 0; |
287 | /* read the element's key */ | ||
282 | GNUNET_CRYPTO_hash (begin, | 288 | GNUNET_CRYPTO_hash (begin, |
283 | strlen (begin), | 289 | strlen (begin), |
284 | &element.key); | 290 | &element.key); |
@@ -316,7 +322,8 @@ run (void *cls, | |||
316 | &responder_callback, | 322 | &responder_callback, |
317 | NULL))) ) ) | 323 | NULL))) ) ) |
318 | { | 324 | { |
319 | GNUNET_break (0); | 325 | fprintf (stderr, |
326 | _("Failed to initiate computation, were all keys unique?\n")); | ||
320 | GNUNET_free (elements); | 327 | GNUNET_free (elements); |
321 | return; | 328 | return; |
322 | } | 329 | } |
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 @@ | |||
1 | #!/bin/bash | ||
2 | # compute a simple scalar product | ||
3 | # payload for this test: | ||
4 | SIZE=1000 | ||
5 | INPUTALICE="-k CCC -e '" | ||
6 | INPUTBOB="-k CCC -e '" | ||
7 | for X in `seq 1 $SIZE` | ||
8 | do | ||
9 | INPUTALICE="${INPUTALICE}A${X},$X;" | ||
10 | INPUTBOB="${INPUTBOB}A${X},$X;" | ||
11 | done | ||
12 | INPUTALICE="${INPUTALICE}BC,-20000;RO,1000;FL,100;LOL,24;'" | ||
13 | INPUTBOB="${INPUTBOB}AB,10;RO,3;FL,3;LOL,-1;'" | ||
14 | |||
15 | # necessary to make the testing prefix deterministic, so we can access the config files | ||
16 | PREFIX=/tmp/test-scalarproduct`date +%H%M%S` | ||
17 | |||
18 | # where can we find the peers config files? | ||
19 | CFGALICE="-c $PREFIX/0/config" | ||
20 | CFGBOB="-c $PREFIX/1/config" | ||
21 | |||
22 | # launch two peers in line topology non-interactively | ||
23 | # | ||
24 | # interactive mode would terminate the test immediately | ||
25 | # because the rest of the script is already in stdin, | ||
26 | # thus redirecting stdin does not suffice) | ||
27 | GNUNET_FORCE_LOG=';;;;ERROR' | ||
28 | GNUNET_TESTING_PREFIX=$PREFIX ../testbed/gnunet-testbed-profiler -n -c test_scalarproduct.conf -p 2 & | ||
29 | PID=$! | ||
30 | # sleep 1 is too short on most systems, 2 works on most, 5 seems to be safe | ||
31 | echo "Waiting for peers to start..." | ||
32 | sleep 5 | ||
33 | # get Bob's peer ID, necessary for Alice | ||
34 | PEERIDBOB=`gnunet-peerinfo -qs $CFGBOB` | ||
35 | |||
36 | echo "Running problem of size $SIZE" | ||
37 | gnunet-scalarproduct $CFGBOB $INPUTBOB & | ||
38 | time RESULT=`gnunet-scalarproduct $CFGALICE $INPUTALICE -p $PEERIDBOB` | ||
39 | |||
40 | echo "Terminating testbed..." | ||
41 | # terminate the testbed | ||
42 | kill $PID | ||
43 | |||
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 | |||
@@ -268,6 +268,40 @@ process_status_message (struct GNUNET_SCALARPRODUCT_ComputationHandle *h, | |||
268 | 268 | ||
269 | 269 | ||
270 | /** | 270 | /** |
271 | * Check if the keys for all given elements are unique. | ||
272 | * | ||
273 | * @param elements elements to check | ||
274 | * @param element_count size of the @a elements array | ||
275 | * @return #GNUNET_OK if all keys are unique | ||
276 | */ | ||
277 | static int | ||
278 | check_unique (const struct GNUNET_SCALARPRODUCT_Element *elements, | ||
279 | uint32_t element_count) | ||
280 | { | ||
281 | struct GNUNET_CONTAINER_MultiHashMap *map; | ||
282 | uint32_t i; | ||
283 | int ok; | ||
284 | |||
285 | ok = GNUNET_OK; | ||
286 | map = GNUNET_CONTAINER_multihashmap_create (2 * element_count, | ||
287 | GNUNET_YES); | ||
288 | for (i=0;i<element_count;i++) | ||
289 | if (GNUNET_OK != | ||
290 | GNUNET_CONTAINER_multihashmap_put (map, | ||
291 | &elements[i].key, | ||
292 | map, | ||
293 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) | ||
294 | { | ||
295 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
296 | _("Keys given to SCALARPRODUCT not unique!\n")); | ||
297 | ok = GNUNET_SYSERR; | ||
298 | } | ||
299 | GNUNET_CONTAINER_multihashmap_destroy (map); | ||
300 | return ok; | ||
301 | } | ||
302 | |||
303 | |||
304 | /** | ||
271 | * Used by Bob's client to cooperate with Alice, | 305 | * Used by Bob's client to cooperate with Alice, |
272 | * | 306 | * |
273 | * @param cfg the gnunet configuration handle | 307 | * @param cfg the gnunet configuration handle |
@@ -291,6 +325,8 @@ GNUNET_SCALARPRODUCT_accept_computation (const struct GNUNET_CONFIGURATION_Handl | |||
291 | uint32_t size; | 325 | uint32_t size; |
292 | uint16_t possible; | 326 | uint16_t possible; |
293 | 327 | ||
328 | if (GNUNET_SYSERR == check_unique (elements, element_count)) | ||
329 | return NULL; | ||
294 | h = GNUNET_new (struct GNUNET_SCALARPRODUCT_ComputationHandle); | 330 | h = GNUNET_new (struct GNUNET_SCALARPRODUCT_ComputationHandle); |
295 | h->cont_status = cont; | 331 | h->cont_status = cont; |
296 | h->cont_cls = cont_cls; | 332 | h->cont_cls = cont_cls; |
@@ -433,6 +469,8 @@ GNUNET_SCALARPRODUCT_start_computation (const struct GNUNET_CONFIGURATION_Handle | |||
433 | uint32_t size; | 469 | uint32_t size; |
434 | uint32_t possible; | 470 | uint32_t possible; |
435 | 471 | ||
472 | if (GNUNET_SYSERR == check_unique (elements, element_count)) | ||
473 | return NULL; | ||
436 | h = GNUNET_new (struct GNUNET_SCALARPRODUCT_ComputationHandle); | 474 | h = GNUNET_new (struct GNUNET_SCALARPRODUCT_ComputationHandle); |
437 | h->client = GNUNET_CLIENT_connect ("scalarproduct-alice", cfg); | 475 | h->client = GNUNET_CLIENT_connect ("scalarproduct-alice", cfg); |
438 | if (NULL == h->client) | 476 | 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" | |||
17 | # interactive mode would terminate the test immediately | 17 | # interactive mode would terminate the test immediately |
18 | # because the rest of the script is already in stdin, | 18 | # because the rest of the script is already in stdin, |
19 | # thus redirecting stdin does not suffice) | 19 | # thus redirecting stdin does not suffice) |
20 | GNUNET_FORCE_LOG='scalarproduct*;;;;DEBUG' | 20 | # GNUNET_FORCE_LOG='scalarproduct*;;;;DEBUG' |
21 | GNUNET_TESTING_PREFIX=$PREFIX ../testbed/gnunet-testbed-profiler -n -c test_scalarproduct.conf -p 2 & | 21 | GNUNET_TESTING_PREFIX=$PREFIX ../testbed/gnunet-testbed-profiler -n -c test_scalarproduct.conf -p 2 & |
22 | PID=$! | 22 | PID=$! |
23 | # sleep 1 is too short on most systems, 2 works on most, 5 seems to be safe | 23 | # sleep 1 is too short on most systems, 2 works on most, 5 seems to be safe |