aboutsummaryrefslogtreecommitdiff
path: root/src/scalarproduct/gnunet-service-scalarproduct_alice.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/scalarproduct/gnunet-service-scalarproduct_alice.c')
-rw-r--r--src/scalarproduct/gnunet-service-scalarproduct_alice.c1141
1 files changed, 571 insertions, 570 deletions
diff --git a/src/scalarproduct/gnunet-service-scalarproduct_alice.c b/src/scalarproduct/gnunet-service-scalarproduct_alice.c
index e138876f5..6e823dca4 100644
--- a/src/scalarproduct/gnunet-service-scalarproduct_alice.c
+++ b/src/scalarproduct/gnunet-service-scalarproduct_alice.c
@@ -37,13 +37,12 @@
37#include "gnunet-service-scalarproduct.h" 37#include "gnunet-service-scalarproduct.h"
38 38
39#define LOG(kind, ...) \ 39#define LOG(kind, ...) \
40 GNUNET_log_from (kind, "scalarproduct-alice", __VA_ARGS__) 40 GNUNET_log_from(kind, "scalarproduct-alice", __VA_ARGS__)
41 41
42/** 42/**
43 * An encrypted element key-value pair. 43 * An encrypted element key-value pair.
44 */ 44 */
45struct MpiElement 45struct MpiElement {
46{
47 /** 46 /**
48 * Key used to identify matching pairs of values to multiply. 47 * Key used to identify matching pairs of values to multiply.
49 * Points into an existing data structure, to avoid copying 48 * Points into an existing data structure, to avoid copying
@@ -62,9 +61,7 @@ struct MpiElement
62 * A scalarproduct session which tracks 61 * A scalarproduct session which tracks
63 * a request form the client to our final response. 62 * a request form the client to our final response.
64 */ 63 */
65struct AliceServiceSession 64struct AliceServiceSession {
66{
67
68 /** 65 /**
69 * (hopefully) unique transaction ID 66 * (hopefully) unique transaction ID
70 */ 67 */
@@ -224,11 +221,11 @@ static struct GNUNET_CADET_Handle *my_cadet;
224 * @return #GNUNET_OK (continue to iterate) 221 * @return #GNUNET_OK (continue to iterate)
225 */ 222 */
226static int 223static int
227free_element_cb (void *cls, const struct GNUNET_HashCode *key, void *value) 224free_element_cb(void *cls, const struct GNUNET_HashCode *key, void *value)
228{ 225{
229 struct GNUNET_SCALARPRODUCT_Element *e = value; 226 struct GNUNET_SCALARPRODUCT_Element *e = value;
230 227
231 GNUNET_free (e); 228 GNUNET_free(e);
232 return GNUNET_OK; 229 return GNUNET_OK;
233} 230}
234 231
@@ -239,69 +236,69 @@ free_element_cb (void *cls, const struct GNUNET_HashCode *key, void *value)
239 * @param s the session to free elements from 236 * @param s the session to free elements from
240 */ 237 */
241static void 238static void
242destroy_service_session (struct AliceServiceSession *s) 239destroy_service_session(struct AliceServiceSession *s)
243{ 240{
244 if (GNUNET_YES == s->in_destroy) 241 if (GNUNET_YES == s->in_destroy)
245 return; 242 return;
246 s->in_destroy = GNUNET_YES; 243 s->in_destroy = GNUNET_YES;
247 if (NULL != s->client) 244 if (NULL != s->client)
248 { 245 {
249 struct GNUNET_SERVICE_Client *c = s->client; 246 struct GNUNET_SERVICE_Client *c = s->client;
250 247
251 s->client = NULL; 248 s->client = NULL;
252 GNUNET_SERVICE_client_drop (c); 249 GNUNET_SERVICE_client_drop(c);
253 } 250 }
254 if (NULL != s->channel) 251 if (NULL != s->channel)
255 { 252 {
256 GNUNET_CADET_channel_destroy (s->channel); 253 GNUNET_CADET_channel_destroy(s->channel);
257 s->channel = NULL; 254 s->channel = NULL;
258 } 255 }
259 if (NULL != s->intersected_elements) 256 if (NULL != s->intersected_elements)
260 { 257 {
261 GNUNET_CONTAINER_multihashmap_iterate (s->intersected_elements, 258 GNUNET_CONTAINER_multihashmap_iterate(s->intersected_elements,
262 &free_element_cb, 259 &free_element_cb,
263 s); 260 s);
264 GNUNET_CONTAINER_multihashmap_destroy (s->intersected_elements); 261 GNUNET_CONTAINER_multihashmap_destroy(s->intersected_elements);
265 s->intersected_elements = NULL; 262 s->intersected_elements = NULL;
266 } 263 }
267 if (NULL != s->intersection_listen) 264 if (NULL != s->intersection_listen)
268 { 265 {
269 GNUNET_SET_listen_cancel (s->intersection_listen); 266 GNUNET_SET_listen_cancel(s->intersection_listen);
270 s->intersection_listen = NULL; 267 s->intersection_listen = NULL;
271 } 268 }
272 if (NULL != s->intersection_op) 269 if (NULL != s->intersection_op)
273 { 270 {
274 GNUNET_SET_operation_cancel (s->intersection_op); 271 GNUNET_SET_operation_cancel(s->intersection_op);
275 s->intersection_op = NULL; 272 s->intersection_op = NULL;
276 } 273 }
277 if (NULL != s->intersection_set) 274 if (NULL != s->intersection_set)
278 { 275 {
279 GNUNET_SET_destroy (s->intersection_set); 276 GNUNET_SET_destroy(s->intersection_set);
280 s->intersection_set = NULL; 277 s->intersection_set = NULL;
281 } 278 }
282 if (NULL != s->sorted_elements) 279 if (NULL != s->sorted_elements)
283 { 280 {
284 for (unsigned int i = 0; i < s->used_element_count; i++) 281 for (unsigned int i = 0; i < s->used_element_count; i++)
285 gcry_mpi_release (s->sorted_elements[i].value); 282 gcry_mpi_release(s->sorted_elements[i].value);
286 GNUNET_free (s->sorted_elements); 283 GNUNET_free(s->sorted_elements);
287 s->sorted_elements = NULL; 284 s->sorted_elements = NULL;
288 } 285 }
289 if (NULL != s->r) 286 if (NULL != s->r)
290 { 287 {
291 GNUNET_free (s->r); 288 GNUNET_free(s->r);
292 s->r = NULL; 289 s->r = NULL;
293 } 290 }
294 if (NULL != s->r_prime) 291 if (NULL != s->r_prime)
295 { 292 {
296 GNUNET_free (s->r_prime); 293 GNUNET_free(s->r_prime);
297 s->r_prime = NULL; 294 s->r_prime = NULL;
298 } 295 }
299 if (NULL != s->product) 296 if (NULL != s->product)
300 { 297 {
301 gcry_mpi_release (s->product); 298 gcry_mpi_release(s->product);
302 s->product = NULL; 299 s->product = NULL;
303 } 300 }
304 GNUNET_free (s); 301 GNUNET_free(s);
305} 302}
306 303
307 304
@@ -312,22 +309,22 @@ destroy_service_session (struct AliceServiceSession *s)
312 * @param session the associated client session to fail or succeed 309 * @param session the associated client session to fail or succeed
313 */ 310 */
314static void 311static void
315prepare_client_end_notification (struct AliceServiceSession *session) 312prepare_client_end_notification(struct AliceServiceSession *session)
316{ 313{
317 struct ClientResponseMessage *msg; 314 struct ClientResponseMessage *msg;
318 struct GNUNET_MQ_Envelope *e; 315 struct GNUNET_MQ_Envelope *e;
319 316
320 if (NULL == session->client_mq) 317 if (NULL == session->client_mq)
321 return; /* no client left to be notified */ 318 return; /* no client left to be notified */
322 GNUNET_log ( 319 GNUNET_log(
323 GNUNET_ERROR_TYPE_DEBUG, 320 GNUNET_ERROR_TYPE_DEBUG,
324 "Sending session-end notification with status %d to client for session %s\n", 321 "Sending session-end notification with status %d to client for session %s\n",
325 session->status, 322 session->status,
326 GNUNET_h2s (&session->session_id)); 323 GNUNET_h2s(&session->session_id));
327 e = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_SCALARPRODUCT_RESULT); 324 e = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_SCALARPRODUCT_RESULT);
328 msg->product_length = htonl (0); 325 msg->product_length = htonl(0);
329 msg->status = htonl (session->status); 326 msg->status = htonl(session->status);
330 GNUNET_MQ_send (session->client_mq, e); 327 GNUNET_MQ_send(session->client_mq, e);
331} 328}
332 329
333 330
@@ -338,7 +335,7 @@ prepare_client_end_notification (struct AliceServiceSession *session)
338 * @param s the session associated with our client. 335 * @param s the session associated with our client.
339 */ 336 */
340static void 337static void
341transmit_client_response (struct AliceServiceSession *s) 338transmit_client_response(struct AliceServiceSession *s)
342{ 339{
343 struct ClientResponseMessage *msg; 340 struct ClientResponseMessage *msg;
344 struct GNUNET_MQ_Envelope *e; 341 struct GNUNET_MQ_Envelope *e;
@@ -350,56 +347,56 @@ transmit_client_response (struct AliceServiceSession *s)
350 gcry_mpi_t value; 347 gcry_mpi_t value;
351 348
352 if (NULL == s->product) 349 if (NULL == s->product)
353 { 350 {
354 GNUNET_break (0); 351 GNUNET_break(0);
355 prepare_client_end_notification (s); 352 prepare_client_end_notification(s);
356 return; 353 return;
357 } 354 }
358 value = gcry_mpi_new (0); 355 value = gcry_mpi_new(0);
359 sign = gcry_mpi_cmp_ui (s->product, 0); 356 sign = gcry_mpi_cmp_ui(s->product, 0);
360 if (0 > sign) 357 if (0 > sign)
361 { 358 {
362 range = -1; 359 range = -1;
363 gcry_mpi_sub (value, value, s->product); 360 gcry_mpi_sub(value, value, s->product);
364 } 361 }
365 else if (0 < sign) 362 else if (0 < sign)
366 { 363 {
367 range = 1; 364 range = 1;
368 gcry_mpi_add (value, value, s->product); 365 gcry_mpi_add(value, value, s->product);
369 } 366 }
370 else 367 else
371 { 368 {
372 /* result is exactly zero */ 369 /* result is exactly zero */
373 range = 0; 370 range = 0;
374 } 371 }
375 gcry_mpi_release (s->product); 372 gcry_mpi_release(s->product);
376 s->product = NULL; 373 s->product = NULL;
377 374
378 if ((0 != range) && (0 != (rc = gcry_mpi_aprint (GCRYMPI_FMT_STD, 375 if ((0 != range) && (0 != (rc = gcry_mpi_aprint(GCRYMPI_FMT_STD,
379 &product_exported, 376 &product_exported,
380 &product_length, 377 &product_length,
381 value)))) 378 value))))
382 { 379 {
383 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); 380 LOG_GCRY(GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc);
384 prepare_client_end_notification (s); 381 prepare_client_end_notification(s);
385 return; 382 return;
386 } 383 }
387 gcry_mpi_release (value); 384 gcry_mpi_release(value);
388 e = GNUNET_MQ_msg_extra (msg, 385 e = GNUNET_MQ_msg_extra(msg,
389 product_length, 386 product_length,
390 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_RESULT); 387 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_RESULT);
391 msg->status = htonl (GNUNET_SCALARPRODUCT_STATUS_SUCCESS); 388 msg->status = htonl(GNUNET_SCALARPRODUCT_STATUS_SUCCESS);
392 msg->range = htonl (range); 389 msg->range = htonl(range);
393 msg->product_length = htonl (product_length); 390 msg->product_length = htonl(product_length);
394 if (NULL != product_exported) 391 if (NULL != product_exported)
395 { 392 {
396 GNUNET_memcpy (&msg[1], product_exported, product_length); 393 GNUNET_memcpy(&msg[1], product_exported, product_length);
397 GNUNET_free (product_exported); 394 GNUNET_free(product_exported);
398 } 395 }
399 GNUNET_MQ_send (s->client_mq, e); 396 GNUNET_MQ_send(s->client_mq, e);
400 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 397 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
401 "Sent result to client, session %s has ended!\n", 398 "Sent result to client, session %s has ended!\n",
402 GNUNET_h2s (&s->session_id)); 399 GNUNET_h2s(&s->session_id));
403} 400}
404 401
405 402
@@ -413,20 +410,20 @@ transmit_client_response (struct AliceServiceSession *s)
413 * @param channel connection to the other end (henceforth invalid) 410 * @param channel connection to the other end (henceforth invalid)
414 */ 411 */
415static void 412static void
416cb_channel_destruction (void *cls, const struct GNUNET_CADET_Channel *channel) 413cb_channel_destruction(void *cls, const struct GNUNET_CADET_Channel *channel)
417{ 414{
418 struct AliceServiceSession *s = cls; 415 struct AliceServiceSession *s = cls;
419 416
420 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 417 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
421 "Peer disconnected, terminating session %s with peer %s\n", 418 "Peer disconnected, terminating session %s with peer %s\n",
422 GNUNET_h2s (&s->session_id), 419 GNUNET_h2s(&s->session_id),
423 GNUNET_i2s (&s->peer)); 420 GNUNET_i2s(&s->peer));
424 if (GNUNET_SCALARPRODUCT_STATUS_ACTIVE == s->status) 421 if (GNUNET_SCALARPRODUCT_STATUS_ACTIVE == s->status)
425 { 422 {
426 /* We didn't get an answer yet, fail with error */ 423 /* We didn't get an answer yet, fail with error */
427 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; 424 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE;
428 prepare_client_end_notification (s); 425 prepare_client_end_notification(s);
429 } 426 }
430 s->channel = NULL; 427 s->channel = NULL;
431} 428}
432 429
@@ -439,21 +436,21 @@ cb_channel_destruction (void *cls, const struct GNUNET_CADET_Channel *channel)
439 * @return an MPI value containing the calculated sum, never NULL 436 * @return an MPI value containing the calculated sum, never NULL
440 */ 437 */
441static gcry_mpi_t 438static gcry_mpi_t
442compute_square_sum_mpi_elements (const struct MpiElement *vector, 439compute_square_sum_mpi_elements(const struct MpiElement *vector,
443 uint32_t length) 440 uint32_t length)
444{ 441{
445 gcry_mpi_t elem; 442 gcry_mpi_t elem;
446 gcry_mpi_t sum; 443 gcry_mpi_t sum;
447 uint32_t i; 444 uint32_t i;
448 445
449 GNUNET_assert (NULL != (sum = gcry_mpi_new (0))); 446 GNUNET_assert(NULL != (sum = gcry_mpi_new(0)));
450 GNUNET_assert (NULL != (elem = gcry_mpi_new (0))); 447 GNUNET_assert(NULL != (elem = gcry_mpi_new(0)));
451 for (i = 0; i < length; i++) 448 for (i = 0; i < length; i++)
452 { 449 {
453 gcry_mpi_mul (elem, vector[i].value, vector[i].value); 450 gcry_mpi_mul(elem, vector[i].value, vector[i].value);
454 gcry_mpi_add (sum, sum, elem); 451 gcry_mpi_add(sum, sum, elem);
455 } 452 }
456 gcry_mpi_release (elem); 453 gcry_mpi_release(elem);
457 return sum; 454 return sum;
458} 455}
459 456
@@ -466,20 +463,20 @@ compute_square_sum_mpi_elements (const struct MpiElement *vector,
466 * @return an MPI value containing the calculated sum, never NULL 463 * @return an MPI value containing the calculated sum, never NULL
467 */ 464 */
468static gcry_mpi_t 465static gcry_mpi_t
469compute_square_sum (const gcry_mpi_t *vector, uint32_t length) 466compute_square_sum(const gcry_mpi_t *vector, uint32_t length)
470{ 467{
471 gcry_mpi_t elem; 468 gcry_mpi_t elem;
472 gcry_mpi_t sum; 469 gcry_mpi_t sum;
473 uint32_t i; 470 uint32_t i;
474 471
475 GNUNET_assert (NULL != (sum = gcry_mpi_new (0))); 472 GNUNET_assert(NULL != (sum = gcry_mpi_new(0)));
476 GNUNET_assert (NULL != (elem = gcry_mpi_new (0))); 473 GNUNET_assert(NULL != (elem = gcry_mpi_new(0)));
477 for (i = 0; i < length; i++) 474 for (i = 0; i < length; i++)
478 { 475 {
479 gcry_mpi_mul (elem, vector[i], vector[i]); 476 gcry_mpi_mul(elem, vector[i], vector[i]);
480 gcry_mpi_add (sum, sum, elem); 477 gcry_mpi_add(sum, sum, elem);
481 } 478 }
482 gcry_mpi_release (elem); 479 gcry_mpi_release(elem);
483 return sum; 480 return sum;
484} 481}
485 482
@@ -491,7 +488,7 @@ compute_square_sum (const gcry_mpi_t *vector, uint32_t length)
491 * @return product as MPI, never NULL 488 * @return product as MPI, never NULL
492 */ 489 */
493static gcry_mpi_t 490static gcry_mpi_t
494compute_scalar_product (struct AliceServiceSession *session) 491compute_scalar_product(struct AliceServiceSession *session)
495{ 492{
496 uint32_t count; 493 uint32_t count;
497 gcry_mpi_t t; 494 gcry_mpi_t t;
@@ -511,80 +508,80 @@ compute_scalar_product (struct AliceServiceSession *session)
511 // from the E(a_pi)(+)E(-b_pi-r_pi) and E(a_qi)(+)E(-r_qi) twice each, 508 // from the E(a_pi)(+)E(-b_pi-r_pi) and E(a_qi)(+)E(-r_qi) twice each,
512 // the result is E((S + a_pi) + (S -b_pi-r_pi)) and E(S + a_qi + S - r_qi) 509 // the result is E((S + a_pi) + (S -b_pi-r_pi)) and E(S + a_qi + S - r_qi)
513 for (i = 0; i < count; i++) 510 for (i = 0; i < count; i++)
514 { 511 {
515 r[i] = gcry_mpi_new (0); 512 r[i] = gcry_mpi_new(0);
516 GNUNET_CRYPTO_paillier_decrypt (&my_privkey, 513 GNUNET_CRYPTO_paillier_decrypt(&my_privkey,
517 &my_pubkey, 514 &my_pubkey,
518 &session->r[i], 515 &session->r[i],
519 r[i]); 516 r[i]);
520 gcry_mpi_sub (r[i], r[i], my_offset); 517 gcry_mpi_sub(r[i], r[i], my_offset);
521 gcry_mpi_sub (r[i], r[i], my_offset); 518 gcry_mpi_sub(r[i], r[i], my_offset);
522 r_prime[i] = gcry_mpi_new (0); 519 r_prime[i] = gcry_mpi_new(0);
523 GNUNET_CRYPTO_paillier_decrypt (&my_privkey, 520 GNUNET_CRYPTO_paillier_decrypt(&my_privkey,
524 &my_pubkey, 521 &my_pubkey,
525 &session->r_prime[i], 522 &session->r_prime[i],
526 r_prime[i]); 523 r_prime[i]);
527 gcry_mpi_sub (r_prime[i], r_prime[i], my_offset); 524 gcry_mpi_sub(r_prime[i], r_prime[i], my_offset);
528 gcry_mpi_sub (r_prime[i], r_prime[i], my_offset); 525 gcry_mpi_sub(r_prime[i], r_prime[i], my_offset);
529 } 526 }
530 527
531 // calculate t = sum(ai) 528 // calculate t = sum(ai)
532 t = compute_square_sum_mpi_elements (session->sorted_elements, count); 529 t = compute_square_sum_mpi_elements(session->sorted_elements, count);
533 // calculate U 530 // calculate U
534 u = gcry_mpi_new (0); 531 u = gcry_mpi_new(0);
535 tmp = compute_square_sum (r, count); 532 tmp = compute_square_sum(r, count);
536 gcry_mpi_sub (u, u, tmp); 533 gcry_mpi_sub(u, u, tmp);
537 gcry_mpi_release (tmp); 534 gcry_mpi_release(tmp);
538 535
539 //calculate U' 536 //calculate U'
540 u_prime = gcry_mpi_new (0); 537 u_prime = gcry_mpi_new(0);
541 tmp = compute_square_sum (r_prime, count); 538 tmp = compute_square_sum(r_prime, count);
542 gcry_mpi_sub (u_prime, u_prime, tmp); 539 gcry_mpi_sub(u_prime, u_prime, tmp);
543 540
544 GNUNET_assert (p = gcry_mpi_new (0)); 541 GNUNET_assert(p = gcry_mpi_new(0));
545 GNUNET_assert (p_prime = gcry_mpi_new (0)); 542 GNUNET_assert(p_prime = gcry_mpi_new(0));
546 GNUNET_assert (s = gcry_mpi_new (0)); 543 GNUNET_assert(s = gcry_mpi_new(0));
547 GNUNET_assert (s_prime = gcry_mpi_new (0)); 544 GNUNET_assert(s_prime = gcry_mpi_new(0));
548 545
549 // compute P 546 // compute P
550 GNUNET_CRYPTO_paillier_decrypt (&my_privkey, &my_pubkey, &session->s, s); 547 GNUNET_CRYPTO_paillier_decrypt(&my_privkey, &my_pubkey, &session->s, s);
551 GNUNET_CRYPTO_paillier_decrypt (&my_privkey, 548 GNUNET_CRYPTO_paillier_decrypt(&my_privkey,
552 &my_pubkey, 549 &my_pubkey,
553 &session->s_prime, 550 &session->s_prime,
554 s_prime); 551 s_prime);
555 552
556 // compute P 553 // compute P
557 gcry_mpi_add (p, s, t); 554 gcry_mpi_add(p, s, t);
558 gcry_mpi_add (p, p, u); 555 gcry_mpi_add(p, p, u);
559 556
560 // compute P' 557 // compute P'
561 gcry_mpi_add (p_prime, s_prime, t); 558 gcry_mpi_add(p_prime, s_prime, t);
562 gcry_mpi_add (p_prime, p_prime, u_prime); 559 gcry_mpi_add(p_prime, p_prime, u_prime);
563 560
564 gcry_mpi_release (t); 561 gcry_mpi_release(t);
565 gcry_mpi_release (u); 562 gcry_mpi_release(u);
566 gcry_mpi_release (u_prime); 563 gcry_mpi_release(u_prime);
567 gcry_mpi_release (s); 564 gcry_mpi_release(s);
568 gcry_mpi_release (s_prime); 565 gcry_mpi_release(s_prime);
569 566
570 // compute product 567 // compute product
571 gcry_mpi_sub (p, p, p_prime); 568 gcry_mpi_sub(p, p, p_prime);
572 gcry_mpi_release (p_prime); 569 gcry_mpi_release(p_prime);
573 tmp = gcry_mpi_set_ui (tmp, 2); 570 tmp = gcry_mpi_set_ui(tmp, 2);
574 gcry_mpi_div (p, NULL, p, tmp, 0); 571 gcry_mpi_div(p, NULL, p, tmp, 0);
575 572
576 gcry_mpi_release (tmp); 573 gcry_mpi_release(tmp);
577 for (i = 0; i < count; i++) 574 for (i = 0; i < count; i++)
578 { 575 {
579 gcry_mpi_release (session->sorted_elements[i].value); 576 gcry_mpi_release(session->sorted_elements[i].value);
580 gcry_mpi_release (r[i]); 577 gcry_mpi_release(r[i]);
581 gcry_mpi_release (r_prime[i]); 578 gcry_mpi_release(r_prime[i]);
582 } 579 }
583 GNUNET_free (session->sorted_elements); 580 GNUNET_free(session->sorted_elements);
584 session->sorted_elements = NULL; 581 session->sorted_elements = NULL;
585 GNUNET_free (session->r); 582 GNUNET_free(session->r);
586 session->r = NULL; 583 session->r = NULL;
587 GNUNET_free (session->r_prime); 584 GNUNET_free(session->r_prime);
588 session->r_prime = NULL; 585 session->r_prime = NULL;
589 586
590 return p; 587 return p;
@@ -601,7 +598,7 @@ compute_scalar_product (struct AliceServiceSession *session)
601 * #GNUNET_SYSERR to close it (signal serious error) 598 * #GNUNET_SYSERR to close it (signal serious error)
602 */ 599 */
603static int 600static int
604check_bobs_cryptodata_multipart ( 601check_bobs_cryptodata_multipart(
605 void *cls, 602 void *cls,
606 const struct BobCryptodataMultipartMessage *msg) 603 const struct BobCryptodataMultipartMessage *msg)
607{ 604{
@@ -610,17 +607,17 @@ check_bobs_cryptodata_multipart (
610 size_t msg_size; 607 size_t msg_size;
611 size_t required_size; 608 size_t required_size;
612 609
613 msg_size = ntohs (msg->header.size); 610 msg_size = ntohs(msg->header.size);
614 contained = ntohl (msg->contained_element_count); 611 contained = ntohl(msg->contained_element_count);
615 required_size = 612 required_size =
616 sizeof (struct BobCryptodataMultipartMessage) + 613 sizeof(struct BobCryptodataMultipartMessage) +
617 2 * contained * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext); 614 2 * contained * sizeof(struct GNUNET_CRYPTO_PaillierCiphertext);
618 if ((required_size != msg_size) || 615 if ((required_size != msg_size) ||
619 (s->cadet_received_element_count + contained > s->used_element_count)) 616 (s->cadet_received_element_count + contained > s->used_element_count))
620 { 617 {
621 GNUNET_break (0); 618 GNUNET_break(0);
622 return GNUNET_SYSERR; 619 return GNUNET_SYSERR;
623 } 620 }
624 return GNUNET_OK; 621 return GNUNET_OK;
625} 622}
626 623
@@ -632,7 +629,7 @@ check_bobs_cryptodata_multipart (
632 * @param msg the actual message 629 * @param msg the actual message
633 */ 630 */
634static void 631static void
635handle_bobs_cryptodata_multipart ( 632handle_bobs_cryptodata_multipart(
636 void *cls, 633 void *cls,
637 const struct BobCryptodataMultipartMessage *msg) 634 const struct BobCryptodataMultipartMessage *msg)
638{ 635{
@@ -641,29 +638,29 @@ handle_bobs_cryptodata_multipart (
641 size_t i; 638 size_t i;
642 uint32_t contained; 639 uint32_t contained;
643 640
644 contained = ntohl (msg->contained_element_count); 641 contained = ntohl(msg->contained_element_count);
645 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 642 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
646 "Received %u additional crypto values from Bob\n", 643 "Received %u additional crypto values from Bob\n",
647 (unsigned int) contained); 644 (unsigned int)contained);
648 645
649 payload = (const struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1]; 646 payload = (const struct GNUNET_CRYPTO_PaillierCiphertext *)&msg[1];
650 /* Convert each k[][perm] to its MPI_value */ 647 /* Convert each k[][perm] to its MPI_value */
651 for (i = 0; i < contained; i++) 648 for (i = 0; i < contained; i++)
652 { 649 {
653 GNUNET_memcpy (&s->r[s->cadet_received_element_count + i], 650 GNUNET_memcpy(&s->r[s->cadet_received_element_count + i],
654 &payload[2 * i], 651 &payload[2 * i],
655 sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); 652 sizeof(struct GNUNET_CRYPTO_PaillierCiphertext));
656 GNUNET_memcpy (&s->r_prime[s->cadet_received_element_count + i], 653 GNUNET_memcpy(&s->r_prime[s->cadet_received_element_count + i],
657 &payload[2 * i], 654 &payload[2 * i],
658 sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); 655 sizeof(struct GNUNET_CRYPTO_PaillierCiphertext));
659 } 656 }
660 s->cadet_received_element_count += contained; 657 s->cadet_received_element_count += contained;
661 GNUNET_CADET_receive_done (s->channel); 658 GNUNET_CADET_receive_done(s->channel);
662 if (s->cadet_received_element_count != s->used_element_count) 659 if (s->cadet_received_element_count != s->used_element_count)
663 return; /* more to come */ 660 return; /* more to come */
664 661
665 s->product = compute_scalar_product (s); 662 s->product = compute_scalar_product(s);
666 transmit_client_response (s); 663 transmit_client_response(s);
667} 664}
668 665
669 666
@@ -677,38 +674,38 @@ handle_bobs_cryptodata_multipart (
677 * #GNUNET_SYSERR to close it (we are done) 674 * #GNUNET_SYSERR to close it (we are done)
678 */ 675 */
679static int 676static int
680check_bobs_cryptodata_message (void *cls, 677check_bobs_cryptodata_message(void *cls,
681 const struct BobCryptodataMessage *msg) 678 const struct BobCryptodataMessage *msg)
682{ 679{
683 struct AliceServiceSession *s = cls; 680 struct AliceServiceSession *s = cls;
684 uint32_t contained; 681 uint32_t contained;
685 uint16_t msg_size; 682 uint16_t msg_size;
686 size_t required_size; 683 size_t required_size;
687 684
688 msg_size = ntohs (msg->header.size); 685 msg_size = ntohs(msg->header.size);
689 contained = ntohl (msg->contained_element_count); 686 contained = ntohl(msg->contained_element_count);
690 required_size = 687 required_size =
691 sizeof (struct BobCryptodataMessage) + 688 sizeof(struct BobCryptodataMessage) +
692 2 * contained * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext) + 689 2 * contained * sizeof(struct GNUNET_CRYPTO_PaillierCiphertext) +
693 2 * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext); 690 2 * sizeof(struct GNUNET_CRYPTO_PaillierCiphertext);
694 if ((msg_size != required_size) || (contained > UINT16_MAX) || 691 if ((msg_size != required_size) || (contained > UINT16_MAX) ||
695 (s->used_element_count < contained)) 692 (s->used_element_count < contained))
696 { 693 {
697 GNUNET_break_op (0); 694 GNUNET_break_op(0);
698 return GNUNET_SYSERR; 695 return GNUNET_SYSERR;
699 } 696 }
700 if (NULL == s->sorted_elements) 697 if (NULL == s->sorted_elements)
701 { 698 {
702 /* we're not ready yet, how can Bob be? */ 699 /* we're not ready yet, how can Bob be? */
703 GNUNET_break_op (0); 700 GNUNET_break_op(0);
704 return GNUNET_SYSERR; 701 return GNUNET_SYSERR;
705 } 702 }
706 if (s->total != s->client_received_element_count) 703 if (s->total != s->client_received_element_count)
707 { 704 {
708 /* we're not ready yet, how can Bob be? */ 705 /* we're not ready yet, how can Bob be? */
709 GNUNET_break_op (0); 706 GNUNET_break_op(0);
710 return GNUNET_SYSERR; 707 return GNUNET_SYSERR;
711 } 708 }
712 return GNUNET_OK; 709 return GNUNET_OK;
713} 710}
714 711
@@ -721,50 +718,50 @@ check_bobs_cryptodata_message (void *cls,
721 * @param msg the actual message 718 * @param msg the actual message
722 */ 719 */
723static void 720static void
724handle_bobs_cryptodata_message (void *cls, 721handle_bobs_cryptodata_message(void *cls,
725 const struct BobCryptodataMessage *msg) 722 const struct BobCryptodataMessage *msg)
726{ 723{
727 struct AliceServiceSession *s = cls; 724 struct AliceServiceSession *s = cls;
728 const struct GNUNET_CRYPTO_PaillierCiphertext *payload; 725 const struct GNUNET_CRYPTO_PaillierCiphertext *payload;
729 uint32_t i; 726 uint32_t i;
730 uint32_t contained; 727 uint32_t contained;
731 728
732 contained = ntohl (msg->contained_element_count); 729 contained = ntohl(msg->contained_element_count);
733 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 730 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
734 "Received %u crypto values from Bob\n", 731 "Received %u crypto values from Bob\n",
735 (unsigned int) contained); 732 (unsigned int)contained);
736 payload = (const struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1]; 733 payload = (const struct GNUNET_CRYPTO_PaillierCiphertext *)&msg[1];
737 GNUNET_memcpy (&s->s, 734 GNUNET_memcpy(&s->s,
738 &payload[0], 735 &payload[0],
739 sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); 736 sizeof(struct GNUNET_CRYPTO_PaillierCiphertext));
740 GNUNET_memcpy (&s->s_prime, 737 GNUNET_memcpy(&s->s_prime,
741 &payload[1], 738 &payload[1],
742 sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); 739 sizeof(struct GNUNET_CRYPTO_PaillierCiphertext));
743 payload = &payload[2]; 740 payload = &payload[2];
744 741
745 s->r = GNUNET_new_array (s->used_element_count, 742 s->r = GNUNET_new_array(s->used_element_count,
746 struct GNUNET_CRYPTO_PaillierCiphertext); 743 struct GNUNET_CRYPTO_PaillierCiphertext);
747 s->r_prime = GNUNET_new_array (s->used_element_count, 744 s->r_prime = GNUNET_new_array(s->used_element_count,
748 struct GNUNET_CRYPTO_PaillierCiphertext); 745 struct GNUNET_CRYPTO_PaillierCiphertext);
749 for (i = 0; i < contained; i++) 746 for (i = 0; i < contained; i++)
750 { 747 {
751 GNUNET_memcpy (&s->r[i], 748 GNUNET_memcpy(&s->r[i],
752 &payload[2 * i], 749 &payload[2 * i],
753 sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); 750 sizeof(struct GNUNET_CRYPTO_PaillierCiphertext));
754 GNUNET_memcpy (&s->r_prime[i], 751 GNUNET_memcpy(&s->r_prime[i],
755 &payload[2 * i + 1], 752 &payload[2 * i + 1],
756 sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); 753 sizeof(struct GNUNET_CRYPTO_PaillierCiphertext));
757 } 754 }
758 s->cadet_received_element_count = contained; 755 s->cadet_received_element_count = contained;
759 GNUNET_CADET_receive_done (s->channel); 756 GNUNET_CADET_receive_done(s->channel);
760 757
761 if (s->cadet_received_element_count != s->used_element_count) 758 if (s->cadet_received_element_count != s->used_element_count)
762 { 759 {
763 /* More to come */ 760 /* More to come */
764 return; 761 return;
765 } 762 }
766 s->product = compute_scalar_product (s); 763 s->product = compute_scalar_product(s);
767 transmit_client_response (s); 764 transmit_client_response(s);
768} 765}
769 766
770 767
@@ -777,19 +774,19 @@ handle_bobs_cryptodata_message (void *cls,
777 * @param value the `struct GNUNET_SCALARPRODUCT_Element *` 774 * @param value the `struct GNUNET_SCALARPRODUCT_Element *`
778 */ 775 */
779static int 776static int
780copy_element_cb (void *cls, const struct GNUNET_HashCode *key, void *value) 777copy_element_cb(void *cls, const struct GNUNET_HashCode *key, void *value)
781{ 778{
782 struct AliceServiceSession *s = cls; 779 struct AliceServiceSession *s = cls;
783 struct GNUNET_SCALARPRODUCT_Element *e = value; 780 struct GNUNET_SCALARPRODUCT_Element *e = value;
784 gcry_mpi_t mval; 781 gcry_mpi_t mval;
785 int64_t val; 782 int64_t val;
786 783
787 mval = gcry_mpi_new (0); 784 mval = gcry_mpi_new(0);
788 val = (int64_t) GNUNET_ntohll (e->value); 785 val = (int64_t)GNUNET_ntohll(e->value);
789 if (0 > val) 786 if (0 > val)
790 gcry_mpi_sub_ui (mval, mval, -val); 787 gcry_mpi_sub_ui(mval, mval, -val);
791 else 788 else
792 gcry_mpi_add_ui (mval, mval, val); 789 gcry_mpi_add_ui(mval, mval, val);
793 s->sorted_elements[s->used_element_count].value = mval; 790 s->sorted_elements[s->used_element_count].value = mval;
794 s->sorted_elements[s->used_element_count].key = &e->key; 791 s->sorted_elements[s->used_element_count].key = &e->key;
795 s->used_element_count++; 792 s->used_element_count++;
@@ -805,12 +802,12 @@ copy_element_cb (void *cls, const struct GNUNET_HashCode *key, void *value)
805 * @return -1 for a < b, 0 for a=b, 1 for a > b. 802 * @return -1 for a < b, 0 for a=b, 1 for a > b.
806 */ 803 */
807static int 804static int
808element_cmp (const void *a, const void *b) 805element_cmp(const void *a, const void *b)
809{ 806{
810 const struct MpiElement *ma = a; 807 const struct MpiElement *ma = a;
811 const struct MpiElement *mb = b; 808 const struct MpiElement *mb = b;
812 809
813 return GNUNET_CRYPTO_hash_cmp (ma->key, mb->key); 810 return GNUNET_CRYPTO_hash_cmp(ma->key, mb->key);
814} 811}
815 812
816 813
@@ -820,8 +817,8 @@ element_cmp (const void *a, const void *b)
820 */ 817 */
821#define ELEMENT_CAPACITY \ 818#define ELEMENT_CAPACITY \
822 ((GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE - 1 - \ 819 ((GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE - 1 - \
823 sizeof (struct AliceCryptodataMessage)) / \ 820 sizeof(struct AliceCryptodataMessage)) / \
824 sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)) 821 sizeof(struct GNUNET_CRYPTO_PaillierCiphertext))
825 822
826 823
827/** 824/**
@@ -831,7 +828,7 @@ element_cmp (const void *a, const void *b)
831 * @param s the associated service session 828 * @param s the associated service session
832 */ 829 */
833static void 830static void
834send_alices_cryptodata_message (struct AliceServiceSession *s) 831send_alices_cryptodata_message(struct AliceServiceSession *s)
835{ 832{
836 struct AliceCryptodataMessage *msg; 833 struct AliceCryptodataMessage *msg;
837 struct GNUNET_MQ_Envelope *e; 834 struct GNUNET_MQ_Envelope *e;
@@ -841,50 +838,50 @@ send_alices_cryptodata_message (struct AliceServiceSession *s)
841 gcry_mpi_t a; 838 gcry_mpi_t a;
842 uint32_t off; 839 uint32_t off;
843 840
844 s->sorted_elements = GNUNET_malloc ( 841 s->sorted_elements = GNUNET_malloc(
845 GNUNET_CONTAINER_multihashmap_size (s->intersected_elements) * 842 GNUNET_CONTAINER_multihashmap_size(s->intersected_elements) *
846 sizeof (struct MpiElement)); 843 sizeof(struct MpiElement));
847 s->used_element_count = 0; 844 s->used_element_count = 0;
848 GNUNET_CONTAINER_multihashmap_iterate (s->intersected_elements, 845 GNUNET_CONTAINER_multihashmap_iterate(s->intersected_elements,
849 &copy_element_cb, 846 &copy_element_cb,
850 s); 847 s);
851 LOG (GNUNET_ERROR_TYPE_DEBUG, 848 LOG(GNUNET_ERROR_TYPE_DEBUG,
852 "Finished intersection, %d items remain\n", 849 "Finished intersection, %d items remain\n",
853 s->used_element_count); 850 s->used_element_count);
854 qsort (s->sorted_elements, 851 qsort(s->sorted_elements,
855 s->used_element_count, 852 s->used_element_count,
856 sizeof (struct MpiElement), 853 sizeof(struct MpiElement),
857 &element_cmp); 854 &element_cmp);
858 off = 0; 855 off = 0;
859 while (off < s->used_element_count) 856 while (off < s->used_element_count)
860 {
861 todo_count = s->used_element_count - off;
862 if (todo_count > ELEMENT_CAPACITY)
863 todo_count = ELEMENT_CAPACITY;
864 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
865 "Sending %u/%u crypto values to Bob\n",
866 (unsigned int) todo_count,
867 (unsigned int) s->used_element_count);
868
869 e =
870 GNUNET_MQ_msg_extra (msg,
871 todo_count *
872 sizeof (struct GNUNET_CRYPTO_PaillierCiphertext),
873 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ALICE_CRYPTODATA);
874 msg->contained_element_count = htonl (todo_count);
875 payload = (struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1];
876 a = gcry_mpi_new (0);
877 for (i = off; i < off + todo_count; i++)
878 { 857 {
879 gcry_mpi_add (a, s->sorted_elements[i].value, my_offset); 858 todo_count = s->used_element_count - off;
880 GNUNET_assert ( 859 if (todo_count > ELEMENT_CAPACITY)
881 3 == 860 todo_count = ELEMENT_CAPACITY;
882 GNUNET_CRYPTO_paillier_encrypt (&my_pubkey, a, 3, &payload[i - off])); 861 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
862 "Sending %u/%u crypto values to Bob\n",
863 (unsigned int)todo_count,
864 (unsigned int)s->used_element_count);
865
866 e =
867 GNUNET_MQ_msg_extra(msg,
868 todo_count *
869 sizeof(struct GNUNET_CRYPTO_PaillierCiphertext),
870 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ALICE_CRYPTODATA);
871 msg->contained_element_count = htonl(todo_count);
872 payload = (struct GNUNET_CRYPTO_PaillierCiphertext *)&msg[1];
873 a = gcry_mpi_new(0);
874 for (i = off; i < off + todo_count; i++)
875 {
876 gcry_mpi_add(a, s->sorted_elements[i].value, my_offset);
877 GNUNET_assert(
878 3 ==
879 GNUNET_CRYPTO_paillier_encrypt(&my_pubkey, a, 3, &payload[i - off]));
880 }
881 gcry_mpi_release(a);
882 off += todo_count;
883 GNUNET_MQ_send(s->cadet_mq, e);
883 } 884 }
884 gcry_mpi_release (a);
885 off += todo_count;
886 GNUNET_MQ_send (s->cadet_mq, e);
887 }
888} 885}
889 886
890 887
@@ -899,66 +896,70 @@ send_alices_cryptodata_message (struct AliceServiceSession *s)
899 * @param status what has happened with the set intersection? 896 * @param status what has happened with the set intersection?
900 */ 897 */
901static void 898static void
902cb_intersection_element_removed (void *cls, 899cb_intersection_element_removed(void *cls,
903 const struct GNUNET_SET_Element *element, 900 const struct GNUNET_SET_Element *element,
904 uint64_t current_size, 901 uint64_t current_size,
905 enum GNUNET_SET_Status status) 902 enum GNUNET_SET_Status status)
906{ 903{
907 struct AliceServiceSession *s = cls; 904 struct AliceServiceSession *s = cls;
908 struct GNUNET_SCALARPRODUCT_Element *se; 905 struct GNUNET_SCALARPRODUCT_Element *se;
909 906
910 switch (status) 907 switch (status)
911 {
912 case GNUNET_SET_STATUS_OK:
913 /* this element has been removed from the set */
914 se = GNUNET_CONTAINER_multihashmap_get (s->intersected_elements,
915 element->data);
916 GNUNET_assert (NULL != se);
917 LOG (GNUNET_ERROR_TYPE_DEBUG,
918 "Intersection removed element with key %s and value %lld\n",
919 GNUNET_h2s (&se->key),
920 (long long) GNUNET_ntohll (se->value));
921 GNUNET_assert (
922 GNUNET_YES ==
923 GNUNET_CONTAINER_multihashmap_remove (s->intersected_elements,
924 element->data,
925 se));
926 GNUNET_free (se);
927 return;
928 case GNUNET_SET_STATUS_DONE:
929 s->intersection_op = NULL;
930 if (NULL != s->intersection_set)
931 { 908 {
932 GNUNET_SET_destroy (s->intersection_set); 909 case GNUNET_SET_STATUS_OK:
933 s->intersection_set = NULL; 910 /* this element has been removed from the set */
911 se = GNUNET_CONTAINER_multihashmap_get(s->intersected_elements,
912 element->data);
913 GNUNET_assert(NULL != se);
914 LOG(GNUNET_ERROR_TYPE_DEBUG,
915 "Intersection removed element with key %s and value %lld\n",
916 GNUNET_h2s(&se->key),
917 (long long)GNUNET_ntohll(se->value));
918 GNUNET_assert(
919 GNUNET_YES ==
920 GNUNET_CONTAINER_multihashmap_remove(s->intersected_elements,
921 element->data,
922 se));
923 GNUNET_free(se);
924 return;
925
926 case GNUNET_SET_STATUS_DONE:
927 s->intersection_op = NULL;
928 if (NULL != s->intersection_set)
929 {
930 GNUNET_SET_destroy(s->intersection_set);
931 s->intersection_set = NULL;
932 }
933 send_alices_cryptodata_message(s);
934 return;
935
936 case GNUNET_SET_STATUS_HALF_DONE:
937 /* unexpected for intersection */
938 GNUNET_break(0);
939 return;
940
941 case GNUNET_SET_STATUS_FAILURE:
942 /* unhandled status code */
943 LOG(GNUNET_ERROR_TYPE_DEBUG, "Set intersection failed!\n");
944 if (NULL != s->intersection_listen)
945 {
946 GNUNET_SET_listen_cancel(s->intersection_listen);
947 s->intersection_listen = NULL;
948 }
949 s->intersection_op = NULL;
950 if (NULL != s->intersection_set)
951 {
952 GNUNET_SET_destroy(s->intersection_set);
953 s->intersection_set = NULL;
954 }
955 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE;
956 prepare_client_end_notification(s);
957 return;
958
959 default:
960 GNUNET_break(0);
961 return;
934 } 962 }
935 send_alices_cryptodata_message (s);
936 return;
937 case GNUNET_SET_STATUS_HALF_DONE:
938 /* unexpected for intersection */
939 GNUNET_break (0);
940 return;
941 case GNUNET_SET_STATUS_FAILURE:
942 /* unhandled status code */
943 LOG (GNUNET_ERROR_TYPE_DEBUG, "Set intersection failed!\n");
944 if (NULL != s->intersection_listen)
945 {
946 GNUNET_SET_listen_cancel (s->intersection_listen);
947 s->intersection_listen = NULL;
948 }
949 s->intersection_op = NULL;
950 if (NULL != s->intersection_set)
951 {
952 GNUNET_SET_destroy (s->intersection_set);
953 s->intersection_set = NULL;
954 }
955 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE;
956 prepare_client_end_notification (s);
957 return;
958 default:
959 GNUNET_break (0);
960 return;
961 }
962} 963}
963 964
964 965
@@ -978,37 +979,37 @@ cb_intersection_element_removed (void *cls,
978 * message. It's necessary to specify the timeout. 979 * message. It's necessary to specify the timeout.
979 */ 980 */
980static void 981static void
981cb_intersection_request_alice (void *cls, 982cb_intersection_request_alice(void *cls,
982 const struct GNUNET_PeerIdentity *other_peer, 983 const struct GNUNET_PeerIdentity *other_peer,
983 const struct GNUNET_MessageHeader *context_msg, 984 const struct GNUNET_MessageHeader *context_msg,
984 struct GNUNET_SET_Request *request) 985 struct GNUNET_SET_Request *request)
985{ 986{
986 struct AliceServiceSession *s = cls; 987 struct AliceServiceSession *s = cls;
987 988
988 if (0 != GNUNET_memcmp (other_peer, &s->peer)) 989 if (0 != GNUNET_memcmp(other_peer, &s->peer))
989 { 990 {
990 GNUNET_break_op (0); 991 GNUNET_break_op(0);
991 return; 992 return;
992 } 993 }
993 s->intersection_op = GNUNET_SET_accept (request, 994 s->intersection_op = GNUNET_SET_accept(request,
994 GNUNET_SET_RESULT_REMOVED, 995 GNUNET_SET_RESULT_REMOVED,
995 (struct GNUNET_SET_Option[]){{0}}, 996 (struct GNUNET_SET_Option[]){ { 0 } },
996 &cb_intersection_element_removed, 997 &cb_intersection_element_removed,
997 s); 998 s);
998 if (NULL == s->intersection_op) 999 if (NULL == s->intersection_op)
999 { 1000 {
1000 GNUNET_break (0); 1001 GNUNET_break(0);
1001 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; 1002 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE;
1002 prepare_client_end_notification (s); 1003 prepare_client_end_notification(s);
1003 return; 1004 return;
1004 } 1005 }
1005 if (GNUNET_OK != GNUNET_SET_commit (s->intersection_op, s->intersection_set)) 1006 if (GNUNET_OK != GNUNET_SET_commit(s->intersection_op, s->intersection_set))
1006 { 1007 {
1007 GNUNET_break (0); 1008 GNUNET_break(0);
1008 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; 1009 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE;
1009 prepare_client_end_notification (s); 1010 prepare_client_end_notification(s);
1010 return; 1011 return;
1011 } 1012 }
1012} 1013}
1013 1014
1014 1015
@@ -1018,58 +1019,58 @@ cb_intersection_request_alice (void *cls,
1018 * @param session the service session context 1019 * @param session the service session context
1019 */ 1020 */
1020static void 1021static void
1021client_request_complete_alice (struct AliceServiceSession *s) 1022client_request_complete_alice(struct AliceServiceSession *s)
1022{ 1023{
1023 struct GNUNET_MQ_MessageHandler cadet_handlers[] = 1024 struct GNUNET_MQ_MessageHandler cadet_handlers[] =
1024 {GNUNET_MQ_hd_var_size (bobs_cryptodata_message, 1025 { GNUNET_MQ_hd_var_size(bobs_cryptodata_message,
1025 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_CRYPTODATA, 1026 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_CRYPTODATA,
1026 struct BobCryptodataMessage, 1027 struct BobCryptodataMessage,
1027 s), 1028 s),
1028 GNUNET_MQ_hd_var_size ( 1029 GNUNET_MQ_hd_var_size(
1029 bobs_cryptodata_multipart, 1030 bobs_cryptodata_multipart,
1030 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_CRYPTODATA_MULTIPART, 1031 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_CRYPTODATA_MULTIPART,
1031 struct BobCryptodataMultipartMessage, 1032 struct BobCryptodataMultipartMessage,
1032 s), 1033 s),
1033 GNUNET_MQ_handler_end ()}; 1034 GNUNET_MQ_handler_end() };
1034 struct ServiceRequestMessage *msg; 1035 struct ServiceRequestMessage *msg;
1035 struct GNUNET_MQ_Envelope *e; 1036 struct GNUNET_MQ_Envelope *e;
1036 1037
1037 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1038 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1038 "Creating new channel for session with key %s.\n", 1039 "Creating new channel for session with key %s.\n",
1039 GNUNET_h2s (&s->session_id)); 1040 GNUNET_h2s(&s->session_id));
1040 s->channel = GNUNET_CADET_channel_create (my_cadet, 1041 s->channel = GNUNET_CADET_channel_create(my_cadet,
1041 s, 1042 s,
1042 &s->peer, 1043 &s->peer,
1043 &s->session_id, 1044 &s->session_id,
1044 NULL, 1045 NULL,
1045 &cb_channel_destruction, 1046 &cb_channel_destruction,
1046 cadet_handlers); 1047 cadet_handlers);
1047 if (NULL == s->channel) 1048 if (NULL == s->channel)
1048 { 1049 {
1049 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; 1050 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE;
1050 prepare_client_end_notification (s); 1051 prepare_client_end_notification(s);
1051 return; 1052 return;
1052 } 1053 }
1053 s->cadet_mq = GNUNET_CADET_get_mq (s->channel); 1054 s->cadet_mq = GNUNET_CADET_get_mq(s->channel);
1054 s->intersection_listen = GNUNET_SET_listen (cfg, 1055 s->intersection_listen = GNUNET_SET_listen(cfg,
1055 GNUNET_SET_OPERATION_INTERSECTION, 1056 GNUNET_SET_OPERATION_INTERSECTION,
1056 &s->session_id, 1057 &s->session_id,
1057 &cb_intersection_request_alice, 1058 &cb_intersection_request_alice,
1058 s); 1059 s);
1059 if (NULL == s->intersection_listen) 1060 if (NULL == s->intersection_listen)
1060 { 1061 {
1061 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; 1062 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE;
1062 GNUNET_CADET_channel_destroy (s->channel); 1063 GNUNET_CADET_channel_destroy(s->channel);
1063 s->channel = NULL; 1064 s->channel = NULL;
1064 prepare_client_end_notification (s); 1065 prepare_client_end_notification(s);
1065 return; 1066 return;
1066 } 1067 }
1067 1068
1068 e = GNUNET_MQ_msg (msg, 1069 e = GNUNET_MQ_msg(msg,
1069 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_SESSION_INITIALIZATION); 1070 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_SESSION_INITIALIZATION);
1070 msg->session_id = s->session_id; 1071 msg->session_id = s->session_id;
1071 msg->public_key = my_pubkey; 1072 msg->public_key = my_pubkey;
1072 GNUNET_MQ_send (s->cadet_mq, e); 1073 GNUNET_MQ_send(s->cadet_mq, e);
1073} 1074}
1074 1075
1075 1076
@@ -1082,7 +1083,7 @@ client_request_complete_alice (struct AliceServiceSession *s)
1082 * @return #GNUNET_OK if @a msg is well-formed 1083 * @return #GNUNET_OK if @a msg is well-formed
1083 */ 1084 */
1084static int 1085static int
1085check_alice_client_message_multipart ( 1086check_alice_client_message_multipart(
1086 void *cls, 1087 void *cls,
1087 const struct ComputationBobCryptodataMultipartMessage *msg) 1088 const struct ComputationBobCryptodataMultipartMessage *msg)
1088{ 1089{
@@ -1090,18 +1091,18 @@ check_alice_client_message_multipart (
1090 uint32_t contained_count; 1091 uint32_t contained_count;
1091 uint16_t msize; 1092 uint16_t msize;
1092 1093
1093 msize = ntohs (msg->header.size); 1094 msize = ntohs(msg->header.size);
1094 contained_count = ntohl (msg->element_count_contained); 1095 contained_count = ntohl(msg->element_count_contained);
1095 if ((msize != 1096 if ((msize !=
1096 (sizeof (struct ComputationBobCryptodataMultipartMessage) + 1097 (sizeof(struct ComputationBobCryptodataMultipartMessage) +
1097 contained_count * sizeof (struct GNUNET_SCALARPRODUCT_Element))) || 1098 contained_count * sizeof(struct GNUNET_SCALARPRODUCT_Element))) ||
1098 (0 == contained_count) || 1099 (0 == contained_count) ||
1099 (s->total == s->client_received_element_count) || 1100 (s->total == s->client_received_element_count) ||
1100 (s->total < s->client_received_element_count + contained_count)) 1101 (s->total < s->client_received_element_count + contained_count))
1101 { 1102 {
1102 GNUNET_break_op (0); 1103 GNUNET_break_op(0);
1103 return GNUNET_SYSERR; 1104 return GNUNET_SYSERR;
1104 } 1105 }
1105 return GNUNET_OK; 1106 return GNUNET_OK;
1106} 1107}
1107 1108
@@ -1114,7 +1115,7 @@ check_alice_client_message_multipart (
1114 * @param msg the actual message 1115 * @param msg the actual message
1115 */ 1116 */
1116static void 1117static void
1117handle_alice_client_message_multipart ( 1118handle_alice_client_message_multipart(
1118 void *cls, 1119 void *cls,
1119 const struct ComputationBobCryptodataMultipartMessage *msg) 1120 const struct ComputationBobCryptodataMultipartMessage *msg)
1120{ 1121{
@@ -1124,38 +1125,38 @@ handle_alice_client_message_multipart (
1124 struct GNUNET_SET_Element set_elem; 1125 struct GNUNET_SET_Element set_elem;
1125 struct GNUNET_SCALARPRODUCT_Element *elem; 1126 struct GNUNET_SCALARPRODUCT_Element *elem;
1126 1127
1127 contained_count = ntohl (msg->element_count_contained); 1128 contained_count = ntohl(msg->element_count_contained);
1128 s->client_received_element_count += contained_count; 1129 s->client_received_element_count += contained_count;
1129 elements = (const struct GNUNET_SCALARPRODUCT_Element *) &msg[1]; 1130 elements = (const struct GNUNET_SCALARPRODUCT_Element *)&msg[1];
1130 for (uint32_t i = 0; i < contained_count; i++) 1131 for (uint32_t i = 0; i < contained_count; i++)
1131 {
1132 elem = GNUNET_new (struct GNUNET_SCALARPRODUCT_Element);
1133 GNUNET_memcpy (elem,
1134 &elements[i],
1135 sizeof (struct GNUNET_SCALARPRODUCT_Element));
1136 if (GNUNET_SYSERR == GNUNET_CONTAINER_multihashmap_put (
1137 s->intersected_elements,
1138 &elem->key,
1139 elem,
1140 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
1141 { 1132 {
1142 GNUNET_break (0); 1133 elem = GNUNET_new(struct GNUNET_SCALARPRODUCT_Element);
1143 GNUNET_free (elem); 1134 GNUNET_memcpy(elem,
1144 continue; 1135 &elements[i],
1136 sizeof(struct GNUNET_SCALARPRODUCT_Element));
1137 if (GNUNET_SYSERR == GNUNET_CONTAINER_multihashmap_put(
1138 s->intersected_elements,
1139 &elem->key,
1140 elem,
1141 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
1142 {
1143 GNUNET_break(0);
1144 GNUNET_free(elem);
1145 continue;
1146 }
1147 set_elem.data = &elem->key;
1148 set_elem.size = sizeof(elem->key);
1149 set_elem.element_type = 0;
1150 GNUNET_SET_add_element(s->intersection_set, &set_elem, NULL, NULL);
1151 s->used_element_count++;
1145 } 1152 }
1146 set_elem.data = &elem->key; 1153 GNUNET_SERVICE_client_continue(s->client);
1147 set_elem.size = sizeof (elem->key);
1148 set_elem.element_type = 0;
1149 GNUNET_SET_add_element (s->intersection_set, &set_elem, NULL, NULL);
1150 s->used_element_count++;
1151 }
1152 GNUNET_SERVICE_client_continue (s->client);
1153 if (s->total != s->client_received_element_count) 1154 if (s->total != s->client_received_element_count)
1154 { 1155 {
1155 /* more to come */ 1156 /* more to come */
1156 return; 1157 return;
1157 } 1158 }
1158 client_request_complete_alice (s); 1159 client_request_complete_alice(s);
1159} 1160}
1160 1161
1161 1162
@@ -1168,8 +1169,8 @@ handle_alice_client_message_multipart (
1168 * @return #GNUNET_OK if @a msg is well-formed 1169 * @return #GNUNET_OK if @a msg is well-formed
1169 */ 1170 */
1170static int 1171static int
1171check_alice_client_message (void *cls, 1172check_alice_client_message(void *cls,
1172 const struct AliceComputationMessage *msg) 1173 const struct AliceComputationMessage *msg)
1173{ 1174{
1174 struct AliceServiceSession *s = cls; 1175 struct AliceServiceSession *s = cls;
1175 uint16_t msize; 1176 uint16_t msize;
@@ -1177,23 +1178,23 @@ check_alice_client_message (void *cls,
1177 uint32_t contained_count; 1178 uint32_t contained_count;
1178 1179
1179 if (NULL != s->intersected_elements) 1180 if (NULL != s->intersected_elements)
1180 { 1181 {
1181 /* only one concurrent session per client connection allowed, 1182 /* only one concurrent session per client connection allowed,
1182 simplifies logic a lot... */ 1183 simplifies logic a lot... */
1183 GNUNET_break (0); 1184 GNUNET_break(0);
1184 return GNUNET_SYSERR; 1185 return GNUNET_SYSERR;
1185 } 1186 }
1186 msize = ntohs (msg->header.size); 1187 msize = ntohs(msg->header.size);
1187 total_count = ntohl (msg->element_count_total); 1188 total_count = ntohl(msg->element_count_total);
1188 contained_count = ntohl (msg->element_count_contained); 1189 contained_count = ntohl(msg->element_count_contained);
1189 if ((0 == total_count) || (0 == contained_count) || 1190 if ((0 == total_count) || (0 == contained_count) ||
1190 (msize != 1191 (msize !=
1191 (sizeof (struct AliceComputationMessage) + 1192 (sizeof(struct AliceComputationMessage) +
1192 contained_count * sizeof (struct GNUNET_SCALARPRODUCT_Element)))) 1193 contained_count * sizeof(struct GNUNET_SCALARPRODUCT_Element))))
1193 { 1194 {
1194 GNUNET_break_op (0); 1195 GNUNET_break_op(0);
1195 return GNUNET_SYSERR; 1196 return GNUNET_SYSERR;
1196 } 1197 }
1197 return GNUNET_OK; 1198 return GNUNET_OK;
1198} 1199}
1199 1200
@@ -1206,8 +1207,8 @@ check_alice_client_message (void *cls,
1206 * @param msg the actual message 1207 * @param msg the actual message
1207 */ 1208 */
1208static void 1209static void
1209handle_alice_client_message (void *cls, 1210handle_alice_client_message(void *cls,
1210 const struct AliceComputationMessage *msg) 1211 const struct AliceComputationMessage *msg)
1211{ 1212{
1212 struct AliceServiceSession *s = cls; 1213 struct AliceServiceSession *s = cls;
1213 uint32_t contained_count; 1214 uint32_t contained_count;
@@ -1216,51 +1217,51 @@ handle_alice_client_message (void *cls,
1216 struct GNUNET_SET_Element set_elem; 1217 struct GNUNET_SET_Element set_elem;
1217 struct GNUNET_SCALARPRODUCT_Element *elem; 1218 struct GNUNET_SCALARPRODUCT_Element *elem;
1218 1219
1219 total_count = ntohl (msg->element_count_total); 1220 total_count = ntohl(msg->element_count_total);
1220 contained_count = ntohl (msg->element_count_contained); 1221 contained_count = ntohl(msg->element_count_contained);
1221 s->peer = msg->peer; 1222 s->peer = msg->peer;
1222 s->status = GNUNET_SCALARPRODUCT_STATUS_ACTIVE; 1223 s->status = GNUNET_SCALARPRODUCT_STATUS_ACTIVE;
1223 s->total = total_count; 1224 s->total = total_count;
1224 s->client_received_element_count = contained_count; 1225 s->client_received_element_count = contained_count;
1225 s->session_id = msg->session_key; 1226 s->session_id = msg->session_key;
1226 elements = (const struct GNUNET_SCALARPRODUCT_Element *) &msg[1]; 1227 elements = (const struct GNUNET_SCALARPRODUCT_Element *)&msg[1];
1227 s->intersected_elements = 1228 s->intersected_elements =
1228 GNUNET_CONTAINER_multihashmap_create (s->total, GNUNET_YES); 1229 GNUNET_CONTAINER_multihashmap_create(s->total, GNUNET_YES);
1229 s->intersection_set = 1230 s->intersection_set =
1230 GNUNET_SET_create (cfg, GNUNET_SET_OPERATION_INTERSECTION); 1231 GNUNET_SET_create(cfg, GNUNET_SET_OPERATION_INTERSECTION);
1231 1232
1232 for (uint32_t i = 0; i < contained_count; i++) 1233 for (uint32_t i = 0; i < contained_count; i++)
1233 {
1234 if (0 == GNUNET_ntohll (elements[i].value))
1235 continue;
1236 elem = GNUNET_new (struct GNUNET_SCALARPRODUCT_Element);
1237 GNUNET_memcpy (elem,
1238 &elements[i],
1239 sizeof (struct GNUNET_SCALARPRODUCT_Element));
1240 if (GNUNET_SYSERR == GNUNET_CONTAINER_multihashmap_put (
1241 s->intersected_elements,
1242 &elem->key,
1243 elem,
1244 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
1245 { 1234 {
1246 /* element with same key encountered twice! */ 1235 if (0 == GNUNET_ntohll(elements[i].value))
1247 GNUNET_break (0); 1236 continue;
1248 GNUNET_free (elem); 1237 elem = GNUNET_new(struct GNUNET_SCALARPRODUCT_Element);
1249 continue; 1238 GNUNET_memcpy(elem,
1239 &elements[i],
1240 sizeof(struct GNUNET_SCALARPRODUCT_Element));
1241 if (GNUNET_SYSERR == GNUNET_CONTAINER_multihashmap_put(
1242 s->intersected_elements,
1243 &elem->key,
1244 elem,
1245 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
1246 {
1247 /* element with same key encountered twice! */
1248 GNUNET_break(0);
1249 GNUNET_free(elem);
1250 continue;
1251 }
1252 set_elem.data = &elem->key;
1253 set_elem.size = sizeof(elem->key);
1254 set_elem.element_type = 0;
1255 GNUNET_SET_add_element(s->intersection_set, &set_elem, NULL, NULL);
1256 s->used_element_count++;
1250 } 1257 }
1251 set_elem.data = &elem->key; 1258 GNUNET_SERVICE_client_continue(s->client);
1252 set_elem.size = sizeof (elem->key);
1253 set_elem.element_type = 0;
1254 GNUNET_SET_add_element (s->intersection_set, &set_elem, NULL, NULL);
1255 s->used_element_count++;
1256 }
1257 GNUNET_SERVICE_client_continue (s->client);
1258 if (s->total != s->client_received_element_count) 1259 if (s->total != s->client_received_element_count)
1259 { 1260 {
1260 /* wait for multipart msg */ 1261 /* wait for multipart msg */
1261 return; 1262 return;
1262 } 1263 }
1263 client_request_complete_alice (s); 1264 client_request_complete_alice(s);
1264} 1265}
1265 1266
1266 1267
@@ -1270,15 +1271,15 @@ handle_alice_client_message (void *cls,
1270 * @param cls unused 1271 * @param cls unused
1271 */ 1272 */
1272static void 1273static void
1273shutdown_task (void *cls) 1274shutdown_task(void *cls)
1274{ 1275{
1275 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down, initiating cleanup.\n"); 1276 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Shutting down, initiating cleanup.\n");
1276 // FIXME: we have to cut our connections to CADET first! 1277 // FIXME: we have to cut our connections to CADET first!
1277 if (NULL != my_cadet) 1278 if (NULL != my_cadet)
1278 { 1279 {
1279 GNUNET_CADET_disconnect (my_cadet); 1280 GNUNET_CADET_disconnect(my_cadet);
1280 my_cadet = NULL; 1281 my_cadet = NULL;
1281 } 1282 }
1282} 1283}
1283 1284
1284 1285
@@ -1293,13 +1294,13 @@ shutdown_task (void *cls)
1293 * @return our `struct AliceServiceSession` 1294 * @return our `struct AliceServiceSession`
1294 */ 1295 */
1295static void * 1296static void *
1296client_connect_cb (void *cls, 1297client_connect_cb(void *cls,
1297 struct GNUNET_SERVICE_Client *client, 1298 struct GNUNET_SERVICE_Client *client,
1298 struct GNUNET_MQ_Handle *mq) 1299 struct GNUNET_MQ_Handle *mq)
1299{ 1300{
1300 struct AliceServiceSession *s; 1301 struct AliceServiceSession *s;
1301 1302
1302 s = GNUNET_new (struct AliceServiceSession); 1303 s = GNUNET_new(struct AliceServiceSession);
1303 s->client = client; 1304 s->client = client;
1304 s->client_mq = mq; 1305 s->client_mq = mq;
1305 return s; 1306 return s;
@@ -1317,18 +1318,18 @@ client_connect_cb (void *cls,
1317 * @param app_cls our `struct AliceServiceSession` 1318 * @param app_cls our `struct AliceServiceSession`
1318 */ 1319 */
1319static void 1320static void
1320client_disconnect_cb (void *cls, 1321client_disconnect_cb(void *cls,
1321 struct GNUNET_SERVICE_Client *client, 1322 struct GNUNET_SERVICE_Client *client,
1322 void *app_cls) 1323 void *app_cls)
1323{ 1324{
1324 struct AliceServiceSession *s = app_cls; 1325 struct AliceServiceSession *s = app_cls;
1325 1326
1326 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1327 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1327 "Client %p disconnected from us.\n", 1328 "Client %p disconnected from us.\n",
1328 client); 1329 client);
1329 s->client = NULL; 1330 s->client = NULL;
1330 s->client_mq = NULL; 1331 s->client_mq = NULL;
1331 destroy_service_session (s); 1332 destroy_service_session(s);
1332} 1333}
1333 1334
1334 1335
@@ -1340,49 +1341,49 @@ client_disconnect_cb (void *cls,
1340 * @param service the initialized service 1341 * @param service the initialized service
1341 */ 1342 */
1342static void 1343static void
1343run (void *cls, 1344run(void *cls,
1344 const struct GNUNET_CONFIGURATION_Handle *c, 1345 const struct GNUNET_CONFIGURATION_Handle *c,
1345 struct GNUNET_SERVICE_Handle *service) 1346 struct GNUNET_SERVICE_Handle *service)
1346{ 1347{
1347 cfg = c; 1348 cfg = c;
1348 /* 1349 /*
1349 offset has to be sufficiently small to allow computation of: 1350 offset has to be sufficiently small to allow computation of:
1350 m1+m2 mod n == (S + a) + (S + b) mod n, 1351 m1+m2 mod n == (S + a) + (S + b) mod n,
1351 if we have more complex operations, this factor needs to be lowered */ 1352 if we have more complex operations, this factor needs to be lowered */
1352 my_offset = gcry_mpi_new (GNUNET_CRYPTO_PAILLIER_BITS / 3); 1353 my_offset = gcry_mpi_new(GNUNET_CRYPTO_PAILLIER_BITS / 3);
1353 gcry_mpi_set_bit (my_offset, GNUNET_CRYPTO_PAILLIER_BITS / 3); 1354 gcry_mpi_set_bit(my_offset, GNUNET_CRYPTO_PAILLIER_BITS / 3);
1354 GNUNET_CRYPTO_paillier_create (&my_pubkey, &my_privkey); 1355 GNUNET_CRYPTO_paillier_create(&my_pubkey, &my_privkey);
1355 my_cadet = GNUNET_CADET_connect (cfg); 1356 my_cadet = GNUNET_CADET_connect(cfg);
1356 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); 1357 GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL);
1357 if (NULL == my_cadet) 1358 if (NULL == my_cadet)
1358 { 1359 {
1359 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ ("Connect to CADET failed\n")); 1360 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, _("Connect to CADET failed\n"));
1360 GNUNET_SCHEDULER_shutdown (); 1361 GNUNET_SCHEDULER_shutdown();
1361 return; 1362 return;
1362 } 1363 }
1363} 1364}
1364 1365
1365 1366
1366/** 1367/**
1367 * Define "main" method using service macro. 1368 * Define "main" method using service macro.
1368 */ 1369 */
1369GNUNET_SERVICE_MAIN ( 1370GNUNET_SERVICE_MAIN(
1370 "scalarproduct-alice", 1371 "scalarproduct-alice",
1371 GNUNET_SERVICE_OPTION_NONE, 1372 GNUNET_SERVICE_OPTION_NONE,
1372 &run, 1373 &run,
1373 &client_connect_cb, 1374 &client_connect_cb,
1374 &client_disconnect_cb, 1375 &client_disconnect_cb,
1375 NULL, 1376 NULL,
1376 GNUNET_MQ_hd_var_size (alice_client_message, 1377 GNUNET_MQ_hd_var_size(alice_client_message,
1377 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_ALICE, 1378 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_ALICE,
1378 struct AliceComputationMessage, 1379 struct AliceComputationMessage,
1379 NULL), 1380 NULL),
1380 GNUNET_MQ_hd_var_size ( 1381 GNUNET_MQ_hd_var_size(
1381 alice_client_message_multipart, 1382 alice_client_message_multipart,
1382 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MULTIPART_ALICE, 1383 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MULTIPART_ALICE,
1383 struct ComputationBobCryptodataMultipartMessage, 1384 struct ComputationBobCryptodataMultipartMessage,
1384 NULL), 1385 NULL),
1385 GNUNET_MQ_handler_end ()); 1386 GNUNET_MQ_handler_end());
1386 1387
1387 1388
1388/* end of gnunet-service-scalarproduct_alice.c */ 1389/* end of gnunet-service-scalarproduct_alice.c */