fix transition to multi-server in cmd line for gnunet-zoneimport
authorChristian Grothoff <christian@grothoff.org>
Mon, 23 Apr 2018 13:59:03 +0000 (15:59 +0200)
committerChristian Grothoff <christian@grothoff.org>
Mon, 23 Apr 2018 13:59:03 +0000 (15:59 +0200)
doc/man/gnunet-zoneimport.1
src/gnsrecord/gnsrecord_misc.c
src/namestore/gnunet-service-namestore.c
src/namestore/gnunet-zoneimport.c

index d268bf9ff2fd201120c7caa764d8e348aa52c0d4..afe3354e64dec510b7cdc6ca1ae0eae5e3ecf628 100644 (file)
@@ -4,12 +4,14 @@
 gnunet\-zoneimport \- import DNS zone into GNS zone
 
 .SH SYNOPSIS
-.B gnunet\-zoneimport -s IP
+.B gnunet\-zoneimport [IP]+
 .br
 
 .SH DESCRIPTION
 \fBgnunet\-zoneimport\fP reads a list of domain names (FQDN) from stdin and issues DNS queries for each of the domain names given.  It then checks if a local ego with a name matching the domain exists. Specifically, if the domain name is "example.fr", it will check if an ego "fr" exists, while for a domain "example.com.fr" it will look for an ego called "com.fr"). If so, it will convert the DNS records into GNS records (in particular converting NS records and glue records to GNS2DNS records) and add them to the namestore under the label ("example" in the examples above).
 
+The arguments given to gnunet\-zoneimport is a list of IP addresses of DNS servers to query.
+
 gnunet\-zoneimport will usually never terminate: it will check when DNS records expire, and re-issue requests when the old DNS records have expired so that GNS always has the latest data.
 
 gnunet\-zoneimport will issue many DNS queries in parallel, but is rate-limited in various ways, so most DNS servers should easily handle the load.  gnunet\-zoneimport will perform a limited number of retries if queries fail.
@@ -23,9 +25,6 @@ Finally, gnunet\-zoneimport keeps information for each domain name in memory.  T
 .IP "\-c FILENAME,  \-\-config=FILENAME"
 Use the configuration file FILENAME.
 .B
-.IP "\-s IP, \-\-server IP"
-IP address of the DNS server to query. Should be the authoritative server for the domain (lookup the IP address of the NS server!) and not some recursive resolver (which would be both slow and is more likely to return only partial information).
-.B
 .IP "\-h, \-\-help"
 Print short help on options.
 
index 3c1ead437c9c6eeb448d1a761f2b4e5ae86996a6..05f56cf703f3e5b00ceb03b5add103c53002b0f4 100644 (file)
@@ -152,8 +152,6 @@ struct GNUNET_TIME_Absolute
 GNUNET_GNSRECORD_record_get_expiration_time (unsigned int rd_count,
                                             const struct GNUNET_GNSRECORD_Data *rd)
 {
-  unsigned int c;
-  unsigned int c2;
   struct GNUNET_TIME_Absolute expire;
   struct GNUNET_TIME_Absolute at;
   struct GNUNET_TIME_Relative rt;
@@ -163,7 +161,7 @@ GNUNET_GNSRECORD_record_get_expiration_time (unsigned int rd_count,
   if (NULL == rd)
     return GNUNET_TIME_UNIT_ZERO_ABS;
   expire = GNUNET_TIME_UNIT_FOREVER_ABS;
-  for (c = 0; c < rd_count; c++)
+  for (unsigned int c = 0; c < rd_count; c++)
   {
     if (0 != (rd[c].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION))
     {
@@ -175,12 +173,12 @@ GNUNET_GNSRECORD_record_get_expiration_time (unsigned int rd_count,
       at.abs_value_us = rd[c].expiration_time;
     }
 
-    for (c2 = 0; c2 < rd_count; c2++)
+    for (unsigned int c2 = 0; c2 < rd_count; c2++)
     {
       /* Check for shadow record */
-      if ((c == c2) ||
-          (rd[c].record_type != rd[c2].record_type) ||
-          (0 == (rd[c2].flags & GNUNET_GNSRECORD_RF_SHADOW_RECORD)))
+      if ( (c == c2) ||
+          (rd[c].record_type != rd[c2].record_type) ||
+          (0 == (rd[c2].flags & GNUNET_GNSRECORD_RF_SHADOW_RECORD)) )
           continue;
       /* We have a shadow record */
       if (0 != (rd[c2].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION))
@@ -192,9 +190,11 @@ GNUNET_GNSRECORD_record_get_expiration_time (unsigned int rd_count,
       {
         at_shadow.abs_value_us = rd[c2].expiration_time;
       }
-      at = GNUNET_TIME_absolute_max (at, at_shadow);
+      at = GNUNET_TIME_absolute_max (at,
+                                    at_shadow);
     }
-    expire = GNUNET_TIME_absolute_min (at, expire);
+    expire = GNUNET_TIME_absolute_min (at, 
+                                      expire);
   }
   LOG (GNUNET_ERROR_TYPE_DEBUG,
        "Determined expiration time for block with %u records to be %s\n",
index 3685c93af565d5519ac78cfc353c6acee2276ec7..3ba4f9ec3311df2f1c332c4a2873005b8f180755 100644 (file)
@@ -439,9 +439,24 @@ get_nick_record (const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone)
 }
 
 
+/**
+ * Merge the nick record @a nick_rd with the rest of the
+ * record set given in @a rd2.  Store the result in @a rdc_res
+ * and @a rd_res.  The @a nick_rd's expiration time is set to
+ * the maximum expiration time of all of the records in @a rd2.
+ *
+ * @param nick_rd the nick record to integrate
+ * @param rd2_length length of the @a rd2 array
+ * @param rd2 array of records
+ * @param rdc_res[out] length of the resulting @a rd_res array
+ * @param rd_res[out] set to an array of records,
+ *                    including @a nick_rd and @a rd2;
+ *           all of the variable-size 'data' fields in @a rd2 are
+ *           allocated in the same chunk of memory!
+ */
 static void
 merge_with_nick_records (const struct GNUNET_GNSRECORD_Data *nick_rd,
-                         unsigned int rdc2,
+                         unsigned int rd2_length,
                          const struct GNUNET_GNSRECORD_Data *rd2,
                          unsigned int *rdc_res,
                          struct GNUNET_GNSRECORD_Data **rd_res)
@@ -452,24 +467,22 @@ merge_with_nick_records (const struct GNUNET_GNSRECORD_Data *nick_rd,
   int record_offset;
   size_t data_offset;
 
-  (*rdc_res) = 1 + rdc2;
-  if (0 == 1 + rdc2)
+  (*rdc_res) = 1 + rd2_length;
+  if (0 == 1 + rd2_length)
   {
     (*rd_res) = NULL;
     return;
   }
-
   req = 0;
   for (unsigned int c=0; c< 1; c++)
     req += sizeof (struct GNUNET_GNSRECORD_Data) + nick_rd[c].data_size;
-  for (unsigned int c=0; c< rdc2; c++)
+  for (unsigned int c=0; c< rd2_length; c++)
     req += sizeof (struct GNUNET_GNSRECORD_Data) + rd2[c].data_size;
   (*rd_res) = GNUNET_malloc (req);
-  data = (char *) &(*rd_res)[1 + rdc2];
+  data = (char *) &(*rd_res)[1 + rd2_length];
   data_offset = 0;
   latest_expiration = 0;
-
-  for (unsigned int c=0; c< rdc2; c++)
+  for (unsigned int c=0; c< rd2_length; c++)
   {
     if (0 != (rd2[c].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION))
     {
@@ -486,17 +499,15 @@ merge_with_nick_records (const struct GNUNET_GNSRECORD_Data *nick_rd,
                    rd2[c].data_size);
     data_offset += (*rd_res)[c].data_size;
   }
-  record_offset = rdc2;
-  for (unsigned int c=0; c< 1; c++)
-  {
-    (*rd_res)[c+record_offset] = nick_rd[c];
-    (*rd_res)[c+record_offset].expiration_time = latest_expiration;
-    (*rd_res)[c+record_offset].data = (void *) &data[data_offset];
-    GNUNET_memcpy ((void *) (*rd_res)[c+record_offset].data,
-                   nick_rd[c].data,
-                   nick_rd[c].data_size);
-    data_offset += (*rd_res)[c+record_offset].data_size;
-  }
+  /* append nick */
+  record_offset = rd2_length;
+  (*rd_res)[record_offset] = *nick_rd;
+  (*rd_res)[record_offset].expiration_time = latest_expiration;
+  (*rd_res)[record_offset].data = (void *) &data[data_offset];
+  GNUNET_memcpy ((void *) (*rd_res)[record_offset].data,
+                nick_rd->data,
+                nick_rd->data_size);
+  data_offset += (*rd_res)[record_offset].data_size;
   GNUNET_assert (req == (sizeof (struct GNUNET_GNSRECORD_Data)) * (*rdc_res) + data_offset);
 }
 
@@ -531,7 +542,9 @@ send_lookup_response (struct NamestoreClient *nc,
   char *rd_ser;
 
   nick = get_nick_record (zone_key);
-  if ((NULL != nick) && (0 != strcmp(name, GNUNET_GNS_EMPTY_LABEL_AT)))
+  if ( (NULL != nick) &&
+       (0 != strcmp (name,
+                    GNUNET_GNS_EMPTY_LABEL_AT)))
   {
     nick->flags = (nick->flags | GNUNET_GNSRECORD_RF_PRIVATE) ^ GNUNET_GNSRECORD_RF_PRIVATE;
     merge_with_nick_records (nick,
@@ -677,13 +690,15 @@ refresh_block (struct NamestoreClient *nc,
     block = GNUNET_GNSRECORD_block_create (zone_key,
                                            GNUNET_TIME_UNIT_ZERO_ABS,
                                            name,
-                                           res, rd_count);
+                                           res,
+                                          rd_count);
   else
     block = GNUNET_GNSRECORD_block_create (zone_key,
                                            GNUNET_GNSRECORD_record_get_expiration_time (res_count,
-                                               res),
+                                                                                       res),
                                            name,
-                                           res, res_count);
+                                           res,
+                                          res_count);
   GNUNET_assert (NULL != block);
   GNUNET_CRYPTO_ecdsa_key_get_public (zone_key,
                                       &pkey);
@@ -773,9 +788,10 @@ lookup_it (void *cls,
         rdc_res = 0;
         rlc->nick->flags = (rlc->nick->flags | GNUNET_GNSRECORD_RF_PRIVATE) ^ GNUNET_GNSRECORD_RF_PRIVATE;
         merge_with_nick_records (rlc->nick,
-                                 rd_count, rd,
-                                 &rdc_res, &rd_res);
-
+                                 rd_count,
+                                rd,
+                                 &rdc_res,
+                                &rd_res);
         rlc->rd_ser_len = GNUNET_GNSRECORD_records_get_size (rdc_res,
                                                              rd_res);
         rlc->res_rd_count = rdc_res;
index 2926fe9bd6c5b17e9c25f43c36da7cb77d153858..4fd0f3aefde1b09810062acf9f8658fd5b1f04eb 100644 (file)
@@ -267,11 +267,6 @@ static struct Request *req_tail;
  */
 static struct GNUNET_SCHEDULER_Task *t;
 
-/**
- * Which DNS server do we use for queries?
- */
-static char *dns_server;
-
 /**
  * Head of list of zones we are managing.
  */
@@ -1454,13 +1449,13 @@ run (void *cls,
              "Failed to initialize GNUnet DNS STUB\n");
     return;
   }
-  if (NULL == args[1])
+  if (NULL == args[0])
   {
     fprintf (stderr,
              "You must provide a list of DNS resolvers on the command line\n");
     return;
   }
-  for (unsigned int i=1;NULL != args[i];i++)
+  for (unsigned int i=0;NULL != args[i];i++)
   {
     if (GNUNET_OK !=
         GNUNET_DNSSTUB_add_dns_ip (ctx,
@@ -1500,12 +1495,6 @@ main (int argc,
       char *const*argv)
 {
   struct GNUNET_GETOPT_CommandLineOption options[] = {
-    GNUNET_GETOPT_option_mandatory
-    (GNUNET_GETOPT_option_string ('s',
-                                 "server",
-                                 "IP",
-                                 "which DNS server should be used",
-                                 &dns_server)),
     GNUNET_GETOPT_OPTION_END
   };