diff options
-rw-r--r-- | src/reclaim/reclaim_api.c | 1009 |
1 files changed, 530 insertions, 479 deletions
diff --git a/src/reclaim/reclaim_api.c b/src/reclaim/reclaim_api.c index 21c870a37..725b2b876 100644 --- a/src/reclaim/reclaim_api.c +++ b/src/reclaim/reclaim_api.c | |||
@@ -292,514 +292,549 @@ struct GNUNET_RECLAIM_Handle | |||
292 | */ | 292 | */ |
293 | struct GNUNET_SCHEDULER_Task *reconnect_task; | 293 | struct GNUNET_SCHEDULER_Task *reconnect_task; |
294 | 294 | ||
295 | /** | 295 | /** |
296 | * Time for next connect retry. | 296 | * Time for next connect retry. |
297 | */ | 297 | */ |
298 | struct GNUNET_TIME_Relative reconnect_backoff; | 298 | struct GNUNET_TIME_Relative reconnect_backoff; |
299 | |||
300 | /** | ||
301 | * Connection to service (if available). | ||
302 | */ | ||
303 | struct GNUNET_MQ_Handle *mq; | ||
304 | |||
305 | /** | ||
306 | * Request Id generator. Incremented by one for each request. | ||
307 | */ | ||
308 | uint32_t r_id_gen; | ||
309 | |||
310 | /** | ||
311 | * Are we polling for incoming messages right now? | ||
312 | */ | ||
313 | int in_receive; | ||
314 | }; | ||
315 | |||
316 | 299 | ||
317 | /** | 300 | /** |
318 | * Try again to connect to the service. | 301 | * Connection to service (if available). |
319 | * | ||
320 | * @param h handle to the reclaim service. | ||
321 | */ | 302 | */ |
322 | static void | 303 | struct GNUNET_MQ_Handle *mq; |
323 | reconnect (struct GNUNET_RECLAIM_Handle *h); | ||
324 | 304 | ||
305 | /** | ||
306 | * Request Id generator. Incremented by one for each request. | ||
307 | */ | ||
308 | uint32_t r_id_gen; | ||
325 | 309 | ||
326 | /** | 310 | /** |
327 | * Reconnect | 311 | * Are we polling for incoming messages right now? |
328 | * | ||
329 | * @param cls the handle | ||
330 | */ | 312 | */ |
331 | static void | 313 | int in_receive; |
332 | reconnect_task (void *cls) | 314 | }; |
333 | { | ||
334 | struct GNUNET_RECLAIM_Handle *handle = cls; | ||
335 | 315 | ||
336 | handle->reconnect_task = NULL; | ||
337 | reconnect (handle); | ||
338 | } | ||
339 | 316 | ||
317 | /** | ||
318 | * Try again to connect to the service. | ||
319 | * | ||
320 | * @param h handle to the reclaim service. | ||
321 | */ | ||
322 | static void | ||
323 | reconnect (struct GNUNET_RECLAIM_Handle *h); | ||
340 | 324 | ||
341 | /** | ||
342 | * Disconnect from service and then reconnect. | ||
343 | * | ||
344 | * @param handle our service | ||
345 | */ | ||
346 | static void | ||
347 | force_reconnect (struct GNUNET_RECLAIM_Handle *handle) | ||
348 | { | ||
349 | GNUNET_MQ_destroy (handle->mq); | ||
350 | handle->mq = NULL; | ||
351 | handle->reconnect_backoff = | ||
352 | GNUNET_TIME_STD_BACKOFF (handle->reconnect_backoff); | ||
353 | handle->reconnect_task = GNUNET_SCHEDULER_add_delayed ( | ||
354 | handle->reconnect_backoff, &reconnect_task, handle); | ||
355 | } | ||
356 | 325 | ||
326 | /** | ||
327 | * Reconnect | ||
328 | * | ||
329 | * @param cls the handle | ||
330 | */ | ||
331 | static void | ||
332 | reconnect_task (void *cls) | ||
333 | { | ||
334 | struct GNUNET_RECLAIM_Handle *handle = cls; | ||
357 | 335 | ||
358 | /** | 336 | handle->reconnect_task = NULL; |
359 | * Free @a it. | 337 | reconnect (handle); |
360 | * | 338 | } |
361 | * @param it entry to free | ||
362 | */ | ||
363 | static void | ||
364 | free_it (struct GNUNET_RECLAIM_AttributeIterator *it) | ||
365 | { | ||
366 | struct GNUNET_RECLAIM_Handle *h = it->h; | ||
367 | 339 | ||
368 | GNUNET_CONTAINER_DLL_remove (h->it_head, h->it_tail, it); | ||
369 | if (NULL != it->env) | ||
370 | GNUNET_MQ_discard (it->env); | ||
371 | GNUNET_free (it); | ||
372 | } | ||
373 | 340 | ||
374 | /** | 341 | /** |
375 | * Free @a op | 342 | * Disconnect from service and then reconnect. |
376 | * | 343 | * |
377 | * @param op the operation to free | 344 | * @param handle our service |
378 | */ | 345 | */ |
379 | static void | 346 | static void |
380 | free_op (struct GNUNET_RECLAIM_Operation *op) | 347 | force_reconnect (struct GNUNET_RECLAIM_Handle *handle) |
381 | { | 348 | { |
382 | if (NULL == op) | 349 | GNUNET_MQ_destroy (handle->mq); |
383 | return; | 350 | handle->mq = NULL; |
384 | if (NULL != op->env) | 351 | handle->reconnect_backoff = |
385 | GNUNET_MQ_discard (op->env); | 352 | GNUNET_TIME_STD_BACKOFF (handle->reconnect_backoff); |
386 | GNUNET_free (op); | 353 | handle->reconnect_task = |
387 | } | 354 | GNUNET_SCHEDULER_add_delayed (handle->reconnect_backoff, |
355 | &reconnect_task, | ||
356 | handle); | ||
357 | } | ||
388 | 358 | ||
389 | 359 | ||
390 | /** | 360 | /** |
391 | * Generic error handler, called with the appropriate error code and | 361 | * Free @a it. |
392 | * the same closure specified at the creation of the message queue. | 362 | * |
393 | * Not every message queue implementation supports an error handler. | 363 | * @param it entry to free |
394 | * | 364 | */ |
395 | * @param cls closure with the `struct GNUNET_GNS_Handle *` | 365 | static void |
396 | * @param error error code | 366 | free_it (struct GNUNET_RECLAIM_AttributeIterator *it) |
397 | */ | 367 | { |
398 | static void | 368 | struct GNUNET_RECLAIM_Handle *h = it->h; |
399 | mq_error_handler (void *cls, enum GNUNET_MQ_Error error) | 369 | |
370 | GNUNET_CONTAINER_DLL_remove (h->it_head, h->it_tail, it); | ||
371 | if (NULL != it->env) | ||
372 | GNUNET_MQ_discard (it->env); | ||
373 | GNUNET_free (it); | ||
374 | } | ||
375 | |||
376 | /** | ||
377 | * Free @a op | ||
378 | * | ||
379 | * @param op the operation to free | ||
380 | */ | ||
381 | static void | ||
382 | free_op (struct GNUNET_RECLAIM_Operation *op) | ||
383 | { | ||
384 | if (NULL == op) | ||
385 | return; | ||
386 | if (NULL != op->env) | ||
387 | GNUNET_MQ_discard (op->env); | ||
388 | GNUNET_free (op); | ||
389 | } | ||
390 | |||
391 | |||
392 | /** | ||
393 | * Generic error handler, called with the appropriate error code and | ||
394 | * the same closure specified at the creation of the message queue. | ||
395 | * Not every message queue implementation supports an error handler. | ||
396 | * | ||
397 | * @param cls closure with the `struct GNUNET_GNS_Handle *` | ||
398 | * @param error error code | ||
399 | */ | ||
400 | static void | ||
401 | mq_error_handler (void *cls, enum GNUNET_MQ_Error error) | ||
402 | { | ||
403 | struct GNUNET_RECLAIM_Handle *handle = cls; | ||
404 | force_reconnect (handle); | ||
405 | } | ||
406 | |||
407 | |||
408 | /** | ||
409 | * Handle an incoming message of type | ||
410 | * #GNUNET_MESSAGE_TYPE_RECLAIM_SUCCESS_RESPONSE | ||
411 | * | ||
412 | * @param cls | ||
413 | * @param msg the message we received | ||
414 | */ | ||
415 | static void | ||
416 | handle_success_response (void *cls, const struct SuccessResultMessage *msg) | ||
417 | { | ||
418 | struct GNUNET_RECLAIM_Handle *h = cls; | ||
419 | struct GNUNET_RECLAIM_Operation *op; | ||
420 | uint32_t r_id = ntohl (msg->id); | ||
421 | int res; | ||
422 | const char *emsg; | ||
423 | |||
424 | for (op = h->op_head; NULL != op; op = op->next) | ||
425 | if (op->r_id == r_id) | ||
426 | break; | ||
427 | if (NULL == op) | ||
428 | return; | ||
429 | |||
430 | res = ntohl (msg->op_result); | ||
431 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
432 | "Received SUCCESS_RESPONSE with result %d\n", | ||
433 | res); | ||
434 | |||
435 | /* TODO: add actual error message to response... */ | ||
436 | if (GNUNET_SYSERR == res) | ||
437 | emsg = _ ("failed to store record\n"); | ||
438 | else | ||
439 | emsg = NULL; | ||
440 | if (NULL != op->as_cb) | ||
441 | op->as_cb (op->cls, res, emsg); | ||
442 | GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op); | ||
443 | free_op (op); | ||
444 | } | ||
445 | |||
446 | |||
447 | /** | ||
448 | * Handle an incoming message of type | ||
449 | * #GNUNET_MESSAGE_TYPE_RECLAIM_CONSUME_TICKET_RESULT | ||
450 | * | ||
451 | * @param cls | ||
452 | * @param msg the message we received | ||
453 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | ||
454 | */ | ||
455 | static int | ||
456 | check_consume_ticket_result (void *cls, | ||
457 | const struct ConsumeTicketResultMessage *msg) | ||
458 | { | ||
459 | size_t msg_len; | ||
460 | size_t attrs_len; | ||
461 | |||
462 | msg_len = ntohs (msg->header.size); | ||
463 | attrs_len = ntohs (msg->attrs_len); | ||
464 | if (msg_len != sizeof (struct ConsumeTicketResultMessage) + attrs_len) | ||
400 | { | 465 | { |
401 | struct GNUNET_RECLAIM_Handle *handle = cls; | 466 | GNUNET_break (0); |
402 | force_reconnect (handle); | 467 | return GNUNET_SYSERR; |
403 | } | 468 | } |
469 | return GNUNET_OK; | ||
470 | } | ||
404 | 471 | ||
405 | 472 | ||
406 | /** | 473 | /** |
407 | * Handle an incoming message of type | 474 | * Handle an incoming message of type |
408 | * #GNUNET_MESSAGE_TYPE_RECLAIM_SUCCESS_RESPONSE | 475 | * #GNUNET_MESSAGE_TYPE_RECLAIM_CONSUME_TICKET_RESULT |
409 | * | 476 | * |
410 | * @param cls | 477 | * @param cls |
411 | * @param msg the message we received | 478 | * @param msg the message we received |
412 | */ | 479 | */ |
413 | static void | 480 | static void |
414 | handle_success_response (void *cls, const struct SuccessResultMessage *msg) | 481 | handle_consume_ticket_result (void *cls, |
415 | { | 482 | const struct ConsumeTicketResultMessage *msg) |
416 | struct GNUNET_RECLAIM_Handle *h = cls; | 483 | { |
417 | struct GNUNET_RECLAIM_Operation *op; | 484 | struct GNUNET_RECLAIM_Handle *h = cls; |
418 | uint32_t r_id = ntohl (msg->id); | 485 | struct GNUNET_RECLAIM_Operation *op; |
419 | int res; | 486 | size_t attrs_len; |
420 | const char *emsg; | 487 | uint32_t r_id = ntohl (msg->id); |
421 | |||
422 | for (op = h->op_head; NULL != op; op = op->next) | ||
423 | if (op->r_id == r_id) | ||
424 | break; | ||
425 | if (NULL == op) | ||
426 | return; | ||
427 | 488 | ||
428 | res = ntohl (msg->op_result); | 489 | attrs_len = ntohs (msg->attrs_len); |
429 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Received SUCCESS_RESPONSE with result %d\n", | 490 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Processing attribute result.\n"); |
430 | res); | ||
431 | 491 | ||
432 | /* TODO: add actual error message to response... */ | 492 | |
433 | if (GNUNET_SYSERR == res) | 493 | for (op = h->op_head; NULL != op; op = op->next) |
434 | emsg = _ ("failed to store record\n"); | 494 | if (op->r_id == r_id) |
435 | else | 495 | break; |
436 | emsg = NULL; | 496 | if (NULL == op) |
437 | if (NULL != op->as_cb) | 497 | return; |
438 | op->as_cb (op->cls, res, emsg); | 498 | |
499 | { | ||
500 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs; | ||
501 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; | ||
502 | attrs = | ||
503 | GNUNET_RECLAIM_ATTRIBUTE_list_deserialize ((char *) &msg[1], attrs_len); | ||
504 | if (NULL != op->ar_cb) | ||
505 | { | ||
506 | if (NULL == attrs) | ||
507 | { | ||
508 | op->ar_cb (op->cls, &msg->identity, NULL); | ||
509 | } | ||
510 | else | ||
511 | { | ||
512 | for (le = attrs->list_head; NULL != le; le = le->next) | ||
513 | op->ar_cb (op->cls, &msg->identity, le->claim); | ||
514 | GNUNET_RECLAIM_ATTRIBUTE_list_destroy (attrs); | ||
515 | attrs = NULL; | ||
516 | } | ||
517 | op->ar_cb (op->cls, NULL, NULL); | ||
518 | } | ||
439 | GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op); | 519 | GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op); |
440 | free_op (op); | 520 | free_op (op); |
521 | GNUNET_free_non_null (attrs); | ||
522 | return; | ||
441 | } | 523 | } |
524 | GNUNET_assert (0); | ||
525 | } | ||
442 | 526 | ||
443 | 527 | ||
444 | /** | 528 | /** |
445 | * Handle an incoming message of type | 529 | * Handle an incoming message of type |
446 | * #GNUNET_MESSAGE_TYPE_RECLAIM_CONSUME_TICKET_RESULT | 530 | * #GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_RESULT |
447 | * | 531 | * |
448 | * @param cls | 532 | * @param cls |
449 | * @param msg the message we received | 533 | * @param msg the message we received |
450 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 534 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
451 | */ | 535 | */ |
452 | static int | 536 | static int |
453 | check_consume_ticket_result (void *cls, | 537 | check_attribute_result (void *cls, const struct AttributeResultMessage *msg) |
454 | const struct ConsumeTicketResultMessage *msg) | 538 | { |
455 | { | 539 | size_t msg_len; |
456 | size_t msg_len; | 540 | size_t attr_len; |
457 | size_t attrs_len; | ||
458 | 541 | ||
459 | msg_len = ntohs (msg->header.size); | 542 | msg_len = ntohs (msg->header.size); |
460 | attrs_len = ntohs (msg->attrs_len); | 543 | attr_len = ntohs (msg->attr_len); |
461 | if (msg_len != sizeof (struct ConsumeTicketResultMessage) + attrs_len) { | 544 | if (msg_len != sizeof (struct AttributeResultMessage) + attr_len) |
462 | GNUNET_break (0); | 545 | { |
463 | return GNUNET_SYSERR; | 546 | GNUNET_break (0); |
464 | } | 547 | return GNUNET_SYSERR; |
465 | return GNUNET_OK; | ||
466 | } | 548 | } |
549 | return GNUNET_OK; | ||
550 | } | ||
467 | 551 | ||
468 | 552 | ||
469 | /** | 553 | /** |
470 | * Handle an incoming message of type | 554 | * Handle an incoming message of type |
471 | * #GNUNET_MESSAGE_TYPE_RECLAIM_CONSUME_TICKET_RESULT | 555 | * #GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_RESULT |
472 | * | 556 | * |
473 | * @param cls | 557 | * @param cls |
474 | * @param msg the message we received | 558 | * @param msg the message we received |
475 | */ | 559 | */ |
476 | static void | 560 | static void |
477 | handle_consume_ticket_result (void *cls, | 561 | handle_attribute_result (void *cls, const struct AttributeResultMessage *msg) |
478 | const struct ConsumeTicketResultMessage *msg) | 562 | { |
479 | { | 563 | static struct GNUNET_CRYPTO_EcdsaPrivateKey identity_dummy; |
480 | struct GNUNET_RECLAIM_Handle *h = cls; | 564 | struct GNUNET_RECLAIM_Handle *h = cls; |
481 | struct GNUNET_RECLAIM_Operation *op; | 565 | struct GNUNET_RECLAIM_AttributeIterator *it; |
482 | size_t attrs_len; | 566 | struct GNUNET_RECLAIM_Operation *op; |
483 | uint32_t r_id = ntohl (msg->id); | 567 | size_t attr_len; |
568 | uint32_t r_id = ntohl (msg->id); | ||
484 | 569 | ||
485 | attrs_len = ntohs (msg->attrs_len); | 570 | attr_len = ntohs (msg->attr_len); |
486 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Processing attribute result.\n"); | 571 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Processing attribute result.\n"); |
487 | 572 | ||
488 | 573 | ||
489 | for (op = h->op_head; NULL != op; op = op->next) | 574 | for (it = h->it_head; NULL != it; it = it->next) |
490 | if (op->r_id == r_id) | 575 | if (it->r_id == r_id) |
491 | break; | 576 | break; |
492 | if (NULL == op) | 577 | for (op = h->op_head; NULL != op; op = op->next) |
493 | return; | 578 | if (op->r_id == r_id) |
579 | break; | ||
580 | if ((NULL == it) && (NULL == op)) | ||
581 | return; | ||
494 | 582 | ||
583 | if ((0 == | ||
584 | (memcmp (&msg->identity, &identity_dummy, sizeof (identity_dummy))))) | ||
585 | { | ||
586 | if ((NULL == it) && (NULL == op)) | ||
587 | { | ||
588 | GNUNET_break (0); | ||
589 | force_reconnect (h); | ||
590 | return; | ||
591 | } | ||
592 | if (NULL != it) | ||
593 | { | ||
594 | if (NULL != it->finish_cb) | ||
595 | it->finish_cb (it->finish_cb_cls); | ||
596 | free_it (it); | ||
597 | } | ||
598 | if (NULL != op) | ||
495 | { | 599 | { |
496 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs; | 600 | if (NULL != op->ar_cb) |
497 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; | ||
498 | attrs = | ||
499 | GNUNET_RECLAIM_ATTRIBUTE_list_deserialize ((char *)&msg[1], attrs_len); | ||
500 | if (NULL != op->ar_cb) { | ||
501 | if (NULL == attrs) { | ||
502 | op->ar_cb (op->cls, &msg->identity, NULL); | ||
503 | } else { | ||
504 | for (le = attrs->list_head; NULL != le; le = le->next) | ||
505 | op->ar_cb (op->cls, &msg->identity, le->claim); | ||
506 | GNUNET_RECLAIM_ATTRIBUTE_list_destroy (attrs); | ||
507 | attrs = NULL; | ||
508 | } | ||
509 | op->ar_cb (op->cls, NULL, NULL); | 601 | op->ar_cb (op->cls, NULL, NULL); |
510 | } | ||
511 | GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op); | 602 | GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op); |
512 | free_op (op); | 603 | free_op (op); |
513 | GNUNET_free_non_null (attrs); | ||
514 | return; | ||
515 | } | 604 | } |
516 | GNUNET_assert (0); | 605 | return; |
517 | } | 606 | } |
518 | 607 | ||
519 | |||
520 | /** | ||
521 | * Handle an incoming message of type | ||
522 | * #GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_RESULT | ||
523 | * | ||
524 | * @param cls | ||
525 | * @param msg the message we received | ||
526 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | ||
527 | */ | ||
528 | static int | ||
529 | check_attribute_result (void *cls, const struct AttributeResultMessage *msg) | ||
530 | { | 608 | { |
531 | size_t msg_len; | 609 | struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr; |
532 | size_t attr_len; | 610 | attr = GNUNET_RECLAIM_ATTRIBUTE_deserialize ((char *) &msg[1], attr_len); |
533 | 611 | if (NULL != it) | |
534 | msg_len = ntohs (msg->header.size); | 612 | { |
535 | attr_len = ntohs (msg->attr_len); | 613 | if (NULL != it->proc) |
536 | if (msg_len != sizeof (struct AttributeResultMessage) + attr_len) { | 614 | it->proc (it->proc_cls, &msg->identity, attr); |
537 | GNUNET_break (0); | ||
538 | return GNUNET_SYSERR; | ||
539 | } | 615 | } |
540 | return GNUNET_OK; | 616 | else if (NULL != op) |
617 | { | ||
618 | if (NULL != op->ar_cb) | ||
619 | op->ar_cb (op->cls, &msg->identity, attr); | ||
620 | } | ||
621 | GNUNET_free (attr); | ||
622 | return; | ||
541 | } | 623 | } |
624 | GNUNET_assert (0); | ||
625 | } | ||
542 | 626 | ||
543 | 627 | ||
544 | /** | 628 | /** |
545 | * Handle an incoming message of type | 629 | * Handle an incoming message of type |
546 | * #GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_RESULT | 630 | * #GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_RESULT |
547 | * | 631 | * |
548 | * @param cls | 632 | * @param cls |
549 | * @param msg the message we received | 633 | * @param msg the message we received |
550 | */ | 634 | */ |
551 | static void | 635 | static void |
552 | handle_attribute_result (void *cls, const struct AttributeResultMessage *msg) | 636 | handle_ticket_result (void *cls, const struct TicketResultMessage *msg) |
637 | { | ||
638 | struct GNUNET_RECLAIM_Handle *handle = cls; | ||
639 | struct GNUNET_RECLAIM_Operation *op; | ||
640 | struct GNUNET_RECLAIM_TicketIterator *it; | ||
641 | uint32_t r_id = ntohl (msg->id); | ||
642 | static const struct GNUNET_RECLAIM_Ticket ticket; | ||
643 | for (op = handle->op_head; NULL != op; op = op->next) | ||
644 | if (op->r_id == r_id) | ||
645 | break; | ||
646 | for (it = handle->ticket_it_head; NULL != it; it = it->next) | ||
647 | if (it->r_id == r_id) | ||
648 | break; | ||
649 | if ((NULL == op) && (NULL == it)) | ||
650 | return; | ||
651 | if (NULL != op) | ||
553 | { | 652 | { |
554 | static struct GNUNET_CRYPTO_EcdsaPrivateKey identity_dummy; | 653 | GNUNET_CONTAINER_DLL_remove (handle->op_head, handle->op_tail, op); |
555 | struct GNUNET_RECLAIM_Handle *h = cls; | 654 | if (0 == |
556 | struct GNUNET_RECLAIM_AttributeIterator *it; | 655 | memcmp (&msg->ticket, &ticket, sizeof (struct GNUNET_RECLAIM_Ticket))) |
557 | struct GNUNET_RECLAIM_Operation *op; | 656 | { |
558 | size_t attr_len; | 657 | if (NULL != op->tr_cb) |
559 | uint32_t r_id = ntohl (msg->id); | 658 | op->tr_cb (op->cls, NULL); |
560 | |||
561 | attr_len = ntohs (msg->attr_len); | ||
562 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Processing attribute result.\n"); | ||
563 | |||
564 | |||
565 | for (it = h->it_head; NULL != it; it = it->next) | ||
566 | if (it->r_id == r_id) | ||
567 | break; | ||
568 | for (op = h->op_head; NULL != op; op = op->next) | ||
569 | if (op->r_id == r_id) | ||
570 | break; | ||
571 | if ((NULL == it) && (NULL == op)) | ||
572 | return; | ||
573 | |||
574 | if ((0 == | ||
575 | (memcmp (&msg->identity, &identity_dummy, sizeof (identity_dummy))))) { | ||
576 | if ((NULL == it) && (NULL == op)) { | ||
577 | GNUNET_break (0); | ||
578 | force_reconnect (h); | ||
579 | return; | ||
580 | } | ||
581 | if (NULL != it) { | ||
582 | if (NULL != it->finish_cb) | ||
583 | it->finish_cb (it->finish_cb_cls); | ||
584 | free_it (it); | ||
585 | } | ||
586 | if (NULL != op) { | ||
587 | if (NULL != op->ar_cb) | ||
588 | op->ar_cb (op->cls, NULL, NULL); | ||
589 | GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op); | ||
590 | free_op (op); | ||
591 | } | ||
592 | return; | ||
593 | } | 659 | } |
594 | 660 | else | |
595 | { | 661 | { |
596 | struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr; | 662 | if (NULL != op->tr_cb) |
597 | attr = GNUNET_RECLAIM_ATTRIBUTE_deserialize ((char *)&msg[1], attr_len); | 663 | op->tr_cb (op->cls, &msg->ticket); |
598 | if (NULL != it) { | ||
599 | if (NULL != it->proc) | ||
600 | it->proc (it->proc_cls, &msg->identity, attr); | ||
601 | } else if (NULL != op) { | ||
602 | if (NULL != op->ar_cb) | ||
603 | op->ar_cb (op->cls, &msg->identity, attr); | ||
604 | } | ||
605 | GNUNET_free (attr); | ||
606 | return; | ||
607 | } | 664 | } |
608 | GNUNET_assert (0); | 665 | free_op (op); |
666 | return; | ||
609 | } | 667 | } |
610 | 668 | else if (NULL != it) | |
611 | |||
612 | /** | ||
613 | * Handle an incoming message of type | ||
614 | * #GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_RESULT | ||
615 | * | ||
616 | * @param cls | ||
617 | * @param msg the message we received | ||
618 | */ | ||
619 | static void | ||
620 | handle_ticket_result (void *cls, const struct TicketResultMessage *msg) | ||
621 | { | 669 | { |
622 | struct GNUNET_RECLAIM_Handle *handle = cls; | 670 | if (0 == |
623 | struct GNUNET_RECLAIM_Operation *op; | 671 | memcmp (&msg->ticket, &ticket, sizeof (struct GNUNET_RECLAIM_Ticket))) |
624 | struct GNUNET_RECLAIM_TicketIterator *it; | 672 | { |
625 | uint32_t r_id = ntohl (msg->id); | 673 | GNUNET_CONTAINER_DLL_remove (handle->ticket_it_head, |
626 | static const struct GNUNET_RECLAIM_Ticket ticket; | 674 | handle->ticket_it_tail, |
627 | for (op = handle->op_head; NULL != op; op = op->next) | 675 | it); |
628 | if (op->r_id == r_id) | 676 | it->finish_cb (it->finish_cb_cls); |
629 | break; | 677 | GNUNET_free (it); |
630 | for (it = handle->ticket_it_head; NULL != it; it = it->next) | ||
631 | if (it->r_id == r_id) | ||
632 | break; | ||
633 | if ((NULL == op) && (NULL == it)) | ||
634 | return; | ||
635 | if (NULL != op) { | ||
636 | GNUNET_CONTAINER_DLL_remove (handle->op_head, handle->op_tail, op); | ||
637 | if (0 == memcmp (&msg->ticket, &ticket, sizeof (struct GNUNET_RECLAIM_Ticket))) | ||
638 | { | ||
639 | if (NULL != op->tr_cb) | ||
640 | op->tr_cb (op->cls, NULL); | ||
641 | } else { | ||
642 | if (NULL != op->tr_cb) | ||
643 | op->tr_cb (op->cls, &msg->ticket); | ||
644 | } | ||
645 | free_op (op); | ||
646 | return; | ||
647 | } else if (NULL != it) { | ||
648 | if (0 == memcmp (&msg->ticket, &ticket, sizeof (struct GNUNET_RECLAIM_Ticket))) | ||
649 | { | ||
650 | GNUNET_CONTAINER_DLL_remove (handle->ticket_it_head, | ||
651 | handle->ticket_it_tail, it); | ||
652 | it->finish_cb (it->finish_cb_cls); | ||
653 | GNUNET_free (it); | ||
654 | } else { | ||
655 | if (NULL != it->tr_cb) | ||
656 | it->tr_cb (it->cls, &msg->ticket); | ||
657 | } | ||
658 | return; | ||
659 | } | 678 | } |
660 | GNUNET_break (0); | 679 | else |
680 | { | ||
681 | if (NULL != it->tr_cb) | ||
682 | it->tr_cb (it->cls, &msg->ticket); | ||
683 | } | ||
684 | return; | ||
661 | } | 685 | } |
686 | GNUNET_break (0); | ||
687 | } | ||
662 | 688 | ||
663 | 689 | ||
664 | /** | 690 | /** |
665 | * Handle an incoming message of type | 691 | * Handle an incoming message of type |
666 | * #GNUNET_MESSAGE_TYPE_RECLAIM_REVOKE_TICKET_RESULT | 692 | * #GNUNET_MESSAGE_TYPE_RECLAIM_REVOKE_TICKET_RESULT |
667 | * | 693 | * |
668 | * @param cls | 694 | * @param cls |
669 | * @param msg the message we received | 695 | * @param msg the message we received |
670 | */ | 696 | */ |
671 | static void | 697 | static void |
672 | handle_revoke_ticket_result (void *cls, | 698 | handle_revoke_ticket_result (void *cls, |
673 | const struct RevokeTicketResultMessage *msg) | 699 | const struct RevokeTicketResultMessage *msg) |
674 | { | 700 | { |
675 | struct GNUNET_RECLAIM_Handle *h = cls; | 701 | struct GNUNET_RECLAIM_Handle *h = cls; |
676 | struct GNUNET_RECLAIM_Operation *op; | 702 | struct GNUNET_RECLAIM_Operation *op; |
677 | uint32_t r_id = ntohl (msg->id); | 703 | uint32_t r_id = ntohl (msg->id); |
678 | int32_t success; | 704 | int32_t success; |
679 | 705 | ||
680 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Processing revocation result.\n"); | 706 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Processing revocation result.\n"); |
681 | 707 | ||
682 | 708 | ||
683 | for (op = h->op_head; NULL != op; op = op->next) | 709 | for (op = h->op_head; NULL != op; op = op->next) |
684 | if (op->r_id == r_id) | 710 | if (op->r_id == r_id) |
685 | break; | 711 | break; |
686 | if (NULL == op) | 712 | if (NULL == op) |
687 | return; | 713 | return; |
688 | success = ntohl (msg->success); | 714 | success = ntohl (msg->success); |
715 | { | ||
716 | if (NULL != op->rvk_cb) | ||
689 | { | 717 | { |
690 | if (NULL != op->rvk_cb) { | 718 | op->rvk_cb (op->cls, success, NULL); |
691 | op->rvk_cb (op->cls, success, NULL); | ||
692 | } | ||
693 | GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op); | ||
694 | free_op (op); | ||
695 | return; | ||
696 | } | 719 | } |
697 | GNUNET_assert (0); | 720 | GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op); |
721 | free_op (op); | ||
722 | return; | ||
698 | } | 723 | } |
724 | GNUNET_assert (0); | ||
725 | } | ||
699 | 726 | ||
700 | 727 | ||
701 | /** | 728 | /** |
702 | * Try again to connect to the service. | 729 | * Try again to connect to the service. |
703 | * | 730 | * |
704 | * @param h handle to the reclaim service. | 731 | * @param h handle to the reclaim service. |
705 | */ | 732 | */ |
706 | static void | 733 | static void |
707 | reconnect (struct GNUNET_RECLAIM_Handle *h) | 734 | reconnect (struct GNUNET_RECLAIM_Handle *h) |
708 | { | 735 | { |
709 | struct GNUNET_MQ_MessageHandler handlers[] = { | 736 | struct GNUNET_MQ_MessageHandler handlers[] = |
710 | GNUNET_MQ_hd_fixed_size (success_response, | 737 | {GNUNET_MQ_hd_fixed_size (success_response, |
711 | GNUNET_MESSAGE_TYPE_RECLAIM_SUCCESS_RESPONSE, | 738 | GNUNET_MESSAGE_TYPE_RECLAIM_SUCCESS_RESPONSE, |
712 | struct SuccessResultMessage, h), | 739 | struct SuccessResultMessage, |
713 | GNUNET_MQ_hd_var_size (attribute_result, | 740 | h), |
714 | GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_RESULT, | 741 | GNUNET_MQ_hd_var_size (attribute_result, |
715 | struct AttributeResultMessage, h), | 742 | GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_RESULT, |
716 | GNUNET_MQ_hd_fixed_size (ticket_result, | 743 | struct AttributeResultMessage, |
717 | GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_RESULT, | 744 | h), |
718 | struct TicketResultMessage, h), | 745 | GNUNET_MQ_hd_fixed_size (ticket_result, |
719 | GNUNET_MQ_hd_var_size (consume_ticket_result, | 746 | GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_RESULT, |
720 | GNUNET_MESSAGE_TYPE_RECLAIM_CONSUME_TICKET_RESULT, | 747 | struct TicketResultMessage, |
721 | struct ConsumeTicketResultMessage, h), | 748 | h), |
722 | GNUNET_MQ_hd_fixed_size (revoke_ticket_result, | 749 | GNUNET_MQ_hd_var_size (consume_ticket_result, |
723 | GNUNET_MESSAGE_TYPE_RECLAIM_REVOKE_TICKET_RESULT, | 750 | GNUNET_MESSAGE_TYPE_RECLAIM_CONSUME_TICKET_RESULT, |
724 | struct RevokeTicketResultMessage, h), | 751 | struct ConsumeTicketResultMessage, |
725 | GNUNET_MQ_handler_end ()}; | 752 | h), |
726 | struct GNUNET_RECLAIM_Operation *op; | 753 | GNUNET_MQ_hd_fixed_size (revoke_ticket_result, |
727 | 754 | GNUNET_MESSAGE_TYPE_RECLAIM_REVOKE_TICKET_RESULT, | |
728 | GNUNET_assert (NULL == h->mq); | 755 | struct RevokeTicketResultMessage, |
729 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Connecting to reclaim service.\n"); | 756 | h), |
730 | 757 | GNUNET_MQ_handler_end ()}; | |
731 | h->mq = | 758 | struct GNUNET_RECLAIM_Operation *op; |
732 | GNUNET_CLIENT_connect (h->cfg, "reclaim", handlers, &mq_error_handler, h); | ||
733 | if (NULL == h->mq) | ||
734 | return; | ||
735 | for (op = h->op_head; NULL != op; op = op->next) | ||
736 | GNUNET_MQ_send_copy (h->mq, op->env); | ||
737 | } | ||
738 | 759 | ||
760 | GNUNET_assert (NULL == h->mq); | ||
761 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Connecting to reclaim service.\n"); | ||
739 | 762 | ||
740 | /** | 763 | h->mq = |
741 | * Connect to the reclaim service. | 764 | GNUNET_CLIENT_connect (h->cfg, "reclaim", handlers, &mq_error_handler, h); |
742 | * | 765 | if (NULL == h->mq) |
743 | * @param cfg the configuration to use | 766 | return; |
744 | * @return handle to use | 767 | for (op = h->op_head; NULL != op; op = op->next) |
745 | */ | 768 | GNUNET_MQ_send_copy (h->mq, op->env); |
746 | struct GNUNET_RECLAIM_Handle * | 769 | } |
747 | GNUNET_RECLAIM_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) | 770 | |
771 | |||
772 | /** | ||
773 | * Connect to the reclaim service. | ||
774 | * | ||
775 | * @param cfg the configuration to use | ||
776 | * @return handle to use | ||
777 | */ | ||
778 | struct GNUNET_RECLAIM_Handle * | ||
779 | GNUNET_RECLAIM_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
780 | { | ||
781 | struct GNUNET_RECLAIM_Handle *h; | ||
782 | |||
783 | h = GNUNET_new (struct GNUNET_RECLAIM_Handle); | ||
784 | h->cfg = cfg; | ||
785 | reconnect (h); | ||
786 | if (NULL == h->mq) | ||
748 | { | 787 | { |
749 | struct GNUNET_RECLAIM_Handle *h; | 788 | GNUNET_free (h); |
750 | 789 | return NULL; | |
751 | h = GNUNET_new (struct GNUNET_RECLAIM_Handle); | ||
752 | h->cfg = cfg; | ||
753 | reconnect (h); | ||
754 | if (NULL == h->mq) { | ||
755 | GNUNET_free (h); | ||
756 | return NULL; | ||
757 | } | ||
758 | return h; | ||
759 | } | 790 | } |
791 | return h; | ||
792 | } | ||
760 | 793 | ||
761 | 794 | ||
762 | /** | 795 | /** |
763 | * Cancel an operation. Note that the operation MAY still | 796 | * Cancel an operation. Note that the operation MAY still |
764 | * be executed; this merely cancels the continuation; if the request | 797 | * be executed; this merely cancels the continuation; if the request |
765 | * was already transmitted, the service may still choose to complete | 798 | * was already transmitted, the service may still choose to complete |
766 | * the operation. | 799 | * the operation. |
767 | * | 800 | * |
768 | * @param op operation to cancel | 801 | * @param op operation to cancel |
769 | */ | 802 | */ |
770 | void | 803 | void |
771 | GNUNET_RECLAIM_cancel (struct GNUNET_RECLAIM_Operation *op) | 804 | GNUNET_RECLAIM_cancel (struct GNUNET_RECLAIM_Operation *op) |
772 | { | 805 | { |
773 | struct GNUNET_RECLAIM_Handle *h = op->h; | 806 | struct GNUNET_RECLAIM_Handle *h = op->h; |
774 | 807 | ||
775 | GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op); | 808 | GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op); |
776 | free_op (op); | 809 | free_op (op); |
777 | } | 810 | } |
778 | 811 | ||
779 | 812 | ||
780 | /** | 813 | /** |
781 | * Disconnect from service | 814 | * Disconnect from service |
782 | * | 815 | * |
783 | * @param h handle to destroy | 816 | * @param h handle to destroy |
784 | */ | 817 | */ |
785 | void | 818 | void |
786 | GNUNET_RECLAIM_disconnect (struct GNUNET_RECLAIM_Handle *h) | 819 | GNUNET_RECLAIM_disconnect (struct GNUNET_RECLAIM_Handle *h) |
820 | { | ||
821 | GNUNET_assert (NULL != h); | ||
822 | if (NULL != h->mq) | ||
787 | { | 823 | { |
788 | GNUNET_assert (NULL != h); | 824 | GNUNET_MQ_destroy (h->mq); |
789 | if (NULL != h->mq) { | 825 | h->mq = NULL; |
790 | GNUNET_MQ_destroy (h->mq); | 826 | } |
791 | h->mq = NULL; | 827 | if (NULL != h->reconnect_task) |
792 | } | 828 | { |
793 | if (NULL != h->reconnect_task) { | 829 | GNUNET_SCHEDULER_cancel (h->reconnect_task); |
794 | GNUNET_SCHEDULER_cancel (h->reconnect_task); | 830 | h->reconnect_task = NULL; |
795 | h->reconnect_task = NULL; | ||
796 | } | ||
797 | GNUNET_assert (NULL == h->op_head); | ||
798 | GNUNET_free (h); | ||
799 | } | 831 | } |
832 | GNUNET_assert (NULL == h->op_head); | ||
833 | GNUNET_free (h); | ||
834 | } | ||
800 | 835 | ||
801 | /** | 836 | /** |
802 | * Store an attribute. If the attribute is already present, | 837 | * Store an attribute. If the attribute is already present, |
803 | * it is replaced with the new attribute. | 838 | * it is replaced with the new attribute. |
804 | * | 839 | * |
805 | * @param h handle to the re:claimID service | 840 | * @param h handle to the re:claimID service |
@@ -812,11 +847,12 @@ struct GNUNET_RECLAIM_Handle | |||
812 | */ | 847 | */ |
813 | struct GNUNET_RECLAIM_Operation * | 848 | struct GNUNET_RECLAIM_Operation * |
814 | GNUNET_RECLAIM_attribute_store ( | 849 | GNUNET_RECLAIM_attribute_store ( |
815 | struct GNUNET_RECLAIM_Handle *h, | 850 | struct GNUNET_RECLAIM_Handle *h, |
816 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey, | 851 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey, |
817 | const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr, | 852 | const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr, |
818 | const struct GNUNET_TIME_Relative *exp_interval, | 853 | const struct GNUNET_TIME_Relative *exp_interval, |
819 | GNUNET_RECLAIM_ContinuationWithStatus cont, void *cont_cls) | 854 | GNUNET_RECLAIM_ContinuationWithStatus cont, |
855 | void *cont_cls) | ||
820 | { | 856 | { |
821 | struct GNUNET_RECLAIM_Operation *op; | 857 | struct GNUNET_RECLAIM_Operation *op; |
822 | struct AttributeStoreMessage *sam; | 858 | struct AttributeStoreMessage *sam; |
@@ -829,13 +865,14 @@ GNUNET_RECLAIM_attribute_store ( | |||
829 | op->r_id = h->r_id_gen++; | 865 | op->r_id = h->r_id_gen++; |
830 | GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op); | 866 | GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op); |
831 | attr_len = GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size (attr); | 867 | attr_len = GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size (attr); |
832 | op->env = GNUNET_MQ_msg_extra (sam, attr_len, | 868 | op->env = GNUNET_MQ_msg_extra (sam, |
869 | attr_len, | ||
833 | GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_STORE); | 870 | GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_STORE); |
834 | sam->identity = *pkey; | 871 | sam->identity = *pkey; |
835 | sam->id = htonl (op->r_id); | 872 | sam->id = htonl (op->r_id); |
836 | sam->exp = GNUNET_htonll (exp_interval->rel_value_us); | 873 | sam->exp = GNUNET_htonll (exp_interval->rel_value_us); |
837 | 874 | ||
838 | GNUNET_RECLAIM_ATTRIBUTE_serialize (attr, (char *)&sam[1]); | 875 | GNUNET_RECLAIM_ATTRIBUTE_serialize (attr, (char *) &sam[1]); |
839 | 876 | ||
840 | sam->attr_len = htons (attr_len); | 877 | sam->attr_len = htons (attr_len); |
841 | if (NULL != h->mq) | 878 | if (NULL != h->mq) |
@@ -857,10 +894,11 @@ GNUNET_RECLAIM_attribute_store ( | |||
857 | */ | 894 | */ |
858 | struct GNUNET_RECLAIM_Operation * | 895 | struct GNUNET_RECLAIM_Operation * |
859 | GNUNET_RECLAIM_attribute_delete ( | 896 | GNUNET_RECLAIM_attribute_delete ( |
860 | struct GNUNET_RECLAIM_Handle *h, | 897 | struct GNUNET_RECLAIM_Handle *h, |
861 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey, | 898 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey, |
862 | const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr, | 899 | const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr, |
863 | GNUNET_RECLAIM_ContinuationWithStatus cont, void *cont_cls) | 900 | GNUNET_RECLAIM_ContinuationWithStatus cont, |
901 | void *cont_cls) | ||
864 | { | 902 | { |
865 | struct GNUNET_RECLAIM_Operation *op; | 903 | struct GNUNET_RECLAIM_Operation *op; |
866 | struct AttributeDeleteMessage *dam; | 904 | struct AttributeDeleteMessage *dam; |
@@ -873,11 +911,12 @@ GNUNET_RECLAIM_attribute_delete ( | |||
873 | op->r_id = h->r_id_gen++; | 911 | op->r_id = h->r_id_gen++; |
874 | GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op); | 912 | GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op); |
875 | attr_len = GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size (attr); | 913 | attr_len = GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size (attr); |
876 | op->env = GNUNET_MQ_msg_extra (dam, attr_len, | 914 | op->env = GNUNET_MQ_msg_extra (dam, |
915 | attr_len, | ||
877 | GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_DELETE); | 916 | GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_DELETE); |
878 | dam->identity = *pkey; | 917 | dam->identity = *pkey; |
879 | dam->id = htonl (op->r_id); | 918 | dam->id = htonl (op->r_id); |
880 | GNUNET_RECLAIM_ATTRIBUTE_serialize (attr, (char *)&dam[1]); | 919 | GNUNET_RECLAIM_ATTRIBUTE_serialize (attr, (char *) &dam[1]); |
881 | 920 | ||
882 | dam->attr_len = htons (attr_len); | 921 | dam->attr_len = htons (attr_len); |
883 | if (NULL != h->mq) | 922 | if (NULL != h->mq) |
@@ -912,11 +951,14 @@ GNUNET_RECLAIM_attribute_delete ( | |||
912 | */ | 951 | */ |
913 | struct GNUNET_RECLAIM_AttributeIterator * | 952 | struct GNUNET_RECLAIM_AttributeIterator * |
914 | GNUNET_RECLAIM_get_attributes_start ( | 953 | GNUNET_RECLAIM_get_attributes_start ( |
915 | struct GNUNET_RECLAIM_Handle *h, | 954 | struct GNUNET_RECLAIM_Handle *h, |
916 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, | 955 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, |
917 | GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls, | 956 | GNUNET_SCHEDULER_TaskCallback error_cb, |
918 | GNUNET_RECLAIM_AttributeResult proc, void *proc_cls, | 957 | void *error_cb_cls, |
919 | GNUNET_SCHEDULER_TaskCallback finish_cb, void *finish_cb_cls) | 958 | GNUNET_RECLAIM_AttributeResult proc, |
959 | void *proc_cls, | ||
960 | GNUNET_SCHEDULER_TaskCallback finish_cb, | ||
961 | void *finish_cb_cls) | ||
920 | { | 962 | { |
921 | struct GNUNET_RECLAIM_AttributeIterator *it; | 963 | struct GNUNET_RECLAIM_AttributeIterator *it; |
922 | struct GNUNET_MQ_Envelope *env; | 964 | struct GNUNET_MQ_Envelope *env; |
@@ -935,8 +977,8 @@ GNUNET_RECLAIM_get_attributes_start ( | |||
935 | it->r_id = rid; | 977 | it->r_id = rid; |
936 | it->identity = *identity; | 978 | it->identity = *identity; |
937 | GNUNET_CONTAINER_DLL_insert_tail (h->it_head, h->it_tail, it); | 979 | GNUNET_CONTAINER_DLL_insert_tail (h->it_head, h->it_tail, it); |
938 | env = GNUNET_MQ_msg (msg, | 980 | env = |
939 | GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_START); | 981 | GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_START); |
940 | msg->id = htonl (rid); | 982 | msg->id = htonl (rid); |
941 | msg->identity = *identity; | 983 | msg->identity = *identity; |
942 | if (NULL == h->mq) | 984 | if (NULL == h->mq) |
@@ -981,9 +1023,10 @@ GNUNET_RECLAIM_get_attributes_stop (struct GNUNET_RECLAIM_AttributeIterator *it) | |||
981 | struct GNUNET_MQ_Envelope *env; | 1023 | struct GNUNET_MQ_Envelope *env; |
982 | struct AttributeIterationStopMessage *msg; | 1024 | struct AttributeIterationStopMessage *msg; |
983 | 1025 | ||
984 | if (NULL != h->mq) { | 1026 | if (NULL != h->mq) |
985 | env = GNUNET_MQ_msg (msg, | 1027 | { |
986 | GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_STOP); | 1028 | env = |
1029 | GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_STOP); | ||
987 | msg->id = htonl (it->r_id); | 1030 | msg->id = htonl (it->r_id); |
988 | GNUNET_MQ_send (h->mq, env); | 1031 | GNUNET_MQ_send (h->mq, env); |
989 | } | 1032 | } |
@@ -1006,16 +1049,17 @@ GNUNET_RECLAIM_get_attributes_stop (struct GNUNET_RECLAIM_AttributeIterator *it) | |||
1006 | */ | 1049 | */ |
1007 | struct GNUNET_RECLAIM_Operation * | 1050 | struct GNUNET_RECLAIM_Operation * |
1008 | GNUNET_RECLAIM_ticket_issue ( | 1051 | GNUNET_RECLAIM_ticket_issue ( |
1009 | struct GNUNET_RECLAIM_Handle *h, | 1052 | struct GNUNET_RECLAIM_Handle *h, |
1010 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *iss, | 1053 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *iss, |
1011 | const struct GNUNET_CRYPTO_EcdsaPublicKey *rp, | 1054 | const struct GNUNET_CRYPTO_EcdsaPublicKey *rp, |
1012 | const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs, | 1055 | const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs, |
1013 | GNUNET_RECLAIM_TicketCallback cb, void *cb_cls) | 1056 | GNUNET_RECLAIM_TicketCallback cb, |
1057 | void *cb_cls) | ||
1014 | { | 1058 | { |
1015 | struct GNUNET_RECLAIM_Operation *op; | 1059 | struct GNUNET_RECLAIM_Operation *op; |
1016 | struct IssueTicketMessage *tim; | 1060 | struct IssueTicketMessage *tim; |
1017 | size_t attr_len; | 1061 | size_t attr_len; |
1018 | fprintf(stderr, "Issuing ticket\n"); | 1062 | fprintf (stderr, "Issuing ticket\n"); |
1019 | op = GNUNET_new (struct GNUNET_RECLAIM_Operation); | 1063 | op = GNUNET_new (struct GNUNET_RECLAIM_Operation); |
1020 | op->h = h; | 1064 | op->h = h; |
1021 | op->tr_cb = cb; | 1065 | op->tr_cb = cb; |
@@ -1023,13 +1067,14 @@ GNUNET_RECLAIM_ticket_issue ( | |||
1023 | op->r_id = h->r_id_gen++; | 1067 | op->r_id = h->r_id_gen++; |
1024 | GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op); | 1068 | GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op); |
1025 | attr_len = GNUNET_RECLAIM_ATTRIBUTE_list_serialize_get_size (attrs); | 1069 | attr_len = GNUNET_RECLAIM_ATTRIBUTE_list_serialize_get_size (attrs); |
1026 | op->env = GNUNET_MQ_msg_extra (tim, attr_len, | 1070 | op->env = GNUNET_MQ_msg_extra (tim, |
1071 | attr_len, | ||
1027 | GNUNET_MESSAGE_TYPE_RECLAIM_ISSUE_TICKET); | 1072 | GNUNET_MESSAGE_TYPE_RECLAIM_ISSUE_TICKET); |
1028 | tim->identity = *iss; | 1073 | tim->identity = *iss; |
1029 | tim->rp = *rp; | 1074 | tim->rp = *rp; |
1030 | tim->id = htonl (op->r_id); | 1075 | tim->id = htonl (op->r_id); |
1031 | 1076 | ||
1032 | GNUNET_RECLAIM_ATTRIBUTE_list_serialize (attrs, (char *)&tim[1]); | 1077 | GNUNET_RECLAIM_ATTRIBUTE_list_serialize (attrs, (char *) &tim[1]); |
1033 | 1078 | ||
1034 | tim->attr_len = htons (attr_len); | 1079 | tim->attr_len = htons (attr_len); |
1035 | if (NULL != h->mq) | 1080 | if (NULL != h->mq) |
@@ -1052,10 +1097,11 @@ GNUNET_RECLAIM_ticket_issue ( | |||
1052 | */ | 1097 | */ |
1053 | struct GNUNET_RECLAIM_Operation * | 1098 | struct GNUNET_RECLAIM_Operation * |
1054 | GNUNET_RECLAIM_ticket_consume ( | 1099 | GNUNET_RECLAIM_ticket_consume ( |
1055 | struct GNUNET_RECLAIM_Handle *h, | 1100 | struct GNUNET_RECLAIM_Handle *h, |
1056 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, | 1101 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, |
1057 | const struct GNUNET_RECLAIM_Ticket *ticket, | 1102 | const struct GNUNET_RECLAIM_Ticket *ticket, |
1058 | GNUNET_RECLAIM_AttributeResult cb, void *cb_cls) | 1103 | GNUNET_RECLAIM_AttributeResult cb, |
1104 | void *cb_cls) | ||
1059 | { | 1105 | { |
1060 | struct GNUNET_RECLAIM_Operation *op; | 1106 | struct GNUNET_RECLAIM_Operation *op; |
1061 | struct ConsumeTicketMessage *ctm; | 1107 | struct ConsumeTicketMessage *ctm; |
@@ -1066,8 +1112,7 @@ GNUNET_RECLAIM_ticket_consume ( | |||
1066 | op->cls = cb_cls; | 1112 | op->cls = cb_cls; |
1067 | op->r_id = h->r_id_gen++; | 1113 | op->r_id = h->r_id_gen++; |
1068 | GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op); | 1114 | GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op); |
1069 | op->env = | 1115 | op->env = GNUNET_MQ_msg (ctm, GNUNET_MESSAGE_TYPE_RECLAIM_CONSUME_TICKET); |
1070 | GNUNET_MQ_msg (ctm, GNUNET_MESSAGE_TYPE_RECLAIM_CONSUME_TICKET); | ||
1071 | ctm->identity = *identity; | 1116 | ctm->identity = *identity; |
1072 | ctm->id = htonl (op->r_id); | 1117 | ctm->id = htonl (op->r_id); |
1073 | ctm->ticket = *ticket; | 1118 | ctm->ticket = *ticket; |
@@ -1096,11 +1141,14 @@ GNUNET_RECLAIM_ticket_consume ( | |||
1096 | */ | 1141 | */ |
1097 | struct GNUNET_RECLAIM_TicketIterator * | 1142 | struct GNUNET_RECLAIM_TicketIterator * |
1098 | GNUNET_RECLAIM_ticket_iteration_start ( | 1143 | GNUNET_RECLAIM_ticket_iteration_start ( |
1099 | struct GNUNET_RECLAIM_Handle *h, | 1144 | struct GNUNET_RECLAIM_Handle *h, |
1100 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, | 1145 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, |
1101 | GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls, | 1146 | GNUNET_SCHEDULER_TaskCallback error_cb, |
1102 | GNUNET_RECLAIM_TicketCallback proc, void *proc_cls, | 1147 | void *error_cb_cls, |
1103 | GNUNET_SCHEDULER_TaskCallback finish_cb, void *finish_cb_cls) | 1148 | GNUNET_RECLAIM_TicketCallback proc, |
1149 | void *proc_cls, | ||
1150 | GNUNET_SCHEDULER_TaskCallback finish_cb, | ||
1151 | void *finish_cb_cls) | ||
1104 | { | 1152 | { |
1105 | struct GNUNET_RECLAIM_TicketIterator *it; | 1153 | struct GNUNET_RECLAIM_TicketIterator *it; |
1106 | struct GNUNET_MQ_Envelope *env; | 1154 | struct GNUNET_MQ_Envelope *env; |
@@ -1162,7 +1210,8 @@ GNUNET_RECLAIM_ticket_iteration_stop (struct GNUNET_RECLAIM_TicketIterator *it) | |||
1162 | struct GNUNET_MQ_Envelope *env; | 1210 | struct GNUNET_MQ_Envelope *env; |
1163 | struct TicketIterationStopMessage *msg; | 1211 | struct TicketIterationStopMessage *msg; |
1164 | 1212 | ||
1165 | if (NULL != h->mq) { | 1213 | if (NULL != h->mq) |
1214 | { | ||
1166 | env = | 1215 | env = |
1167 | GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_ITERATION_STOP); | 1216 | GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_ITERATION_STOP); |
1168 | msg->id = htonl (it->r_id); | 1217 | msg->id = htonl (it->r_id); |
@@ -1187,10 +1236,11 @@ GNUNET_RECLAIM_ticket_iteration_stop (struct GNUNET_RECLAIM_TicketIterator *it) | |||
1187 | */ | 1236 | */ |
1188 | struct GNUNET_RECLAIM_Operation * | 1237 | struct GNUNET_RECLAIM_Operation * |
1189 | GNUNET_RECLAIM_ticket_revoke ( | 1238 | GNUNET_RECLAIM_ticket_revoke ( |
1190 | struct GNUNET_RECLAIM_Handle *h, | 1239 | struct GNUNET_RECLAIM_Handle *h, |
1191 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, | 1240 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, |
1192 | const struct GNUNET_RECLAIM_Ticket *ticket, | 1241 | const struct GNUNET_RECLAIM_Ticket *ticket, |
1193 | GNUNET_RECLAIM_ContinuationWithStatus cb, void *cb_cls) | 1242 | GNUNET_RECLAIM_ContinuationWithStatus cb, |
1243 | void *cb_cls) | ||
1194 | { | 1244 | { |
1195 | struct GNUNET_RECLAIM_Operation *op; | 1245 | struct GNUNET_RECLAIM_Operation *op; |
1196 | struct RevokeTicketMessage *msg; | 1246 | struct RevokeTicketMessage *msg; |
@@ -1207,7 +1257,8 @@ GNUNET_RECLAIM_ticket_revoke ( | |||
1207 | msg->id = htonl (rid); | 1257 | msg->id = htonl (rid); |
1208 | msg->identity = *identity; | 1258 | msg->identity = *identity; |
1209 | msg->ticket = *ticket; | 1259 | msg->ticket = *ticket; |
1210 | if (NULL != h->mq) { | 1260 | if (NULL != h->mq) |
1261 | { | ||
1211 | GNUNET_MQ_send (h->mq, op->env); | 1262 | GNUNET_MQ_send (h->mq, op->env); |
1212 | op->env = NULL; | 1263 | op->env = NULL; |
1213 | } | 1264 | } |