-resolver bugfix, gnunet-gns command line features
authorMartin Schanzenbach <mschanzenbach@posteo.de>
Wed, 14 Mar 2012 15:07:04 +0000 (15:07 +0000)
committerMartin Schanzenbach <mschanzenbach@posteo.de>
Wed, 14 Mar 2012 15:07:04 +0000 (15:07 +0000)
src/gns/gns_api.c
src/gns/gnunet-gns.c
src/gns/gnunet-service-gns_resolver.c

index d6709a96e6875f28b80453ff1119b2a6d4a6f085..fe1ba3200f4bf50525233c13021f0c50e49746e0 100644 (file)
@@ -591,6 +591,7 @@ GNUNET_GNS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
 void
 GNUNET_GNS_disconnect (struct GNUNET_GNS_Handle *handle)
 {
+  GNUNET_CLIENT_disconnect (handle->client, 0);
   /* disco from GNS */
 }
 
index 8c087defecfb771a4537ec2aa00cfc4f2bea11bd..b689cab18459e04a912507774c2b30d2a3fd1190 100644 (file)
@@ -39,7 +39,25 @@ static struct GNUNET_GNS_Handle *gns;
 /**
  * GNS name to shorten. (-s option)
  */
-static char *name;
+static char *shorten_name;
+
+/**
+ * GNS name to lookup. (-u option)
+ */
+static char *lookup_name;
+
+
+/**
+ * record type to look up (-t option)
+ */
+static char *lookup_type;
+
+/**
+ * name to look up authority for (-a option)
+ */
+static char *auth_name;
+
+static enum GNUNET_GNS_RecordType rtype;
 
 /**
  * Task run on shutdown.  Cleans up everything.
@@ -65,6 +83,43 @@ process_shorten_result(void* cls, const char* nshort)
   printf("%s shortened to %s\n", (char*) cls, nshort);
 }
 
+static void
+process_lookup_result(void* cls, uint32_t rd_count,
+                      const struct GNUNET_NAMESTORE_RecordData *rd)
+{
+  int i;
+  char* addr;
+  char* name = (char*) cls;
+
+  if (rd_count == 0)
+    printf("No results.\n");
+
+  for (i=0; i<rd_count; i++)
+  {
+    if (rd[i].record_type != rtype)
+      continue;
+    if (rd[i].record_type == GNUNET_GNS_RECORD_TYPE_A)
+    {
+      addr = inet_ntoa(*((struct in_addr*)rd[i].data));
+      printf("Got A record for %s: %s\n", name, addr);
+    }
+    if (rd[i].record_type == GNUNET_GNS_RECORD_MX)
+    {
+      printf("Got MX record for %s: %s\n", name, (char*)rd[i].data);
+    }
+
+    //FIXME others? maybe to string method for records?
+  }
+
+  GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
+}
+
+static void
+process_auth_result(void* cls, const char* auth)
+{
+  printf ("%s\n", auth);
+}
+
 /**
  * Main function that will be run.
  *
@@ -78,6 +133,8 @@ run (void *cls, char *const *args, const char *cfgfile,
      const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
   gns = GNUNET_GNS_connect (cfg);
+  rtype = GNUNET_GNS_RECORD_TYPE_A;
+
   if (NULL == gns)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -85,14 +142,26 @@ run (void *cls, char *const *args, const char *cfgfile,
     return;
   }
   
-  if (name != NULL)
+  if (shorten_name != NULL)
   {
     /** shorten name */
-    GNUNET_GNS_shorten(gns, name, &process_shorten_result, name);
+    GNUNET_GNS_shorten(gns, shorten_name, &process_shorten_result,
+                       shorten_name);
+  }
+
+  if (lookup_name != NULL)
+  {
+    GNUNET_GNS_lookup(gns, lookup_name, rtype,
+                      &process_lookup_result, lookup_name);
   }
 
+  if (auth_name != NULL)
+  {
+    GNUNET_GNS_get_authority(gns, auth_name, &process_auth_result, auth_name);
+  }
+  
   // FIXME: do work here...
-  GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
+  //GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
 }
 
 
@@ -109,7 +178,16 @@ main (int argc, char *const *argv)
   static const struct GNUNET_GETOPT_CommandLineOption options[] = {
     {'s', "shorten", NULL,
      gettext_noop ("try to shorten a given GNS name"), 1,
-     &GNUNET_GETOPT_set_string, &name},   
+     &GNUNET_GETOPT_set_string, &shorten_name},
+    {'u', "lookup", NULL,
+      gettext_noop ("Lookup a record using GNS (NOT IMPLEMENTED)"), 1,
+      &GNUNET_GETOPT_set_string, &lookup_name},
+    {'a', "authority", NULL,
+      gettext_noop ("Get the authority of a particular name"), 1,
+      &GNUNET_GETOPT_set_string, &auth_name},
+    {'t', "type", NULL,
+      gettext_noop ("Specify the type of the record lookup"), 1,
+      &GNUNET_GETOPT_set_string, &lookup_type},
     GNUNET_GETOPT_OPTION_END
   };
 
index 53fdcc463eb3da8a2df5efbe41df47b2a734fe1d..d3e9d8da69938102dc0b57bef908db625f335a5e 100644 (file)
@@ -651,8 +651,10 @@ handle_record_ns(void* cls, struct ResolverHandle *rh,
   rlh = (struct RecordLookupHandle*) cls;
   if (rd_count == 0)
   {
-    /* ns entry expired. try dht */
-    if (rh->status & (EXPIRED | !EXISTS))
+    /* ns entry expired and not ours. try dht */
+    if (rh->status & (EXPIRED | !EXISTS) &&
+        GNUNET_CRYPTO_hash_cmp(&rh->authority_chain_head->zone,
+                               &rh->authority_chain_tail->zone))
     {
       rh->proc = &handle_record_dht;
       resolve_record_dht(rh);
@@ -842,7 +844,10 @@ handle_delegation_ns(void* cls, struct ResolverHandle *rh,
    * we still have some left
    * check if ns entry is fresh
    **/
-  if (rh->status & (EXISTS | !EXPIRED))
+
+  if ((rh->status & (EXISTS | !EXPIRED)) ||
+      !GNUNET_CRYPTO_hash_cmp(&rh->authority_chain_head->zone,
+                             &rh->authority_chain_tail->zone))
   {
     if (is_canonical(rh->name))
     {