aboutsummaryrefslogtreecommitdiff
path: root/src/scalarproduct/scalarproduct_api.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2014-12-09 21:45:03 +0000
committerChristian Grothoff <christian@grothoff.org>2014-12-09 21:45:03 +0000
commit02102b75a9664460555ae0947350582293465abd (patch)
tree6afbd835d361722977b9aa8f241fdb175c6c8c6e /src/scalarproduct/scalarproduct_api.c
parente0f0366f920a4681be3ceb60bb86ecc82d14ce54 (diff)
downloadgnunet-02102b75a9664460555ae0947350582293465abd.tar.gz
gnunet-02102b75a9664460555ae0947350582293465abd.zip
-running at scale...
Diffstat (limited to 'src/scalarproduct/scalarproduct_api.c')
-rw-r--r--src/scalarproduct/scalarproduct_api.c38
1 files changed, 38 insertions, 0 deletions
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 */
277static int
278check_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)