-consistently use struct GNUNET_HashCode
[oweals/gnunet.git] / src / gns / test_gns_pseu_shorten.c
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_pseu_shorten.c
22  * @brief base testcase for testing on the fly pseu import and shorten
23  *
24  */
25 #include "platform.h"
26 #include "gnunet_testing_lib.h"
27 #include "gnunet_core_service.h"
28 #include "block_gns.h"
29 #include "gnunet_signatures.h"
30 #include "gnunet_namestore_service.h"
31 #include "../namestore/namestore.h"
32 #include "gnunet_dnsparser_lib.h"
33 #include "gnunet_dht_service.h"
34 #include "gnunet_gns_service.h"
35
36 /* DEFINES */
37 #define VERBOSE GNUNET_YES
38
39 /* Timeout for entire testcase */
40 #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5)
41
42 /* If number of peers not in config file, use this number */
43 #define DEFAULT_NUM_PEERS 2
44
45 /* test records to resolve */
46 #define TEST_DOMAIN "www.alice.bob.gnunet"
47 #define TEST_IP "127.0.0.1"
48 #define TEST_RECORD_NAME "www"
49
50 #define TEST_AUTHORITY_BOB "bob"
51 #define TEST_AUTHORITY_ALICE "alice"
52 #define TEST_PSEU_ALICE "carol"
53 #define TEST_EXPECTED_RESULT "www.carol.gnunet"
54
55 #define DHT_OPERATION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
56
57 #define KEYFILE_BOB "../namestore/zonefiles/HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey"
58 #define KEYFILE_ALICE "../namestore/zonefiles/N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey"
59
60 /* Globals */
61
62 /**
63  * Directory to store temp data in, defined in config file
64  */
65 static char *test_directory;
66
67 static struct GNUNET_TESTING_PeerGroup *pg;
68
69 /* Task handle to use to schedule test failure */
70 static GNUNET_SCHEDULER_TaskIdentifier die_task;
71
72 static GNUNET_SCHEDULER_TaskIdentifier disco_task;
73
74 /* Global return value (0 for success, anything else for failure) */
75 static int ok;
76
77 static struct GNUNET_NAMESTORE_Handle *namestore_handle;
78
79 static struct GNUNET_GNS_Handle *gns_handle;
80
81 static struct GNUNET_DHT_Handle *dht_handle;
82
83 const struct GNUNET_CONFIGURATION_Handle *cfg;
84
85 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded alice_pkey;
86 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded bob_pkey;
87 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded our_pkey;
88 struct GNUNET_CRYPTO_RsaPrivateKey *alice_key;
89 struct GNUNET_CRYPTO_RsaPrivateKey *bob_key;
90 struct GNUNET_CRYPTO_RsaPrivateKey *our_key;
91 struct GNUNET_CRYPTO_ShortHashCode alice_hash;
92 struct GNUNET_CRYPTO_ShortHashCode bob_hash;
93 struct GNUNET_CRYPTO_ShortHashCode our_zone;
94
95 /**
96  * Check whether peers successfully shut down.
97  */
98 void
99 shutdown_callback (void *cls, const char *emsg)
100 {
101   if (disco_task != GNUNET_SCHEDULER_NO_TASK)
102   {
103     disco_task = GNUNET_SCHEDULER_NO_TASK;
104     GNUNET_SCHEDULER_cancel(disco_task);
105     GNUNET_DHT_disconnect(dht_handle);
106     dht_handle = NULL;
107   }
108
109   if (emsg != NULL)
110   {
111     GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error on shutdown! ret=%d\n", ok);
112     if (ok == 0)
113       ok = 2;
114   }
115
116   GNUNET_log (GNUNET_ERROR_TYPE_INFO, "done(ret=%d)!\n", ok);
117 }
118
119 static void
120 disco_dht(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
121 {
122   disco_task = GNUNET_SCHEDULER_NO_TASK;
123   GNUNET_DHT_disconnect(dht_handle);
124   dht_handle = NULL;
125 }
126
127 /**
128  * Called when gns shorten finishes
129  */
130 static void
131 process_shorten_result(void* cls, const char* sname)
132 {
133   GNUNET_GNS_disconnect(gns_handle);
134   //GNUNET_SCHEDULER_add_now(disco_dht, NULL);
135   ok = 0;
136
137   if (sname == NULL)
138   {
139     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
140                 "shorten test failed!\n");
141     ok = 1;
142   }
143   else
144   {
145     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
146                 "%s shortened to %s\n", (char*)cls, sname);
147     if (0 != strcmp(sname, TEST_EXPECTED_RESULT))
148     {
149       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
150                   "shorten test failed! (wanted: %s got: %s\n",
151                   (char*)cls, sname);
152       ok = 1;
153     }
154
155     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "shorten test succeeded!\n");
156   }
157
158   GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Shutting down peer1!\n");
159   GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
160 }
161
162 static void
163 do_shorten(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
164 {
165   GNUNET_GNS_shorten_zone (gns_handle, TEST_DOMAIN,
166                      &our_zone, &our_zone,
167                      &process_shorten_result,
168 TEST_DOMAIN);
169 }
170
171 static void
172 on_lookup_result(void *cls, uint32_t rd_count,
173                  const struct GNUNET_NAMESTORE_RecordData *rd)
174 {
175   struct in_addr a;
176   int i;
177   char* addr;
178   
179   if (rd_count == 0)
180   {
181     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
182                 "Lookup failed, rp_filtering?\n");
183     ok = 2;
184   }
185   else
186   {
187     ok = 1;
188     GNUNET_log (GNUNET_ERROR_TYPE_INFO, "name: %s\n", (char*)cls);
189     for (i=0; i<rd_count; i++)
190     {
191       GNUNET_log (GNUNET_ERROR_TYPE_INFO, "type: %d\n", rd[i].record_type);
192       if (rd[i].record_type == GNUNET_GNS_RECORD_TYPE_A)
193       {
194         memcpy(&a, rd[i].data, sizeof(a));
195         addr = inet_ntoa(a);
196         GNUNET_log (GNUNET_ERROR_TYPE_INFO, "address: %s\n", addr);
197         if (0 == strcmp(addr, TEST_IP))
198         {
199           GNUNET_log (GNUNET_ERROR_TYPE_INFO,
200                     "%s correctly resolved to %s!\n", TEST_DOMAIN, addr);
201           ok = 0;
202         }
203       }
204       else
205       {
206         GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No resolution!\n");
207       }
208     }
209   }
210   
211   GNUNET_SCHEDULER_add_delayed (TIMEOUT, &do_shorten, NULL);
212 }
213
214
215 /**
216  * Function scheduled to be run on the successful start of services
217  * tries to look up the dns record for TEST_DOMAIN
218  */
219 static void
220 commence_testing (void *cls, int success)
221 {
222   GNUNET_SCHEDULER_add_now(disco_dht, NULL);
223   //GNUNET_DHT_disconnect(dht_handle);
224
225   GNUNET_CRYPTO_rsa_key_free(our_key);
226   GNUNET_CRYPTO_rsa_key_free(bob_key);
227   GNUNET_CRYPTO_rsa_key_free(alice_key);
228
229   gns_handle = GNUNET_GNS_connect(cfg);
230
231   if (NULL == gns_handle)
232   {
233     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
234                 "Failed to connect to GNS!\n");
235   }
236
237   GNUNET_GNS_lookup_zone (gns_handle, TEST_DOMAIN,
238                           &our_zone, &our_zone,
239                           GNUNET_GNS_RECORD_TYPE_A,
240                           GNUNET_NO,
241                     &on_lookup_result, TEST_DOMAIN);
242 }
243
244 /**
245  * Continuation for the GNUNET_DHT_get_stop call, so that we don't shut
246  * down the peers without freeing memory associated with GET request.
247  */
248 static void
249 end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
250 {
251   GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failing test with error: `%s'!\n",
252               (char *) cls);
253   ok = 1;
254   
255   if (disco_task != GNUNET_SCHEDULER_NO_TASK)
256   {
257     disco_task = GNUNET_SCHEDULER_NO_TASK;
258     GNUNET_SCHEDULER_cancel(disco_task);
259     GNUNET_DHT_disconnect(dht_handle);
260     dht_handle = NULL;
261   }
262   if (pg != NULL)
263     GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
264   GNUNET_SCHEDULER_cancel (die_task);
265 }
266
267 static void
268 put_pseu_dht(void *cls, int success)
269 {
270   struct GNSNameRecordBlock *nrb;
271   struct GNUNET_CRYPTO_ShortHashCode name_hash;
272   struct GNUNET_CRYPTO_ShortHashCode zone_hash;
273   struct GNUNET_HashCode xor_hash;
274   struct GNUNET_HashCode name_hash_double;
275   struct GNUNET_HashCode zone_hash_double;
276   uint32_t rd_payload_length;
277   char* nrb_data = NULL;
278   struct GNUNET_CRYPTO_RsaSignature *sig;
279   struct GNUNET_NAMESTORE_RecordData rd;
280   
281   rd.expiration = GNUNET_TIME_UNIT_FOREVER_ABS;
282   rd.data_size = strlen(TEST_PSEU_ALICE)+1;
283   rd.data = TEST_PSEU_ALICE;
284   rd.record_type = GNUNET_GNS_RECORD_PSEU;
285
286   sig = GNUNET_NAMESTORE_create_signature(alice_key,
287                                           GNUNET_TIME_UNIT_FOREVER_ABS,
288                                           "+",
289                                           &rd, 1);
290   rd_payload_length = GNUNET_NAMESTORE_records_get_size (1, &rd);
291   nrb = GNUNET_malloc(rd_payload_length + strlen("+") + 1
292                       + sizeof(struct GNSNameRecordBlock));
293   nrb->signature = *sig;
294   nrb->public_key = alice_pkey;
295   nrb->rd_count = htonl(1);
296   memset(&nrb[1], 0, strlen("+") + 1);
297   strcpy((char*)&nrb[1], "+");
298   nrb_data = (char*)&nrb[1];
299   nrb_data += strlen("+") + 1;
300
301   if (-1 == GNUNET_NAMESTORE_records_serialize (1,
302                                                 &rd,
303                                                 rd_payload_length,
304                                                 nrb_data))
305   {
306     GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Record serialization failed!\n");
307     ok = 3;
308     GNUNET_DHT_disconnect(dht_handle);
309     
310     
311     GNUNET_CRYPTO_rsa_key_free(our_key);
312     GNUNET_CRYPTO_rsa_key_free(bob_key);
313     GNUNET_CRYPTO_rsa_key_free(alice_key);
314     GNUNET_free(sig);
315     GNUNET_free (nrb);
316     return;
317   }
318   GNUNET_CRYPTO_short_hash("+", strlen("+"), &name_hash);
319   GNUNET_CRYPTO_short_hash(&alice_pkey,
320                      sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
321                      &zone_hash);
322
323   GNUNET_CRYPTO_short_hash_double(&name_hash, &name_hash_double);
324   GNUNET_CRYPTO_short_hash_double(&zone_hash, &zone_hash_double);
325   GNUNET_CRYPTO_hash_xor(&zone_hash_double, &name_hash_double, &xor_hash);
326
327   rd_payload_length += sizeof(struct GNSNameRecordBlock) +
328     strlen("+") + 1;
329
330   GNUNET_DHT_put (dht_handle, &xor_hash,
331                   0,
332                   GNUNET_DHT_RO_NONE,
333                   GNUNET_BLOCK_TYPE_GNS_NAMERECORD,
334                   rd_payload_length,
335                   (char*)nrb,
336                   rd.expiration,
337                   DHT_OPERATION_TIMEOUT,
338                   &commence_testing,
339                   NULL);
340   
341   GNUNET_free(sig);
342   GNUNET_free (nrb);
343 }
344
345 static void
346 put_www_dht(void *cls, int success)
347 {
348   struct GNSNameRecordBlock *nrb;
349   struct GNUNET_CRYPTO_ShortHashCode name_hash;
350   struct GNUNET_CRYPTO_ShortHashCode zone_hash;
351   struct GNUNET_HashCode xor_hash;
352   struct GNUNET_HashCode name_hash_double;
353   struct GNUNET_HashCode zone_hash_double;
354   uint32_t rd_payload_length;
355   char* nrb_data = NULL;
356   struct GNUNET_CRYPTO_RsaSignature *sig;
357   struct GNUNET_NAMESTORE_RecordData rd;
358   char* ip = TEST_IP;
359   struct in_addr *web = GNUNET_malloc(sizeof(struct in_addr));
360   
361   rd.expiration = GNUNET_TIME_UNIT_FOREVER_ABS;
362   GNUNET_assert(1 == inet_pton (AF_INET, ip, web));
363   rd.data_size = sizeof(struct in_addr);
364   rd.data = web;
365   rd.record_type = GNUNET_DNSPARSER_TYPE_A;
366
367   sig = GNUNET_NAMESTORE_create_signature(alice_key,
368                                           GNUNET_TIME_UNIT_FOREVER_ABS,
369                                           TEST_RECORD_NAME,
370                                           &rd, 1);
371   rd_payload_length = GNUNET_NAMESTORE_records_get_size (1, &rd);
372   nrb = GNUNET_malloc(rd_payload_length + strlen(TEST_RECORD_NAME) + 1
373                       + sizeof(struct GNSNameRecordBlock));
374   nrb->signature = *sig;
375   nrb->public_key = alice_pkey;
376   nrb->rd_count = htonl(1);
377   memset(&nrb[1], 0, strlen(TEST_RECORD_NAME) + 1);
378   strcpy((char*)&nrb[1], TEST_RECORD_NAME);
379   nrb_data = (char*)&nrb[1];
380   nrb_data += strlen(TEST_RECORD_NAME) + 1;
381
382   if (-1 == GNUNET_NAMESTORE_records_serialize (1,
383                                                 &rd,
384                                                 rd_payload_length,
385                                                 nrb_data))
386   {
387     GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Record serialization failed!\n");
388     ok = 3;
389     GNUNET_DHT_disconnect(dht_handle);
390     
391     GNUNET_CRYPTO_rsa_key_free(our_key);
392     GNUNET_CRYPTO_rsa_key_free(bob_key);
393     GNUNET_CRYPTO_rsa_key_free(alice_key);
394     GNUNET_free(web);
395     GNUNET_free (nrb);
396     return;
397   }
398   GNUNET_CRYPTO_short_hash(TEST_RECORD_NAME, strlen(TEST_RECORD_NAME), &name_hash);
399   GNUNET_CRYPTO_short_hash(&alice_pkey,
400                      sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
401                      &zone_hash);
402   GNUNET_CRYPTO_short_hash_double(&zone_hash, &zone_hash_double);
403   GNUNET_CRYPTO_short_hash_double(&name_hash, &name_hash_double);
404   GNUNET_CRYPTO_hash_xor(&zone_hash_double, &name_hash_double, &xor_hash);
405
406   rd_payload_length += sizeof(struct GNSNameRecordBlock) +
407     strlen(TEST_RECORD_NAME) + 1;
408
409   GNUNET_DHT_put (dht_handle, &xor_hash,
410                   0,
411                   GNUNET_DHT_RO_NONE,
412                   GNUNET_BLOCK_TYPE_GNS_NAMERECORD,
413                   rd_payload_length,
414                   (char*)nrb,
415                   rd.expiration,
416                   DHT_OPERATION_TIMEOUT,
417                   &put_pseu_dht,
418                   NULL);
419
420   GNUNET_free(web);
421   GNUNET_free (nrb);
422 }
423
424
425 static void
426 put_pkey_dht(void *cls, int32_t success, const char *emsg)
427 {
428   struct GNSNameRecordBlock *nrb;
429   struct GNUNET_CRYPTO_ShortHashCode name_hash;
430   struct GNUNET_CRYPTO_ShortHashCode zone_hash;
431   struct GNUNET_HashCode xor_hash;
432   struct GNUNET_HashCode name_hash_double;
433   struct GNUNET_HashCode zone_hash_double;
434   uint32_t rd_payload_length;
435   char* nrb_data = NULL;
436   struct GNUNET_CRYPTO_RsaSignature *sig;
437   struct GNUNET_NAMESTORE_RecordData rd;
438   
439   rd.expiration = GNUNET_TIME_UNIT_FOREVER_ABS;
440   rd.data_size = sizeof(struct GNUNET_CRYPTO_ShortHashCode);
441   rd.data = &alice_hash;
442   rd.record_type = GNUNET_GNS_RECORD_PKEY;
443
444   sig = GNUNET_NAMESTORE_create_signature(bob_key,
445                                           GNUNET_TIME_UNIT_FOREVER_ABS,
446                                           TEST_AUTHORITY_ALICE,
447                                           &rd,
448                                           1);
449
450   rd_payload_length = GNUNET_NAMESTORE_records_get_size (1, &rd);
451   nrb = GNUNET_malloc(rd_payload_length + strlen(TEST_AUTHORITY_ALICE) + 1
452                       + sizeof(struct GNSNameRecordBlock));
453   nrb->signature = *sig;
454   nrb->public_key = bob_pkey;
455   nrb->rd_count = htonl(1);
456   memset(&nrb[1], 0, strlen(TEST_AUTHORITY_ALICE) + 1);
457   strcpy((char*)&nrb[1], TEST_AUTHORITY_ALICE);
458   nrb_data = (char*)&nrb[1];
459   nrb_data += strlen(TEST_AUTHORITY_ALICE) + 1;
460
461   if (-1 == GNUNET_NAMESTORE_records_serialize (1,
462                                                 &rd,
463                                                 rd_payload_length,
464                                                 nrb_data))
465   {
466     GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Record serialization failed!\n");
467     ok = 3;
468     
469     GNUNET_CRYPTO_rsa_key_free(our_key);
470     GNUNET_CRYPTO_rsa_key_free(bob_key);
471     GNUNET_CRYPTO_rsa_key_free(alice_key);
472     GNUNET_free(sig);
473     GNUNET_free (nrb);
474     return;
475   }
476
477
478   GNUNET_CRYPTO_short_hash(TEST_AUTHORITY_ALICE,
479                      strlen(TEST_AUTHORITY_ALICE), &name_hash);
480   GNUNET_CRYPTO_short_hash(&bob_pkey,
481                      sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
482                      &zone_hash);
483   GNUNET_CRYPTO_short_hash_double(&zone_hash, &zone_hash_double);
484   GNUNET_CRYPTO_short_hash_double(&name_hash, &name_hash_double);
485   GNUNET_CRYPTO_hash_xor(&zone_hash_double, &name_hash_double, &xor_hash); 
486
487   rd_payload_length += sizeof(struct GNSNameRecordBlock) +
488     strlen(TEST_AUTHORITY_ALICE) + 1;
489   GNUNET_DHT_put (dht_handle, &xor_hash,
490                   0,
491                   GNUNET_DHT_RO_NONE,
492                   GNUNET_BLOCK_TYPE_GNS_NAMERECORD,
493                   rd_payload_length,
494                   (char*)nrb,
495                   rd.expiration,
496                   DHT_OPERATION_TIMEOUT,
497                   &put_www_dht,
498                   NULL);
499   GNUNET_NAMESTORE_disconnect(namestore_handle, GNUNET_NO);
500   GNUNET_free (nrb);
501 }
502
503 static void
504 do_lookup(void *cls, const struct GNUNET_PeerIdentity *id,
505           const struct GNUNET_CONFIGURATION_Handle *_cfg,
506           struct GNUNET_TESTING_Daemon *d, const char *emsg)
507 {
508   
509   
510   char* our_keyfile;
511   
512   cfg = _cfg;
513
514   GNUNET_SCHEDULER_cancel (die_task);
515
516   /* put records into namestore */
517   namestore_handle = GNUNET_NAMESTORE_connect(cfg);
518   if (NULL == namestore_handle)
519   {
520     GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to connect to namestore\n");
521     ok = -1;
522     return;
523   }
524   
525   /* dht */
526   dht_handle = GNUNET_DHT_connect(cfg, 1);
527   if (NULL == dht_handle)
528   {
529     GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to connect to dht\n");
530     ok = -1;
531     return;
532   }
533
534   if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns",
535                                                           "ZONEKEY",
536                                                           &our_keyfile))
537   {
538     GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to get key from cfg\n");
539     ok = -1;
540     return;
541   }
542
543   our_key = GNUNET_CRYPTO_rsa_key_create_from_file (our_keyfile);
544   bob_key = GNUNET_CRYPTO_rsa_key_create_from_file (KEYFILE_BOB);
545   alice_key = GNUNET_CRYPTO_rsa_key_create_from_file (KEYFILE_ALICE);
546   
547   GNUNET_free(our_keyfile);
548
549   GNUNET_CRYPTO_rsa_key_get_public (our_key, &our_pkey);
550   GNUNET_CRYPTO_rsa_key_get_public (bob_key, &bob_pkey);
551   GNUNET_CRYPTO_rsa_key_get_public (alice_key, &alice_pkey);
552   GNUNET_CRYPTO_short_hash(&bob_pkey, sizeof(bob_pkey), &bob_hash);
553   GNUNET_CRYPTO_short_hash(&alice_pkey, sizeof(alice_pkey), &alice_hash);
554   GNUNET_CRYPTO_short_hash(&our_pkey, sizeof(our_pkey), &our_zone);
555
556   struct GNUNET_NAMESTORE_RecordData rd;
557   rd.expiration = GNUNET_TIME_UNIT_FOREVER_ABS;
558   rd.data_size = sizeof(struct GNUNET_CRYPTO_ShortHashCode);
559   rd.data = &bob_hash;
560   rd.record_type = GNUNET_GNS_RECORD_PKEY;
561
562   GNUNET_NAMESTORE_record_create (namestore_handle,
563                                   our_key,
564                                   TEST_AUTHORITY_BOB,
565                                   &rd,
566                                   &put_pkey_dht,
567                                   NULL);
568
569
570 }
571
572 static void
573 run (void *cls, char *const *args, const char *cfgfile,
574      const struct GNUNET_CONFIGURATION_Handle *c)
575 {
576   cfg = c;
577    /* Get path from configuration file */
578   if (GNUNET_YES !=
579       GNUNET_CONFIGURATION_get_value_string (cfg, "paths", "servicehome",
580                                              &test_directory))
581   {
582     ok = 404;
583     return;
584   }
585
586     
587   /* Set up a task to end testing if peer start fails */
588   die_task =
589       GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly,
590                                     "didn't start all daemons in reasonable amount of time!!!");
591   
592   /* Start alice */
593   //d1 = GNUNET_TESTING_daemon_start(cfg, TIMEOUT, GNUNET_NO, NULL, NULL, 0,
594   //                                 NULL, NULL, NULL, &do_lookup, NULL);
595   pg = GNUNET_TESTING_daemons_start(cfg, 1, 1, 1, TIMEOUT,
596                                     NULL, NULL, &do_lookup, NULL,
597                                     NULL, NULL, NULL);
598 }
599
600 static int
601 check ()
602 {
603   int ret;
604
605   /* Arguments for GNUNET_PROGRAM_run */
606   char *const argv[] = { "test-gns-pseu-shorten", /* Name to give running binary */
607     "-c",
608     "test_gns_simple_lookup.conf",       /* Config file to use */
609 #if VERBOSE
610     "-L", "DEBUG",
611 #endif
612     NULL
613   };
614   struct GNUNET_GETOPT_CommandLineOption options[] = {
615     GNUNET_GETOPT_OPTION_END
616   };
617   /* Run the run function as a new program */
618   ret =
619       GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
620                           "test-gns-pseu-shorten", "nohelp", options, &run,
621                           &ok);
622   if (ret != GNUNET_OK)
623   {
624     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
625                 "`test-gns-pseu-shorten': Failed with error code %d\n", ret);
626   }
627   return ok;
628 }
629
630 int
631 main (int argc, char *argv[])
632 {
633   int ret;
634
635   GNUNET_log_setup ("test-gns-pseu-shorten",
636 #if VERBOSE
637                     "DEBUG",
638 #else
639                     "WARNING",
640 #endif
641                     NULL);
642   ret = check ();
643   /**
644    * Need to remove base directory, subdirectories taken care
645    * of by the testing framework.
646    */
647   return ret;
648 }
649
650 /* end of test_gns_twopeer.c */