-fix
[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 /* Timeout for entire testcase */
37 #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30)
38
39 /* test records to resolve */
40 #define TEST_DOMAIN "www.alicewonderland.bobbuilder.gads"
41 #define TEST_IP "127.0.0.1"
42 #define TEST_RECORD_NAME "www"
43
44 #define TEST_PRIVATE_ZONE "private"
45 #define TEST_SHORTEN_ZONE "short"
46 #define TEST_AUTHORITY_BOB "bobbuilder"
47 #define TEST_AUTHORITY_ALICE "alicewonderland"
48 #define TEST_PSEU_ALICE "carol"
49 #define TEST_EXPECTED_RESULT "www.carol.short.private.gads"
50
51 #define DHT_OPERATION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
52
53 #define KEYFILE_SHORTEN = "zonefiles/188JSUMKEF25GVU8TTV0PBNNN8JVCPUEDFV1UHJJU884JD25V0T0.zkey"
54 #define KEYFILE_PRIVATE = "zonefiles/OEFL7A4VEF1B40QLEMTG5D8G1CN6EN16QUSG5R2DT71GRJN34LSG.zkey"
55 #define KEYFILE_BOB "../namestore/zonefiles/HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey"
56 #define KEYFILE_ALICE "../namestore/zonefiles/N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey"
57
58 /* Globals */
59
60 /* Task handle to use to schedule test failure */
61 static GNUNET_SCHEDULER_TaskIdentifier die_task;
62
63 /* Global return value (0 for success, anything else for failure) */
64 static int ok;
65
66 static struct GNUNET_NAMESTORE_Handle *namestore_handle;
67
68 static struct GNUNET_GNS_Handle *gns_handle;
69
70 static struct GNUNET_DHT_Handle *dht_handle;
71
72 static const struct GNUNET_CONFIGURATION_Handle *cfg;
73
74 static struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded alice_pkey;
75 static struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded bob_pkey;
76 static struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded our_pkey;
77 static struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded priv_pkey;
78 static struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded short_pkey;
79 static struct GNUNET_CRYPTO_EccPrivateKey *alice_key;
80 static struct GNUNET_CRYPTO_EccPrivateKey *bob_key;
81 static struct GNUNET_CRYPTO_EccPrivateKey *our_key;
82 static struct GNUNET_CRYPTO_EccPrivateKey *priv_key;
83 static struct GNUNET_CRYPTO_EccPrivateKey *short_key;
84 static struct GNUNET_CRYPTO_ShortHashCode alice_hash;
85 static struct GNUNET_CRYPTO_ShortHashCode bob_hash;
86 static struct GNUNET_CRYPTO_ShortHashCode our_zone;
87 static struct GNUNET_CRYPTO_ShortHashCode priv_zone;
88 static struct GNUNET_CRYPTO_ShortHashCode short_zone;
89
90
91 /**
92  * Check if the get_handle is being used, if so stop the request.  Either
93  * way, schedule the end_badly_cont function which actually shuts down the
94  * test.
95  */
96 static void
97 end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
98 {
99   die_task = GNUNET_SCHEDULER_NO_TASK;
100   if (NULL != gns_handle)
101   {
102     GNUNET_GNS_disconnect(gns_handle);
103     gns_handle = NULL;
104   }
105
106   if (NULL != namestore_handle)
107   {
108     GNUNET_NAMESTORE_disconnect (namestore_handle);
109     namestore_handle = NULL;
110   }
111
112   if (NULL != dht_handle)
113   {
114     GNUNET_DHT_disconnect (dht_handle);
115     dht_handle = NULL;
116   }
117
118   GNUNET_break (0);
119   GNUNET_SCHEDULER_shutdown ();
120   ok = 1;
121 }
122
123
124 static void
125 end_badly_now ()
126 {
127   GNUNET_SCHEDULER_cancel (die_task);
128   die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
129 }
130
131
132 static void 
133 shutdown_task (void *cls,
134                const struct GNUNET_SCHEDULER_TaskContext *tc)
135 {
136   GNUNET_GNS_disconnect(gns_handle);
137   GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Shutting down peer!\n");
138   GNUNET_SCHEDULER_shutdown ();
139 }
140
141 /**
142  * Called when gns shorten finishes
143  */
144 static void
145 process_shorten_result(void* cls, const char* sname)
146 {
147
148   if (GNUNET_SCHEDULER_NO_TASK != die_task)
149   {
150       GNUNET_SCHEDULER_cancel (die_task);
151       die_task = GNUNET_SCHEDULER_NO_TASK;
152   }
153
154   if (NULL != dht_handle)
155   {
156     GNUNET_DHT_disconnect (dht_handle);
157     dht_handle = NULL;
158   }
159
160   if (sname == NULL)
161   {
162     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
163                 "shorten test failed!\n");
164     ok = 1;
165   }
166   else
167   {
168     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
169                 "%s shortened to %s\n", (char*)cls, sname);
170     if (0 != strcmp(sname, TEST_EXPECTED_RESULT))
171     {
172       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
173                   "shorten test failed! (wanted: %s got: %s\n",
174                   TEST_EXPECTED_RESULT, sname);
175       ok = 1;
176     }
177
178     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "shorten test succeeded!\n");
179   }
180   GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
181 }
182
183
184 static void
185 on_lookup_result(void *cls, uint32_t rd_count,
186                  const struct GNUNET_NAMESTORE_RecordData *rd)
187 {
188   struct in_addr a;
189   int i;
190   char* addr;
191   
192   if (rd_count == 0)
193   {
194     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
195                 "Lookup failed, rp_filtering?\n");
196     ok = 2;
197   }
198   else
199   {
200     ok = 1;
201     GNUNET_log (GNUNET_ERROR_TYPE_INFO, "name: %s\n", (char*)cls);
202     for (i=0; i<rd_count; i++)
203     {
204       GNUNET_log (GNUNET_ERROR_TYPE_INFO, "type: %d\n", rd[i].record_type);
205       if (rd[i].record_type == GNUNET_GNS_RECORD_A)
206       {
207         memcpy(&a, rd[i].data, sizeof(a));
208         addr = inet_ntoa(a);
209         GNUNET_log (GNUNET_ERROR_TYPE_INFO, "address: %s\n", addr);
210         if (0 == strcmp(addr, TEST_IP))
211         {
212           GNUNET_log (GNUNET_ERROR_TYPE_INFO,
213                     "%s correctly resolved to %s!\n", TEST_DOMAIN, addr);
214           ok = 0;
215         }
216       }
217       else
218       {
219         GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No resolution!\n");
220       }
221     }
222   }
223   GNUNET_GNS_shorten_zone (gns_handle, TEST_DOMAIN,
224                            &priv_zone,
225                            &short_zone,
226                            &our_zone,
227                            &process_shorten_result,
228                            TEST_DOMAIN);
229 }
230
231
232 /**
233  * Function scheduled to be run on the successful start of services
234  * tries to look up the dns record for TEST_DOMAIN
235  */
236 static void
237 commence_testing (void *cls, int success)
238 {
239   GNUNET_CRYPTO_ecc_key_free(our_key);
240   GNUNET_CRYPTO_ecc_key_free(bob_key);
241   GNUNET_CRYPTO_ecc_key_free(alice_key);
242   GNUNET_NAMESTORE_disconnect (namestore_handle);
243   namestore_handle = NULL;
244   gns_handle = GNUNET_GNS_connect(cfg);
245   if (NULL == gns_handle)
246   {
247     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
248                 "Failed to connect to GNS!\n");
249   }
250   GNUNET_GNS_lookup_zone (gns_handle, TEST_DOMAIN,
251                           &our_zone,
252                           GNUNET_GNS_RECORD_A,
253                           GNUNET_NO,
254                           short_key,
255                           &on_lookup_result, TEST_DOMAIN);
256 }
257
258
259 static void
260 put_pseu_dht (void *cls, int success)
261 {
262   struct GNSNameRecordBlock *nrb;
263   struct GNUNET_CRYPTO_ShortHashCode name_hash;
264   struct GNUNET_CRYPTO_ShortHashCode zone_hash;
265   struct GNUNET_HashCode xor_hash;
266   struct GNUNET_HashCode name_hash_double;
267   struct GNUNET_HashCode zone_hash_double;
268   uint32_t rd_payload_length;
269   char* nrb_data = NULL;
270   struct GNUNET_CRYPTO_EccSignature *sig;
271   struct GNUNET_NAMESTORE_RecordData rd;
272   
273   memset (&rd, 0, sizeof (struct GNUNET_NAMESTORE_RecordData));
274   rd.expiration_time = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value;
275   rd.data_size = strlen(TEST_PSEU_ALICE)+1;
276   rd.data = TEST_PSEU_ALICE;
277   rd.record_type = GNUNET_GNS_RECORD_PSEU;
278   rd.flags = 0;
279
280   sig = GNUNET_NAMESTORE_create_signature(alice_key,
281                                            GNUNET_TIME_UNIT_FOREVER_ABS,
282                                            GNUNET_GNS_MASTERZONE_STR,
283                                            &rd, 1);
284
285   GNUNET_assert (NULL != sig);
286
287   GNUNET_break (GNUNET_OK == GNUNET_NAMESTORE_verify_signature (&alice_pkey,
288                                                                  GNUNET_TIME_UNIT_FOREVER_ABS,
289                                                                  GNUNET_GNS_MASTERZONE_STR,
290                                                                  1,
291                                                                  &rd,
292                                                                  sig));
293   rd_payload_length = GNUNET_NAMESTORE_records_get_size (1, &rd);
294   nrb = GNUNET_malloc(rd_payload_length + strlen(GNUNET_GNS_MASTERZONE_STR) + 1
295                       + sizeof(struct GNSNameRecordBlock));
296   nrb->signature = *sig;
297   nrb->public_key = alice_pkey;
298   nrb->rd_count = htonl(1);
299   memset(&nrb[1], 0, strlen(GNUNET_GNS_MASTERZONE_STR) + 1);
300   strcpy((char*)&nrb[1], GNUNET_GNS_MASTERZONE_STR);
301   nrb_data = (char*)&nrb[1];
302   nrb_data += strlen(GNUNET_GNS_MASTERZONE_STR) + 1;
303
304   if (-1 == GNUNET_NAMESTORE_records_serialize (1,
305                                                 &rd,
306                                                 rd_payload_length,
307                                                 nrb_data))
308   {
309     GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Record serialization failed!\n");
310     ok = 3;
311     GNUNET_CRYPTO_ecc_key_free(our_key);
312     GNUNET_CRYPTO_ecc_key_free(bob_key);
313     GNUNET_CRYPTO_ecc_key_free(alice_key);
314     GNUNET_free(sig);
315     GNUNET_free (nrb);
316     end_badly_now ();
317     return;
318   }
319   GNUNET_CRYPTO_short_hash(GNUNET_GNS_MASTERZONE_STR, strlen(GNUNET_GNS_MASTERZONE_STR), &name_hash);
320   GNUNET_CRYPTO_short_hash(&alice_pkey,
321                      sizeof(struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded),
322                      &zone_hash);
323
324   GNUNET_CRYPTO_short_hash_double(&name_hash, &name_hash_double);
325   GNUNET_CRYPTO_short_hash_double(&zone_hash, &zone_hash_double);
326   GNUNET_CRYPTO_hash_xor(&zone_hash_double, &name_hash_double, &xor_hash);
327
328   rd_payload_length += sizeof(struct GNSNameRecordBlock) +
329     strlen(GNUNET_GNS_MASTERZONE_STR) + 1;
330
331   GNUNET_DHT_put (dht_handle, &xor_hash,
332                   0,
333                   GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
334                   GNUNET_BLOCK_TYPE_GNS_NAMERECORD,
335                   rd_payload_length,
336                   (char*)nrb,
337                   GNUNET_TIME_UNIT_FOREVER_ABS,
338                   DHT_OPERATION_TIMEOUT,
339                   &commence_testing,
340                   NULL);
341   
342   GNUNET_free(sig);
343   GNUNET_free (nrb);
344 }
345
346
347 static void
348 put_www_dht(void *cls, int success)
349 {
350   struct GNSNameRecordBlock *nrb;
351   struct GNUNET_CRYPTO_ShortHashCode name_hash;
352   struct GNUNET_CRYPTO_ShortHashCode zone_hash;
353   struct GNUNET_HashCode xor_hash;
354   struct GNUNET_HashCode name_hash_double;
355   struct GNUNET_HashCode zone_hash_double;
356   uint32_t rd_payload_length;
357   char* nrb_data = NULL;
358   struct GNUNET_CRYPTO_EccSignature *sig;
359   struct GNUNET_NAMESTORE_RecordData rd;
360   char* ip = TEST_IP;
361   struct in_addr *web = GNUNET_malloc(sizeof(struct in_addr));
362   
363   rd.expiration_time = UINT64_MAX;
364   GNUNET_assert(1 == inet_pton (AF_INET, ip, web));
365   rd.data_size = sizeof(struct in_addr);
366   rd.data = web;
367   rd.record_type = GNUNET_DNSPARSER_TYPE_A;
368   rd.flags = GNUNET_NAMESTORE_RF_AUTHORITY;
369   
370   sig = GNUNET_NAMESTORE_create_signature(alice_key,
371                                           GNUNET_TIME_UNIT_FOREVER_ABS,
372                                           TEST_RECORD_NAME,
373                                           &rd, 1);
374   
375   GNUNET_break (GNUNET_OK == GNUNET_NAMESTORE_verify_signature (&alice_pkey,
376                                                                  GNUNET_TIME_UNIT_FOREVER_ABS,
377                                                                  TEST_RECORD_NAME,
378                                                                  1,
379                                                                  &rd,
380                                                                  sig));
381   rd_payload_length = GNUNET_NAMESTORE_records_get_size (1, &rd);
382   nrb = GNUNET_malloc(rd_payload_length + strlen(TEST_RECORD_NAME) + 1
383                       + sizeof(struct GNSNameRecordBlock));
384   nrb->signature = *sig;
385   nrb->public_key = alice_pkey;
386   nrb->rd_count = htonl(1);
387   memset(&nrb[1], 0, strlen(TEST_RECORD_NAME) + 1);
388   strcpy((char*)&nrb[1], TEST_RECORD_NAME);
389   nrb_data = (char*)&nrb[1];
390   nrb_data += strlen(TEST_RECORD_NAME) + 1;
391
392   if (-1 == GNUNET_NAMESTORE_records_serialize (1,
393                                                 &rd,
394                                                 rd_payload_length,
395                                                 nrb_data))
396   {
397     GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Record serialization failed!\n");
398     ok = 3;
399     GNUNET_CRYPTO_ecc_key_free(our_key);
400     GNUNET_CRYPTO_ecc_key_free(bob_key);
401     GNUNET_CRYPTO_ecc_key_free(alice_key);
402     GNUNET_free (sig);
403     GNUNET_free(web);
404     GNUNET_free (nrb);
405     end_badly_now();
406     return;
407   }
408   GNUNET_CRYPTO_short_hash(TEST_RECORD_NAME, strlen(TEST_RECORD_NAME), &name_hash);
409   GNUNET_CRYPTO_short_hash(&alice_pkey,
410                      sizeof(struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded),
411                      &zone_hash);
412   GNUNET_CRYPTO_short_hash_double(&zone_hash, &zone_hash_double);
413   GNUNET_CRYPTO_short_hash_double(&name_hash, &name_hash_double);
414   GNUNET_CRYPTO_hash_xor(&zone_hash_double, &name_hash_double, &xor_hash);
415
416   rd_payload_length += sizeof(struct GNSNameRecordBlock) +
417     strlen(TEST_RECORD_NAME) + 1;
418
419   GNUNET_DHT_put (dht_handle, &xor_hash,
420                   0,
421                   GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
422                   GNUNET_BLOCK_TYPE_GNS_NAMERECORD,
423                   rd_payload_length,
424                   (char*)nrb,
425                   GNUNET_TIME_UNIT_FOREVER_ABS,
426                   DHT_OPERATION_TIMEOUT,
427                   &put_pseu_dht,
428                   NULL);
429   GNUNET_free (sig);
430   GNUNET_free (web);
431   GNUNET_free (nrb);
432 }
433
434
435 static void
436 put_pkey_dht(void *cls, int32_t success, const char *emsg)
437 {
438   struct GNSNameRecordBlock *nrb;
439   struct GNUNET_CRYPTO_ShortHashCode name_hash;
440   struct GNUNET_CRYPTO_ShortHashCode zone_hash;
441   struct GNUNET_HashCode xor_hash;
442   struct GNUNET_HashCode name_hash_double;
443   struct GNUNET_HashCode zone_hash_double;
444   uint32_t rd_payload_length;
445   char* nrb_data = NULL;
446   struct GNUNET_CRYPTO_EccSignature *sig;
447   struct GNUNET_NAMESTORE_RecordData rd;
448   
449   rd.expiration_time = UINT64_MAX;
450   rd.data_size = sizeof(struct GNUNET_CRYPTO_ShortHashCode);
451   rd.data = &alice_hash;
452   rd.record_type = GNUNET_GNS_RECORD_PKEY;
453   rd.flags = GNUNET_NAMESTORE_RF_AUTHORITY;
454   
455   sig = GNUNET_NAMESTORE_create_signature(bob_key,
456                                           GNUNET_TIME_UNIT_FOREVER_ABS,
457                                           TEST_AUTHORITY_ALICE,
458                                           &rd,
459                                           1);
460
461   rd_payload_length = GNUNET_NAMESTORE_records_get_size (1, &rd);
462   nrb = GNUNET_malloc(rd_payload_length + strlen(TEST_AUTHORITY_ALICE) + 1
463                       + sizeof(struct GNSNameRecordBlock));
464   nrb->signature = *sig;
465   nrb->public_key = bob_pkey;
466   nrb->rd_count = htonl(1);
467   memset(&nrb[1], 0, strlen(TEST_AUTHORITY_ALICE) + 1);
468   strcpy((char*)&nrb[1], TEST_AUTHORITY_ALICE);
469   nrb_data = (char*)&nrb[1];
470   nrb_data += strlen(TEST_AUTHORITY_ALICE) + 1;
471
472   if (-1 == GNUNET_NAMESTORE_records_serialize (1,
473                                                 &rd,
474                                                 rd_payload_length,
475                                                 nrb_data))
476   {
477     GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Record serialization failed!\n");
478     ok = 3;
479     
480     GNUNET_CRYPTO_ecc_key_free (our_key);
481     GNUNET_CRYPTO_ecc_key_free (bob_key);
482     GNUNET_CRYPTO_ecc_key_free (alice_key);
483     GNUNET_free (sig);
484     GNUNET_free (nrb);
485     end_badly_now ();
486     return;
487   }
488
489
490   GNUNET_CRYPTO_short_hash(TEST_AUTHORITY_ALICE,
491                      strlen(TEST_AUTHORITY_ALICE), &name_hash);
492   GNUNET_CRYPTO_short_hash(&bob_pkey,
493                      sizeof(struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded),
494                      &zone_hash);
495   GNUNET_CRYPTO_short_hash_double(&zone_hash, &zone_hash_double);
496   GNUNET_CRYPTO_short_hash_double(&name_hash, &name_hash_double);
497   GNUNET_CRYPTO_hash_xor(&zone_hash_double, &name_hash_double, &xor_hash); 
498
499   rd_payload_length += sizeof(struct GNSNameRecordBlock) +
500     strlen(TEST_AUTHORITY_ALICE) + 1;
501   GNUNET_DHT_put (dht_handle, &xor_hash,
502                   0,
503                   GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
504                   GNUNET_BLOCK_TYPE_GNS_NAMERECORD,
505                   rd_payload_length,
506                   (char*)nrb,
507                   GNUNET_TIME_UNIT_FOREVER_ABS,
508                   DHT_OPERATION_TIMEOUT,
509                   &put_www_dht,
510                   NULL);
511   GNUNET_free (sig);
512   GNUNET_free (nrb);
513 }
514
515
516 static void
517 fin_init_zone (void *cls, int32_t success, const char *emsg)
518 {
519   struct GNUNET_NAMESTORE_RecordData rd;
520   rd.expiration_time = UINT64_MAX;
521   rd.data_size = sizeof(struct GNUNET_CRYPTO_ShortHashCode);
522   rd.data = &bob_hash;
523   rd.record_type = GNUNET_GNS_RECORD_PKEY;
524   rd.flags = GNUNET_NAMESTORE_RF_AUTHORITY;
525   
526   GNUNET_NAMESTORE_record_create (namestore_handle,
527                                   our_key,
528                                   TEST_AUTHORITY_BOB,
529                                   &rd,
530                                   &put_pkey_dht,
531                                   NULL);
532
533 }
534
535 static void
536 cont_init_zone (void *cls, int32_t success, const char *emsg)
537 {
538
539   struct GNUNET_NAMESTORE_RecordData rd;
540   rd.expiration_time = UINT64_MAX;
541   rd.data_size = sizeof(struct GNUNET_CRYPTO_ShortHashCode);
542   rd.data = &short_zone;
543   rd.record_type = GNUNET_GNS_RECORD_PKEY;
544   rd.flags = GNUNET_NAMESTORE_RF_AUTHORITY;
545
546   GNUNET_NAMESTORE_record_create (namestore_handle,
547                                   priv_key,
548                                   TEST_SHORTEN_ZONE,
549                                   &rd,
550                                   &fin_init_zone,
551                                   NULL);
552 }
553
554
555 static void
556 do_check (void *cls,
557           const struct GNUNET_CONFIGURATION_Handle *ccfg,
558           struct GNUNET_TESTING_Peer *peer)
559 {
560   char* private_keyfile;
561   char* shorten_keyfile;
562   char* our_keyfile;
563   
564   cfg = ccfg;
565   die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
566
567   /* put records into namestore */
568   namestore_handle = GNUNET_NAMESTORE_connect(cfg);
569   if (NULL == namestore_handle)
570   {
571     GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to connect to namestore\n");
572     end_badly_now();
573     return;
574   }
575   
576   /* dht */
577   dht_handle = GNUNET_DHT_connect(cfg, 1);
578   if (NULL == dht_handle)
579   {
580     GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to connect to dht\n");
581     end_badly_now();
582     return;
583   }
584
585   if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns",
586                                                           "ZONEKEY",
587                                                           &our_keyfile))
588   {
589     GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to get key from cfg\n");
590     end_badly_now();
591     return;
592   }
593   
594   if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns",
595                                                           "SHORTEN_ZONEKEY",
596                                                           &shorten_keyfile))
597   {
598     GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
599                "Failed to get shorten zone key from cfg\n");
600     end_badly_now();
601     return;
602   }
603   
604   if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns",
605                                                           "PRIVATE_ZONEKEY",
606                                                           &private_keyfile))
607   {
608     GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
609                "Failed to get private zone key from cfg\n");
610     end_badly_now();
611     return;
612   }
613   our_key = GNUNET_CRYPTO_ecc_key_create_from_file (our_keyfile);
614   priv_key = GNUNET_CRYPTO_ecc_key_create_from_file (private_keyfile);
615   short_key = GNUNET_CRYPTO_ecc_key_create_from_file (shorten_keyfile);
616   bob_key = GNUNET_CRYPTO_ecc_key_create_from_file (KEYFILE_BOB);
617   alice_key = GNUNET_CRYPTO_ecc_key_create_from_file (KEYFILE_ALICE);
618   
619   GNUNET_free(our_keyfile);
620   GNUNET_free(shorten_keyfile);
621   GNUNET_free(private_keyfile);
622
623   GNUNET_CRYPTO_ecc_key_get_public (our_key, &our_pkey);
624   GNUNET_CRYPTO_ecc_key_get_public (priv_key, &priv_pkey);
625   GNUNET_CRYPTO_ecc_key_get_public (short_key, &short_pkey);
626   GNUNET_CRYPTO_ecc_key_get_public (bob_key, &bob_pkey);
627   GNUNET_CRYPTO_ecc_key_get_public (alice_key, &alice_pkey);
628   GNUNET_CRYPTO_short_hash(&bob_pkey, sizeof(bob_pkey), &bob_hash);
629   GNUNET_CRYPTO_short_hash(&alice_pkey, sizeof(alice_pkey), &alice_hash);
630   GNUNET_CRYPTO_short_hash(&our_pkey, sizeof(our_pkey), &our_zone);
631   GNUNET_CRYPTO_short_hash(&priv_pkey, sizeof(priv_pkey), &priv_zone);
632   GNUNET_CRYPTO_short_hash(&short_pkey, sizeof(short_pkey), &short_zone);
633   
634   struct GNUNET_NAMESTORE_RecordData rd;
635   rd.expiration_time = UINT64_MAX;
636   rd.data_size = sizeof(struct GNUNET_CRYPTO_ShortHashCode);
637   rd.data = &priv_zone;
638   rd.record_type = GNUNET_GNS_RECORD_PKEY;
639   rd.flags = GNUNET_NAMESTORE_RF_AUTHORITY;
640
641   GNUNET_NAMESTORE_record_create (namestore_handle,
642                                   our_key,
643                                   TEST_PRIVATE_ZONE,
644                                   &rd,
645                                   &cont_init_zone,
646                                   NULL);
647 }
648
649
650 int
651 main (int argc, char *argv[])
652 {
653   ok = 1;
654   GNUNET_log_setup ("test-gns-pseu-shorten",
655                     "WARNING",
656                     NULL);
657   GNUNET_TESTING_peer_run ("test-gns-pseu-shorten", "test_gns_simple_lookup.conf", &do_check, NULL);
658   return ok;
659 }
660
661 /* end of test_gns_pseu_shorten.c */