diff options
author | Markus Voggenreiter <Markus.Voggenreiter@tum.de> | 2019-11-27 12:30:49 +0100 |
---|---|---|
committer | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2020-01-13 13:31:05 +0100 |
commit | cb08bbcbefc98afe6b8c7600bb0dfb1241343cff (patch) | |
tree | ec801cb4e772bd245ca8d22f19bc751ca67d2737 /src/reclaim/gnunet-service-reclaim.c | |
parent | c0fce9ca75973a646f80372fcc08c059818ba548 (diff) | |
download | gnunet-cb08bbcbefc98afe6b8c7600bb0dfb1241343cff.tar.gz gnunet-cb08bbcbefc98afe6b8c7600bb0dfb1241343cff.zip |
Basic Functionality Implemented
Diffstat (limited to 'src/reclaim/gnunet-service-reclaim.c')
-rw-r--r-- | src/reclaim/gnunet-service-reclaim.c | 71 |
1 files changed, 58 insertions, 13 deletions
diff --git a/src/reclaim/gnunet-service-reclaim.c b/src/reclaim/gnunet-service-reclaim.c index fcbd9413f..8b7557090 100644 --- a/src/reclaim/gnunet-service-reclaim.c +++ b/src/reclaim/gnunet-service-reclaim.c | |||
@@ -1251,6 +1251,31 @@ reference_store_cont (void *cls, int32_t success, const char *emsg) | |||
1251 | } | 1251 | } |
1252 | 1252 | ||
1253 | /** | 1253 | /** |
1254 | * Send a reference error response | ||
1255 | * | ||
1256 | * @param ash our attribute store handle | ||
1257 | * @param success the success status | ||
1258 | */ | ||
1259 | static void | ||
1260 | send_ref_error (struct AttributeStoreHandle *ash) | ||
1261 | { | ||
1262 | struct GNUNET_MQ_Envelope *env; | ||
1263 | struct SuccessResultMessage *acr_msg; | ||
1264 | |||
1265 | ash->ns_qe = NULL; | ||
1266 | GNUNET_CONTAINER_DLL_remove (ash->client->store_op_head, | ||
1267 | ash->client->store_op_tail, | ||
1268 | ash); | ||
1269 | |||
1270 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending SUCCESS_RESPONSE message\n"); | ||
1271 | env = GNUNET_MQ_msg (acr_msg, GNUNET_MESSAGE_TYPE_RECLAIM_SUCCESS_RESPONSE); | ||
1272 | acr_msg->id = htonl (ash->r_id); | ||
1273 | acr_msg->op_result = htonl (GNUNET_SYSERR); | ||
1274 | GNUNET_MQ_send (ash->client->mq, env); | ||
1275 | cleanup_as_handle (ash); | ||
1276 | } | ||
1277 | |||
1278 | /** | ||
1254 | * Check for existing record before storing reference | 1279 | * Check for existing record before storing reference |
1255 | * | 1280 | * |
1256 | * @param cls our attribute store handle | 1281 | * @param cls our attribute store handle |
@@ -1272,33 +1297,46 @@ ref_add_cb (void *cls, | |||
1272 | buf_size = GNUNET_RECLAIM_ATTESTATION_REF_serialize_get_size (ash->reference); | 1297 | buf_size = GNUNET_RECLAIM_ATTESTATION_REF_serialize_get_size (ash->reference); |
1273 | buf = GNUNET_malloc (buf_size); | 1298 | buf = GNUNET_malloc (buf_size); |
1274 | GNUNET_RECLAIM_ATTESTATION_REF_serialize (ash->reference, buf); | 1299 | GNUNET_RECLAIM_ATTESTATION_REF_serialize (ash->reference, buf); |
1300 | struct GNUNET_RECLAIM_ATTESTATION_REFERENCE *ref; | ||
1301 | char *data_tmp; | ||
1275 | if (0 == rd_count ) | 1302 | if (0 == rd_count ) |
1276 | { | 1303 | { |
1277 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1304 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1278 | "Failed to find Attestation entry for Attestation reference\n"); | 1305 | "Failed to find Attestation entry for Attestation reference\n"); |
1279 | cleanup_as_handle (ash); | 1306 | send_ref_error (ash); |
1280 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | ||
1281 | return; | 1307 | return; |
1282 | } | 1308 | } |
1283 | if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTEST_ATTR != rd[0].record_type) | 1309 | if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTEST_ATTR != rd[0].record_type) |
1284 | { | 1310 | { |
1285 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1311 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1286 | "Intended Reference storage location is not an attestation\n"); | 1312 | "Intended Reference storage location is not an attestation\n"); |
1287 | cleanup_as_handle (ash); | 1313 | send_ref_error (ash); |
1288 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | ||
1289 | return; | 1314 | return; |
1290 | } | 1315 | } |
1291 | struct GNUNET_GNSRECORD_Data rd_new[rd_count + 1]; | 1316 | struct GNUNET_GNSRECORD_Data rd_new[rd_count + 1]; |
1292 | int i; | 1317 | int i; |
1293 | for (i = 0; i<rd_count; i++) | 1318 | for (i = 0; i<rd_count; i++) |
1294 | { | 1319 | { |
1320 | data_tmp = GNUNET_malloc (rd[i].data_size); | ||
1321 | GNUNET_memcpy (data_tmp, rd[i].data, rd[i].data_size); | ||
1322 | ref = GNUNET_RECLAIM_ATTESTATION_REF_deserialize (data_tmp, htons ( | ||
1323 | rd[i].data_size)); | ||
1295 | rd_new[i] = rd[i]; | 1324 | rd_new[i] = rd[i]; |
1325 | if ((strcmp (ash->reference->name,ref->name) == 0)&& | ||
1326 | (strcmp (ash->reference->reference_value,ref->reference_value)==0) ) | ||
1327 | { | ||
1328 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1329 | "Reference already stored\n"); | ||
1330 | reference_store_cont (ash,GNUNET_OK, NULL); | ||
1331 | return; | ||
1332 | } | ||
1296 | } | 1333 | } |
1297 | rd_new[rd_count].data_size = buf_size; | 1334 | rd_new[rd_count].data_size = buf_size; |
1298 | rd_new[rd_count].data = buf; | 1335 | rd_new[rd_count].data = buf; |
1299 | rd_new[rd_count].record_type = GNUNET_GNSRECORD_TYPE_RECLAIM_REFERENCE; | 1336 | rd_new[rd_count].record_type = GNUNET_GNSRECORD_TYPE_RECLAIM_REFERENCE; |
1300 | rd_new[rd_count].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; | 1337 | rd_new[rd_count].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; |
1301 | rd_new[rd_count].expiration_time = ash->exp.rel_value_us; | 1338 | rd_new[rd_count].expiration_time = ash->exp.rel_value_us; |
1339 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Encrypting with label %s\n", label); | ||
1302 | ash->ns_qe = GNUNET_NAMESTORE_records_store (nsh, | 1340 | ash->ns_qe = GNUNET_NAMESTORE_records_store (nsh, |
1303 | &ash->identity, | 1341 | &ash->identity, |
1304 | label, | 1342 | label, |
@@ -1339,7 +1377,8 @@ reference_store_task (void *cls) | |||
1339 | 1377 | ||
1340 | label = GNUNET_STRINGS_data_to_string_alloc (&ash->reference->id, | 1378 | label = GNUNET_STRINGS_data_to_string_alloc (&ash->reference->id, |
1341 | sizeof(uint64_t)); | 1379 | sizeof(uint64_t)); |
1342 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Encrypting with label %s\n", label); | 1380 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1381 | "Looking up existing data under label %s\n", label); | ||
1343 | // Test for the content of the existing ID | 1382 | // Test for the content of the existing ID |
1344 | 1383 | ||
1345 | ash->ns_qe = GNUNET_NAMESTORE_records_lookup (nsh, | 1384 | ash->ns_qe = GNUNET_NAMESTORE_records_lookup (nsh, |
@@ -1452,9 +1491,7 @@ ticket_iter (void *cls, | |||
1452 | int has_changed = GNUNET_NO; | 1491 | int has_changed = GNUNET_NO; |
1453 | for (int i = 0; i < rd_count; i++) | 1492 | for (int i = 0; i < rd_count; i++) |
1454 | { | 1493 | { |
1455 | if ((GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF != rd[i].record_type) && | 1494 | if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF != rd[i].record_type) |
1456 | (GNUNET_GNSRECORD_TYPE_RECLAIM_REFERENCE_REF != rd[i].record_type) && | ||
1457 | (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTEST_REF != rd[i].record_type)) | ||
1458 | continue; | 1495 | continue; |
1459 | if (&adh->claim != NULL) | 1496 | if (&adh->claim != NULL) |
1460 | if (0 != memcmp (rd[i].data, &adh->claim->id, sizeof(uint64_t))) | 1497 | if (0 != memcmp (rd[i].data, &adh->claim->id, sizeof(uint64_t))) |
@@ -1559,10 +1596,10 @@ update_tickets (void *cls) | |||
1559 | if ((GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF == rd[i].record_type) | 1596 | if ((GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF == rd[i].record_type) |
1560 | && (0 == memcmp (rd[i].data, &adh->claim->id, sizeof(uint64_t)))) | 1597 | && (0 == memcmp (rd[i].data, &adh->claim->id, sizeof(uint64_t)))) |
1561 | continue; | 1598 | continue; |
1562 | if ((GNUNET_GNSRECORD_TYPE_RECLAIM_REFERENCE_REF == rd[i].record_type) | 1599 | if ((GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF == rd[i].record_type) |
1563 | && (0 == memcmp (rd[i].data, &adh->attest->id, sizeof(uint64_t)))) | 1600 | && (0 == memcmp (rd[i].data, &adh->attest->id, sizeof(uint64_t)))) |
1564 | continue; | 1601 | continue; |
1565 | if ((GNUNET_GNSRECORD_TYPE_RECLAIM_ATTEST_REF == rd[i].record_type) | 1602 | if ((GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF == rd[i].record_type) |
1566 | && (0 == memcmp (rd[i].data, &adh->reference->id, sizeof(uint64_t)))) | 1603 | && (0 == memcmp (rd[i].data, &adh->reference->id, sizeof(uint64_t)))) |
1567 | continue; | 1604 | continue; |
1568 | rd_new[j] = rd[i]; | 1605 | rd_new[j] = rd[i]; |
@@ -1879,7 +1916,7 @@ ref_del_cb (void *cls, | |||
1879 | { | 1916 | { |
1880 | data_tmp = GNUNET_malloc (rd[i].data_size); | 1917 | data_tmp = GNUNET_malloc (rd[i].data_size); |
1881 | GNUNET_memcpy (data_tmp, rd[i].data, rd[i].data_size); | 1918 | GNUNET_memcpy (data_tmp, rd[i].data, rd[i].data_size); |
1882 | attr_len = htons (rd->data_size); | 1919 | attr_len = htons (rd[i].data_size); |
1883 | ref = GNUNET_RECLAIM_ATTESTATION_REF_deserialize (data_tmp, attr_len); | 1920 | ref = GNUNET_RECLAIM_ATTESTATION_REF_deserialize (data_tmp, attr_len); |
1884 | if (NULL == ref ) | 1921 | if (NULL == ref ) |
1885 | { | 1922 | { |
@@ -2045,10 +2082,18 @@ attr_iter_cb (void *cls, | |||
2045 | } | 2082 | } |
2046 | if (rd_count > 1) | 2083 | if (rd_count > 1) |
2047 | { | 2084 | { |
2048 | if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTEST_ATTR != rd[0].record_type) | 2085 | if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF == rd[0].record_type) |
2086 | { | ||
2087 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2088 | "Found Ticket. Ignoring.\n"); | ||
2089 | GNUNET_NAMESTORE_zone_iterator_next (ai->ns_it, 1); | ||
2090 | return; | ||
2091 | } | ||
2092 | else if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTEST_ATTR != rd[0].record_type) | ||
2049 | { | 2093 | { |
2050 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 2094 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
2051 | "Non-Attestation record with multiple entries found\n"); | 2095 | "Non-Attestation record with multiple entries found: %u\n", |
2096 | rd[0].record_type); | ||
2052 | GNUNET_NAMESTORE_zone_iterator_next (ai->ns_it, 1); | 2097 | GNUNET_NAMESTORE_zone_iterator_next (ai->ns_it, 1); |
2053 | return; | 2098 | return; |
2054 | } | 2099 | } |