diff options
author | Martin Schanzenbach <mschanzenbach@posteo.de> | 2012-03-12 14:35:51 +0000 |
---|---|---|
committer | Martin Schanzenbach <mschanzenbach@posteo.de> | 2012-03-12 14:35:51 +0000 |
commit | 1f4e1aa8a84a7cb09b1313cf0eca4351a476f665 (patch) | |
tree | 493eb2ec49f498c53933804305906b1f26f80465 /src | |
parent | 00eda546242086cee3dc920e2f82a7b5be3e0999 (diff) | |
download | gnunet-1f4e1aa8a84a7cb09b1313cf0eca4351a476f665.tar.gz gnunet-1f4e1aa8a84a7cb09b1313cf0eca4351a476f665.zip |
-bugfixes, debug, new test
Diffstat (limited to 'src')
-rw-r--r-- | src/gns/Makefile.am | 16 | ||||
-rw-r--r-- | src/gns/gnunet-service-gns.c | 128 | ||||
-rw-r--r-- | src/gns/test_gns_dht_delegated_lookup.c | 2 | ||||
-rw-r--r-- | src/gns/test_gns_dht_shorten.c | 500 | ||||
-rw-r--r-- | src/gns/test_gns_simple_shorten.c | 4 |
5 files changed, 641 insertions, 9 deletions
diff --git a/src/gns/Makefile.am b/src/gns/Makefile.am index 08da0a8e2..866df1d88 100644 --- a/src/gns/Makefile.am +++ b/src/gns/Makefile.am | |||
@@ -28,6 +28,7 @@ bin_PROGRAMS = \ | |||
28 | 28 | ||
29 | check_PROGRAMS = \ | 29 | check_PROGRAMS = \ |
30 | test_gns_simple_shorten \ | 30 | test_gns_simple_shorten \ |
31 | test_gns_dht_shorten \ | ||
31 | test_gns_simple_get_authority \ | 32 | test_gns_simple_get_authority \ |
32 | test_gns_simple_lookup \ | 33 | test_gns_simple_lookup \ |
33 | test_gns_simple_delegated_lookup \ | 34 | test_gns_simple_delegated_lookup \ |
@@ -107,6 +108,21 @@ test_gns_simple_shorten_DEPENDENCIES = \ | |||
107 | $(top_builddir)/src/gns/libgnunetgns.la \ | 108 | $(top_builddir)/src/gns/libgnunetgns.la \ |
108 | $(top_builddir)/src/testing/libgnunettesting.la | 109 | $(top_builddir)/src/testing/libgnunettesting.la |
109 | 110 | ||
111 | test_gns_dht_shorten_SOURCES = \ | ||
112 | test_gns_dht_shorten.c | ||
113 | test_gns_dht_shorten_LDADD = \ | ||
114 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
115 | $(top_builddir)/src/namestore/libgnunetnamestore.la \ | ||
116 | $(top_builddir)/src/gns/libgnunetgns.la \ | ||
117 | $(top_builddir)/src/dht/libgnunetdht.la \ | ||
118 | $(top_builddir)/src/testing/libgnunettesting.la | ||
119 | test_gns_dht_shorten_DEPENDENCIES = \ | ||
120 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
121 | $(top_builddir)/src/namestore/libgnunetnamestore.la \ | ||
122 | $(top_builddir)/src/gns/libgnunetgns.la \ | ||
123 | $(top_builddir)/src/dht/libgnunetdht.la \ | ||
124 | $(top_builddir)/src/testing/libgnunettesting.la | ||
125 | |||
110 | test_gns_simple_get_authority_SOURCES = \ | 126 | test_gns_simple_get_authority_SOURCES = \ |
111 | test_gns_simple_get_authority.c | 127 | test_gns_simple_get_authority.c |
112 | test_gns_simple_get_authority_LDADD = \ | 128 | test_gns_simple_get_authority_LDADD = \ |
diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c index 480d6bea9..ea9afcb4c 100644 --- a/src/gns/gnunet-service-gns.c +++ b/src/gns/gnunet-service-gns.c | |||
@@ -1761,6 +1761,123 @@ process_shorten_pseu_lookup_ns(void *cls, | |||
1761 | 1761 | ||
1762 | 1762 | ||
1763 | /** | 1763 | /** |
1764 | * Function called when we get a result from the dht | ||
1765 | * for our record query | ||
1766 | * | ||
1767 | * @param cls the request handle | ||
1768 | * @param exp lifetime | ||
1769 | * @param key the key the record was stored under | ||
1770 | * @param get_path get path | ||
1771 | * @param get_path_length get path length | ||
1772 | * @param put_path put path | ||
1773 | * @param put_path_length put path length | ||
1774 | * @param type the block type | ||
1775 | * @param size the size of the record | ||
1776 | * @param data the record data | ||
1777 | */ | ||
1778 | static void | ||
1779 | process_pseu_dht_result(void* cls, | ||
1780 | struct GNUNET_TIME_Absolute exp, | ||
1781 | const GNUNET_HashCode * key, | ||
1782 | const struct GNUNET_PeerIdentity *get_path, | ||
1783 | unsigned int get_path_length, | ||
1784 | const struct GNUNET_PeerIdentity *put_path, | ||
1785 | unsigned int put_path_length, | ||
1786 | enum GNUNET_BLOCK_Type type, | ||
1787 | size_t size, const void *data) | ||
1788 | { | ||
1789 | struct GNUNET_GNS_ResolverHandle *rh; | ||
1790 | struct RecordLookupHandle *rlh; | ||
1791 | struct GNSNameRecordBlock *nrb; | ||
1792 | uint32_t num_records; | ||
1793 | char* name = NULL; | ||
1794 | char* rd_data = (char*)data; | ||
1795 | int i; | ||
1796 | int rd_size; | ||
1797 | |||
1798 | GNUNET_HashCode zone, name_hash; | ||
1799 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "got PSEU dht result (size=%d)\n", size); | ||
1800 | |||
1801 | if (data == NULL) | ||
1802 | return; | ||
1803 | |||
1804 | //FIXME maybe check expiration here, check block type | ||
1805 | |||
1806 | rh = (struct GNUNET_GNS_ResolverHandle *)cls; | ||
1807 | rlh = (struct RecordLookupHandle *) rh->proc_cls; | ||
1808 | nrb = (struct GNSNameRecordBlock*)data; | ||
1809 | |||
1810 | /* stop lookup and timeout task */ | ||
1811 | GNUNET_DHT_get_stop (rh->get_handle); | ||
1812 | GNUNET_SCHEDULER_cancel(rh->dht_timeout_task); | ||
1813 | |||
1814 | rh->get_handle = NULL; | ||
1815 | name = (char*)&nrb[1]; | ||
1816 | num_records = ntohl(nrb->rd_count); | ||
1817 | { | ||
1818 | struct GNUNET_NAMESTORE_RecordData rd[num_records]; | ||
1819 | |||
1820 | rd_data += strlen(name) + 1 + sizeof(struct GNSNameRecordBlock); | ||
1821 | rd_size = size - strlen(name) - 1 - sizeof(struct GNSNameRecordBlock); | ||
1822 | |||
1823 | if (GNUNET_SYSERR == GNUNET_NAMESTORE_records_deserialize (rd_size, | ||
1824 | rd_data, | ||
1825 | num_records, | ||
1826 | rd)) | ||
1827 | { | ||
1828 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Error deserializing data!\n"); | ||
1829 | return; | ||
1830 | } | ||
1831 | |||
1832 | for (i=0; i<num_records; i++) | ||
1833 | { | ||
1834 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
1835 | "Got name: %s (wanted %s)\n", name, rh->name); | ||
1836 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
1837 | "Got type: %d\n", | ||
1838 | rd[i].record_type); | ||
1839 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
1840 | "Got data length: %d\n", rd[i].data_size); | ||
1841 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
1842 | "Got flag %d\n", rd[i].flags); | ||
1843 | |||
1844 | if ((strcmp(name, "+") == 0) && | ||
1845 | (rd[i].record_type == GNUNET_GNS_RECORD_PSEU)) | ||
1846 | { | ||
1847 | rh->answered++; | ||
1848 | } | ||
1849 | |||
1850 | } | ||
1851 | |||
1852 | GNUNET_CRYPTO_hash(name, strlen(name), &name_hash); | ||
1853 | GNUNET_CRYPTO_hash_xor(key, &name_hash, &zone); | ||
1854 | |||
1855 | /** | ||
1856 | * FIXME check pubkey against existing key in namestore? | ||
1857 | * https://gnunet.org/bugs/view.php?id=2179 | ||
1858 | */ | ||
1859 | |||
1860 | /* Save to namestore */ | ||
1861 | GNUNET_NAMESTORE_record_put (namestore_handle, | ||
1862 | &nrb->public_key, | ||
1863 | name, | ||
1864 | exp, | ||
1865 | num_records, | ||
1866 | rd, | ||
1867 | &nrb->signature, | ||
1868 | &on_namestore_record_put_result, //cont | ||
1869 | NULL); //cls | ||
1870 | |||
1871 | if (rh->answered) | ||
1872 | rh->proc(rh->proc_cls, rh, num_records, rd); | ||
1873 | else | ||
1874 | rh->proc(rh->proc_cls, rh, 0, NULL); | ||
1875 | } | ||
1876 | |||
1877 | } | ||
1878 | |||
1879 | |||
1880 | /** | ||
1764 | * Start DHT lookup for a PSEUdonym record in | 1881 | * Start DHT lookup for a PSEUdonym record in |
1765 | * rh->authority's zone | 1882 | * rh->authority's zone |
1766 | * | 1883 | * |
@@ -1773,9 +1890,8 @@ resolve_pseu_dht(struct GNUNET_GNS_ResolverHandle *rh) | |||
1773 | GNUNET_HashCode name_hash; | 1890 | GNUNET_HashCode name_hash; |
1774 | GNUNET_HashCode lookup_key; | 1891 | GNUNET_HashCode lookup_key; |
1775 | 1892 | ||
1776 | //Empty string | 1893 | GNUNET_CRYPTO_hash("+", |
1777 | GNUNET_CRYPTO_hash("", | 1894 | strlen("+"), |
1778 | 1, | ||
1779 | &name_hash); | 1895 | &name_hash); |
1780 | 1896 | ||
1781 | GNUNET_CRYPTO_hash_xor(&name_hash, &rh->authority, &lookup_key); | 1897 | GNUNET_CRYPTO_hash_xor(&name_hash, &rh->authority, &lookup_key); |
@@ -1794,7 +1910,7 @@ resolve_pseu_dht(struct GNUNET_GNS_ResolverHandle *rh) | |||
1794 | GNUNET_DHT_RO_NONE, | 1910 | GNUNET_DHT_RO_NONE, |
1795 | &xquery, | 1911 | &xquery, |
1796 | sizeof(xquery), | 1912 | sizeof(xquery), |
1797 | &process_delegation_result_dht, | 1913 | &process_pseu_dht_result, |
1798 | rh); | 1914 | rh); |
1799 | 1915 | ||
1800 | } | 1916 | } |
@@ -1849,7 +1965,7 @@ handle_shorten_zone_to_name(void *cls, | |||
1849 | rh->proc = &handle_shorten_pseu_ns_result; | 1965 | rh->proc = &handle_shorten_pseu_ns_result; |
1850 | GNUNET_NAMESTORE_lookup_record(namestore_handle, | 1966 | GNUNET_NAMESTORE_lookup_record(namestore_handle, |
1851 | &rh->authority_chain_head->zone, | 1967 | &rh->authority_chain_head->zone, |
1852 | "", | 1968 | "+", |
1853 | GNUNET_GNS_RECORD_PSEU, | 1969 | GNUNET_GNS_RECORD_PSEU, |
1854 | &process_shorten_pseu_lookup_ns, | 1970 | &process_shorten_pseu_lookup_ns, |
1855 | rh); | 1971 | rh); |
@@ -1901,7 +2017,7 @@ handle_shorten_pseu_dht_result(void* cls, | |||
1901 | strcpy(result, rh->name); | 2017 | strcpy(result, rh->name); |
1902 | strcpy(result+strlen(rh->name), "."); | 2018 | strcpy(result+strlen(rh->name), "."); |
1903 | strcpy(result+strlen(rh->name)+1, pseu); | 2019 | strcpy(result+strlen(rh->name)+1, pseu); |
1904 | strcpy(result+strlen(rh->name)+strlen(pseu), gnunet_tld); | 2020 | strcpy(result+strlen(rh->name)+strlen(pseu)+1, gnunet_tld); |
1905 | 2021 | ||
1906 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 2022 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1907 | "Sending pseudonym shorten result %s\n", result); | 2023 | "Sending pseudonym shorten result %s\n", result); |
diff --git a/src/gns/test_gns_dht_delegated_lookup.c b/src/gns/test_gns_dht_delegated_lookup.c index 6fc4a42bb..1fa87c905 100644 --- a/src/gns/test_gns_dht_delegated_lookup.c +++ b/src/gns/test_gns_dht_delegated_lookup.c | |||
@@ -63,7 +63,7 @@ | |||
63 | 63 | ||
64 | #define TEST_AUTHORITY_NAME "bob" | 64 | #define TEST_AUTHORITY_NAME "bob" |
65 | 65 | ||
66 | #define DHT_OPERATION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) | 66 | #define DHT_OPERATION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1) |
67 | 67 | ||
68 | /* Globals */ | 68 | /* Globals */ |
69 | 69 | ||
diff --git a/src/gns/test_gns_dht_shorten.c b/src/gns/test_gns_dht_shorten.c new file mode 100644 index 000000000..32d978290 --- /dev/null +++ b/src/gns/test_gns_dht_shorten.c | |||
@@ -0,0 +1,500 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2009 Christian Grothoff (and other contributing authors) | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | /** | ||
21 | * @file gns/test_gns_twopeer.c | ||
22 | * @brief base testcase for testing DHT service with | ||
23 | * two running peers. | ||
24 | * | ||
25 | * This testcase starts peers using the GNUNET_TESTING_daemons_start | ||
26 | * function call. On peer start, connects to the peers DHT service | ||
27 | * by calling GNUNET_DHT_connected. Once notified about all peers | ||
28 | * being started (by the peers_started_callback function), calls | ||
29 | * GNUNET_TESTING_connect_topology, which connects the peers in a | ||
30 | * "straight line" topology. On notification that all peers have | ||
31 | * been properly connected, calls the do_get function which initiates | ||
32 | * a GNUNET_DHT_get from the *second* peer. Once the GNUNET_DHT_get | ||
33 | * function starts, runs the do_put function to insert data at the first peer. | ||
34 | * If the GET is successful, schedules finish_testing | ||
35 | * to stop the test and shut down peers. If GET is unsuccessful | ||
36 | * after GET_TIMEOUT seconds, prints an error message and shuts down | ||
37 | * the peers. | ||
38 | */ | ||
39 | #include "platform.h" | ||
40 | #include "gnunet_testing_lib.h" | ||
41 | #include "gnunet_core_service.h" | ||
42 | #include "block_gns.h" | ||
43 | #include "gnunet_signatures.h" | ||
44 | #include "gnunet_namestore_service.h" | ||
45 | #include "../namestore/namestore.h" | ||
46 | #include "gnunet_dnsparser_lib.h" | ||
47 | #include "gnunet_dht_service.h" | ||
48 | #include "gnunet_gns_service.h" | ||
49 | |||
50 | /* DEFINES */ | ||
51 | #define VERBOSE GNUNET_YES | ||
52 | |||
53 | /* Timeout for entire testcase */ | ||
54 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10) | ||
55 | |||
56 | /* If number of peers not in config file, use this number */ | ||
57 | #define DEFAULT_NUM_PEERS 2 | ||
58 | |||
59 | /* test records to resolve */ | ||
60 | #define TEST_DOMAIN "www.alice.bob.gnunet" | ||
61 | #define TEST_IP "127.0.0.1" | ||
62 | #define TEST_RECORD_NAME "www" | ||
63 | |||
64 | #define TEST_AUTHORITY_NAME "bob" | ||
65 | #define TEST_AUTHORITY_ALICE "alice" | ||
66 | #define TEST_ALICE_PSEU "carol" | ||
67 | #define TEST_EXPECTED_RESULT "www.carol.gnunet" | ||
68 | |||
69 | #define DHT_OPERATION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1) | ||
70 | |||
71 | /* Globals */ | ||
72 | |||
73 | /** | ||
74 | * Directory to store temp data in, defined in config file | ||
75 | */ | ||
76 | static char *test_directory; | ||
77 | |||
78 | struct GNUNET_TESTING_Daemon *d1; | ||
79 | |||
80 | |||
81 | /* Task handle to use to schedule test failure */ | ||
82 | GNUNET_SCHEDULER_TaskIdentifier die_task; | ||
83 | |||
84 | /* Global return value (0 for success, anything else for failure) */ | ||
85 | static int ok; | ||
86 | |||
87 | static struct GNUNET_NAMESTORE_Handle *namestore_handle; | ||
88 | |||
89 | static struct GNUNET_GNS_Handle *gns_handle; | ||
90 | |||
91 | static struct GNUNET_DHT_Handle *dht_handle; | ||
92 | |||
93 | const struct GNUNET_CONFIGURATION_Handle *cfg; | ||
94 | |||
95 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded alice_pkey; | ||
96 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded bob_pkey; | ||
97 | struct GNUNET_CRYPTO_RsaPrivateKey *alice_key; | ||
98 | struct GNUNET_CRYPTO_RsaPrivateKey *bob_key; | ||
99 | |||
100 | /** | ||
101 | * Check whether peers successfully shut down. | ||
102 | */ | ||
103 | void | ||
104 | shutdown_callback (void *cls, const char *emsg) | ||
105 | { | ||
106 | if (emsg != NULL) | ||
107 | { | ||
108 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error on shutdown! ret=%d\n", ok); | ||
109 | if (ok == 0) | ||
110 | ok = 2; | ||
111 | } | ||
112 | |||
113 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "done(ret=%d)!\n", ok); | ||
114 | } | ||
115 | |||
116 | |||
117 | /** | ||
118 | * Called when gns shorten finishes | ||
119 | */ | ||
120 | static void | ||
121 | process_shorten_result(void* cls, const char* sname) | ||
122 | { | ||
123 | GNUNET_GNS_disconnect(gns_handle); | ||
124 | |||
125 | ok = 0; | ||
126 | |||
127 | if (sname == NULL) | ||
128 | { | ||
129 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
130 | "shorten test failed!\n"); | ||
131 | ok = 1; | ||
132 | } | ||
133 | else | ||
134 | { | ||
135 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
136 | "%s shortened to %s\n", (char*)cls, sname); | ||
137 | if (0 != strcmp(sname, TEST_EXPECTED_RESULT)) | ||
138 | { | ||
139 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
140 | "shorten test failed! (wanted: %s got: %s\n", | ||
141 | (char*)cls, sname); | ||
142 | ok = 1; | ||
143 | } | ||
144 | |||
145 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "shorten test succeeded!\n"); | ||
146 | |||
147 | } | ||
148 | |||
149 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Shutting down peer1!\n"); | ||
150 | GNUNET_TESTING_daemon_stop (d1, TIMEOUT, &shutdown_callback, NULL, | ||
151 | GNUNET_YES, GNUNET_NO); | ||
152 | } | ||
153 | |||
154 | /** | ||
155 | * Function scheduled to be run on the successful start of services | ||
156 | * tries to look up the dns record for TEST_DOMAIN | ||
157 | */ | ||
158 | static void | ||
159 | commence_testing (void* cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
160 | { | ||
161 | GNUNET_NAMESTORE_disconnect(namestore_handle, GNUNET_YES); | ||
162 | |||
163 | gns_handle = GNUNET_GNS_connect(cfg); | ||
164 | |||
165 | if (NULL == gns_handle) | ||
166 | { | ||
167 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
168 | "Failed to connect to GNS!\n"); | ||
169 | ok = 1; | ||
170 | } | ||
171 | |||
172 | GNUNET_GNS_shorten(gns_handle, TEST_DOMAIN, &process_shorten_result, | ||
173 | TEST_DOMAIN); | ||
174 | } | ||
175 | |||
176 | /** | ||
177 | * Continuation for the GNUNET_DHT_get_stop call, so that we don't shut | ||
178 | * down the peers without freeing memory associated with GET request. | ||
179 | */ | ||
180 | static void | ||
181 | end_badly_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
182 | { | ||
183 | |||
184 | if (d1 != NULL) | ||
185 | GNUNET_TESTING_daemon_stop (d1, TIMEOUT, &shutdown_callback, NULL, | ||
186 | GNUNET_YES, GNUNET_NO); | ||
187 | GNUNET_SCHEDULER_cancel (die_task); | ||
188 | } | ||
189 | |||
190 | /** | ||
191 | * Check if the get_handle is being used, if so stop the request. Either | ||
192 | * way, schedule the end_badly_cont function which actually shuts down the | ||
193 | * test. | ||
194 | */ | ||
195 | static void | ||
196 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
197 | { | ||
198 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failing test with error: `%s'!\n", | ||
199 | (char *) cls); | ||
200 | GNUNET_SCHEDULER_add_now (&end_badly_cont, NULL); | ||
201 | ok = 1; | ||
202 | } | ||
203 | |||
204 | |||
205 | static void | ||
206 | put_www_dht(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
207 | { | ||
208 | struct GNSNameRecordBlock *nrb; | ||
209 | GNUNET_HashCode name_hash; | ||
210 | GNUNET_HashCode xor_hash; | ||
211 | GNUNET_HashCode zone_hash; | ||
212 | uint32_t rd_payload_length; | ||
213 | char* nrb_data = NULL; | ||
214 | struct GNUNET_CRYPTO_RsaSignature *sig; | ||
215 | struct GNUNET_NAMESTORE_RecordData rd; | ||
216 | char* ip = TEST_IP; | ||
217 | struct in_addr *web = GNUNET_malloc(sizeof(struct in_addr)); | ||
218 | |||
219 | rd.expiration = GNUNET_TIME_absolute_get_forever (); | ||
220 | GNUNET_assert(1 == inet_pton (AF_INET, ip, web)); | ||
221 | rd.data_size = sizeof(struct in_addr); | ||
222 | rd.data = web; | ||
223 | rd.record_type = GNUNET_DNSPARSER_TYPE_A; | ||
224 | |||
225 | sig = GNUNET_NAMESTORE_create_signature(alice_key, | ||
226 | GNUNET_TIME_absolute_get_forever(), | ||
227 | TEST_RECORD_NAME, | ||
228 | &rd, 1); | ||
229 | rd_payload_length = GNUNET_NAMESTORE_records_get_size (1, &rd); | ||
230 | nrb = GNUNET_malloc(rd_payload_length + strlen(TEST_RECORD_NAME) + 1 | ||
231 | + sizeof(struct GNSNameRecordBlock)); | ||
232 | nrb->signature = *sig; | ||
233 | nrb->public_key = alice_pkey; | ||
234 | nrb->rd_count = htonl(1); | ||
235 | memset(&nrb[1], 0, strlen(TEST_RECORD_NAME) + 1); | ||
236 | memcpy(&nrb[1], TEST_RECORD_NAME, strlen(TEST_RECORD_NAME)); | ||
237 | nrb_data = (char*)&nrb[1]; | ||
238 | nrb_data += strlen(TEST_RECORD_NAME) + 1; | ||
239 | |||
240 | if (-1 == GNUNET_NAMESTORE_records_serialize (1, | ||
241 | &rd, | ||
242 | rd_payload_length, | ||
243 | nrb_data)) | ||
244 | { | ||
245 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Record serialization failed!\n"); | ||
246 | ok = 3; | ||
247 | GNUNET_free (nrb); | ||
248 | return; | ||
249 | } | ||
250 | GNUNET_CRYPTO_hash(TEST_RECORD_NAME, strlen(TEST_RECORD_NAME), &name_hash); | ||
251 | GNUNET_CRYPTO_hash(&alice_pkey, | ||
252 | sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), | ||
253 | &zone_hash); | ||
254 | GNUNET_CRYPTO_hash_xor(&zone_hash, &name_hash, &xor_hash); | ||
255 | |||
256 | rd_payload_length += sizeof(struct GNSNameRecordBlock) + | ||
257 | strlen(TEST_RECORD_NAME) + 1; | ||
258 | GNUNET_DHT_put (dht_handle, &xor_hash, | ||
259 | 0, | ||
260 | GNUNET_DHT_RO_NONE, | ||
261 | GNUNET_BLOCK_TYPE_GNS_NAMERECORD, | ||
262 | rd_payload_length, | ||
263 | (char*)nrb, | ||
264 | rd.expiration, | ||
265 | DHT_OPERATION_TIMEOUT, | ||
266 | NULL, | ||
267 | NULL); | ||
268 | GNUNET_free (nrb); | ||
269 | GNUNET_SCHEDULER_add_delayed(TIMEOUT, &commence_testing, NULL); | ||
270 | } | ||
271 | |||
272 | |||
273 | static void | ||
274 | put_alice_pseu_dht(void *cls, int32_t success, const char *emsg) | ||
275 | { | ||
276 | struct GNSNameRecordBlock *nrb; | ||
277 | GNUNET_HashCode name_hash; | ||
278 | GNUNET_HashCode xor_hash; | ||
279 | GNUNET_HashCode zone_hash; | ||
280 | uint32_t rd_payload_length; | ||
281 | char* nrb_data = NULL; | ||
282 | struct GNUNET_CRYPTO_RsaSignature *sig; | ||
283 | struct GNUNET_NAMESTORE_RecordData rd; | ||
284 | |||
285 | rd.expiration = GNUNET_TIME_absolute_get_forever (); | ||
286 | rd.data_size = strlen(TEST_ALICE_PSEU); | ||
287 | rd.data = TEST_ALICE_PSEU; | ||
288 | rd.record_type = GNUNET_GNS_RECORD_PSEU; | ||
289 | |||
290 | sig = GNUNET_NAMESTORE_create_signature(alice_key, | ||
291 | GNUNET_TIME_absolute_get_forever(), | ||
292 | "+", //empty name for pseu | ||
293 | &rd, 1); | ||
294 | rd_payload_length = GNUNET_NAMESTORE_records_get_size (1, &rd); | ||
295 | nrb = GNUNET_malloc(rd_payload_length + strlen("") + 1 | ||
296 | + sizeof(struct GNSNameRecordBlock)); | ||
297 | nrb->signature = *sig; | ||
298 | nrb->public_key = alice_pkey; | ||
299 | nrb->rd_count = htonl(1); | ||
300 | memset(&nrb[1], 0, strlen("+") + 1); | ||
301 | memcpy(&nrb[1], "+", strlen("+")); | ||
302 | nrb_data = (char*)&nrb[1]; | ||
303 | nrb_data += strlen("+") + 1; | ||
304 | |||
305 | if (-1 == GNUNET_NAMESTORE_records_serialize (1, | ||
306 | &rd, | ||
307 | rd_payload_length, | ||
308 | nrb_data)) | ||
309 | { | ||
310 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Record serialization failed!\n"); | ||
311 | ok = 3; | ||
312 | GNUNET_free (nrb); | ||
313 | return; | ||
314 | } | ||
315 | GNUNET_CRYPTO_hash("+", strlen("+"), &name_hash); | ||
316 | GNUNET_CRYPTO_hash(&alice_pkey, | ||
317 | sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), | ||
318 | &zone_hash); | ||
319 | GNUNET_CRYPTO_hash_xor(&zone_hash, &name_hash, &xor_hash); | ||
320 | |||
321 | rd_payload_length += sizeof(struct GNSNameRecordBlock) + | ||
322 | strlen("+") + 1; | ||
323 | GNUNET_DHT_put (dht_handle, &xor_hash, | ||
324 | 0, | ||
325 | GNUNET_DHT_RO_NONE, | ||
326 | GNUNET_BLOCK_TYPE_GNS_NAMERECORD, | ||
327 | rd_payload_length, | ||
328 | (char*)nrb, | ||
329 | rd.expiration, | ||
330 | DHT_OPERATION_TIMEOUT, | ||
331 | NULL, | ||
332 | NULL); | ||
333 | GNUNET_free (nrb); | ||
334 | GNUNET_SCHEDULER_add_delayed(TIMEOUT, &put_www_dht, NULL); | ||
335 | } | ||
336 | |||
337 | static void | ||
338 | do_shorten(void *cls, const struct GNUNET_PeerIdentity *id, | ||
339 | const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
340 | struct GNUNET_TESTING_Daemon *d, const char *emsg) | ||
341 | { | ||
342 | |||
343 | char* my_keyfile; | ||
344 | struct GNUNET_CRYPTO_RsaPrivateKey *my_key; | ||
345 | GNUNET_HashCode bob_hash; | ||
346 | GNUNET_HashCode alice_hash; | ||
347 | struct GNUNET_CRYPTO_RsaSignature *sig; | ||
348 | |||
349 | |||
350 | GNUNET_SCHEDULER_cancel (die_task); | ||
351 | |||
352 | /* put records into namestore */ | ||
353 | namestore_handle = GNUNET_NAMESTORE_connect(cfg); | ||
354 | if (NULL == namestore_handle) | ||
355 | { | ||
356 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to connect to namestore\n"); | ||
357 | ok = -1; | ||
358 | return; | ||
359 | } | ||
360 | |||
361 | /* dht */ | ||
362 | dht_handle = GNUNET_DHT_connect(cfg, 1); | ||
363 | if (NULL == dht_handle) | ||
364 | { | ||
365 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to connect to dht\n"); | ||
366 | ok = -1; | ||
367 | return; | ||
368 | } | ||
369 | |||
370 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, "gns", | ||
371 | "ZONEKEY", | ||
372 | &my_keyfile)) | ||
373 | { | ||
374 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to get key from cfg\n"); | ||
375 | ok = -1; | ||
376 | return; | ||
377 | } | ||
378 | |||
379 | my_key = GNUNET_CRYPTO_rsa_key_create_from_file (my_keyfile); | ||
380 | alice_key = GNUNET_CRYPTO_rsa_key_create (); | ||
381 | bob_key = GNUNET_CRYPTO_rsa_key_create (); | ||
382 | |||
383 | GNUNET_CRYPTO_rsa_key_get_public (alice_key, &alice_pkey); | ||
384 | GNUNET_CRYPTO_rsa_key_get_public (bob_key, &bob_pkey); | ||
385 | GNUNET_CRYPTO_hash(&bob_pkey, sizeof(bob_pkey), &bob_hash); | ||
386 | GNUNET_CRYPTO_hash(&alice_pkey, sizeof(alice_pkey), &alice_hash); | ||
387 | |||
388 | struct GNUNET_NAMESTORE_RecordData rd; | ||
389 | rd.expiration = GNUNET_TIME_absolute_get_forever (); | ||
390 | rd.data_size = sizeof(GNUNET_HashCode); | ||
391 | rd.data = &bob_hash; | ||
392 | rd.record_type = GNUNET_GNS_RECORD_PKEY; | ||
393 | |||
394 | GNUNET_NAMESTORE_record_create (namestore_handle, | ||
395 | my_key, | ||
396 | TEST_AUTHORITY_NAME, | ||
397 | &rd, | ||
398 | NULL, | ||
399 | NULL); | ||
400 | |||
401 | rd.data = &alice_hash; | ||
402 | |||
403 | sig = GNUNET_NAMESTORE_create_signature(bob_key, | ||
404 | GNUNET_TIME_absolute_get_forever(), | ||
405 | TEST_AUTHORITY_ALICE, | ||
406 | &rd, | ||
407 | 1); | ||
408 | |||
409 | GNUNET_NAMESTORE_record_put (namestore_handle, | ||
410 | &bob_pkey, | ||
411 | TEST_AUTHORITY_ALICE, | ||
412 | GNUNET_TIME_absolute_get_forever(), | ||
413 | 1, | ||
414 | &rd, | ||
415 | sig, | ||
416 | &put_alice_pseu_dht, | ||
417 | NULL); | ||
418 | |||
419 | |||
420 | |||
421 | |||
422 | |||
423 | } | ||
424 | |||
425 | static void | ||
426 | run (void *cls, char *const *args, const char *cfgfile, | ||
427 | const struct GNUNET_CONFIGURATION_Handle *c) | ||
428 | { | ||
429 | cfg = c; | ||
430 | /* Get path from configuration file */ | ||
431 | if (GNUNET_YES != | ||
432 | GNUNET_CONFIGURATION_get_value_string (cfg, "paths", "servicehome", | ||
433 | &test_directory)) | ||
434 | { | ||
435 | ok = 404; | ||
436 | return; | ||
437 | } | ||
438 | |||
439 | |||
440 | /* Set up a task to end testing if peer start fails */ | ||
441 | die_task = | ||
442 | GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, | ||
443 | "didn't start all daemons in reasonable amount of time!!!"); | ||
444 | |||
445 | /* Start alice */ | ||
446 | d1 = GNUNET_TESTING_daemon_start(cfg, TIMEOUT, GNUNET_NO, NULL, NULL, 0, | ||
447 | NULL, NULL, NULL, &do_shorten, NULL); | ||
448 | } | ||
449 | |||
450 | static int | ||
451 | check () | ||
452 | { | ||
453 | int ret; | ||
454 | |||
455 | /* Arguments for GNUNET_PROGRAM_run */ | ||
456 | char *const argv[] = { "test-gns-dht-delegated-lookup", /* Name to give running binary */ | ||
457 | "-c", | ||
458 | "test_gns_simple_lookup.conf", /* Config file to use */ | ||
459 | #if VERBOSE | ||
460 | "-L", "DEBUG", | ||
461 | #endif | ||
462 | NULL | ||
463 | }; | ||
464 | struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
465 | GNUNET_GETOPT_OPTION_END | ||
466 | }; | ||
467 | /* Run the run function as a new program */ | ||
468 | ret = | ||
469 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, | ||
470 | "test-gns-dht-delegated-lookup", "nohelp", options, &run, | ||
471 | &ok); | ||
472 | if (ret != GNUNET_OK) | ||
473 | { | ||
474 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
475 | "`test-gns-dht-delegated-lookup': Failed with error code %d\n", ret); | ||
476 | } | ||
477 | return ok; | ||
478 | } | ||
479 | |||
480 | int | ||
481 | main (int argc, char *argv[]) | ||
482 | { | ||
483 | int ret; | ||
484 | |||
485 | GNUNET_log_setup ("test-gns-simple-lookup", | ||
486 | #if VERBOSE | ||
487 | "DEBUG", | ||
488 | #else | ||
489 | "WARNING", | ||
490 | #endif | ||
491 | NULL); | ||
492 | ret = check (); | ||
493 | /** | ||
494 | * Need to remove base directory, subdirectories taken care | ||
495 | * of by the testing framework. | ||
496 | */ | ||
497 | return ret; | ||
498 | } | ||
499 | |||
500 | /* end of test_gns_twopeer.c */ | ||
diff --git a/src/gns/test_gns_simple_shorten.c b/src/gns/test_gns_simple_shorten.c index 4f8f57acb..17076bb4a 100644 --- a/src/gns/test_gns_simple_shorten.c +++ b/src/gns/test_gns_simple_shorten.c | |||
@@ -290,12 +290,12 @@ do_shorten(void *cls, const struct GNUNET_PeerIdentity *id, | |||
290 | rd.record_type = GNUNET_GNS_RECORD_PSEU; | 290 | rd.record_type = GNUNET_GNS_RECORD_PSEU; |
291 | GNUNET_free(sig); | 291 | GNUNET_free(sig); |
292 | 292 | ||
293 | sig = GNUNET_NAMESTORE_create_signature(alice_key,GNUNET_TIME_absolute_get_forever(), "", | 293 | sig = GNUNET_NAMESTORE_create_signature(alice_key,GNUNET_TIME_absolute_get_forever(), "+", |
294 | &rd, 1); | 294 | &rd, 1); |
295 | 295 | ||
296 | GNUNET_NAMESTORE_record_put (namestore_handle, | 296 | GNUNET_NAMESTORE_record_put (namestore_handle, |
297 | &alice_pkey, | 297 | &alice_pkey, |
298 | "", | 298 | "+", |
299 | GNUNET_TIME_absolute_get_forever(), | 299 | GNUNET_TIME_absolute_get_forever(), |
300 | 1, | 300 | 1, |
301 | &rd, | 301 | &rd, |