aboutsummaryrefslogtreecommitdiff
path: root/src/reclaim/gnunet-service-reclaim.c
diff options
context:
space:
mode:
authorSchanzenbach, Martin <mschanzenbach@posteo.de>2020-02-04 18:42:04 +0100
committerSchanzenbach, Martin <mschanzenbach@posteo.de>2020-02-09 20:38:10 +0100
commit55f6d26b7424d660c99bc89f3677b20294e87a27 (patch)
treea8080fdcf0d9688c154417e50c58055e364f8b6b /src/reclaim/gnunet-service-reclaim.c
parent5b6bb2ce4d60635b2af950d72b45f12686fd5218 (diff)
downloadgnunet-55f6d26b7424d660c99bc89f3677b20294e87a27.tar.gz
gnunet-55f6d26b7424d660c99bc89f3677b20294e87a27.zip
Refactoring reclaim attestations
Diffstat (limited to 'src/reclaim/gnunet-service-reclaim.c')
-rw-r--r--src/reclaim/gnunet-service-reclaim.c602
1 files changed, 43 insertions, 559 deletions
diff --git a/src/reclaim/gnunet-service-reclaim.c b/src/reclaim/gnunet-service-reclaim.c
index a00bc5730..15f9a8385 100644
--- a/src/reclaim/gnunet-service-reclaim.c
+++ b/src/reclaim/gnunet-service-reclaim.c
@@ -263,18 +263,14 @@ struct AttributeDeleteHandle
263 /** 263 /**
264 * The attribute to delete 264 * The attribute to delete
265 */ 265 */
266 struct GNUNET_RECLAIM_ATTRIBUTE_Claim *claim; 266 struct GNUNET_RECLAIM_Attribute *claim;
267 267
268 /** 268 /**
269 * The attestation to delete 269 * The attestation to delete
270 */ 270 */
271 struct GNUNET_RECLAIM_ATTESTATION_Claim *attest; 271 struct GNUNET_RECLAIM_Attestation *attest;
272 272
273 /** 273 /**
274 * The reference to delete
275 */
276 struct GNUNET_RECLAIM_ATTESTATION_REFERENCE *reference;
277 /**
278 * Tickets to update 274 * Tickets to update
279 */ 275 */
280 struct TicketRecordsEntry *tickets_to_update_head; 276 struct TicketRecordsEntry *tickets_to_update_head;
@@ -334,17 +330,12 @@ struct AttributeStoreHandle
334 /** 330 /**
335 * The attribute to store 331 * The attribute to store
336 */ 332 */
337 struct GNUNET_RECLAIM_ATTRIBUTE_Claim *claim; 333 struct GNUNET_RECLAIM_Attribute *claim;
338 334
339 /** 335 /**
340 * The attestation to store 336 * The attestation to store
341 */ 337 */
342 struct GNUNET_RECLAIM_ATTESTATION_Claim *attest; 338 struct GNUNET_RECLAIM_Attestation *attest;
343
344 /**
345 * The reference to store
346 */
347 struct GNUNET_RECLAIM_ATTESTATION_REFERENCE *reference;
348 339
349 /** 340 /**
350 * The attribute expiration interval 341 * The attribute expiration interval
@@ -480,8 +471,6 @@ cleanup_adh (struct AttributeDeleteHandle *adh)
480 GNUNET_free (adh->claim); 471 GNUNET_free (adh->claim);
481 if (NULL != adh->attest) 472 if (NULL != adh->attest)
482 GNUNET_free (adh->attest); 473 GNUNET_free (adh->attest);
483 if (NULL != adh->reference)
484 GNUNET_free (adh->reference);
485 while (NULL != (le = adh->tickets_to_update_head)) 474 while (NULL != (le = adh->tickets_to_update_head))
486 { 475 {
487 GNUNET_CONTAINER_DLL_remove (adh->tickets_to_update_head, 476 GNUNET_CONTAINER_DLL_remove (adh->tickets_to_update_head,
@@ -511,8 +500,6 @@ cleanup_as_handle (struct AttributeStoreHandle *ash)
511 GNUNET_free (ash->claim); 500 GNUNET_free (ash->claim);
512 if (NULL != ash->attest) 501 if (NULL != ash->attest)
513 GNUNET_free (ash->attest); 502 GNUNET_free (ash->attest);
514 if (NULL != ash->reference)
515 GNUNET_free (ash->reference);
516 GNUNET_free (ash); 503 GNUNET_free (ash);
517} 504}
518 505
@@ -718,13 +705,13 @@ handle_issue_ticket_message (void *cls, const struct IssueTicketMessage *im)
718{ 705{
719 struct TicketIssueOperation *tio; 706 struct TicketIssueOperation *tio;
720 struct IdpClient *idp = cls; 707 struct IdpClient *idp = cls;
721 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs; 708 struct GNUNET_RECLAIM_AttributeList *attrs;
722 size_t attrs_len; 709 size_t attrs_len;
723 710
724 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received ISSUE_TICKET message\n"); 711 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received ISSUE_TICKET message\n");
725 tio = GNUNET_new (struct TicketIssueOperation); 712 tio = GNUNET_new (struct TicketIssueOperation);
726 attrs_len = ntohs (im->attr_len); 713 attrs_len = ntohs (im->attr_len);
727 attrs = GNUNET_RECLAIM_ATTRIBUTE_list_deserialize ((char *) &im[1], 714 attrs = GNUNET_RECLAIM_attribute_list_deserialize ((char *) &im[1],
728 attrs_len); 715 attrs_len);
729 tio->r_id = ntohl (im->id); 716 tio->r_id = ntohl (im->id);
730 tio->client = idp; 717 tio->client = idp;
@@ -735,7 +722,7 @@ handle_issue_ticket_message (void *cls, const struct IssueTicketMessage *im)
735 &issue_ticket_result_cb, 722 &issue_ticket_result_cb,
736 tio); 723 tio);
737 GNUNET_SERVICE_client_continue (idp->client); 724 GNUNET_SERVICE_client_continue (idp->client);
738 GNUNET_RECLAIM_ATTRIBUTE_list_destroy (attrs); 725 GNUNET_RECLAIM_attribute_list_destroy (attrs);
739} 726}
740 727
741 728
@@ -828,7 +815,7 @@ handle_revoke_ticket_message (void *cls, const struct RevokeTicketMessage *rm)
828static void 815static void
829consume_result_cb (void *cls, 816consume_result_cb (void *cls,
830 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, 817 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
831 const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs, 818 const struct GNUNET_RECLAIM_AttributeList *attrs,
832 int32_t success, 819 int32_t success,
833 const char *emsg) 820 const char *emsg)
834{ 821{
@@ -842,7 +829,7 @@ consume_result_cb (void *cls,
842 { 829 {
843 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error consuming ticket: %s\n", emsg); 830 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error consuming ticket: %s\n", emsg);
844 } 831 }
845 attrs_len = GNUNET_RECLAIM_ATTRIBUTE_list_serialize_get_size (attrs); 832 attrs_len = GNUNET_RECLAIM_attribute_list_serialize_get_size (attrs);
846 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 833 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
847 "Sending CONSUME_TICKET_RESULT message\n"); 834 "Sending CONSUME_TICKET_RESULT message\n");
848 env = GNUNET_MQ_msg_extra (crm, 835 env = GNUNET_MQ_msg_extra (crm,
@@ -853,7 +840,7 @@ consume_result_cb (void *cls,
853 crm->identity = *identity; 840 crm->identity = *identity;
854 crm->result = htonl (success); 841 crm->result = htonl (success);
855 data_tmp = (char *) &crm[1]; 842 data_tmp = (char *) &crm[1];
856 GNUNET_RECLAIM_ATTRIBUTE_list_serialize (attrs, data_tmp); 843 GNUNET_RECLAIM_attribute_list_serialize (attrs, data_tmp);
857 GNUNET_MQ_send (cop->client->mq, env); 844 GNUNET_MQ_send (cop->client->mq, env);
858 GNUNET_CONTAINER_DLL_remove (cop->client->consume_op_head, 845 GNUNET_CONTAINER_DLL_remove (cop->client->consume_op_head,
859 cop->client->consume_op_tail, 846 cop->client->consume_op_tail,
@@ -965,20 +952,20 @@ attr_store_task (void *cls)
965 size_t buf_size; 952 size_t buf_size;
966 953
967 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Storing attribute\n"); 954 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Storing attribute\n");
968 buf_size = GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size (ash->claim); 955 buf_size = GNUNET_RECLAIM_attribute_serialize_get_size (ash->claim);
969 buf = GNUNET_malloc (buf_size); 956 buf = GNUNET_malloc (buf_size);
970 // Give the ash a new id if unset 957 // Give the ash a new id if unset
971 if (GNUNET_YES == GNUNET_RECLAIM_id_is_zero (&ash->claim->id)) 958 if (GNUNET_YES == GNUNET_RECLAIM_id_is_zero (&ash->claim->id))
972 GNUNET_RECLAIM_id_generate (&ash->claim->id); 959 GNUNET_RECLAIM_id_generate (&ash->claim->id);
973 GNUNET_RECLAIM_ATTRIBUTE_serialize (ash->claim, buf); 960 GNUNET_RECLAIM_attribute_serialize (ash->claim, buf);
974 label 961 label
975 = GNUNET_STRINGS_data_to_string_alloc (&ash->claim->id, 962 = GNUNET_STRINGS_data_to_string_alloc (&ash->claim->id,
976 sizeof (ash->reference->id)); 963 sizeof (ash->claim->id));
977 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Encrypting with label %s\n", label); 964 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Encrypting with label %s\n", label);
978 965
979 rd[0].data_size = buf_size; 966 rd[0].data_size = buf_size;
980 rd[0].data = buf; 967 rd[0].data = buf;
981 rd[0].record_type = GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR; 968 rd[0].record_type = GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE;
982 rd[0].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; 969 rd[0].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
983 rd[0].expiration_time = ash->exp.rel_value_us; 970 rd[0].expiration_time = ash->exp.rel_value_us;
984 ash->ns_qe = GNUNET_NAMESTORE_records_store (nsh, 971 ash->ns_qe = GNUNET_NAMESTORE_records_store (nsh,
@@ -1034,7 +1021,7 @@ handle_attribute_store_message (void *cls,
1034 data_len = ntohs (sam->attr_len); 1021 data_len = ntohs (sam->attr_len);
1035 1022
1036 ash = GNUNET_new (struct AttributeStoreHandle); 1023 ash = GNUNET_new (struct AttributeStoreHandle);
1037 ash->claim = GNUNET_RECLAIM_ATTRIBUTE_deserialize ((char *) &sam[1], 1024 ash->claim = GNUNET_RECLAIM_attribute_deserialize ((char *) &sam[1],
1038 data_len); 1025 data_len);
1039 1026
1040 ash->r_id = ntohl (sam->id); 1027 ash->r_id = ntohl (sam->id);
@@ -1088,32 +1075,6 @@ attest_store_cont (void *cls, int32_t success, const char *emsg)
1088 1075
1089 1076
1090/** 1077/**
1091 * Send a reference error response
1092 *
1093 * @param ash our attribute store handle
1094 * @param success the success status
1095 */
1096static void
1097send_ref_error (struct AttributeStoreHandle *ash)
1098{
1099 struct GNUNET_MQ_Envelope *env;
1100 struct SuccessResultMessage *acr_msg;
1101
1102 ash->ns_qe = NULL;
1103 GNUNET_CONTAINER_DLL_remove (ash->client->store_op_head,
1104 ash->client->store_op_tail,
1105 ash);
1106
1107 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending SUCCESS_RESPONSE message\n");
1108 env = GNUNET_MQ_msg (acr_msg, GNUNET_MESSAGE_TYPE_RECLAIM_SUCCESS_RESPONSE);
1109 acr_msg->id = htonl (ash->r_id);
1110 acr_msg->op_result = htonl (GNUNET_SYSERR);
1111 GNUNET_MQ_send (ash->client->mq, env);
1112 cleanup_as_handle (ash);
1113}
1114
1115
1116/**
1117 * Error looking up potential attestation. Abort. 1078 * Error looking up potential attestation. Abort.
1118 * 1079 *
1119 * @param cls our attribute store handle 1080 * @param cls our attribute store handle
@@ -1131,7 +1092,7 @@ attest_error (void *cls)
1131 1092
1132 1093
1133/** 1094/**
1134* Check for existing record before storing reference 1095* Check for existing record before storing attestation
1135* 1096*
1136* @param cls our attribute store handle 1097* @param cls our attribute store handle
1137* @param zone zone we are iterating 1098* @param zone zone we are iterating
@@ -1149,56 +1110,27 @@ attest_add_cb (void *cls,
1149 struct AttributeStoreHandle *ash = cls; 1110 struct AttributeStoreHandle *ash = cls;
1150 char *buf; 1111 char *buf;
1151 size_t buf_size; 1112 size_t buf_size;
1152 buf_size = GNUNET_RECLAIM_ATTESTATION_serialize_get_size (ash->attest); 1113 buf_size = GNUNET_RECLAIM_attestation_serialize_get_size (ash->attest);
1153 buf = GNUNET_malloc (buf_size); 1114 buf = GNUNET_malloc (buf_size);
1154 GNUNET_RECLAIM_ATTESTATION_serialize (ash->attest, buf); 1115 GNUNET_RECLAIM_attestation_serialize (ash->attest, buf);
1155 if (0 == rd_count) 1116 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1156 { 1117 "Storing new Attestation\n");
1157 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1118 struct GNUNET_GNSRECORD_Data rd_new[1];
1158 "Storing new Attestation\n");
1159 struct GNUNET_GNSRECORD_Data rd_new[1];
1160 rd_new[0].data_size = buf_size;
1161 rd_new[0].data = buf;
1162 rd_new[0].record_type = GNUNET_GNSRECORD_TYPE_RECLAIM_ATTEST_ATTR;
1163 rd_new[0].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
1164 rd_new[0].expiration_time = ash->exp.rel_value_us;
1165 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Encrypting with label %s\n", label);
1166 ash->ns_qe = GNUNET_NAMESTORE_records_store (nsh,
1167 &ash->identity,
1168 label,
1169 1,
1170 rd_new,
1171 &attest_store_cont,
1172 ash);
1173 GNUNET_free (buf);
1174 return;
1175 }
1176 if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTEST_ATTR != rd[0].record_type)
1177 {
1178 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1179 "Existing Attestation location is not an Attestation\n");
1180 send_ref_error (ash);
1181 return;
1182 }
1183 struct GNUNET_GNSRECORD_Data rd_new[rd_count];
1184 for (int i = 0; i<rd_count; i++)
1185 {
1186 rd_new[i] = rd[i];
1187 }
1188 rd_new[0].data_size = buf_size; 1119 rd_new[0].data_size = buf_size;
1189 rd_new[0].data = buf; 1120 rd_new[0].data = buf;
1190 rd_new[0].record_type = GNUNET_GNSRECORD_TYPE_RECLAIM_ATTEST_ATTR; 1121 rd_new[0].record_type = GNUNET_GNSRECORD_TYPE_RECLAIM_ATTESTATION;
1191 rd_new[0].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; 1122 rd_new[0].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
1192 rd_new[0].expiration_time = ash->exp.rel_value_us; 1123 rd_new[0].expiration_time = ash->exp.rel_value_us;
1193 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Encrypting with label %s\n", label); 1124 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Encrypting with label %s\n", label);
1194 ash->ns_qe = GNUNET_NAMESTORE_records_store (nsh, 1125 ash->ns_qe = GNUNET_NAMESTORE_records_store (nsh,
1195 &ash->identity, 1126 &ash->identity,
1196 label, 1127 label,
1197 rd_count, 1128 1,
1198 rd_new, 1129 rd_new,
1199 &attest_store_cont, 1130 &attest_store_cont,
1200 ash); 1131 ash);
1201 GNUNET_free (buf); 1132 GNUNET_free (buf);
1133 return;
1202} 1134}
1203 1135
1204 1136
@@ -1273,7 +1205,7 @@ handle_attestation_store_message (void *cls,
1273 data_len = ntohs (sam->attr_len); 1205 data_len = ntohs (sam->attr_len);
1274 1206
1275 ash = GNUNET_new (struct AttributeStoreHandle); 1207 ash = GNUNET_new (struct AttributeStoreHandle);
1276 ash->attest = GNUNET_RECLAIM_ATTESTATION_deserialize ((char *) &sam[1], 1208 ash->attest = GNUNET_RECLAIM_attestation_deserialize ((char *) &sam[1],
1277 data_len); 1209 data_len);
1278 1210
1279 ash->r_id = ntohl (sam->id); 1211 ash->r_id = ntohl (sam->id);
@@ -1289,250 +1221,6 @@ handle_attestation_store_message (void *cls,
1289 1221
1290 1222
1291/** 1223/**
1292 * Error looking up potential reference value. Abort.
1293 *
1294 * @param cls our attribute store handle
1295 */
1296static void
1297ref_error (void *cls)
1298{
1299 struct AttributeStoreHandle *ash = cls;
1300 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1301 "Failed to find Attestation entry for Attestation reference\n");
1302 cleanup_as_handle (ash);
1303 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
1304 return;
1305}
1306
1307
1308/**
1309 * Error looking up potential reference value. Abort.
1310 *
1311 * @param cls our attribute delete handle
1312 */
1313static void
1314ref_del_error (void *cls)
1315{
1316 struct AttributeDeleteHandle *adh = cls;
1317 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1318 "Failed to find Attestation entry for Attestation reference\n");
1319 cleanup_adh (adh);
1320 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
1321 return;
1322}
1323
1324
1325/**
1326* Reference store result handler
1327*
1328* @param cls our attribute store handle
1329* @param success GNUNET_OK if successful
1330* @param emsg error message (NULL if success=GNUNET_OK)
1331*/
1332static void
1333reference_store_cont (void *cls, int32_t success, const char *emsg)
1334{
1335 struct AttributeStoreHandle *ash = cls;
1336 struct GNUNET_MQ_Envelope *env;
1337 struct SuccessResultMessage *acr_msg;
1338
1339 ash->ns_qe = NULL;
1340 GNUNET_CONTAINER_DLL_remove (ash->client->store_op_head,
1341 ash->client->store_op_tail,
1342 ash);
1343
1344 if (GNUNET_SYSERR == success)
1345 {
1346 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1347 "Failed to store reference %s\n",
1348 emsg);
1349 cleanup_as_handle (ash);
1350 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
1351 return;
1352 }
1353
1354 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending SUCCESS_RESPONSE message\n");
1355 env = GNUNET_MQ_msg (acr_msg, GNUNET_MESSAGE_TYPE_RECLAIM_SUCCESS_RESPONSE);
1356 acr_msg->id = htonl (ash->r_id);
1357 acr_msg->op_result = htonl (GNUNET_OK);
1358 GNUNET_MQ_send (ash->client->mq, env);
1359 cleanup_as_handle (ash);
1360}
1361
1362
1363/**
1364* Check for existing record before storing reference
1365*
1366* @param cls our attribute store handle
1367* @param zone zone we are iterating
1368* @param label label of the records
1369* @param rd_count record count
1370* @param rd records
1371*/
1372static void
1373ref_add_cb (void *cls,
1374 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
1375 const char *label,
1376 unsigned int rd_count,
1377 const struct GNUNET_GNSRECORD_Data *rd)
1378{
1379 struct AttributeStoreHandle *ash = cls;
1380 char *buf;
1381 size_t buf_size;
1382 buf_size = GNUNET_RECLAIM_ATTESTATION_REF_serialize_get_size (ash->reference);
1383 buf = GNUNET_malloc (buf_size);
1384 GNUNET_RECLAIM_ATTESTATION_REF_serialize (ash->reference, buf);
1385 struct GNUNET_RECLAIM_ATTESTATION_REFERENCE *ref;
1386 char *data_tmp;
1387 if (0 == rd_count)
1388 {
1389 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1390 "Failed to find Attestation entry for Attestation reference\n");
1391 send_ref_error (ash);
1392 return;
1393 }
1394 if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTEST_ATTR != rd[0].record_type)
1395 {
1396 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1397 "Intended Reference storage location is not an attestation\n");
1398 send_ref_error (ash);
1399 return;
1400 }
1401 struct GNUNET_GNSRECORD_Data rd_new[rd_count + 1];
1402 int i;
1403 for (i = 0; i<rd_count; i++)
1404 {
1405 data_tmp = GNUNET_malloc (rd[i].data_size);
1406 GNUNET_memcpy (data_tmp, rd[i].data, rd[i].data_size);
1407 ref = GNUNET_RECLAIM_ATTESTATION_REF_deserialize (data_tmp, htons (
1408 rd[i].data_size));
1409 rd_new[i] = rd[i];
1410 if ((strcmp (ash->reference->name,ref->name) == 0) &&
1411 (strcmp (ash->reference->reference_value,ref->reference_value)==0) )
1412 {
1413 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1414 "Reference already stored\n");
1415 reference_store_cont (ash,GNUNET_OK, NULL);
1416 return;
1417 }
1418 }
1419 rd_new[rd_count].data_size = buf_size;
1420 rd_new[rd_count].data = buf;
1421 rd_new[rd_count].record_type = GNUNET_GNSRECORD_TYPE_RECLAIM_REFERENCE;
1422 rd_new[rd_count].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
1423 rd_new[rd_count].expiration_time = ash->exp.rel_value_us;
1424 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Encrypting with label %s\n", label);
1425 ash->ns_qe = GNUNET_NAMESTORE_records_store (nsh,
1426 &ash->identity,
1427 label,
1428 rd_count + 1,
1429 rd_new,
1430 &reference_store_cont,
1431 ash);
1432 GNUNET_free (buf);
1433}
1434
1435
1436/**
1437 * Add a new reference
1438 *
1439 * @param cls the AttributeStoreHandle
1440 */
1441static void
1442reference_store_task (void *cls)
1443{
1444 struct AttributeStoreHandle *ash = cls;
1445 char *label;
1446
1447 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Storing reference\n");
1448
1449 // Give the ash a new id if unset
1450 if (GNUNET_YES == GNUNET_RECLAIM_id_is_zero (&ash->reference->id))
1451 {
1452 if (GNUNET_YES == GNUNET_RECLAIM_id_is_zero (&ash->reference->id_attest))
1453 {
1454 GNUNET_RECLAIM_id_generate (&ash->reference->id);
1455 }
1456 else
1457 {
1458 ash->reference->id = ash->reference->id_attest;
1459 }
1460 }
1461
1462 label = GNUNET_STRINGS_data_to_string_alloc (&ash->reference->id,
1463 sizeof (ash->reference->id));
1464 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1465 "Looking up existing data under label %s\n", label);
1466// Test for the content of the existing ID
1467
1468 ash->ns_qe = GNUNET_NAMESTORE_records_lookup (nsh,
1469 &ash->identity,
1470 label,
1471 &ref_error,
1472 ash,
1473 &ref_add_cb,
1474 ash);
1475 GNUNET_free (label);
1476}
1477
1478
1479/**
1480 * Check an attestation reference store message
1481 *
1482 * @param cls unused
1483 * @param sam the message to check
1484 */
1485static int
1486check_reference_store_message (void *cls,
1487 const struct
1488 AttributeStoreMessage *sam)
1489{
1490 uint16_t size;
1491
1492 size = ntohs (sam->header.size);
1493 if (size <= sizeof(struct AttributeStoreMessage))
1494 {
1495 GNUNET_break (0);
1496 return GNUNET_SYSERR;
1497 }
1498 return GNUNET_OK;
1499}
1500
1501
1502/**
1503 * Handle an attestation reference store message
1504 *
1505 * @param cls our client
1506 * @param sam the message to handle
1507 */
1508static void
1509handle_reference_store_message (void *cls,
1510 const struct AttributeStoreMessage *sam)
1511{
1512 struct AttributeStoreHandle *ash;
1513 struct IdpClient *idp = cls;
1514 size_t data_len;
1515
1516 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received REFERENCE_STORE message\n");
1517
1518 data_len = ntohs (sam->attr_len);
1519 ash = GNUNET_new (struct AttributeStoreHandle);
1520 ash->reference = GNUNET_RECLAIM_ATTESTATION_REF_deserialize ((char *) &sam[1],
1521 data_len);
1522 ash->r_id = ntohl (sam->id);
1523 ash->identity = sam->identity;
1524 ash->exp.rel_value_us = GNUNET_ntohll (sam->exp);
1525 GNUNET_CRYPTO_ecdsa_key_get_public (&sam->identity, &ash->identity_pkey);
1526
1527
1528 GNUNET_SERVICE_client_continue (idp->client);
1529 ash->client = idp;
1530 GNUNET_CONTAINER_DLL_insert (idp->store_op_head, idp->store_op_tail, ash);
1531 GNUNET_SCHEDULER_add_now (&reference_store_task, ash);
1532}
1533
1534
1535/**
1536 * Send a deletion success response 1224 * Send a deletion success response
1537 * 1225 *
1538 * @param adh our attribute deletion handle 1226 * @param adh our attribute deletion handle
@@ -1578,7 +1266,7 @@ ticket_iter (void *cls,
1578 int has_changed = GNUNET_NO; 1266 int has_changed = GNUNET_NO;
1579 for (int i = 0; i < rd_count; i++) 1267 for (int i = 0; i < rd_count; i++)
1580 { 1268 {
1581 if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF != rd[i].record_type) 1269 if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE_REF != rd[i].record_type)
1582 continue; 1270 continue;
1583 if (adh->claim != NULL) 1271 if (adh->claim != NULL)
1584 if (GNUNET_YES != GNUNET_RECLAIM_id_is_equal (rd[i].data, 1272 if (GNUNET_YES != GNUNET_RECLAIM_id_is_equal (rd[i].data,
@@ -1588,12 +1276,8 @@ ticket_iter (void *cls,
1588 if (GNUNET_YES != GNUNET_RECLAIM_id_is_equal (rd[i].data, 1276 if (GNUNET_YES != GNUNET_RECLAIM_id_is_equal (rd[i].data,
1589 &adh->attest->id)) 1277 &adh->attest->id))
1590 continue; 1278 continue;
1591 if (adh->reference != NULL)
1592 if (GNUNET_YES != GNUNET_RECLAIM_id_is_equal (rd[i].data,
1593 &adh->reference->id))
1594 continue;
1595 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1279 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1596 "Attribute or Attestation/Reference to delete found (%s)\n", 1280 "Attribute or Attestation to delete found (%s)\n",
1597 adh->label); 1281 adh->label);
1598 has_changed = GNUNET_YES; 1282 has_changed = GNUNET_YES;
1599 break; 1283 break;
@@ -1684,20 +1368,15 @@ update_tickets (void *cls)
1684 for (int i = 0; i < le->rd_count; i++) 1368 for (int i = 0; i < le->rd_count; i++)
1685 { 1369 {
1686 if (adh->claim != NULL) 1370 if (adh->claim != NULL)
1687 if ((GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF == rd[i].record_type) 1371 if ((GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE_REF == rd[i].record_type)
1688 && (GNUNET_YES == GNUNET_RECLAIM_id_is_equal (rd[i].data, 1372 && (GNUNET_YES == GNUNET_RECLAIM_id_is_equal (rd[i].data,
1689 &adh->claim->id))) 1373 &adh->claim->id)))
1690 continue; 1374 continue;
1691 if (adh->attest != NULL) 1375 if (adh->attest != NULL)
1692 if ((GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF == rd[i].record_type) 1376 if ((GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE_REF == rd[i].record_type)
1693 && (GNUNET_YES == GNUNET_RECLAIM_id_is_equal (rd[i].data, 1377 && (GNUNET_YES == GNUNET_RECLAIM_id_is_equal (rd[i].data,
1694 &adh->attest->id))) 1378 &adh->attest->id)))
1695 continue; 1379 continue;
1696 if (adh->reference != NULL)
1697 if ((GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF == rd[i].record_type)
1698 && (GNUNET_YES == GNUNET_RECLAIM_id_is_equal (rd[i].data,
1699 &adh->reference->id)))
1700 continue;
1701 rd_new[j] = rd[i]; 1380 rd_new[j] = rd[i];
1702 j++; 1381 j++;
1703 } 1382 }
@@ -1837,9 +1516,8 @@ handle_attribute_delete_message (void *cls,
1837 data_len = ntohs (dam->attr_len); 1516 data_len = ntohs (dam->attr_len);
1838 1517
1839 adh = GNUNET_new (struct AttributeDeleteHandle); 1518 adh = GNUNET_new (struct AttributeDeleteHandle);
1840 adh->claim = GNUNET_RECLAIM_ATTRIBUTE_deserialize ((char *) &dam[1], 1519 adh->claim = GNUNET_RECLAIM_attribute_deserialize ((char *) &dam[1],
1841 data_len); 1520 data_len);
1842 adh->reference = NULL;
1843 adh->attest = NULL; 1521 adh->attest = NULL;
1844 1522
1845 adh->r_id = ntohl (dam->id); 1523 adh->r_id = ntohl (dam->id);
@@ -1928,9 +1606,8 @@ handle_attestation_delete_message (void *cls,
1928 data_len = ntohs (dam->attr_len); 1606 data_len = ntohs (dam->attr_len);
1929 1607
1930 adh = GNUNET_new (struct AttributeDeleteHandle); 1608 adh = GNUNET_new (struct AttributeDeleteHandle);
1931 adh->attest = GNUNET_RECLAIM_ATTESTATION_deserialize ((char *) &dam[1], 1609 adh->attest = GNUNET_RECLAIM_attestation_deserialize ((char *) &dam[1],
1932 data_len); 1610 data_len);
1933 adh->reference = NULL;
1934 adh->claim = NULL; 1611 adh->claim = NULL;
1935 1612
1936 adh->r_id = ntohl (dam->id); 1613 adh->r_id = ntohl (dam->id);
@@ -1951,169 +1628,6 @@ handle_attestation_delete_message (void *cls,
1951} 1628}
1952 1629
1953 1630
1954/**
1955* Reference deleted callback
1956*
1957* @param cls our handle
1958* @param success success status
1959* @param emsg error message (NULL if success=GNUNET_OK)
1960*/
1961static void
1962reference_delete_cont (void *cls, int32_t success, const char *emsg)
1963{
1964 struct AttributeDeleteHandle *adh = cls;
1965
1966 adh->ns_qe = NULL;
1967 if (GNUNET_SYSERR == success)
1968 {
1969 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1970 "Error deleting reference %s\n",
1971 adh->label);
1972 send_delete_response (adh, GNUNET_SYSERR);
1973 cleanup_adh (adh);
1974 return;
1975 }
1976 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Updating tickets...\n");
1977 // GNUNET_SCHEDULER_add_now (&start_ticket_update, adh);
1978 send_delete_response (adh, GNUNET_OK);
1979 cleanup_adh (adh);
1980 return;
1981}
1982
1983
1984static void
1985ref_del_cb (void *cls,
1986 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
1987 const char *label,
1988 unsigned int rd_count,
1989 const struct GNUNET_GNSRECORD_Data *rd)
1990{
1991
1992 struct AttributeDeleteHandle *adh = cls;
1993 char *data_tmp;
1994 struct GNUNET_GNSRECORD_Data rd_new[rd_count - 1];
1995 struct GNUNET_RECLAIM_ATTESTATION_REFERENCE *ref;
1996 size_t attr_len;
1997
1998 if (0 == rd_count)
1999 {
2000 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2001 "Failed to find Attestation entry for Attestation reference\n");
2002 cleanup_adh (adh);
2003 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
2004 return;
2005 }
2006 if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTEST_ATTR != rd[0].record_type)
2007 {
2008 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2009 "Intended Reference location is not an attestation\n");
2010 cleanup_adh (adh);
2011 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
2012 return;
2013 }
2014 rd_new[0] = rd[0];
2015 int i;
2016 int j = 1;
2017 for (i = 1; i<rd_count; i++)
2018 {
2019 data_tmp = GNUNET_malloc (rd[i].data_size);
2020 GNUNET_memcpy (data_tmp, rd[i].data, rd[i].data_size);
2021 attr_len = htons (rd[i].data_size);
2022 ref = GNUNET_RECLAIM_ATTESTATION_REF_deserialize (data_tmp, attr_len);
2023 if (NULL == ref)
2024 {
2025 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2026 "Unable to parse attestation reference from %s\n",
2027 data_tmp);
2028 rd_new[j] = rd[i];
2029 j += 1;
2030 continue;
2031 }
2032 if ((strcmp (adh->reference->name,ref->name) == 0) &&
2033 (strcmp (adh->reference->reference_value,ref->reference_value)==0) )
2034 {
2035 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2036 "Found reference to delete.\n");
2037 }
2038 else
2039 {
2040 rd_new[j] = rd[i];
2041 j += 1;
2042 }
2043 GNUNET_free (data_tmp);
2044 }
2045 adh->ns_qe = GNUNET_NAMESTORE_records_store (nsh,
2046 &adh->identity,
2047 label,
2048 j,
2049 rd_new,
2050 &reference_delete_cont,
2051 adh);
2052}
2053
2054
2055/**
2056 * Check an attestation reference delete message
2057 *
2058 * @param cls unused
2059 * @param sam the message to check
2060 */
2061static int
2062check_reference_delete_message (void *cls,
2063 const struct AttributeDeleteMessage *dam)
2064{
2065 uint16_t size;
2066
2067 size = ntohs (dam->header.size);
2068 if (size <= sizeof(struct AttributeDeleteMessage))
2069 {
2070 GNUNET_break (0);
2071 return GNUNET_SYSERR;
2072 }
2073 return GNUNET_OK;
2074}
2075
2076
2077/**
2078 * Handle reference deletion
2079 *
2080 * @param cls our client
2081 * @param dam deletion message
2082 */
2083static void
2084handle_reference_delete_message (void *cls,
2085 const struct AttributeDeleteMessage *dam)
2086{
2087 struct AttributeDeleteHandle *adh;
2088 struct IdpClient *idp = cls;
2089 size_t data_len;
2090
2091 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received REFERENCE_DELETE message\n");
2092 data_len = ntohs (dam->attr_len);
2093 adh = GNUNET_new (struct AttributeDeleteHandle);
2094 adh->reference = GNUNET_RECLAIM_ATTESTATION_REF_deserialize ((char *) &dam[1],
2095 data_len);
2096 adh->attest = NULL;
2097 adh->claim = NULL;
2098
2099 adh->r_id = ntohl (dam->id);
2100 adh->identity = dam->identity;
2101 adh->label
2102 = GNUNET_STRINGS_data_to_string_alloc (&adh->reference->id,
2103 sizeof(adh->reference->id));
2104 GNUNET_SERVICE_client_continue (idp->client);
2105 adh->client = idp;
2106 GNUNET_CONTAINER_DLL_insert (idp->delete_op_head, idp->delete_op_tail, adh);
2107 adh->ns_qe = GNUNET_NAMESTORE_records_lookup (nsh,
2108 &adh->identity,
2109 adh->label,
2110 &ref_del_error,
2111 adh,
2112 &ref_del_cb,
2113 adh);
2114}
2115
2116
2117/************************************************* 1631/*************************************************
2118* Attrubute iteration 1632* Attrubute iteration
2119*************************************************/ 1633*************************************************/
@@ -2159,7 +1673,7 @@ attr_iter_error (void *cls)
2159 1673
2160 1674
2161/** 1675/**
2162 * Got record. Return if it is an attribute or attestation/reference. 1676 * Got record. Return if it is an attribute or attestation.
2163 * 1677 *
2164 * @param cls our attribute iterator 1678 * @param cls our attribute iterator
2165 * @param zone zone we are iterating 1679 * @param zone zone we are iterating
@@ -2185,14 +1699,14 @@ attr_iter_cb (void *cls,
2185 } 1699 }
2186 if (rd_count > 1) 1700 if (rd_count > 1)
2187 { 1701 {
2188 if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF == rd[0].record_type) 1702 if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE_REF == rd[0].record_type)
2189 { 1703 {
2190 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1704 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2191 "Found Ticket. Ignoring.\n"); 1705 "Found Ticket. Ignoring.\n");
2192 GNUNET_NAMESTORE_zone_iterator_next (ai->ns_it, 1); 1706 GNUNET_NAMESTORE_zone_iterator_next (ai->ns_it, 1);
2193 return; 1707 return;
2194 } 1708 }
2195 else if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTEST_ATTR != rd[0].record_type) 1709 else if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTESTATION != rd[0].record_type)
2196 { 1710 {
2197 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1711 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2198 "Non-Attestation record with multiple entries found: %u\n", 1712 "Non-Attestation record with multiple entries found: %u\n",
@@ -2204,15 +1718,14 @@ attr_iter_cb (void *cls,
2204 1718
2205 for (int i = 0; i<rd_count; i++) 1719 for (int i = 0; i<rd_count; i++)
2206 { 1720 {
2207 if ((GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR != rd[i].record_type) && 1721 if ((GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE != rd[i].record_type) &&
2208 (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTEST_ATTR != rd[i].record_type) && 1722 (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTESTATION != rd[i].record_type))
2209 (GNUNET_GNSRECORD_TYPE_RECLAIM_REFERENCE != rd[i].record_type))
2210 { 1723 {
2211 GNUNET_NAMESTORE_zone_iterator_next (ai->ns_it, 1); 1724 GNUNET_NAMESTORE_zone_iterator_next (ai->ns_it, 1);
2212 return; 1725 return;
2213 } 1726 }
2214 1727 // FIXME Send attribute TOGETHER with respective attestation if applicable
2215 if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR == rd[i].record_type) 1728 if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE == rd[i].record_type)
2216 { 1729 {
2217 struct AttributeResultMessage *arm; 1730 struct AttributeResultMessage *arm;
2218 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found attribute under: %s\n", 1731 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found attribute under: %s\n",
@@ -2231,7 +1744,7 @@ attr_iter_cb (void *cls,
2231 } 1744 }
2232 else 1745 else
2233 { 1746 {
2234 if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTEST_ATTR == rd[i].record_type) 1747 if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTESTATION == rd[i].record_type)
2235 { 1748 {
2236 struct AttributeResultMessage *arm; 1749 struct AttributeResultMessage *arm;
2237 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found attestation under: %s\n", 1750 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found attestation under: %s\n",
@@ -2248,26 +1761,6 @@ attr_iter_cb (void *cls,
2248 GNUNET_memcpy (data_tmp, rd[i].data, rd[i].data_size); 1761 GNUNET_memcpy (data_tmp, rd[i].data, rd[i].data_size);
2249 GNUNET_MQ_send (ai->client->mq, env); 1762 GNUNET_MQ_send (ai->client->mq, env);
2250 } 1763 }
2251 else
2252 {
2253 struct ReferenceResultMessage *rrm;
2254 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found reference under: %s\n",
2255 label);
2256 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2257 "Sending REFERENCE_RESULT message\n");
2258 env = GNUNET_MQ_msg_extra (rrm,
2259 rd[i].data_size + rd[0].data_size,
2260 GNUNET_MESSAGE_TYPE_RECLAIM_REFERENCE_RESULT);
2261 rrm->id = htonl (ai->request_id);
2262 rrm->attest_len = htons (rd[0].data_size);
2263 rrm->ref_len = htons (rd[i].data_size);
2264 GNUNET_CRYPTO_ecdsa_key_get_public (zone, &rrm->identity);
2265 data_tmp = (char *) &rrm[1];
2266 GNUNET_memcpy (data_tmp, rd[0].data, rd[0].data_size);
2267 data_tmp += rd[0].data_size;
2268 GNUNET_memcpy (data_tmp, rd[i].data, rd[i].data_size);
2269 GNUNET_MQ_send (ai->client->mq, env);
2270 }
2271 } 1764 }
2272 } 1765 }
2273} 1766}
@@ -2610,19 +2103,10 @@ GNUNET_SERVICE_MAIN (
2610 GNUNET_MESSAGE_TYPE_RECLAIM_ATTESTATION_DELETE, 2103 GNUNET_MESSAGE_TYPE_RECLAIM_ATTESTATION_DELETE,
2611 struct AttributeDeleteMessage, 2104 struct AttributeDeleteMessage,
2612 NULL), 2105 NULL),
2613 GNUNET_MQ_hd_var_size (reference_store_message, 2106 GNUNET_MQ_hd_fixed_size (iteration_start,
2614 GNUNET_MESSAGE_TYPE_RECLAIM_REFERENCE_STORE, 2107 GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_START,
2615 struct AttributeStoreMessage, 2108 struct AttributeIterationStartMessage,
2616 NULL), 2109 NULL),
2617 GNUNET_MQ_hd_var_size (reference_delete_message,
2618 GNUNET_MESSAGE_TYPE_RECLAIM_REFERENCE_DELETE,
2619 struct AttributeDeleteMessage,
2620 NULL),
2621 GNUNET_MQ_hd_fixed_size (
2622 iteration_start,
2623 GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_START,
2624 struct AttributeIterationStartMessage,
2625 NULL),
2626 GNUNET_MQ_hd_fixed_size (iteration_next, 2110 GNUNET_MQ_hd_fixed_size (iteration_next,
2627 GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_NEXT, 2111 GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_NEXT,
2628 struct AttributeIterationNextMessage, 2112 struct AttributeIterationNextMessage,