diff options
Diffstat (limited to 'src/set/set_api.c')
-rw-r--r-- | src/set/set_api.c | 932 |
1 files changed, 469 insertions, 463 deletions
diff --git a/src/set/set_api.c b/src/set/set_api.c index 7db5abcbd..961bfdba9 100644 --- a/src/set/set_api.c +++ b/src/set/set_api.c | |||
@@ -30,9 +30,10 @@ | |||
30 | #include "set.h" | 30 | #include "set.h" |
31 | 31 | ||
32 | 32 | ||
33 | #define LOG(kind, ...) GNUNET_log_from(kind, "set-api", __VA_ARGS__) | 33 | #define LOG(kind, ...) GNUNET_log_from (kind, "set-api", __VA_ARGS__) |
34 | 34 | ||
35 | struct SetCopyRequest { | 35 | struct SetCopyRequest |
36 | { | ||
36 | struct SetCopyRequest *next; | 37 | struct SetCopyRequest *next; |
37 | 38 | ||
38 | struct SetCopyRequest *prev; | 39 | struct SetCopyRequest *prev; |
@@ -45,7 +46,8 @@ struct SetCopyRequest { | |||
45 | /** | 46 | /** |
46 | * Opaque handle to a set. | 47 | * Opaque handle to a set. |
47 | */ | 48 | */ |
48 | struct GNUNET_SET_Handle { | 49 | struct GNUNET_SET_Handle |
50 | { | ||
49 | /** | 51 | /** |
50 | * Message queue for @e client. | 52 | * Message queue for @e client. |
51 | */ | 53 | */ |
@@ -110,7 +112,8 @@ struct GNUNET_SET_Handle { | |||
110 | /** | 112 | /** |
111 | * Handle for a set operation request from another peer. | 113 | * Handle for a set operation request from another peer. |
112 | */ | 114 | */ |
113 | struct GNUNET_SET_Request { | 115 | struct GNUNET_SET_Request |
116 | { | ||
114 | /** | 117 | /** |
115 | * Id of the request, used to identify the request when | 118 | * Id of the request, used to identify the request when |
116 | * accepting/rejecting it. | 119 | * accepting/rejecting it. |
@@ -129,7 +132,8 @@ struct GNUNET_SET_Request { | |||
129 | * Handle to an operation. Only known to the service after committing | 132 | * Handle to an operation. Only known to the service after committing |
130 | * the handle with a set. | 133 | * the handle with a set. |
131 | */ | 134 | */ |
132 | struct GNUNET_SET_OperationHandle { | 135 | struct GNUNET_SET_OperationHandle |
136 | { | ||
133 | /** | 137 | /** |
134 | * Function to be called when we have a result, | 138 | * Function to be called when we have a result, |
135 | * or an error. | 139 | * or an error. |
@@ -179,11 +183,12 @@ struct GNUNET_SET_OperationHandle { | |||
179 | /** | 183 | /** |
180 | * Opaque handle to a listen operation. | 184 | * Opaque handle to a listen operation. |
181 | */ | 185 | */ |
182 | struct GNUNET_SET_ListenHandle { | 186 | struct GNUNET_SET_ListenHandle |
187 | { | ||
183 | /** | 188 | /** |
184 | * Message queue for the client. | 189 | * Message queue for the client. |
185 | */ | 190 | */ |
186 | struct GNUNET_MQ_Handle* mq; | 191 | struct GNUNET_MQ_Handle*mq; |
187 | 192 | ||
188 | /** | 193 | /** |
189 | * Configuration handle for the listener, stored | 194 | * Configuration handle for the listener, stored |
@@ -227,9 +232,9 @@ struct GNUNET_SET_ListenHandle { | |||
227 | 232 | ||
228 | /* mutual recursion with handle_copy_lazy */ | 233 | /* mutual recursion with handle_copy_lazy */ |
229 | static struct GNUNET_SET_Handle * | 234 | static struct GNUNET_SET_Handle * |
230 | create_internal(const struct GNUNET_CONFIGURATION_Handle *cfg, | 235 | create_internal (const struct GNUNET_CONFIGURATION_Handle *cfg, |
231 | enum GNUNET_SET_OperationType op, | 236 | enum GNUNET_SET_OperationType op, |
232 | const uint32_t *cookie); | 237 | const uint32_t *cookie); |
233 | 238 | ||
234 | 239 | ||
235 | /** | 240 | /** |
@@ -240,8 +245,8 @@ create_internal(const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
240 | * @param msg the message | 245 | * @param msg the message |
241 | */ | 246 | */ |
242 | static void | 247 | static void |
243 | handle_copy_lazy(void *cls, | 248 | handle_copy_lazy (void *cls, |
244 | const struct GNUNET_SET_CopyLazyResponseMessage *msg) | 249 | const struct GNUNET_SET_CopyLazyResponseMessage *msg) |
245 | { | 250 | { |
246 | struct GNUNET_SET_Handle *set = cls; | 251 | struct GNUNET_SET_Handle *set = cls; |
247 | struct SetCopyRequest *req; | 252 | struct SetCopyRequest *req; |
@@ -249,24 +254,24 @@ handle_copy_lazy(void *cls, | |||
249 | 254 | ||
250 | req = set->copy_req_head; | 255 | req = set->copy_req_head; |
251 | if (NULL == req) | 256 | if (NULL == req) |
252 | { | 257 | { |
253 | /* Service sent us unsolicited lazy copy response */ | 258 | /* Service sent us unsolicited lazy copy response */ |
254 | GNUNET_break(0); | 259 | GNUNET_break (0); |
255 | return; | 260 | return; |
256 | } | 261 | } |
257 | 262 | ||
258 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 263 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
259 | "Handling response to lazy copy\n"); | 264 | "Handling response to lazy copy\n"); |
260 | GNUNET_CONTAINER_DLL_remove(set->copy_req_head, | 265 | GNUNET_CONTAINER_DLL_remove (set->copy_req_head, |
261 | set->copy_req_tail, | 266 | set->copy_req_tail, |
262 | req); | 267 | req); |
263 | // We pass none as operation here, since it doesn't matter when | 268 | // We pass none as operation here, since it doesn't matter when |
264 | // cloning. | 269 | // cloning. |
265 | new_set = create_internal(set->cfg, | 270 | new_set = create_internal (set->cfg, |
266 | GNUNET_SET_OPERATION_NONE, | 271 | GNUNET_SET_OPERATION_NONE, |
267 | &msg->cookie); | 272 | &msg->cookie); |
268 | req->cb(req->cls, new_set); | 273 | req->cb (req->cls, new_set); |
269 | GNUNET_free(req); | 274 | GNUNET_free (req); |
270 | } | 275 | } |
271 | 276 | ||
272 | 277 | ||
@@ -278,8 +283,8 @@ handle_copy_lazy(void *cls, | |||
278 | * @return #GNUNET_OK if message is well-formed | 283 | * @return #GNUNET_OK if message is well-formed |
279 | */ | 284 | */ |
280 | static int | 285 | static int |
281 | check_iter_element(void *cls, | 286 | check_iter_element (void *cls, |
282 | const struct GNUNET_SET_IterResponseMessage *msg) | 287 | const struct GNUNET_SET_IterResponseMessage *msg) |
283 | { | 288 | { |
284 | /* minimum size was already checked, everything else is OK! */ | 289 | /* minimum size was already checked, everything else is OK! */ |
285 | return GNUNET_OK; | 290 | return GNUNET_OK; |
@@ -294,8 +299,8 @@ check_iter_element(void *cls, | |||
294 | * @param mh the message | 299 | * @param mh the message |
295 | */ | 300 | */ |
296 | static void | 301 | static void |
297 | handle_iter_element(void *cls, | 302 | handle_iter_element (void *cls, |
298 | const struct GNUNET_SET_IterResponseMessage *msg) | 303 | const struct GNUNET_SET_IterResponseMessage *msg) |
299 | { | 304 | { |
300 | struct GNUNET_SET_Handle *set = cls; | 305 | struct GNUNET_SET_Handle *set = cls; |
301 | GNUNET_SET_ElementIterator iter = set->iterator; | 306 | GNUNET_SET_ElementIterator iter = set->iterator; |
@@ -304,26 +309,26 @@ handle_iter_element(void *cls, | |||
304 | struct GNUNET_MQ_Envelope *ev; | 309 | struct GNUNET_MQ_Envelope *ev; |
305 | uint16_t msize; | 310 | uint16_t msize; |
306 | 311 | ||
307 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 312 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
308 | "Received element in set iteration\n"); | 313 | "Received element in set iteration\n"); |
309 | msize = ntohs(msg->header.size); | 314 | msize = ntohs (msg->header.size); |
310 | if (set->iteration_id != ntohs(msg->iteration_id)) | 315 | if (set->iteration_id != ntohs (msg->iteration_id)) |
311 | { | 316 | { |
312 | /* element from a previous iteration, skip! */ | 317 | /* element from a previous iteration, skip! */ |
313 | iter = NULL; | 318 | iter = NULL; |
314 | } | 319 | } |
315 | if (NULL != iter) | 320 | if (NULL != iter) |
316 | { | 321 | { |
317 | element.size = msize - sizeof(struct GNUNET_SET_IterResponseMessage); | 322 | element.size = msize - sizeof(struct GNUNET_SET_IterResponseMessage); |
318 | element.element_type = ntohs(msg->element_type); | 323 | element.element_type = ntohs (msg->element_type); |
319 | element.data = &msg[1]; | 324 | element.data = &msg[1]; |
320 | iter(set->iterator_cls, | 325 | iter (set->iterator_cls, |
321 | &element); | 326 | &element); |
322 | } | 327 | } |
323 | ev = GNUNET_MQ_msg(ack_msg, | 328 | ev = GNUNET_MQ_msg (ack_msg, |
324 | GNUNET_MESSAGE_TYPE_SET_ITER_ACK); | 329 | GNUNET_MESSAGE_TYPE_SET_ITER_ACK); |
325 | ack_msg->send_more = htonl((NULL != iter)); | 330 | ack_msg->send_more = htonl ((NULL != iter)); |
326 | GNUNET_MQ_send(set->mq, ev); | 331 | GNUNET_MQ_send (set->mq, ev); |
327 | } | 332 | } |
328 | 333 | ||
329 | 334 | ||
@@ -335,31 +340,31 @@ handle_iter_element(void *cls, | |||
335 | * @param mh the message | 340 | * @param mh the message |
336 | */ | 341 | */ |
337 | static void | 342 | static void |
338 | handle_iter_done(void *cls, | 343 | handle_iter_done (void *cls, |
339 | const struct GNUNET_MessageHeader *mh) | 344 | const struct GNUNET_MessageHeader *mh) |
340 | { | 345 | { |
341 | struct GNUNET_SET_Handle *set = cls; | 346 | struct GNUNET_SET_Handle *set = cls; |
342 | GNUNET_SET_ElementIterator iter = set->iterator; | 347 | GNUNET_SET_ElementIterator iter = set->iterator; |
343 | 348 | ||
344 | if (NULL == iter) | 349 | if (NULL == iter) |
345 | { | 350 | { |
346 | /* FIXME: if this is true, could cancel+start a fresh one | 351 | /* FIXME: if this is true, could cancel+start a fresh one |
347 | cause elements to go to the wrong iteration? */ | 352 | cause elements to go to the wrong iteration? */ |
348 | LOG(GNUNET_ERROR_TYPE_INFO, | 353 | LOG (GNUNET_ERROR_TYPE_INFO, |
349 | "Service completed set iteration that was already cancelled\n"); | 354 | "Service completed set iteration that was already cancelled\n"); |
350 | return; | 355 | return; |
351 | } | 356 | } |
352 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 357 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
353 | "Set iteration completed\n"); | 358 | "Set iteration completed\n"); |
354 | set->destroy_requested = GNUNET_SYSERR; | 359 | set->destroy_requested = GNUNET_SYSERR; |
355 | set->iterator = NULL; | 360 | set->iterator = NULL; |
356 | set->iteration_id++; | 361 | set->iteration_id++; |
357 | iter(set->iterator_cls, | 362 | iter (set->iterator_cls, |
358 | NULL); | 363 | NULL); |
359 | if (GNUNET_SYSERR == set->destroy_requested) | 364 | if (GNUNET_SYSERR == set->destroy_requested) |
360 | set->destroy_requested = GNUNET_NO; | 365 | set->destroy_requested = GNUNET_NO; |
361 | if (GNUNET_YES == set->destroy_requested) | 366 | if (GNUNET_YES == set->destroy_requested) |
362 | GNUNET_SET_destroy(set); | 367 | GNUNET_SET_destroy (set); |
363 | } | 368 | } |
364 | 369 | ||
365 | 370 | ||
@@ -371,8 +376,8 @@ handle_iter_done(void *cls, | |||
371 | * @return #GNUNET_OK if message is well-formed | 376 | * @return #GNUNET_OK if message is well-formed |
372 | */ | 377 | */ |
373 | static int | 378 | static int |
374 | check_result(void *cls, | 379 | check_result (void *cls, |
375 | const struct GNUNET_SET_ResultMessage *msg) | 380 | const struct GNUNET_SET_ResultMessage *msg) |
376 | { | 381 | { |
377 | /* minimum size was already checked, everything else is OK! */ | 382 | /* minimum size was already checked, everything else is OK! */ |
378 | return GNUNET_OK; | 383 | return GNUNET_OK; |
@@ -386,8 +391,8 @@ check_result(void *cls, | |||
386 | * @param mh the message | 391 | * @param mh the message |
387 | */ | 392 | */ |
388 | static void | 393 | static void |
389 | handle_result(void *cls, | 394 | handle_result (void *cls, |
390 | const struct GNUNET_SET_ResultMessage *msg) | 395 | const struct GNUNET_SET_ResultMessage *msg) |
391 | { | 396 | { |
392 | struct GNUNET_SET_Handle *set = cls; | 397 | struct GNUNET_SET_Handle *set = cls; |
393 | struct GNUNET_SET_OperationHandle *oh; | 398 | struct GNUNET_SET_OperationHandle *oh; |
@@ -395,80 +400,80 @@ handle_result(void *cls, | |||
395 | enum GNUNET_SET_Status result_status; | 400 | enum GNUNET_SET_Status result_status; |
396 | int destroy_set; | 401 | int destroy_set; |
397 | 402 | ||
398 | GNUNET_assert(NULL != set->mq); | 403 | GNUNET_assert (NULL != set->mq); |
399 | result_status = (enum GNUNET_SET_Status)ntohs(msg->result_status); | 404 | result_status = (enum GNUNET_SET_Status) ntohs (msg->result_status); |
400 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 405 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
401 | "Got result message with status %d\n", | 406 | "Got result message with status %d\n", |
402 | result_status); | 407 | result_status); |
403 | 408 | ||
404 | oh = GNUNET_MQ_assoc_get(set->mq, | 409 | oh = GNUNET_MQ_assoc_get (set->mq, |
405 | ntohl(msg->request_id)); | 410 | ntohl (msg->request_id)); |
406 | if (NULL == oh) | 411 | if (NULL == oh) |
407 | { | 412 | { |
408 | /* 'oh' can be NULL if we canceled the operation, but the service | 413 | /* 'oh' can be NULL if we canceled the operation, but the service |
409 | did not get the cancel message yet. */ | 414 | did not get the cancel message yet. */ |
410 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 415 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
411 | "Ignoring result from canceled operation\n"); | 416 | "Ignoring result from canceled operation\n"); |
412 | return; | 417 | return; |
413 | } | 418 | } |
414 | 419 | ||
415 | switch (result_status) | 420 | switch (result_status) |
416 | { | 421 | { |
417 | case GNUNET_SET_STATUS_OK: | 422 | case GNUNET_SET_STATUS_OK: |
418 | case GNUNET_SET_STATUS_ADD_LOCAL: | 423 | case GNUNET_SET_STATUS_ADD_LOCAL: |
419 | case GNUNET_SET_STATUS_ADD_REMOTE: | 424 | case GNUNET_SET_STATUS_ADD_REMOTE: |
420 | goto do_element; | 425 | goto do_element; |
421 | 426 | ||
422 | case GNUNET_SET_STATUS_FAILURE: | 427 | case GNUNET_SET_STATUS_FAILURE: |
423 | case GNUNET_SET_STATUS_DONE: | 428 | case GNUNET_SET_STATUS_DONE: |
424 | goto do_final; | 429 | goto do_final; |
425 | 430 | ||
426 | case GNUNET_SET_STATUS_HALF_DONE: | 431 | case GNUNET_SET_STATUS_HALF_DONE: |
427 | /* not used anymore */ | 432 | /* not used anymore */ |
428 | GNUNET_assert(0); | 433 | GNUNET_assert (0); |
429 | } | 434 | } |
430 | 435 | ||
431 | do_final: | 436 | do_final: |
432 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 437 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
433 | "Treating result as final status\n"); | 438 | "Treating result as final status\n"); |
434 | GNUNET_MQ_assoc_remove(set->mq, | 439 | GNUNET_MQ_assoc_remove (set->mq, |
435 | ntohl(msg->request_id)); | 440 | ntohl (msg->request_id)); |
436 | GNUNET_CONTAINER_DLL_remove(set->ops_head, | 441 | GNUNET_CONTAINER_DLL_remove (set->ops_head, |
437 | set->ops_tail, | 442 | set->ops_tail, |
438 | oh); | 443 | oh); |
439 | /* Need to do this calculation _before_ the result callback, | 444 | /* Need to do this calculation _before_ the result callback, |
440 | as IF the application still has a valid set handle, it | 445 | as IF the application still has a valid set handle, it |
441 | may trigger destruction of the set during the callback. */ | 446 | may trigger destruction of the set during the callback. */ |
442 | destroy_set = (GNUNET_YES == set->destroy_requested) && | 447 | destroy_set = (GNUNET_YES == set->destroy_requested) && |
443 | (NULL == set->ops_head); | 448 | (NULL == set->ops_head); |
444 | if (NULL != oh->result_cb) | 449 | if (NULL != oh->result_cb) |
445 | { | 450 | { |
446 | oh->result_cb(oh->result_cls, | 451 | oh->result_cb (oh->result_cls, |
447 | NULL, | 452 | NULL, |
448 | GNUNET_ntohll(msg->current_size), | 453 | GNUNET_ntohll (msg->current_size), |
449 | result_status); | 454 | result_status); |
450 | } | 455 | } |
451 | else | 456 | else |
452 | { | 457 | { |
453 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 458 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
454 | "No callback for final status\n"); | 459 | "No callback for final status\n"); |
455 | } | 460 | } |
456 | if (destroy_set) | 461 | if (destroy_set) |
457 | GNUNET_SET_destroy(set); | 462 | GNUNET_SET_destroy (set); |
458 | GNUNET_free(oh); | 463 | GNUNET_free (oh); |
459 | return; | 464 | return; |
460 | 465 | ||
461 | do_element: | 466 | do_element: |
462 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 467 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
463 | "Treating result as element\n"); | 468 | "Treating result as element\n"); |
464 | e.data = &msg[1]; | 469 | e.data = &msg[1]; |
465 | e.size = ntohs(msg->header.size) - sizeof(struct GNUNET_SET_ResultMessage); | 470 | e.size = ntohs (msg->header.size) - sizeof(struct GNUNET_SET_ResultMessage); |
466 | e.element_type = ntohs(msg->element_type); | 471 | e.element_type = ntohs (msg->element_type); |
467 | if (NULL != oh->result_cb) | 472 | if (NULL != oh->result_cb) |
468 | oh->result_cb(oh->result_cls, | 473 | oh->result_cb (oh->result_cls, |
469 | &e, | 474 | &e, |
470 | GNUNET_ntohll(msg->current_size), | 475 | GNUNET_ntohll (msg->current_size), |
471 | result_status); | 476 | result_status); |
472 | } | 477 | } |
473 | 478 | ||
474 | 479 | ||
@@ -478,25 +483,25 @@ do_element: | |||
478 | * @param oh set operation to destroy | 483 | * @param oh set operation to destroy |
479 | */ | 484 | */ |
480 | static void | 485 | static void |
481 | set_operation_destroy(struct GNUNET_SET_OperationHandle *oh) | 486 | set_operation_destroy (struct GNUNET_SET_OperationHandle *oh) |
482 | { | 487 | { |
483 | struct GNUNET_SET_Handle *set = oh->set; | 488 | struct GNUNET_SET_Handle *set = oh->set; |
484 | struct GNUNET_SET_OperationHandle *h_assoc; | 489 | struct GNUNET_SET_OperationHandle *h_assoc; |
485 | 490 | ||
486 | if (NULL != oh->conclude_mqm) | 491 | if (NULL != oh->conclude_mqm) |
487 | GNUNET_MQ_discard(oh->conclude_mqm); | 492 | GNUNET_MQ_discard (oh->conclude_mqm); |
488 | /* is the operation already commited? */ | 493 | /* is the operation already commited? */ |
489 | if (NULL != set) | 494 | if (NULL != set) |
490 | { | 495 | { |
491 | GNUNET_CONTAINER_DLL_remove(set->ops_head, | 496 | GNUNET_CONTAINER_DLL_remove (set->ops_head, |
492 | set->ops_tail, | 497 | set->ops_tail, |
493 | oh); | 498 | oh); |
494 | h_assoc = GNUNET_MQ_assoc_remove(set->mq, | 499 | h_assoc = GNUNET_MQ_assoc_remove (set->mq, |
495 | oh->request_id); | 500 | oh->request_id); |
496 | GNUNET_assert((NULL == h_assoc) || | 501 | GNUNET_assert ((NULL == h_assoc) || |
497 | (h_assoc == oh)); | 502 | (h_assoc == oh)); |
498 | } | 503 | } |
499 | GNUNET_free(oh); | 504 | GNUNET_free (oh); |
500 | } | 505 | } |
501 | 506 | ||
502 | 507 | ||
@@ -508,29 +513,29 @@ set_operation_destroy(struct GNUNET_SET_OperationHandle *oh) | |||
508 | * @param oh set operation to cancel | 513 | * @param oh set operation to cancel |
509 | */ | 514 | */ |
510 | void | 515 | void |
511 | GNUNET_SET_operation_cancel(struct GNUNET_SET_OperationHandle *oh) | 516 | GNUNET_SET_operation_cancel (struct GNUNET_SET_OperationHandle *oh) |
512 | { | 517 | { |
513 | struct GNUNET_SET_Handle *set = oh->set; | 518 | struct GNUNET_SET_Handle *set = oh->set; |
514 | struct GNUNET_SET_CancelMessage *m; | 519 | struct GNUNET_SET_CancelMessage *m; |
515 | struct GNUNET_MQ_Envelope *mqm; | 520 | struct GNUNET_MQ_Envelope *mqm; |
516 | 521 | ||
517 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 522 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
518 | "Cancelling SET operation\n"); | 523 | "Cancelling SET operation\n"); |
519 | if (NULL != set) | 524 | if (NULL != set) |
520 | { | 525 | { |
521 | mqm = GNUNET_MQ_msg(m, GNUNET_MESSAGE_TYPE_SET_CANCEL); | 526 | mqm = GNUNET_MQ_msg (m, GNUNET_MESSAGE_TYPE_SET_CANCEL); |
522 | m->request_id = htonl(oh->request_id); | 527 | m->request_id = htonl (oh->request_id); |
523 | GNUNET_MQ_send(set->mq, mqm); | 528 | GNUNET_MQ_send (set->mq, mqm); |
524 | } | 529 | } |
525 | set_operation_destroy(oh); | 530 | set_operation_destroy (oh); |
526 | if ((NULL != set) && | 531 | if ((NULL != set) && |
527 | (GNUNET_YES == set->destroy_requested) && | 532 | (GNUNET_YES == set->destroy_requested) && |
528 | (NULL == set->ops_head)) | 533 | (NULL == set->ops_head)) |
529 | { | 534 | { |
530 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 535 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
531 | "Destroying set after operation cancel\n"); | 536 | "Destroying set after operation cancel\n"); |
532 | GNUNET_SET_destroy(set); | 537 | GNUNET_SET_destroy (set); |
533 | } | 538 | } |
534 | } | 539 | } |
535 | 540 | ||
536 | 541 | ||
@@ -542,31 +547,31 @@ GNUNET_SET_operation_cancel(struct GNUNET_SET_OperationHandle *oh) | |||
542 | * @param error error code | 547 | * @param error error code |
543 | */ | 548 | */ |
544 | static void | 549 | static void |
545 | handle_client_set_error(void *cls, | 550 | handle_client_set_error (void *cls, |
546 | enum GNUNET_MQ_Error error) | 551 | enum GNUNET_MQ_Error error) |
547 | { | 552 | { |
548 | struct GNUNET_SET_Handle *set = cls; | 553 | struct GNUNET_SET_Handle *set = cls; |
549 | GNUNET_SET_ElementIterator iter = set->iterator; | 554 | GNUNET_SET_ElementIterator iter = set->iterator; |
550 | 555 | ||
551 | LOG(GNUNET_ERROR_TYPE_ERROR, | 556 | LOG (GNUNET_ERROR_TYPE_ERROR, |
552 | "Handling client set error %d\n", | 557 | "Handling client set error %d\n", |
553 | error); | 558 | error); |
554 | while (NULL != set->ops_head) | 559 | while (NULL != set->ops_head) |
555 | { | 560 | { |
556 | if ((NULL != set->ops_head->result_cb) && | 561 | if ((NULL != set->ops_head->result_cb) && |
557 | (GNUNET_NO == set->destroy_requested)) | 562 | (GNUNET_NO == set->destroy_requested)) |
558 | set->ops_head->result_cb(set->ops_head->result_cls, | 563 | set->ops_head->result_cb (set->ops_head->result_cls, |
559 | NULL, | 564 | NULL, |
560 | 0, | 565 | 0, |
561 | GNUNET_SET_STATUS_FAILURE); | 566 | GNUNET_SET_STATUS_FAILURE); |
562 | set_operation_destroy(set->ops_head); | 567 | set_operation_destroy (set->ops_head); |
563 | } | 568 | } |
564 | set->iterator = NULL; | 569 | set->iterator = NULL; |
565 | set->iteration_id++; | 570 | set->iteration_id++; |
566 | set->invalid = GNUNET_YES; | 571 | set->invalid = GNUNET_YES; |
567 | if (NULL != iter) | 572 | if (NULL != iter) |
568 | iter(set->iterator_cls, | 573 | iter (set->iterator_cls, |
569 | NULL); | 574 | NULL); |
570 | } | 575 | } |
571 | 576 | ||
572 | 577 | ||
@@ -574,65 +579,65 @@ handle_client_set_error(void *cls, | |||
574 | * FIXME. | 579 | * FIXME. |
575 | */ | 580 | */ |
576 | static struct GNUNET_SET_Handle * | 581 | static struct GNUNET_SET_Handle * |
577 | create_internal(const struct GNUNET_CONFIGURATION_Handle *cfg, | 582 | create_internal (const struct GNUNET_CONFIGURATION_Handle *cfg, |
578 | enum GNUNET_SET_OperationType op, | 583 | enum GNUNET_SET_OperationType op, |
579 | const uint32_t *cookie) | 584 | const uint32_t *cookie) |
580 | { | 585 | { |
581 | struct GNUNET_SET_Handle *set = GNUNET_new(struct GNUNET_SET_Handle); | 586 | struct GNUNET_SET_Handle *set = GNUNET_new (struct GNUNET_SET_Handle); |
582 | struct GNUNET_MQ_MessageHandler mq_handlers[] = { | 587 | struct GNUNET_MQ_MessageHandler mq_handlers[] = { |
583 | GNUNET_MQ_hd_var_size(result, | 588 | GNUNET_MQ_hd_var_size (result, |
584 | GNUNET_MESSAGE_TYPE_SET_RESULT, | 589 | GNUNET_MESSAGE_TYPE_SET_RESULT, |
585 | struct GNUNET_SET_ResultMessage, | 590 | struct GNUNET_SET_ResultMessage, |
586 | set), | 591 | set), |
587 | GNUNET_MQ_hd_var_size(iter_element, | 592 | GNUNET_MQ_hd_var_size (iter_element, |
588 | GNUNET_MESSAGE_TYPE_SET_ITER_ELEMENT, | 593 | GNUNET_MESSAGE_TYPE_SET_ITER_ELEMENT, |
589 | struct GNUNET_SET_IterResponseMessage, | 594 | struct GNUNET_SET_IterResponseMessage, |
590 | set), | 595 | set), |
591 | GNUNET_MQ_hd_fixed_size(iter_done, | 596 | GNUNET_MQ_hd_fixed_size (iter_done, |
592 | GNUNET_MESSAGE_TYPE_SET_ITER_DONE, | 597 | GNUNET_MESSAGE_TYPE_SET_ITER_DONE, |
593 | struct GNUNET_MessageHeader, | 598 | struct GNUNET_MessageHeader, |
594 | set), | 599 | set), |
595 | GNUNET_MQ_hd_fixed_size(copy_lazy, | 600 | GNUNET_MQ_hd_fixed_size (copy_lazy, |
596 | GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_RESPONSE, | 601 | GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_RESPONSE, |
597 | struct GNUNET_SET_CopyLazyResponseMessage, | 602 | struct GNUNET_SET_CopyLazyResponseMessage, |
598 | set), | 603 | set), |
599 | GNUNET_MQ_handler_end() | 604 | GNUNET_MQ_handler_end () |
600 | }; | 605 | }; |
601 | struct GNUNET_MQ_Envelope *mqm; | 606 | struct GNUNET_MQ_Envelope *mqm; |
602 | struct GNUNET_SET_CreateMessage *create_msg; | 607 | struct GNUNET_SET_CreateMessage *create_msg; |
603 | struct GNUNET_SET_CopyLazyConnectMessage *copy_msg; | 608 | struct GNUNET_SET_CopyLazyConnectMessage *copy_msg; |
604 | 609 | ||
605 | set->cfg = cfg; | 610 | set->cfg = cfg; |
606 | set->mq = GNUNET_CLIENT_connect(cfg, | 611 | set->mq = GNUNET_CLIENT_connect (cfg, |
607 | "set", | 612 | "set", |
608 | mq_handlers, | 613 | mq_handlers, |
609 | &handle_client_set_error, | 614 | &handle_client_set_error, |
610 | set); | 615 | set); |
611 | if (NULL == set->mq) | 616 | if (NULL == set->mq) |
612 | { | 617 | { |
613 | GNUNET_free(set); | 618 | GNUNET_free (set); |
614 | return NULL; | 619 | return NULL; |
615 | } | 620 | } |
616 | if (NULL == cookie) | 621 | if (NULL == cookie) |
617 | { | 622 | { |
618 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 623 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
619 | "Creating new set (operation %u)\n", | 624 | "Creating new set (operation %u)\n", |
620 | op); | 625 | op); |
621 | mqm = GNUNET_MQ_msg(create_msg, | 626 | mqm = GNUNET_MQ_msg (create_msg, |
622 | GNUNET_MESSAGE_TYPE_SET_CREATE); | 627 | GNUNET_MESSAGE_TYPE_SET_CREATE); |
623 | create_msg->operation = htonl(op); | 628 | create_msg->operation = htonl (op); |
624 | } | 629 | } |
625 | else | 630 | else |
626 | { | 631 | { |
627 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 632 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
628 | "Creating new set (lazy copy)\n", | 633 | "Creating new set (lazy copy)\n", |
629 | op); | 634 | op); |
630 | mqm = GNUNET_MQ_msg(copy_msg, | 635 | mqm = GNUNET_MQ_msg (copy_msg, |
631 | GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_CONNECT); | 636 | GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_CONNECT); |
632 | copy_msg->cookie = *cookie; | 637 | copy_msg->cookie = *cookie; |
633 | } | 638 | } |
634 | GNUNET_MQ_send(set->mq, | 639 | GNUNET_MQ_send (set->mq, |
635 | mqm); | 640 | mqm); |
636 | return set; | 641 | return set; |
637 | } | 642 | } |
638 | 643 | ||
@@ -649,18 +654,18 @@ create_internal(const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
649 | * @return a handle to the set | 654 | * @return a handle to the set |
650 | */ | 655 | */ |
651 | struct GNUNET_SET_Handle * | 656 | struct GNUNET_SET_Handle * |
652 | GNUNET_SET_create(const struct GNUNET_CONFIGURATION_Handle *cfg, | 657 | GNUNET_SET_create (const struct GNUNET_CONFIGURATION_Handle *cfg, |
653 | enum GNUNET_SET_OperationType op) | 658 | enum GNUNET_SET_OperationType op) |
654 | { | 659 | { |
655 | struct GNUNET_SET_Handle *set; | 660 | struct GNUNET_SET_Handle *set; |
656 | 661 | ||
657 | set = create_internal(cfg, | 662 | set = create_internal (cfg, |
658 | op, | 663 | op, |
659 | NULL); | 664 | NULL); |
660 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 665 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
661 | "Creating set %p for operation %d\n", | 666 | "Creating set %p for operation %d\n", |
662 | set, | 667 | set, |
663 | op); | 668 | op); |
664 | return set; | 669 | return set; |
665 | } | 670 | } |
666 | 671 | ||
@@ -679,35 +684,35 @@ GNUNET_SET_create(const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
679 | * set is invalid (e.g. the set service crashed) | 684 | * set is invalid (e.g. the set service crashed) |
680 | */ | 685 | */ |
681 | int | 686 | int |
682 | GNUNET_SET_add_element(struct GNUNET_SET_Handle *set, | 687 | GNUNET_SET_add_element (struct GNUNET_SET_Handle *set, |
683 | const struct GNUNET_SET_Element *element, | 688 | const struct GNUNET_SET_Element *element, |
684 | GNUNET_SET_Continuation cont, | 689 | GNUNET_SET_Continuation cont, |
685 | void *cont_cls) | 690 | void *cont_cls) |
686 | { | 691 | { |
687 | struct GNUNET_MQ_Envelope *mqm; | 692 | struct GNUNET_MQ_Envelope *mqm; |
688 | struct GNUNET_SET_ElementMessage *msg; | 693 | struct GNUNET_SET_ElementMessage *msg; |
689 | 694 | ||
690 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 695 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
691 | "adding element of type %u to set %p\n", | 696 | "adding element of type %u to set %p\n", |
692 | (unsigned int)element->element_type, | 697 | (unsigned int) element->element_type, |
693 | set); | 698 | set); |
694 | GNUNET_assert(NULL != set); | 699 | GNUNET_assert (NULL != set); |
695 | if (GNUNET_YES == set->invalid) | 700 | if (GNUNET_YES == set->invalid) |
696 | { | 701 | { |
697 | if (NULL != cont) | 702 | if (NULL != cont) |
698 | cont(cont_cls); | 703 | cont (cont_cls); |
699 | return GNUNET_SYSERR; | 704 | return GNUNET_SYSERR; |
700 | } | 705 | } |
701 | mqm = GNUNET_MQ_msg_extra(msg, | 706 | mqm = GNUNET_MQ_msg_extra (msg, |
702 | element->size, | 707 | element->size, |
703 | GNUNET_MESSAGE_TYPE_SET_ADD); | 708 | GNUNET_MESSAGE_TYPE_SET_ADD); |
704 | msg->element_type = htons(element->element_type); | 709 | msg->element_type = htons (element->element_type); |
705 | GNUNET_memcpy(&msg[1], | 710 | GNUNET_memcpy (&msg[1], |
706 | element->data, | 711 | element->data, |
707 | element->size); | 712 | element->size); |
708 | GNUNET_MQ_notify_sent(mqm, | 713 | GNUNET_MQ_notify_sent (mqm, |
709 | cont, cont_cls); | 714 | cont, cont_cls); |
710 | GNUNET_MQ_send(set->mq, mqm); | 715 | GNUNET_MQ_send (set->mq, mqm); |
711 | return GNUNET_OK; | 716 | return GNUNET_OK; |
712 | } | 717 | } |
713 | 718 | ||
@@ -726,33 +731,33 @@ GNUNET_SET_add_element(struct GNUNET_SET_Handle *set, | |||
726 | * set is invalid (e.g. the set service crashed) | 731 | * set is invalid (e.g. the set service crashed) |
727 | */ | 732 | */ |
728 | int | 733 | int |
729 | GNUNET_SET_remove_element(struct GNUNET_SET_Handle *set, | 734 | GNUNET_SET_remove_element (struct GNUNET_SET_Handle *set, |
730 | const struct GNUNET_SET_Element *element, | 735 | const struct GNUNET_SET_Element *element, |
731 | GNUNET_SET_Continuation cont, | 736 | GNUNET_SET_Continuation cont, |
732 | void *cont_cls) | 737 | void *cont_cls) |
733 | { | 738 | { |
734 | struct GNUNET_MQ_Envelope *mqm; | 739 | struct GNUNET_MQ_Envelope *mqm; |
735 | struct GNUNET_SET_ElementMessage *msg; | 740 | struct GNUNET_SET_ElementMessage *msg; |
736 | 741 | ||
737 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 742 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
738 | "Removing element from set %p\n", | 743 | "Removing element from set %p\n", |
739 | set); | 744 | set); |
740 | if (GNUNET_YES == set->invalid) | 745 | if (GNUNET_YES == set->invalid) |
741 | { | 746 | { |
742 | if (NULL != cont) | 747 | if (NULL != cont) |
743 | cont(cont_cls); | 748 | cont (cont_cls); |
744 | return GNUNET_SYSERR; | 749 | return GNUNET_SYSERR; |
745 | } | 750 | } |
746 | mqm = GNUNET_MQ_msg_extra(msg, | 751 | mqm = GNUNET_MQ_msg_extra (msg, |
747 | element->size, | 752 | element->size, |
748 | GNUNET_MESSAGE_TYPE_SET_REMOVE); | 753 | GNUNET_MESSAGE_TYPE_SET_REMOVE); |
749 | msg->element_type = htons(element->element_type); | 754 | msg->element_type = htons (element->element_type); |
750 | GNUNET_memcpy(&msg[1], | 755 | GNUNET_memcpy (&msg[1], |
751 | element->data, | 756 | element->data, |
752 | element->size); | 757 | element->size); |
753 | GNUNET_MQ_notify_sent(mqm, | 758 | GNUNET_MQ_notify_sent (mqm, |
754 | cont, cont_cls); | 759 | cont, cont_cls); |
755 | GNUNET_MQ_send(set->mq, mqm); | 760 | GNUNET_MQ_send (set->mq, mqm); |
756 | return GNUNET_OK; | 761 | return GNUNET_OK; |
757 | } | 762 | } |
758 | 763 | ||
@@ -764,29 +769,29 @@ GNUNET_SET_remove_element(struct GNUNET_SET_Handle *set, | |||
764 | * @param set set handle to destroy | 769 | * @param set set handle to destroy |
765 | */ | 770 | */ |
766 | void | 771 | void |
767 | GNUNET_SET_destroy(struct GNUNET_SET_Handle *set) | 772 | GNUNET_SET_destroy (struct GNUNET_SET_Handle *set) |
768 | { | 773 | { |
769 | /* destroying set while iterator is active is currently | 774 | /* destroying set while iterator is active is currently |
770 | not supported; we should expand the API to allow | 775 | not supported; we should expand the API to allow |
771 | clients to explicitly cancel the iteration! */ | 776 | clients to explicitly cancel the iteration! */ |
772 | GNUNET_assert(NULL != set); | 777 | GNUNET_assert (NULL != set); |
773 | if ((NULL != set->ops_head) || | 778 | if ((NULL != set->ops_head) || |
774 | (NULL != set->iterator) || | 779 | (NULL != set->iterator) || |
775 | (GNUNET_SYSERR == set->destroy_requested)) | 780 | (GNUNET_SYSERR == set->destroy_requested)) |
776 | { | 781 | { |
777 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 782 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
778 | "Set operations are pending, delaying set destruction\n"); | 783 | "Set operations are pending, delaying set destruction\n"); |
779 | set->destroy_requested = GNUNET_YES; | 784 | set->destroy_requested = GNUNET_YES; |
780 | return; | 785 | return; |
781 | } | 786 | } |
782 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 787 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
783 | "Really destroying set\n"); | 788 | "Really destroying set\n"); |
784 | if (NULL != set->mq) | 789 | if (NULL != set->mq) |
785 | { | 790 | { |
786 | GNUNET_MQ_destroy(set->mq); | 791 | GNUNET_MQ_destroy (set->mq); |
787 | set->mq = NULL; | 792 | set->mq = NULL; |
788 | } | 793 | } |
789 | GNUNET_free(set); | 794 | GNUNET_free (set); |
790 | } | 795 | } |
791 | 796 | ||
792 | 797 | ||
@@ -805,53 +810,53 @@ GNUNET_SET_destroy(struct GNUNET_SET_Handle *set) | |||
805 | * @return a handle to cancel the operation | 810 | * @return a handle to cancel the operation |
806 | */ | 811 | */ |
807 | struct GNUNET_SET_OperationHandle * | 812 | struct GNUNET_SET_OperationHandle * |
808 | GNUNET_SET_prepare(const struct GNUNET_PeerIdentity *other_peer, | 813 | GNUNET_SET_prepare (const struct GNUNET_PeerIdentity *other_peer, |
809 | const struct GNUNET_HashCode *app_id, | 814 | const struct GNUNET_HashCode *app_id, |
810 | const struct GNUNET_MessageHeader *context_msg, | 815 | const struct GNUNET_MessageHeader *context_msg, |
811 | enum GNUNET_SET_ResultMode result_mode, | 816 | enum GNUNET_SET_ResultMode result_mode, |
812 | struct GNUNET_SET_Option options[], | 817 | struct GNUNET_SET_Option options[], |
813 | GNUNET_SET_ResultIterator result_cb, | 818 | GNUNET_SET_ResultIterator result_cb, |
814 | void *result_cls) | 819 | void *result_cls) |
815 | { | 820 | { |
816 | struct GNUNET_MQ_Envelope *mqm; | 821 | struct GNUNET_MQ_Envelope *mqm; |
817 | struct GNUNET_SET_OperationHandle *oh; | 822 | struct GNUNET_SET_OperationHandle *oh; |
818 | struct GNUNET_SET_EvaluateMessage *msg; | 823 | struct GNUNET_SET_EvaluateMessage *msg; |
819 | struct GNUNET_SET_Option *opt; | 824 | struct GNUNET_SET_Option *opt; |
820 | 825 | ||
821 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 826 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
822 | "Client prepares set operation (%d)\n", | 827 | "Client prepares set operation (%d)\n", |
823 | result_mode); | 828 | result_mode); |
824 | oh = GNUNET_new(struct GNUNET_SET_OperationHandle); | 829 | oh = GNUNET_new (struct GNUNET_SET_OperationHandle); |
825 | oh->result_cb = result_cb; | 830 | oh->result_cb = result_cb; |
826 | oh->result_cls = result_cls; | 831 | oh->result_cls = result_cls; |
827 | mqm = GNUNET_MQ_msg_nested_mh(msg, | 832 | mqm = GNUNET_MQ_msg_nested_mh (msg, |
828 | GNUNET_MESSAGE_TYPE_SET_EVALUATE, | 833 | GNUNET_MESSAGE_TYPE_SET_EVALUATE, |
829 | context_msg); | 834 | context_msg); |
830 | msg->app_id = *app_id; | 835 | msg->app_id = *app_id; |
831 | msg->result_mode = htonl(result_mode); | 836 | msg->result_mode = htonl (result_mode); |
832 | msg->target_peer = *other_peer; | 837 | msg->target_peer = *other_peer; |
833 | for (opt = options; opt->type != 0; opt++) | 838 | for (opt = options; opt->type != 0; opt++) |
839 | { | ||
840 | switch (opt->type) | ||
834 | { | 841 | { |
835 | switch (opt->type) | 842 | case GNUNET_SET_OPTION_BYZANTINE: |
836 | { | 843 | msg->byzantine = GNUNET_YES; |
837 | case GNUNET_SET_OPTION_BYZANTINE: | 844 | msg->byzantine_lower_bound = opt->v.num; |
838 | msg->byzantine = GNUNET_YES; | 845 | break; |
839 | msg->byzantine_lower_bound = opt->v.num; | 846 | |
840 | break; | 847 | case GNUNET_SET_OPTION_FORCE_FULL: |
841 | 848 | msg->force_full = GNUNET_YES; | |
842 | case GNUNET_SET_OPTION_FORCE_FULL: | 849 | break; |
843 | msg->force_full = GNUNET_YES; | 850 | |
844 | break; | 851 | case GNUNET_SET_OPTION_FORCE_DELTA: |
845 | 852 | msg->force_delta = GNUNET_YES; | |
846 | case GNUNET_SET_OPTION_FORCE_DELTA: | 853 | break; |
847 | msg->force_delta = GNUNET_YES; | 854 | |
848 | break; | 855 | default: |
849 | 856 | LOG (GNUNET_ERROR_TYPE_ERROR, | |
850 | default: | 857 | "Option with type %d not recognized\n", (int) opt->type); |
851 | LOG(GNUNET_ERROR_TYPE_ERROR, | ||
852 | "Option with type %d not recognized\n", (int)opt->type); | ||
853 | } | ||
854 | } | 858 | } |
859 | } | ||
855 | oh->conclude_mqm = mqm; | 860 | oh->conclude_mqm = mqm; |
856 | oh->request_id_addr = &msg->request_id; | 861 | oh->request_id_addr = &msg->request_id; |
857 | 862 | ||
@@ -865,7 +870,7 @@ GNUNET_SET_prepare(const struct GNUNET_PeerIdentity *other_peer, | |||
865 | * @param cls the `struct GNUNET_SET_ListenHandle *` to connect | 870 | * @param cls the `struct GNUNET_SET_ListenHandle *` to connect |
866 | */ | 871 | */ |
867 | static void | 872 | static void |
868 | listen_connect(void *cls); | 873 | listen_connect (void *cls); |
869 | 874 | ||
870 | 875 | ||
871 | /** | 876 | /** |
@@ -876,20 +881,20 @@ listen_connect(void *cls); | |||
876 | * @return #GNUNET_OK if the message is well-formed | 881 | * @return #GNUNET_OK if the message is well-formed |
877 | */ | 882 | */ |
878 | static int | 883 | static int |
879 | check_request(void *cls, | 884 | check_request (void *cls, |
880 | const struct GNUNET_SET_RequestMessage *msg) | 885 | const struct GNUNET_SET_RequestMessage *msg) |
881 | { | 886 | { |
882 | const struct GNUNET_MessageHeader *context_msg; | 887 | const struct GNUNET_MessageHeader *context_msg; |
883 | 888 | ||
884 | if (ntohs(msg->header.size) == sizeof(*msg)) | 889 | if (ntohs (msg->header.size) == sizeof(*msg)) |
885 | return GNUNET_OK; /* no context message is OK */ | 890 | return GNUNET_OK; /* no context message is OK */ |
886 | context_msg = GNUNET_MQ_extract_nested_mh(msg); | 891 | context_msg = GNUNET_MQ_extract_nested_mh (msg); |
887 | if (NULL == context_msg) | 892 | if (NULL == context_msg) |
888 | { | 893 | { |
889 | /* malformed context message is NOT ok */ | 894 | /* malformed context message is NOT ok */ |
890 | GNUNET_break_op(0); | 895 | GNUNET_break_op (0); |
891 | return GNUNET_SYSERR; | 896 | return GNUNET_SYSERR; |
892 | } | 897 | } |
893 | return GNUNET_OK; | 898 | return GNUNET_OK; |
894 | } | 899 | } |
895 | 900 | ||
@@ -901,8 +906,8 @@ check_request(void *cls, | |||
901 | * @param msg the message | 906 | * @param msg the message |
902 | */ | 907 | */ |
903 | static void | 908 | static void |
904 | handle_request(void *cls, | 909 | handle_request (void *cls, |
905 | const struct GNUNET_SET_RequestMessage *msg) | 910 | const struct GNUNET_SET_RequestMessage *msg) |
906 | { | 911 | { |
907 | struct GNUNET_SET_ListenHandle *lh = cls; | 912 | struct GNUNET_SET_ListenHandle *lh = cls; |
908 | struct GNUNET_SET_Request req; | 913 | struct GNUNET_SET_Request req; |
@@ -910,28 +915,28 @@ handle_request(void *cls, | |||
910 | struct GNUNET_MQ_Envelope *mqm; | 915 | struct GNUNET_MQ_Envelope *mqm; |
911 | struct GNUNET_SET_RejectMessage *rmsg; | 916 | struct GNUNET_SET_RejectMessage *rmsg; |
912 | 917 | ||
913 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 918 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
914 | "Processing incoming operation request with id %u\n", | 919 | "Processing incoming operation request with id %u\n", |
915 | ntohl(msg->accept_id)); | 920 | ntohl (msg->accept_id)); |
916 | /* we got another valid request => reset the backoff */ | 921 | /* we got another valid request => reset the backoff */ |
917 | lh->reconnect_backoff = GNUNET_TIME_UNIT_MILLISECONDS; | 922 | lh->reconnect_backoff = GNUNET_TIME_UNIT_MILLISECONDS; |
918 | req.accept_id = ntohl(msg->accept_id); | 923 | req.accept_id = ntohl (msg->accept_id); |
919 | req.accepted = GNUNET_NO; | 924 | req.accepted = GNUNET_NO; |
920 | context_msg = GNUNET_MQ_extract_nested_mh(msg); | 925 | context_msg = GNUNET_MQ_extract_nested_mh (msg); |
921 | /* calling #GNUNET_SET_accept() in the listen cb will set req->accepted */ | 926 | /* calling #GNUNET_SET_accept() in the listen cb will set req->accepted */ |
922 | lh->listen_cb(lh->listen_cls, | 927 | lh->listen_cb (lh->listen_cls, |
923 | &msg->peer_id, | 928 | &msg->peer_id, |
924 | context_msg, | 929 | context_msg, |
925 | &req); | 930 | &req); |
926 | if (GNUNET_YES == req.accepted) | 931 | if (GNUNET_YES == req.accepted) |
927 | return; /* the accept-case is handled in #GNUNET_SET_accept() */ | 932 | return; /* the accept-case is handled in #GNUNET_SET_accept() */ |
928 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 933 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
929 | "Rejected request %u\n", | 934 | "Rejected request %u\n", |
930 | ntohl(msg->accept_id)); | 935 | ntohl (msg->accept_id)); |
931 | mqm = GNUNET_MQ_msg(rmsg, | 936 | mqm = GNUNET_MQ_msg (rmsg, |
932 | GNUNET_MESSAGE_TYPE_SET_REJECT); | 937 | GNUNET_MESSAGE_TYPE_SET_REJECT); |
933 | rmsg->accept_reject_id = msg->accept_id; | 938 | rmsg->accept_reject_id = msg->accept_id; |
934 | GNUNET_MQ_send(lh->mq, mqm); | 939 | GNUNET_MQ_send (lh->mq, mqm); |
935 | } | 940 | } |
936 | 941 | ||
937 | 942 | ||
@@ -943,20 +948,20 @@ handle_request(void *cls, | |||
943 | * @param error reason for the disconnect | 948 | * @param error reason for the disconnect |
944 | */ | 949 | */ |
945 | static void | 950 | static void |
946 | handle_client_listener_error(void *cls, | 951 | handle_client_listener_error (void *cls, |
947 | enum GNUNET_MQ_Error error) | 952 | enum GNUNET_MQ_Error error) |
948 | { | 953 | { |
949 | struct GNUNET_SET_ListenHandle *lh = cls; | 954 | struct GNUNET_SET_ListenHandle *lh = cls; |
950 | 955 | ||
951 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 956 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
952 | "Listener broke down (%d), re-connecting\n", | 957 | "Listener broke down (%d), re-connecting\n", |
953 | (int)error); | 958 | (int) error); |
954 | GNUNET_MQ_destroy(lh->mq); | 959 | GNUNET_MQ_destroy (lh->mq); |
955 | lh->mq = NULL; | 960 | lh->mq = NULL; |
956 | lh->reconnect_task = GNUNET_SCHEDULER_add_delayed(lh->reconnect_backoff, | 961 | lh->reconnect_task = GNUNET_SCHEDULER_add_delayed (lh->reconnect_backoff, |
957 | &listen_connect, | 962 | &listen_connect, |
958 | lh); | 963 | lh); |
959 | lh->reconnect_backoff = GNUNET_TIME_STD_BACKOFF(lh->reconnect_backoff); | 964 | lh->reconnect_backoff = GNUNET_TIME_STD_BACKOFF (lh->reconnect_backoff); |
960 | } | 965 | } |
961 | 966 | ||
962 | 967 | ||
@@ -966,33 +971,33 @@ handle_client_listener_error(void *cls, | |||
966 | * @param cls the `struct GNUNET_SET_ListenHandle *` to connect | 971 | * @param cls the `struct GNUNET_SET_ListenHandle *` to connect |
967 | */ | 972 | */ |
968 | static void | 973 | static void |
969 | listen_connect(void *cls) | 974 | listen_connect (void *cls) |
970 | { | 975 | { |
971 | struct GNUNET_SET_ListenHandle *lh = cls; | 976 | struct GNUNET_SET_ListenHandle *lh = cls; |
972 | struct GNUNET_MQ_MessageHandler mq_handlers[] = { | 977 | struct GNUNET_MQ_MessageHandler mq_handlers[] = { |
973 | GNUNET_MQ_hd_var_size(request, | 978 | GNUNET_MQ_hd_var_size (request, |
974 | GNUNET_MESSAGE_TYPE_SET_REQUEST, | 979 | GNUNET_MESSAGE_TYPE_SET_REQUEST, |
975 | struct GNUNET_SET_RequestMessage, | 980 | struct GNUNET_SET_RequestMessage, |
976 | lh), | 981 | lh), |
977 | GNUNET_MQ_handler_end() | 982 | GNUNET_MQ_handler_end () |
978 | }; | 983 | }; |
979 | struct GNUNET_MQ_Envelope *mqm; | 984 | struct GNUNET_MQ_Envelope *mqm; |
980 | struct GNUNET_SET_ListenMessage *msg; | 985 | struct GNUNET_SET_ListenMessage *msg; |
981 | 986 | ||
982 | lh->reconnect_task = NULL; | 987 | lh->reconnect_task = NULL; |
983 | GNUNET_assert(NULL == lh->mq); | 988 | GNUNET_assert (NULL == lh->mq); |
984 | lh->mq = GNUNET_CLIENT_connect(lh->cfg, | 989 | lh->mq = GNUNET_CLIENT_connect (lh->cfg, |
985 | "set", | 990 | "set", |
986 | mq_handlers, | 991 | mq_handlers, |
987 | &handle_client_listener_error, | 992 | &handle_client_listener_error, |
988 | lh); | 993 | lh); |
989 | if (NULL == lh->mq) | 994 | if (NULL == lh->mq) |
990 | return; | 995 | return; |
991 | mqm = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_SET_LISTEN); | 996 | mqm = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_SET_LISTEN); |
992 | msg->operation = htonl(lh->operation); | 997 | msg->operation = htonl (lh->operation); |
993 | msg->app_id = lh->app_id; | 998 | msg->app_id = lh->app_id; |
994 | GNUNET_MQ_send(lh->mq, | 999 | GNUNET_MQ_send (lh->mq, |
995 | mqm); | 1000 | mqm); |
996 | } | 1001 | } |
997 | 1002 | ||
998 | 1003 | ||
@@ -1009,30 +1014,30 @@ listen_connect(void *cls) | |||
1009 | * @return a handle that can be used to cancel the listen operation | 1014 | * @return a handle that can be used to cancel the listen operation |
1010 | */ | 1015 | */ |
1011 | struct GNUNET_SET_ListenHandle * | 1016 | struct GNUNET_SET_ListenHandle * |
1012 | GNUNET_SET_listen(const struct GNUNET_CONFIGURATION_Handle *cfg, | 1017 | GNUNET_SET_listen (const struct GNUNET_CONFIGURATION_Handle *cfg, |
1013 | enum GNUNET_SET_OperationType operation, | 1018 | enum GNUNET_SET_OperationType operation, |
1014 | const struct GNUNET_HashCode *app_id, | 1019 | const struct GNUNET_HashCode *app_id, |
1015 | GNUNET_SET_ListenCallback listen_cb, | 1020 | GNUNET_SET_ListenCallback listen_cb, |
1016 | void *listen_cls) | 1021 | void *listen_cls) |
1017 | { | 1022 | { |
1018 | struct GNUNET_SET_ListenHandle *lh; | 1023 | struct GNUNET_SET_ListenHandle *lh; |
1019 | 1024 | ||
1020 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1025 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1021 | "Starting listener for app %s\n", | 1026 | "Starting listener for app %s\n", |
1022 | GNUNET_h2s(app_id)); | 1027 | GNUNET_h2s (app_id)); |
1023 | lh = GNUNET_new(struct GNUNET_SET_ListenHandle); | 1028 | lh = GNUNET_new (struct GNUNET_SET_ListenHandle); |
1024 | lh->listen_cb = listen_cb; | 1029 | lh->listen_cb = listen_cb; |
1025 | lh->listen_cls = listen_cls; | 1030 | lh->listen_cls = listen_cls; |
1026 | lh->cfg = cfg; | 1031 | lh->cfg = cfg; |
1027 | lh->operation = operation; | 1032 | lh->operation = operation; |
1028 | lh->app_id = *app_id; | 1033 | lh->app_id = *app_id; |
1029 | lh->reconnect_backoff = GNUNET_TIME_UNIT_MILLISECONDS; | 1034 | lh->reconnect_backoff = GNUNET_TIME_UNIT_MILLISECONDS; |
1030 | listen_connect(lh); | 1035 | listen_connect (lh); |
1031 | if (NULL == lh->mq) | 1036 | if (NULL == lh->mq) |
1032 | { | 1037 | { |
1033 | GNUNET_free(lh); | 1038 | GNUNET_free (lh); |
1034 | return NULL; | 1039 | return NULL; |
1035 | } | 1040 | } |
1036 | return lh; | 1041 | return lh; |
1037 | } | 1042 | } |
1038 | 1043 | ||
@@ -1043,22 +1048,22 @@ GNUNET_SET_listen(const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1043 | * @param lh handle for the listen operation | 1048 | * @param lh handle for the listen operation |
1044 | */ | 1049 | */ |
1045 | void | 1050 | void |
1046 | GNUNET_SET_listen_cancel(struct GNUNET_SET_ListenHandle *lh) | 1051 | GNUNET_SET_listen_cancel (struct GNUNET_SET_ListenHandle *lh) |
1047 | { | 1052 | { |
1048 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1053 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1049 | "Canceling listener %s\n", | 1054 | "Canceling listener %s\n", |
1050 | GNUNET_h2s(&lh->app_id)); | 1055 | GNUNET_h2s (&lh->app_id)); |
1051 | if (NULL != lh->mq) | 1056 | if (NULL != lh->mq) |
1052 | { | 1057 | { |
1053 | GNUNET_MQ_destroy(lh->mq); | 1058 | GNUNET_MQ_destroy (lh->mq); |
1054 | lh->mq = NULL; | 1059 | lh->mq = NULL; |
1055 | } | 1060 | } |
1056 | if (NULL != lh->reconnect_task) | 1061 | if (NULL != lh->reconnect_task) |
1057 | { | 1062 | { |
1058 | GNUNET_SCHEDULER_cancel(lh->reconnect_task); | 1063 | GNUNET_SCHEDULER_cancel (lh->reconnect_task); |
1059 | lh->reconnect_task = NULL; | 1064 | lh->reconnect_task = NULL; |
1060 | } | 1065 | } |
1061 | GNUNET_free(lh); | 1066 | GNUNET_free (lh); |
1062 | } | 1067 | } |
1063 | 1068 | ||
1064 | 1069 | ||
@@ -1077,27 +1082,27 @@ GNUNET_SET_listen_cancel(struct GNUNET_SET_ListenHandle *lh) | |||
1077 | * @return a handle to cancel the operation | 1082 | * @return a handle to cancel the operation |
1078 | */ | 1083 | */ |
1079 | struct GNUNET_SET_OperationHandle * | 1084 | struct GNUNET_SET_OperationHandle * |
1080 | GNUNET_SET_accept(struct GNUNET_SET_Request *request, | 1085 | GNUNET_SET_accept (struct GNUNET_SET_Request *request, |
1081 | enum GNUNET_SET_ResultMode result_mode, | 1086 | enum GNUNET_SET_ResultMode result_mode, |
1082 | struct GNUNET_SET_Option options[], | 1087 | struct GNUNET_SET_Option options[], |
1083 | GNUNET_SET_ResultIterator result_cb, | 1088 | GNUNET_SET_ResultIterator result_cb, |
1084 | void *result_cls) | 1089 | void *result_cls) |
1085 | { | 1090 | { |
1086 | struct GNUNET_MQ_Envelope *mqm; | 1091 | struct GNUNET_MQ_Envelope *mqm; |
1087 | struct GNUNET_SET_OperationHandle *oh; | 1092 | struct GNUNET_SET_OperationHandle *oh; |
1088 | struct GNUNET_SET_AcceptMessage *msg; | 1093 | struct GNUNET_SET_AcceptMessage *msg; |
1089 | 1094 | ||
1090 | GNUNET_assert(GNUNET_NO == request->accepted); | 1095 | GNUNET_assert (GNUNET_NO == request->accepted); |
1091 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1096 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1092 | "Client accepts set operation (%d) with id %u\n", | 1097 | "Client accepts set operation (%d) with id %u\n", |
1093 | result_mode, | 1098 | result_mode, |
1094 | request->accept_id); | 1099 | request->accept_id); |
1095 | request->accepted = GNUNET_YES; | 1100 | request->accepted = GNUNET_YES; |
1096 | mqm = GNUNET_MQ_msg(msg, | 1101 | mqm = GNUNET_MQ_msg (msg, |
1097 | GNUNET_MESSAGE_TYPE_SET_ACCEPT); | 1102 | GNUNET_MESSAGE_TYPE_SET_ACCEPT); |
1098 | msg->accept_reject_id = htonl(request->accept_id); | 1103 | msg->accept_reject_id = htonl (request->accept_id); |
1099 | msg->result_mode = htonl(result_mode); | 1104 | msg->result_mode = htonl (result_mode); |
1100 | oh = GNUNET_new(struct GNUNET_SET_OperationHandle); | 1105 | oh = GNUNET_new (struct GNUNET_SET_OperationHandle); |
1101 | oh->result_cb = result_cb; | 1106 | oh->result_cb = result_cb; |
1102 | oh->result_cls = result_cls; | 1107 | oh->result_cls = result_cls; |
1103 | oh->conclude_mqm = mqm; | 1108 | oh->conclude_mqm = mqm; |
@@ -1120,31 +1125,31 @@ GNUNET_SET_accept(struct GNUNET_SET_Request *request, | |||
1120 | * set is invalid (e.g. the set service crashed) | 1125 | * set is invalid (e.g. the set service crashed) |
1121 | */ | 1126 | */ |
1122 | int | 1127 | int |
1123 | GNUNET_SET_commit(struct GNUNET_SET_OperationHandle *oh, | 1128 | GNUNET_SET_commit (struct GNUNET_SET_OperationHandle *oh, |
1124 | struct GNUNET_SET_Handle *set) | 1129 | struct GNUNET_SET_Handle *set) |
1125 | { | 1130 | { |
1126 | if (NULL != oh->set) | 1131 | if (NULL != oh->set) |
1127 | { | 1132 | { |
1128 | /* Some other set was already committed for this | 1133 | /* Some other set was already committed for this |
1129 | * operation, there is a logic bug in the client of this API */ | 1134 | * operation, there is a logic bug in the client of this API */ |
1130 | GNUNET_break(0); | 1135 | GNUNET_break (0); |
1131 | return GNUNET_OK; | 1136 | return GNUNET_OK; |
1132 | } | 1137 | } |
1133 | GNUNET_assert(NULL != set); | 1138 | GNUNET_assert (NULL != set); |
1134 | if (GNUNET_YES == set->invalid) | 1139 | if (GNUNET_YES == set->invalid) |
1135 | return GNUNET_SYSERR; | 1140 | return GNUNET_SYSERR; |
1136 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1141 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1137 | "Client commits to SET\n"); | 1142 | "Client commits to SET\n"); |
1138 | GNUNET_assert(NULL != oh->conclude_mqm); | 1143 | GNUNET_assert (NULL != oh->conclude_mqm); |
1139 | oh->set = set; | 1144 | oh->set = set; |
1140 | GNUNET_CONTAINER_DLL_insert(set->ops_head, | 1145 | GNUNET_CONTAINER_DLL_insert (set->ops_head, |
1141 | set->ops_tail, | 1146 | set->ops_tail, |
1142 | oh); | 1147 | oh); |
1143 | oh->request_id = GNUNET_MQ_assoc_add(set->mq, | 1148 | oh->request_id = GNUNET_MQ_assoc_add (set->mq, |
1144 | oh); | 1149 | oh); |
1145 | *oh->request_id_addr = htonl(oh->request_id); | 1150 | *oh->request_id_addr = htonl (oh->request_id); |
1146 | GNUNET_MQ_send(set->mq, | 1151 | GNUNET_MQ_send (set->mq, |
1147 | oh->conclude_mqm); | 1152 | oh->conclude_mqm); |
1148 | oh->conclude_mqm = NULL; | 1153 | oh->conclude_mqm = NULL; |
1149 | oh->request_id_addr = NULL; | 1154 | oh->request_id_addr = NULL; |
1150 | return GNUNET_OK; | 1155 | return GNUNET_OK; |
@@ -1164,46 +1169,46 @@ GNUNET_SET_commit(struct GNUNET_SET_OperationHandle *oh, | |||
1164 | * #GNUNET_SYSERR if the set is invalid (e.g. the server crashed, disconnected) | 1169 | * #GNUNET_SYSERR if the set is invalid (e.g. the server crashed, disconnected) |
1165 | */ | 1170 | */ |
1166 | int | 1171 | int |
1167 | GNUNET_SET_iterate(struct GNUNET_SET_Handle *set, | 1172 | GNUNET_SET_iterate (struct GNUNET_SET_Handle *set, |
1168 | GNUNET_SET_ElementIterator iter, | 1173 | GNUNET_SET_ElementIterator iter, |
1169 | void *iter_cls) | 1174 | void *iter_cls) |
1170 | { | 1175 | { |
1171 | struct GNUNET_MQ_Envelope *ev; | 1176 | struct GNUNET_MQ_Envelope *ev; |
1172 | 1177 | ||
1173 | GNUNET_assert(NULL != iter); | 1178 | GNUNET_assert (NULL != iter); |
1174 | if (GNUNET_YES == set->invalid) | 1179 | if (GNUNET_YES == set->invalid) |
1175 | return GNUNET_SYSERR; | 1180 | return GNUNET_SYSERR; |
1176 | if (NULL != set->iterator) | 1181 | if (NULL != set->iterator) |
1177 | return GNUNET_NO; | 1182 | return GNUNET_NO; |
1178 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1183 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1179 | "Iterating over set\n"); | 1184 | "Iterating over set\n"); |
1180 | set->iterator = iter; | 1185 | set->iterator = iter; |
1181 | set->iterator_cls = iter_cls; | 1186 | set->iterator_cls = iter_cls; |
1182 | ev = GNUNET_MQ_msg_header(GNUNET_MESSAGE_TYPE_SET_ITER_REQUEST); | 1187 | ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_SET_ITER_REQUEST); |
1183 | GNUNET_MQ_send(set->mq, ev); | 1188 | GNUNET_MQ_send (set->mq, ev); |
1184 | return GNUNET_YES; | 1189 | return GNUNET_YES; |
1185 | } | 1190 | } |
1186 | 1191 | ||
1187 | 1192 | ||
1188 | void | 1193 | void |
1189 | GNUNET_SET_copy_lazy(struct GNUNET_SET_Handle *set, | 1194 | GNUNET_SET_copy_lazy (struct GNUNET_SET_Handle *set, |
1190 | GNUNET_SET_CopyReadyCallback cb, | 1195 | GNUNET_SET_CopyReadyCallback cb, |
1191 | void *cls) | 1196 | void *cls) |
1192 | { | 1197 | { |
1193 | struct GNUNET_MQ_Envelope *ev; | 1198 | struct GNUNET_MQ_Envelope *ev; |
1194 | struct SetCopyRequest *req; | 1199 | struct SetCopyRequest *req; |
1195 | 1200 | ||
1196 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1201 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1197 | "Creating lazy copy of set\n"); | 1202 | "Creating lazy copy of set\n"); |
1198 | ev = GNUNET_MQ_msg_header(GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_PREPARE); | 1203 | ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_PREPARE); |
1199 | GNUNET_MQ_send(set->mq, ev); | 1204 | GNUNET_MQ_send (set->mq, ev); |
1200 | 1205 | ||
1201 | req = GNUNET_new(struct SetCopyRequest); | 1206 | req = GNUNET_new (struct SetCopyRequest); |
1202 | req->cb = cb; | 1207 | req->cb = cb; |
1203 | req->cls = cls; | 1208 | req->cls = cls; |
1204 | GNUNET_CONTAINER_DLL_insert(set->copy_req_head, | 1209 | GNUNET_CONTAINER_DLL_insert (set->copy_req_head, |
1205 | set->copy_req_tail, | 1210 | set->copy_req_tail, |
1206 | req); | 1211 | req); |
1207 | } | 1212 | } |
1208 | 1213 | ||
1209 | 1214 | ||
@@ -1215,17 +1220,17 @@ GNUNET_SET_copy_lazy(struct GNUNET_SET_Handle *set, | |||
1215 | * @return the copied element | 1220 | * @return the copied element |
1216 | */ | 1221 | */ |
1217 | struct GNUNET_SET_Element * | 1222 | struct GNUNET_SET_Element * |
1218 | GNUNET_SET_element_dup(const struct GNUNET_SET_Element *element) | 1223 | GNUNET_SET_element_dup (const struct GNUNET_SET_Element *element) |
1219 | { | 1224 | { |
1220 | struct GNUNET_SET_Element *copy; | 1225 | struct GNUNET_SET_Element *copy; |
1221 | 1226 | ||
1222 | copy = GNUNET_malloc(element->size + sizeof(struct GNUNET_SET_Element)); | 1227 | copy = GNUNET_malloc (element->size + sizeof(struct GNUNET_SET_Element)); |
1223 | copy->size = element->size; | 1228 | copy->size = element->size; |
1224 | copy->element_type = element->element_type; | 1229 | copy->element_type = element->element_type; |
1225 | copy->data = ©[1]; | 1230 | copy->data = ©[1]; |
1226 | GNUNET_memcpy(©[1], | 1231 | GNUNET_memcpy (©[1], |
1227 | element->data, | 1232 | element->data, |
1228 | copy->size); | 1233 | copy->size); |
1229 | return copy; | 1234 | return copy; |
1230 | } | 1235 | } |
1231 | 1236 | ||
@@ -1238,17 +1243,18 @@ GNUNET_SET_element_dup(const struct GNUNET_SET_Element *element) | |||
1238 | * should be stored | 1243 | * should be stored |
1239 | */ | 1244 | */ |
1240 | void | 1245 | void |
1241 | GNUNET_SET_element_hash(const struct GNUNET_SET_Element *element, | 1246 | GNUNET_SET_element_hash (const struct GNUNET_SET_Element *element, |
1242 | struct GNUNET_HashCode *ret_hash) | 1247 | struct GNUNET_HashCode *ret_hash) |
1243 | { | 1248 | { |
1244 | struct GNUNET_HashContext *ctx = GNUNET_CRYPTO_hash_context_start(); | 1249 | struct GNUNET_HashContext *ctx = GNUNET_CRYPTO_hash_context_start (); |
1245 | 1250 | ||
1246 | /* It's not guaranteed that the element data is always after the element header, | 1251 | /* It's not guaranteed that the element data is always after the element header, |
1247 | so we need to hash the chunks separately. */ | 1252 | so we need to hash the chunks separately. */ |
1248 | GNUNET_CRYPTO_hash_context_read(ctx, &element->size, sizeof(uint16_t)); | 1253 | GNUNET_CRYPTO_hash_context_read (ctx, &element->size, sizeof(uint16_t)); |
1249 | GNUNET_CRYPTO_hash_context_read(ctx, &element->element_type, sizeof(uint16_t)); | 1254 | GNUNET_CRYPTO_hash_context_read (ctx, &element->element_type, |
1250 | GNUNET_CRYPTO_hash_context_read(ctx, element->data, element->size); | 1255 | sizeof(uint16_t)); |
1251 | GNUNET_CRYPTO_hash_context_finish(ctx, ret_hash); | 1256 | GNUNET_CRYPTO_hash_context_read (ctx, element->data, element->size); |
1257 | GNUNET_CRYPTO_hash_context_finish (ctx, ret_hash); | ||
1252 | } | 1258 | } |
1253 | 1259 | ||
1254 | /* end of set_api.c */ | 1260 | /* end of set_api.c */ |