-fixes
[oweals/gnunet.git] / src / gns / gnunet-service-gns_interceptor.c
index 7f34c93cec488fab7927dd98cc975eec890a7330..b3ecdfdf9ef3e489c68e3b3ed037f9b551753482 100644 (file)
@@ -20,7 +20,7 @@
 
 /**
  *
- * @file gns/gns_interceptor.c
+ * @file gns/gnunet-service-gns_interceptor.c
  * @brief GNUnet GNS interceptor logic
  * @author Martin Schanzenbach
  */
@@ -59,18 +59,22 @@ static struct GNUNET_DNS_Handle *dns_handle;
 /**
  * The root zone for this interceptor
  */
-static GNUNET_HashCode our_zone;
+static struct GNUNET_CRYPTO_ShortHashCode our_zone;
 
 /**
  * Our priv key
  */
 static struct GNUNET_CRYPTO_RsaPrivateKey *our_key;
 
+/**
+ * Default timeout
+ */
+static struct GNUNET_TIME_Relative default_lookup_timeout;
+
 /**
  * Reply to dns request with the result from our lookup.
  *
  * @param cls the closure to the request (an InterceptLookupHandle)
- * @param rh the request handle of the lookup
  * @param rd_count the number of records to return
  * @param rd the record data
  */
@@ -241,6 +245,7 @@ start_resolution_for_dns(struct GNUNET_DNS_RequestHandle *request,
   /* Start resolution in our zone */
   gns_resolver_lookup_record(our_zone, q->type, q->name,
                              our_key,
+                             default_lookup_timeout,
                              &reply_to_dns, ilh);
 }
 
@@ -309,7 +314,8 @@ handle_dns_request(void *cls,
    */
   
   if ((is_gnunet_tld(p->queries[0].name) == GNUNET_YES) ||
-      (is_zkey_tld(p->queries[0].name) == GNUNET_YES))
+      (is_zkey_tld(p->queries[0].name) == GNUNET_YES) ||
+      (strcmp(p->queries[0].name, GNUNET_GNS_TLD) == 0))
   {
     start_resolution_for_dns(rh, p, p->queries);
   }
@@ -331,15 +337,17 @@ handle_dns_request(void *cls,
  * Initialized the interceptor
  *
  * @param zone the zone to work in
- * @param the prov key of the zone (can be null, needed for caching)
+ * @param key the prov key of the zone (can be null, needed for caching)
  * @param c the configuration
  * @return GNUNET_OK on success
  */
 int
-gns_interceptor_init(GNUNET_HashCode zone,
+gns_interceptor_init(struct GNUNET_CRYPTO_ShortHashCode zone,
                      struct GNUNET_CRYPTO_RsaPrivateKey *key,
                      const struct GNUNET_CONFIGURATION_Handle *c)
 {
+  unsigned long long default_lookup_timeout_secs = 0;
+
   GNUNET_log(GNUNET_ERROR_TYPE_INFO,
              "DNS hijacking enabled... connecting to service.\n");
 
@@ -352,6 +360,17 @@ gns_interceptor_init(GNUNET_HashCode zone,
                                   GNUNET_DNS_FLAG_PRE_RESOLUTION,
                                   &handle_dns_request, /* rh */
                                   NULL); /* Closure */
+
+  if (GNUNET_OK ==
+      GNUNET_CONFIGURATION_get_value_number(c, "gns",
+                                            "DEFAULT_LOOKUP_TIMEOUT",
+                                            &default_lookup_timeout_secs))
+  {
+    default_lookup_timeout = GNUNET_TIME_relative_multiply(
+                                                  GNUNET_TIME_UNIT_SECONDS,
+                                                  default_lookup_timeout_secs);
+  }
+
   if (NULL == dns_handle)
   {
     GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
@@ -362,4 +381,14 @@ gns_interceptor_init(GNUNET_HashCode zone,
   return GNUNET_YES;
 }
 
+/**
+ * Disconnect from interceptor
+ */
+void
+gns_interceptor_stop(void)
+{
+  if (dns_handle)
+    GNUNET_DNS_disconnect(dns_handle);
+}
+
 /* end of gns_interceptor.c */