aboutsummaryrefslogtreecommitdiff
path: root/src/scalarproduct/scalarproduct_api.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2014-12-06 22:41:30 +0000
committerChristian Grothoff <christian@grothoff.org>2014-12-06 22:41:30 +0000
commit9d487bb2fe029b369f362bdbe4697005061a4e5e (patch)
tree5c2eb6849a5dd7a813a07e29a7f2be60af9b9792 /src/scalarproduct/scalarproduct_api.c
parent6cd1fc3aa29926ce0326d07ba684e1b65a1a0db7 (diff)
downloadgnunet-9d487bb2fe029b369f362bdbe4697005061a4e5e.tar.gz
gnunet-9d487bb2fe029b369f362bdbe4697005061a4e5e.zip
massive rework of scalarproduct service, splitting into Alice and Bob
Diffstat (limited to 'src/scalarproduct/scalarproduct_api.c')
-rw-r--r--src/scalarproduct/scalarproduct_api.c31
1 files changed, 20 insertions, 11 deletions
diff --git a/src/scalarproduct/scalarproduct_api.c b/src/scalarproduct/scalarproduct_api.c
index 5cb827838..8a4a0af98 100644
--- a/src/scalarproduct/scalarproduct_api.c
+++ b/src/scalarproduct/scalarproduct_api.c
@@ -23,6 +23,8 @@
23 * @author Christian Fuchs 23 * @author Christian Fuchs
24 * @author Gaurav Kukreja 24 * @author Gaurav Kukreja
25 * @author Christian Grothoff 25 * @author Christian Grothoff
26 *
27 * TODO: use MQ
26 */ 28 */
27#include "platform.h" 29#include "platform.h"
28#include "gnunet_util_lib.h" 30#include "gnunet_util_lib.h"
@@ -113,6 +115,11 @@ struct GNUNET_SCALARPRODUCT_ComputationHandle
113 */ 115 */
114 uint32_t element_count_transfered; 116 uint32_t element_count_transfered;
115 117
118 /**
119 * Type to use for the multipart messages.
120 */
121 uint16_t mp_type;
122
116}; 123};
117 124
118 125
@@ -307,7 +314,7 @@ do_send_message (void *cls,
307 msg = GNUNET_malloc (nsize); 314 msg = GNUNET_malloc (nsize);
308 h->msg = &msg->header; 315 h->msg = &msg->header;
309 msg->header.size = htons (nsize); 316 msg->header.size = htons (nsize);
310 msg->header.type = htons (GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MUTLIPART); 317 msg->header.type = htons (h->mp_type);
311 msg->element_count_contained = htonl (todo); 318 msg->element_count_contained = htonl (todo);
312 memcpy (&msg[1], 319 memcpy (&msg[1],
313 &h->elements[h->element_count_transfered], 320 &h->elements[h->element_count_transfered],
@@ -342,7 +349,7 @@ GNUNET_SCALARPRODUCT_accept_computation (const struct GNUNET_CONFIGURATION_Handl
342 void *cont_cls) 349 void *cont_cls)
343{ 350{
344 struct GNUNET_SCALARPRODUCT_ComputationHandle *h; 351 struct GNUNET_SCALARPRODUCT_ComputationHandle *h;
345 struct ComputationMessage *msg; 352 struct BobComputationMessage *msg;
346 uint32_t size; 353 uint32_t size;
347 uint16_t possible; 354 uint16_t possible;
348 355
@@ -352,8 +359,9 @@ GNUNET_SCALARPRODUCT_accept_computation (const struct GNUNET_CONFIGURATION_Handl
352 h->response_proc = &process_status_message; 359 h->response_proc = &process_status_message;
353 h->cfg = cfg; 360 h->cfg = cfg;
354 h->key = *session_key; 361 h->key = *session_key;
355 h->client = GNUNET_CLIENT_connect ("scalarproduct", cfg); 362 h->client = GNUNET_CLIENT_connect ("scalarproduct-bob", cfg);
356 h->element_count_total = element_count; 363 h->element_count_total = element_count;
364 h->mp_type = GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MUTLIPART_BOB;
357 if (NULL == h->client) 365 if (NULL == h->client)
358 { 366 {
359 /* scalarproduct configuration error */ 367 /* scalarproduct configuration error */
@@ -361,7 +369,7 @@ GNUNET_SCALARPRODUCT_accept_computation (const struct GNUNET_CONFIGURATION_Handl
361 GNUNET_free (h); 369 GNUNET_free (h);
362 return NULL; 370 return NULL;
363 } 371 }
364 size = sizeof (struct ComputationMessage) 372 size = sizeof (struct BobComputationMessage)
365 + element_count * sizeof (struct GNUNET_SCALARPRODUCT_Element); 373 + element_count * sizeof (struct GNUNET_SCALARPRODUCT_Element);
366 if (GNUNET_SERVER_MAX_MESSAGE_SIZE > size) 374 if (GNUNET_SERVER_MAX_MESSAGE_SIZE > size)
367 { 375 {
@@ -371,10 +379,10 @@ GNUNET_SCALARPRODUCT_accept_computation (const struct GNUNET_CONFIGURATION_Handl
371 else 379 else
372 { 380 {
373 /* create a multipart msg, first we calculate a new msg size for the head msg */ 381 /* create a multipart msg, first we calculate a new msg size for the head msg */
374 possible = (GNUNET_SERVER_MAX_MESSAGE_SIZE - 1 - sizeof (struct ComputationMessage)) 382 possible = (GNUNET_SERVER_MAX_MESSAGE_SIZE - 1 - sizeof (struct BobComputationMessage))
375 / sizeof (struct GNUNET_SCALARPRODUCT_Element); 383 / sizeof (struct GNUNET_SCALARPRODUCT_Element);
376 h->element_count_transfered = possible; 384 h->element_count_transfered = possible;
377 size = sizeof (struct ComputationMessage) 385 size = sizeof (struct BobComputationMessage)
378 + possible * sizeof (struct GNUNET_SCALARPRODUCT_Element); 386 + possible * sizeof (struct GNUNET_SCALARPRODUCT_Element);
379 h->elements = GNUNET_malloc (sizeof(struct GNUNET_SCALARPRODUCT_Element) * element_count); 387 h->elements = GNUNET_malloc (sizeof(struct GNUNET_SCALARPRODUCT_Element) * element_count);
380 memcpy (h->elements, 388 memcpy (h->elements,
@@ -423,12 +431,12 @@ GNUNET_SCALARPRODUCT_start_computation (const struct GNUNET_CONFIGURATION_Handle
423 void *cont_cls) 431 void *cont_cls)
424{ 432{
425 struct GNUNET_SCALARPRODUCT_ComputationHandle *h; 433 struct GNUNET_SCALARPRODUCT_ComputationHandle *h;
426 struct ComputationMessage *msg; 434 struct AliceComputationMessage *msg;
427 uint32_t size; 435 uint32_t size;
428 uint32_t possible; 436 uint32_t possible;
429 437
430 h = GNUNET_new (struct GNUNET_SCALARPRODUCT_ComputationHandle); 438 h = GNUNET_new (struct GNUNET_SCALARPRODUCT_ComputationHandle);
431 h->client = GNUNET_CLIENT_connect ("scalarproduct", cfg); 439 h->client = GNUNET_CLIENT_connect ("scalarproduct-alice", cfg);
432 if (NULL == h->client) 440 if (NULL == h->client)
433 { 441 {
434 /* missconfigured scalarproduct service */ 442 /* missconfigured scalarproduct service */
@@ -442,7 +450,8 @@ GNUNET_SCALARPRODUCT_start_computation (const struct GNUNET_CONFIGURATION_Handle
442 h->response_proc = &process_result_message; 450 h->response_proc = &process_result_message;
443 h->cfg = cfg; 451 h->cfg = cfg;
444 h->key = *session_key; 452 h->key = *session_key;
445 size = sizeof (struct ComputationMessage) 453 h->mp_type = GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MUTLIPART_ALICE;
454 size = sizeof (struct AliceComputationMessage)
446 + element_count * sizeof (struct GNUNET_SCALARPRODUCT_Element); 455 + element_count * sizeof (struct GNUNET_SCALARPRODUCT_Element);
447 if (GNUNET_SERVER_MAX_MESSAGE_SIZE > size) 456 if (GNUNET_SERVER_MAX_MESSAGE_SIZE > size)
448 { 457 {
@@ -452,10 +461,10 @@ GNUNET_SCALARPRODUCT_start_computation (const struct GNUNET_CONFIGURATION_Handle
452 else 461 else
453 { 462 {
454 /* create a multipart msg, first we calculate a new msg size for the head msg */ 463 /* create a multipart msg, first we calculate a new msg size for the head msg */
455 possible = (GNUNET_SERVER_MAX_MESSAGE_SIZE - 1 - sizeof (struct ComputationMessage)) 464 possible = (GNUNET_SERVER_MAX_MESSAGE_SIZE - 1 - sizeof (struct AliceComputationMessage))
456 / sizeof (struct GNUNET_SCALARPRODUCT_Element); 465 / sizeof (struct GNUNET_SCALARPRODUCT_Element);
457 h->element_count_transfered = possible; 466 h->element_count_transfered = possible;
458 size = sizeof (struct ComputationMessage) 467 size = sizeof (struct AliceComputationMessage)
459 + possible * sizeof (struct GNUNET_SCALARPRODUCT_Element); 468 + possible * sizeof (struct GNUNET_SCALARPRODUCT_Element);
460 h->elements = GNUNET_malloc (sizeof(struct GNUNET_SCALARPRODUCT_Element) * element_count); 469 h->elements = GNUNET_malloc (sizeof(struct GNUNET_SCALARPRODUCT_Element) * element_count);
461 memcpy (h->elements, 470 memcpy (h->elements,