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/gnunet-service-namestore.c | |
parent | 34243a1a0c04ef5723a327124f96e2571ac5fd2e (diff) | |
download | gnunet-5a943624e2634d632ee2bf3a78c25b0aeae3813e.tar.gz gnunet-5a943624e2634d632ee2bf3a78c25b0aeae3813e.zip |
- usage of short hashes
Diffstat (limited to 'src/namestore/gnunet-service-namestore.c')
-rw-r--r-- | src/namestore/gnunet-service-namestore.c | 132 |
1 files changed, 71 insertions, 61 deletions
diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c index 6b4250d38..f45492fc8 100644 --- a/src/namestore/gnunet-service-namestore.c +++ b/src/namestore/gnunet-service-namestore.c | |||
@@ -45,7 +45,7 @@ struct GNUNET_NAMESTORE_ZoneIteration | |||
45 | 45 | ||
46 | int has_zone; | 46 | int has_zone; |
47 | 47 | ||
48 | GNUNET_HashCode zone; | 48 | struct GNUNET_CRYPTO_ShortHashCode zone; |
49 | 49 | ||
50 | uint64_t request_id; | 50 | uint64_t request_id; |
51 | uint32_t offset; | 51 | uint32_t offset; |
@@ -73,7 +73,7 @@ struct GNUNET_NAMESTORE_CryptoContainer | |||
73 | { | 73 | { |
74 | char * filename; | 74 | char * filename; |
75 | 75 | ||
76 | GNUNET_HashCode zone; | 76 | struct GNUNET_CRYPTO_ShortHashCode zone; |
77 | struct GNUNET_CRYPTO_RsaPrivateKey *privkey; | 77 | struct GNUNET_CRYPTO_RsaPrivateKey *privkey; |
78 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *pubkey; | 78 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *pubkey; |
79 | }; | 79 | }; |
@@ -125,7 +125,7 @@ write_key_to_file (const char *filename, struct GNUNET_NAMESTORE_CryptoContainer | |||
125 | 125 | ||
126 | if (GNUNET_YES == GNUNET_DISK_file_test (filename)) | 126 | if (GNUNET_YES == GNUNET_DISK_file_test (filename)) |
127 | { | 127 | { |
128 | GNUNET_HashCode zone; | 128 | struct GNUNET_CRYPTO_ShortHashCode zone; |
129 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pubkey; | 129 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pubkey; |
130 | struct GNUNET_CRYPTO_RsaPrivateKey * privkey; | 130 | struct GNUNET_CRYPTO_RsaPrivateKey * privkey; |
131 | 131 | ||
@@ -133,24 +133,24 @@ write_key_to_file (const char *filename, struct GNUNET_NAMESTORE_CryptoContainer | |||
133 | if (privkey == NULL) | 133 | if (privkey == NULL) |
134 | { | 134 | { |
135 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 135 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
136 | _("File zone `%s' but corrupt content already exists, failed to write! \n"), GNUNET_h2s (&zone)); | 136 | _("File zone `%s' but corrupt content already exists, failed to write! \n"), GNUNET_short_h2s (&zone)); |
137 | return GNUNET_SYSERR; | 137 | return GNUNET_SYSERR; |
138 | } | 138 | } |
139 | 139 | ||
140 | GNUNET_CRYPTO_rsa_key_get_public(privkey, &pubkey); | 140 | GNUNET_CRYPTO_rsa_key_get_public (privkey, &pubkey); |
141 | GNUNET_CRYPTO_hash(&pubkey, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &zone); | 141 | GNUNET_CRYPTO_short_hash (&pubkey, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &zone); |
142 | GNUNET_CRYPTO_rsa_key_free(privkey); | 142 | GNUNET_CRYPTO_rsa_key_free (privkey); |
143 | 143 | ||
144 | if (0 == memcmp (&zone, &c->zone, sizeof(zone))) | 144 | if (0 == memcmp (&zone, &c->zone, sizeof(zone))) |
145 | { | 145 | { |
146 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 146 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
147 | _("File zone `%s' containing this key already exists\n"), GNUNET_h2s (&zone)); | 147 | _("File zone `%s' containing this key already exists\n"), GNUNET_short_h2s (&zone)); |
148 | return GNUNET_OK; | 148 | return GNUNET_OK; |
149 | } | 149 | } |
150 | else | 150 | else |
151 | { | 151 | { |
152 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 152 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
153 | _("File zone `%s' but different zone key already exists, failed to write! \n"), GNUNET_h2s (&zone)); | 153 | _("File zone `%s' but different zone key already exists, failed to write! \n"), GNUNET_short_h2s (&zone)); |
154 | return GNUNET_OK; | 154 | return GNUNET_OK; |
155 | } | 155 | } |
156 | } | 156 | } |
@@ -185,12 +185,12 @@ write_key_to_file (const char *filename, struct GNUNET_NAMESTORE_CryptoContainer | |||
185 | GNUNET_assert (GNUNET_YES == GNUNET_DISK_file_close (fd)); | 185 | GNUNET_assert (GNUNET_YES == GNUNET_DISK_file_close (fd)); |
186 | 186 | ||
187 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 187 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
188 | _("Stored zonekey for zone `%s' in file `%s'\n"), GNUNET_h2s(&c->zone), c->filename); | 188 | _("Stored zonekey for zone `%s' in file `%s'\n"), GNUNET_short_h2s(&c->zone), c->filename); |
189 | return GNUNET_OK; | 189 | return GNUNET_OK; |
190 | } | 190 | } |
191 | 191 | ||
192 | int zone_to_disk_it (void *cls, | 192 | int zone_to_disk_it (void *cls, |
193 | const GNUNET_HashCode * key, | 193 | const GNUNET_HashCode *key, |
194 | void *value) | 194 | void *value) |
195 | { | 195 | { |
196 | struct GNUNET_NAMESTORE_CryptoContainer * c = value; | 196 | struct GNUNET_NAMESTORE_CryptoContainer * c = value; |
@@ -199,11 +199,12 @@ int zone_to_disk_it (void *cls, | |||
199 | write_key_to_file(c->filename, c); | 199 | write_key_to_file(c->filename, c); |
200 | else | 200 | else |
201 | { | 201 | { |
202 | GNUNET_asprintf(&c->filename, "%s/%s.zkey", zonefile_directory, GNUNET_h2s_full (&c->zone)); | 202 | GNUNET_asprintf(&c->filename, "%s/%s.zkey", zonefile_directory, GNUNET_short_h2s (&c->zone)); |
203 | write_key_to_file(c->filename, c); | 203 | write_key_to_file(c->filename, c); |
204 | } | 204 | } |
205 | 205 | ||
206 | GNUNET_CONTAINER_multihashmap_remove (zonekeys, key, value);; | 206 | |
207 | GNUNET_CONTAINER_multihashmap_remove (zonekeys, key, value); | ||
207 | GNUNET_CRYPTO_rsa_key_free(c->privkey); | 208 | GNUNET_CRYPTO_rsa_key_free(c->privkey); |
208 | GNUNET_free (c->pubkey); | 209 | GNUNET_free (c->pubkey); |
209 | GNUNET_free(c->filename); | 210 | GNUNET_free(c->filename); |
@@ -340,7 +341,7 @@ struct LookupNameContext | |||
340 | struct GNUNET_NAMESTORE_Client *nc; | 341 | struct GNUNET_NAMESTORE_Client *nc; |
341 | uint32_t request_id; | 342 | uint32_t request_id; |
342 | uint32_t record_type; | 343 | uint32_t record_type; |
343 | GNUNET_HashCode *zone; | 344 | struct GNUNET_CRYPTO_ShortHashCode *zone; |
344 | char * name; | 345 | char * name; |
345 | }; | 346 | }; |
346 | 347 | ||
@@ -352,12 +353,12 @@ void drop_iterator (void *cls, | |||
352 | const struct GNUNET_NAMESTORE_RecordData *rd, | 353 | const struct GNUNET_NAMESTORE_RecordData *rd, |
353 | const struct GNUNET_CRYPTO_RsaSignature *signature) | 354 | const struct GNUNET_CRYPTO_RsaSignature *signature) |
354 | { | 355 | { |
355 | GNUNET_HashCode zone_hash; | 356 | struct GNUNET_CRYPTO_ShortHashCode zone_hash; |
356 | int * stop = cls; | 357 | int * stop = cls; |
357 | if (NULL != zone_key) | 358 | if (NULL != zone_key) |
358 | { | 359 | { |
359 | GNUNET_CRYPTO_hash(zone_key, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &zone_hash); | 360 | GNUNET_CRYPTO_short_hash(zone_key, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &zone_hash); |
360 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Deleting zone `%s'\n", GNUNET_h2s (&zone_hash)); | 361 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Deleting zone `%s'\n", GNUNET_short_h2s (&zone_hash)); |
361 | GSN_database->delete_zone (GSN_database->cls, &zone_hash); | 362 | GSN_database->delete_zone (GSN_database->cls, &zone_hash); |
362 | } | 363 | } |
363 | else | 364 | else |
@@ -383,7 +384,8 @@ handle_lookup_name_it (void *cls, | |||
383 | struct GNUNET_NAMESTORE_CryptoContainer *cc; | 384 | struct GNUNET_NAMESTORE_CryptoContainer *cc; |
384 | struct GNUNET_CRYPTO_RsaSignature *signature_new = NULL; | 385 | struct GNUNET_CRYPTO_RsaSignature *signature_new = NULL; |
385 | struct GNUNET_TIME_Absolute e; | 386 | struct GNUNET_TIME_Absolute e; |
386 | GNUNET_HashCode zone_key_hash; | 387 | struct GNUNET_CRYPTO_ShortHashCode zone_key_hash; |
388 | GNUNET_HashCode long_hash; | ||
387 | char *rd_tmp; | 389 | char *rd_tmp; |
388 | char *name_tmp; | 390 | char *name_tmp; |
389 | size_t rd_ser_len; | 391 | size_t rd_ser_len; |
@@ -408,7 +410,7 @@ handle_lookup_name_it (void *cls, | |||
408 | if (rd[c].record_type == lnc->record_type) | 410 | if (rd[c].record_type == lnc->record_type) |
409 | copied_elements++; /* found matching record */ | 411 | copied_elements++; /* found matching record */ |
410 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found %u records with type %u for name `%s' in zone `%s'\n", | 412 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found %u records with type %u for name `%s' in zone `%s'\n", |
411 | copied_elements, lnc->record_type, lnc->name, GNUNET_h2s(lnc->zone)); | 413 | copied_elements, lnc->record_type, lnc->name, GNUNET_short_h2s(lnc->zone)); |
412 | rd_selected = GNUNET_malloc (copied_elements * sizeof (struct GNUNET_NAMESTORE_RecordData)); | 414 | rd_selected = GNUNET_malloc (copied_elements * sizeof (struct GNUNET_NAMESTORE_RecordData)); |
413 | copied_elements = 0; | 415 | copied_elements = 0; |
414 | for (c = 0; c < rd_count; c ++) | 416 | for (c = 0; c < rd_count; c ++) |
@@ -440,7 +442,7 @@ handle_lookup_name_it (void *cls, | |||
440 | GNUNET_NAMESTORE_records_serialize(copied_elements, rd_selected, rd_ser_len, rd_ser); | 442 | GNUNET_NAMESTORE_records_serialize(copied_elements, rd_selected, rd_ser_len, rd_ser); |
441 | 443 | ||
442 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found %u records for name `%s' in zone `%s'\n", | 444 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found %u records for name `%s' in zone `%s'\n", |
443 | copied_elements, lnc->name, GNUNET_h2s(lnc->zone)); | 445 | copied_elements, lnc->name, GNUNET_short_h2s(lnc->zone)); |
444 | 446 | ||
445 | if ((copied_elements == rd_count) && (NULL != signature)) | 447 | if ((copied_elements == rd_count) && (NULL != signature)) |
446 | contains_signature = GNUNET_YES; /* returning all records, so include signature */ | 448 | contains_signature = GNUNET_YES; /* returning all records, so include signature */ |
@@ -450,18 +452,19 @@ handle_lookup_name_it (void *cls, | |||
450 | 452 | ||
451 | if ((NULL != zone_key) && (copied_elements == rd_count)) | 453 | if ((NULL != zone_key) && (copied_elements == rd_count)) |
452 | { | 454 | { |
453 | GNUNET_CRYPTO_hash(zone_key, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &zone_key_hash); | 455 | GNUNET_CRYPTO_short_hash(zone_key, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &zone_key_hash); |
454 | if (GNUNET_CONTAINER_multihashmap_contains(zonekeys, &zone_key_hash)) | 456 | GNUNET_CRYPTO_short_hash_double (&zone_key_hash, &long_hash); |
457 | if (GNUNET_CONTAINER_multihashmap_contains(zonekeys, &long_hash)) | ||
455 | { | 458 | { |
456 | cc = GNUNET_CONTAINER_multihashmap_get(zonekeys, &zone_key_hash); | 459 | cc = GNUNET_CONTAINER_multihashmap_get(zonekeys, &long_hash); |
457 | e = get_block_expiration_time(rd_count, rd); | 460 | e = get_block_expiration_time(rd_count, rd); |
458 | signature_new = GNUNET_NAMESTORE_create_signature(cc->privkey, e, name, rd, rd_count); | 461 | signature_new = GNUNET_NAMESTORE_create_signature(cc->privkey, e, name, rd, rd_count); |
459 | GNUNET_assert (signature_new != NULL); | 462 | GNUNET_assert (signature_new != NULL); |
460 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating signature for name `%s' with %u records in zone `%s'\n",name, copied_elements, GNUNET_h2s(&zone_key_hash)); | 463 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating signature for name `%s' with %u records in zone `%s'\n",name, copied_elements, GNUNET_short_h2s(&zone_key_hash)); |
461 | authoritative = GNUNET_YES; | 464 | authoritative = GNUNET_YES; |
462 | } | 465 | } |
463 | else | 466 | else |
464 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "I am not authoritative for name `%s' in zone `%s'\n",name, GNUNET_h2s(&zone_key_hash)); | 467 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "I am not authoritative for name `%s' in zone `%s'\n",name, GNUNET_short_h2s(&zone_key_hash)); |
465 | } | 468 | } |
466 | 469 | ||
467 | r_size = sizeof (struct LookupNameResponseMessage) + | 470 | r_size = sizeof (struct LookupNameResponseMessage) + |
@@ -565,9 +568,9 @@ static void handle_lookup_name (void *cls, | |||
565 | } | 568 | } |
566 | 569 | ||
567 | if (0 == type) | 570 | if (0 == type) |
568 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Looking up all records for name `%s' in zone `%s'\n", name, GNUNET_h2s(&ln_msg->zone)); | 571 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Looking up all records for name `%s' in zone `%s'\n", name, GNUNET_short_h2s(&ln_msg->zone)); |
569 | else | 572 | else |
570 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Looking up records with type %u for name `%s' in zone `%s'\n", type, name, GNUNET_h2s(&ln_msg->zone)); | 573 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Looking up records with type %u for name `%s' in zone `%s'\n", type, name, GNUNET_short_h2s(&ln_msg->zone)); |
571 | 574 | ||
572 | /* do the actual lookup */ | 575 | /* do the actual lookup */ |
573 | lnc.request_id = rid; | 576 | lnc.request_id = rid; |
@@ -672,10 +675,10 @@ static void handle_record_put (void *cls, | |||
672 | goto send; | 675 | goto send; |
673 | } | 676 | } |
674 | 677 | ||
675 | GNUNET_HashCode zone_hash; | 678 | struct GNUNET_CRYPTO_ShortHashCode zone_hash; |
676 | GNUNET_CRYPTO_hash (&rp_msg->public_key, sizeof (rp_msg->public_key), &zone_hash); | 679 | GNUNET_CRYPTO_short_hash (&rp_msg->public_key, sizeof (rp_msg->public_key), &zone_hash); |
677 | 680 | ||
678 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Putting %u record for name `%s' in zone `%s'\n", rd_count, name, GNUNET_h2s(&zone_hash)); | 681 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Putting %u record for name `%s' in zone `%s'\n", rd_count, name, GNUNET_short_h2s(&zone_hash)); |
679 | 682 | ||
680 | /* Database operation */ | 683 | /* Database operation */ |
681 | res = GSN_database->put_records(GSN_database->cls, | 684 | res = GSN_database->put_records(GSN_database->cls, |
@@ -836,7 +839,8 @@ static void handle_record_create (void *cls, | |||
836 | struct GNUNET_CRYPTO_RsaPrivateKey *pkey; | 839 | struct GNUNET_CRYPTO_RsaPrivateKey *pkey; |
837 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pub; | 840 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pub; |
838 | struct RecordCreateResponseMessage rcr_msg; | 841 | struct RecordCreateResponseMessage rcr_msg; |
839 | GNUNET_HashCode pubkey_hash; | 842 | struct GNUNET_CRYPTO_ShortHashCode pubkey_hash; |
843 | GNUNET_HashCode long_hash; | ||
840 | size_t name_len; | 844 | size_t name_len; |
841 | size_t msg_size; | 845 | size_t msg_size; |
842 | size_t msg_size_exp; | 846 | size_t msg_size_exp; |
@@ -914,19 +918,19 @@ static void handle_record_create (void *cls, | |||
914 | pkey = GNUNET_CRYPTO_rsa_decode_key((char *) pkey_tmp, key_len); | 918 | pkey = GNUNET_CRYPTO_rsa_decode_key((char *) pkey_tmp, key_len); |
915 | GNUNET_assert (pkey != NULL); | 919 | GNUNET_assert (pkey != NULL); |
916 | GNUNET_CRYPTO_rsa_key_get_public(pkey, &pub); | 920 | GNUNET_CRYPTO_rsa_key_get_public(pkey, &pub); |
917 | GNUNET_CRYPTO_hash (&pub, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &pubkey_hash); | 921 | GNUNET_CRYPTO_short_hash (&pub, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &pubkey_hash); |
922 | GNUNET_CRYPTO_short_hash_double (&pubkey_hash, &long_hash); | ||
918 | 923 | ||
919 | if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains(zonekeys, &pubkey_hash)) | 924 | if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains(zonekeys, &long_hash)) |
920 | { | 925 | { |
921 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received new private key for zone `%s'\n",GNUNET_h2s(&pubkey_hash)); | 926 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received new private key for zone `%s'\n",GNUNET_short_h2s(&pubkey_hash)); |
922 | 927 | ||
923 | cc = GNUNET_malloc (sizeof (struct GNUNET_NAMESTORE_CryptoContainer)); | 928 | cc = GNUNET_malloc (sizeof (struct GNUNET_NAMESTORE_CryptoContainer)); |
924 | cc->privkey = GNUNET_CRYPTO_rsa_decode_key((char *) pkey_tmp, key_len); | 929 | cc->privkey = GNUNET_CRYPTO_rsa_decode_key((char *) pkey_tmp, key_len); |
925 | cc->pubkey = GNUNET_malloc(sizeof (pub)); | 930 | cc->pubkey = GNUNET_malloc(sizeof (pub)); |
926 | memcpy (cc->pubkey, &pub, sizeof(pub)); | 931 | memcpy (cc->pubkey, &pub, sizeof(pub)); |
927 | cc->zone = pubkey_hash; | 932 | cc->zone = pubkey_hash; |
928 | 933 | GNUNET_CONTAINER_multihashmap_put(zonekeys, &long_hash, cc, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | |
929 | GNUNET_CONTAINER_multihashmap_put(zonekeys, &pubkey_hash, cc, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | ||
930 | } | 934 | } |
931 | 935 | ||
932 | crc.expire = GNUNET_TIME_absolute_ntoh(rp_msg->expire); | 936 | crc.expire = GNUNET_TIME_absolute_ntoh(rp_msg->expire); |
@@ -936,7 +940,7 @@ static void handle_record_create (void *cls, | |||
936 | crc.rd = rd; | 940 | crc.rd = rd; |
937 | crc.name = name_tmp; | 941 | crc.name = name_tmp; |
938 | 942 | ||
939 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating record for name `%s' in zone `%s'\n", name_tmp, GNUNET_h2s(&pubkey_hash)); | 943 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating record for name `%s' in zone `%s'\n", name_tmp, GNUNET_short_h2s(&pubkey_hash)); |
940 | 944 | ||
941 | /* Get existing records for name */ | 945 | /* Get existing records for name */ |
942 | res = GSN_database->iterate_records(GSN_database->cls, &pubkey_hash, name_tmp, 0, &handle_create_record_it, &crc); | 946 | res = GSN_database->iterate_records(GSN_database->cls, &pubkey_hash, name_tmp, 0, &handle_create_record_it, &crc); |
@@ -1064,7 +1068,8 @@ static void handle_record_remove (void *cls, | |||
1064 | struct GNUNET_CRYPTO_RsaPrivateKey *pkey; | 1068 | struct GNUNET_CRYPTO_RsaPrivateKey *pkey; |
1065 | struct GNUNET_NAMESTORE_CryptoContainer *cc = NULL; | 1069 | struct GNUNET_NAMESTORE_CryptoContainer *cc = NULL; |
1066 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pub; | 1070 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pub; |
1067 | GNUNET_HashCode pubkey_hash; | 1071 | struct GNUNET_CRYPTO_ShortHashCode pubkey_hash; |
1072 | GNUNET_HashCode long_hash; | ||
1068 | char * pkey_tmp = NULL; | 1073 | char * pkey_tmp = NULL; |
1069 | char * name_tmp = NULL; | 1074 | char * name_tmp = NULL; |
1070 | char * rd_ser = NULL; | 1075 | char * rd_ser = NULL; |
@@ -1154,18 +1159,19 @@ static void handle_record_remove (void *cls, | |||
1154 | pkey = GNUNET_CRYPTO_rsa_decode_key((char *) pkey_tmp, key_len); | 1159 | pkey = GNUNET_CRYPTO_rsa_decode_key((char *) pkey_tmp, key_len); |
1155 | GNUNET_assert (pkey != NULL); | 1160 | GNUNET_assert (pkey != NULL); |
1156 | GNUNET_CRYPTO_rsa_key_get_public(pkey, &pub); | 1161 | GNUNET_CRYPTO_rsa_key_get_public(pkey, &pub); |
1157 | GNUNET_CRYPTO_hash (&pub, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &pubkey_hash); | 1162 | GNUNET_CRYPTO_short_hash (&pub, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &pubkey_hash); |
1163 | GNUNET_CRYPTO_short_hash_double (&pubkey_hash, &long_hash); | ||
1158 | 1164 | ||
1159 | if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains(zonekeys, &pubkey_hash)) | 1165 | if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains(zonekeys, &long_hash)) |
1160 | { | 1166 | { |
1161 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received new private key for zone `%s'\n",GNUNET_h2s(&pubkey_hash)); | 1167 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received new private key for zone `%s'\n",GNUNET_short_h2s(&pubkey_hash)); |
1162 | cc = GNUNET_malloc (sizeof (struct GNUNET_NAMESTORE_CryptoContainer)); | 1168 | cc = GNUNET_malloc (sizeof (struct GNUNET_NAMESTORE_CryptoContainer)); |
1163 | cc->privkey = GNUNET_CRYPTO_rsa_decode_key((char *) pkey_tmp, key_len); | 1169 | cc->privkey = GNUNET_CRYPTO_rsa_decode_key((char *) pkey_tmp, key_len); |
1164 | cc->pubkey = GNUNET_malloc(sizeof (pub)); | 1170 | cc->pubkey = GNUNET_malloc(sizeof (pub)); |
1165 | memcpy (cc->pubkey, &pub, sizeof(pub)); | 1171 | memcpy (cc->pubkey, &pub, sizeof(pub)); |
1166 | cc->zone = pubkey_hash; | 1172 | cc->zone = pubkey_hash; |
1167 | 1173 | ||
1168 | GNUNET_CONTAINER_multihashmap_put(zonekeys, &pubkey_hash, cc, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | 1174 | GNUNET_CONTAINER_multihashmap_put(zonekeys, &long_hash, cc, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); |
1169 | } | 1175 | } |
1170 | 1176 | ||
1171 | struct GNUNET_NAMESTORE_RecordData rd[rd_count]; | 1177 | struct GNUNET_NAMESTORE_RecordData rd[rd_count]; |
@@ -1180,7 +1186,7 @@ static void handle_record_remove (void *cls, | |||
1180 | rrc.rd = rd; | 1186 | rrc.rd = rd; |
1181 | rrc.pkey = pkey; | 1187 | rrc.pkey = pkey; |
1182 | 1188 | ||
1183 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Removing record for name `%s' in zone `%s'\n", name_tmp, GNUNET_h2s(&pubkey_hash)); | 1189 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Removing record for name `%s' in zone `%s'\n", name_tmp, GNUNET_short_h2s(&pubkey_hash)); |
1184 | 1190 | ||
1185 | /* Database operation */ | 1191 | /* Database operation */ |
1186 | res = GSN_database->iterate_records (GSN_database->cls, | 1192 | res = GSN_database->iterate_records (GSN_database->cls, |
@@ -1342,10 +1348,10 @@ static void handle_zone_to_name (void *cls, | |||
1342 | ztn_ctx.rid = rid; | 1348 | ztn_ctx.rid = rid; |
1343 | ztn_ctx.nc = nc; | 1349 | ztn_ctx.nc = nc; |
1344 | 1350 | ||
1345 | char * z_tmp = strdup (GNUNET_h2s (&ztn_msg->zone)); | 1351 | char * z_tmp = strdup (GNUNET_short_h2s (&ztn_msg->zone)); |
1346 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Looking up name for zone `%s' in zone `%s'\n", | 1352 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Looking up name for zone `%s' in zone `%s'\n", |
1347 | z_tmp, | 1353 | z_tmp, |
1348 | GNUNET_h2s (&ztn_msg->value_zone)); | 1354 | GNUNET_short_h2s (&ztn_msg->value_zone)); |
1349 | GNUNET_free (z_tmp); | 1355 | GNUNET_free (z_tmp); |
1350 | 1356 | ||
1351 | GSN_database->zone_to_name (GSN_database->cls, &ztn_msg->zone, &ztn_msg->value_zone, &handle_zone_to_name_it, &ztn_ctx); | 1357 | GSN_database->zone_to_name (GSN_database->cls, &ztn_msg->zone, &ztn_msg->value_zone, &handle_zone_to_name_it, &ztn_ctx); |
@@ -1383,14 +1389,15 @@ void zone_iteration_proc (void *cls, | |||
1383 | struct GNUNET_NAMESTORE_CryptoContainer * cc; | 1389 | struct GNUNET_NAMESTORE_CryptoContainer * cc; |
1384 | struct GNUNET_CRYPTO_RsaSignature *signature_new = NULL; | 1390 | struct GNUNET_CRYPTO_RsaSignature *signature_new = NULL; |
1385 | struct GNUNET_TIME_Absolute e; | 1391 | struct GNUNET_TIME_Absolute e; |
1386 | GNUNET_HashCode zone_key_hash; | 1392 | struct GNUNET_CRYPTO_ShortHashCode zone_key_hash; |
1393 | GNUNET_HashCode long_hash; | ||
1387 | int authoritative = GNUNET_NO; | 1394 | int authoritative = GNUNET_NO; |
1388 | 1395 | ||
1389 | if ((zone_key == NULL) && (name == NULL)) | 1396 | if ((zone_key == NULL) && (name == NULL)) |
1390 | { | 1397 | { |
1391 | struct ZoneIterationResponseMessage zir_msg; | 1398 | struct ZoneIterationResponseMessage zir_msg; |
1392 | if (zi->has_zone == GNUNET_YES) | 1399 | if (zi->has_zone == GNUNET_YES) |
1393 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No more results for zone `%s'\n", GNUNET_h2s(&zi->zone)); | 1400 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No more results for zone `%s'\n", GNUNET_short_h2s(&zi->zone)); |
1394 | else | 1401 | else |
1395 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No more results for all zones\n"); | 1402 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No more results for all zones\n"); |
1396 | 1403 | ||
@@ -1417,7 +1424,7 @@ void zone_iteration_proc (void *cls, | |||
1417 | struct ZoneIterationResponseMessage *zir_msg; | 1424 | struct ZoneIterationResponseMessage *zir_msg; |
1418 | if (zi->has_zone == GNUNET_YES) | 1425 | if (zi->has_zone == GNUNET_YES) |
1419 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending name `%s' for iteration over zone `%s'\n", | 1426 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending name `%s' for iteration over zone `%s'\n", |
1420 | name, GNUNET_h2s(&zi->zone)); | 1427 | name, GNUNET_short_h2s(&zi->zone)); |
1421 | if (zi->has_zone == GNUNET_NO) | 1428 | if (zi->has_zone == GNUNET_NO) |
1422 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending name `%s' for iteration over all zones\n", | 1429 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending name `%s' for iteration over all zones\n", |
1423 | name); | 1430 | name); |
@@ -1438,15 +1445,16 @@ void zone_iteration_proc (void *cls, | |||
1438 | name_tmp = (char *) &zir_msg[1]; | 1445 | name_tmp = (char *) &zir_msg[1]; |
1439 | rd_tmp = &name_tmp[name_len]; | 1446 | rd_tmp = &name_tmp[name_len]; |
1440 | 1447 | ||
1441 | GNUNET_CRYPTO_hash(zone_key, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &zone_key_hash); | 1448 | GNUNET_CRYPTO_short_hash(zone_key, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &zone_key_hash); |
1442 | if (GNUNET_CONTAINER_multihashmap_contains(zonekeys, &zone_key_hash)) | 1449 | GNUNET_CRYPTO_short_hash_double(&zone_key_hash, &long_hash); |
1450 | if (GNUNET_CONTAINER_multihashmap_contains(zonekeys, &long_hash)) | ||
1443 | { | 1451 | { |
1444 | cc = GNUNET_CONTAINER_multihashmap_get(zonekeys, &zone_key_hash); | 1452 | cc = GNUNET_CONTAINER_multihashmap_get(zonekeys, &long_hash); |
1445 | e = get_block_expiration_time(rd_count, rd); | 1453 | e = get_block_expiration_time(rd_count, rd); |
1446 | expire = e; | 1454 | expire = e; |
1447 | signature_new = GNUNET_NAMESTORE_create_signature(cc->privkey, e, name, rd, rd_count); | 1455 | signature_new = GNUNET_NAMESTORE_create_signature(cc->privkey, e, name, rd, rd_count); |
1448 | GNUNET_assert (signature_new != NULL); | 1456 | GNUNET_assert (signature_new != NULL); |
1449 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating signature for `%s' in zone `%s' with %u records and expiration %llu\n", name, GNUNET_h2s(&zone_key_hash), rd_count, e.abs_value); | 1457 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating signature for `%s' in zone `%s' with %u records and expiration %llu\n", name, GNUNET_short_h2s(&zone_key_hash), rd_count, e.abs_value); |
1450 | authoritative = GNUNET_YES; | 1458 | authoritative = GNUNET_YES; |
1451 | } | 1459 | } |
1452 | 1460 | ||
@@ -1502,8 +1510,8 @@ static void handle_iteration_start (void *cls, | |||
1502 | zi->client = nc; | 1510 | zi->client = nc; |
1503 | zi->zone = zis_msg->zone; | 1511 | zi->zone = zis_msg->zone; |
1504 | 1512 | ||
1505 | GNUNET_HashCode dummy; | 1513 | struct GNUNET_CRYPTO_ShortHashCode dummy; |
1506 | GNUNET_HashCode *zone_tmp; | 1514 | struct GNUNET_CRYPTO_ShortHashCode *zone_tmp; |
1507 | memset (&dummy, '\0', sizeof (dummy)); | 1515 | memset (&dummy, '\0', sizeof (dummy)); |
1508 | if (0 == memcmp (&dummy, &zis_msg->zone, sizeof (dummy))) | 1516 | if (0 == memcmp (&dummy, &zis_msg->zone, sizeof (dummy))) |
1509 | { | 1517 | { |
@@ -1513,7 +1521,7 @@ static void handle_iteration_start (void *cls, | |||
1513 | } | 1521 | } |
1514 | else | 1522 | else |
1515 | { | 1523 | { |
1516 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting to iterate over zone `%s'\n", GNUNET_h2s (&zis_msg->zone)); | 1524 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting to iterate over zone `%s'\n", GNUNET_short_h2s (&zis_msg->zone)); |
1517 | zi->has_zone = GNUNET_YES; | 1525 | zi->has_zone = GNUNET_YES; |
1518 | zone_tmp = &zis_msg->zone; | 1526 | zone_tmp = &zis_msg->zone; |
1519 | } | 1527 | } |
@@ -1558,7 +1566,7 @@ static void handle_iteration_stop (void *cls, | |||
1558 | 1566 | ||
1559 | GNUNET_CONTAINER_DLL_remove(nc->op_head, nc->op_tail, zi); | 1567 | GNUNET_CONTAINER_DLL_remove(nc->op_head, nc->op_tail, zi); |
1560 | if (GNUNET_YES == zi->has_zone) | 1568 | if (GNUNET_YES == zi->has_zone) |
1561 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopped zone iteration for zone `%s'\n", GNUNET_h2s (&zi->zone)); | 1569 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopped zone iteration for zone `%s'\n", GNUNET_short_h2s (&zi->zone)); |
1562 | else | 1570 | else |
1563 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopped zone iteration all zones\n"); | 1571 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopped zone iteration all zones\n"); |
1564 | GNUNET_free (zi); | 1572 | GNUNET_free (zi); |
@@ -1574,7 +1582,7 @@ static void handle_iteration_next (void *cls, | |||
1574 | 1582 | ||
1575 | struct GNUNET_NAMESTORE_Client *nc; | 1583 | struct GNUNET_NAMESTORE_Client *nc; |
1576 | struct GNUNET_NAMESTORE_ZoneIteration *zi; | 1584 | struct GNUNET_NAMESTORE_ZoneIteration *zi; |
1577 | GNUNET_HashCode *zone_tmp; | 1585 | struct GNUNET_CRYPTO_ShortHashCode *zone_tmp; |
1578 | struct ZoneIterationStopMessage * zis_msg = (struct ZoneIterationStopMessage *) message; | 1586 | struct ZoneIterationStopMessage * zis_msg = (struct ZoneIterationStopMessage *) message; |
1579 | uint32_t rid; | 1587 | uint32_t rid; |
1580 | 1588 | ||
@@ -1611,6 +1619,7 @@ static void handle_iteration_next (void *cls, | |||
1611 | 1619 | ||
1612 | int zonekey_file_it (void *cls, const char *filename) | 1620 | int zonekey_file_it (void *cls, const char *filename) |
1613 | { | 1621 | { |
1622 | GNUNET_HashCode long_hash; | ||
1614 | int *counter = cls; | 1623 | int *counter = cls; |
1615 | if ((filename != NULL) && (NULL != strstr(filename, ".zkey"))) | 1624 | if ((filename != NULL) && (NULL != strstr(filename, ".zkey"))) |
1616 | { | 1625 | { |
@@ -1624,11 +1633,12 @@ int zonekey_file_it (void *cls, const char *filename) | |||
1624 | c->pubkey = GNUNET_malloc(sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); | 1633 | c->pubkey = GNUNET_malloc(sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); |
1625 | c->privkey = privkey; | 1634 | c->privkey = privkey; |
1626 | GNUNET_CRYPTO_rsa_key_get_public(privkey, c->pubkey); | 1635 | GNUNET_CRYPTO_rsa_key_get_public(privkey, c->pubkey); |
1627 | GNUNET_CRYPTO_hash(c->pubkey, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &c->zone); | 1636 | GNUNET_CRYPTO_short_hash(c->pubkey, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &c->zone); |
1628 | |||
1629 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found zonefile for zone `%s'\n", GNUNET_h2s (&c->zone)); | ||
1630 | 1637 | ||
1631 | GNUNET_CONTAINER_multihashmap_put(zonekeys, &c->zone, c, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | 1638 | //GNUNET_CRYPTO_short_hash_to_enc (&name_hase, &name_enc); |
1639 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found zonefile for zone `%s'\n", GNUNET_short_h2s (&c->zone)); | ||
1640 | GNUNET_CRYPTO_short_hash_double (&c->zone, &long_hash); | ||
1641 | GNUNET_CONTAINER_multihashmap_put(zonekeys, &long_hash, c, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | ||
1632 | (*counter) ++; | 1642 | (*counter) ++; |
1633 | } | 1643 | } |
1634 | return GNUNET_OK; | 1644 | return GNUNET_OK; |