-per user lookups done
authorMartin Schanzenbach <mschanzenbach@posteo.de>
Wed, 9 May 2012 11:07:47 +0000 (11:07 +0000)
committerMartin Schanzenbach <mschanzenbach@posteo.de>
Wed, 9 May 2012 11:07:47 +0000 (11:07 +0000)
src/gns/gnunet-gns.c
src/gns/gnunet-service-gns.c

index c17f15be3cb72d472517d83963b26639e3b274f1..7695f42130c4aa89dfc84a7120fe5390bc4fdedb 100644 (file)
@@ -60,7 +60,7 @@ static char *auth_name;
 /**
  * raw output
  */
-static int raw;
+static int raw = 0;
 
 static enum GNUNET_GNS_RecordType rtype;
 
@@ -142,6 +142,41 @@ static void
 run (void *cls, char *const *args, const char *cfgfile,
      const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
+  char* keyfile;
+  struct GNUNET_CRYPTO_RsaPrivateKey *key = NULL;
+  struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pkey;
+  struct GNUNET_CRYPTO_ShortHashCode *zone = NULL;
+  struct GNUNET_CRYPTO_ShortHashCode user_zone;
+  struct GNUNET_CRYPTO_ShortHashAsciiEncoded zonename;
+
+  if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns",
+                                                           "ZONEKEY", &keyfile))
+  {
+    if (!raw)
+      GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                  "No private key for root zone found, using default!\n");
+    zone = NULL;
+  }
+  else
+  {
+    if (GNUNET_YES == GNUNET_DISK_file_test (keyfile))
+    {
+      key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
+      GNUNET_CRYPTO_rsa_key_get_public (key, &pkey);
+      GNUNET_CRYPTO_short_hash(&pkey,
+                         sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
+                         &user_zone);
+      GNUNET_free(keyfile);
+      zone = &user_zone;
+      GNUNET_CRYPTO_short_hash_to_enc (zone, &zonename);
+      printf("asdsad\n");
+      if (!raw)
+        GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                    "Using zone: %s!\n", &zonename);
+      GNUNET_CRYPTO_rsa_key_free(key);
+    }
+  }
+
   gns = GNUNET_GNS_connect (cfg);
   if (lookup_type != NULL)
     rtype = GNUNET_NAMESTORE_typename_to_number(lookup_type);
@@ -158,7 +193,7 @@ run (void *cls, char *const *args, const char *cfgfile,
   if (shorten_name != NULL)
   {
     /** shorten name */
-    GNUNET_GNS_shorten(gns, shorten_name, &process_shorten_result,
+    GNUNET_GNS_shorten_zone (gns, shorten_name, zone, &process_shorten_result,
                        shorten_name);
   }
 
@@ -166,7 +201,7 @@ run (void *cls, char *const *args, const char *cfgfile,
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "Lookup\n");
-    GNUNET_GNS_lookup(gns, lookup_name, rtype,
+    GNUNET_GNS_lookup_zone (gns, lookup_name, zone, rtype,
                       &process_lookup_result, lookup_name);
   }
 
index d964a6f6871de7a6c92bb9d018dc4f7bea8c155b..6e157ca4b4cde4bf093a556c23409920e893cf13 100644 (file)
@@ -435,6 +435,9 @@ lookup_private_key(struct GNUNET_CRYPTO_ShortHashCode *zone)
   struct GNUNET_CRYPTO_ShortHashAsciiEncoded zonename;
   char* location;
   struct GNUNET_CRYPTO_RsaPrivateKey *key = NULL;
+  
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+              "Looking for private key\n");
 
   if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (GNS_cfg,
                                                             "namestore",
@@ -445,10 +448,19 @@ lookup_private_key(struct GNUNET_CRYPTO_ShortHashCode *zone)
     return NULL;
   }
 
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+              "Zonefile directory is %s\n", keydir);
+
   GNUNET_CRYPTO_short_hash_to_enc (zone, &zonename);
 
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+              "Zonefile is %s.zkey\n", &zonename);
+
   GNUNET_asprintf(&location, "%s%s%s.zkey", keydir,
-                  DIR_SEPARATOR_STR, zonename);
+                  DIR_SEPARATOR_STR, &zonename);
+
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+              "Checking for %s\n", location);
 
   if (GNUNET_YES == GNUNET_DISK_file_test (location))
     key = GNUNET_CRYPTO_rsa_key_create_from_file (location);
@@ -862,7 +874,7 @@ handle_lookup(void *cls,
       key = zone_key;
     else
     {
-      key = lookup_private_key(&sh_msg->zone);
+      key = lookup_private_key(&zone);
       clh->zone_key = key;
     }