diff options
author | Markus Voggenreiter <Markus.Voggenreiter@tum.de> | 2019-10-27 22:43:23 +0100 |
---|---|---|
committer | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2020-01-13 13:31:03 +0100 |
commit | b62682f35d3752eff4b9d7ff52d47e0bfbd6b6f5 (patch) | |
tree | bfa262535f1ed7ce2e343972795a20fd070533db /src/reclaim/gnunet-service-reclaim.c | |
parent | df903a80b2681567bf0b1afe9f1e3c89b13efbc2 (diff) | |
download | gnunet-b62682f35d3752eff4b9d7ff52d47e0bfbd6b6f5.tar.gz gnunet-b62682f35d3752eff4b9d7ff52d47e0bfbd6b6f5.zip |
Deletion of Reference Type
Diffstat (limited to 'src/reclaim/gnunet-service-reclaim.c')
-rw-r--r-- | src/reclaim/gnunet-service-reclaim.c | 198 |
1 files changed, 191 insertions, 7 deletions
diff --git a/src/reclaim/gnunet-service-reclaim.c b/src/reclaim/gnunet-service-reclaim.c index aea96e61e..1f320e196 100644 --- a/src/reclaim/gnunet-service-reclaim.c +++ b/src/reclaim/gnunet-service-reclaim.c | |||
@@ -271,6 +271,10 @@ struct AttributeDeleteHandle | |||
271 | struct GNUNET_RECLAIM_ATTESTATION_Claim *attest; | 271 | struct GNUNET_RECLAIM_ATTESTATION_Claim *attest; |
272 | 272 | ||
273 | /** | 273 | /** |
274 | * The reference to delete | ||
275 | */ | ||
276 | struct GNUNET_RECLAIM_ATTESTATION_REFERENCE *reference; | ||
277 | /** | ||
274 | * Tickets to update | 278 | * Tickets to update |
275 | */ | 279 | */ |
276 | struct TicketRecordsEntry *tickets_to_update_head; | 280 | struct TicketRecordsEntry *tickets_to_update_head; |
@@ -476,6 +480,8 @@ cleanup_adh (struct AttributeDeleteHandle *adh) | |||
476 | GNUNET_free (adh->claim); | 480 | GNUNET_free (adh->claim); |
477 | if (NULL != adh->attest) | 481 | if (NULL != adh->attest) |
478 | GNUNET_free (adh->attest); | 482 | GNUNET_free (adh->attest); |
483 | if (NULL != adh->reference) | ||
484 | GNUNET_free (adh->reference); | ||
479 | while (NULL != (le = adh->tickets_to_update_head)) | 485 | while (NULL != (le = adh->tickets_to_update_head)) |
480 | { | 486 | { |
481 | GNUNET_CONTAINER_DLL_remove (adh->tickets_to_update_head, | 487 | GNUNET_CONTAINER_DLL_remove (adh->tickets_to_update_head, |
@@ -1193,6 +1199,21 @@ ref_error (void *cls) | |||
1193 | } | 1199 | } |
1194 | 1200 | ||
1195 | /** | 1201 | /** |
1202 | * Error looking up potential reference value. Abort. | ||
1203 | * | ||
1204 | * @param cls our attribute delete handle | ||
1205 | */ | ||
1206 | static void | ||
1207 | ref_del_error (void *cls) | ||
1208 | { | ||
1209 | struct AttributeDeleteHandle *adh = cls; | ||
1210 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1211 | "Failed to find Attestation entry for Attestation reference\n"); | ||
1212 | cleanup_adh (adh); | ||
1213 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | ||
1214 | return; | ||
1215 | } | ||
1216 | /** | ||
1196 | * Reference store result handler | 1217 | * Reference store result handler |
1197 | * | 1218 | * |
1198 | * @param cls our attribute store handle | 1219 | * @param cls our attribute store handle |
@@ -1306,8 +1327,9 @@ reference_store_task (void *cls) | |||
1306 | { | 1327 | { |
1307 | if (0 == ash->reference->id_attest) | 1328 | if (0 == ash->reference->id_attest) |
1308 | { | 1329 | { |
1309 | ash->reference->id = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG, | 1330 | ash->reference->id = GNUNET_CRYPTO_random_u64 ( |
1310 | UINT64_MAX); | 1331 | GNUNET_CRYPTO_QUALITY_STRONG, |
1332 | UINT64_MAX); | ||
1311 | } | 1333 | } |
1312 | else | 1334 | else |
1313 | { | 1335 | { |
@@ -1327,7 +1349,7 @@ reference_store_task (void *cls) | |||
1327 | ash, | 1349 | ash, |
1328 | &ref_add_cb, | 1350 | &ref_add_cb, |
1329 | ash); | 1351 | ash); |
1330 | GNUNET_free (label); | 1352 | GNUNET_free (label); |
1331 | } | 1353 | } |
1332 | 1354 | ||
1333 | /** | 1355 | /** |
@@ -1338,8 +1360,8 @@ reference_store_task (void *cls) | |||
1338 | */ | 1360 | */ |
1339 | static int | 1361 | static int |
1340 | check_reference_store_message (void *cls, | 1362 | check_reference_store_message (void *cls, |
1341 | const struct | 1363 | const struct |
1342 | AttributeStoreMessage *sam) | 1364 | AttributeStoreMessage *sam) |
1343 | { | 1365 | { |
1344 | uint16_t size; | 1366 | uint16_t size; |
1345 | 1367 | ||
@@ -1432,14 +1454,18 @@ ticket_iter (void *cls, | |||
1432 | for (int i = 0; i < rd_count; i++) | 1454 | for (int i = 0; i < rd_count; i++) |
1433 | { | 1455 | { |
1434 | if ((GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF != rd[i].record_type) && | 1456 | if ((GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF != rd[i].record_type) && |
1435 | (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTEST_ATTR != rd[i].record_type)) | 1457 | (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTEST_ATTR != rd[i].record_type) && |
1458 | (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTEST_REF != rd[i].record_type)) | ||
1436 | continue; | 1459 | continue; |
1437 | if (0 != memcmp (rd[i].data, &adh->claim->id, sizeof(uint64_t))) | 1460 | if (0 != memcmp (rd[i].data, &adh->claim->id, sizeof(uint64_t))) |
1438 | continue; | 1461 | continue; |
1439 | if (0 != memcmp (rd[i].data, (&adh->attest->id), sizeof(uint64_t))) | 1462 | if (0 != memcmp (rd[i].data, (&adh->attest->id), sizeof(uint64_t))) |
1440 | continue; | 1463 | continue; |
1464 | if (0 != memcmp (rd[i].data, &adh->reference->id, sizeof(uint64_t))) | ||
1465 | continue; | ||
1466 | |||
1441 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1467 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1442 | "Attribute or Attestation to delete found (%s)\n", | 1468 | "Attribute or Attestation/Reference to delete found (%s)\n", |
1443 | adh->label); | 1469 | adh->label); |
1444 | has_changed = GNUNET_YES; | 1470 | has_changed = GNUNET_YES; |
1445 | break; | 1471 | break; |
@@ -1535,6 +1561,9 @@ update_tickets (void *cls) | |||
1535 | if ((GNUNET_GNSRECORD_TYPE_RECLAIM_ATTEST_ATTR == rd[i].record_type) | 1561 | if ((GNUNET_GNSRECORD_TYPE_RECLAIM_ATTEST_ATTR == rd[i].record_type) |
1536 | && (0 == memcmp (rd[i].data, &adh->attest->id, sizeof(uint64_t)))) | 1562 | && (0 == memcmp (rd[i].data, &adh->attest->id, sizeof(uint64_t)))) |
1537 | continue; | 1563 | continue; |
1564 | if ((GNUNET_GNSRECORD_TYPE_RECLAIM_ATTEST_REF == rd[i].record_type) | ||
1565 | && (0 == memcmp (rd[i].data, &adh->reference->id, sizeof(uint64_t)))) | ||
1566 | continue; | ||
1538 | rd_new[j] = rd[i]; | 1567 | rd_new[j] = rd[i]; |
1539 | j++; | 1568 | j++; |
1540 | } | 1569 | } |
@@ -1782,7 +1811,158 @@ handle_attestation_delete_message (void *cls, | |||
1782 | 1811 | ||
1783 | 1812 | ||
1784 | 1813 | ||
1814 | /** | ||
1815 | * Reference deleted callback | ||
1816 | * | ||
1817 | * @param cls our handle | ||
1818 | * @param success success status | ||
1819 | * @param emsg error message (NULL if success=GNUNET_OK) | ||
1820 | */ | ||
1821 | static void | ||
1822 | reference_delete_cont (void *cls, int32_t success, const char *emsg) | ||
1823 | { | ||
1824 | struct AttributeDeleteHandle *adh = cls; | ||
1785 | 1825 | ||
1826 | adh->ns_qe = NULL; | ||
1827 | if (GNUNET_SYSERR == success) | ||
1828 | { | ||
1829 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1830 | "Error deleting reference %s\n", | ||
1831 | adh->label); | ||
1832 | send_delete_response (adh, GNUNET_SYSERR); | ||
1833 | cleanup_adh (adh); | ||
1834 | return; | ||
1835 | } | ||
1836 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Updating tickets...\n"); | ||
1837 | GNUNET_SCHEDULER_add_now (&start_ticket_update, adh); | ||
1838 | } | ||
1839 | |||
1840 | static void | ||
1841 | ref_del_cb (void *cls, | ||
1842 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | ||
1843 | const char *label, | ||
1844 | unsigned int rd_count, | ||
1845 | const struct GNUNET_GNSRECORD_Data *rd) | ||
1846 | { | ||
1847 | |||
1848 | struct AttributeDeleteHandle *adh = cls; | ||
1849 | char *data_tmp; | ||
1850 | struct GNUNET_GNSRECORD_Data rd_new[rd_count - 1]; | ||
1851 | struct GNUNET_RECLAIM_ATTESTATION_REFERENCE *ref; | ||
1852 | size_t attr_len; | ||
1853 | |||
1854 | if (0 == rd_count ) | ||
1855 | { | ||
1856 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1857 | "Failed to find Attestation entry for Attestation reference\n"); | ||
1858 | cleanup_adh (adh); | ||
1859 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | ||
1860 | return; | ||
1861 | } | ||
1862 | if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTEST_ATTR != rd[0].record_type) | ||
1863 | { | ||
1864 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1865 | "Intended Reference location is not an attestation\n"); | ||
1866 | cleanup_adh (adh); | ||
1867 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | ||
1868 | return; | ||
1869 | } | ||
1870 | rd_new[0] = rd[0]; | ||
1871 | int i; | ||
1872 | int j = 1; | ||
1873 | for (i = 1; i<rd_count; i++) | ||
1874 | { | ||
1875 | data_tmp = GNUNET_malloc (rd[i].data_size); | ||
1876 | GNUNET_memcpy (data_tmp, rd[i].data, rd[i].data_size); | ||
1877 | attr_len = htons (rd->data_size); | ||
1878 | ref = GNUNET_RECLAIM_ATTESTATION_REF_deserialize (data_tmp, attr_len); | ||
1879 | if (NULL == ref ) | ||
1880 | { | ||
1881 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1882 | "Unable to parse attestation reference from %s\n", | ||
1883 | data_tmp); | ||
1884 | rd_new[j] = rd[i]; | ||
1885 | j += 1; | ||
1886 | continue; | ||
1887 | } | ||
1888 | if ((strcmp (adh->reference->name,ref->name) == 0)&& | ||
1889 | (strcmp (adh->reference->reference_value,ref->reference_value)==0) ) | ||
1890 | { | ||
1891 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1892 | "Found reference to delete.\n"); | ||
1893 | } | ||
1894 | else | ||
1895 | { | ||
1896 | rd_new[j] = rd[i]; | ||
1897 | j += 1; | ||
1898 | } | ||
1899 | GNUNET_free (data_tmp); | ||
1900 | } | ||
1901 | adh->ns_qe = GNUNET_NAMESTORE_records_store (nsh, | ||
1902 | &adh->identity, | ||
1903 | label, | ||
1904 | j, | ||
1905 | rd_new, | ||
1906 | &reference_delete_cont, | ||
1907 | adh); | ||
1908 | } | ||
1909 | |||
1910 | /** | ||
1911 | * Check an attestation reference delete message | ||
1912 | * | ||
1913 | * @param cls unused | ||
1914 | * @param sam the message to check | ||
1915 | */ | ||
1916 | static int | ||
1917 | check_reference_delete_message (void *cls, | ||
1918 | const struct AttributeDeleteMessage *dam) | ||
1919 | { | ||
1920 | uint16_t size; | ||
1921 | |||
1922 | size = ntohs (dam->header.size); | ||
1923 | if (size <= sizeof(struct AttributeDeleteMessage)) | ||
1924 | { | ||
1925 | GNUNET_break (0); | ||
1926 | return GNUNET_SYSERR; | ||
1927 | } | ||
1928 | return GNUNET_OK; | ||
1929 | } | ||
1930 | |||
1931 | /** | ||
1932 | * Handle reference deletion | ||
1933 | * | ||
1934 | * @param cls our client | ||
1935 | * @param dam deletion message | ||
1936 | */ | ||
1937 | static void | ||
1938 | handle_reference_delete_message (void *cls, | ||
1939 | const struct AttributeDeleteMessage *dam) | ||
1940 | { | ||
1941 | struct AttributeDeleteHandle *adh; | ||
1942 | struct IdpClient *idp = cls; | ||
1943 | size_t data_len; | ||
1944 | |||
1945 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received REFERENCE_DELETE message\n"); | ||
1946 | data_len = ntohs (dam->attr_len); | ||
1947 | adh = GNUNET_new (struct AttributeDeleteHandle); | ||
1948 | adh->reference = GNUNET_RECLAIM_ATTESTATION_REF_deserialize ((char *) &dam[1], | ||
1949 | data_len); | ||
1950 | adh->r_id = ntohl (dam->id); | ||
1951 | adh->identity = dam->identity; | ||
1952 | adh->label | ||
1953 | = GNUNET_STRINGS_data_to_string_alloc (&adh->reference->id, | ||
1954 | sizeof(uint64_t)); | ||
1955 | GNUNET_SERVICE_client_continue (idp->client); | ||
1956 | adh->client = idp; | ||
1957 | GNUNET_CONTAINER_DLL_insert (idp->delete_op_head, idp->delete_op_tail, adh); | ||
1958 | adh->ns_qe = GNUNET_NAMESTORE_records_lookup (nsh, | ||
1959 | &adh->identity, | ||
1960 | adh->label, | ||
1961 | &ref_del_error, | ||
1962 | adh, | ||
1963 | &ref_del_cb, | ||
1964 | adh); | ||
1965 | } | ||
1786 | 1966 | ||
1787 | 1967 | ||
1788 | 1968 | ||
@@ -2238,6 +2418,10 @@ GNUNET_SERVICE_MAIN ( | |||
2238 | GNUNET_MESSAGE_TYPE_RECLAIM_REFERENCE_STORE, | 2418 | GNUNET_MESSAGE_TYPE_RECLAIM_REFERENCE_STORE, |
2239 | struct AttributeStoreMessage, | 2419 | struct AttributeStoreMessage, |
2240 | NULL), | 2420 | NULL), |
2421 | GNUNET_MQ_hd_var_size (reference_delete_message, | ||
2422 | GNUNET_MESSAGE_TYPE_RECLAIM_REFERENCE_DELETE, | ||
2423 | struct AttributeDeleteMessage, | ||
2424 | NULL), | ||
2241 | GNUNET_MQ_hd_fixed_size ( | 2425 | GNUNET_MQ_hd_fixed_size ( |
2242 | iteration_start, | 2426 | iteration_start, |
2243 | GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_START, | 2427 | GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_START, |