-handle failure to load certs more nicely
[oweals/gnunet.git] / src / gns / gnunet-service-gns.c
index 6b4e63914ded40a5a7587639466d6c0fdd1009d0..b7eb1f80993bf90026c197c0ff2f93ae0d50d19a 100644 (file)
 */
 /**
  * @file gns/gnunet-service-gns.c
- * @brief GNUnet GNS service
+ * @brief GNU Name System (main service)
  * @author Martin Schanzenbach
  * @author Christian Grothoff
- *
- * TODO:
- * - conversion of private to public records does NOT check if the
- *   records are actually public 
  */
 #include "platform.h"
 #include "gnunet_util_lib.h"
-#include "gnunet_transport_service.h"
 #include "gnunet_dns_service.h"
 #include "gnunet_dnsparser_lib.h"
 #include "gnunet_dht_service.h"
@@ -37,8 +32,8 @@
 #include "gnunet_gns_service.h"
 #include "gnunet_statistics_service.h"
 #include "gns.h"
-#include "gns_common.h"
 #include "gnunet-service-gns_resolver.h"
+#include "gnunet-service-gns_shorten.h"
 #include "gnunet-service-gns_interceptor.h"
 #include "gnunet_protocols.h"
 
@@ -219,6 +214,7 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 
   GNS_interceptor_done ();
   GNS_resolver_done ();
+  GNS_shorten_done ();
   if (NULL != statistics)
   {
     GNUNET_STATISTICS_destroy (statistics, GNUNET_NO);
@@ -290,6 +286,7 @@ dht_put_continuation (void *cls,
 {
   struct GNUNET_TIME_Relative next_put_interval; 
 
+  active_put = NULL;
   num_public_records++;  
   if ( (num_public_records > last_num_public_records) &&
        (GNUNET_NO == first_zone_iteration) )
@@ -333,7 +330,11 @@ put_gns_record (void *cls,
   struct GNUNET_NAMESTORE_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];
+  unsigned int rd_public_count;
+  unsigned int i;
 
   if (NULL == name)
   {
@@ -385,25 +386,40 @@ put_gns_record (void *cls,
     return;
   }
 
-  /* FIXME: filter out records that are not public! */
+  /* filter out records that are not public, and convert to
+     absolute expiration time. */
+  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)))
+    {
+      rd_public[rd_public_count] = rd[i];
+      if (0 != (rd[i].flags & GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION))
+      {
+       rd_public[rd_public_count].flags &= ~GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION;
+       rd_public[rd_public_count].expiration_time += now.abs_value_us;
+      }
+      rd_public_count++;
+    }
 
   /* We got a set of records to publish */
-  if (0 == rd_count)
+  if (0 == rd_public_count)
   {
     zone_publish_task = GNUNET_SCHEDULER_add_now (&publish_zone_dht_next,
                                                    NULL);
     return;
   }
-  expire = GNUNET_NAMESTORE_record_get_expiration_time (rd_count,
-                                                       rd);
+  expire = GNUNET_NAMESTORE_record_get_expiration_time (rd_public_count,
+                                                       rd_public);
   block = GNUNET_NAMESTORE_block_create (key,
                                         expire,
                                         name,
-                                        rd,
-                                        rd_count);
+                                        rd_public,
+                                        rd_public_count);
   block_size = ntohl (block->purpose.size) 
     + sizeof (struct GNUNET_CRYPTO_EccSignature) 
-    + sizeof (struct GNUNET_CRYPTO_EccPublicKey);
+    + sizeof (struct GNUNET_CRYPTO_EccPublicSignKey);
   GNUNET_NAMESTORE_query_from_private_key (key,
                                           name,
                                           &query);
@@ -457,7 +473,7 @@ publish_zone_dht_start (void *cls,
  * Reply to client with the result from our lookup.
  *
  * @param cls the closure (our client lookup handle)
- * @param rd_count the number of records
+ * @param rd_count the number of records in @a rd
  * @param rd the record data
  */
 static void
@@ -490,6 +506,7 @@ send_lookup_response (void* cls,
   GNUNET_SERVER_receive_done (clh->client, 
                              GNUNET_OK); 
   GNUNET_CONTAINER_DLL_remove (clh_head, clh_tail, clh);
+  GNUNET_SERVER_client_set_user_context (clh->client, NULL);
   GNUNET_free (clh);
   GNUNET_STATISTICS_update (statistics,
                             "Completed lookups", 1, 
@@ -618,7 +635,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_EccPublicKey dns_root;
+  struct GNUNET_CRYPTO_EccPublicSignKey dns_root;
   unsigned long long max_parallel_bg_queries = 0;
   char *dns_root_name;
 
@@ -682,7 +699,7 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
                                             &dns_root_name))
   {
     if (GNUNET_OK !=
-       GNUNET_CRYPTO_ecc_public_key_from_string (dns_root_name,
+       GNUNET_CRYPTO_ecc_public_sign_key_from_string (dns_root_name,
                                                  strlen (dns_root_name),
                                                  &dns_root))
     {
@@ -704,11 +721,10 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
       return;
     }
   }
-  /* FIXME: install client disconnect handle to clean up pending
-     lookups on client disconnect! */
   GNS_resolver_init (namestore_handle, dht_handle, 
                     c,
                     max_parallel_bg_queries);
+  GNS_shorten_init (namestore_handle, dht_handle);
   GNUNET_SERVER_disconnect_notify (server,
                                   &notify_client_disconnect,
                                   NULL);