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_resolver.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_resolver.c')
-rw-r--r-- | src/gns/gnunet-service-gns_resolver.c | 520 |
1 files changed, 390 insertions, 130 deletions
diff --git a/src/gns/gnunet-service-gns_resolver.c b/src/gns/gnunet-service-gns_resolver.c index 71f42e941..ff7842758 100644 --- a/src/gns/gnunet-service-gns_resolver.c +++ b/src/gns/gnunet-service-gns_resolver.c | |||
@@ -168,6 +168,7 @@ process_pseu_lookup_ns (void* cls, | |||
168 | GNUNET_free (gph->ahead); | 168 | GNUNET_free (gph->ahead); |
169 | gph->ahead = iter; | 169 | gph->ahead = iter; |
170 | } while (iter != NULL); | 170 | } while (iter != NULL); |
171 | GNUNET_CRYPTO_rsa_key_free (gph->key); | ||
171 | 172 | ||
172 | GNUNET_free (gph); | 173 | GNUNET_free (gph); |
173 | return; | 174 | return; |
@@ -208,8 +209,8 @@ process_pseu_lookup_ns (void* cls, | |||
208 | GNUNET_free (gph->ahead); | 209 | GNUNET_free (gph->ahead); |
209 | gph->ahead = iter; | 210 | gph->ahead = iter; |
210 | } while (iter != NULL); | 211 | } while (iter != NULL); |
211 | 212 | GNUNET_CRYPTO_rsa_key_free (gph->key); | |
212 | GNUNET_free(gph); | 213 | GNUNET_free (gph); |
213 | 214 | ||
214 | } | 215 | } |
215 | 216 | ||
@@ -329,7 +330,7 @@ process_auth_discovery_dht_result(void* cls, | |||
329 | GNUNET_free (gph->ahead); | 330 | GNUNET_free (gph->ahead); |
330 | gph->ahead = iter; | 331 | gph->ahead = iter; |
331 | } while (iter != NULL); | 332 | } while (iter != NULL); |
332 | 333 | GNUNET_CRYPTO_rsa_key_free (gph->key); | |
333 | GNUNET_free (gph); | 334 | GNUNET_free (gph); |
334 | return; | 335 | return; |
335 | } | 336 | } |
@@ -528,7 +529,7 @@ process_zone_to_name_discover (void *cls, | |||
528 | GNUNET_free (gph->ahead); | 529 | GNUNET_free (gph->ahead); |
529 | gph->ahead = iter; | 530 | gph->ahead = iter; |
530 | } while (iter != NULL); | 531 | } while (iter != NULL); |
531 | 532 | GNUNET_CRYPTO_rsa_key_free (gph->key); | |
532 | GNUNET_free (gph); | 533 | GNUNET_free (gph); |
533 | } | 534 | } |
534 | else | 535 | else |
@@ -579,6 +580,7 @@ start_shorten (struct AuthorityChain *atail, | |||
579 | struct AuthorityChain *acopy; | 580 | struct AuthorityChain *acopy; |
580 | struct GetPseuAuthorityHandle *gph; | 581 | struct GetPseuAuthorityHandle *gph; |
581 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pkey; | 582 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pkey; |
583 | struct GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded *pb_key; | ||
582 | 584 | ||
583 | /* First copy the authority chain in reverse order */ | 585 | /* First copy the authority chain in reverse order */ |
584 | for (iter = atail; iter != NULL; iter = iter->prev) | 586 | for (iter = atail; iter != NULL; iter = iter->prev) |
@@ -593,7 +595,9 @@ start_shorten (struct AuthorityChain *atail, | |||
593 | gph = GNUNET_malloc (sizeof (struct GetPseuAuthorityHandle)); | 595 | gph = GNUNET_malloc (sizeof (struct GetPseuAuthorityHandle)); |
594 | 596 | ||
595 | GNUNET_CRYPTO_rsa_key_get_public (key, &pkey); | 597 | GNUNET_CRYPTO_rsa_key_get_public (key, &pkey); |
596 | gph->key = key;//GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_RsaPrivateKey)); | 598 | pb_key = GNUNET_CRYPTO_rsa_encode_key (key); |
599 | gph->key = GNUNET_CRYPTO_rsa_decode_key ((char*)pb_key, ntohs (pb_key->len)); | ||
600 | //gph->key = key;//GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_RsaPrivateKey)); | ||
597 | //memcpy (gph->key, key, sizeof (struct GNUNET_CRYPTO_RsaPrivateKey)); | 601 | //memcpy (gph->key, key, sizeof (struct GNUNET_CRYPTO_RsaPrivateKey)); |
598 | 602 | ||
599 | GNUNET_CRYPTO_short_hash (&pkey, | 603 | GNUNET_CRYPTO_short_hash (&pkey, |
@@ -2293,6 +2297,12 @@ gns_resolver_lookup_record(struct GNUNET_CRYPTO_ShortHashCode zone, | |||
2293 | rh->get_handle = NULL; | 2297 | rh->get_handle = NULL; |
2294 | rh->private_local_zone = pzone; | 2298 | rh->private_local_zone = pzone; |
2295 | rh->only_cached = only_cached; | 2299 | rh->only_cached = only_cached; |
2300 | |||
2301 | if (NULL == key) | ||
2302 | { | ||
2303 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2304 | "No shorten key for resolution\n"); | ||
2305 | } | ||
2296 | 2306 | ||
2297 | if (timeout.rel_value != GNUNET_TIME_UNIT_FOREVER_REL.rel_value) | 2307 | if (timeout.rel_value != GNUNET_TIME_UNIT_FOREVER_REL.rel_value) |
2298 | { | 2308 | { |
@@ -2394,7 +2404,6 @@ gns_resolver_lookup_record(struct GNUNET_CRYPTO_ShortHashCode zone, | |||
2394 | 2404 | ||
2395 | /******** END Record Resolver ***********/ | 2405 | /******** END Record Resolver ***********/ |
2396 | 2406 | ||
2397 | |||
2398 | /** | 2407 | /** |
2399 | * Callback calles by namestore for a zone to name | 2408 | * Callback calles by namestore for a zone to name |
2400 | * result | 2409 | * result |
@@ -2408,7 +2417,29 @@ gns_resolver_lookup_record(struct GNUNET_CRYPTO_ShortHashCode zone, | |||
2408 | * @param signature the signature for the record data | 2417 | * @param signature the signature for the record data |
2409 | */ | 2418 | */ |
2410 | static void | 2419 | static void |
2411 | process_zone_to_name_shorten(void *cls, | 2420 | process_zone_to_name_shorten_root (void *cls, |
2421 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key, | ||
2422 | struct GNUNET_TIME_Absolute expire, | ||
2423 | const char *name, | ||
2424 | unsigned int rd_len, | ||
2425 | const struct GNUNET_NAMESTORE_RecordData *rd, | ||
2426 | const struct GNUNET_CRYPTO_RsaSignature *signature); | ||
2427 | |||
2428 | |||
2429 | /** | ||
2430 | * Callback called by namestore for a zone to name | ||
2431 | * result | ||
2432 | * | ||
2433 | * @param cls the closure | ||
2434 | * @param zone_key the zone we queried | ||
2435 | * @param expire the expiration time of the name | ||
2436 | * @param name the name found or NULL | ||
2437 | * @param rd_len number of records for the name | ||
2438 | * @param rd the record data (PKEY) for the name | ||
2439 | * @param signature the signature for the record data | ||
2440 | */ | ||
2441 | static void | ||
2442 | process_zone_to_name_shorten_shorten (void *cls, | ||
2412 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key, | 2443 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key, |
2413 | struct GNUNET_TIME_Absolute expire, | 2444 | struct GNUNET_TIME_Absolute expire, |
2414 | const char *name, | 2445 | const char *name, |
@@ -2424,53 +2455,184 @@ process_zone_to_name_shorten(void *cls, | |||
2424 | char tmp_name[MAX_DNS_NAME_LENGTH]; | 2455 | char tmp_name[MAX_DNS_NAME_LENGTH]; |
2425 | size_t answer_len; | 2456 | size_t answer_len; |
2426 | 2457 | ||
2427 | /* we found a match in our own zone */ | 2458 | /* we found a match in our own root zone */ |
2428 | if (rd_len != 0) | 2459 | if (rd_len != 0) |
2429 | { | 2460 | { |
2430 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 2461 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2431 | "result strlen %d\n", strlen(name)); | 2462 | "result strlen %d\n", strlen(name)); |
2432 | answer_len = strlen(rh->name) + strlen(name) + strlen(GNUNET_GNS_TLD) + 3; | 2463 | answer_len = strlen(rh->name) + strlen(name) + strlen(GNUNET_GNS_TLD) + 3; |
2433 | memset(result, 0, answer_len); | 2464 | memset(result, 0, answer_len); |
2465 | |||
2434 | if (strlen(rh->name) > 0) | 2466 | if (strlen(rh->name) > 0) |
2435 | { | 2467 | { |
2436 | strcpy(result, rh->name); | 2468 | sprintf (result, "%s.%s.%s.%s.%s", |
2437 | strcpy(result+strlen(rh->name), "."); | 2469 | rh->name, name, |
2470 | nsh->shorten_zone_name, nsh->private_zone_name, | ||
2471 | GNUNET_GNS_TLD); | ||
2472 | } | ||
2473 | else | ||
2474 | { | ||
2475 | sprintf (result, "%s.%s.%s.%s", name, | ||
2476 | nsh->shorten_zone_name, nsh->private_zone_name, | ||
2477 | GNUNET_GNS_TLD); | ||
2438 | } | 2478 | } |
2439 | |||
2440 | strcpy(result+strlen(result), name); | ||
2441 | strcpy(result+strlen(result), "."); | ||
2442 | strcpy(result+strlen(result), GNUNET_GNS_TLD); | ||
2443 | 2479 | ||
2444 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 2480 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2445 | "Sending shorten result %s\n", result); | 2481 | "Found shorten result %s\n", result); |
2446 | 2482 | if (strlen (nsh->result) > strlen (result)) | |
2447 | nsh->proc(nsh->proc_cls, result); | 2483 | strcpy (nsh->result, result); |
2448 | GNUNET_free(nsh); | ||
2449 | free_resolver_handle(rh); | ||
2450 | } | 2484 | } |
2451 | else if (GNUNET_CRYPTO_short_hash_cmp(&rh->authority_chain_head->zone, | 2485 | else if (GNUNET_CRYPTO_short_hash_cmp(&rh->authority_chain_head->zone, |
2452 | &rh->private_local_zone) == 0) | 2486 | nsh->shorten_zone) == 0) |
2487 | { | ||
2488 | /** | ||
2489 | * This is our zone append .gnunet unless name is empty | ||
2490 | * (it shouldn't be, usually FIXME what happens if we | ||
2491 | * shorten to our zone to a "" record??) | ||
2492 | */ | ||
2493 | |||
2494 | sprintf (result, "%s.%s.%s.%s", | ||
2495 | rh->name, | ||
2496 | nsh->shorten_zone_name, nsh->private_zone_name, | ||
2497 | GNUNET_GNS_TLD); | ||
2498 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
2499 | "Our zone: Found %s as shorten result\n", result); | ||
2500 | |||
2501 | if (strlen (nsh->result) > strlen (result)) | ||
2502 | strcpy (nsh->result, result); | ||
2503 | //nsh->proc(nsh->proc_cls, result); | ||
2504 | //GNUNET_free(nsh); | ||
2505 | //free_resolver_handle(rh); | ||
2506 | //return; | ||
2507 | } | ||
2508 | |||
2509 | |||
2510 | /** | ||
2511 | * No PSEU found. | ||
2512 | * continue with next authority if exists | ||
2513 | */ | ||
2514 | if ((rh->authority_chain_head->next == NULL)) | ||
2515 | { | ||
2516 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2517 | "Sending %s as shorten result\n", nsh->result); | ||
2518 | nsh->proc(nsh->proc_cls, nsh->result); | ||
2519 | GNUNET_free (nsh); | ||
2520 | free_resolver_handle (rh); | ||
2521 | return; | ||
2522 | } | ||
2523 | next_authority = rh->authority_chain_head; | ||
2524 | |||
2525 | GNUNET_snprintf(tmp_name, MAX_DNS_NAME_LENGTH, | ||
2526 | "%s.%s", rh->name, next_authority->name); | ||
2527 | |||
2528 | strcpy(rh->name, tmp_name); | ||
2529 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
2530 | "No PSEU found for authority %s. Promoting back: %s\n", | ||
2531 | next_authority->name, rh->name); | ||
2532 | |||
2533 | GNUNET_CONTAINER_DLL_remove(rh->authority_chain_head, | ||
2534 | rh->authority_chain_tail, | ||
2535 | next_authority); | ||
2536 | |||
2537 | GNUNET_NAMESTORE_zone_to_name (namestore_handle, | ||
2538 | &rh->authority_chain_tail->zone, | ||
2539 | &rh->authority_chain_head->zone, | ||
2540 | &process_zone_to_name_shorten_root, | ||
2541 | rh); | ||
2542 | } | ||
2543 | |||
2544 | /** | ||
2545 | * Callback calles by namestore for a zone to name | ||
2546 | * result | ||
2547 | * | ||
2548 | * @param cls the closure | ||
2549 | * @param zone_key the zone we queried | ||
2550 | * @param expire the expiration time of the name | ||
2551 | * @param name the name found or NULL | ||
2552 | * @param rd_len number of records for the name | ||
2553 | * @param rd the record data (PKEY) for the name | ||
2554 | * @param signature the signature for the record data | ||
2555 | */ | ||
2556 | static void | ||
2557 | process_zone_to_name_shorten_private (void *cls, | ||
2558 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key, | ||
2559 | struct GNUNET_TIME_Absolute expire, | ||
2560 | const char *name, | ||
2561 | unsigned int rd_len, | ||
2562 | const struct GNUNET_NAMESTORE_RecordData *rd, | ||
2563 | const struct GNUNET_CRYPTO_RsaSignature *signature) | ||
2564 | { | ||
2565 | struct ResolverHandle *rh = (struct ResolverHandle *)cls; | ||
2566 | struct NameShortenHandle* nsh = (struct NameShortenHandle*)rh->proc_cls; | ||
2567 | struct AuthorityChain *next_authority; | ||
2568 | |||
2569 | char result[MAX_DNS_NAME_LENGTH]; | ||
2570 | char tmp_name[MAX_DNS_NAME_LENGTH]; | ||
2571 | size_t answer_len; | ||
2572 | |||
2573 | /* we found a match in our own root zone */ | ||
2574 | if (rd_len != 0) | ||
2453 | { | 2575 | { |
2454 | /* our zone, just append .gnunet */ | 2576 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2455 | answer_len = strlen(rh->name) + strlen(GNUNET_GNS_TLD) + 2; | 2577 | "result strlen %d\n", strlen(name)); |
2578 | answer_len = strlen(rh->name) + strlen(name) + strlen(GNUNET_GNS_TLD) + 3; | ||
2456 | memset(result, 0, answer_len); | 2579 | memset(result, 0, answer_len); |
2457 | strcpy(result, rh->name); | ||
2458 | strcpy(result+strlen(rh->name), "."); | ||
2459 | strcpy(result+strlen(rh->name)+1, GNUNET_GNS_TLD); | ||
2460 | 2580 | ||
2581 | if (strlen(rh->name) > 0) | ||
2582 | { | ||
2583 | sprintf (result, "%s.%s.%s", rh->name, name, GNUNET_GNS_TLD); | ||
2584 | } | ||
2585 | else | ||
2586 | { | ||
2587 | sprintf (result, "%s.%s", name, GNUNET_GNS_TLD); | ||
2588 | } | ||
2589 | |||
2461 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 2590 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2462 | "Our zone: Sending name as shorten result %s\n", rh->name); | 2591 | "Found shorten result %s\n", result); |
2592 | if (strlen (nsh->result) > strlen (result)) | ||
2593 | strcpy (nsh->result, result); | ||
2594 | } | ||
2595 | else if (GNUNET_CRYPTO_short_hash_cmp(&rh->authority_chain_head->zone, | ||
2596 | nsh->private_zone) == 0) | ||
2597 | { | ||
2598 | /** | ||
2599 | * This is our zone append .gnunet unless name is empty | ||
2600 | * (it shouldn't be, usually FIXME what happens if we | ||
2601 | * shorten to our zone to a "" record??) | ||
2602 | */ | ||
2463 | 2603 | ||
2464 | nsh->proc(nsh->proc_cls, result); | 2604 | sprintf (result, "%s.%s.%s", |
2465 | GNUNET_free(nsh); | 2605 | rh->name, nsh->private_zone_name, GNUNET_GNS_TLD); |
2466 | free_resolver_handle(rh); | 2606 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2607 | "Our private zone: Found %s as shorten result %s\n", result); | ||
2608 | if (strlen (nsh->result) > strlen (result)) | ||
2609 | strcpy (nsh->result, result); | ||
2610 | } | ||
2611 | |||
2612 | if (nsh->shorten_zone != NULL) | ||
2613 | { | ||
2614 | /* backtrack authorities for names in priv zone */ | ||
2615 | GNUNET_NAMESTORE_zone_to_name (namestore_handle, | ||
2616 | nsh->shorten_zone, | ||
2617 | &rh->authority_chain_head->zone, | ||
2618 | &process_zone_to_name_shorten_shorten, | ||
2619 | rh); | ||
2467 | } | 2620 | } |
2468 | else | 2621 | else |
2469 | { | 2622 | { |
2470 | /** | 2623 | /** |
2471 | * No PSEU found. | 2624 | * No PSEU found. |
2472 | * continue with next authority | 2625 | * continue with next authority if exists |
2473 | */ | 2626 | */ |
2627 | if ((rh->authority_chain_head->next == NULL)) | ||
2628 | { | ||
2629 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
2630 | "Sending %s as shorten result\n", nsh->result); | ||
2631 | nsh->proc(nsh->proc_cls, nsh->result); | ||
2632 | GNUNET_free(nsh); | ||
2633 | free_resolver_handle(rh); | ||
2634 | return; | ||
2635 | } | ||
2474 | next_authority = rh->authority_chain_head; | 2636 | next_authority = rh->authority_chain_head; |
2475 | 2637 | ||
2476 | GNUNET_snprintf(tmp_name, MAX_DNS_NAME_LENGTH, | 2638 | GNUNET_snprintf(tmp_name, MAX_DNS_NAME_LENGTH, |
@@ -2488,32 +2650,125 @@ process_zone_to_name_shorten(void *cls, | |||
2488 | GNUNET_NAMESTORE_zone_to_name (namestore_handle, | 2650 | GNUNET_NAMESTORE_zone_to_name (namestore_handle, |
2489 | &rh->authority_chain_tail->zone, | 2651 | &rh->authority_chain_tail->zone, |
2490 | &rh->authority_chain_head->zone, | 2652 | &rh->authority_chain_head->zone, |
2491 | &process_zone_to_name_shorten, | 2653 | &process_zone_to_name_shorten_root, |
2492 | rh); | 2654 | rh); |
2493 | } | 2655 | } |
2494 | } | 2656 | } |
2495 | 2657 | ||
2496 | /** | 2658 | /** |
2497 | * DHT resolution for delegation. Processing result. | 2659 | * Callback calles by namestore for a zone to name |
2660 | * result | ||
2498 | * | 2661 | * |
2499 | * @param cls the closure | 2662 | * @param cls the closure |
2500 | * @param rh resolver handle | 2663 | * @param zone_key the zone we queried |
2501 | * @param rd_count number of results | 2664 | * @param expire the expiration time of the name |
2502 | * @param rd record data | 2665 | * @param name the name found or NULL |
2666 | * @param rd_len number of records for the name | ||
2667 | * @param rd the record data (PKEY) for the name | ||
2668 | * @param signature the signature for the record data | ||
2503 | */ | 2669 | */ |
2504 | static void | 2670 | static void |
2505 | handle_delegation_dht_bg_shorten(void* cls, struct ResolverHandle *rh, | 2671 | process_zone_to_name_shorten_root (void *cls, |
2506 | unsigned int rd_count, | 2672 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key, |
2507 | const struct GNUNET_NAMESTORE_RecordData *rd) | 2673 | struct GNUNET_TIME_Absolute expire, |
2674 | const char *name, | ||
2675 | unsigned int rd_len, | ||
2676 | const struct GNUNET_NAMESTORE_RecordData *rd, | ||
2677 | const struct GNUNET_CRYPTO_RsaSignature *signature) | ||
2508 | { | 2678 | { |
2679 | struct ResolverHandle *rh = (struct ResolverHandle *)cls; | ||
2680 | struct NameShortenHandle* nsh = (struct NameShortenHandle*)rh->proc_cls; | ||
2681 | struct AuthorityChain *next_authority; | ||
2682 | |||
2683 | char result[MAX_DNS_NAME_LENGTH]; | ||
2684 | char tmp_name[MAX_DNS_NAME_LENGTH]; | ||
2685 | size_t answer_len; | ||
2509 | 2686 | ||
2510 | /* We resolved full name for delegation. resolving record */ | 2687 | /* we found a match in our own root zone */ |
2511 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 2688 | if (rd_len != 0) |
2512 | "GNS_SHORTEN: Resolved up to %s for delegation via DHT in background.\n", | 2689 | { |
2513 | rh->name); | 2690 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2514 | free_resolver_handle(rh); | 2691 | "result strlen %d\n", strlen(name)); |
2692 | answer_len = strlen(rh->name) + strlen(name) + strlen(GNUNET_GNS_TLD) + 3; | ||
2693 | memset(result, 0, answer_len); | ||
2694 | |||
2695 | if (strlen(rh->name) > 0) | ||
2696 | { | ||
2697 | sprintf (result, "%s.%s.%s", rh->name, name, GNUNET_GNS_TLD); | ||
2698 | } | ||
2699 | else | ||
2700 | { | ||
2701 | sprintf (result, "%s.%s", name, GNUNET_GNS_TLD); | ||
2702 | } | ||
2703 | |||
2704 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
2705 | "Found shorten result %s\n", result); | ||
2706 | if (strlen (nsh->result) > strlen (result)) | ||
2707 | strcpy (nsh->result, result); | ||
2708 | } | ||
2709 | else if (GNUNET_CRYPTO_short_hash_cmp(&rh->authority_chain_head->zone, | ||
2710 | nsh->root_zone) == 0) | ||
2711 | { | ||
2712 | /** | ||
2713 | * This is our zone append .gnunet unless name is empty | ||
2714 | * (it shouldn't be, usually FIXME what happens if we | ||
2715 | * shorten to our zone to a "" record??) | ||
2716 | */ | ||
2717 | |||
2718 | sprintf (result, "%s.%s", rh->name, GNUNET_GNS_TLD); | ||
2719 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
2720 | "Our zone: Found %s as shorten result\n", result); | ||
2721 | if (strlen (nsh->result) > strlen (result)) | ||
2722 | strcpy (nsh->result, result); | ||
2723 | } | ||
2724 | |||
2725 | if (nsh->private_zone != NULL) | ||
2726 | { | ||
2727 | /* backtrack authorities for names in priv zone */ | ||
2728 | GNUNET_NAMESTORE_zone_to_name (namestore_handle, | ||
2729 | nsh->private_zone, | ||
2730 | &rh->authority_chain_head->zone, | ||
2731 | &process_zone_to_name_shorten_private, | ||
2732 | rh); | ||
2733 | } | ||
2734 | else | ||
2735 | { | ||
2736 | /** | ||
2737 | * No PSEU found. | ||
2738 | * continue with next authority if exists | ||
2739 | */ | ||
2740 | if ((rh->authority_chain_head->next == NULL)) | ||
2741 | { | ||
2742 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
2743 | "Sending %s as shorten result\n", nsh->result); | ||
2744 | nsh->proc(nsh->proc_cls, nsh->result); | ||
2745 | GNUNET_free(nsh); | ||
2746 | free_resolver_handle(rh); | ||
2747 | return; | ||
2748 | } | ||
2749 | next_authority = rh->authority_chain_head; | ||
2750 | |||
2751 | GNUNET_snprintf(tmp_name, MAX_DNS_NAME_LENGTH, | ||
2752 | "%s.%s", rh->name, next_authority->name); | ||
2753 | |||
2754 | strcpy(rh->name, tmp_name); | ||
2755 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
2756 | "No PSEU found for authority %s. Promoting back: %s\n", | ||
2757 | next_authority->name, rh->name); | ||
2758 | |||
2759 | GNUNET_CONTAINER_DLL_remove(rh->authority_chain_head, | ||
2760 | rh->authority_chain_tail, | ||
2761 | next_authority); | ||
2762 | |||
2763 | GNUNET_NAMESTORE_zone_to_name (namestore_handle, | ||
2764 | &rh->authority_chain_tail->zone, | ||
2765 | &rh->authority_chain_head->zone, | ||
2766 | &process_zone_to_name_shorten_root, | ||
2767 | rh); | ||
2768 | } | ||
2515 | } | 2769 | } |
2516 | 2770 | ||
2771 | |||
2517 | /** | 2772 | /** |
2518 | * Process result from namestore delegation lookup | 2773 | * Process result from namestore delegation lookup |
2519 | * for shorten operation | 2774 | * for shorten operation |
@@ -2531,8 +2786,6 @@ handle_delegation_ns_shorten(void* cls, | |||
2531 | { | 2786 | { |
2532 | struct NameShortenHandle *nsh; | 2787 | struct NameShortenHandle *nsh; |
2533 | char result[MAX_DNS_NAME_LENGTH]; | 2788 | char result[MAX_DNS_NAME_LENGTH]; |
2534 | size_t answer_len; | ||
2535 | struct ResolverHandle *rh_bg; | ||
2536 | 2789 | ||
2537 | nsh = (struct NameShortenHandle *)cls; | 2790 | nsh = (struct NameShortenHandle *)cls; |
2538 | 2791 | ||
@@ -2545,9 +2798,10 @@ handle_delegation_ns_shorten(void* cls, | |||
2545 | 2798 | ||
2546 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 2799 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2547 | "PKEY resolved as far as possible in ns up to %s!\n", rh->name); | 2800 | "PKEY resolved as far as possible in ns up to %s!\n", rh->name); |
2801 | memset(result, 0, sizeof (result)); | ||
2548 | 2802 | ||
2549 | if (GNUNET_CRYPTO_short_hash_cmp(&rh->authority_chain_head->zone, | 2803 | if (GNUNET_CRYPTO_short_hash_cmp(&rh->authority_chain_head->zone, |
2550 | &rh->private_local_zone) == 0) | 2804 | nsh->root_zone) == 0) |
2551 | { | 2805 | { |
2552 | /** | 2806 | /** |
2553 | * This is our zone append .gnunet unless name is empty | 2807 | * This is our zone append .gnunet unless name is empty |
@@ -2555,64 +2809,57 @@ handle_delegation_ns_shorten(void* cls, | |||
2555 | * shorten to our zone to a "" record??) | 2809 | * shorten to our zone to a "" record??) |
2556 | */ | 2810 | */ |
2557 | 2811 | ||
2558 | answer_len = strlen(rh->name) + strlen(GNUNET_GNS_TLD) + 2; | 2812 | sprintf (result, "%s.%s", rh->name, GNUNET_GNS_TLD); |
2559 | memset(result, 0, answer_len); | 2813 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2560 | strcpy(result, rh->name); | 2814 | "Our zone: Found %s as shorten result\n", result); |
2561 | strcpy(result+strlen(rh->name), "."); | 2815 | |
2562 | strcpy(result+strlen(rh->name)+1, GNUNET_GNS_TLD); | 2816 | if (strlen (nsh->result) > strlen (result)) |
2817 | strcpy (nsh->result, result); | ||
2563 | 2818 | ||
2819 | } | ||
2820 | else if (GNUNET_CRYPTO_short_hash_cmp(&rh->authority_chain_head->zone, | ||
2821 | nsh->private_zone) == 0) | ||
2822 | { | ||
2823 | /** | ||
2824 | * This is our zone append .gnunet unless name is empty | ||
2825 | * (it shouldn't be, usually FIXME what happens if we | ||
2826 | * shorten to our zone to a "" record??) | ||
2827 | */ | ||
2828 | |||
2829 | sprintf (result, "%s.%s.%s", | ||
2830 | rh->name, nsh->private_zone_name, GNUNET_GNS_TLD); | ||
2564 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 2831 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2565 | "Our zone: Sending name as shorten result %s\n", rh->name); | 2832 | "Our zone: Found %s as shorten result %s\n", result); |
2566 | 2833 | ||
2567 | nsh->proc(nsh->proc_cls, result); | 2834 | if (strlen (nsh->result) > strlen (result)) |
2568 | GNUNET_free(nsh); | 2835 | strcpy (nsh->result, result); |
2569 | free_resolver_handle(rh); | ||
2570 | return; | ||
2571 | } | 2836 | } |
2572 | 2837 | else if (GNUNET_CRYPTO_short_hash_cmp(&rh->authority_chain_head->zone, | |
2573 | /** | 2838 | nsh->shorten_zone) == 0) |
2574 | * we have to this before zone to name for rh might | ||
2575 | * be freed by then | ||
2576 | */ | ||
2577 | rh_bg = NULL; | ||
2578 | if (!is_canonical(rh->name)) | ||
2579 | { | 2839 | { |
2580 | rh_bg = GNUNET_malloc(sizeof(struct ResolverHandle)); | 2840 | /** |
2581 | memcpy(rh_bg, rh, sizeof(struct ResolverHandle)); | 2841 | * This is our zone append .gnunet unless name is empty |
2582 | rh_bg->id = rid++; | 2842 | * (it shouldn't be, usually FIXME what happens if we |
2843 | * shorten to our zone to a "" record??) | ||
2844 | */ | ||
2845 | |||
2846 | sprintf (result, "%s.%s.%s", | ||
2847 | rh->name, nsh->private_zone_name, GNUNET_GNS_TLD); | ||
2848 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
2849 | "Our zone: Found %s as shorten result\n", result); | ||
2850 | |||
2851 | if (strlen (nsh->result) > strlen (result)) | ||
2852 | strcpy (nsh->result, result); | ||
2583 | } | 2853 | } |
2584 | 2854 | ||
2855 | |||
2585 | /* backtrack authorities for names */ | 2856 | /* backtrack authorities for names */ |
2586 | GNUNET_NAMESTORE_zone_to_name (namestore_handle, | 2857 | GNUNET_NAMESTORE_zone_to_name (namestore_handle, |
2587 | &rh->authority_chain_tail->zone, //ours | 2858 | nsh->root_zone, |
2588 | &rh->authority_chain_head->zone, | 2859 | &rh->authority_chain_head->zone, |
2589 | &process_zone_to_name_shorten, | 2860 | &process_zone_to_name_shorten_root, |
2590 | rh); | 2861 | rh); |
2591 | 2862 | ||
2592 | if (rh_bg == NULL) | ||
2593 | { | ||
2594 | return; | ||
2595 | } | ||
2596 | |||
2597 | /** | ||
2598 | * If authority resolution is incomplete we can do a background lookup | ||
2599 | * of the full name so that next time we can (likely) fully or at least | ||
2600 | * further shorten the name | ||
2601 | */ | ||
2602 | rh_bg->authority_chain_head = GNUNET_malloc(sizeof(struct AuthorityChain)); | ||
2603 | rh_bg->authority_chain_tail = rh_bg->authority_chain_head; | ||
2604 | rh_bg->authority_chain_head->zone = rh_bg->authority; | ||
2605 | |||
2606 | rh_bg->proc = &handle_delegation_dht_bg_shorten; | ||
2607 | rh_bg->proc_cls = NULL; | ||
2608 | rh_bg->timeout = GNUNET_TIME_UNIT_FOREVER_REL; | ||
2609 | |||
2610 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
2611 | "GNS_SHORTEN: Starting background lookup for %s\n", | ||
2612 | rh_bg->name); | ||
2613 | |||
2614 | resolve_delegation_dht(rh_bg); | ||
2615 | |||
2616 | } | 2863 | } |
2617 | 2864 | ||
2618 | 2865 | ||
@@ -2662,6 +2909,9 @@ process_zone_to_name_zkey(void *cls, | |||
2662 | else | 2909 | else |
2663 | GNUNET_snprintf(new_name, MAX_DNS_NAME_LENGTH, "%s.%s", | 2910 | GNUNET_snprintf(new_name, MAX_DNS_NAME_LENGTH, "%s.%s", |
2664 | enc, GNUNET_GNS_TLD_ZKEY); | 2911 | enc, GNUNET_GNS_TLD_ZKEY); |
2912 | |||
2913 | strcpy (nsh->result, new_name); | ||
2914 | |||
2665 | nsh->proc(nsh->proc_cls, new_name); | 2915 | nsh->proc(nsh->proc_cls, new_name); |
2666 | GNUNET_free(nsh); | 2916 | GNUNET_free(nsh); |
2667 | free_resolver_handle(rh); | 2917 | free_resolver_handle(rh); |
@@ -2692,20 +2942,24 @@ process_zone_to_name_zkey(void *cls, | |||
2692 | /** | 2942 | /** |
2693 | * Shorten api from resolver | 2943 | * Shorten api from resolver |
2694 | * | 2944 | * |
2695 | * @param zone the zone to use | 2945 | * @param zone the root zone to use |
2696 | * @param pzone the private local zone | 2946 | * @param pzone the private zone to use |
2947 | * @param szone the shorten zone to use | ||
2697 | * @param name the name to shorten | 2948 | * @param name the name to shorten |
2698 | * @param key optional private key for background lookups and PSEU import | 2949 | * @param private_zone_name name of the private zone |
2950 | * @param shorten_zone_name name of the shorten zone | ||
2699 | * @param proc the processor to call with result | 2951 | * @param proc the processor to call with result |
2700 | * @param proc_cls closure to pass to proc | 2952 | * @param proc_cls closure to pass to proc |
2701 | */ | 2953 | */ |
2702 | void | 2954 | void |
2703 | gns_resolver_shorten_name(struct GNUNET_CRYPTO_ShortHashCode zone, | 2955 | gns_resolver_shorten_name (struct GNUNET_CRYPTO_ShortHashCode *zone, |
2704 | struct GNUNET_CRYPTO_ShortHashCode pzone, | 2956 | struct GNUNET_CRYPTO_ShortHashCode *pzone, |
2705 | const char* name, | 2957 | struct GNUNET_CRYPTO_ShortHashCode *szone, |
2706 | struct GNUNET_CRYPTO_RsaPrivateKey *key, | 2958 | const char* name, |
2707 | ShortenResultProcessor proc, | 2959 | const char* private_zone_name, |
2708 | void* proc_cls) | 2960 | const char* shorten_zone_name, |
2961 | ShortenResultProcessor proc, | ||
2962 | void* proc_cls) | ||
2709 | { | 2963 | { |
2710 | struct ResolverHandle *rh; | 2964 | struct ResolverHandle *rh; |
2711 | struct NameShortenHandle *nsh; | 2965 | struct NameShortenHandle *nsh; |
@@ -2718,31 +2972,37 @@ gns_resolver_shorten_name(struct GNUNET_CRYPTO_ShortHashCode zone, | |||
2718 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2972 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2719 | "Starting shorten for %s!\n", name); | 2973 | "Starting shorten for %s!\n", name); |
2720 | 2974 | ||
2721 | if (is_canonical((char*)name)) | 2975 | if (is_canonical ((char*)name)) |
2722 | { | 2976 | { |
2723 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2977 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2724 | "%s is canonical. Returning verbatim\n", name); | 2978 | "%s is canonical. Returning verbatim\n", name); |
2725 | proc(proc_cls, name); | 2979 | proc (proc_cls, name); |
2726 | return; | 2980 | return; |
2727 | } | 2981 | } |
2728 | 2982 | ||
2729 | nsh = GNUNET_malloc(sizeof (struct NameShortenHandle)); | 2983 | nsh = GNUNET_malloc (sizeof (struct NameShortenHandle)); |
2730 | 2984 | ||
2731 | nsh->proc = proc; | 2985 | nsh->proc = proc; |
2732 | nsh->proc_cls = proc_cls; | 2986 | nsh->proc_cls = proc_cls; |
2733 | 2987 | nsh->root_zone = zone; | |
2734 | rh = GNUNET_malloc(sizeof (struct ResolverHandle)); | 2988 | nsh->private_zone = pzone; |
2735 | rh->authority = zone; | 2989 | nsh->shorten_zone = szone; |
2990 | strcpy (nsh->private_zone_name, private_zone_name); | ||
2991 | strcpy (nsh->shorten_zone_name, shorten_zone_name); | ||
2992 | strcpy (nsh->result, name); | ||
2993 | |||
2994 | rh = GNUNET_malloc (sizeof (struct ResolverHandle)); | ||
2995 | rh->authority = *zone; | ||
2736 | rh->id = rid++; | 2996 | rh->id = rid++; |
2737 | rh->priv_key = key; | 2997 | rh->priv_key = NULL; |
2738 | rh->proc = &handle_delegation_ns_shorten; | 2998 | rh->proc = &handle_delegation_ns_shorten; |
2739 | rh->proc_cls = nsh; | 2999 | rh->proc_cls = nsh; |
2740 | rh->id = rid++; | 3000 | rh->id = rid++; |
2741 | rh->private_local_zone = pzone; | 3001 | rh->private_local_zone = *zone; |
2742 | 3002 | ||
2743 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3003 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2744 | "Checking for TLD...\n"); | 3004 | "Checking for TLD...\n"); |
2745 | if (is_zkey_tld(name) == GNUNET_YES) | 3005 | if (is_zkey_tld (name) == GNUNET_YES) |
2746 | { | 3006 | { |
2747 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3007 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2748 | "TLD is zkey\n"); | 3008 | "TLD is zkey\n"); |
@@ -2751,30 +3011,30 @@ gns_resolver_shorten_name(struct GNUNET_CRYPTO_ShortHashCode zone, | |||
2751 | * build hash and use as initial authority | 3011 | * build hash and use as initial authority |
2752 | * FIXME sscanf | 3012 | * FIXME sscanf |
2753 | */ | 3013 | */ |
2754 | memset(rh->name, 0, | 3014 | memset (rh->name, 0, |
2755 | strlen(name)-strlen(GNUNET_GNS_TLD_ZKEY)); | 3015 | strlen (name)-strlen (GNUNET_GNS_TLD_ZKEY)); |
2756 | memcpy(rh->name, name, | 3016 | memcpy (rh->name, name, |
2757 | strlen(name)-strlen(GNUNET_GNS_TLD_ZKEY) - 1); | 3017 | strlen(name)-strlen (GNUNET_GNS_TLD_ZKEY) - 1); |
2758 | pop_tld(rh->name, string_hash); | 3018 | pop_tld (rh->name, string_hash); |
2759 | 3019 | ||
2760 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3020 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2761 | "ZKEY is %s!\n", string_hash); | 3021 | "ZKEY is %s!\n", string_hash); |
2762 | 3022 | ||
2763 | GNUNET_STRINGS_utf8_toupper(string_hash, &nzkey_ptr); | 3023 | GNUNET_STRINGS_utf8_toupper (string_hash, &nzkey_ptr); |
2764 | 3024 | ||
2765 | if (GNUNET_OK != GNUNET_CRYPTO_short_hash_from_string(nzkey, | 3025 | if (GNUNET_OK != GNUNET_CRYPTO_short_hash_from_string (nzkey, |
2766 | &zkey)) | 3026 | &zkey)) |
2767 | { | 3027 | { |
2768 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 3028 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
2769 | "Cannot convert ZKEY %s to hash!\n", nzkey); | 3029 | "Cannot convert ZKEY %s to hash!\n", nzkey); |
2770 | GNUNET_free(rh); | 3030 | GNUNET_free (rh); |
2771 | GNUNET_free(nsh); | 3031 | GNUNET_free (nsh); |
2772 | proc(proc_cls, name); | 3032 | proc (proc_cls, name); |
2773 | return; | 3033 | return; |
2774 | } | 3034 | } |
2775 | 3035 | ||
2776 | GNUNET_NAMESTORE_zone_to_name (namestore_handle, | 3036 | GNUNET_NAMESTORE_zone_to_name (namestore_handle, |
2777 | &zone, //ours | 3037 | zone, //ours |
2778 | &zkey, | 3038 | &zkey, |
2779 | &process_zone_to_name_zkey, | 3039 | &process_zone_to_name_zkey, |
2780 | rh); | 3040 | rh); |
@@ -2788,19 +3048,19 @@ gns_resolver_shorten_name(struct GNUNET_CRYPTO_ShortHashCode zone, | |||
2788 | /** | 3048 | /** |
2789 | * Presumably GNUNET tld | 3049 | * Presumably GNUNET tld |
2790 | */ | 3050 | */ |
2791 | memset(rh->name, 0, | 3051 | memset (rh->name, 0, |
2792 | strlen(name)-strlen(GNUNET_GNS_TLD)); | 3052 | strlen (name)-strlen (GNUNET_GNS_TLD)); |
2793 | memcpy(rh->name, name, | 3053 | memcpy (rh->name, name, |
2794 | strlen(name)-strlen(GNUNET_GNS_TLD) - 1); | 3054 | strlen (name)-strlen (GNUNET_GNS_TLD) - 1); |
2795 | } | 3055 | } |
2796 | 3056 | ||
2797 | rh->authority_chain_head = GNUNET_malloc(sizeof(struct AuthorityChain)); | 3057 | rh->authority_chain_head = GNUNET_malloc (sizeof (struct AuthorityChain)); |
2798 | rh->authority_chain_tail = rh->authority_chain_head; | 3058 | rh->authority_chain_tail = rh->authority_chain_head; |
2799 | rh->authority_chain_head->zone = zone; | 3059 | rh->authority_chain_head->zone = *zone; |
2800 | 3060 | ||
2801 | 3061 | ||
2802 | /* Start delegation resolution in our namestore */ | 3062 | /* Start delegation resolution in our namestore */ |
2803 | resolve_delegation_ns(rh); | 3063 | resolve_delegation_ns (rh); |
2804 | } | 3064 | } |
2805 | 3065 | ||
2806 | /*********** END NAME SHORTEN ********************/ | 3066 | /*********** END NAME SHORTEN ********************/ |