diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2012-03-19 17:11:46 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2012-03-19 17:11:46 +0000 |
commit | 5a943624e2634d632ee2bf3a78c25b0aeae3813e (patch) | |
tree | e1fb2539304003d54d0d1e6ea0fdfd3730eb697c /src/namestore/plugin_namestore_sqlite.c | |
parent | 34243a1a0c04ef5723a327124f96e2571ac5fd2e (diff) | |
download | gnunet-5a943624e2634d632ee2bf3a78c25b0aeae3813e.tar.gz gnunet-5a943624e2634d632ee2bf3a78c25b0aeae3813e.zip |
- usage of short hashes
Diffstat (limited to 'src/namestore/plugin_namestore_sqlite.c')
-rw-r--r-- | src/namestore/plugin_namestore_sqlite.c | 57 |
1 files changed, 28 insertions, 29 deletions
diff --git a/src/namestore/plugin_namestore_sqlite.c b/src/namestore/plugin_namestore_sqlite.c index 39cd185fc..45fad545c 100644 --- a/src/namestore/plugin_namestore_sqlite.c +++ b/src/namestore/plugin_namestore_sqlite.c | |||
@@ -397,19 +397,18 @@ database_shutdown (struct Plugin *plugin) | |||
397 | */ | 397 | */ |
398 | static int | 398 | static int |
399 | namestore_sqlite_remove_records (void *cls, | 399 | namestore_sqlite_remove_records (void *cls, |
400 | const GNUNET_HashCode *zone, | 400 | const struct GNUNET_CRYPTO_ShortHashCode *zone, |
401 | const char *name) | 401 | const char *name) |
402 | { | 402 | { |
403 | struct Plugin *plugin = cls; | 403 | struct Plugin *plugin = cls; |
404 | GNUNET_HashCode nh; | 404 | struct GNUNET_CRYPTO_ShortHashCode nh; |
405 | size_t name_len; | 405 | size_t name_len; |
406 | int n; | 406 | int n; |
407 | |||
408 | name_len = strlen (name); | 407 | name_len = strlen (name); |
409 | GNUNET_CRYPTO_hash (name, name_len, &nh); | 408 | GNUNET_CRYPTO_short_hash (name, name_len, &nh); |
410 | 409 | ||
411 | if ((SQLITE_OK != sqlite3_bind_blob (plugin->remove_records, 1, zone, sizeof (GNUNET_HashCode), SQLITE_STATIC)) || | 410 | if ((SQLITE_OK != sqlite3_bind_blob (plugin->remove_records, 1, zone, sizeof (struct GNUNET_CRYPTO_ShortHashCode), SQLITE_STATIC)) || |
412 | (SQLITE_OK != sqlite3_bind_blob (plugin->remove_records, 2, &nh, sizeof (GNUNET_HashCode), SQLITE_STATIC))) | 411 | (SQLITE_OK != sqlite3_bind_blob (plugin->remove_records, 2, &nh, sizeof (struct GNUNET_CRYPTO_ShortHashCode), SQLITE_STATIC))) |
413 | { | 412 | { |
414 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 413 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
415 | "sqlite3_bind_XXXX"); | 414 | "sqlite3_bind_XXXX"); |
@@ -466,26 +465,26 @@ namestore_sqlite_put_records (void *cls, | |||
466 | { | 465 | { |
467 | struct Plugin *plugin = cls; | 466 | struct Plugin *plugin = cls; |
468 | int n; | 467 | int n; |
469 | GNUNET_HashCode zone; | 468 | struct GNUNET_CRYPTO_ShortHashCode zone; |
470 | GNUNET_HashCode zone_delegation; | 469 | struct GNUNET_CRYPTO_ShortHashCode zone_delegation; |
471 | GNUNET_HashCode nh; | 470 | struct GNUNET_CRYPTO_ShortHashCode nh; |
472 | size_t name_len; | 471 | size_t name_len; |
473 | uint64_t rvalue; | 472 | uint64_t rvalue; |
474 | size_t data_size; | 473 | size_t data_size; |
475 | unsigned int i; | 474 | unsigned int i; |
476 | 475 | ||
477 | GNUNET_CRYPTO_hash (zone_key, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &zone); | 476 | GNUNET_CRYPTO_short_hash (zone_key, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &zone); |
478 | (void) namestore_sqlite_remove_records (plugin, &zone, name); | 477 | (void) namestore_sqlite_remove_records (plugin, &zone, name); |
479 | name_len = strlen (name); | 478 | name_len = strlen (name); |
480 | GNUNET_CRYPTO_hash (name, name_len, &nh); | 479 | GNUNET_CRYPTO_short_hash (name, name_len, &nh); |
481 | memset (&zone_delegation, 0, sizeof (zone_delegation)); | 480 | memset (&zone_delegation, 0, sizeof (zone_delegation)); |
482 | for (i=0;i<rd_count;i++) | 481 | for (i=0;i<rd_count;i++) |
483 | if (rd[i].record_type == GNUNET_NAMESTORE_TYPE_PKEY) | 482 | if (rd[i].record_type == GNUNET_NAMESTORE_TYPE_PKEY) |
484 | { | 483 | { |
485 | GNUNET_assert (sizeof (GNUNET_HashCode) == rd[i].data_size); | 484 | GNUNET_assert (sizeof (struct GNUNET_CRYPTO_ShortHashCode) == rd[i].data_size); |
486 | memcpy (&zone_delegation, | 485 | memcpy (&zone_delegation, |
487 | rd[i].data, | 486 | rd[i].data, |
488 | sizeof (GNUNET_HashCode)); | 487 | sizeof (struct GNUNET_CRYPTO_ShortHashCode)); |
489 | break; | 488 | break; |
490 | } | 489 | } |
491 | rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX); | 490 | rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX); |
@@ -510,9 +509,9 @@ namestore_sqlite_put_records (void *cls, | |||
510 | (SQLITE_OK != sqlite3_bind_blob (plugin->put_records, 4, data, data_size, SQLITE_STATIC)) || | 509 | (SQLITE_OK != sqlite3_bind_blob (plugin->put_records, 4, data, data_size, SQLITE_STATIC)) || |
511 | (SQLITE_OK != sqlite3_bind_int64 (plugin->put_records, 5, expire.abs_value)) || | 510 | (SQLITE_OK != sqlite3_bind_int64 (plugin->put_records, 5, expire.abs_value)) || |
512 | (SQLITE_OK != sqlite3_bind_blob (plugin->put_records, 6, signature, sizeof (struct GNUNET_CRYPTO_RsaSignature), SQLITE_STATIC)) || | 511 | (SQLITE_OK != sqlite3_bind_blob (plugin->put_records, 6, signature, sizeof (struct GNUNET_CRYPTO_RsaSignature), SQLITE_STATIC)) || |
513 | (SQLITE_OK != sqlite3_bind_blob (plugin->put_records, 7, &zone_delegation, sizeof (GNUNET_HashCode), SQLITE_STATIC)) || | 512 | (SQLITE_OK != sqlite3_bind_blob (plugin->put_records, 7, &zone_delegation, sizeof (struct GNUNET_CRYPTO_ShortHashCode), SQLITE_STATIC)) || |
514 | (SQLITE_OK != sqlite3_bind_blob (plugin->put_records, 8, &zone, sizeof (GNUNET_HashCode), SQLITE_STATIC)) || | 513 | (SQLITE_OK != sqlite3_bind_blob (plugin->put_records, 8, &zone, sizeof (struct GNUNET_CRYPTO_ShortHashCode), SQLITE_STATIC)) || |
515 | (SQLITE_OK != sqlite3_bind_blob (plugin->put_records, 9, &nh, sizeof (GNUNET_HashCode), SQLITE_STATIC)) || | 514 | (SQLITE_OK != sqlite3_bind_blob (plugin->put_records, 9, &nh, sizeof (struct GNUNET_CRYPTO_ShortHashCode), SQLITE_STATIC)) || |
516 | (SQLITE_OK != sqlite3_bind_int64 (plugin->put_records, 10, rvalue)) ) | 515 | (SQLITE_OK != sqlite3_bind_int64 (plugin->put_records, 10, rvalue)) ) |
517 | { | 516 | { |
518 | LOG_SQLITE (plugin, | 517 | LOG_SQLITE (plugin, |
@@ -638,14 +637,14 @@ get_record_and_call_iterator (struct Plugin *plugin, | |||
638 | */ | 637 | */ |
639 | static int | 638 | static int |
640 | namestore_sqlite_iterate_records (void *cls, | 639 | namestore_sqlite_iterate_records (void *cls, |
641 | const GNUNET_HashCode *zone, | 640 | const struct GNUNET_CRYPTO_ShortHashCode *zone, |
642 | const char *name, | 641 | const char *name, |
643 | uint64_t offset, | 642 | uint64_t offset, |
644 | GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls) | 643 | GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls) |
645 | { | 644 | { |
646 | struct Plugin *plugin = cls; | 645 | struct Plugin *plugin = cls; |
647 | sqlite3_stmt *stmt; | 646 | sqlite3_stmt *stmt; |
648 | GNUNET_HashCode name_hase; | 647 | struct GNUNET_CRYPTO_ShortHashCode name_hase; |
649 | unsigned int boff; | 648 | unsigned int boff; |
650 | 649 | ||
651 | if (NULL == zone) | 650 | if (NULL == zone) |
@@ -653,7 +652,7 @@ namestore_sqlite_iterate_records (void *cls, | |||
653 | stmt = plugin->iterate_all; | 652 | stmt = plugin->iterate_all; |
654 | else | 653 | else |
655 | { | 654 | { |
656 | GNUNET_CRYPTO_hash (name, strlen(name), &name_hase); | 655 | GNUNET_CRYPTO_short_hash (name, strlen(name), &name_hase); |
657 | stmt = plugin->iterate_by_name; | 656 | stmt = plugin->iterate_by_name; |
658 | } | 657 | } |
659 | else | 658 | else |
@@ -661,14 +660,14 @@ namestore_sqlite_iterate_records (void *cls, | |||
661 | stmt = plugin->iterate_by_zone; | 660 | stmt = plugin->iterate_by_zone; |
662 | else | 661 | else |
663 | { | 662 | { |
664 | GNUNET_CRYPTO_hash (name, strlen(name), &name_hase); | 663 | GNUNET_CRYPTO_short_hash (name, strlen(name), &name_hase); |
665 | stmt = plugin->iterate_records; | 664 | stmt = plugin->iterate_records; |
666 | } | 665 | } |
667 | 666 | ||
668 | boff = 0; | 667 | boff = 0; |
669 | if ( (NULL != zone) && | 668 | if ( (NULL != zone) && |
670 | (SQLITE_OK != sqlite3_bind_blob (stmt, ++boff, | 669 | (SQLITE_OK != sqlite3_bind_blob (stmt, ++boff, |
671 | zone, sizeof (GNUNET_HashCode), | 670 | zone, sizeof (struct GNUNET_CRYPTO_ShortHashCode), |
672 | SQLITE_STATIC)) ) | 671 | SQLITE_STATIC)) ) |
673 | { | 672 | { |
674 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 673 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
@@ -681,10 +680,10 @@ namestore_sqlite_iterate_records (void *cls, | |||
681 | } | 680 | } |
682 | if ( (NULL != name) && | 681 | if ( (NULL != name) && |
683 | (SQLITE_OK != sqlite3_bind_blob (stmt, ++boff, | 682 | (SQLITE_OK != sqlite3_bind_blob (stmt, ++boff, |
684 | &name_hase, sizeof (GNUNET_HashCode), | 683 | &name_hase, sizeof (struct GNUNET_CRYPTO_ShortHashCode), |
685 | SQLITE_STATIC)) ) | 684 | SQLITE_STATIC)) ) |
686 | { | 685 | { |
687 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "ITERATE NAME HASH: `%s'", GNUNET_h2s_full(&name_hase)); | 686 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "ITERATE NAME HASH: `%8s'", GNUNET_short_h2s(&name_hase)); |
688 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 687 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
689 | "sqlite3_bind_XXXX"); | 688 | "sqlite3_bind_XXXX"); |
690 | if (SQLITE_OK != sqlite3_reset (stmt)) | 689 | if (SQLITE_OK != sqlite3_reset (stmt)) |
@@ -723,8 +722,8 @@ namestore_sqlite_iterate_records (void *cls, | |||
723 | */ | 722 | */ |
724 | static int | 723 | static int |
725 | namestore_sqlite_zone_to_name (void *cls, | 724 | namestore_sqlite_zone_to_name (void *cls, |
726 | const GNUNET_HashCode *zone, | 725 | const struct GNUNET_CRYPTO_ShortHashCode *zone, |
727 | const GNUNET_HashCode *value_zone, | 726 | const struct GNUNET_CRYPTO_ShortHashCode *value_zone, |
728 | GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls) | 727 | GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls) |
729 | { | 728 | { |
730 | struct Plugin *plugin = cls; | 729 | struct Plugin *plugin = cls; |
@@ -732,10 +731,10 @@ namestore_sqlite_zone_to_name (void *cls, | |||
732 | 731 | ||
733 | stmt = plugin->zone_to_name; | 732 | stmt = plugin->zone_to_name; |
734 | if ( (SQLITE_OK != sqlite3_bind_blob (stmt, 1, | 733 | if ( (SQLITE_OK != sqlite3_bind_blob (stmt, 1, |
735 | zone, sizeof (GNUNET_HashCode), | 734 | zone, sizeof (struct GNUNET_CRYPTO_ShortHashCode), |
736 | SQLITE_STATIC)) || | 735 | SQLITE_STATIC)) || |
737 | (SQLITE_OK != sqlite3_bind_blob (stmt, 2, | 736 | (SQLITE_OK != sqlite3_bind_blob (stmt, 2, |
738 | value_zone, sizeof (GNUNET_HashCode), | 737 | value_zone, sizeof (struct GNUNET_CRYPTO_ShortHashCode), |
739 | SQLITE_STATIC)) ) | 738 | SQLITE_STATIC)) ) |
740 | { | 739 | { |
741 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 740 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
@@ -759,13 +758,13 @@ namestore_sqlite_zone_to_name (void *cls, | |||
759 | */ | 758 | */ |
760 | static void | 759 | static void |
761 | namestore_sqlite_delete_zone (void *cls, | 760 | namestore_sqlite_delete_zone (void *cls, |
762 | const GNUNET_HashCode *zone) | 761 | const struct GNUNET_CRYPTO_ShortHashCode *zone) |
763 | { | 762 | { |
764 | struct Plugin *plugin = cls; | 763 | struct Plugin *plugin = cls; |
765 | sqlite3_stmt *stmt = plugin->delete_zone; | 764 | sqlite3_stmt *stmt = plugin->delete_zone; |
766 | int n; | 765 | int n; |
767 | 766 | ||
768 | if (SQLITE_OK != sqlite3_bind_blob (stmt, 1, zone, sizeof (GNUNET_HashCode), SQLITE_STATIC)) | 767 | if (SQLITE_OK != sqlite3_bind_blob (stmt, 1, zone, sizeof (struct GNUNET_CRYPTO_ShortHashCode), SQLITE_STATIC)) |
769 | { | 768 | { |
770 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 769 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
771 | "sqlite3_bind_XXXX"); | 770 | "sqlite3_bind_XXXX"); |