diff options
author | Alexia Pagkopoulou <a.pagkopoulou@tum.de> | 2019-06-28 14:10:53 +0200 |
---|---|---|
committer | Alexia Pagkopoulou <a.pagkopoulou@tum.de> | 2019-06-28 14:10:53 +0200 |
commit | 113dd536ef29b539e1716d3894903a75d2537196 (patch) | |
tree | c6f293f004bca1f886b5eee9cd10c5aa2911e90a | |
parent | 1945e37dbe9dd0fbb559ca7a1b33c2369c9da639 (diff) | |
download | gnunet-113dd536ef29b539e1716d3894903a75d2537196.tar.gz gnunet-113dd536ef29b539e1716d3894903a75d2537196.zip |
ticket duplicates fix
-rw-r--r-- | src/reclaim/gnunet-service-reclaim_tickets.c | 108 |
1 files changed, 104 insertions, 4 deletions
diff --git a/src/reclaim/gnunet-service-reclaim_tickets.c b/src/reclaim/gnunet-service-reclaim_tickets.c index 182cb6186..65f3f450f 100644 --- a/src/reclaim/gnunet-service-reclaim_tickets.c +++ b/src/reclaim/gnunet-service-reclaim_tickets.c | |||
@@ -168,6 +168,11 @@ struct TicketIssueHandle | |||
168 | * QueueEntry | 168 | * QueueEntry |
169 | */ | 169 | */ |
170 | struct GNUNET_NAMESTORE_QueueEntry *ns_qe; | 170 | struct GNUNET_NAMESTORE_QueueEntry *ns_qe; |
171 | |||
172 | /** | ||
173 | * Namestore Iterator | ||
174 | */ | ||
175 | struct GNUNET_NAMESTORE_ZoneIterator *ns_it; | ||
171 | 176 | ||
172 | /** | 177 | /** |
173 | * Callback | 178 | * Callback |
@@ -1013,6 +1018,94 @@ issue_ticket (struct TicketIssueHandle *ih) | |||
1013 | GNUNET_free (label); | 1018 | GNUNET_free (label); |
1014 | } | 1019 | } |
1015 | 1020 | ||
1021 | /************************************************* | ||
1022 | * Ticket iteration (finding a specific ticket) | ||
1023 | *************************************************/ | ||
1024 | |||
1025 | static void | ||
1026 | filter_tickets_error_cb (void *cls) | ||
1027 | { | ||
1028 | struct TicketIssueHandle *tih = cls; | ||
1029 | tih->ns_it = NULL; | ||
1030 | tih->cb (tih->cb_cls, &tih->ticket, GNUNET_SYSERR, "Error storing AuthZ ticket in GNS"); | ||
1031 | cleanup_issue_handle (tih); | ||
1032 | } | ||
1033 | |||
1034 | static void | ||
1035 | filter_tickets_cb (void *cls, | ||
1036 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | ||
1037 | const char *label, | ||
1038 | unsigned int rd_count, | ||
1039 | const struct GNUNET_GNSRECORD_Data *rd) | ||
1040 | { | ||
1041 | struct TicketIssueHandle *tih = cls; | ||
1042 | struct GNUNET_RECLAIM_Ticket *ticket = NULL; | ||
1043 | |||
1044 | // figure out the number of requested attributes | ||
1045 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; | ||
1046 | unsigned int attr_cnt = 0; | ||
1047 | for (le = tih->attrs->list_head; NULL != le; le = le->next) | ||
1048 | attr_cnt++; | ||
1049 | |||
1050 | // ticket search | ||
1051 | unsigned int found_attrs_cnt = 0; | ||
1052 | |||
1053 | for (int i = 0; i < rd_count; i++) | ||
1054 | { | ||
1055 | // found ticket | ||
1056 | if (GNUNET_GNSRECORD_TYPE_RECLAIM_TICKET == rd[i].record_type) | ||
1057 | { | ||
1058 | ticket = (struct GNUNET_RECLAIM_Ticket *) rd[i].data; | ||
1059 | // cmp audience | ||
1060 | if (0 == memcmp (&tih->ticket.audience, | ||
1061 | &ticket->audience, | ||
1062 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))) | ||
1063 | { | ||
1064 | tih->ticket = *ticket; | ||
1065 | continue; | ||
1066 | } | ||
1067 | ticket = NULL; | ||
1068 | } | ||
1069 | |||
1070 | // cmp requested attributes with ticket attributes | ||
1071 | if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF != rd[i].record_type) | ||
1072 | continue; | ||
1073 | for (le = tih->attrs->list_head; NULL != le; le = le->next) | ||
1074 | { | ||
1075 | // cmp attr_ref id with requested attr id | ||
1076 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1077 | " %" PRIu64 "\n %" PRIu64 "\n", | ||
1078 | *((uint64_t *) rd[i].data), le->claim->id); | ||
1079 | |||
1080 | |||
1081 | if (0 == memcmp (rd[i].data, | ||
1082 | &le->claim->id, | ||
1083 | sizeof (uint64_t))) | ||
1084 | found_attrs_cnt++; | ||
1085 | } | ||
1086 | } | ||
1087 | |||
1088 | if (attr_cnt == found_attrs_cnt && NULL != ticket) | ||
1089 | { | ||
1090 | GNUNET_NAMESTORE_zone_iteration_stop (tih->ns_it); | ||
1091 | tih->cb (tih->cb_cls, &tih->ticket, GNUNET_OK, NULL); | ||
1092 | cleanup_issue_handle (tih); | ||
1093 | return; | ||
1094 | } | ||
1095 | |||
1096 | // ticket not found in current record | ||
1097 | GNUNET_NAMESTORE_zone_iterator_next (tih->ns_it, 1); | ||
1098 | } | ||
1099 | |||
1100 | |||
1101 | static void | ||
1102 | filter_tickets_finished_cb (void *cls) | ||
1103 | { | ||
1104 | struct TicketIssueHandle *tih = cls; | ||
1105 | GNUNET_CRYPTO_ecdsa_key_get_public (&tih->identity, &tih->ticket.identity); | ||
1106 | tih->ticket.rnd = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG, UINT64_MAX); | ||
1107 | issue_ticket (tih); | ||
1108 | } | ||
1016 | 1109 | ||
1017 | void | 1110 | void |
1018 | RECLAIM_TICKETS_issue (const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, | 1111 | RECLAIM_TICKETS_issue (const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, |
@@ -1027,11 +1120,18 @@ RECLAIM_TICKETS_issue (const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, | |||
1027 | tih->cb_cls = cb_cls; | 1120 | tih->cb_cls = cb_cls; |
1028 | tih->attrs = GNUNET_RECLAIM_ATTRIBUTE_list_dup (attrs); | 1121 | tih->attrs = GNUNET_RECLAIM_ATTRIBUTE_list_dup (attrs); |
1029 | tih->identity = *identity; | 1122 | tih->identity = *identity; |
1030 | GNUNET_CRYPTO_ecdsa_key_get_public (identity, &tih->ticket.identity); | ||
1031 | tih->ticket.rnd = | ||
1032 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG, UINT64_MAX); | ||
1033 | tih->ticket.audience = *audience; | 1123 | tih->ticket.audience = *audience; |
1034 | issue_ticket (tih); | 1124 | |
1125 | // check whether the ticket has already been issued | ||
1126 | tih->ns_it = | ||
1127 | GNUNET_NAMESTORE_zone_iteration_start (nsh, | ||
1128 | &tih->identity, | ||
1129 | &filter_tickets_error_cb, | ||
1130 | tih, | ||
1131 | &filter_tickets_cb, | ||
1132 | tih, | ||
1133 | &filter_tickets_finished_cb, | ||
1134 | tih); | ||
1035 | } | 1135 | } |
1036 | 1136 | ||
1037 | /************************************ | 1137 | /************************************ |