-indentation, code cleanup
[oweals/gnunet.git] / src / gns / gnunet-service-gns.c
index 8fcd75e7c37ddf637b99aa10aaec4a5fa6703e6c..53d6c11a4239d556d4e9c9cde638bb998464e360 100644 (file)
@@ -28,6 +28,7 @@
 #include "gnunet_dns_service.h"
 #include "gnunet_dnsparser_lib.h"
 #include "gnunet_dht_service.h"
+#include "gnunet_namecache_service.h"
 #include "gnunet_namestore_service.h"
 #include "gnunet_gns_service.h"
 #include "gnunet_statistics_service.h"
@@ -120,6 +121,11 @@ static struct GNUNET_DHT_PutHandle *active_put;
  */
 static struct GNUNET_NAMESTORE_Handle *namestore_handle;
 
+/**
+ * Our handle to the namecache service
+ */
+static struct GNUNET_NAMECACHE_Handle *namecache_handle;
+
 /**
  * Handle to iterate over our authoritative zone in namestore
  */
@@ -231,6 +237,11 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
     GNUNET_NAMESTORE_disconnect (namestore_handle);
     namestore_handle = NULL;
   }
+  if (NULL != namecache_handle)
+  {
+    GNUNET_NAMECACHE_disconnect (namecache_handle);
+    namecache_handle = NULL;
+  }
   if (NULL != active_put)
   {
     GNUNET_DHT_put_cancel (active_put);
@@ -318,17 +329,17 @@ dht_put_continuation (void *cls,
  */
 static void
 put_gns_record (void *cls,
-                const struct GNUNET_CRYPTO_EccPrivateKey *key,
+                const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
                 const char *name,
                 unsigned int rd_count,
-                const struct GNUNET_NAMESTORE_RecordData *rd)
+                const struct GNUNET_GNSRECORD_Data *rd)
 {
-  struct GNUNET_NAMESTORE_Block *block;
+  struct GNUNET_GNSRECORD_Block *block;
   struct GNUNET_HashCode query;
   struct GNUNET_TIME_Absolute expire;
   struct GNUNET_TIME_Absolute now;
   size_t block_size;
-  struct GNUNET_NAMESTORE_RecordData rd_public[rd_count];
+  struct GNUNET_GNSRECORD_Data rd_public[rd_count];
   unsigned int rd_public_count;
   unsigned int i;
 
@@ -387,13 +398,13 @@ put_gns_record (void *cls,
   rd_public_count = 0;
   now = GNUNET_TIME_absolute_get ();
   for (i=0;i<rd_count;i++)
-    if (0 == (rd[i].flags & (GNUNET_NAMESTORE_RF_PRIVATE |
-                            GNUNET_NAMESTORE_RF_PENDING)))
+    if (0 == (rd[i].flags & (GNUNET_GNSRECORD_RF_PRIVATE |
+                            GNUNET_GNSRECORD_RF_PENDING)))
     {
       rd_public[rd_public_count] = rd[i];
-      if (0 != (rd[i].flags & GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION))
+      if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION))
       {
-       rd_public[rd_public_count].flags &= ~GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION;
+       rd_public[rd_public_count].flags &= ~GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
        rd_public[rd_public_count].expiration_time += now.abs_value_us;
       }
       rd_public_count++;
@@ -406,17 +417,17 @@ put_gns_record (void *cls,
                                                    NULL);
     return;
   }
-  expire = GNUNET_NAMESTORE_record_get_expiration_time (rd_public_count,
+  expire = GNUNET_GNSRECORD_record_get_expiration_time (rd_public_count,
                                                        rd_public);
-  block = GNUNET_NAMESTORE_block_create (key,
+  block = GNUNET_GNSRECORD_block_create (key,
                                         expire,
                                         name,
                                         rd_public,
                                         rd_public_count);
   block_size = ntohl (block->purpose.size)
-    + sizeof (struct GNUNET_CRYPTO_EccSignature)
-    + sizeof (struct GNUNET_CRYPTO_EccPublicSignKey);
-  GNUNET_NAMESTORE_query_from_private_key (key,
+    + sizeof (struct GNUNET_CRYPTO_EcdsaSignature)
+    + sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey);
+  GNUNET_GNSRECORD_query_from_private_key (key,
                                           name,
                                           &query);
 
@@ -475,7 +486,7 @@ publish_zone_dht_start (void *cls,
 static void
 send_lookup_response (void* cls,
                      uint32_t rd_count,
-                     const struct GNUNET_NAMESTORE_RecordData *rd)
+                     const struct GNUNET_GNSRECORD_Data *rd)
 {
   struct ClientLookupHandle *clh = cls;
   struct GNUNET_GNS_ClientLookupResultMessage *rmsg;
@@ -486,13 +497,13 @@ send_lookup_response (void* cls,
               "LOOKUP_RESULT",
              rd_count);
 
-  len = GNUNET_NAMESTORE_records_get_size (rd_count, rd);
+  len = GNUNET_GNSRECORD_records_get_size (rd_count, rd);
   rmsg = GNUNET_malloc (len + sizeof (struct GNUNET_GNS_ClientLookupResultMessage));
   rmsg->header.type = htons (GNUNET_MESSAGE_TYPE_GNS_LOOKUP_RESULT);
   rmsg->header.size = htons (len + sizeof(struct GNUNET_GNS_ClientLookupResultMessage));
   rmsg->id = clh->request_id;
   rmsg->rd_count = htonl (rd_count);
-  GNUNET_NAMESTORE_records_serialize (rd_count, rd, len,
+  GNUNET_GNSRECORD_records_serialize (rd_count, rd, len,
                                      (char*) &rmsg[1]);
   GNUNET_SERVER_notification_context_unicast (nc,
                                              clh->client,
@@ -528,7 +539,7 @@ handle_lookup (void *cls,
   struct ClientLookupHandle *clh;
   char *nameptr = name;
   const char *utf_in;
-  const struct GNUNET_CRYPTO_EccPrivateKey *key;
+  const struct GNUNET_CRYPTO_EcdsaPrivateKey *key;
   uint16_t msg_size;
   const struct GNUNET_GNS_ClientLookupMessage *sh_msg;
 
@@ -630,7 +641,7 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
     { &handle_lookup, NULL, GNUNET_MESSAGE_TYPE_GNS_LOOKUP, 0},
     {NULL, NULL, 0, 0}
   };
-  struct GNUNET_CRYPTO_EccPublicSignKey dns_root;
+  struct GNUNET_CRYPTO_EcdsaPublicKey dns_root;
   unsigned long long max_parallel_bg_queries = 0;
   char *dns_root_name;
 
@@ -645,6 +656,14 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
     GNUNET_SCHEDULER_shutdown ();
     return;
   }
+  namecache_handle = GNUNET_NAMECACHE_connect (c);
+  if (NULL == namecache_handle)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+               _("Failed to connect to the namecache!\n"));
+    GNUNET_SCHEDULER_shutdown ();
+    return;
+  }
 
   put_interval = INITIAL_PUT_INTERVAL;
   zone_publish_time_window = DEFAULT_ZONE_PUBLISH_TIME_WINDOW;
@@ -683,7 +702,7 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
                                             &dns_root_name))
   {
     if (GNUNET_OK !=
-       GNUNET_CRYPTO_ecc_public_sign_key_from_string (dns_root_name,
+       GNUNET_CRYPTO_ecdsa_public_key_from_string (dns_root_name,
                                                  strlen (dns_root_name),
                                                  &dns_root))
     {
@@ -705,10 +724,14 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
       return;
     }
   }
-  GNS_resolver_init (namestore_handle, dht_handle,
+  GNS_resolver_init (namestore_handle,
+                     namecache_handle,
+                     dht_handle,
                     c,
                     max_parallel_bg_queries);
-  GNS_shorten_init (namestore_handle, dht_handle);
+  GNS_shorten_init (namestore_handle,
+                    namecache_handle,
+                    dht_handle);
   GNUNET_SERVER_disconnect_notify (server,
                                   &notify_client_disconnect,
                                   NULL);