* @brief GNUnet GNS resolver logic
* @author Martin Schanzenbach
* @author Christian Grothoff
+ *
+ * TODO:
+ * - recurive GNS resulution
+ * - recursive DNS resolution
+ * - shortening triggers
+ * - revocation checks (privacy!?)
*/
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_dns_service.h"
#include "gnunet_resolver_service.h"
#include "gnunet_dnsparser_lib.h"
-#include "gns_protocol.h"
#include "gnunet_gns_service.h"
-#include "gns_common.h"
#include "gns.h"
#include "gnunet-service-gns_resolver.h"
#include "gnunet_vpn_service.h"
-#define DHT_OPERATION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
-
-#define GNUNET_GNS_DEFAULT_LOOKUP_TIMEOUT \
- GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
-
-#define DHT_LOOKUP_TIMEOUT DHT_OPERATION_TIMEOUT
-
-#define DHT_GNS_REPLICATION_LEVEL 5
-
-#define GNUNET_GNS_MAX_PARALLEL_LOOKUPS 500
-
-#define GNUNET_GNS_MAX_NS_TASKS 500
-
+/**
+ * Default DHT timeout for lookups.
+ */
+#define DHT_LOOKUP_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
/**
- * Default DHT timeout
+ * Default timeout for DNS lookups.
*/
-#define DHT_LOOKUP_TIMEOUT DHT_OPERATION_TIMEOUT
+#define DNS_LOOKUP_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
/**
* DHT replication level
*/
#define DHT_GNS_REPLICATION_LEVEL 5
+/**
+ * How deep do we allow recursions to go before we abort?
+ */
+#define MAX_RECURSION 256
+
/**
* DLL to hold the authority chain we had to pass in the resolution
struct AuthorityChain *next;
/**
- * label corresponding to the authority
+ * Resolver handle this entry in the chain belongs to.
+ */
+ struct GNS_ResolverHandle *rh;
+
+ /**
+ * label/name corresponding to the authority
*/
- char label[GNUNET_DNSPARSER_MAX_LABEL_LENGTH];
+ char *label;
/**
* #GNUNET_YES if the authority was a GNS authority,
};
+/**
+ * A result we got from DNS.
+ */
+struct DnsResult
+{
+
+ /**
+ * Kept in DLL.
+ */
+ struct DnsResult *next;
+
+ /**
+ * Kept in DLL.
+ */
+ struct DnsResult *prev;
+
+ /**
+ * Binary value stored in the DNS record (appended to this struct)
+ */
+ const void *data;
+
+ /**
+ * Expiration time for the DNS record, 0 if we didn't
+ * get anything useful (i.e. 'gethostbyname' was used).
+ */
+ uint64_t expiration_time;
+
+ /**
+ * Number of bytes in 'data'.
+ */
+ size_t data_size;
+
+ /**
+ * Type of the GNS/DNS record.
+ */
+ uint32_t record_type;
+
+};
+
+
/**
* Handle to a currenty pending resolution. On result (positive or
* negative) the #GNS_ResultProcessor is called.
*/
struct GNUNET_DNSSTUB_RequestSocket *dns_request;
+ /**
+ * Handle for standard DNS resolution, NULL if none is active.
+ */
+ struct GNUNET_RESOLVER_RequestHandle *std_resolve;
+
/**
* Pending Namestore task
*/
- struct GNUNET_NAMESTORE_QueueEntry *namestore_task;
+ struct GNUNET_NAMESTORE_QueueEntry *namestore_qe;
/**
* Heap node associated with this lookup. Used to limit number of
/**
* DLL to store the authority chain
*/
- struct AuthorityChain *authority_chain_head;
+ struct AuthorityChain *ac_head;
/**
* DLL to store the authority chain
*/
- struct AuthorityChain *authority_chain_tail;
+ struct AuthorityChain *ac_tail;
/**
* Private key of the shorten zone, NULL to not shorten.
*/
struct GNUNET_CRYPTO_EccPrivateKey *shorten_key;
+ /**
+ * ID of a task associated with the resolution process.
+ */
+ GNUNET_SCHEDULER_TaskIdentifier task_id;
+
/**
* The name to resolve
*/
- char name[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
+ char *name;
+
+ /**
+ * DLL of results we got from DNS.
+ */
+ struct DnsResult *dns_result_head;
+
+ /**
+ * DLL of results we got from DNS.
+ */
+ struct DnsResult *dns_result_tail;
/**
* Current offset in 'name' where we are resolving.
*/
int only_cached;
+ /**
+ * Desired type for the resolution.
+ */
+ int record_type;
+
+ /**
+ * We increment the loop limiter for each step in a recursive
+ * resolution. If it passes our threshold (i.e. due to
+ * self-recursion in the resolution, i.e CNAME fun), we stop.
+ */
+ unsigned int loop_limiter;
+
};
*/
char label[GNUNET_DNSPARSER_MAX_LABEL_LENGTH + 1];
+ /**
+ * Label we are currently trying out (during #perform_pseu_lookup).
+ */
+ char *current_label;
+
/**
* The zone for which we are trying to find the PSEU record.
*/
static struct GNUNET_CONTAINER_Heap *dht_lookup_heap;
/**
- * Maximum amount of parallel queries in background
+ * Maximum amount of parallel queries to the DHT
*/
static unsigned long long max_allowed_background_queries;
* even though they consist of multiple labels.
*
* Examples:
- * a.b.gads = not canonical
+ * a.b.gnu = not canonical
* a = canonical
* _foo._srv = canonical
* _f.bar = not canonical
gph->timeout_task = GNUNET_SCHEDULER_NO_TASK;
}
GNUNET_CONTAINER_DLL_remove (gph_head, gph_tail, gph);
+ GNUNET_free_non_null (gph->current_label);
GNUNET_free (gph);
}
* (or with rd_count=0 to indicate no matches).
*
* @param cls the pending query
- * @param key the key of the zone we did the lookup
- * @param name the name for which we need an authority
* @param rd_count the number of records with 'name'
* @param rd the record data
*/
static void
process_pseu_lookup_ns (void *cls,
- const struct GNUNET_CRYPTO_EccPrivateKey *key,
- const char *name,
+ unsigned int rd_count,
+ const struct GNUNET_NAMESTORE_RecordData *rd);
+
+
+/**
+ * We obtained a result for our query to the shorten zone from
+ * the namestore. Try to decrypt.
+ *
+ * @param cls the handle to our shorten operation
+ * @param block resulting encrypted block
+ */
+static void
+process_pseu_block_ns (void *cls,
+ const struct GNUNET_NAMESTORE_Block *block)
+{
+ struct GetPseuAuthorityHandle *gph = cls;
+ struct GNUNET_CRYPTO_EccPublicKey pub;
+
+ gph->namestore_task = NULL;
+ if (NULL == block)
+ {
+ process_pseu_lookup_ns (gph, 0, NULL);
+ return;
+ }
+ GNUNET_CRYPTO_ecc_key_get_public (&gph->shorten_zone_key,
+ &pub);
+ if (GNUNET_OK !=
+ GNUNET_NAMESTORE_block_decrypt (block,
+ &pub,
+ gph->current_label,
+ &process_pseu_lookup_ns,
+ gph))
+ {
+ GNUNET_break (0);
+ free_get_pseu_authority_handle (gph);
+ return;
+ }
+}
+
+
+/**
+ * Lookup in the namestore for the shorten zone the given label.
+ *
+ * @param gph the handle to our shorten operation
+ * @param label the label to lookup
+ */
+static void
+perform_pseu_lookup (struct GetPseuAuthorityHandle *gph,
+ const char *label)
+{
+ struct GNUNET_CRYPTO_EccPublicKey pub;
+ struct GNUNET_HashCode query;
+
+ GNUNET_CRYPTO_ecc_key_get_public (&gph->shorten_zone_key,
+ &pub);
+ GNUNET_free_non_null (gph->current_label);
+ gph->current_label = GNUNET_strdup (label);
+ GNUNET_NAMESTORE_query_from_public_key (&pub,
+ label,
+ &query);
+ gph->namestore_task = GNUNET_NAMESTORE_lookup_block (namestore_handle,
+ &query,
+ &process_pseu_block_ns,
+ gph);
+}
+
+
+/**
+ * Namestore calls this function if we have record for this name.
+ * (or with rd_count=0 to indicate no matches).
+ *
+ * @param cls the pending query
+ * @param rd_count the number of records with 'name'
+ * @param rd the record data
+ */
+static void
+process_pseu_lookup_ns (void *cls,
unsigned int rd_count,
const struct GNUNET_NAMESTORE_RecordData *rd)
{
{
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
"Name `%s' already taken, cannot shorten.\n",
- name);
+ gph->current_label);
/* if this was not yet the original label, try one more
time, this time not using PSEU but the original label */
- if (0 == strcmp (name,
+ if (0 == strcmp (gph->current_label,
gph->label))
+ {
free_get_pseu_authority_handle (gph);
+ }
else
- gph->namestore_task = GNUNET_NAMESTORE_lookup (namestore_handle,
- &gph->shorten_zone_key,
- gph->label,
- GNUNET_NAMESTORE_TYPE_ANY,
- &process_pseu_lookup_ns,
- gph);
+ {
+ perform_pseu_lookup (gph, gph->label);
+ }
return;
}
/* name is available */
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Shortening `%s' to `%s'\n",
GNUNET_NAMESTORE_z2s (&gph->target_zone),
- name);
+ gph->current_label);
new_pkey.expiration_time = UINT64_MAX;
new_pkey.data_size = sizeof (struct GNUNET_CRYPTO_EccPublicKey);
new_pkey.data = &gph->target_zone;
gph->namestore_task
= GNUNET_NAMESTORE_records_store (namestore_handle,
&gph->shorten_zone_key,
- name,
+ gph->current_label,
1, &new_pkey,
&create_pkey_cont, gph);
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"No PSEU found, trying original label `%s' instead.\n",
gph->label);
- gph->namestore_task = GNUNET_NAMESTORE_lookup (namestore_handle,
- &gph->shorten_zone_key,
- gph->label,
- GNUNET_NAMESTORE_TYPE_ANY,
- &process_pseu_lookup_ns,
- gph);
+ perform_pseu_lookup (gph, gph->label);
return;
- }
-
+ }
/* check if 'pseu' is taken */
- gph->namestore_task = GNUNET_NAMESTORE_lookup (namestore_handle,
- &gph->shorten_zone_key,
- pseu,
- GNUNET_NAMESTORE_TYPE_ANY,
- &process_pseu_lookup_ns,
- gph);
+ perform_pseu_lookup (gph, pseu);
}
/* ************************** Resolution **************************** */
#if 0
+
+
/**
- * Helper function to free resolver handle
+ * Namestore calls this function if we have record for this name.
+ * (or with rd_count=0 to indicate no matches)
*
- * @param rh the handle to free
+ * @param cls the pending query
+ * @param key the key of the zone we did the lookup
+ * @param expiration expiration date of the namestore entry
+ * @param name the name for which we need an authority
+ * @param rd_count the number of records with 'name'
+ * @param rd the record data
+ * @param signature the signature of the authority for the record data
*/
static void
-free_resolver_handle (struct ResolverHandle* rh)
+process_record_result_ns (void* cls,
+ const struct GNUNET_CRYPTO_EccPublicKey *key,
+ struct GNUNET_TIME_Absolute expiration,
+ const char *name, unsigned int rd_count,
+ const struct GNUNET_NAMESTORE_RecordData *rd,
+ const struct GNUNET_CRYPTO_EccSignature *signature)
{
- struct AuthorityChain *ac;
- struct AuthorityChain *ac_next;
-
- if (NULL == rh)
- return;
+ struct ResolverHandle *rh = cls;
+ struct RecordLookupHandle *rlh = rh->proc_cls;
+ struct GNUNET_TIME_Relative remaining_time;
+ struct GNUNET_CRYPTO_ShortHashCode zone;
+ struct GNUNET_TIME_Absolute et;
+ unsigned int i;
- ac_next = rh->authority_chain_head;
- while (NULL != (ac = ac_next))
+ rh->namestore_task = NULL;
+ GNUNET_CRYPTO_short_hash (key,
+ sizeof (struct GNUNET_CRYPTO_EccPublicKey),
+ &zone);
+ remaining_time = GNUNET_TIME_absolute_get_remaining (expiration);
+ rh->status = 0;
+ if (NULL != name)
{
- ac_next = ac->next;
- GNUNET_free (ac);
+ rh->status |= RSL_RECORD_EXISTS;
+ if (remaining_time.rel_value_us == 0)
+ rh->status |= RSL_RECORD_EXPIRED;
}
-
- if (NULL != rh->get_handle)
- GNUNET_DHT_get_stop (rh->get_handle);
- if (NULL != rh->dns_raw_packet)
- GNUNET_free (rh->dns_raw_packet);
- if (NULL != rh->namestore_task)
+ if (0 == rd_count)
{
- GNUNET_NAMESTORE_cancel (rh->namestore_task);
- rh->namestore_task = NULL;
- }
- if (GNUNET_SCHEDULER_NO_TASK != rh->dns_read_task)
- GNUNET_SCHEDULER_cancel (rh->dns_read_task);
- if (GNUNET_SCHEDULER_NO_TASK != rh->timeout_task)
- GNUNET_SCHEDULER_cancel (rh->timeout_task);
- if (NULL != rh->dns_sock)
- GNUNET_NETWORK_socket_close (rh->dns_sock);
- if (NULL != rh->dns_resolver_handle)
- GNUNET_RESOLVER_request_cancel (rh->dns_resolver_handle);
- if (NULL != rh->rd.data)
- GNUNET_free ((void*)(rh->rd.data));
- if (NULL != rh->dht_heap_node)
- GNUNET_CONTAINER_heap_remove_node (rh->dht_heap_node);
- GNUNET_free (rh);
-}
-
-
-/**
- * Callback when record data is put into namestore
- *
- * @param cls the closure
- * @param success GNUNET_OK on success
- * @param emsg the error message. NULL if SUCCESS==GNUNET_OK
- */
-void
-on_namestore_record_put_result (void *cls,
- int32_t success,
- const char *emsg)
-{
- struct NamestoreBGTask *nbg = cls;
-
- GNUNET_CONTAINER_heap_remove_node (nbg->node);
- GNUNET_free (nbg);
+ /**
+ * Lookup terminated and no results
+ */
+ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+ "GNS_PHASE_REC-%llu: Namestore lookup for %s terminated without results\n",
+ rh->id, name);
- if (GNUNET_NO == success)
- {
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "GNS_NS: records already in namestore\n");
+ "GNS_PHASE_REC-%llu: Record %s unknown in namestore\n",
+ rh->id, rh->name);
+ /**
+ * Our zone and no result? Cannot resolve TT
+ */
+ rh->proc(rh->proc_cls, rh, 0, NULL);
return;
+
}
- else if (GNUNET_YES == success)
+ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+ "GNS_PHASE_REC-%llu: Processing additional result %s from namestore\n",
+ rh->id, name);
+ for (i = 0; i < rd_count;i++)
{
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "GNS_NS: records successfully put in namestore\n");
+ if (rd[i].record_type != rlh->record_type)
+ continue;
+
+ if (ignore_pending_records &&
+ (rd[i].flags & GNUNET_NAMESTORE_RF_PENDING))
+ {
+ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+ "GNS_PHASE_REC-%llu: Record %s is awaiting user confirmation. Skipping\n",
+ rh->id, name);
+ continue;
+ }
+
+ //FIXME: eh? do I have to handle this here?
+ GNUNET_break (0 == (rd[i].flags & GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION));
+ et.abs_value_us = rd[i].expiration_time;
+ if (0 == (GNUNET_TIME_absolute_get_remaining (et)).rel_value_us)
+ {
+ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+ "GNS_PHASE_REC-%llu: This record is expired. Skipping\n",
+ rh->id);
+ continue;
+ }
+ rh->answered++;
+ }
+
+ /**
+ * no answers found
+ */
+ if (0 == rh->answered)
+ {
+ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+ "GNS_PHASE_REC-%llu: No answers found. This is odd!\n", rh->id);
+ rh->proc(rh->proc_cls, rh, 0, NULL);
return;
}
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
- "GNS_NS: Error putting records into namestore: %s\n", emsg);
+ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+ "GNS_PHASE_REC-%llu: Found %d answer(s) to query in %d records!\n",
+ rh->id, rh->answered, rd_count);
+ rh->proc(rh->proc_cls, rh, rd_count, rd);
}
/**
- * Function called when we get a result from the dht
- * for our record query
+ * VPN redirect result callback
*
- * @param cls the request handle
- * @param exp lifetime
- * @param key the key the record was stored under
- * @param get_path get path
- * @param get_path_length get path length
- * @param put_path put path
- * @param put_path_length put path length
- * @param type the block type
- * @param size the size of the record
- * @param data the record data
+ * @param cls the resolver handle
+ * @param af the requested address family
+ * @param address in_addr(6) respectively
*/
static void
-process_record_result_dht (void* cls,
- struct GNUNET_TIME_Absolute exp,
- const struct GNUNET_HashCode * key,
- const struct GNUNET_PeerIdentity *get_path,
- unsigned int get_path_length,
- const struct GNUNET_PeerIdentity *put_path,
- unsigned int put_path_length,
- enum GNUNET_BLOCK_Type type,
- size_t size, const void *data)
+process_record_result_vpn (void* cls, int af, const void *address)
{
struct ResolverHandle *rh = cls;
struct RecordLookupHandle *rlh = rh->proc_cls;
- const struct GNSNameRecordBlock *nrb = data;
- uint32_t num_records;
- const char* name;
- const char* rd_data;
- uint32_t i;
- size_t rd_size;
+ struct GNUNET_NAMESTORE_RecordData rd;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "GNS_PHASE_REC-%llu: got dht result (size=%d)\n", rh->id, size);
- /* stop lookup and timeout task */
- GNUNET_DHT_get_stop (rh->get_handle);
- rh->get_handle = NULL;
- if (rh->dht_heap_node != NULL)
- {
- GNUNET_CONTAINER_heap_remove_node (rh->dht_heap_node);
- rh->dht_heap_node = NULL;
- }
- if (rh->timeout_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (rh->timeout_task);
- rh->timeout_task = GNUNET_SCHEDULER_NO_TASK;
- }
- rh->get_handle = NULL;
- name = (const char*) &nrb[1];
- num_records = ntohl (nrb->rd_count);
- {
- struct GNUNET_NAMESTORE_RecordData rd[num_records];
- struct NamestoreBGTask *ns_heap_root;
- struct NamestoreBGTask *namestore_bg_task;
-
- rd_data = &name[strlen (name) + 1];
- rd_size = size - strlen (name) - 1 - sizeof (struct GNSNameRecordBlock);
- if (GNUNET_SYSERR ==
- GNUNET_NAMESTORE_records_deserialize (rd_size,
- rd_data,
- num_records,
- rd))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "GNS_PHASE_REC-%llu: Error deserializing data!\n", rh->id);
- rh->proc (rh->proc_cls, rh, 0, NULL);
- return;
- }
- for (i = 0; i < num_records; i++)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "GNS_PHASE_REC-%llu: Got name: %s (wanted %s)\n",
- rh->id, name, rh->name);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "GNS_PHASE_REC-%llu: Got type: %d (wanted %d)\n",
- rh->id, rd[i].record_type, rlh->record_type);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "GNS_PHASE_REC-%llu: Got data length: %d\n",
- rh->id, rd[i].data_size);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "GNS_PHASE_REC-%llu: Got flag %d\n",
- rh->id, rd[i].flags);
-
- if ((strcmp (name, rh->name) == 0) &&
- (rd[i].record_type == rlh->record_type))
- rh->answered++;
-
- }
-
- /**
- * FIXME check pubkey against existing key in namestore?
- * https://gnunet.org/bugs/view.php?id=2179
- */
- if (max_allowed_ns_tasks <=
- GNUNET_CONTAINER_heap_get_size (ns_task_heap))
- {
- ns_heap_root = GNUNET_CONTAINER_heap_remove_root (ns_task_heap);
- GNUNET_NAMESTORE_cancel (ns_heap_root->qe);
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "GNS_PHASE_REC-%llu: Replacing oldest background ns task\n",
- rh->id);
- }
-
- /* Save to namestore */
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "GNS_PHASE_REC-%llu: Caching record for %s\n",
- rh->id, name);
- namestore_bg_task = GNUNET_malloc (sizeof (struct NamestoreBGTask));
- namestore_bg_task->qe = GNUNET_NAMESTORE_record_put (namestore_handle,
- &nrb->public_key,
- name,
- exp,
- num_records,
- rd,
- &nrb->signature,
- &on_namestore_record_put_result, //cont
- namestore_bg_task);
-
- namestore_bg_task->node = GNUNET_CONTAINER_heap_insert (ns_task_heap,
- namestore_bg_task,
- GNUNET_TIME_absolute_get().abs_value_us);
- if (0 < rh->answered)
- rh->proc (rh->proc_cls, rh, num_records, rd);
- else
- rh->proc (rh->proc_cls, rh, 0, NULL);
- }
-}
-
-
-/**
- * Start DHT lookup for a (name -> query->record_type) record in
- * rh->authority's zone
- *
- * @param rh the pending gns query context
- */
-static void
-resolve_record_dht (struct ResolverHandle *rh)
-{
- struct RecordLookupHandle *rlh = rh->proc_cls;
- uint32_t xquery;
- struct GNUNET_HashCode lookup_key;
- struct ResolverHandle *rh_heap_root;
-
- GNUNET_GNS_get_key_for_record (rh->name, &rh->authority, &lookup_key);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "GNS_PHASE_REC-%llu: starting dht lookup for %s with key: %s\n",
- rh->id, rh->name, GNUNET_h2s (&lookup_key));
-
- rh->dht_heap_node = NULL;
-
- if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != rh->timeout.rel_value_us)
- {
- /**
- * Update timeout if necessary
- */
- if (GNUNET_SCHEDULER_NO_TASK == rh->timeout_task)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "GNS_PHASE_REC-%llu: Adjusting timeout to %s/2\n",
- rh->id,
- GNUNET_STRINGS_relative_time_to_string (rh->timeout, GNUNET_YES));
- /*
- * Set timeout for authority lookup phase to 1/2
- */
- rh->timeout_task = GNUNET_SCHEDULER_add_delayed (
- GNUNET_TIME_relative_divide (rh->timeout, 2),
- &handle_lookup_timeout,
- rh);
- }
- rh->timeout_cont = &dht_lookup_timeout;
- rh->timeout_cont_cls = rh;
- }
- else
- {
- if (max_allowed_background_queries <=
- GNUNET_CONTAINER_heap_get_size (dht_lookup_heap))
- {
- rh_heap_root = GNUNET_CONTAINER_heap_remove_root (dht_lookup_heap);
- GNUNET_DHT_get_stop (rh_heap_root->get_handle);
- rh_heap_root->get_handle = NULL;
- rh_heap_root->dht_heap_node = NULL;
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "GNS_PHASE_REC-%llu: Replacing oldest background query for %s\n",
- rh->id, rh_heap_root->name);
- rh_heap_root->proc (rh_heap_root->proc_cls,
- rh_heap_root,
- 0,
- NULL);
- }
- rh->dht_heap_node = GNUNET_CONTAINER_heap_insert (dht_lookup_heap,
- rh,
- GNUNET_TIME_absolute_get ().abs_value_us);
- }
-
- xquery = htonl (rlh->record_type);
-
- GNUNET_assert (rh->get_handle == NULL);
- rh->get_handle = GNUNET_DHT_get_start (dht_handle,
- GNUNET_BLOCK_TYPE_GNS_NAMERECORD,
- &lookup_key,
- DHT_GNS_REPLICATION_LEVEL,
- GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
- &xquery,
- sizeof (xquery),
- &process_record_result_dht,
- rh);
-
-}
-
-
-/**
- * Namestore calls this function if we have record for this name.
- * (or with rd_count=0 to indicate no matches)
- *
- * @param cls the pending query
- * @param key the key of the zone we did the lookup
- * @param expiration expiration date of the namestore entry
- * @param name the name for which we need an authority
- * @param rd_count the number of records with 'name'
- * @param rd the record data
- * @param signature the signature of the authority for the record data
- */
-static void
-process_record_result_ns (void* cls,
- const struct GNUNET_CRYPTO_EccPublicKey *key,
- struct GNUNET_TIME_Absolute expiration,
- const char *name, unsigned int rd_count,
- const struct GNUNET_NAMESTORE_RecordData *rd,
- const struct GNUNET_CRYPTO_EccSignature *signature)
-{
- struct ResolverHandle *rh = cls;
- struct RecordLookupHandle *rlh = rh->proc_cls;
- struct GNUNET_TIME_Relative remaining_time;
- struct GNUNET_CRYPTO_ShortHashCode zone;
- struct GNUNET_TIME_Absolute et;
- unsigned int i;
-
- rh->namestore_task = NULL;
- GNUNET_CRYPTO_short_hash (key,
- sizeof (struct GNUNET_CRYPTO_EccPublicKey),
- &zone);
- remaining_time = GNUNET_TIME_absolute_get_remaining (expiration);
- rh->status = 0;
- if (NULL != name)
- {
- rh->status |= RSL_RECORD_EXISTS;
- if (remaining_time.rel_value_us == 0)
- rh->status |= RSL_RECORD_EXPIRED;
- }
- if (0 == rd_count)
- {
- /**
- * Lookup terminated and no results
- */
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "GNS_PHASE_REC-%llu: Namestore lookup for %s terminated without results\n",
- rh->id, name);
-
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "GNS_PHASE_REC-%llu: Record %s unknown in namestore\n",
- rh->id, rh->name);
- /**
- * Our zone and no result? Cannot resolve TT
- */
- rh->proc(rh->proc_cls, rh, 0, NULL);
- return;
-
- }
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "GNS_PHASE_REC-%llu: Processing additional result %s from namestore\n",
- rh->id, name);
- for (i = 0; i < rd_count;i++)
- {
- if (rd[i].record_type != rlh->record_type)
- continue;
-
- if (ignore_pending_records &&
- (rd[i].flags & GNUNET_NAMESTORE_RF_PENDING))
- {
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "GNS_PHASE_REC-%llu: Record %s is awaiting user confirmation. Skipping\n",
- rh->id, name);
- continue;
- }
-
- //FIXME: eh? do I have to handle this here?
- GNUNET_break (0 == (rd[i].flags & GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION));
- et.abs_value_us = rd[i].expiration_time;
- if (0 == (GNUNET_TIME_absolute_get_remaining (et)).rel_value_us)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "GNS_PHASE_REC-%llu: This record is expired. Skipping\n",
- rh->id);
- continue;
- }
- rh->answered++;
- }
-
- /**
- * no answers found
- */
- if (0 == rh->answered)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "GNS_PHASE_REC-%llu: No answers found. This is odd!\n", rh->id);
- rh->proc(rh->proc_cls, rh, 0, NULL);
- return;
- }
-
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "GNS_PHASE_REC-%llu: Found %d answer(s) to query in %d records!\n",
- rh->id, rh->answered, rd_count);
- rh->proc(rh->proc_cls, rh, rd_count, rd);
-}
-
-
-#ifndef WINDOWS
-/**
- * VPN redirect result callback
- *
- * @param cls the resolver handle
- * @param af the requested address family
- * @param address in_addr(6) respectively
- */
-static void
-process_record_result_vpn (void* cls, int af, const void *address)
-{
- struct ResolverHandle *rh = cls;
- struct RecordLookupHandle *rlh = rh->proc_cls;
- struct GNUNET_NAMESTORE_RecordData rd;
-
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "GNS_PHASE_REC_VPN-%llu: Got answer from VPN to query!\n",
- rh->id);
- if (AF_INET == af)
+ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+ "GNS_PHASE_REC_VPN-%llu: Got answer from VPN to query!\n",
+ rh->id);
+ if (AF_INET == af)
{
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
"GNS_PHASE_REC-%llu: Answer is IPv4!\n",
rh->id);
rh->proc (rh->proc_cls, rh, 0, NULL);
}
-#endif
/**
struct RecordLookupHandle *rlh = rh->proc_cls;
struct GNUNET_DNSPARSER_Query query;
struct GNUNET_DNSPARSER_Packet packet;
- struct GNUNET_DNSPARSER_Flags flags;
+ struct GNUNET_TUN_DnsFlags flags;
struct in_addr dnsip;
struct sockaddr_in addr;
struct sockaddr *sa;
}
query.name = rh->dns_name;
query.type = rlh->record_type;
- query.class = GNUNET_DNSPARSER_CLASS_INTERNET;
+ query.class = GNUNET_TUN_DNS_CLASS_INTERNET;
memset (&flags, 0, sizeof (flags));
flags.recursion_desired = 1;
flags.checking_disabled = 1;
{
struct RecordLookupHandle *rlh = rh->proc_cls;
struct GNUNET_HashCode serv_desc;
- struct vpn_data* vpn;
+ struct GNUNET_TUN_GnsVpnRecord* vpn;
int af;
/* We cancel here as to not include the ns lookup in the timeout */
rh->priv_key);
}
- vpn = (struct vpn_data*)rd->data;
+ vpn = (struct GNUNET_TUN_GnsVpnRecord*)rd->data;
GNUNET_CRYPTO_hash ((char*)&vpn[1],
strlen ((char*)&vpn[1]) + 1,
&serv_desc);
/**
- * Handle timeout for DHT requests
+ * This is a callback function that checks for key revocation
*
- * @param cls the request handle as closure
- * @param tc the task context
+ * @param cls the pending query
+ * @param key the key of the zone we did the lookup
+ * @param expiration expiration date of the record data set in the namestore
+ * @param name the name for which we need an authority
+ * @param rd_count the number of records with 'name'
+ * @param rd the record data
+ * @param signature the signature of the authority for the record data
*/
static void
-dht_authority_lookup_timeout (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+process_pkey_revocation_result_ns (void *cls,
+ const struct GNUNET_CRYPTO_EccPublicKey *key,
+ struct GNUNET_TIME_Absolute expiration,
+ const char *name,
+ unsigned int rd_count,
+ const struct GNUNET_NAMESTORE_RecordData *rd,
+ const struct GNUNET_CRYPTO_EccSignature *signature)
{
struct ResolverHandle *rh = cls;
- struct RecordLookupHandle *rlh = rh->proc_cls;
- char new_name[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "GNS_PHASE_DELEGATE_DHT-%llu: dht lookup for query %s (%s) timed out.\n",
- rh->id, rh->authority_name,
- GNUNET_STRINGS_relative_time_to_string (rh->timeout,
- GNUNET_YES));
-
- rh->status |= RSL_TIMED_OUT;
- rh->timeout_task = GNUNET_SCHEDULER_NO_TASK;
- if (NULL != rh->get_handle)
- {
- GNUNET_DHT_get_stop (rh->get_handle);
- rh->get_handle = NULL;
- }
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "GNS_PHASE_DELEGATE_DHT-%llu: Got shutdown\n",
- rh->id);
- rh->proc (rh->proc_cls, rh, 0, NULL);
- return;
- }
- if (0 == strcmp (rh->name, ""))
- {
- /*
- * promote authority back to name and try to resolve record
- */
- strcpy (rh->name, rh->authority_name);
- rh->proc (rh->proc_cls, rh, 0, NULL);
- return;
- }
-
- /**
- * Start resolution in bg
- */
- GNUNET_snprintf (new_name, GNUNET_DNSPARSER_MAX_NAME_LENGTH,
- "%s.%s.%s",
- rh->name, rh->authority_name, GNUNET_GNS_TLD);
- strcpy (rh->name, new_name);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "GNS_PHASE_DELEGATE_DHT-%llu: Starting background query for %s type %d\n",
- rh->id, rh->name,
- rlh->record_type);
- gns_resolver_lookup_record (rh->authority,
- rh->private_local_zone,
- rlh->record_type,
- new_name,
- NULL,
- GNUNET_TIME_UNIT_FOREVER_REL,
- GNUNET_NO,
- &background_lookup_result_processor,
- NULL);
- rh->proc (rh->proc_cls, rh, 0, NULL);
-}
-
-
-/**
- * This is a callback function that checks for key revocation
- *
- * @param cls the pending query
- * @param key the key of the zone we did the lookup
- * @param expiration expiration date of the record data set in the namestore
- * @param name the name for which we need an authority
- * @param rd_count the number of records with 'name'
- * @param rd the record data
- * @param signature the signature of the authority for the record data
- */
-static void
-process_pkey_revocation_result_ns (void *cls,
- const struct GNUNET_CRYPTO_EccPublicKey *key,
- struct GNUNET_TIME_Absolute expiration,
- const char *name,
- unsigned int rd_count,
- const struct GNUNET_NAMESTORE_RecordData *rd,
- const struct GNUNET_CRYPTO_EccSignature *signature)
-{
- struct ResolverHandle *rh = cls;
- struct GNUNET_TIME_Relative remaining_time;
- int i;
-
- rh->namestore_task = NULL;
- remaining_time = GNUNET_TIME_absolute_get_remaining (expiration);
-
- for (i = 0; i < rd_count; i++)
+ struct GNUNET_TIME_Relative remaining_time;
+ int i;
+
+ rh->namestore_task = NULL;
+ remaining_time = GNUNET_TIME_absolute_get_remaining (expiration);
+
+ for (i = 0; i < rd_count; i++)
{
if (GNUNET_NAMESTORE_TYPE_REV == rd[i].record_type)
{
{
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
"GNS_PHASE_DELEGATE_REV-%llu: Starting background lookup for %s type %d\n",
- rh->id, "+.gads", GNUNET_NAMESTORE_TYPE_REV);
+ rh->id, "+.gnu", GNUNET_NAMESTORE_TYPE_REV);
gns_resolver_lookup_record(rh->authority,
rh->private_local_zone,
}
-/**
- * Callback when record data is put into namestore
- *
- * @param cls the closure
- * @param success GNUNET_OK on success
- * @param emsg the error message. NULL if SUCCESS==GNUNET_OK
- */
-static void
-on_namestore_delegation_put_result(void *cls,
- int32_t success,
- const char *emsg)
-{
- struct NamestoreBGTask *nbg = cls;
-
- GNUNET_CONTAINER_heap_remove_node (nbg->node);
- GNUNET_free (nbg);
-
- if (GNUNET_NO == success)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "GNS_NS: records already in namestore\n");
- return;
- }
- else if (GNUNET_YES == success)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "GNS_NS: records successfully put in namestore\n");
- return;
- }
-
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
- "GNS_NS: Error putting records into namestore: %s\n", emsg);
-}
-
-
/**
* Function called when we get a result from the dht
* for our query. Recursively tries to resolve authorities
/* Check for key revocation and delegate */
- rh->namestore_task = GNUNET_NAMESTORE_lookup_record (namestore_handle,
- &rh->authority,
- GNUNET_GNS_MASTERZONE_STR,
- GNUNET_NAMESTORE_TYPE_REV,
- &process_pkey_revocation_result_ns,
- rh);
+ rh->namestore_task = GNUNET_NAMESTORE_lookup (namestore_handle,
+ &rh->authority,
+ GNUNET_GNS_MASTERZONE_STR,
+ GNUNET_NAMESTORE_TYPE_REV,
+ &process_pkey_revocation_result_ns,
+ rh);
return;
}
char new_mx_data[MAX_MX_LENGTH];
char new_soa_data[MAX_SOA_LENGTH];
char new_srv_data[MAX_SRV_LENGTH];
- struct srv_data *old_srv;
- struct srv_data *new_srv;
- struct soa_data *old_soa;
- struct soa_data *new_soa;
+ struct GNUNET_TUN_DnsSrvRecord *old_srv;
+ struct GNUNET_TUN_DnsSrvRecord *new_srv;
+ struct GNUNET_TUN_DnsSoaRecord *old_soa;
+ struct GNUNET_TUN_DnsSoaRecord *new_soa;
struct GNUNET_NAMESTORE_RecordData p_rd[rd_count];
char* repl_string;
char* pos;
/*
* Prio, weight and port
*/
- new_srv = (struct srv_data*)new_srv_data;
- old_srv = (struct srv_data*)rd[i].data;
+ new_srv = (struct GNUNET_TUN_DnsSrvRecord*)new_srv_data;
+ old_srv = (struct GNUNET_TUN_DnsSrvRecord*)rd[i].data;
new_srv->prio = old_srv->prio;
new_srv->weight = old_srv->weight;
new_srv->port = old_srv->port;
expand_plus((char*)&new_srv[1], (char*)&old_srv[1],
repl_string);
p_rd[i].data = new_srv_data;
- p_rd[i].data_size = sizeof (struct srv_data) + strlen ((char*)&new_srv[1]) + 1;
+ p_rd[i].data_size = sizeof (struct GNUNET_TUN_DnsSrvRecord) + strlen ((char*)&new_srv[1]) + 1;
}
else if (GNUNET_DNSPARSER_TYPE_SOA == rd[i].record_type)
{
/* expand mname and rname */
- old_soa = (struct soa_data*)rd[i].data;
- new_soa = (struct soa_data*)new_soa_data;
- memcpy (new_soa, old_soa, sizeof (struct soa_data));
+ old_soa = (struct GNUNET_TUN_DnsSoaRecord*)rd[i].data;
+ new_soa = (struct GNUNET_TUN_DnsSoaRecord*)new_soa_data;
+ memcpy (new_soa, old_soa, sizeof (struct GNUNET_TUN_DnsSoaRecord));
// FIXME: how do we know that 'new_soa[1]' has enough space for the new name?
expand_plus((char*)&new_soa[1], (char*)&old_soa[1], repl_string);
offset = strlen ((char*)&new_soa[1]) + 1;
expand_plus((char*)&new_soa[1] + offset,
(char*)&old_soa[1] + strlen ((char*)&old_soa[1]) + 1,
repl_string);
- p_rd[i].data_size = sizeof (struct soa_data)
+ p_rd[i].data_size = sizeof (struct GNUNET_TUN_DnsSoaRecord)
+ offset
+ strlen ((char*)&new_soa[1] + offset);
p_rd[i].data = new_soa_data;
memcpy ((void*)rh->rd.data, rd[i].data, rd[i].data_size);
rh->rd_count = 1;
/* Check for key revocation and delegate */
- rh->namestore_task = GNUNET_NAMESTORE_lookup_record (namestore_handle,
- &rh->authority,
- GNUNET_GNS_MASTERZONE_STR,
- GNUNET_NAMESTORE_TYPE_REV,
- &process_pkey_revocation_result_ns,
- rh);
+ rh->namestore_task = GNUNET_NAMESTORE_lookup (namestore_handle,
+ &rh->authority,
+ GNUNET_GNS_MASTERZONE_STR,
+ GNUNET_NAMESTORE_TYPE_REV,
+ &process_pkey_revocation_result_ns,
+ rh);
return;
default:
/* ignore, move to next result */
}
+#endif
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+
/**
- * Resolve the delegation chain for the request in our namestore
- * (as in, find the respective authority for the leftmost label).
+ * Task scheduled to asynchronously fail a resolution.
*
- * @param rh the resolver handle
+ * @param cls the 'struct GNS_ResolverHandle' of the resolution to fail
+ * @param tc task context
*/
static void
-resolve_delegation_ns (struct ResolverHandle *rh)
+fail_resolution (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
{
- pop_tld (rh->name, rh->authority_name);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "GNS_PHASE_DELEGATE_NS-%llu: Finding authority for `%s' by looking up `%s' in GADS zone `%s'\n",
- rh->id,
- rh->name,
- rh->authority_name,
- GNUNET_short_h2s (&rh->authority));
- rh->namestore_task = GNUNET_NAMESTORE_lookup_record (namestore_handle,
- &rh->authority,
- rh->authority_name,
- GNUNET_DNSPARSER_TYPE_ANY,
- &process_delegation_result_ns,
- rh);
+ struct GNS_ResolverHandle *rh = cls;
+
+ rh->task_id = GNUNET_SCHEDULER_NO_TASK;
+ rh->proc (rh->proc_cls, 0, NULL);
+ GNS_resolver_lookup_cancel (rh);
}
-#endif
+/**
+ * Get the next, rightmost label from the name that we are trying to resolve,
+ * and update the resolution position accordingly.
+ *
+ * @param rh handle to the resolution operation to get the next label from
+ * @return NULL if there are no more labels
+ */
+static char *
+resolver_lookup_get_next_label (struct GNS_ResolverHandle *rh)
+{
+ const char *rp;
+ const char *dot;
+ size_t len;
+
+ if (0 == rh->name_resolution_pos)
+ return NULL;
+ dot = memrchr (rh->name, (int) '.', rh->name_resolution_pos);
+ if (NULL == dot)
+ {
+ /* done, this was the last one */
+ len = rh->name_resolution_pos;
+ rp = rh->name;
+ rh->name_resolution_pos = 0;
+ }
+ else
+ {
+ /* advance by one label */
+ len = rh->name_resolution_pos - (dot - rh->name) - 1;
+ rp = dot + 1;
+ rh->name_resolution_pos = dot - rh->name;
+ }
+ return GNUNET_strndup (rp, len);
+}
+
+
+/**
+ * Gives the cummulative result obtained to the callback and clean up the request.
+ *
+ * @param rh resolution process that has culminated in a result
+ */
+static void
+transmit_lookup_dns_result (struct GNS_ResolverHandle *rh)
+{
+ struct DnsResult *pos;
+ unsigned int n;
+ unsigned int i;
+
+ n = 0;
+ for (pos = rh->dns_result_head; NULL != pos; pos = pos->next)
+ n++;
+ {
+ struct GNUNET_NAMESTORE_RecordData rd[n];
+
+ i = 0;
+ for (pos = rh->dns_result_head; NULL != pos; pos = pos->next)
+ {
+ rd[i].data = pos->data;
+ rd[i].data_size = pos->data_size;
+ rd[i].record_type = pos->record_type;
+ if (0 == pos->expiration_time)
+ {
+ rd[i].flags = GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION;
+ rd[i].expiration_time = 0;
+ }
+ else
+ {
+ rd[i].flags = GNUNET_NAMESTORE_RF_NONE;
+ rd[i].expiration_time = pos->expiration_time;
+ }
+ }
+ rh->proc (rh->proc_cls,
+ n,
+ rd);
+ }
+ GNS_resolver_lookup_cancel (rh);
+}
+
+
+/**
+ * Add a result from DNS to the records to be returned to the application.
+ *
+ * @param rh resolution request to extend with a result
+ * @param expiration_time expiration time for the answer
+ * @param record_type DNS record type of the answer
+ * @param data_size number of bytes in @a data
+ * @param data binary data to return in DNS record
+ */
+static void
+add_dns_result (struct GNS_ResolverHandle *rh,
+ uint64_t expiration_time,
+ uint32_t record_type,
+ size_t data_size,
+ const void *data)
+{
+ struct DnsResult *res;
+
+ res = GNUNET_malloc (sizeof (struct DnsResult) + data_size);
+ res->expiration_time = expiration_time;
+ res->data_size = data_size;
+ res->record_type = record_type;
+ res->data = &res[1];
+ memcpy (&res[1], data, data_size);
+ GNUNET_CONTAINER_DLL_insert (rh->dns_result_head,
+ rh->dns_result_tail,
+ res);
+}
+
+
+/**
+ * We had to do a DNS lookup. Convert the result (if any) and return
+ * it.
+ *
+ * @param cls closure with the 'struct GNS_ResolverHandle'
+ * @param addr one of the addresses of the host, NULL for the last address
+ * @param addrlen length of the address
+ */
+static void
+handle_dns_result (void *cls,
+ const struct sockaddr *addr,
+ socklen_t addrlen)
+{
+ struct GNS_ResolverHandle *rh = cls;
+ const struct sockaddr_in *sa4;
+ const struct sockaddr_in6 *sa6;
+
+ rh->std_resolve = NULL;
+ if (NULL == addr)
+ {
+ transmit_lookup_dns_result (rh);
+ return;
+ }
+ switch (addr->sa_family)
+ {
+ case AF_INET:
+ sa4 = (const struct sockaddr_in *) addr;
+ add_dns_result (rh,
+ 0 /* expiration time is unknown */,
+ GNUNET_DNSPARSER_TYPE_A,
+ sizeof (struct in_addr),
+ &sa4->sin_addr);
+ break;
+ case AF_INET6:
+ sa6 = (const struct sockaddr_in6 *) addr;
+ add_dns_result (rh,
+ 0 /* expiration time is unknown */,
+ GNUNET_DNSPARSER_TYPE_AAAA,
+ sizeof (struct in6_addr),
+ &sa6->sin6_addr);
+ break;
+ default:
+ GNUNET_break (0);
+ break;
+ }
+}
+
+
+/**
+ * Task scheduled to continue with the resolution process.
+ *
+ * @param cls the 'struct GNS_ResolverHandle' of the resolution
+ * @param tc task context
+ */
+static void
+recursive_resolution (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc);
+
+
+/**
+ * Function called with the result of a DNS resolution.
+ *
+ * @param cls the request handle of the resolution that
+ * we were attempting to make
+ * @param rs socket that received the response
+ * @param dns dns response, never NULL
+ * @param dns_len number of bytes in 'dns'
+ */
+static void
+dns_result_parser (void *cls,
+ struct GNUNET_DNSSTUB_RequestSocket *rs,
+ const struct GNUNET_TUN_DnsHeader *dns,
+ size_t dns_len)
+{
+ struct GNS_ResolverHandle *rh = cls;
+ struct GNUNET_DNSPARSER_Packet *p;
+
+ rh->dns_request = NULL;
+ GNUNET_SCHEDULER_cancel (rh->task_id);
+ rh->task_id = GNUNET_SCHEDULER_NO_TASK;
+ p = GNUNET_DNSPARSER_parse ((const char *) dns,
+ dns_len);
+ if (NULL == p)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Failed to parse DNS response\n"));
+ rh->proc (rh->proc_cls, 0, NULL);
+ GNS_resolver_lookup_cancel (rh);
+ return;
+ }
+ // FIXME:
+ // Check if the packet is the final answer, or
+ // just pointing us to another NS or another name (CNAME), or another domain (DNAME);
+ // then do the right thing (TM) -- possibly using "recursive_dns_resolution".
+ GNUNET_break (0);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("NOT IMPLEMENTED\n"));
+ rh->proc (rh->proc_cls, 0, NULL);
+ GNS_resolver_lookup_cancel (rh);
+
+
+ GNUNET_DNSPARSER_free_packet (p);
+}
+
+
+/**
+ * Perform recursive DNS resolution. Asks the given DNS resolver to
+ * resolve "rh->dns_name", possibly recursively proceeding following
+ * NS delegations, CNAMES, etc., until 'rh->loop_limiter' bounds us or
+ * we find the answer.
+ *
+ * @param rh resolution information
+ */
+static void
+recursive_dns_resolution (struct GNS_ResolverHandle *rh)
+{
+ struct AuthorityChain *ac;
+ socklen_t sa_len;
+ struct GNUNET_DNSPARSER_Query *query;
+ struct GNUNET_DNSPARSER_Packet *p;
+ char *dns_request;
+ size_t dns_request_length;
+
+ ac = rh->ac_tail;
+ GNUNET_assert (NULL != ac);
+ GNUNET_assert (GNUNET_NO == ac->gns_authority);
+ switch (((const struct sockaddr *) &ac->authority_info.dns_authority.dns_ip)->sa_family)
+ {
+ case AF_INET:
+ sa_len = sizeof (struct sockaddr_in);
+ break;
+ case AF_INET6:
+ sa_len = sizeof (struct sockaddr_in6);
+ break;
+ default:
+ GNUNET_break (0);
+ rh->proc (rh->proc_cls, 0, NULL);
+ GNS_resolver_lookup_cancel (rh);
+ return;
+ }
+ query = GNUNET_new (struct GNUNET_DNSPARSER_Query);
+ query->name = GNUNET_strdup (ac->label);
+ query->type = rh->record_type;
+ query->class = GNUNET_TUN_DNS_CLASS_INTERNET;
+ p = GNUNET_new (struct GNUNET_DNSPARSER_Packet);
+ p->queries = query;
+ p->num_queries = 1;
+ p->id = (uint16_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE,
+ UINT16_MAX);
+ p->flags.opcode = GNUNET_TUN_DNS_OPCODE_QUERY;
+ p->flags.recursion_desired = 1;
+ if (GNUNET_OK !=
+ GNUNET_DNSPARSER_pack (p, 1024, &dns_request, &dns_request_length))
+ {
+ GNUNET_break (0);
+ rh->proc (rh->proc_cls, 0, NULL);
+ GNS_resolver_lookup_cancel (rh);
+ }
+ else
+ {
+ rh->dns_request = GNUNET_DNSSTUB_resolve (dns_handle,
+ (const struct sockaddr *) &ac->authority_info.dns_authority.dns_ip,
+ sa_len,
+ dns_request,
+ dns_request_length,
+ &dns_result_parser,
+ rh);
+ rh->task_id = GNUNET_SCHEDULER_add_delayed (DNS_LOOKUP_TIMEOUT,
+ &fail_resolution,
+ rh);
+ }
+ GNUNET_free (dns_request);
+ GNUNET_DNSPARSER_free_packet (p);
+}
+
+
+/**
+ * Process a records that were decrypted from a block.
+ *
+ * @param cls closure with the 'struct GNS_ResolverHandle'
+ * @param rd_count number of entries in @a rd array
+ * @param rd array of records with data to store
+ */
+static void
+handle_gns_resolution_result (void *cls,
+ unsigned int rd_count,
+ const struct GNUNET_NAMESTORE_RecordData *rd)
+{
+ struct GNS_ResolverHandle *rh = cls;
+
+ // FIXME: not implemented
+ // if this was the last label, return 'rd' to application
+ // (possibly first checking about converting records
+ // to requested type, if possible).
+ // if not, look for PKEY, CNAME, DNAME or NS to extend
+ // auth chain and continue with recursion
+ GNUNET_break (0);
+ rh->proc (rh->proc_cls, 0, NULL);
+ GNS_resolver_lookup_cancel (rh);
+}
+
+
+/**
+ * Function called once the namestore has completed the request for
+ * caching a block.
+ *
+ * @param cls closure with the 'struct GNS_ResolverHandle'
+ * @param success #GNUNET_OK on success
+ * @param emsg error message
+ */
+static void
+namestore_cache_continuation (void *cls,
+ int32_t success,
+ const char *emsg)
+{
+ struct GNS_ResolverHandle *rh = cls;
+
+ rh->namestore_qe = NULL;
+ if (NULL != emsg)
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Failed to cache GNS resolution: %s\n"),
+ emsg);
+}
+
+
+/**
+ * Iterator called on each result obtained for a DHT
+ * operation that expects a reply
+ *
+ * @param cls closure with the 'struct GNS_ResolverHandle'
+ * @param exp when will this value expire
+ * @param key key of the result
+ * @param get_path peers on reply path (or NULL if not recorded)
+ * [0] = datastore's first neighbor, [length - 1] = local peer
+ * @param get_path_length number of entries in get_path
+ * @param put_path peers on the PUT path (or NULL if not recorded)
+ * [0] = origin, [length - 1] = datastore
+ * @param put_path_length number of entries in get_path
+ * @param type type of the result
+ * @param size number of bytes in data
+ * @param data pointer to the result data
+ */
+static void
+handle_dht_response (void *cls,
+ struct GNUNET_TIME_Absolute exp,
+ const struct GNUNET_HashCode * key,
+ const struct GNUNET_PeerIdentity *get_path,
+ unsigned int get_path_length,
+ const struct GNUNET_PeerIdentity *put_path,
+ unsigned int put_path_length,
+ enum GNUNET_BLOCK_Type type,
+ size_t size, const void *data)
+{
+ struct GNS_ResolverHandle *rh = cls;
+ struct AuthorityChain *ac = rh->ac_tail;
+ const struct GNUNET_NAMESTORE_Block *block;
+
+ GNUNET_DHT_get_stop (rh->get_handle);
+ rh->get_handle = NULL;
+ GNUNET_CONTAINER_heap_remove_node (rh->dht_heap_node);
+ rh->dht_heap_node = NULL;
+ if (size < sizeof (struct GNUNET_NAMESTORE_Block))
+ {
+ /* how did this pass DHT block validation!? */
+ GNUNET_break (0);
+ rh->proc (rh->proc_cls, 0, NULL);
+ GNS_resolver_lookup_cancel (rh);
+ return;
+ }
+ block = data;
+ if (size !=
+ ntohs (block->purpose.size) +
+ sizeof (struct GNUNET_CRYPTO_EccPublicKey) +
+ sizeof (struct GNUNET_CRYPTO_EccSignature))
+ {
+ /* how did this pass DHT block validation!? */
+ GNUNET_break (0);
+ rh->proc (rh->proc_cls, 0, NULL);
+ GNS_resolver_lookup_cancel (rh);
+ return;
+ }
+ if (GNUNET_OK !=
+ GNUNET_NAMESTORE_block_decrypt (block,
+ &ac->authority_info.gns_authority,
+ ac->label,
+ &handle_gns_resolution_result,
+ rh))
+ {
+ GNUNET_break_op (0); /* block was ill-formed */
+ rh->proc (rh->proc_cls, 0, NULL);
+ GNS_resolver_lookup_cancel (rh);
+ return;
+ }
+ /* Cache well-formed blocks */
+ rh->namestore_qe = GNUNET_NAMESTORE_block_cache (namestore_handle,
+ block,
+ &namestore_cache_continuation,
+ rh);
+}
+
+
+/**
+ * Process a record that was stored in the namestore.
+ *
+ * @param cls closure with the 'struct GNS_ResolverHandle'
+ * @param block block that was stored in the namestore
+ */
+static void
+handle_namestore_block_response (void *cls,
+ const struct GNUNET_NAMESTORE_Block *block)
+{
+ struct GNS_ResolverHandle *rh = cls;
+ struct GNS_ResolverHandle *rx;
+ struct AuthorityChain *ac = rh->ac_tail;
+ const char *label = ac->label;
+ const struct GNUNET_CRYPTO_EccPublicKey *auth = &ac->authority_info.gns_authority;
+ struct GNUNET_HashCode query;
+
+ GNUNET_NAMESTORE_query_from_public_key (auth,
+ label,
+ &query);
+ rh->namestore_qe = NULL;
+ if (NULL == block)
+ {
+ /* Namestore knows nothing; try DHT lookup */
+ rh->get_handle = GNUNET_DHT_get_start (dht_handle,
+ GNUNET_BLOCK_TYPE_GNS_NAMERECORD,
+ &query,
+ DHT_GNS_REPLICATION_LEVEL,
+ GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
+ NULL, 0,
+ &handle_dht_response, rh);
+ rh->dht_heap_node = GNUNET_CONTAINER_heap_insert (dht_lookup_heap,
+ rh,
+ GNUNET_TIME_absolute_get ().abs_value_us);
+ if (GNUNET_CONTAINER_heap_get_size (dht_lookup_heap) > max_allowed_background_queries)
+ {
+ /* fail longest-standing DHT request */
+ rx = GNUNET_CONTAINER_heap_peek (dht_lookup_heap);
+ rx->proc (rx->proc_cls, 0, NULL);
+ GNS_resolver_lookup_cancel (rx);
+ }
+ return;
+ }
+ if (GNUNET_OK !=
+ GNUNET_NAMESTORE_block_decrypt (block,
+ auth,
+ label,
+ &handle_gns_resolution_result,
+ rh))
+ {
+ GNUNET_break_op (0); /* block was ill-formed */
+ rh->proc (rh->proc_cls, 0, NULL);
+ GNS_resolver_lookup_cancel (rh);
+ return;
+ }
+}
+
+
+/**
+ * Lookup tail of our authority chain in the namestore.
+ *
+ * @param rh query we are processing
+ */
+static void
+recursive_gns_resolution_namestore (struct GNS_ResolverHandle *rh)
+{
+ struct AuthorityChain *ac = rh->ac_tail;
+ struct GNUNET_HashCode query;
+
+ GNUNET_NAMESTORE_query_from_public_key (&ac->authority_info.gns_authority,
+ ac->label,
+ &query);
+ rh->namestore_qe = GNUNET_NAMESTORE_lookup_block (namestore_handle,
+ &query,
+ &handle_namestore_block_response,
+ rh);
+}
+
+
+/**
+ * Task scheduled to continue with the resolution process.
+ *
+ * @param cls the 'struct GNS_ResolverHandle' of the resolution
+ * @param tc task context
+ */
+static void
+recursive_resolution (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ struct GNS_ResolverHandle *rh = cls;
+
+ rh->task_id = GNUNET_SCHEDULER_NO_TASK;
+ if (MAX_RECURSION < rh->loop_limiter++)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Encountered unbounded recursion resolving `%s'\n",
+ rh->name);
+ rh->proc (rh->proc_cls, 0, NULL);
+ GNS_resolver_lookup_cancel (rh);
+ return;
+ }
+ if (GNUNET_YES == rh->ac_tail->gns_authority)
+ recursive_gns_resolution_namestore (rh);
+ else
+ recursive_dns_resolution (rh);
+}
/**
int only_cached,
GNS_ResultProcessor proc, void *proc_cls)
{
- return NULL;
-#if 0
- struct ResolverHandle *rh;
- struct RecordLookupHandle* rlh;
- char string_hash[GNUNET_DNSPARSER_MAX_LABEL_LENGTH];
- char nzkey[GNUNET_DNSPARSER_MAX_LABEL_LENGTH];
- char* nzkey_ptr = nzkey;
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Starting resolution for `%s' (type=%d) with timeout %s!\n",
- name, record_type,
- GNUNET_STRINGS_relative_time_to_string (timeout, GNUNET_YES));
-
- if ((is_canonical ((char*)name) == GNUNET_YES) &&
- (strcmp(GNUNET_GNS_TLD, name) != 0))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "%s is canonical and not gnunet -> cannot resolve!\n", name);
- proc(cls, 0, NULL);
- return;
- }
-
- rlh = GNUNET_malloc (sizeof(struct RecordLookupHandle));
- rh = GNUNET_malloc (sizeof (struct ResolverHandle));
- rh->authority = zone;
- rh->id = rid_gen++;
- rh->proc_cls = rlh;
- rh->priv_key = key;
- rh->timeout = timeout;
- rh->private_local_zone = pzone;
+ struct GNS_ResolverHandle *rh;
+ struct AuthorityChain *ac;
+ char *x;
+ char *y;
+ char *pkey;
+
+ rh = GNUNET_new (struct GNS_ResolverHandle);
+ GNUNET_CONTAINER_DLL_insert (rlh_head,
+ rlh_tail,
+ rh);
+ rh->authority_zone = *zone;
+ rh->proc = proc;
+ rh->proc_cls = proc_cls;
rh->only_cached = only_cached;
-
- GNUNET_CONTAINER_DLL_insert (rlh_head, rlh_tail, rh);
-
- if (NULL == key)
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "No shorten key for resolution\n");
-
- if (timeout.rel_value_us != GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us)
- {
- /*
- * Set timeout for authority lookup phase to 1/2
- */
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Timeout for lookup set to %s/2\n",
- GNUNET_STRINGS_relative_time_to_string (rh->timeout, GNUNET_YES));
- rh->timeout_task = GNUNET_SCHEDULER_add_delayed (
- GNUNET_TIME_relative_divide(timeout, 2),
- &handle_lookup_timeout,
- rh);
- rh->timeout_cont = &dht_authority_lookup_timeout;
- rh->timeout_cont_cls = rh;
- }
- else
+ rh->record_type = record_type;
+ rh->name = GNUNET_strdup (name);
+ rh->name_resolution_pos = strlen (name);
+ if (NULL != shorten_key)
{
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "No timeout for query!\n");
- rh->timeout_task = GNUNET_SCHEDULER_NO_TASK;
+ rh->shorten_key = GNUNET_new (struct GNUNET_CRYPTO_EccPrivateKey);
+ *rh->shorten_key = *shorten_key;
}
-
- if (strcmp(GNUNET_GNS_TLD, name) == 0)
- {
- /**
- * Only '.gads' given
- */
- strcpy (rh->name, "\0");
- }
- else
- {
- if (is_zkey_tld(name) == GNUNET_YES)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "TLD is zkey\n");
- /**
- * This is a zkey tld
- * build hash and use as initial authority
- */
- memset(rh->name, 0,
- strlen(name)-strlen(GNUNET_GNS_TLD_ZKEY));
- memcpy(rh->name, name,
- strlen(name)-strlen(GNUNET_GNS_TLD_ZKEY) - 1);
- pop_tld (rh->name, string_hash);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "ZKEY is %s!\n", string_hash);
-
- GNUNET_STRINGS_utf8_toupper(string_hash, &nzkey_ptr);
-
- if (GNUNET_OK != GNUNET_CRYPTO_short_hash_from_string(nzkey,
- &rh->authority))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Cannot convert ZKEY `%s' to hash!\n", string_hash);
-
- if (GNUNET_SCHEDULER_NO_TASK != rh->timeout_task)
- GNUNET_SCHEDULER_cancel (rh->timeout_task);
- GNUNET_CONTAINER_DLL_remove (rlh_head, rlh_tail, rh);
- GNUNET_free (rh);
- GNUNET_free (rlh);
- proc (cls, 0, NULL);
- return;
- }
+ if ( ( (GNUNET_YES == is_canonical (name)) &&
+ (0 != strcmp (GNUNET_GNS_TLD, name)) ) ||
+ ( (GNUNET_YES != is_gnu_tld (name)) &&
+ (GNUNET_YES != is_zkey_tld (name)) ) )
+ {
+ /* use standard DNS lookup */
+ int af;
- }
- else if (is_gads_tld (name) == GNUNET_YES)
+ switch (record_type)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "TLD is gads\n");
- /**
- * Presumably GADS tld
- */
- memcpy (rh->name, name,
- strlen (name) - strlen(GNUNET_GNS_TLD) - 1);
- rh->name[strlen (name) - strlen(GNUNET_GNS_TLD) - 1] = '\0';
+ case GNUNET_DNSPARSER_TYPE_A:
+ af = AF_INET;
+ break;
+ case GNUNET_DNSPARSER_TYPE_AAAA:
+ af = AF_INET6;
+ break;
+ default:
+ af = AF_UNSPEC;
+ break;
}
- else
+ rh->std_resolve = GNUNET_RESOLVER_ip_get (name,
+ af,
+ DNS_LOOKUP_TIMEOUT,
+ &handle_dns_result,
+ rh);
+ return rh;
+ }
+ if (is_zkey_tld (name))
+ {
+ /* Name ends with ".zkey", try to replace authority zone with zkey
+ authority */
+ GNUNET_free (resolver_lookup_get_next_label (rh)); /* will return "zkey" */
+ x = resolver_lookup_get_next_label (rh); /* will return 'x' coordinate */
+ y = resolver_lookup_get_next_label (rh); /* will return 'y' coordinate */
+ GNUNET_asprintf (&pkey,
+ "%s%s",
+ x, y);
+ if ( (NULL == x) ||
+ (NULL == y) ||
+ (GNUNET_OK !=
+ GNUNET_CRYPTO_ecc_public_key_from_string (pkey,
+ strlen (pkey),
+ &rh->authority_zone)) )
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Not a GADS TLD: `%s'\n"),
- name);
- if (GNUNET_SCHEDULER_NO_TASK != rh->timeout_task)
- GNUNET_SCHEDULER_cancel (rh->timeout_task);
- GNUNET_CONTAINER_DLL_remove (rlh_head, rlh_tail, rh);
- GNUNET_free (rh);
- GNUNET_free (rlh);
- proc (cls, 0, NULL);
- return;
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Hostname `%s' is not well-formed, resolution fails\n"),
+ name);
+ rh->task_id = GNUNET_SCHEDULER_add_now (&fail_resolution, rh);
}
+ GNUNET_free_non_null (x);
+ GNUNET_free_non_null (y);
+ GNUNET_free (pkey);
}
-
- /**
- * Initialize authority chain
- */
- rh->authority_chain_head = GNUNET_malloc (sizeof(struct AuthorityChain));
- rh->authority_chain_tail = rh->authority_chain_head;
- rh->authority_chain_head->zone = rh->authority;
- strcpy (rh->authority_chain_head->name, "");
-
- /**
- * Copy original query into lookup handle
- */
- rlh->record_type = record_type;
- memset(rlh->name, 0, strlen(name) + 1);
- strcpy(rlh->name, name);
- rlh->proc = proc;
- rlh->proc_cls = cls;
-
- rh->proc = &handle_delegation_ns;
- resolve_delegation_ns (rh);
-#endif
+ else
+ {
+ /* Name ends with ".gnu", eat ".gnu" and continue with resolution */
+ GNUNET_free (resolver_lookup_get_next_label (rh));
+ }
+ ac = GNUNET_new (struct AuthorityChain);
+ ac->rh = rh;
+ ac->label = resolver_lookup_get_next_label (rh);
+ if (NULL == ac->label)
+ /* name was just "gnu", so we default to label '+' */
+ ac->label = GNUNET_strdup (GNUNET_GNS_MASTERZONE_STR);
+ ac->gns_authority = GNUNET_YES;
+ ac->authority_info.gns_authority = rh->authority_zone;
+ GNUNET_CONTAINER_DLL_insert_tail (rh->ac_head,
+ rh->ac_tail,
+ ac);
+ rh->task_id = GNUNET_SCHEDULER_add_now (&recursive_resolution,
+ rh);
+ return rh;
}
-
/**
* Cancel active resolution (i.e. client disconnected).
*
- * @param h resolution to abort
+ * @param rh resolution to abort
*/
void
-GNS_resolver_lookup_cancel (struct GNS_ResolverHandle *h)
+GNS_resolver_lookup_cancel (struct GNS_ResolverHandle *rh)
{
+ struct DnsResult *dr;
+ struct AuthorityChain *ac;
+
+ GNUNET_CONTAINER_DLL_remove (rlh_head,
+ rlh_tail,
+ rh);
+ while (NULL != (ac = rh->ac_head))
+ {
+ GNUNET_CONTAINER_DLL_remove (rh->ac_head,
+ rh->ac_tail,
+ ac);
+ GNUNET_free (ac->label);
+ GNUNET_free (ac);
+ }
+ if (GNUNET_SCHEDULER_NO_TASK != rh->task_id)
+ {
+ GNUNET_SCHEDULER_cancel (rh->task_id);
+ rh->task_id = GNUNET_SCHEDULER_NO_TASK;
+ }
+ if (NULL != rh->get_handle)
+ {
+ GNUNET_DHT_get_stop (rh->get_handle);
+ rh->get_handle = NULL;
+ }
+ if (NULL != rh->dht_heap_node)
+ {
+ GNUNET_CONTAINER_heap_remove_node (rh->dht_heap_node);
+ rh->dht_heap_node = NULL;
+ }
+ if (NULL != rh->dns_request)
+ {
+ GNUNET_DNSSTUB_resolve_cancel (rh->dns_request);
+ rh->dns_request = NULL;
+ }
+ if (NULL != rh->namestore_qe)
+ {
+ GNUNET_NAMESTORE_cancel (rh->namestore_qe);
+ rh->namestore_qe = NULL;
+ }
+ if (NULL != rh->std_resolve)
+ {
+ GNUNET_RESOLVER_request_cancel (rh->std_resolve);
+ rh->std_resolve = NULL;
+ }
+ while (NULL != (dr = rh->dns_result_head))
+ {
+ GNUNET_CONTAINER_DLL_remove (rh->dns_result_head,
+ rh->dns_result_tail,
+ dr);
+ GNUNET_free (dr);
+ }
+ GNUNET_free_non_null (rh->shorten_key);
+ GNUNET_free (rh->name);
+ GNUNET_free (rh);
}
* Initialize the resolver
*
* @param nh the namestore handle
- * @param dh the dht handle
+ * @param dht the dht handle
* @param c configuration handle
* @param max_bg_queries maximum number of parallel background queries in dht
- * @param ignore_pending ignore records that still require user confirmation
- * on lookup
*/
void
GNS_resolver_init (struct GNUNET_NAMESTORE_Handle *nh,
- struct GNUNET_DHT_Handle *dh,
+ struct GNUNET_DHT_Handle *dht,
const struct GNUNET_CONFIGURATION_Handle *c,
unsigned long long max_bg_queries)
{
cfg = c;
namestore_handle = nh;
- dht_handle = dh;
+ dht_handle = dht;
dht_lookup_heap =
GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
max_allowed_background_queries = max_bg_queries;
void
GNS_resolver_done ()
{
+ struct GNS_ResolverHandle *rh;
+
+ /* abort active resolutions */
+ while (NULL != (rh = rlh_head))
+ {
+ rh->proc (rh->proc_cls, 0, NULL);
+ GNS_resolver_lookup_cancel (rh);
+ }
+ /* abort active shorten operations */
while (NULL != gph_head)
free_get_pseu_authority_handle (gph_head);
GNUNET_CONTAINER_heap_destroy (dht_lookup_heap);