aboutsummaryrefslogtreecommitdiff
path: root/src/gns/test_gns_simple_delegated_lookup.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gns/test_gns_simple_delegated_lookup.c')
-rw-r--r--src/gns/test_gns_simple_delegated_lookup.c189
1 files changed, 84 insertions, 105 deletions
diff --git a/src/gns/test_gns_simple_delegated_lookup.c b/src/gns/test_gns_simple_delegated_lookup.c
index b456e4112..c01bd8cce 100644
--- a/src/gns/test_gns_simple_delegated_lookup.c
+++ b/src/gns/test_gns_simple_delegated_lookup.c
@@ -18,7 +18,7 @@
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20/** 20/**
21 * @file gns/test_gns_twopeer.c 21 * @file gns/test_gns_simple_delegated_lookup.c
22 * @brief base testcase for testing DHT service with 22 * @brief base testcase for testing DHT service with
23 * two running peers. 23 * two running peers.
24 * 24 *
@@ -46,15 +46,9 @@
46#include "gnunet_dnsparser_lib.h" 46#include "gnunet_dnsparser_lib.h"
47#include "gnunet_gns_service.h" 47#include "gnunet_gns_service.h"
48 48
49/* DEFINES */
50#define VERBOSE GNUNET_YES
51
52/* Timeout for entire testcase */ 49/* Timeout for entire testcase */
53#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 20) 50#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 20)
54 51
55/* If number of peers not in config file, use this number */
56#define DEFAULT_NUM_PEERS 2
57
58/* test records to resolve */ 52/* test records to resolve */
59#define TEST_DOMAIN "www.bob.gads" 53#define TEST_DOMAIN "www.bob.gads"
60#define TEST_IP "127.0.0.1" 54#define TEST_IP "127.0.0.1"
@@ -64,10 +58,8 @@
64 58
65#define KEYFILE_BOB "../namestore/zonefiles/HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey" 59#define KEYFILE_BOB "../namestore/zonefiles/HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey"
66 60
67/* Globals */
68
69/* Task handle to use to schedule test failure */ 61/* Task handle to use to schedule test failure */
70GNUNET_SCHEDULER_TaskIdentifier die_task; 62static GNUNET_SCHEDULER_TaskIdentifier die_task;
71 63
72/* Global return value (0 for success, anything else for failure) */ 64/* Global return value (0 for success, anything else for failure) */
73static int ok; 65static int ok;
@@ -76,7 +68,8 @@ static struct GNUNET_NAMESTORE_Handle *namestore_handle;
76 68
77static struct GNUNET_GNS_Handle *gns_handle; 69static struct GNUNET_GNS_Handle *gns_handle;
78 70
79const struct GNUNET_CONFIGURATION_Handle *cfg; 71static const struct GNUNET_CONFIGURATION_Handle *cfg;
72
80 73
81/** 74/**
82 * Check if the get_handle is being used, if so stop the request. Either 75 * Check if the get_handle is being used, if so stop the request. Either
@@ -92,7 +85,6 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
92 GNUNET_GNS_disconnect(gns_handle); 85 GNUNET_GNS_disconnect(gns_handle);
93 gns_handle = NULL; 86 gns_handle = NULL;
94 } 87 }
95
96 if (NULL != namestore_handle) 88 if (NULL != namestore_handle)
97 { 89 {
98 GNUNET_NAMESTORE_disconnect (namestore_handle); 90 GNUNET_NAMESTORE_disconnect (namestore_handle);
@@ -103,66 +95,60 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
103 ok = 1; 95 ok = 1;
104} 96}
105 97
106void end_badly_now ()
107{
108 GNUNET_SCHEDULER_cancel (die_task);
109 die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
110}
111
112 98
113static void shutdown_task (void *cls, 99static void
114 const struct GNUNET_SCHEDULER_TaskContext *tc) 100shutdown_task (void *cls,
101 const struct GNUNET_SCHEDULER_TaskContext *tc)
115{ 102{
116 GNUNET_GNS_disconnect(gns_handle); 103 GNUNET_GNS_disconnect (gns_handle);
104 gns_handle = NULL;
117 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Shutting down peer!\n"); 105 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Shutting down peer!\n");
118 GNUNET_SCHEDULER_shutdown (); 106 GNUNET_SCHEDULER_shutdown ();
119} 107}
120 108
109
121static void 110static void
122on_lookup_result(void *cls, uint32_t rd_count, 111on_lookup_result (void *cls, uint32_t rd_count,
123 const struct GNUNET_NAMESTORE_RecordData *rd) 112 const struct GNUNET_NAMESTORE_RecordData *rd)
124{ 113{
114 const char *name = cls;
115 uint32_t i;
116 const char* addr;
125 struct in_addr a; 117 struct in_addr a;
126 int i;
127 char* addr;
128
129 if (GNUNET_SCHEDULER_NO_TASK != die_task)
130 {
131 GNUNET_SCHEDULER_cancel (die_task);
132 die_task = GNUNET_SCHEDULER_NO_TASK;
133 }
134 118
135 GNUNET_NAMESTORE_disconnect (namestore_handle); 119 GNUNET_NAMESTORE_disconnect (namestore_handle);
136 if (rd_count == 0) 120 namestore_handle = NULL;
121 if (0 == rd_count)
137 { 122 {
138 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 123 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
139 "Lookup failed, rp_filtering?\n"); 124 "Lookup failed!\n");
140 ok = 2; 125 ok = 2;
126 GNUNET_SCHEDULER_shutdown ();
127 return;
128 }
129 if (GNUNET_SCHEDULER_NO_TASK != die_task)
130 {
131 GNUNET_SCHEDULER_cancel (die_task);
132 die_task = GNUNET_SCHEDULER_NO_TASK;
141 } 133 }
142 else 134 ok = 1;
135 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
136 "name: %s\n",
137 name);
138 for (i=0; i<rd_count; i++)
143 { 139 {
144 ok = 1; 140 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "type: %d\n", rd[i].record_type);
145 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "name: %s\n", (char*)cls); 141 if (rd[i].record_type != GNUNET_GNS_RECORD_A)
146 for (i=0; i<rd_count; i++) 142 continue;
147 { 143 memcpy (&a, rd[i].data, sizeof (a));
148 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "type: %d\n", rd[i].record_type); 144 addr = inet_ntoa (a);
149 if (rd[i].record_type == GNUNET_GNS_RECORD_A) 145 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
150 { 146 "address: %s\n", addr);
151 memcpy(&a, rd[i].data, sizeof(a)); 147 if (0 != strcmp (addr, TEST_IP))
152 addr = inet_ntoa(a); 148 continue;
153 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "address: %s\n", addr); 149 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
154 if (0 == strcmp(addr, TEST_IP)) 150 "%s correctly resolved to %s!\n", TEST_DOMAIN, addr);
155 { 151 ok = 0;
156 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
157 "%s correctly resolved to %s!\n", TEST_DOMAIN, addr);
158 ok = 0;
159 }
160 }
161 else
162 {
163 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No resolution!\n");
164 }
165 }
166 } 152 }
167 GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); 153 GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
168} 154}
@@ -175,28 +161,33 @@ on_lookup_result(void *cls, uint32_t rd_count,
175static void 161static void
176commence_testing (void *cls, int32_t success, const char *emsg) 162commence_testing (void *cls, int32_t success, const char *emsg)
177{ 163{
178 164 if (NULL != emsg)
165 {
166 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
167 "Failed to store record in namestore: %s\n",
168 emsg);
169 GNUNET_SCHEDULER_shutdown ();
170 return;
171 }
179 gns_handle = GNUNET_GNS_connect(cfg); 172 gns_handle = GNUNET_GNS_connect(cfg);
180
181 if (NULL == gns_handle) 173 if (NULL == gns_handle)
182 { 174 {
183 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 175 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
184 "Failed to connect to GNS!\n"); 176 "Failed to connect to GNS!\n");
185 end_badly_now(); 177 GNUNET_SCHEDULER_shutdown ();
186 return; 178 return;
187 } 179 }
188 180 GNUNET_GNS_lookup (gns_handle, TEST_DOMAIN, GNUNET_GNS_RECORD_A,
189 GNUNET_GNS_lookup(gns_handle, TEST_DOMAIN, GNUNET_GNS_RECORD_A, 181 GNUNET_NO,
190 GNUNET_NO, 182 NULL,
191 NULL, 183 &on_lookup_result, TEST_DOMAIN);
192 &on_lookup_result, TEST_DOMAIN);
193} 184}
194 185
195 186
196 187static void
197void do_check (void *cls, 188do_check (void *cls,
198 const struct GNUNET_CONFIGURATION_Handle *ccfg, 189 const struct GNUNET_CONFIGURATION_Handle *ccfg,
199 struct GNUNET_TESTING_Peer *peer) 190 struct GNUNET_TESTING_Peer *peer)
200{ 191{
201 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded alice_pkey; 192 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded alice_pkey;
202 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded bob_pkey; 193 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded bob_pkey;
@@ -206,6 +197,9 @@ void do_check (void *cls,
206 struct GNUNET_CRYPTO_RsaSignature *sig; 197 struct GNUNET_CRYPTO_RsaSignature *sig;
207 char* alice_keyfile; 198 char* alice_keyfile;
208 struct GNUNET_TIME_Absolute et; 199 struct GNUNET_TIME_Absolute et;
200 struct GNUNET_NAMESTORE_RecordData rd;
201 const char* ip = TEST_IP;
202 struct in_addr web;
209 203
210 cfg = ccfg; 204 cfg = ccfg;
211 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); 205 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
@@ -214,53 +208,45 @@ void do_check (void *cls,
214 namestore_handle = GNUNET_NAMESTORE_connect(cfg); 208 namestore_handle = GNUNET_NAMESTORE_connect(cfg);
215 if (NULL == namestore_handle) 209 if (NULL == namestore_handle)
216 { 210 {
217 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to connect to namestore\n"); 211 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
218 end_badly_now () ; 212 "Failed to connect to namestore\n");
213 GNUNET_SCHEDULER_shutdown ();
219 return; 214 return;
220 } 215 }
221 216
222 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns", 217 if (GNUNET_OK !=
223 "ZONEKEY", 218 GNUNET_CONFIGURATION_get_value_filename (cfg, "gns",
224 &alice_keyfile)) 219 "ZONEKEY",
220 &alice_keyfile))
225 { 221 {
226 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to get key from cfg\n"); 222 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to get key from cfg\n");
227 end_badly_now () ; 223 GNUNET_SCHEDULER_shutdown ();
228 return; 224 return;
229 } 225 }
230
231 alice_key = GNUNET_CRYPTO_rsa_key_create_from_file (alice_keyfile); 226 alice_key = GNUNET_CRYPTO_rsa_key_create_from_file (alice_keyfile);
232 bob_key = GNUNET_CRYPTO_rsa_key_create_from_file (KEYFILE_BOB); 227 bob_key = GNUNET_CRYPTO_rsa_key_create_from_file (KEYFILE_BOB);
233
234 GNUNET_CRYPTO_rsa_key_get_public (alice_key, &alice_pkey); 228 GNUNET_CRYPTO_rsa_key_get_public (alice_key, &alice_pkey);
235 GNUNET_CRYPTO_rsa_key_get_public (bob_key, &bob_pkey); 229 GNUNET_CRYPTO_rsa_key_get_public (bob_key, &bob_pkey);
236
237 struct GNUNET_NAMESTORE_RecordData rd;
238 char* ip = TEST_IP;
239 struct in_addr *web = GNUNET_malloc(sizeof(struct in_addr));
240 rd.expiration_time = UINT64_MAX; 230 rd.expiration_time = UINT64_MAX;
241 GNUNET_assert(1 == inet_pton (AF_INET, ip, web)); 231 GNUNET_assert (1 == inet_pton (AF_INET, ip, &web));
242 232 GNUNET_CRYPTO_short_hash (&bob_pkey, sizeof(bob_pkey), &bob_hash);
243 GNUNET_CRYPTO_short_hash(&bob_pkey, sizeof(bob_pkey), &bob_hash);
244
245 rd.data_size = sizeof(struct GNUNET_CRYPTO_ShortHashCode); 233 rd.data_size = sizeof(struct GNUNET_CRYPTO_ShortHashCode);
246 rd.data = &bob_hash; 234 rd.data = &bob_hash;
247 rd.record_type = GNUNET_GNS_RECORD_PKEY; 235 rd.record_type = GNUNET_GNS_RECORD_PKEY;
248 rd.flags = GNUNET_NAMESTORE_RF_AUTHORITY; 236 rd.flags = GNUNET_NAMESTORE_RF_AUTHORITY;
249
250 GNUNET_NAMESTORE_record_create (namestore_handle, 237 GNUNET_NAMESTORE_record_create (namestore_handle,
251 alice_key, 238 alice_key,
252 TEST_AUTHORITY_NAME, 239 TEST_AUTHORITY_NAME,
253 &rd, 240 &rd,
254 NULL, 241 NULL,
255 NULL); 242 NULL);
256
257 rd.data_size = sizeof(struct in_addr); 243 rd.data_size = sizeof(struct in_addr);
258 rd.data = web; 244 rd.data = &web;
259 rd.record_type = GNUNET_DNSPARSER_TYPE_A; 245 rd.record_type = GNUNET_DNSPARSER_TYPE_A;
260 sig = GNUNET_NAMESTORE_create_signature(bob_key, 246 sig = GNUNET_NAMESTORE_create_signature (bob_key,
261 GNUNET_TIME_UNIT_FOREVER_ABS, 247 GNUNET_TIME_UNIT_FOREVER_ABS,
262 TEST_RECORD_NAME, 248 TEST_RECORD_NAME,
263 &rd, 1); 249 &rd, 1);
264 et.abs_value = rd.expiration_time; 250 et.abs_value = rd.expiration_time;
265 GNUNET_NAMESTORE_record_put (namestore_handle, 251 GNUNET_NAMESTORE_record_put (namestore_handle,
266 &bob_pkey, 252 &bob_pkey,
@@ -271,12 +257,10 @@ void do_check (void *cls,
271 sig, 257 sig,
272 &commence_testing, 258 &commence_testing,
273 NULL); 259 NULL);
274
275 GNUNET_free (web);
276 GNUNET_free (sig); 260 GNUNET_free (sig);
277 GNUNET_free (alice_keyfile); 261 GNUNET_free (alice_keyfile);
278 GNUNET_CRYPTO_rsa_key_free(bob_key); 262 GNUNET_CRYPTO_rsa_key_free (bob_key);
279 GNUNET_CRYPTO_rsa_key_free(alice_key); 263 GNUNET_CRYPTO_rsa_key_free (alice_key);
280} 264}
281 265
282 266
@@ -284,18 +268,13 @@ int
284main (int argc, char *argv[]) 268main (int argc, char *argv[])
285{ 269{
286 ok = 1; 270 ok = 1;
287
288 GNUNET_log_setup ("test-gns-simple-delegated-lookup", 271 GNUNET_log_setup ("test-gns-simple-delegated-lookup",
289#if VERBOSE
290 "DEBUG",
291#else
292 "WARNING", 272 "WARNING",
293#endif
294 NULL); 273 NULL);
295 274 GNUNET_TESTING_peer_run ("test-gns-simple-delegated-lookup",
296 GNUNET_TESTING_peer_run ("test-gns-simple-delegated-lookup", "test_gns_simple_lookup.conf", &do_check, NULL); 275 "test_gns_simple_lookup.conf",
297 276 &do_check, NULL);
298 return ok; 277 return ok;
299} 278}
300 279
301/* end of test_gns_twopeer.c */ 280/* end of test_gns_simple_delegated_lookup.c */