summaryrefslogtreecommitdiff
path: root/src/scalarproduct/scalarproduct_api.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/scalarproduct/scalarproduct_api.c')
-rw-r--r--src/scalarproduct/scalarproduct_api.c406
1 files changed, 202 insertions, 204 deletions
diff --git a/src/scalarproduct/scalarproduct_api.c b/src/scalarproduct/scalarproduct_api.c
index 89aec14bc..5fd810317 100644
--- a/src/scalarproduct/scalarproduct_api.c
+++ b/src/scalarproduct/scalarproduct_api.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
@@ -31,7 +31,7 @@
31#include "gnunet_protocols.h" 31#include "gnunet_protocols.h"
32#include "scalarproduct.h" 32#include "scalarproduct.h"
33 33
34#define LOG(kind,...) GNUNET_log_from (kind, "scalarproduct-api",__VA_ARGS__) 34#define LOG(kind, ...) GNUNET_log_from(kind, "scalarproduct-api", __VA_ARGS__)
35 35
36 36
37/** 37/**
@@ -50,8 +50,7 @@ typedef void
50/** 50/**
51 * A handle returned for each computation 51 * A handle returned for each computation
52 */ 52 */
53struct GNUNET_SCALARPRODUCT_ComputationHandle 53struct GNUNET_SCALARPRODUCT_ComputationHandle {
54{
55 /** 54 /**
56 * Our configuration. 55 * Our configuration.
57 */ 56 */
@@ -87,7 +86,6 @@ struct GNUNET_SCALARPRODUCT_ComputationHandle
87 * The shared session key identifying this computation 86 * The shared session key identifying this computation
88 */ 87 */
89 struct GNUNET_HashCode key; 88 struct GNUNET_HashCode key;
90
91}; 89};
92 90
93 91
@@ -100,15 +98,15 @@ struct GNUNET_SCALARPRODUCT_ComputationHandle
100 * @return #GNUNET_OK if @a message is well-formed 98 * @return #GNUNET_OK if @a message is well-formed
101 */ 99 */
102static int 100static int
103check_response (void *cls, 101check_response(void *cls,
104 const struct ClientResponseMessage *message) 102 const struct ClientResponseMessage *message)
105{ 103{
106 if (ntohs (message->header.size) != 104 if (ntohs(message->header.size) !=
107 ntohl (message->product_length) + sizeof (struct ClientResponseMessage)) 105 ntohl(message->product_length) + sizeof(struct ClientResponseMessage))
108 { 106 {
109 GNUNET_break (0); 107 GNUNET_break(0);
110 return GNUNET_SYSERR; 108 return GNUNET_SYSERR;
111 } 109 }
112 return GNUNET_OK; 110 return GNUNET_OK;
113} 111}
114 112
@@ -123,14 +121,14 @@ check_response (void *cls,
123 * @param status the condition the request was terminated with (eg: disconnect) 121 * @param status the condition the request was terminated with (eg: disconnect)
124 */ 122 */
125static void 123static void
126process_status_message (struct GNUNET_SCALARPRODUCT_ComputationHandle *h, 124process_status_message(struct GNUNET_SCALARPRODUCT_ComputationHandle *h,
127 const struct ClientResponseMessage *msg, 125 const struct ClientResponseMessage *msg,
128 enum GNUNET_SCALARPRODUCT_ResponseStatus status) 126 enum GNUNET_SCALARPRODUCT_ResponseStatus status)
129{ 127{
130 if (NULL != h->cont_status) 128 if (NULL != h->cont_status)
131 h->cont_status (h->cont_cls, 129 h->cont_status(h->cont_cls,
132 status); 130 status);
133 GNUNET_SCALARPRODUCT_cancel (h); 131 GNUNET_SCALARPRODUCT_cancel(h);
134} 132}
135 133
136 134
@@ -143,16 +141,16 @@ process_status_message (struct GNUNET_SCALARPRODUCT_ComputationHandle *h,
143 * @param msg Pointer to the data received in response 141 * @param msg Pointer to the data received in response
144 */ 142 */
145static void 143static void
146handle_response (void *cls, 144handle_response(void *cls,
147 const struct ClientResponseMessage *message) 145 const struct ClientResponseMessage *message)
148{ 146{
149 struct GNUNET_SCALARPRODUCT_ComputationHandle *h = cls; 147 struct GNUNET_SCALARPRODUCT_ComputationHandle *h = cls;
150 enum GNUNET_SCALARPRODUCT_ResponseStatus status; 148 enum GNUNET_SCALARPRODUCT_ResponseStatus status;
151 149
152 status = (enum GNUNET_SCALARPRODUCT_ResponseStatus) ntohl (message->status); 150 status = (enum GNUNET_SCALARPRODUCT_ResponseStatus)ntohl(message->status);
153 h->response_proc (h, 151 h->response_proc(h,
154 message, 152 message,
155 status); 153 status);
156} 154}
157 155
158 156
@@ -164,28 +162,28 @@ handle_response (void *cls,
164 * @return #GNUNET_OK if all keys are unique 162 * @return #GNUNET_OK if all keys are unique
165 */ 163 */
166static int 164static int
167check_unique (const struct GNUNET_SCALARPRODUCT_Element *elements, 165check_unique(const struct GNUNET_SCALARPRODUCT_Element *elements,
168 uint32_t element_count) 166 uint32_t element_count)
169{ 167{
170 struct GNUNET_CONTAINER_MultiHashMap *map; 168 struct GNUNET_CONTAINER_MultiHashMap *map;
171 uint32_t i; 169 uint32_t i;
172 int ok; 170 int ok;
173 171
174 ok = GNUNET_OK; 172 ok = GNUNET_OK;
175 map = GNUNET_CONTAINER_multihashmap_create (2 * element_count, 173 map = GNUNET_CONTAINER_multihashmap_create(2 * element_count,
176 GNUNET_YES); 174 GNUNET_YES);
177 for (i=0;i<element_count;i++) 175 for (i = 0; i < element_count; i++)
178 if (GNUNET_OK != 176 if (GNUNET_OK !=
179 GNUNET_CONTAINER_multihashmap_put (map, 177 GNUNET_CONTAINER_multihashmap_put(map,
180 &elements[i].key, 178 &elements[i].key,
181 map, 179 map,
182 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) 180 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
183 { 181 {
184 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 182 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
185 _("Keys given to SCALARPRODUCT not unique!\n")); 183 _("Keys given to SCALARPRODUCT not unique!\n"));
186 ok = GNUNET_SYSERR; 184 ok = GNUNET_SYSERR;
187 } 185 }
188 GNUNET_CONTAINER_multihashmap_destroy (map); 186 GNUNET_CONTAINER_multihashmap_destroy(map);
189 return ok; 187 return ok;
190} 188}
191 189
@@ -198,16 +196,16 @@ check_unique (const struct GNUNET_SCALARPRODUCT_Element *elements,
198 * @param error error code 196 * @param error error code
199 */ 197 */
200static void 198static void
201mq_error_handler (void *cls, 199mq_error_handler(void *cls,
202 enum GNUNET_MQ_Error error) 200 enum GNUNET_MQ_Error error)
203{ 201{
204 struct GNUNET_SCALARPRODUCT_ComputationHandle *h = cls; 202 struct GNUNET_SCALARPRODUCT_ComputationHandle *h = cls;
205 203
206 LOG (GNUNET_ERROR_TYPE_INFO, 204 LOG(GNUNET_ERROR_TYPE_INFO,
207 "Disconnected from SCALARPRODUCT service.\n"); 205 "Disconnected from SCALARPRODUCT service.\n");
208 h->response_proc (h, 206 h->response_proc(h,
209 NULL, 207 NULL,
210 GNUNET_SCALARPRODUCT_STATUS_DISCONNECTED); 208 GNUNET_SCALARPRODUCT_STATUS_DISCONNECTED);
211} 209}
212 210
213 211
@@ -223,21 +221,21 @@ mq_error_handler (void *cls,
223 * @return a new handle for this computation 221 * @return a new handle for this computation
224 */ 222 */
225struct GNUNET_SCALARPRODUCT_ComputationHandle * 223struct GNUNET_SCALARPRODUCT_ComputationHandle *
226GNUNET_SCALARPRODUCT_accept_computation (const struct GNUNET_CONFIGURATION_Handle *cfg, 224GNUNET_SCALARPRODUCT_accept_computation(const struct GNUNET_CONFIGURATION_Handle *cfg,
227 const struct GNUNET_HashCode *session_key, 225 const struct GNUNET_HashCode *session_key,
228 const struct GNUNET_SCALARPRODUCT_Element *elements, 226 const struct GNUNET_SCALARPRODUCT_Element *elements,
229 uint32_t element_count, 227 uint32_t element_count,
230 GNUNET_SCALARPRODUCT_ContinuationWithStatus cont, 228 GNUNET_SCALARPRODUCT_ContinuationWithStatus cont,
231 void *cont_cls) 229 void *cont_cls)
232{ 230{
233 struct GNUNET_SCALARPRODUCT_ComputationHandle *h 231 struct GNUNET_SCALARPRODUCT_ComputationHandle *h
234 = GNUNET_new (struct GNUNET_SCALARPRODUCT_ComputationHandle); 232 = GNUNET_new(struct GNUNET_SCALARPRODUCT_ComputationHandle);
235 struct GNUNET_MQ_MessageHandler handlers[] = { 233 struct GNUNET_MQ_MessageHandler handlers[] = {
236 GNUNET_MQ_hd_var_size (response, 234 GNUNET_MQ_hd_var_size(response,
237 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_RESULT, 235 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_RESULT,
238 struct ClientResponseMessage, 236 struct ClientResponseMessage,
239 h), 237 h),
240 GNUNET_MQ_handler_end () 238 GNUNET_MQ_handler_end()
241 }; 239 };
242 struct GNUNET_MQ_Envelope *env; 240 struct GNUNET_MQ_Envelope *env;
243 struct BobComputationMessage *msg; 241 struct BobComputationMessage *msg;
@@ -248,61 +246,61 @@ GNUNET_SCALARPRODUCT_accept_computation (const struct GNUNET_CONFIGURATION_Handl
248 uint32_t element_count_transfered; 246 uint32_t element_count_transfered;
249 247
250 248
251 if (GNUNET_SYSERR == check_unique (elements, 249 if (GNUNET_SYSERR == check_unique(elements,
252 element_count)) 250 element_count))
253 return NULL; 251 return NULL;
254 h->cont_status = cont; 252 h->cont_status = cont;
255 h->cont_cls = cont_cls; 253 h->cont_cls = cont_cls;
256 h->response_proc = &process_status_message; 254 h->response_proc = &process_status_message;
257 h->cfg = cfg; 255 h->cfg = cfg;
258 h->key = *session_key; 256 h->key = *session_key;
259 h->mq = GNUNET_CLIENT_connect (cfg, 257 h->mq = GNUNET_CLIENT_connect(cfg,
260 "scalarproduct-bob", 258 "scalarproduct-bob",
261 handlers, 259 handlers,
262 &mq_error_handler, 260 &mq_error_handler,
263 h); 261 h);
264 if (NULL == h->mq) 262 if (NULL == h->mq)
265 { 263 {
266 /* scalarproduct configuration error */ 264 /* scalarproduct configuration error */
267 GNUNET_break (0); 265 GNUNET_break(0);
268 GNUNET_free (h); 266 GNUNET_free(h);
269 return NULL; 267 return NULL;
270 } 268 }
271 possible = (GNUNET_MAX_MESSAGE_SIZE - 1 - sizeof (struct BobComputationMessage)) 269 possible = (GNUNET_MAX_MESSAGE_SIZE - 1 - sizeof(struct BobComputationMessage))
272 / sizeof (struct GNUNET_SCALARPRODUCT_Element); 270 / sizeof(struct GNUNET_SCALARPRODUCT_Element);
273 todo = GNUNET_MIN (possible, 271 todo = GNUNET_MIN(possible,
274 element_count); 272 element_count);
275 size = todo * sizeof (struct GNUNET_SCALARPRODUCT_Element); 273 size = todo * sizeof(struct GNUNET_SCALARPRODUCT_Element);
276 env = GNUNET_MQ_msg_extra (msg, 274 env = GNUNET_MQ_msg_extra(msg,
277 size, 275 size,
278 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_BOB); 276 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_BOB);
279 msg->element_count_total = htonl (element_count); 277 msg->element_count_total = htonl(element_count);
280 msg->element_count_contained = htonl (todo); 278 msg->element_count_contained = htonl(todo);
281 msg->session_key = *session_key; 279 msg->session_key = *session_key;
282 GNUNET_memcpy (&msg[1], 280 GNUNET_memcpy(&msg[1],
283 elements, 281 elements,
284 size); 282 size);
285 element_count_transfered = todo; 283 element_count_transfered = todo;
286 GNUNET_MQ_send (h->mq, 284 GNUNET_MQ_send(h->mq,
287 env); 285 env);
288 possible = (GNUNET_MAX_MESSAGE_SIZE - 1 - sizeof (*mmsg)) 286 possible = (GNUNET_MAX_MESSAGE_SIZE - 1 - sizeof(*mmsg))
289 / sizeof (struct GNUNET_SCALARPRODUCT_Element); 287 / sizeof(struct GNUNET_SCALARPRODUCT_Element);
290 while (element_count_transfered < element_count) 288 while (element_count_transfered < element_count)
291 { 289 {
292 todo = GNUNET_MIN (possible, 290 todo = GNUNET_MIN(possible,
293 element_count - element_count_transfered); 291 element_count - element_count_transfered);
294 size = todo * sizeof (struct GNUNET_SCALARPRODUCT_Element); 292 size = todo * sizeof(struct GNUNET_SCALARPRODUCT_Element);
295 env = GNUNET_MQ_msg_extra (mmsg, 293 env = GNUNET_MQ_msg_extra(mmsg,
296 size, 294 size,
297 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MULTIPART_BOB); 295 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MULTIPART_BOB);
298 mmsg->element_count_contained = htonl (todo); 296 mmsg->element_count_contained = htonl(todo);
299 GNUNET_memcpy (&mmsg[1], 297 GNUNET_memcpy(&mmsg[1],
300 &elements[element_count_transfered], 298 &elements[element_count_transfered],
301 size); 299 size);
302 element_count_transfered += todo; 300 element_count_transfered += todo;
303 GNUNET_MQ_send (h->mq, 301 GNUNET_MQ_send(h->mq,
304 env); 302 env);
305 } 303 }
306 return h; 304 return h;
307} 305}
308 306
@@ -317,9 +315,9 @@ GNUNET_SCALARPRODUCT_accept_computation (const struct GNUNET_CONFIGURATION_Handl
317 * @param status the condition the request was terminated with (eg: disconnect) 315 * @param status the condition the request was terminated with (eg: disconnect)
318 */ 316 */
319static void 317static void
320process_result_message (struct GNUNET_SCALARPRODUCT_ComputationHandle *h, 318process_result_message(struct GNUNET_SCALARPRODUCT_ComputationHandle *h,
321 const struct ClientResponseMessage *msg, 319 const struct ClientResponseMessage *msg,
322 enum GNUNET_SCALARPRODUCT_ResponseStatus status) 320 enum GNUNET_SCALARPRODUCT_ResponseStatus status)
323{ 321{
324 uint32_t product_len; 322 uint32_t product_len;
325 gcry_mpi_t result = NULL; 323 gcry_mpi_t result = NULL;
@@ -328,42 +326,42 @@ process_result_message (struct GNUNET_SCALARPRODUCT_ComputationHandle *h,
328 size_t rsize; 326 size_t rsize;
329 327
330 if (GNUNET_SCALARPRODUCT_STATUS_SUCCESS == status) 328 if (GNUNET_SCALARPRODUCT_STATUS_SUCCESS == status)
331 {
332 result = gcry_mpi_new (0);
333
334 product_len = ntohl (msg->product_length);
335 if (0 < product_len)
336 { 329 {
337 rsize = 0; 330 result = gcry_mpi_new(0);
338 if (0 != (rc = gcry_mpi_scan (&num, GCRYMPI_FMT_STD, 331
339 &msg[1], 332 product_len = ntohl(msg->product_length);
340 product_len, 333 if (0 < product_len)
341 &rsize))) 334 {
342 { 335 rsize = 0;
343 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, 336 if (0 != (rc = gcry_mpi_scan(&num, GCRYMPI_FMT_STD,
344 "gcry_mpi_scan", 337 &msg[1],
345 rc); 338 product_len,
346 gcry_mpi_release (result); 339 &rsize)))
347 result = NULL; 340 {
348 status = GNUNET_SCALARPRODUCT_STATUS_INVALID_RESPONSE; 341 LOG_GCRY(GNUNET_ERROR_TYPE_ERROR,
349 } 342 "gcry_mpi_scan",
350 else 343 rc);
351 { 344 gcry_mpi_release(result);
352 if (0 < (int32_t) ntohl (msg->range)) 345 result = NULL;
353 gcry_mpi_add (result, result, num); 346 status = GNUNET_SCALARPRODUCT_STATUS_INVALID_RESPONSE;
354 else 347 }
355 gcry_mpi_sub (result, result, num); 348 else
356 gcry_mpi_release (num); 349 {
357 } 350 if (0 < (int32_t)ntohl(msg->range))
351 gcry_mpi_add(result, result, num);
352 else
353 gcry_mpi_sub(result, result, num);
354 gcry_mpi_release(num);
355 }
356 }
358 } 357 }
359 }
360 if (NULL != h->cont_datum) 358 if (NULL != h->cont_datum)
361 h->cont_datum (h->cont_cls, 359 h->cont_datum(h->cont_cls,
362 status, 360 status,
363 result); 361 result);
364 if (NULL != result) 362 if (NULL != result)
365 gcry_mpi_release (result); 363 gcry_mpi_release(result);
366 GNUNET_SCALARPRODUCT_cancel (h); 364 GNUNET_SCALARPRODUCT_cancel(h);
367} 365}
368 366
369 367
@@ -380,22 +378,22 @@ process_result_message (struct GNUNET_SCALARPRODUCT_ComputationHandle *h,
380 * @return a new handle for this computation 378 * @return a new handle for this computation
381 */ 379 */
382struct GNUNET_SCALARPRODUCT_ComputationHandle * 380struct GNUNET_SCALARPRODUCT_ComputationHandle *
383GNUNET_SCALARPRODUCT_start_computation (const struct GNUNET_CONFIGURATION_Handle *cfg, 381GNUNET_SCALARPRODUCT_start_computation(const struct GNUNET_CONFIGURATION_Handle *cfg,
384 const struct GNUNET_HashCode *session_key, 382 const struct GNUNET_HashCode *session_key,
385 const struct GNUNET_PeerIdentity *peer, 383 const struct GNUNET_PeerIdentity *peer,
386 const struct GNUNET_SCALARPRODUCT_Element *elements, 384 const struct GNUNET_SCALARPRODUCT_Element *elements,
387 uint32_t element_count, 385 uint32_t element_count,
388 GNUNET_SCALARPRODUCT_DatumProcessor cont, 386 GNUNET_SCALARPRODUCT_DatumProcessor cont,
389 void *cont_cls) 387 void *cont_cls)
390{ 388{
391 struct GNUNET_SCALARPRODUCT_ComputationHandle *h 389 struct GNUNET_SCALARPRODUCT_ComputationHandle *h
392 = GNUNET_new (struct GNUNET_SCALARPRODUCT_ComputationHandle); 390 = GNUNET_new(struct GNUNET_SCALARPRODUCT_ComputationHandle);
393 struct GNUNET_MQ_MessageHandler handlers[] = { 391 struct GNUNET_MQ_MessageHandler handlers[] = {
394 GNUNET_MQ_hd_var_size (response, 392 GNUNET_MQ_hd_var_size(response,
395 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_RESULT, 393 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_RESULT,
396 struct ClientResponseMessage, 394 struct ClientResponseMessage,
397 h), 395 h),
398 GNUNET_MQ_handler_end () 396 GNUNET_MQ_handler_end()
399 }; 397 };
400 struct GNUNET_MQ_Envelope *env; 398 struct GNUNET_MQ_Envelope *env;
401 struct AliceComputationMessage *msg; 399 struct AliceComputationMessage *msg;
@@ -405,64 +403,64 @@ GNUNET_SCALARPRODUCT_start_computation (const struct GNUNET_CONFIGURATION_Handle
405 uint16_t todo; 403 uint16_t todo;
406 uint32_t element_count_transfered; 404 uint32_t element_count_transfered;
407 405
408 if (GNUNET_SYSERR == check_unique (elements, 406 if (GNUNET_SYSERR == check_unique(elements,
409 element_count)) 407 element_count))
410 return NULL; 408 return NULL;
411 h->mq = GNUNET_CLIENT_connect (cfg, 409 h->mq = GNUNET_CLIENT_connect(cfg,
412 "scalarproduct-alice", 410 "scalarproduct-alice",
413 handlers, 411 handlers,
414 &mq_error_handler, 412 &mq_error_handler,
415 h); 413 h);
416 if (NULL == h->mq) 414 if (NULL == h->mq)
417 { 415 {
418 /* missconfigured scalarproduct service */ 416 /* missconfigured scalarproduct service */
419 GNUNET_break (0); 417 GNUNET_break(0);
420 GNUNET_free (h); 418 GNUNET_free(h);
421 return NULL; 419 return NULL;
422 } 420 }
423 h->cont_datum = cont; 421 h->cont_datum = cont;
424 h->cont_cls = cont_cls; 422 h->cont_cls = cont_cls;
425 h->response_proc = &process_result_message; 423 h->response_proc = &process_result_message;
426 h->cfg = cfg; 424 h->cfg = cfg;
427 h->key = *session_key; 425 h->key = *session_key;
428 426
429 possible = (GNUNET_MAX_MESSAGE_SIZE - 1 - sizeof (struct AliceComputationMessage)) 427 possible = (GNUNET_MAX_MESSAGE_SIZE - 1 - sizeof(struct AliceComputationMessage))
430 / sizeof (struct GNUNET_SCALARPRODUCT_Element); 428 / sizeof(struct GNUNET_SCALARPRODUCT_Element);
431 todo = GNUNET_MIN (possible, 429 todo = GNUNET_MIN(possible,
432 element_count); 430 element_count);
433 size = todo * sizeof (struct GNUNET_SCALARPRODUCT_Element); 431 size = todo * sizeof(struct GNUNET_SCALARPRODUCT_Element);
434 env = GNUNET_MQ_msg_extra (msg, 432 env = GNUNET_MQ_msg_extra(msg,
435 size, 433 size,
436 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_ALICE); 434 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_ALICE);
437 msg->element_count_total = htonl (element_count); 435 msg->element_count_total = htonl(element_count);
438 msg->element_count_contained = htonl (todo); 436 msg->element_count_contained = htonl(todo);
439 msg->reserved = htonl (0); 437 msg->reserved = htonl(0);
440 msg->peer = *peer; 438 msg->peer = *peer;
441 msg->session_key = *session_key; 439 msg->session_key = *session_key;
442 GNUNET_memcpy (&msg[1], 440 GNUNET_memcpy(&msg[1],
443 elements, 441 elements,
444 size); 442 size);
445 GNUNET_MQ_send (h->mq, 443 GNUNET_MQ_send(h->mq,
446 env); 444 env);
447 element_count_transfered = todo; 445 element_count_transfered = todo;
448 possible = (GNUNET_MAX_MESSAGE_SIZE - 1 - sizeof (*mmsg)) 446 possible = (GNUNET_MAX_MESSAGE_SIZE - 1 - sizeof(*mmsg))
449 / sizeof (struct GNUNET_SCALARPRODUCT_Element); 447 / sizeof(struct GNUNET_SCALARPRODUCT_Element);
450 while (element_count_transfered < element_count) 448 while (element_count_transfered < element_count)
451 { 449 {
452 todo = GNUNET_MIN (possible, 450 todo = GNUNET_MIN(possible,
453 element_count - element_count_transfered); 451 element_count - element_count_transfered);
454 size = todo * sizeof (struct GNUNET_SCALARPRODUCT_Element); 452 size = todo * sizeof(struct GNUNET_SCALARPRODUCT_Element);
455 env = GNUNET_MQ_msg_extra (mmsg, 453 env = GNUNET_MQ_msg_extra(mmsg,
456 size, 454 size,
457 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MULTIPART_ALICE); 455 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MULTIPART_ALICE);
458 mmsg->element_count_contained = htonl (todo); 456 mmsg->element_count_contained = htonl(todo);
459 GNUNET_memcpy (&mmsg[1], 457 GNUNET_memcpy(&mmsg[1],
460 &elements[element_count_transfered], 458 &elements[element_count_transfered],
461 size); 459 size);
462 element_count_transfered += todo; 460 element_count_transfered += todo;
463 GNUNET_MQ_send (h->mq, 461 GNUNET_MQ_send(h->mq,
464 env); 462 env);
465 } 463 }
466 return h; 464 return h;
467} 465}
468 466
@@ -474,14 +472,14 @@ GNUNET_SCALARPRODUCT_start_computation (const struct GNUNET_CONFIGURATION_Handle
474 * @param h computation handle to terminate 472 * @param h computation handle to terminate
475 */ 473 */
476void 474void
477GNUNET_SCALARPRODUCT_cancel (struct GNUNET_SCALARPRODUCT_ComputationHandle *h) 475GNUNET_SCALARPRODUCT_cancel(struct GNUNET_SCALARPRODUCT_ComputationHandle *h)
478{ 476{
479 if (NULL != h->mq) 477 if (NULL != h->mq)
480 { 478 {
481 GNUNET_MQ_destroy (h->mq); 479 GNUNET_MQ_destroy(h->mq);
482 h->mq = NULL; 480 h->mq = NULL;
483 } 481 }
484 GNUNET_free (h); 482 GNUNET_free(h);
485} 483}
486 484
487 485