aboutsummaryrefslogtreecommitdiff
path: root/src/namestore/gnunet-namestore.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-08-12 19:09:52 +0000
committerChristian Grothoff <christian@grothoff.org>2013-08-12 19:09:52 +0000
commit5e05019536c0d38bf20f965613636f21ae7c2be6 (patch)
treeeda1dee12e49c010171462d618162d28b21c9c6a /src/namestore/gnunet-namestore.c
parent566dfe32be22ed1f071b974be3c4dd8bc5721151 (diff)
downloadgnunet-5e05019536c0d38bf20f965613636f21ae7c2be6.tar.gz
gnunet-5e05019536c0d38bf20f965613636f21ae7c2be6.zip
-towards namestore support for the new privacy-preserving GNS queries
Diffstat (limited to 'src/namestore/gnunet-namestore.c')
-rw-r--r--src/namestore/gnunet-namestore.c160
1 files changed, 61 insertions, 99 deletions
diff --git a/src/namestore/gnunet-namestore.c b/src/namestore/gnunet-namestore.c
index d0f68b78e..4f6eeb435 100644
--- a/src/namestore/gnunet-namestore.c
+++ b/src/namestore/gnunet-namestore.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 (C) 2012 Christian Grothoff (and other contributing authors) 3 (C) 2012, 2013 Christian Grothoff (and other contributing authors)
4 4
5 GNUnet is free software; you can redistribute it and/or modify 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 6 it under the terms of the GNU General Public License as published
@@ -39,17 +39,12 @@
39static struct GNUNET_NAMESTORE_Handle *ns; 39static struct GNUNET_NAMESTORE_Handle *ns;
40 40
41/** 41/**
42 * Hash of the public key of our zone.
43 */
44static struct GNUNET_CRYPTO_ShortHashCode zone;
45
46/**
47 * Private key for the our zone. 42 * Private key for the our zone.
48 */ 43 */
49static struct GNUNET_CRYPTO_EccPrivateKey *zone_pkey; 44static struct GNUNET_CRYPTO_EccPrivateKey *zone_pkey;
50 45
51/** 46/**
52 * Keyfile to manipulate. 47 * Keyfile to manipulate. FIXME: change to ego's name!
53 */ 48 */
54static char *keyfile; 49static char *keyfile;
55 50
@@ -59,9 +54,9 @@ static char *keyfile;
59static int add; 54static int add;
60 55
61/** 56/**
62 * Queue entry for the 'add' operation. 57 * Iterator for the 'add' operation.
63 */ 58 */
64static struct GNUNET_NAMESTORE_QueueEntry *add_qe; 59static struct GNUNET_NAMESTORE_ZoneIterator *add_zit;
65 60
66/** 61/**
67 * Queue entry for the 'add-uri' operation. 62 * Queue entry for the 'add-uri' operation.
@@ -69,6 +64,11 @@ static struct GNUNET_NAMESTORE_QueueEntry *add_qe;
69static struct GNUNET_NAMESTORE_QueueEntry *add_qe_uri; 64static struct GNUNET_NAMESTORE_QueueEntry *add_qe_uri;
70 65
71/** 66/**
67 * Queue entry for the 'add' operation.
68 */
69static struct GNUNET_NAMESTORE_QueueEntry *add_qe;
70
71/**
72 * Desired action is to list records. 72 * Desired action is to list records.
73 */ 73 */
74static int list; 74static int list;
@@ -168,6 +168,7 @@ static struct GNUNET_NAMESTORE_ZoneMonitor *zm;
168 */ 168 */
169static int monitor; 169static int monitor;
170 170
171
171/** 172/**
172 * Task run on shutdown. Cleans up everything. 173 * Task run on shutdown. Cleans up everything.
173 * 174 *
@@ -291,33 +292,21 @@ del_continuation (void *cls,
291 * Process a record that was stored in the namestore. 292 * Process a record that was stored in the namestore.
292 * 293 *
293 * @param cls closure 294 * @param cls closure
294 * @param zone_key public key of the zone 295 * @param zone_key private key of the zone
295 * @param expire when does the corresponding block in the DHT expire (until
296 * when should we never do a DHT lookup for the same name again)?;
297 * GNUNET_TIME_UNIT_ZERO_ABS if there are no records of any type in the namestore,
298 * or the expiration time of the block in the namestore (even if there are zero
299 * records matching the desired record type)
300 * @param name name that is being mapped (at most 255 characters long) 296 * @param name name that is being mapped (at most 255 characters long)
301 * @param rd_len number of entries in 'rd' array 297 * @param rd_len number of entries in 'rd' array
302 * @param rd array of records with data to store 298 * @param rd array of records with data to store
303 * @param signature signature of the record block, NULL if signature is unavailable (i.e.
304 * because the user queried for a particular record type only)
305 */ 299 */
306static void 300static void
307display_record (void *cls, 301display_record (void *cls,
308 const struct GNUNET_CRYPTO_EccPublicKey *zone_key, 302 const struct GNUNET_CRYPTO_EccPrivateKey *zone_key,
309 struct GNUNET_TIME_Absolute expire,
310 const char *name, 303 const char *name,
311 unsigned int rd_len, 304 unsigned int rd_len,
312 const struct GNUNET_NAMESTORE_RecordData *rd, 305 const struct GNUNET_NAMESTORE_RecordData *rd)
313 const struct GNUNET_CRYPTO_EccSignature *signature)
314{ 306{
315 const char *typestring; 307 const char *typestring;
316 char *s; 308 char *s;
317 unsigned int i; 309 unsigned int i;
318 const char *etime;
319 struct GNUNET_TIME_Absolute aex;
320 struct GNUNET_TIME_Relative rex;
321 310
322 if (NULL == name) 311 if (NULL == name)
323 { 312 {
@@ -343,21 +332,10 @@ display_record (void *cls,
343 (unsigned int) rd[i].record_type); 332 (unsigned int) rd[i].record_type);
344 continue; 333 continue;
345 } 334 }
346 if (0 != (rd[i].flags & GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION)) 335 FPRINTF (stdout,
347 { 336 "\t%s: %s\n",
348 rex.rel_value_us = rd[i].expiration_time; 337 typestring,
349 etime = GNUNET_STRINGS_relative_time_to_string (rex, GNUNET_YES); 338 s);
350 }
351 else
352 {
353 aex.abs_value_us = rd[i].expiration_time;
354 etime = GNUNET_STRINGS_absolute_time_to_string (aex);
355 }
356 FPRINTF (stdout, "\t%s: %s (%s %s)\n", typestring, s,
357 (0 != (rd[i].flags & GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION))
358 ? _(/* what follows is relative expiration */ "for at least")
359 : _(/* what follows is absolute expiration */ "until"),
360 etime);
361 GNUNET_free (s); 339 GNUNET_free (s);
362 } 340 }
363 FPRINTF (stdout, "%s", "\n"); 341 FPRINTF (stdout, "%s", "\n");
@@ -382,31 +360,27 @@ sync_cb (void *cls)
382 * so that we can merge the information. 360 * so that we can merge the information.
383 * 361 *
384 * @param cls closure, unused 362 * @param cls closure, unused
385 * @param zone_key public key of the zone 363 * @param zone_key private key of the zone
386 * @param freshness when does the corresponding block in the DHT expire (until
387 * when should we never do a DHT lookup for the same name again)?;
388 * GNUNET_TIME_UNIT_ZERO_ABS if there are no records of any type in the namestore,
389 * or the expiration time of the block in the namestore (even if there are zero
390 * records matching the desired record type)
391 * @param rec_name name that is being mapped (at most 255 characters long) 364 * @param rec_name name that is being mapped (at most 255 characters long)
392 * @param rd_count number of entries in 'rd' array 365 * @param rd_count number of entries in 'rd' array
393 * @param rd array of records with data to store 366 * @param rd array of records with data to store
394 * @param signature signature of the record block, NULL if signature is unavailable (i.e.
395 * because the user queried for a particular record type only)
396 */ 367 */
397static void 368static void
398get_existing_record (void *cls, 369get_existing_record (void *cls,
399 const struct GNUNET_CRYPTO_EccPublicKey *zone_key, 370 const struct GNUNET_CRYPTO_EccPrivateKey *zone_key,
400 struct GNUNET_TIME_Absolute freshness,
401 const char *rec_name, 371 const char *rec_name,
402 unsigned int rd_count, 372 unsigned int rd_count,
403 const struct GNUNET_NAMESTORE_RecordData *rd, 373 const struct GNUNET_NAMESTORE_RecordData *rd)
404 const struct GNUNET_CRYPTO_EccSignature *signature)
405{ 374{
406 struct GNUNET_NAMESTORE_RecordData rdn[rd_count + 1]; 375 struct GNUNET_NAMESTORE_RecordData rdn[rd_count + 1];
407 struct GNUNET_NAMESTORE_RecordData *rde; 376 struct GNUNET_NAMESTORE_RecordData *rde;
408 377
409 add_qe = NULL; 378 if ( (NULL != zone_key) &&
379 (0 != strcmp (rec_name, name)) )
380 {
381 GNUNET_NAMESTORE_zone_iterator_next (add_zit);
382 return;
383 }
410 memset (rdn, 0, sizeof (struct GNUNET_NAMESTORE_RecordData)); 384 memset (rdn, 0, sizeof (struct GNUNET_NAMESTORE_RecordData));
411 memcpy (&rdn[1], rd, rd_count * sizeof (struct GNUNET_NAMESTORE_RecordData)); 385 memcpy (&rdn[1], rd, rd_count * sizeof (struct GNUNET_NAMESTORE_RecordData));
412 /* FIXME: should add some logic to overwrite records if there 386 /* FIXME: should add some logic to overwrite records if there
@@ -416,27 +390,20 @@ get_existing_record (void *cls,
416 rde->data = data; 390 rde->data = data;
417 rde->data_size = data_size; 391 rde->data_size = data_size;
418 rde->record_type = type; 392 rde->record_type = type;
419 if (GNUNET_YES == etime_is_rel)
420 {
421 rde->expiration_time = etime_rel.rel_value_us;
422 rde->flags |= GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION;
423 }
424 else if (GNUNET_NO == etime_is_rel)
425 {
426 rde->expiration_time = etime_abs.abs_value_us;
427 }
428 if (1 != nonauthority) 393 if (1 != nonauthority)
429 rde->flags |= GNUNET_NAMESTORE_RF_AUTHORITY; 394 rde->flags |= GNUNET_NAMESTORE_RF_AUTHORITY;
430 if (1 != public) 395 if (1 != public)
431 rde->flags |= GNUNET_NAMESTORE_RF_PRIVATE; 396 rde->flags |= GNUNET_NAMESTORE_RF_PRIVATE;
432 GNUNET_assert (NULL != name); 397 GNUNET_assert (NULL != name);
433 add_qe = GNUNET_NAMESTORE_record_put_by_authority (ns, 398 add_qe = GNUNET_NAMESTORE_records_store (ns,
434 zone_pkey, 399 zone_pkey,
435 name, 400 name,
436 rd_count + 1, 401 rd_count + 1,
437 rde, 402 rde,
438 &add_continuation, 403 &add_continuation,
439 &add_qe); 404 &add_qe);
405 GNUNET_NAMESTORE_zone_iteration_stop (add_zit);
406 add_zit = NULL;
440} 407}
441 408
442 409
@@ -494,7 +461,6 @@ testservice_task (void *cls,
494 } 461 }
495 GNUNET_CRYPTO_ecc_key_get_public (zone_pkey, 462 GNUNET_CRYPTO_ecc_key_get_public (zone_pkey,
496 &pub); 463 &pub);
497 GNUNET_CRYPTO_short_hash (&pub, sizeof (pub), &zone);
498 464
499 ns = GNUNET_NAMESTORE_connect (cfg); 465 ns = GNUNET_NAMESTORE_connect (cfg);
500 if (NULL == ns) 466 if (NULL == ns)
@@ -590,12 +556,10 @@ testservice_task (void *cls,
590 ret = 1; 556 ret = 1;
591 return; 557 return;
592 } 558 }
593 add_qe = GNUNET_NAMESTORE_lookup_record (ns, 559 add_zit = GNUNET_NAMESTORE_zone_iteration_start (ns,
594 &zone, 560 zone_pkey,
595 name, 561 &get_existing_record,
596 0, 562 NULL);
597 &get_existing_record,
598 NULL);
599 } 563 }
600 if (del) 564 if (del)
601 { 565 {
@@ -608,12 +572,12 @@ testservice_task (void *cls,
608 ret = 1; 572 ret = 1;
609 return; 573 return;
610 } 574 }
611 del_qe = GNUNET_NAMESTORE_record_put_by_authority (ns, 575 del_qe = GNUNET_NAMESTORE_records_store (ns,
612 zone_pkey, 576 zone_pkey,
613 name, 577 name,
614 0, NULL, 578 0, NULL,
615 &del_continuation, 579 &del_continuation,
616 NULL); 580 NULL);
617 } 581 }
618 if (list) 582 if (list)
619 { 583 {
@@ -626,24 +590,22 @@ testservice_task (void *cls,
626 must_not_flags |= GNUNET_NAMESTORE_RF_PRIVATE; 590 must_not_flags |= GNUNET_NAMESTORE_RF_PRIVATE;
627 591
628 list_it = GNUNET_NAMESTORE_zone_iteration_start (ns, 592 list_it = GNUNET_NAMESTORE_zone_iteration_start (ns,
629 &zone, 593 zone_pkey,
630 GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION,
631 must_not_flags,
632 &display_record, 594 &display_record,
633 NULL); 595 NULL);
634 } 596 }
635 if (NULL != uri) 597 if (NULL != uri)
636 { 598 {
637 char sh[53]; 599 char sh[105];
638 char sname[64]; 600 char sname[64];
639 struct GNUNET_CRYPTO_ShortHashCode sc; 601 struct GNUNET_CRYPTO_EccPublicKey pkey;
640 602
641 if ( (2 != (sscanf (uri, 603 if ( (2 != (sscanf (uri,
642 "gnunet://gns/%52s/%63s", 604 "gnunet://gns/%104s/%63s",
643 sh, 605 sh,
644 sname)) ) || 606 sname)) ) ||
645 (GNUNET_OK != 607 (GNUNET_OK !=
646 GNUNET_CRYPTO_short_hash_from_string (sh, &sc)) ) 608 GNUNET_CRYPTO_ecc_public_key_from_string (sh, strlen (sh), &pkey)) )
647 { 609 {
648 fprintf (stderr, 610 fprintf (stderr,
649 _("Invalid URI `%s'\n"), 611 _("Invalid URI `%s'\n"),
@@ -653,8 +615,8 @@ testservice_task (void *cls,
653 return; 615 return;
654 } 616 }
655 memset (&rd, 0, sizeof (rd)); 617 memset (&rd, 0, sizeof (rd));
656 rd.data = &sc; 618 rd.data = &pkey;
657 rd.data_size = sizeof (struct GNUNET_CRYPTO_ShortHashCode); 619 rd.data_size = sizeof (struct GNUNET_CRYPTO_EccPublicKey);
658 rd.record_type = GNUNET_NAMESTORE_TYPE_PKEY; 620 rd.record_type = GNUNET_NAMESTORE_TYPE_PKEY;
659 if (GNUNET_YES == etime_is_rel) 621 if (GNUNET_YES == etime_is_rel)
660 { 622 {
@@ -667,18 +629,18 @@ testservice_task (void *cls,
667 rd.expiration_time = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us; 629 rd.expiration_time = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us;
668 if (1 != nonauthority) 630 if (1 != nonauthority)
669 rd.flags |= GNUNET_NAMESTORE_RF_AUTHORITY; 631 rd.flags |= GNUNET_NAMESTORE_RF_AUTHORITY;
670 add_qe_uri = GNUNET_NAMESTORE_record_put_by_authority (ns, 632 add_qe_uri = GNUNET_NAMESTORE_records_store (ns,
671 zone_pkey, 633 zone_pkey,
672 sname, 634 sname,
673 1, 635 1,
674 &rd, 636 &rd,
675 &add_continuation, 637 &add_continuation,
676 &add_qe_uri); 638 &add_qe_uri);
677 } 639 }
678 if (monitor) 640 if (monitor)
679 { 641 {
680 zm = GNUNET_NAMESTORE_zone_monitor_start (cfg, 642 zm = GNUNET_NAMESTORE_zone_monitor_start (cfg,
681 &zone, 643 zone_pkey,
682 &display_record, 644 &display_record,
683 &sync_cb, 645 &sync_cb,
684 NULL); 646 NULL);