-fix for #688590: allow user to specify how to install nsslibs
[oweals/gnunet.git] / src / gns / gnunet-service-gns_resolver.h
index 17d0a7221477feddade87d5c12ede8e8339cab71..b24fd1274613095a8bc65e498cf50f663f6fc577 100644 (file)
@@ -4,13 +4,14 @@
 #include "gns.h"
 #include "gnunet_dht_service.h"
 
-#define DHT_OPERATION_TIMEOUT  GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3)
+#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
 
 /*
  * DLL to hold the authority chain
@@ -35,10 +36,6 @@ struct AuthorityChain
 /* handle to a resolution process */
 struct ResolverHandle;
 
-/**
- * continuation called when cleanup of resolver finishes
- */
-typedef void (*ResolverCleanupContinuation) (void);
 
 /**
  * processor for a record lookup result
@@ -88,12 +85,22 @@ typedef void (*ResolutionResultProcessor) (void *cls,
  * RSL_RECORD_EXISTS: the name to lookup exists
  * RSL_RECORD_EXPIRED: the name in the record expired
  * RSL_TIMED_OUT: resolution timed out
+ * RSL_DELEGATE_VPN: Found VPN delegation
+ * RSL_DELEGATE_NS: Found NS delegation
+ * RSL_DELEGATE_PKEY: Found PKEY delegation
+ * RSL_CNAME_FOUND: Found CNAME record
+ * RSL_PKEY_REVOKED: Found PKEY has been revoked
  */
 enum ResolutionStatus
 {
   RSL_RECORD_EXISTS = 1,
   RSL_RECORD_EXPIRED = 2,
-  RSL_TIMED_OUT = 4
+  RSL_TIMED_OUT = 4,
+  RSL_DELEGATE_VPN = 8,
+  RSL_DELEGATE_NS = 16,
+  RSL_DELEGATE_PKEY = 32,
+  RSL_CNAME_FOUND = 64,
+  RSL_PKEY_REVOKED = 128
 };
 
 /**
@@ -108,12 +115,28 @@ enum ResolutionStatus
  */
 struct ResolverHandle
 {
+
+  /* DLL */
+  struct ResolverHandle *next;
+
+  /* DLL */
+  struct ResolverHandle *prev;
+
+  /* Last record data found */
+  struct GNUNET_NAMESTORE_RecordData rd;
+
+  /* Number of last record data found */
+  unsigned int rd_count;
+
   /* The name to resolve */
   char name[MAX_DNS_NAME_LENGTH];
 
   /* has this query been answered? how many matches */
   int answered;
 
+  /* Use only cache */
+  int only_cached;
+
   /* the authoritative zone to query */
   struct GNUNET_CRYPTO_ShortHashCode authority;
 
@@ -126,6 +149,33 @@ struct ResolverHandle
   /* timeout set for this lookup task */
   struct GNUNET_TIME_Relative timeout;
 
+  /* a handle to a vpn request */
+  struct GNUNET_VPN_RedirectionRequest *vpn_handle;
+
+  /* a socket for a dns request */
+  struct GNUNET_NETWORK_Handle *dns_sock;
+
+  /* a synthesized dns name */
+  char dns_name[MAX_DNS_NAME_LENGTH];
+
+  /* the authoritative dns zone */
+  char dns_zone[MAX_DNS_NAME_LENGTH];
+
+  /* the address of the DNS server FIXME not needed? */
+  struct sockaddr_in dns_addr;
+
+  /* handle to the local stub resolver request */
+  struct GNUNET_RESOLVER_RequestHandle *dns_resolver_handle;
+
+  /* select task for DNS */
+  GNUNET_SCHEDULER_TaskIdentifier dns_read_task;
+
+  /* pointer to raw dns query payload FIXME needs to be freed/NULL */
+  char *dns_raw_packet;
+
+  /* size of the raw dns query */
+  size_t dns_raw_packet_size;
+
   /* timeout task for the lookup */
   GNUNET_SCHEDULER_TaskIdentifier timeout_task;
 
@@ -150,6 +200,9 @@ struct ResolverHandle
   /* status of the resolution result */
   enum ResolutionStatus status;
 
+  /* The provate local zone of this request */
+  struct GNUNET_CRYPTO_ShortHashCode private_local_zone;
+
   /**
    * private key of an/our authoritative zone
    * can be NULL but automatical PKEY import will not work
@@ -167,6 +220,11 @@ struct ResolverHandle
    */
   unsigned long long id;
 
+  /**
+   * Pending Namestore task
+   */
+  struct GNUNET_NAMESTORE_QueueEntry *namestore_task;
+
 };
 
 
@@ -200,6 +258,25 @@ struct NameShortenHandle
 
   /* closure to pass to proc */
   void* proc_cls;
+
+  /* result of shorten */
+  char result[MAX_DNS_NAME_LENGTH];
+
+  /* root zone */
+  struct GNUNET_CRYPTO_ShortHashCode *root_zone;
+
+  /* private zone */
+  struct GNUNET_CRYPTO_ShortHashCode *private_zone;
+
+  /* name of private zone */
+  char private_zone_name[MAX_DNS_LABEL_LENGTH];
+
+  /* shorten zone */
+  struct GNUNET_CRYPTO_ShortHashCode *shorten_zone;
+
+  /* name of shorten zone */
+  char shorten_zone_name[MAX_DNS_LABEL_LENGTH];
+
 };
 
 /**
@@ -209,6 +286,9 @@ struct GetNameAuthorityHandle
 {
   /* the name to look up authority for */
   char name[MAX_DNS_NAME_LENGTH];
+
+  /* the result */
+  char result[MAX_DNS_NAME_LENGTH];
   
   /* Method to call on result */
   GetAuthorityResultProcessor proc;
@@ -222,17 +302,20 @@ struct GetNameAuthorityHandle
  */
 struct GetPseuAuthorityHandle
 {
-  /* the name given from delegation */
+  /* DLL */
+  struct GetPseuAuthorityHandle *next;
+
+  /* DLL */
+  struct GetPseuAuthorityHandle *prev;
+
+  /* the name to store the zone under */
   char name[MAX_DNS_LABEL_LENGTH];
 
-  /* name to store the pseu under */
-  char new_name[MAX_DNS_LABEL_LENGTH];
+  /* test name to store the zone under */
+  char test_name[MAX_DNS_LABEL_LENGTH];
   
-  /* the zone of discovered authority */
-  struct GNUNET_CRYPTO_ShortHashCode new_zone;
-
   /* the zone of our authority */
-  struct GNUNET_CRYPTO_ShortHashCode zone;
+  struct GNUNET_CRYPTO_ShortHashCode our_zone;
 
   /* the private key of the zone to store the pseu in */
   struct GNUNET_CRYPTO_RsaPrivateKey *key;
@@ -242,6 +325,24 @@ struct GetPseuAuthorityHandle
 
   /* timeout task for lookup */
   GNUNET_SCHEDULER_TaskIdentifier timeout;
+
+  /* Authority to shorten */
+  struct AuthorityChain *auth;
+
+  /* handle to namestore request */
+  struct GNUNET_NAMESTORE_QueueEntry* namestore_task;
+};
+
+/**
+ * Namestore queue entries in background
+ */
+struct NamestoreBGTask
+{
+  /* node in heap */
+  struct GNUNET_CONTAINER_HeapNode *node;
+
+  /* queue entry */
+  struct GNUNET_NAMESTORE_QueueEntry *qe;
 };
 
 /**
@@ -251,6 +352,7 @@ struct GetPseuAuthorityHandle
  * @param nh handle to the namestore
  * @param dh handle to the dht
  * @param lz the local zone
+ * @param c configuration handle
  * @param max_bg_queries maximum amount of background queries
  * @param ignore_pending ignore records that still require user confirmation
  *        on lookup
@@ -260,35 +362,38 @@ int
 gns_resolver_init(struct GNUNET_NAMESTORE_Handle *nh,
                   struct GNUNET_DHT_Handle *dh,
                   struct GNUNET_CRYPTO_ShortHashCode lz,
+                  const struct GNUNET_CONFIGURATION_Handle *c,
                   unsigned long long max_bg_queries,
                   int ignore_pending);
 
 /**
  * Cleanup resolver: Terminate pending lookups
- * 
- * @param cont continuation to call when finished
  */
 void
-gns_resolver_cleanup(ResolverCleanupContinuation cont);
+gns_resolver_cleanup(void);
 
 /**
  * Lookup of a record in a specific zone
  * calls RecordLookupProcessor on result or timeout
  *
  * @param zone the root zone
+ * @param pzone the private local 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 timeout timeout for the resolution
+ * @param only_cached GNUNET_NO to only check locally not DHT for performance
  * @param proc the processor to call
  * @param cls the closure to pass to proc
  */
 void
 gns_resolver_lookup_record(struct GNUNET_CRYPTO_ShortHashCode zone,
+                           struct GNUNET_CRYPTO_ShortHashCode pzone,
                            uint32_t record_type,
                            const char* name,
                            struct GNUNET_CRYPTO_RsaPrivateKey *key,
                            struct GNUNET_TIME_Relative timeout,
+                           int only_cached,
                            RecordLookupProcessor proc,
                            void* cls);
 
@@ -299,16 +404,22 @@ gns_resolver_lookup_record(struct GNUNET_CRYPTO_ShortHashCode zone,
  * There is no guarantee that the shortened name will
  * actually be canonical/short etc.
  *
- * @param zone the zone to perform the operation in
+ * @param zone the root zone to use
+ * @param pzone the private zone to use
+ * @param szone the shorten zone to use
  * @param name name to shorten
- * @param key optional private key for background lookups and PSEU import
+ * @param private_zone_name name of the private zone
+ * @param shorten_zone_name name of the shorten zone
  * @param proc the processor to call on shorten result
  * @param proc_cls the closure to pass to proc
  */
 void
-gns_resolver_shorten_name(struct GNUNET_CRYPTO_ShortHashCode zone,
+gns_resolver_shorten_name(struct GNUNET_CRYPTO_ShortHashCode *zone,
+                          struct GNUNET_CRYPTO_ShortHashCode *pzone,
+                          struct GNUNET_CRYPTO_ShortHashCode *szone,
                           const char* name,
-                          struct GNUNET_CRYPTO_RsaPrivateKey *key,
+                          const char* private_zone_name,
+                          const char* shorten_zone_name,
                           ShortenResultProcessor proc,
                           void* proc_cls);
 
@@ -317,12 +428,14 @@ gns_resolver_shorten_name(struct GNUNET_CRYPTO_ShortHashCode zone,
  * in our namestore
  *
  * @param zone the root zone to look up for
+ * @param pzone the private local zone
  * @param name the name to lookup up
  * @param proc the processor to call when finished
  * @param proc_cls the closure to pass to the processor
  */
 void
 gns_resolver_get_authority(struct GNUNET_CRYPTO_ShortHashCode zone,
+                           struct GNUNET_CRYPTO_ShortHashCode pzone,
                            const char* name,
                            GetAuthorityResultProcessor proc,
                            void* proc_cls);