broken build
[oweals/gnunet.git] / src / gns / gnunet-service-gns_resolver.c
index 2a51d29727636784a0c20ac08bb965c1951dd34f..68996a2040392028e192ffd66eb86f16ff2fe1fa 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     (C) 2009, 2010, 2011 Christian Grothoff (and other contributing authors)
+     (C) 2009, 2010, 2011, 2012, 2013 Christian Grothoff (and other contributing authors)
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -22,6 +22,7 @@
  * @file gns/gnunet-service-gns_resolver.c
  * @brief GNUnet GNS resolver logic
  * @author Martin Schanzenbach
+ * @author Christian Grothoff
  */
 #include "platform.h"
 #include "gnunet_util_lib.h"
@@ -223,7 +224,7 @@ free_get_pseu_authority_handle (struct GetPseuAuthorityHandle *gph)
 {
   gph->namestore_task = NULL;
   GNUNET_free (gph->auth);
-  GNUNET_CRYPTO_rsa_key_free (gph->key);
+  GNUNET_CRYPTO_ecc_key_free (gph->key);
   GNUNET_CONTAINER_DLL_remove (gph_head, gph_tail, gph);
   GNUNET_free (gph);
 }
@@ -269,11 +270,11 @@ create_pkey_cont (void* cls, int32_t success, const char* emsg)
  */
 static void
 process_pseu_lookup_ns (void* cls,
-                       const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *key,
+                       const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *key,
                        struct GNUNET_TIME_Absolute expiration,
                        const char *name, unsigned int rd_count,
                        const struct GNUNET_NAMESTORE_RecordData *rd,
-                       const struct GNUNET_CRYPTO_RsaSignature *signature)
+                       const struct GNUNET_CRYPTO_EccSignature *signature)
 {
   struct GetPseuAuthorityHandle* gph = cls;
   struct GNUNET_NAMESTORE_RecordData new_pkey;
@@ -299,12 +300,13 @@ process_pseu_lookup_ns (void* cls,
   new_pkey.flags = GNUNET_NAMESTORE_RF_AUTHORITY
                  | GNUNET_NAMESTORE_RF_PRIVATE
                  | GNUNET_NAMESTORE_RF_PENDING;
-  gph->namestore_task = GNUNET_NAMESTORE_record_create (namestore_handle,
-                                                       gph->key,
-                                                       gph->test_name,
-                                                       &new_pkey,
-                                                       &create_pkey_cont, 
-                                                       gph);
+  gph->namestore_task = GNUNET_NAMESTORE_record_put_by_authority (namestore_handle,
+                                                                 gph->key,
+                                                                 gph->test_name,
+                                                                 1,
+                                                                 &new_pkey,
+                                                                 &create_pkey_cont, 
+                                                                 gph);
 }
 
 
@@ -462,12 +464,12 @@ process_auth_discovery_dht_result (void* cls,
  */
 static void
 process_auth_discovery_ns_result (void* cls,
-                      const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *key,
+                      const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *key,
                       struct GNUNET_TIME_Absolute expiration,
                       const char *name,
                       unsigned int rd_count,
                       const struct GNUNET_NAMESTORE_RecordData *rd,
-                      const struct GNUNET_CRYPTO_RsaSignature *signature)
+                      const struct GNUNET_CRYPTO_EccSignature *signature)
 {
   struct GetPseuAuthorityHandle* gph = cls;
   struct GNUNET_HashCode lookup_key;
@@ -535,12 +537,12 @@ process_auth_discovery_ns_result (void* cls,
  */
 static void
 process_zone_to_name_discover (void *cls,
-                 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
+                 const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *zone_key,
                  struct GNUNET_TIME_Absolute expire,
                  const char *name,
                  unsigned int rd_len,
                  const struct GNUNET_NAMESTORE_RecordData *rd,
-                 const struct GNUNET_CRYPTO_RsaSignature *signature)
+                 const struct GNUNET_CRYPTO_EccSignature *signature)
 {
   struct GetPseuAuthorityHandle* gph = cls;
   
@@ -591,31 +593,33 @@ shorten_authority_chain (struct GetPseuAuthorityHandle *gph)
  */
 static void
 start_shorten (struct AuthorityChain *auth,
-               const struct GNUNET_CRYPTO_RsaPrivateKey *key)
+               const struct GNUNET_CRYPTO_EccPrivateKey *key)
 {
   struct GetPseuAuthorityHandle *gph;
-  struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pkey;
-  struct GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded *pb_key;
+  struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pkey;
+  struct GNUNET_CRYPTO_EccPrivateKeyBinaryEncoded *pb_key;
   
-  GNUNET_CRYPTO_rsa_key_get_public (key, &pkey);
-  if (NULL == (pb_key = GNUNET_CRYPTO_rsa_encode_key (key)))
+  GNUNET_CRYPTO_ecc_key_get_public (key, &pkey);
+  if (NULL == (pb_key = GNUNET_CRYPTO_ecc_encode_key (key)))
   {
     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                "Failed to encode RSA key on shorten\n");
+                "Failed to encode ECC key on shorten\n");
     return;
   }
-  gph = GNUNET_malloc (sizeof (struct GetPseuAuthorityHandle));
-  gph->key = GNUNET_CRYPTO_rsa_decode_key ((const char*) pb_key, ntohs (pb_key->len));
+  gph = GNUNET_new (struct GetPseuAuthorityHandle);
+  gph->key = GNUNET_CRYPTO_ecc_decode_key ((const char*) pb_key, 
+                                          ntohs (pb_key->size),
+                                          GNUNET_YES);
   GNUNET_free (pb_key);
   if (NULL == gph->key)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                "Failed to decode RSA key on shorten\n");
+                "Failed to decode ECC key on shorten\n");
     GNUNET_free (gph);
     return;
   }
   GNUNET_CRYPTO_short_hash (&pkey,
-                        sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
+                        sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded),
                         &gph->our_zone);
   gph->auth = GNUNET_malloc (sizeof (struct AuthorityChain));
   memcpy (gph->auth, auth, sizeof (struct AuthorityChain));
@@ -1153,11 +1157,11 @@ resolve_record_dht (struct ResolverHandle *rh)
  */
 static void
 process_record_result_ns (void* cls,
-                          const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *key,
+                          const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *key,
                           struct GNUNET_TIME_Absolute expiration,
                           const char *name, unsigned int rd_count,
                           const struct GNUNET_NAMESTORE_RecordData *rd,
-                          const struct GNUNET_CRYPTO_RsaSignature *signature)
+                          const struct GNUNET_CRYPTO_EccSignature *signature)
 {
   struct ResolverHandle *rh = cls;
   struct RecordLookupHandle *rlh = rh->proc_cls;
@@ -1168,7 +1172,7 @@ process_record_result_ns (void* cls,
 
   rh->namestore_task = NULL;
   GNUNET_CRYPTO_short_hash (key,
-                           sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
+                           sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded),
                            &zone);
   remaining_time = GNUNET_TIME_absolute_get_remaining (expiration);
   rh->status = 0;
@@ -1745,7 +1749,8 @@ resolve_record_dns (struct ResolverHandle *rh,
   sa->sa_family = AF_INET;
   if (GNUNET_OK != GNUNET_NETWORK_socket_bind (rh->dns_sock,
                                                sa,
-                                               sizeof (struct sockaddr_in)))
+                                               sizeof (struct sockaddr_in),
+                                               0))
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "GNS_PHASE_REC_DNS-%llu: Error binding UDP socket for DNS lookup!\n",
@@ -2033,12 +2038,12 @@ handle_delegation_ns (void* cls, struct ResolverHandle *rh,
  */
 static void
 process_pkey_revocation_result_ns (void *cls,
-                                  const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *key,
+                                  const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *key,
                                   struct GNUNET_TIME_Absolute expiration,
                                   const char *name,
                                   unsigned int rd_count,
                                   const struct GNUNET_NAMESTORE_RecordData *rd,
-                                  const struct GNUNET_CRYPTO_RsaSignature *signature)
+                                  const struct GNUNET_CRYPTO_EccSignature *signature)
 {
   struct ResolverHandle *rh = cls;
   struct GNUNET_TIME_Relative remaining_time;
@@ -3062,12 +3067,12 @@ handle_delegation_ns (void* cls, struct ResolverHandle *rh,
  */
 static void
 process_delegation_result_ns (void* cls,
-                             const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *key,
+                             const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *key,
                              struct GNUNET_TIME_Absolute expiration,
                              const char *name,
                              unsigned int rd_count,
                              const struct GNUNET_NAMESTORE_RecordData *rd,
-                             const struct GNUNET_CRYPTO_RsaSignature *signature)
+                             const struct GNUNET_CRYPTO_EccSignature *signature)
 {
   struct ResolverHandle *rh = cls;
   struct GNUNET_TIME_Relative remaining_time;
@@ -3079,7 +3084,7 @@ process_delegation_result_ns (void* cls,
  
   rh->namestore_task = NULL;
   GNUNET_CRYPTO_short_hash (key,
-                           sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
+                           sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded),
                            &zone);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "GNS_PHASE_DELEGATE_NS-%llu: Got %d records from authority lookup for `%s' in zone %s\n",
@@ -3325,7 +3330,7 @@ gns_resolver_lookup_record (struct GNUNET_CRYPTO_ShortHashCode zone,
                             struct GNUNET_CRYPTO_ShortHashCode pzone,
                             uint32_t record_type,
                             const char* name,
-                            struct GNUNET_CRYPTO_RsaPrivateKey *key,
+                            struct GNUNET_CRYPTO_EccPrivateKey *key,
                             struct GNUNET_TIME_Relative timeout,
                             int only_cached,
                             RecordLookupProcessor proc,
@@ -3508,12 +3513,12 @@ finish_shorten (struct ResolverHandle *rh,
  */
 static void
 process_zone_to_name_shorten_root (void *cls,
-                 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
+                 const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *zone_key,
                  struct GNUNET_TIME_Absolute expire,
                  const char *name,
                  unsigned int rd_len,
                  const struct GNUNET_NAMESTORE_RecordData *rd,
-                 const struct GNUNET_CRYPTO_RsaSignature *signature);
+                 const struct GNUNET_CRYPTO_EccSignature *signature);
 
 
 /**
@@ -3530,12 +3535,12 @@ process_zone_to_name_shorten_root (void *cls,
  */
 static void
 process_zone_to_name_shorten_shorten (void *cls,
-                 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
+                 const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *zone_key,
                  struct GNUNET_TIME_Absolute expire,
                  const char *name,
                  unsigned int rd_len,
                  const struct GNUNET_NAMESTORE_RecordData *rd,
-                 const struct GNUNET_CRYPTO_RsaSignature *signature)
+                 const struct GNUNET_CRYPTO_EccSignature *signature)
 {
   struct ResolverHandle *rh = cls;
   struct NameShortenHandle* nsh = rh->proc_cls;
@@ -3646,12 +3651,12 @@ process_zone_to_name_shorten_shorten (void *cls,
  */
 static void
 process_zone_to_name_shorten_private (void *cls,
-                 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
+                 const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *zone_key,
                  struct GNUNET_TIME_Absolute expire,
                  const char *name,
                  unsigned int rd_len,
                  const struct GNUNET_NAMESTORE_RecordData *rd,
-                 const struct GNUNET_CRYPTO_RsaSignature *signature)
+                 const struct GNUNET_CRYPTO_EccSignature *signature)
 {
   struct ResolverHandle *rh = cls;
   struct NameShortenHandle* nsh = rh->proc_cls;
@@ -3761,12 +3766,12 @@ process_zone_to_name_shorten_private (void *cls,
  */
 static void
 process_zone_to_name_shorten_root (void *cls,
-                 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
+                 const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *zone_key,
                  struct GNUNET_TIME_Absolute expire,
                  const char *name,
                  unsigned int rd_len,
                  const struct GNUNET_NAMESTORE_RecordData *rd,
-                 const struct GNUNET_CRYPTO_RsaSignature *signature)
+                 const struct GNUNET_CRYPTO_EccSignature *signature)
 {
   struct ResolverHandle *rh = cls;
   struct NameShortenHandle* nsh = rh->proc_cls;
@@ -3984,12 +3989,12 @@ handle_delegation_ns_shorten (void* cls,
  */
 static void
 process_zone_to_name_zkey(void *cls,
-                 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
+                 const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *zone_key,
                  struct GNUNET_TIME_Absolute expire,
                  const char *name,
                  unsigned int rd_len,
                  const struct GNUNET_NAMESTORE_RecordData *rd,
-                 const struct GNUNET_CRYPTO_RsaSignature *signature)
+                 const struct GNUNET_CRYPTO_EccSignature *signature)
 {
   struct ResolverHandle *rh = cls;
   struct NameShortenHandle *nsh = rh->proc_cls;