- added check against statistics
[oweals/gnunet.git] / src / gns / gnunet-service-gns.c
index 6acd2285ce2ccdbae72863e7db5f5fae3e579f3b..c2ea2a44d3ee065eda0cfcd60790d293973fffd8 100644 (file)
@@ -31,7 +31,6 @@
 #include "gnunet_dnsparser_lib.h"
 #include "gnunet_dht_service.h"
 #include "gnunet_namestore_service.h"
-#include <unicase.h>
 #include "gnunet_gns_service.h"
 #include "block_gns.h"
 #include "gns.h"
@@ -143,6 +142,11 @@ struct GNUNET_CRYPTO_ShortHashCode zone_hash;
  */
 static int num_public_records =  3600;
 
+/**
+ * update interval in seconds
+ */
+static unsigned long long int dht_max_update_interval;
+
 /* dht update interval FIXME define? */
 static struct GNUNET_TIME_Relative dht_update_interval;
 
@@ -155,25 +159,6 @@ static int auto_import_pkey;
 /* lookup timeout */
 static struct GNUNET_TIME_Relative default_lookup_timeout;
 
-/**
- * Normalizes the name in old
- *
- * @param old the old name to normalize
- * @param new the buffer to write the new name to
- */
-static void
-normalize_name(const char* old, char** new)
-{
-  uint8_t *tmp_name;
-  size_t n_len;
-
-  tmp_name = u8_tolower ((uint8_t*)old, strlen ((char *) old),
-                       NULL, UNINORM_NFD, NULL, &n_len);
-
-  memcpy(*new, tmp_name, n_len);
-  (*new)[n_len] = '\0';
-  free(tmp_name);
-}
 /**
  * Continue shutdown
  */
@@ -273,11 +258,11 @@ put_gns_record(void *cls,
   {
     GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
                "Zone iteration finished. Rescheduling put in %ds\n",
-               GNUNET_GNS_DHT_MAX_UPDATE_INTERVAL);
+               dht_max_update_interval);
     zone_update_taskid = GNUNET_SCHEDULER_add_delayed (
                                         GNUNET_TIME_relative_multiply(
                                             GNUNET_TIME_UNIT_SECONDS,
-                                            GNUNET_GNS_DHT_MAX_UPDATE_INTERVAL
+                                            dht_max_update_interval
                                             ),
                                             &update_zone_dht_start,
                                             NULL);
@@ -344,6 +329,9 @@ put_gns_record(void *cls,
   GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
              "putting records for %s under key: %s with size %d\n",
              name, (char*)&xor_hash_string, rd_payload_length);
+  
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+             "DHT req to %d\n", DHT_OPERATION_TIMEOUT.rel_value);
 
   GNUNET_DHT_put (dht_handle, &xor_hash,
                   DHT_GNS_REPLICATION_LEVEL,
@@ -383,20 +371,20 @@ update_zone_dht_start(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   {
     dht_update_interval = GNUNET_TIME_relative_multiply(
                                             GNUNET_TIME_UNIT_SECONDS,
-                                            GNUNET_GNS_DHT_MAX_UPDATE_INTERVAL);
+                                            dht_max_update_interval);
     GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
                "No records in db. Adjusted DHT update interval to %ds\n",
-               GNUNET_GNS_DHT_MAX_UPDATE_INTERVAL);
+               dht_max_update_interval);
   }
   else
   {
     
     dht_update_interval = GNUNET_TIME_relative_multiply(
-                                                      GNUNET_TIME_UNIT_SECONDS,
-                                                     (3600/num_public_records));
+                                  GNUNET_TIME_UNIT_SECONDS,
+                                  (dht_max_update_interval/num_public_records));
     GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
                "Adjusted DHT update interval to %ds!\n",
-               (3600/num_public_records));
+               (dht_max_update_interval/num_public_records));
   }
 
   /* start counting again */
@@ -469,6 +457,7 @@ static void handle_shorten(void *cls,
   size_t msg_size = 0;
   struct ClientShortenHandle *csh;
   char name[MAX_DNS_NAME_LENGTH];
+  char* nameptr = name;
 
   if (ntohs (message->size) < sizeof (struct GNUNET_GNS_ClientShortenMessage))
   {
@@ -495,7 +484,7 @@ static void handle_shorten(void *cls,
   csh->client = client;
   csh->unique_id = sh_msg->id;
   
-  normalize_name((char*)&sh_msg[1], (char**)&name);
+  GNUNET_STRINGS_utf8_tolower((char*)&sh_msg[1], &nameptr);
 
   if (strlen (name) < strlen(GNUNET_GNS_TLD)) {
     csh->name = NULL;
@@ -584,6 +573,8 @@ static void handle_get_authority(void *cls,
   size_t msg_size = 0;
   struct ClientGetAuthHandle *cah;
   char name[MAX_DNS_NAME_LENGTH];
+  char* nameptr = name;
+
 
   if (ntohs (message->size) < sizeof (struct GNUNET_GNS_ClientGetAuthMessage))
   {
@@ -606,7 +597,7 @@ static void handle_get_authority(void *cls,
     return;
   }
   
-  normalize_name((char*)&sh_msg[1], (char**)&name);
+  GNUNET_STRINGS_utf8_tolower((char*)&sh_msg[1], &nameptr);
 
 
   cah = GNUNET_malloc(sizeof(struct ClientGetAuthHandle));
@@ -713,6 +704,7 @@ handle_lookup(void *cls,
   size_t namelen;
   char name[MAX_DNS_NAME_LENGTH];
   struct ClientLookupHandle *clh;
+  char* nameptr = name;
 
   if (ntohs (message->size) < sizeof (struct GNUNET_GNS_ClientLookupMessage))
   {
@@ -735,7 +727,7 @@ handle_lookup(void *cls,
     return;
   }
   
-  normalize_name((char*)&sh_msg[1], (char**)&name);
+  GNUNET_STRINGS_utf8_tolower((char*)&sh_msg[1], &nameptr);
   namelen = strlen(name)+1;
   clh = GNUNET_malloc(sizeof(struct ClientLookupHandle));
   clh->client = client;
@@ -780,6 +772,7 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
   struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pkey;
   unsigned long long max_parallel_bg_queries = 0;
   unsigned long long default_lookup_timeout_secs = 0;
+  int ignore_pending = GNUNET_NO;
 
   static const struct GNUNET_SERVER_MessageHandler handlers[] = {
     {&handle_shorten, NULL, GNUNET_MESSAGE_TYPE_GNS_SHORTEN, 0},
@@ -821,15 +814,9 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
     return;
   }
   
-  /**
-   * handle to the dht
-   */
-  dht_handle = GNUNET_DHT_connect(c, 1); //FIXME get ht_len from cfg
+  
 
-  if (NULL == dht_handle)
-  {
-    GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Could not connect to DHT!\n");
-  }
+  auto_import_pkey = GNUNET_NO;
 
   if (GNUNET_YES ==
       GNUNET_CONFIGURATION_get_value_yesno (c, "gns",
@@ -841,8 +828,20 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
 
   }
 
+  dht_max_update_interval = GNUNET_GNS_DHT_MAX_UPDATE_INTERVAL;
+
   if (GNUNET_OK ==
-      GNUNET_CONFIGURATION_get_value_number(c, "gns",
+      GNUNET_CONFIGURATION_get_value_number (c, "gns",
+                                             "DHT_MAX_UPDATE_INTERVAL",
+                                             &dht_max_update_interval))
+  {
+    GNUNET_log(GNUNET_ERROR_TYPE_INFO,
+               "DHT zone update interval: %d\n",
+               dht_max_update_interval);
+  }
+
+  if (GNUNET_OK ==
+      GNUNET_CONFIGURATION_get_value_number (c, "gns",
                                             "MAX_PARALLEL_BACKGROUND_QUERIES",
                                             &max_parallel_bg_queries))
   {
@@ -851,6 +850,15 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
                max_parallel_bg_queries);
   }
 
+  if (GNUNET_YES ==
+      GNUNET_CONFIGURATION_get_value_yesno (c, "gns",
+                                            "AUTO_IMPORT_CONFIRMATION_REQ"))
+  {
+    GNUNET_log(GNUNET_ERROR_TYPE_INFO,
+               "Auto import requires user confirmation\n");
+    ignore_pending = GNUNET_YES;
+  }
+
   if (GNUNET_OK ==
       GNUNET_CONFIGURATION_get_value_number(c, "gns",
                                             "DEFAULT_LOOKUP_TIMEOUT",
@@ -863,8 +871,21 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
                                             default_lookup_timeout_secs);
   }
   
+  /**
+   * handle to the dht
+   */
+  dht_handle = GNUNET_DHT_connect(c,
+                       //max_parallel_bg_queries); //FIXME get ht_len from cfg
+                       1024);
+
+  if (NULL == dht_handle)
+  {
+    GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Could not connect to DHT!\n");
+  }
+  
   if (gns_resolver_init(namestore_handle, dht_handle, zone_hash,
-                        max_parallel_bg_queries)
+                        max_parallel_bg_queries,
+                        ignore_pending)
       == GNUNET_SYSERR)
   {
     GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
@@ -886,8 +907,6 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
     }
   }
   
-  //put_some_records(); //FIXME for testing
-  
   /**
    * Schedule periodic put
    * for our records