/*
This file is part of GNUnet
- Copyright (C) 2012-2013 GNUnet e.V.
+ Copyright (C) 2012-2020 GNUnet e.V.
GNUnet is free software: you can redistribute it and/or modify it
under the terms of the GNU Affero General Public License as published
int16_t options GNUNET_PACKED;
/**
- * Always 0.
+ * Recursion depth limit, i.e. how many more
+ * GNS zones may be traversed during the resolution
+ * of this name.
*/
- int16_t reserved GNUNET_PACKED;
+ uint16_t recursion_depth_limit GNUNET_PACKED;
/**
* the type of record to look up
/*
This file is part of GNUnet.
- Copyright (C) 2009-2013, 2016, 2018 GNUnet e.V.
+ Copyright (C) 2009-2020 GNUnet e.V.
GNUnet is free software: you can redistribute it and/or modify it
under the terms of the GNU Affero General Public License as published
#define LOG(kind, ...) GNUNET_log_from (kind, "gns-api", __VA_ARGS__)
+/**
+ * Default recursion depth limit to apply if
+ * the application does not specify any.
+ */
+#define DEFAULT_LIMIT 128
+
/**
* Handle to a lookup request
*/
*
* @param handle handle to the GNS service
* @param name the name to look up (in UTF-8 encoding)
- * @param zone the zone to start the resolution in
- * @param type the record type to look up
+ * @param zone zone to look in
+ * @param type the GNS record type to look for
* @param options local options for the lookup
- * @param proc processor to call on result
+ * @param recursion_depth_limit maximum number of zones
+ * that the lookup may (still) traverse
+ * @param proc function to call on result
* @param proc_cls closure for @a proc
- * @return handle to the get request
+ * @return handle to the queued request
*/
-struct GNUNET_GNS_LookupRequest*
-GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle,
- const char *name,
- const struct GNUNET_CRYPTO_EcdsaPublicKey *zone,
- uint32_t type,
- enum GNUNET_GNS_LocalOptions options,
- GNUNET_GNS_LookupResultProcessor proc,
- void *proc_cls)
+struct GNUNET_GNS_LookupRequest *
+GNUNET_GNS_lookup_limited (struct GNUNET_GNS_Handle *handle,
+ const char *name,
+ const struct GNUNET_CRYPTO_EcdsaPublicKey *zone,
+ uint32_t type,
+ enum GNUNET_GNS_LocalOptions options,
+ uint16_t recursion_depth_limit,
+ GNUNET_GNS_LookupResultProcessor proc,
+ void *proc_cls)
{
/* IPC to shorten gns names, return shorten_handle */
struct LookupMessage *lookup_msg;
GNUNET_MESSAGE_TYPE_GNS_LOOKUP);
lookup_msg->id = htonl (lr->r_id);
lookup_msg->options = htons ((uint16_t) options);
+ lookup_msg->recursion_depth_limit
+ = htons (recursion_depth_limit);
lookup_msg->zone = *zone;
lookup_msg->type = htonl (type);
GNUNET_memcpy (&lookup_msg[1],
}
+/**
+ * Perform an asynchronous lookup operation on the GNS.
+ *
+ * @param handle handle to the GNS service
+ * @param name the name to look up (in UTF-8 encoding)
+ * @param zone the zone to start the resolution in
+ * @param type the record type to look up
+ * @param options local options for the lookup
+ * @param proc processor to call on result
+ * @param proc_cls closure for @a proc
+ * @return handle to the get request
+ */
+struct GNUNET_GNS_LookupRequest*
+GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle,
+ const char *name,
+ const struct GNUNET_CRYPTO_EcdsaPublicKey *zone,
+ uint32_t type,
+ enum GNUNET_GNS_LocalOptions options,
+ GNUNET_GNS_LookupResultProcessor proc,
+ void *proc_cls)
+{
+ return GNUNET_GNS_lookup_limited (handle,
+ name,
+ zone,
+ type,
+ options,
+ DEFAULT_LIMIT,
+ proc,
+ proc_cls);
+}
+
/* end of gns_api.c */
name,
(enum GNUNET_GNS_LocalOptions) ntohs (
sh_msg->options),
+ ntohs (sh_msg->recursion_depth_limit),
&send_lookup_response, clh);
GNUNET_STATISTICS_update (statistics,
"Lookup attempts",
#include "gns.h"
+/**
+ * How deep do we allow recursions to go before we abort?
+ */
+#define MAX_RECURSION 256
+
+
/**
* Handle to a DNS intercepted
* reslution request
p->queries[0].type,
p->queries[0].name,
GNUNET_NO,
+ MAX_RECURSION,
&reply_to_dns, ilh);
return;
}
*/
#define DHT_GNS_REPLICATION_LEVEL 10
-/**
- * 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
/**
* closure passed to @e proc
*/
- void*proc_cls;
+ void *proc_cls;
/**
* Handle for DHT lookups. should be NULL if no lookups are in progress
struct DnsResult *dns_result_tail;
/**
- * Current offset in 'name' where we are resolving.
+ * Current offset in @e name where we are resolving.
*/
size_t name_resolution_pos;
/**
* We increment the loop limiter for each step in a recursive
- * resolution. If it passes our threshold (i.e. due to
+ * resolution. If it passes our @e loop_threshold (i.e. due to
* self-recursion in the resolution, i.e CNAME fun), we stop.
*/
unsigned int loop_limiter;
+ /**
+ * Maximum value of @e loop_limiter allowed by client.
+ */
+ unsigned int loop_threshold;
+
/**
* 16 bit random ID we used in the @e dns_request.
*/
gp->rh->record_type = GNUNET_GNSRECORD_TYPE_ANY;
gp->rh->options = GNUNET_GNS_LO_DEFAULT;
gp->rh->loop_limiter = rh->loop_limiter + 1;
+ gp->rh->loop_threshold = rh->loop_threshold;
gp->rh->task_id
= GNUNET_SCHEDULER_add_now (&start_resolver_lookup,
gp->rh);
struct GNS_ResolverHandle *rh = cls;
rh->task_id = NULL;
- if (MAX_RECURSION < rh->loop_limiter++)
+ if (rh->loop_threshold < rh->loop_limiter++)
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"Encountered unbounded recursion resolving `%s'\n",
* @param record_type the record type to look up
* @param name the name to look up
* @param options local options to control local lookup
+ * @param recursion_depth_limit how many zones to traverse
+ * at most
* @param proc the processor to call on result
* @param proc_cls the closure to pass to @a proc
* @return handle to cancel operation
uint32_t record_type,
const char *name,
enum GNUNET_GNS_LocalOptions options,
+ uint16_t recursion_depth_limit,
GNS_ResultProcessor proc,
void *proc_cls)
{
rh->record_type = record_type;
rh->name = GNUNET_strdup (name);
rh->name_resolution_pos = strlen (name);
+ rh->loop_threshold = recursion_depth_limit;
rh->task_id = GNUNET_SCHEDULER_add_now (&start_resolver_lookup,
rh);
return rh;
/*
This file is part of GNUnet.
- Copyright (C) 2009-2013 GNUnet e.V.
+ Copyright (C) 2009-2020 GNUnet e.V.
GNUnet is free software: you can redistribute it and/or modify it
under the terms of the GNU Affero General Public License as published
* @param record_type the record type to look up
* @param name the name to look up
* @param options options set to control local lookup
+ * @param recursion_depth_limit how many zones to traverse
+ * at most
* @param proc the processor to call
* @param proc_cls the closure to pass to @a proc
* @return handle to cancel operation
uint32_t record_type,
const char *name,
enum GNUNET_GNS_LocalOptions options,
+ uint16_t recursion_depth_limit,
GNS_ResultProcessor proc,
void *proc_cls);
void *proc_cls);
+/**
+ * Perform an asynchronous lookup operation on the GNS.
+ *
+ * @param handle handle to the GNS service
+ * @param name the name to look up (in UTF-8 encoding)
+ * @param zone zone to look in
+ * @param type the GNS record type to look for
+ * @param options local options for the lookup
+ * @param recursion_depth_limit maximum number of zones
+ * that the lookup may (still) traverse
+ * @param proc function to call on result
+ * @param proc_cls closure for @a proc
+ * @return handle to the queued request
+ */
+struct GNUNET_GNS_LookupRequest *
+GNUNET_GNS_lookup_limited (struct GNUNET_GNS_Handle *handle,
+ const char *name,
+ const struct GNUNET_CRYPTO_EcdsaPublicKey *zone,
+ uint32_t type,
+ enum GNUNET_GNS_LocalOptions options,
+ uint16_t recursion_depth_limit,
+ GNUNET_GNS_LookupResultProcessor proc,
+ void *proc_cls);
+
+
/**
* Cancel pending lookup request
*