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