Merge branch 'master' of gnunet.org:gnunet
authorNils Gillmann <ng0@n0.is>
Mon, 14 May 2018 07:11:13 +0000 (07:11 +0000)
committerNils Gillmann <ng0@n0.is>
Mon, 14 May 2018 07:11:13 +0000 (07:11 +0000)
102 files changed:
contrib/no_autostart_above_core.conf
contrib/no_forcestart.conf
contrib/visualize_stats.sh
contrib/zonewalk-to-types.sh [new file with mode: 0755]
doc/documentation/tutorial-examples/005.c
doc/man/gnunet-zoneimport.1
src/abe/abe.c
src/credential/gnunet-service-credential.c
src/credential/plugin_gnsrecord_credential.c
src/credential/plugin_rest_credential.c
src/dns/Makefile.am
src/dns/dnsparser.c
src/dns/dnsstub.c
src/dns/gnunet-zoneimport.c [deleted file]
src/dns/gnunet-zonewalk.c [new file with mode: 0644]
src/fs/gnunet-service-fs_indexing.c
src/gns/.gitignore
src/gns/Makefile.am
src/gns/gns.conf.in
src/gns/gns_api.c
src/gns/gnunet-gns-benchmark.c [new file with mode: 0644]
src/gns/gnunet-service-gns_resolver.c
src/gns/plugin_gnsrecord_gns.c
src/gns/test_gns_at_lookup.sh [new file with mode: 0755]
src/gns/test_gns_cname_lookup.sh
src/gns/test_gns_delegated_lookup.sh
src/gns/test_gns_dht_lookup.sh
src/gns/test_gns_gns2dns_lookup.sh
src/gns/test_gns_ipv6_lookup.sh
src/gns/test_gns_mx_lookup.sh
src/gns/test_gns_plus_lookup.sh [deleted file]
src/gns/test_gns_quickupdate.sh
src/gns/test_gns_rel_expiration.sh
src/gns/test_gns_revocation.sh
src/gns/test_gns_soa_lookup.sh
src/gns/test_gns_txt_lookup.sh
src/gns/test_gns_zkey_lookup.sh
src/gnsrecord/.gitignore
src/gnsrecord/Makefile.am
src/gnsrecord/gnsrecord.c
src/gnsrecord/gnsrecord_crypto.c
src/gnsrecord/gnsrecord_serialization.c
src/gnsrecord/perf_gnsrecord_crypto.c [new file with mode: 0644]
src/gnsrecord/test_gnsrecord_crypto.c
src/hostlist/test_gnunet_daemon_hostlist.c
src/hostlist/test_gnunet_daemon_hostlist_learning.c
src/hostlist/test_gnunet_daemon_hostlist_reconnect.c
src/identity-provider/identity_provider_api.c
src/include/gnunet_disk_lib.h
src/include/gnunet_sq_lib.h
src/multicast/test_multicast_2peers.c
src/multicast/test_multicast_multipeer.c
src/namestore/gnunet-namestore.c
src/namestore/gnunet-service-namestore.c
src/namestore/gnunet-zoneimport.c
src/namestore/namestore_api.c
src/namestore/perf_namestore_api_flat.conf
src/namestore/perf_namestore_api_postgres.conf
src/namestore/perf_namestore_api_sqlite.conf
src/namestore/perf_namestore_api_zone_iteration.c
src/namestore/plugin_namestore_flat.c
src/namestore/plugin_namestore_sqlite.c
src/namestore/test_namestore_api.conf
src/namestore/test_namestore_api_flat.conf
src/namestore/test_namestore_api_lookup_nick.c
src/namestore/test_namestore_api_lookup_private.c
src/namestore/test_namestore_api_lookup_public.c
src/namestore/test_namestore_api_lookup_shadow.c
src/namestore/test_namestore_api_lookup_shadow_filter.c
src/namestore/test_namestore_api_monitoring.c
src/namestore/test_namestore_api_monitoring_existing.c
src/namestore/test_namestore_api_postgres.conf
src/namestore/test_namestore_api_remove.c
src/namestore/test_namestore_api_remove_not_existing_record.c
src/namestore/test_namestore_api_sqlite.conf
src/namestore/test_namestore_api_store.c
src/namestore/test_namestore_api_store_update.c
src/namestore/test_namestore_api_zone_iteration.c
src/namestore/test_namestore_api_zone_iteration_nick.c
src/namestore/test_namestore_api_zone_iteration_specific_zone.c
src/namestore/test_namestore_api_zone_iteration_stop.c
src/namestore/test_namestore_api_zone_to_name.c
src/namestore/test_plugin_namestore.c
src/namestore/test_plugin_namestore_flat.conf
src/nat/gnunet-helper-nat-client.c
src/nat/gnunet-helper-nat-server.c
src/nat/gnunet-service-nat.c
src/regex/regex_test_lib.c
src/rps/test_rps.c
src/sq/Makefile.am
src/sq/sq_exec.c [new file with mode: 0644]
src/sq/sq_prepare.c [new file with mode: 0644]
src/statistics/test_gnunet_statistics.py.in
src/statistics/test_statistics_api_data.conf
src/transport/test_plugin_transport.c
src/util/crypto_abe.c
src/util/disk.c
src/zonemaster/.gitignore
src/zonemaster/Makefile.am
src/zonemaster/gnunet-service-zonemaster-monitor.c [new file with mode: 0644]
src/zonemaster/gnunet-service-zonemaster.c
src/zonemaster/zonemaster.conf.in

index 81c01898f3fb92d552ed578c84a2c8b8b033a1a6..7bcf6c8ae12b618f84f4b3ee88d7f153a0a93c6b 100644 (file)
@@ -85,3 +85,6 @@ AUTOSTART = NO
 
 [sensor]
 AUTOSTART = NO
+
+[zonemaster-monitor]
+AUTOSTART = NO
index e21187ed21d18cb18a155027f73cfdf709a34774..a332d6da7dc7859d32c72ee2427cb7f1721feb0b 100644 (file)
@@ -35,4 +35,7 @@ FORCESTART = NO
 FORCESTART = NO
 
 [zonemaster]
-FORCESTART = NO
\ No newline at end of file
+FORCESTART = NO
+
+[zonemaster-monitor]
+FORCESTART = NO
index 87d8fc6c4cfb69602bef6cf398c798a8b52a93dd..aaa5e657b80b5919711aa83b1b9c499939b6242d 100755 (executable)
@@ -34,7 +34,7 @@ case "$1" in
        NOW=`date +%s`
        RELAT=$[$NOW-$STARTTIME]
        gnunet-statistics | while read KEY VALUE; do
-               
+               KEY=`echo $KEY | tr / .`
                # Collect stats of previous round
                if [ -e "$STATDIR/$KEY.dat" ]; then
                        PREV=`tail --lines=1 "$STATDIR/$KEY.dat" | sed -e "s/.* //g"`
diff --git a/contrib/zonewalk-to-types.sh b/contrib/zonewalk-to-types.sh
new file mode 100755 (executable)
index 0000000..c453702
--- /dev/null
@@ -0,0 +1,35 @@
+#!/bin/sh
+# This script is in the public domain.
+# Converts the output of gnunet-zonewalk (DNS resolutions)
+# into a proper input for gnunet-gns-benchmark.
+
+NUM_CLIENTS=3
+# How many different groups of names should we
+# create?  1/N will be in the 'shared' group.
+
+# FILE ($1) contains results from DNS lookup; strip
+# everything but the hostnames, remove duplicates
+# and then randomize the order.
+cat $1 | awk '{print $1}' | sort | uniq | shuf > $1.tmp
+TOTAL=`cat $1.tmp | wc -l`
+GROUP_SIZE=`expr $TOTAL / \( $NUM_TYPES + 1 \)`
+
+# First group (0) is to be shared among all clients
+for i in `seq 1 $NUM_CLIENTS`
+do
+  cat $1.tmp | head -n $GROUP_SIZE | awk "{print 0 \" \" \$1}" > $1.$i.tmp
+done
+
+# Second group (1) is unique per client
+OFF=0
+for i in `seq 1 $NUM_CLIENTS`
+do
+  END=`expr $OFF + $GROUP_SIZE`
+  cat $1.tmp | head -n $END | tail -n $GROUP_SIZE | awk "{print 1 \" \" \$1}" >> $1.$i.tmp
+# Shuffle again, so we mix the different request categories in terms of
+# when we issue the queries.
+  cat $1.$i.tmp | shuf > $1.$i
+  OFF="$END"
+  rm $1.$i.tmp
+done
+rm $1.tmp
index 0c459f509d1c4ad86497d7ccf0a418fc9927fa09..1b59f85a6bef1dafbd4ee88e3cfcc3a7211a3561 100644 (file)
@@ -2,7 +2,8 @@ struct GNUNET_MQ_Envelope *env;
 struct GNUNET_MessageHeader *msg;
 
 env = GNUNET_MQ_msg_extra (msg, payload_size, GNUNET_MY_MESSAGE_TYPE);
-memcpy (&msg[1], &payload, payload_size);
+GNUNET_memcpy (&msg[1],
+               &payload,
+               payload_size);
 // Send message via message queue 'mq'
 GNUNET_mq_send (mq, env);
-
index bcfa7b734b42ffc5192c46b066ac5b1a2d60be82..cf76b86eed4540b566fe66e63fbfb5685cea6c89 100644 (file)
@@ -48,6 +48,14 @@ Use the configuration file FILENAME.
 .IP "\-h, \-\-help"
 Print short help on options.
 .B
+.IP "\-m RELATIVETIME, \-\-minimum-expiration=RELATIVETIME"
+.B
+Ensure that imported DNS records never have an expiration time that
+is less than RELATIVETIME into the future.  RELATIVETIME is a time
+given like "1 week" or "1 h".   If DNS returns records with a shorter
+lifetime, gnunet\-zoneimport will simply bump the lifetime to the
+specified value (relative to the time of the import). Default is zero.
+
 .IP "\-s MAPSIZE, \-\-size=MAPSIZE"
 Specifies the size (in number of entries) to use for the main hash
 map.  The value provided should be at least twice the number of domain
index 3f1f6dc5b68af35a593bb4f0ea864e732b891364..8b59953fbd0035bf79a89b46b6538493499e1abf 100644 (file)
@@ -54,12 +54,12 @@ init_aes( element_t k, int enc,
   int rc;
   int key_len;
   unsigned char* key_buf;
-  
+
   key_len = element_length_in_bytes(k) < 33 ? 3 : element_length_in_bytes(k);
   key_buf = (unsigned char*) malloc(key_len);
   element_to_bytes(key_buf, k);
 
-  memcpy (key->aes_key, key_buf, GNUNET_CRYPTO_AES_KEY_LENGTH); 
+  GNUNET_memcpy (key->aes_key, key_buf, GNUNET_CRYPTO_AES_KEY_LENGTH);
   GNUNET_assert (0 ==
                  gcry_cipher_open (handle, GCRY_CIPHER_AES256,
                                    GCRY_CIPHER_MODE_CFB, 0));
@@ -124,16 +124,16 @@ aes_128_cbc_decrypt( char* ct,
   unsigned char iv[16];
   char* tmp;
   uint32_t len;
-  
+
   init_aes(k, 1, &handle, &skey, iv);
 
   tmp = GNUNET_malloc (size);
 
   //AES_cbc_encrypt(ct->data, pt->data, ct->len, &key, iv, AES_DECRYPT);
-  GNUNET_assert (0 == gcry_cipher_decrypt (handle, tmp, size, ct, size)); 
+  GNUNET_assert (0 == gcry_cipher_decrypt (handle, tmp, size, ct, size));
   gcry_cipher_close (handle);
   /* TODO make less crufty */
-  
+
   /* get real length */
   len = 0;
   len = len
@@ -195,7 +195,7 @@ GNUNET_ABE_cpabe_create_key (struct GNUNET_ABE_AbeMasterKey *key,
   struct GNUNET_ABE_AbeKey *prv_key;
   int size;
   char *tmp;
-  
+
   prv_key = GNUNET_new (struct GNUNET_ABE_AbeKey);
   prv_key->prv = gabe_keygen(key->pub, key->msk, attrs);
   size = gabe_pub_serialize(key->pub, &tmp);
@@ -234,7 +234,7 @@ write_cpabe (void **result,
 {
   char *ptr;
   uint32_t *len;
-  
+
   *result = GNUNET_malloc (12 + cph_buf_len + aes_buf_len);
   ptr = *result;
   len = (uint32_t*) ptr;
@@ -243,12 +243,12 @@ write_cpabe (void **result,
   len = (uint32_t*) ptr;
   *len = htonl (aes_buf_len);
   ptr += 4;
-  memcpy (ptr, aes_buf, aes_buf_len);
+  GNUNET_memcpy (ptr, aes_buf, aes_buf_len);
   ptr += aes_buf_len;
   len = (uint32_t*) ptr;
   *len = htonl (cph_buf_len);
   ptr += 4;
-  memcpy (ptr, cph_buf, cph_buf_len);
+  GNUNET_memcpy (ptr, cph_buf, cph_buf_len);
   return 12 + cph_buf_len + aes_buf_len;
 }
 
@@ -271,13 +271,13 @@ read_cpabe (const void *data,
   *aes_buf_len = ntohl (*len);
   ptr += 4;
   *aes_buf = GNUNET_malloc (*aes_buf_len);
-  memcpy(*aes_buf, ptr, *aes_buf_len);
+  GNUNET_memcpy(*aes_buf, ptr, *aes_buf_len);
   ptr += *aes_buf_len;
   len = (uint32_t*)ptr;
   *cph_buf_len = ntohl (*len);
   ptr += 4;
   *cph_buf = GNUNET_malloc (*cph_buf_len);
-  memcpy(*cph_buf, ptr, *cph_buf_len);
+  GNUNET_memcpy(*cph_buf, ptr, *cph_buf_len);
 
   return buf_len;
 }
@@ -429,7 +429,7 @@ GNUNET_ABE_cpabe_deserialize_key (const void *data,
               &prv_len);
   key->pub = gabe_pub_unserialize (pub, pub_len);
   key->prv = gabe_prv_unserialize (key->pub, prv, prv_len);
-  
+
   GNUNET_free (pub);
   GNUNET_free (prv);
   return key;
@@ -491,7 +491,7 @@ GNUNET_ABE_cpabe_deserialize_master_key (const void *data,
               &msk_len);
   key->pub = gabe_pub_unserialize (pub, pub_len);
   key->msk = gabe_msk_unserialize (key->pub, msk, msk_len);
-  
+
   GNUNET_free (pub);
   GNUNET_free (msk);
 
index 399371a2ea227f56f78f45537b99900cf4c27590..29bdf63d825385228cf12fe251360507cef6af88 100644 (file)
@@ -61,17 +61,17 @@ struct DelegationChainEntry
    * The issuer
    */
   struct GNUNET_CRYPTO_EcdsaPublicKey issuer_key;
-  
+
   /**
    * The subject
    */
   struct GNUNET_CRYPTO_EcdsaPublicKey subject_key;
-  
+
   /**
    * The issued attribute
    */
   char *issuer_attribute;
-  
+
   /**
    * The delegated attribute
    */
@@ -92,7 +92,7 @@ struct CredentialRecordEntry
    * DLL
    */
   struct CredentialRecordEntry *prev;
-  
+
   /**
    * Number of references in delegation chains
    */
@@ -409,7 +409,7 @@ cleanup_handle (struct VerifyRequestHandle *vrh)
   }
   cleanup_delegation_set (vrh->root_set);
   GNUNET_free_non_null (vrh->issuer_attribute);
-  for (cr_entry = vrh->cred_chain_head; 
+  for (cr_entry = vrh->cred_chain_head;
        NULL != vrh->cred_chain_head;
        cr_entry = vrh->cred_chain_head)
   {
@@ -543,7 +543,7 @@ send_lookup_response (struct VerifyRequestHandle *vrh)
   else
     rmsg->cred_found = htonl (GNUNET_NO);
 
-  GNUNET_assert (-1 != 
+  GNUNET_assert (-1 !=
                  GNUNET_CREDENTIAL_delegation_chain_serialize (vrh->delegation_chain_size,
                                                                dd,
                                                                vrh->cred_chain_size,
@@ -587,7 +587,7 @@ backward_resolution (void* cls,
               "Got %d attrs\n", rd_count);
 
   // Each OR
-  for (uint32_t i=0; i < rd_count; i++) 
+  for (uint32_t i=0; i < rd_count; i++)
   {
     if (GNUNET_GNSRECORD_TYPE_ATTRIBUTE != rd[i].record_type)
       continue;
@@ -665,10 +665,10 @@ backward_resolution (void* cls,
       /**
        * Check if this delegation already matches one of our credentials
        */
-      for(cred_pointer = vrh->cred_chain_head; cred_pointer != NULL; 
+      for(cred_pointer = vrh->cred_chain_head; cred_pointer != NULL;
           cred_pointer = cred_pointer->next)
       {
-        if(0 != memcmp (&set->subject_key, 
+        if(0 != memcmp (&set->subject_key,
                         &cred_pointer->credential->issuer_key,
                         sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)))
           continue;
@@ -769,7 +769,7 @@ backward_resolution (void* cls,
     return;
 
   }
-} 
+}
 
 
 /**
@@ -809,7 +809,7 @@ delegation_chain_resolution_start (void* cls)
   }
 
   /**
-   * Check for attributes from the issuer and follow the chain 
+   * Check for attributes from the issuer and follow the chain
    * till you get the required subject's attributes
    */
   char issuer_attribute_name[strlen (vrh->issuer_attribute) + strlen (".gnu") + 1];
@@ -821,9 +821,9 @@ delegation_chain_resolution_start (void* cls)
               "Looking up %s\n", issuer_attribute_name);
   ds_entry = GNUNET_new (struct DelegationSetQueueEntry);
   ds_entry->issuer_key = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPublicKey);
-  memcpy (ds_entry->issuer_key,
-          &vrh->issuer_key,
-          sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey));
+  GNUNET_memcpy (ds_entry->issuer_key,
+                 &vrh->issuer_key,
+                 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey));
   ds_entry->issuer_attribute = GNUNET_strdup (vrh->issuer_attribute);
   ds_entry->handle = vrh;
   ds_entry->lookup_attribute = GNUNET_strdup (vrh->issuer_attribute);
@@ -869,7 +869,7 @@ check_verify (void *cls,
 
 static void
 handle_verify (void *cls,
-               const struct VerifyMessage *v_msg) 
+               const struct VerifyMessage *v_msg)
 {
   struct VerifyRequestHandle *vrh;
   struct GNUNET_SERVICE_Client *client = cls;
@@ -886,7 +886,9 @@ handle_verify (void *cls,
               "Received VERIFY message\n");
   utf_in = (const char *) &v_msg[1];
   GNUNET_STRINGS_utf8_tolower (utf_in, attrptr);
-  GNUNET_memcpy (issuer_attribute, attr, ntohs (v_msg->issuer_attribute_len));
+  GNUNET_memcpy (issuer_attribute,
+                 attr,
+                 ntohs (v_msg->issuer_attribute_len));
   issuer_attribute[ntohs (v_msg->issuer_attribute_len)] = '\0';
   vrh = GNUNET_new (struct VerifyRequestHandle);
   GNUNET_CONTAINER_DLL_insert (vrh_head, vrh_tail, vrh);
@@ -897,7 +899,7 @@ handle_verify (void *cls,
   vrh->issuer_attribute = GNUNET_strdup (issuer_attribute);
   if (0 == strlen (issuer_attribute))
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "No issuer attribute provided!\n");
     send_lookup_response (vrh);
     return;
@@ -907,7 +909,7 @@ handle_verify (void *cls,
    * TODO: cleanup!
    */
   credentials_count = ntohl(v_msg->c_count);
-  credential_data_size = ntohs (v_msg->header.size) 
+  credential_data_size = ntohs (v_msg->header.size)
     - sizeof (struct VerifyMessage)
     - ntohs (v_msg->issuer_attribute_len)
     - 1;
@@ -918,7 +920,7 @@ handle_verify (void *cls,
                                                               credentials_count,
                                                               credentials))
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "Cannot deserialize credentials!\n");
     send_lookup_response (vrh);
     return;
@@ -1015,7 +1017,7 @@ handle_cred_collection_finished_cb (void *cls)
 
 static void
 handle_collect (void *cls,
-                const struct CollectMessage *c_msg) 
+                const struct CollectMessage *c_msg)
 {
   char attr[GNUNET_CREDENTIAL_MAX_LENGTH + 1];
   char issuer_attribute[GNUNET_CREDENTIAL_MAX_LENGTH + 1];
@@ -1030,7 +1032,9 @@ handle_collect (void *cls,
   utf_in = (const char *) &c_msg[1];
   GNUNET_STRINGS_utf8_tolower (utf_in, attrptr);
 
-  GNUNET_memcpy (issuer_attribute, attr, ntohs (c_msg->issuer_attribute_len));
+  GNUNET_memcpy (issuer_attribute,
+                 attr,
+                 ntohs (c_msg->issuer_attribute_len));
   issuer_attribute[ntohs (c_msg->issuer_attribute_len)] = '\0';
   vrh = GNUNET_new (struct VerifyRequestHandle);
   GNUNET_CONTAINER_DLL_insert (vrh_head, vrh_tail, vrh);
@@ -1043,7 +1047,7 @@ handle_collect (void *cls,
 
   if (0 == strlen (issuer_attribute))
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "No issuer attribute provided!\n");
     send_lookup_response (vrh);
     return;
index ffb2857dc125fb858ccbb397fafc5485fdf88061..cba362a50484162ba35b51062c546b14d497ae2d 100644 (file)
@@ -62,9 +62,9 @@ credential_value_to_string (void *cls,
     int i;
     if (data_size < sizeof (struct GNUNET_CREDENTIAL_DelegationRecord))
       return NULL; /* malformed */
-    memcpy (&sets,
-            data,
-            sizeof (sets));
+    GNUNET_memcpy (&sets,
+                   data,
+                   sizeof (sets));
     cdata = data;
     struct GNUNET_CREDENTIAL_DelegationSet set[ntohl(sets.set_count)];
     if (GNUNET_OK != GNUNET_CREDENTIAL_delegation_set_deserialize (GNUNET_ntohll (sets.data_size),
@@ -224,7 +224,7 @@ credential_string_to_value (void *cls,
         }
         tmp_data_size = GNUNET_CREDENTIAL_delegation_set_get_size (entries,
                                                                    set);
-        
+
         if (-1 == tmp_data_size)
         {
           GNUNET_free (tmp_str);
@@ -248,7 +248,7 @@ credential_string_to_value (void *cls,
         return GNUNET_OK;
       }
     case GNUNET_GNSRECORD_TYPE_CREDENTIAL:
-      { 
+      {
         struct GNUNET_CREDENTIAL_Credential *cred;
         cred = GNUNET_CREDENTIAL_credential_from_string (s);
 
index 2e43139de0769c798b32e411ef06a04622f88cd3..7f39b34ead28402a291f32f938081811227e6a23 100644 (file)
@@ -309,14 +309,14 @@ json_to_credential (json_t *res)
                  sig,
                  sizeof (struct GNUNET_CRYPTO_EcdsaSignature));
   GNUNET_free (sig);
+
   tmp = json_object_get (res, "expiration");
   if (0 == json_is_integer (tmp))
   {
     GNUNET_free (cred);
     return NULL;
   }
-  cred->expiration.abs_value_us = json_integer_value (tmp); 
+  cred->expiration.abs_value_us = json_integer_value (tmp);
   return cred;
 }
 
@@ -342,7 +342,7 @@ credential_to_json (struct GNUNET_CREDENTIAL_Credential *cred)
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "Issuer in credential malformed\n");
     return NULL;
-  }  
+  }
   subject = GNUNET_CRYPTO_ecdsa_public_key_to_string (&cred->subject_key);
   if (NULL == subject)
   {
@@ -354,9 +354,9 @@ credential_to_json (struct GNUNET_CREDENTIAL_Credential *cred)
   GNUNET_STRINGS_base64_encode ((char*)&cred->signature,
                                 sizeof (struct GNUNET_CRYPTO_EcdsaSignature),
                                 &signature);
-  memcpy (attribute,
-          cred->issuer_attribute,
-          cred->issuer_attribute_len);
+  GNUNET_memcpy (attribute,
+                 cred->issuer_attribute,
+                 cred->issuer_attribute_len);
   attribute[cred->issuer_attribute_len] = '\0';
   cred_obj = json_object ();
   json_object_set_new (cred_obj, "issuer", json_string (issuer));
@@ -570,7 +570,7 @@ collect_cred_cont (struct GNUNET_REST_RequestHandle *conndata_handle,
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "Missing issuer attribute\n");
-    GNUNET_SCHEDULER_add_now (&do_error, handle); 
+    GNUNET_SCHEDULER_add_now (&do_error, handle);
     return;
   }
   tmp = GNUNET_CONTAINER_multihashmap_get (conndata_handle->url_param_map,
@@ -585,7 +585,7 @@ collect_cred_cont (struct GNUNET_REST_RequestHandle *conndata_handle,
     GNUNET_SCHEDULER_add_now (&do_error, handle);
     return;
   }
-  if (GNUNET_OK != 
+  if (GNUNET_OK !=
       GNUNET_CRYPTO_ecdsa_public_key_from_string (tmp,
                                                   strlen (tmp),
                                                   &handle->issuer_key))
@@ -626,7 +626,7 @@ collect_cred_cont (struct GNUNET_REST_RequestHandle *conndata_handle,
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "Malformed subject\n");
-    GNUNET_SCHEDULER_add_now (&do_error, handle); 
+    GNUNET_SCHEDULER_add_now (&do_error, handle);
     return;
   }
   handle->ego_lookup = GNUNET_IDENTITY_ego_lookup (cfg,
@@ -679,7 +679,7 @@ verify_cred_cont (struct GNUNET_REST_RequestHandle *conndata_handle,
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "Missing issuer attribute\n");
-    GNUNET_SCHEDULER_add_now (&do_error, handle); 
+    GNUNET_SCHEDULER_add_now (&do_error, handle);
     return;
   }
   tmp = GNUNET_CONTAINER_multihashmap_get (conndata_handle->url_param_map,
@@ -694,7 +694,7 @@ verify_cred_cont (struct GNUNET_REST_RequestHandle *conndata_handle,
     GNUNET_SCHEDULER_add_now (&do_error, handle);
     return;
   }
-  if (GNUNET_OK != 
+  if (GNUNET_OK !=
       GNUNET_CRYPTO_ecdsa_public_key_from_string (tmp,
                                                   strlen (tmp),
                                                   &handle->issuer_key))
@@ -735,7 +735,7 @@ verify_cred_cont (struct GNUNET_REST_RequestHandle *conndata_handle,
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "Malformed subject\n");
-    GNUNET_SCHEDULER_add_now (&do_error, handle); 
+    GNUNET_SCHEDULER_add_now (&do_error, handle);
     return;
   }
   if (GNUNET_OK !=
@@ -946,7 +946,7 @@ get_cred_issuer_cb (void *cls,
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "Missing expiration\n");
-    GNUNET_SCHEDULER_add_now (&do_error, handle); 
+    GNUNET_SCHEDULER_add_now (&do_error, handle);
     return;
   }
   expiration_str = GNUNET_CONTAINER_multihashmap_get (handle->rest_handle->url_param_map,
@@ -955,7 +955,7 @@ get_cred_issuer_cb (void *cls,
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "Expiration malformed\n");
-    GNUNET_SCHEDULER_add_now (&do_error, handle); 
+    GNUNET_SCHEDULER_add_now (&do_error, handle);
     return;
   }
 
@@ -968,7 +968,7 @@ get_cred_issuer_cb (void *cls,
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "Malformed expiration: %s\n", expiration_str);
-    GNUNET_SCHEDULER_add_now (&do_error, handle); 
+    GNUNET_SCHEDULER_add_now (&do_error, handle);
     return;
   }
   GNUNET_CRYPTO_hash (GNUNET_REST_JSONAPI_CREDENTIAL_ISSUER_ATTR,
@@ -980,10 +980,10 @@ get_cred_issuer_cb (void *cls,
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "Missing issuer attribute\n");
-    GNUNET_SCHEDULER_add_now (&do_error, handle); 
+    GNUNET_SCHEDULER_add_now (&do_error, handle);
     return;
   }
-  handle->issuer_attr = GNUNET_strdup(GNUNET_CONTAINER_multihashmap_get 
+  handle->issuer_attr = GNUNET_strdup(GNUNET_CONTAINER_multihashmap_get
                                       (handle->rest_handle->url_param_map,
                                        &key));
   GNUNET_CRYPTO_hash (GNUNET_REST_JSONAPI_CREDENTIAL_SUBJECT_KEY,
@@ -1004,7 +1004,7 @@ get_cred_issuer_cb (void *cls,
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "Malformed subject\n");
-    GNUNET_SCHEDULER_add_now (&do_error, handle); 
+    GNUNET_SCHEDULER_add_now (&do_error, handle);
     return;
   }
   if (GNUNET_OK !=
index 8e5b06043de10770c4ec8a109baee8453e99c1df..9a4ecdcfd9eeb3c0fb33d5ddafbcfc2f8b6267a5 100644 (file)
@@ -37,7 +37,7 @@ libexec_PROGRAMS = \
 noinst_PROGRAMS = \
   gnunet-dns-monitor \
   gnunet-dns-redirector \
-  gnunet-zoneimport
+  gnunet-zonewalk
 
 plugin_LTLIBRARIES = \
   libgnunet_plugin_block_dns.la
@@ -62,9 +62,9 @@ gnunet_dns_monitor_LDADD = \
   $(top_builddir)/src/util/libgnunetutil.la \
   $(GN_LIBINTL)
 
-gnunet_zoneimport_SOURCES = \
- gnunet-zoneimport.c
-gnunet_zoneimport_LDADD = \
+gnunet_zonewalk_SOURCES = \
+ gnunet-zonewalk.c
+gnunet_zonewalk_LDADD = \
   libgnunetdnsparser.la \
   libgnunetdnsstub.la \
   $(top_builddir)/src/util/libgnunetutil.la \
index 7e200ee7cfe37e620d1b2bfe033260492c9b8786..6f9a24b7e523e84bd2d4d34bad8efac9287f2162 100644 (file)
@@ -815,7 +815,9 @@ GNUNET_DNSPARSER_builder_add_name (char *dst,
     return GNUNET_SYSERR;
 
   if (IDNA_SUCCESS !=
-      (rc = idna_to_ascii_8z (name, &idna_start, IDNA_ALLOW_UNASSIGNED)))
+      (rc = idna_to_ascii_8z (name,
+                              &idna_start,
+                              IDNA_ALLOW_UNASSIGNED)))
   {
     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
                _("Failed to convert UTF-8 name `%s' to DNS IDNA format: %s\n"),
@@ -841,7 +843,9 @@ GNUNET_DNSPARSER_builder_add_name (char *dst,
       goto fail; /* segment too long or empty */
     }
     dst[pos++] = (char) (uint8_t) len;
-    GNUNET_memcpy (&dst[pos], idna_name, len);
+    GNUNET_memcpy (&dst[pos],
+                   idna_name,
+                   len);
     pos += len;
     idna_name += len + 1; /* also skip dot */
   }
index 6eb3612c27f96dafff54b09f33ede5b70517bb1b..b1068a6de040274d7ae9d7426a788d23bcbe568e 100644 (file)
@@ -508,9 +508,10 @@ transmit_query (void *cls)
                                     sa,
                                     salen))
     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-               _("Failed to send DNS request to %s\n"),
+               _("Failed to send DNS request to %s: %s\n"),
                GNUNET_a2s (sa,
-                            salen));
+                            salen),
+                STRERROR (errno));
   else
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                _("Sent DNS request to %s\n"),
@@ -687,14 +688,14 @@ GNUNET_DNSSTUB_add_dns_sa (struct GNUNET_DNSSTUB_Context *ctx,
   switch (sa->sa_family)
   {
   case AF_INET:
-    memcpy (&ds->ss,
-            sa,
-            sizeof (struct sockaddr_in));
+    GNUNET_memcpy (&ds->ss,
+                   sa,
+                   sizeof (struct sockaddr_in));
     break;
   case AF_INET6:
-    memcpy (&ds->ss,
-            sa,
-            sizeof (struct sockaddr_in6));
+    GNUNET_memcpy (&ds->ss,
+                   sa,
+                   sizeof (struct sockaddr_in6));
     break;
   default:
     GNUNET_break (0);
diff --git a/src/dns/gnunet-zoneimport.c b/src/dns/gnunet-zoneimport.c
deleted file mode 100644 (file)
index 860672e..0000000
+++ /dev/null
@@ -1,597 +0,0 @@
-/*
-     This file is part of GNUnet
-     Copyright (C) 2018 GNUnet e.V.
-
-     GNUnet is free software; you can redistribute it and/or modify
-     it under the terms of the GNU General Public License as published
-     by the Free Software Foundation; either version 3, or (at your
-     option) any later version.
-
-     GNUnet is distributed in the hope that it will be useful, but
-     WITHOUT ANY WARRANTY; without even the implied warranty of
-     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-     General Public License for more details.
-
-     You should have received a copy of the GNU General Public License
-     along with GNUnet; see the file COPYING.  If not, write to the
-     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-     Boston, MA 02110-1301, USA.
-*/
-
-/**
- * @file src/dns/gnunet-zoneimport.c
- * @brief import a DNS zone for analysis, brute force
- * @author Christian Grothoff
- */
-#include "platform.h"
-#include <gnunet_util_lib.h>
-#include <gnunet_dnsstub_lib.h>
-#include <gnunet_dnsparser_lib.h>
-
-/**
- * Request we should make.
- */
-struct Request
-{
-  /**
-   * Requests are kept in a DLL.
-   */
-  struct Request *next;
-
-  /**
-   * Requests are kept in a DLL.
-   */
-  struct Request *prev;
-
-  /**
-   * Socket used to make the request, NULL if not active.
-   */
-  struct GNUNET_DNSSTUB_RequestSocket *rs;
-
-  /**
-   * Raw DNS query.
-   */
-  void *raw;
-
-  /**
-   * Number of bytes in @e raw.
-   */
-  size_t raw_len;
-
-  /**
-   * Hostname we are resolving.
-   */
-  char *hostname;
-
-  /**
-   * When did we last issue this request?
-   */
-  time_t time;
-
-  /**
-   * How often did we issue this query?
-   */
-  int issue_num;
-
-  /**
-   * random 16-bit DNS query identifier.
-   */
-  uint16_t id;
-};
-
-
-/**
- * Context for DNS resolution.
- */
-static struct GNUNET_DNSSTUB_Context *ctx;
-
-/**
- * The number of queries that are outstanding
- */
-static unsigned int pending;
-
-/**
- * Number of lookups we performed overall.
- */
-static unsigned int lookups;
-
-/**
- * Number of lookups that failed.
- */
-static unsigned int failures;
-
-/**
- * Number of records we found.
- */
-static unsigned int records;
-
-/**
- * Head of DLL of all requests to perform.
- */
-static struct Request *req_head;
-
-/**
- * Tail of DLL of all requests to perform.
- */
-static struct Request *req_tail;
-
-/**
- * Main task.
- */
-static struct GNUNET_SCHEDULER_Task *t;
-
-/**
- * Maximum number of queries pending at the same time.
- */
-#define THRESH 20
-
-/**
- * TIME_THRESH is in usecs.  How quickly do we submit fresh queries.
- * Used as an additional throttle.
- */
-#define TIME_THRESH 10
-
-/**
- * How often do we retry a query before giving up for good?
- */
-#define MAX_RETRIES 5
-
-
-/**
- * We received @a rec for @a req. Remember the answer.
- *
- * @param req request
- * @param rec response
- */
-static void
-process_record (struct Request *req,
-                struct GNUNET_DNSPARSER_Record *rec)
-{
-  char buf[INET6_ADDRSTRLEN];
-
-  records++;
-  switch (rec->type)
-  {
-  case GNUNET_DNSPARSER_TYPE_A:
-    fprintf (stdout,
-             "%s A %s\n",
-             req->hostname,
-             inet_ntop (AF_INET,
-                        rec->data.raw.data,
-                        buf,
-                        sizeof (buf)));
-    break;
-  case GNUNET_DNSPARSER_TYPE_AAAA:
-    fprintf (stdout,
-             "%s AAAA %s\n",
-             req->hostname,
-             inet_ntop (AF_INET6,
-                        rec->data.raw.data,
-                        buf,
-                        sizeof (buf)));
-    break;
-  case GNUNET_DNSPARSER_TYPE_NS:
-    fprintf (stdout,
-             "%s NS %s\n",
-             req->hostname,
-             rec->data.hostname);
-    break;
-  case GNUNET_DNSPARSER_TYPE_CNAME:
-    fprintf (stdout,
-             "%s CNAME %s\n",
-             req->hostname,
-             rec->data.hostname);
-    break;
-  case GNUNET_DNSPARSER_TYPE_MX:
-    fprintf (stdout,
-             "%s MX %u %s\n",
-             req->hostname,
-             (unsigned int) rec->data.mx->preference,
-             rec->data.mx->mxhost);
-    break;
-  case GNUNET_DNSPARSER_TYPE_SOA:
-    fprintf (stdout,
-             "%s SOA %s %s %u %u %u %u %u\n",
-             req->hostname,
-             rec->data.soa->mname,
-             rec->data.soa->rname,
-             (unsigned int) rec->data.soa->serial,
-             (unsigned int) rec->data.soa->refresh,
-             (unsigned int) rec->data.soa->retry,
-             (unsigned int) rec->data.soa->expire,
-             (unsigned int) rec->data.soa->minimum_ttl);
-    break;
-  case GNUNET_DNSPARSER_TYPE_SRV:
-    fprintf (stdout,
-             "%s SRV %s %u %u %u\n",
-             req->hostname,
-             rec->data.srv->target,
-             rec->data.srv->priority,
-             rec->data.srv->weight,
-             rec->data.srv->port);
-    break;
-  case GNUNET_DNSPARSER_TYPE_PTR:
-    fprintf (stdout,
-             "%s PTR %s\n",
-             req->hostname,
-             rec->data.hostname);
-    break;
-  case GNUNET_DNSPARSER_TYPE_TXT:
-    fprintf (stdout,
-             "%s TXT %.*s\n",
-             req->hostname,
-             (int) rec->data.raw.data_len,
-             (char *) rec->data.raw.data);
-    break;
-  case GNUNET_DNSPARSER_TYPE_DNAME:
-    fprintf (stdout,
-             "%s DNAME %s\n",
-             req->hostname,
-             rec->data.hostname);
-    break;
-
-    /* obscure records */
-  case GNUNET_DNSPARSER_TYPE_AFSDB:
-  case GNUNET_DNSPARSER_TYPE_NAPTR:
-  case GNUNET_DNSPARSER_TYPE_APL:
-  case GNUNET_DNSPARSER_TYPE_DHCID:
-  case GNUNET_DNSPARSER_TYPE_HIP:
-  case GNUNET_DNSPARSER_TYPE_LOC:
-  case GNUNET_DNSPARSER_TYPE_RP:
-  case GNUNET_DNSPARSER_TYPE_TKEY:
-  case GNUNET_DNSPARSER_TYPE_TSIG:
-  case GNUNET_DNSPARSER_TYPE_URI:
-  case GNUNET_DNSPARSER_TYPE_TA:
-
-    /* DNSSEC */
-  case GNUNET_DNSPARSER_TYPE_DS:
-  case GNUNET_DNSPARSER_TYPE_RRSIG:
-  case GNUNET_DNSPARSER_TYPE_NSEC:
-  case GNUNET_DNSPARSER_TYPE_DNSKEY:
-  case GNUNET_DNSPARSER_TYPE_NSEC3:
-  case GNUNET_DNSPARSER_TYPE_NSEC3PARAM:
-  case GNUNET_DNSPARSER_TYPE_CDS:
-  case GNUNET_DNSPARSER_TYPE_CDNSKEY:
-
-    /* DNSSEC payload */
-  case GNUNET_DNSPARSER_TYPE_CERT:
-  case GNUNET_DNSPARSER_TYPE_SSHFP:
-  case GNUNET_DNSPARSER_TYPE_IPSECKEY:
-  case GNUNET_DNSPARSER_TYPE_TLSA:
-  case GNUNET_DNSPARSER_TYPE_OPENPGPKEY:
-
-    /* obsolete records */
-  case GNUNET_DNSPARSER_TYPE_SIG:
-  case GNUNET_DNSPARSER_TYPE_KEY:
-  case GNUNET_DNSPARSER_TYPE_KX:
-    {
-      char *base32;
-
-      base32 = GNUNET_STRINGS_data_to_string_alloc (rec->data.raw.data,
-                                                    rec->data.raw.data_len);
-      fprintf (stdout,
-               "%s (%u) %s\n",
-               req->hostname,
-               rec->type,
-               base32);
-      GNUNET_free (base32);
-    }
-    break;
-  default:
-    fprintf (stderr,
-             "Unsupported type %u\n",
-             (unsigned int) rec->type);
-    break;
-  }
-}
-
-
-/**
- * Function called with the result of a DNS resolution.
- *
- * @param cls closure with the `struct Request`
- * @param dns dns response, never NULL
- * @param dns_len number of bytes in @a dns
- */
-static void
-process_result (void *cls,
-                const struct GNUNET_TUN_DnsHeader *dns,
-                size_t dns_len)
-{
-  struct Request *req = cls;
-  struct GNUNET_DNSPARSER_Packet *p;
-
-  if (NULL == dns)
-  {
-    /* stub gave up */
-    pending--;
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                "Stub gave up on DNS reply for `%s'\n",
-                req->hostname);
-    GNUNET_CONTAINER_DLL_remove (req_head,
-                                 req_tail,
-                                 req);
-    if (req->issue_num > MAX_RETRIES)
-    {
-      failures++;
-      GNUNET_free (req->hostname);
-      GNUNET_free (req->raw);
-      GNUNET_free (req);
-      return;
-    }
-    GNUNET_CONTAINER_DLL_insert_tail (req_head,
-                                      req_tail,
-                                      req);
-    req->rs = NULL;
-    return;
-  }
-  if (req->id != dns->id)
-    return;
-  pending--;
-  GNUNET_DNSSTUB_resolve_cancel (req->rs);
-  req->rs = NULL;
-  GNUNET_CONTAINER_DLL_remove (req_head,
-                               req_tail,
-                               req);
-  p = GNUNET_DNSPARSER_parse ((const char *) dns,
-                              dns_len);
-  if (NULL == p)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                "Failed to parse DNS reply for `%s'\n",
-                req->hostname);
-    if (req->issue_num > MAX_RETRIES)
-    {
-      failures++;
-      GNUNET_free (req->hostname);
-      GNUNET_free (req->raw);
-      GNUNET_free (req);
-      return;
-    }
-    GNUNET_CONTAINER_DLL_insert_tail (req_head,
-                                      req_tail,
-                                      req);
-    return;
-  }
-  for (unsigned int i=0;i<p->num_answers;i++)
-  {
-    struct GNUNET_DNSPARSER_Record *rs = &p->answers[i];
-
-    process_record (req,
-                    rs);
-  }
-  for (unsigned int i=0;i<p->num_authority_records;i++)
-  {
-    struct GNUNET_DNSPARSER_Record *rs = &p->authority_records[i];
-
-    process_record (req,
-                    rs);
-  }
-  for (unsigned int i=0;i<p->num_additional_records;i++)
-  {
-    struct GNUNET_DNSPARSER_Record *rs = &p->additional_records[i];
-
-    process_record (req,
-                    rs);
-  }
-  GNUNET_DNSPARSER_free_packet (p);
-  GNUNET_free (req->hostname);
-  GNUNET_free (req->raw);
-  GNUNET_free (req);
-}
-
-
-/**
- * Submit a request to DNS unless we need to slow down because
- * we are at the rate limit.
- *
- * @param req request to submit
- * @return #GNUNET_OK if request was submitted
- *         #GNUNET_NO if request was already submitted
- *         #GNUNET_SYSERR if we are at the rate limit
- */
-static int
-submit_req (struct Request *req)
-{
-  static struct timeval last_request;
-  struct timeval now;
-
-  if (NULL != req->rs)
-    return GNUNET_NO; /* already submitted */
-  gettimeofday (&now,
-                NULL);
-  if ( ( ( (now.tv_sec - last_request.tv_sec) == 0) &&
-         ( (now.tv_usec - last_request.tv_usec) < TIME_THRESH) ) ||
-       (pending >= THRESH) )
-    return GNUNET_SYSERR;
-  GNUNET_assert (NULL == req->rs);
-  req->rs = GNUNET_DNSSTUB_resolve (ctx,
-                                    req->raw,
-                                    req->raw_len,
-                                    &process_result,
-                                    req);
-  GNUNET_assert (NULL != req->rs);
-  req->issue_num++;
-  last_request = now;
-  lookups++;
-  pending++;
-  req->time = time (NULL);
-  return GNUNET_OK;
-}
-
-
-/**
- * Process as many requests as possible from the queue.
- *
- * @param cls NULL
- */
-static void
-process_queue(void *cls)
-{
-  (void) cls;
-  t = NULL;
-  for (struct Request *req = req_head;
-       NULL != req;
-       req = req->next)
-  {
-    if (GNUNET_SYSERR == submit_req (req))
-      break;
-  }
-  if (NULL != req_head)
-    t = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS,
-                                  &process_queue,
-                                  NULL);
-  else
-    GNUNET_SCHEDULER_shutdown ();
-}
-
-
-/**
- * Clean up and terminate the process.
- *
- * @param cls NULL
- */
-static void
-do_shutdown (void *cls)
-{
-  (void) cls;
-  if (NULL != t)
-  {
-    GNUNET_SCHEDULER_cancel (t);
-    t = NULL;
-  }
-  GNUNET_DNSSTUB_stop (ctx);
-  ctx = NULL;
-}
-
-
-/**
- * Process requests from the queue, then if the queue is
- * not empty, try again.
- *
- * @param cls NULL
- */
-static void
-run (void *cls)
-{
-  (void) cls;
-
-  GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
-                                 NULL);
-  t = GNUNET_SCHEDULER_add_now (&process_queue,
-                                NULL);
-}
-
-
-/**
- * Add @a hostname to the list of requests to be made.
- *
- * @param hostname name to resolve
- */
-static void
-queue (const char *hostname)
-{
-  struct GNUNET_DNSPARSER_Packet p;
-  struct GNUNET_DNSPARSER_Query q;
-  struct Request *req;
-  char *raw;
-  size_t raw_size;
-
-  if (GNUNET_OK !=
-      GNUNET_DNSPARSER_check_name (hostname))
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                "Refusing invalid hostname `%s'\n",
-                hostname);
-    return;
-  }
-  q.name = (char *) hostname;
-  q.type = GNUNET_DNSPARSER_TYPE_NS;
-  q.dns_traffic_class = GNUNET_TUN_DNS_CLASS_INTERNET;
-
-  memset (&p,
-          0,
-          sizeof (p));
-  p.num_queries = 1;
-  p.queries = &q;
-  p.id = (uint16_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE,
-                                              UINT16_MAX);
-
-  if (GNUNET_OK !=
-      GNUNET_DNSPARSER_pack (&p,
-                             UINT16_MAX,
-                             &raw,
-                             &raw_size))
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                "Failed to pack query for hostname `%s'\n",
-                hostname);
-    return;
-  }
-
-  req = GNUNET_new (struct Request);
-  req->hostname = strdup (hostname);
-  req->raw = raw;
-  req->raw_len = raw_size;
-  req->id = p.id;
-  GNUNET_CONTAINER_DLL_insert_tail (req_head,
-                                    req_tail,
-                                    req);
-}
-
-
-/**
- * Call with IP address of resolver to query.
- *
- * @param argc should be 2
- * @param argv[1] should contain IP address
- * @return 0 on success
- */
-int
-main (int argc,
-      char **argv)
-{
-  char hn[256];
-
-  if (2 != argc)
-  {
-    fprintf (stderr,
-             "Missing required configuration argument\n");
-    return -1;
-  }
-  ctx = GNUNET_DNSSTUB_start (256);
-  if (NULL == ctx)
-  {
-    fprintf (stderr,
-             "Failed to initialize GNUnet DNS STUB\n");
-    return 1;
-  }
-  if (GNUNET_OK !=
-      GNUNET_DNSSTUB_add_dns_ip (ctx,
-                                 argv[1]))
-  {
-    fprintf (stderr,
-             "Failed to use `%s' for DNS resolver\n",
-             argv[1]);
-    return 1;
-  }
-
-  while (NULL !=
-         fgets (hn,
-                sizeof (hn),
-                stdin))
-  {
-    if (strlen(hn) > 0)
-      hn[strlen(hn)-1] = '\0'; /* eat newline */
-    queue (hn);
-  }
-  GNUNET_SCHEDULER_run (&run,
-                        NULL);
-  fprintf (stderr,
-           "Did %u lookups, found %u records, %u lookups failed, %u pending on shutdown\n",
-           lookups,
-           records,
-           failures,
-           pending);
-  return 0;
-}
diff --git a/src/dns/gnunet-zonewalk.c b/src/dns/gnunet-zonewalk.c
new file mode 100644 (file)
index 0000000..860672e
--- /dev/null
@@ -0,0 +1,597 @@
+/*
+     This file is part of GNUnet
+     Copyright (C) 2018 GNUnet e.V.
+
+     GNUnet is free software; you can redistribute it and/or modify
+     it under the terms of the GNU General Public License as published
+     by the Free Software Foundation; either version 3, or (at your
+     option) any later version.
+
+     GNUnet is distributed in the hope that it will be useful, but
+     WITHOUT ANY WARRANTY; without even the implied warranty of
+     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+     General Public License for more details.
+
+     You should have received a copy of the GNU General Public License
+     along with GNUnet; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+     Boston, MA 02110-1301, USA.
+*/
+
+/**
+ * @file src/dns/gnunet-zoneimport.c
+ * @brief import a DNS zone for analysis, brute force
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include <gnunet_util_lib.h>
+#include <gnunet_dnsstub_lib.h>
+#include <gnunet_dnsparser_lib.h>
+
+/**
+ * Request we should make.
+ */
+struct Request
+{
+  /**
+   * Requests are kept in a DLL.
+   */
+  struct Request *next;
+
+  /**
+   * Requests are kept in a DLL.
+   */
+  struct Request *prev;
+
+  /**
+   * Socket used to make the request, NULL if not active.
+   */
+  struct GNUNET_DNSSTUB_RequestSocket *rs;
+
+  /**
+   * Raw DNS query.
+   */
+  void *raw;
+
+  /**
+   * Number of bytes in @e raw.
+   */
+  size_t raw_len;
+
+  /**
+   * Hostname we are resolving.
+   */
+  char *hostname;
+
+  /**
+   * When did we last issue this request?
+   */
+  time_t time;
+
+  /**
+   * How often did we issue this query?
+   */
+  int issue_num;
+
+  /**
+   * random 16-bit DNS query identifier.
+   */
+  uint16_t id;
+};
+
+
+/**
+ * Context for DNS resolution.
+ */
+static struct GNUNET_DNSSTUB_Context *ctx;
+
+/**
+ * The number of queries that are outstanding
+ */
+static unsigned int pending;
+
+/**
+ * Number of lookups we performed overall.
+ */
+static unsigned int lookups;
+
+/**
+ * Number of lookups that failed.
+ */
+static unsigned int failures;
+
+/**
+ * Number of records we found.
+ */
+static unsigned int records;
+
+/**
+ * Head of DLL of all requests to perform.
+ */
+static struct Request *req_head;
+
+/**
+ * Tail of DLL of all requests to perform.
+ */
+static struct Request *req_tail;
+
+/**
+ * Main task.
+ */
+static struct GNUNET_SCHEDULER_Task *t;
+
+/**
+ * Maximum number of queries pending at the same time.
+ */
+#define THRESH 20
+
+/**
+ * TIME_THRESH is in usecs.  How quickly do we submit fresh queries.
+ * Used as an additional throttle.
+ */
+#define TIME_THRESH 10
+
+/**
+ * How often do we retry a query before giving up for good?
+ */
+#define MAX_RETRIES 5
+
+
+/**
+ * We received @a rec for @a req. Remember the answer.
+ *
+ * @param req request
+ * @param rec response
+ */
+static void
+process_record (struct Request *req,
+                struct GNUNET_DNSPARSER_Record *rec)
+{
+  char buf[INET6_ADDRSTRLEN];
+
+  records++;
+  switch (rec->type)
+  {
+  case GNUNET_DNSPARSER_TYPE_A:
+    fprintf (stdout,
+             "%s A %s\n",
+             req->hostname,
+             inet_ntop (AF_INET,
+                        rec->data.raw.data,
+                        buf,
+                        sizeof (buf)));
+    break;
+  case GNUNET_DNSPARSER_TYPE_AAAA:
+    fprintf (stdout,
+             "%s AAAA %s\n",
+             req->hostname,
+             inet_ntop (AF_INET6,
+                        rec->data.raw.data,
+                        buf,
+                        sizeof (buf)));
+    break;
+  case GNUNET_DNSPARSER_TYPE_NS:
+    fprintf (stdout,
+             "%s NS %s\n",
+             req->hostname,
+             rec->data.hostname);
+    break;
+  case GNUNET_DNSPARSER_TYPE_CNAME:
+    fprintf (stdout,
+             "%s CNAME %s\n",
+             req->hostname,
+             rec->data.hostname);
+    break;
+  case GNUNET_DNSPARSER_TYPE_MX:
+    fprintf (stdout,
+             "%s MX %u %s\n",
+             req->hostname,
+             (unsigned int) rec->data.mx->preference,
+             rec->data.mx->mxhost);
+    break;
+  case GNUNET_DNSPARSER_TYPE_SOA:
+    fprintf (stdout,
+             "%s SOA %s %s %u %u %u %u %u\n",
+             req->hostname,
+             rec->data.soa->mname,
+             rec->data.soa->rname,
+             (unsigned int) rec->data.soa->serial,
+             (unsigned int) rec->data.soa->refresh,
+             (unsigned int) rec->data.soa->retry,
+             (unsigned int) rec->data.soa->expire,
+             (unsigned int) rec->data.soa->minimum_ttl);
+    break;
+  case GNUNET_DNSPARSER_TYPE_SRV:
+    fprintf (stdout,
+             "%s SRV %s %u %u %u\n",
+             req->hostname,
+             rec->data.srv->target,
+             rec->data.srv->priority,
+             rec->data.srv->weight,
+             rec->data.srv->port);
+    break;
+  case GNUNET_DNSPARSER_TYPE_PTR:
+    fprintf (stdout,
+             "%s PTR %s\n",
+             req->hostname,
+             rec->data.hostname);
+    break;
+  case GNUNET_DNSPARSER_TYPE_TXT:
+    fprintf (stdout,
+             "%s TXT %.*s\n",
+             req->hostname,
+             (int) rec->data.raw.data_len,
+             (char *) rec->data.raw.data);
+    break;
+  case GNUNET_DNSPARSER_TYPE_DNAME:
+    fprintf (stdout,
+             "%s DNAME %s\n",
+             req->hostname,
+             rec->data.hostname);
+    break;
+
+    /* obscure records */
+  case GNUNET_DNSPARSER_TYPE_AFSDB:
+  case GNUNET_DNSPARSER_TYPE_NAPTR:
+  case GNUNET_DNSPARSER_TYPE_APL:
+  case GNUNET_DNSPARSER_TYPE_DHCID:
+  case GNUNET_DNSPARSER_TYPE_HIP:
+  case GNUNET_DNSPARSER_TYPE_LOC:
+  case GNUNET_DNSPARSER_TYPE_RP:
+  case GNUNET_DNSPARSER_TYPE_TKEY:
+  case GNUNET_DNSPARSER_TYPE_TSIG:
+  case GNUNET_DNSPARSER_TYPE_URI:
+  case GNUNET_DNSPARSER_TYPE_TA:
+
+    /* DNSSEC */
+  case GNUNET_DNSPARSER_TYPE_DS:
+  case GNUNET_DNSPARSER_TYPE_RRSIG:
+  case GNUNET_DNSPARSER_TYPE_NSEC:
+  case GNUNET_DNSPARSER_TYPE_DNSKEY:
+  case GNUNET_DNSPARSER_TYPE_NSEC3:
+  case GNUNET_DNSPARSER_TYPE_NSEC3PARAM:
+  case GNUNET_DNSPARSER_TYPE_CDS:
+  case GNUNET_DNSPARSER_TYPE_CDNSKEY:
+
+    /* DNSSEC payload */
+  case GNUNET_DNSPARSER_TYPE_CERT:
+  case GNUNET_DNSPARSER_TYPE_SSHFP:
+  case GNUNET_DNSPARSER_TYPE_IPSECKEY:
+  case GNUNET_DNSPARSER_TYPE_TLSA:
+  case GNUNET_DNSPARSER_TYPE_OPENPGPKEY:
+
+    /* obsolete records */
+  case GNUNET_DNSPARSER_TYPE_SIG:
+  case GNUNET_DNSPARSER_TYPE_KEY:
+  case GNUNET_DNSPARSER_TYPE_KX:
+    {
+      char *base32;
+
+      base32 = GNUNET_STRINGS_data_to_string_alloc (rec->data.raw.data,
+                                                    rec->data.raw.data_len);
+      fprintf (stdout,
+               "%s (%u) %s\n",
+               req->hostname,
+               rec->type,
+               base32);
+      GNUNET_free (base32);
+    }
+    break;
+  default:
+    fprintf (stderr,
+             "Unsupported type %u\n",
+             (unsigned int) rec->type);
+    break;
+  }
+}
+
+
+/**
+ * Function called with the result of a DNS resolution.
+ *
+ * @param cls closure with the `struct Request`
+ * @param dns dns response, never NULL
+ * @param dns_len number of bytes in @a dns
+ */
+static void
+process_result (void *cls,
+                const struct GNUNET_TUN_DnsHeader *dns,
+                size_t dns_len)
+{
+  struct Request *req = cls;
+  struct GNUNET_DNSPARSER_Packet *p;
+
+  if (NULL == dns)
+  {
+    /* stub gave up */
+    pending--;
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Stub gave up on DNS reply for `%s'\n",
+                req->hostname);
+    GNUNET_CONTAINER_DLL_remove (req_head,
+                                 req_tail,
+                                 req);
+    if (req->issue_num > MAX_RETRIES)
+    {
+      failures++;
+      GNUNET_free (req->hostname);
+      GNUNET_free (req->raw);
+      GNUNET_free (req);
+      return;
+    }
+    GNUNET_CONTAINER_DLL_insert_tail (req_head,
+                                      req_tail,
+                                      req);
+    req->rs = NULL;
+    return;
+  }
+  if (req->id != dns->id)
+    return;
+  pending--;
+  GNUNET_DNSSTUB_resolve_cancel (req->rs);
+  req->rs = NULL;
+  GNUNET_CONTAINER_DLL_remove (req_head,
+                               req_tail,
+                               req);
+  p = GNUNET_DNSPARSER_parse ((const char *) dns,
+                              dns_len);
+  if (NULL == p)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Failed to parse DNS reply for `%s'\n",
+                req->hostname);
+    if (req->issue_num > MAX_RETRIES)
+    {
+      failures++;
+      GNUNET_free (req->hostname);
+      GNUNET_free (req->raw);
+      GNUNET_free (req);
+      return;
+    }
+    GNUNET_CONTAINER_DLL_insert_tail (req_head,
+                                      req_tail,
+                                      req);
+    return;
+  }
+  for (unsigned int i=0;i<p->num_answers;i++)
+  {
+    struct GNUNET_DNSPARSER_Record *rs = &p->answers[i];
+
+    process_record (req,
+                    rs);
+  }
+  for (unsigned int i=0;i<p->num_authority_records;i++)
+  {
+    struct GNUNET_DNSPARSER_Record *rs = &p->authority_records[i];
+
+    process_record (req,
+                    rs);
+  }
+  for (unsigned int i=0;i<p->num_additional_records;i++)
+  {
+    struct GNUNET_DNSPARSER_Record *rs = &p->additional_records[i];
+
+    process_record (req,
+                    rs);
+  }
+  GNUNET_DNSPARSER_free_packet (p);
+  GNUNET_free (req->hostname);
+  GNUNET_free (req->raw);
+  GNUNET_free (req);
+}
+
+
+/**
+ * Submit a request to DNS unless we need to slow down because
+ * we are at the rate limit.
+ *
+ * @param req request to submit
+ * @return #GNUNET_OK if request was submitted
+ *         #GNUNET_NO if request was already submitted
+ *         #GNUNET_SYSERR if we are at the rate limit
+ */
+static int
+submit_req (struct Request *req)
+{
+  static struct timeval last_request;
+  struct timeval now;
+
+  if (NULL != req->rs)
+    return GNUNET_NO; /* already submitted */
+  gettimeofday (&now,
+                NULL);
+  if ( ( ( (now.tv_sec - last_request.tv_sec) == 0) &&
+         ( (now.tv_usec - last_request.tv_usec) < TIME_THRESH) ) ||
+       (pending >= THRESH) )
+    return GNUNET_SYSERR;
+  GNUNET_assert (NULL == req->rs);
+  req->rs = GNUNET_DNSSTUB_resolve (ctx,
+                                    req->raw,
+                                    req->raw_len,
+                                    &process_result,
+                                    req);
+  GNUNET_assert (NULL != req->rs);
+  req->issue_num++;
+  last_request = now;
+  lookups++;
+  pending++;
+  req->time = time (NULL);
+  return GNUNET_OK;
+}
+
+
+/**
+ * Process as many requests as possible from the queue.
+ *
+ * @param cls NULL
+ */
+static void
+process_queue(void *cls)
+{
+  (void) cls;
+  t = NULL;
+  for (struct Request *req = req_head;
+       NULL != req;
+       req = req->next)
+  {
+    if (GNUNET_SYSERR == submit_req (req))
+      break;
+  }
+  if (NULL != req_head)
+    t = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS,
+                                  &process_queue,
+                                  NULL);
+  else
+    GNUNET_SCHEDULER_shutdown ();
+}
+
+
+/**
+ * Clean up and terminate the process.
+ *
+ * @param cls NULL
+ */
+static void
+do_shutdown (void *cls)
+{
+  (void) cls;
+  if (NULL != t)
+  {
+    GNUNET_SCHEDULER_cancel (t);
+    t = NULL;
+  }
+  GNUNET_DNSSTUB_stop (ctx);
+  ctx = NULL;
+}
+
+
+/**
+ * Process requests from the queue, then if the queue is
+ * not empty, try again.
+ *
+ * @param cls NULL
+ */
+static void
+run (void *cls)
+{
+  (void) cls;
+
+  GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
+                                 NULL);
+  t = GNUNET_SCHEDULER_add_now (&process_queue,
+                                NULL);
+}
+
+
+/**
+ * Add @a hostname to the list of requests to be made.
+ *
+ * @param hostname name to resolve
+ */
+static void
+queue (const char *hostname)
+{
+  struct GNUNET_DNSPARSER_Packet p;
+  struct GNUNET_DNSPARSER_Query q;
+  struct Request *req;
+  char *raw;
+  size_t raw_size;
+
+  if (GNUNET_OK !=
+      GNUNET_DNSPARSER_check_name (hostname))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Refusing invalid hostname `%s'\n",
+                hostname);
+    return;
+  }
+  q.name = (char *) hostname;
+  q.type = GNUNET_DNSPARSER_TYPE_NS;
+  q.dns_traffic_class = GNUNET_TUN_DNS_CLASS_INTERNET;
+
+  memset (&p,
+          0,
+          sizeof (p));
+  p.num_queries = 1;
+  p.queries = &q;
+  p.id = (uint16_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE,
+                                              UINT16_MAX);
+
+  if (GNUNET_OK !=
+      GNUNET_DNSPARSER_pack (&p,
+                             UINT16_MAX,
+                             &raw,
+                             &raw_size))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Failed to pack query for hostname `%s'\n",
+                hostname);
+    return;
+  }
+
+  req = GNUNET_new (struct Request);
+  req->hostname = strdup (hostname);
+  req->raw = raw;
+  req->raw_len = raw_size;
+  req->id = p.id;
+  GNUNET_CONTAINER_DLL_insert_tail (req_head,
+                                    req_tail,
+                                    req);
+}
+
+
+/**
+ * Call with IP address of resolver to query.
+ *
+ * @param argc should be 2
+ * @param argv[1] should contain IP address
+ * @return 0 on success
+ */
+int
+main (int argc,
+      char **argv)
+{
+  char hn[256];
+
+  if (2 != argc)
+  {
+    fprintf (stderr,
+             "Missing required configuration argument\n");
+    return -1;
+  }
+  ctx = GNUNET_DNSSTUB_start (256);
+  if (NULL == ctx)
+  {
+    fprintf (stderr,
+             "Failed to initialize GNUnet DNS STUB\n");
+    return 1;
+  }
+  if (GNUNET_OK !=
+      GNUNET_DNSSTUB_add_dns_ip (ctx,
+                                 argv[1]))
+  {
+    fprintf (stderr,
+             "Failed to use `%s' for DNS resolver\n",
+             argv[1]);
+    return 1;
+  }
+
+  while (NULL !=
+         fgets (hn,
+                sizeof (hn),
+                stdin))
+  {
+    if (strlen(hn) > 0)
+      hn[strlen(hn)-1] = '\0'; /* eat newline */
+    queue (hn);
+  }
+  GNUNET_SCHEDULER_run (&run,
+                        NULL);
+  fprintf (stderr,
+           "Did %u lookups, found %u records, %u lookups failed, %u pending on shutdown\n",
+           lookups,
+           records,
+           failures,
+           pending);
+  return 0;
+}
index b5e8af95ffc21cb789d3daef063cf7c93d602e1f..f3cc03adc96a48cff150c20cbe876ba69163b5f7 100644 (file)
@@ -528,9 +528,9 @@ GNUNET_FS_add_to_index (const char *filename,
   ii = GNUNET_malloc (sizeof (struct IndexInfo) + slen);
   ii->file_id = *file_id;
   ii->filename = (const char *) &ii[1];
-  memcpy (&ii[1],
-          filename,
-          slen);
+  GNUNET_memcpy (&ii[1],
+                 filename,
+                 slen);
   GNUNET_CONTAINER_DLL_insert (indexed_files_head,
                               indexed_files_tail,
                               ii);
index 5aecfd51de22a2dc4ce53d6298efad3bb1eee933..2b9a18f21abc5ff69628ff39f0222d4a5a6ba728 100644 (file)
@@ -3,3 +3,4 @@ gnunet-bcd
 gnunet-dns2gns
 gnunet-gns
 gnunet-gns-proxy
+gnunet-gns-benchmark
index 57b096b96e7e14bd03034fff47eaf8ee8b7964a1..ac11c834e88944f2b67490a10146a4e925dda03a 100644 (file)
@@ -76,6 +76,9 @@ bin_PROGRAMS = \
   $(DO_NONPOSIX_GNSIMPORT) \
   gnunet-gns
 
+noinst_PROGRAMS = \
+  gnunet-gns-benchmark
+
 if HAVE_MHD
 if LINUX
 bin_PROGRAMS += gnunet-bcd
@@ -114,6 +117,14 @@ gnunet_gns_LDADD = \
   $(top_builddir)/src/util/libgnunetutil.la \
   $(GN_LIBINTL)
 
+gnunet_gns_benchmark_SOURCES = \
+ gnunet-gns-benchmark.c
+gnunet_gns_benchmark_LDADD = \
+  libgnunetgns.la \
+  $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \
+  $(top_builddir)/src/util/libgnunetutil.la \
+  $(GN_LIBINTL)
+
 
 gnunet_bcd_SOURCES = \
  gnunet-bcd.c
@@ -255,7 +266,7 @@ check_SCRIPTS = \
   test_gns_gns2dns_lookup.sh \
   test_gns_dht_lookup.sh\
   test_gns_delegated_lookup.sh \
-  test_gns_plus_lookup.sh\
+  test_gns_at_lookup.sh\
   test_gns_zkey_lookup.sh\
   test_gns_rel_expiration.sh\
   test_gns_soa_lookup.sh\
index 2e49a4c60d539c87da65779e5e5618a3d453361c..f7682cda709e4a50a99a17a16d09c8243983670d 100644 (file)
@@ -26,7 +26,7 @@ INTERCEPT_DNS = YES
 
 # Zones
 .pin = DWJASSPE33MRN8T6Q0PENRNBTQY0E6ZYGTRCDP5DGPBF2CRJMJEG
-
+.fr = TFDAXBXMAN40MCG4E8Y9Y1C6D16JCMDPH2VMD30KMB92SECEMYGG
 
 [gns-proxy]
 BINARY = gnunet-gns-proxy
index ff67f0205250f1b941b55c6608f788e59534bb4d..ed30fa44c876bb5d1d6458ff75ccdf013b6c73d2 100644 (file)
@@ -157,7 +157,7 @@ check_result (void *cls,
   size_t mlen = ntohs (lookup_msg->header.size) - sizeof (*lookup_msg);
   uint32_t rd_count = ntohl (lookup_msg->rd_count);
   struct GNUNET_GNSRECORD_Data rd[rd_count];
-  
+
   (void) cls;
   if (GNUNET_SYSERR ==
       GNUNET_GNSRECORD_records_deserialize (mlen,
@@ -201,7 +201,7 @@ handle_result (void *cls,
     return;
   proc = lr->lookup_proc;
   proc_cls = lr->proc_cls;
-  
+
   GNUNET_assert (GNUNET_OK ==
                  GNUNET_GNSRECORD_records_deserialize (mlen,
                                                        (const char*) &lookup_msg[1],
diff --git a/src/gns/gnunet-gns-benchmark.c b/src/gns/gnunet-gns-benchmark.c
new file mode 100644 (file)
index 0000000..afa540c
--- /dev/null
@@ -0,0 +1,587 @@
+/*
+     This file is part of GNUnet
+     Copyright (C) 2018 GNUnet e.V.
+
+     GNUnet is free software; you can redistribute it and/or modify
+     it under the terms of the GNU General Public License as published
+     by the Free Software Foundation; either version 3, or (at your
+     option) any later version.
+
+     GNUnet is distributed in the hope that it will be useful, but
+     WITHOUT ANY WARRANTY; without even the implied warranty of
+     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+     General Public License for more details.
+
+     You should have received a copy of the GNU General Public License
+     along with GNUnet; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+     Boston, MA 02110-1301, USA.
+*/
+/**
+ * @file src/gns/gnunet-gns-benchmark.c
+ * @brief issue many queries to GNS and compute performance statistics
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include <gnunet_util_lib.h>
+#include <gnunet_gnsrecord_lib.h>
+#include <gnunet_gns_service.h>
+
+
+/**
+ * How long do we wait at least between requests by default?
+ */
+#define DEF_REQUEST_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 1)
+
+/**
+ * How long do we wait until we consider a request failed by default?
+ */
+#define DEF_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 1)
+
+
+/**
+ * We distinguish between different categories of
+ * requests, for which we track statistics separately.
+ * However, this process does not change how it acts
+ * based on the category.
+ */
+enum RequestCategory
+{
+  RC_SHARED = 0,
+  RC_PRIVATE = 1,
+  /**
+   * Must be last and match number of categories.
+   */
+  RC_MAX = 2
+};
+
+
+/**
+ * Request we should make.  We keep this struct in memory per request,
+ * thus optimizing it is crucial for the overall memory consumption of
+ * the zone importer.
+ */
+struct Request
+{
+
+  /**
+   * Active requests are kept in a DLL.
+   */
+  struct Request *next;
+
+  /**
+   * Active requests are kept in a DLL.
+   */
+  struct Request *prev;
+
+  /**
+   * Socket used to make the request, NULL if not active.
+   */
+  struct GNUNET_GNS_LookupWithTldRequest *lr;
+
+  /**
+   * Hostname we are resolving, allocated at the end of
+   * this struct (optimizing memory consumption by reducing
+   * total number of allocations).
+   */
+  char *hostname;
+
+  /**
+   * While we are fetching the record, the value is set to the
+   * starting time of the GNS operation.
+   */
+  struct GNUNET_TIME_Absolute op_start_time;
+
+  /**
+   * Observed latency, set once we got a reply.
+   */
+  struct GNUNET_TIME_Relative latency;
+
+  /**
+   * Category of the request.
+   */
+  enum RequestCategory cat;
+
+};
+
+
+/**
+ * GNS handle.
+ */
+static struct GNUNET_GNS_Handle *gns;
+
+/**
+ * Number of lookups we performed overall per category.
+ */
+static unsigned int lookups[RC_MAX];
+
+/**
+ * Number of replies we got per category.
+ */
+static unsigned int replies[RC_MAX];
+
+/**
+ * Number of replies we got per category.
+ */
+static unsigned int failures[RC_MAX];
+
+/**
+ * Sum of the observed latencies of successful queries,
+ * per category.
+ */
+static struct GNUNET_TIME_Relative latency_sum[RC_MAX];
+
+/**
+ * Active requests are kept in a DLL.
+ */
+static struct Request *act_head;
+
+/**
+ * Active requests are kept in a DLL.
+ */
+static struct Request *act_tail;
+
+/**
+ * Completed successful requests are kept in a DLL.
+ */
+static struct Request *succ_head;
+
+/**
+ * Completed successful requests are kept in a DLL.
+ */
+static struct Request *succ_tail;
+
+/**
+ * Yet to be started requests are kept in a DLL.
+ */
+static struct Request *todo_head;
+
+/**
+ * Yet to be started requests are kept in a DLL.
+ */
+static struct Request *todo_tail;
+
+/**
+ * Main task.
+ */
+static struct GNUNET_SCHEDULER_Task *t;
+
+/**
+ * Delay between requests.
+ */
+static struct GNUNET_TIME_Relative request_delay;
+
+/**
+ * Timeout for requests.
+ */
+static struct GNUNET_TIME_Relative timeout;
+
+
+/**
+ * Free @a req and data structures reachable from it.
+ *
+ * @param req request to free
+ */
+static void
+free_request (struct Request *req)
+{
+  if (NULL != req->lr)
+    GNUNET_GNS_lookup_with_tld_cancel (req->lr);
+  GNUNET_free (req);
+}
+
+
+/**
+ * Function called with the result of a GNS resolution.
+ *
+ * @param cls closure with the `struct Request`
+ * @param gns_tld #GNUNET_YES if GNS lookup was attempted
+ * @param rd_count number of records in @a rd
+ * @param rd the records in reply
+ */
+static void
+process_result (void *cls,
+               int gns_tld,
+               uint32_t rd_count,
+               const struct GNUNET_GNSRECORD_Data *rd)
+{
+  struct Request *req = cls;
+
+  (void) gns_tld;
+  (void) rd_count;
+  (void) rd;
+  req->lr = NULL;
+  req->latency = GNUNET_TIME_absolute_get_duration (req->op_start_time);
+  GNUNET_CONTAINER_DLL_remove (act_head,
+                              act_tail,
+                              req);
+  GNUNET_CONTAINER_DLL_insert (succ_head,
+                              succ_tail,
+                              req);
+  replies[req->cat]++;
+  latency_sum[req->cat]
+    = GNUNET_TIME_relative_add (latency_sum[req->cat],
+                               req->latency);
+}
+
+
+/**
+ * Process request from the queue.
+ *
+ * @param cls NULL
+ */
+static void
+process_queue (void *cls)
+{
+  struct Request *req;
+  struct GNUNET_TIME_Relative duration;
+
+  (void) cls;
+  t = NULL;
+  /* check for expired requests */
+  while (NULL != (req = act_head))
+  {
+    duration = GNUNET_TIME_absolute_get_duration (req->op_start_time);
+    if (duration.rel_value_us < timeout.rel_value_us)
+      break;
+    GNUNET_CONTAINER_DLL_remove (act_head,
+                                act_tail,
+                                req);
+    failures[req->cat]++;
+    free_request (req);
+  }
+  if (NULL == (req = todo_head))
+  {
+    struct GNUNET_TIME_Absolute at;
+
+    if (NULL == (req = act_head))
+    {
+      GNUNET_SCHEDULER_shutdown ();
+      return;
+    }
+    at = GNUNET_TIME_absolute_add (req->op_start_time,
+                                  timeout);
+    t = GNUNET_SCHEDULER_add_at (at,
+                                &process_queue,
+                                NULL);
+    return;
+  }
+  GNUNET_CONTAINER_DLL_remove (todo_head,
+                              todo_tail,
+                              req);
+  GNUNET_CONTAINER_DLL_insert_tail (act_head,
+                                   act_tail,
+                                   req);
+  lookups[req->cat]++;
+  req->op_start_time = GNUNET_TIME_absolute_get ();
+  req->lr = GNUNET_GNS_lookup_with_tld (gns,
+                                       req->hostname,
+                                       GNUNET_GNSRECORD_TYPE_ANY,
+                                       GNUNET_GNS_LO_DEFAULT,
+                                       &process_result,
+                                       req);
+  t = GNUNET_SCHEDULER_add_delayed (request_delay,
+                                    &process_queue,
+                                    NULL);
+}
+
+
+/**
+ * Compare two requests by latency for qsort().
+ *
+ * @param c1 pointer to `struct Request *`
+ * @param c2 pointer to `struct Request *`
+ * @return -1 if c1<c2, 1 if c1>c2, 0 if c1==c2.
+ */
+static int
+compare_req (const void *c1,
+            const void *c2)
+{
+  const struct Request *r1 = *(void **) c1;
+  const struct Request *r2 = *(void **) c2;
+
+  if (r1->latency.rel_value_us < r2->latency.rel_value_us)
+    return -1;
+  if (r1->latency.rel_value_us > r2->latency.rel_value_us)
+    return 1;
+  return 0;
+}
+
+
+/**
+ * Output statistics, then clean up and terminate the process.
+ *
+ * @param cls NULL
+ */
+static void
+do_shutdown (void *cls)
+{
+  struct Request *req;
+  struct Request **ra[RC_MAX];
+  unsigned int rp[RC_MAX];
+
+  (void) cls;
+  for (enum RequestCategory rc = 0;rc < RC_MAX;rc++)
+  {
+    ra[rc] = GNUNET_new_array (replies[rc],
+                              struct Request *);
+    rp[rc] = 0;
+  }
+  for (req = succ_head;NULL != req; req = req->next)
+  {
+    GNUNET_assert (rp[req->cat] < replies[req->cat]);
+    ra[req->cat][rp[req->cat]++] = req;
+  }
+  for (enum RequestCategory rc = 0;rc < RC_MAX;rc++)
+  {
+    unsigned int off;
+
+    fprintf (stdout,
+            "Category %u\n",
+            rc);
+    fprintf (stdout,
+            "\tlookups: %u replies: %u failures: %u\n",
+            lookups[rc],
+            replies[rc],
+            failures[rc]);
+    if (0 == rp[rc])
+      continue;
+    qsort (ra[rc],
+          rp[rc],
+          sizeof (struct Request *),
+          &compare_req);
+    latency_sum[rc] = GNUNET_TIME_relative_divide (latency_sum[rc],
+                                                   replies[rc]);
+    fprintf (stdout,
+            "\taverage: %s\n",
+            GNUNET_STRINGS_relative_time_to_string (latency_sum[rc],
+                                                    GNUNET_YES));
+    off = rp[rc] * 50 / 100;
+    fprintf (stdout,
+            "\tmedian(50): %s\n",
+            GNUNET_STRINGS_relative_time_to_string (ra[rc][off]->latency,
+                                                    GNUNET_YES));
+    off = rp[rc] * 75 / 100;
+    fprintf (stdout,
+            "\tquantile(75): %s\n",
+            GNUNET_STRINGS_relative_time_to_string (ra[rc][off]->latency,
+                                                    GNUNET_YES));
+    off = rp[rc] * 90 / 100;
+    fprintf (stdout,
+            "\tquantile(90): %s\n",
+            GNUNET_STRINGS_relative_time_to_string (ra[rc][off]->latency,
+                                                    GNUNET_YES));
+    off = rp[rc] * 99 / 100;
+    fprintf (stdout,
+            "\tquantile(99): %s\n",
+            GNUNET_STRINGS_relative_time_to_string (ra[rc][off]->latency,
+                                                    GNUNET_YES));
+    GNUNET_free (ra[rc]);
+  }
+  if (NULL != t)
+  {
+    GNUNET_SCHEDULER_cancel (t);
+    t = NULL;
+  }
+  while (NULL != (req = act_head))
+  {
+    GNUNET_CONTAINER_DLL_remove (act_head,
+                                act_tail,
+                                req);
+    free_request (req);
+  }
+  while (NULL != (req = succ_head))
+  {
+    GNUNET_CONTAINER_DLL_remove (succ_head,
+                                succ_tail,
+                                req);
+    free_request (req);
+  }
+  while (NULL != (req = todo_head))
+  {
+    GNUNET_CONTAINER_DLL_remove (todo_head,
+                                todo_tail,
+                                req);
+    free_request (req);
+  }
+  if (NULL != gns)
+  {
+    GNUNET_GNS_disconnect (gns);
+    gns = NULL;
+  }
+}
+
+
+/**
+ * Add @a hostname to the list of requests to be made.
+ *
+ * @param hostname name to resolve
+ * @param cat category of the @a hostname
+ */
+static void
+queue (const char *hostname,
+       enum RequestCategory cat)
+{
+  struct Request *req;
+  const char *dot;
+  size_t hlen;
+
+  dot = strchr (hostname,
+                (unsigned char) '.');
+  if (NULL == dot)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Refusing invalid hostname `%s' (lacks '.')\n",
+                hostname);
+    return;
+  }
+  hlen = strlen (hostname) + 1;
+  req = GNUNET_malloc (sizeof (struct Request) + hlen);
+  req->cat = cat;
+  req->hostname = (char *) &req[1];
+  GNUNET_memcpy (req->hostname,
+                 hostname,
+                 hlen);
+  GNUNET_CONTAINER_DLL_insert (todo_head,
+                              todo_tail,
+                              req);
+}
+
+
+/**
+ * Begin processing hostnames from stdin.
+ *
+ * @param cls NULL
+ */
+static void
+process_stdin (void *cls)
+{
+  static struct GNUNET_TIME_Absolute last;
+  static uint64_t idot;
+  unsigned int cat;
+  char hn[256];
+  char in[270];
+
+  (void) cls;
+  t = NULL;
+  while (NULL !=
+         fgets (in,
+                sizeof (in),
+                stdin))
+  {
+    if (strlen(in) > 0)
+      hn[strlen(in)-1] = '\0'; /* eat newline */
+    if ( (2 != sscanf (in,
+                      "%u %255s",
+                      &cat,
+                      hn)) ||
+        (cat >= RC_MAX) )
+    {
+      fprintf (stderr,
+              "Malformed input line `%s', skipping\n",
+              in);
+      continue;
+    }
+    if (0 == idot)
+      last = GNUNET_TIME_absolute_get ();
+    idot++;
+    if (0 == idot % 100000)
+    {
+      struct GNUNET_TIME_Relative delta;
+
+      delta = GNUNET_TIME_absolute_get_duration (last);
+      last = GNUNET_TIME_absolute_get ();
+      fprintf (stderr,
+              "Read 10000 domain names in %s\n",
+              GNUNET_STRINGS_relative_time_to_string (delta,
+                                                      GNUNET_YES));
+    }
+    queue (hn,
+          (enum RequestCategory) cat);
+  }
+  fprintf (stderr,
+           "Done reading %llu domain names\n",
+           (unsigned long long) idot);
+  t = GNUNET_SCHEDULER_add_now (&process_queue,
+                               NULL);
+}
+
+
+/**
+ * Process requests from the queue, then if the queue is
+ * not empty, try again.
+ *
+ * @param cls NULL
+ * @param args remaining command-line arguments
+ * @param cfgfile name of the configuration file used (for saving, can be NULL!)
+ * @param cfg configuration
+ */
+static void
+run (void *cls,
+     char *const *args,
+     const char *cfgfile,
+     const struct GNUNET_CONFIGURATION_Handle *cfg)
+{
+  (void) cls;
+  (void) args;
+  (void) cfgfile;
+  GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
+                                 NULL);
+  gns = GNUNET_GNS_connect (cfg);
+  if (NULL == gns)
+  {
+    GNUNET_break (0);
+    GNUNET_SCHEDULER_shutdown ();
+    return;
+  }
+  t = GNUNET_SCHEDULER_add_now (&process_stdin,
+                               NULL);
+}
+
+
+/**
+ * Call with list of names with numeric category to query.
+ *
+ * @param argc unused
+ * @param argv unused
+ * @return 0 on success
+ */
+int
+main (int argc,
+      char *const*argv)
+{
+  int ret = 0;
+  struct GNUNET_GETOPT_CommandLineOption options[] = {
+    GNUNET_GETOPT_option_relative_time ('d',
+                                        "delay",
+                                        "RELATIVETIME",
+                                        gettext_noop ("how long to wait between queries"),
+                                        &request_delay),
+    GNUNET_GETOPT_option_relative_time ('t',
+                                        "timeout",
+                                        "RELATIVETIME",
+                                        gettext_noop ("how long to wait for an answer"),
+                                        &timeout),
+    GNUNET_GETOPT_OPTION_END
+  };
+
+  if (GNUNET_OK !=
+      GNUNET_STRINGS_get_utf8_args (argc, argv,
+                                   &argc, &argv))
+    return 2;
+  timeout = DEF_TIMEOUT;
+  request_delay = DEF_REQUEST_DELAY;
+  if (GNUNET_OK !=
+      GNUNET_PROGRAM_run (argc,
+                         argv,
+                         "gnunet-gns-benchmark",
+                         "resolve GNS names and measure performance",
+                         options,
+                         &run,
+                         NULL))
+    ret = 1;
+  GNUNET_free ((void*) argv);
+  return ret;
+}
+
+/* end of gnunet-gns-benchmark.c */
index 92e03bc6935b4ccb4c4caff15e0aeff81e61f4b7..542085910fcca7b4504229473b7c8fbdcfa396f4 100644 (file)
@@ -109,6 +109,11 @@ struct Gns2DnsPending
    * Handle for DNS resolution of the DNS nameserver.
    */
   struct GNUNET_RESOLVER_RequestHandle *dns_rh;
+
+  /**
+   * How many results did we get?
+   */
+  unsigned int num_results;
 };
 
 
@@ -813,7 +818,9 @@ add_dns_result (struct GNS_ResolverHandle *rh,
   res->data_size = data_size;
   res->record_type = record_type;
   res->data = &res[1];
-  GNUNET_memcpy (&res[1], data, data_size);
+  GNUNET_memcpy (&res[1],
+                 data,
+                 data_size);
   GNUNET_CONTAINER_DLL_insert (rh->dns_result_head,
                               rh->dns_result_tail,
                               res);
@@ -1494,26 +1501,48 @@ handle_gns2dns_ip (void *cls,
 {
   struct Gns2DnsPending *gp = cls;
   struct AuthorityChain *ac = gp->ac;
+  struct sockaddr_storage ss;
+  struct sockaddr_in *v4;
+  struct sockaddr_in6 *v6;
 
-  GNUNET_RESOLVER_request_cancel (gp->dns_rh);
-  GNUNET_CONTAINER_DLL_remove (ac->authority_info.dns_authority.gp_head,
-                               ac->authority_info.dns_authority.gp_tail,
-                               gp);
-  GNUNET_free (gp);
   if (NULL == addr)
   {
-    /* DNS resolution failed */
-    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                "Failed to use DNS to resolve name of DNS resolver\n");
+    /* DNS resolution finished */
+    if (0 == gp->num_results)
+      GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                  "Failed to use DNS to resolve name of DNS resolver\n");
+    GNUNET_CONTAINER_DLL_remove (ac->authority_info.dns_authority.gp_head,
+                                 ac->authority_info.dns_authority.gp_tail,
+                                 gp);
+    GNUNET_free (gp);
+    continue_with_gns2dns (ac);
+    return;
   }
-  else
+  GNUNET_memcpy (&ss,
+                 addr,
+                 addrlen);
+  switch (ss.ss_family)
   {
-    if (GNUNET_OK ==
-        GNUNET_DNSSTUB_add_dns_sa (ac->authority_info.dns_authority.dns_handle,
-                                   addr))
-      ac->authority_info.dns_authority.found = GNUNET_YES;
+  case AF_INET:
+    v4 = (struct sockaddr_in *) &ss;
+    v4->sin_port = htons (53);
+    gp->num_results++;
+    break;
+  case AF_INET6:
+    v6 = (struct sockaddr_in6 *) &ss;
+    v6->sin6_port = htons (53);
+    gp->num_results++;
+    break;
+  default:
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Unsupported AF %d\n",
+                ss.ss_family);
+    return;
   }
-  continue_with_gns2dns (ac);
+  if (GNUNET_OK ==
+      GNUNET_DNSSTUB_add_dns_sa (ac->authority_info.dns_authority.dns_handle,
+                                 (struct sockaddr *) &ss))
+    ac->authority_info.dns_authority.found = GNUNET_YES;
 }
 
 
index 07d1a9c040aab7cdee8d57cdf995dede8ec6c2f0..b88e8fcc25d66aad8215ea8c7d0c424f77a65276 100644 (file)
@@ -102,9 +102,9 @@ gns_value_to_string (void *cls,
           ('\0' != cdata[data_size - 1]) )
        return NULL; /* malformed */
       /* need to memcpy for alignment */
-      memcpy (&vpn,
-              data,
-              sizeof (vpn));
+      GNUNET_memcpy (&vpn,
+                     data,
+                     sizeof (vpn));
       GNUNET_asprintf (&vpn_str,
                        "%u %s %s",
                        (unsigned int) ntohs (vpn.proto),
@@ -122,9 +122,9 @@ gns_value_to_string (void *cls,
       cdata = data;
       if (data_size < sizeof (struct GNUNET_GNSRECORD_BoxRecord))
        return NULL; /* malformed */
-      memcpy (&box,
-              data,
-              sizeof (box));
+      GNUNET_memcpy (&box,
+                     data,
+                     sizeof (box));
       rt = ntohl (box.record_type);
       ival = GNUNET_GNSRECORD_value_to_string (rt,
                                                &cdata[sizeof (box)],
diff --git a/src/gns/test_gns_at_lookup.sh b/src/gns/test_gns_at_lookup.sh
new file mode 100755 (executable)
index 0000000..8c1d2a0
--- /dev/null
@@ -0,0 +1,39 @@
+#!/bin/bash
+trap "gnunet-arm -e -c test_gns_lookup.conf" SIGINT
+
+LOCATION=$(which gnunet-config)
+if [ -z $LOCATION ]
+then
+  LOCATION="gnunet-config"
+fi
+$LOCATION --version 1> /dev/null
+if test $? != 0
+then
+       echo "GNUnet command line tools cannot be found, check environmental variables PATH and GNUNET_PREFIX"
+       exit 77
+fi
+
+which timeout &> /dev/null && DO_TIMEOUT="timeout 5"
+rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
+
+TEST_IP="127.0.0.1"
+MY_EGO="myego"
+gnunet-arm -s -c test_gns_lookup.conf
+gnunet-identity -C delegatedego -c test_gns_lookup.conf
+DELEGATED_PKEY=$(gnunet-identity -d -c test_gns_lookup.conf | grep delegatedego | awk '{print $3}')
+gnunet-identity -C $MY_EGO -c test_gns_lookup.conf
+gnunet-namestore -p -z $MY_EGO -a -n b -t PKEY -V $DELEGATED_PKEY -e never -c test_gns_lookup.conf
+gnunet-namestore -p -z delegatedego -a -n '@' -t A -V $TEST_IP -e never -c test_gns_lookup.conf
+RES_IP=`$DO_TIMEOUT gnunet-gns --raw -u b.$MY_EGO -t A -c test_gns_lookup.conf`
+gnunet-namestore -z $MY_EGO -d -n b -t PKEY -V $DELEGATED_PKEY  -e never -c test_gns_lookup.conf
+gnunet-namestore -z delegatedego -d -n '@' -t A -V $TEST_IP  -e never -c test_gns_lookup.conf
+gnunet-arm -e -c test_gns_lookup.conf
+rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
+
+if [ "$RES_IP" == "$TEST_IP" ]
+then
+  exit 0
+else
+  echo "Failed to resolve to proper IP, got $RES_IP."
+  exit 1
+fi
index d9627850fb04ab5eacd9d53e4363193254ffae1e..00ccd265b49e7431d3656af059ba99295569c55d 100755 (executable)
@@ -22,7 +22,7 @@ then
 fi
 
 
-rm -rf /tmp/test-gnunet-gns-peer-1/
+rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
 
 TEST_IP_PLUS="127.0.0.1"
 TEST_IP_DNS="131.159.74.67"
@@ -51,7 +51,7 @@ gnunet-namestore -p -z $MY_EGO -d -n $TEST_RECORD_NAME_PLUS -t CNAME -V $TEST_RE
 gnunet-namestore -p -z $MY_EGO -d -n $TEST_RECORD_CNAME_SERVER -t A -V $TEST_IP_PLUS -e never -c test_gns_lookup.conf
 gnunet-identity -D $MY_EGO -c test_gns_lookup.conf
 gnunet-arm -e -c test_gns_lookup.conf
-rm -rf /tmp/test-gnunet-gns-peer-1/
+rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
 
 if [ "$RES_CNAME_RAW" == "server.$TESTEGOZONE" ]
 then
index edda688ffd17e22a6f2f9f126ac82a26cb2e550b..3374f1b3bf564ab0b68a50686d5f9b624d7af1d8 100755 (executable)
@@ -14,7 +14,7 @@ then
        exit 77
 fi
 
-rm -rf /tmp/test-gnunet-gns-peer-1/
+rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
 MY_EGO="myego"
 OTHER_EGO="delegatedego"
 FINAL_LABEL="www"
@@ -32,7 +32,7 @@ gnunet-namestore -z $MY_EGO -d -n b -t PKEY -V $DELEGATED_PKEY  -e never -c test
 gnunet-namestore -z $OTHER_EGO -d -n $FINAL_LABEL -t A -V $TEST_IP  -e never -c test_gns_lookup.conf
 gnunet-arm -e -c test_gns_lookup.conf
 
-rm -rf /tmp/test-gnunet-gns-peer-1/
+rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
 
 if [ "$RES_IP" == "$TEST_IP" ]
 then
index 365c77339a9f71f5b6de652afe741f654326f940..6c977bb0d5a1953a0d455d5c2345de8e2cde266f 100755 (executable)
@@ -18,7 +18,7 @@ TEST_IP="127.0.0.1"
 MY_EGO="myego"
 OTHER_EGO="delegatedego"
 
-
+rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
 gnunet-arm -s -c test_gns_lookup.conf
 gnunet-identity -C $OTHER_EGO -c test_gns_lookup.conf
 DELEGATED_PKEY=$(gnunet-identity -d -c test_gns_lookup.conf | grep $OTHER_EGO | awk '{print $3}')
@@ -31,7 +31,7 @@ gnunet-namestore -z $OTHER_EGO -d -n www -t A -V $TEST_IP  -e never -c test_gns_
 RES_IP=`$DO_TIMEOUT gnunet-gns --raw -u www.b.$MY_EGO -t A -c test_gns_lookup.conf`
 gnunet-namestore -z $MY_EGO -d -n b -t PKEY -V $DELEGATED_PKEY  -e never -c test_gns_lookup.conf
 gnunet-arm -e -c test_gns_lookup.conf
-rm -rf /tmp/test-gnunet-gns-peer-1/
+rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
 
 if [ "$RES_IP" == "$TEST_IP" ]
 then
index 921d9594d78eef5ba444f761417f4fce3194f7d9..ad5d762eb25205ca1ef56e9b9b918dc305c016c8 100755 (executable)
@@ -13,7 +13,7 @@ then
        exit 77
 fi
 
-rm -r rm -rf /tmp/test-gnunet-gns-peer-1/
+rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
 # IP address of 'uk.gnunet.org'
 TEST_IP_ALT2="81.187.252.184"
 # IP address of 'www.gnunet.org'
@@ -72,7 +72,7 @@ gnunet-namestore -z $MY_EGO -d -n $TEST_RESOLVER_LABEL -t A -V $TEST_IP_GNS2DNS
 gnunet-namestore -z $MY_EGO -d -n $TEST_RECORD_NAME -t GNS2DNS -V $TEST_RECORD_GNS2DNS -e never -c test_gns_lookup.conf
 gnunet-identity -D $MY_EGO -c test_gns_lookup.conf
 gnunet-arm -e -c test_gns_lookup.conf
-rm -rf /tmp/test-gnunet-gns-peer-1/
+rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
 
 ret=0
 if [ "$RES_IP" == "$TEST_IP" ]
index 118c23060b8c317f26231cc180ec0bdb15dbb10b..301e6ae0c0e83f9cb5514ffc7d5d166220df13f8 100755 (executable)
@@ -24,7 +24,7 @@ RES_IP=`$DO_TIMEOUT gnunet-gns --raw -u www.$MY_EGO -t AAAA -c test_gns_lookup.c
 gnunet-namestore -z $MY_EGO -d -n www -t AAAA -V $TEST_IP -e never -c test_gns_lookup.conf
 gnunet-identity -D $MY_EGO -c test_gns_lookup.conf
 gnunet-arm -e -c test_gns_lookup.conf
-rm -rf /tmp/test-gnunet-gns-peer-1/
+rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
 
 if [ "$RES_IP" == "$TEST_IP" ]
 then
index 8abc9f50966bcc4c603b7b445d4028cc6ad94de7..5a7ef21c3a6e226bc2f5c33f1e1fab35398eb7a3 100755 (executable)
@@ -13,7 +13,7 @@ then
        exit 77
 fi
 
-rm -rf /tmp/test-gnunet-gns-peer-1/
+rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
 which timeout &> /dev/null && DO_TIMEOUT="timeout 5"
 
 MY_EGO="myego"
@@ -28,7 +28,7 @@ RES_MX=`$DO_TIMEOUT gnunet-gns --raw -u www.$MY_EGO -t MX -c test_gns_lookup.con
 gnunet-namestore -z $MY_EGO -d -n www -t MX -V "$TEST_MX" -e never -c test_gns_lookup.conf
 gnunet-identity -D $MY_EGO -c test_gns_lookup.conf
 gnunet-arm -e -c test_gns_lookup.conf
-rm -rf /tmp/test-gnunet-gns-peer-1/
+rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
 
 if [ "$RES_MX" == "$WANT_MX" ]
 then
diff --git a/src/gns/test_gns_plus_lookup.sh b/src/gns/test_gns_plus_lookup.sh
deleted file mode 100755 (executable)
index 4cf7a88..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-#!/bin/bash
-trap "gnunet-arm -e -c test_gns_lookup.conf" SIGINT
-
-LOCATION=$(which gnunet-config)
-if [ -z $LOCATION ]
-then
-  LOCATION="gnunet-config"
-fi
-$LOCATION --version 1> /dev/null
-if test $? != 0
-then
-       echo "GNUnet command line tools cannot be found, check environmental variables PATH and GNUNET_PREFIX"
-       exit 77
-fi
-
-which timeout &> /dev/null && DO_TIMEOUT="timeout 5"
-rm -rf /tmp/test-gnunet-gns-peer-1/
-
-TEST_IP="127.0.0.1"
-MY_EGO="myego"
-gnunet-arm -s -c test_gns_lookup.conf
-gnunet-identity -C delegatedego -c test_gns_lookup.conf
-DELEGATED_PKEY=$(gnunet-identity -d -c test_gns_lookup.conf | grep delegatedego | awk '{print $3}')
-gnunet-identity -C $MY_EGO -c test_gns_lookup.conf
-gnunet-namestore -p -z $MY_EGO -a -n b -t PKEY -V $DELEGATED_PKEY -e never -c test_gns_lookup.conf
-gnunet-namestore -p -z delegatedego -a -n '+' -t A -V $TEST_IP -e never -c test_gns_lookup.conf
-RES_IP=`$DO_TIMEOUT gnunet-gns --raw -u b.$MY_EGO -t A -c test_gns_lookup.conf`
-gnunet-namestore -z $MY_EGO -d -n b -t PKEY -V $DELEGATED_PKEY  -e never -c test_gns_lookup.conf
-gnunet-namestore -z delegatedego -d -n '+' -t A -V $TEST_IP  -e never -c test_gns_lookup.conf
-gnunet-arm -e -c test_gns_lookup.conf
-rm -rf /tmp/test-gnunet-gns-peer-1/
-
-if [ "$RES_IP" == "$TEST_IP" ]
-then
-  exit 0
-else
-  echo "Failed to resolve to proper IP, got $RES_IP."
-  exit 1
-fi
index 5606491e481283d40ec05f70248c427717638779..e0eb33f2e30d7506fe5afb65743f9665b80cf48b 100755 (executable)
@@ -17,7 +17,7 @@ MY_EGO="myego"
 OTHER_EGO="delegatedego"
 
 
-rm -rf /tmp/test-gnunet-gns-peer-1/
+rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
 which timeout &> /dev/null && DO_TIMEOUT="timeout 5"
 TEST_IP="127.0.0.1"
 gnunet-arm -s -c test_gns_lookup.conf
@@ -53,7 +53,7 @@ gnunet-namestore -z $MY_EGO -d -n b -t PKEY -V $DELEGATED_PKEY  -e never -c test
 gnunet-identity -D $MY_EGO -c test_gns_lookup.conf
 gnunet-identity -D $OTHER_EGO -c test_gns_lookup.conf
 gnunet-arm -e -c test_gns_lookup.conf
-rm -rf /tmp/test-gnunet-gns-peer-1/
+rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
 
 if [ "$RES_IP" == "$TEST_IP" ]
 then
index 992098db3ee2618f819c7ecb33bba230693bf88f..a266a7484e3db16c46a4c906d2885b27be630372 100755 (executable)
@@ -16,7 +16,7 @@ fi
 MY_EGO="myego"
 OTHER_EGO="delegatedego"
 
-rm -rf /tmp/test-gnunet-gns-peer-1/
+rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
 which timeout &> /dev/null && DO_TIMEOUT="timeout 5"
 TEST_IP="127.0.0.1"
 gnunet-arm -s -c test_gns_lookup.conf
@@ -38,7 +38,7 @@ gnunet-namestore -z $MY_EGO -d -n b -t PKEY -V $DELEGATED_PKEY  -e never -c test
 gnunet-identity -D $MY_EGO -c test_gns_lookup.conf
 gnunet-identity -D $OTHER_EGO -c test_gns_lookup.conf
 gnunet-arm -e -c test_gns_lookup.conf
-rm -rf /tmp/test-gnunet-gns-peer-1/
+rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
 
 if [ "$RES_IP_EXP" == "$TEST_IP" ]
 then
index 269b940d9b0245f27231f4127be3ab691f73dd31..12f0c088143183010df10dd74216994472bac438 100755 (executable)
@@ -14,7 +14,7 @@ then
        exit 77
 fi
 
-rm -rf /tmp/test-gnunet-gns-peer-1/
+rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
 MY_EGO="myego"
 OTHER_EGO="delegatedego"
 TEST_IP="127.0.0.1"
@@ -31,7 +31,7 @@ RES_IP_REV=`$DO_TIMEOUT gnunet-gns --raw -u www.b.$MY_EGO -t A -c test_gns_looku
 gnunet-namestore -z $MY_EGO -d -n b -t PKEY -V $DELEGATED_PKEY  -e never -c test_gns_lookup.conf
 gnunet-namestore -z $OTHER_EGO -d -n www -t A -V $TEST_IP  -e never -c test_gns_lookup.conf
 gnunet-arm -e -c test_gns_lookup.conf
-rm -rf /tmp/test-gnunet-gns-peer-1/
+rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
 
 if [ "$RES_IP" != "$TEST_IP" ]
 then
index 2f9cc58de9f667f6a449f910f3104d3ef19eef84..82a5885c332a04e27c04dd724a7085d69f6965e1 100755 (executable)
@@ -15,7 +15,7 @@ fi
 
 which timeout &> /dev/null && DO_TIMEOUT="timeout 5"
 
-rm -rf /tmp/test-gnunet-gns-peer-1/
+rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
 MY_EGO="myego"
 TEST_DOMAIN="homepage.$MY_EGO"
 # some public DNS resolver we can use
@@ -36,7 +36,7 @@ RES_SOA=`$DO_TIMEOUT gnunet-gns --raw -u $TEST_DOMAIN -t SOA -c test_gns_lookup.
 gnunet-namestore -z $MY_EGO -d -n $TEST_RECORD_NAME -t GNS2DNS -V ${TEST_RECORD_GNS2DNS}@${TEST_IP_GNS2DNS} -e never -c test_gns_lookup.conf &> /dev/null
 gnunet-identity -D $MY_EGO -c test_gns_lookup.conf
 gnunet-arm -e -c test_gns_lookup.conf
-rm -rf /tmp/test-gnunet-gns-peer-1/
+rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
 
 if [ "x$RES_SOA" != "x" ]
 then
index 68a60c8b67841bdd9589e759d48dabc68bba3ba4..ce9b9e8066650a9de2b150991d86c0ecf1e38407 100755 (executable)
@@ -13,7 +13,7 @@ then
        exit 77
 fi
 
-rm -rf /tmp/test-gnunet-gns-peer-1/
+rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
 which timeout &> /dev/null && DO_TIMEOUT="timeout 30"
 TEST_TXT="GNS powered txt record data"
 MY_EGO="myego"
@@ -25,7 +25,7 @@ RES_TXT=`$DO_TIMEOUT gnunet-gns --raw -u $LABEL.$MY_EGO -t TXT -c test_gns_looku
 gnunet-namestore -z $MY_EGO -d -n $LABEL -t TXT -V "$TEST_TXT" -e never -c test_gns_lookup.conf
 gnunet-identity -D $MY_EGO -c test_gns_lookup.conf
 gnunet-arm -e -c test_gns_lookup.conf
-rm -rf /tmp/test-gnunet-gns-peer-1/
+rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
 
 if [ "$RES_TXT" == "$TEST_TXT" ]
 then
index 3121987806ae1fc9e9a5adfe52fa91bf9523d240..5e67e0ce24accf7fc33b92b8a92781296b51f31f 100755 (executable)
@@ -14,7 +14,7 @@ then
        exit 77
 fi
 
-rm -rf /tmp/test-gnunet-gns-peer-1/
+rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
 
 TEST_IP="127.0.0.1"
 gnunet-arm -s -c test_gns_lookup.conf
@@ -27,7 +27,7 @@ RES_IP=`$DO_TIMEOUT gnunet-gns --raw -u www.${DELEGATED_PKEY} -t A -c test_gns_l
 gnunet-namestore -z testego -d -n b -t PKEY -V $DELEGATED_PKEY  -e never -c test_gns_lookup.conf
 gnunet-namestore -z delegatedego -d -n www -t A -V $TEST_IP  -e never -c test_gns_lookup.conf
 gnunet-arm -e -c test_gns_lookup.conf
-rm -rf /tmp/test-gnunet-gns-peer-1/
+rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
 
 if [ "$RES_IP" == "$TEST_IP" ]
 then
index 374abdb608dd07ae9f6c1ea72b79591b7bf90743..53d3bb22d10eb8578297fa2ed54643f4c5a268e6 100644 (file)
@@ -2,3 +2,4 @@ test_gnsrecord_block_expiration
 test_gnsrecord_crypto
 test_gnsrecord_serialization
 zonefiles
+perf_gnsrecord_crypto
index 2fb427c69016e26d52ed7a765172a7ceed9e7fe4..c83aa33079197b3fdd5214ab212f27f456694c97 100644 (file)
@@ -19,7 +19,8 @@ endif
 check_PROGRAMS = \
  test_gnsrecord_crypto \
  test_gnsrecord_serialization \
- test_gnsrecord_block_expiration
+ test_gnsrecord_block_expiration \
+ perf_gnsrecord_crypto
 
 if ENABLE_TEST_RUN
 AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset XDG_CONFIG_HOME;
@@ -85,3 +86,10 @@ test_gnsrecord_crypto_LDADD = \
   libgnunetgnsrecord.la \
   $(top_builddir)/src/util/libgnunetutil.la
 
+
+perf_gnsrecord_crypto_SOURCES = \
+ perf_gnsrecord_crypto.c
+perf_gnsrecord_crypto_LDADD = \
+  $(top_builddir)/src/testing/libgnunettesting.la \
+  libgnunetgnsrecord.la \
+  $(top_builddir)/src/util/libgnunetutil.la
index 35005b5ca826354cac6c2deffe7d78820d8030fb..ece1665fc9284e379d2727867cf1f7f1de8af03a 100644 (file)
@@ -114,10 +114,9 @@ init ()
 void __attribute__ ((destructor))
 GNSRECORD_fini ()
 {
-  unsigned int i;
   struct Plugin *plugin;
 
-  for (i = 0; i < num_plugins; i++)
+  for (unsigned int i = 0; i < num_plugins; i++)
   {
     plugin = gns_plugins[i];
     GNUNET_break (NULL ==
@@ -146,12 +145,11 @@ GNUNET_GNSRECORD_value_to_string (uint32_t type,
                                  const void *data,
                                  size_t data_size)
 {
-  unsigned int i;
   struct Plugin *plugin;
   char *ret;
 
   init ();
-  for (i = 0; i < num_plugins; i++)
+  for (unsigned int i = 0; i < num_plugins; i++)
   {
     plugin = gns_plugins[i];
     if (NULL != (ret = plugin->api->value_to_string (plugin->api->cls,
@@ -180,11 +178,10 @@ GNUNET_GNSRECORD_string_to_value (uint32_t type,
                                  void **data,
                                  size_t *data_size)
 {
-  unsigned int i;
   struct Plugin *plugin;
 
   init ();
-  for (i = 0; i < num_plugins; i++)
+  for (unsigned int i = 0; i < num_plugins; i++)
   {
     plugin = gns_plugins[i];
     if (GNUNET_OK == plugin->api->string_to_value (plugin->api->cls,
@@ -207,7 +204,6 @@ GNUNET_GNSRECORD_string_to_value (uint32_t type,
 uint32_t
 GNUNET_GNSRECORD_typename_to_number (const char *dns_typename)
 {
-  unsigned int i;
   struct Plugin *plugin;
   uint32_t ret;
 
@@ -215,7 +211,7 @@ GNUNET_GNSRECORD_typename_to_number (const char *dns_typename)
                        "ANY"))
     return GNUNET_GNSRECORD_TYPE_ANY;
   init ();
-  for (i = 0; i < num_plugins; i++)
+  for (unsigned int i = 0; i < num_plugins; i++)
   {
     plugin = gns_plugins[i];
     if (UINT32_MAX != (ret = plugin->api->typename_to_number (plugin->api->cls,
@@ -235,14 +231,13 @@ GNUNET_GNSRECORD_typename_to_number (const char *dns_typename)
 const char *
 GNUNET_GNSRECORD_number_to_typename (uint32_t type)
 {
-  unsigned int i;
   struct Plugin *plugin;
   const char * ret;
 
   if (GNUNET_GNSRECORD_TYPE_ANY == type)
     return "ANY";
   init ();
-  for (i = 0; i < num_plugins; i++)
+  for (unsigned int i = 0; i < num_plugins; i++)
   {
     plugin = gns_plugins[i];
     if (NULL != (ret = plugin->api->number_to_typename (plugin->api->cls,
index cebc842f377aee62bbbebf1da9f32d5aea72fb38..6d59a545a2d20f7b53a29051af28be07a7fddc52 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     Copyright (C) 2009-2013 GNUnet e.V.
+     Copyright (C) 2009-2013, 2018 GNUnet e.V.
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -94,7 +94,7 @@ block_create (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
   struct GNUNET_CRYPTO_EcdsaPrivateKey *dkey;
   struct GNUNET_CRYPTO_SymmetricInitializationVector iv;
   struct GNUNET_CRYPTO_SymmetricSessionKey skey;
-  struct GNUNET_GNSRECORD_Data rdc[rd_count];
+  struct GNUNET_GNSRECORD_Data rdc[GNUNET_NZL(rd_count)];
   uint32_t rd_count_nbo;
   struct GNUNET_TIME_Absolute now;
 
@@ -246,6 +246,7 @@ GNUNET_GNSRECORD_block_create2 (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
     GNUNET_CRYPTO_ecdsa_key_get_public (key,
                                         &line->pkey);
   }
+#undef CSIZE
   return block_create (key,
                        &line->pkey,
                        expire,
@@ -304,18 +305,21 @@ GNUNET_GNSRECORD_block_decrypt (const struct GNUNET_GNSRECORD_Block *block,
     GNUNET_break_op (0);
     return GNUNET_SYSERR;
   }
-  derive_block_aes_key (&iv, &skey, label, zone_key);
+  derive_block_aes_key (&iv,
+                        &skey,
+                        label,
+                        zone_key);
   {
     char payload[payload_len];
     uint32_t rd_count;
 
     GNUNET_break (payload_len ==
                  GNUNET_CRYPTO_symmetric_decrypt (&block[1], payload_len,
-                                            &skey, &iv,
-                                            payload));
+                                                   &skey, &iv,
+                                                   payload));
     GNUNET_memcpy (&rd_count,
-           payload,
-           sizeof (uint32_t));
+                   payload,
+                   sizeof (uint32_t));
     rd_count = ntohl (rd_count);
     if (rd_count > 2048)
     {
@@ -324,7 +328,7 @@ GNUNET_GNSRECORD_block_decrypt (const struct GNUNET_GNSRECORD_Block *block,
       return GNUNET_SYSERR;
     }
     {
-      struct GNUNET_GNSRECORD_Data rd[rd_count];
+      struct GNUNET_GNSRECORD_Data rd[GNUNET_NZL(rd_count)];
       unsigned int j;
       struct GNUNET_TIME_Absolute now;
 
@@ -359,10 +363,13 @@ GNUNET_GNSRECORD_block_decrypt (const struct GNUNET_GNSRECORD_Block *block,
               continue;
             if (rd[i].expiration_time < now.abs_value_us)
               include_record = GNUNET_NO; /* Shadow record is expired */
-            if ((rd[k].record_type == rd[i].record_type)
-                && (rd[k].expiration_time >= now.abs_value_us)
-                && (0 == (rd[k].flags & GNUNET_GNSRECORD_RF_SHADOW_RECORD)))
+            if ( (rd[k].record_type == rd[i].record_type) &&
+                 (rd[k].expiration_time >= now.abs_value_us) &&
+                 (0 == (rd[k].flags & GNUNET_GNSRECORD_RF_SHADOW_RECORD)) )
+            {
               include_record = GNUNET_NO; /* We have a non-expired, non-shadow record of the same type */
+              break;
+            }
           }
           if (GNUNET_YES == include_record)
           {
index 190f62fc2c66f7fe9e05ac001fba97ef1d872bb0..1db27464fd2ec344f7ec4792c93d53720353f7dc 100644 (file)
@@ -84,11 +84,10 @@ size_t
 GNUNET_GNSRECORD_records_get_size (unsigned int rd_count,
                                   const struct GNUNET_GNSRECORD_Data *rd)
 {
-  unsigned int i;
   size_t ret;
 
   ret = sizeof (struct NetworkRecord) * rd_count;
-  for (i=0;i<rd_count;i++)
+  for (unsigned int i=0;i<rd_count;i++)
   {
     GNUNET_assert ((ret + rd[i].data_size) >= ret);
     ret += rd[i].data_size;
@@ -113,11 +112,10 @@ GNUNET_GNSRECORD_records_serialize (unsigned int rd_count,
                                    char *dest)
 {
   struct NetworkRecord rec;
-  unsigned int i;
   size_t off;
 
   off = 0;
-  for (i=0;i<rd_count;i++)
+  for (unsigned int i=0;i<rd_count;i++)
   {
     LOG (GNUNET_ERROR_TYPE_DEBUG,
          "Serializing record %u with flags %d and expiration time %llu\n",
@@ -129,17 +127,38 @@ GNUNET_GNSRECORD_records_serialize (unsigned int rd_count,
     rec.record_type = htonl (rd[i].record_type);
     rec.flags = htonl (rd[i].flags);
     if (off + sizeof (rec) > dest_size)
+    {
+      GNUNET_break (0);
       return -1;
+    }
     GNUNET_memcpy (&dest[off],
                    &rec,
                    sizeof (rec));
     off += sizeof (rec);
     if (off + rd[i].data_size > dest_size)
+    {
+      GNUNET_break (0);
       return -1;
+    }
     GNUNET_memcpy (&dest[off],
                    rd[i].data,
                    rd[i].data_size);
     off += rd[i].data_size;
+#if GNUNET_EXTRA_LOGGING
+    {
+      char *str;
+
+      str = GNUNET_GNSRECORD_value_to_string (rd[i].record_type,
+                                              rd[i].data,
+                                              rd[i].data_size);
+      if (NULL == str)
+      {
+        GNUNET_break_op (0);
+        return GNUNET_SYSERR;
+      }
+      GNUNET_free (str);
+    }
+#endif
   }
   return off;
 }
@@ -161,24 +180,46 @@ GNUNET_GNSRECORD_records_deserialize (size_t len,
                                      struct GNUNET_GNSRECORD_Data *dest)
 {
   struct NetworkRecord rec;
-  unsigned int i;
   size_t off;
 
   off = 0;
-  for (i=0;i<rd_count;i++)
+  for (unsigned int i=0;i<rd_count;i++)
   {
     if (off + sizeof (rec) > len)
+    {
+      GNUNET_break_op (0);
       return GNUNET_SYSERR;
-    GNUNET_memcpy (&rec, &src[off], sizeof (rec));
+    }
+    GNUNET_memcpy (&rec,
+                   &src[off],
+                   sizeof (rec));
     dest[i].expiration_time = GNUNET_ntohll (rec.expiration_time);
     dest[i].data_size = ntohl ((uint32_t) rec.data_size);
     dest[i].record_type = ntohl (rec.record_type);
     dest[i].flags = ntohl (rec.flags);
     off += sizeof (rec);
     if (off + dest[i].data_size > len)
+    {
+      GNUNET_break_op (0);
       return GNUNET_SYSERR;
+    }
     dest[i].data = &src[off];
     off += dest[i].data_size;
+#if GNUNET_EXTRA_LOGGING
+    {
+      char *str;
+
+      str = GNUNET_GNSRECORD_value_to_string (dest[i].record_type,
+                                              dest[i].data,
+                                              dest[i].data_size);
+      if (NULL == str)
+      {
+        GNUNET_break_op (0);
+        return GNUNET_SYSERR;
+      }
+      GNUNET_free (str);
+    }
+#endif
     LOG (GNUNET_ERROR_TYPE_DEBUG,
          "Deserialized record %u with flags %d and expiration time %llu\n",
          i,
diff --git a/src/gnsrecord/perf_gnsrecord_crypto.c b/src/gnsrecord/perf_gnsrecord_crypto.c
new file mode 100644 (file)
index 0000000..ff97210
--- /dev/null
@@ -0,0 +1,137 @@
+/*
+     This file is part of GNUnet.
+     Copyright (C) 2018 GNUnet e.V.
+
+     GNUnet is free software; you can redistribute it and/or modify
+     it under the terms of the GNU General Public License as published
+     by the Free Software Foundation; either version 3, or (at your
+     option) any later version.
+
+     GNUnet is distributed in the hope that it will be useful, but
+     WITHOUT ANY WARRANTY; without even the implied warranty of
+     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+     General Public License for more details.
+
+     You should have received a copy of the GNU General Public License
+     along with GNUnet; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+     Boston, MA 02110-1301, USA.
+*/
+/**
+ * @file gnsrecord/test_gnsrecord_crypto.c
+ * @brief testcase for block creation, verification and decryption
+ */
+#include "platform.h"
+#include "gnunet_util_lib.h"
+#include "gnunet_gnsrecord_lib.h"
+
+#define ROUNDS 1000
+
+#define RECORDS 5
+
+#define TEST_RECORD_TYPE 1234
+
+#define TEST_RECORD_DATALEN 123
+
+#define TEST_RECORD_DATA 'a'
+
+#define TEST_REMOVE_RECORD_TYPE 4321
+
+#define TEST_REMOVE_RECORD_DATALEN 255
+
+#define TEST_REMOVE_RECORD_DATA 'b'
+
+
+static struct GNUNET_GNSRECORD_Data *
+create_record (int count)
+{
+  struct GNUNET_GNSRECORD_Data *rd;
+
+  rd = GNUNET_new_array (count,
+                         struct GNUNET_GNSRECORD_Data);
+  for (unsigned int c = 0; c < count; c++)
+  {
+    rd[c].expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000;
+    rd[c].record_type = TEST_RECORD_TYPE;
+    rd[c].data_size = TEST_RECORD_DATALEN;
+    rd[c].data = GNUNET_malloc(TEST_RECORD_DATALEN);
+    memset ((char *) rd[c].data, TEST_RECORD_DATA, TEST_RECORD_DATALEN);
+  }
+  return rd;
+}
+
+
+static void
+run (void *cls,
+     char *const *args,
+     const char *cfgfile,
+     const struct GNUNET_CONFIGURATION_Handle *cfg)
+{
+  struct GNUNET_GNSRECORD_Block *block;
+  struct GNUNET_HashCode query;
+  struct GNUNET_GNSRECORD_Data *s_rd;
+  const char *s_name;
+  struct GNUNET_TIME_Absolute start_time;
+  struct GNUNET_CRYPTO_EcdsaPrivateKey * privkey;
+  struct GNUNET_TIME_Absolute expire;
+
+  (void) cls;
+  (void) args;
+  (void) cfgfile;
+  (void) cfg;
+  expire = GNUNET_TIME_absolute_get();
+  privkey = GNUNET_CRYPTO_ecdsa_key_create ();
+  GNUNET_assert (NULL != privkey);
+
+  /* test block creation */
+  s_name = "DUMMY.dummy.gnunet";
+  s_rd = create_record (RECORDS);
+  start_time = GNUNET_TIME_absolute_get ();
+  for (unsigned int i=0;i<ROUNDS;i++)
+  {
+    GNUNET_assert (NULL != (block =
+                            GNUNET_GNSRECORD_block_create2 (privkey,
+                                                            expire,
+                                                            s_name,
+                                                            s_rd,
+                                                            RECORDS)));
+    GNUNET_GNSRECORD_query_from_private_key (privkey,
+                                             s_name,
+                                             &query);
+    GNUNET_free (block);
+  }
+  fprintf (stderr,
+           "Took %s to produce %u GNS blocks for the DHT\n",
+           GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start_time),
+                                                   GNUNET_YES),
+           ROUNDS);
+  for (unsigned int i=0;i<RECORDS;i++)
+    GNUNET_free ((void *) s_rd[i].data);
+  GNUNET_free (s_rd);
+  GNUNET_free (privkey);
+}
+
+
+int
+main (int argc, char *argv[])
+{
+  static char *const argvx[] = {
+    "perf-gnsrecord-crypto",
+    NULL
+  };
+  static struct GNUNET_GETOPT_CommandLineOption options[] = {
+    GNUNET_GETOPT_OPTION_END
+  };
+
+  if (GNUNET_OK !=
+      GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
+                          argvx,
+                          "perf-gnsrecord-crypto",
+                          "nohelp", options,
+                          &run,
+                          NULL))
+    return 1;
+  return 0;
+}
+
+/* end of test_gnsrecord_crypto.c */
index 1df3f37300e59e30fbeccd89b7f43d0fbb0cdeca..9ba303e6624aadea838f269d7fab600aabc15ebf 100644 (file)
@@ -54,7 +54,7 @@ create_record (int count)
 {
   struct GNUNET_GNSRECORD_Data *rd;
 
-  rd = GNUNET_malloc (count * sizeof (struct GNUNET_GNSRECORD_Data));
+  rd = GNUNET_new_array (count, struct GNUNET_GNSRECORD_Data);
   for (unsigned int c = 0; c < count; c++)
   {
     rd[c].expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000;
@@ -103,11 +103,10 @@ run (void *cls,
   struct GNUNET_CRYPTO_EcdsaPublicKey pubkey;
   struct GNUNET_HashCode query_pub;
   struct GNUNET_HashCode query_priv;
+  struct GNUNET_TIME_Absolute expire = GNUNET_TIME_absolute_get();
 
   privkey = GNUNET_CRYPTO_ecdsa_key_create ();
   GNUNET_assert (NULL != privkey);
-  struct GNUNET_TIME_Absolute expire = GNUNET_TIME_absolute_get();
-
   /* get public key */
   GNUNET_CRYPTO_ecdsa_key_get_public (privkey,
                                       &pubkey);
@@ -142,6 +141,7 @@ run (void *cls,
                                                  &rd_decrypt_cb,
                                                  s_name));
   GNUNET_free (block);
+  GNUNET_free (privkey);
 }
 
 
index eb4a851151333d91819ad88f30d502e91b6d9a61..dcdabaf6be8d1dcd72ef12e9396411e9045879d3 100644 (file)
@@ -265,16 +265,22 @@ main (int argc, char *argv[])
 {
   int ret;
 
-  GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-1");
-  GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-2");
-  GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist");
+  GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_peer1.conf",
+                             "GNUNET_TEST_HOME");
+  GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_peer2.conf",
+                             "GNUNET_TEST_HOME");
+  GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_data.conf",
+                             "GNUNET_TEST_HOME");
   GNUNET_log_setup ("test-gnunet-daemon-hostlist",
                     "WARNING",
                     NULL);
   ret = check ();
-  GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-1");
-  GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-2");
-  GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist");
+  GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_peer1.conf",
+                             "GNUNET_TEST_HOME");
+  GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_peer2.conf",
+                             "GNUNET_TEST_HOME");
+  GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_data.conf",
+                             "GNUNET_TEST_HOME");
   return ret;
 }
 
index 88ad22a1ab29b5aa7bdef344302c037e760201bf..799ffc3ffae781dd504ce3e13dca8313e45154d4 100644 (file)
@@ -562,14 +562,18 @@ main (int argc, char *argv[])
 {
   int ret;
 
-  GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-1");
-  GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-2");
+  GNUNET_DISK_purge_cfg_dir ("test_learning_learn_peer.conf",
+                             "GNUNET_TEST_HOME");
+  GNUNET_DISK_purge_cfg_dir ("test_learning_adv_peer.conf",
+                             "GNUNET_TEST_HOME");
   GNUNET_log_setup ("test-gnunet-daemon-hostlist",
                     "WARNING",
                     NULL);
   ret = check ();
-  GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-1");
-  GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-2");
+  GNUNET_DISK_purge_cfg_dir ("test_learning_learn_peer.conf",
+                             "GNUNET_TEST_HOME");
+  GNUNET_DISK_purge_cfg_dir ("test_learning_adv_peer.conf",
+                             "GNUNET_TEST_HOME");
   if (GNUNET_YES ==
       GNUNET_DISK_file_test ("hostlists_learn_peer.file"))
   {
index 2ebc780a7ebe2db57aea4ae9c171c7c2c56b663c..2ab55b6681ea3b3cc1358ce242ae82f542fc10e8 100644 (file)
@@ -242,9 +242,12 @@ main (int argcx,
     GNUNET_GETOPT_OPTION_END
   };
 
-  GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-1");
-  GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-2");
-  GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-3");
+  GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_peer1.conf",
+                             "GNUNET_TEST_HOME");
+  GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_peer2.conf",
+                             "GNUNET_TEST_HOME");
+  GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_data.conf",
+                             "GNUNET_TEST_HOME");
   GNUNET_log_setup ("test-gnunet-daemon-hostlist",
                     "WARNING",
                     NULL);
@@ -272,9 +275,12 @@ main (int argcx,
             "%s",
             ".\n");
   }
-  GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-1");
-  GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-2");
-  GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-3");
+  GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_peer1.conf",
+                             "GNUNET_TEST_HOME");
+  GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_peer2.conf",
+                             "GNUNET_TEST_HOME");
+  GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_data.conf",
+                             "GNUNET_TEST_HOME");
   return ok;
 }
 
index 47217442a2db7c89ae4c3cda2708613df11ecc53..6d30f9e2a6fbfb8ced2af778f00d5241281cccb7 100644 (file)
@@ -71,7 +71,7 @@ struct GNUNET_IDENTITY_PROVIDER_Operation
    * Attribute result callback
    */
   GNUNET_IDENTITY_PROVIDER_AttributeResult ar_cb;
-  
+
   /**
    * Revocation result callback
    */
@@ -613,7 +613,7 @@ handle_attribute_result (void *cls,
         it->finish_cb (it->finish_cb_cls);
       free_it (it);
     }
-    if (NULL != op) 
+    if (NULL != op)
     {
       if (NULL != op->ar_cb)
         op->ar_cb (op->cls,
@@ -953,7 +953,7 @@ GNUNET_IDENTITY_PROVIDER_attribute_store (struct GNUNET_IDENTITY_PROVIDER_Handle
 
 
 /**
- * List all attributes for a local identity. 
+ * List all attributes for a local identity.
  * This MUST lock the `struct GNUNET_IDENTITY_PROVIDER_Handle`
  * for any other calls than #GNUNET_IDENTITY_PROVIDER_get_attributes_next() and
  * #GNUNET_IDENTITY_PROVIDER_get_attributes_stop. @a proc will be called once
@@ -1370,9 +1370,9 @@ GNUNET_IDENTITY_PROVIDER_ticket_revoke (struct GNUNET_IDENTITY_PROVIDER_Handle *
                              GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_REVOKE_TICKET);
   msg->id = htonl (rid);
   msg->identity = *identity;
-  memcpy (&msg[1],
-          ticket,
-          sizeof (struct GNUNET_IDENTITY_PROVIDER_Ticket));
+  GNUNET_memcpy (&msg[1],
+                 ticket,
+                 sizeof (struct GNUNET_IDENTITY_PROVIDER_Ticket));
   if (NULL == h->mq)
     op->env = env;
   else
index be28854600c1f6c27deaff9ba55118d643b67415..114a220521f785c85fe26a845b61ff6f672d9f60 100644 (file)
@@ -708,6 +708,18 @@ int
 GNUNET_DISK_directory_remove (const char *filename);
 
 
+/**
+ * Remove the directory given under @a option in
+ * section [PATHS] in configuration under @a cfg_filename
+ *
+ * @param cfg_filename configuration file to parse
+ * @param option option with the dir name to purge
+ */
+void
+GNUNET_DISK_purge_cfg_dir (const char *cfg_filename,
+                           const char *option);
+
+
 /**
  * Implementation of "mkdir -p"
  *
index f3adbc4c2fb005bf3ec2ea8c1d23d82bec4e1b9b..61fd5299ae4a0686ad4bf10cb5c9b950e35ff1b6 100644 (file)
@@ -446,6 +446,125 @@ void
 GNUNET_SQ_cleanup_result (struct GNUNET_SQ_ResultSpec *rs);
 
 
+
+/* ******************** sq_prepare.c functions ************** */
+
+
+/**
+ * Information needed to run a list of SQL statements using
+ * #GNUNET_SQ_exec_statements().
+ */
+struct GNUNET_SQ_PrepareStatement {
+
+  /**
+   * Actual SQL statement.
+   */
+  const char *sql;
+
+  /**
+   * Where to store handle?
+   */
+  sqlite3_stmt **pstmt;
+
+};
+
+
+/**
+ * Terminator for executable statement list.
+ */
+#define GNUNET_SQ_PREPARE_END { NULL, NULL }
+
+
+/**
+ * Create a `struct GNUNET_SQ_PrepareStatement`
+ *
+ * @param sql actual SQL statement
+ * @param pstmt where to store the handle
+ * @return initialized struct
+ */
+struct GNUNET_SQ_PrepareStatement
+GNUNET_SQ_make_prepare (const char *sql,
+                        sqlite3_stmt **pstmt);
+
+
+
+/**
+ * Prepare all statements given in the (NULL,NULL)-terminated
+ * array at @a ps
+ *
+ * @param dbh database handle
+ * @param ps array of statements to prepare
+ * @return #GNUNET_OK on success
+ */
+int
+GNUNET_SQ_prepare (sqlite3 *dbh,
+                   const struct GNUNET_SQ_PrepareStatement *ps);
+
+
+/* ******************** sq_exec.c functions ************** */
+
+
+/**
+ * Information needed to run a list of SQL statements using
+ * #GNUNET_SQ_exec_statements().
+ */
+struct GNUNET_SQ_ExecuteStatement {
+
+  /**
+   * Actual SQL statement.
+   */
+  const char *sql;
+
+  /**
+   * Should we ignore errors?
+   */
+  int ignore_errors;
+
+};
+
+
+/**
+ * Terminator for executable statement list.
+ */
+#define GNUNET_SQ_EXECUTE_STATEMENT_END { NULL, GNUNET_SYSERR }
+
+
+/**
+ * Create a `struct GNUNET_SQ_ExecuteStatement` where errors are fatal.
+ *
+ * @param sql actual SQL statement
+ * @return initialized struct
+ */
+struct GNUNET_SQ_ExecuteStatement
+GNUNET_SQ_make_execute (const char *sql);
+
+
+/**
+ * Create a `struct GNUNET_SQ_ExecuteStatement` where errors should
+ * be tolerated.
+ *
+ * @param sql actual SQL statement
+ * @return initialized struct
+ */
+struct GNUNET_SQ_ExecuteStatement
+GNUNET_SQ_make_try_execute (const char *sql);
+
+
+/**
+ * Request execution of an array of statements @a es from Postgres.
+ *
+ * @param dbh database to execute the statements over
+ * @param es #GNUNET_PQ_PREPARED_STATEMENT_END-terminated array of prepared
+ *            statements.
+ * @return #GNUNET_OK on success (modulo statements where errors can be ignored)
+ *         #GNUNET_SYSERR on error
+ */
+int
+GNUNET_SQ_exec_statements (sqlite3 *dbh,
+                           const struct GNUNET_SQ_ExecuteStatement *es);
+
+
+
 #endif  /* GNUNET_SQ_LIB_H_ */
 
 /* end of include/gnunet_sq_lib.h */
index 8ce4d585fcd4dc66bd9cc57b98ca01ccf6080271..ad1a48d6cf038d3d22bdae2225631c7ceab2d19a 100644 (file)
@@ -223,8 +223,11 @@ origin_notify (void *cls,
                void *data)
 {
   char text[] = "pong";
+
   *data_size = strlen(text)+1;
-  memcpy(data, text, *data_size);
+  GNUNET_memcpy (data,
+                 text,
+                 *data_size);
 
   GNUNET_log (GNUNET_ERROR_TYPE_INFO, "origin sends (to all): %s\n", text);
 
index d1ed1cb39bad09d53fa10c1069ede8e7daaec41a..96e86cbb447bfa6c99c26aea5bbd58d66001939b 100644 (file)
@@ -54,7 +54,7 @@ enum pingpong
 struct pingpong_msg
 {
   int peer;
-  enum pingpong msg; 
+  enum pingpong msg;
 };
 
 static void service_connect (void *cls,
@@ -143,13 +143,13 @@ member_join_request (void *cls,
 {
   struct MulticastPeerContext *mc_peer = (struct MulticastPeerContext*)cls;
   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-              "Peer #%u (%s) sent a join request.\n", 
-              mc_peer->peer, 
+              "Peer #%u (%s) sent a join request.\n",
+              mc_peer->peer,
               GNUNET_i2s (multicast_peers[mc_peer->peer]->id));
 }
 
 
-static int 
+static int
 notify (void *cls,
         size_t *data_size,
         void *data)
@@ -163,7 +163,7 @@ notify (void *cls,
   *data_size = sizeof (struct pingpong_msg);
   GNUNET_memcpy(data, pp_msg, *data_size);
 
-  GNUNET_log (GNUNET_ERROR_TYPE_INFO, 
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
               "Peer #%u sents ping to origin\n", mc_peer->peer);
 
   return GNUNET_YES;
@@ -179,20 +179,20 @@ member_join_decision (void *cls,
                       const struct GNUNET_MessageHeader *join_msg)
 {
   struct MulticastPeerContext *mc_peer = (struct MulticastPeerContext*)cls;
-  
-  GNUNET_log (GNUNET_ERROR_TYPE_INFO, 
-              "Peer #%u (%s) received a decision from origin: %s\n", 
-              mc_peer->peer, 
+
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+              "Peer #%u (%s) received a decision from origin: %s\n",
+              mc_peer->peer,
               GNUNET_i2s (multicast_peers[mc_peer->peer]->id),
               (GNUNET_YES == is_admitted)?"accepted":"rejected");
-  
+
   if (GNUNET_YES == is_admitted)
   {
     GNUNET_MULTICAST_member_to_origin (members[mc_peer->peer],
                                        0,
                                        notify,
                                        cls);
-    
+
   }
 }
 
@@ -236,7 +236,7 @@ member_disconnected_cb (void *cls)
 
 
 static void
-member_message (void *cls, 
+member_message (void *cls,
                 const struct GNUNET_MULTICAST_MessageHeader *msg)
 {
   struct MulticastPeerContext *mc_peer = (struct MulticastPeerContext*)cls;
@@ -245,7 +245,7 @@ member_message (void *cls,
   if (PONG == pp_msg->msg && mc_peer->peer == pp_msg->peer)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-                "peer #%i (%s) receives a pong\n", 
+                "peer #%i (%s) receives a pong\n",
                 mc_peer->peer,
                 GNUNET_i2s (multicast_peers[mc_peer->peer]->id));
     mc_peer->test_ok = GNUNET_OK;
@@ -269,9 +269,9 @@ origin_join_request (void *cls,
 
   uint8_t data_size = ntohs (join_msg->size);
 
-  GNUNET_log (GNUNET_ERROR_TYPE_INFO, 
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
               "origin got a join request...\n");
-  GNUNET_log (GNUNET_ERROR_TYPE_INFO, 
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
               "origin receives: '%s'\n", (char *)&join_msg[1]);
 
   char data[] = "Come in!";
@@ -281,7 +281,7 @@ origin_join_request (void *cls,
   join_resp->type = htons (123);
   GNUNET_memcpy (&join_resp[1], data, data_size);
 
-  GNUNET_log (GNUNET_ERROR_TYPE_INFO, 
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
               "origin sends: '%s'\n", data);
 
   GNUNET_MULTICAST_join_decision (jh,
@@ -311,7 +311,7 @@ origin_replay_msg (void *cls,
                    uint64_t message_id,
                    uint64_t fragment_offset,
                    uint64_t flags,
-                   struct GNUNET_MULTICAST_ReplayHandle *rh) 
+                   struct GNUNET_MULTICAST_ReplayHandle *rh)
 {
 
   GNUNET_log (GNUNET_ERROR_TYPE_INFO, "origin replay msg\n");
@@ -319,8 +319,8 @@ origin_replay_msg (void *cls,
 
 
 static int
-origin_notify (void *cls, 
-               size_t *data_size, 
+origin_notify (void *cls,
+               size_t *data_size,
                void *data)
 {
   struct pingpong_msg *rcv_pp_msg = (struct pingpong_msg*)cls;
@@ -329,11 +329,11 @@ origin_notify (void *cls,
   pp_msg->peer = rcv_pp_msg->peer;
   pp_msg->msg = PONG;
   *data_size = sizeof (struct pingpong_msg);
-  memcpy(data, pp_msg, *data_size); 
+  GNUNET_memcpy(data, pp_msg, *data_size);
 
   GNUNET_log (GNUNET_ERROR_TYPE_INFO, "origin sends pong\n");
 
-  return GNUNET_YES; 
+  return GNUNET_YES;
 }
 
 
@@ -345,7 +345,7 @@ origin_request (void *cls,
 
   req++;
   struct pingpong_msg *pp_msg = (struct pingpong_msg *) req;
-  
+
   if (1 != pp_msg->msg) {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "origin didn't reveice a correct request");
   }
@@ -360,7 +360,7 @@ origin_request (void *cls,
 
 static void
 origin_message (void *cls,
-                const struct GNUNET_MULTICAST_MessageHeader *msg) 
+                const struct GNUNET_MULTICAST_MessageHeader *msg)
 {
   GNUNET_log (GNUNET_ERROR_TYPE_INFO, "origin message msg\n");
 }
@@ -386,7 +386,7 @@ multicast_connect (void *cls,
   {
     group_key = GNUNET_CRYPTO_eddsa_key_create ();
     GNUNET_CRYPTO_eddsa_key_get_public (group_key, &group_pub_key);
-  
+
     GNUNET_CRYPTO_hash (&group_pub_key, sizeof (group_pub_key), &group_pub_key_hash);
     origin = GNUNET_MULTICAST_origin_start (cfg,
                                             group_key,
@@ -414,7 +414,7 @@ multicast_connect (void *cls,
   {
     multicast_peer->key = GNUNET_CRYPTO_ecdsa_key_create ();
 
-    sprintf(data, "Hi, I am peer #%u (%s). Can I enter?", 
+    sprintf(data, "Hi, I am peer #%u (%s). Can I enter?",
             multicast_peer->peer,
             GNUNET_i2s (multicast_peers[multicast_peer->peer]->id));
     uint8_t data_size = strlen (data) + 1;
@@ -424,7 +424,7 @@ multicast_connect (void *cls,
     GNUNET_memcpy (&join_msg[1], data, data_size);
 
     GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-                "Peer #%u (%s) tries to join multicast group %s\n", 
+                "Peer #%u (%s) tries to join multicast group %s\n",
                 multicast_peer->peer,
                 GNUNET_i2s (multicast_peers[multicast_peer->peer]->id),
                 GNUNET_h2s (&group_pub_key_hash));
@@ -465,12 +465,12 @@ peer_information_cb (void *cls,
   multicast_peers[mc_peer->peer]->id = pinfo->result.id;
 
   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-              "Got peer information of %s (%s)\n", 
-              (0 == mc_peer->peer)? "origin" : "member", 
+              "Got peer information of %s (%s)\n",
+              (0 == mc_peer->peer)? "origin" : "member",
               GNUNET_i2s (pinfo->result.id));
 
   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-              "Create peer #%u (%s)\n", 
+              "Create peer #%u (%s)\n",
               mc_peer->peer,
               GNUNET_i2s (multicast_peers[mc_peer->peer]->id));
 
@@ -479,7 +479,7 @@ peer_information_cb (void *cls,
     /* connect to multicast service of members */
     op[mc_peer->peer] =
       GNUNET_TESTBED_service_connect (/* Closure for operation */
-                                      NULL, 
+                                      NULL,
                                       /* The peer whose service to connect to */
                                       peers[mc_peer->peer],
                                       /* The name of the service */
@@ -508,8 +508,8 @@ service_connect (void *cls,
 
   if (NULL == ca_result)
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_INFO, 
-                "Connection adapter not created for peer #%u (%s)\n", 
+    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                "Connection adapter not created for peer #%u (%s)\n",
                 mc_peer->peer,
                 GNUNET_i2s (multicast_peers[mc_peer->peer]->id));
 
@@ -519,8 +519,8 @@ service_connect (void *cls,
 
   if (0 == mc_peer->peer)
   {
-    // Get GNUnet identity of members 
-    for (int i = 0; i<PEERS_REQUESTED; i++) 
+    // Get GNUnet identity of members
+    for (int i = 0; i<PEERS_REQUESTED; i++)
     {
       pi_op[i] = GNUNET_TESTBED_peer_get_information (peers[i],
                                                       GNUNET_TESTBED_PIT_IDENTITY,
@@ -547,7 +547,7 @@ service_connect (void *cls,
  * @param PEERS_REQUESTED size of the 'peers' array
  * @param links_succeeded number of links between peers that were created
  * @param links_failed number of links testbed was unable to establish
- */ 
+ */
 static void
 testbed_master (void *cls,
                 struct GNUNET_TESTBED_RunHandle *h,
@@ -562,7 +562,7 @@ testbed_master (void *cls,
   multicast_peers = GNUNET_new_array (PEERS_REQUESTED, struct MulticastPeerContext*);
 
   // Create test contexts for members
-  for (int i = 0; i<PEERS_REQUESTED; i++) 
+  for (int i = 0; i<PEERS_REQUESTED; i++)
   {
     multicast_peers[i] = GNUNET_new (struct MulticastPeerContext);
     multicast_peers[i]->peer = i;
@@ -604,7 +604,7 @@ main (int argc, char *argv[])
   int ret;
   char const *config_file;
 
-  if (strstr (argv[0], "_line") != NULL) 
+  if (strstr (argv[0], "_line") != NULL)
   {
     config_file = "test_multicast_line.conf";
   }
@@ -612,7 +612,7 @@ main (int argc, char *argv[])
   {
     config_file = "test_multicast_star.conf";
   }
-  else 
+  else
   {
     config_file = "test_multicast_star.conf";
   }
@@ -620,19 +620,19 @@ main (int argc, char *argv[])
   result = GNUNET_SYSERR;
   ret =
     GNUNET_TESTBED_test_run ("test-multicast-multipeer",
-                             config_file, 
+                             config_file,
                              /* number of peers to start */
-                             PEERS_REQUESTED, 
+                             PEERS_REQUESTED,
                              /* Event mask - set to 0 for no event notifications */
-                             0LL, 
+                             0LL,
                              /* Controller event callback */
-                             NULL, 
+                             NULL,
                              /* Closure for controller event callback */
-                             NULL, 
+                             NULL,
                              /* called when testbed setup is complete */
-                             testbed_master, 
+                             testbed_master,
                              /* Closure for the test_master callback */
-                             NULL); 
+                             NULL);
   if ( (GNUNET_OK != ret) || (GNUNET_OK != result) )
     return 1;
   return 0;
index 32b1a39d0191e62515b4d232672bb33dfd1dd179..753ee79d13b89dec0fce1df7f55fdf5819fe4fa7 100644 (file)
@@ -79,6 +79,11 @@ static struct GNUNET_NAMESTORE_QueueEntry *add_qe_uri;
  */
 static struct GNUNET_NAMESTORE_QueueEntry *add_qe;
 
+/**
+ * Queue entry for the 'lookup' operation.
+ */
+static struct GNUNET_NAMESTORE_QueueEntry *get_qe;
+
 /**
  * Queue entry for the 'reverse lookup' operation (in combination with a name).
  */
@@ -234,6 +239,11 @@ do_shutdown (void *cls)
     GNUNET_NAMESTORE_cancel (add_qe_uri);
     add_qe_uri = NULL;
   }
+  if (NULL != get_qe)
+  {
+    GNUNET_NAMESTORE_cancel (get_qe);
+    get_qe = NULL;
+  }
   if (NULL != del_qe)
   {
     GNUNET_NAMESTORE_cancel (del_qe);
@@ -271,6 +281,7 @@ test_finished ()
 {
   if ( (NULL == add_qe) &&
        (NULL == add_qe_uri) &&
+       (NULL == get_qe) &&
        (NULL == del_qe) &&
        (NULL == reverse_qe) &&
        (NULL == list_it) )
@@ -491,6 +502,30 @@ display_record_monitor (void *cls,
 }
 
 
+/**
+ * Process a record that was stored in the namestore.
+ *
+ * @param cls closure
+ * @param zone_key private key of the zone
+ * @param rname name that is being mapped (at most 255 characters long)
+ * @param rd_len number of entries in @a rd array
+ * @param rd array of records with data to store
+ */
+static void
+display_record_lookup (void *cls,
+                       const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
+                       const char *rname,
+                       unsigned int rd_len,
+                       const struct GNUNET_GNSRECORD_Data *rd)
+{
+  get_qe = NULL;
+  display_record (rname,
+                  rd_len,
+                  rd);
+  test_finished ();
+}
+
+
 /**
  * Function called once we are in sync in monitor mode.
  *
@@ -522,10 +557,27 @@ monitor_error_cb (void *cls)
 
 
 /**
- * Function called if lookup fails.
+ * Function called on errors while monitoring.
+ *
+ * @param cls NULL
  */
 static void
 lookup_error_cb (void *cls)
+{
+  (void) cls;
+  get_qe = NULL;
+  FPRINTF (stderr,
+          "%s",
+          "Failed to lookup record.\n");
+  test_finished ();
+}
+
+
+/**
+ * Function called if lookup fails.
+ */
+static void
+add_error_cb (void *cls)
 {
   (void) cls;
   add_qe = NULL;
@@ -970,7 +1022,7 @@ identity_cb (void *cls,
     add_qe = GNUNET_NAMESTORE_records_lookup (ns,
                                               &zone_pkey,
                                               name,
-                                              &lookup_error_cb,
+                                              &add_error_cb,
                                               NULL,
                                               &get_existing_record,
                                               NULL);
@@ -996,14 +1048,23 @@ identity_cb (void *cls,
   }
   if (list)
   {
-    list_it = GNUNET_NAMESTORE_zone_iteration_start (ns,
-                                                     &zone_pkey,
-                                                     &zone_iteration_error_cb,
-                                                     NULL,
-                                                     &display_record_iterator,
-                                                     NULL,
-                                                     &zone_iteration_finished,
-                                                     NULL);
+    if (NULL != name)
+      get_qe = GNUNET_NAMESTORE_records_lookup (ns,
+                                                &zone_pkey,
+                                                name,
+                                                &lookup_error_cb,
+                                                NULL,
+                                                &display_record_lookup,
+                                                NULL);
+    else
+      list_it = GNUNET_NAMESTORE_zone_iteration_start (ns,
+                                                       &zone_pkey,
+                                                       &zone_iteration_error_cb,
+                                                       NULL,
+                                                       &display_record_iterator,
+                                                       NULL,
+                                                       &zone_iteration_finished,
+                                                       NULL);
   }
   if (NULL != reverse_pkey)
   {
index f47c8776bb990920d854343fce24b7483a85114a..8e88558def990b2ff0da827372edf8ab0d7f21dd 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     Copyright (C) 2012, 2013, 2014 GNUnet e.V.
+     Copyright (C) 2012, 2013, 2014, 2018 GNUnet e.V.
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -23,6 +23,9 @@
  * @brief namestore for the GNUnet naming system
  * @author Matthias Wachs
  * @author Christian Grothoff
+ *
+ * TODO:
+ * - run testcases, make sure everything works!
  */
 #include "platform.h"
 #include "gnunet_util_lib.h"
 
 #define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file (kind, "util", syscall, filename)
 
+/**
+ * If a monitor takes more than 1 minute to process an event, print a warning.
+ */
+#define MONITOR_STALL_WARN_DELAY GNUNET_TIME_UNIT_MINUTES
+
 
 /**
  * A namestore client
@@ -160,6 +168,16 @@ struct ZoneMonitor
    */
   struct GNUNET_SCHEDULER_Task *task;
 
+  /**
+   * Task to warn about slow monitors.
+   */
+  struct GNUNET_SCHEDULER_Task *sa_wait_warning;
+
+  /**
+   * Since when are we blocked on this monitor?
+   */
+  struct GNUNET_TIME_Absolute sa_waiting_start;
+
   /**
    * Last sequence number in the zone iteration used to address next
    * result of the zone iteration in the store
@@ -175,6 +193,27 @@ struct ZoneMonitor
    */
   uint64_t limit;
 
+  /**
+   * How many more requests may we receive from the iterator
+   * before it is at the limit we gave it?  Will be below or
+   * equal to @e limit.  The effective limit for monitor
+   * events is thus @e iteration_cnt - @e limit!
+   */
+  uint64_t iteration_cnt;
+
+  /**
+   * Are we (still) in the initial iteration pass?
+   */
+  int in_first_iteration;
+
+  /**
+   * Is there a store activity waiting for this monitor?  We only raise the
+   * flag when it happens and search the DLL for the store activity when we
+   * had a limit increase.  If we cannot find any waiting store activity at
+   * that time, we clear the flag again.
+   */
+  int sa_waiting;
+
 };
 
 
@@ -211,6 +250,57 @@ struct CacheOperation
 };
 
 
+/**
+ * Information for an ongoing #handle_record_store() operation.
+ * Needed as we may wait for monitors to be ready for the notification.
+ */
+struct StoreActivity
+{
+  /**
+   * Kept in a DLL.
+   */
+  struct StoreActivity *next;
+
+  /**
+   * Kept in a DLL.
+   */
+  struct StoreActivity *prev;
+
+  /**
+   * Which client triggered the store activity?
+   */
+  struct NamestoreClient *nc;
+
+  /**
+   * Copy of the original store message (as data fields in @e rd will
+   * point into it!).
+   */
+  const struct RecordStoreMessage *rsm;
+
+  /**
+   * Array of record data to store (without NICK unless this is about
+   * #GNUNET_GNS_EMPTY_LABEL_AT).  Length is in @e rd_count.
+   */
+  struct GNUNET_GNSRECORD_Data *rd;
+
+  /**
+   * Next zone monitor that still needs to be notified about this PUT.
+   */
+  struct ZoneMonitor *zm_pos;
+
+  /**
+   * Label nicely canonicalized (lower case).
+   */
+  char *conv_name;
+
+  /**
+   * How many records do we try to store?
+   */
+  unsigned int rd_count;
+
+};
+
+
 /**
  * Public key of all zeros.
  */
@@ -261,6 +351,16 @@ static struct ZoneMonitor *monitor_head;
  */
 static struct ZoneMonitor *monitor_tail;
 
+/**
+ * Head of DLL of monitor-blocked store activities.
+ */
+static struct StoreActivity *sa_head;
+
+/**
+ * Tail of DLL of monitor-blocked store activities.
+ */
+static struct StoreActivity *sa_tail;
+
 /**
  * Notification context shared by all monitors.
  */
@@ -326,80 +426,21 @@ cleanup_task (void *cls)
 
 
 /**
- * Called whenever a client is disconnected.
- * Frees our resources associated with that client.
+ * Release memory used by @a sa.
  *
- * @param cls closure
- * @param client identification of the client
- * @param app_ctx the `struct NamestoreClient` of @a client
+ * @param sa activity to free
  */
 static void
-client_disconnect_cb (void *cls,
-                     struct GNUNET_SERVICE_Client *client,
-                     void *app_ctx)
-{
-  struct NamestoreClient *nc = app_ctx;
-  struct ZoneIteration *no;
-  struct ZoneMonitor *zm;
-  struct CacheOperation *cop;
-
-  (void) cls;
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-             "Client %p disconnected\n",
-             client);
-  for (zm = monitor_head; NULL != zm; zm = zm->next)
-  {
-    if (nc == zm->nc)
-    {
-      GNUNET_CONTAINER_DLL_remove (monitor_head,
-                                  monitor_tail,
-                                  zm);
-      if (NULL != zm->task)
-      {
-       GNUNET_SCHEDULER_cancel (zm->task);
-       zm->task = NULL;
-      }
-      GNUNET_free (zm);
-      break;
-    }
-  }
-  while (NULL != (no = nc->op_head))
-  {
-    GNUNET_CONTAINER_DLL_remove (nc->op_head,
-                                nc->op_tail,
-                                no);
-    GNUNET_free (no);
-  }
-  for (cop = cop_head; NULL != cop; cop = cop->next)
-    if (nc == cop->nc)
-      cop->nc = NULL;
-  GNUNET_free (nc);
-}
-
-
-/**
- * Add a client to our list of active clients.
- *
- * @param cls NULL
- * @param client client to add
- * @param mq message queue for @a client
- * @return internal namestore client structure for this client
- */
-static void *
-client_connect_cb (void *cls,
-                  struct GNUNET_SERVICE_Client *client,
-                  struct GNUNET_MQ_Handle *mq)
+free_store_activity (struct StoreActivity *sa)
 {
-  struct NamestoreClient *nc;
-
-  (void) cls;
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-             "Client %p connected\n",
-             client);
-  nc = GNUNET_new (struct NamestoreClient);
-  nc->client = client;
-  nc->mq = mq;
-  return nc;
+  GNUNET_CONTAINER_DLL_remove (sa_head,
+                               sa_tail,
+                               sa);
+  GNUNET_array_grow (sa->rd,
+                     sa->rd_count,
+                     0);
+  GNUNET_free (sa->conv_name);
+  GNUNET_free (sa);
 }
 
 
@@ -509,18 +550,16 @@ merge_with_nick_records (const struct GNUNET_GNSRECORD_Data *nick_rd,
   uint64_t latest_expiration;
   size_t req;
   char *data;
-  int record_offset;
   size_t data_offset;
 
   (*rdc_res) = 1 + rd2_length;
   if (0 == 1 + rd2_length)
   {
+    GNUNET_break (0);
     (*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;
+  req = sizeof (struct GNUNET_GNSRECORD_Data) + nick_rd->data_size;
   for (unsigned int c=0; c< rd2_length; c++)
     req += sizeof (struct GNUNET_GNSRECORD_Data) + rd2[c].data_size;
   (*rd_res) = GNUNET_malloc (req);
@@ -539,20 +578,19 @@ merge_with_nick_records (const struct GNUNET_GNSRECORD_Data *nick_rd,
       latest_expiration = rd2[c].expiration_time;
     (*rd_res)[c] = rd2[c];
     (*rd_res)[c].data = (void *) &data[data_offset];
-    GNUNET_memcpy ((void *) (*rd_res)[c].data,
+    GNUNET_memcpy (&data[data_offset],
                    rd2[c].data,
                    rd2[c].data_size);
     data_offset += (*rd_res)[c].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,
+  (*rd_res)[rd2_length] = *nick_rd;
+  (*rd_res)[rd2_length].expiration_time = latest_expiration;
+  (*rd_res)[rd2_length].data = (void *) &data[data_offset];
+  GNUNET_memcpy ((void *) (*rd_res)[rd2_length].data,
                 nick_rd->data,
                 nick_rd->data_size);
-  data_offset += (*rd_res)[record_offset].data_size;
+  data_offset += (*rd_res)[rd2_length].data_size;
   GNUNET_assert (req == (sizeof (struct GNUNET_GNSRECORD_Data)) * (*rdc_res) + data_offset);
 }
 
@@ -606,7 +644,8 @@ send_lookup_response (struct NamestoreClient *nc,
   }
 
   name_len = strlen (name) + 1;
-  rd_ser_len = GNUNET_GNSRECORD_records_get_size (res_count, res);
+  rd_ser_len = GNUNET_GNSRECORD_records_get_size (res_count,
+                                                  res);
   env = GNUNET_MQ_msg_extra (zir_msg,
                             name_len + rd_ser_len,
                             GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT);
@@ -655,6 +694,10 @@ send_store_response (struct NamestoreClient *nc,
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "Sending RECORD_STORE_RESPONSE message\n");
+  GNUNET_STATISTICS_update (statistics,
+                            "Store requests completed",
+                            1,
+                            GNUNET_NO);
   env = GNUNET_MQ_msg (rcr_msg,
                       GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE);
   rcr_msg->gns_header.r_id = htonl (rid);
@@ -794,6 +837,208 @@ refresh_block (struct NamestoreClient *nc,
 }
 
 
+/**
+ * Print a warning that one of our monitors is no longer reacting.
+ *
+ * @param cls a `struct ZoneMonitor` to warn about
+ */
+static void
+warn_monitor_slow (void *cls)
+{
+  struct ZoneMonitor *zm = cls;
+
+  GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+              "No response from monitor since %s\n",
+              GNUNET_STRINGS_absolute_time_to_string (zm->sa_waiting_start));
+  zm->sa_wait_warning = GNUNET_SCHEDULER_add_delayed (MONITOR_STALL_WARN_DELAY,
+                                                      &warn_monitor_slow,
+                                                      zm);
+}
+
+
+/**
+ * Continue processing the @a sa.
+ *
+ * @param sa store activity to process
+ */
+static void
+continue_store_activity (struct StoreActivity *sa)
+{
+  const struct RecordStoreMessage *rp_msg = sa->rsm;
+
+  for (struct ZoneMonitor *zm = sa->zm_pos;
+       NULL != zm;
+       zm = sa->zm_pos)
+  {
+    if ( (0 != memcmp (&rp_msg->private_key,
+                       &zm->zone,
+                       sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) &&
+         (0 != memcmp (&zm->zone,
+                       &zero,
+                       sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) )
+      sa->zm_pos = zm->next; /* not interesting to this monitor */
+    if (zm->limit == zm->iteration_cnt)
+    {
+      zm->sa_waiting = GNUNET_YES;
+      zm->sa_waiting_start = GNUNET_TIME_absolute_get ();
+      if (NULL != zm->sa_wait_warning)
+        GNUNET_SCHEDULER_cancel (zm->sa_wait_warning);
+      zm->sa_wait_warning = GNUNET_SCHEDULER_add_delayed (MONITOR_STALL_WARN_DELAY,
+                                                          &warn_monitor_slow,
+                                                          zm);
+      return; /* blocked on zone monitor */
+    }
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "Notifying monitor about changes under label `%s'\n",
+                sa->conv_name);
+    zm->limit--;
+    send_lookup_response (zm->nc,
+                          0,
+                          &rp_msg->private_key,
+                          sa->conv_name,
+                          sa->rd_count,
+                          sa->rd);
+    sa->zm_pos = zm->next;
+  }
+  /* great, done with the monitors, unpack (again) for refresh_block operation */
+  {
+    size_t name_len;
+    size_t rd_ser_len;
+    uint32_t rid;
+    const char *name_tmp;
+    const char *rd_ser;
+    unsigned int rd_count;
+
+    rid = ntohl (rp_msg->gns_header.r_id);
+    name_len = ntohs (rp_msg->name_len);
+    rd_count = ntohs (rp_msg->rd_count);
+    rd_ser_len = ntohs (rp_msg->rd_len);
+    name_tmp = (const char *) &rp_msg[1];
+    rd_ser = &name_tmp[name_len];
+    {
+      struct GNUNET_GNSRECORD_Data rd[rd_count];
+
+      /* We did this before, must succeed again */
+      GNUNET_assert (GNUNET_OK ==
+                     GNUNET_GNSRECORD_records_deserialize (rd_ser_len,
+                                                           rd_ser,
+                                                           rd_count,
+                                                           rd));
+      refresh_block (sa->nc,
+                     rid,
+                     &rp_msg->private_key,
+                     sa->conv_name,
+                     rd_count,
+                     rd);
+    }
+  }
+  GNUNET_SERVICE_client_continue (sa->nc->client);
+  free_store_activity (sa);
+}
+
+
+/**
+ * Called whenever a client is disconnected.
+ * Frees our resources associated with that client.
+ *
+ * @param cls closure
+ * @param client identification of the client
+ * @param app_ctx the `struct NamestoreClient` of @a client
+ */
+static void
+client_disconnect_cb (void *cls,
+                     struct GNUNET_SERVICE_Client *client,
+                     void *app_ctx)
+{
+  struct NamestoreClient *nc = app_ctx;
+  struct ZoneIteration *no;
+  struct CacheOperation *cop;
+
+  (void) cls;
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+             "Client %p disconnected\n",
+             client);
+  for (struct ZoneMonitor *zm = monitor_head; NULL != zm; zm = zm->next)
+  {
+    struct StoreActivity *san;
+
+    if (nc != zm->nc)
+      continue;
+    GNUNET_CONTAINER_DLL_remove (monitor_head,
+                                 monitor_tail,
+                                 zm);
+    if (NULL != zm->task)
+    {
+      GNUNET_SCHEDULER_cancel (zm->task);
+      zm->task = NULL;
+    }
+    if (NULL != zm->sa_wait_warning)
+    {
+      GNUNET_SCHEDULER_cancel (zm->sa_wait_warning);
+      zm->sa_wait_warning = NULL;
+    }
+    for (struct StoreActivity *sa = sa_head; NULL != sa; sa = san)
+    {
+      san = sa->next;
+      if (zm == sa->zm_pos)
+      {
+        sa->zm_pos = zm->next;
+        /* this may free sa */
+        continue_store_activity (sa);
+      }
+    }
+    GNUNET_free (zm);
+    break;
+  }
+  for (struct StoreActivity *sa = sa_head; NULL != sa; sa = sa->next)
+  {
+    if (sa->nc == nc)
+    {
+      /* this may free sa */
+      free_store_activity (sa);
+      break; /* there can only be one per nc */
+    }
+  }
+  while (NULL != (no = nc->op_head))
+  {
+    GNUNET_CONTAINER_DLL_remove (nc->op_head,
+                                nc->op_tail,
+                                no);
+    GNUNET_free (no);
+  }
+  for (cop = cop_head; NULL != cop; cop = cop->next)
+    if (nc == cop->nc)
+      cop->nc = NULL;
+  GNUNET_free (nc);
+}
+
+
+/**
+ * Add a client to our list of active clients.
+ *
+ * @param cls NULL
+ * @param client client to add
+ * @param mq message queue for @a client
+ * @return internal namestore client structure for this client
+ */
+static void *
+client_connect_cb (void *cls,
+                  struct GNUNET_SERVICE_Client *client,
+                  struct GNUNET_MQ_Handle *mq)
+{
+  struct NamestoreClient *nc;
+
+  (void) cls;
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+             "Client %p connected\n",
+             client);
+  nc = GNUNET_new (struct NamestoreClient);
+  nc->client = client;
+  nc->mq = mq;
+  return nc;
+}
+
+
 /**
  * Closure for #lookup_it().
  */
@@ -1073,7 +1318,7 @@ handle_record_store (void *cls,
   const char *rd_ser;
   unsigned int rd_count;
   int res;
-  struct ZoneMonitor *zm;
+  struct StoreActivity *sa;
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "Received NAMESTORE_RECORD_STORE message\n");
@@ -1085,7 +1330,9 @@ handle_record_store (void *cls,
   name_tmp = (const char *) &rp_msg[1];
   rd_ser = &name_tmp[name_len];
   {
-    struct GNUNET_GNSRECORD_Data rd[rd_count];
+    struct GNUNET_GNSRECORD_Data rd[GNUNET_NZL(rd_count)];
+    struct GNUNET_GNSRECORD_Data rd_clean[GNUNET_NZL(rd_count)];
+    unsigned int rd_clean_off;
 
     if (GNUNET_OK !=
        GNUNET_GNSRECORD_records_deserialize (rd_ser_len,
@@ -1108,6 +1355,10 @@ handle_record_store (void *cls,
       GNUNET_SERVICE_client_drop (nc->client);
       return;
     }
+    GNUNET_STATISTICS_update (statistics,
+                              "Well-formed store requests received",
+                              1,
+                              GNUNET_NO);
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                "Creating %u records for name `%s'\n",
                (unsigned int) rd_count,
@@ -1128,9 +1379,6 @@ handle_record_store (void *cls,
     }
     else
     {
-      struct GNUNET_GNSRECORD_Data rd_clean[rd_count];
-      unsigned int rd_clean_off;
-
       /* remove "NICK" records, unless this is for the
          #GNUNET_GNS_EMPTY_LABEL_AT label */
       rd_clean_off = 0;
@@ -1147,59 +1395,39 @@ handle_record_store (void *cls,
                                         conv_name,
                                         rd_clean_off,
                                          rd_clean);
-      if (GNUNET_OK == res)
-      {
-        for (zm = monitor_head; NULL != zm; zm = zm->next)
-        {
-          if ( (0 == memcmp (&rp_msg->private_key,
-                             &zm->zone,
-                             sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) ||
-               (0 == memcmp (&zm->zone,
-                             &zero,
-                             sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) )
-          {
-            GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                        "Notifying monitor about changes under label `%s'\n",
-                        conv_name);
-            send_lookup_response (zm->nc,
-                                  0,
-                                  &rp_msg->private_key,
-                                  conv_name,
-                                  rd_count, rd);
-          }
-          else
-            GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                        "Monitor is for another zone\n");
-        }
-        if (NULL == monitor_head)
-          GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                      "No monitors active\n");
-      }
-      else
-      {
-        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                    "Error storing record: %d\n",
-                    res);
-      }
     }
-    if (GNUNET_OK == res)
+
+    if (GNUNET_OK != res)
     {
-      refresh_block (nc,
-                    rid,
-                     &rp_msg->private_key,
-                     conv_name,
-                     rd_count,
-                    rd);
+      /* store not successful, not need to tell monitors */
+      send_store_response (nc,
+                           res,
+                           rid);
       GNUNET_SERVICE_client_continue (nc->client);
       GNUNET_free (conv_name);
       return;
     }
-    GNUNET_free (conv_name);
+
+    sa = GNUNET_malloc (sizeof (struct StoreActivity) +
+                        ntohs (rp_msg->gns_header.header.size));
+    GNUNET_CONTAINER_DLL_insert (sa_head,
+                                 sa_tail,
+                                 sa);
+    sa->nc = nc;
+    sa->rsm = (const struct RecordStoreMessage *) &sa[1];
+    GNUNET_memcpy (&sa[1],
+                   rp_msg,
+                   ntohs (rp_msg->gns_header.header.size));
+    sa->zm_pos = monitor_head;
+    sa->conv_name = conv_name;
+    GNUNET_array_grow (sa->rd,
+                       sa->rd_count,
+                       rd_clean_off);
+    GNUNET_memcpy (sa->rd,
+                   rd_clean,
+                   sizeof (struct GNUNET_GNSRECORD_Data) * rd_clean_off);
+    continue_store_activity (sa);
   }
-  send_store_response (nc,
-                       res,
-                       rid);
-  GNUNET_SERVICE_client_continue (nc->client);
 }
 
 
@@ -1311,8 +1539,7 @@ handle_zone_to_name (void *cls,
   struct ZoneToNameResponseMessage *ztnr_msg;
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-             "Received `%s' message\n",
-             "ZONE_TO_NAME");
+             "Received ZONE_TO_NAME message\n");
   ztn_ctx.rid = ntohl (ztn_msg->gns_header.r_id);
   ztn_ctx.nc = nc;
   ztn_ctx.success = GNUNET_NO;
@@ -1600,6 +1827,46 @@ handle_iteration_next (void *cls,
 }
 
 
+/**
+ * Function called when the monitor is ready for more data, and we
+ * should thus unblock PUT operations that were blocked on the
+ * monitor not being ready.
+ */
+static void
+monitor_unblock (struct ZoneMonitor *zm)
+{
+  struct StoreActivity *sa = sa_head;
+
+  while ( (NULL != sa) &&
+          (zm->limit > zm->iteration_cnt) )
+  {
+    struct StoreActivity *sn = sa->next;
+
+    if (sa->zm_pos == zm)
+      continue_store_activity (sa);
+    sa = sn;
+  }
+  if (zm->limit > zm->iteration_cnt)
+  {
+    zm->sa_waiting = GNUNET_NO;
+    if (NULL != zm->sa_wait_warning)
+    {
+      GNUNET_SCHEDULER_cancel (zm->sa_wait_warning);
+      zm->sa_wait_warning = NULL;
+    }
+  }
+  else if (GNUNET_YES == zm->sa_waiting)
+  {
+    zm->sa_waiting_start = GNUNET_TIME_absolute_get ();
+    if (NULL != zm->sa_wait_warning)
+      GNUNET_SCHEDULER_cancel (zm->sa_wait_warning);
+    zm->sa_wait_warning = GNUNET_SCHEDULER_add_delayed (MONITOR_STALL_WARN_DELAY,
+                                                        &warn_monitor_slow,
+                                                        zm);
+  }
+}
+
+
 /**
  * Send 'sync' message to zone monitor, we're now in sync.
  *
@@ -1615,16 +1882,22 @@ monitor_sync (struct ZoneMonitor *zm)
                       GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_SYNC);
   GNUNET_MQ_send (zm->nc->mq,
                  env);
+  /* mark iteration done */
+  zm->in_first_iteration = GNUNET_NO;
+  zm->iteration_cnt = 0;
+  if ( (zm->limit > 0) &&
+       (zm->sa_waiting) )
+    monitor_unblock (zm);
 }
 
 
 /**
- * Obtain the next datum during the zone monitor's zone intiial iteration.
+ * Obtain the next datum during the zone monitor's zone initial iteration.
  *
  * @param cls zone monitor that does its initial iteration
  */
 static void
-monitor_next (void *cls);
+monitor_iteration_next (void *cls);
 
 
 /**
@@ -1658,14 +1931,23 @@ monitor_iterate_cb (void *cls,
                             "Monitor notifications sent",
                             1,
                             GNUNET_NO);
+  zm->limit--;
+  zm->iteration_cnt--;
   send_lookup_response (zm->nc,
                        0,
                        zone_key,
                        name,
                        rd_count,
                        rd);
-  zm->task = GNUNET_SCHEDULER_add_now (&monitor_next,
-                                      zm);
+  if ( (0 == zm->iteration_cnt) &&
+       (0 != zm->limit) )
+  {
+    /* We are done with the current iteration batch, AND the
+       client would right now accept more, so go again! */
+    GNUNET_assert (NULL == zm->task);
+    zm->task = GNUNET_SCHEDULER_add_now (&monitor_iteration_next,
+                                         zm);
+  }
 }
 
 
@@ -1687,6 +1969,8 @@ handle_monitor_start (void *cls,
   zm = GNUNET_new (struct ZoneMonitor);
   zm->nc = nc;
   zm->zone = zis_msg->zone;
+  zm->limit = 1;
+  zm->in_first_iteration = (GNUNET_YES == ntohl (zis_msg->iterate_first));
   GNUNET_CONTAINER_DLL_insert (monitor_head,
                               monitor_tail,
                               zm);
@@ -1694,8 +1978,8 @@ handle_monitor_start (void *cls,
   GNUNET_SERVICE_client_continue (nc->client);
   GNUNET_notification_context_add (monitor_nc,
                                   nc->mq);
-  if (GNUNET_YES == ntohl (zis_msg->iterate_first))
-    zm->task = GNUNET_SCHEDULER_add_now (&monitor_next,
+  if (zm->in_first_iteration)
+    zm->task = GNUNET_SCHEDULER_add_now (&monitor_iteration_next,
                                         zm);
   else
     monitor_sync (zm);
@@ -1708,12 +1992,17 @@ handle_monitor_start (void *cls,
  * @param cls zone monitor that does its initial iteration
  */
 static void
-monitor_next (void *cls)
+monitor_iteration_next (void *cls)
 {
   struct ZoneMonitor *zm = cls;
   int ret;
 
   zm->task = NULL;
+  GNUNET_assert (0 == zm->iteration_cnt);
+  if (zm->limit > 16)
+    zm->iteration_cnt = zm->limit / 2; /* leave half for monitor events */
+  else
+    zm->iteration_cnt = zm->limit; /* use it all */
   ret = GSN_database->iterate_records (GSN_database->cls,
                                        (0 == memcmp (&zm->zone,
                                                     &zero,
@@ -1721,7 +2010,7 @@ monitor_next (void *cls)
                                        ? NULL
                                        : &zm->zone,
                                       zm->seq,
-                                       1,
+                                       zm->iteration_cnt,
                                       &monitor_iterate_cb,
                                       zm);
   if (GNUNET_SYSERR == ret)
@@ -1773,13 +2062,30 @@ handle_monitor_next (void *cls,
     return;
   }
   zm->limit += inc;
-#if 0
-  if (GNUNET_YES == ntohl (zis_msg->iterate_first))
-    zm->task = GNUNET_SCHEDULER_add_now (&monitor_next,
-                                        zm);
-  else
-    monitor_sync (zm);
-#endif
+  if ( (zm->in_first_iteration) &&
+       (zm->limit == inc) )
+  {
+    /* We are still iterating, and the previous iteration must
+       have stopped due to the client's limit, so continue it! */
+    GNUNET_assert (NULL == zm->task);
+    zm->task = GNUNET_SCHEDULER_add_now (&monitor_iteration_next,
+                                         zm);
+  }
+  GNUNET_assert (zm->iteration_cnt <= zm->limit);
+  if ( (zm->limit > zm->iteration_cnt) &&
+       (zm->sa_waiting) )
+  {
+    monitor_unblock (zm);
+  }
+  else if (GNUNET_YES == zm->sa_waiting)
+  {
+    if (NULL != zm->sa_wait_warning)
+      GNUNET_SCHEDULER_cancel (zm->sa_wait_warning);
+    zm->sa_waiting_start = GNUNET_TIME_absolute_get ();
+    zm->sa_wait_warning = GNUNET_SCHEDULER_add_delayed (MONITOR_STALL_WARN_DELAY,
+                                                        &warn_monitor_slow,
+                                                        zm);
+  }
 }
 
 
index 0fd0a4ab88838c14c28fd0be3c2686ef3165fe8b..b394178a6ce2a653376ccba37f5531ccba30b07a 100644 (file)
  */
 #define SERIES_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MICROSECONDS, 10)
 
+/**
+ * How long do DNS records have to last at least after being imported?
+ */
+static struct GNUNET_TIME_Relative minimum_expiration_time;
+
 /**
  * How many requests do we request from NAMESTORE in one batch
  * during our initial iteration?
@@ -429,9 +434,9 @@ get_label (struct Request *req)
     GNUNET_break (0);
     return NULL;
   }
-  memcpy (label,
-         req->hostname,
-         dot - req->hostname);
+  GNUNET_memcpy (label,
+                 req->hostname,
+                 dot - req->hostname);
   label[dot - req->hostname] = '\0';
   return label;
 }
@@ -486,9 +491,9 @@ build_dns_query (struct Request *req,
     GNUNET_free (rawp);
     return NULL;
   }
-  memcpy (raw,
-         rawp,
-         *raw_size);
+  GNUNET_memcpy (raw,
+                 rawp,
+                 *raw_size);
   GNUNET_free (rawp);
   return raw;
 }
@@ -632,10 +637,19 @@ check_for_glue (void *cls,
   size_t off;
   char ip[INET6_ADDRSTRLEN+1];
   socklen_t ip_size = (socklen_t) sizeof (ip);
+  struct GNUNET_TIME_Absolute expiration_time;
+  struct GNUNET_TIME_Relative left;
 
   if (0 != strcasecmp (rec->name,
                       gc->ns))
     return;
+  expiration_time = rec->expiration_time;
+  left = GNUNET_TIME_absolute_get_remaining (expiration_time);
+  if (0 == left.rel_value_us)
+    return; /* ignore expired glue records */
+  /* if expiration window is too short, bump it to configured minimum */
+  if (left.rel_value_us < minimum_expiration_time.rel_value_us)
+    expiration_time = GNUNET_TIME_relative_to_absolute (minimum_expiration_time);
   dst_len = sizeof (dst);
   off = 0;
   switch (rec->type)
@@ -668,7 +682,7 @@ check_for_glue (void *cls,
     {
       add_record (gc->req,
                  GNUNET_GNSRECORD_TYPE_GNS2DNS,
-                 rec->expiration_time,
+                 expiration_time,
                  dst,
                  off);
       gc->found = GNUNET_YES;
@@ -702,7 +716,7 @@ check_for_glue (void *cls,
     {
       add_record (gc->req,
                  GNUNET_GNSRECORD_TYPE_GNS2DNS,
-                 rec->expiration_time,
+                 expiration_time,
                  dst,
                  off);
       gc->found = GNUNET_YES;
@@ -722,7 +736,7 @@ check_for_glue (void *cls,
     {
       add_record (gc->req,
                  GNUNET_GNSRECORD_TYPE_GNS2DNS,
-                 rec->expiration_time,
+                 expiration_time,
                  dst,
                  off);
       gc->found = GNUNET_YES;
@@ -768,6 +782,8 @@ process_record (void *cls,
   char dst[65536];
   size_t dst_len;
   size_t off;
+  struct GNUNET_TIME_Absolute expiration_time;
+  struct GNUNET_TIME_Relative left;
 
   dst_len = sizeof (dst);
   off = 0;
@@ -783,18 +799,27 @@ process_record (void *cls,
     return; /* does not match hostname, might be glue, but
               not useful for this pass! */
   }
-  if (0 ==
-      GNUNET_TIME_absolute_get_remaining (rec->expiration_time).rel_value_us)
+  expiration_time = rec->expiration_time;
+  left = GNUNET_TIME_absolute_get_remaining (expiration_time);
+  if (0 == left.rel_value_us)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                "DNS returned expired record for `%s'\n",
                req->hostname);
+    GNUNET_STATISTICS_update (stats,
+                              "# expired records obtained from DNS",
+                              1,
+                              GNUNET_NO);
     return; /* record expired */
   }
+
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "DNS returned record that expires at %s for `%s'\n",
-              GNUNET_STRINGS_absolute_time_to_string (rec->expiration_time),
+              GNUNET_STRINGS_absolute_time_to_string (expiration_time),
               req->hostname);
+  /* if expiration window is too short, bump it to configured minimum */
+  if (left.rel_value_us < minimum_expiration_time.rel_value_us)
+    expiration_time = GNUNET_TIME_relative_to_absolute (minimum_expiration_time);
   switch (rec->type)
   {
   case GNUNET_DNSPARSER_TYPE_NS:
@@ -828,7 +853,7 @@ process_record (void *cls,
                    rec->name);
        add_record (req,
                    GNUNET_GNSRECORD_TYPE_GNS2DNS,
-                   rec->expiration_time,
+                   expiration_time,
                    dst,
                    off);
       }
@@ -853,7 +878,7 @@ process_record (void *cls,
                  rec->name);
       add_record (req,
                  rec->type,
-                 rec->expiration_time,
+                 expiration_time,
                  dst,
                  off);
     }
@@ -878,7 +903,7 @@ process_record (void *cls,
                  rec->name);
       add_record (req,
                  rec->type,
-                 rec->expiration_time,
+                 expiration_time,
                  dst,
                  off);
     }
@@ -896,7 +921,7 @@ process_record (void *cls,
                  rec->name);
       add_record (req,
                  rec->type,
-                 rec->expiration_time,
+                 expiration_time,
                  dst,
                  off);
     }
@@ -913,7 +938,7 @@ process_record (void *cls,
                  rec->name);
       add_record (req,
                  rec->type,
-                 rec->expiration_time,
+                 expiration_time,
                  dst,
                  off);
     }
@@ -931,7 +956,7 @@ process_record (void *cls,
                  rec->name);
       add_record (req,
                  rec->type,
-                 rec->expiration_time,
+                 expiration_time,
                  dst,
                  off);
     }
@@ -948,7 +973,7 @@ process_record (void *cls,
                  rec->name);
       add_record (req,
                  rec->type,
-                 rec->expiration_time,
+                 expiration_time,
                  dst,
                  off);
     }
@@ -966,7 +991,7 @@ process_record (void *cls,
                rec->name);
     add_record (req,
                rec->type,
-               rec->expiration_time,
+               expiration_time,
                rec->data.raw.data,
                rec->data.raw.data_len);
     break;
@@ -1551,7 +1576,17 @@ ns_lookup_result_cb (void *cls,
   {
     struct GNUNET_TIME_Absolute at;
 
-    at.abs_value_us = rd->expiration_time;
+    if (0 != (rd->flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION))
+    {
+      struct GNUNET_TIME_Relative rel;
+
+      rel.rel_value_us = rd->expiration_time;
+      at = GNUNET_TIME_relative_to_absolute (rel);
+    }
+    else
+    {
+      at.abs_value_us = rd->expiration_time;
+    }
     add_record (req,
                rd->record_type,
                at,
@@ -1648,9 +1683,9 @@ queue (const char *hostname)
   req = GNUNET_malloc (sizeof (struct Request) + hlen);
   req->zone = zone;
   req->hostname = (char *) &req[1];
-  memcpy (req->hostname,
-         hostname,
-         hlen);
+  GNUNET_memcpy (req->hostname,
+                 hostname,
+                 hlen);
   req->id = (uint16_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE,
                                                 UINT16_MAX);
   GNUNET_CRYPTO_hash (req->hostname,
@@ -1800,14 +1835,14 @@ process_stdin (void *cls)
     if (0 == idot)
       last = GNUNET_TIME_absolute_get ();
     idot++;
-    if (0 == idot % 10000)
+    if (0 == idot % 100000)
     {
       struct GNUNET_TIME_Relative delta;
 
       delta = GNUNET_TIME_absolute_get_duration (last);
       last = GNUNET_TIME_absolute_get ();
       fprintf (stderr,
-              "Imported 10000 records in %s\n",
+              "Read 10000 domain names in %s\n",
               GNUNET_STRINGS_relative_time_to_string (delta,
                                                       GNUNET_YES));
       GNUNET_STATISTICS_set (stats,
@@ -1986,6 +2021,11 @@ main (int argc,
                                "MAPSIZE",
                                gettext_noop ("size to use for the main hash map"),
                                &map_size),
+    GNUNET_GETOPT_option_relative_time ('m',
+                                        "minimum-expiration",
+                                        "RELATIVETIME",
+                                        gettext_noop ("minimum expiration time we assume for imported records"),
+                                        &minimum_expiration_time),
     GNUNET_GETOPT_OPTION_END
   };
 
index ab356838b7e3bf364217c0f88d90784f3abc338d..57bf8f81be306f8ffc8e9c84e18a677a28736ecf 100644 (file)
 
 #define LOG(kind,...) GNUNET_log_from (kind, "namestore-api",__VA_ARGS__)
 
+/**
+ * We grant the namestore up to 1 minute of latency, if it is slower than
+ * that, store queries will fail.
+ */
+#define NAMESTORE_DELAY_TOLERANCE GNUNET_TIME_UNIT_MINUTES
 
 /**
  * An QueueEntry used to store information for a pending
@@ -99,6 +104,11 @@ struct GNUNET_NAMESTORE_QueueEntry
    */
   struct GNUNET_MQ_Envelope *env;
 
+  /**
+   * Task scheduled to warn us if the namestore is way too slow.
+   */
+  struct GNUNET_SCHEDULER_Task *timeout_task;
+
   /**
    * The operation id this zone iteration operation has
    */
@@ -300,6 +310,8 @@ free_qe (struct GNUNET_NAMESTORE_QueueEntry *qe)
                                qe);
   if (NULL != qe->env)
     GNUNET_MQ_discard (qe->env);
+  if (NULL != qe->timeout_task)
+    GNUNET_SCHEDULER_cancel (qe->timeout_task);
   GNUNET_free (qe);
 }
 
@@ -967,6 +979,33 @@ GNUNET_NAMESTORE_disconnect (struct GNUNET_NAMESTORE_Handle *h)
 }
 
 
+/**
+ * Task launched to warn the user that the namestore is
+ * excessively slow and that a query was thus dropped.
+ *
+ * @param cls a `struct GNUNET_NAMESTORE_QueueEntry *`
+ */
+static void
+warn_delay (void *cls)
+{
+  struct GNUNET_NAMESTORE_QueueEntry *qe = cls;
+
+  qe->timeout_task = NULL;
+  LOG (GNUNET_ERROR_TYPE_WARNING,
+       "Did not receive response from namestore after %s!\n",
+       GNUNET_STRINGS_relative_time_to_string (NAMESTORE_DELAY_TOLERANCE,
+                                               GNUNET_YES));
+  if (NULL != qe->cont)
+  {
+    qe->cont (qe->cont_cls,
+              GNUNET_SYSERR,
+              "timeout");
+    qe->cont = NULL;
+  }
+  GNUNET_NAMESTORE_cancel (qe);
+}
+
+
 /**
  * Store an item in the namestore.  If the item is already present,
  * it is replaced with the new record.  Use an empty array to
@@ -1048,12 +1087,20 @@ GNUNET_NAMESTORE_records_store (struct GNUNET_NAMESTORE_Handle *h,
        "Sending NAMESTORE_RECORD_STORE message for name `%s' with %u records\n",
        label,
        rd_count);
-
+  qe->timeout_task = GNUNET_SCHEDULER_add_delayed (NAMESTORE_DELAY_TOLERANCE,
+                                                   &warn_delay,
+                                                   qe);
   if (NULL == h->mq)
+  {
     qe->env = env;
+    LOG (GNUNET_ERROR_TYPE_WARNING,
+         "Delaying NAMESTORE_RECORD_STORE message as namestore is not ready!\n");
+  }
   else
+  {
     GNUNET_MQ_send (h->mq,
                     env);
+  }
   return qe;
 }
 
index 26e2f2c5102c4c715523ecae5e4c177f57d42a12..f356e9061c32e79614a2a792c7f214ec4c0c50e5 100644 (file)
@@ -5,3 +5,6 @@ DATABASE = flat
 
 [namecache]
 DISABLE = YES
+
+[namestore-flat]
+FILENAME = $GNUNET_TEST_HOME/namestore/flat.db
index 259ce35e73834e6635f3d46ab873888698cee769..16f53025229b07ff64746eab9da293e7322dc77f 100644 (file)
@@ -5,3 +5,7 @@ DATABASE = postgres
 
 [namecache]
 DISABLE = YES
+
+[namestore-postgres]
+CONFIG = connect_timeout=10; dbname=gnunetcheck
+TEMPORARY_TABLE = YES
index 72b609226a16ac1066761316c8fa14835bfa5052..de0fa3f1f81f538ab6f811e9e32bb2b170517709 100644 (file)
@@ -2,3 +2,6 @@
 
 [namecache]
 DISABLE = YES
+
+[namestore-sqlite]
+FILENAME = $GNUNET_TEST_HOME/namestore/sqlite_test.db
index 4ef8d340739c25e668abc76eabb54ccd6cc4bc0c..55d6fafa0da60c3f253e0968b8e34d504a4aa768 100644 (file)
@@ -69,8 +69,6 @@ static struct GNUNET_NAMESTORE_QueueEntry *qe;
 
 static int res;
 
-static char *directory;
-
 static unsigned int off;
 
 static unsigned int left_until_next;
@@ -333,13 +331,6 @@ run (void *cls,
      const struct GNUNET_CONFIGURATION_Handle *cfg,
      struct GNUNET_TESTING_Peer *peer)
 {
-  directory = NULL;
-  GNUNET_assert (GNUNET_OK ==
-                 GNUNET_CONFIGURATION_get_value_string(cfg,
-                                                       "PATHS",
-                                                       "GNUNET_TEST_HOME",
-                                                       &directory));
-  GNUNET_DISK_directory_remove (directory);
   GNUNET_SCHEDULER_add_shutdown (&end,
                                  NULL);
   timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
@@ -367,6 +358,8 @@ main (int argc,
                    "perf_namestore_api_%s.conf",
                    plugin_name);
   res = 1;
+  GNUNET_DISK_purge_cfg_dir (cfg_name,
+                             "GNUNET_TEST_HOME");
   if (0 !=
       GNUNET_TESTING_peer_run ("perf-namestore-api-zone-iteration",
                                cfg_name,
@@ -375,12 +368,9 @@ main (int argc,
   {
     res = 1;
   }
+  GNUNET_DISK_purge_cfg_dir (cfg_name,
+                             "GNUNET_TEST_HOME");
   GNUNET_free (cfg_name);
-  if (NULL != directory)
-  {
-    GNUNET_DISK_directory_remove (directory);
-    GNUNET_free (directory);
-  }
   return res;
 }
 
index bbb9e3c62807f4eb43bb15f89285ee150ab1963d..35d8424b42d58943da2a8cd7e3de6bb2fffc6bbb 100644 (file)
@@ -49,41 +49,6 @@ struct Plugin
    */
   struct GNUNET_CONTAINER_MultiHashMap *hm;
 
-  /**
-   * Offset
-   */
-  uint32_t offset;
-
-  /**
-   * Target Offset
-   */
-  uint32_t target_offset;
-
-  /**
-   * Iterator closure
-   */
-  void *iter_cls;
-
-  /**
-   * Iterator
-   */
-  GNUNET_NAMESTORE_RecordIterator iter;
-
-  /**
-   * Zone to iterate
-   */
-  const struct GNUNET_CRYPTO_EcdsaPrivateKey *iter_zone;
-
-  /**
-   * PKEY to look for in zone to name
-   */
-  const struct GNUNET_CRYPTO_EcdsaPublicKey *iter_pkey;
-
-  /**
-   * Iteration result found
-   */
-  int iter_result_found;
-
 };
 
 
@@ -364,10 +329,10 @@ store_and_free_entries (void *cls,
                                   &record_data_b64);
   }
   GNUNET_asprintf (&line,
-                   "%s,%lu,%u,%s,%s\n",
+                   "%s,%llu,%u,%s,%s\n",
                    zone_private_key,
-                   entry->rvalue,
-                   entry->record_count,
+                   (unsigned long long) entry->rvalue,
+                   (unsigned int) entry->record_count,
                    record_data_b64,
                    entry->label);
   GNUNET_free (record_data_b64);
@@ -608,7 +573,6 @@ iterate_zones (void *cls,
   struct FlatFileEntry *entry = value;
 
   (void) key;
-  ic->pos++;
   if (0 == ic->limit)
     return GNUNET_NO;
   if ( (NULL != ic->zone) &&
@@ -616,6 +580,7 @@ iterate_zones (void *cls,
                      ic->zone,
                      sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) )
     return GNUNET_YES;
+  ic->pos++;
   if (ic->offset > 0)
   {
     ic->offset--;
@@ -670,17 +635,31 @@ namestore_flat_iterate_records (void *cls,
 }
 
 
+/**
+ * Closure for #zone_to_name.
+ */
+struct ZoneToNameContext
+{
+  const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone;
+  const struct GNUNET_CRYPTO_EcdsaPublicKey *value_zone;
+  GNUNET_NAMESTORE_RecordIterator iter;
+  void *iter_cls;
+
+  int result_found;
+};
+
+
 static int
 zone_to_name (void *cls,
               const struct GNUNET_HashCode *key,
               void *value)
 {
-  struct Plugin *plugin = cls;
+  struct ZoneToNameContext *ztn = cls;
   struct FlatFileEntry *entry = value;
 
   (void) key;
   if (0 != memcmp (entry->private_key,
-                   plugin->iter_zone,
+                   ztn->zone,
                    sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)))
     return GNUNET_YES;
 
@@ -688,18 +667,17 @@ zone_to_name (void *cls,
   {
     if (GNUNET_GNSRECORD_TYPE_PKEY != entry->record_data[i].record_type)
       continue;
-    if (0 == memcmp (plugin->iter_pkey,
+    if (0 == memcmp (ztn->value_zone,
                      entry->record_data[i].data,
                      sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)))
     {
-      plugin->iter (plugin->iter_cls,
-                   0,
-                    entry->private_key,
-                    entry->label,
-                    entry->record_count,
-                    entry->record_data);
-      plugin->iter_result_found = GNUNET_YES;
-
+      ztn->iter (ztn->iter_cls,
+                 0,
+                 entry->private_key,
+                 entry->label,
+                 entry->record_count,
+                 entry->record_data);
+      ztn->result_found = GNUNET_YES;
     }
   }
   return GNUNET_YES;
@@ -725,21 +703,21 @@ namestore_flat_zone_to_name (void *cls,
                              void *iter_cls)
 {
   struct Plugin *plugin = cls;
+  struct ZoneToNameContext ztn = {
+    .iter = iter,
+    .iter_cls = iter_cls,
+    .zone = zone,
+    .value_zone = value_zone,
+    .result_found = GNUNET_NO
+  };
 
-  /* FIXME: maybe use separate closure to better handle
-     recursive calls? */
-  plugin->iter = iter;
-  plugin->iter_cls = iter_cls;
-  plugin->iter_zone = zone;
-  plugin->iter_pkey = value_zone;
-  plugin->iter_result_found = GNUNET_NO;
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Performing reverse lookup for `%s'\n",
               GNUNET_GNSRECORD_z2s (value_zone));
   GNUNET_CONTAINER_multihashmap_iterate (plugin->hm,
                                          &zone_to_name,
-                                         plugin);
-  return plugin->iter_result_found;
+                                         &ztn);
+  return ztn.result_found;
 }
 
 
index f62be1e18f8433538a19ebfdadd7427f024ba0b5..34e5486138aaa10795af761fe137e08a7dcc3e23 100644 (file)
@@ -105,72 +105,6 @@ struct Plugin
 };
 
 
-/**
- * @brief Prepare a SQL statement
- *
- * @param dbh handle to the database
- * @param zSql SQL statement, UTF-8 encoded
- * @param ppStmt set to the prepared statement
- * @return 0 on success
- */
-static int
-sq_prepare (sqlite3 *dbh,
-            const char *zSql,
-            sqlite3_stmt **ppStmt)
-{
-  char *dummy;
-  int result;
-
-  result =
-      sqlite3_prepare_v2 (dbh,
-                          zSql,
-                          strlen (zSql),
-                          ppStmt,
-                          (const char **) &dummy);
-  LOG (GNUNET_ERROR_TYPE_DEBUG,
-       "Prepared `%s' / %p: %d\n",
-       zSql,
-       *ppStmt,
-       result);
-  return result;
-}
-
-
-/**
- * Create our database indices.
- *
- * @param dbh handle to the database
- */
-static void
-create_indices (sqlite3 * dbh)
-{
-  /* create indices */
-  if ( (SQLITE_OK !=
-       sqlite3_exec (dbh,
-                      "CREATE INDEX IF NOT EXISTS ir_pkey_reverse "
-                     "ON ns098records (zone_private_key,pkey)",
-                     NULL, NULL, NULL)) ||
-       (SQLITE_OK !=
-       sqlite3_exec (dbh,
-                      "CREATE INDEX IF NOT EXISTS ir_pkey_iter "
-                     "ON ns098records (zone_private_key,uid)",
-                     NULL, NULL, NULL)) )
-    LOG (GNUNET_ERROR_TYPE_ERROR,
-        "Failed to create indices: %s\n",
-         sqlite3_errmsg (dbh));
-}
-
-
-#if 0
-#define CHECK(a) GNUNET_break(a)
-#define ENULL NULL
-#else
-#define ENULL &e
-#define ENULL_DEFINED 1
-#define CHECK(a) if (! (a)) { GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "%s\n", e); sqlite3_free(e); }
-#endif
-
-
 /**
  * Initialize the database connections and associated
  * data structures (create tables and indices
@@ -182,17 +116,66 @@ create_indices (sqlite3 * dbh)
 static int
 database_setup (struct Plugin *plugin)
 {
-  sqlite3_stmt *stmt;
-  char *afsdir;
-#if ENULL_DEFINED
-  char *e;
-#endif
+  char *sqlite_filename;
+  struct GNUNET_SQ_ExecuteStatement es[] = {
+    GNUNET_SQ_make_try_execute ("PRAGMA temp_store=MEMORY"),
+    GNUNET_SQ_make_try_execute ("PRAGMA synchronous=NORMAL"),
+    GNUNET_SQ_make_try_execute ("PRAGMA legacy_file_format=OFF"),
+    GNUNET_SQ_make_try_execute ("PRAGMA auto_vacuum=INCREMENTAL"),
+    GNUNET_SQ_make_try_execute ("PRAGMA encoding=\"UTF-8\""),
+    GNUNET_SQ_make_try_execute ("PRAGMA locking_mode=EXCLUSIVE"),
+    GNUNET_SQ_make_try_execute ("PRAGMA page_size=4092"),
+    GNUNET_SQ_make_execute ("CREATE TABLE IF NOT EXISTS ns098records ("
+                            " uid INTEGER PRIMARY KEY,"
+                            " zone_private_key BLOB NOT NULL,"
+                            " pkey BLOB,"
+                            " rvalue INT8 NOT NULL,"
+                            " record_count INT NOT NULL,"
+                            " record_data BLOB NOT NULL,"
+                            " label TEXT NOT NULL"
+                            ")"),
+    GNUNET_SQ_make_try_execute ("CREATE INDEX IF NOT EXISTS ir_pkey_reverse "
+                                "ON ns098records (zone_private_key,pkey)"),
+    GNUNET_SQ_make_try_execute ("CREATE INDEX IF NOT EXISTS ir_pkey_iter "
+                                "ON ns098records (zone_private_key,uid)"),
+    GNUNET_SQ_EXECUTE_STATEMENT_END
+  };
+  struct GNUNET_SQ_PrepareStatement ps[] = {
+    GNUNET_SQ_make_prepare ("INSERT INTO ns098records "
+                            "(zone_private_key,pkey,rvalue,record_count,record_data,label)"
+                            " VALUES (?, ?, ?, ?, ?, ?)",
+                            &plugin->store_records),
+    GNUNET_SQ_make_prepare ("DELETE FROM ns098records "
+                            "WHERE zone_private_key=? AND label=?",
+                            &plugin->delete_records),
+    GNUNET_SQ_make_prepare ("SELECT uid,record_count,record_data,label"
+                            " FROM ns098records"
+                            " WHERE zone_private_key=? AND pkey=?",
+                            &plugin->zone_to_name),
+    GNUNET_SQ_make_prepare ("SELECT uid,record_count,record_data,label"
+                            " FROM ns098records"
+                            " WHERE zone_private_key=? AND _rowid_ >= ?"
+                            " ORDER BY _rowid_ ASC"
+                            " LIMIT ?",
+                            &plugin->iterate_zone),
+    GNUNET_SQ_make_prepare ("SELECT uid,record_count,record_data,label,zone_private_key"
+                            " FROM ns098records"
+                            " WHERE _rowid_ >= ?"
+                            " ORDER BY _rowid_ ASC"
+                            " LIMIT ?",
+                            &plugin->iterate_all_zones),
+    GNUNET_SQ_make_prepare ("SELECT uid,record_count,record_data,label,zone_private_key"
+                            " FROM ns098records"
+                            " WHERE zone_private_key=? AND label=?",
+                            &plugin->lookup_label),
+    GNUNET_SQ_PREPARE_END
+  };
 
   if (GNUNET_OK !=
       GNUNET_CONFIGURATION_get_value_filename (plugin->cfg,
                                                "namestore-sqlite",
                                                "FILENAME",
-                                               &afsdir))
+                                               &sqlite_filename))
   {
     GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
                               "namestore-sqlite",
@@ -200,132 +183,51 @@ database_setup (struct Plugin *plugin)
     return GNUNET_SYSERR;
   }
   if (GNUNET_OK !=
-      GNUNET_DISK_file_test (afsdir))
+      GNUNET_DISK_file_test (sqlite_filename))
   {
     if (GNUNET_OK !=
-        GNUNET_DISK_directory_create_for_file (afsdir))
+        GNUNET_DISK_directory_create_for_file (sqlite_filename))
     {
       GNUNET_break (0);
-      GNUNET_free (afsdir);
+      GNUNET_free (sqlite_filename);
       return GNUNET_SYSERR;
     }
   }
-  /* afsdir should be UTF-8-encoded. If it isn't, it's a bug */
-  plugin->fn = afsdir;
+  /* sqlite_filename should be UTF-8-encoded. If it isn't, it's a bug */
+  plugin->fn = sqlite_filename;
 
   /* Open database and precompile statements */
-  if (sqlite3_open (plugin->fn, &plugin->dbh) != SQLITE_OK)
+  if (SQLITE_OK !=
+      sqlite3_open (plugin->fn,
+                    &plugin->dbh))
   {
     LOG (GNUNET_ERROR_TYPE_ERROR,
         _("Unable to initialize SQLite: %s.\n"),
         sqlite3_errmsg (plugin->dbh));
     return GNUNET_SYSERR;
   }
-  CHECK (SQLITE_OK ==
-         sqlite3_exec (plugin->dbh,
-                       "PRAGMA temp_store=MEMORY", NULL, NULL,
-                       ENULL));
-  CHECK (SQLITE_OK ==
-         sqlite3_exec (plugin->dbh,
-                       "PRAGMA synchronous=NORMAL", NULL, NULL,
-                       ENULL));
-  CHECK (SQLITE_OK ==
-         sqlite3_exec (plugin->dbh,
-                       "PRAGMA legacy_file_format=OFF", NULL, NULL,
-                       ENULL));
-  CHECK (SQLITE_OK ==
-         sqlite3_exec (plugin->dbh,
-                       "PRAGMA auto_vacuum=INCREMENTAL", NULL,
-                       NULL, ENULL));
-  CHECK (SQLITE_OK ==
-         sqlite3_exec (plugin->dbh,
-                       "PRAGMA encoding=\"UTF-8\"", NULL,
-                       NULL, ENULL));
-  CHECK (SQLITE_OK ==
-         sqlite3_exec (plugin->dbh,
-                       "PRAGMA locking_mode=EXCLUSIVE", NULL, NULL,
-                       ENULL));
-  CHECK (SQLITE_OK ==
-         sqlite3_exec (plugin->dbh,
-                       "PRAGMA page_size=4092", NULL, NULL,
-                       ENULL));
-
-  CHECK (SQLITE_OK ==
-         sqlite3_busy_timeout (plugin->dbh,
-                               BUSY_TIMEOUT_MS));
-
-
-  /* Create table */
-  CHECK (SQLITE_OK ==
-         sq_prepare (plugin->dbh,
-                     "SELECT 1 FROM sqlite_master WHERE tbl_name = 'ns098records'",
-                     &stmt));
-  if ( (sqlite3_step (stmt) == SQLITE_DONE) &&
-       (SQLITE_OK !=
-       sqlite3_exec (plugin->dbh,
-                     "CREATE TABLE ns098records ("
-                     " uid INTEGER PRIMARY KEY,"
-                     " zone_private_key BLOB NOT NULL,"
-                     " pkey BLOB,"
-                     " rvalue INT8 NOT NULL,"
-                     " record_count INT NOT NULL,"
-                     " record_data BLOB NOT NULL,"
-                     " label TEXT NOT NULL"
-                     ")",
-                     NULL, NULL, NULL)) )
+  GNUNET_break (SQLITE_OK ==
+                sqlite3_busy_timeout (plugin->dbh,
+                                      BUSY_TIMEOUT_MS));
+  if (GNUNET_OK !=
+      GNUNET_SQ_exec_statements (plugin->dbh,
+                                 es))
   {
-    LOG_SQLITE (plugin,
-               GNUNET_ERROR_TYPE_ERROR,
-                "sqlite3_exec");
-    sqlite3_finalize (stmt);
+    GNUNET_break (0);
+    LOG (GNUNET_ERROR_TYPE_ERROR,
+        _("Failed to setup database at `%s'\n"),
+        plugin->fn);
     return GNUNET_SYSERR;
   }
-  sqlite3_finalize (stmt);
-
-  create_indices (plugin->dbh);
-
-  if ( (SQLITE_OK !=
-        sq_prepare (plugin->dbh,
-                    "INSERT INTO ns098records (zone_private_key, pkey, rvalue, record_count, record_data, label)"
-                    " VALUES (?, ?, ?, ?, ?, ?)",
-                    &plugin->store_records)) ||
-       (SQLITE_OK !=
-        sq_prepare (plugin->dbh,
-                    "DELETE FROM ns098records WHERE zone_private_key=? AND label=?",
-                    &plugin->delete_records)) ||
-       (SQLITE_OK !=
-        sq_prepare (plugin->dbh,
-                    "SELECT uid,record_count,record_data,label"
-                    " FROM ns098records"
-                   " WHERE zone_private_key=? AND pkey=?",
-                    &plugin->zone_to_name)) ||
-       (SQLITE_OK !=
-        sq_prepare (plugin->dbh,
-                    "SELECT uid,record_count,record_data,label"
-                    " FROM ns098records"
-                   " WHERE zone_private_key=? AND _rowid_ >= ?"
-                    " ORDER BY _rowid_ ASC"
-                   " LIMIT ?",
-                    &plugin->iterate_zone)) ||
-       (SQLITE_OK !=
-        sq_prepare (plugin->dbh,
-                    "SELECT uid,record_count,record_data,label,zone_private_key"
-                    " FROM ns098records"
-                   " WHERE _rowid_ >= ?"
-                   " ORDER BY _rowid_ ASC"
-                   " LIMIT ?",
-                    &plugin->iterate_all_zones))  ||
-       (SQLITE_OK !=
-        sq_prepare (plugin->dbh,
-                    "SELECT uid,record_count,record_data,label,zone_private_key"
-                    " FROM ns098records"
-                   " WHERE zone_private_key=? AND label=?",
-                    &plugin->lookup_label))
-       )
+
+  if (GNUNET_OK !=
+      GNUNET_SQ_prepare (plugin->dbh,
+                         ps))
   {
-    LOG_SQLITE (plugin,
-                GNUNET_ERROR_TYPE_ERROR,
-                "precompiling");
+    GNUNET_break (0);
+    LOG (GNUNET_ERROR_TYPE_ERROR,
+        _("Failed to setup database at `%s'\n"),
+        plugin->fn);
     return GNUNET_SYSERR;
   }
   return GNUNET_OK;
index 1e36c52fe4c81b331703d67851bd2115ee25df54..07409ea2b315c52f7a3ab8ba1dbe1fb25835670b 100644 (file)
@@ -15,13 +15,6 @@ AUTOSTART = YES
 [identity]
 AUTOSTART = YES
 
-[namestore-sqlite]
-FILENAME = $GNUNET_TEST_HOME/namestore/sqlite_test.db
-
-[namestore-postgres]
-CONFIG = connect_timeout=10; dbname=gnunetcheck
-TEMPORARY_TABLE = YES
-
 [nse]
 WORKBITS = 0
 
index 49fe2546837bc62c715e3bf1ee6aee43d36d254f..6a28306e3767f42b35f7263e94d98565cb7c6d47 100644 (file)
@@ -2,3 +2,6 @@
 
 [namestore]
 DATABASE = flat
+
+[namestore-flat]
+FILENAME = $GNUNET_TEST_HOME/namestore/flat.db
index 50d1fd9a9c6a42c583413268ad806011df6eb927..b9ae93bf2b8cdf84275efd225c14607340efb23a 100644 (file)
@@ -52,7 +52,6 @@ static struct GNUNET_NAMESTORE_QueueEntry *nsqe;
 //static const char * name = "dummy.dummy.gnunet";
 static const char * name = "d";
 
-static char *directory;
 
 static void
 cleanup ()
@@ -283,29 +282,22 @@ run (void *cls,
      const struct GNUNET_CONFIGURATION_Handle *cfg,
      struct GNUNET_TESTING_Peer *peer)
 {
-  char *hostkey_file;
-
-  directory = NULL;
-  GNUNET_assert (GNUNET_OK ==
-                 GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS", "GNUNET_TEST_HOME", &directory));
-  GNUNET_DISK_directory_remove (directory);
-
   endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
-                                               &endbadly, NULL);
-  GNUNET_asprintf (&hostkey_file,
-                  "zonefiles%s%s",
-                  DIR_SEPARATOR_STR,
-                  "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
-  privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file);
-  GNUNET_free (hostkey_file);
+                                               &endbadly,
+                                                NULL);
+  privkey = GNUNET_CRYPTO_ecdsa_key_create ();
   GNUNET_assert (privkey != NULL);
-  GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey);
+  GNUNET_CRYPTO_ecdsa_key_get_public (privkey,
+                                      &pubkey);
 
   nsh = GNUNET_NAMESTORE_connect (cfg);
   GNUNET_break (NULL != nsh);
 
-  nsqe = GNUNET_NAMESTORE_set_nick (nsh, privkey, TEST_NICK, &nick_cont, (void *) name);
+  nsqe = GNUNET_NAMESTORE_set_nick (nsh,
+                                    privkey,
+                                    TEST_NICK,
+                                    &nick_cont,
+                                    (void *) name);
   if (NULL == nsqe)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -324,6 +316,8 @@ main (int argc, char *argv[])
   GNUNET_asprintf (&cfg_name,
                    "test_namestore_api_%s.conf",
                    plugin_name);
+  GNUNET_DISK_purge_cfg_dir (cfg_name,
+                             "GNUNET_TEST_HOME");
   res = 1;
   if (0 !=
       GNUNET_TESTING_peer_run ("test-namestore-api-lookup-nick",
@@ -333,12 +327,9 @@ main (int argc, char *argv[])
   {
     res = 1;
   }
+  GNUNET_DISK_purge_cfg_dir (cfg_name,
+                             "GNUNET_TEST_HOME");
   GNUNET_free (cfg_name);
-  if (NULL != directory)
-  {
-      GNUNET_DISK_directory_remove (directory);
-      GNUNET_free (directory);
-  }
   return res;
 }
 
index 7866749f1ae43f40b43874e79e4ae13020f907b0..689e73a2e904d53d2ef90a44b728ac988c321d7e 100644 (file)
@@ -48,7 +48,6 @@ static struct GNUNET_NAMESTORE_QueueEntry *nsqe;
 //static const char * name = "dummy.dummy.gnunet";
 static const char * name = "d";
 
-static char *directory;
 
 static void
 cleanup ()
@@ -71,11 +70,11 @@ cleanup ()
  * Re-establish the connection to the service.
  *
  * @param cls handle to use to re-connect.
- * @param tc scheduler context
  */
 static void
 endbadly (void *cls)
 {
+  endbadly_task = NULL;
   if (NULL != nsqe)
   {
     GNUNET_NAMESTORE_cancel (nsqe);
@@ -109,7 +108,7 @@ lookup_it (void *cls,
   {
     GNUNET_break(0);
     GNUNET_SCHEDULER_cancel (endbadly_task);
-    endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL );
+    endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
     return;
   }
 
@@ -118,7 +117,7 @@ lookup_it (void *cls,
   {
     GNUNET_break(0);
     GNUNET_SCHEDULER_cancel (endbadly_task);
-    endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL );
+    endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
     return;
   }
 
@@ -126,7 +125,7 @@ lookup_it (void *cls,
   {
     GNUNET_break(0);
     GNUNET_SCHEDULER_cancel (endbadly_task);
-    endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL );
+    endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
     return;
   }
 
@@ -134,14 +133,14 @@ lookup_it (void *cls,
   {
     GNUNET_break(0);
     GNUNET_SCHEDULER_cancel (endbadly_task);
-    endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL );
+    endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
     return;
   }
 
   /* Done */
   GNUNET_SCHEDULER_cancel (endbadly_task);
   endbadly_task = NULL;
-  GNUNET_SCHEDULER_add_now (&end, NULL );
+  GNUNET_SCHEDULER_add_now (&end, NULL);
 }
 
 
@@ -153,7 +152,9 @@ fail_cb (void *cls)
 
 
 static void
-put_cont (void *cls, int32_t success, const char *emsg)
+put_cont (void *cls,
+          int32_t success,
+          const char *emsg)
 {
   const char *name = cls;
 
@@ -187,22 +188,11 @@ run (void *cls,
      struct GNUNET_TESTING_Peer *peer)
 {
   struct GNUNET_GNSRECORD_Data rd;
-  char *hostkey_file;
-
-  directory = NULL;
-  GNUNET_assert (GNUNET_OK ==
-                 GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS", "GNUNET_TEST_HOME", &directory));
-  GNUNET_DISK_directory_remove (directory);
 
   endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
-                                               &endbadly, NULL);
-  GNUNET_asprintf (&hostkey_file,
-                  "zonefiles%s%s",
-                  DIR_SEPARATOR_STR,
-                  "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
-  privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file);
-  GNUNET_free (hostkey_file);
+                                               &endbadly,
+                                                NULL);
+  privkey = GNUNET_CRYPTO_ecdsa_key_create ();
   GNUNET_assert (privkey != NULL);
   GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey);
 
@@ -215,8 +205,13 @@ run (void *cls,
 
   nsh = GNUNET_NAMESTORE_connect (cfg);
   GNUNET_break (NULL != nsh);
-  nsqe = GNUNET_NAMESTORE_records_store (nsh, privkey, name,
-                                     1, &rd, &put_cont, (void *) name);
+  nsqe = GNUNET_NAMESTORE_records_store (nsh,
+                                         privkey,
+                                         name,
+                                         1,
+                                         &rd,
+                                         &put_cont,
+                                         (void *) name);
   if (NULL == nsqe)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -237,6 +232,8 @@ main (int argc, char *argv[])
   GNUNET_asprintf (&cfg_name,
                    "test_namestore_api_%s.conf",
                    plugin_name);
+  GNUNET_DISK_purge_cfg_dir (cfg_name,
+                             "GNUNET_TEST_HOME");
   res = 1;
   if (0 !=
       GNUNET_TESTING_peer_run ("test-namestore-api-lookup-private",
@@ -246,12 +243,9 @@ main (int argc, char *argv[])
   {
     res = 1;
   }
+  GNUNET_DISK_purge_cfg_dir (cfg_name,
+                             "GNUNET_TEST_HOME");
   GNUNET_free (cfg_name);
-  if (NULL != directory)
-  {
-      GNUNET_DISK_directory_remove (directory);
-      GNUNET_free (directory);
-  }
   return res;
 }
 
index 02ca16042006c8036bd93a429e8e5d59a4970521..28a68daf9c721a2414a2b4c3aa20eeb8cb8f2953 100644 (file)
@@ -51,7 +51,6 @@ static struct GNUNET_NAMESTORE_QueueEntry *nsqe;
 
 static struct GNUNET_NAMECACHE_QueueEntry *ncqe;
 
-static char *directory;
 
 static void
 cleanup ()
@@ -190,26 +189,15 @@ run (void *cls,
      struct GNUNET_TESTING_Peer *peer)
 {
   struct GNUNET_GNSRECORD_Data rd;
-  char *hostkey_file;
   const char * name = "dummy.dummy.gnunet";
 
-  directory = NULL;
-  GNUNET_assert (GNUNET_OK ==
-                 GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS", "GNUNET_TEST_HOME", &directory));
-  GNUNET_DISK_directory_remove (directory);
-
   endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
-                                               &endbadly, NULL);
-  GNUNET_asprintf (&hostkey_file,
-                  "zonefiles%s%s",
-                  DIR_SEPARATOR_STR,
-                  "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
-  privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file);
-  GNUNET_free (hostkey_file);
+                                               &endbadly,
+                                                NULL);
+  privkey = GNUNET_CRYPTO_ecdsa_key_create ();
   GNUNET_assert (privkey != NULL);
-  GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey);
-
+  GNUNET_CRYPTO_ecdsa_key_get_public (privkey,
+                                      &pubkey);
 
   rd.expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000;
   rd.record_type = TEST_RECORD_TYPE;
@@ -244,6 +232,8 @@ main (int argc, char *argv[])
   GNUNET_asprintf (&cfg_name,
                    "test_namestore_api_%s.conf",
                    plugin_name);
+  GNUNET_DISK_purge_cfg_dir (cfg_name,
+                             "GNUNET_TEST_HOME");
   res = 1;
   if (0 !=
       GNUNET_TESTING_peer_run ("test-namestore-api",
@@ -253,12 +243,9 @@ main (int argc, char *argv[])
   {
     res = 1;
   }
+  GNUNET_DISK_purge_cfg_dir (cfg_name,
+                             "GNUNET_TEST_HOME");
   GNUNET_free (cfg_name);
-  if (NULL != directory)
-  {
-      GNUNET_DISK_directory_remove (directory);
-      GNUNET_free (directory);
-  }
   return res;
 }
 
index e8033579646ea880fa74fddb42b73b4ae5436cf2..39ce4e564fb2369957d1fa4ce0400758e158def3 100644 (file)
@@ -53,7 +53,6 @@ static struct GNUNET_NAMESTORE_QueueEntry *nsqe;
 
 static struct GNUNET_NAMECACHE_QueueEntry *ncqe;
 
-static char *directory;
 
 static void
 cleanup ()
@@ -222,26 +221,15 @@ run (void *cls,
      struct GNUNET_TESTING_Peer *peer)
 {
   struct GNUNET_GNSRECORD_Data rd;
-  char *hostkey_file;
   const char * name = "dummy.dummy.gnunet";
 
-  directory = NULL;
-  GNUNET_assert (GNUNET_OK ==
-                 GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS", "GNUNET_TEST_HOME", &directory));
-  GNUNET_DISK_directory_remove (directory);
-
   endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
-                                               &endbadly, NULL);
-  GNUNET_asprintf (&hostkey_file,
-                  "zonefiles%s%s",
-                  DIR_SEPARATOR_STR,
-                  "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
-  privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file);
-  GNUNET_free (hostkey_file);
+                                               &endbadly,
+                                                NULL);
+  privkey = GNUNET_CRYPTO_ecdsa_key_create ();
   GNUNET_assert (privkey != NULL);
-  GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey);
-
+  GNUNET_CRYPTO_ecdsa_key_get_public (privkey,
+                                      &pubkey);
   rd.expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000;
   rd.record_type = TEST_RECORD_TYPE;
   rd.data_size = TEST_RECORD_DATALEN;
@@ -253,8 +241,13 @@ run (void *cls,
   nch = GNUNET_NAMECACHE_connect (cfg);
   GNUNET_break (NULL != nsh);
   GNUNET_break (NULL != nch);
-  nsqe = GNUNET_NAMESTORE_records_store (nsh, privkey, name,
-                                     1, &rd, &put_cont, (void *) name);
+  nsqe = GNUNET_NAMESTORE_records_store (nsh,
+                                         privkey,
+                                         name,
+                                         1,
+                                         &rd,
+                                         &put_cont,
+                                         (void *) name);
   if (NULL == nsqe)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -274,6 +267,8 @@ main (int argc, char *argv[])
   GNUNET_asprintf (&cfg_name,
                    "test_namestore_api_%s.conf",
                    plugin_name);
+  GNUNET_DISK_purge_cfg_dir (cfg_name,
+                             "GNUNET_TEST_HOME");
   res = 1;
   if (0 !=
       GNUNET_TESTING_peer_run ("test-namestore-api-lookup-shadow",
@@ -284,11 +279,8 @@ main (int argc, char *argv[])
     res = 1;
   }
   GNUNET_free (cfg_name);
-  if (NULL != directory)
-  {
-      GNUNET_DISK_directory_remove (directory);
-      GNUNET_free (directory);
-  }
+  GNUNET_DISK_purge_cfg_dir (cfg_name,
+                             "GNUNET_TEST_HOME");
   return res;
 }
 
index 5b8811a2315a8babe80d5701bb074b6e29b4d0a9..09fd8ce073cf3028c0ce2b84be8ce7b7883c6a78 100644 (file)
@@ -66,7 +66,6 @@ static struct GNUNET_HashCode derived_hash;
 
 static struct GNUNET_CRYPTO_EcdsaPublicKey pubkey;
 
-static char *directory;
 
 static void
 cleanup ()
@@ -291,26 +290,16 @@ run (void *cls,
      const struct GNUNET_CONFIGURATION_Handle *cfg,
      struct GNUNET_TESTING_Peer *peer)
 {
-  char *hostkey_file;
-
-  directory = NULL;
-  GNUNET_assert (GNUNET_OK ==
-                 GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS", "GNUNET_TEST_HOME", &directory));
-  GNUNET_DISK_directory_remove (directory);
-
   endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
-                                               &endbadly, NULL);
-  GNUNET_asprintf (&hostkey_file,
-                  "zonefiles%s%s",
-                  DIR_SEPARATOR_STR,
-                  "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
-  privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file);
-  GNUNET_free (hostkey_file);
+                                               &endbadly,
+                                                NULL);
+  privkey = GNUNET_CRYPTO_ecdsa_key_create ();
   GNUNET_assert (privkey != NULL);
-  GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey);
+  GNUNET_CRYPTO_ecdsa_key_get_public (privkey,
+                                      &pubkey);
 
-  record_expiration = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), EXPIRATION);
+  record_expiration = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get(),
+                                                EXPIRATION);
   records[0].expiration_time = record_expiration.abs_value_us;
   records[0].record_type = TEST_RECORD_TYPE;
   records[0].data_size = TEST_RECORD_DATALEN;
@@ -352,6 +341,8 @@ main (int argc, char *argv[])
   GNUNET_asprintf (&cfg_name,
                    "test_namestore_api_%s.conf",
                    plugin_name);
+  GNUNET_DISK_purge_cfg_dir (cfg_name,
+                             "GNUNET_TEST_HOME");
   res = 1;
   if (0 !=
       GNUNET_TESTING_peer_run ("test-namestore-api-lookup-shadow-filter",
@@ -362,11 +353,8 @@ main (int argc, char *argv[])
     res = 1;
   }
   GNUNET_free (cfg_name);
-  if (NULL != directory)
-  {
-      GNUNET_DISK_directory_remove (directory);
-      GNUNET_free (directory);
-  }
+  GNUNET_DISK_purge_cfg_dir (cfg_name,
+                             "GNUNET_TEST_HOME");
   return res;
 }
 
index cd38b2c80825f0328a89172412e3df327e517ee2..de202d53558e328355ad81b8747a2748d3c9e38c 100644 (file)
@@ -56,7 +56,6 @@ static struct GNUNET_GNSRECORD_Data *s_rd_3;
 
 struct GNUNET_NAMESTORE_QueueEntry * ns_ops[3];
 
-static char *directory;
 
 static void
 do_shutdown ()
@@ -66,7 +65,6 @@ do_shutdown ()
     GNUNET_NAMESTORE_zone_monitor_stop (zm);
     zm = NULL;
   }
-
   if (NULL != ns_ops[0])
   {
        GNUNET_NAMESTORE_cancel(ns_ops[0]);
@@ -82,13 +80,11 @@ do_shutdown ()
        GNUNET_NAMESTORE_cancel(ns_ops[2]);
        ns_ops[2] = NULL;
   }
-
   if (NULL != nsh)
   {
     GNUNET_NAMESTORE_disconnect (nsh);
     nsh = NULL;
   }
-
   GNUNET_free_non_null(s_name_1);
   GNUNET_free_non_null(s_name_2);
   GNUNET_free_non_null(s_name_3);
@@ -284,23 +280,8 @@ run (void *cls,
      const struct GNUNET_CONFIGURATION_Handle *cfg,
      struct GNUNET_TESTING_Peer *peer)
 {
-  char *hostkey_file;
-
   res = 1;
-
-  directory = NULL;
-  GNUNET_assert (GNUNET_OK ==
-                 GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS", "GNUNET_TEST_HOME", &directory));
-  GNUNET_DISK_directory_remove (directory);
-
-  GNUNET_asprintf(&hostkey_file,
-                 "zonefiles%s%s",
-                 DIR_SEPARATOR_STR,
-                 "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-             "Using zonekey file `%s' \n", hostkey_file);
-  privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file);
-  GNUNET_free (hostkey_file);
+  privkey = GNUNET_CRYPTO_ecdsa_key_create ();
   GNUNET_assert (privkey != NULL);
 
   /* Start monitoring */
@@ -333,16 +314,12 @@ run (void *cls,
     return;
   }
 
-  GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",
-                 DIR_SEPARATOR_STR,
-                 "HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey");
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
-  privkey2 = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file);
-  GNUNET_free (hostkey_file);
+  privkey2 = GNUNET_CRYPTO_ecdsa_key_create ();
   GNUNET_assert (privkey2 != NULL);
 
 
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 3\n");
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Created record 3\n");
   /* name in different zone */
   GNUNET_asprintf(&s_name_3, "dummy3");
   s_rd_3 = create_record(1);
@@ -358,22 +335,33 @@ run (void *cls,
              "Created record 1\n");
   GNUNET_asprintf(&s_name_1, "dummy1");
   s_rd_1 = create_record(1);
-  GNUNET_assert (NULL != (ns_ops[0] = GNUNET_NAMESTORE_records_store(nsh, privkey, s_name_1,
-               1, s_rd_1, &put_cont, s_name_1)));
+  GNUNET_assert (NULL != (ns_ops[0] =
+                          GNUNET_NAMESTORE_records_store (nsh,
+                                                          privkey,
+                                                          s_name_1,
+                                                          1,
+                                                          s_rd_1,
+                                                          &put_cont,
+                                                          s_name_1)));
 
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 2 \n");
   GNUNET_asprintf(&s_name_2, "dummy2");
   s_rd_2 = create_record(1);
-  GNUNET_assert (NULL != (ns_ops[1] = GNUNET_NAMESTORE_records_store(nsh, privkey, s_name_2,
-               1, s_rd_2, &put_cont, s_name_2)));
-
-
+  GNUNET_assert (NULL != (ns_ops[1] =
+                          GNUNET_NAMESTORE_records_store (nsh,
+                                                          privkey,
+                                                          s_name_2,
+                                                          1,
+                                                          s_rd_2,
+                                                          &put_cont,
+                                                          s_name_2)));
 }
 
 
 int
-main (int argc, char *argv[])
+main (int argc,
+      char *argv[])
 {
   const char *plugin_name;
   char *cfg_name;
@@ -382,6 +370,8 @@ main (int argc, char *argv[])
   GNUNET_asprintf (&cfg_name,
                    "test_namestore_api_%s.conf",
                    plugin_name);
+  GNUNET_DISK_purge_cfg_dir (cfg_name,
+                             "GNUNET_TEST_HOME");
   res = 1;
   if (0 !=
       GNUNET_TESTING_peer_run ("test-namestore-api-monitoring",
@@ -391,12 +381,9 @@ main (int argc, char *argv[])
   {
     res = 1;
   }
+  GNUNET_DISK_purge_cfg_dir (cfg_name,
+                             "GNUNET_TEST_HOME");
   GNUNET_free (cfg_name);
-  if (NULL != directory)
-  {
-      GNUNET_DISK_directory_remove (directory);
-      GNUNET_free (directory);
-  }
   return res;
 }
 
index f6a74609ea6a911a312323cbe0b9baeef7011358..449b36d65d9243b86776785f6ab15ec2c141af4a 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     Copyright (C) 2013 GNUnet e.V.
+     Copyright (C) 2013, 2018 GNUnet e.V.
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -18,7 +18,7 @@
      Boston, MA 02110-1301, USA.
 */
 /**
- * @file namestore/test_namestore_api_monitoring.c
+ * @file namestore/test_namestore_api_monitoring_existing.c
  * @brief testcase for zone monitoring functionality: add records first, then monitor
  */
 #include "platform.h"
@@ -27,7 +27,7 @@
 #include "namestore.h"
 
 
-#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100)
+#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
 
 static const struct GNUNET_CONFIGURATION_Handle *cfg;
 
@@ -57,18 +57,30 @@ static struct GNUNET_GNSRECORD_Data *s_rd_3;
 
 struct GNUNET_NAMESTORE_QueueEntry * ns_ops[3];
 
-static char *directory;
+
+/**
+ * Re-establish the connection to the service.
+ *
+ * @param cls handle to use to re-connect.
+ */
+static void
+endbadly (void *cls)
+{
+  endbadly_task = NULL;
+  GNUNET_break (0);
+  GNUNET_SCHEDULER_shutdown ();
+  res = 1;
+}
 
 
 static void
-do_shutdown ()
+end (void *cls)
 {
   if (NULL != zm)
   {
     GNUNET_NAMESTORE_zone_monitor_stop (zm);
     zm = NULL;
   }
-
   if (NULL != ns_ops[0])
   {
     GNUNET_NAMESTORE_cancel(ns_ops[0]);
@@ -84,7 +96,11 @@ do_shutdown ()
     GNUNET_NAMESTORE_cancel(ns_ops[2]);
     ns_ops[2] = NULL;
   }
-
+  if (NULL != endbadly_task)
+  {
+    GNUNET_SCHEDULER_cancel (endbadly_task);
+    endbadly_task = NULL;
+  }
   if (NULL != nsh)
   {
     GNUNET_NAMESTORE_disconnect (nsh);
@@ -124,27 +140,6 @@ do_shutdown ()
 }
 
 
-/**
- * Re-establish the connection to the service.
- *
- * @param cls handle to use to re-connect.
- */
-static void
-endbadly (void *cls)
-{
-  do_shutdown ();
-  res = 1;
-}
-
-
-static void
-end (void *cls)
-{
-  do_shutdown ();
-  res = 0;
-}
-
-
 static void
 zone_proc (void *cls,
           const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
@@ -166,9 +161,7 @@ zone_proc (void *cls,
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "Monitoring returned wrong zone key\n");
     GNUNET_break (0);
-    GNUNET_SCHEDULER_cancel (endbadly_task);
-    endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly,
-                                              NULL);
+    GNUNET_SCHEDULER_shutdown ();
     return;
   }
 
@@ -203,17 +196,16 @@ zone_proc (void *cls,
                                       1);
   if (2 == ++returned_records)
   {
-    if (endbadly_task != NULL)
+    GNUNET_SCHEDULER_shutdown ();
+    if (GNUNET_YES == fail)
     {
-      GNUNET_SCHEDULER_cancel (endbadly_task);
-      endbadly_task = NULL;
+      GNUNET_break (0);
+      res = 1;
     }
-    if (GNUNET_YES == fail)
-      GNUNET_SCHEDULER_add_now (&endbadly,
-                                NULL);
     else
-      GNUNET_SCHEDULER_add_now (&end,
-                                NULL);
+    {
+      res = 0;
+    }
   }
 }
 
@@ -260,8 +252,9 @@ put_cont (void *cls,
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "Failed to created records\n");
     GNUNET_break (0);
-    GNUNET_SCHEDULER_cancel (endbadly_task);
-    endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
+    res = 1;
+    GNUNET_SCHEDULER_shutdown ();
+    return;
   }
 
   if (3 == c)
@@ -281,8 +274,8 @@ put_cont (void *cls,
       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                   "Failed to create zone monitor\n");
       GNUNET_break (0);
-      endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly,
-                                                NULL);
+      res = 1;
+      GNUNET_SCHEDULER_shutdown ();
       return;
     }
   }
@@ -316,30 +309,16 @@ run (void *cls,
      const struct GNUNET_CONFIGURATION_Handle *mycfg,
      struct GNUNET_TESTING_Peer *peer)
 {
-  char *hostkey_file;
-
-  directory = NULL;
-  GNUNET_assert (GNUNET_OK ==
-                 GNUNET_CONFIGURATION_get_value_string (mycfg,
-                                                        "PATHS",
-                                                        "GNUNET_TEST_HOME",
-                                                        &directory));
-  GNUNET_DISK_directory_remove (directory);
-
   res = 1;
-
-  GNUNET_asprintf(&hostkey_file,
-                 "zonefiles%s%s",
-                 DIR_SEPARATOR_STR,
-                 "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-             "Using zonekey file `%s' \n", hostkey_file);
-  privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file);
-  GNUNET_free (hostkey_file);
+  privkey = GNUNET_CRYPTO_ecdsa_key_create ();
   GNUNET_assert (privkey != NULL);
 
   cfg = mycfg;
-  endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &endbadly, NULL);
+  GNUNET_SCHEDULER_add_shutdown (&end,
+                                 NULL);
+  endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
+                                                &endbadly,
+                                                NULL);
   /* Connect to namestore */
   nsh = GNUNET_NAMESTORE_connect (cfg);
   if (NULL == nsh)
@@ -350,12 +329,7 @@ run (void *cls,
     return;
   }
 
-  GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",
-                 DIR_SEPARATOR_STR,
-                 "HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey");
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
-  privkey2 = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file);
-  GNUNET_free (hostkey_file);
+  privkey2 = GNUNET_CRYPTO_ecdsa_key_create ();
   GNUNET_assert (privkey2 != NULL);
 
 
@@ -363,16 +337,29 @@ run (void *cls,
   /* name in different zone */
   GNUNET_asprintf(&s_name_3, "dummy3");
   s_rd_3 = create_record(1);
-  GNUNET_assert (NULL != (ns_ops[2] = GNUNET_NAMESTORE_records_store (nsh, privkey2, s_name_3,
-               1, s_rd_3, &put_cont, s_name_3)));
+  GNUNET_assert (NULL != (ns_ops[2] =
+                          GNUNET_NAMESTORE_records_store (nsh,
+                                                          privkey2,
+                                                          s_name_3,
+                                                          1,
+                                                          s_rd_3,
+                                                          &put_cont,
+                                                          s_name_3)));
 
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 1\n");
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Created record 1\n");
   GNUNET_asprintf(&s_name_1, "dummy1");
   s_rd_1 = create_record(1);
-  GNUNET_assert (NULL != (ns_ops[0] = GNUNET_NAMESTORE_records_store(nsh, privkey, s_name_1,
-               1, s_rd_1, &put_cont, s_name_1)));
-
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 2 \n");
+  GNUNET_assert (NULL != (ns_ops[0] =
+                          GNUNET_NAMESTORE_records_store(nsh,
+                                                         privkey,
+                                                         s_name_1,
+                                                         1,
+                                                         s_rd_1,
+                                                         &put_cont,
+                                                         s_name_1)));
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Created record 2 \n");
   GNUNET_asprintf(&s_name_2, "dummy2");
   s_rd_2 = create_record(1);
   GNUNET_assert (NULL != (ns_ops[1] =
@@ -397,6 +384,8 @@ main (int argc, char *argv[])
                    "test_namestore_api_%s.conf",
                    plugin_name);
   res = 1;
+  GNUNET_DISK_purge_cfg_dir (cfg_name,
+                             "GNUNET_TEST_HOME");
   if (0 !=
       GNUNET_TESTING_peer_run ("test-namestore-api-monitoring-existing",
                                cfg_name,
@@ -405,12 +394,9 @@ main (int argc, char *argv[])
   {
     res = 1;
   }
+  GNUNET_DISK_purge_cfg_dir (cfg_name,
+                             "GNUNET_TEST_HOME");
   GNUNET_free (cfg_name);
-  if (NULL != directory)
-  {
-      GNUNET_DISK_directory_remove (directory);
-      GNUNET_free (directory);
-  }
   return res;
 }
 
index 397cb4b2f6283b64437088495818eaf1983ab92d..9960e63155d190bba0b5f4710145f6e98d8e06d9 100644 (file)
@@ -2,3 +2,8 @@
 
 [namestore]
 DATABASE = postgres
+
+
+[namestore-postgres]
+CONFIG = connect_timeout=10; dbname=gnunetcheck
+TEMPORARY_TABLE = YES
index 532a751da4f7dab49e8a6df99b94713bf5345371..c9e2802bd7a878d333cc00ac1bad919728c8cf66 100644 (file)
@@ -48,7 +48,6 @@ static int removed;
 
 static struct GNUNET_NAMESTORE_QueueEntry *nsqe;
 
-static char *directory;
 
 static void
 cleanup ()
@@ -157,29 +156,12 @@ run (void *cls,
      struct GNUNET_TESTING_Peer *peer)
 {
   struct GNUNET_GNSRECORD_Data rd;
-  char *hostkey_file;
   const char * name = "dummy.dummy.gnunet";
 
-  directory = NULL;
-  GNUNET_assert (GNUNET_OK ==
-                 GNUNET_CONFIGURATION_get_value_string(cfg,
-                                                       "PATHS",
-                                                       "GNUNET_TEST_HOME",
-                                                       &directory));
-  GNUNET_DISK_directory_remove (directory);
-
   endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
                                                &endbadly,
                                                 NULL);
-  GNUNET_asprintf (&hostkey_file,
-                  "zonefiles%s%s",
-                  DIR_SEPARATOR_STR,
-                  "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Using zonekey file `%s' \n",
-              hostkey_file);
-  privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file);
-  GNUNET_free (hostkey_file);
+  privkey = GNUNET_CRYPTO_ecdsa_key_create ();
   GNUNET_assert (privkey != NULL);
   GNUNET_CRYPTO_ecdsa_key_get_public (privkey,
                                       &pubkey);
@@ -191,12 +173,19 @@ run (void *cls,
   rd.data_size = TEST_RECORD_DATALEN;
   rd.data = GNUNET_malloc (TEST_RECORD_DATALEN);
   rd.flags = 0;
-  memset ((char *) rd.data, 'a', TEST_RECORD_DATALEN);
+  memset ((char *) rd.data,
+          'a',
+          TEST_RECORD_DATALEN);
 
   nsh = GNUNET_NAMESTORE_connect (cfg);
   GNUNET_break (NULL != nsh);
-  nsqe = GNUNET_NAMESTORE_records_store (nsh, privkey, name,
-                                     1, &rd, &put_cont, (void *) name);
+  nsqe = GNUNET_NAMESTORE_records_store (nsh,
+                                         privkey,
+                                         name,
+                                         1,
+                                         &rd,
+                                         &put_cont,
+                                         (void *) name);
   if (NULL == nsqe)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -216,6 +205,8 @@ main (int argc, char *argv[])
   GNUNET_asprintf (&cfg_name,
                    "test_namestore_api_%s.conf",
                    plugin_name);
+  GNUNET_DISK_purge_cfg_dir (cfg_name,
+                             "GNUNET_TEST_HOME");
   res = 1;
   if (0 !=
       GNUNET_TESTING_peer_run ("test-namestore-api-remove",
@@ -225,12 +216,9 @@ main (int argc, char *argv[])
   {
     res = 1;
   }
+  GNUNET_DISK_purge_cfg_dir (cfg_name,
+                             "GNUNET_TEST_HOME");
   GNUNET_free (cfg_name);
-  if (NULL != directory)
-  {
-      GNUNET_DISK_directory_remove (directory);
-      GNUNET_free (directory);
-  }
   return res;
 }
 
index 2f20c3636f4de0eae99db0f314c9e238fe036d7d..d0438a7e1301a18106203f5b7bcb3b8dbb715aeb 100644 (file)
@@ -46,7 +46,6 @@ static int res;
 
 static struct GNUNET_NAMESTORE_QueueEntry *nsqe;
 
-static char *directory;
 
 static void
 cleanup ()
@@ -92,7 +91,9 @@ end (void *cls)
 
 
 static void
-put_cont (void *cls, int32_t success, const char *emsg)
+put_cont (void *cls,
+          int32_t success,
+          const char *emsg)
 {
   GNUNET_assert (NULL != cls);
   nsqe = NULL;
@@ -101,8 +102,8 @@ put_cont (void *cls, int32_t success, const char *emsg)
     GNUNET_SCHEDULER_cancel (endbadly_task);
     endbadly_task = NULL;
   }
-
-  switch (success) {
+  switch (success)
+  {
     case GNUNET_NO:
       /* We expected GNUNET_NO, since record was not found */
       GNUNET_SCHEDULER_add_now (&end, NULL);
@@ -129,25 +130,12 @@ run (void *cls,
      const struct GNUNET_CONFIGURATION_Handle *cfg,
      struct GNUNET_TESTING_Peer *peer)
 {
-  char *hostkey_file;
   const char * name = "dummy.dummy.gnunet";
 
-  directory = NULL;
-  GNUNET_assert (GNUNET_OK ==
-                 GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS", "GNUNET_TEST_HOME", &directory));
-  GNUNET_DISK_directory_remove (directory);
-
   endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
-                                               &endbadly, NULL);
-  GNUNET_asprintf (&hostkey_file,
-                  "zonefiles%s%s",
-                  DIR_SEPARATOR_STR,
-                  "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Using zonekey file `%s' \n",
-              hostkey_file);
-  privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file);
-  GNUNET_free (hostkey_file);
+                                               &endbadly,
+                                                NULL);
+  privkey = GNUNET_CRYPTO_ecdsa_key_create ();
   GNUNET_assert (privkey != NULL);
   GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey);
 
@@ -174,6 +162,8 @@ main (int argc, char *argv[])
   GNUNET_asprintf (&cfg_name,
                    "test_namestore_api_%s.conf",
                    plugin_name);
+  GNUNET_DISK_purge_cfg_dir (cfg_name,
+                             "GNUNET_TEST_HOME");
   res = 1;
   if (0 !=
       GNUNET_TESTING_peer_run ("test-namestore-api-remove-non-existing-record",
@@ -183,12 +173,9 @@ main (int argc, char *argv[])
   {
     res = 1;
   }
+  GNUNET_DISK_purge_cfg_dir (cfg_name,
+                             "GNUNET_TEST_HOME");
   GNUNET_free (cfg_name);
-  if (NULL != directory)
-  {
-      GNUNET_DISK_directory_remove (directory);
-      GNUNET_free (directory);
-  }
   return res;
 }
 
index 5416daec388411e4f8a28d7382ec7353d6be1883..82663400aabd9317c310495216e7a14428db9503 100644 (file)
@@ -2,3 +2,6 @@
 
 [namestore]
 DATABASE = sqlite
+
+[namestore-sqlite]
+FILENAME = $GNUNET_TEST_HOME/namestore/sqlite_test.db
index 4e51678a18261f39b4fffa893ea5782f76263304..4abcfa4d336a14b4ae8b4f6bee1b431d60c0249a 100644 (file)
@@ -46,7 +46,6 @@ static int res;
 
 static struct GNUNET_NAMESTORE_QueueEntry *nsqe;
 
-static char *directory;
 
 static void
 cleanup ()
@@ -114,23 +113,11 @@ run (void *cls,
      struct GNUNET_TESTING_Peer *peer)
 {
   struct GNUNET_GNSRECORD_Data rd;
-  char *hostkey_file;
   const char * name = "dummy.dummy.gnunet";
 
-  directory = NULL;
-  GNUNET_assert (GNUNET_OK ==
-                 GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS", "GNUNET_TEST_HOME", &directory));
-  GNUNET_DISK_directory_remove (directory);
-
   endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
                                                &endbadly, NULL);
-  GNUNET_asprintf (&hostkey_file,
-                  "zonefiles%s%s",
-                  DIR_SEPARATOR_STR,
-                  "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
-  privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file);
-  GNUNET_free (hostkey_file);
+  privkey = GNUNET_CRYPTO_ecdsa_key_create ();
   GNUNET_assert (privkey != NULL);
   GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey);
 
@@ -144,8 +131,13 @@ run (void *cls,
 
   nsh = GNUNET_NAMESTORE_connect (cfg);
   GNUNET_break (NULL != nsh);
-  nsqe = GNUNET_NAMESTORE_records_store (nsh, privkey, name,
-                                     1, &rd, &put_cont, (void *) name);
+  nsqe = GNUNET_NAMESTORE_records_store (nsh,
+                                         privkey,
+                                         name,
+                                         1,
+                                         &rd,
+                                         &put_cont,
+                                         (void *) name);
   if (NULL == nsqe)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -167,6 +159,8 @@ main (int argc, char *argv[])
                    "test_namestore_api_%s.conf",
                    plugin_name);
   res = 1;
+  GNUNET_DISK_purge_cfg_dir (cfg_name,
+                             "GNUNET_TEST_HOME");
   if (0 !=
       GNUNET_TESTING_peer_run ("test-namestore-api",
                                cfg_name,
@@ -175,12 +169,9 @@ main (int argc, char *argv[])
   {
     res = 1;
   }
+  GNUNET_DISK_purge_cfg_dir (cfg_name,
+                             "GNUNET_TEST_HOME");
   GNUNET_free (cfg_name);
-  if (NULL != directory)
-  {
-    GNUNET_DISK_directory_remove (directory);
-    GNUNET_free (directory);
-  }
   return res;
 }
 
index 0a4551f217235e8c762ef8da807ba8fb1e0ecef9..7b13cd9c58e0633ffe98ad1399c330faddf09c34 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     Copyright (C) 2012, 2013 GNUnet e.V.
+     Copyright (C) 2012, 2013, 2018 GNUnet e.V.
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -21,6 +21,7 @@
  * @file namestore/test_namestore_api_store_update.c
  * @brief testcase for namestore_api.c: store a record, update it and perform a lookup
  * @author Matthias Wachs
+ * @author Christian Grothoff
  */
 #include "platform.h"
 #include "gnunet_namecache_service.h"
@@ -33,7 +34,6 @@
 
 #define TEST_RECORD_DATA 'a'
 
-
 #define TEST_RECORD_TYPE2 4321
 
 #define TEST_RECORD_DATALEN2 234
@@ -63,38 +63,30 @@ static struct GNUNET_NAMECACHE_QueueEntry *ncqe;
 
 static const char *name = "dummy";
 
-static char *directory;
 
+/**
+ * Terminate test with error.
+ *
+ * @param cls handle to use to re-connect.
+ */
 static void
-cleanup ()
+endbadly (void *cls)
 {
-  if (NULL != nsh)
-  {
-    GNUNET_NAMESTORE_disconnect (nsh);
-    nsh = NULL;
-  }
-  if (NULL != nch)
-  {
-    GNUNET_NAMECACHE_disconnect (nch);
-    nch = NULL;
-  }
-  if (NULL != privkey)
-  {
-    GNUNET_free (privkey);
-    privkey = NULL;
-  }
+  GNUNET_break (0);
+  endbadly_task = NULL;
   GNUNET_SCHEDULER_shutdown ();
+  res = 1;
 }
 
 
-/**
- * Re-establish the connection to the service.
- *
- * @param cls handle to use to re-connect.
- */
 static void
-endbadly (void *cls)
+end (void *cls)
 {
+  if (NULL != endbadly_task)
+  {
+    GNUNET_SCHEDULER_cancel (endbadly_task);
+    endbadly_task = NULL;
+  }
   if (NULL != nsqe)
   {
     GNUNET_NAMESTORE_cancel (nsqe);
@@ -105,21 +97,28 @@ endbadly (void *cls)
     GNUNET_NAMECACHE_cancel (ncqe);
     ncqe = NULL;
   }
-  cleanup ();
-  res = 1;
-}
-
-
-static void
-end (void *cls)
-{
-  cleanup ();
-  res = 0;
+  if (NULL != nsh)
+  {
+    GNUNET_NAMESTORE_disconnect (nsh);
+    nsh = NULL;
+  }
+  if (NULL != nch)
+  {
+    GNUNET_NAMECACHE_disconnect (nch);
+    nch = NULL;
+  }
+  if (NULL != privkey)
+  {
+    GNUNET_free (privkey);
+    privkey = NULL;
+  }
 }
 
 
 static void
-put_cont (void *cls, int32_t success, const char *emsg);
+put_cont (void *cls,
+          int32_t success,
+          const char *emsg);
 
 
 static void
@@ -135,11 +134,15 @@ rd_decrypt_cb (void *cls,
   if (GNUNET_NO == update_performed)
   {
     char rd_cmp_data[TEST_RECORD_DATALEN];
-    memset (rd_cmp_data, TEST_RECORD_DATA, TEST_RECORD_DATALEN);
 
+    memset (rd_cmp_data,
+            TEST_RECORD_DATA,
+            TEST_RECORD_DATALEN);
     GNUNET_assert (TEST_RECORD_TYPE == rd[0].record_type);
     GNUNET_assert (TEST_RECORD_DATALEN == rd[0].data_size);
-    GNUNET_assert (0 == memcmp (&rd_cmp_data, rd[0].data, TEST_RECORD_DATALEN));
+    GNUNET_assert (0 == memcmp (&rd_cmp_data,
+                                rd[0].data,
+                                TEST_RECORD_DATALEN));
 
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "Block was decrypted successfully, updating record \n");
@@ -149,24 +152,33 @@ rd_decrypt_cb (void *cls,
     rd_new.record_type = TEST_RECORD_TYPE2;
     rd_new.data_size = TEST_RECORD_DATALEN2;
     rd_new.data = GNUNET_malloc (TEST_RECORD_DATALEN2);
-    memset ((char *) rd_new.data, TEST_RECORD_DATA2, TEST_RECORD_DATALEN2);
+    memset ((char *) rd_new.data,
+            TEST_RECORD_DATA2,
+            TEST_RECORD_DATALEN2);
 
-    nsqe = GNUNET_NAMESTORE_records_store (nsh, privkey, name,
-                                           1, &rd_new, &put_cont, (void *) name);
+    nsqe = GNUNET_NAMESTORE_records_store (nsh,
+                                           privkey,
+                                           name,
+                                           1,
+                                           &rd_new,
+                                           &put_cont,
+                                           (void *) name);
     update_performed = GNUNET_YES;
   }
   else
   {
     char rd_cmp_data[TEST_RECORD_DATALEN2];
-    memset (rd_cmp_data, TEST_RECORD_DATA2, TEST_RECORD_DATALEN2);
 
+    memset (rd_cmp_data,
+            TEST_RECORD_DATA2,
+            TEST_RECORD_DATALEN2);
     GNUNET_assert (TEST_RECORD_TYPE2 == rd[0].record_type);
     GNUNET_assert (TEST_RECORD_DATALEN2 == rd[0].data_size);
-    GNUNET_assert (0 == memcmp (&rd_cmp_data, rd[0].data, TEST_RECORD_DATALEN2));
-
-    GNUNET_SCHEDULER_cancel (endbadly_task);
-    endbadly_task = NULL;
-    GNUNET_SCHEDULER_add_now (&end, NULL);
+    GNUNET_assert (0 == memcmp (&rd_cmp_data,
+                                rd[0].data,
+                                TEST_RECORD_DATALEN2));
+    GNUNET_SCHEDULER_shutdown ();
+    res = 0;
   }
 }
 
@@ -184,21 +196,25 @@ name_lookup_proc (void *cls,
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 _("Namecache returned no block for `%s'\n"),
                 name);
-    if (endbadly_task != NULL)
-      GNUNET_SCHEDULER_cancel (endbadly_task);
-    endbadly_task =  GNUNET_SCHEDULER_add_now (&endbadly, NULL);
+    GNUNET_SCHEDULER_shutdown ();
     return;
   }
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "Namecache returned block, decrypting \n");
-  GNUNET_assert (GNUNET_OK == GNUNET_GNSRECORD_block_decrypt(block,
-               &pubkey, name, &rd_decrypt_cb, (void *) name));
+  GNUNET_assert (GNUNET_OK ==
+                 GNUNET_GNSRECORD_block_decrypt (block,
+                                                 &pubkey,
+                                                 name,
+                                                 &rd_decrypt_cb,
+                                                 (void *) name));
 }
 
 
 static void
-put_cont (void *cls, int32_t success, const char *emsg)
+put_cont (void *cls,
+          int32_t success,
+          const char *emsg)
 {
   const char *name = cls;
   struct GNUNET_HashCode derived_hash;
@@ -216,7 +232,8 @@ put_cont (void *cls, int32_t success, const char *emsg)
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "Looking in namecache for `%s'\n",
               GNUNET_h2s (&derived_hash));
-  ncqe = GNUNET_NAMECACHE_lookup_block (nch, &derived_hash,
+  ncqe = GNUNET_NAMECACHE_lookup_block (nch,
+                                        &derived_hash,
                                         &name_lookup_proc, (void *) name);
 }
 
@@ -227,41 +244,37 @@ run (void *cls,
      struct GNUNET_TESTING_Peer *peer)
 {
   struct GNUNET_GNSRECORD_Data rd;
-  char *hostkey_file;
-
-  directory = NULL;
-  GNUNET_assert (GNUNET_OK ==
-                 GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS", "GNUNET_TEST_HOME", &directory));
-  GNUNET_DISK_directory_remove (directory);
 
   update_performed = GNUNET_NO;
+  GNUNET_SCHEDULER_add_shutdown (&end,
+                                 NULL);
   endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
-                                               &endbadly, NULL);
-  GNUNET_asprintf (&hostkey_file,
-                  "zonefiles%s%s",
-                  DIR_SEPARATOR_STR,
-                  "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
-  privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file);
-  GNUNET_free (hostkey_file);
+                                               &endbadly,
+                                                NULL);
+  privkey = GNUNET_CRYPTO_ecdsa_key_create ();
   GNUNET_assert (privkey != NULL);
-  GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey);
-
+  GNUNET_CRYPTO_ecdsa_key_get_public (privkey,
+                                      &pubkey);
   rd.flags = GNUNET_GNSRECORD_RF_NONE;
   rd.expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000;
   rd.record_type = TEST_RECORD_TYPE;
   rd.data_size = TEST_RECORD_DATALEN;
   rd.data = GNUNET_malloc (TEST_RECORD_DATALEN);
-  memset ((char *) rd.data, TEST_RECORD_DATA, TEST_RECORD_DATALEN);
+  memset ((char *) rd.data,
+          TEST_RECORD_DATA,
+          TEST_RECORD_DATALEN);
 
   nsh = GNUNET_NAMESTORE_connect (cfg);
   GNUNET_break (NULL != nsh);
   nch = GNUNET_NAMECACHE_connect (cfg);
   GNUNET_break (NULL != nch);
   nsqe = GNUNET_NAMESTORE_records_store (nsh,
-                                         privkey, name,
-                                         1, &rd,
-                                         &put_cont, (void *) name);
+                                         privkey,
+                                         name,
+                                         1,
+                                         &rd,
+                                         &put_cont,
+                                         (void *) name);
   if (NULL == nsqe)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -272,7 +285,8 @@ run (void *cls,
 
 
 int
-main (int argc, char *argv[])
+main (int argc,
+      char *argv[])
 {
   const char *plugin_name;
   char *cfg_name;
@@ -282,6 +296,8 @@ main (int argc, char *argv[])
                    "test_namestore_api_%s.conf",
                    plugin_name);
   res = 1;
+  GNUNET_DISK_purge_cfg_dir (cfg_name,
+                             "GNUNET_TEST_HOME");
   if (0 !=
       GNUNET_TESTING_peer_run ("test-namestore-api-store-update",
                                cfg_name,
@@ -290,14 +306,11 @@ main (int argc, char *argv[])
   {
     res = 1;
   }
+  GNUNET_DISK_purge_cfg_dir (cfg_name,
+                             "GNUNET_TEST_HOME");
   GNUNET_free (cfg_name);
-  if (NULL != directory)
-  {
-      GNUNET_DISK_directory_remove (directory);
-      GNUNET_free (directory);
-  }
   return res;
 }
 
 
-/* end of test_namestore_api_store_update.c*/
+/* end of test_namestore_api_store_update.c */
index 806605d94e0654d34dc19b97e71aacb16cec437a..68c3de9b83cfe4af57997acb7561caa62281cdf7 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     Copyright (C) 2013 GNUnet e.V.
+     Copyright (C) 2013, 2018 GNUnet e.V.
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -56,8 +56,6 @@ static char * s_name_3;
 
 static struct GNUNET_GNSRECORD_Data *s_rd_3;
 
-static char *directory;
-
 
 /**
  * Re-establish the connection to the service.
@@ -68,43 +66,8 @@ static char *directory;
 static void
 endbadly (void *cls)
 {
-  if (NULL != zi)
-  {
-    GNUNET_NAMESTORE_zone_iteration_stop (zi);
-    zi = NULL;
-  }
-  if (nsh != NULL)
-  {
-    GNUNET_NAMESTORE_disconnect (nsh);
-    nsh = NULL;
-  }
-  GNUNET_free_non_null(s_name_1);
-  GNUNET_free_non_null(s_name_2);
-  GNUNET_free_non_null(s_name_3);
-
-  if (s_rd_1 != NULL)
-  {
-    GNUNET_free ((void *)s_rd_1->data);
-    GNUNET_free (s_rd_1);
-  }
-  if (s_rd_2 != NULL)
-  {
-    GNUNET_free ((void *)s_rd_2->data);
-    GNUNET_free (s_rd_2);
-  }
-  if (s_rd_3 != NULL)
-  {
-    GNUNET_free ((void *)s_rd_3->data);
-    GNUNET_free (s_rd_3);
-  }
-
-  if (privkey != NULL)
-    GNUNET_free (privkey);
-  privkey = NULL;
-
-  if (privkey2 != NULL)
-    GNUNET_free (privkey2);
-  privkey2 = NULL;
+  endbadly_task = NULL;
+  GNUNET_SCHEDULER_shutdown ();
   res = 1;
 }
 
@@ -117,41 +80,44 @@ end (void *cls)
     GNUNET_NAMESTORE_zone_iteration_stop (zi);
     zi = NULL;
   }
-  if (endbadly_task != NULL)
+  if (NULL != endbadly_task)
   {
     GNUNET_SCHEDULER_cancel (endbadly_task);
     endbadly_task = NULL;
   }
-
-  if (privkey != NULL)
+  if (NULL != privkey)
+  {
     GNUNET_free (privkey);
-  privkey = NULL;
-
-  if (privkey2 != NULL)
+    privkey = NULL;
+  }
+  if (NULL != privkey2)
+  {
     GNUNET_free (privkey2);
-  privkey2 = NULL;
-
+    privkey2 = NULL;
+  }
   GNUNET_free (s_name_1);
   GNUNET_free (s_name_2);
   GNUNET_free (s_name_3);
-  if (s_rd_1 != NULL)
+  if (NULL != s_rd_1)
   {
     GNUNET_free ((void *)s_rd_1->data);
     GNUNET_free (s_rd_1);
   }
-  if (s_rd_2 != NULL)
+  if (NULL != s_rd_2)
   {
     GNUNET_free ((void *)s_rd_2->data);
     GNUNET_free (s_rd_2);
   }
-  if (s_rd_3 != NULL)
+  if (NULL != s_rd_3)
   {
     GNUNET_free ((void *)s_rd_3->data);
     GNUNET_free (s_rd_3);
   }
-  if (nsh != NULL)
+  if (NULL != nsh)
+  {
     GNUNET_NAMESTORE_disconnect (nsh);
-  nsh = NULL;
+    nsh = NULL;
+  }
 }
 
 
@@ -170,7 +136,7 @@ zone_end (void *cls)
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Received last result, iteration done after receing %u results\n",
               returned_records);
-  GNUNET_SCHEDULER_add_now (&end, NULL);
+  GNUNET_SCHEDULER_shutdown ();
 }
 
 
@@ -191,7 +157,9 @@ zone_proc (void *cls,
   int failed = GNUNET_NO;
 
   GNUNET_assert (NULL != zone);
-  if (0 == memcmp (zone, privkey, sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)))
+  if (0 == memcmp (zone,
+                   privkey,
+                   sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)))
   {
     if (0 == strcmp (label, s_name_1))
     {
@@ -230,12 +198,15 @@ zone_proc (void *cls,
     else
     {
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                  "Comparing result failed: got name `%s' for first zone\n", label);
+                  "Comparing result failed: got name `%s' for first zone\n",
+                  label);
       failed = GNUNET_YES;
       GNUNET_break (0);
     }
   }
-  else if (0 == memcmp (zone, privkey2, sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)))
+  else if (0 == memcmp (zone,
+                        privkey2,
+                        sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)))
   {
     if (0 == strcmp (label, s_name_3))
     {
@@ -258,7 +229,8 @@ zone_proc (void *cls,
     else
     {
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                  "Comparing result failed: got name `%s' for first zone\n", label);
+                  "Comparing result failed: got name `%s' for first zone\n",
+                  label);
       failed = GNUNET_YES;
       GNUNET_break (0);
     }
@@ -282,29 +254,34 @@ zone_proc (void *cls,
   else
   {
     GNUNET_break (0);
-    GNUNET_SCHEDULER_add_now (&end, NULL);
+    GNUNET_SCHEDULER_shutdown ();
+    res = 1;
   }
 }
 
 
 static void
-put_cont (void *cls, int32_t success, const char *emsg)
+put_cont (void *cls,
+          int32_t success,
+          const char *emsg)
 {
   static int c = 0;
 
   if (success == GNUNET_OK)
   {
     c++;
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record %u \n", c);
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "Created record %u \n",
+                c);
   }
   else
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to created records: `%s'\n",
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Failed to created records: `%s'\n",
                emsg);
     GNUNET_break (0);
-    if (NULL != endbadly_task)
-       GNUNET_SCHEDULER_cancel (endbadly_task);
-    endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
+    GNUNET_SCHEDULER_shutdown ();
+    res = 1;
     return;
   }
 
@@ -312,7 +289,8 @@ put_cont (void *cls, int32_t success, const char *emsg)
   {
     res = 1;
     returned_records = 0;
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All records created, starting iteration over all zones \n");
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "All records created, starting iteration over all zones \n");
     zi = GNUNET_NAMESTORE_zone_iteration_start (nsh,
                                                 NULL,
                                                 &fail_cb,
@@ -323,11 +301,11 @@ put_cont (void *cls, int32_t success, const char *emsg)
                                                 NULL);
     if (zi == NULL)
     {
-      GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create zone iterator\n");
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                  "Failed to create zone iterator\n");
       GNUNET_break (0);
-      if (NULL != endbadly_task)
-       GNUNET_SCHEDULER_cancel (endbadly_task);
-      endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
+      GNUNET_SCHEDULER_shutdown ();
+      res = 1;
       return;
     }
   }
@@ -337,11 +315,11 @@ put_cont (void *cls, int32_t success, const char *emsg)
 static struct GNUNET_GNSRECORD_Data *
 create_record (unsigned int count)
 {
-  unsigned int c;
   struct GNUNET_GNSRECORD_Data * rd;
 
-  rd = GNUNET_malloc (count * sizeof (struct GNUNET_GNSRECORD_Data));
-  for (c = 0; c < count; c++)
+  rd = GNUNET_new_array (count,
+                         struct GNUNET_GNSRECORD_Data);
+  for (unsigned int c = 0; c < count; c++)
   {
     rd[c].expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS).abs_value_us;
     rd[c].record_type = 1111;
@@ -372,9 +350,8 @@ empty_zone_proc (void *cls,
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                _("Expected empty zone but received zone private key\n"));
     GNUNET_break (0);
-    if (endbadly_task != NULL)
-      GNUNET_SCHEDULER_cancel (endbadly_task);
-    endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
+    GNUNET_SCHEDULER_shutdown ();
+    res = 1;
     return;
   }
   if ((NULL != label) || (NULL != rd) || (0 != rd_count))
@@ -382,9 +359,8 @@ empty_zone_proc (void *cls,
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                _("Expected no zone content but received data\n"));
     GNUNET_break (0);
-    if (endbadly_task != NULL)
-      GNUNET_SCHEDULER_cancel (endbadly_task);
-    endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
+    GNUNET_SCHEDULER_shutdown ();
+    res = 1;
     return;
   }
   GNUNET_assert (0);
@@ -412,7 +388,9 @@ empty_zone_end (void *cls)
                    "zonefiles%s%s",
                    DIR_SEPARATOR_STR,
                    "HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey");
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Using zonekey file `%s' \n",
+              hostkey_file);
   privkey2 = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file);
   GNUNET_free (hostkey_file);
   GNUNET_assert (privkey2 != NULL);
@@ -425,8 +403,8 @@ empty_zone_end (void *cls)
                                   privkey,
                                   s_name_1,
                                   1, s_rd_1,
-                                  &put_cont, NULL);
-
+                                  &put_cont,
+                                  NULL);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Created record 2 \n");
   GNUNET_asprintf(&s_name_2, "dummy2");
@@ -437,16 +415,18 @@ empty_zone_end (void *cls)
                                   1, s_rd_2,
                                   &put_cont,
                                   NULL);
-
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Created record 3\n");
-
   /* name in different zone */
   GNUNET_asprintf(&s_name_3, "dummy3");
   s_rd_3 = create_record(1);
-  GNUNET_NAMESTORE_records_store (nsh, privkey2, s_name_3,
-                                  1, s_rd_3,
-                                  &put_cont, NULL);
+  GNUNET_NAMESTORE_records_store (nsh,
+                                  privkey2,
+                                  s_name_3,
+                                  1,
+                                  s_rd_3,
+                                  &put_cont,
+                                  NULL);
 }
 
 
@@ -455,31 +435,30 @@ run (void *cls,
      const struct GNUNET_CONFIGURATION_Handle *cfg,
      struct GNUNET_TESTING_Peer *peer)
 {
-  directory = NULL;
-  GNUNET_assert (GNUNET_OK ==
-                 GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS",
-                                                       "GNUNET_TEST_HOME",
-                                                       &directory));
-  GNUNET_DISK_directory_remove (directory);
-
-  endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, &endbadly, NULL);
+  endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
+                                                &endbadly,
+                                                NULL);
+  GNUNET_SCHEDULER_add_shutdown (&end,
+                                 NULL);
+
   nsh = GNUNET_NAMESTORE_connect (cfg);
   GNUNET_break (NULL != nsh);
   /* first, iterate over empty namestore */
-  zi = GNUNET_NAMESTORE_zone_iteration_start(nsh,
-                                            NULL,
-                                             &fail_cb,
-                                             NULL,
-                                             &empty_zone_proc,
-                                             nsh,
-                                             &empty_zone_end,
-                                             NULL);
+  zi = GNUNET_NAMESTORE_zone_iteration_start (nsh,
+                                              NULL,
+                                              &fail_cb,
+                                              NULL,
+                                              &empty_zone_proc,
+                                              nsh,
+                                              &empty_zone_end,
+                                              NULL);
   if (NULL == zi)
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create zone iterator\n");
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Failed to create zone iterator\n");
     GNUNET_break (0);
-    GNUNET_SCHEDULER_cancel (endbadly_task);
-    endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
+    res = 1;
+    GNUNET_SCHEDULER_shutdown ();
   }
 }
 
@@ -494,6 +473,8 @@ main (int argc, char *argv[])
   GNUNET_asprintf (&cfg_name,
                    "test_namestore_api_%s.conf",
                    plugin_name);
+  GNUNET_DISK_purge_cfg_dir (cfg_name,
+                             "GNUNET_TEST_HOME");
   res = 1;
   if (0 !=
       GNUNET_TESTING_peer_run ("test-namestore-api-zone-iteration",
@@ -503,12 +484,9 @@ main (int argc, char *argv[])
   {
     res = 1;
   }
+  GNUNET_DISK_purge_cfg_dir (cfg_name,
+                             "GNUNET_TEST_HOME");
   GNUNET_free (cfg_name);
-  if (NULL != directory)
-  {
-      GNUNET_DISK_directory_remove (directory);
-      GNUNET_free (directory);
-  }
   return res;
 }
 
index a8864686458db7d525f1de1c82c3da4275c6c08d..d950b7e693d7f1d41eeddf3f334a859a26594b4e 100644 (file)
@@ -60,7 +60,6 @@ static struct GNUNET_GNSRECORD_Data *s_rd_3;
 
 static struct GNUNET_NAMESTORE_QueueEntry *nsqe;
 
-static char *directory;
 
 /**
  * Re-establish the connection to the service.
@@ -265,7 +264,9 @@ fail_cb (void *cls)
 
 
 static void
-put_cont (void *cls, int32_t success, const char *emsg)
+put_cont (void *cls,
+          int32_t success,
+          const char *emsg)
 {
   static int c = 0;
 
@@ -314,11 +315,11 @@ put_cont (void *cls, int32_t success, const char *emsg)
 static struct GNUNET_GNSRECORD_Data *
 create_record (unsigned int count)
 {
-  unsigned int c;
   struct GNUNET_GNSRECORD_Data * rd;
 
-  rd = GNUNET_malloc (count * sizeof (struct GNUNET_GNSRECORD_Data));
-  for (c = 0; c < count; c++)
+  rd = GNUNET_new_array (count,
+                         struct GNUNET_GNSRECORD_Data);
+  for (unsigned int c = 0; c < count; c++)
   {
     rd[c].expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS).abs_value_us;
     rd[c].record_type = 1111;
@@ -332,7 +333,9 @@ create_record (unsigned int count)
 
 
 static void
-nick_2_cont (void *cls, int32_t success, const char *emsg)
+nick_2_cont (void *cls,
+             int32_t success,
+             const char *emsg)
 {
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Nick added : %s\n",
@@ -422,25 +425,18 @@ empty_zone_proc (void *cls,
 static void
 empty_zone_end (void *cls)
 {
-  char *hostkey_file;
   GNUNET_assert (nsh == cls);
-
   zi = NULL;
-  GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR,
-      "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
-  privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file);
-  GNUNET_free (hostkey_file);
+  privkey = GNUNET_CRYPTO_ecdsa_key_create ();
   GNUNET_assert (privkey != NULL);
-
-  GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR,
-      "HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey");
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
-  privkey2 = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file);
-  GNUNET_free (hostkey_file);
+  privkey2 = GNUNET_CRYPTO_ecdsa_key_create ();
   GNUNET_assert (privkey2 != NULL);
 
-  nsqe = GNUNET_NAMESTORE_set_nick (nsh, privkey, ZONE_NICK_1, &nick_1_cont, &privkey);
+  nsqe = GNUNET_NAMESTORE_set_nick (nsh,
+                                    privkey,
+                                    ZONE_NICK_1,
+                                    &nick_1_cont,
+                                    &privkey);
   if (NULL == nsqe)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -455,15 +451,9 @@ run (void *cls,
      const struct GNUNET_CONFIGURATION_Handle *cfg,
      struct GNUNET_TESTING_Peer *peer)
 {
-  directory = NULL;
-  GNUNET_assert (GNUNET_OK ==
-                 GNUNET_CONFIGURATION_get_value_string (cfg,
-                                                        "PATHS",
-                                                        "GNUNET_TEST_HOME",
-                                                        &directory));
-  GNUNET_DISK_directory_remove (directory);
-
-  endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, &endbadly, NULL);
+  endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
+                                                &endbadly,
+                                                NULL);
   nsh = GNUNET_NAMESTORE_connect (cfg);
   GNUNET_break (NULL != nsh);
 
@@ -498,6 +488,8 @@ main (int argc, char *argv[])
                    "test_namestore_api_%s.conf",
                    plugin_name);
   res = 1;
+  GNUNET_DISK_purge_cfg_dir (cfg_name,
+                             "GNUNET_TEST_HOME");
   if (0 !=
       GNUNET_TESTING_peer_run ("test-namestore-api-zone-iteration-nick",
                                cfg_name,
@@ -506,12 +498,9 @@ main (int argc, char *argv[])
   {
     res = 1;
   }
+  GNUNET_DISK_purge_cfg_dir (cfg_name,
+                             "GNUNET_TEST_HOME");
   GNUNET_free (cfg_name);
-  if (NULL != directory)
-  {
-      GNUNET_DISK_directory_remove (directory);
-      GNUNET_free (directory);
-  }
   return res;
 }
 
index a4fb320e914656e563a49034be331cf4540c235b..0b137cc629eb0c9499659971c898a1534d12eac3 100644 (file)
@@ -57,53 +57,17 @@ static char * s_name_3;
 
 static struct GNUNET_GNSRECORD_Data *s_rd_3;
 
-static char *directory;
 
 /**
- * Re-establish the connection to the service.
+ * Handle timeout.
  *
  * @param cls handle to use to re-connect.
- * @param tc scheduler context
  */
 static void
 endbadly (void *cls)
 {
-  if (NULL != zi)
-  {
-    GNUNET_NAMESTORE_zone_iteration_stop (zi);
-    zi = NULL;
-  }
-  if (nsh != NULL)
-    GNUNET_NAMESTORE_disconnect (nsh);
-  nsh = NULL;
-
-  GNUNET_free_non_null(s_name_1);
-  GNUNET_free_non_null(s_name_2);
-  GNUNET_free_non_null(s_name_3);
-
-  if (s_rd_1 != NULL)
-  {
-    GNUNET_free ((void *)s_rd_1->data);
-    GNUNET_free (s_rd_1);
-  }
-  if (s_rd_2 != NULL)
-  {
-    GNUNET_free ((void *)s_rd_2->data);
-    GNUNET_free (s_rd_2);
-  }
-  if (s_rd_3 != NULL)
-  {
-    GNUNET_free ((void *)s_rd_3->data);
-    GNUNET_free (s_rd_3);
-  }
-
-  if (privkey != NULL)
-    GNUNET_free (privkey);
-  privkey = NULL;
-
-  if (privkey2 != NULL)
-    GNUNET_free (privkey2);
-  privkey2 = NULL;
+  endbadly_task = NULL;
+  GNUNET_SCHEDULER_shutdown ();
   res = 1;
 }
 
@@ -116,21 +80,21 @@ end (void *cls)
     GNUNET_NAMESTORE_zone_iteration_stop (zi);
     zi = NULL;
   }
-
-  if (endbadly_task != NULL)
+  if (NULL != endbadly_task)
   {
     GNUNET_SCHEDULER_cancel (endbadly_task);
     endbadly_task = NULL;
   }
-
-  if (privkey != NULL)
+  if (NULL != privkey)
+  {
     GNUNET_free (privkey);
-  privkey = NULL;
-
-  if (privkey2 != NULL)
+    privkey = NULL;
+  }
+  if (NULL != privkey2)
+  {
     GNUNET_free (privkey2);
-  privkey2 = NULL;
-
+    privkey2 = NULL;
+  }
   GNUNET_free (s_name_1);
   GNUNET_free (s_name_2);
   GNUNET_free (s_name_3);
@@ -150,8 +114,10 @@ end (void *cls)
     GNUNET_free (s_rd_3);
   }
   if (nsh != NULL)
+  {
     GNUNET_NAMESTORE_disconnect (nsh);
-  nsh = NULL;
+    nsh = NULL;
+  }
 }
 
 
@@ -159,6 +125,7 @@ static void
 fail_cb (void *cls)
 {
   GNUNET_assert (0);
+  zi = NULL;
 }
 
 
@@ -244,7 +211,8 @@ zone_proc (void *cls,
   else
   {
     GNUNET_break (0);
-    GNUNET_SCHEDULER_add_now (&end, NULL);
+    res = 2;
+    GNUNET_SCHEDULER_shutdown ();
   }
 }
 
@@ -252,24 +220,28 @@ zone_proc (void *cls,
 static void
 zone_proc_end (void *cls)
 {
+  zi = NULL;
   GNUNET_break (2 == returned_records);
   if (2 == returned_records)
   {
     res = 0; /* Last iteraterator callback, we are done */
-    zi = NULL;
   }
   else
+  {
     res = 1;
+  }
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Received last result, iteration done after receing %u results\n",
               returned_records);
-  GNUNET_SCHEDULER_add_now (&end, NULL);
+  GNUNET_SCHEDULER_shutdown ();
 }
 
 
 static void
-put_cont (void *cls, int32_t success, const char *emsg)
+put_cont (void *cls,
+          int32_t success,
+          const char *emsg)
 {
   static int c = 0;
 
@@ -285,9 +257,8 @@ put_cont (void *cls, int32_t success, const char *emsg)
                 "Failed to created records: `%s'\n",
                emsg);
     GNUNET_break (0);
-    if (NULL != endbadly_task)
-       GNUNET_SCHEDULER_cancel (endbadly_task);
-    endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
+    res = 2;
+    GNUNET_SCHEDULER_shutdown ();
     return;
   }
 
@@ -310,9 +281,8 @@ put_cont (void *cls, int32_t success, const char *emsg)
       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                   "Failed to create zone iterator\n");
       GNUNET_break (0);
-      if (NULL != endbadly_task)
-       GNUNET_SCHEDULER_cancel (endbadly_task);
-      endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
+      res = 2;
+      GNUNET_SCHEDULER_shutdown ();
       return;
     }
   }
@@ -322,11 +292,11 @@ put_cont (void *cls, int32_t success, const char *emsg)
 static struct GNUNET_GNSRECORD_Data *
 create_record (unsigned int count)
 {
-  unsigned int c;
-  struct GNUNET_GNSRECORD_Data * rd;
+  struct GNUNET_GNSRECORD_Data *rd;
 
-  rd = GNUNET_malloc (count * sizeof (struct GNUNET_GNSRECORD_Data));
-  for (c = 0; c < count; c++)
+  rd = GNUNET_new_array (count,
+                         struct GNUNET_GNSRECORD_Data);
+  for (unsigned int c = 0; c < count; c++)
   {
     rd[c].expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS).abs_value_us;
     rd[c].record_type = 1111;
@@ -357,9 +327,8 @@ empty_zone_proc (void *cls,
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 _("Expected empty zone but received zone private key\n"));
     GNUNET_break (0);
-    if (endbadly_task != NULL)
-      GNUNET_SCHEDULER_cancel (endbadly_task);
-    endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
+    res = 2;
+    GNUNET_SCHEDULER_shutdown ();
     return;
   }
   if ((NULL != label) || (NULL != rd) || (0 != rd_count))
@@ -367,9 +336,8 @@ empty_zone_proc (void *cls,
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 _("Expected no zone content but received data\n"));
     GNUNET_break (0);
-    if (endbadly_task != NULL)
-      GNUNET_SCHEDULER_cancel (endbadly_task);
-    endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
+    res = 2;
+    GNUNET_SCHEDULER_shutdown ();
     return;
   }
   GNUNET_assert (0);
@@ -379,35 +347,16 @@ empty_zone_proc (void *cls,
 static void
 empty_zone_proc_end (void *cls)
 {
-  char *hostkey_file;
-
   zi = NULL;
-  GNUNET_asprintf (&hostkey_file,
-                   "zonefiles%s%s",
-                   DIR_SEPARATOR_STR,
-                   "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Using zonekey file `%s'\n",
-              hostkey_file);
-  privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file);
-  GNUNET_free (hostkey_file);
+  privkey = GNUNET_CRYPTO_ecdsa_key_create ();
   GNUNET_assert (privkey != NULL);
-
-  GNUNET_asprintf(&hostkey_file,
-                  "zonefiles%s%s",
-                  DIR_SEPARATOR_STR,
-                  "HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey");
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Using zonekey file `%s' \n",
-              hostkey_file);
-  privkey2 = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file);
-  GNUNET_free (hostkey_file);
+  privkey2 = GNUNET_CRYPTO_ecdsa_key_create ();
   GNUNET_assert (privkey2 != NULL);
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Created record 1\n");
-
-  GNUNET_asprintf(&s_name_1, "dummy1");
+  GNUNET_asprintf (&s_name_1,
+                   "dummy1");
   s_rd_1 = create_record (1);
   GNUNET_NAMESTORE_records_store (nsh,
                                   privkey,
@@ -419,7 +368,8 @@ empty_zone_proc_end (void *cls)
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Created record 2 \n");
-  GNUNET_asprintf(&s_name_2, "dummy2");
+  GNUNET_asprintf (&s_name_2,
+                   "dummy2");
   s_rd_2 = create_record (1);
   GNUNET_NAMESTORE_records_store (nsh,
                                   privkey,
@@ -433,7 +383,8 @@ empty_zone_proc_end (void *cls)
               "Created record 3\n");
 
   /* name in different zone */
-  GNUNET_asprintf(&s_name_3, "dummy3");
+  GNUNET_asprintf (&s_name_3,
+                   "dummy3");
   s_rd_3 = create_record (1);
   GNUNET_NAMESTORE_records_store (nsh,
                                   privkey2,
@@ -449,14 +400,8 @@ run (void *cls,
      const struct GNUNET_CONFIGURATION_Handle *cfg,
      struct GNUNET_TESTING_Peer *peer)
 {
-  directory = NULL;
-  GNUNET_assert (GNUNET_OK ==
-                 GNUNET_CONFIGURATION_get_value_string (cfg,
-                                                        "PATHS",
-                                                        "GNUNET_TEST_HOME",
-                                                        &directory));
-  GNUNET_DISK_directory_remove (directory);
-
+  GNUNET_SCHEDULER_add_shutdown (&end,
+                                 NULL);
   endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
                                                 &endbadly,
                                                 NULL);
@@ -476,8 +421,7 @@ run (void *cls,
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "Failed to create zone iterator\n");
     GNUNET_break (0);
-    GNUNET_SCHEDULER_cancel (endbadly_task);
-    endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
+    GNUNET_SCHEDULER_shutdown ();
   }
 }
 
@@ -493,6 +437,8 @@ main (int argc, char *argv[])
                    "test_namestore_api_%s.conf",
                    plugin_name);
   res = 1;
+  GNUNET_DISK_purge_cfg_dir (cfg_name,
+                             "GNUNET_TEST_HOME");
   if (0 !=
       GNUNET_TESTING_peer_run ("test-namestore-api-zone-iteration-specific-zone",
                                cfg_name,
@@ -501,12 +447,9 @@ main (int argc, char *argv[])
   {
     res = 1;
   }
+  GNUNET_DISK_purge_cfg_dir (cfg_name,
+                             "GNUNET_TEST_HOME");
   GNUNET_free (cfg_name);
-  if (NULL != directory)
-  {
-      GNUNET_DISK_directory_remove (directory);
-      GNUNET_free (directory);
-  }
   return res;
 }
 
index c7be5feadd3bd61055a2490af85e9cda0864fd3a..c7358fc6eaa8d86c1beda61db6958b6c353cbd0e 100644 (file)
@@ -56,7 +56,6 @@ static char * s_name_3;
 
 static struct GNUNET_GNSRECORD_Data *s_rd_3;
 
-static char *directory;
 
 
 /**
@@ -475,14 +474,9 @@ run (void *cls,
      const struct GNUNET_CONFIGURATION_Handle *cfg,
      struct GNUNET_TESTING_Peer *peer)
 {
-  GNUNET_assert (GNUNET_OK ==
-                 GNUNET_CONFIGURATION_get_value_string (cfg,
-                                                        "PATHS",
-                                                        "GNUNET_TEST_HOME",
-                                                        &directory));
-  GNUNET_DISK_directory_remove (directory);
-
-  endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &endbadly, NULL);
+  endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
+                                                &endbadly,
+                                                NULL);
   nsh = GNUNET_NAMESTORE_connect (cfg);
   GNUNET_break (NULL != nsh);
   /* first, iterate over empty namestore */
@@ -515,6 +509,8 @@ main (int argc, char *argv[])
   GNUNET_asprintf (&cfg_name,
                    "test_namestore_api_%s.conf",
                    plugin_name);
+  GNUNET_DISK_purge_cfg_dir (cfg_name,
+                             "GNUNET_TEST_HOME");
   res = 1;
   if (0 !=
       GNUNET_TESTING_peer_run ("test-namestore-api-zone-iteration-stop",
@@ -524,12 +520,10 @@ main (int argc, char *argv[])
   {
     res = 1;
   }
+  GNUNET_DISK_purge_cfg_dir (cfg_name,
+                             "GNUNET_TEST_HOME");
   GNUNET_free (cfg_name);
-  if (NULL != directory)
-  {
-      GNUNET_DISK_directory_remove (directory);
-      GNUNET_free (directory);
-  }
+
   return res;
 }
 
index 5b088d90b0f1be7dc7db909b500731de0736fd09..292d8f7019246be760bac2a6d8ea171143b5bc96 100644 (file)
@@ -51,8 +51,6 @@ static char * s_name;
 
 static int res;
 
-static char *directory;
-
 static struct GNUNET_NAMESTORE_QueueEntry *qe;
 
 
@@ -204,34 +202,13 @@ run (void *cls,
 {
   (void) cls;
   (void) peer;
-  directory = NULL;
-  GNUNET_assert (GNUNET_OK ==
-                GNUNET_CONFIGURATION_get_value_string (cfg,
-                                                       "PATHS",
-                                                       "GNUNET_TEST_HOME",
-                                                       &directory));
-  GNUNET_DISK_directory_remove (directory);
-
   endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
                                                &endbadly,
                                                NULL);
   GNUNET_SCHEDULER_add_shutdown (&end,
                                 NULL);
   GNUNET_asprintf (&s_name, "dummy");
-  /* load privat key */
-  {
-    char *zonekey_file;
-
-    GNUNET_asprintf (&zonekey_file,
-                    "zonefiles%s%s",
-                    DIR_SEPARATOR_STR,
-                    "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-               "Using zonekey file `%s'\n",
-               zonekey_file);
-    privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (zonekey_file);
-    GNUNET_free (zonekey_file);
-  }
+  privkey = GNUNET_CRYPTO_ecdsa_key_create ();
   GNUNET_assert (NULL != privkey);
   /* get public key */
   GNUNET_CRYPTO_ecdsa_key_get_public (privkey,
@@ -274,6 +251,8 @@ main (int argc,
   GNUNET_asprintf (&cfg_name,
                    "test_namestore_api_%s.conf",
                    plugin_name);
+  GNUNET_DISK_purge_cfg_dir (cfg_name,
+                             "GNUNET_TEST_HOME");
   res = 1;
   if (0 !=
       GNUNET_TESTING_peer_run ("test-namestore-api-zone-to-name",
@@ -283,12 +262,9 @@ main (int argc,
   {
     res = 1;
   }
+  GNUNET_DISK_purge_cfg_dir (cfg_name,
+                             "GNUNET_TEST_HOME");
   GNUNET_free (cfg_name);
-  if (NULL != directory)
-  {
-    GNUNET_DISK_directory_remove (directory);
-    GNUNET_free (directory);
-  }
   return res;
 }
 
index 6bccd1706b1b286f55632fc7a9937ba0a4dec0c8..8732acbcb2fbc6e02ef4185c24897c3bba25a553 100644 (file)
@@ -215,6 +215,8 @@ main (int argc,
                    sizeof (cfg_name),
                    "test_plugin_namestore_%s.conf",
                    plugin_name);
+  GNUNET_DISK_purge_cfg_dir (cfg_name,
+                             "GNUNET_TMP");
   GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1,
                       xargv,
                       "test-plugin-namestore",
@@ -222,6 +224,8 @@ main (int argc,
                       options,
                       &run,
                       NULL);
+  GNUNET_DISK_purge_cfg_dir (cfg_name,
+                             "GNUNET_TMP");
   if (ok != 0)
     FPRINTF (stderr,
              "Missed some testcases: %d\n",
index 6a5491df728f834b8e12c06b389fd31c69e8eaed..5c632f0d1e3ae37c3d37e7d5bab14fb9f7c45ba7 100644 (file)
@@ -1,5 +1,2 @@
 [namestore-flat]
-FILENAME = $GNUNET_TMP/gnunet-test-plugin-namestore-sqlite/flatdb
-
-[namestore]
-# PREFIX = valgrind --log-file=/home/schanzen/dev/gnunet/src/namestore/vg_log
+FILENAME = $GNUNET_TMP/gnunet-test-plugin-namestore-flat/flatdb
index d9129afb08bafd8d5196a17e038a52db98bfb0e8..359e529b0f3ed4b3814b6676dba64f95f5e93c56 100644 (file)
 #define ICMP_TIME_EXCEEDED 11
 #endif
 
+/**
+ * Call memcpy() but check for @a n being 0 first. In the latter
+ * case, it is now safe to pass NULL for @a src or @a dst.
+ * Unlike traditional memcpy(), returns nothing.
+ *
+ * @param dst destination of the copy, may be NULL if @a n is zero
+ * @param src source of the copy, may be NULL if @a n is zero
+ * @param n number of bytes to copy
+ */
+#define GNUNET_memcpy(dst,src,n) do { if (0 != n) { (void) memcpy (dst,src,n); } } while (0)
+
 /**
  * Must match IP given in the server.
  */
@@ -251,14 +262,18 @@ send_icmp_udp (const struct in_addr *my_ip, const struct in_addr *other)
   ip_pkt.dst_ip = other->s_addr;
   ip_pkt.checksum =
       htons (calc_checksum ((uint16_t *) & ip_pkt, sizeof (struct ip_header)));
-  memcpy (&packet[off], &ip_pkt, sizeof (struct ip_header));
+  GNUNET_memcpy (&packet[off],
+                 &ip_pkt,
+                 sizeof (struct ip_header));
   off += sizeof (struct ip_header);
 
   icmp_pkt.type = ICMP_TIME_EXCEEDED;
   icmp_pkt.code = 0;
   icmp_pkt.checksum = 0;
   icmp_pkt.unused = 0;
-  memcpy (&packet[off], &icmp_pkt, sizeof (struct icmp_ttl_exceeded_header));
+  GNUNET_memcpy (&packet[off],
+                 &icmp_pkt,
+                 sizeof (struct icmp_ttl_exceeded_header));
   off += sizeof (struct icmp_ttl_exceeded_header);
 
   /* ip header of the presumably 'lost' udp packet */
@@ -275,7 +290,9 @@ send_icmp_udp (const struct in_addr *my_ip, const struct in_addr *other)
   ip_pkt.dst_ip = dummy.s_addr;
   ip_pkt.checksum =
       htons (calc_checksum ((uint16_t *) & ip_pkt, sizeof (struct ip_header)));
-  memcpy (&packet[off], &ip_pkt, sizeof (struct ip_header));
+  GNUNET_memcpy (&packet[off],
+                 &ip_pkt,
+                 sizeof (struct ip_header));
   off += sizeof (struct ip_header);
 
   /* build UDP header */
@@ -283,7 +300,9 @@ send_icmp_udp (const struct in_addr *my_ip, const struct in_addr *other)
   udp_pkt.dst_port = htons (NAT_TRAV_PORT);
   udp_pkt.length = htons (port);
   udp_pkt.crc = 0;
-  memcpy (&packet[off], &udp_pkt, sizeof (struct udp_header));
+  GNUNET_memcpy (&packet[off],
+                 &udp_pkt,
+                 sizeof (struct udp_header));
   off += sizeof (struct udp_header);
 
   /* set ICMP checksum */
@@ -292,8 +311,9 @@ send_icmp_udp (const struct in_addr *my_ip, const struct in_addr *other)
              ((uint16_t *) & packet[sizeof (struct ip_header)],
               sizeof (struct icmp_ttl_exceeded_header) +
               sizeof (struct ip_header) + sizeof (struct udp_header)));
-  memcpy (&packet[sizeof (struct ip_header)], &icmp_pkt,
-          sizeof (struct icmp_ttl_exceeded_header));
+  GNUNET_memcpy (&packet[sizeof (struct ip_header)],
+                 &icmp_pkt,
+                 sizeof (struct icmp_ttl_exceeded_header));
 
   memset (&dst, 0, sizeof (dst));
   dst.sin_family = AF_INET;
@@ -352,7 +372,9 @@ send_icmp (const struct in_addr *my_ip, const struct in_addr *other)
   ip_pkt.dst_ip = other->s_addr;
   ip_pkt.checksum =
       htons (calc_checksum ((uint16_t *) & ip_pkt, sizeof (struct ip_header)));
-  memcpy (&packet[off], &ip_pkt, sizeof (struct ip_header));
+  GNUNET_memcpy (&packet[off],
+                 &ip_pkt,
+                 sizeof (struct ip_header));
   off = sizeof (ip_pkt);
 
   /* icmp reply: time exceeded */
@@ -360,7 +382,9 @@ send_icmp (const struct in_addr *my_ip, const struct in_addr *other)
   icmp_ttl.code = 0;
   icmp_ttl.checksum = 0;
   icmp_ttl.unused = 0;
-  memcpy (&packet[off], &icmp_ttl, sizeof (struct icmp_ttl_exceeded_header));
+  GNUNET_memcpy (&packet[off],
+                 &icmp_ttl,
+                 sizeof (struct icmp_ttl_exceeded_header));
   off += sizeof (struct icmp_ttl_exceeded_header);
 
   /* ip header of the presumably 'lost' udp packet */
@@ -377,7 +401,9 @@ send_icmp (const struct in_addr *my_ip, const struct in_addr *other)
   ip_pkt.checksum = 0;
   ip_pkt.checksum =
       htons (calc_checksum ((uint16_t *) & ip_pkt, sizeof (struct ip_header)));
-  memcpy (&packet[off], &ip_pkt, sizeof (struct ip_header));
+  GNUNET_memcpy (&packet[off],
+                 &ip_pkt,
+                 sizeof (struct ip_header));
   off += sizeof (struct ip_header);
 
   icmp_echo.type = ICMP_ECHO;
@@ -386,8 +412,10 @@ send_icmp (const struct in_addr *my_ip, const struct in_addr *other)
   icmp_echo.checksum = 0;
   icmp_echo.checksum =
       htons (calc_checksum
-             ((uint16_t *) & icmp_echo, sizeof (struct icmp_echo_header)));
-  memcpy (&packet[off], &icmp_echo, sizeof (struct icmp_echo_header));
+             ((uint16_t *) &icmp_echo, sizeof (struct icmp_echo_header)));
+  GNUNET_memcpy (&packet[off],
+                 &icmp_echo,
+                 sizeof (struct icmp_echo_header));
 
   /* no go back to calculate ICMP packet checksum */
   off = sizeof (struct ip_header);
@@ -396,7 +424,9 @@ send_icmp (const struct in_addr *my_ip, const struct in_addr *other)
              ((uint16_t *) & packet[off],
               sizeof (struct icmp_ttl_exceeded_header) +
               sizeof (struct ip_header) + sizeof (struct icmp_echo_header)));
-  memcpy (&packet[off], &icmp_ttl, sizeof (struct icmp_ttl_exceeded_header));
+  GNUNET_memcpy (&packet[off],
+                 &icmp_ttl,
+                 sizeof (struct icmp_ttl_exceeded_header));
 
   /* prepare for transmission */
   memset (&dst, 0, sizeof (dst));
index ef8e97482771d0054713251e7f23c35fc028ed0d..b8f499b4d06f6e88e718f29015eb50e7a8d521b5 100644 (file)
 #define ICMP_TIME_EXCEEDED 11
 #endif
 
+/**
+ * Call memcpy() but check for @a n being 0 first. In the latter
+ * case, it is now safe to pass NULL for @a src or @a dst.
+ * Unlike traditional memcpy(), returns nothing.
+ *
+ * @param dst destination of the copy, may be NULL if @a n is zero
+ * @param src source of the copy, may be NULL if @a n is zero
+ * @param n number of bytes to copy
+ */
+#define GNUNET_memcpy(dst,src,n) do { if (0 != n) { (void) memcpy (dst,src,n); } } while (0)
+
 /**
  * Should we print some debug output?
  */
@@ -266,9 +277,9 @@ send_icmp_echo (const struct in_addr *my_ip)
   ip_pkt.checksum =
       htons (calc_checksum ((uint16_t *) & ip_pkt,
                            sizeof (struct ip_header)));
-  memcpy (&packet[off],
-         &ip_pkt,
-         sizeof (struct ip_header));
+  GNUNET_memcpy (&packet[off],
+                 &ip_pkt,
+                 sizeof (struct ip_header));
   off += sizeof (struct ip_header);
 
   icmp_echo.type = ICMP_ECHO;
@@ -279,9 +290,9 @@ send_icmp_echo (const struct in_addr *my_ip)
     htons (calc_checksum
           ((uint16_t *) & icmp_echo,
            sizeof (struct icmp_echo_header)));
-  memcpy (&packet[off],
-         &icmp_echo,
-         sizeof (struct icmp_echo_header));
+  GNUNET_memcpy (&packet[off],
+                 &icmp_echo,
+                 sizeof (struct icmp_echo_header));
   off += sizeof (struct icmp_echo_header);
 
   memset (&dst, 0, sizeof (dst));
@@ -388,9 +399,13 @@ process_icmp_response ()
     return;
   }
   off = 0;
-  memcpy (&ip_pkt, &buf[off], sizeof (struct ip_header));
+  GNUNET_memcpy (&ip_pkt,
+                 &buf[off],
+                 sizeof (struct ip_header));
   off += sizeof (struct ip_header);
-  memcpy (&icmp_ttl, &buf[off], sizeof (struct icmp_ttl_exceeded_header));
+  GNUNET_memcpy (&icmp_ttl,
+                 &buf[off],
+                 sizeof (struct icmp_ttl_exceeded_header));
   off += sizeof (struct icmp_ttl_exceeded_header);
   if ((ICMP_TIME_EXCEEDED != icmp_ttl.type) || (0 != icmp_ttl.code))
   {
@@ -401,7 +416,9 @@ process_icmp_response ()
   source_ip.s_addr = ip_pkt.src_ip;
 
   /* skip 2nd IP header */
-  memcpy (&ip_pkt, &buf[off], sizeof (struct ip_header));
+  GNUNET_memcpy (&ip_pkt,
+                 &buf[off],
+                 sizeof (struct ip_header));
   off += sizeof (struct ip_header);
 
   switch (ip_pkt.proto)
@@ -416,7 +433,9 @@ process_icmp_response ()
       return;
     }
     /* grab ICMP ECHO content */
-    memcpy (&icmp_echo, &buf[off], sizeof (struct icmp_echo_header));
+    GNUNET_memcpy (&icmp_echo,
+                   &buf[off],
+                   sizeof (struct icmp_echo_header));
     port = (uint16_t) ntohl (icmp_echo.reserved);
     break;
   case IPPROTO_UDP:
@@ -428,7 +447,9 @@ process_icmp_response ()
       return;
     }
     /* grab UDP content */
-    memcpy (&udp_pkt, &buf[off], sizeof (struct udp_header));
+    GNUNET_memcpy (&udp_pkt,
+                   &buf[off],
+                   sizeof (struct udp_header));
     port = ntohs (udp_pkt.length);
     break;
   default:
index 0695c7ac70b63a9ab1ad88844841e2580b74d4c5..21089890de616a1ed0896c9c945ecc218d457c6b 100644 (file)
@@ -1234,8 +1234,12 @@ process_external_ip (void *cls,
              ch->hole_external);
 
   /* build sockaddr storage with port number */
-  memset (&ss, 0, sizeof (ss));
-  memcpy (&ss, addr, addrlen);
+  memset (&ss,
+          0,
+          sizeof (ss));
+  GNUNET_memcpy (&ss,
+                 addr,
+                 addrlen);
   switch (addr->sa_family)
   {
   case AF_INET:
index 814380246523af01255d3b75493257d4476e04e9..c5f9f6cf0e76585ed73ee618528388476a359ef3 100644 (file)
@@ -172,9 +172,9 @@ move_children (struct RegexCombineCtx *dst,
   size_t array_size;
 
   array_size = sizeof(struct RegexCombineCtx *) * src->size;
-  memcpy (dst->children,
-         src->children,
-         array_size);
+  GNUNET_memcpy (dst->children,
+                 src->children,
+                 array_size);
   for (unsigned int i = 0; i < src->size; i++)
   {
     src->children[i] = NULL;
@@ -364,7 +364,9 @@ regex_add_multiple (struct RegexCombineCtx *ctx,
       newctx = new_regex_ctx(ctx->size);
       newctx->s = GNUNET_strdup (tmp);
       if (children != NULL)
-        memcpy (newctx->children, children, sizeof (*children) * ctx->size);
+        GNUNET_memcpy (newctx->children,
+                       children,
+                       sizeof (*children) * ctx->size);
       ctx->children[c2i(tmp[0], ctx->size)] = newctx;
     }
   }
index 8d31bf50d6437a8a8af3989bd1266f3cdfeb96ba..b433a51d4d92d391fd306eaa0eb3d6d0b07488ae 100644 (file)
@@ -1836,7 +1836,7 @@ static uint32_t binom (uint32_t n, uint32_t k)
  * @param a
  * @param b
  *
- * @return 
+ * @return
  */
 static int is_in_view (uint32_t a, uint32_t b)
 {
@@ -2172,9 +2172,9 @@ void view_update_cb (void *cls,
                      rps_peer->cur_view_count,
                      view_size);
   //*rps_peer->cur_view = *peers;
-  memcpy (rps_peer->cur_view,
-          peers,
-          view_size * sizeof (struct GNUNET_PeerIdentity));
+  GNUNET_memcpy (rps_peer->cur_view,
+                 peers,
+                 view_size * sizeof (struct GNUNET_PeerIdentity));
   to_file ("/tmp/rps/count_in_views.txt",
          "%" PRIu64 " %" PRIu32 "",
          rps_peer->index,
index 119a9473497de388ec9e48d81871a983d03e9e14..fb936400541450fa12ddc82c6bf5ad39ec3797e0 100644 (file)
@@ -1,5 +1,5 @@
 # This Makefile.am is in the public domain
-AM_CPPFLAGS = -I$(top_srcdir)/src/include 
+AM_CPPFLAGS = -I$(top_srcdir)/src/include
 
 if MINGW
   WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols
@@ -15,6 +15,8 @@ endif
 
 libgnunetsq_la_SOURCES = \
   sq.c \
+  sq_exec.c \
+  sq_prepare.c \
   sq_query_helper.c \
   sq_result_helper.c
 libgnunetsq_la_LIBADD = -lsqlite3 \
diff --git a/src/sq/sq_exec.c b/src/sq/sq_exec.c
new file mode 100644 (file)
index 0000000..c40b1fb
--- /dev/null
@@ -0,0 +1,109 @@
+/*
+  This file is part of GNUnet
+  Copyright (C) 2018 GNUnet e.V.
+
+  GNUnet is free software; you can redistribute it and/or modify it under the
+  terms of the GNU General Public License as published by the Free Software
+  Foundation; either version 3, or (at your option) any later version.
+
+  GNUnet is distributed in the hope that it will be useful, but WITHOUT ANY
+  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+  A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License along with
+  GNUnet; see the file COPYING.  If not, If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file sq/sq_exec.c
+ * @brief helper functions for executing SQL statements
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "gnunet_sq_lib.h"
+
+
+/**
+ * Create a `struct GNUNET_SQ_ExecuteStatement` where errors are fatal.
+ *
+ * @param sql actual SQL statement
+ * @return initialized struct
+ */
+struct GNUNET_SQ_ExecuteStatement
+GNUNET_SQ_make_execute (const char *sql)
+  {
+  struct GNUNET_SQ_ExecuteStatement es = {
+    .sql = sql,
+    .ignore_errors = GNUNET_NO
+  };
+
+  return es;
+}
+
+
+
+/**
+ * Create a `struct GNUNET_SQ_ExecuteStatement` where errors should
+ * be tolerated.
+ *
+ * @param sql actual SQL statement
+ * @return initialized struct
+ */
+struct GNUNET_SQ_ExecuteStatement
+GNUNET_SQ_make_try_execute (const char *sql)
+{
+  struct GNUNET_SQ_ExecuteStatement es = {
+    .sql = sql,
+    .ignore_errors = GNUNET_YES
+  };
+
+  return es;
+}
+
+
+/**
+ * Request execution of an array of statements @a es from Postgres.
+ *
+ * @param dbh database to execute the statements over
+ * @param es #GNUNET_PQ_PREPARED_STATEMENT_END-terminated array of prepared
+ *            statements.
+ * @return #GNUNET_OK on success (modulo statements where errors can be ignored)
+ *         #GNUNET_SYSERR on error
+ */
+int
+GNUNET_SQ_exec_statements (sqlite3 *dbh,
+                           const struct GNUNET_SQ_ExecuteStatement *es)
+{
+  for (unsigned int i=0;NULL != es[i].sql;i++)
+  {
+    char *emsg = NULL;
+
+    if (SQLITE_OK !=
+        sqlite3_exec (dbh,
+                      es[i].sql,
+                      NULL,
+                      NULL,
+                      &emsg))
+    {
+      if (es[i].ignore_errors)
+      {
+        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                    "Failed to run SQL `%s': %s\n",
+                    es[i].sql,
+                    emsg);
+      }
+      else
+      {
+        GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                    "Failed to run SQL `%s': %s\n",
+                    es[i].sql,
+                    emsg);
+        sqlite3_free (emsg);
+        return GNUNET_SYSERR;
+      }
+      sqlite3_free (emsg);
+    }
+  }
+  return GNUNET_OK;
+}
+
+/* end of sq_exec */
diff --git a/src/sq/sq_prepare.c b/src/sq/sq_prepare.c
new file mode 100644 (file)
index 0000000..db1047c
--- /dev/null
@@ -0,0 +1,81 @@
+/*
+  This file is part of GNUnet
+  Copyright (C) 2018 GNUnet e.V.
+
+  GNUnet is free software; you can redistribute it and/or modify it under the
+  terms of the GNU General Public License as published by the Free Software
+  Foundation; either version 3, or (at your option) any later version.
+
+  GNUnet is distributed in the hope that it will be useful, but WITHOUT ANY
+  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+  A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License along with
+  GNUnet; see the file COPYING.  If not, If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file sq/sq_prepare.c
+ * @brief helper functions for executing SQL statements
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "gnunet_sq_lib.h"
+
+
+/**
+ * Create a `struct GNUNET_SQ_PrepareStatement`
+ *
+ * @param sql actual SQL statement
+ * @param pstmt where to store the handle
+ * @return initialized struct
+ */
+struct GNUNET_SQ_PrepareStatement
+GNUNET_SQ_make_prepare (const char *sql,
+                        sqlite3_stmt **pstmt)
+{
+  struct GNUNET_SQ_PrepareStatement ps = {
+    .sql = sql,
+    .pstmt = pstmt
+  };
+
+  return ps;
+}
+
+
+
+/**
+ * Prepare all statements given in the (NULL,NULL)-terminated
+ * array at @a ps
+ *
+ * @param dbh database to use
+ * @param ps array of statements to prepare
+ * @return #GNUNET_OK on success
+ */
+int
+GNUNET_SQ_prepare (sqlite3 *dbh,
+                   const struct GNUNET_SQ_PrepareStatement *ps)
+{
+  for (unsigned int i=0;NULL != ps[i].sql;i++)
+  {
+    const char *epos = NULL;
+    int ret;
+
+    if (SQLITE_OK !=
+        (ret = sqlite3_prepare_v2 (dbh,
+                                   ps[i].sql,
+                                   strlen (ps[i].sql),
+                                   ps[i].pstmt,
+                                   &epos)))
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                  "Failed to prepare SQL `%s': error %d at %s\n",
+                  ps[i].sql,
+                  ret,
+                  epos);
+      return GNUNET_SYSERR;
+    }
+  }
+  return GNUNET_OK;
+}
+
+/* end of sq_prepare.c */
index 8f6966b6f073ccabcb2377246262783fa086a1f5..96714cf9a88d9ad435822e2047b290884320b035 100644 (file)
@@ -8,10 +8,10 @@ import subprocess
 import time
 
 if os.name == "nt":
-  tmp = os.getenv ("TEMP")
-elif os.environ["TMPDIR"]:
+    tmp = os.getenv ("TEMP")
+elif None != os.environ.get("TMPDIR"):
     tmp = os.getenv("TMPDIR")
-elif os.environ["TMP"]:
+elif None != os.environ.get("TMP"):
     tmp = os.getenv("TMP")
 else:
     tmp = "/tmp"
index 66555291cd14dd15b1a19f4d48892751e2ff7089..9ef8d067375db8dd9b786db776459ec41cd958e8 100644 (file)
@@ -1,5 +1,5 @@
 @INLINE@ ../../contrib/no_forcestart.conf
+@INLINE@ ../../contrib/no_autostart_above_core.conf
 
 [PATHS]
 GNUNET_TEST_HOME = $GNUNET_TMP/test-gnunet-statistics/
-
index acb3911f05afd5baa0cac10bd615ab53a807f36d..2ef3a0cebed2cfa840e425f7f0da892da7de52b8 100644 (file)
@@ -566,8 +566,10 @@ handle_helper_message (void *cls,
  * @param c configuration to use
  */
 static void
-run (void *cls, char * const *args, const char *cfgfile,
-    const struct GNUNET_CONFIGURATION_Handle *c)
+run (void *cls,
+     char * const *args,
+     const char *cfgfile,
+     const struct GNUNET_CONFIGURATION_Handle *c)
 {
   char * const *argv = cls;
   unsigned long long tneigh;
@@ -575,26 +577,32 @@ run (void *cls, char * const *args, const char *cfgfile,
   char *plugin;
   char *sep;
 
-  timeout_endbadly = GNUNET_SCHEDULER_add_delayed (TIMEOUT, end_badly, &ok);
-
+  timeout_endbadly = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
+                                                   &end_badly,
+                                                   &ok);
   cfg = c;
   /* parse configuration */
-  if ((GNUNET_OK
-      != GNUNET_CONFIGURATION_get_value_number (c, "TRANSPORT",
-          "NEIGHBOUR_LIMIT", &tneigh))
-      || (GNUNET_OK
-          != GNUNET_CONFIGURATION_get_value_filename (c, "PEER", "PRIVATE_KEY",
-              &keyfile)))
+  if ( (GNUNET_OK !=
+        GNUNET_CONFIGURATION_get_value_number (c,
+                                               "TRANSPORT",
+                                               "NEIGHBOUR_LIMIT",
+                                               &tneigh)) ||
+       (GNUNET_OK !=
+        GNUNET_CONFIGURATION_get_value_filename (c,
+                                                 "PEER",
+                                                 "PRIVATE_KEY",
+                                                 &keyfile)))
   {
     GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
         "Transport service is lacking key configuration settings.  Exiting.\n");
     return;
   }
 
-  if (NULL == (stats = GNUNET_STATISTICS_create ("transport", cfg)))
+  if (NULL == (stats = GNUNET_STATISTICS_create ("transport",
+                                                 cfg)))
   {
     GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
-        "Could not create statistics.  Exiting.\n");
+               "Could not create statistics.  Exiting.\n");
     GNUNET_free(keyfile);
     end_badly_now ();
     return;
@@ -602,27 +610,33 @@ run (void *cls, char * const *args, const char *cfgfile,
 
   if (GNUNET_OK != GNUNET_DISK_file_test (HOSTKEY_FILE))
   {
-    GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Hostkey `%s' missing.  Exiting.\n",
-        HOSTKEY_FILE);
+    GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
+               "Hostkey `%s' missing.  Exiting.\n",
+               HOSTKEY_FILE);
     GNUNET_free(keyfile);
     end_badly_now ();
     return;
   }
 
-  if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (keyfile))
+  if (GNUNET_OK !=
+      GNUNET_DISK_directory_create_for_file (keyfile))
   {
     GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
-        "Could not create a directory for hostkey `%s'.  Exiting.\n", keyfile);
+               "Could not create a directory for hostkey `%s'.  Exiting.\n",
+               keyfile);
     GNUNET_free(keyfile);
     end_badly_now ();
     return;
   }
 
-  if (GNUNET_OK != GNUNET_DISK_file_copy (HOSTKEY_FILE, keyfile))
+  if (GNUNET_OK !=
+      GNUNET_DISK_file_copy (HOSTKEY_FILE,
+                             keyfile))
   {
     GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
-        "Could not copy hostkey `%s' to destination `%s'.  Exiting.\n",
-        HOSTKEY_FILE, keyfile);
+               "Could not copy hostkey `%s' to destination `%s'.  Exiting.\n",
+               HOSTKEY_FILE,
+               keyfile);
     GNUNET_free(keyfile);
     end_badly_now ();
     return;
@@ -730,9 +744,9 @@ run (void *cls, char * const *args, const char *cfgfile,
     end_badly_now ();
     return;
   }
-
 }
 
+
 /**
  * The main function for the test
  *
@@ -741,23 +755,32 @@ run (void *cls, char * const *args, const char *cfgfile,
  * @return 0 ok, 1 on error
  */
 int
-main (int argc, char * const *argv)
+main (int argc,
+      char * const *argv)
 {
   static struct GNUNET_GETOPT_CommandLineOption options[] = {
-      GNUNET_GETOPT_OPTION_END };
+    GNUNET_GETOPT_OPTION_END
+  };
   int ret;
-
-  GNUNET_DISK_directory_remove (GNUNET_DISK_mktemp("test-gnunetd-plugin-transport"));
-
-  char * const argv_prog[] = { "test_plugin_transport", "-c",
-      "test_plugin_transport_data.conf", NULL };
-  GNUNET_log_setup ("test-plugin-transport", "WARNING", NULL );
+  char * const argv_prog[] = {
+    "test_plugin_transport",
+    "-c",
+    "test_plugin_transport_data.conf",
+    NULL
+  };
+
+  GNUNET_log_setup ("test-plugin-transport",
+                    "WARNING",
+                    NULL);
+  GNUNET_DISK_purge_cfg_dir ("test_plugin_transport_data.conf",
+                             "GNUNET_TEST_HOME");
   ok = 1; /* set to fail */
   ret =
       (GNUNET_OK
           == GNUNET_PROGRAM_run (3, argv_prog, "test-plugin-transport",
               "testcase", options, &run, (void *) argv)) ? ok : 1;
-  GNUNET_DISK_directory_remove (GNUNET_DISK_mktemp("test-gnunetd-plugin-transport"));
+  GNUNET_DISK_purge_cfg_dir ("test_plugin_transport_data.conf",
+                             "GNUNET_TEST_HOME");
   return ret;
 }
 
index fcaa826eda111f4bcd1a10430f99897210ed8bc7..a5cdb2823b0c1690a81a7cfab04006c3372fc51e 100644 (file)
@@ -53,12 +53,14 @@ init_aes( element_t k, int enc,
   int rc;
   int key_len;
   unsigned char* key_buf;
-  
+
   key_len = element_length_in_bytes(k) < 33 ? 3 : element_length_in_bytes(k);
   key_buf = (unsigned char*) malloc(key_len);
   element_to_bytes(key_buf, k);
 
-  memcpy (key->aes_key, key_buf, GNUNET_CRYPTO_AES_KEY_LENGTH); 
+  GNUNET_memcpy (key->aes_key,
+                 key_buf,
+                 GNUNET_CRYPTO_AES_KEY_LENGTH);
   GNUNET_assert (0 ==
                  gcry_cipher_open (handle, GCRY_CIPHER_AES256,
                                    GCRY_CIPHER_MODE_CFB, 0));
@@ -123,16 +125,16 @@ aes_128_cbc_decrypt( char* ct,
   unsigned char iv[16];
   char* tmp;
   uint32_t len;
-  
+
   init_aes(k, 1, &handle, &skey, iv);
 
   tmp = GNUNET_malloc (size);
 
   //AES_cbc_encrypt(ct->data, pt->data, ct->len, &key, iv, AES_DECRYPT);
-  GNUNET_assert (0 == gcry_cipher_decrypt (handle, tmp, size, ct, size)); 
+  GNUNET_assert (0 == gcry_cipher_decrypt (handle, tmp, size, ct, size));
   gcry_cipher_close (handle);
   /* TODO make less crufty */
-  
+
   /* get real length */
   len = 0;
   len = len
@@ -173,7 +175,7 @@ GNUNET_CRYPTO_cpabe_create_key (struct GNUNET_CRYPTO_AbeMasterKey *key,
   struct GNUNET_CRYPTO_AbeKey *prv_key;
   int size;
   char *tmp;
-  
+
   prv_key = GNUNET_new (struct GNUNET_CRYPTO_AbeKey);
   prv_key->prv = gabe_keygen(key->pub, key->msk, attrs);
   size = gabe_pub_serialize(key->pub, &tmp);
@@ -204,7 +206,7 @@ write_cpabe (void **result,
 {
   char *ptr;
   uint32_t *len;
-  
+
   *result = GNUNET_malloc (12 + cph_buf_len + aes_buf_len);
   ptr = *result;
   len = (uint32_t*) ptr;
@@ -213,12 +215,12 @@ write_cpabe (void **result,
   len = (uint32_t*) ptr;
   *len = htonl (aes_buf_len);
   ptr += 4;
-  memcpy (ptr, aes_buf, aes_buf_len);
+  GNUNET_memcpy (ptr, aes_buf, aes_buf_len);
   ptr += aes_buf_len;
   len = (uint32_t*) ptr;
   *len = htonl (cph_buf_len);
   ptr += 4;
-  memcpy (ptr, cph_buf, cph_buf_len);
+  GNUNET_memcpy (ptr, cph_buf, cph_buf_len);
   return 12 + cph_buf_len + aes_buf_len;
 }
 
@@ -241,13 +243,13 @@ read_cpabe (const void *data,
   *aes_buf_len = ntohl (*len);
   ptr += 4;
   *aes_buf = GNUNET_malloc (*aes_buf_len);
-  memcpy(*aes_buf, ptr, *aes_buf_len);
+  GNUNET_memcpy (*aes_buf, ptr, *aes_buf_len);
   ptr += *aes_buf_len;
   len = (uint32_t*)ptr;
   *cph_buf_len = ntohl (*len);
   ptr += 4;
   *cph_buf = GNUNET_malloc (*cph_buf_len);
-  memcpy(*cph_buf, ptr, *cph_buf_len);
+  GNUNET_memcpy (*cph_buf, ptr, *cph_buf_len);
 
   return buf_len;
 }
@@ -362,7 +364,7 @@ GNUNET_CRYPTO_cpabe_deserialize_key (const void *data,
               &prv_len);
   key->pub = gabe_pub_unserialize (pub, pub_len);
   key->prv = gabe_prv_unserialize (key->pub, prv, prv_len);
-  
+
   GNUNET_free (pub);
   GNUNET_free (prv);
   return key;
@@ -408,7 +410,7 @@ GNUNET_CRYPTO_cpabe_deserialize_master_key (const void *data,
               &msk_len);
   key->pub = gabe_pub_unserialize (pub, pub_len);
   key->msk = gabe_msk_unserialize (key->pub, msk, msk_len);
-  
+
   GNUNET_free (pub);
   GNUNET_free (msk);
 
index 8fd689070aeca4d594f649d86e718fb1653430f2..9e542a91cc1498a908ee5597828c56ba4827f17b 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     Copyright (C) 2001--2013, 2016 GNUnet e.V.
+     Copyright (C) 2001--2013, 2016, 2018 GNUnet e.V.
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -1401,13 +1401,28 @@ GNUNET_DISK_file_copy (const char *src,
   struct GNUNET_DISK_FileHandle *in;
   struct GNUNET_DISK_FileHandle *out;
 
-  if (GNUNET_OK != GNUNET_DISK_file_size (src, &size, GNUNET_YES, GNUNET_YES))
+  if (GNUNET_OK !=
+      GNUNET_DISK_file_size (src,
+                             &size,
+                             GNUNET_YES,
+                             GNUNET_YES))
+  {
+    GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
+                              "stat",
+                              src);
     return GNUNET_SYSERR;
+  }
   pos = 0;
-  in = GNUNET_DISK_file_open (src, GNUNET_DISK_OPEN_READ,
+  in = GNUNET_DISK_file_open (src,
+                              GNUNET_DISK_OPEN_READ,
                               GNUNET_DISK_PERM_NONE);
-  if (!in)
+  if (! in)
+  {
+    GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
+                              "open",
+                              src);
     return GNUNET_SYSERR;
+  }
   out =
       GNUNET_DISK_file_open (dst,
                              GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE |
@@ -1418,6 +1433,9 @@ GNUNET_DISK_file_copy (const char *src,
                              GNUNET_DISK_PERM_GROUP_WRITE);
   if (!out)
   {
+    GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
+                              "open",
+                              dst);
     GNUNET_DISK_file_close (in);
     return GNUNET_SYSERR;
   }
@@ -2641,4 +2659,55 @@ GNUNET_DISK_internal_file_handle_ (const struct GNUNET_DISK_FileHandle *fh,
   return GNUNET_OK;
 }
 
+
+/**
+ * Remove the directory given under @a option in
+ * section [PATHS] in configuration under @a cfg_filename
+ *
+ * @param cfg_filename configuration file to parse
+ * @param option option with the dir name to purge
+ */
+void
+GNUNET_DISK_purge_cfg_dir (const char *cfg_filename,
+                           const char *option)
+{
+  struct GNUNET_CONFIGURATION_Handle *cfg;
+  char *tmpname;
+
+  cfg = GNUNET_CONFIGURATION_create ();
+  if (GNUNET_OK !=
+      GNUNET_CONFIGURATION_load (cfg,
+                                 cfg_filename))
+  {
+    GNUNET_break (0);
+    GNUNET_CONFIGURATION_destroy (cfg);
+    return;
+  }
+  if (GNUNET_OK !=
+      GNUNET_CONFIGURATION_get_value_filename (cfg,
+                                               "PATHS",
+                                               option,
+                                               &tmpname))
+  {
+    GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+                               "PATHS",
+                               option);
+    GNUNET_CONFIGURATION_destroy (cfg);
+    return;
+  }
+  GNUNET_CONFIGURATION_destroy (cfg);
+  if (GNUNET_SYSERR ==
+      GNUNET_DISK_directory_remove (tmpname))
+  {
+    GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
+                              "remove",
+                              tmpname);
+    GNUNET_free (tmpname);
+    return;
+  }
+  GNUNET_free (tmpname);
+}
+
+
+
 /* end of disk.c */
index 1a0e22b66ab3f1bb06a066e44d8e28ce2b4b7e07..cde57fa0a997297694974f6925060198186efac9 100644 (file)
@@ -1 +1,2 @@
 gnunet-service-zonemaster
+gnunet-service-zonemaster-monitor
index 21f98649891bd2a52ef02d121a7765d110f07b81..b655b9ef366ecdf7afa340d08678cdb333df0142 100644 (file)
@@ -1,5 +1,5 @@
 # This Makefile.am is in the public domain
-AM_CPPFLAGS = -I$(top_srcdir)/src/include 
+AM_CPPFLAGS = -I$(top_srcdir)/src/include
 
 plugindir = $(libdir)/gnunet
 
@@ -20,11 +20,11 @@ if USE_COVERAGE
 endif
 
 libexec_PROGRAMS = \
- gnunet-service-zonemaster
+ gnunet-service-zonemaster \
+ gnunet-service-zonemaster-monitor
 
 gnunet_service_zonemaster_SOURCES = \
  gnunet-service-zonemaster.c
-
 gnunet_service_zonemaster_LDADD = \
   $(top_builddir)/src/dht/libgnunetdht.la \
   $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \
@@ -33,3 +33,14 @@ gnunet_service_zonemaster_LDADD = \
   $(top_builddir)/src/namestore/libgnunetnamestore.la \
   $(GN_LIBINTL)
 
+
+gnunet_service_zonemaster_monitor_SOURCES = \
+ gnunet-service-zonemaster-monitor.c
+
+gnunet_service_zonemaster_monitor_LDADD = \
+  $(top_builddir)/src/dht/libgnunetdht.la \
+  $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \
+  $(top_builddir)/src/statistics/libgnunetstatistics.la \
+  $(top_builddir)/src/util/libgnunetutil.la \
+  $(top_builddir)/src/namestore/libgnunetnamestore.la \
+  $(GN_LIBINTL)
diff --git a/src/zonemaster/gnunet-service-zonemaster-monitor.c b/src/zonemaster/gnunet-service-zonemaster-monitor.c
new file mode 100644 (file)
index 0000000..275a3a5
--- /dev/null
@@ -0,0 +1,479 @@
+/*
+     This file is part of GNUnet.
+     Copyright (C) 2012, 2013, 2014, 2017, 2018 GNUnet e.V.
+
+     GNUnet is free software; you can redistribute it and/or modify
+     it under the terms of the GNU General Public License as published
+     by the Free Software Foundation; either version 3, or (at your
+     option) any later version.
+
+     GNUnet is distributed in the hope that it will be useful, but
+     WITHOUT ANY WARRANTY; without even the implied warranty of
+     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+     General Public License for more details.
+
+     You should have received a copy of the GNU General Public License
+     along with GNUnet; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+     Boston, MA 02110-1301, USA.
+*/
+
+/**
+ * @file zonemaster/gnunet-service-zonemaster-monitor.c
+ * @brief monitor namestore changes and publish them immediately to GNUnet name system
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "gnunet_util_lib.h"
+#include "gnunet_dht_service.h"
+#include "gnunet_namestore_service.h"
+#include "gnunet_statistics_service.h"
+
+
+#define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file (kind, "util", syscall, filename)
+
+
+/**
+ * How often should we (re)publish each record before
+ * it expires?
+ */
+#define PUBLISH_OPS_PER_EXPIRATION 4
+
+/**
+ * How many pending DHT operations do we allow at most?
+ */
+#define DHT_QUEUE_LIMIT 2000
+
+/**
+ * How many events may the namestore give us before it has to wait
+ * for us to keep up?
+ */
+#define NAMESTORE_QUEUE_LIMIT 5
+
+/**
+ * What replication level do we use for DHT PUT operations?
+ */
+#define DHT_GNS_REPLICATION_LEVEL 5
+
+
+/**
+ * Handle for DHT PUT activity triggered from the namestore monitor.
+ */
+struct DhtPutActivity
+{
+  /**
+   * Kept in a DLL.
+   */
+  struct DhtPutActivity *next;
+
+  /**
+   * Kept in a DLL.
+   */
+  struct DhtPutActivity *prev;
+
+  /**
+   * Handle for the DHT PUT operation.
+   */
+  struct GNUNET_DHT_PutHandle *ph;
+
+  /**
+   * When was this PUT initiated?
+   */
+  struct GNUNET_TIME_Absolute start_date;
+};
+
+
+/**
+ * Handle to the statistics service
+ */
+static struct GNUNET_STATISTICS_Handle *statistics;
+
+/**
+ * Our handle to the DHT
+ */
+static struct GNUNET_DHT_Handle *dht_handle;
+
+/**
+ * Our handle to the namestore service
+ */
+static struct GNUNET_NAMESTORE_Handle *namestore_handle;
+
+/**
+ * Handle to monitor namestore changes to instant propagation.
+ */
+static struct GNUNET_NAMESTORE_ZoneMonitor *zmon;
+
+/**
+ * Head of monitor activities; kept in a DLL.
+ */
+static struct DhtPutActivity *ma_head;
+
+/**
+ * Tail of monitor activities; kept in a DLL.
+ */
+static struct DhtPutActivity *ma_tail;
+
+/**
+ * Number of entries in the DHT queue #ma_head.
+ */
+static unsigned int ma_queue_length;
+
+/**
+ * Optimize block insertion by caching map of private keys to
+ * public keys in memory?
+ */
+static int cache_keys;
+
+
+/**
+ * Task run during shutdown.
+ *
+ * @param cls unused
+ * @param tc unused
+ */
+static void
+shutdown_task (void *cls)
+{
+  struct DhtPutActivity *ma;
+
+  (void) cls;
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Shutting down!\n");
+  while (NULL != (ma = ma_head))
+  {
+    GNUNET_DHT_put_cancel (ma->ph);
+    ma_queue_length--;
+    GNUNET_CONTAINER_DLL_remove (ma_head,
+                                 ma_tail,
+                                 ma);
+    GNUNET_free (ma);
+  }
+  if (NULL != statistics)
+  {
+    GNUNET_STATISTICS_destroy (statistics,
+                               GNUNET_NO);
+    statistics = NULL;
+  }
+  if (NULL != zmon)
+  {
+    GNUNET_NAMESTORE_zone_monitor_stop (zmon);
+    zmon = NULL;
+  }
+  if (NULL != namestore_handle)
+  {
+    GNUNET_NAMESTORE_disconnect (namestore_handle);
+    namestore_handle = NULL;
+  }
+  if (NULL != dht_handle)
+  {
+    GNUNET_DHT_disconnect (dht_handle);
+    dht_handle = NULL;
+  }
+}
+
+
+/**
+ * Continuation called from DHT once the PUT operation triggered
+ * by a monitor is done.
+ *
+ * @param cls a `struct DhtPutActivity`
+ */
+static void
+dht_put_monitor_continuation (void *cls)
+{
+  struct DhtPutActivity *ma = cls;
+
+  GNUNET_NAMESTORE_zone_monitor_next (zmon,
+                                      1);
+  ma_queue_length--;
+  GNUNET_CONTAINER_DLL_remove (ma_head,
+                               ma_tail,
+                               ma);
+  GNUNET_free (ma);
+}
+
+
+/**
+ * Convert namestore records from the internal format to that
+ * suitable for publication (removes private records, converts
+ * to absolute expiration time).
+ *
+ * @param rd input records
+ * @param rd_count size of the @a rd and @a rd_public arrays
+ * @param rd_public where to write the converted records
+ * @return number of records written to @a rd_public
+ */
+static unsigned int
+convert_records_for_export (const struct GNUNET_GNSRECORD_Data *rd,
+                            unsigned int rd_count,
+                            struct GNUNET_GNSRECORD_Data *rd_public)
+{
+  struct GNUNET_TIME_Absolute now;
+  unsigned int rd_public_count;
+
+  rd_public_count = 0;
+  now = GNUNET_TIME_absolute_get ();
+  for (unsigned int i=0;i<rd_count;i++)
+  {
+    if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_PRIVATE))
+      continue;
+    if ( (0 == (rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION)) &&
+         (rd[i].expiration_time < now.abs_value_us) )
+      continue;  /* record already expired, skip it */
+    rd_public[rd_public_count++] = rd[i];
+  }
+  return rd_public_count;
+}
+
+
+/**
+ * Store GNS records in the DHT.
+ *
+ * @param key key of the zone
+ * @param label label to store under
+ * @param rd_public public record data
+ * @param rd_public_count number of records in @a rd_public
+ * @param ma handle for the PUT operation
+ * @return DHT PUT handle, NULL on error
+ */
+static struct GNUNET_DHT_PutHandle *
+perform_dht_put (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
+                 const char *label,
+                 const struct GNUNET_GNSRECORD_Data *rd_public,
+                 unsigned int rd_public_count,
+                 struct DhtPutActivity *ma)
+{
+  struct GNUNET_GNSRECORD_Block *block;
+  struct GNUNET_HashCode query;
+  struct GNUNET_TIME_Absolute expire;
+  size_t block_size;
+  struct GNUNET_DHT_PutHandle *ret;
+
+  expire = GNUNET_GNSRECORD_record_get_expiration_time (rd_public_count,
+                                                        rd_public);
+  if (cache_keys)
+    block = GNUNET_GNSRECORD_block_create2 (key,
+                                            expire,
+                                            label,
+                                            rd_public,
+                                            rd_public_count);
+  else
+    block = GNUNET_GNSRECORD_block_create (key,
+                                           expire,
+                                           label,
+                                           rd_public,
+                                           rd_public_count);
+  if (NULL == block)
+  {
+    GNUNET_break (0);
+    return NULL; /* whoops */
+  }
+  block_size = ntohl (block->purpose.size)
+    + sizeof (struct GNUNET_CRYPTO_EcdsaSignature)
+    + sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey);
+  GNUNET_GNSRECORD_query_from_private_key (key,
+                                           label,
+                                           &query);
+  GNUNET_STATISTICS_update (statistics,
+                            "DHT put operations initiated",
+                            1,
+                            GNUNET_NO);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Storing %u record(s) for label `%s' in DHT with expiration `%s' under key %s\n",
+              rd_public_count,
+              label,
+              GNUNET_STRINGS_absolute_time_to_string (expire),
+              GNUNET_h2s (&query));
+  ret = GNUNET_DHT_put (dht_handle,
+                        &query,
+                        DHT_GNS_REPLICATION_LEVEL,
+                        GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
+                        GNUNET_BLOCK_TYPE_GNS_NAMERECORD,
+                        block_size,
+                        block,
+                        expire,
+                        &dht_put_monitor_continuation,
+                        ma);
+  GNUNET_free (block);
+  return ret;
+}
+
+
+/**
+ * Process a record that was stored in the namestore
+ * (invoked by the monitor).
+ *
+ * @param cls closure, NULL
+ * @param zone private key of the zone; NULL on disconnect
+ * @param label label of the records; NULL on disconnect
+ * @param rd_count number of entries in @a rd array, 0 if label was deleted
+ * @param rd array of records with data to store
+ */
+static void
+handle_monitor_event (void *cls,
+                      const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
+                      const char *label,
+                      unsigned int rd_count,
+                      const struct GNUNET_GNSRECORD_Data *rd)
+{
+  struct GNUNET_GNSRECORD_Data rd_public[rd_count];
+  unsigned int rd_public_count;
+  struct DhtPutActivity *ma;
+
+  (void) cls;
+  GNUNET_STATISTICS_update (statistics,
+                            "Namestore monitor events received",
+                            1,
+                            GNUNET_NO);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Received %u records for label `%s' via namestore monitor\n",
+              rd_count,
+              label);
+  /* filter out records that are not public, and convert to
+     absolute expiration time. */
+  rd_public_count = convert_records_for_export (rd,
+                                                rd_count,
+                                                rd_public);
+  if (0 == rd_public_count)
+  {
+    GNUNET_NAMESTORE_zone_monitor_next (zmon,
+                                        1);
+    return; /* nothing to do */
+  }
+  ma = GNUNET_new (struct DhtPutActivity);
+  ma->start_date = GNUNET_TIME_absolute_get ();
+  ma->ph = perform_dht_put (zone,
+                            label,
+                            rd,
+                            rd_count,
+                            ma);
+  if (NULL == ma->ph)
+  {
+    /* PUT failed, do not remember operation */
+    GNUNET_free (ma);
+    GNUNET_NAMESTORE_zone_monitor_next (zmon,
+                                        1);
+    return;
+  }
+  GNUNET_CONTAINER_DLL_insert_tail (ma_head,
+                                   ma_tail,
+                                   ma);
+  ma_queue_length++;
+  if (ma_queue_length > DHT_QUEUE_LIMIT)
+  {
+    ma = ma_head;
+    GNUNET_CONTAINER_DLL_remove (ma_head,
+                                 ma_tail,
+                                 ma);
+    GNUNET_DHT_put_cancel (ma->ph);
+    ma_queue_length--;
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                "DHT PUT unconfirmed after %s, aborting PUT\n",
+                GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (ma->start_date),
+                                                        GNUNET_YES));
+    GNUNET_free (ma);
+  }
+}
+
+
+/**
+ * The zone monitor encountered an IPC error trying to to get in
+ * sync. Restart from the beginning.
+ *
+ * @param cls NULL
+ */
+static void
+handle_monitor_error (void *cls)
+{
+  (void) cls;
+  GNUNET_STATISTICS_update (statistics,
+                            "Namestore monitor errors encountered",
+                            1,
+                            GNUNET_NO);
+}
+
+
+/**
+ * Performe zonemaster duties: watch namestore, publish records.
+ *
+ * @param cls closure
+ * @param server the initialized server
+ * @param c configuration to use
+ */
+static void
+run (void *cls,
+     const struct GNUNET_CONFIGURATION_Handle *c,
+     struct GNUNET_SERVICE_Handle *service)
+{
+  unsigned long long max_parallel_bg_queries = 128;
+
+  (void) cls;
+  (void) service;
+  namestore_handle = GNUNET_NAMESTORE_connect (c);
+  if (NULL == namestore_handle)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                _("Failed to connect to the namestore!\n"));
+    GNUNET_SCHEDULER_shutdown ();
+    return;
+  }
+  cache_keys = GNUNET_CONFIGURATION_get_value_yesno (c,
+                                                     "namestore",
+                                                     "CACHE_KEYS");
+  if (GNUNET_OK ==
+      GNUNET_CONFIGURATION_get_value_number (c,
+                                            "zonemaster",
+                                             "MAX_PARALLEL_BACKGROUND_QUERIES",
+                                             &max_parallel_bg_queries))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "Number of allowed parallel background queries: %llu\n",
+                max_parallel_bg_queries);
+  }
+  if (0 == max_parallel_bg_queries)
+    max_parallel_bg_queries = 1;
+  dht_handle = GNUNET_DHT_connect (c,
+                                   (unsigned int) max_parallel_bg_queries);
+  if (NULL == dht_handle)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                _("Could not connect to DHT!\n"));
+    GNUNET_SCHEDULER_add_now (&shutdown_task,
+                             NULL);
+    return;
+  }
+
+  /* Schedule periodic put for our records. */
+  statistics = GNUNET_STATISTICS_create ("zonemaster-mon",
+                                         c);
+  zmon = GNUNET_NAMESTORE_zone_monitor_start (c,
+                                              NULL,
+                                              GNUNET_NO,
+                                              &handle_monitor_error,
+                                              NULL,
+                                              &handle_monitor_event,
+                                              NULL,
+                                              NULL /* sync_cb */,
+                                              NULL);
+  GNUNET_NAMESTORE_zone_monitor_next (zmon,
+                                      NAMESTORE_QUEUE_LIMIT - 1);
+  GNUNET_break (NULL != zmon);
+  GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+                                NULL);
+}
+
+
+/**
+ * Define "main" method using service macro.
+ */
+GNUNET_SERVICE_MAIN
+("zonemaster-monitor",
+ GNUNET_SERVICE_OPTION_NONE,
+ &run,
+ NULL,
+ NULL,
+ NULL,
+ GNUNET_MQ_handler_end());
+
+
+/* end of gnunet-service-zonemaster-monitor.c */
index 8220e6eab4448c3196744a31cb55507f64da1022..81d6fa2d967667d048849d6dd0b712404d3d6a15 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     Copyright (C) 2012, 2013, 2014, 2017 GNUnet e.V.
+     Copyright (C) 2012, 2013, 2014, 2017, 2018 GNUnet e.V.
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -29,8 +29,6 @@
 #include "gnunet_dht_service.h"
 #include "gnunet_namestore_service.h"
 #include "gnunet_statistics_service.h"
-#include "gnunet_namestore_plugin.h"
-#include "gnunet_signatures.h"
 
 
 #define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file (kind, "util", syscall, filename)
  */
 #define MAXIMUM_ZONE_ITERATION_INTERVAL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)
 
-/**
- * The default put interval for the zone iteration. In case
- * no option is found
- */
-#define DEFAULT_ZONE_PUBLISH_TIME_WINDOW GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 4)
-
 /**
  * The factor the current zone iteration interval is divided by for each
  * additional new record
  */
 #define LATE_ITERATION_SPEEDUP_FACTOR 2
 
-/**
- * How long until a DHT PUT attempt should time out?
- */
-#define DHT_OPERATION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
-
 /**
  * What replication level do we use for DHT PUT operations?
  */
@@ -147,21 +134,6 @@ static struct GNUNET_NAMESTORE_Handle *namestore_handle;
  */
 static struct GNUNET_NAMESTORE_ZoneIterator *namestore_iter;
 
-/**
- * Handle to monitor namestore changes to instant propagation.
- */
-static struct GNUNET_NAMESTORE_ZoneMonitor *zmon;
-
-/**
- * Head of monitor activities; kept in a DLL.
- */
-static struct DhtPutActivity *ma_head;
-
-/**
- * Tail of monitor activities; kept in a DLL.
- */
-static struct DhtPutActivity *ma_tail;
-
 /**
  * Head of iteration put activities; kept in a DLL.
  */
@@ -177,11 +149,6 @@ static struct DhtPutActivity *it_tail;
  */
 static unsigned int dht_queue_length;
 
-/**
- * Number of entries in the DHT queue #ma_head.
- */
-static unsigned int ma_queue_length;
-
 /**
  * Useful for zone update for DHT put
  */
@@ -281,15 +248,6 @@ shutdown_task (void *cls)
   (void) cls;
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Shutting down!\n");
-  while (NULL != (ma = ma_head))
-  {
-    GNUNET_DHT_put_cancel (ma->ph);
-    ma_queue_length--;
-    GNUNET_CONTAINER_DLL_remove (ma_head,
-                                 ma_tail,
-                                 ma);
-    GNUNET_free (ma);
-  }
   while (NULL != (ma = it_head))
   {
     GNUNET_DHT_put_cancel (ma->ph);
@@ -316,11 +274,6 @@ shutdown_task (void *cls)
     GNUNET_NAMESTORE_zone_iteration_stop (namestore_iter);
     namestore_iter = NULL;
   }
-  if (NULL != zmon)
-  {
-    GNUNET_NAMESTORE_zone_monitor_stop (zmon);
-    zmon = NULL;
-  }
   if (NULL != namestore_handle)
   {
     GNUNET_NAMESTORE_disconnect (namestore_handle);
@@ -361,27 +314,6 @@ static void
 publish_zone_dht_start (void *cls);
 
 
-/**
- * Continuation called from DHT once the PUT operation triggered
- * by a monitor is done.
- *
- * @param cls a `struct DhtPutActivity`
- */
-static void
-dht_put_monitor_continuation (void *cls)
-{
-  struct DhtPutActivity *ma = cls;
-
-  GNUNET_NAMESTORE_zone_monitor_next (zmon,
-                                      1);
-  ma_queue_length--;
-  GNUNET_CONTAINER_DLL_remove (ma_head,
-                               ma_tail,
-                               ma);
-  GNUNET_free (ma);
-}
-
-
 /**
  * Calculate #target_iteration_velocity_per_record.
  */
@@ -520,10 +452,6 @@ update_velocity (unsigned int cnt)
                          "# size of the DHT queue (it)",
                          dht_queue_length,
                          GNUNET_NO);
-  GNUNET_STATISTICS_set (statistics,
-                         "# size of the DHT queue (mon)",
-                         ma_queue_length,
-                         GNUNET_NO);
   GNUNET_STATISTICS_set (statistics,
                          "% speed increase needed for target velocity",
                          pct,
@@ -558,6 +486,12 @@ check_zone_namestore_next ()
                          GNUNET_NO);
   delay = GNUNET_TIME_relative_multiply (delay,
                                          NS_BLOCK_SIZE);
+  /* make sure we do not overshoot because of the #NS_BLOCK_SIZE factor */
+  delay = GNUNET_TIME_relative_min (MAXIMUM_ZONE_ITERATION_INTERVAL,
+                                    delay);
+  /* no delays on first iteration */
+  if (GNUNET_YES == first_zone_iteration)
+    delay = GNUNET_TIME_UNIT_ZERO;
   GNUNET_assert (NULL == zone_publish_task);
   zone_publish_task = GNUNET_SCHEDULER_add_delayed (delay,
                                                     &publish_zone_namestore_next,
@@ -606,24 +540,22 @@ convert_records_for_export (const struct GNUNET_GNSRECORD_Data *rd,
   rd_public_count = 0;
   now = GNUNET_TIME_absolute_get ();
   for (unsigned int i=0;i<rd_count;i++)
-    if (0 == (rd[i].flags & GNUNET_GNSRECORD_RF_PRIVATE))
+  {
+    if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_PRIVATE))
+      continue;
+    if ( (0 == (rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION)) &&
+         (rd[i].expiration_time < now.abs_value_us) )
+      continue;  /* record already expired, skip it */
+    if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION))
     {
-      rd_public[rd_public_count] = rd[i];
-      if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION))
-      {
-        /* GNUNET_GNSRECORD_block_create will convert to absolute time;
-           we just need to adjust our iteration frequency */
-        min_relative_record_time.rel_value_us =
-          GNUNET_MIN (rd_public[rd_public_count].expiration_time,
-                      min_relative_record_time.rel_value_us);
-      }
-      else if (rd_public[rd_public_count].expiration_time < now.abs_value_us)
-      {
-        /* record already expired, skip it */
-        continue;
-      }
-      rd_public_count++;
+      /* GNUNET_GNSRECORD_block_create will convert to absolute time;
+         we just need to adjust our iteration frequency */
+      min_relative_record_time.rel_value_us =
+        GNUNET_MIN (rd[i].expiration_time,
+                    min_relative_record_time.rel_value_us);
     }
+    rd_public[rd_public_count++] = rd[i];
+  }
   return rd_public_count;
 }
 
@@ -635,8 +567,7 @@ convert_records_for_export (const struct GNUNET_GNSRECORD_Data *rd,
  * @param label label to store under
  * @param rd_public public record data
  * @param rd_public_count number of records in @a rd_public
- * @param cont function to call with PUT result
- * @param cont_cls closure for @a cont
+ * @param ma handle for the put operation
  * @return DHT PUT handle, NULL on error
  */
 static struct GNUNET_DHT_PutHandle *
@@ -644,8 +575,7 @@ perform_dht_put (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
                  const char *label,
                  const struct GNUNET_GNSRECORD_Data *rd_public,
                  unsigned int rd_public_count,
-                 GNUNET_SCHEDULER_TaskCallback cont,
-                 void *cont_cls)
+                 struct DhtPutActivity *ma)
 {
   struct GNUNET_GNSRECORD_Block *block;
   struct GNUNET_HashCode query;
@@ -697,8 +627,8 @@ perform_dht_put (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
                         block_size,
                         block,
                         expire,
-                        cont,
-                        cont_cls);
+                        &dht_put_continuation,
+                        ma);
   GNUNET_free (block);
   return ret;
 }
@@ -746,8 +676,7 @@ zone_iteration_finished (void *cls)
   calculate_put_interval ();
   /* reset for next iteration */
   min_relative_record_time
-    = GNUNET_TIME_relative_multiply (GNUNET_DHT_DEFAULT_REPUBLISH_FREQUENCY,
-                                    PUBLISH_OPS_PER_EXPIRATION);
+    = GNUNET_TIME_UNIT_FOREVER_REL;
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Zone iteration finished. Adjusted zone iteration interval to %s\n",
               GNUNET_STRINGS_relative_time_to_string (target_iteration_velocity_per_record,
@@ -816,7 +745,6 @@ put_gns_record (void *cls,
                             label,
                             rd_public,
                             rd_public_count,
-                            &dht_put_continuation,
                             ma);
   put_cnt++;
   if (0 == put_cnt % DELTA_INTERVAL)
@@ -883,131 +811,6 @@ publish_zone_dht_start (void *cls)
 }
 
 
-/**
- * Process a record that was stored in the namestore
- * (invoked by the monitor).
- *
- * @param cls closure, NULL
- * @param zone private key of the zone; NULL on disconnect
- * @param label label of the records; NULL on disconnect
- * @param rd_count number of entries in @a rd array, 0 if label was deleted
- * @param rd array of records with data to store
- */
-static void
-handle_monitor_event (void *cls,
-                      const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
-                      const char *label,
-                      unsigned int rd_count,
-                      const struct GNUNET_GNSRECORD_Data *rd)
-{
-  struct GNUNET_GNSRECORD_Data rd_public[rd_count];
-  unsigned int rd_public_count;
-  struct DhtPutActivity *ma;
-
-  (void) cls;
-  GNUNET_STATISTICS_update (statistics,
-                            "Namestore monitor events received",
-                            1,
-                            GNUNET_NO);
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Received %u records for label `%s' via namestore monitor\n",
-              rd_count,
-              label);
-  /* filter out records that are not public, and convert to
-     absolute expiration time. */
-  rd_public_count = convert_records_for_export (rd,
-                                                rd_count,
-                                                rd_public);
-  if (0 == rd_public_count)
-  {
-    GNUNET_NAMESTORE_zone_monitor_next (zmon,
-                                        1);
-    return; /* nothing to do */
-  }
-  num_public_records++;
-  ma = GNUNET_new (struct DhtPutActivity);
-  ma->start_date = GNUNET_TIME_absolute_get ();
-  ma->ph = perform_dht_put (zone,
-                            label,
-                            rd,
-                            rd_count,
-                            &dht_put_monitor_continuation,
-                            ma);
-  if (NULL == ma->ph)
-  {
-    /* PUT failed, do not remember operation */
-    GNUNET_free (ma);
-    GNUNET_NAMESTORE_zone_monitor_next (zmon,
-                                        1);
-    return;
-  }
-  GNUNET_CONTAINER_DLL_insert_tail (ma_head,
-                                   ma_tail,
-                                   ma);
-  ma_queue_length++;
-  if (ma_queue_length > DHT_QUEUE_LIMIT)
-  {
-    ma = ma_head;
-    GNUNET_CONTAINER_DLL_remove (ma_head,
-                                 ma_tail,
-                                 ma);
-    GNUNET_DHT_put_cancel (ma->ph);
-    ma_queue_length--;
-    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                "DHT PUT unconfirmed after %s, aborting PUT\n",
-                GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (ma->start_date),
-                                                        GNUNET_YES));
-    GNUNET_free (ma);
-  }
-}
-
-
-/**
- * The zone monitor is now in SYNC with the current state of the
- * name store.  Start to perform periodic iterations.
- *
- * @param cls NULL
- */
-static void
-monitor_sync_event (void *cls)
-{
-  (void) cls;
-  if ( (NULL == zone_publish_task) &&
-       (NULL == namestore_iter) )
-    zone_publish_task = GNUNET_SCHEDULER_add_now (&publish_zone_dht_start,
-                                                  NULL);
-}
-
-
-/**
- * The zone monitor encountered an IPC error trying to to get in
- * sync. Restart from the beginning.
- *
- * @param cls NULL
- */
-static void
-handle_monitor_error (void *cls)
-{
-  (void) cls;
-  GNUNET_STATISTICS_update (statistics,
-                            "Namestore monitor errors encountered",
-                            1,
-                            GNUNET_NO);
-  if (NULL != zone_publish_task)
-  {
-    GNUNET_SCHEDULER_cancel (zone_publish_task);
-    zone_publish_task = NULL;
-  }
-  if (NULL != namestore_iter)
-  {
-    GNUNET_NAMESTORE_zone_iteration_stop (namestore_iter);
-    namestore_iter = NULL;
-  }
-  zone_publish_task = GNUNET_SCHEDULER_add_now (&publish_zone_dht_start,
-                                                NULL);
-}
-
-
 /**
  * Performe zonemaster duties: watch namestore, publish records.
  *
@@ -1026,8 +829,7 @@ run (void *cls,
   (void) service;
   last_put_100 = GNUNET_TIME_absolute_get (); /* first time! */
   min_relative_record_time
-    = GNUNET_TIME_relative_multiply (GNUNET_DHT_DEFAULT_REPUBLISH_FREQUENCY,
-                                    PUBLISH_OPS_PER_EXPIRATION);
+    = GNUNET_TIME_UNIT_FOREVER_REL;
   target_iteration_velocity_per_record = INITIAL_ZONE_ITERATION_INTERVAL;
   namestore_handle = GNUNET_NAMESTORE_connect (c);
   if (NULL == namestore_handle)
@@ -1040,7 +842,7 @@ run (void *cls,
   cache_keys = GNUNET_CONFIGURATION_get_value_yesno (c,
                                                      "namestore",
                                                      "CACHE_KEYS");
-  zone_publish_time_window_default = DEFAULT_ZONE_PUBLISH_TIME_WINDOW;
+  zone_publish_time_window_default = GNUNET_DHT_DEFAULT_REPUBLISH_FREQUENCY;
   if (GNUNET_OK ==
       GNUNET_CONFIGURATION_get_value_time (c,
                                           "zonemaster",
@@ -1084,18 +886,8 @@ run (void *cls,
                          "Target zone iteration velocity (μs)",
                          target_iteration_velocity_per_record.rel_value_us,
                          GNUNET_NO);
-  zmon = GNUNET_NAMESTORE_zone_monitor_start (c,
-                                              NULL,
-                                              GNUNET_NO,
-                                              &handle_monitor_error,
-                                              NULL,
-                                              &handle_monitor_event,
-                                              NULL,
-                                              &monitor_sync_event,
-                                              NULL);
-  GNUNET_NAMESTORE_zone_monitor_next (zmon,
-                                      NAMESTORE_QUEUE_LIMIT - 1);
-  GNUNET_break (NULL != zmon);
+  zone_publish_task = GNUNET_SCHEDULER_add_now (&publish_zone_dht_start,
+                                                NULL);
   GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
                                 NULL);
 }
index 871eb9c8fe015cb92b6f9fdbf3fc98d0d8fb132e..6179b87be2b9cdba593a4a1959ddf00a59749293 100644 (file)
@@ -23,3 +23,20 @@ ZONE_PUBLISH_TIME_WINDOW = 4 h
 # USE_CACHE = YES
 
 # PREFIX = valgrind --leak-check=full --track-origins=yes
+
+
+
+[zonemaster-monitor]
+AUTOSTART = @AUTOSTART@
+FORCESTART = YES
+HOSTNAME = localhost
+BINARY = gnunet-service-zonemaster-monitor
+UNIXPATH = $GNUNET_USER_RUNTIME_DIR/gnunet-service-zonemaster-monitor.sock
+@JAVAPORT@PORT = 2124
+
+# Do we require users that want to access GNS to run this process
+# (usually not a good idea)
+UNIX_MATCH_UID = NO
+
+# Do we require users that want to access GNS to be in the 'gnunet' group?
+UNIX_MATCH_GID = NO