2 This file is part of GNUnet.
3 (C) 2011-2013 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file gns/gnunet-service-gns_resolver.c
23 * @brief GNUnet GNS resolver logic
24 * @author Martin Schanzenbach
25 * @author Christian Grothoff
28 #include "gnunet_util_lib.h"
29 #include "gnunet_transport_service.h"
30 #include "gnunet_dnsstub_lib.h"
31 #include "gnunet_dht_service.h"
32 #include "gnunet_namestore_service.h"
33 #include "gnunet_dns_service.h"
34 #include "gnunet_resolver_service.h"
35 #include "gnunet_dnsparser_lib.h"
36 #include "gns_protocol.h"
37 #include "gnunet_gns_service.h"
38 #include "gns_common.h"
40 #include "gnunet-service-gns_resolver.h"
41 #include "gnunet_vpn_service.h"
45 * Default DHT timeout for lookups.
47 #define DHT_LOOKUP_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
50 * DHT replication level
52 #define DHT_GNS_REPLICATION_LEVEL 5
56 * DLL to hold the authority chain we had to pass in the resolution
64 struct AuthorityChain *prev;
69 struct AuthorityChain *next;
72 * label corresponding to the authority
74 char label[GNUNET_DNSPARSER_MAX_LABEL_LENGTH];
77 * #GNUNET_YES if the authority was a GNS authority,
78 * #GNUNET_NO if the authority was a DNS authority.
83 * Information about the resolver authority for this label.
89 * The zone of the GNS authority
91 struct GNUNET_CRYPTO_EccPublicKey gns_authority;
96 * Domain of the DNS resolver that is the authority.
97 * (appended to construct the DNS name to resolve;
98 * this is NOT the DNS name of the DNS server!).
100 char name[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
103 * IP address of the DNS resolver that is authoritative.
104 * (this implementation currently only supports one
107 struct sockaddr_storage dns_ip;
117 * Resolution status indicator
119 enum ResolutionStatus
122 * the name to lookup exists
124 RSL_RECORD_EXISTS = 1,
127 * the name in the record expired
129 RSL_RECORD_EXPIRED = 2,
132 * resolution timed out
137 * Found VPN delegation
139 RSL_DELEGATE_VPN = 8,
142 * Found NS delegation
144 RSL_DELEGATE_NS = 16,
147 * Found PKEY delegation
149 RSL_DELEGATE_PKEY = 32,
154 RSL_CNAME_FOUND = 64,
157 * Found PKEY has been revoked
159 RSL_PKEY_REVOKED = 128
164 * Handle to a currenty pending resolution. On result (positive or
165 * negative) the #GNS_ResultProcessor is called.
167 struct GNS_ResolverHandle
173 struct GNS_ResolverHandle *next;
178 struct GNS_ResolverHandle *prev;
181 * The top-level GNS authoritative zone to query
183 struct GNUNET_CRYPTO_EccPublicKey authority_zone;
186 * called when resolution phase finishes
188 GNS_ResultProcessor proc;
191 * closure passed to proc
196 * Handle for DHT lookups. should be NULL if no lookups are in progress
198 struct GNUNET_DHT_GetHandle *get_handle;
201 * Handle to a VPN request, NULL if none is active.
203 struct GNUNET_VPN_RedirectionRequest *vpn_handle;
206 * Socket for a DNS request, NULL if none is active.
208 struct GNUNET_DNSSTUB_RequestSocket *dns_request;
211 * Pending Namestore task
213 struct GNUNET_NAMESTORE_QueueEntry *namestore_task;
216 * Heap node associated with this lookup. Used to limit number of
217 * concurrent requests.
219 struct GNUNET_CONTAINER_HeapNode *dht_heap_node;
222 * DLL to store the authority chain
224 struct AuthorityChain *authority_chain_head;
227 * DLL to store the authority chain
229 struct AuthorityChain *authority_chain_tail;
232 * Private key of the shorten zone, NULL to not shorten.
234 struct GNUNET_CRYPTO_EccPrivateKey *shorten_key;
237 * The name to resolve
239 char name[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
242 * Current offset in 'name' where we are resolving.
244 size_t name_resolution_pos;
255 * Handle for a PSEU lookup used to shorten names.
257 struct GetPseuAuthorityHandle
262 struct GetPseuAuthorityHandle *next;
267 struct GetPseuAuthorityHandle *prev;
270 * Private key of the (shorten) zone to store the resulting
273 struct GNUNET_CRYPTO_EccPrivateKey shorten_zone_key;
276 * Original label (used if no PSEU record is found).
278 char label[GNUNET_DNSPARSER_MAX_LABEL_LENGTH + 1];
281 * The zone for which we are trying to find the PSEU record.
283 struct GNUNET_CRYPTO_EccPublicKey target_zone;
286 * Handle for DHT lookups. Should be NULL if no lookups are in progress
288 struct GNUNET_DHT_GetHandle *get_handle;
291 * Handle to namestore request
293 struct GNUNET_NAMESTORE_QueueEntry *namestore_task;
296 * Task to abort DHT lookup operation.
298 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
304 * Our handle to the namestore service
306 static struct GNUNET_NAMESTORE_Handle *namestore_handle;
309 * Our handle to the vpn service
311 static struct GNUNET_VPN_Handle *vpn_handle;
314 * Resolver handle to the dht
316 static struct GNUNET_DHT_Handle *dht_handle;
319 * Handle to perform DNS lookups.
321 static struct GNUNET_DNSSTUB_Context *dns_handle;
324 * Heap for limiting parallel DHT lookups
326 static struct GNUNET_CONTAINER_Heap *dht_lookup_heap;
329 * Maximum amount of parallel queries in background
331 static unsigned long long max_allowed_background_queries;
334 * Head of PSEU/shorten operations list.
336 struct GetPseuAuthorityHandle *gph_head;
339 * Tail of PSEU/shorten operations list.
341 struct GetPseuAuthorityHandle *gph_tail;
344 * Head of resolver lookup list
346 static struct GNS_ResolverHandle *rlh_head;
349 * Tail of resolver lookup list
351 static struct GNS_ResolverHandle *rlh_tail;
354 * Global configuration.
356 static const struct GNUNET_CONFIGURATION_Handle *cfg;
360 * Check if name is in srv format (_x._y.xxx)
363 * @return GNUNET_YES if true
366 is_srv (const char *name)
373 if (NULL == strstr (name, "._"))
376 ndup = GNUNET_strdup (name);
378 if (NULL == strtok (NULL, "."))
380 if (NULL == strtok (NULL, "."))
382 if (NULL != strtok (NULL, "."))
390 * Determine if this name is canonical (is a legal name in a zone, without delegation);
391 * note that we do not test that the name does not contain illegal characters, we only
392 * test for delegation. Note that service records (i.e. _foo._srv) are canonical names
393 * even though they consist of multiple labels.
396 * a.b.gads = not canonical
398 * _foo._srv = canonical
399 * _f.bar = not canonical
401 * @param name the name to test
402 * @return GNUNET_YES if canonical
405 is_canonical (const char *name)
410 if (NULL == strchr (name, '.'))
415 while (NULL != (dot = strchr (pos, '.')))
424 /* ******************** Shortening logic ************************ */
428 * Cleanup a 'struct GetPseuAuthorityHandle', terminating all
429 * pending activities.
431 * @param gph handle to terminate
434 free_get_pseu_authority_handle (struct GetPseuAuthorityHandle *gph)
436 if (NULL != gph->get_handle)
438 GNUNET_DHT_get_stop (gph->get_handle);
439 gph->get_handle = NULL;
441 if (NULL != gph->namestore_task)
443 GNUNET_NAMESTORE_cancel (gph->namestore_task);
444 gph->namestore_task = NULL;
446 if (GNUNET_SCHEDULER_NO_TASK != gph->timeout_task)
448 GNUNET_SCHEDULER_cancel (gph->timeout_task);
449 gph->timeout_task = GNUNET_SCHEDULER_NO_TASK;
451 GNUNET_CONTAINER_DLL_remove (gph_head, gph_tail, gph);
457 * Continuation for pkey record creation (shorten)
459 * @param cls a GetPseuAuthorityHandle
460 * @param success unused
464 create_pkey_cont (void* cls,
468 struct GetPseuAuthorityHandle* gph = cls;
470 gph->namestore_task = NULL;
471 free_get_pseu_authority_handle (gph);
476 * Namestore calls this function if we have record for this name.
477 * (or with rd_count=0 to indicate no matches).
479 * @param cls the pending query
480 * @param key the key of the zone we did the lookup
481 * @param name the name for which we need an authority
482 * @param rd_count the number of records with 'name'
483 * @param rd the record data
486 process_pseu_lookup_ns (void *cls,
487 const struct GNUNET_CRYPTO_EccPrivateKey *key,
489 unsigned int rd_count,
490 const struct GNUNET_NAMESTORE_RecordData *rd)
492 struct GetPseuAuthorityHandle *gph = cls;
493 struct GNUNET_NAMESTORE_RecordData new_pkey;
494 struct GNUNET_CRYPTO_EccPublicKey pub;
496 gph->namestore_task = NULL;
499 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
500 "Name `%s' already taken, cannot shorten.\n",
502 /* if this was not yet the original label, try one more
503 time, this time not using PSEU but the original label */
504 if (0 == strcmp (name,
507 free_get_pseu_authority_handle (gph);
511 GNUNET_CRYPTO_ecc_key_get_public (&gph->shorten_zone_key,
513 gph->namestore_task = GNUNET_NAMESTORE_lookup (namestore_handle,
516 &process_pseu_lookup_ns,
521 /* name is available */
522 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
523 "Shortening `%s' to `%s'\n",
524 GNUNET_NAMESTORE_z2s (&gph->target_zone),
526 new_pkey.expiration_time = UINT64_MAX;
527 new_pkey.data_size = sizeof (struct GNUNET_CRYPTO_EccPublicKey);
528 new_pkey.data = &gph->target_zone;
529 new_pkey.record_type = GNUNET_NAMESTORE_TYPE_PKEY;
530 new_pkey.flags = GNUNET_NAMESTORE_RF_AUTHORITY
531 | GNUNET_NAMESTORE_RF_PRIVATE
532 | GNUNET_NAMESTORE_RF_PENDING;
534 = GNUNET_NAMESTORE_records_store (namestore_handle,
535 &gph->shorten_zone_key,
538 &create_pkey_cont, gph);
543 * Process result of a DHT lookup for a PSEU record.
545 * @param gph the handle to our shorten operation
546 * @param pseu the pseu result or NULL
549 process_pseu_result (struct GetPseuAuthorityHandle* gph,
552 struct GNUNET_CRYPTO_EccPublicKey pub;
554 GNUNET_CRYPTO_ecc_key_get_public (&gph->shorten_zone_key,
558 /* no PSEU found, try original label */
559 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
560 "No PSEU found, trying original label `%s' instead.\n",
562 gph->namestore_task = GNUNET_NAMESTORE_lookup (namestore_handle,
565 &process_pseu_lookup_ns,
570 /* check if 'pseu' is taken */
571 gph->namestore_task = GNUNET_NAMESTORE_lookup (namestore_handle,
574 &process_pseu_lookup_ns,
580 * Handle timeout for DHT request during shortening.
582 * @param cls the request handle as closure
583 * @param tc the task context
586 handle_auth_discovery_timeout (void *cls,
587 const struct GNUNET_SCHEDULER_TaskContext *tc)
589 struct GetPseuAuthorityHandle *gph = cls;
591 gph->timeout_task = GNUNET_SCHEDULER_NO_TASK;
592 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
593 "DHT lookup for PSEU query timed out.\n");
594 GNUNET_DHT_get_stop (gph->get_handle);
595 gph->get_handle = NULL;
596 process_pseu_result (gph, NULL);
601 * Handle decrypted records from DHT result.
603 * @param cls closure with our 'struct GetPseuAuthorityHandle'
604 * @param rd_count number of entries in 'rd' array
605 * @param rd array of records with data to store
608 process_auth_records (void *cls,
609 unsigned int rd_count,
610 const struct GNUNET_NAMESTORE_RecordData *rd)
612 struct GetPseuAuthorityHandle *gph = cls;
615 for (i=0; i < rd_count; i++)
617 if (GNUNET_NAMESTORE_TYPE_PSEU == rd[i].record_type)
620 process_pseu_result (gph,
621 (const char *) rd[i].data);
625 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
626 "No PSEU record found in DHT reply.\n");
627 process_pseu_result (gph, NULL);
632 * Function called when we find a PSEU entry in the DHT
634 * @param cls the request handle
635 * @param exp lifetime
636 * @param key the key the record was stored under
637 * @param get_path get path
638 * @param get_path_length get path length
639 * @param put_path put path
640 * @param put_path_length put path length
641 * @param type the block type
642 * @param size the size of the record
643 * @param data the record data
646 process_auth_discovery_dht_result (void* cls,
647 struct GNUNET_TIME_Absolute exp,
648 const struct GNUNET_HashCode *key,
649 const struct GNUNET_PeerIdentity *get_path,
650 unsigned int get_path_length,
651 const struct GNUNET_PeerIdentity *put_path,
652 unsigned int put_path_length,
653 enum GNUNET_BLOCK_Type type,
657 struct GetPseuAuthorityHandle *gph = cls;
658 const struct GNUNET_NAMESTORE_Block *block;
660 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
661 "Got DHT result for PSEU request\n");
662 GNUNET_DHT_get_stop (gph->get_handle);
663 gph->get_handle = NULL;
664 GNUNET_SCHEDULER_cancel (gph->timeout_task);
665 gph->timeout_task = GNUNET_SCHEDULER_NO_TASK;
669 /* is this allowed!? */
671 process_pseu_result (gph, NULL);
674 if (size < sizeof (struct GNUNET_NAMESTORE_Block))
676 /* how did this pass DHT block validation!? */
678 process_pseu_result (gph, NULL);
683 ntohs (block->purpose.size) +
684 sizeof (struct GNUNET_CRYPTO_EccPublicKey) +
685 sizeof (struct GNUNET_CRYPTO_EccSignature))
687 /* how did this pass DHT block validation!? */
689 process_pseu_result (gph, NULL);
693 GNUNET_NAMESTORE_block_decrypt (block,
696 &process_auth_records,
699 /* other peer encrypted invalid block, complain */
701 process_pseu_result (gph, NULL);
708 * Callback called by namestore for a zone to name result. We're
709 * trying to see if a short name for a given zone already exists.
711 * @param cls the closure
712 * @param zone_key the zone we queried
713 * @param name the name found or NULL
714 * @param rd_len number of records for the name
715 * @param rd the record data (PKEY) for the name
718 process_zone_to_name_discover (void *cls,
719 const struct GNUNET_CRYPTO_EccPrivateKey *zone_key,
722 const struct GNUNET_NAMESTORE_RecordData *rd)
724 struct GetPseuAuthorityHandle* gph = cls;
725 struct GNUNET_HashCode lookup_key;
727 gph->namestore_task = NULL;
730 /* we found a match in our own zone */
731 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
732 "Shortening aborted, name `%s' already reserved for the zone\n",
734 free_get_pseu_authority_handle (gph);
737 /* record does not yet exist, go into DHT to find PSEU record */
738 GNUNET_NAMESTORE_query_from_public_key (&gph->target_zone,
741 gph->timeout_task = GNUNET_SCHEDULER_add_delayed (DHT_LOOKUP_TIMEOUT,
742 &handle_auth_discovery_timeout,
744 gph->get_handle = GNUNET_DHT_get_start (dht_handle,
745 GNUNET_BLOCK_TYPE_GNS_NAMERECORD,
747 DHT_GNS_REPLICATION_LEVEL,
748 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
750 &process_auth_discovery_dht_result,
756 * Start shortening algorithm, try to allocate a nice short
757 * canonical name for @a pub in @a shorten_zone, using
758 * @a original_label as one possible suggestion.
760 * @param original_label original label for the zone
761 * @param pub public key of the zone to shorten
762 * @param shorten_zone private key of the target zone for the new record
765 start_shorten (const char *original_label,
766 const struct GNUNET_CRYPTO_EccPublicKey *pub,
767 const struct GNUNET_CRYPTO_EccPrivateKey *shorten_zone)
769 struct GetPseuAuthorityHandle *gph;
771 if (strlen (original_label) > GNUNET_DNSPARSER_MAX_LABEL_LENGTH)
776 gph = GNUNET_new (struct GetPseuAuthorityHandle);
777 gph->shorten_zone_key = *shorten_zone;
778 gph->target_zone = *pub;
779 strcpy (gph->label, original_label);
780 GNUNET_CONTAINER_DLL_insert (gph_head, gph_tail, gph);
781 /* first, check if we *already* have a record for this zone */
782 gph->namestore_task = GNUNET_NAMESTORE_zone_to_name (namestore_handle,
785 &process_zone_to_name_discover,
790 /* ************************** Resolution **************************** */
794 * Helper function to free resolver handle
796 * @param rh the handle to free
799 free_resolver_handle (struct ResolverHandle* rh)
801 struct AuthorityChain *ac;
802 struct AuthorityChain *ac_next;
807 ac_next = rh->authority_chain_head;
808 while (NULL != (ac = ac_next))
814 if (NULL != rh->get_handle)
815 GNUNET_DHT_get_stop (rh->get_handle);
816 if (NULL != rh->dns_raw_packet)
817 GNUNET_free (rh->dns_raw_packet);
818 if (NULL != rh->namestore_task)
820 GNUNET_NAMESTORE_cancel (rh->namestore_task);
821 rh->namestore_task = NULL;
823 if (GNUNET_SCHEDULER_NO_TASK != rh->dns_read_task)
824 GNUNET_SCHEDULER_cancel (rh->dns_read_task);
825 if (GNUNET_SCHEDULER_NO_TASK != rh->timeout_task)
826 GNUNET_SCHEDULER_cancel (rh->timeout_task);
827 if (NULL != rh->dns_sock)
828 GNUNET_NETWORK_socket_close (rh->dns_sock);
829 if (NULL != rh->dns_resolver_handle)
830 GNUNET_RESOLVER_request_cancel (rh->dns_resolver_handle);
831 if (NULL != rh->rd.data)
832 GNUNET_free ((void*)(rh->rd.data));
833 if (NULL != rh->dht_heap_node)
834 GNUNET_CONTAINER_heap_remove_node (rh->dht_heap_node);
840 * Callback when record data is put into namestore
842 * @param cls the closure
843 * @param success GNUNET_OK on success
844 * @param emsg the error message. NULL if SUCCESS==GNUNET_OK
847 on_namestore_record_put_result (void *cls,
851 struct NamestoreBGTask *nbg = cls;
853 GNUNET_CONTAINER_heap_remove_node (nbg->node);
856 if (GNUNET_NO == success)
858 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
859 "GNS_NS: records already in namestore\n");
862 else if (GNUNET_YES == success)
864 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
865 "GNS_NS: records successfully put in namestore\n");
869 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
870 "GNS_NS: Error putting records into namestore: %s\n", emsg);
875 * Function called when we get a result from the dht
876 * for our record query
878 * @param cls the request handle
879 * @param exp lifetime
880 * @param key the key the record was stored under
881 * @param get_path get path
882 * @param get_path_length get path length
883 * @param put_path put path
884 * @param put_path_length put path length
885 * @param type the block type
886 * @param size the size of the record
887 * @param data the record data
890 process_record_result_dht (void* cls,
891 struct GNUNET_TIME_Absolute exp,
892 const struct GNUNET_HashCode * key,
893 const struct GNUNET_PeerIdentity *get_path,
894 unsigned int get_path_length,
895 const struct GNUNET_PeerIdentity *put_path,
896 unsigned int put_path_length,
897 enum GNUNET_BLOCK_Type type,
898 size_t size, const void *data)
900 struct ResolverHandle *rh = cls;
901 struct RecordLookupHandle *rlh = rh->proc_cls;
902 const struct GNSNameRecordBlock *nrb = data;
903 uint32_t num_records;
909 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
910 "GNS_PHASE_REC-%llu: got dht result (size=%d)\n", rh->id, size);
911 /* stop lookup and timeout task */
912 GNUNET_DHT_get_stop (rh->get_handle);
913 rh->get_handle = NULL;
914 if (rh->dht_heap_node != NULL)
916 GNUNET_CONTAINER_heap_remove_node (rh->dht_heap_node);
917 rh->dht_heap_node = NULL;
919 if (rh->timeout_task != GNUNET_SCHEDULER_NO_TASK)
921 GNUNET_SCHEDULER_cancel (rh->timeout_task);
922 rh->timeout_task = GNUNET_SCHEDULER_NO_TASK;
924 rh->get_handle = NULL;
925 name = (const char*) &nrb[1];
926 num_records = ntohl (nrb->rd_count);
928 struct GNUNET_NAMESTORE_RecordData rd[num_records];
929 struct NamestoreBGTask *ns_heap_root;
930 struct NamestoreBGTask *namestore_bg_task;
932 rd_data = &name[strlen (name) + 1];
933 rd_size = size - strlen (name) - 1 - sizeof (struct GNSNameRecordBlock);
935 GNUNET_NAMESTORE_records_deserialize (rd_size,
940 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
941 "GNS_PHASE_REC-%llu: Error deserializing data!\n", rh->id);
942 rh->proc (rh->proc_cls, rh, 0, NULL);
945 for (i = 0; i < num_records; i++)
947 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
948 "GNS_PHASE_REC-%llu: Got name: %s (wanted %s)\n",
949 rh->id, name, rh->name);
950 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
951 "GNS_PHASE_REC-%llu: Got type: %d (wanted %d)\n",
952 rh->id, rd[i].record_type, rlh->record_type);
953 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
954 "GNS_PHASE_REC-%llu: Got data length: %d\n",
955 rh->id, rd[i].data_size);
956 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
957 "GNS_PHASE_REC-%llu: Got flag %d\n",
958 rh->id, rd[i].flags);
960 if ((strcmp (name, rh->name) == 0) &&
961 (rd[i].record_type == rlh->record_type))
967 * FIXME check pubkey against existing key in namestore?
968 * https://gnunet.org/bugs/view.php?id=2179
970 if (max_allowed_ns_tasks <=
971 GNUNET_CONTAINER_heap_get_size (ns_task_heap))
973 ns_heap_root = GNUNET_CONTAINER_heap_remove_root (ns_task_heap);
974 GNUNET_NAMESTORE_cancel (ns_heap_root->qe);
976 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
977 "GNS_PHASE_REC-%llu: Replacing oldest background ns task\n",
981 /* Save to namestore */
982 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
983 "GNS_PHASE_REC-%llu: Caching record for %s\n",
985 namestore_bg_task = GNUNET_malloc (sizeof (struct NamestoreBGTask));
986 namestore_bg_task->qe = GNUNET_NAMESTORE_record_put (namestore_handle,
993 &on_namestore_record_put_result, //cont
996 namestore_bg_task->node = GNUNET_CONTAINER_heap_insert (ns_task_heap,
998 GNUNET_TIME_absolute_get().abs_value_us);
999 if (0 < rh->answered)
1000 rh->proc (rh->proc_cls, rh, num_records, rd);
1002 rh->proc (rh->proc_cls, rh, 0, NULL);
1008 * Start DHT lookup for a (name -> query->record_type) record in
1009 * rh->authority's zone
1011 * @param rh the pending gns query context
1014 resolve_record_dht (struct ResolverHandle *rh)
1016 struct RecordLookupHandle *rlh = rh->proc_cls;
1018 struct GNUNET_HashCode lookup_key;
1019 struct ResolverHandle *rh_heap_root;
1021 GNUNET_GNS_get_key_for_record (rh->name, &rh->authority, &lookup_key);
1022 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1023 "GNS_PHASE_REC-%llu: starting dht lookup for %s with key: %s\n",
1024 rh->id, rh->name, GNUNET_h2s (&lookup_key));
1026 rh->dht_heap_node = NULL;
1028 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != rh->timeout.rel_value_us)
1031 * Update timeout if necessary
1033 if (GNUNET_SCHEDULER_NO_TASK == rh->timeout_task)
1035 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1036 "GNS_PHASE_REC-%llu: Adjusting timeout to %s/2\n",
1038 GNUNET_STRINGS_relative_time_to_string (rh->timeout, GNUNET_YES));
1040 * Set timeout for authority lookup phase to 1/2
1042 rh->timeout_task = GNUNET_SCHEDULER_add_delayed (
1043 GNUNET_TIME_relative_divide (rh->timeout, 2),
1044 &handle_lookup_timeout,
1047 rh->timeout_cont = &dht_lookup_timeout;
1048 rh->timeout_cont_cls = rh;
1052 if (max_allowed_background_queries <=
1053 GNUNET_CONTAINER_heap_get_size (dht_lookup_heap))
1055 rh_heap_root = GNUNET_CONTAINER_heap_remove_root (dht_lookup_heap);
1056 GNUNET_DHT_get_stop (rh_heap_root->get_handle);
1057 rh_heap_root->get_handle = NULL;
1058 rh_heap_root->dht_heap_node = NULL;
1060 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1061 "GNS_PHASE_REC-%llu: Replacing oldest background query for %s\n",
1062 rh->id, rh_heap_root->name);
1063 rh_heap_root->proc (rh_heap_root->proc_cls,
1068 rh->dht_heap_node = GNUNET_CONTAINER_heap_insert (dht_lookup_heap,
1070 GNUNET_TIME_absolute_get ().abs_value_us);
1073 xquery = htonl (rlh->record_type);
1075 GNUNET_assert (rh->get_handle == NULL);
1076 rh->get_handle = GNUNET_DHT_get_start (dht_handle,
1077 GNUNET_BLOCK_TYPE_GNS_NAMERECORD,
1079 DHT_GNS_REPLICATION_LEVEL,
1080 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
1083 &process_record_result_dht,
1090 * Namestore calls this function if we have record for this name.
1091 * (or with rd_count=0 to indicate no matches)
1093 * @param cls the pending query
1094 * @param key the key of the zone we did the lookup
1095 * @param expiration expiration date of the namestore entry
1096 * @param name the name for which we need an authority
1097 * @param rd_count the number of records with 'name'
1098 * @param rd the record data
1099 * @param signature the signature of the authority for the record data
1102 process_record_result_ns (void* cls,
1103 const struct GNUNET_CRYPTO_EccPublicKey *key,
1104 struct GNUNET_TIME_Absolute expiration,
1105 const char *name, unsigned int rd_count,
1106 const struct GNUNET_NAMESTORE_RecordData *rd,
1107 const struct GNUNET_CRYPTO_EccSignature *signature)
1109 struct ResolverHandle *rh = cls;
1110 struct RecordLookupHandle *rlh = rh->proc_cls;
1111 struct GNUNET_TIME_Relative remaining_time;
1112 struct GNUNET_CRYPTO_ShortHashCode zone;
1113 struct GNUNET_TIME_Absolute et;
1116 rh->namestore_task = NULL;
1117 GNUNET_CRYPTO_short_hash (key,
1118 sizeof (struct GNUNET_CRYPTO_EccPublicKey),
1120 remaining_time = GNUNET_TIME_absolute_get_remaining (expiration);
1124 rh->status |= RSL_RECORD_EXISTS;
1125 if (remaining_time.rel_value_us == 0)
1126 rh->status |= RSL_RECORD_EXPIRED;
1131 * Lookup terminated and no results
1133 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1134 "GNS_PHASE_REC-%llu: Namestore lookup for %s terminated without results\n",
1137 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1138 "GNS_PHASE_REC-%llu: Record %s unknown in namestore\n",
1141 * Our zone and no result? Cannot resolve TT
1143 rh->proc(rh->proc_cls, rh, 0, NULL);
1147 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1148 "GNS_PHASE_REC-%llu: Processing additional result %s from namestore\n",
1150 for (i = 0; i < rd_count;i++)
1152 if (rd[i].record_type != rlh->record_type)
1155 if (ignore_pending_records &&
1156 (rd[i].flags & GNUNET_NAMESTORE_RF_PENDING))
1158 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1159 "GNS_PHASE_REC-%llu: Record %s is awaiting user confirmation. Skipping\n",
1164 //FIXME: eh? do I have to handle this here?
1165 GNUNET_break (0 == (rd[i].flags & GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION));
1166 et.abs_value_us = rd[i].expiration_time;
1167 if (0 == (GNUNET_TIME_absolute_get_remaining (et)).rel_value_us)
1169 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1170 "GNS_PHASE_REC-%llu: This record is expired. Skipping\n",
1180 if (0 == rh->answered)
1182 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1183 "GNS_PHASE_REC-%llu: No answers found. This is odd!\n", rh->id);
1184 rh->proc(rh->proc_cls, rh, 0, NULL);
1188 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1189 "GNS_PHASE_REC-%llu: Found %d answer(s) to query in %d records!\n",
1190 rh->id, rh->answered, rd_count);
1191 rh->proc(rh->proc_cls, rh, rd_count, rd);
1197 * VPN redirect result callback
1199 * @param cls the resolver handle
1200 * @param af the requested address family
1201 * @param address in_addr(6) respectively
1204 process_record_result_vpn (void* cls, int af, const void *address)
1206 struct ResolverHandle *rh = cls;
1207 struct RecordLookupHandle *rlh = rh->proc_cls;
1208 struct GNUNET_NAMESTORE_RecordData rd;
1210 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1211 "GNS_PHASE_REC_VPN-%llu: Got answer from VPN to query!\n",
1215 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1216 "GNS_PHASE_REC-%llu: Answer is IPv4!\n",
1218 if (GNUNET_DNSPARSER_TYPE_A != rlh->record_type)
1220 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1221 "GNS_PHASE_REC-%llu: Requested record is not IPv4!\n",
1223 rh->proc (rh->proc_cls, rh, 0, NULL);
1226 rd.record_type = GNUNET_DNSPARSER_TYPE_A;
1227 rd.expiration_time = UINT64_MAX; /* FIXME: should probably pick something shorter... */
1229 rd.data_size = sizeof (struct in_addr);
1231 rh->proc (rh->proc_cls, rh, 1, &rd);
1234 else if (AF_INET6 == af)
1236 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1237 "GNS_PHASE_REC-%llu: Answer is IPv6!\n",
1239 if (GNUNET_DNSPARSER_TYPE_AAAA != rlh->record_type)
1241 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1242 "GNS_PHASE_REC-%llu: Requested record is not IPv6!\n",
1244 rh->proc (rh->proc_cls, rh, 0, NULL);
1247 rd.record_type = GNUNET_DNSPARSER_TYPE_AAAA;
1248 rd.expiration_time = UINT64_MAX; /* FIXME: should probably pick something shorter... */
1250 rd.data_size = sizeof (struct in6_addr);
1252 rh->proc (rh->proc_cls, rh, 1, &rd);
1256 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1257 "GNS_PHASE_REC-%llu: Got garbage from VPN!\n",
1259 rh->proc (rh->proc_cls, rh, 0, NULL);
1265 * Process VPN lookup result for record
1267 * @param cls the record lookup handle
1268 * @param rh resolver handle
1269 * @param rd_count number of results (1)
1270 * @param rd record data containing the result
1273 handle_record_vpn (void* cls, struct ResolverHandle *rh,
1274 unsigned int rd_count,
1275 const struct GNUNET_NAMESTORE_RecordData *rd)
1277 struct RecordLookupHandle* rlh = cls;
1281 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1282 "GNS_PHASE_REC_VPN-%llu: VPN returned no records. (status: %d)!\n",
1285 /* give up, cannot resolve */
1286 finish_lookup(rh, rlh, 0, NULL);
1290 /* results found yay */
1291 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1292 "GNS_PHASE_REC_VPN-%llu: Record resolved from VPN!\n",
1295 finish_lookup(rh, rlh, rd_count, rd);
1300 * The final phase of resoution.
1301 * We found a NS RR and want to resolve via DNS
1303 * @param rh the pending lookup handle
1304 * @param rd_count length of record data
1305 * @param rd record data containing VPN RR
1308 resolve_record_dns (struct ResolverHandle *rh,
1309 unsigned int rd_count,
1310 const struct GNUNET_NAMESTORE_RecordData *rd)
1312 struct RecordLookupHandle *rlh = rh->proc_cls;
1313 struct GNUNET_DNSPARSER_Query query;
1314 struct GNUNET_DNSPARSER_Packet packet;
1315 struct GNUNET_DNSPARSER_Flags flags;
1316 struct in_addr dnsip;
1317 struct sockaddr_in addr;
1318 struct sockaddr *sa;
1321 memset (&packet, 0, sizeof (struct GNUNET_DNSPARSER_Packet));
1322 memset (rh->dns_name, 0, sizeof (rh->dns_name));
1324 /* We cancel here as to not include the ns lookup in the timeout */
1325 if (GNUNET_SCHEDULER_NO_TASK != rh->timeout_task)
1327 GNUNET_SCHEDULER_cancel(rh->timeout_task);
1328 rh->timeout_task = GNUNET_SCHEDULER_NO_TASK;
1330 /* Start shortening */
1331 if ((NULL != rh->priv_key) &&
1332 (GNUNET_YES == is_canonical (rh->name)))
1334 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1335 "GNS_PHASE_REC_DNS-%llu: Trying to shorten authority chain\n",
1337 start_shorten (rh->authority_chain_head,
1341 for (i = 0; i < rd_count; i++)
1343 /* Synthesize dns name */
1344 if (GNUNET_DNSPARSER_TYPE_NS == rd[i].record_type)
1346 strcpy (rh->dns_zone, (char*)rd[i].data);
1347 if (0 == strcmp (rh->name, ""))
1348 strcpy (rh->dns_name, (char*)rd[i].data);
1350 sprintf (rh->dns_name, "%s.%s", rh->name, (char*)rd[i].data);
1353 if (GNUNET_DNSPARSER_TYPE_A == rd[i].record_type)
1354 /* need to use memcpy as .data may be unaligned */
1355 memcpy (&dnsip, rd[i].data, sizeof (dnsip));
1358 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1359 "GNS_PHASE_REC_DNS-%llu: Looking up `%s' from `%s'\n",
1363 rh->dns_sock = GNUNET_NETWORK_socket_create (AF_INET, SOCK_DGRAM, 0);
1364 if (NULL == rh->dns_sock)
1366 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1367 "GNS_PHASE_REC_DNS-%llu: Error creating udp socket for dns!\n",
1369 finish_lookup (rh, rlh, 0, NULL);
1373 memset (&addr, 0, sizeof (struct sockaddr_in));
1374 sa = (struct sockaddr *) &addr;
1375 sa->sa_family = AF_INET;
1376 if (GNUNET_OK != GNUNET_NETWORK_socket_bind (rh->dns_sock,
1378 sizeof (struct sockaddr_in),
1381 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1382 "GNS_PHASE_REC_DNS-%llu: Error binding UDP socket for DNS lookup!\n",
1384 finish_lookup (rh, rlh, 0, NULL);
1387 query.name = rh->dns_name;
1388 query.type = rlh->record_type;
1389 query.class = GNUNET_DNSPARSER_CLASS_INTERNET;
1390 memset (&flags, 0, sizeof (flags));
1391 flags.recursion_desired = 1;
1392 flags.checking_disabled = 1;
1393 packet.queries = &query;
1394 packet.answers = NULL;
1395 packet.authority_records = NULL;
1396 packet.num_queries = 1;
1397 packet.num_answers = 0;
1398 packet.num_authority_records = 0;
1399 packet.num_additional_records = 0;
1400 packet.flags = flags;
1402 if (GNUNET_OK != GNUNET_DNSPARSER_pack (&packet,
1404 &rh->dns_raw_packet,
1405 &rh->dns_raw_packet_size))
1407 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1408 "GNS_PHASE_REC_DNS-%llu: Creating raw dns packet!\n",
1410 GNUNET_NETWORK_socket_close (rh->dns_sock);
1411 finish_lookup (rh, rlh, 0, NULL);
1415 rh->dns_addr.sin_family = AF_INET;
1416 rh->dns_addr.sin_port = htons (53); //domain
1417 rh->dns_addr.sin_addr = dnsip;
1418 #if HAVE_SOCKADDR_IN_SIN_LEN
1419 rh->dns_addr.sin_len = (u_char) sizeof (struct sockaddr_in);
1421 send_dns_packet (rh);
1426 * The final phase of resoution.
1427 * We found a VPN RR and want to request an IPv4/6 address
1429 * @param rh the pending lookup handle
1430 * @param rd_count length of record data
1431 * @param rd record data containing VPN RR
1434 resolve_record_vpn (struct ResolverHandle *rh,
1435 unsigned int rd_count,
1436 const struct GNUNET_NAMESTORE_RecordData *rd)
1438 struct RecordLookupHandle *rlh = rh->proc_cls;
1439 struct GNUNET_HashCode serv_desc;
1440 struct vpn_data* vpn;
1443 /* We cancel here as to not include the ns lookup in the timeout */
1444 if (GNUNET_SCHEDULER_NO_TASK != rh->timeout_task)
1446 GNUNET_SCHEDULER_cancel(rh->timeout_task);
1447 rh->timeout_task = GNUNET_SCHEDULER_NO_TASK;
1449 /* Start shortening */
1450 if ((NULL != rh->priv_key) &&
1451 (GNUNET_YES == is_canonical (rh->name)))
1453 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1454 "GNS_PHASE_REC_VPN-%llu: Trying to shorten authority chain\n",
1456 start_shorten (rh->authority_chain_head,
1460 vpn = (struct vpn_data*)rd->data;
1461 GNUNET_CRYPTO_hash ((char*)&vpn[1],
1462 strlen ((char*)&vpn[1]) + 1,
1464 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1465 "GNS_PHASE_REC_VPN-%llu: proto %hu peer %s!\n",
1468 GNUNET_h2s (&vpn->peer));
1470 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1471 "GNS_PHASE_REC_VPN-%llu: service %s -> %s!\n",
1474 GNUNET_h2s (&serv_desc));
1475 rh->proc = &handle_record_vpn;
1476 if (GNUNET_DNSPARSER_TYPE_A == rlh->record_type)
1481 if (NULL == vpn_handle)
1483 vpn_handle = GNUNET_VPN_connect (cfg);
1484 if (NULL == vpn_handle)
1486 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1487 "GNS_PHASE_INIT: Error connecting to VPN!\n");
1488 finish_lookup (rh, rh->proc_cls, 0, NULL);
1493 rh->vpn_handle = GNUNET_VPN_redirect_to_peer (vpn_handle,
1494 af, ntohs (vpn->proto),
1495 (struct GNUNET_PeerIdentity *)&vpn->peer,
1498 GNUNET_TIME_UNIT_FOREVER_ABS, //FIXME
1499 &process_record_result_vpn,
1502 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1503 "Error connecting to VPN (not available on W32 yet)\n");
1504 finish_lookup (rh, rh->proc_cls, 0, NULL);
1510 * The final phase of resolution.
1511 * rh->name is a name that is canonical and we do not have a delegation.
1512 * Query namestore for this record
1514 * @param rh the pending lookup handle
1517 resolve_record_ns(struct ResolverHandle *rh)
1519 struct RecordLookupHandle *rlh = rh->proc_cls;
1521 /* We cancel here as to not include the ns lookup in the timeout */
1522 if (GNUNET_SCHEDULER_NO_TASK != rh->timeout_task)
1524 GNUNET_SCHEDULER_cancel(rh->timeout_task);
1525 rh->timeout_task = GNUNET_SCHEDULER_NO_TASK;
1527 /* Start shortening */
1528 if ((NULL != rh->priv_key) &&
1529 (GNUNET_YES == is_canonical (rh->name)))
1531 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1532 "GNS_PHASE_REC-%llu: Trying to shorten authority chain\n",
1534 start_shorten (rh->authority_chain_head,
1539 * Try to resolve this record in our namestore.
1540 * The name to resolve is now in rh->authority_name
1541 * since we tried to resolve it to an authority
1544 rh->namestore_task = GNUNET_NAMESTORE_lookup_record(namestore_handle,
1548 &process_record_result_ns,
1554 * Handle timeout for DHT requests
1556 * @param cls the request handle as closure
1557 * @param tc the task context
1560 dht_authority_lookup_timeout (void *cls,
1561 const struct GNUNET_SCHEDULER_TaskContext *tc)
1563 struct ResolverHandle *rh = cls;
1564 struct RecordLookupHandle *rlh = rh->proc_cls;
1565 char new_name[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
1567 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1568 "GNS_PHASE_DELEGATE_DHT-%llu: dht lookup for query %s (%s) timed out.\n",
1569 rh->id, rh->authority_name,
1570 GNUNET_STRINGS_relative_time_to_string (rh->timeout,
1573 rh->status |= RSL_TIMED_OUT;
1574 rh->timeout_task = GNUNET_SCHEDULER_NO_TASK;
1575 if (NULL != rh->get_handle)
1577 GNUNET_DHT_get_stop (rh->get_handle);
1578 rh->get_handle = NULL;
1580 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
1582 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1583 "GNS_PHASE_DELEGATE_DHT-%llu: Got shutdown\n",
1585 rh->proc (rh->proc_cls, rh, 0, NULL);
1588 if (0 == strcmp (rh->name, ""))
1591 * promote authority back to name and try to resolve record
1593 strcpy (rh->name, rh->authority_name);
1594 rh->proc (rh->proc_cls, rh, 0, NULL);
1599 * Start resolution in bg
1601 GNUNET_snprintf (new_name, GNUNET_DNSPARSER_MAX_NAME_LENGTH,
1603 rh->name, rh->authority_name, GNUNET_GNS_TLD);
1604 strcpy (rh->name, new_name);
1605 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1606 "GNS_PHASE_DELEGATE_DHT-%llu: Starting background query for %s type %d\n",
1609 gns_resolver_lookup_record (rh->authority,
1610 rh->private_local_zone,
1614 GNUNET_TIME_UNIT_FOREVER_REL,
1616 &background_lookup_result_processor,
1618 rh->proc (rh->proc_cls, rh, 0, NULL);
1623 * This is a callback function that checks for key revocation
1625 * @param cls the pending query
1626 * @param key the key of the zone we did the lookup
1627 * @param expiration expiration date of the record data set in the namestore
1628 * @param name the name for which we need an authority
1629 * @param rd_count the number of records with 'name'
1630 * @param rd the record data
1631 * @param signature the signature of the authority for the record data
1634 process_pkey_revocation_result_ns (void *cls,
1635 const struct GNUNET_CRYPTO_EccPublicKey *key,
1636 struct GNUNET_TIME_Absolute expiration,
1638 unsigned int rd_count,
1639 const struct GNUNET_NAMESTORE_RecordData *rd,
1640 const struct GNUNET_CRYPTO_EccSignature *signature)
1642 struct ResolverHandle *rh = cls;
1643 struct GNUNET_TIME_Relative remaining_time;
1646 rh->namestore_task = NULL;
1647 remaining_time = GNUNET_TIME_absolute_get_remaining (expiration);
1649 for (i = 0; i < rd_count; i++)
1651 if (GNUNET_NAMESTORE_TYPE_REV == rd[i].record_type)
1653 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1654 "GNS_PHASE_DELEGATE_REV-%llu: Zone has been revoked.\n",
1656 rh->status |= RSL_PKEY_REVOKED;
1657 rh->proc (rh->proc_cls, rh, 0, NULL);
1662 if ((NULL == name) ||
1663 (0 == remaining_time.rel_value_us))
1665 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1666 "GNS_PHASE_DELEGATE_REV-%llu: + Records don't exist or are expired.\n",
1669 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != rh->timeout.rel_value_us)
1671 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1672 "GNS_PHASE_DELEGATE_REV-%llu: Starting background lookup for %s type %d\n",
1673 rh->id, "+.gads", GNUNET_NAMESTORE_TYPE_REV);
1675 gns_resolver_lookup_record(rh->authority,
1676 rh->private_local_zone,
1677 GNUNET_NAMESTORE_TYPE_REV,
1680 GNUNET_TIME_UNIT_FOREVER_REL,
1682 &background_lookup_result_processor,
1686 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1687 "GNS_PHASE_DELEGATE_REV-%llu: Revocation check passed\n",
1690 * We are done with PKEY resolution if name is empty
1691 * else resolve again with new authority
1693 if (strcmp (rh->name, "") == 0)
1694 rh->proc (rh->proc_cls, rh, rh->rd_count, &rh->rd);
1696 resolve_delegation_ns (rh);
1701 * Callback when record data is put into namestore
1703 * @param cls the closure
1704 * @param success GNUNET_OK on success
1705 * @param emsg the error message. NULL if SUCCESS==GNUNET_OK
1708 on_namestore_delegation_put_result(void *cls,
1712 struct NamestoreBGTask *nbg = cls;
1714 GNUNET_CONTAINER_heap_remove_node (nbg->node);
1717 if (GNUNET_NO == success)
1719 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1720 "GNS_NS: records already in namestore\n");
1723 else if (GNUNET_YES == success)
1725 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1726 "GNS_NS: records successfully put in namestore\n");
1730 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1731 "GNS_NS: Error putting records into namestore: %s\n", emsg);
1736 * Function called when we get a result from the dht
1737 * for our query. Recursively tries to resolve authorities
1740 * @param cls the request handle
1741 * @param exp lifetime
1742 * @param key the key the record was stored under
1743 * @param get_path get path
1744 * @param get_path_length get path length
1745 * @param put_path put path
1746 * @param put_path_length put path length
1747 * @param type the block type
1748 * @param size the size of the record
1749 * @param data the record data
1752 process_delegation_result_dht (void* cls,
1753 struct GNUNET_TIME_Absolute exp,
1754 const struct GNUNET_HashCode * key,
1755 const struct GNUNET_PeerIdentity *get_path,
1756 unsigned int get_path_length,
1757 const struct GNUNET_PeerIdentity *put_path,
1758 unsigned int put_path_length,
1759 enum GNUNET_BLOCK_Type type,
1760 size_t size, const void *data)
1762 struct ResolverHandle *rh = cls;
1763 const struct GNSNameRecordBlock *nrb = data;
1764 const char* rd_data;
1765 uint32_t num_records;
1769 struct GNUNET_CRYPTO_ShortHashCode zone;
1771 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1772 "GNS_PHASE_DELEGATE_DHT-%llu: Got DHT result\n",
1776 /* stop dht lookup and timeout task */
1777 GNUNET_DHT_get_stop (rh->get_handle);
1778 rh->get_handle = NULL;
1779 if (rh->dht_heap_node != NULL)
1781 GNUNET_CONTAINER_heap_remove_node(rh->dht_heap_node);
1782 rh->dht_heap_node = NULL;
1785 num_records = ntohl(nrb->rd_count);
1786 name = (const char*) &nrb[1];
1788 struct GNUNET_NAMESTORE_RecordData rd[num_records];
1789 struct NamestoreBGTask *ns_heap_root;
1790 struct NamestoreBGTask *namestore_bg_task;
1792 rd_data = name + strlen(name) + 1;
1793 rd_size = size - strlen(name) - 1 - sizeof (struct GNSNameRecordBlock);
1794 if (GNUNET_SYSERR == GNUNET_NAMESTORE_records_deserialize (rd_size,
1799 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1800 "GNS_PHASE_DELEGATE_DHT-%llu: Error deserializing data!\n",
1805 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1806 "GNS_PHASE_DELEGATE_DHT-%llu: Got name: %s (wanted %s)\n",
1807 rh->id, name, rh->authority_name);
1808 for (i=0; i<num_records; i++)
1810 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1811 "GNS_PHASE_DELEGATE_DHT-%llu: Got name: %s (wanted %s)\n",
1812 rh->id, name, rh->authority_name);
1813 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1814 "GNS_PHASE_DELEGATE_DHT-%llu: Got type: %d (wanted %d)\n",
1815 rh->id, rd[i].record_type, GNUNET_NAMESTORE_TYPE_PKEY);
1816 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1817 "GNS_PHASE_DELEGATE_DHT-%llu: Got data length: %d\n",
1818 rh->id, rd[i].data_size);
1819 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1820 "GNS_PHASE_DELEGATE_DHT-%llu: Got flag %d\n",
1821 rh->id, rd[i].flags);
1823 if ((GNUNET_NAMESTORE_TYPE_VPN == rd[i].record_type) ||
1824 (GNUNET_DNSPARSER_TYPE_NS == rd[i].record_type) ||
1825 (GNUNET_DNSPARSER_TYPE_CNAME == rd[i].record_type))
1828 * This is a VPN,NS,CNAME entry. Let namestore handle this after caching
1830 if (0 == strcmp(rh->name, ""))
1831 strcpy(rh->name, rh->authority_name);
1833 GNUNET_snprintf(rh->name, GNUNET_DNSPARSER_MAX_NAME_LENGTH, "%s.%s",
1834 rh->name, rh->authority_name); //FIXME ret
1839 if ((0 == strcmp(name, rh->authority_name)) &&
1840 (GNUNET_NAMESTORE_TYPE_PKEY == rd[i].record_type))
1842 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1843 "GNS_PHASE_DELEGATE_DHT-%llu: Authority found in DHT\n",
1846 memcpy(&rh->authority, rd[i].data, sizeof(struct GNUNET_CRYPTO_ShortHashCode));
1847 struct AuthorityChain *auth =
1848 GNUNET_malloc(sizeof(struct AuthorityChain));
1849 auth->zone = rh->authority;
1850 memset(auth->name, 0, strlen(rh->authority_name)+1);
1851 strcpy(auth->name, rh->authority_name);
1852 GNUNET_CONTAINER_DLL_insert (rh->authority_chain_head,
1853 rh->authority_chain_tail,
1856 if (NULL != rh->rd.data)
1857 GNUNET_free ((void*)rh->rd.data);
1859 memcpy (&rh->rd, &rd[i], sizeof (struct GNUNET_NAMESTORE_RecordData));
1860 rh->rd.data = GNUNET_malloc (rd[i].data_size);
1861 memcpy ((void*)(rh->rd.data), rd[i].data, rd[i].data_size);
1864 /** try to import pkey if private key available */
1865 //if (rh->priv_key && is_canonical (rh->name))
1866 // process_discovered_authority(name, auth->zone,
1867 // rh->authority_chain_tail->zone,
1872 GNUNET_GNS_get_zone_from_key (name, key, &zone);
1875 /* Save to namestore
1876 if (0 != GNUNET_CRYPTO_short_hash_cmp(&rh->authority_chain_head->zone,
1879 if (max_allowed_ns_tasks <=
1880 GNUNET_CONTAINER_heap_get_size (ns_task_heap))
1882 ns_heap_root = GNUNET_CONTAINER_heap_remove_root (ns_task_heap);
1883 GNUNET_NAMESTORE_cancel (ns_heap_root->qe);
1885 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1886 "GNS_PHASE_DELEGATE_DHT-%llu: Replacing oldest background ns task\n",
1889 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1890 "GNS_PHASE_DELEGATE_DHT-%llu: Caching record for %s\n",
1892 namestore_bg_task = GNUNET_malloc (sizeof (struct NamestoreBGTask));
1894 namestore_bg_task->node = GNUNET_CONTAINER_heap_insert (ns_task_heap,
1896 GNUNET_TIME_absolute_get().abs_value_us);
1897 namestore_bg_task->qe = GNUNET_NAMESTORE_record_put (namestore_handle,
1904 &on_namestore_delegation_put_result, //cont
1905 namestore_bg_task); //cls
1909 if (0 != rh->answered)
1914 * FIXME in this case. should we ask namestore again?
1916 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1917 "GNS_PHASE_DELEGATE_DHT-%llu: Answer from DHT for %s. Yet to resolve: %s\n",
1918 rh->id, rh->authority_name, rh->name);
1920 if (0 == strcmp(rh->name, ""))
1922 /* Start shortening */
1923 if ((NULL != rh->priv_key) &&
1924 (GNUNET_YES == is_canonical (rh->name)))
1926 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1927 "GNS_PHASE_DELEGATE_DHT-%llu: Trying to shorten authority chain\n",
1929 start_shorten (rh->authority_chain_head,
1934 rh->proc = &handle_delegation_ns;
1937 /* Check for key revocation and delegate */
1938 rh->namestore_task = GNUNET_NAMESTORE_lookup (namestore_handle,
1940 GNUNET_GNS_MASTERZONE_STR,
1941 GNUNET_NAMESTORE_TYPE_REV,
1942 &process_pkey_revocation_result_ns,
1949 * No pkey but name exists
1952 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1953 "GNS_PHASE_DELEGATE_DHT-%llu: Adding %s back to %s\n",
1954 rh->id, rh->authority_name, rh->name);
1955 if (0 == strcmp(rh->name, ""))
1956 strcpy(rh->name, rh->authority_name);
1958 GNUNET_snprintf(rh->name, GNUNET_DNSPARSER_MAX_NAME_LENGTH, "%s.%s",
1959 rh->name, rh->authority_name); //FIXME ret
1961 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1962 "GNS_PHASE_DELEGATE_DHT-%llu: %s restored\n", rh->id, rh->name);
1963 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1964 "GNS_PHASE_DELEGATE_DHT-%llu: DHT authority lookup found no match!\n",
1966 rh->proc(rh->proc_cls, rh, 0, NULL);
1969 //FIXME maybe define somewhere else?
1970 #define MAX_SOA_LENGTH sizeof(uint32_t)+sizeof(uint32_t)+sizeof(uint32_t)+sizeof(uint32_t)\
1971 +(GNUNET_DNSPARSER_MAX_NAME_LENGTH*2)
1972 #define MAX_MX_LENGTH sizeof(uint16_t)+GNUNET_DNSPARSER_MAX_NAME_LENGTH
1973 #define MAX_SRV_LENGTH (sizeof(uint16_t)*3)+GNUNET_DNSPARSER_MAX_NAME_LENGTH
1977 * Exands a name ending in .+ with the zone of origin.
1978 * FIXME: funky api: 'dest' must be large enough to hold
1979 * the result; this is a bit yucky...
1981 * @param dest destination buffer
1982 * @param src the .+ name
1983 * @param repl the string to replace the + with
1986 expand_plus (char* dest,
1991 size_t s_len = strlen (src) + 1;
1993 //Eh? I guess this is at least strlen ('x.+') == 3 FIXME
1996 /* no postprocessing */
1997 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1998 "GNS_POSTPROCESS: %s too short\n", src);
1999 memcpy (dest, src, s_len);
2002 if (0 == strcmp (src + s_len - 3, ".+"))
2004 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2005 "GNS_POSTPROCESS: Expanding .+ in %s\n",
2007 memset (dest, 0, s_len + strlen (repl) + strlen(GNUNET_GNS_TLD));
2009 pos = dest + s_len - 2;
2011 pos += strlen (repl);
2012 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2013 "GNS_POSTPROCESS: Expanded to %s\n",
2018 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2019 "GNS_POSTPROCESS: No postprocessing for %s\n", src);
2020 memcpy (dest, src, s_len);
2029 finish_lookup (struct ResolverHandle *rh,
2030 struct RecordLookupHandle* rlh,
2031 unsigned int rd_count,
2032 const struct GNUNET_NAMESTORE_RecordData *rd)
2035 char new_rr_data[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
2036 char new_mx_data[MAX_MX_LENGTH];
2037 char new_soa_data[MAX_SOA_LENGTH];
2038 char new_srv_data[MAX_SRV_LENGTH];
2039 struct srv_data *old_srv;
2040 struct srv_data *new_srv;
2041 struct soa_data *old_soa;
2042 struct soa_data *new_soa;
2043 struct GNUNET_NAMESTORE_RecordData p_rd[rd_count];
2046 unsigned int offset;
2048 if (GNUNET_SCHEDULER_NO_TASK != rh->timeout_task)
2050 GNUNET_SCHEDULER_cancel(rh->timeout_task);
2051 rh->timeout_task = GNUNET_SCHEDULER_NO_TASK;
2054 GNUNET_CONTAINER_DLL_remove (rlh_head, rlh_tail, rh);
2057 memcpy(p_rd, rd, rd_count*sizeof(struct GNUNET_NAMESTORE_RecordData));
2059 for (i = 0; i < rd_count; i++)
2062 if ((GNUNET_DNSPARSER_TYPE_NS != rd[i].record_type) &&
2063 (GNUNET_DNSPARSER_TYPE_PTR != rd[i].record_type) &&
2064 (GNUNET_DNSPARSER_TYPE_CNAME != rd[i].record_type) &&
2065 (GNUNET_DNSPARSER_TYPE_MX != rd[i].record_type) &&
2066 (GNUNET_DNSPARSER_TYPE_SOA != rd[i].record_type) &&
2067 (GNUNET_DNSPARSER_TYPE_SRV != rd[i].record_type))
2069 p_rd[i].data = rd[i].data;
2074 * for all those records we 'should'
2075 * also try to resolve the A/AAAA records (RFC1035)
2076 * This is a feature and not important
2079 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2080 "GNS_POSTPROCESS: Postprocessing\n");
2081 if (0 == strcmp(rh->name, GNUNET_GNS_MASTERZONE_STR))
2082 repl_string = rlh->name;
2084 repl_string = rlh->name+strlen(rh->name)+1;
2087 if (GNUNET_DNSPARSER_TYPE_MX == rd[i].record_type)
2089 memcpy (new_mx_data, (char*)rd[i].data, sizeof(uint16_t));
2090 offset = sizeof (uint16_t);
2091 pos = new_mx_data + offset;
2092 // FIXME: how do we know that 'pos' has enough space for the new name?
2093 expand_plus (pos, (char*)rd[i].data+sizeof(uint16_t),
2095 offset += strlen(new_mx_data+sizeof(uint16_t)) + 1;
2096 p_rd[i].data = new_mx_data;
2097 p_rd[i].data_size = offset;
2099 else if (GNUNET_DNSPARSER_TYPE_SRV == rd[i].record_type)
2102 * Prio, weight and port
2104 new_srv = (struct srv_data*)new_srv_data;
2105 old_srv = (struct srv_data*)rd[i].data;
2106 new_srv->prio = old_srv->prio;
2107 new_srv->weight = old_srv->weight;
2108 new_srv->port = old_srv->port;
2109 // FIXME: how do we know that '&new_srv[1]' has enough space for the new name?
2110 expand_plus((char*)&new_srv[1], (char*)&old_srv[1],
2112 p_rd[i].data = new_srv_data;
2113 p_rd[i].data_size = sizeof (struct srv_data) + strlen ((char*)&new_srv[1]) + 1;
2115 else if (GNUNET_DNSPARSER_TYPE_SOA == rd[i].record_type)
2117 /* expand mname and rname */
2118 old_soa = (struct soa_data*)rd[i].data;
2119 new_soa = (struct soa_data*)new_soa_data;
2120 memcpy (new_soa, old_soa, sizeof (struct soa_data));
2121 // FIXME: how do we know that 'new_soa[1]' has enough space for the new name?
2122 expand_plus((char*)&new_soa[1], (char*)&old_soa[1], repl_string);
2123 offset = strlen ((char*)&new_soa[1]) + 1;
2124 // FIXME: how do we know that 'new_soa[1]' has enough space for the new name?
2125 expand_plus((char*)&new_soa[1] + offset,
2126 (char*)&old_soa[1] + strlen ((char*)&old_soa[1]) + 1,
2128 p_rd[i].data_size = sizeof (struct soa_data)
2130 + strlen ((char*)&new_soa[1] + offset);
2131 p_rd[i].data = new_soa_data;
2136 // FIXME: how do we know that 'rd[i].data' has enough space for the new name?
2137 expand_plus(pos, (char*)rd[i].data, repl_string);
2138 p_rd[i].data_size = strlen(new_rr_data)+1;
2139 p_rd[i].data = new_rr_data;
2144 rlh->proc(rlh->proc_cls, rd_count, p_rd);
2146 free_resolver_handle (rh);
2151 * Process DHT lookup result for record.
2153 * @param cls the closure
2154 * @param rh resolver handle
2155 * @param rd_count number of results
2156 * @param rd record data
2159 handle_record_dht (void* cls, struct ResolverHandle *rh,
2160 unsigned int rd_count,
2161 const struct GNUNET_NAMESTORE_RecordData *rd)
2163 struct RecordLookupHandle* rlh = cls;
2167 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2168 "GNS_PHASE_REC-%llu: No records for %s found in DHT. Aborting\n",
2170 /* give up, cannot resolve */
2171 finish_lookup (rh, rlh, 0, NULL);
2174 /* results found yay */
2175 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2176 "GNS_PHASE_REC-%llu: Record resolved from DHT!", rh->id);
2177 finish_lookup (rh, rlh, rd_count, rd);
2182 * Process namestore lookup result for record.
2184 * @param cls the closure
2185 * @param rh resolver handle
2186 * @param rd_count number of results
2187 * @param rd record data
2190 handle_record_ns (void* cls, struct ResolverHandle *rh,
2191 unsigned int rd_count,
2192 const struct GNUNET_NAMESTORE_RecordData *rd)
2194 struct RecordLookupHandle* rlh = cls;
2195 int check_dht = GNUNET_YES;
2199 /* results found yay */
2200 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2201 "GNS_PHASE_REC-%llu: Record resolved from namestore!\n", rh->id);
2202 finish_lookup (rh, rlh, rd_count, rd);
2206 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2207 "GNS_PHASE_REC-%llu: NS returned no records. (status: %d)!\n",
2211 * There are 5 conditions that have to met for us to consult the DHT:
2212 * 1. The entry in the DHT is RSL_RECORD_EXPIRED OR
2213 * 2. No entry in the NS existed AND
2214 * 3. The zone queried is not the local resolver's zone AND
2215 * 4. The name that was looked up is '+'
2216 * because if it was any other canonical name we either already queried
2217 * the DHT for the authority in the authority lookup phase (and thus
2218 * would already have an entry in the NS for the record)
2219 * 5. We are not in cache only mode
2221 if ((0 != (rh->status & RSL_RECORD_EXPIRED)) &&
2222 (0 == (rh->status & RSL_RECORD_EXISTS)) )
2225 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2226 "GNS_PHASE_REC-%llu: Not expired and exists!\n",
2228 check_dht = GNUNET_NO;
2231 if (0 == GNUNET_CRYPTO_short_hash_cmp(&rh->authority_chain_head->zone,
2232 &rh->private_local_zone))
2235 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2236 "GNS_PHASE_REC-%llu: Our zone!\n",
2238 check_dht = GNUNET_NO;
2241 if ((0 != strcmp (rh->name, GNUNET_GNS_MASTERZONE_STR)) && (GNUNET_YES == is_srv (rh->name)))
2242 check_dht = GNUNET_NO;
2244 if (GNUNET_YES == rh->only_cached)
2245 check_dht = GNUNET_NO;
2247 if (GNUNET_YES == check_dht)
2249 rh->proc = &handle_record_dht;
2250 resolve_record_dht(rh);
2253 /* give up, cannot resolve */
2254 finish_lookup (rh, rlh, 0, NULL);
2259 * Move one level up in the domain hierarchy and return the
2260 * passed top level domain.
2262 * FIXME: funky API: not only 'dest' is updated, so is 'name'!
2264 * @param name the domain
2265 * @param dest the destination where the tld will be put
2268 pop_tld (char* name, char* dest)
2272 if (GNUNET_YES == is_canonical (name))
2274 strcpy (dest, name);
2279 for (len = strlen(name); 0 < len; len--)
2281 if (*(name+len) == '.')
2289 strcpy (dest, (name+len+1));
2294 * DHT resolution for delegation finished. Processing result.
2296 * @param cls the closure
2297 * @param rh resolver handle
2298 * @param rd_count number of results (always 0)
2299 * @param rd record data (always NULL)
2302 handle_delegation_dht(void* cls, struct ResolverHandle *rh,
2303 unsigned int rd_count,
2304 const struct GNUNET_NAMESTORE_RecordData *rd)
2306 struct RecordLookupHandle* rlh = cls;
2308 if (0 == strcmp(rh->name, ""))
2310 if (GNUNET_NAMESTORE_TYPE_PKEY == rlh->record_type)
2312 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2313 "GNS_PHASE_DELEGATE_DHT-%llu: Resolved queried PKEY via DHT.\n",
2315 finish_lookup(rh, rlh, rd_count, rd);
2318 /* We resolved full name for delegation. resolving record */
2319 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2320 "GNS_PHASE_DELEGATE_DHT-%llu: Resolved full name for delegation via DHT.\n",
2322 strcpy(rh->name, "+\0");
2323 rh->proc = &handle_record_ns;
2324 resolve_record_ns(rh);
2329 * we still have some left
2331 if (GNUNET_YES == is_canonical (rh->name))
2333 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2334 "GNS_PHASE_DELEGATE_DHT-%llu: Resolving canonical record %s in ns\n",
2337 rh->proc = &handle_record_ns;
2338 resolve_record_ns(rh);
2341 /* give up, cannot resolve */
2342 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2343 "GNS_PHASE_DELEGATE_DHT-%llu: Cannot fully resolve delegation for %s via DHT!\n",
2345 finish_lookup(rh, rlh, 0, NULL);
2350 * Start DHT lookup for a name -> PKEY (compare NS) record in
2351 * rh->authority's zone
2353 * @param rh the pending gns query
2356 resolve_delegation_dht (struct ResolverHandle *rh)
2359 struct GNUNET_HashCode lookup_key;
2360 struct ResolverHandle *rh_heap_root;
2362 pop_tld (rh->name, rh->authority_name);
2363 GNUNET_GNS_get_key_for_record (rh->authority_name,
2366 rh->dht_heap_node = NULL;
2367 if (rh->timeout.rel_value_us != GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us)
2369 rh->timeout_cont = &dht_authority_lookup_timeout;
2370 rh->timeout_cont_cls = rh;
2374 if (max_allowed_background_queries <=
2375 GNUNET_CONTAINER_heap_get_size (dht_lookup_heap))
2377 /* terminate oldest lookup */
2378 rh_heap_root = GNUNET_CONTAINER_heap_remove_root (dht_lookup_heap);
2379 GNUNET_DHT_get_stop (rh_heap_root->get_handle);
2380 rh_heap_root->get_handle = NULL;
2381 rh_heap_root->dht_heap_node = NULL;
2382 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2383 "GNS_PHASE_DELEGATE_DHT-%llu: Replacing oldest background query for %s\n",
2385 rh_heap_root->authority_name);
2386 rh_heap_root->proc (rh_heap_root->proc_cls,
2391 rh->dht_heap_node = GNUNET_CONTAINER_heap_insert (dht_lookup_heap,
2393 GNUNET_TIME_absolute_get().abs_value_us);
2395 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2396 "Beginning DHT lookup for %s in zone %s for request %llu\n",
2398 GNUNET_short_h2s (&rh->authority),
2400 xquery = htonl (GNUNET_NAMESTORE_TYPE_PKEY);
2401 GNUNET_assert (rh->get_handle == NULL);
2402 rh->get_handle = GNUNET_DHT_get_start (dht_handle,
2403 GNUNET_BLOCK_TYPE_GNS_NAMERECORD,
2405 DHT_GNS_REPLICATION_LEVEL,
2406 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
2409 &process_delegation_result_dht,
2415 * Namestore resolution for delegation finished. Processing result.
2417 * @param cls the closure
2418 * @param rh resolver handle
2419 * @param rd_count number of results (always 0)
2420 * @param rd record data (always NULL)
2423 handle_delegation_ns (void* cls, struct ResolverHandle *rh,
2424 unsigned int rd_count,
2425 const struct GNUNET_NAMESTORE_RecordData *rd)
2427 struct RecordLookupHandle* rlh = cls;
2431 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2432 "GNS_PHASE_DELEGATE_NS-%llu: Resolution status: %d.\n",
2433 rh->id, rh->status);
2435 if (rh->status & RSL_PKEY_REVOKED)
2437 finish_lookup (rh, rlh, 0, NULL);
2441 if (0 == strcmp(rh->name, ""))
2444 /* We resolved full name for delegation. resolving record */
2445 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2446 "GNS_PHASE_DELEGATE_NS-%llu: Resolved full name for delegation.\n",
2448 if (rh->status & RSL_CNAME_FOUND)
2450 if (GNUNET_DNSPARSER_TYPE_CNAME == rlh->record_type)
2452 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2453 "GNS_PHASE_DELEGATE_NS-%llu: Resolved queried CNAME in NS.\n",
2455 strcpy (rh->name, rh->authority_name);
2456 finish_lookup (rh, rlh, rd_count, rd);
2461 if (GNUNET_YES == is_tld ((char*)rd->data, GNUNET_GNS_TLD_PLUS))
2463 s_len = strlen (rd->data) - 2;
2464 memcpy (rh->name, rd->data, s_len);
2465 rh->name[s_len] = '\0';
2466 resolve_delegation_ns (rh);
2469 else if (GNUNET_YES == is_tld ((char*)rd->data, GNUNET_GNS_TLD_ZKEY))
2471 gns_resolver_lookup_record (rh->authority,
2472 rh->private_local_zone,
2481 GNUNET_CONTAINER_DLL_remove (rlh_head, rlh_tail, rh);
2482 free_resolver_handle (rh);
2488 strcpy (rh->dns_name, (char*)rd->data);
2489 resolve_dns_name (rh);
2494 else if (rh->status & RSL_DELEGATE_VPN)
2496 if (GNUNET_NAMESTORE_TYPE_VPN == rlh->record_type)
2498 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2499 "GNS_PHASE_DELEGATE_NS-%llu: Resolved queried VPNRR in NS.\n",
2501 finish_lookup(rh, rlh, rd_count, rd);
2504 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2505 "GNS_PHASE_DELEGATE_NS-%llu: VPN delegation starting.\n",
2507 GNUNET_assert (NULL != rd);
2508 rh->proc = &handle_record_vpn;
2509 resolve_record_vpn (rh, rd_count, rd);
2512 else if (rh->status & RSL_DELEGATE_NS)
2514 if (GNUNET_DNSPARSER_TYPE_NS == rlh->record_type)
2516 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2517 "GNS_PHASE_DELEGATE_NS-%llu: Resolved queried NSRR in NS.\n",
2519 finish_lookup (rh, rlh, rd_count, rd);
2522 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2523 "GNS_PHASE_DELEGATE_NS-%llu: NS delegation starting.\n",
2525 GNUNET_assert (NULL != rd);
2526 rh->proc = &handle_record_ns;
2527 resolve_record_dns (rh, rd_count, rd);
2530 else if (rh->status & RSL_DELEGATE_PKEY)
2532 if (rh->status & RSL_PKEY_REVOKED)
2534 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2535 "GNS_PHASE_DELEGATE_NS-%llu: Resolved PKEY is revoked.\n",
2537 finish_lookup (rh, rlh, 0, NULL);
2540 else if (GNUNET_NAMESTORE_TYPE_PKEY == rlh->record_type)
2542 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2543 "GNS_PHASE_DELEGATE_NS-%llu: Resolved queried PKEY in NS.\n",
2545 finish_lookup(rh, rlh, rd_count, rd);
2549 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2550 "GNS_PHASE_DELEGATE_NS-%llu: Resolving record +\n",
2552 strcpy(rh->name, "+\0");
2553 rh->proc = &handle_record_ns;
2554 resolve_record_ns(rh);
2558 if (rh->status & RSL_DELEGATE_NS)
2560 if (GNUNET_DNSPARSER_TYPE_NS == rlh->record_type)
2562 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2563 "GNS_PHASE_DELEGATE_NS-%llu: Resolved queried NSRR in NS.\n",
2565 finish_lookup(rh, rlh, rd_count, rd);
2569 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2570 "GNS_PHASE_DELEGATE_NS-%llu: NS delegation starting.\n",
2572 GNUNET_assert (NULL != rd);
2573 rh->proc = &handle_record_ns;
2574 resolve_record_dns (rh, rd_count, rd);
2579 * we still have some left
2580 * check if authority in ns is fresh
2582 * or we are authority
2585 check_dht = GNUNET_YES;
2586 if ((rh->status & RSL_RECORD_EXISTS) &&
2587 !(rh->status & RSL_RECORD_EXPIRED))
2588 check_dht = GNUNET_NO;
2590 if (0 == GNUNET_CRYPTO_short_hash_cmp(&rh->authority_chain_head->zone,
2591 &rh->private_local_zone))
2592 check_dht = GNUNET_NO;
2594 if (GNUNET_YES == rh->only_cached)
2595 check_dht = GNUNET_NO;
2597 if (GNUNET_YES == check_dht)
2600 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2601 "GNS_PHASE_DELEGATE_NS-%llu: Trying to resolve delegation for %s via DHT\n",
2603 rh->proc = &handle_delegation_dht;
2604 resolve_delegation_dht(rh);
2608 if (GNUNET_NO == is_canonical (rh->name))
2610 /* give up, cannot resolve */
2611 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2612 "GNS_PHASE_DELEGATE_NS-%llu: Cannot fully resolve delegation for %s!\n",
2615 finish_lookup(rh, rlh, rd_count, rd);
2618 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2619 "GNS_PHASE_DELEGATE_NS-%llu: Resolving canonical record %s\n",
2622 rh->proc = &handle_record_ns;
2623 resolve_record_ns(rh);
2628 * This is a callback function that should give us only PKEY
2629 * records. Used to query the namestore for the authority (PKEY)
2630 * for 'name'. It will recursively try to resolve the
2631 * authority for a given name from the namestore.
2633 * @param cls the pending query
2634 * @param key the key of the zone we did the lookup
2635 * @param expiration expiration date of the record data set in the namestore
2636 * @param name the name for which we need an authority
2637 * @param rd_count the number of records with 'name'
2638 * @param rd the record data
2639 * @param signature the signature of the authority for the record data
2642 process_delegation_result_ns (void* cls,
2643 const struct GNUNET_CRYPTO_EccPublicKey *key,
2644 struct GNUNET_TIME_Absolute expiration,
2646 unsigned int rd_count,
2647 const struct GNUNET_NAMESTORE_RecordData *rd,
2648 const struct GNUNET_CRYPTO_EccSignature *signature)
2650 struct ResolverHandle *rh = cls;
2651 struct GNUNET_TIME_Relative remaining_time;
2652 struct GNUNET_CRYPTO_ShortHashCode zone;
2653 char new_name[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
2655 struct GNUNET_TIME_Absolute et;
2656 struct AuthorityChain *auth;
2658 rh->namestore_task = NULL;
2659 GNUNET_CRYPTO_short_hash (key,
2660 sizeof (struct GNUNET_CRYPTO_EccPublicKey),
2662 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2663 "GNS_PHASE_DELEGATE_NS-%llu: Got %d records from authority lookup for `%s' in zone %s\n",
2666 GNUNET_short_h2s (&zone));
2668 remaining_time = GNUNET_TIME_absolute_get_remaining (expiration);
2674 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2675 "GNS_PHASE_DELEGATE_NS-%llu: Records with name `%s' exist in zone %s.\n",
2677 GNUNET_short_h2s (&zone));
2678 rh->status |= RSL_RECORD_EXISTS;
2680 if (0 == remaining_time.rel_value_us)
2682 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2683 "GNS_PHASE_DELEGATE_NS-%llu: Record set %s expired.\n",
2685 rh->status |= RSL_RECORD_EXPIRED;
2690 * No authority found in namestore.
2695 * We did not find an authority in the namestore
2700 * Promote this authority back to a name maybe it is
2703 if (strcmp (rh->name, "") == 0)
2705 /* simply promote back */
2706 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2707 "GNS_PHASE_DELEGATE_NS-%llu: Promoting %s back to name\n",
2708 rh->id, rh->authority_name);
2709 strcpy (rh->name, rh->authority_name);
2713 /* add back to existing name */
2714 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2715 "GNS_PHASE_DELEGATE_NS-%llu: Adding %s back to %s\n",
2716 rh->id, rh->authority_name, rh->name);
2717 GNUNET_snprintf (new_name, GNUNET_DNSPARSER_MAX_NAME_LENGTH, "%s.%s",
2718 rh->name, rh->authority_name);
2719 strcpy (rh->name, new_name);
2720 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2721 "GNS_PHASE_DELEGATE_NS-%llu: %s restored\n",
2725 rh->proc (rh->proc_cls, rh, 0, NULL);
2730 * We found an authority that may be able to help us
2731 * move on with query
2732 * Note only 1 pkey should have been returned.. anything else would be strange
2734 for (i=0; i < rd_count;i++)
2736 switch (rd[i].record_type)
2738 case GNUNET_DNSPARSER_TYPE_CNAME:
2739 /* Like in regular DNS this should mean that there is no other
2740 * record for this name. */
2742 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2743 "GNS_PHASE_DELEGATE_NS-%llu: CNAME `%.*s' found.\n",
2745 (int) rd[i].data_size,
2747 rh->status |= RSL_CNAME_FOUND;
2748 rh->proc (rh->proc_cls, rh, rd_count, rd);
2750 case GNUNET_NAMESTORE_TYPE_VPN:
2751 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2752 "GNS_PHASE_DELEGATE_NS-%llu: VPN found.\n",
2754 rh->status |= RSL_DELEGATE_VPN;
2755 rh->proc (rh->proc_cls, rh, rd_count, rd);
2757 case GNUNET_DNSPARSER_TYPE_NS:
2758 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2759 "GNS_PHASE_DELEGATE_NS-%llu: NS `%.*s' found.\n",
2761 (int) rd[i].data_size,
2763 rh->status |= RSL_DELEGATE_NS;
2764 rh->proc (rh->proc_cls, rh, rd_count, rd);
2766 case GNUNET_NAMESTORE_TYPE_PKEY:
2767 rh->status |= RSL_DELEGATE_PKEY;
2768 if ((ignore_pending_records != 0) &&
2769 (rd[i].flags & GNUNET_NAMESTORE_RF_PENDING))
2771 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2772 "GNS_PHASE_DELEGATE_NS-%llu: PKEY for %s is pending user confirmation.\n",
2777 GNUNET_break (0 == (rd[i].flags & GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION));
2778 et.abs_value_us = rd[i].expiration_time;
2779 if (0 == (GNUNET_TIME_absolute_get_remaining (et)).rel_value_us)
2781 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2782 "GNS_PHASE_DELEGATE_NS-%llu: This pkey is expired.\n",
2784 if (remaining_time.rel_value_us == 0)
2786 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2787 "GNS_PHASE_DELEGATE_NS-%llu: This dht entry is expired.\n",
2789 rh->authority_chain_head->fresh = 0;
2790 rh->proc (rh->proc_cls, rh, 0, NULL);
2795 /* Resolve rest of query with new authority */
2796 memcpy (&rh->authority, rd[i].data,
2797 sizeof (struct GNUNET_CRYPTO_ShortHashCode));
2798 auth = GNUNET_malloc(sizeof (struct AuthorityChain));
2799 auth->zone = rh->authority;
2800 memset (auth->name, 0, strlen (rh->authority_name)+1);
2801 strcpy (auth->name, rh->authority_name);
2802 GNUNET_CONTAINER_DLL_insert (rh->authority_chain_head,
2803 rh->authority_chain_tail,
2805 if (NULL != rh->rd.data)
2806 GNUNET_free ((void*)(rh->rd.data));
2807 memcpy (&rh->rd, &rd[i], sizeof (struct GNUNET_NAMESTORE_RecordData));
2808 rh->rd.data = GNUNET_malloc (rd[i].data_size);
2809 memcpy ((void*)rh->rd.data, rd[i].data, rd[i].data_size);
2811 /* Check for key revocation and delegate */
2812 rh->namestore_task = GNUNET_NAMESTORE_lookup (namestore_handle,
2814 GNUNET_GNS_MASTERZONE_STR,
2815 GNUNET_NAMESTORE_TYPE_REV,
2816 &process_pkey_revocation_result_ns,
2820 /* ignore, move to next result */
2825 /* no answers that would cause delegation were found */
2826 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2827 "GNS_PHASE_DELEGATE_NS-%llu: Authority lookup failed (no PKEY record)\n",
2830 * If we have found some records for the LAST label
2831 * we return the results. Else NULL.
2833 if (0 == strcmp (rh->name, ""))
2835 /* Start shortening */
2836 if ((rh->priv_key != NULL) &&
2837 (is_canonical (rh->name) == GNUNET_YES))
2839 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2840 "GNS_PHASE_DELEGATE_NS-%llu: Trying to shorten authority chain\n",
2842 start_shorten (rh->authority_chain_head,
2845 /* simply promote back */
2846 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2847 "GNS_PHASE_DELEGATE_NS-%llu: Promoting %s back to name\n",
2848 rh->id, rh->authority_name);
2849 strcpy (rh->name, rh->authority_name);
2850 rh->proc (rh->proc_cls, rh, rd_count, rd);
2854 GNUNET_snprintf (new_name, GNUNET_DNSPARSER_MAX_NAME_LENGTH,
2855 "%s.%s", rh->name, rh->authority_name);
2856 strcpy (rh->name, new_name);
2857 rh->proc (rh->proc_cls, rh, 0, NULL);
2863 * Resolve the delegation chain for the request in our namestore
2864 * (as in, find the respective authority for the leftmost label).
2866 * @param rh the resolver handle
2869 resolve_delegation_ns (struct ResolverHandle *rh)
2871 pop_tld (rh->name, rh->authority_name);
2872 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2873 "GNS_PHASE_DELEGATE_NS-%llu: Finding authority for `%s' by looking up `%s' in GADS zone `%s'\n",
2877 GNUNET_short_h2s (&rh->authority));
2878 rh->namestore_task = GNUNET_NAMESTORE_lookup (namestore_handle,
2881 &process_delegation_result_ns,
2890 * Lookup of a record in a specific zone calls lookup result processor
2893 * @param zone the zone to perform the lookup in
2894 * @param record_type the record type to look up
2895 * @param name the name to look up
2896 * @param shorten_key a private key for use with PSEU import (can be NULL)
2897 * @param only_cached GNUNET_NO to only check locally not DHT for performance
2898 * @param proc the processor to call on result
2899 * @param proc_cls the closure to pass to @a proc
2900 * @return handle to cancel operation
2902 struct GNS_ResolverHandle *
2903 GNS_resolver_lookup (const struct GNUNET_CRYPTO_EccPublicKey *zone,
2904 uint32_t record_type,
2906 const struct GNUNET_CRYPTO_EccPrivateKey *shorten_key,
2908 GNS_ResultProcessor proc, void *proc_cls)
2912 struct ResolverHandle *rh;
2913 struct RecordLookupHandle* rlh;
2914 char string_hash[GNUNET_DNSPARSER_MAX_LABEL_LENGTH];
2915 char nzkey[GNUNET_DNSPARSER_MAX_LABEL_LENGTH];
2916 char* nzkey_ptr = nzkey;
2918 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2919 "Starting resolution for `%s' (type=%d) with timeout %s!\n",
2921 GNUNET_STRINGS_relative_time_to_string (timeout, GNUNET_YES));
2923 if ((is_canonical ((char*)name) == GNUNET_YES) &&
2924 (strcmp(GNUNET_GNS_TLD, name) != 0))
2926 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2927 "%s is canonical and not gnunet -> cannot resolve!\n", name);
2932 rlh = GNUNET_malloc (sizeof(struct RecordLookupHandle));
2933 rh = GNUNET_malloc (sizeof (struct ResolverHandle));
2934 rh->authority = zone;
2938 rh->timeout = timeout;
2939 rh->private_local_zone = pzone;
2940 rh->only_cached = only_cached;
2942 GNUNET_CONTAINER_DLL_insert (rlh_head, rlh_tail, rh);
2945 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2946 "No shorten key for resolution\n");
2948 if (timeout.rel_value_us != GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us)
2951 * Set timeout for authority lookup phase to 1/2
2953 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2954 "Timeout for lookup set to %s/2\n",
2955 GNUNET_STRINGS_relative_time_to_string (rh->timeout, GNUNET_YES));
2956 rh->timeout_task = GNUNET_SCHEDULER_add_delayed (
2957 GNUNET_TIME_relative_divide(timeout, 2),
2958 &handle_lookup_timeout,
2960 rh->timeout_cont = &dht_authority_lookup_timeout;
2961 rh->timeout_cont_cls = rh;
2965 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "No timeout for query!\n");
2966 rh->timeout_task = GNUNET_SCHEDULER_NO_TASK;
2969 if (strcmp(GNUNET_GNS_TLD, name) == 0)
2972 * Only '.gads' given
2974 strcpy (rh->name, "\0");
2978 if (is_zkey_tld(name) == GNUNET_YES)
2980 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2983 * This is a zkey tld
2984 * build hash and use as initial authority
2987 strlen(name)-strlen(GNUNET_GNS_TLD_ZKEY));
2988 memcpy(rh->name, name,
2989 strlen(name)-strlen(GNUNET_GNS_TLD_ZKEY) - 1);
2990 pop_tld (rh->name, string_hash);
2992 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2993 "ZKEY is %s!\n", string_hash);
2995 GNUNET_STRINGS_utf8_toupper(string_hash, &nzkey_ptr);
2997 if (GNUNET_OK != GNUNET_CRYPTO_short_hash_from_string(nzkey,
3000 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
3001 "Cannot convert ZKEY `%s' to hash!\n", string_hash);
3003 if (GNUNET_SCHEDULER_NO_TASK != rh->timeout_task)
3004 GNUNET_SCHEDULER_cancel (rh->timeout_task);
3005 GNUNET_CONTAINER_DLL_remove (rlh_head, rlh_tail, rh);
3008 proc (cls, 0, NULL);
3013 else if (is_gads_tld (name) == GNUNET_YES)
3015 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3018 * Presumably GADS tld
3020 memcpy (rh->name, name,
3021 strlen (name) - strlen(GNUNET_GNS_TLD) - 1);
3022 rh->name[strlen (name) - strlen(GNUNET_GNS_TLD) - 1] = '\0';
3026 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
3027 _("Not a GADS TLD: `%s'\n"),
3029 if (GNUNET_SCHEDULER_NO_TASK != rh->timeout_task)
3030 GNUNET_SCHEDULER_cancel (rh->timeout_task);
3031 GNUNET_CONTAINER_DLL_remove (rlh_head, rlh_tail, rh);
3034 proc (cls, 0, NULL);
3040 * Initialize authority chain
3042 rh->authority_chain_head = GNUNET_malloc (sizeof(struct AuthorityChain));
3043 rh->authority_chain_tail = rh->authority_chain_head;
3044 rh->authority_chain_head->zone = rh->authority;
3045 strcpy (rh->authority_chain_head->name, "");
3048 * Copy original query into lookup handle
3050 rlh->record_type = record_type;
3051 memset(rlh->name, 0, strlen(name) + 1);
3052 strcpy(rlh->name, name);
3054 rlh->proc_cls = cls;
3056 rh->proc = &handle_delegation_ns;
3057 resolve_delegation_ns (rh);
3064 * Cancel active resolution (i.e. client disconnected).
3066 * @param h resolution to abort
3069 GNS_resolver_lookup_cancel (struct GNS_ResolverHandle *h)
3074 /* ***************** Resolver initialization ********************* */
3078 * Initialize the resolver
3080 * @param nh the namestore handle
3081 * @param dh the dht handle
3082 * @param c configuration handle
3083 * @param max_bg_queries maximum number of parallel background queries in dht
3084 * @param ignore_pending ignore records that still require user confirmation
3088 GNS_resolver_init (struct GNUNET_NAMESTORE_Handle *nh,
3089 struct GNUNET_DHT_Handle *dh,
3090 const struct GNUNET_CONFIGURATION_Handle *c,
3091 unsigned long long max_bg_queries)
3096 namestore_handle = nh;
3099 GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
3100 max_allowed_background_queries = max_bg_queries;
3102 GNUNET_CONFIGURATION_get_value_string (c,
3107 /* user did not specify DNS resolver, use 8.8.8.8 */
3108 dns_ip = GNUNET_strdup ("8.8.8.8");
3110 dns_handle = GNUNET_DNSSTUB_start (dns_ip);
3111 GNUNET_free (dns_ip);
3119 GNS_resolver_done ()
3121 while (NULL != gph_head)
3122 free_get_pseu_authority_handle (gph_head);
3123 GNUNET_CONTAINER_heap_destroy (dht_lookup_heap);
3124 dht_lookup_heap = NULL;
3125 GNUNET_DNSSTUB_stop (dns_handle);
3130 /* *************** common helper functions (do not really belong here) *********** */
3133 * Checks if "name" ends in ".tld"
3135 * @param name the name to check
3136 * @param tld the TLD to check for
3137 * @return GNUNET_YES or GNUNET_NO
3140 is_tld (const char* name, const char* tld)
3144 if (strlen (name) <= strlen (tld))
3146 offset = strlen (name) - strlen (tld);
3147 if (0 != strcmp (name + offset, tld))
3155 /* end of gnunet-service-gns_resolver.c */