diff options
Diffstat (limited to 'src/scalarproduct/gnunet-service-scalarproduct-ecc_bob.c')
-rw-r--r-- | src/scalarproduct/gnunet-service-scalarproduct-ecc_bob.c | 902 |
1 files changed, 456 insertions, 446 deletions
diff --git a/src/scalarproduct/gnunet-service-scalarproduct-ecc_bob.c b/src/scalarproduct/gnunet-service-scalarproduct-ecc_bob.c index fc2d1d8c5..2da79f845 100644 --- a/src/scalarproduct/gnunet-service-scalarproduct-ecc_bob.c +++ b/src/scalarproduct/gnunet-service-scalarproduct-ecc_bob.c | |||
@@ -36,13 +36,14 @@ | |||
36 | #include "scalarproduct.h" | 36 | #include "scalarproduct.h" |
37 | #include "gnunet-service-scalarproduct-ecc.h" | 37 | #include "gnunet-service-scalarproduct-ecc.h" |
38 | 38 | ||
39 | #define LOG(kind, ...) GNUNET_log_from(kind, "scalarproduct-bob", __VA_ARGS__) | 39 | #define LOG(kind, ...) GNUNET_log_from (kind, "scalarproduct-bob", __VA_ARGS__) |
40 | 40 | ||
41 | 41 | ||
42 | /** | 42 | /** |
43 | * An encrypted element key-value pair. | 43 | * An encrypted element key-value pair. |
44 | */ | 44 | */ |
45 | struct MpiElement { | 45 | struct MpiElement |
46 | { | ||
46 | /** | 47 | /** |
47 | * Key used to identify matching pairs of values to multiply. | 48 | * Key used to identify matching pairs of values to multiply. |
48 | * Points into an existing data structure, to avoid copying | 49 | * Points into an existing data structure, to avoid copying |
@@ -61,7 +62,8 @@ struct MpiElement { | |||
61 | * A scalarproduct session which tracks an offer for a | 62 | * A scalarproduct session which tracks an offer for a |
62 | * multiplication service by a local client. | 63 | * multiplication service by a local client. |
63 | */ | 64 | */ |
64 | struct BobServiceSession { | 65 | struct BobServiceSession |
66 | { | ||
65 | /** | 67 | /** |
66 | * The client this request is related to. | 68 | * The client this request is related to. |
67 | */ | 69 | */ |
@@ -192,13 +194,13 @@ static struct GNUNET_CRYPTO_EccDlogContext *edc; | |||
192 | * @param value the value to free | 194 | * @param value the value to free |
193 | */ | 195 | */ |
194 | static int | 196 | static int |
195 | free_element_cb(void *cls, | 197 | free_element_cb (void *cls, |
196 | const struct GNUNET_HashCode *key, | 198 | const struct GNUNET_HashCode *key, |
197 | void *value) | 199 | void *value) |
198 | { | 200 | { |
199 | struct GNUNET_SCALARPRODUCT_Element *element = value; | 201 | struct GNUNET_SCALARPRODUCT_Element *element = value; |
200 | 202 | ||
201 | GNUNET_free(element); | 203 | GNUNET_free (element); |
202 | return GNUNET_OK; | 204 | return GNUNET_OK; |
203 | } | 205 | } |
204 | 206 | ||
@@ -209,7 +211,7 @@ free_element_cb(void *cls, | |||
209 | * @param session the session to free elements from | 211 | * @param session the session to free elements from |
210 | */ | 212 | */ |
211 | static void | 213 | static void |
212 | destroy_service_session(struct BobServiceSession *s) | 214 | destroy_service_session (struct BobServiceSession *s) |
213 | { | 215 | { |
214 | unsigned int i; | 216 | unsigned int i; |
215 | 217 | ||
@@ -217,58 +219,58 @@ destroy_service_session(struct BobServiceSession *s) | |||
217 | return; | 219 | return; |
218 | s->in_destroy = GNUNET_YES; | 220 | s->in_destroy = GNUNET_YES; |
219 | if (NULL != s->client) | 221 | if (NULL != s->client) |
220 | { | 222 | { |
221 | struct GNUNET_SERVICE_Client *c = s->client; | 223 | struct GNUNET_SERVICE_Client *c = s->client; |
222 | 224 | ||
223 | s->client = NULL; | 225 | s->client = NULL; |
224 | GNUNET_SERVICE_client_drop(c); | 226 | GNUNET_SERVICE_client_drop (c); |
225 | } | 227 | } |
226 | if (NULL != s->intersected_elements) | 228 | if (NULL != s->intersected_elements) |
227 | { | 229 | { |
228 | GNUNET_CONTAINER_multihashmap_iterate(s->intersected_elements, | 230 | GNUNET_CONTAINER_multihashmap_iterate (s->intersected_elements, |
229 | &free_element_cb, | 231 | &free_element_cb, |
230 | NULL); | 232 | NULL); |
231 | GNUNET_CONTAINER_multihashmap_destroy(s->intersected_elements); | 233 | GNUNET_CONTAINER_multihashmap_destroy (s->intersected_elements); |
232 | s->intersected_elements = NULL; | 234 | s->intersected_elements = NULL; |
233 | } | 235 | } |
234 | if (NULL != s->intersection_op) | 236 | if (NULL != s->intersection_op) |
235 | { | 237 | { |
236 | GNUNET_SET_operation_cancel(s->intersection_op); | 238 | GNUNET_SET_operation_cancel (s->intersection_op); |
237 | s->intersection_op = NULL; | 239 | s->intersection_op = NULL; |
238 | } | 240 | } |
239 | if (NULL != s->intersection_set) | 241 | if (NULL != s->intersection_set) |
240 | { | 242 | { |
241 | GNUNET_SET_destroy(s->intersection_set); | 243 | GNUNET_SET_destroy (s->intersection_set); |
242 | s->intersection_set = NULL; | 244 | s->intersection_set = NULL; |
243 | } | 245 | } |
244 | if (NULL != s->sorted_elements) | 246 | if (NULL != s->sorted_elements) |
245 | { | 247 | { |
246 | for (i = 0; i < s->used_element_count; i++) | 248 | for (i = 0; i < s->used_element_count; i++) |
247 | gcry_mpi_release(s->sorted_elements[i].value); | 249 | gcry_mpi_release (s->sorted_elements[i].value); |
248 | GNUNET_free(s->sorted_elements); | 250 | GNUNET_free (s->sorted_elements); |
249 | s->sorted_elements = NULL; | 251 | s->sorted_elements = NULL; |
250 | } | 252 | } |
251 | if (NULL != s->prod_g_i_b_i) | 253 | if (NULL != s->prod_g_i_b_i) |
252 | { | 254 | { |
253 | gcry_mpi_point_release(s->prod_g_i_b_i); | 255 | gcry_mpi_point_release (s->prod_g_i_b_i); |
254 | s->prod_g_i_b_i = NULL; | 256 | s->prod_g_i_b_i = NULL; |
255 | } | 257 | } |
256 | if (NULL != s->prod_h_i_b_i) | 258 | if (NULL != s->prod_h_i_b_i) |
257 | { | 259 | { |
258 | gcry_mpi_point_release(s->prod_h_i_b_i); | 260 | gcry_mpi_point_release (s->prod_h_i_b_i); |
259 | s->prod_h_i_b_i = NULL; | 261 | s->prod_h_i_b_i = NULL; |
260 | } | 262 | } |
261 | if (NULL != s->port) | 263 | if (NULL != s->port) |
262 | { | 264 | { |
263 | GNUNET_CADET_close_port(s->port); | 265 | GNUNET_CADET_close_port (s->port); |
264 | s->port = NULL; | 266 | s->port = NULL; |
265 | } | 267 | } |
266 | if (NULL != s->channel) | 268 | if (NULL != s->channel) |
267 | { | 269 | { |
268 | GNUNET_CADET_channel_destroy(s->channel); | 270 | GNUNET_CADET_channel_destroy (s->channel); |
269 | s->channel = NULL; | 271 | s->channel = NULL; |
270 | } | 272 | } |
271 | GNUNET_free(s); | 273 | GNUNET_free (s); |
272 | } | 274 | } |
273 | 275 | ||
274 | 276 | ||
@@ -280,24 +282,24 @@ destroy_service_session(struct BobServiceSession *s) | |||
280 | * @param session the associated client session to fail or succeed | 282 | * @param session the associated client session to fail or succeed |
281 | */ | 283 | */ |
282 | static void | 284 | static void |
283 | prepare_client_end_notification(struct BobServiceSession *session) | 285 | prepare_client_end_notification (struct BobServiceSession *session) |
284 | { | 286 | { |
285 | struct ClientResponseMessage *msg; | 287 | struct ClientResponseMessage *msg; |
286 | struct GNUNET_MQ_Envelope *e; | 288 | struct GNUNET_MQ_Envelope *e; |
287 | 289 | ||
288 | if (NULL == session->client_mq) | 290 | if (NULL == session->client_mq) |
289 | return; /* no client left to be notified */ | 291 | return; /* no client left to be notified */ |
290 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 292 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
291 | "Sending session-end notification with status %d to client for session %s\n", | 293 | "Sending session-end notification with status %d to client for session %s\n", |
292 | session->status, | 294 | session->status, |
293 | GNUNET_h2s(&session->session_id)); | 295 | GNUNET_h2s (&session->session_id)); |
294 | e = GNUNET_MQ_msg(msg, | 296 | e = GNUNET_MQ_msg (msg, |
295 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_RESULT); | 297 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_RESULT); |
296 | msg->range = 0; | 298 | msg->range = 0; |
297 | msg->product_length = htonl(0); | 299 | msg->product_length = htonl (0); |
298 | msg->status = htonl(session->status); | 300 | msg->status = htonl (session->status); |
299 | GNUNET_MQ_send(session->client_mq, | 301 | GNUNET_MQ_send (session->client_mq, |
300 | e); | 302 | e); |
301 | } | 303 | } |
302 | 304 | ||
303 | 305 | ||
@@ -313,22 +315,22 @@ prepare_client_end_notification(struct BobServiceSession *session) | |||
313 | * with the channel is stored | 315 | * with the channel is stored |
314 | */ | 316 | */ |
315 | static void | 317 | static void |
316 | cb_channel_destruction(void *cls, | 318 | cb_channel_destruction (void *cls, |
317 | const struct GNUNET_CADET_Channel *channel) | 319 | const struct GNUNET_CADET_Channel *channel) |
318 | { | 320 | { |
319 | struct BobServiceSession *s = cls; | 321 | struct BobServiceSession *s = cls; |
320 | 322 | ||
321 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 323 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
322 | "Peer disconnected, terminating session %s with peer %s\n", | 324 | "Peer disconnected, terminating session %s with peer %s\n", |
323 | GNUNET_h2s(&s->session_id), | 325 | GNUNET_h2s (&s->session_id), |
324 | GNUNET_i2s(&s->peer)); | 326 | GNUNET_i2s (&s->peer)); |
325 | s->channel = NULL; | 327 | s->channel = NULL; |
326 | if (GNUNET_SCALARPRODUCT_STATUS_ACTIVE == s->status) | 328 | if (GNUNET_SCALARPRODUCT_STATUS_ACTIVE == s->status) |
327 | { | 329 | { |
328 | s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; | 330 | s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; |
329 | prepare_client_end_notification(s); | 331 | prepare_client_end_notification (s); |
330 | } | 332 | } |
331 | destroy_service_session(s); | 333 | destroy_service_session (s); |
332 | } | 334 | } |
333 | 335 | ||
334 | 336 | ||
@@ -337,12 +339,12 @@ cb_channel_destruction(void *cls, | |||
337 | * the client that we are finished. | 339 | * the client that we are finished. |
338 | */ | 340 | */ |
339 | static void | 341 | static void |
340 | bob_cadet_done_cb(void *cls) | 342 | bob_cadet_done_cb (void *cls) |
341 | { | 343 | { |
342 | struct BobServiceSession *session = cls; | 344 | struct BobServiceSession *session = cls; |
343 | 345 | ||
344 | session->status = GNUNET_SCALARPRODUCT_STATUS_SUCCESS; | 346 | session->status = GNUNET_SCALARPRODUCT_STATUS_SUCCESS; |
345 | prepare_client_end_notification(session); | 347 | prepare_client_end_notification (session); |
346 | } | 348 | } |
347 | 349 | ||
348 | 350 | ||
@@ -352,29 +354,29 @@ bob_cadet_done_cb(void *cls) | |||
352 | * @param s the associated requesting session with Alice | 354 | * @param s the associated requesting session with Alice |
353 | */ | 355 | */ |
354 | static void | 356 | static void |
355 | transmit_bobs_cryptodata_message(struct BobServiceSession *s) | 357 | transmit_bobs_cryptodata_message (struct BobServiceSession *s) |
356 | { | 358 | { |
357 | struct EccBobCryptodataMessage *msg; | 359 | struct EccBobCryptodataMessage *msg; |
358 | struct GNUNET_MQ_Envelope *e; | 360 | struct GNUNET_MQ_Envelope *e; |
359 | 361 | ||
360 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 362 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
361 | "Sending response to Alice\n"); | 363 | "Sending response to Alice\n"); |
362 | e = GNUNET_MQ_msg(msg, | 364 | e = GNUNET_MQ_msg (msg, |
363 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_BOB_CRYPTODATA); | 365 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_BOB_CRYPTODATA); |
364 | msg->contained_element_count = htonl(2); | 366 | msg->contained_element_count = htonl (2); |
365 | if (NULL != s->prod_g_i_b_i) | 367 | if (NULL != s->prod_g_i_b_i) |
366 | GNUNET_CRYPTO_ecc_point_to_bin(edc, | 368 | GNUNET_CRYPTO_ecc_point_to_bin (edc, |
367 | s->prod_g_i_b_i, | 369 | s->prod_g_i_b_i, |
368 | &msg->prod_g_i_b_i); | 370 | &msg->prod_g_i_b_i); |
369 | if (NULL != s->prod_h_i_b_i) | 371 | if (NULL != s->prod_h_i_b_i) |
370 | GNUNET_CRYPTO_ecc_point_to_bin(edc, | 372 | GNUNET_CRYPTO_ecc_point_to_bin (edc, |
371 | s->prod_h_i_b_i, | 373 | s->prod_h_i_b_i, |
372 | &msg->prod_h_i_b_i); | 374 | &msg->prod_h_i_b_i); |
373 | GNUNET_MQ_notify_sent(e, | 375 | GNUNET_MQ_notify_sent (e, |
374 | &bob_cadet_done_cb, | 376 | &bob_cadet_done_cb, |
375 | s); | 377 | s); |
376 | GNUNET_MQ_send(s->cadet_mq, | 378 | GNUNET_MQ_send (s->cadet_mq, |
377 | e); | 379 | e); |
378 | } | 380 | } |
379 | 381 | ||
380 | 382 | ||
@@ -388,21 +390,21 @@ transmit_bobs_cryptodata_message(struct BobServiceSession *s) | |||
388 | * TODO: code duplication with Alice! | 390 | * TODO: code duplication with Alice! |
389 | */ | 391 | */ |
390 | static int | 392 | static int |
391 | copy_element_cb(void *cls, | 393 | copy_element_cb (void *cls, |
392 | const struct GNUNET_HashCode *key, | 394 | const struct GNUNET_HashCode *key, |
393 | void *value) | 395 | void *value) |
394 | { | 396 | { |
395 | struct BobServiceSession *s = cls; | 397 | struct BobServiceSession *s = cls; |
396 | struct GNUNET_SCALARPRODUCT_Element *e = value; | 398 | struct GNUNET_SCALARPRODUCT_Element *e = value; |
397 | gcry_mpi_t mval; | 399 | gcry_mpi_t mval; |
398 | int64_t val; | 400 | int64_t val; |
399 | 401 | ||
400 | mval = gcry_mpi_new(0); | 402 | mval = gcry_mpi_new (0); |
401 | val = (int64_t)GNUNET_ntohll(e->value); | 403 | val = (int64_t) GNUNET_ntohll (e->value); |
402 | if (0 > val) | 404 | if (0 > val) |
403 | gcry_mpi_sub_ui(mval, mval, -val); | 405 | gcry_mpi_sub_ui (mval, mval, -val); |
404 | else | 406 | else |
405 | gcry_mpi_add_ui(mval, mval, val); | 407 | gcry_mpi_add_ui (mval, mval, val); |
406 | s->sorted_elements [s->used_element_count].value = mval; | 408 | s->sorted_elements [s->used_element_count].value = mval; |
407 | s->sorted_elements [s->used_element_count].key = &e->key; | 409 | s->sorted_elements [s->used_element_count].key = &e->key; |
408 | s->used_element_count++; | 410 | s->used_element_count++; |
@@ -419,14 +421,14 @@ copy_element_cb(void *cls, | |||
419 | * TODO: code duplication with Alice! | 421 | * TODO: code duplication with Alice! |
420 | */ | 422 | */ |
421 | static int | 423 | static int |
422 | element_cmp(const void *a, | 424 | element_cmp (const void *a, |
423 | const void *b) | 425 | const void *b) |
424 | { | 426 | { |
425 | const struct MpiElement *ma = a; | 427 | const struct MpiElement *ma = a; |
426 | const struct MpiElement *mb = b; | 428 | const struct MpiElement *mb = b; |
427 | 429 | ||
428 | return GNUNET_CRYPTO_hash_cmp(ma->key, | 430 | return GNUNET_CRYPTO_hash_cmp (ma->key, |
429 | mb->key); | 431 | mb->key); |
430 | } | 432 | } |
431 | 433 | ||
432 | 434 | ||
@@ -440,8 +442,8 @@ element_cmp(const void *a, | |||
440 | * #GNUNET_SYSERR to close it (signal serious error) | 442 | * #GNUNET_SYSERR to close it (signal serious error) |
441 | */ | 443 | */ |
442 | static int | 444 | static int |
443 | check_alices_cryptodata_message(void *cls, | 445 | check_alices_cryptodata_message (void *cls, |
444 | const struct EccAliceCryptodataMessage *msg) | 446 | const struct EccAliceCryptodataMessage *msg) |
445 | { | 447 | { |
446 | struct BobServiceSession *s = cls; | 448 | struct BobServiceSession *s = cls; |
447 | uint32_t contained_elements; | 449 | uint32_t contained_elements; |
@@ -449,26 +451,26 @@ check_alices_cryptodata_message(void *cls, | |||
449 | uint16_t msize; | 451 | uint16_t msize; |
450 | unsigned int max; | 452 | unsigned int max; |
451 | 453 | ||
452 | msize = ntohs(msg->header.size); | 454 | msize = ntohs (msg->header.size); |
453 | if (msize <= sizeof(struct EccAliceCryptodataMessage)) | 455 | if (msize <= sizeof(struct EccAliceCryptodataMessage)) |
454 | { | 456 | { |
455 | GNUNET_break_op(0); | 457 | GNUNET_break_op (0); |
456 | return GNUNET_SYSERR; | 458 | return GNUNET_SYSERR; |
457 | } | 459 | } |
458 | contained_elements = ntohl(msg->contained_element_count); | 460 | contained_elements = ntohl (msg->contained_element_count); |
459 | /* Our intersection may still be ongoing, but this is nevertheless | 461 | /* Our intersection may still be ongoing, but this is nevertheless |
460 | an upper bound on the required array size */ | 462 | an upper bound on the required array size */ |
461 | max = GNUNET_CONTAINER_multihashmap_size(s->intersected_elements); | 463 | max = GNUNET_CONTAINER_multihashmap_size (s->intersected_elements); |
462 | msg_length = sizeof(struct EccAliceCryptodataMessage) | 464 | msg_length = sizeof(struct EccAliceCryptodataMessage) |
463 | + contained_elements * sizeof(struct GNUNET_CRYPTO_EccPoint) * 2; | 465 | + contained_elements * sizeof(struct GNUNET_CRYPTO_EccPoint) * 2; |
464 | if ((msize != msg_length) || | 466 | if ((msize != msg_length) || |
465 | (0 == contained_elements) || | 467 | (0 == contained_elements) || |
466 | (contained_elements > UINT16_MAX) || | 468 | (contained_elements > UINT16_MAX) || |
467 | (max < contained_elements + s->cadet_received_element_count)) | 469 | (max < contained_elements + s->cadet_received_element_count)) |
468 | { | 470 | { |
469 | GNUNET_break_op(0); | 471 | GNUNET_break_op (0); |
470 | return GNUNET_SYSERR; | 472 | return GNUNET_SYSERR; |
471 | } | 473 | } |
472 | return GNUNET_OK; | 474 | return GNUNET_OK; |
473 | } | 475 | } |
474 | 476 | ||
@@ -481,8 +483,8 @@ check_alices_cryptodata_message(void *cls, | |||
481 | * @param msg the actual message | 483 | * @param msg the actual message |
482 | */ | 484 | */ |
483 | static void | 485 | static void |
484 | handle_alices_cryptodata_message(void *cls, | 486 | handle_alices_cryptodata_message (void *cls, |
485 | const struct EccAliceCryptodataMessage *msg) | 487 | const struct EccAliceCryptodataMessage *msg) |
486 | { | 488 | { |
487 | struct BobServiceSession *s = cls; | 489 | struct BobServiceSession *s = cls; |
488 | const struct GNUNET_CRYPTO_EccPoint *payload; | 490 | const struct GNUNET_CRYPTO_EccPoint *payload; |
@@ -496,77 +498,78 @@ handle_alices_cryptodata_message(void *cls, | |||
496 | gcry_mpi_point_t g_i_b_i; | 498 | gcry_mpi_point_t g_i_b_i; |
497 | gcry_mpi_point_t h_i_b_i; | 499 | gcry_mpi_point_t h_i_b_i; |
498 | 500 | ||
499 | contained_elements = ntohl(msg->contained_element_count); | 501 | contained_elements = ntohl (msg->contained_element_count); |
500 | max = GNUNET_CONTAINER_multihashmap_size(s->intersected_elements); | 502 | max = GNUNET_CONTAINER_multihashmap_size (s->intersected_elements); |
501 | /* sort our vector for the computation */ | 503 | /* sort our vector for the computation */ |
502 | if (NULL == s->sorted_elements) | 504 | if (NULL == s->sorted_elements) |
503 | { | 505 | { |
504 | s->sorted_elements | 506 | s->sorted_elements |
505 | = GNUNET_new_array(GNUNET_CONTAINER_multihashmap_size(s->intersected_elements), | 507 | = GNUNET_new_array (GNUNET_CONTAINER_multihashmap_size ( |
506 | struct MpiElement); | 508 | s->intersected_elements), |
507 | s->used_element_count = 0; | 509 | struct MpiElement); |
508 | GNUNET_CONTAINER_multihashmap_iterate(s->intersected_elements, | 510 | s->used_element_count = 0; |
509 | ©_element_cb, | 511 | GNUNET_CONTAINER_multihashmap_iterate (s->intersected_elements, |
510 | s); | 512 | ©_element_cb, |
511 | qsort(s->sorted_elements, | 513 | s); |
512 | s->used_element_count, | 514 | qsort (s->sorted_elements, |
513 | sizeof(struct MpiElement), | 515 | s->used_element_count, |
514 | &element_cmp); | 516 | sizeof(struct MpiElement), |
515 | } | 517 | &element_cmp); |
516 | 518 | } | |
517 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 519 | |
518 | "Received %u crypto values from Alice\n", | 520 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
519 | (unsigned int)contained_elements); | 521 | "Received %u crypto values from Alice\n", |
520 | payload = (const struct GNUNET_CRYPTO_EccPoint *)&msg[1]; | 522 | (unsigned int) contained_elements); |
523 | payload = (const struct GNUNET_CRYPTO_EccPoint *) &msg[1]; | ||
521 | 524 | ||
522 | for (i = 0; i < contained_elements; i++) | 525 | for (i = 0; i < contained_elements; i++) |
526 | { | ||
527 | b_i = &s->sorted_elements[i + s->cadet_received_element_count]; | ||
528 | g_i = GNUNET_CRYPTO_ecc_bin_to_point (edc, | ||
529 | &payload[i * 2]); | ||
530 | g_i_b_i = GNUNET_CRYPTO_ecc_pmul_mpi (edc, | ||
531 | g_i, | ||
532 | b_i->value); | ||
533 | gcry_mpi_point_release (g_i); | ||
534 | h_i = GNUNET_CRYPTO_ecc_bin_to_point (edc, | ||
535 | &payload[i * 2 + 1]); | ||
536 | h_i_b_i = GNUNET_CRYPTO_ecc_pmul_mpi (edc, | ||
537 | h_i, | ||
538 | b_i->value); | ||
539 | gcry_mpi_point_release (h_i); | ||
540 | if (0 == i + s->cadet_received_element_count) | ||
541 | { | ||
542 | /* first iteration, nothing to add */ | ||
543 | s->prod_g_i_b_i = g_i_b_i; | ||
544 | s->prod_h_i_b_i = h_i_b_i; | ||
545 | } | ||
546 | else | ||
523 | { | 547 | { |
524 | b_i = &s->sorted_elements[i + s->cadet_received_element_count]; | 548 | /* further iterations, cummulate resulting value */ |
525 | g_i = GNUNET_CRYPTO_ecc_bin_to_point(edc, | 549 | tmp = GNUNET_CRYPTO_ecc_add (edc, |
526 | &payload[i * 2]); | 550 | s->prod_g_i_b_i, |
527 | g_i_b_i = GNUNET_CRYPTO_ecc_pmul_mpi(edc, | 551 | g_i_b_i); |
528 | g_i, | 552 | gcry_mpi_point_release (s->prod_g_i_b_i); |
529 | b_i->value); | 553 | gcry_mpi_point_release (g_i_b_i); |
530 | gcry_mpi_point_release(g_i); | 554 | s->prod_g_i_b_i = tmp; |
531 | h_i = GNUNET_CRYPTO_ecc_bin_to_point(edc, | 555 | tmp = GNUNET_CRYPTO_ecc_add (edc, |
532 | &payload[i * 2 + 1]); | 556 | s->prod_h_i_b_i, |
533 | h_i_b_i = GNUNET_CRYPTO_ecc_pmul_mpi(edc, | 557 | h_i_b_i); |
534 | h_i, | 558 | gcry_mpi_point_release (s->prod_h_i_b_i); |
535 | b_i->value); | 559 | gcry_mpi_point_release (h_i_b_i); |
536 | gcry_mpi_point_release(h_i); | 560 | s->prod_h_i_b_i = tmp; |
537 | if (0 == i + s->cadet_received_element_count) | ||
538 | { | ||
539 | /* first iteration, nothing to add */ | ||
540 | s->prod_g_i_b_i = g_i_b_i; | ||
541 | s->prod_h_i_b_i = h_i_b_i; | ||
542 | } | ||
543 | else | ||
544 | { | ||
545 | /* further iterations, cummulate resulting value */ | ||
546 | tmp = GNUNET_CRYPTO_ecc_add(edc, | ||
547 | s->prod_g_i_b_i, | ||
548 | g_i_b_i); | ||
549 | gcry_mpi_point_release(s->prod_g_i_b_i); | ||
550 | gcry_mpi_point_release(g_i_b_i); | ||
551 | s->prod_g_i_b_i = tmp; | ||
552 | tmp = GNUNET_CRYPTO_ecc_add(edc, | ||
553 | s->prod_h_i_b_i, | ||
554 | h_i_b_i); | ||
555 | gcry_mpi_point_release(s->prod_h_i_b_i); | ||
556 | gcry_mpi_point_release(h_i_b_i); | ||
557 | s->prod_h_i_b_i = tmp; | ||
558 | } | ||
559 | } | 561 | } |
562 | } | ||
560 | s->cadet_received_element_count += contained_elements; | 563 | s->cadet_received_element_count += contained_elements; |
561 | if ((s->cadet_received_element_count == max) && | 564 | if ((s->cadet_received_element_count == max) && |
562 | (NULL == s->intersection_op)) | 565 | (NULL == s->intersection_op)) |
563 | { | 566 | { |
564 | /* intersection has finished also on our side, and | 567 | /* intersection has finished also on our side, and |
565 | we got the full set, so we can proceed with the | 568 | we got the full set, so we can proceed with the |
566 | CADET response(s) */ | 569 | CADET response(s) */ |
567 | transmit_bobs_cryptodata_message(s); | 570 | transmit_bobs_cryptodata_message (s); |
568 | } | 571 | } |
569 | GNUNET_CADET_receive_done(s->channel); | 572 | GNUNET_CADET_receive_done (s->channel); |
570 | } | 573 | } |
571 | 574 | ||
572 | 575 | ||
@@ -580,71 +583,72 @@ handle_alices_cryptodata_message(void *cls, | |||
580 | * @param status what has happened with the set intersection? | 583 | * @param status what has happened with the set intersection? |
581 | */ | 584 | */ |
582 | static void | 585 | static void |
583 | cb_intersection_element_removed(void *cls, | 586 | cb_intersection_element_removed (void *cls, |
584 | const struct GNUNET_SET_Element *element, | 587 | const struct GNUNET_SET_Element *element, |
585 | uint64_t current_size, | 588 | uint64_t current_size, |
586 | enum GNUNET_SET_Status status) | 589 | enum GNUNET_SET_Status status) |
587 | { | 590 | { |
588 | struct BobServiceSession *s = cls; | 591 | struct BobServiceSession *s = cls; |
589 | struct GNUNET_SCALARPRODUCT_Element *se; | 592 | struct GNUNET_SCALARPRODUCT_Element *se; |
590 | 593 | ||
591 | switch (status) | 594 | switch (status) |
595 | { | ||
596 | case GNUNET_SET_STATUS_OK: | ||
597 | /* this element has been removed from the set */ | ||
598 | se = GNUNET_CONTAINER_multihashmap_get (s->intersected_elements, | ||
599 | element->data); | ||
600 | GNUNET_assert (NULL != se); | ||
601 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
602 | "Removed element with key %s and value %lld\n", | ||
603 | GNUNET_h2s (&se->key), | ||
604 | (long long) GNUNET_ntohll (se->value)); | ||
605 | GNUNET_assert (GNUNET_YES == | ||
606 | GNUNET_CONTAINER_multihashmap_remove ( | ||
607 | s->intersected_elements, | ||
608 | element->data, | ||
609 | se)); | ||
610 | GNUNET_free (se); | ||
611 | return; | ||
612 | |||
613 | case GNUNET_SET_STATUS_DONE: | ||
614 | s->intersection_op = NULL; | ||
615 | GNUNET_break (NULL == s->intersection_set); | ||
616 | GNUNET_CADET_receive_done (s->channel); | ||
617 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
618 | "Finished intersection, %d items remain\n", | ||
619 | GNUNET_CONTAINER_multihashmap_size (s->intersected_elements)); | ||
620 | if (s->client_received_element_count == | ||
621 | GNUNET_CONTAINER_multihashmap_size (s->intersected_elements)) | ||
592 | { | 622 | { |
593 | case GNUNET_SET_STATUS_OK: | 623 | /* CADET transmission from Alice is also already done, |
594 | /* this element has been removed from the set */ | 624 | start with our own reply */ |
595 | se = GNUNET_CONTAINER_multihashmap_get(s->intersected_elements, | 625 | transmit_bobs_cryptodata_message (s); |
596 | element->data); | ||
597 | GNUNET_assert(NULL != se); | ||
598 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
599 | "Removed element with key %s and value %lld\n", | ||
600 | GNUNET_h2s(&se->key), | ||
601 | (long long)GNUNET_ntohll(se->value)); | ||
602 | GNUNET_assert(GNUNET_YES == | ||
603 | GNUNET_CONTAINER_multihashmap_remove(s->intersected_elements, | ||
604 | element->data, | ||
605 | se)); | ||
606 | GNUNET_free(se); | ||
607 | return; | ||
608 | |||
609 | case GNUNET_SET_STATUS_DONE: | ||
610 | s->intersection_op = NULL; | ||
611 | GNUNET_break(NULL == s->intersection_set); | ||
612 | GNUNET_CADET_receive_done(s->channel); | ||
613 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
614 | "Finished intersection, %d items remain\n", | ||
615 | GNUNET_CONTAINER_multihashmap_size(s->intersected_elements)); | ||
616 | if (s->client_received_element_count == | ||
617 | GNUNET_CONTAINER_multihashmap_size(s->intersected_elements)) | ||
618 | { | ||
619 | /* CADET transmission from Alice is also already done, | ||
620 | start with our own reply */ | ||
621 | transmit_bobs_cryptodata_message(s); | ||
622 | } | ||
623 | return; | ||
624 | |||
625 | case GNUNET_SET_STATUS_HALF_DONE: | ||
626 | /* unexpected for intersection */ | ||
627 | GNUNET_break(0); | ||
628 | return; | ||
629 | |||
630 | case GNUNET_SET_STATUS_FAILURE: | ||
631 | /* unhandled status code */ | ||
632 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
633 | "Set intersection failed!\n"); | ||
634 | s->intersection_op = NULL; | ||
635 | if (NULL != s->intersection_set) | ||
636 | { | ||
637 | GNUNET_SET_destroy(s->intersection_set); | ||
638 | s->intersection_set = NULL; | ||
639 | } | ||
640 | s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; | ||
641 | prepare_client_end_notification(s); | ||
642 | return; | ||
643 | |||
644 | default: | ||
645 | GNUNET_break(0); | ||
646 | return; | ||
647 | } | 626 | } |
627 | return; | ||
628 | |||
629 | case GNUNET_SET_STATUS_HALF_DONE: | ||
630 | /* unexpected for intersection */ | ||
631 | GNUNET_break (0); | ||
632 | return; | ||
633 | |||
634 | case GNUNET_SET_STATUS_FAILURE: | ||
635 | /* unhandled status code */ | ||
636 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
637 | "Set intersection failed!\n"); | ||
638 | s->intersection_op = NULL; | ||
639 | if (NULL != s->intersection_set) | ||
640 | { | ||
641 | GNUNET_SET_destroy (s->intersection_set); | ||
642 | s->intersection_set = NULL; | ||
643 | } | ||
644 | s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; | ||
645 | prepare_client_end_notification (s); | ||
646 | return; | ||
647 | |||
648 | default: | ||
649 | GNUNET_break (0); | ||
650 | return; | ||
651 | } | ||
648 | } | 652 | } |
649 | 653 | ||
650 | 654 | ||
@@ -655,36 +659,36 @@ cb_intersection_element_removed(void *cls, | |||
655 | * @param s client session to start intersection for | 659 | * @param s client session to start intersection for |
656 | */ | 660 | */ |
657 | static void | 661 | static void |
658 | start_intersection(struct BobServiceSession *s) | 662 | start_intersection (struct BobServiceSession *s) |
659 | { | 663 | { |
660 | struct GNUNET_HashCode set_sid; | 664 | struct GNUNET_HashCode set_sid; |
661 | 665 | ||
662 | GNUNET_CRYPTO_hash(&s->session_id, | 666 | GNUNET_CRYPTO_hash (&s->session_id, |
663 | sizeof(struct GNUNET_HashCode), | 667 | sizeof(struct GNUNET_HashCode), |
664 | &set_sid); | 668 | &set_sid); |
665 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 669 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
666 | "Got session with key %s and %u elements, starting intersection.\n", | 670 | "Got session with key %s and %u elements, starting intersection.\n", |
667 | GNUNET_h2s(&s->session_id), | 671 | GNUNET_h2s (&s->session_id), |
668 | (unsigned int)s->total); | 672 | (unsigned int) s->total); |
669 | 673 | ||
670 | s->intersection_op | 674 | s->intersection_op |
671 | = GNUNET_SET_prepare(&s->peer, | 675 | = GNUNET_SET_prepare (&s->peer, |
672 | &set_sid, | 676 | &set_sid, |
673 | NULL, | 677 | NULL, |
674 | GNUNET_SET_RESULT_REMOVED, | 678 | GNUNET_SET_RESULT_REMOVED, |
675 | (struct GNUNET_SET_Option[]) { { 0 } }, | 679 | (struct GNUNET_SET_Option[]) { { 0 } }, |
676 | &cb_intersection_element_removed, | 680 | &cb_intersection_element_removed, |
677 | s); | 681 | s); |
678 | if (GNUNET_OK != | 682 | if (GNUNET_OK != |
679 | GNUNET_SET_commit(s->intersection_op, | 683 | GNUNET_SET_commit (s->intersection_op, |
680 | s->intersection_set)) | 684 | s->intersection_set)) |
681 | { | 685 | { |
682 | GNUNET_break(0); | 686 | GNUNET_break (0); |
683 | s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; | 687 | s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; |
684 | prepare_client_end_notification(s); | 688 | prepare_client_end_notification (s); |
685 | return; | 689 | return; |
686 | } | 690 | } |
687 | GNUNET_SET_destroy(s->intersection_set); | 691 | GNUNET_SET_destroy (s->intersection_set); |
688 | s->intersection_set = NULL; | 692 | s->intersection_set = NULL; |
689 | } | 693 | } |
690 | 694 | ||
@@ -696,21 +700,21 @@ start_intersection(struct BobServiceSession *s) | |||
696 | * @param msg the actual message | 700 | * @param msg the actual message |
697 | */ | 701 | */ |
698 | static void | 702 | static void |
699 | handle_alices_computation_request(void *cls, | 703 | handle_alices_computation_request (void *cls, |
700 | const struct EccServiceRequestMessage *msg) | 704 | const struct EccServiceRequestMessage *msg) |
701 | { | 705 | { |
702 | struct BobServiceSession *s = cls; | 706 | struct BobServiceSession *s = cls; |
703 | 707 | ||
704 | s->session_id = msg->session_id; // ?? | 708 | s->session_id = msg->session_id; // ?? |
705 | if (s->client_received_element_count < s->total) | 709 | if (s->client_received_element_count < s->total) |
706 | { | 710 | { |
707 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 711 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
708 | "Alice ready, still waiting for Bob client data!\n"); | 712 | "Alice ready, still waiting for Bob client data!\n"); |
709 | return; | 713 | return; |
710 | } | 714 | } |
711 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 715 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
712 | "Both ready, launching intersection!\n"); | 716 | "Both ready, launching intersection!\n"); |
713 | start_intersection(s); | 717 | start_intersection (s); |
714 | } | 718 | } |
715 | 719 | ||
716 | 720 | ||
@@ -725,20 +729,20 @@ handle_alices_computation_request(void *cls, | |||
725 | * @return session associated with the channel | 729 | * @return session associated with the channel |
726 | */ | 730 | */ |
727 | static void * | 731 | static void * |
728 | cb_channel_incoming(void *cls, | 732 | cb_channel_incoming (void *cls, |
729 | struct GNUNET_CADET_Channel *channel, | 733 | struct GNUNET_CADET_Channel *channel, |
730 | const struct GNUNET_PeerIdentity *initiator) | 734 | const struct GNUNET_PeerIdentity *initiator) |
731 | { | 735 | { |
732 | struct BobServiceSession *s = cls; | 736 | struct BobServiceSession *s = cls; |
733 | 737 | ||
734 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 738 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
735 | "New incoming channel from peer %s.\n", | 739 | "New incoming channel from peer %s.\n", |
736 | GNUNET_i2s(initiator)); | 740 | GNUNET_i2s (initiator)); |
737 | GNUNET_CADET_close_port(s->port); | 741 | GNUNET_CADET_close_port (s->port); |
738 | s->port = NULL; | 742 | s->port = NULL; |
739 | s->peer = *initiator; | 743 | s->peer = *initiator; |
740 | s->channel = channel; | 744 | s->channel = channel; |
741 | s->cadet_mq = GNUNET_CADET_get_mq(s->channel); | 745 | s->cadet_mq = GNUNET_CADET_get_mq (s->channel); |
742 | return s; | 746 | return s; |
743 | } | 747 | } |
744 | 748 | ||
@@ -751,25 +755,28 @@ cb_channel_incoming(void *cls, | |||
751 | * @return #GNUNET_OK if @a msg is well-formed | 755 | * @return #GNUNET_OK if @a msg is well-formed |
752 | */ | 756 | */ |
753 | static int | 757 | static int |
754 | check_bob_client_message_multipart(void *cls, | 758 | check_bob_client_message_multipart (void *cls, |
755 | const struct ComputationBobCryptodataMultipartMessage *msg) | 759 | const struct |
760 | ComputationBobCryptodataMultipartMessage * | ||
761 | msg) | ||
756 | { | 762 | { |
757 | struct BobServiceSession *s = cls; | 763 | struct BobServiceSession *s = cls; |
758 | uint32_t contained_count; | 764 | uint32_t contained_count; |
759 | uint16_t msize; | 765 | uint16_t msize; |
760 | 766 | ||
761 | msize = ntohs(msg->header.size); | 767 | msize = ntohs (msg->header.size); |
762 | contained_count = ntohl(msg->element_count_contained); | 768 | contained_count = ntohl (msg->element_count_contained); |
763 | if ((msize != (sizeof(struct ComputationBobCryptodataMultipartMessage) + | 769 | if ((msize != (sizeof(struct ComputationBobCryptodataMultipartMessage) |
764 | contained_count * sizeof(struct GNUNET_SCALARPRODUCT_Element))) || | 770 | + contained_count * sizeof(struct |
771 | GNUNET_SCALARPRODUCT_Element))) || | ||
765 | (0 == contained_count) || | 772 | (0 == contained_count) || |
766 | (UINT16_MAX < contained_count) || | 773 | (UINT16_MAX < contained_count) || |
767 | (s->total == s->client_received_element_count) || | 774 | (s->total == s->client_received_element_count) || |
768 | (s->total < s->client_received_element_count + contained_count)) | 775 | (s->total < s->client_received_element_count + contained_count)) |
769 | { | 776 | { |
770 | GNUNET_break(0); | 777 | GNUNET_break (0); |
771 | return GNUNET_SYSERR; | 778 | return GNUNET_SYSERR; |
772 | } | 779 | } |
773 | return GNUNET_OK; | 780 | return GNUNET_OK; |
774 | } | 781 | } |
775 | 782 | ||
@@ -782,8 +789,10 @@ check_bob_client_message_multipart(void *cls, | |||
782 | * @param msg the actual message | 789 | * @param msg the actual message |
783 | */ | 790 | */ |
784 | static void | 791 | static void |
785 | handle_bob_client_message_multipart(void *cls, | 792 | handle_bob_client_message_multipart (void *cls, |
786 | const struct ComputationBobCryptodataMultipartMessage *msg) | 793 | const struct |
794 | ComputationBobCryptodataMultipartMessage * | ||
795 | msg) | ||
787 | { | 796 | { |
788 | struct BobServiceSession *s = cls; | 797 | struct BobServiceSession *s = cls; |
789 | uint32_t contained_count; | 798 | uint32_t contained_count; |
@@ -791,50 +800,50 @@ handle_bob_client_message_multipart(void *cls, | |||
791 | struct GNUNET_SET_Element set_elem; | 800 | struct GNUNET_SET_Element set_elem; |
792 | struct GNUNET_SCALARPRODUCT_Element *elem; | 801 | struct GNUNET_SCALARPRODUCT_Element *elem; |
793 | 802 | ||
794 | contained_count = ntohl(msg->element_count_contained); | 803 | contained_count = ntohl (msg->element_count_contained); |
795 | elements = (const struct GNUNET_SCALARPRODUCT_Element *)&msg[1]; | 804 | elements = (const struct GNUNET_SCALARPRODUCT_Element *) &msg[1]; |
796 | for (uint32_t i = 0; i < contained_count; i++) | 805 | for (uint32_t i = 0; i < contained_count; i++) |
806 | { | ||
807 | elem = GNUNET_new (struct GNUNET_SCALARPRODUCT_Element); | ||
808 | GNUNET_memcpy (elem, | ||
809 | &elements[i], | ||
810 | sizeof(struct GNUNET_SCALARPRODUCT_Element)); | ||
811 | if (GNUNET_SYSERR == | ||
812 | GNUNET_CONTAINER_multihashmap_put (s->intersected_elements, | ||
813 | &elem->key, | ||
814 | elem, | ||
815 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) | ||
797 | { | 816 | { |
798 | elem = GNUNET_new(struct GNUNET_SCALARPRODUCT_Element); | 817 | GNUNET_break (0); |
799 | GNUNET_memcpy(elem, | 818 | GNUNET_free (elem); |
800 | &elements[i], | 819 | continue; |
801 | sizeof(struct GNUNET_SCALARPRODUCT_Element)); | ||
802 | if (GNUNET_SYSERR == | ||
803 | GNUNET_CONTAINER_multihashmap_put(s->intersected_elements, | ||
804 | &elem->key, | ||
805 | elem, | ||
806 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) | ||
807 | { | ||
808 | GNUNET_break(0); | ||
809 | GNUNET_free(elem); | ||
810 | continue; | ||
811 | } | ||
812 | set_elem.data = &elem->key; | ||
813 | set_elem.size = sizeof(elem->key); | ||
814 | set_elem.element_type = 0; | ||
815 | GNUNET_SET_add_element(s->intersection_set, | ||
816 | &set_elem, | ||
817 | NULL, NULL); | ||
818 | } | 820 | } |
821 | set_elem.data = &elem->key; | ||
822 | set_elem.size = sizeof(elem->key); | ||
823 | set_elem.element_type = 0; | ||
824 | GNUNET_SET_add_element (s->intersection_set, | ||
825 | &set_elem, | ||
826 | NULL, NULL); | ||
827 | } | ||
819 | s->client_received_element_count += contained_count; | 828 | s->client_received_element_count += contained_count; |
820 | GNUNET_SERVICE_client_continue(s->client); | 829 | GNUNET_SERVICE_client_continue (s->client); |
821 | if (s->total != s->client_received_element_count) | 830 | if (s->total != s->client_received_element_count) |
822 | { | 831 | { |
823 | /* more to come */ | 832 | /* more to come */ |
824 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 833 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
825 | "Request still partial, waiting for more client data!\n"); | 834 | "Request still partial, waiting for more client data!\n"); |
826 | return; | 835 | return; |
827 | } | 836 | } |
828 | if (NULL == s->channel) | 837 | if (NULL == s->channel) |
829 | { | 838 | { |
830 | /* no Alice waiting for this request, wait for Alice */ | 839 | /* no Alice waiting for this request, wait for Alice */ |
831 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 840 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
832 | "Client ready, still waiting for Alice!\n"); | 841 | "Client ready, still waiting for Alice!\n"); |
833 | return; | 842 | return; |
834 | } | 843 | } |
835 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 844 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
836 | "Both ready, launching intersection!\n"); | 845 | "Both ready, launching intersection!\n"); |
837 | start_intersection(s); | 846 | start_intersection (s); |
838 | } | 847 | } |
839 | 848 | ||
840 | 849 | ||
@@ -847,8 +856,8 @@ handle_bob_client_message_multipart(void *cls, | |||
847 | * @return #GNUNET_OK if @a msg is well-formed | 856 | * @return #GNUNET_OK if @a msg is well-formed |
848 | */ | 857 | */ |
849 | static int | 858 | static int |
850 | check_bob_client_message(void *cls, | 859 | check_bob_client_message (void *cls, |
851 | const struct BobComputationMessage *msg) | 860 | const struct BobComputationMessage *msg) |
852 | { | 861 | { |
853 | struct BobServiceSession *s = cls; | 862 | struct BobServiceSession *s = cls; |
854 | uint32_t contained_count; | 863 | uint32_t contained_count; |
@@ -856,22 +865,23 @@ check_bob_client_message(void *cls, | |||
856 | uint16_t msize; | 865 | uint16_t msize; |
857 | 866 | ||
858 | if (GNUNET_SCALARPRODUCT_STATUS_INIT != s->status) | 867 | if (GNUNET_SCALARPRODUCT_STATUS_INIT != s->status) |
859 | { | 868 | { |
860 | GNUNET_break(0); | 869 | GNUNET_break (0); |
861 | return GNUNET_SYSERR; | 870 | return GNUNET_SYSERR; |
862 | } | 871 | } |
863 | msize = ntohs(msg->header.size); | 872 | msize = ntohs (msg->header.size); |
864 | total_count = ntohl(msg->element_count_total); | 873 | total_count = ntohl (msg->element_count_total); |
865 | contained_count = ntohl(msg->element_count_contained); | 874 | contained_count = ntohl (msg->element_count_contained); |
866 | if ((0 == total_count) || | 875 | if ((0 == total_count) || |
867 | (0 == contained_count) || | 876 | (0 == contained_count) || |
868 | (UINT16_MAX < contained_count) || | 877 | (UINT16_MAX < contained_count) || |
869 | (msize != (sizeof(struct BobComputationMessage) + | 878 | (msize != (sizeof(struct BobComputationMessage) |
870 | contained_count * sizeof(struct GNUNET_SCALARPRODUCT_Element)))) | 879 | + contained_count * sizeof(struct |
871 | { | 880 | GNUNET_SCALARPRODUCT_Element)))) |
872 | GNUNET_break_op(0); | 881 | { |
873 | return GNUNET_SYSERR; | 882 | GNUNET_break_op (0); |
874 | } | 883 | return GNUNET_SYSERR; |
884 | } | ||
875 | return GNUNET_OK; | 885 | return GNUNET_OK; |
876 | } | 886 | } |
877 | 887 | ||
@@ -885,20 +895,20 @@ check_bob_client_message(void *cls, | |||
885 | * @param msg the actual message | 895 | * @param msg the actual message |
886 | */ | 896 | */ |
887 | static void | 897 | static void |
888 | handle_bob_client_message(void *cls, | 898 | handle_bob_client_message (void *cls, |
889 | const struct BobComputationMessage *msg) | 899 | const struct BobComputationMessage *msg) |
890 | { | 900 | { |
891 | struct BobServiceSession *s = cls; | 901 | struct BobServiceSession *s = cls; |
892 | struct GNUNET_MQ_MessageHandler cadet_handlers[] = { | 902 | struct GNUNET_MQ_MessageHandler cadet_handlers[] = { |
893 | GNUNET_MQ_hd_fixed_size(alices_computation_request, | 903 | GNUNET_MQ_hd_fixed_size (alices_computation_request, |
894 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_SESSION_INITIALIZATION, | 904 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_SESSION_INITIALIZATION, |
895 | struct EccServiceRequestMessage, | 905 | struct EccServiceRequestMessage, |
896 | s), | 906 | s), |
897 | GNUNET_MQ_hd_var_size(alices_cryptodata_message, | 907 | GNUNET_MQ_hd_var_size (alices_cryptodata_message, |
898 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_ALICE_CRYPTODATA, | 908 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_ALICE_CRYPTODATA, |
899 | struct EccAliceCryptodataMessage, | 909 | struct EccAliceCryptodataMessage, |
900 | s), | 910 | s), |
901 | GNUNET_MQ_handler_end() | 911 | GNUNET_MQ_handler_end () |
902 | }; | 912 | }; |
903 | uint32_t contained_count; | 913 | uint32_t contained_count; |
904 | uint32_t total_count; | 914 | uint32_t total_count; |
@@ -906,63 +916,63 @@ handle_bob_client_message(void *cls, | |||
906 | struct GNUNET_SET_Element set_elem; | 916 | struct GNUNET_SET_Element set_elem; |
907 | struct GNUNET_SCALARPRODUCT_Element *elem; | 917 | struct GNUNET_SCALARPRODUCT_Element *elem; |
908 | 918 | ||
909 | total_count = ntohl(msg->element_count_total); | 919 | total_count = ntohl (msg->element_count_total); |
910 | contained_count = ntohl(msg->element_count_contained); | 920 | contained_count = ntohl (msg->element_count_contained); |
911 | 921 | ||
912 | s->status = GNUNET_SCALARPRODUCT_STATUS_ACTIVE; | 922 | s->status = GNUNET_SCALARPRODUCT_STATUS_ACTIVE; |
913 | s->total = total_count; | 923 | s->total = total_count; |
914 | s->client_received_element_count = contained_count; | 924 | s->client_received_element_count = contained_count; |
915 | s->session_id = msg->session_key; | 925 | s->session_id = msg->session_key; |
916 | elements = (const struct GNUNET_SCALARPRODUCT_Element *)&msg[1]; | 926 | elements = (const struct GNUNET_SCALARPRODUCT_Element *) &msg[1]; |
917 | s->intersected_elements | 927 | s->intersected_elements |
918 | = GNUNET_CONTAINER_multihashmap_create(s->total, | 928 | = GNUNET_CONTAINER_multihashmap_create (s->total, |
919 | GNUNET_YES); | 929 | GNUNET_YES); |
920 | s->intersection_set | 930 | s->intersection_set |
921 | = GNUNET_SET_create(cfg, | 931 | = GNUNET_SET_create (cfg, |
922 | GNUNET_SET_OPERATION_INTERSECTION); | 932 | GNUNET_SET_OPERATION_INTERSECTION); |
923 | for (uint32_t i = 0; i < contained_count; i++) | 933 | for (uint32_t i = 0; i < contained_count; i++) |
934 | { | ||
935 | if (0 == GNUNET_ntohll (elements[i].value)) | ||
936 | continue; | ||
937 | elem = GNUNET_new (struct GNUNET_SCALARPRODUCT_Element); | ||
938 | GNUNET_memcpy (elem, | ||
939 | &elements[i], | ||
940 | sizeof(struct GNUNET_SCALARPRODUCT_Element)); | ||
941 | if (GNUNET_SYSERR == | ||
942 | GNUNET_CONTAINER_multihashmap_put (s->intersected_elements, | ||
943 | &elem->key, | ||
944 | elem, | ||
945 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) | ||
924 | { | 946 | { |
925 | if (0 == GNUNET_ntohll(elements[i].value)) | 947 | GNUNET_break (0); |
926 | continue; | 948 | GNUNET_free (elem); |
927 | elem = GNUNET_new(struct GNUNET_SCALARPRODUCT_Element); | 949 | continue; |
928 | GNUNET_memcpy(elem, | ||
929 | &elements[i], | ||
930 | sizeof(struct GNUNET_SCALARPRODUCT_Element)); | ||
931 | if (GNUNET_SYSERR == | ||
932 | GNUNET_CONTAINER_multihashmap_put(s->intersected_elements, | ||
933 | &elem->key, | ||
934 | elem, | ||
935 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) | ||
936 | { | ||
937 | GNUNET_break(0); | ||
938 | GNUNET_free(elem); | ||
939 | continue; | ||
940 | } | ||
941 | set_elem.data = &elem->key; | ||
942 | set_elem.size = sizeof(elem->key); | ||
943 | set_elem.element_type = 0; | ||
944 | GNUNET_SET_add_element(s->intersection_set, | ||
945 | &set_elem, | ||
946 | NULL, NULL); | ||
947 | s->used_element_count++; | ||
948 | } | 950 | } |
949 | GNUNET_SERVICE_client_continue(s->client); | 951 | set_elem.data = &elem->key; |
950 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 952 | set_elem.size = sizeof(elem->key); |
951 | "Received client request, opening port %s!\n", | 953 | set_elem.element_type = 0; |
952 | GNUNET_h2s(&msg->session_key)); | 954 | GNUNET_SET_add_element (s->intersection_set, |
953 | s->port = GNUNET_CADET_open_port(my_cadet, | 955 | &set_elem, |
954 | &msg->session_key, | 956 | NULL, NULL); |
955 | &cb_channel_incoming, | 957 | s->used_element_count++; |
956 | s, | 958 | } |
957 | NULL, | 959 | GNUNET_SERVICE_client_continue (s->client); |
958 | &cb_channel_destruction, | 960 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
959 | cadet_handlers); | 961 | "Received client request, opening port %s!\n", |
962 | GNUNET_h2s (&msg->session_key)); | ||
963 | s->port = GNUNET_CADET_open_port (my_cadet, | ||
964 | &msg->session_key, | ||
965 | &cb_channel_incoming, | ||
966 | s, | ||
967 | NULL, | ||
968 | &cb_channel_destruction, | ||
969 | cadet_handlers); | ||
960 | if (NULL == s->port) | 970 | if (NULL == s->port) |
961 | { | 971 | { |
962 | GNUNET_break(0); | 972 | GNUNET_break (0); |
963 | GNUNET_SERVICE_client_drop(s->client); | 973 | GNUNET_SERVICE_client_drop (s->client); |
964 | return; | 974 | return; |
965 | } | 975 | } |
966 | } | 976 | } |
967 | 977 | ||
968 | 978 | ||
@@ -972,21 +982,21 @@ handle_bob_client_message(void *cls, | |||
972 | * @param cls unused | 982 | * @param cls unused |
973 | */ | 983 | */ |
974 | static void | 984 | static void |
975 | shutdown_task(void *cls) | 985 | shutdown_task (void *cls) |
976 | { | 986 | { |
977 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 987 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
978 | "Shutting down, initiating cleanup.\n"); | 988 | "Shutting down, initiating cleanup.\n"); |
979 | // FIXME: we have to cut our connections to CADET first! | 989 | // FIXME: we have to cut our connections to CADET first! |
980 | if (NULL != my_cadet) | 990 | if (NULL != my_cadet) |
981 | { | 991 | { |
982 | GNUNET_CADET_disconnect(my_cadet); | 992 | GNUNET_CADET_disconnect (my_cadet); |
983 | my_cadet = NULL; | 993 | my_cadet = NULL; |
984 | } | 994 | } |
985 | if (NULL != edc) | 995 | if (NULL != edc) |
986 | { | 996 | { |
987 | GNUNET_CRYPTO_ecc_dlog_release(edc); | 997 | GNUNET_CRYPTO_ecc_dlog_release (edc); |
988 | edc = NULL; | 998 | edc = NULL; |
989 | } | 999 | } |
990 | } | 1000 | } |
991 | 1001 | ||
992 | 1002 | ||
@@ -1001,13 +1011,13 @@ shutdown_task(void *cls) | |||
1001 | * @return our `struct BobServiceSession` | 1011 | * @return our `struct BobServiceSession` |
1002 | */ | 1012 | */ |
1003 | static void * | 1013 | static void * |
1004 | client_connect_cb(void *cls, | 1014 | client_connect_cb (void *cls, |
1005 | struct GNUNET_SERVICE_Client *client, | 1015 | struct GNUNET_SERVICE_Client *client, |
1006 | struct GNUNET_MQ_Handle *mq) | 1016 | struct GNUNET_MQ_Handle *mq) |
1007 | { | 1017 | { |
1008 | struct BobServiceSession *s; | 1018 | struct BobServiceSession *s; |
1009 | 1019 | ||
1010 | s = GNUNET_new(struct BobServiceSession); | 1020 | s = GNUNET_new (struct BobServiceSession); |
1011 | s->client = client; | 1021 | s->client = client; |
1012 | s->client_mq = mq; | 1022 | s->client_mq = mq; |
1013 | return s; | 1023 | return s; |
@@ -1025,16 +1035,16 @@ client_connect_cb(void *cls, | |||
1025 | * @param app_cls our `struct BobServiceSession` | 1035 | * @param app_cls our `struct BobServiceSession` |
1026 | */ | 1036 | */ |
1027 | static void | 1037 | static void |
1028 | client_disconnect_cb(void *cls, | 1038 | client_disconnect_cb (void *cls, |
1029 | struct GNUNET_SERVICE_Client *client, | 1039 | struct GNUNET_SERVICE_Client *client, |
1030 | void *app_cls) | 1040 | void *app_cls) |
1031 | { | 1041 | { |
1032 | struct BobServiceSession *s = app_cls; | 1042 | struct BobServiceSession *s = app_cls; |
1033 | 1043 | ||
1034 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1044 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1035 | "Client disconnected from us.\n"); | 1045 | "Client disconnected from us.\n"); |
1036 | s->client = NULL; | 1046 | s->client = NULL; |
1037 | destroy_service_session(s); | 1047 | destroy_service_session (s); |
1038 | } | 1048 | } |
1039 | 1049 | ||
1040 | 1050 | ||
@@ -1046,24 +1056,24 @@ client_disconnect_cb(void *cls, | |||
1046 | * @param service the initialized service | 1056 | * @param service the initialized service |
1047 | */ | 1057 | */ |
1048 | static void | 1058 | static void |
1049 | run(void *cls, | 1059 | run (void *cls, |
1050 | const struct GNUNET_CONFIGURATION_Handle *c, | 1060 | const struct GNUNET_CONFIGURATION_Handle *c, |
1051 | struct GNUNET_SERVICE_Handle *service) | 1061 | struct GNUNET_SERVICE_Handle *service) |
1052 | { | 1062 | { |
1053 | cfg = c; | 1063 | cfg = c; |
1054 | /* We don't really do DLOG, so we can setup with very minimal resources */ | 1064 | /* We don't really do DLOG, so we can setup with very minimal resources */ |
1055 | edc = GNUNET_CRYPTO_ecc_dlog_prepare(4 /* max value */, | 1065 | edc = GNUNET_CRYPTO_ecc_dlog_prepare (4 /* max value */, |
1056 | 2 /* RAM */); | 1066 | 2 /* RAM */); |
1057 | my_cadet = GNUNET_CADET_connect(cfg); | 1067 | my_cadet = GNUNET_CADET_connect (cfg); |
1058 | GNUNET_SCHEDULER_add_shutdown(&shutdown_task, | 1068 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, |
1059 | NULL); | 1069 | NULL); |
1060 | if (NULL == my_cadet) | 1070 | if (NULL == my_cadet) |
1061 | { | 1071 | { |
1062 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 1072 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1063 | _("Connect to CADET failed\n")); | 1073 | _ ("Connect to CADET failed\n")); |
1064 | GNUNET_SCHEDULER_shutdown(); | 1074 | GNUNET_SCHEDULER_shutdown (); |
1065 | return; | 1075 | return; |
1066 | } | 1076 | } |
1067 | } | 1077 | } |
1068 | 1078 | ||
1069 | 1079 | ||
@@ -1077,15 +1087,15 @@ GNUNET_SERVICE_MAIN | |||
1077 | &client_connect_cb, | 1087 | &client_connect_cb, |
1078 | &client_disconnect_cb, | 1088 | &client_disconnect_cb, |
1079 | NULL, | 1089 | NULL, |
1080 | GNUNET_MQ_hd_var_size(bob_client_message, | 1090 | GNUNET_MQ_hd_var_size (bob_client_message, |
1081 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_BOB, | 1091 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_BOB, |
1082 | struct BobComputationMessage, | 1092 | struct BobComputationMessage, |
1083 | NULL), | 1093 | NULL), |
1084 | GNUNET_MQ_hd_var_size(bob_client_message_multipart, | 1094 | GNUNET_MQ_hd_var_size (bob_client_message_multipart, |
1085 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MULTIPART_BOB, | 1095 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MULTIPART_BOB, |
1086 | struct ComputationBobCryptodataMultipartMessage, | 1096 | struct ComputationBobCryptodataMultipartMessage, |
1087 | NULL), | 1097 | NULL), |
1088 | GNUNET_MQ_handler_end()); | 1098 | GNUNET_MQ_handler_end ()); |
1089 | 1099 | ||
1090 | 1100 | ||
1091 | /* end of gnunet-service-scalarproduct-ecc_bob.c */ | 1101 | /* end of gnunet-service-scalarproduct-ecc_bob.c */ |