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