-use configuration option for reset of zone_publish_time_window, also frequency shoul...
[oweals/gnunet.git] / src / gns / gnunet-service-gns_resolver.h
index a7f86a2d786952a790c41bd132f7c46b3b3b02b6..7728c397db35bd0469524d7c4ee691dd260f7e42 100644 (file)
+/*
+     This file is part of GNUnet.
+     (C) 2009-2013 Christian Grothoff (and other contributing authors)
+
+     GNUnet is free software; you can redistribute it and/or modify
+     it under the terms of the GNU General Public License as published
+     by the Free Software Foundation; either version 3, or (at your
+     option) any later version.
+
+     GNUnet is distributed in the hope that it will be useful, but
+     WITHOUT ANY WARRANTY; without even the implied warranty of
+     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+     General Public License for more details.
+
+     You should have received a copy of the GNU General Public License
+     along with GNUnet; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+     Boston, MA 02111-1307, USA.
+*/
+/**
+ * @file gns/gnunet-service-gns_resolver.h
+ * @brief GNUnet GNS service
+ * @author Martin Schanzenbach
+ */
 #ifndef GNS_RESOLVER_H
 #define GNS_RESOLVER_H
-
 #include "gns.h"
 #include "gnunet_dht_service.h"
-
-#define DHT_OPERATION_TIMEOUT  GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3)
-#define DHT_LOOKUP_TIMEOUT DHT_OPERATION_TIMEOUT
-#define DHT_GNS_REPLICATION_LEVEL 5
-#define MAX_DNS_LABEL_LENGTH 63
-
-/*
- * DLL to hold the authority chain
- * we had to pass in the resolution process
- */
-struct AuthorityChain
-{
-  struct AuthorityChain *prev;
-
-  struct AuthorityChain *next;
-  
-  /* the zone hash of the authority */
-  GNUNET_HashCode zone;
-
-  /* (local) name of the authority */
-  char* name;
-
-  /* was the ns entry fresh */
-  int fresh;
-};
-
-/* handle to a resolution process */
-struct ResolverHandle;
-
-
-/**
- * processor for a resultion result
- *
- * @param cls the closure
- * @param rh the resolution handle
- * @param rd_count number of results
- * @pram rd resukt data
- */
-typedef void (*RecordLookupProcessor) (void *cls,
-                                  uint32_t rd_count,
-                                  const struct GNUNET_NAMESTORE_RecordData *rd);
-
-
-/**
- * processor for a shorten result
- *
- * @param cls the closure
- * @param name shortened name
- */
-typedef void (*ShortenResultProcessor) (void *cls, const char* name);
-
-
-/**
- * processor for an authority result
- *
- * @param cls the closure
- * @param name name
- */
-typedef void (*GetAuthorityResultProcessor) (void *cls, const char* name);
+#include "gnunet_namecache_service.h"
 
 /**
- * processor for a resultion result
+ * Initialize the resolver subsystem.
+ * MUST be called before #GNS_resolver_lookup.
  *
- * @param cls the closure
- * @param rh the resolution handle
- * @param rd_count number of results
- * @param rd result data
+ * @param nh handle to the namestore
+ * @param nc the namecache handle
+ * @param dht handle to the dht
+ * @param c configuration handle
+ * @param max_bg_queries maximum amount of background queries
  */
-typedef void (*ResolutionResultProcessor) (void *cls,
-                                  struct ResolverHandle *rh,
-                                  uint32_t rd_count,
-                                  const struct GNUNET_NAMESTORE_RecordData *rd);
-
+void
+GNS_resolver_init (struct GNUNET_NAMESTORE_Handle *nh,
+                   struct GNUNET_NAMECACHE_Handle *nc,
+                  struct GNUNET_DHT_Handle *dht,
+                  const struct GNUNET_CONFIGURATION_Handle *c,
+                  unsigned long long max_bg_queries);
 
-/**
- * Resoltion status indicator
- * EXISTS: the name to lookup exists
- * EXPIRED: the name in the record expired
- */
-enum ResolutionStatus
-{
-  EXISTS = 1,
-  EXPIRED = 2
-};
 
 /**
- * Handle to a currenty pending resolution
+ * Cleanup resolver: Terminate pending lookups
  */
-struct ResolverHandle
-{
-  /* The name to resolve */
-  char *name;
-
-  /* has this query been answered? how many matches */
-  int answered;
-
-  /* the authoritative zone to query */
-  GNUNET_HashCode authority;
-
-  /* the name of the authoritative zone to query */
-  char *authority_name;
-
-  /**
-   * we have an authority in namestore that
-   * may be able to resolve
-   */
-  int authority_found;
-
-  /* a handle for dht lookups. should be NULL if no lookups are in progress */
-  struct GNUNET_DHT_GetHandle *get_handle;
-
-  /* timeout task for dht lookups */
-  GNUNET_SCHEDULER_TaskIdentifier dht_timeout_task;
-
-  /* called when resolution phase finishes */
-  ResolutionResultProcessor proc;
-  
-  /* closure passed to proc */
-  void* proc_cls;
-
-  /* DLL to store the authority chain */
-  struct AuthorityChain *authority_chain_head;
-
-  /* DLL to store the authority chain */
-  struct AuthorityChain *authority_chain_tail;
-  
-  /* status of the resolution result */
-  enum ResolutionStatus status;
-
-  struct GNUNET_CRYPTO_RsaPrivateKey *priv_key;
-
-};
+void
+GNS_resolver_done (void);
 
 
 /**
- * Handle to a record lookup
+ * Handle for an active request.
  */
-struct RecordLookupHandle
-{
-  /* the record type to look up */
-  enum GNUNET_GNS_RecordType record_type;
-
-  /* the name to look up */
-  char *name;
-
-  /* Method to call on record resolution result */
-  RecordLookupProcessor proc;
-
-  /* closure to pass to proc */
-  void* proc_cls;
-
-};
+struct GNS_ResolverHandle;
 
 
 /**
- * Handle to a shorten context
+ * Function called with results for a GNS resolution.
+ *
+ * @param cls closure
+ * @param rd_count number of records in @a rd
+ * @param rd records returned for the lookup
  */
-struct NameShortenHandle
-{
-
-
-  /* Method to call on shorten result */
-  ShortenResultProcessor proc;
+typedef void (*GNS_ResultProcessor)(void *cls,
+                                   uint32_t rd_count,
+                                   const struct GNUNET_GNSRECORD_Data *rd);
 
-  /* closure to pass to proc */
-  void* proc_cls;
-
-};
 
 /**
- * Handle to a get authority context
+ * Lookup of a record in a specific zone
+ * calls RecordLookupProcessor on result or timeout
+ *
+ * @param zone the zone to perform the lookup in
+ * @param record_type the record type to look up
+ * @param name the name to look up
+ * @param shorten_key optional private key for authority caching, can be NULL
+ * @param only_cached GNUNET_NO to only check locally not DHT for performance
+ * @param proc the processor to call
+ * @param proc_cls the closure to pass to @a proc
+ * @return handle to cancel operation
  */
-struct GetNameAuthorityHandle
-{
-  
-  /* the name to look up authority for */
-  char* name;
-  
-  /* Method to call on result */
-  GetAuthorityResultProcessor proc;
+struct GNS_ResolverHandle *
+GNS_resolver_lookup (const struct GNUNET_CRYPTO_EcdsaPublicKey *zone,
+                    uint32_t record_type,
+                    const char *name,
+                    const struct GNUNET_CRYPTO_EcdsaPrivateKey *shorten_key,
+                    int only_cached,
+                    GNS_ResultProcessor proc,
+                    void *proc_cls);
 
-  /* closure to pass to proc */
-  void* proc_cls;
-
-};
 
 /**
- * Handle to a pseu lookup
+ * Cancel active resolution (i.e. client disconnected).
+ *
+ * @param rh resolution to abort
  */
-struct GetPseuAuthorityHandle
-{
-  /* the name given from delegation */
-  char* name;
-
-  /* name to store the pseu under */
-  char* new_name;
-  
-  /* the zone of discovered authority */
-  GNUNET_HashCode new_zone;
-
-  /* the zone of our authority */
-  GNUNET_HashCode zone;
+void
+GNS_resolver_lookup_cancel (struct GNS_ResolverHandle *rh);
 
-  /* the private key of the zone to store the pseu in */
-  struct GNUNET_CRYPTO_RsaPrivateKey *key;
 
-  /* a handle for dht lookups. should be NULL if no lookups are in progress */
-  struct GNUNET_DHT_GetHandle *get_handle;
 
-  /* timeout task for dht lookups */
-  GNUNET_SCHEDULER_TaskIdentifier dht_timeout;
-};
 
 /**
- * Initialize the resolver
+ * Generic function to check for TLDs.  Checks if "name" ends in ".tld"
  *
- * @param nh handle to the namestore
- * @param dh handle to the dht
- * @returns GNUNET_OK on success
+ * @param name the name to check
+ * @param tld the tld to check
+ * @return #GNUNET_YES or #GNUNET_NO
  */
 int
-gns_resolver_init(struct GNUNET_NAMESTORE_Handle *nh,
-                  struct GNUNET_DHT_Handle *dh);
+is_tld (const char *name,
+       const char *tld);
 
-/**
- * Lookup of a record in a specific zone
- * calls lookup result processor on result
- *
- * @param zone the root zone
- * @param record_type the record type to look up
- * @param name the name to look up
- * @param key optional private key for authority caching
- * @param proc the processor to call
- * @param cls the closure to pass to proc
- */
-void
-gns_resolver_lookup_record(GNUNET_HashCode zone,
-                           uint32_t record_type,
-                           const char* name,
-                           struct GNUNET_CRYPTO_RsaPrivateKey *key,
-                           RecordLookupProcessor proc,
-                           void* cls);
 
-void
-gns_resolver_shorten_name(GNUNET_HashCode zone,
-                          const char* name,
-                          ShortenResultProcessor proc,
-                          void* cls);
 
 /**
- * Tries to resolve the authority for name
- * in our namestore
- *
- * @param zone the root zone to look up for
- * @param name the name to lookup up
- * @param proc the processor to call when finished
- * @param cls the closure to pass to the processor
+ * Checks for gnu/zkey
  */
-void
-gns_resolver_get_authority(GNUNET_HashCode zone,
-                           const char* name,
-                           GetAuthorityResultProcessor proc,
-                           void* cls);
+#define is_gnu_tld(name) is_tld(name, GNUNET_GNS_TLD)
+#define is_zkey_tld(name) is_tld(name, GNUNET_GNS_TLD_ZKEY)
+
 
 #endif