diff options
author | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2019-04-13 09:50:04 +0200 |
---|---|---|
committer | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2019-04-14 10:01:24 +0200 |
commit | 0a6ac045814213ff33e9317a40daf7250528249a (patch) | |
tree | 3828195017701a02ec0373cec12cf3cc6fad881c /src/reclaim | |
parent | 7a923f1b2d38d55ca921abb57980ccfd1340f634 (diff) | |
download | gnunet-0a6ac045814213ff33e9317a40daf7250528249a.tar.gz gnunet-0a6ac045814213ff33e9317a40daf7250528249a.zip |
RECLAIM: Refactoring
Diffstat (limited to 'src/reclaim')
-rw-r--r-- | src/reclaim/gnunet-service-reclaim.c | 971 | ||||
-rw-r--r-- | src/reclaim/gnunet-service-reclaim_tickets.c | 571 |
2 files changed, 530 insertions, 1012 deletions
diff --git a/src/reclaim/gnunet-service-reclaim.c b/src/reclaim/gnunet-service-reclaim.c index c8ae8a238..51d8554e2 100644 --- a/src/reclaim/gnunet-service-reclaim.c +++ b/src/reclaim/gnunet-service-reclaim.c | |||
@@ -23,17 +23,17 @@ | |||
23 | * @brief reclaim Service | 23 | * @brief reclaim Service |
24 | * | 24 | * |
25 | */ | 25 | */ |
26 | #include "platform.h" | 26 | #include "gnunet-service-reclaim_tickets.h" |
27 | #include "gnunet_util_lib.h" | ||
28 | #include "gnunet_constants.h" | 27 | #include "gnunet_constants.h" |
29 | #include "gnunet_protocols.h" | ||
30 | #include "gnunet_identity_service.h" | ||
31 | #include "gnunet_gnsrecord_lib.h" | 28 | #include "gnunet_gnsrecord_lib.h" |
29 | #include "gnunet_identity_service.h" | ||
32 | #include "gnunet_namestore_service.h" | 30 | #include "gnunet_namestore_service.h" |
33 | #include "gnunet_reclaim_plugin.h" | 31 | #include "gnunet_protocols.h" |
34 | #include "gnunet_reclaim_attribute_lib.h" | 32 | #include "gnunet_reclaim_attribute_lib.h" |
33 | #include "gnunet_reclaim_plugin.h" | ||
35 | #include "gnunet_signatures.h" | 34 | #include "gnunet_signatures.h" |
36 | #include "gnunet-service-reclaim_tickets.h" | 35 | #include "gnunet_util_lib.h" |
36 | #include "platform.h" | ||
37 | #include "reclaim.h" | 37 | #include "reclaim.h" |
38 | 38 | ||
39 | /** | 39 | /** |
@@ -91,7 +91,6 @@ static struct GNUNET_SCHEDULER_Task *timeout_task; | |||
91 | */ | 91 | */ |
92 | static struct GNUNET_SCHEDULER_Task *update_task; | 92 | static struct GNUNET_SCHEDULER_Task *update_task; |
93 | 93 | ||
94 | |||
95 | /** | 94 | /** |
96 | * Our configuration. | 95 | * Our configuration. |
97 | */ | 96 | */ |
@@ -105,8 +104,7 @@ struct IdpClient; | |||
105 | /** | 104 | /** |
106 | * A ticket iteration operation. | 105 | * A ticket iteration operation. |
107 | */ | 106 | */ |
108 | struct TicketIteration | 107 | struct TicketIteration { |
109 | { | ||
110 | /** | 108 | /** |
111 | * DLL | 109 | * DLL |
112 | */ | 110 | */ |
@@ -133,12 +131,10 @@ struct TicketIteration | |||
133 | struct RECLAIM_TICKETS_Iterator *iter; | 131 | struct RECLAIM_TICKETS_Iterator *iter; |
134 | }; | 132 | }; |
135 | 133 | ||
136 | |||
137 | /** | 134 | /** |
138 | * An attribute iteration operation. | 135 | * An attribute iteration operation. |
139 | */ | 136 | */ |
140 | struct AttributeIterator | 137 | struct AttributeIterator { |
141 | { | ||
142 | /** | 138 | /** |
143 | * Next element in the DLL | 139 | * Next element in the DLL |
144 | */ | 140 | */ |
@@ -168,16 +164,12 @@ struct AttributeIterator | |||
168 | * The operation id fot the zone iteration in the response for the client | 164 | * The operation id fot the zone iteration in the response for the client |
169 | */ | 165 | */ |
170 | uint32_t request_id; | 166 | uint32_t request_id; |
171 | |||
172 | }; | 167 | }; |
173 | 168 | ||
174 | |||
175 | |||
176 | /** | 169 | /** |
177 | * An idp client | 170 | * An idp client |
178 | */ | 171 | */ |
179 | struct IdpClient | 172 | struct IdpClient { |
180 | { | ||
181 | 173 | ||
182 | /** | 174 | /** |
183 | * The client | 175 | * The client |
@@ -252,11 +244,9 @@ struct IdpClient | |||
252 | * Tail of DLL of attribute store ops | 244 | * Tail of DLL of attribute store ops |
253 | */ | 245 | */ |
254 | struct AttributeStoreHandle *store_op_tail; | 246 | struct AttributeStoreHandle *store_op_tail; |
255 | |||
256 | }; | 247 | }; |
257 | 248 | ||
258 | struct AttributeStoreHandle | 249 | struct AttributeStoreHandle { |
259 | { | ||
260 | /** | 250 | /** |
261 | * DLL | 251 | * DLL |
262 | */ | 252 | */ |
@@ -303,9 +293,7 @@ struct AttributeStoreHandle | |||
303 | uint32_t r_id; | 293 | uint32_t r_id; |
304 | }; | 294 | }; |
305 | 295 | ||
306 | 296 | struct ConsumeTicketOperation { | |
307 | struct ConsumeTicketOperation | ||
308 | { | ||
309 | /** | 297 | /** |
310 | * DLL | 298 | * DLL |
311 | */ | 299 | */ |
@@ -332,12 +320,10 @@ struct ConsumeTicketOperation | |||
332 | struct RECLAIM_TICKETS_ConsumeHandle *ch; | 320 | struct RECLAIM_TICKETS_ConsumeHandle *ch; |
333 | }; | 321 | }; |
334 | 322 | ||
335 | |||
336 | /** | 323 | /** |
337 | * Updated attribute IDs | 324 | * Updated attribute IDs |
338 | */ | 325 | */ |
339 | struct TicketAttributeUpdateEntry | 326 | struct TicketAttributeUpdateEntry { |
340 | { | ||
341 | /** | 327 | /** |
342 | * DLL | 328 | * DLL |
343 | */ | 329 | */ |
@@ -362,8 +348,7 @@ struct TicketAttributeUpdateEntry | |||
362 | /** | 348 | /** |
363 | * Ticket revocation request handle | 349 | * Ticket revocation request handle |
364 | */ | 350 | */ |
365 | struct TicketRevocationHandle | 351 | struct TicketRevocationHandle { |
366 | { | ||
367 | /** | 352 | /** |
368 | * DLL | 353 | * DLL |
369 | */ | 354 | */ |
@@ -430,13 +415,10 @@ struct TicketRevocationHandle | |||
430 | uint32_t r_id; | 415 | uint32_t r_id; |
431 | }; | 416 | }; |
432 | 417 | ||
433 | |||
434 | |||
435 | /** | 418 | /** |
436 | * Ticket issue operation handle | 419 | * Ticket issue operation handle |
437 | */ | 420 | */ |
438 | struct TicketIssueOperation | 421 | struct TicketIssueOperation { |
439 | { | ||
440 | /** | 422 | /** |
441 | * DLL | 423 | * DLL |
442 | */ | 424 | */ |
@@ -458,14 +440,12 @@ struct TicketIssueOperation | |||
458 | uint32_t r_id; | 440 | uint32_t r_id; |
459 | }; | 441 | }; |
460 | 442 | ||
461 | |||
462 | /** | 443 | /** |
463 | * DLL for ego handles to egos containing the RECLAIM_ATTRS in a | 444 | * DLL for ego handles to egos containing the RECLAIM_ATTRS in a |
464 | * map in json_t format | 445 | * map in json_t format |
465 | * | 446 | * |
466 | */ | 447 | */ |
467 | struct EgoEntry | 448 | struct EgoEntry { |
468 | { | ||
469 | /** | 449 | /** |
470 | * DLL | 450 | * DLL |
471 | */ | 451 | */ |
@@ -485,21 +465,17 @@ struct EgoEntry | |||
485 | * Attribute map. Contains the attributes as json_t | 465 | * Attribute map. Contains the attributes as json_t |
486 | */ | 466 | */ |
487 | struct GNUNET_CONTAINER_MultiHashMap *attr_map; | 467 | struct GNUNET_CONTAINER_MultiHashMap *attr_map; |
488 | |||
489 | }; | 468 | }; |
490 | 469 | ||
491 | /** | 470 | /** |
492 | * Cleanup task | 471 | * Cleanup task |
493 | */ | 472 | */ |
494 | static void | 473 | static void cleanup () |
495 | cleanup() | ||
496 | { | 474 | { |
497 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 475 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n"); |
498 | "Cleaning up\n"); | ||
499 | 476 | ||
500 | RECLAIM_TICKETS_deinit (); | 477 | RECLAIM_TICKETS_deinit (); |
501 | GNUNET_break (NULL == GNUNET_PLUGIN_unload (db_lib_name, | 478 | GNUNET_break (NULL == GNUNET_PLUGIN_unload (db_lib_name, TKT_database)); |
502 | TKT_database)); | ||
503 | GNUNET_free (db_lib_name); | 479 | GNUNET_free (db_lib_name); |
504 | db_lib_name = NULL; | 480 | db_lib_name = NULL; |
505 | if (NULL != timeout_task) | 481 | if (NULL != timeout_task) |
@@ -517,117 +493,89 @@ cleanup() | |||
517 | * | 493 | * |
518 | * @param cls NULL | 494 | * @param cls NULL |
519 | */ | 495 | */ |
520 | static void | 496 | static void do_shutdown (void *cls) |
521 | do_shutdown (void *cls) | ||
522 | { | 497 | { |
523 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 498 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Shutting down...\n"); |
524 | "Shutting down...\n"); | 499 | cleanup (); |
525 | cleanup(); | ||
526 | } | 500 | } |
527 | 501 | ||
528 | 502 | static int create_sym_key_from_ecdh ( | |
529 | static int | 503 | const struct GNUNET_HashCode *new_key_hash, |
530 | create_sym_key_from_ecdh (const struct GNUNET_HashCode *new_key_hash, | 504 | struct GNUNET_CRYPTO_SymmetricSessionKey *skey, |
531 | struct GNUNET_CRYPTO_SymmetricSessionKey *skey, | 505 | struct GNUNET_CRYPTO_SymmetricInitializationVector *iv) |
532 | struct GNUNET_CRYPTO_SymmetricInitializationVector *iv) | ||
533 | { | 506 | { |
534 | struct GNUNET_CRYPTO_HashAsciiEncoded new_key_hash_str; | 507 | struct GNUNET_CRYPTO_HashAsciiEncoded new_key_hash_str; |
535 | 508 | ||
536 | GNUNET_CRYPTO_hash_to_enc (new_key_hash, | 509 | GNUNET_CRYPTO_hash_to_enc (new_key_hash, &new_key_hash_str); |
537 | &new_key_hash_str); | 510 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating symmetric rsa key from %s\n", |
538 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating symmetric rsa key from %s\n", (char*)&new_key_hash_str); | 511 | (char *)&new_key_hash_str); |
539 | static const char ctx_key[] = "gnuid-aes-ctx-key"; | 512 | static const char ctx_key[] = "gnuid-aes-ctx-key"; |
540 | GNUNET_CRYPTO_kdf (skey, sizeof (struct GNUNET_CRYPTO_SymmetricSessionKey), | 513 | GNUNET_CRYPTO_kdf (skey, sizeof (struct GNUNET_CRYPTO_SymmetricSessionKey), |
541 | new_key_hash, sizeof (struct GNUNET_HashCode), | 514 | new_key_hash, sizeof (struct GNUNET_HashCode), ctx_key, |
542 | ctx_key, strlen (ctx_key), | 515 | strlen (ctx_key), NULL, 0); |
543 | NULL, 0); | ||
544 | static const char ctx_iv[] = "gnuid-aes-ctx-iv"; | 516 | static const char ctx_iv[] = "gnuid-aes-ctx-iv"; |
545 | GNUNET_CRYPTO_kdf (iv, sizeof (struct GNUNET_CRYPTO_SymmetricInitializationVector), | 517 | GNUNET_CRYPTO_kdf ( |
546 | new_key_hash, sizeof (struct GNUNET_HashCode), | 518 | iv, sizeof (struct GNUNET_CRYPTO_SymmetricInitializationVector), |
547 | ctx_iv, strlen (ctx_iv), | 519 | new_key_hash, sizeof (struct GNUNET_HashCode), ctx_iv, strlen (ctx_iv), |
548 | NULL, 0); | 520 | NULL, 0); |
549 | return GNUNET_OK; | 521 | return GNUNET_OK; |
550 | } | 522 | } |
551 | 523 | ||
552 | 524 | static void send_ticket_result (const struct IdpClient *client, uint32_t r_id, | |
553 | static void | 525 | const struct GNUNET_RECLAIM_Ticket *ticket, |
554 | send_ticket_result (const struct IdpClient *client, | 526 | uint32_t success) |
555 | uint32_t r_id, | ||
556 | const struct GNUNET_RECLAIM_Ticket *ticket, | ||
557 | uint32_t success) | ||
558 | { | 527 | { |
559 | struct TicketResultMessage *irm; | 528 | struct TicketResultMessage *irm; |
560 | struct GNUNET_MQ_Envelope *env; | 529 | struct GNUNET_MQ_Envelope *env; |
561 | struct GNUNET_RECLAIM_Ticket *ticket_buf; | 530 | struct GNUNET_RECLAIM_Ticket *ticket_buf; |
562 | 531 | ||
563 | if (NULL != ticket) | 532 | if (NULL != ticket) { |
564 | { | 533 | env = GNUNET_MQ_msg_extra (irm, sizeof (struct GNUNET_RECLAIM_Ticket), |
565 | env = GNUNET_MQ_msg_extra (irm, | ||
566 | sizeof (struct GNUNET_RECLAIM_Ticket), | ||
567 | GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_RESULT); | 534 | GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_RESULT); |
568 | ticket_buf = (struct GNUNET_RECLAIM_Ticket *)&irm[1]; | 535 | ticket_buf = (struct GNUNET_RECLAIM_Ticket *)&irm[1]; |
569 | *ticket_buf = *ticket; | 536 | *ticket_buf = *ticket; |
570 | } else { | 537 | } else { |
571 | env = GNUNET_MQ_msg (irm, | 538 | env = GNUNET_MQ_msg (irm, GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_RESULT); |
572 | GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_RESULT); | ||
573 | } | 539 | } |
574 | //TODO add success member | 540 | // TODO add success member |
575 | irm->id = htonl (r_id); | 541 | irm->id = htonl (r_id); |
576 | GNUNET_MQ_send (client->mq, | 542 | GNUNET_MQ_send (client->mq, env); |
577 | env); | ||
578 | } | 543 | } |
579 | 544 | ||
580 | 545 | static void issue_ticket_result_cb (void *cls, | |
581 | static void | 546 | struct GNUNET_RECLAIM_Ticket *ticket, |
582 | issue_ticket_result_cb (void *cls, | 547 | uint32_t success, const char *emsg) |
583 | struct GNUNET_RECLAIM_Ticket *ticket, | ||
584 | uint32_t success, | ||
585 | const char* emsg) | ||
586 | { | 548 | { |
587 | struct TicketIssueOperation *tio = cls; | 549 | struct TicketIssueOperation *tio = cls; |
588 | if (GNUNET_OK != success) | 550 | if (GNUNET_OK != success) { |
589 | { | 551 | send_ticket_result (tio->client, tio->r_id, NULL, GNUNET_SYSERR); |
590 | send_ticket_result (tio->client, | ||
591 | tio->r_id, | ||
592 | NULL, | ||
593 | GNUNET_SYSERR); | ||
594 | GNUNET_CONTAINER_DLL_remove (tio->client->issue_op_head, | 552 | GNUNET_CONTAINER_DLL_remove (tio->client->issue_op_head, |
595 | tio->client->issue_op_tail, | 553 | tio->client->issue_op_tail, tio); |
596 | tio); | ||
597 | GNUNET_free (tio); | 554 | GNUNET_free (tio); |
598 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 555 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error issuing ticket: %s\n", emsg); |
599 | "Error issuing ticket: %s\n", | ||
600 | emsg); | ||
601 | return; | 556 | return; |
602 | } | 557 | } |
603 | send_ticket_result (tio->client, | 558 | send_ticket_result (tio->client, tio->r_id, ticket, GNUNET_SYSERR); |
604 | tio->r_id, | ||
605 | ticket, | ||
606 | GNUNET_SYSERR); | ||
607 | GNUNET_CONTAINER_DLL_remove (tio->client->issue_op_head, | 559 | GNUNET_CONTAINER_DLL_remove (tio->client->issue_op_head, |
608 | tio->client->issue_op_tail, | 560 | tio->client->issue_op_tail, tio); |
609 | tio); | ||
610 | GNUNET_free (tio); | 561 | GNUNET_free (tio); |
611 | } | 562 | } |
612 | 563 | ||
613 | static int | 564 | static int check_issue_ticket_message (void *cls, |
614 | check_issue_ticket_message (void *cls, | 565 | const struct IssueTicketMessage *im) |
615 | const struct IssueTicketMessage *im) | ||
616 | { | 566 | { |
617 | uint16_t size; | 567 | uint16_t size; |
618 | 568 | ||
619 | size = ntohs (im->header.size); | 569 | size = ntohs (im->header.size); |
620 | if (size <= sizeof (struct IssueTicketMessage)) | 570 | if (size <= sizeof (struct IssueTicketMessage)) { |
621 | { | ||
622 | GNUNET_break (0); | 571 | GNUNET_break (0); |
623 | return GNUNET_SYSERR; | 572 | return GNUNET_SYSERR; |
624 | } | 573 | } |
625 | return GNUNET_OK; | 574 | return GNUNET_OK; |
626 | } | 575 | } |
627 | 576 | ||
628 | static void | 577 | static void handle_issue_ticket_message (void *cls, |
629 | handle_issue_ticket_message (void *cls, | 578 | const struct IssueTicketMessage *im) |
630 | const struct IssueTicketMessage *im) | ||
631 | { | 579 | { |
632 | struct TicketIssueOperation *tio; | 580 | struct TicketIssueOperation *tio; |
633 | struct IdpClient *idp = cls; | 581 | struct IdpClient *idp = cls; |
@@ -636,16 +584,11 @@ handle_issue_ticket_message (void *cls, | |||
636 | 584 | ||
637 | tio = GNUNET_new (struct TicketIssueOperation); | 585 | tio = GNUNET_new (struct TicketIssueOperation); |
638 | attrs_len = ntohs (im->attr_len); | 586 | attrs_len = ntohs (im->attr_len); |
639 | attrs = GNUNET_RECLAIM_ATTRIBUTE_list_deserialize ((char*)&im[1], attrs_len); | 587 | attrs = GNUNET_RECLAIM_ATTRIBUTE_list_deserialize ((char *)&im[1], attrs_len); |
640 | tio->r_id = ntohl (im->id); | 588 | tio->r_id = ntohl (im->id); |
641 | tio->client = idp; | 589 | tio->client = idp; |
642 | GNUNET_CONTAINER_DLL_insert (idp->issue_op_head, | 590 | GNUNET_CONTAINER_DLL_insert (idp->issue_op_head, idp->issue_op_tail, tio); |
643 | idp->issue_op_tail, | 591 | RECLAIM_TICKETS_issue (&im->identity, attrs, &im->rp, &issue_ticket_result_cb, |
644 | tio); | ||
645 | RECLAIM_TICKETS_issue (&im->identity, | ||
646 | attrs, | ||
647 | &im->rp, | ||
648 | &issue_ticket_result_cb, | ||
649 | tio); | 592 | tio); |
650 | GNUNET_SERVICE_client_continue (idp->client); | 593 | GNUNET_SERVICE_client_continue (idp->client); |
651 | GNUNET_RECLAIM_ATTRIBUTE_list_destroy (attrs); | 594 | GNUNET_RECLAIM_ATTRIBUTE_list_destroy (attrs); |
@@ -660,8 +603,7 @@ handle_issue_ticket_message (void *cls, | |||
660 | * | 603 | * |
661 | * @param rh the ticket revocation handle | 604 | * @param rh the ticket revocation handle |
662 | */ | 605 | */ |
663 | static void | 606 | static void cleanup_revoke_ticket_handle (struct TicketRevocationHandle *rh) |
664 | cleanup_revoke_ticket_handle (struct TicketRevocationHandle *rh) | ||
665 | { | 607 | { |
666 | if (NULL != rh->attrs) | 608 | if (NULL != rh->attrs) |
667 | GNUNET_RECLAIM_ATTRIBUTE_list_destroy (rh->attrs); | 609 | GNUNET_RECLAIM_ATTRIBUTE_list_destroy (rh->attrs); |
@@ -690,88 +632,73 @@ serialize_authz_record (const struct GNUNET_RECLAIM_Ticket *ticket, | |||
690 | char *buf; | 632 | char *buf; |
691 | char *write_ptr; | 633 | char *write_ptr; |
692 | char attrs_str_len; | 634 | char attrs_str_len; |
693 | char* label; | 635 | char *label; |
694 | 636 | ||
695 | GNUNET_assert (NULL != attrs->list_head); | 637 | GNUNET_assert (NULL != attrs->list_head); |
696 | attrs_str_len = 0; | 638 | attrs_str_len = 0; |
697 | for (le = attrs->list_head; NULL != le; le = le->next) { | 639 | for (le = attrs->list_head; NULL != le; le = le->next) { |
698 | attrs_str_len += 15 + 1; //TODO propery calculate | 640 | attrs_str_len += 15 + 1; // TODO propery calculate |
699 | } | 641 | } |
700 | buf = GNUNET_malloc (attrs_str_len); | 642 | buf = GNUNET_malloc (attrs_str_len); |
701 | write_ptr = buf; | 643 | write_ptr = buf; |
702 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 644 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Writing attributes\n"); |
703 | "Writing attributes\n"); | ||
704 | for (le = attrs->list_head; NULL != le; le = le->next) { | 645 | for (le = attrs->list_head; NULL != le; le = le->next) { |
705 | label = GNUNET_STRINGS_data_to_string_alloc (&le->claim->id, | 646 | label = |
706 | sizeof (uint64_t)); | 647 | GNUNET_STRINGS_data_to_string_alloc (&le->claim->id, sizeof (uint64_t)); |
707 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 648 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Adding attribute to record: %s\n", |
708 | "Adding attribute to record: %s\n", label); | 649 | label); |
709 | 650 | ||
710 | GNUNET_memcpy (write_ptr, | 651 | GNUNET_memcpy (write_ptr, label, strlen (label)); |
711 | label, | ||
712 | strlen (label)); | ||
713 | write_ptr[strlen (label)] = ','; | 652 | write_ptr[strlen (label)] = ','; |
714 | write_ptr += strlen (label) + 1; | 653 | write_ptr += strlen (label) + 1; |
715 | GNUNET_free (label); | 654 | GNUNET_free (label); |
716 | } | 655 | } |
717 | write_ptr--; | 656 | write_ptr--; |
718 | write_ptr[0] = '\0'; //replace last , with a 0-terminator | 657 | write_ptr[0] = '\0'; // replace last , with a 0-terminator |
719 | // ECDH keypair E = eG | 658 | // ECDH keypair E = eG |
720 | *ecdh_privkey = GNUNET_CRYPTO_ecdhe_key_create(); | 659 | *ecdh_privkey = GNUNET_CRYPTO_ecdhe_key_create (); |
721 | GNUNET_CRYPTO_ecdhe_key_get_public (*ecdh_privkey, | 660 | GNUNET_CRYPTO_ecdhe_key_get_public (*ecdh_privkey, &ecdh_pubkey); |
722 | &ecdh_pubkey); | ||
723 | enc_keyinfo = GNUNET_malloc (attrs_str_len); | 661 | enc_keyinfo = GNUNET_malloc (attrs_str_len); |
724 | // Derived key K = H(eB) | 662 | // Derived key K = H(eB) |
725 | GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_ecdh_ecdsa (*ecdh_privkey, | 663 | GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_ecdh_ecdsa (*ecdh_privkey, |
726 | &ticket->audience, | 664 | &ticket->audience, |
727 | &new_key_hash)); | 665 | &new_key_hash)); |
728 | create_sym_key_from_ecdh (&new_key_hash, &skey, &iv); | 666 | create_sym_key_from_ecdh (&new_key_hash, &skey, &iv); |
729 | enc_size = GNUNET_CRYPTO_symmetric_encrypt (buf, | 667 | enc_size = GNUNET_CRYPTO_symmetric_encrypt (buf, attrs_str_len, &skey, &iv, |
730 | attrs_str_len, | ||
731 | &skey, &iv, | ||
732 | enc_keyinfo); | 668 | enc_keyinfo); |
733 | *result = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_EcdhePublicKey)+ | 669 | *result = |
734 | enc_size); | 670 | GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_EcdhePublicKey) + enc_size); |
735 | GNUNET_memcpy (*result, | 671 | GNUNET_memcpy (*result, &ecdh_pubkey, |
736 | &ecdh_pubkey, | ||
737 | sizeof (struct GNUNET_CRYPTO_EcdhePublicKey)); | 672 | sizeof (struct GNUNET_CRYPTO_EcdhePublicKey)); |
738 | GNUNET_memcpy (*result + sizeof (struct GNUNET_CRYPTO_EcdhePublicKey), | 673 | GNUNET_memcpy (*result + sizeof (struct GNUNET_CRYPTO_EcdhePublicKey), |
739 | enc_keyinfo, | 674 | enc_keyinfo, enc_size); |
740 | enc_size); | ||
741 | GNUNET_free (enc_keyinfo); | 675 | GNUNET_free (enc_keyinfo); |
742 | GNUNET_free (buf); | 676 | GNUNET_free (buf); |
743 | return sizeof (struct GNUNET_CRYPTO_EcdhePublicKey)+enc_size; | 677 | return sizeof (struct GNUNET_CRYPTO_EcdhePublicKey) + enc_size; |
744 | } | 678 | } |
745 | 679 | ||
746 | |||
747 | /** | 680 | /** |
748 | * Send revocation result | 681 | * Send revocation result |
749 | * | 682 | * |
750 | * @param rh ticket revocation handle | 683 | * @param rh ticket revocation handle |
751 | * @param success GNUNET_OK if successful result | 684 | * @param success GNUNET_OK if successful result |
752 | */ | 685 | */ |
753 | static void | 686 | static void send_revocation_finished (struct TicketRevocationHandle *rh, |
754 | send_revocation_finished (struct TicketRevocationHandle *rh, | 687 | uint32_t success) |
755 | uint32_t success) | ||
756 | { | 688 | { |
757 | struct GNUNET_MQ_Envelope *env; | 689 | struct GNUNET_MQ_Envelope *env; |
758 | struct RevokeTicketResultMessage *trm; | 690 | struct RevokeTicketResultMessage *trm; |
759 | 691 | ||
760 | GNUNET_break(TKT_database->delete_ticket (TKT_database->cls, | 692 | GNUNET_break (TKT_database->delete_ticket (TKT_database->cls, &rh->ticket)); |
761 | &rh->ticket)); | ||
762 | 693 | ||
763 | env = GNUNET_MQ_msg (trm, | 694 | env = GNUNET_MQ_msg (trm, GNUNET_MESSAGE_TYPE_RECLAIM_REVOKE_TICKET_RESULT); |
764 | GNUNET_MESSAGE_TYPE_RECLAIM_REVOKE_TICKET_RESULT); | ||
765 | trm->id = htonl (rh->r_id); | 695 | trm->id = htonl (rh->r_id); |
766 | trm->success = htonl (success); | 696 | trm->success = htonl (success); |
767 | GNUNET_MQ_send (rh->client->mq, | 697 | GNUNET_MQ_send (rh->client->mq, env); |
768 | env); | ||
769 | GNUNET_CONTAINER_DLL_remove (rh->client->revoke_op_head, | 698 | GNUNET_CONTAINER_DLL_remove (rh->client->revoke_op_head, |
770 | rh->client->revoke_op_tail, | 699 | rh->client->revoke_op_tail, rh); |
771 | rh); | ||
772 | } | 700 | } |
773 | 701 | ||
774 | |||
775 | /** | 702 | /** |
776 | * Process ticket from database | 703 | * Process ticket from database |
777 | * | 704 | * |
@@ -780,13 +707,10 @@ send_revocation_finished (struct TicketRevocationHandle *rh, | |||
780 | * @param attrs the attributes | 707 | * @param attrs the attributes |
781 | */ | 708 | */ |
782 | static void | 709 | static void |
783 | ticket_reissue_proc (void *cls, | 710 | ticket_reissue_proc (void *cls, const struct GNUNET_RECLAIM_Ticket *ticket, |
784 | const struct GNUNET_RECLAIM_Ticket *ticket, | ||
785 | const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs); | 711 | const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs); |
786 | 712 | ||
787 | static void | 713 | static void revocation_reissue_tickets (struct TicketRevocationHandle *rh); |
788 | revocation_reissue_tickets (struct TicketRevocationHandle *rh); | ||
789 | |||
790 | 714 | ||
791 | static void reissue_next (void *cls) | 715 | static void reissue_next (void *cls) |
792 | { | 716 | { |
@@ -794,19 +718,13 @@ static void reissue_next (void *cls) | |||
794 | revocation_reissue_tickets (rh); | 718 | revocation_reissue_tickets (rh); |
795 | } | 719 | } |
796 | 720 | ||
797 | 721 | static void reissue_ticket_cont (void *cls, int32_t success, const char *emsg) | |
798 | static void | ||
799 | reissue_ticket_cont (void *cls, | ||
800 | int32_t success, | ||
801 | const char *emsg) | ||
802 | { | 722 | { |
803 | struct TicketRevocationHandle *rh = cls; | 723 | struct TicketRevocationHandle *rh = cls; |
804 | 724 | ||
805 | rh->ns_qe = NULL; | 725 | rh->ns_qe = NULL; |
806 | if (GNUNET_SYSERR == success) | 726 | if (GNUNET_SYSERR == success) { |
807 | { | 727 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s\n", "Unknown Error\n"); |
808 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s\n", | ||
809 | "Unknown Error\n"); | ||
810 | send_revocation_finished (rh, GNUNET_SYSERR); | 728 | send_revocation_finished (rh, GNUNET_SYSERR); |
811 | cleanup_revoke_ticket_handle (rh); | 729 | cleanup_revoke_ticket_handle (rh); |
812 | return; | 730 | return; |
@@ -815,7 +733,6 @@ reissue_ticket_cont (void *cls, | |||
815 | GNUNET_SCHEDULER_add_now (&reissue_next, rh); | 733 | GNUNET_SCHEDULER_add_now (&reissue_next, rh); |
816 | } | 734 | } |
817 | 735 | ||
818 | |||
819 | /** | 736 | /** |
820 | * Process ticket from database | 737 | * Process ticket from database |
821 | * | 738 | * |
@@ -824,8 +741,7 @@ reissue_ticket_cont (void *cls, | |||
824 | * @param attrs the attributes | 741 | * @param attrs the attributes |
825 | */ | 742 | */ |
826 | static void | 743 | static void |
827 | ticket_reissue_proc (void *cls, | 744 | ticket_reissue_proc (void *cls, const struct GNUNET_RECLAIM_Ticket *ticket, |
828 | const struct GNUNET_RECLAIM_Ticket *ticket, | ||
829 | const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs) | 745 | const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs) |
830 | { | 746 | { |
831 | struct TicketRevocationHandle *rh = cls; | 747 | struct TicketRevocationHandle *rh = cls; |
@@ -838,30 +754,20 @@ ticket_reissue_proc (void *cls, | |||
838 | char *authz_record_data; | 754 | char *authz_record_data; |
839 | char *label; | 755 | char *label; |
840 | 756 | ||
841 | 757 | if (NULL == ticket) { | |
842 | if (NULL == ticket) | 758 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Iteration done\n"); |
843 | { | ||
844 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
845 | "Iteration done\n"); | ||
846 | return; | 759 | return; |
847 | } | 760 | } |
848 | 761 | ||
849 | if (0 == memcmp (&ticket->audience, | 762 | if (0 == memcmp (&ticket->audience, &rh->ticket.audience, |
850 | &rh->ticket.audience, | 763 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))) { |
851 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))) | ||
852 | { | ||
853 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 764 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
854 | "Do not reissue for this identity.!\n"); | 765 | "Do not reissue for this identity.!\n"); |
855 | label = GNUNET_STRINGS_data_to_string_alloc (&rh->ticket.rnd, | 766 | label = GNUNET_STRINGS_data_to_string_alloc (&rh->ticket.rnd, |
856 | sizeof (uint64_t)); | 767 | sizeof (uint64_t)); |
857 | //Delete record | 768 | // Delete record |
858 | rh->ns_qe = GNUNET_NAMESTORE_records_store (nsh, | 769 | rh->ns_qe = GNUNET_NAMESTORE_records_store (nsh, &rh->identity, label, 0, |
859 | &rh->identity, | 770 | NULL, &reissue_ticket_cont, rh); |
860 | label, | ||
861 | 0, | ||
862 | NULL, | ||
863 | &reissue_ticket_cont, | ||
864 | rh); | ||
865 | 771 | ||
866 | GNUNET_free (label); | 772 | GNUNET_free (label); |
867 | return; | 773 | return; |
@@ -871,38 +777,29 @@ ticket_reissue_proc (void *cls, | |||
871 | * Check if any attribute of this ticket intersects with a rollover attribute | 777 | * Check if any attribute of this ticket intersects with a rollover attribute |
872 | */ | 778 | */ |
873 | reissue_ticket = GNUNET_NO; | 779 | reissue_ticket = GNUNET_NO; |
874 | for (le = attrs->list_head; NULL != le; le = le->next) | 780 | for (le = attrs->list_head; NULL != le; le = le->next) { |
875 | { | 781 | for (tue = rh->attr_updates_head; NULL != tue; tue = tue->next) { |
876 | for (tue = rh->attr_updates_head; | 782 | if (tue->old_id == le->claim->id) { |
877 | NULL != tue; | ||
878 | tue = tue->next) | ||
879 | { | ||
880 | if (tue->old_id == le->claim->id) | ||
881 | { | ||
882 | reissue_ticket = GNUNET_YES; | 783 | reissue_ticket = GNUNET_YES; |
883 | le->claim->id = tue->new_id; | 784 | le->claim->id = tue->new_id; |
884 | } | 785 | } |
885 | } | 786 | } |
886 | } | 787 | } |
887 | 788 | ||
888 | if (GNUNET_NO == reissue_ticket) | 789 | if (GNUNET_NO == reissue_ticket) { |
889 | { | 790 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Skipping ticket.\n"); |
890 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
891 | "Skipping ticket.\n"); | ||
892 | 791 | ||
893 | rh->offset++; | 792 | rh->offset++; |
894 | GNUNET_SCHEDULER_add_now (&reissue_next, rh); | 793 | GNUNET_SCHEDULER_add_now (&reissue_next, rh); |
895 | return; | 794 | return; |
896 | } | 795 | } |
897 | 796 | ||
898 | //Create new ABE key for RP | 797 | // Create new ABE key for RP |
899 | 798 | ||
900 | /* If this is the RP we want to revoke attributes of, the do so */ | 799 | /* If this is the RP we want to revoke attributes of, the do so */ |
901 | 800 | ||
902 | //TODO rename function | 801 | // TODO rename function |
903 | authz_record_len = serialize_authz_record (ticket, | 802 | authz_record_len = serialize_authz_record (ticket, attrs, &ecdhe_privkey, |
904 | attrs, | ||
905 | &ecdhe_privkey, | ||
906 | &authz_record_data); | 803 | &authz_record_data); |
907 | code_record[0].data = authz_record_data; | 804 | code_record[0].data = authz_record_data; |
908 | code_record[0].data_size = authz_record_len; | 805 | code_record[0].data_size = authz_record_len; |
@@ -910,46 +807,30 @@ ticket_reissue_proc (void *cls, | |||
910 | code_record[0].record_type = GNUNET_GNSRECORD_TYPE_RECLAIM_AUTHZ; | 807 | code_record[0].record_type = GNUNET_GNSRECORD_TYPE_RECLAIM_AUTHZ; |
911 | code_record[0].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; | 808 | code_record[0].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; |
912 | 809 | ||
913 | label = GNUNET_STRINGS_data_to_string_alloc (&ticket->rnd, | 810 | label = GNUNET_STRINGS_data_to_string_alloc (&ticket->rnd, sizeof (uint64_t)); |
914 | sizeof (uint64_t)); | 811 | // Publish record |
915 | //Publish record | 812 | rh->ns_qe = GNUNET_NAMESTORE_records_store ( |
916 | rh->ns_qe = GNUNET_NAMESTORE_records_store (nsh, | 813 | nsh, &rh->identity, label, 1, code_record, &reissue_ticket_cont, rh); |
917 | &rh->identity, | ||
918 | label, | ||
919 | 1, | ||
920 | code_record, | ||
921 | &reissue_ticket_cont, | ||
922 | rh); | ||
923 | GNUNET_free (ecdhe_privkey); | 814 | GNUNET_free (ecdhe_privkey); |
924 | GNUNET_free (label); | 815 | GNUNET_free (label); |
925 | GNUNET_free (authz_record_data); | 816 | GNUNET_free (authz_record_data); |
926 | } | 817 | } |
927 | 818 | ||
928 | |||
929 | /* Prototype for below function */ | 819 | /* Prototype for below function */ |
930 | static void | 820 | static void attr_reenc_cont (void *cls, int32_t success, const char *emsg); |
931 | attr_reenc_cont (void *cls, | ||
932 | int32_t success, | ||
933 | const char *emsg); | ||
934 | 821 | ||
935 | static void | 822 | static void revocation_reissue_tickets (struct TicketRevocationHandle *rh) |
936 | revocation_reissue_tickets (struct TicketRevocationHandle *rh) | ||
937 | { | 823 | { |
938 | int ret; | 824 | int ret; |
939 | /* Done, issue new keys */ | 825 | /* Done, issue new keys */ |
940 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 826 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
941 | "Revocation Phase III: Reissuing Tickets\n"); | 827 | "Revocation Phase III: Reissuing Tickets\n"); |
942 | if (GNUNET_SYSERR == (ret = TKT_database->iterate_tickets (TKT_database->cls, | 828 | if (GNUNET_SYSERR == (ret = TKT_database->iterate_tickets ( |
943 | &rh->ticket.identity, | 829 | TKT_database->cls, &rh->ticket.identity, GNUNET_NO, |
944 | GNUNET_NO, | 830 | rh->offset, &ticket_reissue_proc, rh))) { |
945 | rh->offset, | ||
946 | &ticket_reissue_proc, | ||
947 | rh))) | ||
948 | { | ||
949 | GNUNET_break (0); | 831 | GNUNET_break (0); |
950 | } | 832 | } |
951 | if (GNUNET_NO == ret) | 833 | if (GNUNET_NO == ret) { |
952 | { | ||
953 | send_revocation_finished (rh, GNUNET_OK); | 834 | send_revocation_finished (rh, GNUNET_OK); |
954 | cleanup_revoke_ticket_handle (rh); | 835 | cleanup_revoke_ticket_handle (rh); |
955 | return; | 836 | return; |
@@ -959,8 +840,7 @@ revocation_reissue_tickets (struct TicketRevocationHandle *rh) | |||
959 | /** | 840 | /** |
960 | * Failed to check for attribute | 841 | * Failed to check for attribute |
961 | */ | 842 | */ |
962 | static void | 843 | static void check_attr_error (void *cls) |
963 | check_attr_error (void *cls) | ||
964 | { | 844 | { |
965 | struct TicketRevocationHandle *rh = cls; | 845 | struct TicketRevocationHandle *rh = cls; |
966 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 846 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
@@ -970,156 +850,121 @@ check_attr_error (void *cls) | |||
970 | cleanup_revoke_ticket_handle (rh); | 850 | cleanup_revoke_ticket_handle (rh); |
971 | } | 851 | } |
972 | 852 | ||
973 | |||
974 | /** | 853 | /** |
975 | * Revoke next attribte by reencryption with | 854 | * Revoke next attribte by reencryption with |
976 | * new ABE master | 855 | * new ABE master |
977 | */ | 856 | */ |
978 | static void | 857 | static void reenc_next_attribute (void *cls); |
979 | reenc_next_attribute (void *cls); | ||
980 | 858 | ||
981 | /** | 859 | /** |
982 | * Check for existing attribute and overwrite | 860 | * Check for existing attribute and overwrite |
983 | */ | 861 | */ |
984 | static void | 862 | static void check_attr_cb (void *cls, |
985 | check_attr_cb (void *cls, | 863 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, |
986 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 864 | const char *label, unsigned int rd_count, |
987 | const char *label, | 865 | const struct GNUNET_GNSRECORD_Data *rd_old) |
988 | unsigned int rd_count, | ||
989 | const struct GNUNET_GNSRECORD_Data *rd_old) | ||
990 | { | 866 | { |
991 | struct TicketRevocationHandle *rh = cls; | 867 | struct TicketRevocationHandle *rh = cls; |
992 | struct TicketAttributeUpdateEntry *tue; | 868 | struct TicketAttributeUpdateEntry *tue; |
993 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; | 869 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; |
994 | struct GNUNET_GNSRECORD_Data rd[1]; | 870 | struct GNUNET_GNSRECORD_Data rd[1]; |
995 | char* buf; | 871 | char *buf; |
996 | size_t buf_size; | 872 | size_t buf_size; |
997 | char* new_label; | 873 | char *new_label; |
998 | 874 | ||
999 | rh->ns_qe = NULL; | 875 | rh->ns_qe = NULL; |
1000 | if (1 != rd_count) { | 876 | if (1 != rd_count) { |
1001 | le = rh->attrs->list_head; | 877 | le = rh->attrs->list_head; |
1002 | GNUNET_CONTAINER_DLL_remove (rh->attrs->list_head, | 878 | GNUNET_CONTAINER_DLL_remove (rh->attrs->list_head, rh->attrs->list_tail, |
1003 | rh->attrs->list_tail, | ||
1004 | le); | 879 | le); |
1005 | GNUNET_assert (NULL != rh->rvk_attrs); | 880 | GNUNET_assert (NULL != rh->rvk_attrs); |
1006 | GNUNET_CONTAINER_DLL_insert (rh->rvk_attrs->list_head, | 881 | GNUNET_CONTAINER_DLL_insert (rh->rvk_attrs->list_head, |
1007 | rh->rvk_attrs->list_tail, | 882 | rh->rvk_attrs->list_tail, le); |
1008 | le); | 883 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Re-encrypting next attribute\n"); |
1009 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 884 | GNUNET_SCHEDULER_add_now (&reenc_next_attribute, rh); |
1010 | "Re-encrypting next attribute\n"); | ||
1011 | GNUNET_SCHEDULER_add_now (&reenc_next_attribute, | ||
1012 | rh); | ||
1013 | return; | 885 | return; |
1014 | } | 886 | } |
1015 | 887 | ||
1016 | buf_size = GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size (rh->attrs->list_head->claim); | 888 | buf_size = |
889 | GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size (rh->attrs->list_head->claim); | ||
1017 | buf = GNUNET_malloc (buf_size); | 890 | buf = GNUNET_malloc (buf_size); |
1018 | rh->attrs->list_head->claim->version++; | 891 | rh->attrs->list_head->claim->version++; |
1019 | GNUNET_RECLAIM_ATTRIBUTE_serialize (rh->attrs->list_head->claim, | 892 | GNUNET_RECLAIM_ATTRIBUTE_serialize (rh->attrs->list_head->claim, buf); |
1020 | buf); | ||
1021 | tue = GNUNET_new (struct TicketAttributeUpdateEntry); | 893 | tue = GNUNET_new (struct TicketAttributeUpdateEntry); |
1022 | tue->old_id = rh->attrs->list_head->claim->id; | 894 | tue->old_id = rh->attrs->list_head->claim->id; |
1023 | tue->new_id = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG, | 895 | tue->new_id = |
1024 | UINT64_MAX); | 896 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG, UINT64_MAX); |
1025 | GNUNET_CONTAINER_DLL_insert (rh->attr_updates_head, | 897 | GNUNET_CONTAINER_DLL_insert (rh->attr_updates_head, rh->attr_updates_tail, |
1026 | rh->attr_updates_tail, | ||
1027 | tue); | 898 | tue); |
1028 | rh->attrs->list_head->claim->id = tue->new_id; | 899 | rh->attrs->list_head->claim->id = tue->new_id; |
1029 | new_label = GNUNET_STRINGS_data_to_string_alloc (&tue->new_id, | 900 | new_label = |
1030 | sizeof (uint64_t)); | 901 | GNUNET_STRINGS_data_to_string_alloc (&tue->new_id, sizeof (uint64_t)); |
1031 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 902 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "New attr id %s\n", new_label); |
1032 | "New attr id %s\n", new_label); | ||
1033 | rd[0].data_size = buf_size; | 903 | rd[0].data_size = buf_size; |
1034 | rd[0].data = buf; | 904 | rd[0].data = buf; |
1035 | rd[0].record_type = GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR; | 905 | rd[0].record_type = GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR; |
1036 | rd[0].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; | 906 | rd[0].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; |
1037 | rd[0].expiration_time = rd_old[0].expiration_time; | 907 | rd[0].expiration_time = rd_old[0].expiration_time; |
1038 | rh->ns_qe = GNUNET_NAMESTORE_records_store (nsh, | 908 | rh->ns_qe = GNUNET_NAMESTORE_records_store (nsh, &rh->identity, new_label, 1, |
1039 | &rh->identity, | 909 | rd, &attr_reenc_cont, rh); |
1040 | new_label, | ||
1041 | 1, | ||
1042 | rd, | ||
1043 | &attr_reenc_cont, | ||
1044 | rh); | ||
1045 | } | 910 | } |
1046 | 911 | ||
1047 | |||
1048 | /** | 912 | /** |
1049 | * Revoke next attribte by reencryption with | 913 | * Revoke next attribte by reencryption with |
1050 | * new ABE master | 914 | * new ABE master |
1051 | */ | 915 | */ |
1052 | static void | 916 | static void reenc_next_attribute (void *cls) |
1053 | reenc_next_attribute (void *cls) | ||
1054 | { | 917 | { |
1055 | struct TicketRevocationHandle *rh = cls; | 918 | struct TicketRevocationHandle *rh = cls; |
1056 | char *label; | 919 | char *label; |
1057 | if (NULL == rh->attrs->list_head) | 920 | if (NULL == rh->attrs->list_head) { |
1058 | { | ||
1059 | revocation_reissue_tickets (rh); | 921 | revocation_reissue_tickets (rh); |
1060 | return; | 922 | return; |
1061 | } | 923 | } |
1062 | /* First check if attribute still exists */ | 924 | /* First check if attribute still exists */ |
1063 | label = GNUNET_STRINGS_data_to_string_alloc (&rh->attrs->list_head->claim->id, | 925 | label = GNUNET_STRINGS_data_to_string_alloc (&rh->attrs->list_head->claim->id, |
1064 | sizeof (uint64_t)); | 926 | sizeof (uint64_t)); |
1065 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "ID: %lu\n", rh->attrs->list_head->claim->id); | 927 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "ID: %lu\n", |
1066 | rh->ns_qe = GNUNET_NAMESTORE_records_lookup (nsh, | 928 | rh->attrs->list_head->claim->id); |
1067 | &rh->identity, | 929 | rh->ns_qe = GNUNET_NAMESTORE_records_lookup ( |
1068 | label, | 930 | nsh, &rh->identity, label, &check_attr_error, rh, &check_attr_cb, rh); |
1069 | &check_attr_error, | ||
1070 | rh, | ||
1071 | &check_attr_cb, | ||
1072 | rh); | ||
1073 | GNUNET_free (label); | 931 | GNUNET_free (label); |
1074 | } | 932 | } |
1075 | 933 | ||
1076 | |||
1077 | /** | 934 | /** |
1078 | * Namestore callback after revoked attribute | 935 | * Namestore callback after revoked attribute |
1079 | * is stored | 936 | * is stored |
1080 | */ | 937 | */ |
1081 | static void | 938 | static void attr_reenc_cont (void *cls, int32_t success, const char *emsg) |
1082 | attr_reenc_cont (void *cls, | ||
1083 | int32_t success, | ||
1084 | const char *emsg) | ||
1085 | { | 939 | { |
1086 | struct TicketRevocationHandle *rh = cls; | 940 | struct TicketRevocationHandle *rh = cls; |
1087 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; | 941 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; |
1088 | 942 | ||
1089 | rh->ns_qe = NULL; | 943 | rh->ns_qe = NULL; |
1090 | if (GNUNET_SYSERR == success) | 944 | if (GNUNET_SYSERR == success) { |
1091 | { | 945 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to reencrypt attribute %s\n", |
1092 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1093 | "Failed to reencrypt attribute %s\n", | ||
1094 | emsg); | 946 | emsg); |
1095 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | 947 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); |
1096 | return; | 948 | return; |
1097 | } | 949 | } |
1098 | if (NULL == rh->attrs->list_head) | 950 | if (NULL == rh->attrs->list_head) { |
1099 | { | ||
1100 | revocation_reissue_tickets (rh); | 951 | revocation_reissue_tickets (rh); |
1101 | return; | 952 | return; |
1102 | } | 953 | } |
1103 | le = rh->attrs->list_head; | 954 | le = rh->attrs->list_head; |
1104 | GNUNET_CONTAINER_DLL_remove (rh->attrs->list_head, | 955 | GNUNET_CONTAINER_DLL_remove (rh->attrs->list_head, rh->attrs->list_tail, le); |
1105 | rh->attrs->list_tail, | ||
1106 | le); | ||
1107 | GNUNET_assert (NULL != rh->rvk_attrs); | 956 | GNUNET_assert (NULL != rh->rvk_attrs); |
1108 | GNUNET_CONTAINER_DLL_insert (rh->rvk_attrs->list_head, | 957 | GNUNET_CONTAINER_DLL_insert (rh->rvk_attrs->list_head, |
1109 | rh->rvk_attrs->list_tail, | 958 | rh->rvk_attrs->list_tail, le); |
1110 | le); | ||
1111 | |||
1112 | 959 | ||
1113 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 960 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Re-encrypting next attribute\n"); |
1114 | "Re-encrypting next attribute\n"); | ||
1115 | reenc_next_attribute (rh); | 961 | reenc_next_attribute (rh); |
1116 | } | 962 | } |
1117 | 963 | ||
1118 | 964 | ||
1119 | static void | 965 | static void process_attributes_to_update ( |
1120 | process_attributes_to_update (void *cls, | 966 | void *cls, const struct GNUNET_RECLAIM_Ticket *ticket, |
1121 | const struct GNUNET_RECLAIM_Ticket *ticket, | 967 | const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs) |
1122 | const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs) | ||
1123 | { | 968 | { |
1124 | struct TicketRevocationHandle *rh = cls; | 969 | struct TicketRevocationHandle *rh = cls; |
1125 | 970 | ||
@@ -1127,8 +972,7 @@ process_attributes_to_update (void *cls, | |||
1127 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 972 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1128 | "Revocation Phase I: Collecting attributes\n"); | 973 | "Revocation Phase I: Collecting attributes\n"); |
1129 | /* Reencrypt all attributes with new key */ | 974 | /* Reencrypt all attributes with new key */ |
1130 | if (NULL == rh->attrs->list_head) | 975 | if (NULL == rh->attrs->list_head) { |
1131 | { | ||
1132 | /* No attributes to reencrypt */ | 976 | /* No attributes to reencrypt */ |
1133 | send_revocation_finished (rh, GNUNET_OK); | 977 | send_revocation_finished (rh, GNUNET_OK); |
1134 | cleanup_revoke_ticket_handle (rh); | 978 | cleanup_revoke_ticket_handle (rh); |
@@ -1138,65 +982,52 @@ process_attributes_to_update (void *cls, | |||
1138 | "Revocation Phase II: Re-encrypting attributes\n"); | 982 | "Revocation Phase II: Re-encrypting attributes\n"); |
1139 | reenc_next_attribute (rh); | 983 | reenc_next_attribute (rh); |
1140 | } | 984 | } |
1141 | |||
1142 | } | 985 | } |
1143 | 986 | ||
1144 | 987 | static int check_revoke_ticket_message (void *cls, | |
1145 | static int | 988 | const struct RevokeTicketMessage *im) |
1146 | check_revoke_ticket_message(void *cls, | ||
1147 | const struct RevokeTicketMessage *im) | ||
1148 | { | 989 | { |
1149 | uint16_t size; | 990 | uint16_t size; |
1150 | 991 | ||
1151 | size = ntohs (im->header.size); | 992 | size = ntohs (im->header.size); |
1152 | if (size <= sizeof (struct RevokeTicketMessage)) | 993 | if (size <= sizeof (struct RevokeTicketMessage)) { |
1153 | { | ||
1154 | GNUNET_break (0); | 994 | GNUNET_break (0); |
1155 | return GNUNET_SYSERR; | 995 | return GNUNET_SYSERR; |
1156 | } | 996 | } |
1157 | return GNUNET_OK; | 997 | return GNUNET_OK; |
1158 | } | 998 | } |
1159 | 999 | ||
1160 | static void | 1000 | static void handle_revoke_ticket_message (void *cls, |
1161 | handle_revoke_ticket_message (void *cls, | 1001 | const struct RevokeTicketMessage *rm) |
1162 | const struct RevokeTicketMessage *rm) | ||
1163 | { | 1002 | { |
1164 | struct TicketRevocationHandle *rh; | 1003 | struct TicketRevocationHandle *rh; |
1165 | struct IdpClient *idp = cls; | 1004 | struct IdpClient *idp = cls; |
1166 | struct GNUNET_RECLAIM_Ticket *ticket; | 1005 | struct GNUNET_RECLAIM_Ticket *ticket; |
1167 | 1006 | ||
1168 | rh = GNUNET_new (struct TicketRevocationHandle); | 1007 | rh = GNUNET_new (struct TicketRevocationHandle); |
1169 | ticket = (struct GNUNET_RECLAIM_Ticket*)&rm[1]; | 1008 | ticket = (struct GNUNET_RECLAIM_Ticket *)&rm[1]; |
1170 | rh->rvk_attrs = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList); | 1009 | rh->rvk_attrs = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList); |
1171 | rh->ticket = *ticket; | 1010 | rh->ticket = *ticket; |
1172 | rh->r_id = ntohl (rm->id); | 1011 | rh->r_id = ntohl (rm->id); |
1173 | rh->client = idp; | 1012 | rh->client = idp; |
1174 | rh->identity = rm->identity; | 1013 | rh->identity = rm->identity; |
1175 | GNUNET_CRYPTO_ecdsa_key_get_public (&rh->identity, | 1014 | GNUNET_CRYPTO_ecdsa_key_get_public (&rh->identity, &rh->ticket.identity); |
1176 | &rh->ticket.identity); | 1015 | GNUNET_CONTAINER_DLL_insert (idp->revoke_op_head, idp->revoke_op_tail, rh); |
1177 | GNUNET_CONTAINER_DLL_insert (idp->revoke_op_head, | ||
1178 | idp->revoke_op_tail, | ||
1179 | rh); | ||
1180 | /** | 1016 | /** |
1181 | * TODO replace with GNS storage | 1017 | * TODO replace with GNS storage |
1182 | */ | 1018 | */ |
1183 | TKT_database->get_ticket_attributes (TKT_database->cls, | 1019 | TKT_database->get_ticket_attributes (TKT_database->cls, &rh->ticket, |
1184 | &rh->ticket, | 1020 | &process_attributes_to_update, rh); |
1185 | &process_attributes_to_update, | ||
1186 | rh); | ||
1187 | GNUNET_SERVICE_client_continue (idp->client); | 1021 | GNUNET_SERVICE_client_continue (idp->client); |
1188 | |||
1189 | } | 1022 | } |
1190 | 1023 | ||
1191 | static int | 1024 | static int check_consume_ticket_message (void *cls, |
1192 | check_consume_ticket_message (void *cls, | 1025 | const struct ConsumeTicketMessage *cm) |
1193 | const struct ConsumeTicketMessage *cm) | ||
1194 | { | 1026 | { |
1195 | uint16_t size; | 1027 | uint16_t size; |
1196 | 1028 | ||
1197 | size = ntohs (cm->header.size); | 1029 | size = ntohs (cm->header.size); |
1198 | if (size <= sizeof (struct ConsumeTicketMessage)) | 1030 | if (size <= sizeof (struct ConsumeTicketMessage)) { |
1199 | { | ||
1200 | GNUNET_break (0); | 1031 | GNUNET_break (0); |
1201 | return GNUNET_SYSERR; | 1032 | return GNUNET_SYSERR; |
1202 | } | 1033 | } |
@@ -1207,42 +1038,33 @@ static void | |||
1207 | consume_result_cb (void *cls, | 1038 | consume_result_cb (void *cls, |
1208 | const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, | 1039 | const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, |
1209 | const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs, | 1040 | const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs, |
1210 | uint32_t success, | 1041 | uint32_t success, const char *emsg) |
1211 | const char *emsg) | ||
1212 | { | 1042 | { |
1213 | struct ConsumeTicketOperation *cop = cls; | 1043 | struct ConsumeTicketOperation *cop = cls; |
1214 | struct ConsumeTicketResultMessage *crm; | 1044 | struct ConsumeTicketResultMessage *crm; |
1215 | struct GNUNET_MQ_Envelope *env; | 1045 | struct GNUNET_MQ_Envelope *env; |
1216 | char *data_tmp; | 1046 | char *data_tmp; |
1217 | size_t attrs_len; | 1047 | size_t attrs_len; |
1218 | if (GNUNET_OK != success) | 1048 | if (GNUNET_OK != success) { |
1219 | { | 1049 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error consuming ticket: %s\n", emsg); |
1220 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1221 | "Error consuming ticket: %s\n", | ||
1222 | emsg); | ||
1223 | } | 1050 | } |
1224 | attrs_len = GNUNET_RECLAIM_ATTRIBUTE_list_serialize_get_size (attrs); | 1051 | attrs_len = GNUNET_RECLAIM_ATTRIBUTE_list_serialize_get_size (attrs); |
1225 | env = GNUNET_MQ_msg_extra (crm, | 1052 | env = GNUNET_MQ_msg_extra (crm, attrs_len, |
1226 | attrs_len, | ||
1227 | GNUNET_MESSAGE_TYPE_RECLAIM_CONSUME_TICKET_RESULT); | 1053 | GNUNET_MESSAGE_TYPE_RECLAIM_CONSUME_TICKET_RESULT); |
1228 | crm->id = htonl (cop->r_id); | 1054 | crm->id = htonl (cop->r_id); |
1229 | crm->attrs_len = htons (attrs_len); | 1055 | crm->attrs_len = htons (attrs_len); |
1230 | crm->identity = *identity; | 1056 | crm->identity = *identity; |
1231 | crm->result = htonl (success); | 1057 | crm->result = htonl (success); |
1232 | data_tmp = (char *) &crm[1]; | 1058 | data_tmp = (char *)&crm[1]; |
1233 | GNUNET_RECLAIM_ATTRIBUTE_list_serialize (attrs, | 1059 | GNUNET_RECLAIM_ATTRIBUTE_list_serialize (attrs, data_tmp); |
1234 | data_tmp); | ||
1235 | GNUNET_MQ_send (cop->client->mq, env); | 1060 | GNUNET_MQ_send (cop->client->mq, env); |
1236 | GNUNET_CONTAINER_DLL_remove (cop->client->consume_op_head, | 1061 | GNUNET_CONTAINER_DLL_remove (cop->client->consume_op_head, |
1237 | cop->client->consume_op_tail, | 1062 | cop->client->consume_op_tail, cop); |
1238 | cop); | ||
1239 | GNUNET_free (cop); | 1063 | GNUNET_free (cop); |
1240 | |||
1241 | } | 1064 | } |
1242 | 1065 | ||
1243 | static void | 1066 | static void |
1244 | handle_consume_ticket_message (void *cls, | 1067 | handle_consume_ticket_message (void *cls, const struct ConsumeTicketMessage *cm) |
1245 | const struct ConsumeTicketMessage *cm) | ||
1246 | { | 1068 | { |
1247 | struct ConsumeTicketOperation *cop; | 1069 | struct ConsumeTicketOperation *cop; |
1248 | struct GNUNET_RECLAIM_Ticket *ticket; | 1070 | struct GNUNET_RECLAIM_Ticket *ticket; |
@@ -1251,14 +1073,10 @@ handle_consume_ticket_message (void *cls, | |||
1251 | cop = GNUNET_new (struct ConsumeTicketOperation); | 1073 | cop = GNUNET_new (struct ConsumeTicketOperation); |
1252 | cop->r_id = ntohl (cm->id); | 1074 | cop->r_id = ntohl (cm->id); |
1253 | cop->client = idp; | 1075 | cop->client = idp; |
1254 | ticket = (struct GNUNET_RECLAIM_Ticket*)&cm[1]; | 1076 | ticket = (struct GNUNET_RECLAIM_Ticket *)&cm[1]; |
1255 | cop->ch = RECLAIM_TICKETS_consume (&cm->identity, | 1077 | cop->ch = |
1256 | ticket, | 1078 | RECLAIM_TICKETS_consume (&cm->identity, ticket, &consume_result_cb, cop); |
1257 | &consume_result_cb, | 1079 | GNUNET_CONTAINER_DLL_insert (idp->consume_op_head, idp->consume_op_tail, cop); |
1258 | cop); | ||
1259 | GNUNET_CONTAINER_DLL_insert (idp->consume_op_head, | ||
1260 | idp->consume_op_tail, | ||
1261 | cop); | ||
1262 | GNUNET_SERVICE_client_continue (idp->client); | 1080 | GNUNET_SERVICE_client_continue (idp->client); |
1263 | } | 1081 | } |
1264 | 1082 | ||
@@ -1271,8 +1089,7 @@ handle_consume_ticket_message (void *cls, | |||
1271 | * | 1089 | * |
1272 | * @param handle handle to clean up | 1090 | * @param handle handle to clean up |
1273 | */ | 1091 | */ |
1274 | static void | 1092 | static void cleanup_as_handle (struct AttributeStoreHandle *ash) |
1275 | cleanup_as_handle (struct AttributeStoreHandle *ash) | ||
1276 | { | 1093 | { |
1277 | if (NULL != ash->ns_qe) | 1094 | if (NULL != ash->ns_qe) |
1278 | GNUNET_NAMESTORE_cancel (ash->ns_qe); | 1095 | GNUNET_NAMESTORE_cancel (ash->ns_qe); |
@@ -1281,10 +1098,7 @@ cleanup_as_handle (struct AttributeStoreHandle *ash) | |||
1281 | GNUNET_free (ash); | 1098 | GNUNET_free (ash); |
1282 | } | 1099 | } |
1283 | 1100 | ||
1284 | static void | 1101 | static void attr_store_cont (void *cls, int32_t success, const char *emsg) |
1285 | attr_store_cont (void *cls, | ||
1286 | int32_t success, | ||
1287 | const char *emsg) | ||
1288 | { | 1102 | { |
1289 | struct AttributeStoreHandle *ash = cls; | 1103 | struct AttributeStoreHandle *ash = cls; |
1290 | struct GNUNET_MQ_Envelope *env; | 1104 | struct GNUNET_MQ_Envelope *env; |
@@ -1292,13 +1106,10 @@ attr_store_cont (void *cls, | |||
1292 | 1106 | ||
1293 | ash->ns_qe = NULL; | 1107 | ash->ns_qe = NULL; |
1294 | GNUNET_CONTAINER_DLL_remove (ash->client->store_op_head, | 1108 | GNUNET_CONTAINER_DLL_remove (ash->client->store_op_head, |
1295 | ash->client->store_op_tail, | 1109 | ash->client->store_op_tail, ash); |
1296 | ash); | ||
1297 | 1110 | ||
1298 | if (GNUNET_SYSERR == success) | 1111 | if (GNUNET_SYSERR == success) { |
1299 | { | 1112 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to store attribute %s\n", |
1300 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1301 | "Failed to store attribute %s\n", | ||
1302 | emsg); | 1113 | emsg); |
1303 | cleanup_as_handle (ash); | 1114 | cleanup_as_handle (ash); |
1304 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | 1115 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); |
@@ -1311,8 +1122,7 @@ attr_store_cont (void *cls, | |||
1311 | GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_STORE_RESPONSE); | 1122 | GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_STORE_RESPONSE); |
1312 | acr_msg->id = htonl (ash->r_id); | 1123 | acr_msg->id = htonl (ash->r_id); |
1313 | acr_msg->op_result = htonl (GNUNET_OK); | 1124 | acr_msg->op_result = htonl (GNUNET_OK); |
1314 | GNUNET_MQ_send (ash->client->mq, | 1125 | GNUNET_MQ_send (ash->client->mq, env); |
1315 | env); | ||
1316 | cleanup_as_handle (ash); | 1126 | cleanup_as_handle (ash); |
1317 | } | 1127 | } |
1318 | 1128 | ||
@@ -1321,61 +1131,49 @@ attr_store_cont (void *cls, | |||
1321 | * | 1131 | * |
1322 | * @param cls the AttributeStoreHandle | 1132 | * @param cls the AttributeStoreHandle |
1323 | */ | 1133 | */ |
1324 | static void | 1134 | static void attr_store_task (void *cls) |
1325 | attr_store_task (void *cls) | ||
1326 | { | 1135 | { |
1327 | struct AttributeStoreHandle *ash = cls; | 1136 | struct AttributeStoreHandle *ash = cls; |
1328 | struct GNUNET_GNSRECORD_Data rd[1]; | 1137 | struct GNUNET_GNSRECORD_Data rd[1]; |
1329 | char* buf; | 1138 | char *buf; |
1330 | char* label; | 1139 | char *label; |
1331 | size_t buf_size; | 1140 | size_t buf_size; |
1332 | 1141 | ||
1333 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1142 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Storing attribute\n"); |
1334 | "Storing attribute\n"); | ||
1335 | buf_size = GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size (ash->claim); | 1143 | buf_size = GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size (ash->claim); |
1336 | buf = GNUNET_malloc (buf_size); | 1144 | buf = GNUNET_malloc (buf_size); |
1337 | //Give the ash a new id | 1145 | // Give the ash a new id |
1338 | ash->claim->id = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG, | 1146 | ash->claim->id = |
1339 | UINT64_MAX); | 1147 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG, UINT64_MAX); |
1340 | GNUNET_RECLAIM_ATTRIBUTE_serialize (ash->claim, | 1148 | GNUNET_RECLAIM_ATTRIBUTE_serialize (ash->claim, buf); |
1341 | buf); | 1149 | label = |
1342 | label = GNUNET_STRINGS_data_to_string_alloc (&ash->claim->id, | 1150 | GNUNET_STRINGS_data_to_string_alloc (&ash->claim->id, sizeof (uint64_t)); |
1343 | sizeof (uint64_t)); | 1151 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Encrypting with label %s\n", label); |
1344 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1345 | "Encrypting with label %s\n", label); | ||
1346 | 1152 | ||
1347 | rd[0].data_size = buf_size; | 1153 | rd[0].data_size = buf_size; |
1348 | rd[0].data = buf; | 1154 | rd[0].data = buf; |
1349 | rd[0].record_type = GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR; | 1155 | rd[0].record_type = GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR; |
1350 | rd[0].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; | 1156 | rd[0].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; |
1351 | rd[0].expiration_time = ash->exp.rel_value_us; | 1157 | rd[0].expiration_time = ash->exp.rel_value_us; |
1352 | ash->ns_qe = GNUNET_NAMESTORE_records_store (nsh, | 1158 | ash->ns_qe = GNUNET_NAMESTORE_records_store (nsh, &ash->identity, label, 1, |
1353 | &ash->identity, | 1159 | rd, &attr_store_cont, ash); |
1354 | label, | ||
1355 | 1, | ||
1356 | rd, | ||
1357 | &attr_store_cont, | ||
1358 | ash); | ||
1359 | GNUNET_free (buf); | 1160 | GNUNET_free (buf); |
1360 | } | 1161 | } |
1361 | 1162 | ||
1362 | |||
1363 | static int | 1163 | static int |
1364 | check_attribute_store_message(void *cls, | 1164 | check_attribute_store_message (void *cls, |
1365 | const struct AttributeStoreMessage *sam) | 1165 | const struct AttributeStoreMessage *sam) |
1366 | { | 1166 | { |
1367 | uint16_t size; | 1167 | uint16_t size; |
1368 | 1168 | ||
1369 | size = ntohs (sam->header.size); | 1169 | size = ntohs (sam->header.size); |
1370 | if (size <= sizeof (struct AttributeStoreMessage)) | 1170 | if (size <= sizeof (struct AttributeStoreMessage)) { |
1371 | { | ||
1372 | GNUNET_break (0); | 1171 | GNUNET_break (0); |
1373 | return GNUNET_SYSERR; | 1172 | return GNUNET_SYSERR; |
1374 | } | 1173 | } |
1375 | return GNUNET_OK; | 1174 | return GNUNET_OK; |
1376 | } | 1175 | } |
1377 | 1176 | ||
1378 | |||
1379 | static void | 1177 | static void |
1380 | handle_attribute_store_message (void *cls, | 1178 | handle_attribute_store_message (void *cls, |
1381 | const struct AttributeStoreMessage *sam) | 1179 | const struct AttributeStoreMessage *sam) |
@@ -1383,26 +1181,21 @@ handle_attribute_store_message (void *cls, | |||
1383 | struct AttributeStoreHandle *ash; | 1181 | struct AttributeStoreHandle *ash; |
1384 | struct IdpClient *idp = cls; | 1182 | struct IdpClient *idp = cls; |
1385 | size_t data_len; | 1183 | size_t data_len; |
1386 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1184 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received ATTRIBUTE_STORE message\n"); |
1387 | "Received ATTRIBUTE_STORE message\n"); | ||
1388 | 1185 | ||
1389 | data_len = ntohs (sam->attr_len); | 1186 | data_len = ntohs (sam->attr_len); |
1390 | 1187 | ||
1391 | ash = GNUNET_new (struct AttributeStoreHandle); | 1188 | ash = GNUNET_new (struct AttributeStoreHandle); |
1392 | ash->claim = GNUNET_RECLAIM_ATTRIBUTE_deserialize ((char*)&sam[1], | 1189 | ash->claim = GNUNET_RECLAIM_ATTRIBUTE_deserialize ((char *)&sam[1], data_len); |
1393 | data_len); | ||
1394 | 1190 | ||
1395 | ash->r_id = ntohl (sam->id); | 1191 | ash->r_id = ntohl (sam->id); |
1396 | ash->identity = sam->identity; | 1192 | ash->identity = sam->identity; |
1397 | ash->exp.rel_value_us = GNUNET_ntohll (sam->exp); | 1193 | ash->exp.rel_value_us = GNUNET_ntohll (sam->exp); |
1398 | GNUNET_CRYPTO_ecdsa_key_get_public (&sam->identity, | 1194 | GNUNET_CRYPTO_ecdsa_key_get_public (&sam->identity, &ash->identity_pkey); |
1399 | &ash->identity_pkey); | ||
1400 | 1195 | ||
1401 | GNUNET_SERVICE_client_continue (idp->client); | 1196 | GNUNET_SERVICE_client_continue (idp->client); |
1402 | ash->client = idp; | 1197 | ash->client = idp; |
1403 | GNUNET_CONTAINER_DLL_insert (idp->store_op_head, | 1198 | GNUNET_CONTAINER_DLL_insert (idp->store_op_head, idp->store_op_tail, ash); |
1404 | idp->store_op_tail, | ||
1405 | ash); | ||
1406 | GNUNET_SCHEDULER_add_now (&attr_store_task, ash); | 1199 | GNUNET_SCHEDULER_add_now (&attr_store_task, ash); |
1407 | } | 1200 | } |
1408 | 1201 | ||
@@ -1410,85 +1203,66 @@ handle_attribute_store_message (void *cls, | |||
1410 | * Attrubute iteration | 1203 | * Attrubute iteration |
1411 | *************************************************/ | 1204 | *************************************************/ |
1412 | 1205 | ||
1413 | static void | 1206 | static void cleanup_attribute_iter_handle (struct AttributeIterator *ai) |
1414 | cleanup_attribute_iter_handle (struct AttributeIterator *ai) | ||
1415 | { | 1207 | { |
1416 | GNUNET_free (ai); | 1208 | GNUNET_free (ai); |
1417 | } | 1209 | } |
1418 | 1210 | ||
1419 | static void | 1211 | static void attr_iter_error (void *cls) |
1420 | attr_iter_error (void *cls) | ||
1421 | { | 1212 | { |
1422 | struct AttributeIterator *ai = cls; | 1213 | struct AttributeIterator *ai = cls; |
1423 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1214 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to iterate over attributes\n"); |
1424 | "Failed to iterate over attributes\n"); | ||
1425 | GNUNET_CONTAINER_DLL_remove (ai->client->attr_iter_head, | 1215 | GNUNET_CONTAINER_DLL_remove (ai->client->attr_iter_head, |
1426 | ai->client->attr_iter_tail, | 1216 | ai->client->attr_iter_tail, ai); |
1427 | ai); | ||
1428 | cleanup_attribute_iter_handle (ai); | 1217 | cleanup_attribute_iter_handle (ai); |
1429 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | 1218 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); |
1430 | } | 1219 | } |
1431 | 1220 | ||
1432 | static void | 1221 | static void attr_iter_finished (void *cls) |
1433 | attr_iter_finished (void *cls) | ||
1434 | { | 1222 | { |
1435 | struct AttributeIterator *ai = cls; | 1223 | struct AttributeIterator *ai = cls; |
1436 | struct GNUNET_MQ_Envelope *env; | 1224 | struct GNUNET_MQ_Envelope *env; |
1437 | struct AttributeResultMessage *arm; | 1225 | struct AttributeResultMessage *arm; |
1438 | 1226 | ||
1439 | env = GNUNET_MQ_msg (arm, | 1227 | env = GNUNET_MQ_msg (arm, GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_RESULT); |
1440 | GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_RESULT); | ||
1441 | arm->id = htonl (ai->request_id); | 1228 | arm->id = htonl (ai->request_id); |
1442 | arm->attr_len = htons (0); | 1229 | arm->attr_len = htons (0); |
1443 | GNUNET_MQ_send (ai->client->mq, env); | 1230 | GNUNET_MQ_send (ai->client->mq, env); |
1444 | GNUNET_CONTAINER_DLL_remove (ai->client->attr_iter_head, | 1231 | GNUNET_CONTAINER_DLL_remove (ai->client->attr_iter_head, |
1445 | ai->client->attr_iter_tail, | 1232 | ai->client->attr_iter_tail, ai); |
1446 | ai); | ||
1447 | cleanup_attribute_iter_handle (ai); | 1233 | cleanup_attribute_iter_handle (ai); |
1448 | } | 1234 | } |
1449 | 1235 | ||
1450 | static void | 1236 | static void attr_iter_cb (void *cls, |
1451 | attr_iter_cb (void *cls, | 1237 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, |
1452 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 1238 | const char *label, unsigned int rd_count, |
1453 | const char *label, | 1239 | const struct GNUNET_GNSRECORD_Data *rd) |
1454 | unsigned int rd_count, | ||
1455 | const struct GNUNET_GNSRECORD_Data *rd) | ||
1456 | { | 1240 | { |
1457 | struct AttributeIterator *ai = cls; | 1241 | struct AttributeIterator *ai = cls; |
1458 | struct AttributeResultMessage *arm; | 1242 | struct AttributeResultMessage *arm; |
1459 | struct GNUNET_MQ_Envelope *env; | 1243 | struct GNUNET_MQ_Envelope *env; |
1460 | char* data_tmp; | 1244 | char *data_tmp; |
1461 | 1245 | ||
1462 | if (rd_count != 1) | 1246 | if (rd_count != 1) { |
1463 | { | 1247 | GNUNET_NAMESTORE_zone_iterator_next (ai->ns_it, 1); |
1464 | GNUNET_NAMESTORE_zone_iterator_next (ai->ns_it, | ||
1465 | 1); | ||
1466 | return; | 1248 | return; |
1467 | } | 1249 | } |
1468 | 1250 | ||
1469 | if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR != rd->record_type) | 1251 | if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR != rd->record_type) { |
1470 | { | 1252 | GNUNET_NAMESTORE_zone_iterator_next (ai->ns_it, 1); |
1471 | GNUNET_NAMESTORE_zone_iterator_next (ai->ns_it, | ||
1472 | 1); | ||
1473 | return; | 1253 | return; |
1474 | } | 1254 | } |
1475 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1255 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found attribute under: %s\n", label); |
1476 | "Found attribute under: %s\n", label); | 1256 | env = GNUNET_MQ_msg_extra (arm, rd->data_size, |
1477 | env = GNUNET_MQ_msg_extra (arm, | ||
1478 | rd->data_size, | ||
1479 | GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_RESULT); | 1257 | GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_RESULT); |
1480 | arm->id = htonl (ai->request_id); | 1258 | arm->id = htonl (ai->request_id); |
1481 | arm->attr_len = htons (rd->data_size); | 1259 | arm->attr_len = htons (rd->data_size); |
1482 | GNUNET_CRYPTO_ecdsa_key_get_public (zone, | 1260 | GNUNET_CRYPTO_ecdsa_key_get_public (zone, &arm->identity); |
1483 | &arm->identity); | 1261 | data_tmp = (char *)&arm[1]; |
1484 | data_tmp = (char *) &arm[1]; | 1262 | GNUNET_memcpy (data_tmp, rd->data, rd->data_size); |
1485 | GNUNET_memcpy (data_tmp, | ||
1486 | rd->data, | ||
1487 | rd->data_size); | ||
1488 | GNUNET_MQ_send (ai->client->mq, env); | 1263 | GNUNET_MQ_send (ai->client->mq, env); |
1489 | } | 1264 | } |
1490 | 1265 | ||
1491 | |||
1492 | static void | 1266 | static void |
1493 | handle_iteration_start (void *cls, | 1267 | handle_iteration_start (void *cls, |
1494 | const struct AttributeIterationStartMessage *ais_msg) | 1268 | const struct AttributeIterationStartMessage *ais_msg) |
@@ -1503,21 +1277,13 @@ handle_iteration_start (void *cls, | |||
1503 | ai->client = idp; | 1277 | ai->client = idp; |
1504 | ai->identity = ais_msg->identity; | 1278 | ai->identity = ais_msg->identity; |
1505 | 1279 | ||
1506 | GNUNET_CONTAINER_DLL_insert (idp->attr_iter_head, | 1280 | GNUNET_CONTAINER_DLL_insert (idp->attr_iter_head, idp->attr_iter_tail, ai); |
1507 | idp->attr_iter_tail, | 1281 | ai->ns_it = GNUNET_NAMESTORE_zone_iteration_start ( |
1508 | ai); | 1282 | nsh, &ai->identity, &attr_iter_error, ai, &attr_iter_cb, ai, |
1509 | ai->ns_it = GNUNET_NAMESTORE_zone_iteration_start (nsh, | 1283 | &attr_iter_finished, ai); |
1510 | &ai->identity, | ||
1511 | &attr_iter_error, | ||
1512 | ai, | ||
1513 | &attr_iter_cb, | ||
1514 | ai, | ||
1515 | &attr_iter_finished, | ||
1516 | ai); | ||
1517 | GNUNET_SERVICE_client_continue (idp->client); | 1284 | GNUNET_SERVICE_client_continue (idp->client); |
1518 | } | 1285 | } |
1519 | 1286 | ||
1520 | |||
1521 | static void | 1287 | static void |
1522 | handle_iteration_stop (void *cls, | 1288 | handle_iteration_stop (void *cls, |
1523 | const struct AttributeIterationStopMessage *ais_msg) | 1289 | const struct AttributeIterationStopMessage *ais_msg) |
@@ -1526,27 +1292,22 @@ handle_iteration_stop (void *cls, | |||
1526 | struct AttributeIterator *ai; | 1292 | struct AttributeIterator *ai; |
1527 | uint32_t rid; | 1293 | uint32_t rid; |
1528 | 1294 | ||
1529 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1295 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", |
1530 | "Received `%s' message\n", | ||
1531 | "ATTRIBUTE_ITERATION_STOP"); | 1296 | "ATTRIBUTE_ITERATION_STOP"); |
1532 | rid = ntohl (ais_msg->id); | 1297 | rid = ntohl (ais_msg->id); |
1533 | for (ai = idp->attr_iter_head; NULL != ai; ai = ai->next) | 1298 | for (ai = idp->attr_iter_head; NULL != ai; ai = ai->next) |
1534 | if (ai->request_id == rid) | 1299 | if (ai->request_id == rid) |
1535 | break; | 1300 | break; |
1536 | if (NULL == ai) | 1301 | if (NULL == ai) { |
1537 | { | ||
1538 | GNUNET_break (0); | 1302 | GNUNET_break (0); |
1539 | GNUNET_SERVICE_client_drop (idp->client); | 1303 | GNUNET_SERVICE_client_drop (idp->client); |
1540 | return; | 1304 | return; |
1541 | } | 1305 | } |
1542 | GNUNET_CONTAINER_DLL_remove (idp->attr_iter_head, | 1306 | GNUNET_CONTAINER_DLL_remove (idp->attr_iter_head, idp->attr_iter_tail, ai); |
1543 | idp->attr_iter_tail, | ||
1544 | ai); | ||
1545 | GNUNET_free (ai); | 1307 | GNUNET_free (ai); |
1546 | GNUNET_SERVICE_client_continue (idp->client); | 1308 | GNUNET_SERVICE_client_continue (idp->client); |
1547 | } | 1309 | } |
1548 | 1310 | ||
1549 | |||
1550 | static void | 1311 | static void |
1551 | handle_iteration_next (void *cls, | 1312 | handle_iteration_next (void *cls, |
1552 | const struct AttributeIterationNextMessage *ais_msg) | 1313 | const struct AttributeIterationNextMessage *ais_msg) |
@@ -1561,14 +1322,12 @@ handle_iteration_next (void *cls, | |||
1561 | for (ai = idp->attr_iter_head; NULL != ai; ai = ai->next) | 1322 | for (ai = idp->attr_iter_head; NULL != ai; ai = ai->next) |
1562 | if (ai->request_id == rid) | 1323 | if (ai->request_id == rid) |
1563 | break; | 1324 | break; |
1564 | if (NULL == ai) | 1325 | if (NULL == ai) { |
1565 | { | ||
1566 | GNUNET_break (0); | 1326 | GNUNET_break (0); |
1567 | GNUNET_SERVICE_client_drop (idp->client); | 1327 | GNUNET_SERVICE_client_drop (idp->client); |
1568 | return; | 1328 | return; |
1569 | } | 1329 | } |
1570 | GNUNET_NAMESTORE_zone_iterator_next (ai->ns_it, | 1330 | GNUNET_NAMESTORE_zone_iterator_next (ai->ns_it, 1); |
1571 | 1); | ||
1572 | GNUNET_SERVICE_client_continue (idp->client); | 1331 | GNUNET_SERVICE_client_continue (idp->client); |
1573 | } | 1332 | } |
1574 | 1333 | ||
@@ -1576,37 +1335,29 @@ handle_iteration_next (void *cls, | |||
1576 | * Ticket iteration | 1335 | * Ticket iteration |
1577 | ******************************************************/ | 1336 | ******************************************************/ |
1578 | 1337 | ||
1579 | static void | 1338 | static void ticket_iter_cb (void *cls, struct GNUNET_RECLAIM_Ticket *ticket) |
1580 | ticket_iter_cb (void *cls, | ||
1581 | struct GNUNET_RECLAIM_Ticket *ticket) | ||
1582 | { | 1339 | { |
1583 | struct TicketIteration *ti = cls; | 1340 | struct TicketIteration *ti = cls; |
1584 | struct GNUNET_MQ_Envelope *env; | 1341 | struct GNUNET_MQ_Envelope *env; |
1585 | struct TicketResultMessage *trm; | 1342 | struct TicketResultMessage *trm; |
1586 | 1343 | ||
1587 | if (NULL == ticket) | 1344 | if (NULL == ticket) { |
1588 | { | ||
1589 | /* send empty response to indicate end of list */ | 1345 | /* send empty response to indicate end of list */ |
1590 | env = GNUNET_MQ_msg (trm, | 1346 | env = GNUNET_MQ_msg (trm, GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_RESULT); |
1591 | GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_RESULT); | ||
1592 | GNUNET_CONTAINER_DLL_remove (ti->client->ticket_iter_head, | 1347 | GNUNET_CONTAINER_DLL_remove (ti->client->ticket_iter_head, |
1593 | ti->client->ticket_iter_tail, | 1348 | ti->client->ticket_iter_tail, ti); |
1594 | ti); | ||
1595 | } else { | 1349 | } else { |
1596 | env = GNUNET_MQ_msg_extra (trm, | 1350 | env = GNUNET_MQ_msg_extra (trm, sizeof (struct GNUNET_RECLAIM_Ticket), |
1597 | sizeof (struct GNUNET_RECLAIM_Ticket), | ||
1598 | GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_RESULT); | 1351 | GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_RESULT); |
1599 | } | 1352 | } |
1600 | trm->id = htonl (ti->r_id); | 1353 | trm->id = htonl (ti->r_id); |
1601 | GNUNET_MQ_send (ti->client->mq, | 1354 | GNUNET_MQ_send (ti->client->mq, env); |
1602 | env); | ||
1603 | if (NULL == ticket) | 1355 | if (NULL == ticket) |
1604 | GNUNET_free (ti); | 1356 | GNUNET_free (ti); |
1605 | } | 1357 | } |
1606 | 1358 | ||
1607 | static void | 1359 | static void handle_ticket_iteration_start ( |
1608 | handle_ticket_iteration_start (void *cls, | 1360 | void *cls, const struct TicketIterationStartMessage *tis_msg) |
1609 | const struct TicketIterationStartMessage *tis_msg) | ||
1610 | { | 1361 | { |
1611 | struct IdpClient *client = cls; | 1362 | struct IdpClient *client = cls; |
1612 | struct TicketIteration *ti; | 1363 | struct TicketIteration *ti; |
@@ -1618,15 +1369,12 @@ handle_ticket_iteration_start (void *cls, | |||
1618 | ti->client = client; | 1369 | ti->client = client; |
1619 | 1370 | ||
1620 | GNUNET_CONTAINER_DLL_insert (client->ticket_iter_head, | 1371 | GNUNET_CONTAINER_DLL_insert (client->ticket_iter_head, |
1621 | client->ticket_iter_tail, | 1372 | client->ticket_iter_tail, ti); |
1622 | ti); | 1373 | ti->iter = |
1623 | ti->iter = RECLAIM_TICKETS_iteration_start (&tis_msg->identity, | 1374 | RECLAIM_TICKETS_iteration_start (&tis_msg->identity, &ticket_iter_cb, ti); |
1624 | &ticket_iter_cb, | ||
1625 | ti); | ||
1626 | GNUNET_SERVICE_client_continue (client->client); | 1375 | GNUNET_SERVICE_client_continue (client->client); |
1627 | } | 1376 | } |
1628 | 1377 | ||
1629 | |||
1630 | static void | 1378 | static void |
1631 | handle_ticket_iteration_stop (void *cls, | 1379 | handle_ticket_iteration_stop (void *cls, |
1632 | const struct TicketIterationStopMessage *tis_msg) | 1380 | const struct TicketIterationStopMessage *tis_msg) |
@@ -1635,28 +1383,24 @@ handle_ticket_iteration_stop (void *cls, | |||
1635 | struct TicketIteration *ti; | 1383 | struct TicketIteration *ti; |
1636 | uint32_t rid; | 1384 | uint32_t rid; |
1637 | 1385 | ||
1638 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1386 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", |
1639 | "Received `%s' message\n", | ||
1640 | "TICKET_ITERATION_STOP"); | 1387 | "TICKET_ITERATION_STOP"); |
1641 | rid = ntohl (tis_msg->id); | 1388 | rid = ntohl (tis_msg->id); |
1642 | for (ti = client->ticket_iter_head; NULL != ti; ti = ti->next) | 1389 | for (ti = client->ticket_iter_head; NULL != ti; ti = ti->next) |
1643 | if (ti->r_id == rid) | 1390 | if (ti->r_id == rid) |
1644 | break; | 1391 | break; |
1645 | if (NULL == ti) | 1392 | if (NULL == ti) { |
1646 | { | ||
1647 | GNUNET_break (0); | 1393 | GNUNET_break (0); |
1648 | GNUNET_SERVICE_client_drop (client->client); | 1394 | GNUNET_SERVICE_client_drop (client->client); |
1649 | return; | 1395 | return; |
1650 | } | 1396 | } |
1651 | RECLAIM_TICKETS_iteration_stop (ti->iter); | 1397 | RECLAIM_TICKETS_iteration_stop (ti->iter); |
1652 | GNUNET_CONTAINER_DLL_remove (client->ticket_iter_head, | 1398 | GNUNET_CONTAINER_DLL_remove (client->ticket_iter_head, |
1653 | client->ticket_iter_tail, | 1399 | client->ticket_iter_tail, ti); |
1654 | ti); | ||
1655 | GNUNET_free (ti); | 1400 | GNUNET_free (ti); |
1656 | GNUNET_SERVICE_client_continue (client->client); | 1401 | GNUNET_SERVICE_client_continue (client->client); |
1657 | } | 1402 | } |
1658 | 1403 | ||
1659 | |||
1660 | static void | 1404 | static void |
1661 | handle_ticket_iteration_next (void *cls, | 1405 | handle_ticket_iteration_next (void *cls, |
1662 | const struct TicketIterationNextMessage *tis_msg) | 1406 | const struct TicketIterationNextMessage *tis_msg) |
@@ -1671,8 +1415,7 @@ handle_ticket_iteration_next (void *cls, | |||
1671 | for (ti = client->ticket_iter_head; NULL != ti; ti = ti->next) | 1415 | for (ti = client->ticket_iter_head; NULL != ti; ti = ti->next) |
1672 | if (ti->r_id == rid) | 1416 | if (ti->r_id == rid) |
1673 | break; | 1417 | break; |
1674 | if (NULL == ti) | 1418 | if (NULL == ti) { |
1675 | { | ||
1676 | GNUNET_break (0); | 1419 | GNUNET_break (0); |
1677 | GNUNET_SERVICE_client_drop (client->client); | 1420 | GNUNET_SERVICE_client_drop (client->client); |
1678 | return; | 1421 | return; |
@@ -1681,9 +1424,6 @@ handle_ticket_iteration_next (void *cls, | |||
1681 | GNUNET_SERVICE_client_continue (client->client); | 1424 | GNUNET_SERVICE_client_continue (client->client); |
1682 | } | 1425 | } |
1683 | 1426 | ||
1684 | |||
1685 | |||
1686 | |||
1687 | /** | 1427 | /** |
1688 | * Main function that will be run | 1428 | * Main function that will be run |
1689 | * | 1429 | * |
@@ -1691,65 +1431,46 @@ handle_ticket_iteration_next (void *cls, | |||
1691 | * @param c the configuration used | 1431 | * @param c the configuration used |
1692 | * @param server the service handle | 1432 | * @param server the service handle |
1693 | */ | 1433 | */ |
1694 | static void | 1434 | static void run (void *cls, const struct GNUNET_CONFIGURATION_Handle *c, |
1695 | run (void *cls, | 1435 | struct GNUNET_SERVICE_Handle *server) |
1696 | const struct GNUNET_CONFIGURATION_Handle *c, | ||
1697 | struct GNUNET_SERVICE_Handle *server) | ||
1698 | { | 1436 | { |
1699 | char *database; | 1437 | char *database; |
1700 | cfg = c; | 1438 | cfg = c; |
1701 | 1439 | ||
1702 | 1440 | if (GNUNET_OK != RECLAIM_TICKETS_init (cfg)) { | |
1703 | if (GNUNET_OK != RECLAIM_TICKETS_init (cfg)) | ||
1704 | { | ||
1705 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1441 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1706 | "Unable to initialized TICKETS subsystem.\n"); | 1442 | "Unable to initialized TICKETS subsystem.\n"); |
1707 | GNUNET_SCHEDULER_shutdown (); | 1443 | GNUNET_SCHEDULER_shutdown (); |
1708 | return; | 1444 | return; |
1709 | } | 1445 | } |
1710 | //Connect to identity and namestore services | 1446 | // Connect to identity and namestore services |
1711 | nsh = GNUNET_NAMESTORE_connect (cfg); | 1447 | nsh = GNUNET_NAMESTORE_connect (cfg); |
1712 | if (NULL == nsh) | 1448 | if (NULL == nsh) { |
1713 | { | 1449 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, |
1714 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "error connecting to namestore"); | 1450 | "error connecting to namestore"); |
1715 | } | 1451 | } |
1716 | 1452 | ||
1717 | identity_handle = GNUNET_IDENTITY_connect (cfg, | 1453 | identity_handle = GNUNET_IDENTITY_connect (cfg, NULL, NULL); |
1718 | NULL, | ||
1719 | NULL); | ||
1720 | /* Loading DB plugin */ | 1454 | /* Loading DB plugin */ |
1721 | if (GNUNET_OK != | 1455 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string ( |
1722 | GNUNET_CONFIGURATION_get_value_string (cfg, | 1456 | cfg, "reclaim", "database", &database)) |
1723 | "reclaim", | 1457 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No database backend configured\n"); |
1724 | "database", | 1458 | GNUNET_asprintf (&db_lib_name, "libgnunet_plugin_reclaim_%s", database); |
1725 | &database)) | 1459 | TKT_database = GNUNET_PLUGIN_load (db_lib_name, (void *)cfg); |
1726 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1727 | "No database backend configured\n"); | ||
1728 | GNUNET_asprintf (&db_lib_name, | ||
1729 | "libgnunet_plugin_reclaim_%s", | ||
1730 | database); | ||
1731 | TKT_database = GNUNET_PLUGIN_load (db_lib_name, | ||
1732 | (void *) cfg); | ||
1733 | GNUNET_free (database); | 1460 | GNUNET_free (database); |
1734 | if (NULL == TKT_database) | 1461 | if (NULL == TKT_database) { |
1735 | { | ||
1736 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1462 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1737 | "Could not load database backend `%s'\n", | 1463 | "Could not load database backend `%s'\n", db_lib_name); |
1738 | db_lib_name); | ||
1739 | GNUNET_SCHEDULER_shutdown (); | 1464 | GNUNET_SCHEDULER_shutdown (); |
1740 | return; | 1465 | return; |
1741 | } | 1466 | } |
1742 | 1467 | ||
1743 | if (GNUNET_OK == | 1468 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_time ( |
1744 | GNUNET_CONFIGURATION_get_value_time (cfg, | 1469 | cfg, "reclaim", "TOKEN_EXPIRATION_INTERVAL", |
1745 | "reclaim", | 1470 | &token_expiration_interval)) { |
1746 | "TOKEN_EXPIRATION_INTERVAL", | 1471 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Time window for zone iteration: %s\n", |
1747 | &token_expiration_interval)) | 1472 | GNUNET_STRINGS_relative_time_to_string ( |
1748 | { | 1473 | token_expiration_interval, GNUNET_YES)); |
1749 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1750 | "Time window for zone iteration: %s\n", | ||
1751 | GNUNET_STRINGS_relative_time_to_string (token_expiration_interval, | ||
1752 | GNUNET_YES)); | ||
1753 | } else { | 1474 | } else { |
1754 | token_expiration_interval = DEFAULT_TOKEN_EXPIRATION_INTERVAL; | 1475 | token_expiration_interval = DEFAULT_TOKEN_EXPIRATION_INTERVAL; |
1755 | } | 1476 | } |
@@ -1764,10 +1485,9 @@ run (void *cls, | |||
1764 | * @param client identification of the client | 1485 | * @param client identification of the client |
1765 | * @param app_ctx @a client | 1486 | * @param app_ctx @a client |
1766 | */ | 1487 | */ |
1767 | static void | 1488 | static void client_disconnect_cb (void *cls, |
1768 | client_disconnect_cb (void *cls, | 1489 | struct GNUNET_SERVICE_Client *client, |
1769 | struct GNUNET_SERVICE_Client *client, | 1490 | void *app_ctx) |
1770 | void *app_ctx) | ||
1771 | { | 1491 | { |
1772 | struct IdpClient *idp = app_ctx; | 1492 | struct IdpClient *idp = app_ctx; |
1773 | struct AttributeIterator *ai; | 1493 | struct AttributeIterator *ai; |
@@ -1777,61 +1497,42 @@ client_disconnect_cb (void *cls, | |||
1777 | struct ConsumeTicketOperation *ct; | 1497 | struct ConsumeTicketOperation *ct; |
1778 | struct AttributeStoreHandle *as; | 1498 | struct AttributeStoreHandle *as; |
1779 | 1499 | ||
1780 | //TODO other operations | 1500 | // TODO other operations |
1781 | 1501 | ||
1782 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1502 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p disconnected\n", client); |
1783 | "Client %p disconnected\n", | 1503 | |
1784 | client); | 1504 | while (NULL != (iss = idp->issue_op_head)) { |
1785 | 1505 | GNUNET_CONTAINER_DLL_remove (idp->issue_op_head, idp->issue_op_tail, iss); | |
1786 | while (NULL != (iss = idp->issue_op_head)) | ||
1787 | { | ||
1788 | GNUNET_CONTAINER_DLL_remove (idp->issue_op_head, | ||
1789 | idp->issue_op_tail, | ||
1790 | iss); | ||
1791 | GNUNET_free (iss); | 1506 | GNUNET_free (iss); |
1792 | } | 1507 | } |
1793 | while (NULL != (ct = idp->consume_op_head)) | 1508 | while (NULL != (ct = idp->consume_op_head)) { |
1794 | { | 1509 | GNUNET_CONTAINER_DLL_remove (idp->consume_op_head, idp->consume_op_tail, |
1795 | GNUNET_CONTAINER_DLL_remove (idp->consume_op_head, | ||
1796 | idp->consume_op_tail, | ||
1797 | ct); | 1510 | ct); |
1798 | if (NULL != ct->ch) | 1511 | if (NULL != ct->ch) |
1799 | RECLAIM_TICKETS_consume_cancel (ct->ch); | 1512 | RECLAIM_TICKETS_consume_cancel (ct->ch); |
1800 | GNUNET_free (ct); | 1513 | GNUNET_free (ct); |
1801 | } | 1514 | } |
1802 | while (NULL != (as = idp->store_op_head)) | 1515 | while (NULL != (as = idp->store_op_head)) { |
1803 | { | 1516 | GNUNET_CONTAINER_DLL_remove (idp->store_op_head, idp->store_op_tail, as); |
1804 | GNUNET_CONTAINER_DLL_remove (idp->store_op_head, | ||
1805 | idp->store_op_tail, | ||
1806 | as); | ||
1807 | cleanup_as_handle (as); | 1517 | cleanup_as_handle (as); |
1808 | } | 1518 | } |
1809 | 1519 | ||
1810 | while (NULL != (ai = idp->attr_iter_head)) | 1520 | while (NULL != (ai = idp->attr_iter_head)) { |
1811 | { | 1521 | GNUNET_CONTAINER_DLL_remove (idp->attr_iter_head, idp->attr_iter_tail, ai); |
1812 | GNUNET_CONTAINER_DLL_remove (idp->attr_iter_head, | ||
1813 | idp->attr_iter_tail, | ||
1814 | ai); | ||
1815 | cleanup_attribute_iter_handle (ai); | 1522 | cleanup_attribute_iter_handle (ai); |
1816 | } | 1523 | } |
1817 | while (NULL != (rh = idp->revoke_op_head)) | 1524 | while (NULL != (rh = idp->revoke_op_head)) { |
1818 | { | 1525 | GNUNET_CONTAINER_DLL_remove (idp->revoke_op_head, idp->revoke_op_tail, rh); |
1819 | GNUNET_CONTAINER_DLL_remove (idp->revoke_op_head, | ||
1820 | idp->revoke_op_tail, | ||
1821 | rh); | ||
1822 | cleanup_revoke_ticket_handle (rh); | 1526 | cleanup_revoke_ticket_handle (rh); |
1823 | } | 1527 | } |
1824 | while (NULL != (ti = idp->ticket_iter_head)) | 1528 | while (NULL != (ti = idp->ticket_iter_head)) { |
1825 | { | 1529 | GNUNET_CONTAINER_DLL_remove (idp->ticket_iter_head, idp->ticket_iter_tail, |
1826 | GNUNET_CONTAINER_DLL_remove (idp->ticket_iter_head, | ||
1827 | idp->ticket_iter_tail, | ||
1828 | ti); | 1530 | ti); |
1829 | GNUNET_free (ti); | 1531 | GNUNET_free (ti); |
1830 | } | 1532 | } |
1831 | GNUNET_free (idp); | 1533 | GNUNET_free (idp); |
1832 | } | 1534 | } |
1833 | 1535 | ||
1834 | |||
1835 | /** | 1536 | /** |
1836 | * Add a client to our list of active clients. | 1537 | * Add a client to our list of active clients. |
1837 | * | 1538 | * |
@@ -1840,72 +1541,52 @@ client_disconnect_cb (void *cls, | |||
1840 | * @param mq message queue for @a client | 1541 | * @param mq message queue for @a client |
1841 | * @return internal namestore client structure for this client | 1542 | * @return internal namestore client structure for this client |
1842 | */ | 1543 | */ |
1843 | static void * | 1544 | static void *client_connect_cb (void *cls, struct GNUNET_SERVICE_Client *client, |
1844 | client_connect_cb (void *cls, | 1545 | struct GNUNET_MQ_Handle *mq) |
1845 | struct GNUNET_SERVICE_Client *client, | ||
1846 | struct GNUNET_MQ_Handle *mq) | ||
1847 | { | 1546 | { |
1848 | struct IdpClient *idp; | 1547 | struct IdpClient *idp; |
1849 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1548 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p connected\n", client); |
1850 | "Client %p connected\n", | ||
1851 | client); | ||
1852 | idp = GNUNET_new (struct IdpClient); | 1549 | idp = GNUNET_new (struct IdpClient); |
1853 | idp->client = client; | 1550 | idp->client = client; |
1854 | idp->mq = mq; | 1551 | idp->mq = mq; |
1855 | return idp; | 1552 | return idp; |
1856 | } | 1553 | } |
1857 | 1554 | ||
1858 | |||
1859 | |||
1860 | /** | 1555 | /** |
1861 | * Define "main" method using service macro. | 1556 | * Define "main" method using service macro. |
1862 | */ | 1557 | */ |
1863 | GNUNET_SERVICE_MAIN | 1558 | GNUNET_SERVICE_MAIN ( |
1864 | ("reclaim", | 1559 | "reclaim", GNUNET_SERVICE_OPTION_NONE, &run, &client_connect_cb, |
1865 | GNUNET_SERVICE_OPTION_NONE, | 1560 | &client_disconnect_cb, NULL, |
1866 | &run, | 1561 | GNUNET_MQ_hd_var_size (attribute_store_message, |
1867 | &client_connect_cb, | 1562 | GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_STORE, |
1868 | &client_disconnect_cb, | 1563 | struct AttributeStoreMessage, NULL), |
1869 | NULL, | 1564 | GNUNET_MQ_hd_fixed_size ( |
1870 | GNUNET_MQ_hd_var_size (attribute_store_message, | 1565 | iteration_start, GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_START, |
1871 | GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_STORE, | 1566 | struct AttributeIterationStartMessage, NULL), |
1872 | struct AttributeStoreMessage, | 1567 | GNUNET_MQ_hd_fixed_size ( |
1873 | NULL), | 1568 | iteration_next, GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_NEXT, |
1874 | GNUNET_MQ_hd_fixed_size (iteration_start, | 1569 | struct AttributeIterationNextMessage, NULL), |
1875 | GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_START, | 1570 | GNUNET_MQ_hd_fixed_size ( |
1876 | struct AttributeIterationStartMessage, | 1571 | iteration_stop, GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_STOP, |
1877 | NULL), | 1572 | struct AttributeIterationStopMessage, NULL), |
1878 | GNUNET_MQ_hd_fixed_size (iteration_next, | 1573 | GNUNET_MQ_hd_var_size (issue_ticket_message, |
1879 | GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_NEXT, | 1574 | GNUNET_MESSAGE_TYPE_RECLAIM_ISSUE_TICKET, |
1880 | struct AttributeIterationNextMessage, | 1575 | struct IssueTicketMessage, NULL), |
1881 | NULL), | 1576 | GNUNET_MQ_hd_var_size (consume_ticket_message, |
1882 | GNUNET_MQ_hd_fixed_size (iteration_stop, | 1577 | GNUNET_MESSAGE_TYPE_RECLAIM_CONSUME_TICKET, |
1883 | GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_STOP, | 1578 | struct ConsumeTicketMessage, NULL), |
1884 | struct AttributeIterationStopMessage, | 1579 | GNUNET_MQ_hd_fixed_size (ticket_iteration_start, |
1885 | NULL), | 1580 | GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_ITERATION_START, |
1886 | GNUNET_MQ_hd_var_size (issue_ticket_message, | 1581 | struct TicketIterationStartMessage, NULL), |
1887 | GNUNET_MESSAGE_TYPE_RECLAIM_ISSUE_TICKET, | 1582 | GNUNET_MQ_hd_fixed_size (ticket_iteration_next, |
1888 | struct IssueTicketMessage, | 1583 | GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_ITERATION_NEXT, |
1889 | NULL), | 1584 | struct TicketIterationNextMessage, NULL), |
1890 | GNUNET_MQ_hd_var_size (consume_ticket_message, | 1585 | GNUNET_MQ_hd_fixed_size (ticket_iteration_stop, |
1891 | GNUNET_MESSAGE_TYPE_RECLAIM_CONSUME_TICKET, | 1586 | GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_ITERATION_STOP, |
1892 | struct ConsumeTicketMessage, | 1587 | struct TicketIterationStopMessage, NULL), |
1893 | NULL), | 1588 | GNUNET_MQ_hd_var_size (revoke_ticket_message, |
1894 | GNUNET_MQ_hd_fixed_size (ticket_iteration_start, | 1589 | GNUNET_MESSAGE_TYPE_RECLAIM_REVOKE_TICKET, |
1895 | GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_ITERATION_START, | 1590 | struct RevokeTicketMessage, NULL), |
1896 | struct TicketIterationStartMessage, | 1591 | GNUNET_MQ_handler_end ()); |
1897 | NULL), | ||
1898 | GNUNET_MQ_hd_fixed_size (ticket_iteration_next, | ||
1899 | GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_ITERATION_NEXT, | ||
1900 | struct TicketIterationNextMessage, | ||
1901 | NULL), | ||
1902 | GNUNET_MQ_hd_fixed_size (ticket_iteration_stop, | ||
1903 | GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_ITERATION_STOP, | ||
1904 | struct TicketIterationStopMessage, | ||
1905 | NULL), | ||
1906 | GNUNET_MQ_hd_var_size (revoke_ticket_message, | ||
1907 | GNUNET_MESSAGE_TYPE_RECLAIM_REVOKE_TICKET, | ||
1908 | struct RevokeTicketMessage, | ||
1909 | NULL), | ||
1910 | GNUNET_MQ_handler_end()); | ||
1911 | /* end of gnunet-service-reclaim.c */ | 1592 | /* end of gnunet-service-reclaim.c */ |
diff --git a/src/reclaim/gnunet-service-reclaim_tickets.c b/src/reclaim/gnunet-service-reclaim_tickets.c index a39a4be5a..54e5659a4 100644 --- a/src/reclaim/gnunet-service-reclaim_tickets.c +++ b/src/reclaim/gnunet-service-reclaim_tickets.c | |||
@@ -28,8 +28,7 @@ | |||
28 | 28 | ||
29 | struct ParallelLookup; | 29 | struct ParallelLookup; |
30 | 30 | ||
31 | struct RECLAIM_TICKETS_ConsumeHandle | 31 | struct RECLAIM_TICKETS_ConsumeHandle { |
32 | { | ||
33 | /** | 32 | /** |
34 | * Ticket | 33 | * Ticket |
35 | */ | 34 | */ |
@@ -84,14 +83,12 @@ struct RECLAIM_TICKETS_ConsumeHandle | |||
84 | * Callbacl closure | 83 | * Callbacl closure |
85 | */ | 84 | */ |
86 | void *cb_cls; | 85 | void *cb_cls; |
87 | |||
88 | }; | 86 | }; |
89 | 87 | ||
90 | /** | 88 | /** |
91 | * Handle for a parallel GNS lookup job | 89 | * Handle for a parallel GNS lookup job |
92 | */ | 90 | */ |
93 | struct ParallelLookup | 91 | struct ParallelLookup { |
94 | { | ||
95 | /* DLL */ | 92 | /* DLL */ |
96 | struct ParallelLookup *next; | 93 | struct ParallelLookup *next; |
97 | 94 | ||
@@ -117,8 +114,7 @@ struct ParallelLookup | |||
117 | /** | 114 | /** |
118 | * A reference to a ticket stored in GNS | 115 | * A reference to a ticket stored in GNS |
119 | */ | 116 | */ |
120 | struct TicketReference | 117 | struct TicketReference { |
121 | { | ||
122 | /** | 118 | /** |
123 | * DLL | 119 | * DLL |
124 | */ | 120 | */ |
@@ -144,8 +140,7 @@ struct TicketReference | |||
144 | /** | 140 | /** |
145 | * Ticket issue request handle | 141 | * Ticket issue request handle |
146 | */ | 142 | */ |
147 | struct TicketIssueHandle | 143 | struct TicketIssueHandle { |
148 | { | ||
149 | /** | 144 | /** |
150 | * Attributes to issue | 145 | * Attributes to issue |
151 | */ | 146 | */ |
@@ -190,14 +185,12 @@ struct TicketIssueHandle | |||
190 | * Callback cls | 185 | * Callback cls |
191 | */ | 186 | */ |
192 | void *cb_cls; | 187 | void *cb_cls; |
193 | |||
194 | }; | 188 | }; |
195 | 189 | ||
196 | /** | 190 | /** |
197 | * Ticket iterator | 191 | * Ticket iterator |
198 | */ | 192 | */ |
199 | struct RECLAIM_TICKETS_Iterator | 193 | struct RECLAIM_TICKETS_Iterator { |
200 | { | ||
201 | /** | 194 | /** |
202 | * Issuer Key | 195 | * Issuer Key |
203 | */ | 196 | */ |
@@ -243,26 +236,25 @@ static struct GNUNET_GNS_Handle *gns; | |||
243 | /* Handle to the statistics service */ | 236 | /* Handle to the statistics service */ |
244 | static struct GNUNET_STATISTICS_Handle *stats; | 237 | static struct GNUNET_STATISTICS_Handle *stats; |
245 | 238 | ||
246 | static int | 239 | static int create_sym_key_from_ecdh ( |
247 | create_sym_key_from_ecdh (const struct GNUNET_HashCode *new_key_hash, | 240 | const struct GNUNET_HashCode *new_key_hash, |
248 | struct GNUNET_CRYPTO_SymmetricSessionKey *skey, | 241 | struct GNUNET_CRYPTO_SymmetricSessionKey *skey, |
249 | struct GNUNET_CRYPTO_SymmetricInitializationVector *iv) | 242 | struct GNUNET_CRYPTO_SymmetricInitializationVector *iv) |
250 | { | 243 | { |
251 | struct GNUNET_CRYPTO_HashAsciiEncoded new_key_hash_str; | 244 | struct GNUNET_CRYPTO_HashAsciiEncoded new_key_hash_str; |
252 | 245 | ||
253 | GNUNET_CRYPTO_hash_to_enc (new_key_hash, | 246 | GNUNET_CRYPTO_hash_to_enc (new_key_hash, &new_key_hash_str); |
254 | &new_key_hash_str); | 247 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating symmetric rsa key from %s\n", |
255 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating symmetric rsa key from %s\n", (char*)&new_key_hash_str); | 248 | (char *)&new_key_hash_str); |
256 | static const char ctx_key[] = "gnuid-aes-ctx-key"; | 249 | static const char ctx_key[] = "gnuid-aes-ctx-key"; |
257 | GNUNET_CRYPTO_kdf (skey, sizeof (struct GNUNET_CRYPTO_SymmetricSessionKey), | 250 | GNUNET_CRYPTO_kdf (skey, sizeof (struct GNUNET_CRYPTO_SymmetricSessionKey), |
258 | new_key_hash, sizeof (struct GNUNET_HashCode), | 251 | new_key_hash, sizeof (struct GNUNET_HashCode), ctx_key, |
259 | ctx_key, strlen (ctx_key), | 252 | strlen (ctx_key), NULL, 0); |
260 | NULL, 0); | ||
261 | static const char ctx_iv[] = "gnuid-aes-ctx-iv"; | 253 | static const char ctx_iv[] = "gnuid-aes-ctx-iv"; |
262 | GNUNET_CRYPTO_kdf (iv, sizeof (struct GNUNET_CRYPTO_SymmetricInitializationVector), | 254 | GNUNET_CRYPTO_kdf ( |
263 | new_key_hash, sizeof (struct GNUNET_HashCode), | 255 | iv, sizeof (struct GNUNET_CRYPTO_SymmetricInitializationVector), |
264 | ctx_iv, strlen (ctx_iv), | 256 | new_key_hash, sizeof (struct GNUNET_HashCode), ctx_iv, strlen (ctx_iv), |
265 | NULL, 0); | 257 | NULL, 0); |
266 | return GNUNET_OK; | 258 | return GNUNET_OK; |
267 | } | 259 | } |
268 | 260 | ||
@@ -271,21 +263,18 @@ create_sym_key_from_ecdh (const struct GNUNET_HashCode *new_key_hash, | |||
271 | * Cleanup ticket consume handle | 263 | * Cleanup ticket consume handle |
272 | * @param cth the handle to clean up | 264 | * @param cth the handle to clean up |
273 | */ | 265 | */ |
274 | static void | 266 | static void cleanup_cth (struct RECLAIM_TICKETS_ConsumeHandle *cth) |
275 | cleanup_cth (struct RECLAIM_TICKETS_ConsumeHandle *cth) | ||
276 | { | 267 | { |
277 | struct ParallelLookup *lu; | 268 | struct ParallelLookup *lu; |
278 | struct ParallelLookup *tmp; | 269 | struct ParallelLookup *tmp; |
279 | if (NULL != cth->lookup_request) | 270 | if (NULL != cth->lookup_request) |
280 | GNUNET_GNS_lookup_cancel (cth->lookup_request); | 271 | GNUNET_GNS_lookup_cancel (cth->lookup_request); |
281 | for (lu = cth->parallel_lookups_head; | 272 | for (lu = cth->parallel_lookups_head; NULL != lu;) { |
282 | NULL != lu;) { | ||
283 | GNUNET_GNS_lookup_cancel (lu->lookup_request); | 273 | GNUNET_GNS_lookup_cancel (lu->lookup_request); |
284 | GNUNET_free (lu->label); | 274 | GNUNET_free (lu->label); |
285 | tmp = lu->next; | 275 | tmp = lu->next; |
286 | GNUNET_CONTAINER_DLL_remove (cth->parallel_lookups_head, | 276 | GNUNET_CONTAINER_DLL_remove (cth->parallel_lookups_head, |
287 | cth->parallel_lookups_tail, | 277 | cth->parallel_lookups_tail, lu); |
288 | lu); | ||
289 | GNUNET_free (lu); | 278 | GNUNET_free (lu); |
290 | lu = tmp; | 279 | lu = tmp; |
291 | } | 280 | } |
@@ -297,90 +286,69 @@ cleanup_cth (struct RECLAIM_TICKETS_ConsumeHandle *cth) | |||
297 | 286 | ||
298 | 287 | ||
299 | static void | 288 | static void |
300 | process_parallel_lookup_result (void *cls, | 289 | process_parallel_lookup_result (void *cls, uint32_t rd_count, |
301 | uint32_t rd_count, | 290 | const struct GNUNET_GNSRECORD_Data *rd) |
302 | const struct GNUNET_GNSRECORD_Data *rd) | ||
303 | { | 291 | { |
304 | struct ParallelLookup *parallel_lookup = cls; | 292 | struct ParallelLookup *parallel_lookup = cls; |
305 | struct RECLAIM_TICKETS_ConsumeHandle *cth = parallel_lookup->handle; | 293 | struct RECLAIM_TICKETS_ConsumeHandle *cth = parallel_lookup->handle; |
306 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *attr_le; | 294 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *attr_le; |
307 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 295 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Parallel lookup finished (count=%u)\n", |
308 | "Parallel lookup finished (count=%u)\n", rd_count); | 296 | rd_count); |
309 | 297 | ||
310 | GNUNET_CONTAINER_DLL_remove (cth->parallel_lookups_head, | 298 | GNUNET_CONTAINER_DLL_remove (cth->parallel_lookups_head, |
311 | cth->parallel_lookups_tail, | 299 | cth->parallel_lookups_tail, parallel_lookup); |
312 | parallel_lookup); | ||
313 | GNUNET_free (parallel_lookup->label); | 300 | GNUNET_free (parallel_lookup->label); |
314 | 301 | ||
315 | GNUNET_STATISTICS_update (stats, | 302 | GNUNET_STATISTICS_update ( |
316 | "attribute_lookup_time_total", | 303 | stats, "attribute_lookup_time_total", |
317 | GNUNET_TIME_absolute_get_duration (parallel_lookup->lookup_start_time).rel_value_us, | 304 | GNUNET_TIME_absolute_get_duration (parallel_lookup->lookup_start_time) |
318 | GNUNET_YES); | 305 | .rel_value_us, |
319 | GNUNET_STATISTICS_update (stats, | 306 | GNUNET_YES); |
320 | "attribute_lookups_count", | 307 | GNUNET_STATISTICS_update (stats, "attribute_lookups_count", 1, GNUNET_YES); |
321 | 1, | ||
322 | GNUNET_YES); | ||
323 | 308 | ||
324 | 309 | ||
325 | GNUNET_free (parallel_lookup); | 310 | GNUNET_free (parallel_lookup); |
326 | if (1 != rd_count) | 311 | if (1 != rd_count) |
327 | GNUNET_break(0);//TODO | 312 | GNUNET_break (0); // TODO |
328 | if (rd->record_type == GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR) | 313 | if (rd->record_type == GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR) { |
329 | { | ||
330 | attr_le = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry); | 314 | attr_le = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry); |
331 | attr_le->claim = GNUNET_RECLAIM_ATTRIBUTE_deserialize (rd->data, | 315 | attr_le->claim = |
332 | rd->data_size); | 316 | GNUNET_RECLAIM_ATTRIBUTE_deserialize (rd->data, rd->data_size); |
333 | GNUNET_CONTAINER_DLL_insert (cth->attrs->list_head, | 317 | GNUNET_CONTAINER_DLL_insert (cth->attrs->list_head, cth->attrs->list_tail, |
334 | cth->attrs->list_tail, | ||
335 | attr_le); | 318 | attr_le); |
336 | } | 319 | } |
337 | if (NULL != cth->parallel_lookups_head) | 320 | if (NULL != cth->parallel_lookups_head) |
338 | return; //Wait for more | 321 | return; // Wait for more |
339 | /* Else we are done */ | 322 | /* Else we are done */ |
340 | 323 | ||
341 | GNUNET_SCHEDULER_cancel (cth->kill_task); | 324 | GNUNET_SCHEDULER_cancel (cth->kill_task); |
342 | cth->cb (cth->cb_cls, | 325 | cth->cb (cth->cb_cls, &cth->ticket.identity, cth->attrs, GNUNET_OK, NULL); |
343 | &cth->ticket.identity, | ||
344 | cth->attrs, | ||
345 | GNUNET_OK, | ||
346 | NULL); | ||
347 | cleanup_cth (cth); | 326 | cleanup_cth (cth); |
348 | } | 327 | } |
349 | 328 | ||
350 | 329 | ||
351 | static void | 330 | static void abort_parallel_lookups (void *cls) |
352 | abort_parallel_lookups (void *cls) | ||
353 | { | 331 | { |
354 | struct RECLAIM_TICKETS_ConsumeHandle *cth = cls; | 332 | struct RECLAIM_TICKETS_ConsumeHandle *cth = cls; |
355 | struct ParallelLookup *lu; | 333 | struct ParallelLookup *lu; |
356 | struct ParallelLookup *tmp; | 334 | struct ParallelLookup *tmp; |
357 | 335 | ||
358 | cth->kill_task = NULL; | 336 | cth->kill_task = NULL; |
359 | for (lu = cth->parallel_lookups_head; | 337 | for (lu = cth->parallel_lookups_head; NULL != lu;) { |
360 | NULL != lu;) { | ||
361 | GNUNET_GNS_lookup_cancel (lu->lookup_request); | 338 | GNUNET_GNS_lookup_cancel (lu->lookup_request); |
362 | GNUNET_free (lu->label); | 339 | GNUNET_free (lu->label); |
363 | tmp = lu->next; | 340 | tmp = lu->next; |
364 | GNUNET_CONTAINER_DLL_remove (cth->parallel_lookups_head, | 341 | GNUNET_CONTAINER_DLL_remove (cth->parallel_lookups_head, |
365 | cth->parallel_lookups_tail, | 342 | cth->parallel_lookups_tail, lu); |
366 | lu); | ||
367 | GNUNET_free (lu); | 343 | GNUNET_free (lu); |
368 | lu = tmp; | 344 | lu = tmp; |
369 | } | 345 | } |
370 | cth->cb (cth->cb_cls, | 346 | cth->cb (cth->cb_cls, NULL, NULL, GNUNET_SYSERR, "Aborted"); |
371 | NULL, | ||
372 | NULL, | ||
373 | GNUNET_SYSERR, | ||
374 | "Aborted"); | ||
375 | |||
376 | } | 347 | } |
377 | 348 | ||
378 | 349 | ||
379 | 350 | static void lookup_authz_cb (void *cls, uint32_t rd_count, | |
380 | static void | 351 | const struct GNUNET_GNSRECORD_Data *rd) |
381 | lookup_authz_cb (void *cls, | ||
382 | uint32_t rd_count, | ||
383 | const struct GNUNET_GNSRECORD_Data *rd) | ||
384 | { | 352 | { |
385 | struct RECLAIM_TICKETS_ConsumeHandle *cth = cls; | 353 | struct RECLAIM_TICKETS_ConsumeHandle *cth = cls; |
386 | struct GNUNET_HashCode new_key_hash; | 354 | struct GNUNET_HashCode new_key_hash; |
@@ -394,125 +362,90 @@ lookup_authz_cb (void *cls, | |||
394 | char *lbls; | 362 | char *lbls; |
395 | 363 | ||
396 | cth->lookup_request = NULL; | 364 | cth->lookup_request = NULL; |
397 | if (1 != rd_count) | 365 | if (1 != rd_count) { |
398 | { | 366 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Number of keys %d != 1.", rd_count); |
399 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 367 | cth->cb (cth->cb_cls, NULL, NULL, GNUNET_SYSERR, "Number of keys %d != 1."); |
400 | "Number of keys %d != 1.", | ||
401 | rd_count); | ||
402 | cth->cb (cth->cb_cls, | ||
403 | NULL, | ||
404 | NULL, | ||
405 | GNUNET_SYSERR, | ||
406 | "Number of keys %d != 1."); | ||
407 | cleanup_cth (cth); | 368 | cleanup_cth (cth); |
408 | return; | 369 | return; |
409 | } | 370 | } |
410 | 371 | ||
411 | //Decrypt | 372 | // Decrypt |
412 | ecdh_key = (struct GNUNET_CRYPTO_EcdhePublicKey *)rd->data; | 373 | ecdh_key = (struct GNUNET_CRYPTO_EcdhePublicKey *)rd->data; |
413 | 374 | ||
414 | buf = GNUNET_malloc (rd->data_size | 375 | buf = GNUNET_malloc (rd->data_size - |
415 | - sizeof (struct GNUNET_CRYPTO_EcdhePublicKey)); | 376 | sizeof (struct GNUNET_CRYPTO_EcdhePublicKey)); |
416 | 377 | ||
417 | //Calculate symmetric key from ecdh parameters | 378 | // Calculate symmetric key from ecdh parameters |
418 | GNUNET_assert (GNUNET_OK == | 379 | GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_ecdsa_ecdh ( |
419 | GNUNET_CRYPTO_ecdsa_ecdh (&cth->identity, | 380 | &cth->identity, ecdh_key, &new_key_hash)); |
420 | ecdh_key, | 381 | create_sym_key_from_ecdh (&new_key_hash, &enc_key, &enc_iv); |
421 | &new_key_hash)); | 382 | size = GNUNET_CRYPTO_symmetric_decrypt ( |
422 | create_sym_key_from_ecdh (&new_key_hash, | 383 | rd->data + sizeof (struct GNUNET_CRYPTO_EcdhePublicKey), |
423 | &enc_key, | 384 | rd->data_size - sizeof (struct GNUNET_CRYPTO_EcdhePublicKey), &enc_key, |
424 | &enc_iv); | 385 | &enc_iv, buf); |
425 | size = GNUNET_CRYPTO_symmetric_decrypt (rd->data | ||
426 | + sizeof (struct GNUNET_CRYPTO_EcdhePublicKey), | ||
427 | rd->data_size | ||
428 | - sizeof (struct GNUNET_CRYPTO_EcdhePublicKey), | ||
429 | &enc_key, | ||
430 | &enc_iv, | ||
431 | buf); | ||
432 | 386 | ||
433 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 387 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
434 | "Decrypted bytes: %zd Expected bytes: %zd\n", | 388 | "Decrypted bytes: %zd Expected bytes: %zd\n", size, |
435 | size, | ||
436 | rd->data_size - sizeof (struct GNUNET_CRYPTO_EcdhePublicKey)); | 389 | rd->data_size - sizeof (struct GNUNET_CRYPTO_EcdhePublicKey)); |
437 | GNUNET_STATISTICS_update (stats, | 390 | GNUNET_STATISTICS_update ( |
438 | "reclaim_authz_lookup_time_total", | 391 | stats, "reclaim_authz_lookup_time_total", |
439 | GNUNET_TIME_absolute_get_duration (cth->lookup_start_time).rel_value_us, | 392 | GNUNET_TIME_absolute_get_duration (cth->lookup_start_time).rel_value_us, |
440 | GNUNET_YES); | 393 | GNUNET_YES); |
441 | GNUNET_STATISTICS_update (stats, | 394 | GNUNET_STATISTICS_update (stats, "reclaim_authz_lookups_count", 1, |
442 | "reclaim_authz_lookups_count", | ||
443 | 1, | ||
444 | GNUNET_YES); | 395 | GNUNET_YES); |
445 | lbls = GNUNET_strdup (buf); | 396 | lbls = GNUNET_strdup (buf); |
446 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 397 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Attributes found %s\n", lbls); |
447 | "Attributes found %s\n", lbls); | 398 | |
448 | 399 | for (attr_lbl = strtok (lbls, ","); NULL != attr_lbl; | |
449 | for (attr_lbl = strtok (lbls, ","); | 400 | attr_lbl = strtok (NULL, ",")) { |
450 | NULL != attr_lbl; | 401 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Looking up %s\n", attr_lbl); |
451 | attr_lbl = strtok (NULL, ",")) | ||
452 | { | ||
453 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
454 | "Looking up %s\n", attr_lbl); | ||
455 | parallel_lookup = GNUNET_new (struct ParallelLookup); | 402 | parallel_lookup = GNUNET_new (struct ParallelLookup); |
456 | parallel_lookup->handle = cth; | 403 | parallel_lookup->handle = cth; |
457 | parallel_lookup->label = GNUNET_strdup (attr_lbl); | 404 | parallel_lookup->label = GNUNET_strdup (attr_lbl); |
458 | parallel_lookup->lookup_start_time = GNUNET_TIME_absolute_get(); | 405 | parallel_lookup->lookup_start_time = GNUNET_TIME_absolute_get (); |
459 | parallel_lookup->lookup_request | 406 | parallel_lookup->lookup_request = GNUNET_GNS_lookup ( |
460 | = GNUNET_GNS_lookup (gns, | 407 | gns, attr_lbl, &cth->ticket.identity, |
461 | attr_lbl, | 408 | GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR, GNUNET_GNS_LO_DEFAULT, |
462 | &cth->ticket.identity, | 409 | &process_parallel_lookup_result, parallel_lookup); |
463 | GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR, | ||
464 | GNUNET_GNS_LO_DEFAULT, | ||
465 | &process_parallel_lookup_result, | ||
466 | parallel_lookup); | ||
467 | GNUNET_CONTAINER_DLL_insert (cth->parallel_lookups_head, | 410 | GNUNET_CONTAINER_DLL_insert (cth->parallel_lookups_head, |
468 | cth->parallel_lookups_tail, | 411 | cth->parallel_lookups_tail, parallel_lookup); |
469 | parallel_lookup); | ||
470 | } | 412 | } |
471 | GNUNET_free (lbls); | 413 | GNUNET_free (lbls); |
472 | GNUNET_free (buf); | 414 | GNUNET_free (buf); |
473 | cth->kill_task = GNUNET_SCHEDULER_add_delayed ( | 415 | cth->kill_task = GNUNET_SCHEDULER_add_delayed ( |
474 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES,3), | 416 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 3), |
475 | &abort_parallel_lookups, | 417 | &abort_parallel_lookups, cth); |
476 | cth); | ||
477 | } | 418 | } |
478 | 419 | ||
479 | 420 | ||
480 | 421 | struct RECLAIM_TICKETS_ConsumeHandle * | |
481 | struct RECLAIM_TICKETS_ConsumeHandle* | ||
482 | RECLAIM_TICKETS_consume (const struct GNUNET_CRYPTO_EcdsaPrivateKey *id, | 422 | RECLAIM_TICKETS_consume (const struct GNUNET_CRYPTO_EcdsaPrivateKey *id, |
483 | const struct GNUNET_RECLAIM_Ticket *ticket, | 423 | const struct GNUNET_RECLAIM_Ticket *ticket, |
484 | RECLAIM_TICKETS_ConsumeCallback cb, | 424 | RECLAIM_TICKETS_ConsumeCallback cb, void *cb_cls) |
485 | void* cb_cls) | ||
486 | { | 425 | { |
487 | struct RECLAIM_TICKETS_ConsumeHandle *cth; | 426 | struct RECLAIM_TICKETS_ConsumeHandle *cth; |
488 | char *label; | 427 | char *label; |
489 | cth = GNUNET_new (struct RECLAIM_TICKETS_ConsumeHandle); | 428 | cth = GNUNET_new (struct RECLAIM_TICKETS_ConsumeHandle); |
490 | 429 | ||
491 | cth->identity = *id; | 430 | cth->identity = *id; |
492 | GNUNET_CRYPTO_ecdsa_key_get_public (&cth->identity, | 431 | GNUNET_CRYPTO_ecdsa_key_get_public (&cth->identity, &cth->identity_pub); |
493 | &cth->identity_pub); | ||
494 | cth->attrs = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList); | 432 | cth->attrs = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList); |
495 | cth->ticket = *ticket; | 433 | cth->ticket = *ticket; |
496 | cth->cb = cb; | 434 | cth->cb = cb; |
497 | cth->cb_cls = cb_cls; | 435 | cth->cb_cls = cb_cls; |
498 | label = GNUNET_STRINGS_data_to_string_alloc (&cth->ticket.rnd, | 436 | label = |
499 | sizeof (uint64_t)); | 437 | GNUNET_STRINGS_data_to_string_alloc (&cth->ticket.rnd, sizeof (uint64_t)); |
500 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 438 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Looking for AuthZ info under %s\n", |
501 | "Looking for AuthZ info under %s\n", label); | 439 | label); |
502 | cth->lookup_start_time = GNUNET_TIME_absolute_get (); | 440 | cth->lookup_start_time = GNUNET_TIME_absolute_get (); |
503 | cth->lookup_request = GNUNET_GNS_lookup (gns, | 441 | cth->lookup_request = GNUNET_GNS_lookup ( |
504 | label, | 442 | gns, label, &cth->ticket.identity, GNUNET_GNSRECORD_TYPE_RECLAIM_AUTHZ, |
505 | &cth->ticket.identity, | 443 | GNUNET_GNS_LO_DEFAULT, &lookup_authz_cb, cth); |
506 | GNUNET_GNSRECORD_TYPE_RECLAIM_AUTHZ, | ||
507 | GNUNET_GNS_LO_DEFAULT, | ||
508 | &lookup_authz_cb, | ||
509 | cth); | ||
510 | GNUNET_free (label); | 444 | GNUNET_free (label); |
511 | return cth; | 445 | return cth; |
512 | } | 446 | } |
513 | 447 | ||
514 | void | 448 | void RECLAIM_TICKETS_consume_cancel (struct RECLAIM_TICKETS_ConsumeHandle *cth) |
515 | RECLAIM_TICKETS_consume_cancel (struct RECLAIM_TICKETS_ConsumeHandle *cth) | ||
516 | { | 449 | { |
517 | cleanup_cth (cth); | 450 | cleanup_cth (cth); |
518 | return; | 451 | return; |
@@ -527,8 +460,7 @@ RECLAIM_TICKETS_consume_cancel (struct RECLAIM_TICKETS_ConsumeHandle *cth) | |||
527 | * Cleanup ticket consume handle | 460 | * Cleanup ticket consume handle |
528 | * @param handle the handle to clean up | 461 | * @param handle the handle to clean up |
529 | */ | 462 | */ |
530 | static void | 463 | static void cleanup_issue_handle (struct TicketIssueHandle *handle) |
531 | cleanup_issue_handle (struct TicketIssueHandle *handle) | ||
532 | { | 464 | { |
533 | struct TicketReference *tr; | 465 | struct TicketReference *tr; |
534 | struct TicketReference *tr_tmp; | 466 | struct TicketReference *tr_tmp; |
@@ -536,8 +468,7 @@ cleanup_issue_handle (struct TicketIssueHandle *handle) | |||
536 | GNUNET_RECLAIM_ATTRIBUTE_list_destroy (handle->attrs); | 468 | GNUNET_RECLAIM_ATTRIBUTE_list_destroy (handle->attrs); |
537 | if (NULL != handle->ns_qe) | 469 | if (NULL != handle->ns_qe) |
538 | GNUNET_NAMESTORE_cancel (handle->ns_qe); | 470 | GNUNET_NAMESTORE_cancel (handle->ns_qe); |
539 | for (tr = handle->ticket_refs_head; NULL != tr;) | 471 | for (tr = handle->ticket_refs_head; NULL != tr;) { |
540 | { | ||
541 | if (NULL != tr->attrs) | 472 | if (NULL != tr->attrs) |
542 | GNUNET_RECLAIM_ATTRIBUTE_list_destroy (tr->attrs); | 473 | GNUNET_RECLAIM_ATTRIBUTE_list_destroy (tr->attrs); |
543 | tr_tmp = tr; | 474 | tr_tmp = tr; |
@@ -548,156 +479,119 @@ cleanup_issue_handle (struct TicketIssueHandle *handle) | |||
548 | } | 479 | } |
549 | 480 | ||
550 | 481 | ||
551 | 482 | static void store_ticket_refs_cont (void *cls, int32_t success, | |
552 | static void | 483 | const char *emsg) |
553 | store_ticket_refs_cont (void *cls, | ||
554 | int32_t success, | ||
555 | const char *emsg) | ||
556 | { | 484 | { |
557 | struct TicketIssueHandle *handle = cls; | 485 | struct TicketIssueHandle *handle = cls; |
558 | handle->ns_qe = NULL; | 486 | handle->ns_qe = NULL; |
559 | if (GNUNET_OK != success) | 487 | if (GNUNET_OK != success) { |
560 | { | 488 | handle->cb (handle->cb_cls, NULL, GNUNET_SYSERR, |
561 | handle->cb (handle->cb_cls, | ||
562 | NULL, | ||
563 | GNUNET_SYSERR, | ||
564 | "Error storing updated ticket refs in GNS"); | 489 | "Error storing updated ticket refs in GNS"); |
565 | cleanup_issue_handle (handle); | 490 | cleanup_issue_handle (handle); |
566 | return; | 491 | return; |
567 | } | 492 | } |
568 | handle->cb (handle->cb_cls, | 493 | handle->cb (handle->cb_cls, &handle->ticket, GNUNET_OK, NULL); |
569 | &handle->ticket, | ||
570 | GNUNET_OK, | ||
571 | NULL); | ||
572 | cleanup_issue_handle (handle); | 494 | cleanup_issue_handle (handle); |
573 | } | 495 | } |
574 | 496 | ||
575 | 497 | ||
576 | 498 | static void update_ticket_refs (void *cls) | |
577 | static void | ||
578 | update_ticket_refs (void* cls) | ||
579 | { | 499 | { |
580 | struct TicketIssueHandle *handle = cls; | 500 | struct TicketIssueHandle *handle = cls; |
581 | struct GNUNET_GNSRECORD_Data refs_rd[handle->ticket_ref_num]; | 501 | struct GNUNET_GNSRECORD_Data refs_rd[handle->ticket_ref_num]; |
582 | struct TicketReference *tr; | 502 | struct TicketReference *tr; |
583 | char* buf; | 503 | char *buf; |
584 | size_t buf_size; | 504 | size_t buf_size; |
585 | 505 | ||
586 | tr = handle->ticket_refs_head; | 506 | tr = handle->ticket_refs_head; |
587 | for (int i = 0; i < handle->ticket_ref_num; i++) | 507 | for (int i = 0; i < handle->ticket_ref_num; i++) { |
588 | { | ||
589 | buf_size = GNUNET_RECLAIM_ATTRIBUTE_list_serialize_get_size (tr->attrs); | 508 | buf_size = GNUNET_RECLAIM_ATTRIBUTE_list_serialize_get_size (tr->attrs); |
590 | buf_size += sizeof (struct GNUNET_RECLAIM_Ticket); | 509 | buf_size += sizeof (struct GNUNET_RECLAIM_Ticket); |
591 | buf = GNUNET_malloc (buf_size); | 510 | buf = GNUNET_malloc (buf_size); |
592 | memcpy (buf, &tr->ticket, sizeof (struct GNUNET_RECLAIM_Ticket)); | 511 | memcpy (buf, &tr->ticket, sizeof (struct GNUNET_RECLAIM_Ticket)); |
593 | GNUNET_RECLAIM_ATTRIBUTE_list_serialize (tr->attrs, | 512 | GNUNET_RECLAIM_ATTRIBUTE_list_serialize ( |
594 | buf + sizeof (struct GNUNET_RECLAIM_Ticket)); | 513 | tr->attrs, buf + sizeof (struct GNUNET_RECLAIM_Ticket)); |
595 | refs_rd[i].data = buf; | 514 | refs_rd[i].data = buf; |
596 | refs_rd[i].data_size = buf_size; | 515 | refs_rd[i].data_size = buf_size; |
597 | refs_rd[i].expiration_time = GNUNET_TIME_UNIT_DAYS.rel_value_us; | 516 | refs_rd[i].expiration_time = GNUNET_TIME_UNIT_DAYS.rel_value_us; |
598 | refs_rd[i].record_type = GNUNET_GNSRECORD_TYPE_RECLAIM_TICKETREF; | 517 | refs_rd[i].record_type = GNUNET_GNSRECORD_TYPE_RECLAIM_TICKETREF; |
599 | refs_rd[i].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION | | 518 | refs_rd[i].flags = |
600 | GNUNET_GNSRECORD_RF_PRIVATE; | 519 | GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION | GNUNET_GNSRECORD_RF_PRIVATE; |
601 | tr = tr->next; | 520 | tr = tr->next; |
602 | } | 521 | } |
603 | 522 | ||
604 | handle->ns_qe = GNUNET_NAMESTORE_records_store (nsh, | 523 | handle->ns_qe = GNUNET_NAMESTORE_records_store ( |
605 | &handle->identity, | 524 | nsh, &handle->identity, GNUNET_GNS_EMPTY_LABEL_AT, handle->ticket_ref_num, |
606 | GNUNET_GNS_EMPTY_LABEL_AT, | 525 | refs_rd, &store_ticket_refs_cont, handle); |
607 | handle->ticket_ref_num, | ||
608 | refs_rd, | ||
609 | &store_ticket_refs_cont, | ||
610 | handle); | ||
611 | for (int i = 0; i < handle->ticket_ref_num; i++) | 526 | for (int i = 0; i < handle->ticket_ref_num; i++) |
612 | GNUNET_free ((char*)refs_rd[i].data); | 527 | GNUNET_free ((char *)refs_rd[i].data); |
613 | } | 528 | } |
614 | 529 | ||
615 | 530 | ||
616 | 531 | static void ticket_lookup_cb (void *cls, | |
617 | static void | 532 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, |
618 | ticket_lookup_cb (void *cls, | 533 | const char *label, unsigned int rd_count, |
619 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 534 | const struct GNUNET_GNSRECORD_Data *rd) |
620 | const char *label, | ||
621 | unsigned int rd_count, | ||
622 | const struct GNUNET_GNSRECORD_Data *rd) | ||
623 | { | 535 | { |
624 | struct TicketIssueHandle *handle = cls; | 536 | struct TicketIssueHandle *handle = cls; |
625 | struct TicketReference *tr; | 537 | struct TicketReference *tr; |
626 | const char* attr_data; | 538 | const char *attr_data; |
627 | size_t attr_data_len; | 539 | size_t attr_data_len; |
628 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 540 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
629 | "Received tickets from local namestore.\n"); | 541 | "Received tickets from local namestore.\n"); |
630 | handle->ns_qe = NULL; | 542 | handle->ns_qe = NULL; |
631 | for (int i = 0; i < rd_count; i++) | 543 | for (int i = 0; i < rd_count; i++) { |
632 | { | ||
633 | if (GNUNET_GNSRECORD_TYPE_RECLAIM_TICKETREF != rd[i].record_type) | 544 | if (GNUNET_GNSRECORD_TYPE_RECLAIM_TICKETREF != rd[i].record_type) |
634 | continue; | 545 | continue; |
635 | tr = GNUNET_new (struct TicketReference); | 546 | tr = GNUNET_new (struct TicketReference); |
636 | memcpy (&tr->ticket, rd[i].data, | 547 | memcpy (&tr->ticket, rd[i].data, sizeof (struct GNUNET_RECLAIM_Ticket)); |
637 | sizeof (struct GNUNET_RECLAIM_Ticket)); | 548 | if (0 != memcmp (&tr->ticket.identity, &handle->ticket.identity, |
638 | if (0 != memcmp (&tr->ticket.identity, | 549 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))) { |
639 | &handle->ticket.identity, | 550 | // Not our ticket |
640 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))) | ||
641 | { | ||
642 | //Not our ticket | ||
643 | GNUNET_free (tr); | 551 | GNUNET_free (tr); |
644 | continue; | 552 | continue; |
645 | } | 553 | } |
646 | attr_data = rd[i].data + sizeof (struct GNUNET_RECLAIM_Ticket); | 554 | attr_data = rd[i].data + sizeof (struct GNUNET_RECLAIM_Ticket); |
647 | attr_data_len = rd[i].data_size - sizeof (struct GNUNET_RECLAIM_Ticket); | 555 | attr_data_len = rd[i].data_size - sizeof (struct GNUNET_RECLAIM_Ticket); |
648 | tr->attrs = GNUNET_RECLAIM_ATTRIBUTE_list_deserialize (attr_data, | 556 | tr->attrs = |
649 | attr_data_len); | 557 | GNUNET_RECLAIM_ATTRIBUTE_list_deserialize (attr_data, attr_data_len); |
650 | GNUNET_CONTAINER_DLL_insert (handle->ticket_refs_head, | 558 | GNUNET_CONTAINER_DLL_insert (handle->ticket_refs_head, |
651 | handle->ticket_refs_tail, | 559 | handle->ticket_refs_tail, tr); |
652 | tr); | ||
653 | handle->ticket_ref_num++; | 560 | handle->ticket_ref_num++; |
654 | } | 561 | } |
655 | tr = GNUNET_new (struct TicketReference); | 562 | tr = GNUNET_new (struct TicketReference); |
656 | tr->ticket = handle->ticket; | 563 | tr->ticket = handle->ticket; |
657 | tr->attrs = GNUNET_RECLAIM_ATTRIBUTE_list_dup (handle->attrs); | 564 | tr->attrs = GNUNET_RECLAIM_ATTRIBUTE_list_dup (handle->attrs); |
658 | GNUNET_CONTAINER_DLL_insert (handle->ticket_refs_head, | 565 | GNUNET_CONTAINER_DLL_insert (handle->ticket_refs_head, |
659 | handle->ticket_refs_tail, | 566 | handle->ticket_refs_tail, tr); |
660 | tr); | ||
661 | handle->ticket_ref_num++; | 567 | handle->ticket_ref_num++; |
662 | GNUNET_SCHEDULER_add_now (&update_ticket_refs, handle); | 568 | GNUNET_SCHEDULER_add_now (&update_ticket_refs, handle); |
663 | } | 569 | } |
664 | 570 | ||
665 | static void | 571 | static void ticket_lookup_error_cb (void *cls) |
666 | ticket_lookup_error_cb (void *cls) | ||
667 | { | 572 | { |
668 | struct TicketIssueHandle *handle = cls; | 573 | struct TicketIssueHandle *handle = cls; |
669 | handle->ns_qe = NULL; | 574 | handle->ns_qe = NULL; |
670 | handle->cb (handle->cb_cls, | 575 | handle->cb (handle->cb_cls, &handle->ticket, GNUNET_SYSERR, |
671 | &handle->ticket, | ||
672 | GNUNET_SYSERR, | ||
673 | "Error checking for ticketsin GNS\n"); | 576 | "Error checking for ticketsin GNS\n"); |
674 | cleanup_issue_handle (handle); | 577 | cleanup_issue_handle (handle); |
675 | } | 578 | } |
676 | 579 | ||
677 | static void | 580 | static void store_ticket_issue_cont (void *cls, int32_t success, |
678 | store_ticket_issue_cont (void *cls, | 581 | const char *emsg) |
679 | int32_t success, | ||
680 | const char *emsg) | ||
681 | { | 582 | { |
682 | struct TicketIssueHandle *handle = cls; | 583 | struct TicketIssueHandle *handle = cls; |
683 | 584 | ||
684 | handle->ns_qe = NULL; | 585 | handle->ns_qe = NULL; |
685 | if (GNUNET_SYSERR == success) | 586 | if (GNUNET_SYSERR == success) { |
686 | { | 587 | handle->cb (handle->cb_cls, &handle->ticket, GNUNET_SYSERR, |
687 | handle->cb (handle->cb_cls, | ||
688 | &handle->ticket, | ||
689 | GNUNET_SYSERR, | ||
690 | "Error storing AuthZ ticket in GNS"); | 588 | "Error storing AuthZ ticket in GNS"); |
691 | return; | 589 | return; |
692 | } | 590 | } |
693 | /* First, local references to tickets */ | 591 | /* First, local references to tickets */ |
694 | handle->ns_qe = GNUNET_NAMESTORE_records_lookup (nsh, | 592 | handle->ns_qe = GNUNET_NAMESTORE_records_lookup ( |
695 | &handle->identity, | 593 | nsh, &handle->identity, GNUNET_GNS_EMPTY_LABEL_AT, |
696 | GNUNET_GNS_EMPTY_LABEL_AT, | 594 | &ticket_lookup_error_cb, handle, &ticket_lookup_cb, handle); |
697 | &ticket_lookup_error_cb, | ||
698 | handle, | ||
699 | &ticket_lookup_cb, | ||
700 | handle); | ||
701 | } | 595 | } |
702 | 596 | ||
703 | 597 | ||
@@ -717,63 +611,53 @@ serialize_authz_record (const struct GNUNET_RECLAIM_Ticket *ticket, | |||
717 | char *buf; | 611 | char *buf; |
718 | char *write_ptr; | 612 | char *write_ptr; |
719 | char attrs_str_len; | 613 | char attrs_str_len; |
720 | char* label; | 614 | char *label; |
721 | 615 | ||
722 | GNUNET_assert (NULL != attrs->list_head); | 616 | GNUNET_assert (NULL != attrs->list_head); |
723 | attrs_str_len = 0; | 617 | attrs_str_len = 0; |
724 | for (le = attrs->list_head; NULL != le; le = le->next) { | 618 | for (le = attrs->list_head; NULL != le; le = le->next) { |
725 | attrs_str_len += 15 + 1; //TODO propery calculate | 619 | attrs_str_len += 15 + 1; // TODO propery calculate |
726 | } | 620 | } |
727 | buf = GNUNET_malloc (attrs_str_len); | 621 | buf = GNUNET_malloc (attrs_str_len); |
728 | write_ptr = buf; | 622 | write_ptr = buf; |
729 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 623 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Writing attributes\n"); |
730 | "Writing attributes\n"); | ||
731 | for (le = attrs->list_head; NULL != le; le = le->next) { | 624 | for (le = attrs->list_head; NULL != le; le = le->next) { |
732 | label = GNUNET_STRINGS_data_to_string_alloc (&le->claim->id, | 625 | label = |
733 | sizeof (uint64_t)); | 626 | GNUNET_STRINGS_data_to_string_alloc (&le->claim->id, sizeof (uint64_t)); |
734 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 627 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Adding attribute to record: %s\n", |
735 | "Adding attribute to record: %s\n", label); | 628 | label); |
736 | 629 | ||
737 | GNUNET_memcpy (write_ptr, | 630 | GNUNET_memcpy (write_ptr, label, strlen (label)); |
738 | label, | ||
739 | strlen (label)); | ||
740 | write_ptr[strlen (label)] = ','; | 631 | write_ptr[strlen (label)] = ','; |
741 | write_ptr += strlen (label) + 1; | 632 | write_ptr += strlen (label) + 1; |
742 | GNUNET_free (label); | 633 | GNUNET_free (label); |
743 | } | 634 | } |
744 | write_ptr--; | 635 | write_ptr--; |
745 | write_ptr[0] = '\0'; //replace last , with a 0-terminator | 636 | write_ptr[0] = '\0'; // replace last , with a 0-terminator |
746 | // ECDH keypair E = eG | 637 | // ECDH keypair E = eG |
747 | *ecdh_privkey = GNUNET_CRYPTO_ecdhe_key_create(); | 638 | *ecdh_privkey = GNUNET_CRYPTO_ecdhe_key_create (); |
748 | GNUNET_CRYPTO_ecdhe_key_get_public (*ecdh_privkey, | 639 | GNUNET_CRYPTO_ecdhe_key_get_public (*ecdh_privkey, &ecdh_pubkey); |
749 | &ecdh_pubkey); | ||
750 | enc_keyinfo = GNUNET_malloc (attrs_str_len); | 640 | enc_keyinfo = GNUNET_malloc (attrs_str_len); |
751 | // Derived key K = H(eB) | 641 | // Derived key K = H(eB) |
752 | GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_ecdh_ecdsa (*ecdh_privkey, | 642 | GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_ecdh_ecdsa (*ecdh_privkey, |
753 | &ticket->audience, | 643 | &ticket->audience, |
754 | &new_key_hash)); | 644 | &new_key_hash)); |
755 | create_sym_key_from_ecdh (&new_key_hash, &skey, &iv); | 645 | create_sym_key_from_ecdh (&new_key_hash, &skey, &iv); |
756 | enc_size = GNUNET_CRYPTO_symmetric_encrypt (buf, | 646 | enc_size = GNUNET_CRYPTO_symmetric_encrypt (buf, attrs_str_len, &skey, &iv, |
757 | attrs_str_len, | ||
758 | &skey, &iv, | ||
759 | enc_keyinfo); | 647 | enc_keyinfo); |
760 | *result = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_EcdhePublicKey)+ | 648 | *result = |
761 | enc_size); | 649 | GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_EcdhePublicKey) + enc_size); |
762 | GNUNET_memcpy (*result, | 650 | GNUNET_memcpy (*result, &ecdh_pubkey, |
763 | &ecdh_pubkey, | ||
764 | sizeof (struct GNUNET_CRYPTO_EcdhePublicKey)); | 651 | sizeof (struct GNUNET_CRYPTO_EcdhePublicKey)); |
765 | GNUNET_memcpy (*result + sizeof (struct GNUNET_CRYPTO_EcdhePublicKey), | 652 | GNUNET_memcpy (*result + sizeof (struct GNUNET_CRYPTO_EcdhePublicKey), |
766 | enc_keyinfo, | 653 | enc_keyinfo, enc_size); |
767 | enc_size); | ||
768 | GNUNET_free (enc_keyinfo); | 654 | GNUNET_free (enc_keyinfo); |
769 | GNUNET_free (buf); | 655 | GNUNET_free (buf); |
770 | return sizeof (struct GNUNET_CRYPTO_EcdhePublicKey)+enc_size; | 656 | return sizeof (struct GNUNET_CRYPTO_EcdhePublicKey) + enc_size; |
771 | } | 657 | } |
772 | 658 | ||
773 | 659 | ||
774 | 660 | static void issue_ticket (struct TicketIssueHandle *ih) | |
775 | static void | ||
776 | issue_ticket (struct TicketIssueHandle *ih) | ||
777 | { | 661 | { |
778 | struct GNUNET_CRYPTO_EcdhePrivateKey *ecdhe_privkey; | 662 | struct GNUNET_CRYPTO_EcdhePrivateKey *ecdhe_privkey; |
779 | struct GNUNET_GNSRECORD_Data code_record[1]; | 663 | struct GNUNET_GNSRECORD_Data code_record[1]; |
@@ -781,41 +665,31 @@ issue_ticket (struct TicketIssueHandle *ih) | |||
781 | size_t authz_record_len; | 665 | size_t authz_record_len; |
782 | char *label; | 666 | char *label; |
783 | 667 | ||
784 | //TODO rename function | 668 | // TODO rename function |
785 | authz_record_len = serialize_authz_record (&ih->ticket, | 669 | authz_record_len = serialize_authz_record ( |
786 | ih->attrs, | 670 | &ih->ticket, ih->attrs, &ecdhe_privkey, &authz_record_data); |
787 | &ecdhe_privkey, | ||
788 | &authz_record_data); | ||
789 | code_record[0].data = authz_record_data; | 671 | code_record[0].data = authz_record_data; |
790 | code_record[0].data_size = authz_record_len; | 672 | code_record[0].data_size = authz_record_len; |
791 | code_record[0].expiration_time = GNUNET_TIME_UNIT_DAYS.rel_value_us; | 673 | code_record[0].expiration_time = GNUNET_TIME_UNIT_DAYS.rel_value_us; |
792 | code_record[0].record_type = GNUNET_GNSRECORD_TYPE_RECLAIM_AUTHZ; | 674 | code_record[0].record_type = GNUNET_GNSRECORD_TYPE_RECLAIM_AUTHZ; |
793 | code_record[0].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; | 675 | code_record[0].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; |
794 | 676 | ||
795 | label = GNUNET_STRINGS_data_to_string_alloc (&ih->ticket.rnd, | 677 | label = |
796 | sizeof (uint64_t)); | 678 | GNUNET_STRINGS_data_to_string_alloc (&ih->ticket.rnd, sizeof (uint64_t)); |
797 | //Publish record | 679 | // Publish record |
798 | ih->ns_qe = GNUNET_NAMESTORE_records_store (nsh, | 680 | ih->ns_qe = GNUNET_NAMESTORE_records_store ( |
799 | &ih->identity, | 681 | nsh, &ih->identity, label, 1, code_record, &store_ticket_issue_cont, ih); |
800 | label, | ||
801 | 1, | ||
802 | code_record, | ||
803 | &store_ticket_issue_cont, | ||
804 | ih); | ||
805 | GNUNET_free (ecdhe_privkey); | 682 | GNUNET_free (ecdhe_privkey); |
806 | GNUNET_free (label); | 683 | GNUNET_free (label); |
807 | GNUNET_free (authz_record_data); | 684 | GNUNET_free (authz_record_data); |
808 | } | 685 | } |
809 | 686 | ||
810 | 687 | ||
811 | 688 | void RECLAIM_TICKETS_issue ( | |
812 | 689 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, | |
813 | void | 690 | const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs, |
814 | RECLAIM_TICKETS_issue (const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, | 691 | const struct GNUNET_CRYPTO_EcdsaPublicKey *audience, |
815 | const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs, | 692 | RECLAIM_TICKETS_TicketResult cb, void *cb_cls) |
816 | const struct GNUNET_CRYPTO_EcdsaPublicKey *audience, | ||
817 | RECLAIM_TICKETS_TicketResult cb, | ||
818 | void* cb_cls) | ||
819 | { | 693 | { |
820 | struct TicketIssueHandle *tih; | 694 | struct TicketIssueHandle *tih; |
821 | tih = GNUNET_new (struct TicketIssueHandle); | 695 | tih = GNUNET_new (struct TicketIssueHandle); |
@@ -823,11 +697,9 @@ RECLAIM_TICKETS_issue (const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, | |||
823 | tih->cb_cls = cb_cls; | 697 | tih->cb_cls = cb_cls; |
824 | tih->attrs = GNUNET_RECLAIM_ATTRIBUTE_list_dup (attrs); | 698 | tih->attrs = GNUNET_RECLAIM_ATTRIBUTE_list_dup (attrs); |
825 | tih->identity = *identity; | 699 | tih->identity = *identity; |
826 | GNUNET_CRYPTO_ecdsa_key_get_public (identity, | 700 | GNUNET_CRYPTO_ecdsa_key_get_public (identity, &tih->ticket.identity); |
827 | &tih->ticket.identity); | ||
828 | tih->ticket.rnd = | 701 | tih->ticket.rnd = |
829 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG, | 702 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG, UINT64_MAX); |
830 | UINT64_MAX); | ||
831 | tih->ticket.audience = *audience; | 703 | tih->ticket.audience = *audience; |
832 | issue_ticket (tih); | 704 | issue_ticket (tih); |
833 | } | 705 | } |
@@ -836,15 +708,13 @@ RECLAIM_TICKETS_issue (const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, | |||
836 | * Ticket iteration | 708 | * Ticket iteration |
837 | ************************************/ | 709 | ************************************/ |
838 | 710 | ||
839 | static void | 711 | static void cleanup_iter (struct RECLAIM_TICKETS_Iterator *iter) |
840 | cleanup_iter (struct RECLAIM_TICKETS_Iterator *iter) | ||
841 | { | 712 | { |
842 | struct TicketReference *tr; | 713 | struct TicketReference *tr; |
843 | struct TicketReference *tr_tmp; | 714 | struct TicketReference *tr_tmp; |
844 | if (NULL != iter->ns_qe) | 715 | if (NULL != iter->ns_qe) |
845 | GNUNET_NAMESTORE_cancel (iter->ns_qe); | 716 | GNUNET_NAMESTORE_cancel (iter->ns_qe); |
846 | for (tr = iter->tickets_head; NULL != tr;) | 717 | for (tr = iter->tickets_head; NULL != tr;) { |
847 | { | ||
848 | if (NULL != tr->attrs) | 718 | if (NULL != tr->attrs) |
849 | GNUNET_RECLAIM_ATTRIBUTE_list_destroy (tr->attrs); | 719 | GNUNET_RECLAIM_ATTRIBUTE_list_destroy (tr->attrs); |
850 | tr_tmp = tr; | 720 | tr_tmp = tr; |
@@ -854,8 +724,7 @@ cleanup_iter (struct RECLAIM_TICKETS_Iterator *iter) | |||
854 | GNUNET_free (iter); | 724 | GNUNET_free (iter); |
855 | } | 725 | } |
856 | 726 | ||
857 | static void | 727 | static void do_cleanup_iter (void *cls) |
858 | do_cleanup_iter (void* cls) | ||
859 | { | 728 | { |
860 | struct RECLAIM_TICKETS_Iterator *iter = cls; | 729 | struct RECLAIM_TICKETS_Iterator *iter = cls; |
861 | cleanup_iter (iter); | 730 | cleanup_iter (iter); |
@@ -866,140 +735,109 @@ do_cleanup_iter (void* cls) | |||
866 | * | 735 | * |
867 | * @param ti ticket iterator to process | 736 | * @param ti ticket iterator to process |
868 | */ | 737 | */ |
869 | static void | 738 | static void run_ticket_iteration_round (struct RECLAIM_TICKETS_Iterator *iter) |
870 | run_ticket_iteration_round (struct RECLAIM_TICKETS_Iterator *iter) | ||
871 | { | 739 | { |
872 | struct TicketReference *tr; | 740 | struct TicketReference *tr; |
873 | if (NULL == iter->tickets_head) | 741 | if (NULL == iter->tickets_head) { |
874 | { | 742 | // No more tickets |
875 | //No more tickets | 743 | iter->cb (iter->cb_cls, NULL); |
876 | iter->cb (iter->cb_cls, | ||
877 | NULL); | ||
878 | GNUNET_SCHEDULER_add_now (&do_cleanup_iter, iter); | 744 | GNUNET_SCHEDULER_add_now (&do_cleanup_iter, iter); |
879 | return; | 745 | return; |
880 | } | 746 | } |
881 | tr = iter->tickets_head; | 747 | tr = iter->tickets_head; |
882 | GNUNET_CONTAINER_DLL_remove (iter->tickets_head, | 748 | GNUNET_CONTAINER_DLL_remove (iter->tickets_head, iter->tickets_tail, tr); |
883 | iter->tickets_tail, | 749 | iter->cb (iter->cb_cls, &tr->ticket); |
884 | tr); | ||
885 | iter->cb (iter->cb_cls, | ||
886 | &tr->ticket); | ||
887 | if (NULL != tr->attrs) | 750 | if (NULL != tr->attrs) |
888 | GNUNET_RECLAIM_ATTRIBUTE_list_destroy (tr->attrs); | 751 | GNUNET_RECLAIM_ATTRIBUTE_list_destroy (tr->attrs); |
889 | GNUNET_free (tr); | 752 | GNUNET_free (tr); |
890 | } | 753 | } |
891 | 754 | ||
892 | static void | 755 | static void |
893 | collect_tickets_cb (void *cls, | 756 | collect_tickets_cb (void *cls, const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, |
894 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 757 | const char *label, unsigned int rd_count, |
895 | const char *label, | ||
896 | unsigned int rd_count, | ||
897 | const struct GNUNET_GNSRECORD_Data *rd) | 758 | const struct GNUNET_GNSRECORD_Data *rd) |
898 | { | 759 | { |
899 | struct RECLAIM_TICKETS_Iterator *iter = cls; | 760 | struct RECLAIM_TICKETS_Iterator *iter = cls; |
900 | struct TicketReference *tr; | 761 | struct TicketReference *tr; |
901 | size_t attr_data_len; | 762 | size_t attr_data_len; |
902 | const char* attr_data; | 763 | const char *attr_data; |
903 | iter->ns_qe = NULL; | 764 | iter->ns_qe = NULL; |
904 | 765 | ||
905 | for (int i = 0; i < rd_count; i++) | 766 | for (int i = 0; i < rd_count; i++) { |
906 | { | ||
907 | if (GNUNET_GNSRECORD_TYPE_RECLAIM_TICKETREF != rd[i].record_type) | 767 | if (GNUNET_GNSRECORD_TYPE_RECLAIM_TICKETREF != rd[i].record_type) |
908 | continue; | 768 | continue; |
909 | tr = GNUNET_new (struct TicketReference); | 769 | tr = GNUNET_new (struct TicketReference); |
910 | memcpy (&tr->ticket, rd[i].data, | 770 | memcpy (&tr->ticket, rd[i].data, sizeof (struct GNUNET_RECLAIM_Ticket)); |
911 | sizeof (struct GNUNET_RECLAIM_Ticket)); | 771 | if (0 != memcmp (&tr->ticket.identity, &iter->identity_pub, |
912 | if (0 != memcmp (&tr->ticket.identity, | 772 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))) { |
913 | &iter->identity_pub, | 773 | // Not our ticket |
914 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))) | ||
915 | { | ||
916 | //Not our ticket | ||
917 | GNUNET_free (tr); | 774 | GNUNET_free (tr); |
918 | continue; | 775 | continue; |
919 | } | 776 | } |
920 | attr_data = rd[i].data + sizeof (struct GNUNET_RECLAIM_Ticket); | 777 | attr_data = rd[i].data + sizeof (struct GNUNET_RECLAIM_Ticket); |
921 | attr_data_len = rd[i].data_size - sizeof (struct GNUNET_RECLAIM_Ticket); | 778 | attr_data_len = rd[i].data_size - sizeof (struct GNUNET_RECLAIM_Ticket); |
922 | tr->attrs = GNUNET_RECLAIM_ATTRIBUTE_list_deserialize (attr_data, | 779 | tr->attrs = |
923 | attr_data_len); | 780 | GNUNET_RECLAIM_ATTRIBUTE_list_deserialize (attr_data, attr_data_len); |
924 | GNUNET_CONTAINER_DLL_insert (iter->tickets_head, | 781 | GNUNET_CONTAINER_DLL_insert (iter->tickets_head, iter->tickets_tail, tr); |
925 | iter->tickets_tail, | ||
926 | tr); | ||
927 | } | 782 | } |
928 | run_ticket_iteration_round (iter); | 783 | run_ticket_iteration_round (iter); |
929 | } | 784 | } |
930 | 785 | ||
931 | static void | 786 | static void collect_tickets_error_cb (void *cls) |
932 | collect_tickets_error_cb (void *cls) | ||
933 | { | 787 | { |
934 | struct RECLAIM_TICKETS_Iterator *iter = cls; | 788 | struct RECLAIM_TICKETS_Iterator *iter = cls; |
935 | iter->ns_qe = NULL; | 789 | iter->ns_qe = NULL; |
936 | iter->cb (iter->cb_cls, | 790 | iter->cb (iter->cb_cls, NULL); |
937 | NULL); | ||
938 | cleanup_iter (iter); | 791 | cleanup_iter (iter); |
939 | } | 792 | } |
940 | 793 | ||
941 | void | 794 | void RECLAIM_TICKETS_iteration_next (struct RECLAIM_TICKETS_Iterator *iter) |
942 | RECLAIM_TICKETS_iteration_next (struct RECLAIM_TICKETS_Iterator *iter) | ||
943 | { | 795 | { |
944 | run_ticket_iteration_round (iter); | 796 | run_ticket_iteration_round (iter); |
945 | } | 797 | } |
946 | 798 | ||
947 | void | 799 | void RECLAIM_TICKETS_iteration_stop (struct RECLAIM_TICKETS_Iterator *iter) |
948 | RECLAIM_TICKETS_iteration_stop (struct RECLAIM_TICKETS_Iterator *iter) | ||
949 | { | 800 | { |
950 | cleanup_iter (iter); | 801 | cleanup_iter (iter); |
951 | } | 802 | } |
952 | 803 | ||
953 | struct RECLAIM_TICKETS_Iterator* | 804 | struct RECLAIM_TICKETS_Iterator *RECLAIM_TICKETS_iteration_start ( |
954 | RECLAIM_TICKETS_iteration_start (const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, | 805 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, |
955 | RECLAIM_TICKETS_TicketIter cb, | 806 | RECLAIM_TICKETS_TicketIter cb, void *cb_cls) |
956 | void* cb_cls) | ||
957 | { | 807 | { |
958 | struct RECLAIM_TICKETS_Iterator *iter; | 808 | struct RECLAIM_TICKETS_Iterator *iter; |
959 | 809 | ||
960 | iter = GNUNET_new (struct RECLAIM_TICKETS_Iterator); | 810 | iter = GNUNET_new (struct RECLAIM_TICKETS_Iterator); |
961 | iter->identity = *identity; | 811 | iter->identity = *identity; |
962 | GNUNET_CRYPTO_ecdsa_key_get_public (identity, | 812 | GNUNET_CRYPTO_ecdsa_key_get_public (identity, &iter->identity_pub); |
963 | &iter->identity_pub); | ||
964 | iter->cb = cb; | 813 | iter->cb = cb; |
965 | iter->cb_cls = cb_cls; | 814 | iter->cb_cls = cb_cls; |
966 | iter->ns_qe = GNUNET_NAMESTORE_records_lookup (nsh, | 815 | iter->ns_qe = GNUNET_NAMESTORE_records_lookup ( |
967 | identity, | 816 | nsh, identity, GNUNET_GNS_EMPTY_LABEL_AT, &collect_tickets_error_cb, iter, |
968 | GNUNET_GNS_EMPTY_LABEL_AT, | 817 | &collect_tickets_cb, iter); |
969 | &collect_tickets_error_cb, | ||
970 | iter, | ||
971 | &collect_tickets_cb, | ||
972 | iter); | ||
973 | return iter; | 818 | return iter; |
974 | } | 819 | } |
975 | 820 | ||
976 | 821 | ||
977 | 822 | int RECLAIM_TICKETS_init (const struct GNUNET_CONFIGURATION_Handle *c) | |
978 | |||
979 | int | ||
980 | RECLAIM_TICKETS_init (const struct GNUNET_CONFIGURATION_Handle *c) | ||
981 | { | 823 | { |
982 | //Connect to identity and namestore services | 824 | // Connect to identity and namestore services |
983 | nsh = GNUNET_NAMESTORE_connect (c); | 825 | nsh = GNUNET_NAMESTORE_connect (c); |
984 | if (NULL == nsh) | 826 | if (NULL == nsh) { |
985 | { | ||
986 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, | 827 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, |
987 | "error connecting to namestore"); | 828 | "error connecting to namestore"); |
988 | return GNUNET_SYSERR; | 829 | return GNUNET_SYSERR; |
989 | } | 830 | } |
990 | gns = GNUNET_GNS_connect (c); | 831 | gns = GNUNET_GNS_connect (c); |
991 | if (NULL == gns) | 832 | if (NULL == gns) { |
992 | { | 833 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "error connecting to gns"); |
993 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, | ||
994 | "error connecting to gns"); | ||
995 | return GNUNET_SYSERR; | 834 | return GNUNET_SYSERR; |
996 | } | 835 | } |
997 | stats = GNUNET_STATISTICS_create ("reclaim", c); | 836 | stats = GNUNET_STATISTICS_create ("reclaim", c); |
998 | return GNUNET_OK; | 837 | return GNUNET_OK; |
999 | } | 838 | } |
1000 | 839 | ||
1001 | void | 840 | void RECLAIM_TICKETS_deinit (void) |
1002 | RECLAIM_TICKETS_deinit (void) | ||
1003 | { | 841 | { |
1004 | if (NULL != nsh) | 842 | if (NULL != nsh) |
1005 | GNUNET_NAMESTORE_disconnect (nsh); | 843 | GNUNET_NAMESTORE_disconnect (nsh); |
@@ -1007,8 +845,7 @@ RECLAIM_TICKETS_deinit (void) | |||
1007 | if (NULL != gns) | 845 | if (NULL != gns) |
1008 | GNUNET_GNS_disconnect (gns); | 846 | GNUNET_GNS_disconnect (gns); |
1009 | gns = NULL; | 847 | gns = NULL; |
1010 | if (NULL != stats) | 848 | if (NULL != stats) { |
1011 | { | ||
1012 | GNUNET_STATISTICS_destroy (stats, GNUNET_NO); | 849 | GNUNET_STATISTICS_destroy (stats, GNUNET_NO); |
1013 | stats = NULL; | 850 | stats = NULL; |
1014 | } | 851 | } |