diff options
Diffstat (limited to 'src/cli/namestore/gnunet-namestore.c')
-rw-r--r-- | src/cli/namestore/gnunet-namestore.c | 99 |
1 files changed, 37 insertions, 62 deletions
diff --git a/src/cli/namestore/gnunet-namestore.c b/src/cli/namestore/gnunet-namestore.c index 00eacfcfd..ec834cc01 100644 --- a/src/cli/namestore/gnunet-namestore.c +++ b/src/cli/namestore/gnunet-namestore.c | |||
@@ -38,7 +38,7 @@ | |||
38 | * (per record). | 38 | * (per record). |
39 | */ | 39 | */ |
40 | #define WARN_RELATIVE_EXPIRATION_LIMIT GNUNET_TIME_relative_multiply ( \ | 40 | #define WARN_RELATIVE_EXPIRATION_LIMIT GNUNET_TIME_relative_multiply ( \ |
41 | GNUNET_TIME_UNIT_MINUTES, 15) | 41 | GNUNET_TIME_UNIT_MINUTES, 15) |
42 | 42 | ||
43 | /** | 43 | /** |
44 | * Entry in record set for bulk processing. | 44 | * Entry in record set for bulk processing. |
@@ -479,6 +479,7 @@ parse_recordline (const char *line) | |||
479 | return GNUNET_OK; | 479 | return GNUNET_OK; |
480 | } | 480 | } |
481 | 481 | ||
482 | |||
482 | static void | 483 | static void |
483 | reset_handles (void) | 484 | reset_handles (void) |
484 | { | 485 | { |
@@ -588,7 +589,6 @@ reset_handles (void) | |||
588 | } | 589 | } |
589 | 590 | ||
590 | 591 | ||
591 | |||
592 | /** | 592 | /** |
593 | * Task run on shutdown. Cleans up everything. | 593 | * Task run on shutdown. Cleans up everything. |
594 | * | 594 | * |
@@ -626,18 +626,6 @@ do_shutdown (void *cls) | |||
626 | } | 626 | } |
627 | } | 627 | } |
628 | 628 | ||
629 | static void | ||
630 | commit_cb (void *cls, enum GNUNET_ErrorCode ec) | ||
631 | { | ||
632 | ns_qe = NULL; | ||
633 | if (GNUNET_EC_NONE != ec) | ||
634 | { | ||
635 | fprintf (stderr, "Failed to commit to namestore: `%s'\n", | ||
636 | GNUNET_ErrorCode_get_hint (ec)); | ||
637 | ret = 1; | ||
638 | } | ||
639 | GNUNET_SCHEDULER_shutdown (); | ||
640 | } | ||
641 | 629 | ||
642 | static void | 630 | static void |
643 | process_command_stdin (); | 631 | process_command_stdin (); |
@@ -652,7 +640,7 @@ finish_command (void) | |||
652 | process_command_stdin (); | 640 | process_command_stdin (); |
653 | return; | 641 | return; |
654 | } | 642 | } |
655 | ns_qe = GNUNET_NAMESTORE_transaction_commit (ns, &commit_cb, NULL); | 643 | GNUNET_SCHEDULER_shutdown (); |
656 | } | 644 | } |
657 | 645 | ||
658 | 646 | ||
@@ -689,6 +677,7 @@ del_continuation (void *cls, enum GNUNET_ErrorCode ec) | |||
689 | finish_command (); | 677 | finish_command (); |
690 | } | 678 | } |
691 | 679 | ||
680 | |||
692 | static void | 681 | static void |
693 | purge_next_record (void *cls); | 682 | purge_next_record (void *cls); |
694 | 683 | ||
@@ -722,16 +711,17 @@ purge_next_record (void *cls) | |||
722 | GNUNET_CONTAINER_DLL_remove (marked_head, | 711 | GNUNET_CONTAINER_DLL_remove (marked_head, |
723 | marked_tail, | 712 | marked_tail, |
724 | mrec); | 713 | mrec); |
725 | del_qe = GNUNET_NAMESTORE_records_store (ns, | 714 | del_qe = GNUNET_NAMESTORE_record_set_store (ns, |
726 | &mrec->key, | 715 | &mrec->key, |
727 | mrec->name, | 716 | mrec->name, |
728 | 0, NULL, | 717 | 0, NULL, |
729 | &marked_deleted, | 718 | &marked_deleted, |
730 | NULL); | 719 | NULL); |
731 | GNUNET_free (mrec->name); | 720 | GNUNET_free (mrec->name); |
732 | GNUNET_free (mrec); | 721 | GNUNET_free (mrec); |
733 | } | 722 | } |
734 | 723 | ||
724 | |||
735 | /** | 725 | /** |
736 | * Function called when we are done with a zone iteration. | 726 | * Function called when we are done with a zone iteration. |
737 | */ | 727 | */ |
@@ -763,6 +753,7 @@ zone_iteration_error_cb (void *cls) | |||
763 | finish_command (); | 753 | finish_command (); |
764 | } | 754 | } |
765 | 755 | ||
756 | |||
766 | static void | 757 | static void |
767 | collect_zone_records_to_purge (const struct | 758 | collect_zone_records_to_purge (const struct |
768 | GNUNET_CRYPTO_PrivateKey *zone_key, | 759 | GNUNET_CRYPTO_PrivateKey *zone_key, |
@@ -812,6 +803,7 @@ collect_orphans (const struct GNUNET_CRYPTO_PrivateKey *zone_key, | |||
812 | } | 803 | } |
813 | } | 804 | } |
814 | 805 | ||
806 | |||
815 | /** | 807 | /** |
816 | * Process a record that was stored in the namestore. | 808 | * Process a record that was stored in the namestore. |
817 | * | 809 | * |
@@ -929,6 +921,7 @@ display_record (const struct GNUNET_CRYPTO_PrivateKey *zone_key, | |||
929 | // fprintf (stdout, "%s", "\n"); | 921 | // fprintf (stdout, "%s", "\n"); |
930 | } | 922 | } |
931 | 923 | ||
924 | |||
932 | static void | 925 | static void |
933 | purge_zone_iterator (void *cls, | 926 | purge_zone_iterator (void *cls, |
934 | const struct GNUNET_CRYPTO_PrivateKey *zone_key, | 927 | const struct GNUNET_CRYPTO_PrivateKey *zone_key, |
@@ -1160,13 +1153,13 @@ get_existing_record (void *cls, | |||
1160 | else if (GNUNET_NO != etime_is_rel) | 1153 | else if (GNUNET_NO != etime_is_rel) |
1161 | rde->expiration_time = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us; | 1154 | rde->expiration_time = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us; |
1162 | GNUNET_assert (NULL != name); | 1155 | GNUNET_assert (NULL != name); |
1163 | add_qe = GNUNET_NAMESTORE_records_store (ns, | 1156 | add_qe = GNUNET_NAMESTORE_record_set_store (ns, |
1164 | &zone_pkey, | 1157 | &zone_pkey, |
1165 | name, | 1158 | name, |
1166 | rd_count + 1, | 1159 | rd_count + 1, |
1167 | rde, | 1160 | rde, |
1168 | &add_continuation, | 1161 | &add_continuation, |
1169 | &add_qe); | 1162 | &add_qe); |
1170 | } | 1163 | } |
1171 | 1164 | ||
1172 | 1165 | ||
@@ -1265,7 +1258,7 @@ del_monitor (void *cls, | |||
1265 | if ((NULL == value) && (NULL == typestring)) | 1258 | if ((NULL == value) && (NULL == typestring)) |
1266 | { | 1259 | { |
1267 | /* delete everything */ | 1260 | /* delete everything */ |
1268 | del_qe = GNUNET_NAMESTORE_records_store (ns, | 1261 | del_qe = GNUNET_NAMESTORE_record_set_store (ns, |
1269 | &zone_pkey, | 1262 | &zone_pkey, |
1270 | name, | 1263 | name, |
1271 | 0, | 1264 | 0, |
@@ -1305,7 +1298,7 @@ del_monitor (void *cls, | |||
1305 | return; | 1298 | return; |
1306 | } | 1299 | } |
1307 | /* delete everything but what we copied to 'rdx' */ | 1300 | /* delete everything but what we copied to 'rdx' */ |
1308 | del_qe = GNUNET_NAMESTORE_records_store (ns, | 1301 | del_qe = GNUNET_NAMESTORE_record_set_store (ns, |
1309 | &zone_pkey, | 1302 | &zone_pkey, |
1310 | name, | 1303 | name, |
1311 | rd_left, | 1304 | rd_left, |
@@ -1393,7 +1386,7 @@ run_with_zone_pkey (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
1393 | rd[rd_count] = e->record; | 1386 | rd[rd_count] = e->record; |
1394 | rd_count++; | 1387 | rd_count++; |
1395 | } | 1388 | } |
1396 | set_qe = GNUNET_NAMESTORE_records_store (ns, | 1389 | set_qe = GNUNET_NAMESTORE_record_set_store (ns, |
1397 | &zone_pkey, | 1390 | &zone_pkey, |
1398 | name, | 1391 | name, |
1399 | rd_count, | 1392 | rd_count, |
@@ -1637,7 +1630,7 @@ run_with_zone_pkey (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
1637 | } | 1630 | } |
1638 | if (GNUNET_OK != | 1631 | if (GNUNET_OK != |
1639 | GNUNET_CRYPTO_public_key_from_string (reverse_pkey, | 1632 | GNUNET_CRYPTO_public_key_from_string (reverse_pkey, |
1640 | &pubkey)) | 1633 | &pubkey)) |
1641 | { | 1634 | { |
1642 | fprintf (stderr, | 1635 | fprintf (stderr, |
1643 | _ ("Invalid public key for reverse lookup `%s'\n"), | 1636 | _ ("Invalid public key for reverse lookup `%s'\n"), |
@@ -1708,7 +1701,7 @@ run_with_zone_pkey (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
1708 | rd.flags |= GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; | 1701 | rd.flags |= GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; |
1709 | if (1 == is_shadow) | 1702 | if (1 == is_shadow) |
1710 | rd.flags |= GNUNET_GNSRECORD_RF_SHADOW; | 1703 | rd.flags |= GNUNET_GNSRECORD_RF_SHADOW; |
1711 | add_qe_uri = GNUNET_NAMESTORE_records_store (ns, | 1704 | add_qe_uri = GNUNET_NAMESTORE_record_set_store (ns, |
1712 | &zone_pkey, | 1705 | &zone_pkey, |
1713 | sname, | 1706 | sname, |
1714 | 1, | 1707 | 1, |
@@ -1732,6 +1725,7 @@ run_with_zone_pkey (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
1732 | } | 1725 | } |
1733 | } | 1726 | } |
1734 | 1727 | ||
1728 | |||
1735 | #define MAX_LINE_LEN 4086 | 1729 | #define MAX_LINE_LEN 4086 |
1736 | 1730 | ||
1737 | #define MAX_ARGS 20 | 1731 | #define MAX_ARGS 20 |
@@ -1746,7 +1740,7 @@ get_identity_for_string (const char *str, | |||
1746 | struct EgoEntry *ego_entry; | 1740 | struct EgoEntry *ego_entry; |
1747 | 1741 | ||
1748 | if (GNUNET_OK == GNUNET_CRYPTO_public_key_from_string (str, | 1742 | if (GNUNET_OK == GNUNET_CRYPTO_public_key_from_string (str, |
1749 | &pubkey)) | 1743 | &pubkey)) |
1750 | { | 1744 | { |
1751 | for (ego_entry = ego_head; | 1745 | for (ego_entry = ego_head; |
1752 | NULL != ego_entry; ego_entry = ego_entry->next) | 1746 | NULL != ego_entry; ego_entry = ego_entry->next) |
@@ -1774,6 +1768,7 @@ get_identity_for_string (const char *str, | |||
1774 | return GNUNET_NO; | 1768 | return GNUNET_NO; |
1775 | } | 1769 | } |
1776 | 1770 | ||
1771 | |||
1777 | static void | 1772 | static void |
1778 | process_command_stdin () | 1773 | process_command_stdin () |
1779 | { | 1774 | { |
@@ -1811,7 +1806,7 @@ process_command_stdin () | |||
1811 | if (NULL == tmp) | 1806 | if (NULL == tmp) |
1812 | { | 1807 | { |
1813 | fprintf (stderr, "Error parsing name `%s'\n", next_name); | 1808 | fprintf (stderr, "Error parsing name `%s'\n", next_name); |
1814 | ns_qe = GNUNET_NAMESTORE_transaction_commit (ns, &commit_cb, NULL); | 1809 | GNUNET_SCHEDULER_shutdown(); |
1815 | ret = 1; | 1810 | ret = 1; |
1816 | return; | 1811 | return; |
1817 | } | 1812 | } |
@@ -1857,32 +1852,11 @@ process_command_stdin () | |||
1857 | fprintf (stderr, "Warning, encountered recordline without zone\n"); | 1852 | fprintf (stderr, "Warning, encountered recordline without zone\n"); |
1858 | } | 1853 | } |
1859 | } | 1854 | } |
1860 | ns_qe = GNUNET_NAMESTORE_transaction_commit (ns, &commit_cb, NULL); | 1855 | GNUNET_SCHEDULER_shutdown(); |
1861 | return; | 1856 | return; |
1862 | } | 1857 | } |
1863 | 1858 | ||
1864 | 1859 | ||
1865 | static void | ||
1866 | begin_cb (void *cls, enum GNUNET_ErrorCode ec) | ||
1867 | { | ||
1868 | ns_qe = NULL; | ||
1869 | if (GNUNET_EC_NONE != ec) | ||
1870 | { | ||
1871 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1872 | "Failed to start transaction: %s\n", | ||
1873 | GNUNET_ErrorCode_get_hint (ec)); | ||
1874 | GNUNET_SCHEDULER_shutdown (); | ||
1875 | return; | ||
1876 | } | ||
1877 | if (read_from_stdin) | ||
1878 | { | ||
1879 | process_command_stdin (); | ||
1880 | return; | ||
1881 | } | ||
1882 | run_with_zone_pkey (cfg); | ||
1883 | } | ||
1884 | |||
1885 | |||
1886 | /** | 1860 | /** |
1887 | * Function called with ALL of the egos known to the | 1861 | * Function called with ALL of the egos known to the |
1888 | * identity service, used on startup if the user did | 1862 | * identity service, used on startup if the user did |
@@ -1922,13 +1896,15 @@ id_connect_cb (void *cls, | |||
1922 | } | 1896 | } |
1923 | if (NULL != ego) | 1897 | if (NULL != ego) |
1924 | return; | 1898 | return; |
1925 | ns_qe = GNUNET_NAMESTORE_transaction_begin (ns, &begin_cb, (void *) cfg); | 1899 | if (read_from_stdin) |
1900 | { | ||
1901 | process_command_stdin (); | ||
1902 | return; | ||
1903 | } | ||
1904 | run_with_zone_pkey (cfg); | ||
1926 | } | 1905 | } |
1927 | 1906 | ||
1928 | 1907 | ||
1929 | |||
1930 | |||
1931 | |||
1932 | /** | 1908 | /** |
1933 | * Main function that will be run. | 1909 | * Main function that will be run. |
1934 | * | 1910 | * |
@@ -1971,7 +1947,6 @@ run (void *cls, | |||
1971 | } | 1947 | } |
1972 | 1948 | ||
1973 | 1949 | ||
1974 | |||
1975 | /** | 1950 | /** |
1976 | * The main function for gnunet-namestore. | 1951 | * The main function for gnunet-namestore. |
1977 | * | 1952 | * |