diff options
author | Martin Schanzenbach <mschanzenbach@posteo.de> | 2012-06-13 17:36:47 +0000 |
---|---|---|
committer | Martin Schanzenbach <mschanzenbach@posteo.de> | 2012-06-13 17:36:47 +0000 |
commit | 1f5326cd1032cbcc914c7809df1a64994eeebbe9 (patch) | |
tree | bd04389845d0b3096d98e3e97033040486108830 /src/gns/test_gns_pseu_shorten.c | |
parent | a8c5598ba43fcd61a5a340f14a3bab1613adbe7c (diff) | |
download | gnunet-1f5326cd1032cbcc914c7809df1a64994eeebbe9.tar.gz gnunet-1f5326cd1032cbcc914c7809df1a64994eeebbe9.zip |
- big shorten algorithm rewrite
- API change for lookup
- tests fixed
- introduces 3 zone system: root, private and shortened
Diffstat (limited to 'src/gns/test_gns_pseu_shorten.c')
-rw-r--r-- | src/gns/test_gns_pseu_shorten.c | 109 |
1 files changed, 92 insertions, 17 deletions
diff --git a/src/gns/test_gns_pseu_shorten.c b/src/gns/test_gns_pseu_shorten.c index 88fe17c29..34c69709b 100644 --- a/src/gns/test_gns_pseu_shorten.c +++ b/src/gns/test_gns_pseu_shorten.c | |||
@@ -43,14 +43,16 @@ | |||
43 | #define DEFAULT_NUM_PEERS 2 | 43 | #define DEFAULT_NUM_PEERS 2 |
44 | 44 | ||
45 | /* test records to resolve */ | 45 | /* test records to resolve */ |
46 | #define TEST_DOMAIN "www.alice.bob.gnunet" | 46 | #define TEST_DOMAIN "www.alicewonderland.bobbuilder.gnunet" |
47 | #define TEST_IP "127.0.0.1" | 47 | #define TEST_IP "127.0.0.1" |
48 | #define TEST_RECORD_NAME "www" | 48 | #define TEST_RECORD_NAME "www" |
49 | 49 | ||
50 | #define TEST_AUTHORITY_BOB "bob" | 50 | #define TEST_PRIVATE_ZONE "private" |
51 | #define TEST_AUTHORITY_ALICE "alice" | 51 | #define TEST_SHORTEN_ZONE "short" |
52 | #define TEST_AUTHORITY_BOB "bobbuilder" | ||
53 | #define TEST_AUTHORITY_ALICE "alicewonderland" | ||
52 | #define TEST_PSEU_ALICE "carol" | 54 | #define TEST_PSEU_ALICE "carol" |
53 | #define TEST_EXPECTED_RESULT "www.carol.gnunet" | 55 | #define TEST_EXPECTED_RESULT "www.carol.short.private.gnunet" |
54 | 56 | ||
55 | #define DHT_OPERATION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) | 57 | #define DHT_OPERATION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) |
56 | 58 | ||
@@ -85,12 +87,18 @@ const struct GNUNET_CONFIGURATION_Handle *cfg; | |||
85 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded alice_pkey; | 87 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded alice_pkey; |
86 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded bob_pkey; | 88 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded bob_pkey; |
87 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded our_pkey; | 89 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded our_pkey; |
90 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded priv_pkey; | ||
91 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded short_pkey; | ||
88 | struct GNUNET_CRYPTO_RsaPrivateKey *alice_key; | 92 | struct GNUNET_CRYPTO_RsaPrivateKey *alice_key; |
89 | struct GNUNET_CRYPTO_RsaPrivateKey *bob_key; | 93 | struct GNUNET_CRYPTO_RsaPrivateKey *bob_key; |
90 | struct GNUNET_CRYPTO_RsaPrivateKey *our_key; | 94 | struct GNUNET_CRYPTO_RsaPrivateKey *our_key; |
95 | struct GNUNET_CRYPTO_RsaPrivateKey *priv_key; | ||
96 | struct GNUNET_CRYPTO_RsaPrivateKey *short_key; | ||
91 | struct GNUNET_CRYPTO_ShortHashCode alice_hash; | 97 | struct GNUNET_CRYPTO_ShortHashCode alice_hash; |
92 | struct GNUNET_CRYPTO_ShortHashCode bob_hash; | 98 | struct GNUNET_CRYPTO_ShortHashCode bob_hash; |
93 | struct GNUNET_CRYPTO_ShortHashCode our_zone; | 99 | struct GNUNET_CRYPTO_ShortHashCode our_zone; |
100 | struct GNUNET_CRYPTO_ShortHashCode priv_zone; | ||
101 | struct GNUNET_CRYPTO_ShortHashCode short_zone; | ||
94 | 102 | ||
95 | /** | 103 | /** |
96 | * Check whether peers successfully shut down. | 104 | * Check whether peers successfully shut down. |
@@ -163,9 +171,9 @@ static void | |||
163 | do_shorten(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 171 | do_shorten(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
164 | { | 172 | { |
165 | GNUNET_GNS_shorten_zone (gns_handle, TEST_DOMAIN, | 173 | GNUNET_GNS_shorten_zone (gns_handle, TEST_DOMAIN, |
166 | &our_zone, &our_zone, | 174 | &our_zone, |
167 | &process_shorten_result, | 175 | &process_shorten_result, |
168 | TEST_DOMAIN); | 176 | TEST_DOMAIN); |
169 | } | 177 | } |
170 | 178 | ||
171 | static void | 179 | static void |
@@ -235,10 +243,11 @@ commence_testing (void *cls, int success) | |||
235 | } | 243 | } |
236 | 244 | ||
237 | GNUNET_GNS_lookup_zone (gns_handle, TEST_DOMAIN, | 245 | GNUNET_GNS_lookup_zone (gns_handle, TEST_DOMAIN, |
238 | &our_zone, &our_zone, | 246 | &our_zone, |
239 | GNUNET_GNS_RECORD_TYPE_A, | 247 | GNUNET_GNS_RECORD_TYPE_A, |
240 | GNUNET_NO, | 248 | GNUNET_NO, |
241 | &on_lookup_result, TEST_DOMAIN); | 249 | short_key, |
250 | &on_lookup_result, TEST_DOMAIN); | ||
242 | } | 251 | } |
243 | 252 | ||
244 | /** | 253 | /** |
@@ -501,12 +510,49 @@ put_pkey_dht(void *cls, int32_t success, const char *emsg) | |||
501 | } | 510 | } |
502 | 511 | ||
503 | static void | 512 | static void |
504 | do_lookup(void *cls, const struct GNUNET_PeerIdentity *id, | 513 | fin_init_zone (void *cls, int32_t success, const char *emsg) |
505 | const struct GNUNET_CONFIGURATION_Handle *_cfg, | 514 | { |
506 | struct GNUNET_TESTING_Daemon *d, const char *emsg) | 515 | struct GNUNET_NAMESTORE_RecordData rd; |
516 | rd.expiration = GNUNET_TIME_UNIT_FOREVER_ABS; | ||
517 | rd.data_size = sizeof(struct GNUNET_CRYPTO_ShortHashCode); | ||
518 | rd.data = &bob_hash; | ||
519 | rd.record_type = GNUNET_GNS_RECORD_PKEY; | ||
520 | |||
521 | GNUNET_NAMESTORE_record_create (namestore_handle, | ||
522 | our_key, | ||
523 | TEST_AUTHORITY_BOB, | ||
524 | &rd, | ||
525 | &put_pkey_dht, | ||
526 | NULL); | ||
527 | |||
528 | } | ||
529 | |||
530 | static void | ||
531 | cont_init_zone (void *cls, int32_t success, const char *emsg) | ||
532 | { | ||
533 | |||
534 | struct GNUNET_NAMESTORE_RecordData rd; | ||
535 | rd.expiration = GNUNET_TIME_UNIT_FOREVER_ABS; | ||
536 | rd.data_size = sizeof(struct GNUNET_CRYPTO_ShortHashCode); | ||
537 | rd.data = &short_zone; | ||
538 | rd.record_type = GNUNET_GNS_RECORD_PKEY; | ||
539 | |||
540 | GNUNET_NAMESTORE_record_create (namestore_handle, | ||
541 | priv_key, | ||
542 | TEST_SHORTEN_ZONE, | ||
543 | &rd, | ||
544 | &fin_init_zone, | ||
545 | NULL); | ||
546 | } | ||
547 | |||
548 | static void | ||
549 | do_lookup (void *cls, const struct GNUNET_PeerIdentity *id, | ||
550 | const struct GNUNET_CONFIGURATION_Handle *_cfg, | ||
551 | struct GNUNET_TESTING_Daemon *d, const char *emsg) | ||
507 | { | 552 | { |
508 | 553 | ||
509 | 554 | char* private_keyfile; | |
555 | char* shorten_keyfile; | ||
510 | char* our_keyfile; | 556 | char* our_keyfile; |
511 | 557 | ||
512 | cfg = _cfg; | 558 | cfg = _cfg; |
@@ -539,34 +585,63 @@ do_lookup(void *cls, const struct GNUNET_PeerIdentity *id, | |||
539 | ok = -1; | 585 | ok = -1; |
540 | return; | 586 | return; |
541 | } | 587 | } |
542 | 588 | ||
589 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns", | ||
590 | "SHORTEN_ZONEKEY", | ||
591 | &shorten_keyfile)) | ||
592 | { | ||
593 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
594 | "Failed to get shorten zone key from cfg\n"); | ||
595 | ok = -1; | ||
596 | return; | ||
597 | } | ||
598 | |||
599 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns", | ||
600 | "PRIVATE_ZONEKEY", | ||
601 | &private_keyfile)) | ||
602 | { | ||
603 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
604 | "Failed to get private zone key from cfg\n"); | ||
605 | ok = -1; | ||
606 | return; | ||
607 | } | ||
543 | our_key = GNUNET_CRYPTO_rsa_key_create_from_file (our_keyfile); | 608 | our_key = GNUNET_CRYPTO_rsa_key_create_from_file (our_keyfile); |
609 | priv_key = GNUNET_CRYPTO_rsa_key_create_from_file (private_keyfile); | ||
610 | short_key = GNUNET_CRYPTO_rsa_key_create_from_file (shorten_keyfile); | ||
544 | bob_key = GNUNET_CRYPTO_rsa_key_create_from_file (KEYFILE_BOB); | 611 | bob_key = GNUNET_CRYPTO_rsa_key_create_from_file (KEYFILE_BOB); |
545 | alice_key = GNUNET_CRYPTO_rsa_key_create_from_file (KEYFILE_ALICE); | 612 | alice_key = GNUNET_CRYPTO_rsa_key_create_from_file (KEYFILE_ALICE); |
546 | 613 | ||
547 | GNUNET_free(our_keyfile); | 614 | GNUNET_free(our_keyfile); |
615 | GNUNET_free(shorten_keyfile); | ||
616 | GNUNET_free(private_keyfile); | ||
548 | 617 | ||
549 | GNUNET_CRYPTO_rsa_key_get_public (our_key, &our_pkey); | 618 | GNUNET_CRYPTO_rsa_key_get_public (our_key, &our_pkey); |
619 | GNUNET_CRYPTO_rsa_key_get_public (priv_key, &priv_pkey); | ||
620 | GNUNET_CRYPTO_rsa_key_get_public (short_key, &short_pkey); | ||
550 | GNUNET_CRYPTO_rsa_key_get_public (bob_key, &bob_pkey); | 621 | GNUNET_CRYPTO_rsa_key_get_public (bob_key, &bob_pkey); |
551 | GNUNET_CRYPTO_rsa_key_get_public (alice_key, &alice_pkey); | 622 | GNUNET_CRYPTO_rsa_key_get_public (alice_key, &alice_pkey); |
552 | GNUNET_CRYPTO_short_hash(&bob_pkey, sizeof(bob_pkey), &bob_hash); | 623 | GNUNET_CRYPTO_short_hash(&bob_pkey, sizeof(bob_pkey), &bob_hash); |
553 | GNUNET_CRYPTO_short_hash(&alice_pkey, sizeof(alice_pkey), &alice_hash); | 624 | GNUNET_CRYPTO_short_hash(&alice_pkey, sizeof(alice_pkey), &alice_hash); |
554 | GNUNET_CRYPTO_short_hash(&our_pkey, sizeof(our_pkey), &our_zone); | 625 | GNUNET_CRYPTO_short_hash(&our_pkey, sizeof(our_pkey), &our_zone); |
555 | 626 | GNUNET_CRYPTO_short_hash(&priv_pkey, sizeof(priv_pkey), &priv_zone); | |
627 | GNUNET_CRYPTO_short_hash(&short_pkey, sizeof(short_pkey), &short_zone); | ||
628 | |||
556 | struct GNUNET_NAMESTORE_RecordData rd; | 629 | struct GNUNET_NAMESTORE_RecordData rd; |
557 | rd.expiration = GNUNET_TIME_UNIT_FOREVER_ABS; | 630 | rd.expiration = GNUNET_TIME_UNIT_FOREVER_ABS; |
558 | rd.data_size = sizeof(struct GNUNET_CRYPTO_ShortHashCode); | 631 | rd.data_size = sizeof(struct GNUNET_CRYPTO_ShortHashCode); |
559 | rd.data = &bob_hash; | 632 | rd.data = &priv_zone; |
560 | rd.record_type = GNUNET_GNS_RECORD_PKEY; | 633 | rd.record_type = GNUNET_GNS_RECORD_PKEY; |
561 | 634 | ||
562 | GNUNET_NAMESTORE_record_create (namestore_handle, | 635 | GNUNET_NAMESTORE_record_create (namestore_handle, |
563 | our_key, | 636 | our_key, |
564 | TEST_AUTHORITY_BOB, | 637 | TEST_PRIVATE_ZONE, |
565 | &rd, | 638 | &rd, |
566 | &put_pkey_dht, | 639 | &cont_init_zone, |
567 | NULL); | 640 | NULL); |
568 | 641 | ||
569 | 642 | ||
643 | |||
644 | |||
570 | } | 645 | } |
571 | 646 | ||
572 | static void | 647 | static void |