first preparations for GNS mapping arbitrary TLDs
authorChristian Grothoff <christian@grothoff.org>
Sun, 25 Feb 2018 22:21:34 +0000 (23:21 +0100)
committerChristian Grothoff <christian@grothoff.org>
Sun, 25 Feb 2018 22:21:34 +0000 (23:21 +0100)
contrib/gns-bcd.tex
src/exit/gnunet-daemon-exit.c
src/gns/Makefile.am
src/gns/gnunet-service-gns.c
src/gns/gnunet-service-gns_interceptor.c
src/gns/gnunet-service-gns_resolver.c

index 5e33ffbc73cd7586c057b0a2397e225f030d635f..73a302985c88a6627149c4b079370fcc0e87e634 100644 (file)
 %        \card{english}
 %    \end{center}
 %\end{figure}
-
index d9a5dd6848a0596723a485e4694fa7b629408ff2..c624e083e5d6f4170372419b5b5c68ac1cbed732 100644 (file)
@@ -3373,10 +3373,10 @@ add_services (int proto,
 
 
 /**
- * Reads the configuration servicecfg and populates udp_services
+ * Reads the configuration and populates #udp_services and #tcp_services
  *
  * @param cls unused
- * @param section name of section in config, equal to hostname
+ * @param section name of section in config
  */
 static void
 read_service_conf (void *cls,
index 977eb87e36dd74a69c9fc66ccadc85e1100fa42e..e89192414e3534704f35362490b1e94aba9afcbd 100644 (file)
@@ -185,7 +185,7 @@ w32nsp_resolve_SOURCES = \
 w32nsp_resolve_LDADD = -lws2_32
 
 gnunet_service_gns_SOURCES = \
- gnunet-service-gns.c \
+ gnunet-service-gns.c gnunet-service-gns.h \
  gnunet-service-gns_resolver.c gnunet-service-gns_resolver.h \
  gnunet-service-gns_interceptor.c gnunet-service-gns_interceptor.h
 gnunet_service_gns_LDADD = \
index 0ca25ac190d7069d9b43dd98b5e585ebb877f876..e13beb8897d4fe9d9eb4c2a1897bc4ab293f6c78 100644 (file)
@@ -100,6 +100,38 @@ struct GnsClient
 };
 
 
+/**
+ * Representation of a TLD, mapping the respective TLD string
+ * (i.e. ".gnu") to the respective public key of the zone.
+ */
+struct GNS_TopLevelDomain
+{
+
+  /**
+   * Kept in a DLL, as there are unlikely enough of these to
+   * warrant a hash map.
+   */
+  struct GNS_TopLevelDomain *next;
+
+  /**
+   * Kept in a DLL, as there are unlikely enough of these to
+   * warrant a hash map.
+   */
+  struct GNS_TopLevelDomain *prev;
+
+  /**
+   * Public key associated with the @a tld.
+   */
+  struct GNUNET_CRYPTO_EddsaPublicKey pkey;
+
+  /**
+   * Top-level domain as a string, including leading ".".
+   */
+  char *tld;
+
+};
+
+
 /**
  * Our handle to the DHT
  */
@@ -136,6 +168,50 @@ static int v4_enabled;
  */
 static struct GNUNET_STATISTICS_Handle *statistics;
 
+/**
+ * Head of DLL of TLDs we map to GNS zones.
+ */
+static struct GNS_TopLevelDomain *tld_head;
+
+/**
+ * Tail of DLL of TLDs we map to GNS zones.
+ */
+static struct GNS_TopLevelDomain *tld_tail;
+
+
+/**
+ * Find GNS zone belonging to TLD @a tld.
+ *
+ * @param tld_str top-level domain to look up
+ * @param[out] pkey public key to set
+ * @return #GNUNET_YES if @a tld was found #GNUNET_NO if not
+ */
+int
+GNS_find_tld (const char *tld_str,
+              struct GNUNET_CRYPTO_EddsaPublicKey *pkey)
+{
+  if ('\0' == *tld_str)
+    return GNUNET_NO;
+  for (struct GNS_TopLevelDomain *tld = tld_head;
+       NULL != tld;
+       tld = tld->next)
+  {
+    if (0 == strcasecmp (tld_str,
+                         tld->tld))
+    {
+      *pkey = tld->pkey;
+      return GNUNET_YES;
+    }
+  }
+  if (GNUNET_OK ==
+      GNUNET_STRINGS_string_to_data (tld_str + 1,
+                                     strlen (tld_str + 1),
+                                     pkey,
+                                     sizeof (*pkey)))
+    return GNUNET_YES; /* TLD string *was* the public key */
+  return GNUNET_NO;
+}
+
 
 /**
  * Task run during shutdown.
@@ -146,6 +222,7 @@ static struct GNUNET_STATISTICS_Handle *statistics;
 static void
 shutdown_task (void *cls)
 {
+  struct GNS_TopLevelDomain *tld;
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Shutting down!\n");
   GNS_interceptor_done ();
@@ -176,6 +253,14 @@ shutdown_task (void *cls)
     GNUNET_DHT_disconnect (dht_handle);
     dht_handle = NULL;
   }
+  while (NULL != (tld = tld_head))
+  {
+    GNUNET_CONTAINER_DLL_remove (tld_head,
+                                 tld_tail,
+                                 tld);
+    GNUNET_free (tld->tld);
+    GNUNET_free (tld);
+  }
 }
 
 
@@ -419,6 +504,47 @@ identity_intercept_cb (void *cls,
 }
 
 
+/**
+ * Reads the configuration and populates TLDs
+ *
+ * @param cls unused
+ * @param section name of section in config, always "gns"
+ * @param option name of the option, TLDs start with "."
+ * @param value value for the option, public key for TLDs
+ */
+static void
+read_service_conf (void *cls,
+                   const char *section,
+                   const char *option,
+                   const char *value)
+{
+  struct GNUNET_CRYPTO_EddsaPublicKey pk;
+  struct GNS_TopLevelDomain *tld;
+
+  if (option[0] != '.')
+    return;
+  if (GNUNET_OK !=
+      GNUNET_STRINGS_string_to_data (value,
+                                     strlen (value),
+                                     &pk,
+                                     sizeof (pk)))
+  {
+    GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
+                               section,
+                               option,
+                               _("Properly base32-encoded public key required"));
+    return;
+  }
+  tld = GNUNET_new (struct GNS_TopLevelDomain);
+  tld->tld = GNUNET_strdup (option);
+  tld->pkey = pk;
+  GNUNET_CONTAINER_DLL_insert (tld_head,
+                               tld_tail,
+                               tld);
+}
+
+
+
 /**
  * Process GNS requests.
  *
@@ -433,6 +559,10 @@ run (void *cls,
 {
   unsigned long long max_parallel_bg_queries = 16;
 
+  GNUNET_CONFIGURATION_iterate_section_values (c,
+                                               "gns",
+                                               &read_service_conf,
+                                               NULL);
   v6_enabled = GNUNET_NETWORK_test_pf (PF_INET6);
   v4_enabled = GNUNET_NETWORK_test_pf (PF_INET);
   namecache_handle = GNUNET_NAMECACHE_connect (c);
@@ -459,7 +589,8 @@ run (void *cls,
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 _("Could not connect to DHT!\n"));
-    GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
+    GNUNET_SCHEDULER_add_now (&shutdown_task,
+                              NULL);
     return;
   }
 
index a9e2078916e8b2fb827e9f0be7625593a3a4b8ed..71aa08dc58fd6bd78dcb9abdb3c87e532ff0f001 100644 (file)
@@ -327,7 +327,9 @@ handle_dns_request (void *cls,
   {
     /* Start resolution in GNS */
     ilh = GNUNET_new (struct InterceptLookupHandle);
-    GNUNET_CONTAINER_DLL_insert (ilh_head, ilh_tail, ilh);
+    GNUNET_CONTAINER_DLL_insert (ilh_head,
+                                 ilh_tail,
+                                 ilh);
     ilh->packet = p;
     ilh->request_handle = rh;
     ilh->lookup = GNS_resolver_lookup (&zone,
index 5bf443267329b13929d9e42d884e1f1402f44968..533c0cada8154a85bd3fa519f68157f472343b93 100644 (file)
@@ -2252,7 +2252,7 @@ recursive_resolution (void *cls)
  * Begin the resolution process from 'name', starting with
  * the identification of the zone specified by 'name'.
  *
- * @param cls the `struct GNS_ResolverHandle` 
+ * @param cls the `struct GNS_ResolverHandle`
  */
 static void
 start_resolver_lookup (void *cls)
@@ -2595,10 +2595,11 @@ GNS_resolver_done ()
  *
  * @param name the name to check
  * @param tld the TLD to check for
- * @return GNUNET_YES or GNUNET_NO
+ * @return #GNUNET_YES or #GNUNET_NO
  */
 int
-is_tld (const char* name, const char* tld)
+is_tld (const char* name,
+        const char* tld)
 {
   size_t offset = 0;