diff options
author | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2019-06-05 00:19:09 +0200 |
---|---|---|
committer | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2019-06-05 00:19:09 +0200 |
commit | 2af1b568199c62152fe7892ec33579aed326c136 (patch) | |
tree | bbb5b8f17aa875fc3d8862602268295bc6709b7a | |
parent | 761cdce49f33607b0e8e1ef0c4275bf8d7e82c02 (diff) | |
download | gnunet-2af1b568199c62152fe7892ec33579aed326c136.tar.gz gnunet-2af1b568199c62152fe7892ec33579aed326c136.zip |
fix message sizes; pending test
-rw-r--r-- | src/reclaim/gnunet-service-reclaim.c | 19 | ||||
-rw-r--r-- | src/reclaim/reclaim.h | 15 | ||||
-rw-r--r-- | src/reclaim/reclaim_api.c | 33 |
3 files changed, 31 insertions, 36 deletions
diff --git a/src/reclaim/gnunet-service-reclaim.c b/src/reclaim/gnunet-service-reclaim.c index 322063fd9..52dc12725 100644 --- a/src/reclaim/gnunet-service-reclaim.c +++ b/src/reclaim/gnunet-service-reclaim.c | |||
@@ -746,7 +746,7 @@ check_revoke_ticket_message (void *cls, const struct RevokeTicketMessage *im) | |||
746 | uint16_t size; | 746 | uint16_t size; |
747 | 747 | ||
748 | size = ntohs (im->header.size); | 748 | size = ntohs (im->header.size); |
749 | if (size <= sizeof (struct RevokeTicketMessage)) { | 749 | if (size != sizeof (struct RevokeTicketMessage)) { |
750 | GNUNET_break (0); | 750 | GNUNET_break (0); |
751 | return GNUNET_SYSERR; | 751 | return GNUNET_SYSERR; |
752 | } | 752 | } |
@@ -765,16 +765,14 @@ handle_revoke_ticket_message (void *cls, const struct RevokeTicketMessage *rm) | |||
765 | { | 765 | { |
766 | struct TicketRevocationOperation *rop; | 766 | struct TicketRevocationOperation *rop; |
767 | struct IdpClient *idp = cls; | 767 | struct IdpClient *idp = cls; |
768 | struct GNUNET_RECLAIM_Ticket *ticket; | ||
769 | 768 | ||
770 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received REVOKE_TICKET message\n"); | 769 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received REVOKE_TICKET message\n"); |
771 | rop = GNUNET_new (struct TicketRevocationOperation); | 770 | rop = GNUNET_new (struct TicketRevocationOperation); |
772 | ticket = (struct GNUNET_RECLAIM_Ticket *)&rm[1]; | ||
773 | rop->r_id = ntohl (rm->id); | 771 | rop->r_id = ntohl (rm->id); |
774 | rop->client = idp; | 772 | rop->client = idp; |
775 | GNUNET_CONTAINER_DLL_insert (idp->revoke_op_head, idp->revoke_op_tail, rop); | 773 | GNUNET_CONTAINER_DLL_insert (idp->revoke_op_head, idp->revoke_op_tail, rop); |
776 | rop->rh | 774 | rop->rh |
777 | = RECLAIM_TICKETS_revoke (ticket, &rm->identity, &revoke_result_cb, rop); | 775 | = RECLAIM_TICKETS_revoke (&rm->ticket, &rm->identity, &revoke_result_cb, rop); |
778 | GNUNET_SERVICE_client_continue (idp->client); | 776 | GNUNET_SERVICE_client_continue (idp->client); |
779 | } | 777 | } |
780 | 778 | ||
@@ -834,7 +832,7 @@ check_consume_ticket_message (void *cls, const struct ConsumeTicketMessage *cm) | |||
834 | uint16_t size; | 832 | uint16_t size; |
835 | 833 | ||
836 | size = ntohs (cm->header.size); | 834 | size = ntohs (cm->header.size); |
837 | if (size <= sizeof (struct ConsumeTicketMessage)) { | 835 | if (size != sizeof (struct ConsumeTicketMessage)) { |
838 | GNUNET_break (0); | 836 | GNUNET_break (0); |
839 | return GNUNET_SYSERR; | 837 | return GNUNET_SYSERR; |
840 | } | 838 | } |
@@ -852,16 +850,14 @@ static void | |||
852 | handle_consume_ticket_message (void *cls, const struct ConsumeTicketMessage *cm) | 850 | handle_consume_ticket_message (void *cls, const struct ConsumeTicketMessage *cm) |
853 | { | 851 | { |
854 | struct ConsumeTicketOperation *cop; | 852 | struct ConsumeTicketOperation *cop; |
855 | struct GNUNET_RECLAIM_Ticket *ticket; | ||
856 | struct IdpClient *idp = cls; | 853 | struct IdpClient *idp = cls; |
857 | 854 | ||
858 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received CONSUME_TICKET message\n"); | 855 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received CONSUME_TICKET message\n"); |
859 | cop = GNUNET_new (struct ConsumeTicketOperation); | 856 | cop = GNUNET_new (struct ConsumeTicketOperation); |
860 | cop->r_id = ntohl (cm->id); | 857 | cop->r_id = ntohl (cm->id); |
861 | cop->client = idp; | 858 | cop->client = idp; |
862 | ticket = (struct GNUNET_RECLAIM_Ticket *)&cm[1]; | ||
863 | cop->ch | 859 | cop->ch |
864 | = RECLAIM_TICKETS_consume (&cm->identity, ticket, &consume_result_cb, cop); | 860 | = RECLAIM_TICKETS_consume (&cm->identity, &cm->ticket, &consume_result_cb, cop); |
865 | GNUNET_CONTAINER_DLL_insert (idp->consume_op_head, idp->consume_op_tail, cop); | 861 | GNUNET_CONTAINER_DLL_insert (idp->consume_op_head, idp->consume_op_tail, cop); |
866 | GNUNET_SERVICE_client_continue (idp->client); | 862 | GNUNET_SERVICE_client_continue (idp->client); |
867 | } | 863 | } |
@@ -1493,17 +1489,14 @@ ticket_iter_cb (void *cls, struct GNUNET_RECLAIM_Ticket *ticket) | |||
1493 | struct GNUNET_MQ_Envelope *env; | 1489 | struct GNUNET_MQ_Envelope *env; |
1494 | struct TicketResultMessage *trm; | 1490 | struct TicketResultMessage *trm; |
1495 | 1491 | ||
1492 | env = GNUNET_MQ_msg (trm, GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_RESULT); | ||
1496 | if (NULL == ticket) { | 1493 | if (NULL == ticket) { |
1497 | /* send empty response to indicate end of list */ | 1494 | /* send empty response to indicate end of list */ |
1498 | env = GNUNET_MQ_msg (trm, GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_RESULT); | ||
1499 | GNUNET_CONTAINER_DLL_remove (ti->client->ticket_iter_head, | 1495 | GNUNET_CONTAINER_DLL_remove (ti->client->ticket_iter_head, |
1500 | ti->client->ticket_iter_tail, | 1496 | ti->client->ticket_iter_tail, |
1501 | ti); | 1497 | ti); |
1502 | } else { | 1498 | } else { |
1503 | env = GNUNET_MQ_msg_extra (trm, | 1499 | trm->ticket = *ticket; |
1504 | sizeof (struct GNUNET_RECLAIM_Ticket), | ||
1505 | GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_RESULT); | ||
1506 | memcpy (&trm[1], ticket, sizeof (struct GNUNET_RECLAIM_Ticket)); | ||
1507 | } | 1500 | } |
1508 | trm->id = htonl (ti->r_id); | 1501 | trm->id = htonl (ti->r_id); |
1509 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending TICKET_RESULT message\n"); | 1502 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending TICKET_RESULT message\n"); |
diff --git a/src/reclaim/reclaim.h b/src/reclaim/reclaim.h index 982cd8ae4..3c7c05a10 100644 --- a/src/reclaim/reclaim.h +++ b/src/reclaim/reclaim.h | |||
@@ -323,7 +323,10 @@ struct RevokeTicketMessage | |||
323 | */ | 323 | */ |
324 | uint32_t attrs_len GNUNET_PACKED; | 324 | uint32_t attrs_len GNUNET_PACKED; |
325 | 325 | ||
326 | // Followed by a ticket and serialized attribute list | 326 | /** |
327 | * The ticket to revoke | ||
328 | */ | ||
329 | struct GNUNET_RECLAIM_Ticket ticket; | ||
327 | }; | 330 | }; |
328 | 331 | ||
329 | /** | 332 | /** |
@@ -362,6 +365,11 @@ struct TicketResultMessage | |||
362 | * Unique identifier for this request (for key collisions). | 365 | * Unique identifier for this request (for key collisions). |
363 | */ | 366 | */ |
364 | uint32_t id GNUNET_PACKED; | 367 | uint32_t id GNUNET_PACKED; |
368 | |||
369 | /** | ||
370 | * The new ticket | ||
371 | */ | ||
372 | struct GNUNET_RECLAIM_Ticket ticket; | ||
365 | }; | 373 | }; |
366 | 374 | ||
367 | /** | 375 | /** |
@@ -384,7 +392,10 @@ struct ConsumeTicketMessage | |||
384 | */ | 392 | */ |
385 | struct GNUNET_CRYPTO_EcdsaPrivateKey identity; | 393 | struct GNUNET_CRYPTO_EcdsaPrivateKey identity; |
386 | 394 | ||
387 | // Followed by a serialized ticket | 395 | /** |
396 | * The ticket to consume | ||
397 | */ | ||
398 | struct GNUNET_RECLAIM_Ticket ticket; | ||
388 | }; | 399 | }; |
389 | 400 | ||
390 | /** | 401 | /** |
diff --git a/src/reclaim/reclaim_api.c b/src/reclaim/reclaim_api.c index b0bedfac5..63f8b9ba3 100644 --- a/src/reclaim/reclaim_api.c +++ b/src/reclaim/reclaim_api.c | |||
@@ -642,9 +642,7 @@ handle_ticket_result (void *cls, const struct TicketResultMessage *msg) | |||
642 | struct GNUNET_RECLAIM_Handle *handle = cls; | 642 | struct GNUNET_RECLAIM_Handle *handle = cls; |
643 | struct GNUNET_RECLAIM_Operation *op; | 643 | struct GNUNET_RECLAIM_Operation *op; |
644 | struct GNUNET_RECLAIM_TicketIterator *it; | 644 | struct GNUNET_RECLAIM_TicketIterator *it; |
645 | const struct GNUNET_RECLAIM_Ticket *ticket; | ||
646 | uint32_t r_id = ntohl (msg->id); | 645 | uint32_t r_id = ntohl (msg->id); |
647 | size_t msg_len; | ||
648 | 646 | ||
649 | for (op = handle->op_head; NULL != op; op = op->next) | 647 | for (op = handle->op_head; NULL != op; op = op->next) |
650 | if (op->r_id == r_id) | 648 | if (op->r_id == r_id) |
@@ -654,30 +652,28 @@ handle_ticket_result (void *cls, const struct TicketResultMessage *msg) | |||
654 | break; | 652 | break; |
655 | if ((NULL == op) && (NULL == it)) | 653 | if ((NULL == op) && (NULL == it)) |
656 | return; | 654 | return; |
657 | msg_len = ntohs (msg->header.size); | ||
658 | if (NULL != op) { | 655 | if (NULL != op) { |
659 | GNUNET_CONTAINER_DLL_remove (handle->op_head, handle->op_tail, op); | 656 | GNUNET_CONTAINER_DLL_remove (handle->op_head, handle->op_tail, op); |
660 | if (msg_len == sizeof (struct TicketResultMessage)) { | 657 | if (memcmp (&msg->ticket, 0, sizeof (struct GNUNET_RECLAIM_Ticket))) |
658 | { | ||
661 | if (NULL != op->tr_cb) | 659 | if (NULL != op->tr_cb) |
662 | op->tr_cb (op->cls, NULL); | 660 | op->tr_cb (op->cls, NULL); |
663 | } else { | 661 | } else { |
664 | ticket = (struct GNUNET_RECLAIM_Ticket *)&msg[1]; | ||
665 | if (NULL != op->tr_cb) | 662 | if (NULL != op->tr_cb) |
666 | op->tr_cb (op->cls, ticket); | 663 | op->tr_cb (op->cls, &msg->ticket); |
667 | } | 664 | } |
668 | free_op (op); | 665 | free_op (op); |
669 | return; | 666 | return; |
670 | } else if (NULL != it) { | 667 | } else if (NULL != it) { |
671 | if (msg_len == sizeof (struct TicketResultMessage)) { | 668 | if (memcmp (&msg->ticket, 0, sizeof (struct GNUNET_RECLAIM_Ticket))) |
672 | if (NULL != it->tr_cb) | 669 | { |
673 | GNUNET_CONTAINER_DLL_remove (handle->ticket_it_head, | 670 | GNUNET_CONTAINER_DLL_remove (handle->ticket_it_head, |
674 | handle->ticket_it_tail, it); | 671 | handle->ticket_it_tail, it); |
675 | it->finish_cb (it->finish_cb_cls); | 672 | it->finish_cb (it->finish_cb_cls); |
676 | GNUNET_free (it); | 673 | GNUNET_free (it); |
677 | } else { | 674 | } else { |
678 | ticket = (struct GNUNET_RECLAIM_Ticket *)&msg[1]; | ||
679 | if (NULL != it->tr_cb) | 675 | if (NULL != it->tr_cb) |
680 | it->tr_cb (it->cls, ticket); | 676 | it->tr_cb (it->cls, &msg->ticket); |
681 | } | 677 | } |
682 | return; | 678 | return; |
683 | } | 679 | } |
@@ -1091,14 +1087,10 @@ GNUNET_RECLAIM_ticket_consume ( | |||
1091 | op->r_id = h->r_id_gen++; | 1087 | op->r_id = h->r_id_gen++; |
1092 | GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op); | 1088 | GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op); |
1093 | op->env = | 1089 | op->env = |
1094 | GNUNET_MQ_msg_extra (ctm, sizeof (const struct GNUNET_RECLAIM_Ticket), | 1090 | GNUNET_MQ_msg (ctm, GNUNET_MESSAGE_TYPE_RECLAIM_CONSUME_TICKET); |
1095 | GNUNET_MESSAGE_TYPE_RECLAIM_CONSUME_TICKET); | ||
1096 | ctm->identity = *identity; | 1091 | ctm->identity = *identity; |
1097 | ctm->id = htonl (op->r_id); | 1092 | ctm->id = htonl (op->r_id); |
1098 | 1093 | ctm->ticket = *ticket; | |
1099 | GNUNET_memcpy ((char *)&ctm[1], ticket, | ||
1100 | sizeof (const struct GNUNET_RECLAIM_Ticket)); | ||
1101 | |||
1102 | if (NULL != h->mq) | 1094 | if (NULL != h->mq) |
1103 | GNUNET_MQ_send_copy (h->mq, op->env); | 1095 | GNUNET_MQ_send_copy (h->mq, op->env); |
1104 | return op; | 1096 | return op; |
@@ -1231,11 +1223,10 @@ GNUNET_RECLAIM_ticket_revoke ( | |||
1231 | op->cls = cb_cls; | 1223 | op->cls = cb_cls; |
1232 | op->r_id = rid; | 1224 | op->r_id = rid; |
1233 | GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op); | 1225 | GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op); |
1234 | op->env = GNUNET_MQ_msg_extra (msg, sizeof (struct GNUNET_RECLAIM_Ticket), | 1226 | op->env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RECLAIM_REVOKE_TICKET); |
1235 | GNUNET_MESSAGE_TYPE_RECLAIM_REVOKE_TICKET); | ||
1236 | msg->id = htonl (rid); | 1227 | msg->id = htonl (rid); |
1237 | msg->identity = *identity; | 1228 | msg->identity = *identity; |
1238 | GNUNET_memcpy (&msg[1], ticket, sizeof (struct GNUNET_RECLAIM_Ticket)); | 1229 | msg->ticket = *ticket; |
1239 | if (NULL != h->mq) { | 1230 | if (NULL != h->mq) { |
1240 | GNUNET_MQ_send (h->mq, op->env); | 1231 | GNUNET_MQ_send (h->mq, op->env); |
1241 | op->env = NULL; | 1232 | op->env = NULL; |