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/gnunet-service-gns.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/gnunet-service-gns.c')
-rw-r--r-- | src/gns/gnunet-service-gns.c | 281 |
1 files changed, 179 insertions, 102 deletions
diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c index 8f8340207..79aedccf4 100644 --- a/src/gns/gnunet-service-gns.c +++ b/src/gns/gnunet-service-gns.c | |||
@@ -64,8 +64,16 @@ struct ClientShortenHandle | |||
64 | struct GNUNET_CRYPTO_RsaPrivateKey *shorten_key; | 64 | struct GNUNET_CRYPTO_RsaPrivateKey *shorten_key; |
65 | 65 | ||
66 | /* name to shorten */ | 66 | /* name to shorten */ |
67 | char* name; | 67 | char name[MAX_DNS_NAME_LENGTH]; |
68 | 68 | ||
69 | /* root zone */ | ||
70 | struct GNUNET_CRYPTO_ShortHashCode root_zone; | ||
71 | |||
72 | /* private zone */ | ||
73 | struct GNUNET_CRYPTO_ShortHashCode private_zone; | ||
74 | |||
75 | /* shorten zone */ | ||
76 | struct GNUNET_CRYPTO_ShortHashCode shorten_zone; | ||
69 | }; | 77 | }; |
70 | 78 | ||
71 | 79 | ||
@@ -94,6 +102,12 @@ struct ClientLookupHandle | |||
94 | /* the requesting client that */ | 102 | /* the requesting client that */ |
95 | struct GNUNET_SERVER_Client *client; | 103 | struct GNUNET_SERVER_Client *client; |
96 | 104 | ||
105 | /* The zone we look up in */ | ||
106 | struct GNUNET_CRYPTO_ShortHashCode zone; | ||
107 | |||
108 | /* Do we only want to lookup from local cache? */ | ||
109 | int only_cached; | ||
110 | |||
97 | /* request id */ | 111 | /* request id */ |
98 | uint64_t unique_id; | 112 | uint64_t unique_id; |
99 | 113 | ||
@@ -167,6 +181,12 @@ static int auto_import_pkey; | |||
167 | /* lookup timeout */ | 181 | /* lookup timeout */ |
168 | static struct GNUNET_TIME_Relative default_lookup_timeout; | 182 | static struct GNUNET_TIME_Relative default_lookup_timeout; |
169 | 183 | ||
184 | /* name of the private zone */ | ||
185 | static char *private_zone_id; | ||
186 | |||
187 | /* name of the public zone */ | ||
188 | static char *shorten_zone_id; | ||
189 | |||
170 | /** | 190 | /** |
171 | * Continue shutdown | 191 | * Continue shutdown |
172 | */ | 192 | */ |
@@ -424,56 +444,6 @@ update_zone_dht_start(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
424 | NULL); | 444 | NULL); |
425 | } | 445 | } |
426 | 446 | ||
427 | /** | ||
428 | * Lookup the shorten key for the zone | ||
429 | * | ||
430 | * @param short_zone the zone we want a private key for | ||
431 | * @return NULL of not found else the key | ||
432 | */ | ||
433 | struct GNUNET_CRYPTO_RsaPrivateKey* | ||
434 | lookup_shorten_key(struct GNUNET_CRYPTO_ShortHashCode *short_zone) | ||
435 | { | ||
436 | char* keydir; | ||
437 | struct GNUNET_CRYPTO_ShortHashAsciiEncoded zonename; | ||
438 | char* location; | ||
439 | struct GNUNET_CRYPTO_RsaPrivateKey *key = NULL; | ||
440 | |||
441 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
442 | "Looking for shorten zonekey\n"); | ||
443 | |||
444 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (GNS_cfg, | ||
445 | "namestore", | ||
446 | "ZONEFILE_DIRECTORY", &keydir)) | ||
447 | { | ||
448 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
449 | "No zonefile directory!\n"); | ||
450 | return NULL; | ||
451 | } | ||
452 | |||
453 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
454 | "Zonefile directory is %s\n", keydir); | ||
455 | |||
456 | GNUNET_CRYPTO_short_hash_to_enc (short_zone, &zonename); | ||
457 | |||
458 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
459 | "Zonefile for shorten is %s.zkey\n", &zonename); | ||
460 | |||
461 | GNUNET_asprintf(&location, "%s%s%s.zkey", keydir, | ||
462 | DIR_SEPARATOR_STR, &zonename); | ||
463 | |||
464 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
465 | "Checking for %s\n", location); | ||
466 | |||
467 | if (GNUNET_YES == GNUNET_DISK_file_test (location)) | ||
468 | key = GNUNET_CRYPTO_rsa_key_create_from_file (location); | ||
469 | |||
470 | GNUNET_free(location); | ||
471 | GNUNET_free(keydir); | ||
472 | |||
473 | return key; | ||
474 | |||
475 | } | ||
476 | |||
477 | /* END DHT ZONE PROPAGATION */ | 447 | /* END DHT ZONE PROPAGATION */ |
478 | 448 | ||
479 | /** | 449 | /** |
@@ -512,12 +482,115 @@ send_shorten_response(void* cls, const char* name) | |||
512 | GNUNET_SERVER_receive_done (csh->client, GNUNET_OK); | 482 | GNUNET_SERVER_receive_done (csh->client, GNUNET_OK); |
513 | 483 | ||
514 | GNUNET_free(rmsg); | 484 | GNUNET_free(rmsg); |
515 | GNUNET_free_non_null(csh->name); | ||
516 | GNUNET_free_non_null(csh->shorten_key); | 485 | GNUNET_free_non_null(csh->shorten_key); |
517 | GNUNET_free(csh); | 486 | GNUNET_free(csh); |
518 | 487 | ||
519 | } | 488 | } |
520 | 489 | ||
490 | |||
491 | static void | ||
492 | process_shorten_zone_shorten (void *cls, | ||
493 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *key, | ||
494 | struct GNUNET_TIME_Absolute expiration, | ||
495 | const char *name, | ||
496 | unsigned int rd_count, | ||
497 | const struct GNUNET_NAMESTORE_RecordData *rd, | ||
498 | const struct GNUNET_CRYPTO_RsaSignature *signature) | ||
499 | { | ||
500 | struct ClientShortenHandle *csh = cls; | ||
501 | struct GNUNET_TIME_Relative remaining_time; | ||
502 | |||
503 | remaining_time = GNUNET_TIME_absolute_get_remaining (expiration); | ||
504 | |||
505 | if ((rd_count == 1) && | ||
506 | (remaining_time.rel_value != 0)) | ||
507 | { | ||
508 | remaining_time = GNUNET_TIME_absolute_get_remaining (rd->expiration); | ||
509 | if ((rd->record_type == GNUNET_GNS_RECORD_PKEY) && | ||
510 | (remaining_time.rel_value != 0)) | ||
511 | { | ||
512 | csh->shorten_zone = *((struct GNUNET_CRYPTO_ShortHashCode*)rd->data); | ||
513 | } | ||
514 | } | ||
515 | gns_resolver_shorten_name (&csh->root_zone, | ||
516 | &csh->private_zone, | ||
517 | &csh->shorten_zone, | ||
518 | csh->name, | ||
519 | private_zone_id, | ||
520 | shorten_zone_id, | ||
521 | &send_shorten_response, csh); | ||
522 | |||
523 | } | ||
524 | |||
525 | static void | ||
526 | process_private_zone_shorten (void *cls, | ||
527 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *key, | ||
528 | struct GNUNET_TIME_Absolute expiration, | ||
529 | const char *name, | ||
530 | unsigned int rd_count, | ||
531 | const struct GNUNET_NAMESTORE_RecordData *rd, | ||
532 | const struct GNUNET_CRYPTO_RsaSignature *signature) | ||
533 | { | ||
534 | struct GNUNET_TIME_Relative remaining_time; | ||
535 | struct ClientShortenHandle *csh = cls; | ||
536 | |||
537 | remaining_time = GNUNET_TIME_absolute_get_remaining (expiration); | ||
538 | |||
539 | if ((rd_count == 1) && | ||
540 | (remaining_time.rel_value != 0)) | ||
541 | { | ||
542 | remaining_time = GNUNET_TIME_absolute_get_remaining (rd->expiration); | ||
543 | if ((rd->record_type == GNUNET_GNS_RECORD_PKEY) && | ||
544 | (remaining_time.rel_value != 0)) | ||
545 | { | ||
546 | |||
547 | |||
548 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
549 | "Looking for shorten zone in private zone\n"); | ||
550 | csh->private_zone = *((struct GNUNET_CRYPTO_ShortHashCode*)rd->data); | ||
551 | GNUNET_NAMESTORE_lookup_record (namestore_handle, | ||
552 | &csh->private_zone, | ||
553 | shorten_zone_id, | ||
554 | GNUNET_GNS_RECORD_ANY, | ||
555 | &process_shorten_zone_shorten, | ||
556 | cls); | ||
557 | } | ||
558 | return; | ||
559 | } | ||
560 | |||
561 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
562 | "No private zone found!\n"); | ||
563 | gns_resolver_shorten_name (&csh->root_zone, | ||
564 | &csh->private_zone, | ||
565 | &csh->shorten_zone, | ||
566 | csh->name, | ||
567 | private_zone_id, | ||
568 | shorten_zone_id, | ||
569 | &send_shorten_response, csh); | ||
570 | |||
571 | } | ||
572 | |||
573 | /** | ||
574 | * Lookup the zone infos and shorten name | ||
575 | * | ||
576 | * @param csh the shorten handle | ||
577 | * | ||
578 | */ | ||
579 | static void | ||
580 | start_shorten_name (struct ClientShortenHandle *csh) | ||
581 | { | ||
582 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
583 | "Looking for private zone in root zone\n"); | ||
584 | |||
585 | GNUNET_NAMESTORE_lookup_record (namestore_handle, | ||
586 | &csh->root_zone, | ||
587 | private_zone_id, | ||
588 | GNUNET_GNS_RECORD_ANY, | ||
589 | &process_private_zone_shorten, | ||
590 | csh); | ||
591 | } | ||
592 | |||
593 | |||
521 | /** | 594 | /** |
522 | * Handle a shorten message from the api | 595 | * Handle a shorten message from the api |
523 | * | 596 | * |
@@ -525,9 +598,9 @@ send_shorten_response(void* cls, const char* name) | |||
525 | * @param client the client | 598 | * @param client the client |
526 | * @param message the message | 599 | * @param message the message |
527 | */ | 600 | */ |
528 | static void handle_shorten(void *cls, | 601 | static void handle_shorten (void *cls, |
529 | struct GNUNET_SERVER_Client * client, | 602 | struct GNUNET_SERVER_Client * client, |
530 | const struct GNUNET_MessageHeader * message) | 603 | const struct GNUNET_MessageHeader * message) |
531 | { | 604 | { |
532 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "SHORTEN"); | 605 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "SHORTEN"); |
533 | 606 | ||
@@ -535,8 +608,6 @@ static void handle_shorten(void *cls, | |||
535 | struct ClientShortenHandle *csh; | 608 | struct ClientShortenHandle *csh; |
536 | char name[MAX_DNS_NAME_LENGTH]; | 609 | char name[MAX_DNS_NAME_LENGTH]; |
537 | char* nameptr = name; | 610 | char* nameptr = name; |
538 | struct GNUNET_CRYPTO_ShortHashCode zone; | ||
539 | struct GNUNET_CRYPTO_RsaPrivateKey *key; | ||
540 | 611 | ||
541 | if (ntohs (message->size) < sizeof (struct GNUNET_GNS_ClientShortenMessage)) | 612 | if (ntohs (message->size) < sizeof (struct GNUNET_GNS_ClientShortenMessage)) |
542 | { | 613 | { |
@@ -568,7 +639,6 @@ static void handle_shorten(void *cls, | |||
568 | if (strlen (name) < strlen(GNUNET_GNS_TLD)) { | 639 | if (strlen (name) < strlen(GNUNET_GNS_TLD)) { |
569 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 640 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
570 | "SHORTEN: %s is too short", name); | 641 | "SHORTEN: %s is too short", name); |
571 | csh->name = NULL; | ||
572 | send_shorten_response(csh, name); | 642 | send_shorten_response(csh, name); |
573 | return; | 643 | return; |
574 | } | 644 | } |
@@ -576,7 +646,6 @@ static void handle_shorten(void *cls, | |||
576 | if (strlen (name) > MAX_DNS_NAME_LENGTH) { | 646 | if (strlen (name) > MAX_DNS_NAME_LENGTH) { |
577 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 647 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
578 | "SHORTEN: %s is too long", name); | 648 | "SHORTEN: %s is too long", name); |
579 | csh->name = NULL; | ||
580 | send_shorten_response(csh, name); | 649 | send_shorten_response(csh, name); |
581 | return; | 650 | return; |
582 | } | 651 | } |
@@ -585,34 +654,21 @@ static void handle_shorten(void *cls, | |||
585 | { | 654 | { |
586 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 655 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
587 | "%s is not our domain. Returning\n", name); | 656 | "%s is not our domain. Returning\n", name); |
588 | csh->name = NULL; | ||
589 | send_shorten_response(csh, name); | 657 | send_shorten_response(csh, name); |
590 | return; | 658 | return; |
591 | } | 659 | } |
660 | |||
661 | strcpy (csh->name, name); | ||
592 | 662 | ||
593 | GNUNET_SERVER_notification_context_add (nc, client); | 663 | GNUNET_SERVER_notification_context_add (nc, client); |
594 | 664 | ||
595 | if (1 == ntohl(sh_msg->use_default_zone)) | 665 | if (1 == ntohl(sh_msg->use_default_zone)) |
596 | zone = zone_hash; //Default zone | 666 | csh->root_zone = zone_hash; //Default zone |
597 | else | 667 | else |
598 | zone = sh_msg->zone; | 668 | csh->root_zone = sh_msg->zone; |
669 | |||
670 | start_shorten_name (csh); | ||
599 | 671 | ||
600 | /* Start shortening */ | ||
601 | if (GNUNET_YES == auto_import_pkey) | ||
602 | { | ||
603 | if (0 == ntohl(sh_msg->use_shorten_zone)) | ||
604 | key = NULL; | ||
605 | else | ||
606 | { | ||
607 | key = lookup_shorten_key(&sh_msg->shorten_zone); | ||
608 | csh->shorten_key = key; | ||
609 | } | ||
610 | gns_resolver_shorten_name(zone, zone, name, key, | ||
611 | &send_shorten_response, csh); | ||
612 | } | ||
613 | else | ||
614 | gns_resolver_shorten_name(zone, zone, name, NULL, | ||
615 | &send_shorten_response, csh); | ||
616 | } | 672 | } |
617 | 673 | ||
618 | 674 | ||
@@ -823,9 +879,10 @@ handle_lookup(void *cls, | |||
823 | char name[MAX_DNS_NAME_LENGTH]; | 879 | char name[MAX_DNS_NAME_LENGTH]; |
824 | struct ClientLookupHandle *clh; | 880 | struct ClientLookupHandle *clh; |
825 | char* nameptr = name; | 881 | char* nameptr = name; |
826 | struct GNUNET_CRYPTO_RsaPrivateKey *key = NULL; | ||
827 | struct GNUNET_CRYPTO_ShortHashCode zone; | ||
828 | int only_cached; | 882 | int only_cached; |
883 | struct GNUNET_CRYPTO_RsaPrivateKey *key; | ||
884 | struct GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded *pkey; | ||
885 | char* tmp_pkey; | ||
829 | 886 | ||
830 | if (ntohs (message->size) < sizeof (struct GNUNET_GNS_ClientLookupMessage)) | 887 | if (ntohs (message->size) < sizeof (struct GNUNET_GNS_ClientLookupMessage)) |
831 | { | 888 | { |
@@ -847,8 +904,20 @@ handle_lookup(void *cls, | |||
847 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 904 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
848 | return; | 905 | return; |
849 | } | 906 | } |
907 | |||
908 | if (1 == ntohl(sh_msg->have_key)) | ||
909 | { | ||
910 | pkey = (struct GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded *)&sh_msg[1]; | ||
911 | tmp_pkey = (char*)&sh_msg[1]; | ||
912 | key = GNUNET_CRYPTO_rsa_decode_key (tmp_pkey, ntohs(pkey->len)); | ||
913 | GNUNET_STRINGS_utf8_tolower(&tmp_pkey[ntohs(pkey->len)], &nameptr); | ||
914 | } | ||
915 | else | ||
916 | { | ||
917 | key = NULL; | ||
918 | GNUNET_STRINGS_utf8_tolower((char*)&sh_msg[1], &nameptr); | ||
919 | } | ||
850 | 920 | ||
851 | GNUNET_STRINGS_utf8_tolower((char*)&sh_msg[1], &nameptr); | ||
852 | namelen = strlen(name)+1; | 921 | namelen = strlen(name)+1; |
853 | clh = GNUNET_malloc(sizeof(struct ClientLookupHandle)); | 922 | clh = GNUNET_malloc(sizeof(struct ClientLookupHandle)); |
854 | clh->client = client; | 923 | clh->client = client; |
@@ -856,7 +925,7 @@ handle_lookup(void *cls, | |||
856 | strcpy(clh->name, name); | 925 | strcpy(clh->name, name); |
857 | clh->unique_id = sh_msg->id; | 926 | clh->unique_id = sh_msg->id; |
858 | clh->type = ntohl(sh_msg->type); | 927 | clh->type = ntohl(sh_msg->type); |
859 | clh->shorten_key = NULL; | 928 | clh->shorten_key = key; |
860 | 929 | ||
861 | only_cached = ntohl(sh_msg->only_cached); | 930 | only_cached = ntohl(sh_msg->only_cached); |
862 | 931 | ||
@@ -869,33 +938,25 @@ handle_lookup(void *cls, | |||
869 | } | 938 | } |
870 | 939 | ||
871 | if (1 == ntohl(sh_msg->use_default_zone)) | 940 | if (1 == ntohl(sh_msg->use_default_zone)) |
872 | zone = zone_hash; //Default zone | 941 | clh->zone = zone_hash; //Default zone |
873 | else | 942 | else |
874 | zone = sh_msg->zone; | 943 | clh->zone = sh_msg->zone; |
875 | 944 | ||
876 | if (GNUNET_YES == auto_import_pkey) | 945 | if (GNUNET_YES == auto_import_pkey) |
877 | { | 946 | { |
878 | if (1 == ntohl(sh_msg->use_shorten_zone)) | 947 | gns_resolver_lookup_record (clh->zone, clh->zone, clh->type, clh->name, |
879 | key = zone_key; | 948 | clh->shorten_key, |
880 | else | 949 | default_lookup_timeout, |
881 | { | 950 | clh->only_cached, |
882 | key = lookup_shorten_key(&sh_msg->shorten_zone); | 951 | &send_lookup_response, clh); |
883 | clh->shorten_key = key; | ||
884 | } | ||
885 | |||
886 | gns_resolver_lookup_record(zone, zone, clh->type, name, | ||
887 | key, | ||
888 | default_lookup_timeout, | ||
889 | only_cached, | ||
890 | &send_lookup_response, clh); | ||
891 | } | 952 | } |
892 | else | 953 | else |
893 | { | 954 | { |
894 | gns_resolver_lookup_record(zone, zone, clh->type, name, | 955 | gns_resolver_lookup_record (clh->zone, clh->zone, clh->type, name, |
895 | NULL, | 956 | NULL, |
896 | default_lookup_timeout, | 957 | default_lookup_timeout, |
897 | only_cached, | 958 | only_cached, |
898 | &send_lookup_response, clh); | 959 | &send_lookup_response, clh); |
899 | } | 960 | } |
900 | } | 961 | } |
901 | 962 | ||
@@ -977,6 +1038,22 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
977 | 1038 | ||
978 | } | 1039 | } |
979 | 1040 | ||
1041 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (c, "gns", | ||
1042 | "PRIVATE_ZONE", | ||
1043 | &private_zone_id)) | ||
1044 | { | ||
1045 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | ||
1046 | "Private zone id: %s\n", private_zone_id); | ||
1047 | } | ||
1048 | |||
1049 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (c, "gns", | ||
1050 | "SHORTEN_ZONE", | ||
1051 | &shorten_zone_id)) | ||
1052 | { | ||
1053 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | ||
1054 | "Shorten zone id: %s\n", shorten_zone_id); | ||
1055 | } | ||
1056 | |||
980 | dht_max_update_interval = GNUNET_GNS_DHT_MAX_UPDATE_INTERVAL; | 1057 | dht_max_update_interval = GNUNET_GNS_DHT_MAX_UPDATE_INTERVAL; |
981 | 1058 | ||
982 | if (GNUNET_OK == | 1059 | if (GNUNET_OK == |