aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNils Gillmann <ng0@n0.is>2018-05-14 07:11:13 +0000
committerNils Gillmann <ng0@n0.is>2018-05-14 07:11:13 +0000
commit7e1a12e25b39cbd78569547054f576c1bce478b2 (patch)
tree050410119b7a70d5615e3f33db81f65b94a22030 /src
parentf1c528c2196d1bf1cc3a662a157ee0a0ffc15fbb (diff)
parent3eca7d41eafd7d2f3bf000c6df221e913fe6ff23 (diff)
downloadgnunet-7e1a12e25b39cbd78569547054f576c1bce478b2.tar.gz
gnunet-7e1a12e25b39cbd78569547054f576c1bce478b2.zip
Merge branch 'master' of gnunet.org:gnunet
Diffstat (limited to 'src')
-rw-r--r--src/abe/abe.c26
-rw-r--r--src/credential/gnunet-service-credential.c48
-rw-r--r--src/credential/plugin_gnsrecord_credential.c10
-rw-r--r--src/credential/plugin_rest_credential.c36
-rw-r--r--src/dns/Makefile.am8
-rw-r--r--src/dns/dnsparser.c8
-rw-r--r--src/dns/dnsstub.c17
-rw-r--r--src/dns/gnunet-zonewalk.c (renamed from src/dns/gnunet-zoneimport.c)0
-rw-r--r--src/fs/gnunet-service-fs_indexing.c6
-rw-r--r--src/gns/.gitignore1
-rw-r--r--src/gns/Makefile.am13
-rw-r--r--src/gns/gns.conf.in2
-rw-r--r--src/gns/gns_api.c4
-rw-r--r--src/gns/gnunet-gns-benchmark.c587
-rw-r--r--src/gns/gnunet-service-gns_resolver.c59
-rw-r--r--src/gns/plugin_gnsrecord_gns.c12
-rwxr-xr-xsrc/gns/test_gns_at_lookup.sh (renamed from src/gns/test_gns_plus_lookup.sh)8
-rwxr-xr-xsrc/gns/test_gns_cname_lookup.sh4
-rwxr-xr-xsrc/gns/test_gns_delegated_lookup.sh4
-rwxr-xr-xsrc/gns/test_gns_dht_lookup.sh4
-rwxr-xr-xsrc/gns/test_gns_gns2dns_lookup.sh4
-rwxr-xr-xsrc/gns/test_gns_ipv6_lookup.sh2
-rwxr-xr-xsrc/gns/test_gns_mx_lookup.sh4
-rwxr-xr-xsrc/gns/test_gns_quickupdate.sh4
-rwxr-xr-xsrc/gns/test_gns_rel_expiration.sh4
-rwxr-xr-xsrc/gns/test_gns_revocation.sh4
-rwxr-xr-xsrc/gns/test_gns_soa_lookup.sh4
-rwxr-xr-xsrc/gns/test_gns_txt_lookup.sh4
-rwxr-xr-xsrc/gns/test_gns_zkey_lookup.sh4
-rw-r--r--src/gnsrecord/.gitignore1
-rw-r--r--src/gnsrecord/Makefile.am10
-rw-r--r--src/gnsrecord/gnsrecord.c15
-rw-r--r--src/gnsrecord/gnsrecord_crypto.c29
-rw-r--r--src/gnsrecord/gnsrecord_serialization.c55
-rw-r--r--src/gnsrecord/perf_gnsrecord_crypto.c137
-rw-r--r--src/gnsrecord/test_gnsrecord_crypto.c6
-rw-r--r--src/hostlist/test_gnunet_daemon_hostlist.c18
-rw-r--r--src/hostlist/test_gnunet_daemon_hostlist_learning.c12
-rw-r--r--src/hostlist/test_gnunet_daemon_hostlist_reconnect.c18
-rw-r--r--src/identity-provider/identity_provider_api.c12
-rw-r--r--src/include/gnunet_disk_lib.h12
-rw-r--r--src/include/gnunet_sq_lib.h119
-rw-r--r--src/multicast/test_multicast_2peers.c5
-rw-r--r--src/multicast/test_multicast_multipeer.c90
-rw-r--r--src/namestore/gnunet-namestore.c81
-rw-r--r--src/namestore/gnunet-service-namestore.c608
-rw-r--r--src/namestore/gnunet-zoneimport.c92
-rw-r--r--src/namestore/namestore_api.c49
-rw-r--r--src/namestore/perf_namestore_api_flat.conf3
-rw-r--r--src/namestore/perf_namestore_api_postgres.conf4
-rw-r--r--src/namestore/perf_namestore_api_sqlite.conf3
-rw-r--r--src/namestore/perf_namestore_api_zone_iteration.c18
-rw-r--r--src/namestore/plugin_namestore_flat.c96
-rw-r--r--src/namestore/plugin_namestore_sqlite.c260
-rw-r--r--src/namestore/test_namestore_api.conf7
-rw-r--r--src/namestore/test_namestore_api_flat.conf3
-rw-r--r--src/namestore/test_namestore_api_lookup_nick.c37
-rw-r--r--src/namestore/test_namestore_api_lookup_private.c52
-rw-r--r--src/namestore/test_namestore_api_lookup_public.c31
-rw-r--r--src/namestore/test_namestore_api_lookup_shadow.c40
-rw-r--r--src/namestore/test_namestore_api_lookup_shadow_filter.c34
-rw-r--r--src/namestore/test_namestore_api_monitoring.c65
-rw-r--r--src/namestore/test_namestore_api_monitoring_existing.c148
-rw-r--r--src/namestore/test_namestore_api_postgres.conf5
-rw-r--r--src/namestore/test_namestore_api_remove.c42
-rw-r--r--src/namestore/test_namestore_api_remove_not_existing_record.c37
-rw-r--r--src/namestore/test_namestore_api_sqlite.conf3
-rw-r--r--src/namestore/test_namestore_api_store.c33
-rw-r--r--src/namestore/test_namestore_api_store_update.c175
-rw-r--r--src/namestore/test_namestore_api_zone_iteration.c200
-rw-r--r--src/namestore/test_namestore_api_zone_iteration_nick.c57
-rw-r--r--src/namestore/test_namestore_api_zone_iteration_specific_zone.c161
-rw-r--r--src/namestore/test_namestore_api_zone_iteration_stop.c22
-rw-r--r--src/namestore/test_namestore_api_zone_to_name.c34
-rw-r--r--src/namestore/test_plugin_namestore.c4
-rw-r--r--src/namestore/test_plugin_namestore_flat.conf5
-rw-r--r--src/nat/gnunet-helper-nat-client.c54
-rw-r--r--src/nat/gnunet-helper-nat-server.c43
-rw-r--r--src/nat/gnunet-service-nat.c8
-rw-r--r--src/regex/regex_test_lib.c10
-rw-r--r--src/rps/test_rps.c8
-rw-r--r--src/sq/Makefile.am4
-rw-r--r--src/sq/sq_exec.c109
-rw-r--r--src/sq/sq_prepare.c81
-rw-r--r--src/statistics/test_gnunet_statistics.py.in6
-rw-r--r--src/statistics/test_statistics_api_data.conf2
-rw-r--r--src/transport/test_plugin_transport.c81
-rw-r--r--src/util/crypto_abe.c28
-rw-r--r--src/util/disk.c77
-rw-r--r--src/zonemaster/.gitignore1
-rw-r--r--src/zonemaster/Makefile.am17
-rw-r--r--src/zonemaster/gnunet-service-zonemaster-monitor.c479
-rw-r--r--src/zonemaster/gnunet-service-zonemaster.c268
-rw-r--r--src/zonemaster/zonemaster.conf.in17
94 files changed, 3437 insertions, 1695 deletions
diff --git a/src/abe/abe.c b/src/abe/abe.c
index 3f1f6dc5b..8b59953fb 100644
--- a/src/abe/abe.c
+++ b/src/abe/abe.c
@@ -54,12 +54,12 @@ init_aes( element_t k, int enc,
54 int rc; 54 int rc;
55 int key_len; 55 int key_len;
56 unsigned char* key_buf; 56 unsigned char* key_buf;
57 57
58 key_len = element_length_in_bytes(k) < 33 ? 3 : element_length_in_bytes(k); 58 key_len = element_length_in_bytes(k) < 33 ? 3 : element_length_in_bytes(k);
59 key_buf = (unsigned char*) malloc(key_len); 59 key_buf = (unsigned char*) malloc(key_len);
60 element_to_bytes(key_buf, k); 60 element_to_bytes(key_buf, k);
61 61
62 memcpy (key->aes_key, key_buf, GNUNET_CRYPTO_AES_KEY_LENGTH); 62 GNUNET_memcpy (key->aes_key, key_buf, GNUNET_CRYPTO_AES_KEY_LENGTH);
63 GNUNET_assert (0 == 63 GNUNET_assert (0 ==
64 gcry_cipher_open (handle, GCRY_CIPHER_AES256, 64 gcry_cipher_open (handle, GCRY_CIPHER_AES256,
65 GCRY_CIPHER_MODE_CFB, 0)); 65 GCRY_CIPHER_MODE_CFB, 0));
@@ -124,16 +124,16 @@ aes_128_cbc_decrypt( char* ct,
124 unsigned char iv[16]; 124 unsigned char iv[16];
125 char* tmp; 125 char* tmp;
126 uint32_t len; 126 uint32_t len;
127 127
128 init_aes(k, 1, &handle, &skey, iv); 128 init_aes(k, 1, &handle, &skey, iv);
129 129
130 tmp = GNUNET_malloc (size); 130 tmp = GNUNET_malloc (size);
131 131
132 //AES_cbc_encrypt(ct->data, pt->data, ct->len, &key, iv, AES_DECRYPT); 132 //AES_cbc_encrypt(ct->data, pt->data, ct->len, &key, iv, AES_DECRYPT);
133 GNUNET_assert (0 == gcry_cipher_decrypt (handle, tmp, size, ct, size)); 133 GNUNET_assert (0 == gcry_cipher_decrypt (handle, tmp, size, ct, size));
134 gcry_cipher_close (handle); 134 gcry_cipher_close (handle);
135 /* TODO make less crufty */ 135 /* TODO make less crufty */
136 136
137 /* get real length */ 137 /* get real length */
138 len = 0; 138 len = 0;
139 len = len 139 len = len
@@ -195,7 +195,7 @@ GNUNET_ABE_cpabe_create_key (struct GNUNET_ABE_AbeMasterKey *key,
195 struct GNUNET_ABE_AbeKey *prv_key; 195 struct GNUNET_ABE_AbeKey *prv_key;
196 int size; 196 int size;
197 char *tmp; 197 char *tmp;
198 198
199 prv_key = GNUNET_new (struct GNUNET_ABE_AbeKey); 199 prv_key = GNUNET_new (struct GNUNET_ABE_AbeKey);
200 prv_key->prv = gabe_keygen(key->pub, key->msk, attrs); 200 prv_key->prv = gabe_keygen(key->pub, key->msk, attrs);
201 size = gabe_pub_serialize(key->pub, &tmp); 201 size = gabe_pub_serialize(key->pub, &tmp);
@@ -234,7 +234,7 @@ write_cpabe (void **result,
234{ 234{
235 char *ptr; 235 char *ptr;
236 uint32_t *len; 236 uint32_t *len;
237 237
238 *result = GNUNET_malloc (12 + cph_buf_len + aes_buf_len); 238 *result = GNUNET_malloc (12 + cph_buf_len + aes_buf_len);
239 ptr = *result; 239 ptr = *result;
240 len = (uint32_t*) ptr; 240 len = (uint32_t*) ptr;
@@ -243,12 +243,12 @@ write_cpabe (void **result,
243 len = (uint32_t*) ptr; 243 len = (uint32_t*) ptr;
244 *len = htonl (aes_buf_len); 244 *len = htonl (aes_buf_len);
245 ptr += 4; 245 ptr += 4;
246 memcpy (ptr, aes_buf, aes_buf_len); 246 GNUNET_memcpy (ptr, aes_buf, aes_buf_len);
247 ptr += aes_buf_len; 247 ptr += aes_buf_len;
248 len = (uint32_t*) ptr; 248 len = (uint32_t*) ptr;
249 *len = htonl (cph_buf_len); 249 *len = htonl (cph_buf_len);
250 ptr += 4; 250 ptr += 4;
251 memcpy (ptr, cph_buf, cph_buf_len); 251 GNUNET_memcpy (ptr, cph_buf, cph_buf_len);
252 return 12 + cph_buf_len + aes_buf_len; 252 return 12 + cph_buf_len + aes_buf_len;
253} 253}
254 254
@@ -271,13 +271,13 @@ read_cpabe (const void *data,
271 *aes_buf_len = ntohl (*len); 271 *aes_buf_len = ntohl (*len);
272 ptr += 4; 272 ptr += 4;
273 *aes_buf = GNUNET_malloc (*aes_buf_len); 273 *aes_buf = GNUNET_malloc (*aes_buf_len);
274 memcpy(*aes_buf, ptr, *aes_buf_len); 274 GNUNET_memcpy(*aes_buf, ptr, *aes_buf_len);
275 ptr += *aes_buf_len; 275 ptr += *aes_buf_len;
276 len = (uint32_t*)ptr; 276 len = (uint32_t*)ptr;
277 *cph_buf_len = ntohl (*len); 277 *cph_buf_len = ntohl (*len);
278 ptr += 4; 278 ptr += 4;
279 *cph_buf = GNUNET_malloc (*cph_buf_len); 279 *cph_buf = GNUNET_malloc (*cph_buf_len);
280 memcpy(*cph_buf, ptr, *cph_buf_len); 280 GNUNET_memcpy(*cph_buf, ptr, *cph_buf_len);
281 281
282 return buf_len; 282 return buf_len;
283} 283}
@@ -429,7 +429,7 @@ GNUNET_ABE_cpabe_deserialize_key (const void *data,
429 &prv_len); 429 &prv_len);
430 key->pub = gabe_pub_unserialize (pub, pub_len); 430 key->pub = gabe_pub_unserialize (pub, pub_len);
431 key->prv = gabe_prv_unserialize (key->pub, prv, prv_len); 431 key->prv = gabe_prv_unserialize (key->pub, prv, prv_len);
432 432
433 GNUNET_free (pub); 433 GNUNET_free (pub);
434 GNUNET_free (prv); 434 GNUNET_free (prv);
435 return key; 435 return key;
@@ -491,7 +491,7 @@ GNUNET_ABE_cpabe_deserialize_master_key (const void *data,
491 &msk_len); 491 &msk_len);
492 key->pub = gabe_pub_unserialize (pub, pub_len); 492 key->pub = gabe_pub_unserialize (pub, pub_len);
493 key->msk = gabe_msk_unserialize (key->pub, msk, msk_len); 493 key->msk = gabe_msk_unserialize (key->pub, msk, msk_len);
494 494
495 GNUNET_free (pub); 495 GNUNET_free (pub);
496 GNUNET_free (msk); 496 GNUNET_free (msk);
497 497
diff --git a/src/credential/gnunet-service-credential.c b/src/credential/gnunet-service-credential.c
index 399371a2e..29bdf63d8 100644
--- a/src/credential/gnunet-service-credential.c
+++ b/src/credential/gnunet-service-credential.c
@@ -61,17 +61,17 @@ struct DelegationChainEntry
61 * The issuer 61 * The issuer
62 */ 62 */
63 struct GNUNET_CRYPTO_EcdsaPublicKey issuer_key; 63 struct GNUNET_CRYPTO_EcdsaPublicKey issuer_key;
64 64
65 /** 65 /**
66 * The subject 66 * The subject
67 */ 67 */
68 struct GNUNET_CRYPTO_EcdsaPublicKey subject_key; 68 struct GNUNET_CRYPTO_EcdsaPublicKey subject_key;
69 69
70 /** 70 /**
71 * The issued attribute 71 * The issued attribute
72 */ 72 */
73 char *issuer_attribute; 73 char *issuer_attribute;
74 74
75 /** 75 /**
76 * The delegated attribute 76 * The delegated attribute
77 */ 77 */
@@ -92,7 +92,7 @@ struct CredentialRecordEntry
92 * DLL 92 * DLL
93 */ 93 */
94 struct CredentialRecordEntry *prev; 94 struct CredentialRecordEntry *prev;
95 95
96 /** 96 /**
97 * Number of references in delegation chains 97 * Number of references in delegation chains
98 */ 98 */
@@ -409,7 +409,7 @@ cleanup_handle (struct VerifyRequestHandle *vrh)
409 } 409 }
410 cleanup_delegation_set (vrh->root_set); 410 cleanup_delegation_set (vrh->root_set);
411 GNUNET_free_non_null (vrh->issuer_attribute); 411 GNUNET_free_non_null (vrh->issuer_attribute);
412 for (cr_entry = vrh->cred_chain_head; 412 for (cr_entry = vrh->cred_chain_head;
413 NULL != vrh->cred_chain_head; 413 NULL != vrh->cred_chain_head;
414 cr_entry = vrh->cred_chain_head) 414 cr_entry = vrh->cred_chain_head)
415 { 415 {
@@ -543,7 +543,7 @@ send_lookup_response (struct VerifyRequestHandle *vrh)
543 else 543 else
544 rmsg->cred_found = htonl (GNUNET_NO); 544 rmsg->cred_found = htonl (GNUNET_NO);
545 545
546 GNUNET_assert (-1 != 546 GNUNET_assert (-1 !=
547 GNUNET_CREDENTIAL_delegation_chain_serialize (vrh->delegation_chain_size, 547 GNUNET_CREDENTIAL_delegation_chain_serialize (vrh->delegation_chain_size,
548 dd, 548 dd,
549 vrh->cred_chain_size, 549 vrh->cred_chain_size,
@@ -587,7 +587,7 @@ backward_resolution (void* cls,
587 "Got %d attrs\n", rd_count); 587 "Got %d attrs\n", rd_count);
588 588
589 // Each OR 589 // Each OR
590 for (uint32_t i=0; i < rd_count; i++) 590 for (uint32_t i=0; i < rd_count; i++)
591 { 591 {
592 if (GNUNET_GNSRECORD_TYPE_ATTRIBUTE != rd[i].record_type) 592 if (GNUNET_GNSRECORD_TYPE_ATTRIBUTE != rd[i].record_type)
593 continue; 593 continue;
@@ -665,10 +665,10 @@ backward_resolution (void* cls,
665 /** 665 /**
666 * Check if this delegation already matches one of our credentials 666 * Check if this delegation already matches one of our credentials
667 */ 667 */
668 for(cred_pointer = vrh->cred_chain_head; cred_pointer != NULL; 668 for(cred_pointer = vrh->cred_chain_head; cred_pointer != NULL;
669 cred_pointer = cred_pointer->next) 669 cred_pointer = cred_pointer->next)
670 { 670 {
671 if(0 != memcmp (&set->subject_key, 671 if(0 != memcmp (&set->subject_key,
672 &cred_pointer->credential->issuer_key, 672 &cred_pointer->credential->issuer_key,
673 sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey))) 673 sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)))
674 continue; 674 continue;
@@ -769,7 +769,7 @@ backward_resolution (void* cls,
769 return; 769 return;
770 770
771 } 771 }
772} 772}
773 773
774 774
775/** 775/**
@@ -809,7 +809,7 @@ delegation_chain_resolution_start (void* cls)
809 } 809 }
810 810
811 /** 811 /**
812 * Check for attributes from the issuer and follow the chain 812 * Check for attributes from the issuer and follow the chain
813 * till you get the required subject's attributes 813 * till you get the required subject's attributes
814 */ 814 */
815 char issuer_attribute_name[strlen (vrh->issuer_attribute) + strlen (".gnu") + 1]; 815 char issuer_attribute_name[strlen (vrh->issuer_attribute) + strlen (".gnu") + 1];
@@ -821,9 +821,9 @@ delegation_chain_resolution_start (void* cls)
821 "Looking up %s\n", issuer_attribute_name); 821 "Looking up %s\n", issuer_attribute_name);
822 ds_entry = GNUNET_new (struct DelegationSetQueueEntry); 822 ds_entry = GNUNET_new (struct DelegationSetQueueEntry);
823 ds_entry->issuer_key = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPublicKey); 823 ds_entry->issuer_key = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPublicKey);
824 memcpy (ds_entry->issuer_key, 824 GNUNET_memcpy (ds_entry->issuer_key,
825 &vrh->issuer_key, 825 &vrh->issuer_key,
826 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)); 826 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey));
827 ds_entry->issuer_attribute = GNUNET_strdup (vrh->issuer_attribute); 827 ds_entry->issuer_attribute = GNUNET_strdup (vrh->issuer_attribute);
828 ds_entry->handle = vrh; 828 ds_entry->handle = vrh;
829 ds_entry->lookup_attribute = GNUNET_strdup (vrh->issuer_attribute); 829 ds_entry->lookup_attribute = GNUNET_strdup (vrh->issuer_attribute);
@@ -869,7 +869,7 @@ check_verify (void *cls,
869 869
870static void 870static void
871handle_verify (void *cls, 871handle_verify (void *cls,
872 const struct VerifyMessage *v_msg) 872 const struct VerifyMessage *v_msg)
873{ 873{
874 struct VerifyRequestHandle *vrh; 874 struct VerifyRequestHandle *vrh;
875 struct GNUNET_SERVICE_Client *client = cls; 875 struct GNUNET_SERVICE_Client *client = cls;
@@ -886,7 +886,9 @@ handle_verify (void *cls,
886 "Received VERIFY message\n"); 886 "Received VERIFY message\n");
887 utf_in = (const char *) &v_msg[1]; 887 utf_in = (const char *) &v_msg[1];
888 GNUNET_STRINGS_utf8_tolower (utf_in, attrptr); 888 GNUNET_STRINGS_utf8_tolower (utf_in, attrptr);
889 GNUNET_memcpy (issuer_attribute, attr, ntohs (v_msg->issuer_attribute_len)); 889 GNUNET_memcpy (issuer_attribute,
890 attr,
891 ntohs (v_msg->issuer_attribute_len));
890 issuer_attribute[ntohs (v_msg->issuer_attribute_len)] = '\0'; 892 issuer_attribute[ntohs (v_msg->issuer_attribute_len)] = '\0';
891 vrh = GNUNET_new (struct VerifyRequestHandle); 893 vrh = GNUNET_new (struct VerifyRequestHandle);
892 GNUNET_CONTAINER_DLL_insert (vrh_head, vrh_tail, vrh); 894 GNUNET_CONTAINER_DLL_insert (vrh_head, vrh_tail, vrh);
@@ -897,7 +899,7 @@ handle_verify (void *cls,
897 vrh->issuer_attribute = GNUNET_strdup (issuer_attribute); 899 vrh->issuer_attribute = GNUNET_strdup (issuer_attribute);
898 if (0 == strlen (issuer_attribute)) 900 if (0 == strlen (issuer_attribute))
899 { 901 {
900 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 902 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
901 "No issuer attribute provided!\n"); 903 "No issuer attribute provided!\n");
902 send_lookup_response (vrh); 904 send_lookup_response (vrh);
903 return; 905 return;
@@ -907,7 +909,7 @@ handle_verify (void *cls,
907 * TODO: cleanup! 909 * TODO: cleanup!
908 */ 910 */
909 credentials_count = ntohl(v_msg->c_count); 911 credentials_count = ntohl(v_msg->c_count);
910 credential_data_size = ntohs (v_msg->header.size) 912 credential_data_size = ntohs (v_msg->header.size)
911 - sizeof (struct VerifyMessage) 913 - sizeof (struct VerifyMessage)
912 - ntohs (v_msg->issuer_attribute_len) 914 - ntohs (v_msg->issuer_attribute_len)
913 - 1; 915 - 1;
@@ -918,7 +920,7 @@ handle_verify (void *cls,
918 credentials_count, 920 credentials_count,
919 credentials)) 921 credentials))
920 { 922 {
921 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 923 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
922 "Cannot deserialize credentials!\n"); 924 "Cannot deserialize credentials!\n");
923 send_lookup_response (vrh); 925 send_lookup_response (vrh);
924 return; 926 return;
@@ -1015,7 +1017,7 @@ handle_cred_collection_finished_cb (void *cls)
1015 1017
1016static void 1018static void
1017handle_collect (void *cls, 1019handle_collect (void *cls,
1018 const struct CollectMessage *c_msg) 1020 const struct CollectMessage *c_msg)
1019{ 1021{
1020 char attr[GNUNET_CREDENTIAL_MAX_LENGTH + 1]; 1022 char attr[GNUNET_CREDENTIAL_MAX_LENGTH + 1];
1021 char issuer_attribute[GNUNET_CREDENTIAL_MAX_LENGTH + 1]; 1023 char issuer_attribute[GNUNET_CREDENTIAL_MAX_LENGTH + 1];
@@ -1030,7 +1032,9 @@ handle_collect (void *cls,
1030 utf_in = (const char *) &c_msg[1]; 1032 utf_in = (const char *) &c_msg[1];
1031 GNUNET_STRINGS_utf8_tolower (utf_in, attrptr); 1033 GNUNET_STRINGS_utf8_tolower (utf_in, attrptr);
1032 1034
1033 GNUNET_memcpy (issuer_attribute, attr, ntohs (c_msg->issuer_attribute_len)); 1035 GNUNET_memcpy (issuer_attribute,
1036 attr,
1037 ntohs (c_msg->issuer_attribute_len));
1034 issuer_attribute[ntohs (c_msg->issuer_attribute_len)] = '\0'; 1038 issuer_attribute[ntohs (c_msg->issuer_attribute_len)] = '\0';
1035 vrh = GNUNET_new (struct VerifyRequestHandle); 1039 vrh = GNUNET_new (struct VerifyRequestHandle);
1036 GNUNET_CONTAINER_DLL_insert (vrh_head, vrh_tail, vrh); 1040 GNUNET_CONTAINER_DLL_insert (vrh_head, vrh_tail, vrh);
@@ -1043,7 +1047,7 @@ handle_collect (void *cls,
1043 1047
1044 if (0 == strlen (issuer_attribute)) 1048 if (0 == strlen (issuer_attribute))
1045 { 1049 {
1046 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1050 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1047 "No issuer attribute provided!\n"); 1051 "No issuer attribute provided!\n");
1048 send_lookup_response (vrh); 1052 send_lookup_response (vrh);
1049 return; 1053 return;
diff --git a/src/credential/plugin_gnsrecord_credential.c b/src/credential/plugin_gnsrecord_credential.c
index ffb2857dc..cba362a50 100644
--- a/src/credential/plugin_gnsrecord_credential.c
+++ b/src/credential/plugin_gnsrecord_credential.c
@@ -62,9 +62,9 @@ credential_value_to_string (void *cls,
62 int i; 62 int i;
63 if (data_size < sizeof (struct GNUNET_CREDENTIAL_DelegationRecord)) 63 if (data_size < sizeof (struct GNUNET_CREDENTIAL_DelegationRecord))
64 return NULL; /* malformed */ 64 return NULL; /* malformed */
65 memcpy (&sets, 65 GNUNET_memcpy (&sets,
66 data, 66 data,
67 sizeof (sets)); 67 sizeof (sets));
68 cdata = data; 68 cdata = data;
69 struct GNUNET_CREDENTIAL_DelegationSet set[ntohl(sets.set_count)]; 69 struct GNUNET_CREDENTIAL_DelegationSet set[ntohl(sets.set_count)];
70 if (GNUNET_OK != GNUNET_CREDENTIAL_delegation_set_deserialize (GNUNET_ntohll (sets.data_size), 70 if (GNUNET_OK != GNUNET_CREDENTIAL_delegation_set_deserialize (GNUNET_ntohll (sets.data_size),
@@ -224,7 +224,7 @@ credential_string_to_value (void *cls,
224 } 224 }
225 tmp_data_size = GNUNET_CREDENTIAL_delegation_set_get_size (entries, 225 tmp_data_size = GNUNET_CREDENTIAL_delegation_set_get_size (entries,
226 set); 226 set);
227 227
228 if (-1 == tmp_data_size) 228 if (-1 == tmp_data_size)
229 { 229 {
230 GNUNET_free (tmp_str); 230 GNUNET_free (tmp_str);
@@ -248,7 +248,7 @@ credential_string_to_value (void *cls,
248 return GNUNET_OK; 248 return GNUNET_OK;
249 } 249 }
250 case GNUNET_GNSRECORD_TYPE_CREDENTIAL: 250 case GNUNET_GNSRECORD_TYPE_CREDENTIAL:
251 { 251 {
252 struct GNUNET_CREDENTIAL_Credential *cred; 252 struct GNUNET_CREDENTIAL_Credential *cred;
253 cred = GNUNET_CREDENTIAL_credential_from_string (s); 253 cred = GNUNET_CREDENTIAL_credential_from_string (s);
254 254
diff --git a/src/credential/plugin_rest_credential.c b/src/credential/plugin_rest_credential.c
index 2e43139de..7f39b34ea 100644
--- a/src/credential/plugin_rest_credential.c
+++ b/src/credential/plugin_rest_credential.c
@@ -309,14 +309,14 @@ json_to_credential (json_t *res)
309 sig, 309 sig,
310 sizeof (struct GNUNET_CRYPTO_EcdsaSignature)); 310 sizeof (struct GNUNET_CRYPTO_EcdsaSignature));
311 GNUNET_free (sig); 311 GNUNET_free (sig);
312 312
313 tmp = json_object_get (res, "expiration"); 313 tmp = json_object_get (res, "expiration");
314 if (0 == json_is_integer (tmp)) 314 if (0 == json_is_integer (tmp))
315 { 315 {
316 GNUNET_free (cred); 316 GNUNET_free (cred);
317 return NULL; 317 return NULL;
318 } 318 }
319 cred->expiration.abs_value_us = json_integer_value (tmp); 319 cred->expiration.abs_value_us = json_integer_value (tmp);
320 return cred; 320 return cred;
321} 321}
322 322
@@ -342,7 +342,7 @@ credential_to_json (struct GNUNET_CREDENTIAL_Credential *cred)
342 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 342 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
343 "Issuer in credential malformed\n"); 343 "Issuer in credential malformed\n");
344 return NULL; 344 return NULL;
345 } 345 }
346 subject = GNUNET_CRYPTO_ecdsa_public_key_to_string (&cred->subject_key); 346 subject = GNUNET_CRYPTO_ecdsa_public_key_to_string (&cred->subject_key);
347 if (NULL == subject) 347 if (NULL == subject)
348 { 348 {
@@ -354,9 +354,9 @@ credential_to_json (struct GNUNET_CREDENTIAL_Credential *cred)
354 GNUNET_STRINGS_base64_encode ((char*)&cred->signature, 354 GNUNET_STRINGS_base64_encode ((char*)&cred->signature,
355 sizeof (struct GNUNET_CRYPTO_EcdsaSignature), 355 sizeof (struct GNUNET_CRYPTO_EcdsaSignature),
356 &signature); 356 &signature);
357 memcpy (attribute, 357 GNUNET_memcpy (attribute,
358 cred->issuer_attribute, 358 cred->issuer_attribute,
359 cred->issuer_attribute_len); 359 cred->issuer_attribute_len);
360 attribute[cred->issuer_attribute_len] = '\0'; 360 attribute[cred->issuer_attribute_len] = '\0';
361 cred_obj = json_object (); 361 cred_obj = json_object ();
362 json_object_set_new (cred_obj, "issuer", json_string (issuer)); 362 json_object_set_new (cred_obj, "issuer", json_string (issuer));
@@ -570,7 +570,7 @@ collect_cred_cont (struct GNUNET_REST_RequestHandle *conndata_handle,
570 { 570 {
571 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 571 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
572 "Missing issuer attribute\n"); 572 "Missing issuer attribute\n");
573 GNUNET_SCHEDULER_add_now (&do_error, handle); 573 GNUNET_SCHEDULER_add_now (&do_error, handle);
574 return; 574 return;
575 } 575 }
576 tmp = GNUNET_CONTAINER_multihashmap_get (conndata_handle->url_param_map, 576 tmp = GNUNET_CONTAINER_multihashmap_get (conndata_handle->url_param_map,
@@ -585,7 +585,7 @@ collect_cred_cont (struct GNUNET_REST_RequestHandle *conndata_handle,
585 GNUNET_SCHEDULER_add_now (&do_error, handle); 585 GNUNET_SCHEDULER_add_now (&do_error, handle);
586 return; 586 return;
587 } 587 }
588 if (GNUNET_OK != 588 if (GNUNET_OK !=
589 GNUNET_CRYPTO_ecdsa_public_key_from_string (tmp, 589 GNUNET_CRYPTO_ecdsa_public_key_from_string (tmp,
590 strlen (tmp), 590 strlen (tmp),
591 &handle->issuer_key)) 591 &handle->issuer_key))
@@ -626,7 +626,7 @@ collect_cred_cont (struct GNUNET_REST_RequestHandle *conndata_handle,
626 { 626 {
627 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 627 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
628 "Malformed subject\n"); 628 "Malformed subject\n");
629 GNUNET_SCHEDULER_add_now (&do_error, handle); 629 GNUNET_SCHEDULER_add_now (&do_error, handle);
630 return; 630 return;
631 } 631 }
632 handle->ego_lookup = GNUNET_IDENTITY_ego_lookup (cfg, 632 handle->ego_lookup = GNUNET_IDENTITY_ego_lookup (cfg,
@@ -679,7 +679,7 @@ verify_cred_cont (struct GNUNET_REST_RequestHandle *conndata_handle,
679 { 679 {
680 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 680 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
681 "Missing issuer attribute\n"); 681 "Missing issuer attribute\n");
682 GNUNET_SCHEDULER_add_now (&do_error, handle); 682 GNUNET_SCHEDULER_add_now (&do_error, handle);
683 return; 683 return;
684 } 684 }
685 tmp = GNUNET_CONTAINER_multihashmap_get (conndata_handle->url_param_map, 685 tmp = GNUNET_CONTAINER_multihashmap_get (conndata_handle->url_param_map,
@@ -694,7 +694,7 @@ verify_cred_cont (struct GNUNET_REST_RequestHandle *conndata_handle,
694 GNUNET_SCHEDULER_add_now (&do_error, handle); 694 GNUNET_SCHEDULER_add_now (&do_error, handle);
695 return; 695 return;
696 } 696 }
697 if (GNUNET_OK != 697 if (GNUNET_OK !=
698 GNUNET_CRYPTO_ecdsa_public_key_from_string (tmp, 698 GNUNET_CRYPTO_ecdsa_public_key_from_string (tmp,
699 strlen (tmp), 699 strlen (tmp),
700 &handle->issuer_key)) 700 &handle->issuer_key))
@@ -735,7 +735,7 @@ verify_cred_cont (struct GNUNET_REST_RequestHandle *conndata_handle,
735 { 735 {
736 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 736 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
737 "Malformed subject\n"); 737 "Malformed subject\n");
738 GNUNET_SCHEDULER_add_now (&do_error, handle); 738 GNUNET_SCHEDULER_add_now (&do_error, handle);
739 return; 739 return;
740 } 740 }
741 if (GNUNET_OK != 741 if (GNUNET_OK !=
@@ -946,7 +946,7 @@ get_cred_issuer_cb (void *cls,
946 { 946 {
947 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 947 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
948 "Missing expiration\n"); 948 "Missing expiration\n");
949 GNUNET_SCHEDULER_add_now (&do_error, handle); 949 GNUNET_SCHEDULER_add_now (&do_error, handle);
950 return; 950 return;
951 } 951 }
952 expiration_str = GNUNET_CONTAINER_multihashmap_get (handle->rest_handle->url_param_map, 952 expiration_str = GNUNET_CONTAINER_multihashmap_get (handle->rest_handle->url_param_map,
@@ -955,7 +955,7 @@ get_cred_issuer_cb (void *cls,
955 { 955 {
956 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 956 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
957 "Expiration malformed\n"); 957 "Expiration malformed\n");
958 GNUNET_SCHEDULER_add_now (&do_error, handle); 958 GNUNET_SCHEDULER_add_now (&do_error, handle);
959 return; 959 return;
960 } 960 }
961 961
@@ -968,7 +968,7 @@ get_cred_issuer_cb (void *cls,
968 { 968 {
969 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 969 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
970 "Malformed expiration: %s\n", expiration_str); 970 "Malformed expiration: %s\n", expiration_str);
971 GNUNET_SCHEDULER_add_now (&do_error, handle); 971 GNUNET_SCHEDULER_add_now (&do_error, handle);
972 return; 972 return;
973 } 973 }
974 GNUNET_CRYPTO_hash (GNUNET_REST_JSONAPI_CREDENTIAL_ISSUER_ATTR, 974 GNUNET_CRYPTO_hash (GNUNET_REST_JSONAPI_CREDENTIAL_ISSUER_ATTR,
@@ -980,10 +980,10 @@ get_cred_issuer_cb (void *cls,
980 { 980 {
981 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 981 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
982 "Missing issuer attribute\n"); 982 "Missing issuer attribute\n");
983 GNUNET_SCHEDULER_add_now (&do_error, handle); 983 GNUNET_SCHEDULER_add_now (&do_error, handle);
984 return; 984 return;
985 } 985 }
986 handle->issuer_attr = GNUNET_strdup(GNUNET_CONTAINER_multihashmap_get 986 handle->issuer_attr = GNUNET_strdup(GNUNET_CONTAINER_multihashmap_get
987 (handle->rest_handle->url_param_map, 987 (handle->rest_handle->url_param_map,
988 &key)); 988 &key));
989 GNUNET_CRYPTO_hash (GNUNET_REST_JSONAPI_CREDENTIAL_SUBJECT_KEY, 989 GNUNET_CRYPTO_hash (GNUNET_REST_JSONAPI_CREDENTIAL_SUBJECT_KEY,
@@ -1004,7 +1004,7 @@ get_cred_issuer_cb (void *cls,
1004 { 1004 {
1005 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1005 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1006 "Malformed subject\n"); 1006 "Malformed subject\n");
1007 GNUNET_SCHEDULER_add_now (&do_error, handle); 1007 GNUNET_SCHEDULER_add_now (&do_error, handle);
1008 return; 1008 return;
1009 } 1009 }
1010 if (GNUNET_OK != 1010 if (GNUNET_OK !=
diff --git a/src/dns/Makefile.am b/src/dns/Makefile.am
index 8e5b06043..9a4ecdcfd 100644
--- a/src/dns/Makefile.am
+++ b/src/dns/Makefile.am
@@ -37,7 +37,7 @@ libexec_PROGRAMS = \
37noinst_PROGRAMS = \ 37noinst_PROGRAMS = \
38 gnunet-dns-monitor \ 38 gnunet-dns-monitor \
39 gnunet-dns-redirector \ 39 gnunet-dns-redirector \
40 gnunet-zoneimport 40 gnunet-zonewalk
41 41
42plugin_LTLIBRARIES = \ 42plugin_LTLIBRARIES = \
43 libgnunet_plugin_block_dns.la 43 libgnunet_plugin_block_dns.la
@@ -62,9 +62,9 @@ gnunet_dns_monitor_LDADD = \
62 $(top_builddir)/src/util/libgnunetutil.la \ 62 $(top_builddir)/src/util/libgnunetutil.la \
63 $(GN_LIBINTL) 63 $(GN_LIBINTL)
64 64
65gnunet_zoneimport_SOURCES = \ 65gnunet_zonewalk_SOURCES = \
66 gnunet-zoneimport.c 66 gnunet-zonewalk.c
67gnunet_zoneimport_LDADD = \ 67gnunet_zonewalk_LDADD = \
68 libgnunetdnsparser.la \ 68 libgnunetdnsparser.la \
69 libgnunetdnsstub.la \ 69 libgnunetdnsstub.la \
70 $(top_builddir)/src/util/libgnunetutil.la \ 70 $(top_builddir)/src/util/libgnunetutil.la \
diff --git a/src/dns/dnsparser.c b/src/dns/dnsparser.c
index 7e200ee7c..6f9a24b7e 100644
--- a/src/dns/dnsparser.c
+++ b/src/dns/dnsparser.c
@@ -815,7 +815,9 @@ GNUNET_DNSPARSER_builder_add_name (char *dst,
815 return GNUNET_SYSERR; 815 return GNUNET_SYSERR;
816 816
817 if (IDNA_SUCCESS != 817 if (IDNA_SUCCESS !=
818 (rc = idna_to_ascii_8z (name, &idna_start, IDNA_ALLOW_UNASSIGNED))) 818 (rc = idna_to_ascii_8z (name,
819 &idna_start,
820 IDNA_ALLOW_UNASSIGNED)))
819 { 821 {
820 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 822 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
821 _("Failed to convert UTF-8 name `%s' to DNS IDNA format: %s\n"), 823 _("Failed to convert UTF-8 name `%s' to DNS IDNA format: %s\n"),
@@ -841,7 +843,9 @@ GNUNET_DNSPARSER_builder_add_name (char *dst,
841 goto fail; /* segment too long or empty */ 843 goto fail; /* segment too long or empty */
842 } 844 }
843 dst[pos++] = (char) (uint8_t) len; 845 dst[pos++] = (char) (uint8_t) len;
844 GNUNET_memcpy (&dst[pos], idna_name, len); 846 GNUNET_memcpy (&dst[pos],
847 idna_name,
848 len);
845 pos += len; 849 pos += len;
846 idna_name += len + 1; /* also skip dot */ 850 idna_name += len + 1; /* also skip dot */
847 } 851 }
diff --git a/src/dns/dnsstub.c b/src/dns/dnsstub.c
index 6eb3612c2..b1068a6de 100644
--- a/src/dns/dnsstub.c
+++ b/src/dns/dnsstub.c
@@ -508,9 +508,10 @@ transmit_query (void *cls)
508 sa, 508 sa,
509 salen)) 509 salen))
510 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 510 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
511 _("Failed to send DNS request to %s\n"), 511 _("Failed to send DNS request to %s: %s\n"),
512 GNUNET_a2s (sa, 512 GNUNET_a2s (sa,
513 salen)); 513 salen),
514 STRERROR (errno));
514 else 515 else
515 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 516 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
516 _("Sent DNS request to %s\n"), 517 _("Sent DNS request to %s\n"),
@@ -687,14 +688,14 @@ GNUNET_DNSSTUB_add_dns_sa (struct GNUNET_DNSSTUB_Context *ctx,
687 switch (sa->sa_family) 688 switch (sa->sa_family)
688 { 689 {
689 case AF_INET: 690 case AF_INET:
690 memcpy (&ds->ss, 691 GNUNET_memcpy (&ds->ss,
691 sa, 692 sa,
692 sizeof (struct sockaddr_in)); 693 sizeof (struct sockaddr_in));
693 break; 694 break;
694 case AF_INET6: 695 case AF_INET6:
695 memcpy (&ds->ss, 696 GNUNET_memcpy (&ds->ss,
696 sa, 697 sa,
697 sizeof (struct sockaddr_in6)); 698 sizeof (struct sockaddr_in6));
698 break; 699 break;
699 default: 700 default:
700 GNUNET_break (0); 701 GNUNET_break (0);
diff --git a/src/dns/gnunet-zoneimport.c b/src/dns/gnunet-zonewalk.c
index 860672e7a..860672e7a 100644
--- a/src/dns/gnunet-zoneimport.c
+++ b/src/dns/gnunet-zonewalk.c
diff --git a/src/fs/gnunet-service-fs_indexing.c b/src/fs/gnunet-service-fs_indexing.c
index b5e8af95f..f3cc03adc 100644
--- a/src/fs/gnunet-service-fs_indexing.c
+++ b/src/fs/gnunet-service-fs_indexing.c
@@ -528,9 +528,9 @@ GNUNET_FS_add_to_index (const char *filename,
528 ii = GNUNET_malloc (sizeof (struct IndexInfo) + slen); 528 ii = GNUNET_malloc (sizeof (struct IndexInfo) + slen);
529 ii->file_id = *file_id; 529 ii->file_id = *file_id;
530 ii->filename = (const char *) &ii[1]; 530 ii->filename = (const char *) &ii[1];
531 memcpy (&ii[1], 531 GNUNET_memcpy (&ii[1],
532 filename, 532 filename,
533 slen); 533 slen);
534 GNUNET_CONTAINER_DLL_insert (indexed_files_head, 534 GNUNET_CONTAINER_DLL_insert (indexed_files_head,
535 indexed_files_tail, 535 indexed_files_tail,
536 ii); 536 ii);
diff --git a/src/gns/.gitignore b/src/gns/.gitignore
index 5aecfd51d..2b9a18f21 100644
--- a/src/gns/.gitignore
+++ b/src/gns/.gitignore
@@ -3,3 +3,4 @@ gnunet-bcd
3gnunet-dns2gns 3gnunet-dns2gns
4gnunet-gns 4gnunet-gns
5gnunet-gns-proxy 5gnunet-gns-proxy
6gnunet-gns-benchmark
diff --git a/src/gns/Makefile.am b/src/gns/Makefile.am
index 57b096b96..ac11c834e 100644
--- a/src/gns/Makefile.am
+++ b/src/gns/Makefile.am
@@ -76,6 +76,9 @@ bin_PROGRAMS = \
76 $(DO_NONPOSIX_GNSIMPORT) \ 76 $(DO_NONPOSIX_GNSIMPORT) \
77 gnunet-gns 77 gnunet-gns
78 78
79noinst_PROGRAMS = \
80 gnunet-gns-benchmark
81
79if HAVE_MHD 82if HAVE_MHD
80if LINUX 83if LINUX
81bin_PROGRAMS += gnunet-bcd 84bin_PROGRAMS += gnunet-bcd
@@ -114,6 +117,14 @@ gnunet_gns_LDADD = \
114 $(top_builddir)/src/util/libgnunetutil.la \ 117 $(top_builddir)/src/util/libgnunetutil.la \
115 $(GN_LIBINTL) 118 $(GN_LIBINTL)
116 119
120gnunet_gns_benchmark_SOURCES = \
121 gnunet-gns-benchmark.c
122gnunet_gns_benchmark_LDADD = \
123 libgnunetgns.la \
124 $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \
125 $(top_builddir)/src/util/libgnunetutil.la \
126 $(GN_LIBINTL)
127
117 128
118gnunet_bcd_SOURCES = \ 129gnunet_bcd_SOURCES = \
119 gnunet-bcd.c 130 gnunet-bcd.c
@@ -255,7 +266,7 @@ check_SCRIPTS = \
255 test_gns_gns2dns_lookup.sh \ 266 test_gns_gns2dns_lookup.sh \
256 test_gns_dht_lookup.sh\ 267 test_gns_dht_lookup.sh\
257 test_gns_delegated_lookup.sh \ 268 test_gns_delegated_lookup.sh \
258 test_gns_plus_lookup.sh\ 269 test_gns_at_lookup.sh\
259 test_gns_zkey_lookup.sh\ 270 test_gns_zkey_lookup.sh\
260 test_gns_rel_expiration.sh\ 271 test_gns_rel_expiration.sh\
261 test_gns_soa_lookup.sh\ 272 test_gns_soa_lookup.sh\
diff --git a/src/gns/gns.conf.in b/src/gns/gns.conf.in
index 2e49a4c60..f7682cda7 100644
--- a/src/gns/gns.conf.in
+++ b/src/gns/gns.conf.in
@@ -26,7 +26,7 @@ INTERCEPT_DNS = YES
26 26
27# Zones 27# Zones
28.pin = DWJASSPE33MRN8T6Q0PENRNBTQY0E6ZYGTRCDP5DGPBF2CRJMJEG 28.pin = DWJASSPE33MRN8T6Q0PENRNBTQY0E6ZYGTRCDP5DGPBF2CRJMJEG
29 29.fr = TFDAXBXMAN40MCG4E8Y9Y1C6D16JCMDPH2VMD30KMB92SECEMYGG
30 30
31[gns-proxy] 31[gns-proxy]
32BINARY = gnunet-gns-proxy 32BINARY = gnunet-gns-proxy
diff --git a/src/gns/gns_api.c b/src/gns/gns_api.c
index ff67f0205..ed30fa44c 100644
--- a/src/gns/gns_api.c
+++ b/src/gns/gns_api.c
@@ -157,7 +157,7 @@ check_result (void *cls,
157 size_t mlen = ntohs (lookup_msg->header.size) - sizeof (*lookup_msg); 157 size_t mlen = ntohs (lookup_msg->header.size) - sizeof (*lookup_msg);
158 uint32_t rd_count = ntohl (lookup_msg->rd_count); 158 uint32_t rd_count = ntohl (lookup_msg->rd_count);
159 struct GNUNET_GNSRECORD_Data rd[rd_count]; 159 struct GNUNET_GNSRECORD_Data rd[rd_count];
160 160
161 (void) cls; 161 (void) cls;
162 if (GNUNET_SYSERR == 162 if (GNUNET_SYSERR ==
163 GNUNET_GNSRECORD_records_deserialize (mlen, 163 GNUNET_GNSRECORD_records_deserialize (mlen,
@@ -201,7 +201,7 @@ handle_result (void *cls,
201 return; 201 return;
202 proc = lr->lookup_proc; 202 proc = lr->lookup_proc;
203 proc_cls = lr->proc_cls; 203 proc_cls = lr->proc_cls;
204 204
205 GNUNET_assert (GNUNET_OK == 205 GNUNET_assert (GNUNET_OK ==
206 GNUNET_GNSRECORD_records_deserialize (mlen, 206 GNUNET_GNSRECORD_records_deserialize (mlen,
207 (const char*) &lookup_msg[1], 207 (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
index 000000000..afa540c85
--- /dev/null
+++ b/src/gns/gnunet-gns-benchmark.c
@@ -0,0 +1,587 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2018 GNUnet e.V.
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/
20/**
21 * @file src/gns/gnunet-gns-benchmark.c
22 * @brief issue many queries to GNS and compute performance statistics
23 * @author Christian Grothoff
24 */
25#include "platform.h"
26#include <gnunet_util_lib.h>
27#include <gnunet_gnsrecord_lib.h>
28#include <gnunet_gns_service.h>
29
30
31/**
32 * How long do we wait at least between requests by default?
33 */
34#define DEF_REQUEST_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 1)
35
36/**
37 * How long do we wait until we consider a request failed by default?
38 */
39#define DEF_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 1)
40
41
42/**
43 * We distinguish between different categories of
44 * requests, for which we track statistics separately.
45 * However, this process does not change how it acts
46 * based on the category.
47 */
48enum RequestCategory
49{
50 RC_SHARED = 0,
51 RC_PRIVATE = 1,
52 /**
53 * Must be last and match number of categories.
54 */
55 RC_MAX = 2
56};
57
58
59/**
60 * Request we should make. We keep this struct in memory per request,
61 * thus optimizing it is crucial for the overall memory consumption of
62 * the zone importer.
63 */
64struct Request
65{
66
67 /**
68 * Active requests are kept in a DLL.
69 */
70 struct Request *next;
71
72 /**
73 * Active requests are kept in a DLL.
74 */
75 struct Request *prev;
76
77 /**
78 * Socket used to make the request, NULL if not active.
79 */
80 struct GNUNET_GNS_LookupWithTldRequest *lr;
81
82 /**
83 * Hostname we are resolving, allocated at the end of
84 * this struct (optimizing memory consumption by reducing
85 * total number of allocations).
86 */
87 char *hostname;
88
89 /**
90 * While we are fetching the record, the value is set to the
91 * starting time of the GNS operation.
92 */
93 struct GNUNET_TIME_Absolute op_start_time;
94
95 /**
96 * Observed latency, set once we got a reply.
97 */
98 struct GNUNET_TIME_Relative latency;
99
100 /**
101 * Category of the request.
102 */
103 enum RequestCategory cat;
104
105};
106
107
108/**
109 * GNS handle.
110 */
111static struct GNUNET_GNS_Handle *gns;
112
113/**
114 * Number of lookups we performed overall per category.
115 */
116static unsigned int lookups[RC_MAX];
117
118/**
119 * Number of replies we got per category.
120 */
121static unsigned int replies[RC_MAX];
122
123/**
124 * Number of replies we got per category.
125 */
126static unsigned int failures[RC_MAX];
127
128/**
129 * Sum of the observed latencies of successful queries,
130 * per category.
131 */
132static struct GNUNET_TIME_Relative latency_sum[RC_MAX];
133
134/**
135 * Active requests are kept in a DLL.
136 */
137static struct Request *act_head;
138
139/**
140 * Active requests are kept in a DLL.
141 */
142static struct Request *act_tail;
143
144/**
145 * Completed successful requests are kept in a DLL.
146 */
147static struct Request *succ_head;
148
149/**
150 * Completed successful requests are kept in a DLL.
151 */
152static struct Request *succ_tail;
153
154/**
155 * Yet to be started requests are kept in a DLL.
156 */
157static struct Request *todo_head;
158
159/**
160 * Yet to be started requests are kept in a DLL.
161 */
162static struct Request *todo_tail;
163
164/**
165 * Main task.
166 */
167static struct GNUNET_SCHEDULER_Task *t;
168
169/**
170 * Delay between requests.
171 */
172static struct GNUNET_TIME_Relative request_delay;
173
174/**
175 * Timeout for requests.
176 */
177static struct GNUNET_TIME_Relative timeout;
178
179
180/**
181 * Free @a req and data structures reachable from it.
182 *
183 * @param req request to free
184 */
185static void
186free_request (struct Request *req)
187{
188 if (NULL != req->lr)
189 GNUNET_GNS_lookup_with_tld_cancel (req->lr);
190 GNUNET_free (req);
191}
192
193
194/**
195 * Function called with the result of a GNS resolution.
196 *
197 * @param cls closure with the `struct Request`
198 * @param gns_tld #GNUNET_YES if GNS lookup was attempted
199 * @param rd_count number of records in @a rd
200 * @param rd the records in reply
201 */
202static void
203process_result (void *cls,
204 int gns_tld,
205 uint32_t rd_count,
206 const struct GNUNET_GNSRECORD_Data *rd)
207{
208 struct Request *req = cls;
209
210 (void) gns_tld;
211 (void) rd_count;
212 (void) rd;
213 req->lr = NULL;
214 req->latency = GNUNET_TIME_absolute_get_duration (req->op_start_time);
215 GNUNET_CONTAINER_DLL_remove (act_head,
216 act_tail,
217 req);
218 GNUNET_CONTAINER_DLL_insert (succ_head,
219 succ_tail,
220 req);
221 replies[req->cat]++;
222 latency_sum[req->cat]
223 = GNUNET_TIME_relative_add (latency_sum[req->cat],
224 req->latency);
225}
226
227
228/**
229 * Process request from the queue.
230 *
231 * @param cls NULL
232 */
233static void
234process_queue (void *cls)
235{
236 struct Request *req;
237 struct GNUNET_TIME_Relative duration;
238
239 (void) cls;
240 t = NULL;
241 /* check for expired requests */
242 while (NULL != (req = act_head))
243 {
244 duration = GNUNET_TIME_absolute_get_duration (req->op_start_time);
245 if (duration.rel_value_us < timeout.rel_value_us)
246 break;
247 GNUNET_CONTAINER_DLL_remove (act_head,
248 act_tail,
249 req);
250 failures[req->cat]++;
251 free_request (req);
252 }
253 if (NULL == (req = todo_head))
254 {
255 struct GNUNET_TIME_Absolute at;
256
257 if (NULL == (req = act_head))
258 {
259 GNUNET_SCHEDULER_shutdown ();
260 return;
261 }
262 at = GNUNET_TIME_absolute_add (req->op_start_time,
263 timeout);
264 t = GNUNET_SCHEDULER_add_at (at,
265 &process_queue,
266 NULL);
267 return;
268 }
269 GNUNET_CONTAINER_DLL_remove (todo_head,
270 todo_tail,
271 req);
272 GNUNET_CONTAINER_DLL_insert_tail (act_head,
273 act_tail,
274 req);
275 lookups[req->cat]++;
276 req->op_start_time = GNUNET_TIME_absolute_get ();
277 req->lr = GNUNET_GNS_lookup_with_tld (gns,
278 req->hostname,
279 GNUNET_GNSRECORD_TYPE_ANY,
280 GNUNET_GNS_LO_DEFAULT,
281 &process_result,
282 req);
283 t = GNUNET_SCHEDULER_add_delayed (request_delay,
284 &process_queue,
285 NULL);
286}
287
288
289/**
290 * Compare two requests by latency for qsort().
291 *
292 * @param c1 pointer to `struct Request *`
293 * @param c2 pointer to `struct Request *`
294 * @return -1 if c1<c2, 1 if c1>c2, 0 if c1==c2.
295 */
296static int
297compare_req (const void *c1,
298 const void *c2)
299{
300 const struct Request *r1 = *(void **) c1;
301 const struct Request *r2 = *(void **) c2;
302
303 if (r1->latency.rel_value_us < r2->latency.rel_value_us)
304 return -1;
305 if (r1->latency.rel_value_us > r2->latency.rel_value_us)
306 return 1;
307 return 0;
308}
309
310
311/**
312 * Output statistics, then clean up and terminate the process.
313 *
314 * @param cls NULL
315 */
316static void
317do_shutdown (void *cls)
318{
319 struct Request *req;
320 struct Request **ra[RC_MAX];
321 unsigned int rp[RC_MAX];
322
323 (void) cls;
324 for (enum RequestCategory rc = 0;rc < RC_MAX;rc++)
325 {
326 ra[rc] = GNUNET_new_array (replies[rc],
327 struct Request *);
328 rp[rc] = 0;
329 }
330 for (req = succ_head;NULL != req; req = req->next)
331 {
332 GNUNET_assert (rp[req->cat] < replies[req->cat]);
333 ra[req->cat][rp[req->cat]++] = req;
334 }
335 for (enum RequestCategory rc = 0;rc < RC_MAX;rc++)
336 {
337 unsigned int off;
338
339 fprintf (stdout,
340 "Category %u\n",
341 rc);
342 fprintf (stdout,
343 "\tlookups: %u replies: %u failures: %u\n",
344 lookups[rc],
345 replies[rc],
346 failures[rc]);
347 if (0 == rp[rc])
348 continue;
349 qsort (ra[rc],
350 rp[rc],
351 sizeof (struct Request *),
352 &compare_req);
353 latency_sum[rc] = GNUNET_TIME_relative_divide (latency_sum[rc],
354 replies[rc]);
355 fprintf (stdout,
356 "\taverage: %s\n",
357 GNUNET_STRINGS_relative_time_to_string (latency_sum[rc],
358 GNUNET_YES));
359 off = rp[rc] * 50 / 100;
360 fprintf (stdout,
361 "\tmedian(50): %s\n",
362 GNUNET_STRINGS_relative_time_to_string (ra[rc][off]->latency,
363 GNUNET_YES));
364 off = rp[rc] * 75 / 100;
365 fprintf (stdout,
366 "\tquantile(75): %s\n",
367 GNUNET_STRINGS_relative_time_to_string (ra[rc][off]->latency,
368 GNUNET_YES));
369 off = rp[rc] * 90 / 100;
370 fprintf (stdout,
371 "\tquantile(90): %s\n",
372 GNUNET_STRINGS_relative_time_to_string (ra[rc][off]->latency,
373 GNUNET_YES));
374 off = rp[rc] * 99 / 100;
375 fprintf (stdout,
376 "\tquantile(99): %s\n",
377 GNUNET_STRINGS_relative_time_to_string (ra[rc][off]->latency,
378 GNUNET_YES));
379 GNUNET_free (ra[rc]);
380 }
381 if (NULL != t)
382 {
383 GNUNET_SCHEDULER_cancel (t);
384 t = NULL;
385 }
386 while (NULL != (req = act_head))
387 {
388 GNUNET_CONTAINER_DLL_remove (act_head,
389 act_tail,
390 req);
391 free_request (req);
392 }
393 while (NULL != (req = succ_head))
394 {
395 GNUNET_CONTAINER_DLL_remove (succ_head,
396 succ_tail,
397 req);
398 free_request (req);
399 }
400 while (NULL != (req = todo_head))
401 {
402 GNUNET_CONTAINER_DLL_remove (todo_head,
403 todo_tail,
404 req);
405 free_request (req);
406 }
407 if (NULL != gns)
408 {
409 GNUNET_GNS_disconnect (gns);
410 gns = NULL;
411 }
412}
413
414
415/**
416 * Add @a hostname to the list of requests to be made.
417 *
418 * @param hostname name to resolve
419 * @param cat category of the @a hostname
420 */
421static void
422queue (const char *hostname,
423 enum RequestCategory cat)
424{
425 struct Request *req;
426 const char *dot;
427 size_t hlen;
428
429 dot = strchr (hostname,
430 (unsigned char) '.');
431 if (NULL == dot)
432 {
433 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
434 "Refusing invalid hostname `%s' (lacks '.')\n",
435 hostname);
436 return;
437 }
438 hlen = strlen (hostname) + 1;
439 req = GNUNET_malloc (sizeof (struct Request) + hlen);
440 req->cat = cat;
441 req->hostname = (char *) &req[1];
442 GNUNET_memcpy (req->hostname,
443 hostname,
444 hlen);
445 GNUNET_CONTAINER_DLL_insert (todo_head,
446 todo_tail,
447 req);
448}
449
450
451/**
452 * Begin processing hostnames from stdin.
453 *
454 * @param cls NULL
455 */
456static void
457process_stdin (void *cls)
458{
459 static struct GNUNET_TIME_Absolute last;
460 static uint64_t idot;
461 unsigned int cat;
462 char hn[256];
463 char in[270];
464
465 (void) cls;
466 t = NULL;
467 while (NULL !=
468 fgets (in,
469 sizeof (in),
470 stdin))
471 {
472 if (strlen(in) > 0)
473 hn[strlen(in)-1] = '\0'; /* eat newline */
474 if ( (2 != sscanf (in,
475 "%u %255s",
476 &cat,
477 hn)) ||
478 (cat >= RC_MAX) )
479 {
480 fprintf (stderr,
481 "Malformed input line `%s', skipping\n",
482 in);
483 continue;
484 }
485 if (0 == idot)
486 last = GNUNET_TIME_absolute_get ();
487 idot++;
488 if (0 == idot % 100000)
489 {
490 struct GNUNET_TIME_Relative delta;
491
492 delta = GNUNET_TIME_absolute_get_duration (last);
493 last = GNUNET_TIME_absolute_get ();
494 fprintf (stderr,
495 "Read 10000 domain names in %s\n",
496 GNUNET_STRINGS_relative_time_to_string (delta,
497 GNUNET_YES));
498 }
499 queue (hn,
500 (enum RequestCategory) cat);
501 }
502 fprintf (stderr,
503 "Done reading %llu domain names\n",
504 (unsigned long long) idot);
505 t = GNUNET_SCHEDULER_add_now (&process_queue,
506 NULL);
507}
508
509
510/**
511 * Process requests from the queue, then if the queue is
512 * not empty, try again.
513 *
514 * @param cls NULL
515 * @param args remaining command-line arguments
516 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
517 * @param cfg configuration
518 */
519static void
520run (void *cls,
521 char *const *args,
522 const char *cfgfile,
523 const struct GNUNET_CONFIGURATION_Handle *cfg)
524{
525 (void) cls;
526 (void) args;
527 (void) cfgfile;
528 GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
529 NULL);
530 gns = GNUNET_GNS_connect (cfg);
531 if (NULL == gns)
532 {
533 GNUNET_break (0);
534 GNUNET_SCHEDULER_shutdown ();
535 return;
536 }
537 t = GNUNET_SCHEDULER_add_now (&process_stdin,
538 NULL);
539}
540
541
542/**
543 * Call with list of names with numeric category to query.
544 *
545 * @param argc unused
546 * @param argv unused
547 * @return 0 on success
548 */
549int
550main (int argc,
551 char *const*argv)
552{
553 int ret = 0;
554 struct GNUNET_GETOPT_CommandLineOption options[] = {
555 GNUNET_GETOPT_option_relative_time ('d',
556 "delay",
557 "RELATIVETIME",
558 gettext_noop ("how long to wait between queries"),
559 &request_delay),
560 GNUNET_GETOPT_option_relative_time ('t',
561 "timeout",
562 "RELATIVETIME",
563 gettext_noop ("how long to wait for an answer"),
564 &timeout),
565 GNUNET_GETOPT_OPTION_END
566 };
567
568 if (GNUNET_OK !=
569 GNUNET_STRINGS_get_utf8_args (argc, argv,
570 &argc, &argv))
571 return 2;
572 timeout = DEF_TIMEOUT;
573 request_delay = DEF_REQUEST_DELAY;
574 if (GNUNET_OK !=
575 GNUNET_PROGRAM_run (argc,
576 argv,
577 "gnunet-gns-benchmark",
578 "resolve GNS names and measure performance",
579 options,
580 &run,
581 NULL))
582 ret = 1;
583 GNUNET_free ((void*) argv);
584 return ret;
585}
586
587/* end of gnunet-gns-benchmark.c */
diff --git a/src/gns/gnunet-service-gns_resolver.c b/src/gns/gnunet-service-gns_resolver.c
index 92e03bc69..542085910 100644
--- a/src/gns/gnunet-service-gns_resolver.c
+++ b/src/gns/gnunet-service-gns_resolver.c
@@ -109,6 +109,11 @@ struct Gns2DnsPending
109 * Handle for DNS resolution of the DNS nameserver. 109 * Handle for DNS resolution of the DNS nameserver.
110 */ 110 */
111 struct GNUNET_RESOLVER_RequestHandle *dns_rh; 111 struct GNUNET_RESOLVER_RequestHandle *dns_rh;
112
113 /**
114 * How many results did we get?
115 */
116 unsigned int num_results;
112}; 117};
113 118
114 119
@@ -813,7 +818,9 @@ add_dns_result (struct GNS_ResolverHandle *rh,
813 res->data_size = data_size; 818 res->data_size = data_size;
814 res->record_type = record_type; 819 res->record_type = record_type;
815 res->data = &res[1]; 820 res->data = &res[1];
816 GNUNET_memcpy (&res[1], data, data_size); 821 GNUNET_memcpy (&res[1],
822 data,
823 data_size);
817 GNUNET_CONTAINER_DLL_insert (rh->dns_result_head, 824 GNUNET_CONTAINER_DLL_insert (rh->dns_result_head,
818 rh->dns_result_tail, 825 rh->dns_result_tail,
819 res); 826 res);
@@ -1494,26 +1501,48 @@ handle_gns2dns_ip (void *cls,
1494{ 1501{
1495 struct Gns2DnsPending *gp = cls; 1502 struct Gns2DnsPending *gp = cls;
1496 struct AuthorityChain *ac = gp->ac; 1503 struct AuthorityChain *ac = gp->ac;
1504 struct sockaddr_storage ss;
1505 struct sockaddr_in *v4;
1506 struct sockaddr_in6 *v6;
1497 1507
1498 GNUNET_RESOLVER_request_cancel (gp->dns_rh);
1499 GNUNET_CONTAINER_DLL_remove (ac->authority_info.dns_authority.gp_head,
1500 ac->authority_info.dns_authority.gp_tail,
1501 gp);
1502 GNUNET_free (gp);
1503 if (NULL == addr) 1508 if (NULL == addr)
1504 { 1509 {
1505 /* DNS resolution failed */ 1510 /* DNS resolution finished */
1506 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1511 if (0 == gp->num_results)
1507 "Failed to use DNS to resolve name of DNS resolver\n"); 1512 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1513 "Failed to use DNS to resolve name of DNS resolver\n");
1514 GNUNET_CONTAINER_DLL_remove (ac->authority_info.dns_authority.gp_head,
1515 ac->authority_info.dns_authority.gp_tail,
1516 gp);
1517 GNUNET_free (gp);
1518 continue_with_gns2dns (ac);
1519 return;
1508 } 1520 }
1509 else 1521 GNUNET_memcpy (&ss,
1522 addr,
1523 addrlen);
1524 switch (ss.ss_family)
1510 { 1525 {
1511 if (GNUNET_OK == 1526 case AF_INET:
1512 GNUNET_DNSSTUB_add_dns_sa (ac->authority_info.dns_authority.dns_handle, 1527 v4 = (struct sockaddr_in *) &ss;
1513 addr)) 1528 v4->sin_port = htons (53);
1514 ac->authority_info.dns_authority.found = GNUNET_YES; 1529 gp->num_results++;
1530 break;
1531 case AF_INET6:
1532 v6 = (struct sockaddr_in6 *) &ss;
1533 v6->sin6_port = htons (53);
1534 gp->num_results++;
1535 break;
1536 default:
1537 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1538 "Unsupported AF %d\n",
1539 ss.ss_family);
1540 return;
1515 } 1541 }
1516 continue_with_gns2dns (ac); 1542 if (GNUNET_OK ==
1543 GNUNET_DNSSTUB_add_dns_sa (ac->authority_info.dns_authority.dns_handle,
1544 (struct sockaddr *) &ss))
1545 ac->authority_info.dns_authority.found = GNUNET_YES;
1517} 1546}
1518 1547
1519 1548
diff --git a/src/gns/plugin_gnsrecord_gns.c b/src/gns/plugin_gnsrecord_gns.c
index 07d1a9c04..b88e8fcc2 100644
--- a/src/gns/plugin_gnsrecord_gns.c
+++ b/src/gns/plugin_gnsrecord_gns.c
@@ -102,9 +102,9 @@ gns_value_to_string (void *cls,
102 ('\0' != cdata[data_size - 1]) ) 102 ('\0' != cdata[data_size - 1]) )
103 return NULL; /* malformed */ 103 return NULL; /* malformed */
104 /* need to memcpy for alignment */ 104 /* need to memcpy for alignment */
105 memcpy (&vpn, 105 GNUNET_memcpy (&vpn,
106 data, 106 data,
107 sizeof (vpn)); 107 sizeof (vpn));
108 GNUNET_asprintf (&vpn_str, 108 GNUNET_asprintf (&vpn_str,
109 "%u %s %s", 109 "%u %s %s",
110 (unsigned int) ntohs (vpn.proto), 110 (unsigned int) ntohs (vpn.proto),
@@ -122,9 +122,9 @@ gns_value_to_string (void *cls,
122 cdata = data; 122 cdata = data;
123 if (data_size < sizeof (struct GNUNET_GNSRECORD_BoxRecord)) 123 if (data_size < sizeof (struct GNUNET_GNSRECORD_BoxRecord))
124 return NULL; /* malformed */ 124 return NULL; /* malformed */
125 memcpy (&box, 125 GNUNET_memcpy (&box,
126 data, 126 data,
127 sizeof (box)); 127 sizeof (box));
128 rt = ntohl (box.record_type); 128 rt = ntohl (box.record_type);
129 ival = GNUNET_GNSRECORD_value_to_string (rt, 129 ival = GNUNET_GNSRECORD_value_to_string (rt,
130 &cdata[sizeof (box)], 130 &cdata[sizeof (box)],
diff --git a/src/gns/test_gns_plus_lookup.sh b/src/gns/test_gns_at_lookup.sh
index 4cf7a8855..8c1d2a088 100755
--- a/src/gns/test_gns_plus_lookup.sh
+++ b/src/gns/test_gns_at_lookup.sh
@@ -14,7 +14,7 @@ then
14fi 14fi
15 15
16which timeout &> /dev/null && DO_TIMEOUT="timeout 5" 16which timeout &> /dev/null && DO_TIMEOUT="timeout 5"
17rm -rf /tmp/test-gnunet-gns-peer-1/ 17rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
18 18
19TEST_IP="127.0.0.1" 19TEST_IP="127.0.0.1"
20MY_EGO="myego" 20MY_EGO="myego"
@@ -23,12 +23,12 @@ gnunet-identity -C delegatedego -c test_gns_lookup.conf
23DELEGATED_PKEY=$(gnunet-identity -d -c test_gns_lookup.conf | grep delegatedego | awk '{print $3}') 23DELEGATED_PKEY=$(gnunet-identity -d -c test_gns_lookup.conf | grep delegatedego | awk '{print $3}')
24gnunet-identity -C $MY_EGO -c test_gns_lookup.conf 24gnunet-identity -C $MY_EGO -c test_gns_lookup.conf
25gnunet-namestore -p -z $MY_EGO -a -n b -t PKEY -V $DELEGATED_PKEY -e never -c test_gns_lookup.conf 25gnunet-namestore -p -z $MY_EGO -a -n b -t PKEY -V $DELEGATED_PKEY -e never -c test_gns_lookup.conf
26gnunet-namestore -p -z delegatedego -a -n '+' -t A -V $TEST_IP -e never -c test_gns_lookup.conf 26gnunet-namestore -p -z delegatedego -a -n '@' -t A -V $TEST_IP -e never -c test_gns_lookup.conf
27RES_IP=`$DO_TIMEOUT gnunet-gns --raw -u b.$MY_EGO -t A -c test_gns_lookup.conf` 27RES_IP=`$DO_TIMEOUT gnunet-gns --raw -u b.$MY_EGO -t A -c test_gns_lookup.conf`
28gnunet-namestore -z $MY_EGO -d -n b -t PKEY -V $DELEGATED_PKEY -e never -c test_gns_lookup.conf 28gnunet-namestore -z $MY_EGO -d -n b -t PKEY -V $DELEGATED_PKEY -e never -c test_gns_lookup.conf
29gnunet-namestore -z delegatedego -d -n '+' -t A -V $TEST_IP -e never -c test_gns_lookup.conf 29gnunet-namestore -z delegatedego -d -n '@' -t A -V $TEST_IP -e never -c test_gns_lookup.conf
30gnunet-arm -e -c test_gns_lookup.conf 30gnunet-arm -e -c test_gns_lookup.conf
31rm -rf /tmp/test-gnunet-gns-peer-1/ 31rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
32 32
33if [ "$RES_IP" == "$TEST_IP" ] 33if [ "$RES_IP" == "$TEST_IP" ]
34then 34then
diff --git a/src/gns/test_gns_cname_lookup.sh b/src/gns/test_gns_cname_lookup.sh
index d9627850f..00ccd265b 100755
--- a/src/gns/test_gns_cname_lookup.sh
+++ b/src/gns/test_gns_cname_lookup.sh
@@ -22,7 +22,7 @@ then
22fi 22fi
23 23
24 24
25rm -rf /tmp/test-gnunet-gns-peer-1/ 25rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
26 26
27TEST_IP_PLUS="127.0.0.1" 27TEST_IP_PLUS="127.0.0.1"
28TEST_IP_DNS="131.159.74.67" 28TEST_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
51gnunet-namestore -p -z $MY_EGO -d -n $TEST_RECORD_CNAME_SERVER -t A -V $TEST_IP_PLUS -e never -c test_gns_lookup.conf 51gnunet-namestore -p -z $MY_EGO -d -n $TEST_RECORD_CNAME_SERVER -t A -V $TEST_IP_PLUS -e never -c test_gns_lookup.conf
52gnunet-identity -D $MY_EGO -c test_gns_lookup.conf 52gnunet-identity -D $MY_EGO -c test_gns_lookup.conf
53gnunet-arm -e -c test_gns_lookup.conf 53gnunet-arm -e -c test_gns_lookup.conf
54rm -rf /tmp/test-gnunet-gns-peer-1/ 54rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
55 55
56if [ "$RES_CNAME_RAW" == "server.$TESTEGOZONE" ] 56if [ "$RES_CNAME_RAW" == "server.$TESTEGOZONE" ]
57then 57then
diff --git a/src/gns/test_gns_delegated_lookup.sh b/src/gns/test_gns_delegated_lookup.sh
index edda688ff..3374f1b3b 100755
--- a/src/gns/test_gns_delegated_lookup.sh
+++ b/src/gns/test_gns_delegated_lookup.sh
@@ -14,7 +14,7 @@ then
14 exit 77 14 exit 77
15fi 15fi
16 16
17rm -rf /tmp/test-gnunet-gns-peer-1/ 17rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
18MY_EGO="myego" 18MY_EGO="myego"
19OTHER_EGO="delegatedego" 19OTHER_EGO="delegatedego"
20FINAL_LABEL="www" 20FINAL_LABEL="www"
@@ -32,7 +32,7 @@ gnunet-namestore -z $MY_EGO -d -n b -t PKEY -V $DELEGATED_PKEY -e never -c test
32gnunet-namestore -z $OTHER_EGO -d -n $FINAL_LABEL -t A -V $TEST_IP -e never -c test_gns_lookup.conf 32gnunet-namestore -z $OTHER_EGO -d -n $FINAL_LABEL -t A -V $TEST_IP -e never -c test_gns_lookup.conf
33gnunet-arm -e -c test_gns_lookup.conf 33gnunet-arm -e -c test_gns_lookup.conf
34 34
35rm -rf /tmp/test-gnunet-gns-peer-1/ 35rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
36 36
37if [ "$RES_IP" == "$TEST_IP" ] 37if [ "$RES_IP" == "$TEST_IP" ]
38then 38then
diff --git a/src/gns/test_gns_dht_lookup.sh b/src/gns/test_gns_dht_lookup.sh
index 365c77339..6c977bb0d 100755
--- a/src/gns/test_gns_dht_lookup.sh
+++ b/src/gns/test_gns_dht_lookup.sh
@@ -18,7 +18,7 @@ TEST_IP="127.0.0.1"
18MY_EGO="myego" 18MY_EGO="myego"
19OTHER_EGO="delegatedego" 19OTHER_EGO="delegatedego"
20 20
21 21rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
22gnunet-arm -s -c test_gns_lookup.conf 22gnunet-arm -s -c test_gns_lookup.conf
23gnunet-identity -C $OTHER_EGO -c test_gns_lookup.conf 23gnunet-identity -C $OTHER_EGO -c test_gns_lookup.conf
24DELEGATED_PKEY=$(gnunet-identity -d -c test_gns_lookup.conf | grep $OTHER_EGO | awk '{print $3}') 24DELEGATED_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_
31RES_IP=`$DO_TIMEOUT gnunet-gns --raw -u www.b.$MY_EGO -t A -c test_gns_lookup.conf` 31RES_IP=`$DO_TIMEOUT gnunet-gns --raw -u www.b.$MY_EGO -t A -c test_gns_lookup.conf`
32gnunet-namestore -z $MY_EGO -d -n b -t PKEY -V $DELEGATED_PKEY -e never -c test_gns_lookup.conf 32gnunet-namestore -z $MY_EGO -d -n b -t PKEY -V $DELEGATED_PKEY -e never -c test_gns_lookup.conf
33gnunet-arm -e -c test_gns_lookup.conf 33gnunet-arm -e -c test_gns_lookup.conf
34rm -rf /tmp/test-gnunet-gns-peer-1/ 34rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
35 35
36if [ "$RES_IP" == "$TEST_IP" ] 36if [ "$RES_IP" == "$TEST_IP" ]
37then 37then
diff --git a/src/gns/test_gns_gns2dns_lookup.sh b/src/gns/test_gns_gns2dns_lookup.sh
index 921d9594d..ad5d762eb 100755
--- a/src/gns/test_gns_gns2dns_lookup.sh
+++ b/src/gns/test_gns_gns2dns_lookup.sh
@@ -13,7 +13,7 @@ then
13 exit 77 13 exit 77
14fi 14fi
15 15
16rm -r rm -rf /tmp/test-gnunet-gns-peer-1/ 16rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
17# IP address of 'uk.gnunet.org' 17# IP address of 'uk.gnunet.org'
18TEST_IP_ALT2="81.187.252.184" 18TEST_IP_ALT2="81.187.252.184"
19# IP address of 'www.gnunet.org' 19# 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
72gnunet-namestore -z $MY_EGO -d -n $TEST_RECORD_NAME -t GNS2DNS -V $TEST_RECORD_GNS2DNS -e never -c test_gns_lookup.conf 72gnunet-namestore -z $MY_EGO -d -n $TEST_RECORD_NAME -t GNS2DNS -V $TEST_RECORD_GNS2DNS -e never -c test_gns_lookup.conf
73gnunet-identity -D $MY_EGO -c test_gns_lookup.conf 73gnunet-identity -D $MY_EGO -c test_gns_lookup.conf
74gnunet-arm -e -c test_gns_lookup.conf 74gnunet-arm -e -c test_gns_lookup.conf
75rm -rf /tmp/test-gnunet-gns-peer-1/ 75rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
76 76
77ret=0 77ret=0
78if [ "$RES_IP" == "$TEST_IP" ] 78if [ "$RES_IP" == "$TEST_IP" ]
diff --git a/src/gns/test_gns_ipv6_lookup.sh b/src/gns/test_gns_ipv6_lookup.sh
index 118c23060..301e6ae0c 100755
--- a/src/gns/test_gns_ipv6_lookup.sh
+++ b/src/gns/test_gns_ipv6_lookup.sh
@@ -24,7 +24,7 @@ RES_IP=`$DO_TIMEOUT gnunet-gns --raw -u www.$MY_EGO -t AAAA -c test_gns_lookup.c
24gnunet-namestore -z $MY_EGO -d -n www -t AAAA -V $TEST_IP -e never -c test_gns_lookup.conf 24gnunet-namestore -z $MY_EGO -d -n www -t AAAA -V $TEST_IP -e never -c test_gns_lookup.conf
25gnunet-identity -D $MY_EGO -c test_gns_lookup.conf 25gnunet-identity -D $MY_EGO -c test_gns_lookup.conf
26gnunet-arm -e -c test_gns_lookup.conf 26gnunet-arm -e -c test_gns_lookup.conf
27rm -rf /tmp/test-gnunet-gns-peer-1/ 27rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
28 28
29if [ "$RES_IP" == "$TEST_IP" ] 29if [ "$RES_IP" == "$TEST_IP" ]
30then 30then
diff --git a/src/gns/test_gns_mx_lookup.sh b/src/gns/test_gns_mx_lookup.sh
index 8abc9f509..5a7ef21c3 100755
--- a/src/gns/test_gns_mx_lookup.sh
+++ b/src/gns/test_gns_mx_lookup.sh
@@ -13,7 +13,7 @@ then
13 exit 77 13 exit 77
14fi 14fi
15 15
16rm -rf /tmp/test-gnunet-gns-peer-1/ 16rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
17which timeout &> /dev/null && DO_TIMEOUT="timeout 5" 17which timeout &> /dev/null && DO_TIMEOUT="timeout 5"
18 18
19MY_EGO="myego" 19MY_EGO="myego"
@@ -28,7 +28,7 @@ RES_MX=`$DO_TIMEOUT gnunet-gns --raw -u www.$MY_EGO -t MX -c test_gns_lookup.con
28gnunet-namestore -z $MY_EGO -d -n www -t MX -V "$TEST_MX" -e never -c test_gns_lookup.conf 28gnunet-namestore -z $MY_EGO -d -n www -t MX -V "$TEST_MX" -e never -c test_gns_lookup.conf
29gnunet-identity -D $MY_EGO -c test_gns_lookup.conf 29gnunet-identity -D $MY_EGO -c test_gns_lookup.conf
30gnunet-arm -e -c test_gns_lookup.conf 30gnunet-arm -e -c test_gns_lookup.conf
31rm -rf /tmp/test-gnunet-gns-peer-1/ 31rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
32 32
33if [ "$RES_MX" == "$WANT_MX" ] 33if [ "$RES_MX" == "$WANT_MX" ]
34then 34then
diff --git a/src/gns/test_gns_quickupdate.sh b/src/gns/test_gns_quickupdate.sh
index 5606491e4..e0eb33f2e 100755
--- a/src/gns/test_gns_quickupdate.sh
+++ b/src/gns/test_gns_quickupdate.sh
@@ -17,7 +17,7 @@ MY_EGO="myego"
17OTHER_EGO="delegatedego" 17OTHER_EGO="delegatedego"
18 18
19 19
20rm -rf /tmp/test-gnunet-gns-peer-1/ 20rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
21which timeout &> /dev/null && DO_TIMEOUT="timeout 5" 21which timeout &> /dev/null && DO_TIMEOUT="timeout 5"
22TEST_IP="127.0.0.1" 22TEST_IP="127.0.0.1"
23gnunet-arm -s -c test_gns_lookup.conf 23gnunet-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
53gnunet-identity -D $MY_EGO -c test_gns_lookup.conf 53gnunet-identity -D $MY_EGO -c test_gns_lookup.conf
54gnunet-identity -D $OTHER_EGO -c test_gns_lookup.conf 54gnunet-identity -D $OTHER_EGO -c test_gns_lookup.conf
55gnunet-arm -e -c test_gns_lookup.conf 55gnunet-arm -e -c test_gns_lookup.conf
56rm -rf /tmp/test-gnunet-gns-peer-1/ 56rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
57 57
58if [ "$RES_IP" == "$TEST_IP" ] 58if [ "$RES_IP" == "$TEST_IP" ]
59then 59then
diff --git a/src/gns/test_gns_rel_expiration.sh b/src/gns/test_gns_rel_expiration.sh
index 992098db3..a266a7484 100755
--- a/src/gns/test_gns_rel_expiration.sh
+++ b/src/gns/test_gns_rel_expiration.sh
@@ -16,7 +16,7 @@ fi
16MY_EGO="myego" 16MY_EGO="myego"
17OTHER_EGO="delegatedego" 17OTHER_EGO="delegatedego"
18 18
19rm -rf /tmp/test-gnunet-gns-peer-1/ 19rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
20which timeout &> /dev/null && DO_TIMEOUT="timeout 5" 20which timeout &> /dev/null && DO_TIMEOUT="timeout 5"
21TEST_IP="127.0.0.1" 21TEST_IP="127.0.0.1"
22gnunet-arm -s -c test_gns_lookup.conf 22gnunet-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
38gnunet-identity -D $MY_EGO -c test_gns_lookup.conf 38gnunet-identity -D $MY_EGO -c test_gns_lookup.conf
39gnunet-identity -D $OTHER_EGO -c test_gns_lookup.conf 39gnunet-identity -D $OTHER_EGO -c test_gns_lookup.conf
40gnunet-arm -e -c test_gns_lookup.conf 40gnunet-arm -e -c test_gns_lookup.conf
41rm -rf /tmp/test-gnunet-gns-peer-1/ 41rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
42 42
43if [ "$RES_IP_EXP" == "$TEST_IP" ] 43if [ "$RES_IP_EXP" == "$TEST_IP" ]
44then 44then
diff --git a/src/gns/test_gns_revocation.sh b/src/gns/test_gns_revocation.sh
index 269b940d9..12f0c0881 100755
--- a/src/gns/test_gns_revocation.sh
+++ b/src/gns/test_gns_revocation.sh
@@ -14,7 +14,7 @@ then
14 exit 77 14 exit 77
15fi 15fi
16 16
17rm -rf /tmp/test-gnunet-gns-peer-1/ 17rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
18MY_EGO="myego" 18MY_EGO="myego"
19OTHER_EGO="delegatedego" 19OTHER_EGO="delegatedego"
20TEST_IP="127.0.0.1" 20TEST_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
31gnunet-namestore -z $MY_EGO -d -n b -t PKEY -V $DELEGATED_PKEY -e never -c test_gns_lookup.conf 31gnunet-namestore -z $MY_EGO -d -n b -t PKEY -V $DELEGATED_PKEY -e never -c test_gns_lookup.conf
32gnunet-namestore -z $OTHER_EGO -d -n www -t A -V $TEST_IP -e never -c test_gns_lookup.conf 32gnunet-namestore -z $OTHER_EGO -d -n www -t A -V $TEST_IP -e never -c test_gns_lookup.conf
33gnunet-arm -e -c test_gns_lookup.conf 33gnunet-arm -e -c test_gns_lookup.conf
34rm -rf /tmp/test-gnunet-gns-peer-1/ 34rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
35 35
36if [ "$RES_IP" != "$TEST_IP" ] 36if [ "$RES_IP" != "$TEST_IP" ]
37then 37then
diff --git a/src/gns/test_gns_soa_lookup.sh b/src/gns/test_gns_soa_lookup.sh
index 2f9cc58de..82a5885c3 100755
--- a/src/gns/test_gns_soa_lookup.sh
+++ b/src/gns/test_gns_soa_lookup.sh
@@ -15,7 +15,7 @@ fi
15 15
16which timeout &> /dev/null && DO_TIMEOUT="timeout 5" 16which timeout &> /dev/null && DO_TIMEOUT="timeout 5"
17 17
18rm -rf /tmp/test-gnunet-gns-peer-1/ 18rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
19MY_EGO="myego" 19MY_EGO="myego"
20TEST_DOMAIN="homepage.$MY_EGO" 20TEST_DOMAIN="homepage.$MY_EGO"
21# some public DNS resolver we can use 21# 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.
36gnunet-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 36gnunet-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
37gnunet-identity -D $MY_EGO -c test_gns_lookup.conf 37gnunet-identity -D $MY_EGO -c test_gns_lookup.conf
38gnunet-arm -e -c test_gns_lookup.conf 38gnunet-arm -e -c test_gns_lookup.conf
39rm -rf /tmp/test-gnunet-gns-peer-1/ 39rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
40 40
41if [ "x$RES_SOA" != "x" ] 41if [ "x$RES_SOA" != "x" ]
42then 42then
diff --git a/src/gns/test_gns_txt_lookup.sh b/src/gns/test_gns_txt_lookup.sh
index 68a60c8b6..ce9b9e806 100755
--- a/src/gns/test_gns_txt_lookup.sh
+++ b/src/gns/test_gns_txt_lookup.sh
@@ -13,7 +13,7 @@ then
13 exit 77 13 exit 77
14fi 14fi
15 15
16rm -rf /tmp/test-gnunet-gns-peer-1/ 16rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
17which timeout &> /dev/null && DO_TIMEOUT="timeout 30" 17which timeout &> /dev/null && DO_TIMEOUT="timeout 30"
18TEST_TXT="GNS powered txt record data" 18TEST_TXT="GNS powered txt record data"
19MY_EGO="myego" 19MY_EGO="myego"
@@ -25,7 +25,7 @@ RES_TXT=`$DO_TIMEOUT gnunet-gns --raw -u $LABEL.$MY_EGO -t TXT -c test_gns_looku
25gnunet-namestore -z $MY_EGO -d -n $LABEL -t TXT -V "$TEST_TXT" -e never -c test_gns_lookup.conf 25gnunet-namestore -z $MY_EGO -d -n $LABEL -t TXT -V "$TEST_TXT" -e never -c test_gns_lookup.conf
26gnunet-identity -D $MY_EGO -c test_gns_lookup.conf 26gnunet-identity -D $MY_EGO -c test_gns_lookup.conf
27gnunet-arm -e -c test_gns_lookup.conf 27gnunet-arm -e -c test_gns_lookup.conf
28rm -rf /tmp/test-gnunet-gns-peer-1/ 28rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
29 29
30if [ "$RES_TXT" == "$TEST_TXT" ] 30if [ "$RES_TXT" == "$TEST_TXT" ]
31then 31then
diff --git a/src/gns/test_gns_zkey_lookup.sh b/src/gns/test_gns_zkey_lookup.sh
index 312198780..5e67e0ce2 100755
--- a/src/gns/test_gns_zkey_lookup.sh
+++ b/src/gns/test_gns_zkey_lookup.sh
@@ -14,7 +14,7 @@ then
14 exit 77 14 exit 77
15fi 15fi
16 16
17rm -rf /tmp/test-gnunet-gns-peer-1/ 17rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
18 18
19TEST_IP="127.0.0.1" 19TEST_IP="127.0.0.1"
20gnunet-arm -s -c test_gns_lookup.conf 20gnunet-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
27gnunet-namestore -z testego -d -n b -t PKEY -V $DELEGATED_PKEY -e never -c test_gns_lookup.conf 27gnunet-namestore -z testego -d -n b -t PKEY -V $DELEGATED_PKEY -e never -c test_gns_lookup.conf
28gnunet-namestore -z delegatedego -d -n www -t A -V $TEST_IP -e never -c test_gns_lookup.conf 28gnunet-namestore -z delegatedego -d -n www -t A -V $TEST_IP -e never -c test_gns_lookup.conf
29gnunet-arm -e -c test_gns_lookup.conf 29gnunet-arm -e -c test_gns_lookup.conf
30rm -rf /tmp/test-gnunet-gns-peer-1/ 30rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
31 31
32if [ "$RES_IP" == "$TEST_IP" ] 32if [ "$RES_IP" == "$TEST_IP" ]
33then 33then
diff --git a/src/gnsrecord/.gitignore b/src/gnsrecord/.gitignore
index 374abdb60..53d3bb22d 100644
--- a/src/gnsrecord/.gitignore
+++ b/src/gnsrecord/.gitignore
@@ -2,3 +2,4 @@ test_gnsrecord_block_expiration
2test_gnsrecord_crypto 2test_gnsrecord_crypto
3test_gnsrecord_serialization 3test_gnsrecord_serialization
4zonefiles 4zonefiles
5perf_gnsrecord_crypto
diff --git a/src/gnsrecord/Makefile.am b/src/gnsrecord/Makefile.am
index 2fb427c69..c83aa3307 100644
--- a/src/gnsrecord/Makefile.am
+++ b/src/gnsrecord/Makefile.am
@@ -19,7 +19,8 @@ endif
19check_PROGRAMS = \ 19check_PROGRAMS = \
20 test_gnsrecord_crypto \ 20 test_gnsrecord_crypto \
21 test_gnsrecord_serialization \ 21 test_gnsrecord_serialization \
22 test_gnsrecord_block_expiration 22 test_gnsrecord_block_expiration \
23 perf_gnsrecord_crypto
23 24
24if ENABLE_TEST_RUN 25if ENABLE_TEST_RUN
25AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset XDG_CONFIG_HOME; 26AM_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 = \
85 libgnunetgnsrecord.la \ 86 libgnunetgnsrecord.la \
86 $(top_builddir)/src/util/libgnunetutil.la 87 $(top_builddir)/src/util/libgnunetutil.la
87 88
89
90perf_gnsrecord_crypto_SOURCES = \
91 perf_gnsrecord_crypto.c
92perf_gnsrecord_crypto_LDADD = \
93 $(top_builddir)/src/testing/libgnunettesting.la \
94 libgnunetgnsrecord.la \
95 $(top_builddir)/src/util/libgnunetutil.la
diff --git a/src/gnsrecord/gnsrecord.c b/src/gnsrecord/gnsrecord.c
index 35005b5ca..ece1665fc 100644
--- a/src/gnsrecord/gnsrecord.c
+++ b/src/gnsrecord/gnsrecord.c
@@ -114,10 +114,9 @@ init ()
114void __attribute__ ((destructor)) 114void __attribute__ ((destructor))
115GNSRECORD_fini () 115GNSRECORD_fini ()
116{ 116{
117 unsigned int i;
118 struct Plugin *plugin; 117 struct Plugin *plugin;
119 118
120 for (i = 0; i < num_plugins; i++) 119 for (unsigned int i = 0; i < num_plugins; i++)
121 { 120 {
122 plugin = gns_plugins[i]; 121 plugin = gns_plugins[i];
123 GNUNET_break (NULL == 122 GNUNET_break (NULL ==
@@ -146,12 +145,11 @@ GNUNET_GNSRECORD_value_to_string (uint32_t type,
146 const void *data, 145 const void *data,
147 size_t data_size) 146 size_t data_size)
148{ 147{
149 unsigned int i;
150 struct Plugin *plugin; 148 struct Plugin *plugin;
151 char *ret; 149 char *ret;
152 150
153 init (); 151 init ();
154 for (i = 0; i < num_plugins; i++) 152 for (unsigned int i = 0; i < num_plugins; i++)
155 { 153 {
156 plugin = gns_plugins[i]; 154 plugin = gns_plugins[i];
157 if (NULL != (ret = plugin->api->value_to_string (plugin->api->cls, 155 if (NULL != (ret = plugin->api->value_to_string (plugin->api->cls,
@@ -180,11 +178,10 @@ GNUNET_GNSRECORD_string_to_value (uint32_t type,
180 void **data, 178 void **data,
181 size_t *data_size) 179 size_t *data_size)
182{ 180{
183 unsigned int i;
184 struct Plugin *plugin; 181 struct Plugin *plugin;
185 182
186 init (); 183 init ();
187 for (i = 0; i < num_plugins; i++) 184 for (unsigned int i = 0; i < num_plugins; i++)
188 { 185 {
189 plugin = gns_plugins[i]; 186 plugin = gns_plugins[i];
190 if (GNUNET_OK == plugin->api->string_to_value (plugin->api->cls, 187 if (GNUNET_OK == plugin->api->string_to_value (plugin->api->cls,
@@ -207,7 +204,6 @@ GNUNET_GNSRECORD_string_to_value (uint32_t type,
207uint32_t 204uint32_t
208GNUNET_GNSRECORD_typename_to_number (const char *dns_typename) 205GNUNET_GNSRECORD_typename_to_number (const char *dns_typename)
209{ 206{
210 unsigned int i;
211 struct Plugin *plugin; 207 struct Plugin *plugin;
212 uint32_t ret; 208 uint32_t ret;
213 209
@@ -215,7 +211,7 @@ GNUNET_GNSRECORD_typename_to_number (const char *dns_typename)
215 "ANY")) 211 "ANY"))
216 return GNUNET_GNSRECORD_TYPE_ANY; 212 return GNUNET_GNSRECORD_TYPE_ANY;
217 init (); 213 init ();
218 for (i = 0; i < num_plugins; i++) 214 for (unsigned int i = 0; i < num_plugins; i++)
219 { 215 {
220 plugin = gns_plugins[i]; 216 plugin = gns_plugins[i];
221 if (UINT32_MAX != (ret = plugin->api->typename_to_number (plugin->api->cls, 217 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)
235const char * 231const char *
236GNUNET_GNSRECORD_number_to_typename (uint32_t type) 232GNUNET_GNSRECORD_number_to_typename (uint32_t type)
237{ 233{
238 unsigned int i;
239 struct Plugin *plugin; 234 struct Plugin *plugin;
240 const char * ret; 235 const char * ret;
241 236
242 if (GNUNET_GNSRECORD_TYPE_ANY == type) 237 if (GNUNET_GNSRECORD_TYPE_ANY == type)
243 return "ANY"; 238 return "ANY";
244 init (); 239 init ();
245 for (i = 0; i < num_plugins; i++) 240 for (unsigned int i = 0; i < num_plugins; i++)
246 { 241 {
247 plugin = gns_plugins[i]; 242 plugin = gns_plugins[i];
248 if (NULL != (ret = plugin->api->number_to_typename (plugin->api->cls, 243 if (NULL != (ret = plugin->api->number_to_typename (plugin->api->cls,
diff --git a/src/gnsrecord/gnsrecord_crypto.c b/src/gnsrecord/gnsrecord_crypto.c
index cebc842f3..6d59a545a 100644
--- a/src/gnsrecord/gnsrecord_crypto.c
+++ b/src/gnsrecord/gnsrecord_crypto.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2009-2013 GNUnet e.V. 3 Copyright (C) 2009-2013, 2018 GNUnet e.V.
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -94,7 +94,7 @@ block_create (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
94 struct GNUNET_CRYPTO_EcdsaPrivateKey *dkey; 94 struct GNUNET_CRYPTO_EcdsaPrivateKey *dkey;
95 struct GNUNET_CRYPTO_SymmetricInitializationVector iv; 95 struct GNUNET_CRYPTO_SymmetricInitializationVector iv;
96 struct GNUNET_CRYPTO_SymmetricSessionKey skey; 96 struct GNUNET_CRYPTO_SymmetricSessionKey skey;
97 struct GNUNET_GNSRECORD_Data rdc[rd_count]; 97 struct GNUNET_GNSRECORD_Data rdc[GNUNET_NZL(rd_count)];
98 uint32_t rd_count_nbo; 98 uint32_t rd_count_nbo;
99 struct GNUNET_TIME_Absolute now; 99 struct GNUNET_TIME_Absolute now;
100 100
@@ -246,6 +246,7 @@ GNUNET_GNSRECORD_block_create2 (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
246 GNUNET_CRYPTO_ecdsa_key_get_public (key, 246 GNUNET_CRYPTO_ecdsa_key_get_public (key,
247 &line->pkey); 247 &line->pkey);
248 } 248 }
249#undef CSIZE
249 return block_create (key, 250 return block_create (key,
250 &line->pkey, 251 &line->pkey,
251 expire, 252 expire,
@@ -304,18 +305,21 @@ GNUNET_GNSRECORD_block_decrypt (const struct GNUNET_GNSRECORD_Block *block,
304 GNUNET_break_op (0); 305 GNUNET_break_op (0);
305 return GNUNET_SYSERR; 306 return GNUNET_SYSERR;
306 } 307 }
307 derive_block_aes_key (&iv, &skey, label, zone_key); 308 derive_block_aes_key (&iv,
309 &skey,
310 label,
311 zone_key);
308 { 312 {
309 char payload[payload_len]; 313 char payload[payload_len];
310 uint32_t rd_count; 314 uint32_t rd_count;
311 315
312 GNUNET_break (payload_len == 316 GNUNET_break (payload_len ==
313 GNUNET_CRYPTO_symmetric_decrypt (&block[1], payload_len, 317 GNUNET_CRYPTO_symmetric_decrypt (&block[1], payload_len,
314 &skey, &iv, 318 &skey, &iv,
315 payload)); 319 payload));
316 GNUNET_memcpy (&rd_count, 320 GNUNET_memcpy (&rd_count,
317 payload, 321 payload,
318 sizeof (uint32_t)); 322 sizeof (uint32_t));
319 rd_count = ntohl (rd_count); 323 rd_count = ntohl (rd_count);
320 if (rd_count > 2048) 324 if (rd_count > 2048)
321 { 325 {
@@ -324,7 +328,7 @@ GNUNET_GNSRECORD_block_decrypt (const struct GNUNET_GNSRECORD_Block *block,
324 return GNUNET_SYSERR; 328 return GNUNET_SYSERR;
325 } 329 }
326 { 330 {
327 struct GNUNET_GNSRECORD_Data rd[rd_count]; 331 struct GNUNET_GNSRECORD_Data rd[GNUNET_NZL(rd_count)];
328 unsigned int j; 332 unsigned int j;
329 struct GNUNET_TIME_Absolute now; 333 struct GNUNET_TIME_Absolute now;
330 334
@@ -359,10 +363,13 @@ GNUNET_GNSRECORD_block_decrypt (const struct GNUNET_GNSRECORD_Block *block,
359 continue; 363 continue;
360 if (rd[i].expiration_time < now.abs_value_us) 364 if (rd[i].expiration_time < now.abs_value_us)
361 include_record = GNUNET_NO; /* Shadow record is expired */ 365 include_record = GNUNET_NO; /* Shadow record is expired */
362 if ((rd[k].record_type == rd[i].record_type) 366 if ( (rd[k].record_type == rd[i].record_type) &&
363 && (rd[k].expiration_time >= now.abs_value_us) 367 (rd[k].expiration_time >= now.abs_value_us) &&
364 && (0 == (rd[k].flags & GNUNET_GNSRECORD_RF_SHADOW_RECORD))) 368 (0 == (rd[k].flags & GNUNET_GNSRECORD_RF_SHADOW_RECORD)) )
369 {
365 include_record = GNUNET_NO; /* We have a non-expired, non-shadow record of the same type */ 370 include_record = GNUNET_NO; /* We have a non-expired, non-shadow record of the same type */
371 break;
372 }
366 } 373 }
367 if (GNUNET_YES == include_record) 374 if (GNUNET_YES == include_record)
368 { 375 {
diff --git a/src/gnsrecord/gnsrecord_serialization.c b/src/gnsrecord/gnsrecord_serialization.c
index 190f62fc2..1db27464f 100644
--- a/src/gnsrecord/gnsrecord_serialization.c
+++ b/src/gnsrecord/gnsrecord_serialization.c
@@ -84,11 +84,10 @@ size_t
84GNUNET_GNSRECORD_records_get_size (unsigned int rd_count, 84GNUNET_GNSRECORD_records_get_size (unsigned int rd_count,
85 const struct GNUNET_GNSRECORD_Data *rd) 85 const struct GNUNET_GNSRECORD_Data *rd)
86{ 86{
87 unsigned int i;
88 size_t ret; 87 size_t ret;
89 88
90 ret = sizeof (struct NetworkRecord) * rd_count; 89 ret = sizeof (struct NetworkRecord) * rd_count;
91 for (i=0;i<rd_count;i++) 90 for (unsigned int i=0;i<rd_count;i++)
92 { 91 {
93 GNUNET_assert ((ret + rd[i].data_size) >= ret); 92 GNUNET_assert ((ret + rd[i].data_size) >= ret);
94 ret += rd[i].data_size; 93 ret += rd[i].data_size;
@@ -113,11 +112,10 @@ GNUNET_GNSRECORD_records_serialize (unsigned int rd_count,
113 char *dest) 112 char *dest)
114{ 113{
115 struct NetworkRecord rec; 114 struct NetworkRecord rec;
116 unsigned int i;
117 size_t off; 115 size_t off;
118 116
119 off = 0; 117 off = 0;
120 for (i=0;i<rd_count;i++) 118 for (unsigned int i=0;i<rd_count;i++)
121 { 119 {
122 LOG (GNUNET_ERROR_TYPE_DEBUG, 120 LOG (GNUNET_ERROR_TYPE_DEBUG,
123 "Serializing record %u with flags %d and expiration time %llu\n", 121 "Serializing record %u with flags %d and expiration time %llu\n",
@@ -129,17 +127,38 @@ GNUNET_GNSRECORD_records_serialize (unsigned int rd_count,
129 rec.record_type = htonl (rd[i].record_type); 127 rec.record_type = htonl (rd[i].record_type);
130 rec.flags = htonl (rd[i].flags); 128 rec.flags = htonl (rd[i].flags);
131 if (off + sizeof (rec) > dest_size) 129 if (off + sizeof (rec) > dest_size)
130 {
131 GNUNET_break (0);
132 return -1; 132 return -1;
133 }
133 GNUNET_memcpy (&dest[off], 134 GNUNET_memcpy (&dest[off],
134 &rec, 135 &rec,
135 sizeof (rec)); 136 sizeof (rec));
136 off += sizeof (rec); 137 off += sizeof (rec);
137 if (off + rd[i].data_size > dest_size) 138 if (off + rd[i].data_size > dest_size)
139 {
140 GNUNET_break (0);
138 return -1; 141 return -1;
142 }
139 GNUNET_memcpy (&dest[off], 143 GNUNET_memcpy (&dest[off],
140 rd[i].data, 144 rd[i].data,
141 rd[i].data_size); 145 rd[i].data_size);
142 off += rd[i].data_size; 146 off += rd[i].data_size;
147#if GNUNET_EXTRA_LOGGING
148 {
149 char *str;
150
151 str = GNUNET_GNSRECORD_value_to_string (rd[i].record_type,
152 rd[i].data,
153 rd[i].data_size);
154 if (NULL == str)
155 {
156 GNUNET_break_op (0);
157 return GNUNET_SYSERR;
158 }
159 GNUNET_free (str);
160 }
161#endif
143 } 162 }
144 return off; 163 return off;
145} 164}
@@ -161,24 +180,46 @@ GNUNET_GNSRECORD_records_deserialize (size_t len,
161 struct GNUNET_GNSRECORD_Data *dest) 180 struct GNUNET_GNSRECORD_Data *dest)
162{ 181{
163 struct NetworkRecord rec; 182 struct NetworkRecord rec;
164 unsigned int i;
165 size_t off; 183 size_t off;
166 184
167 off = 0; 185 off = 0;
168 for (i=0;i<rd_count;i++) 186 for (unsigned int i=0;i<rd_count;i++)
169 { 187 {
170 if (off + sizeof (rec) > len) 188 if (off + sizeof (rec) > len)
189 {
190 GNUNET_break_op (0);
171 return GNUNET_SYSERR; 191 return GNUNET_SYSERR;
172 GNUNET_memcpy (&rec, &src[off], sizeof (rec)); 192 }
193 GNUNET_memcpy (&rec,
194 &src[off],
195 sizeof (rec));
173 dest[i].expiration_time = GNUNET_ntohll (rec.expiration_time); 196 dest[i].expiration_time = GNUNET_ntohll (rec.expiration_time);
174 dest[i].data_size = ntohl ((uint32_t) rec.data_size); 197 dest[i].data_size = ntohl ((uint32_t) rec.data_size);
175 dest[i].record_type = ntohl (rec.record_type); 198 dest[i].record_type = ntohl (rec.record_type);
176 dest[i].flags = ntohl (rec.flags); 199 dest[i].flags = ntohl (rec.flags);
177 off += sizeof (rec); 200 off += sizeof (rec);
178 if (off + dest[i].data_size > len) 201 if (off + dest[i].data_size > len)
202 {
203 GNUNET_break_op (0);
179 return GNUNET_SYSERR; 204 return GNUNET_SYSERR;
205 }
180 dest[i].data = &src[off]; 206 dest[i].data = &src[off];
181 off += dest[i].data_size; 207 off += dest[i].data_size;
208#if GNUNET_EXTRA_LOGGING
209 {
210 char *str;
211
212 str = GNUNET_GNSRECORD_value_to_string (dest[i].record_type,
213 dest[i].data,
214 dest[i].data_size);
215 if (NULL == str)
216 {
217 GNUNET_break_op (0);
218 return GNUNET_SYSERR;
219 }
220 GNUNET_free (str);
221 }
222#endif
182 LOG (GNUNET_ERROR_TYPE_DEBUG, 223 LOG (GNUNET_ERROR_TYPE_DEBUG,
183 "Deserialized record %u with flags %d and expiration time %llu\n", 224 "Deserialized record %u with flags %d and expiration time %llu\n",
184 i, 225 i,
diff --git a/src/gnsrecord/perf_gnsrecord_crypto.c b/src/gnsrecord/perf_gnsrecord_crypto.c
new file mode 100644
index 000000000..ff9721006
--- /dev/null
+++ b/src/gnsrecord/perf_gnsrecord_crypto.c
@@ -0,0 +1,137 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2018 GNUnet e.V.
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/
20/**
21 * @file gnsrecord/test_gnsrecord_crypto.c
22 * @brief testcase for block creation, verification and decryption
23 */
24#include "platform.h"
25#include "gnunet_util_lib.h"
26#include "gnunet_gnsrecord_lib.h"
27
28#define ROUNDS 1000
29
30#define RECORDS 5
31
32#define TEST_RECORD_TYPE 1234
33
34#define TEST_RECORD_DATALEN 123
35
36#define TEST_RECORD_DATA 'a'
37
38#define TEST_REMOVE_RECORD_TYPE 4321
39
40#define TEST_REMOVE_RECORD_DATALEN 255
41
42#define TEST_REMOVE_RECORD_DATA 'b'
43
44
45static struct GNUNET_GNSRECORD_Data *
46create_record (int count)
47{
48 struct GNUNET_GNSRECORD_Data *rd;
49
50 rd = GNUNET_new_array (count,
51 struct GNUNET_GNSRECORD_Data);
52 for (unsigned int c = 0; c < count; c++)
53 {
54 rd[c].expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000;
55 rd[c].record_type = TEST_RECORD_TYPE;
56 rd[c].data_size = TEST_RECORD_DATALEN;
57 rd[c].data = GNUNET_malloc(TEST_RECORD_DATALEN);
58 memset ((char *) rd[c].data, TEST_RECORD_DATA, TEST_RECORD_DATALEN);
59 }
60 return rd;
61}
62
63
64static void
65run (void *cls,
66 char *const *args,
67 const char *cfgfile,
68 const struct GNUNET_CONFIGURATION_Handle *cfg)
69{
70 struct GNUNET_GNSRECORD_Block *block;
71 struct GNUNET_HashCode query;
72 struct GNUNET_GNSRECORD_Data *s_rd;
73 const char *s_name;
74 struct GNUNET_TIME_Absolute start_time;
75 struct GNUNET_CRYPTO_EcdsaPrivateKey * privkey;
76 struct GNUNET_TIME_Absolute expire;
77
78 (void) cls;
79 (void) args;
80 (void) cfgfile;
81 (void) cfg;
82 expire = GNUNET_TIME_absolute_get();
83 privkey = GNUNET_CRYPTO_ecdsa_key_create ();
84 GNUNET_assert (NULL != privkey);
85
86 /* test block creation */
87 s_name = "DUMMY.dummy.gnunet";
88 s_rd = create_record (RECORDS);
89 start_time = GNUNET_TIME_absolute_get ();
90 for (unsigned int i=0;i<ROUNDS;i++)
91 {
92 GNUNET_assert (NULL != (block =
93 GNUNET_GNSRECORD_block_create2 (privkey,
94 expire,
95 s_name,
96 s_rd,
97 RECORDS)));
98 GNUNET_GNSRECORD_query_from_private_key (privkey,
99 s_name,
100 &query);
101 GNUNET_free (block);
102 }
103 fprintf (stderr,
104 "Took %s to produce %u GNS blocks for the DHT\n",
105 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start_time),
106 GNUNET_YES),
107 ROUNDS);
108 for (unsigned int i=0;i<RECORDS;i++)
109 GNUNET_free ((void *) s_rd[i].data);
110 GNUNET_free (s_rd);
111 GNUNET_free (privkey);
112}
113
114
115int
116main (int argc, char *argv[])
117{
118 static char *const argvx[] = {
119 "perf-gnsrecord-crypto",
120 NULL
121 };
122 static struct GNUNET_GETOPT_CommandLineOption options[] = {
123 GNUNET_GETOPT_OPTION_END
124 };
125
126 if (GNUNET_OK !=
127 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
128 argvx,
129 "perf-gnsrecord-crypto",
130 "nohelp", options,
131 &run,
132 NULL))
133 return 1;
134 return 0;
135}
136
137/* end of test_gnsrecord_crypto.c */
diff --git a/src/gnsrecord/test_gnsrecord_crypto.c b/src/gnsrecord/test_gnsrecord_crypto.c
index 1df3f3730..9ba303e66 100644
--- a/src/gnsrecord/test_gnsrecord_crypto.c
+++ b/src/gnsrecord/test_gnsrecord_crypto.c
@@ -54,7 +54,7 @@ create_record (int count)
54{ 54{
55 struct GNUNET_GNSRECORD_Data *rd; 55 struct GNUNET_GNSRECORD_Data *rd;
56 56
57 rd = GNUNET_malloc (count * sizeof (struct GNUNET_GNSRECORD_Data)); 57 rd = GNUNET_new_array (count, struct GNUNET_GNSRECORD_Data);
58 for (unsigned int c = 0; c < count; c++) 58 for (unsigned int c = 0; c < count; c++)
59 { 59 {
60 rd[c].expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000; 60 rd[c].expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000;
@@ -103,11 +103,10 @@ run (void *cls,
103 struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; 103 struct GNUNET_CRYPTO_EcdsaPublicKey pubkey;
104 struct GNUNET_HashCode query_pub; 104 struct GNUNET_HashCode query_pub;
105 struct GNUNET_HashCode query_priv; 105 struct GNUNET_HashCode query_priv;
106 struct GNUNET_TIME_Absolute expire = GNUNET_TIME_absolute_get();
106 107
107 privkey = GNUNET_CRYPTO_ecdsa_key_create (); 108 privkey = GNUNET_CRYPTO_ecdsa_key_create ();
108 GNUNET_assert (NULL != privkey); 109 GNUNET_assert (NULL != privkey);
109 struct GNUNET_TIME_Absolute expire = GNUNET_TIME_absolute_get();
110
111 /* get public key */ 110 /* get public key */
112 GNUNET_CRYPTO_ecdsa_key_get_public (privkey, 111 GNUNET_CRYPTO_ecdsa_key_get_public (privkey,
113 &pubkey); 112 &pubkey);
@@ -142,6 +141,7 @@ run (void *cls,
142 &rd_decrypt_cb, 141 &rd_decrypt_cb,
143 s_name)); 142 s_name));
144 GNUNET_free (block); 143 GNUNET_free (block);
144 GNUNET_free (privkey);
145} 145}
146 146
147 147
diff --git a/src/hostlist/test_gnunet_daemon_hostlist.c b/src/hostlist/test_gnunet_daemon_hostlist.c
index eb4a85115..dcdabaf6b 100644
--- a/src/hostlist/test_gnunet_daemon_hostlist.c
+++ b/src/hostlist/test_gnunet_daemon_hostlist.c
@@ -265,16 +265,22 @@ main (int argc, char *argv[])
265{ 265{
266 int ret; 266 int ret;
267 267
268 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-1"); 268 GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_peer1.conf",
269 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-2"); 269 "GNUNET_TEST_HOME");
270 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist"); 270 GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_peer2.conf",
271 "GNUNET_TEST_HOME");
272 GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_data.conf",
273 "GNUNET_TEST_HOME");
271 GNUNET_log_setup ("test-gnunet-daemon-hostlist", 274 GNUNET_log_setup ("test-gnunet-daemon-hostlist",
272 "WARNING", 275 "WARNING",
273 NULL); 276 NULL);
274 ret = check (); 277 ret = check ();
275 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-1"); 278 GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_peer1.conf",
276 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-2"); 279 "GNUNET_TEST_HOME");
277 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist"); 280 GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_peer2.conf",
281 "GNUNET_TEST_HOME");
282 GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_data.conf",
283 "GNUNET_TEST_HOME");
278 return ret; 284 return ret;
279} 285}
280 286
diff --git a/src/hostlist/test_gnunet_daemon_hostlist_learning.c b/src/hostlist/test_gnunet_daemon_hostlist_learning.c
index 88ad22a1a..799ffc3ff 100644
--- a/src/hostlist/test_gnunet_daemon_hostlist_learning.c
+++ b/src/hostlist/test_gnunet_daemon_hostlist_learning.c
@@ -562,14 +562,18 @@ main (int argc, char *argv[])
562{ 562{
563 int ret; 563 int ret;
564 564
565 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-1"); 565 GNUNET_DISK_purge_cfg_dir ("test_learning_learn_peer.conf",
566 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-2"); 566 "GNUNET_TEST_HOME");
567 GNUNET_DISK_purge_cfg_dir ("test_learning_adv_peer.conf",
568 "GNUNET_TEST_HOME");
567 GNUNET_log_setup ("test-gnunet-daemon-hostlist", 569 GNUNET_log_setup ("test-gnunet-daemon-hostlist",
568 "WARNING", 570 "WARNING",
569 NULL); 571 NULL);
570 ret = check (); 572 ret = check ();
571 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-1"); 573 GNUNET_DISK_purge_cfg_dir ("test_learning_learn_peer.conf",
572 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-2"); 574 "GNUNET_TEST_HOME");
575 GNUNET_DISK_purge_cfg_dir ("test_learning_adv_peer.conf",
576 "GNUNET_TEST_HOME");
573 if (GNUNET_YES == 577 if (GNUNET_YES ==
574 GNUNET_DISK_file_test ("hostlists_learn_peer.file")) 578 GNUNET_DISK_file_test ("hostlists_learn_peer.file"))
575 { 579 {
diff --git a/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c b/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c
index 2ebc780a7..2ab55b668 100644
--- a/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c
+++ b/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c
@@ -242,9 +242,12 @@ main (int argcx,
242 GNUNET_GETOPT_OPTION_END 242 GNUNET_GETOPT_OPTION_END
243 }; 243 };
244 244
245 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-1"); 245 GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_peer1.conf",
246 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-2"); 246 "GNUNET_TEST_HOME");
247 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-3"); 247 GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_peer2.conf",
248 "GNUNET_TEST_HOME");
249 GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_data.conf",
250 "GNUNET_TEST_HOME");
248 GNUNET_log_setup ("test-gnunet-daemon-hostlist", 251 GNUNET_log_setup ("test-gnunet-daemon-hostlist",
249 "WARNING", 252 "WARNING",
250 NULL); 253 NULL);
@@ -272,9 +275,12 @@ main (int argcx,
272 "%s", 275 "%s",
273 ".\n"); 276 ".\n");
274 } 277 }
275 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-1"); 278 GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_peer1.conf",
276 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-2"); 279 "GNUNET_TEST_HOME");
277 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-3"); 280 GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_peer2.conf",
281 "GNUNET_TEST_HOME");
282 GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_data.conf",
283 "GNUNET_TEST_HOME");
278 return ok; 284 return ok;
279} 285}
280 286
diff --git a/src/identity-provider/identity_provider_api.c b/src/identity-provider/identity_provider_api.c
index 47217442a..6d30f9e2a 100644
--- a/src/identity-provider/identity_provider_api.c
+++ b/src/identity-provider/identity_provider_api.c
@@ -71,7 +71,7 @@ struct GNUNET_IDENTITY_PROVIDER_Operation
71 * Attribute result callback 71 * Attribute result callback
72 */ 72 */
73 GNUNET_IDENTITY_PROVIDER_AttributeResult ar_cb; 73 GNUNET_IDENTITY_PROVIDER_AttributeResult ar_cb;
74 74
75 /** 75 /**
76 * Revocation result callback 76 * Revocation result callback
77 */ 77 */
@@ -613,7 +613,7 @@ handle_attribute_result (void *cls,
613 it->finish_cb (it->finish_cb_cls); 613 it->finish_cb (it->finish_cb_cls);
614 free_it (it); 614 free_it (it);
615 } 615 }
616 if (NULL != op) 616 if (NULL != op)
617 { 617 {
618 if (NULL != op->ar_cb) 618 if (NULL != op->ar_cb)
619 op->ar_cb (op->cls, 619 op->ar_cb (op->cls,
@@ -953,7 +953,7 @@ GNUNET_IDENTITY_PROVIDER_attribute_store (struct GNUNET_IDENTITY_PROVIDER_Handle
953 953
954 954
955/** 955/**
956 * List all attributes for a local identity. 956 * List all attributes for a local identity.
957 * This MUST lock the `struct GNUNET_IDENTITY_PROVIDER_Handle` 957 * This MUST lock the `struct GNUNET_IDENTITY_PROVIDER_Handle`
958 * for any other calls than #GNUNET_IDENTITY_PROVIDER_get_attributes_next() and 958 * for any other calls than #GNUNET_IDENTITY_PROVIDER_get_attributes_next() and
959 * #GNUNET_IDENTITY_PROVIDER_get_attributes_stop. @a proc will be called once 959 * #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 *
1370 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_REVOKE_TICKET); 1370 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_REVOKE_TICKET);
1371 msg->id = htonl (rid); 1371 msg->id = htonl (rid);
1372 msg->identity = *identity; 1372 msg->identity = *identity;
1373 memcpy (&msg[1], 1373 GNUNET_memcpy (&msg[1],
1374 ticket, 1374 ticket,
1375 sizeof (struct GNUNET_IDENTITY_PROVIDER_Ticket)); 1375 sizeof (struct GNUNET_IDENTITY_PROVIDER_Ticket));
1376 if (NULL == h->mq) 1376 if (NULL == h->mq)
1377 op->env = env; 1377 op->env = env;
1378 else 1378 else
diff --git a/src/include/gnunet_disk_lib.h b/src/include/gnunet_disk_lib.h
index be2885460..114a22052 100644
--- a/src/include/gnunet_disk_lib.h
+++ b/src/include/gnunet_disk_lib.h
@@ -709,6 +709,18 @@ GNUNET_DISK_directory_remove (const char *filename);
709 709
710 710
711/** 711/**
712 * Remove the directory given under @a option in
713 * section [PATHS] in configuration under @a cfg_filename
714 *
715 * @param cfg_filename configuration file to parse
716 * @param option option with the dir name to purge
717 */
718void
719GNUNET_DISK_purge_cfg_dir (const char *cfg_filename,
720 const char *option);
721
722
723/**
712 * Implementation of "mkdir -p" 724 * Implementation of "mkdir -p"
713 * 725 *
714 * @param dir the directory to create 726 * @param dir the directory to create
diff --git a/src/include/gnunet_sq_lib.h b/src/include/gnunet_sq_lib.h
index f3adbc4c2..61fd5299a 100644
--- a/src/include/gnunet_sq_lib.h
+++ b/src/include/gnunet_sq_lib.h
@@ -446,6 +446,125 @@ void
446GNUNET_SQ_cleanup_result (struct GNUNET_SQ_ResultSpec *rs); 446GNUNET_SQ_cleanup_result (struct GNUNET_SQ_ResultSpec *rs);
447 447
448 448
449
450/* ******************** sq_prepare.c functions ************** */
451
452
453/**
454 * Information needed to run a list of SQL statements using
455 * #GNUNET_SQ_exec_statements().
456 */
457struct GNUNET_SQ_PrepareStatement {
458
459 /**
460 * Actual SQL statement.
461 */
462 const char *sql;
463
464 /**
465 * Where to store handle?
466 */
467 sqlite3_stmt **pstmt;
468
469};
470
471
472/**
473 * Terminator for executable statement list.
474 */
475#define GNUNET_SQ_PREPARE_END { NULL, NULL }
476
477
478/**
479 * Create a `struct GNUNET_SQ_PrepareStatement`
480 *
481 * @param sql actual SQL statement
482 * @param pstmt where to store the handle
483 * @return initialized struct
484 */
485struct GNUNET_SQ_PrepareStatement
486GNUNET_SQ_make_prepare (const char *sql,
487 sqlite3_stmt **pstmt);
488
489
490
491/**
492 * Prepare all statements given in the (NULL,NULL)-terminated
493 * array at @a ps
494 *
495 * @param dbh database handle
496 * @param ps array of statements to prepare
497 * @return #GNUNET_OK on success
498 */
499int
500GNUNET_SQ_prepare (sqlite3 *dbh,
501 const struct GNUNET_SQ_PrepareStatement *ps);
502
503
504/* ******************** sq_exec.c functions ************** */
505
506
507/**
508 * Information needed to run a list of SQL statements using
509 * #GNUNET_SQ_exec_statements().
510 */
511struct GNUNET_SQ_ExecuteStatement {
512
513 /**
514 * Actual SQL statement.
515 */
516 const char *sql;
517
518 /**
519 * Should we ignore errors?
520 */
521 int ignore_errors;
522
523};
524
525
526/**
527 * Terminator for executable statement list.
528 */
529#define GNUNET_SQ_EXECUTE_STATEMENT_END { NULL, GNUNET_SYSERR }
530
531
532/**
533 * Create a `struct GNUNET_SQ_ExecuteStatement` where errors are fatal.
534 *
535 * @param sql actual SQL statement
536 * @return initialized struct
537 */
538struct GNUNET_SQ_ExecuteStatement
539GNUNET_SQ_make_execute (const char *sql);
540
541
542/**
543 * Create a `struct GNUNET_SQ_ExecuteStatement` where errors should
544 * be tolerated.
545 *
546 * @param sql actual SQL statement
547 * @return initialized struct
548 */
549struct GNUNET_SQ_ExecuteStatement
550GNUNET_SQ_make_try_execute (const char *sql);
551
552
553/**
554 * Request execution of an array of statements @a es from Postgres.
555 *
556 * @param dbh database to execute the statements over
557 * @param es #GNUNET_PQ_PREPARED_STATEMENT_END-terminated array of prepared
558 * statements.
559 * @return #GNUNET_OK on success (modulo statements where errors can be ignored)
560 * #GNUNET_SYSERR on error
561 */
562int
563GNUNET_SQ_exec_statements (sqlite3 *dbh,
564 const struct GNUNET_SQ_ExecuteStatement *es);
565
566
567
449#endif /* GNUNET_SQ_LIB_H_ */ 568#endif /* GNUNET_SQ_LIB_H_ */
450 569
451/* end of include/gnunet_sq_lib.h */ 570/* end of include/gnunet_sq_lib.h */
diff --git a/src/multicast/test_multicast_2peers.c b/src/multicast/test_multicast_2peers.c
index 8ce4d585f..ad1a48d6c 100644
--- a/src/multicast/test_multicast_2peers.c
+++ b/src/multicast/test_multicast_2peers.c
@@ -223,8 +223,11 @@ origin_notify (void *cls,
223 void *data) 223 void *data)
224{ 224{
225 char text[] = "pong"; 225 char text[] = "pong";
226
226 *data_size = strlen(text)+1; 227 *data_size = strlen(text)+1;
227 memcpy(data, text, *data_size); 228 GNUNET_memcpy (data,
229 text,
230 *data_size);
228 231
229 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "origin sends (to all): %s\n", text); 232 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "origin sends (to all): %s\n", text);
230 233
diff --git a/src/multicast/test_multicast_multipeer.c b/src/multicast/test_multicast_multipeer.c
index d1ed1cb39..96e86cbb4 100644
--- a/src/multicast/test_multicast_multipeer.c
+++ b/src/multicast/test_multicast_multipeer.c
@@ -54,7 +54,7 @@ enum pingpong
54struct pingpong_msg 54struct pingpong_msg
55{ 55{
56 int peer; 56 int peer;
57 enum pingpong msg; 57 enum pingpong msg;
58}; 58};
59 59
60static void service_connect (void *cls, 60static void service_connect (void *cls,
@@ -143,13 +143,13 @@ member_join_request (void *cls,
143{ 143{
144 struct MulticastPeerContext *mc_peer = (struct MulticastPeerContext*)cls; 144 struct MulticastPeerContext *mc_peer = (struct MulticastPeerContext*)cls;
145 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 145 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
146 "Peer #%u (%s) sent a join request.\n", 146 "Peer #%u (%s) sent a join request.\n",
147 mc_peer->peer, 147 mc_peer->peer,
148 GNUNET_i2s (multicast_peers[mc_peer->peer]->id)); 148 GNUNET_i2s (multicast_peers[mc_peer->peer]->id));
149} 149}
150 150
151 151
152static int 152static int
153notify (void *cls, 153notify (void *cls,
154 size_t *data_size, 154 size_t *data_size,
155 void *data) 155 void *data)
@@ -163,7 +163,7 @@ notify (void *cls,
163 *data_size = sizeof (struct pingpong_msg); 163 *data_size = sizeof (struct pingpong_msg);
164 GNUNET_memcpy(data, pp_msg, *data_size); 164 GNUNET_memcpy(data, pp_msg, *data_size);
165 165
166 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 166 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
167 "Peer #%u sents ping to origin\n", mc_peer->peer); 167 "Peer #%u sents ping to origin\n", mc_peer->peer);
168 168
169 return GNUNET_YES; 169 return GNUNET_YES;
@@ -179,20 +179,20 @@ member_join_decision (void *cls,
179 const struct GNUNET_MessageHeader *join_msg) 179 const struct GNUNET_MessageHeader *join_msg)
180{ 180{
181 struct MulticastPeerContext *mc_peer = (struct MulticastPeerContext*)cls; 181 struct MulticastPeerContext *mc_peer = (struct MulticastPeerContext*)cls;
182 182
183 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 183 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
184 "Peer #%u (%s) received a decision from origin: %s\n", 184 "Peer #%u (%s) received a decision from origin: %s\n",
185 mc_peer->peer, 185 mc_peer->peer,
186 GNUNET_i2s (multicast_peers[mc_peer->peer]->id), 186 GNUNET_i2s (multicast_peers[mc_peer->peer]->id),
187 (GNUNET_YES == is_admitted)?"accepted":"rejected"); 187 (GNUNET_YES == is_admitted)?"accepted":"rejected");
188 188
189 if (GNUNET_YES == is_admitted) 189 if (GNUNET_YES == is_admitted)
190 { 190 {
191 GNUNET_MULTICAST_member_to_origin (members[mc_peer->peer], 191 GNUNET_MULTICAST_member_to_origin (members[mc_peer->peer],
192 0, 192 0,
193 notify, 193 notify,
194 cls); 194 cls);
195 195
196 } 196 }
197} 197}
198 198
@@ -236,7 +236,7 @@ member_disconnected_cb (void *cls)
236 236
237 237
238static void 238static void
239member_message (void *cls, 239member_message (void *cls,
240 const struct GNUNET_MULTICAST_MessageHeader *msg) 240 const struct GNUNET_MULTICAST_MessageHeader *msg)
241{ 241{
242 struct MulticastPeerContext *mc_peer = (struct MulticastPeerContext*)cls; 242 struct MulticastPeerContext *mc_peer = (struct MulticastPeerContext*)cls;
@@ -245,7 +245,7 @@ member_message (void *cls,
245 if (PONG == pp_msg->msg && mc_peer->peer == pp_msg->peer) 245 if (PONG == pp_msg->msg && mc_peer->peer == pp_msg->peer)
246 { 246 {
247 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 247 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
248 "peer #%i (%s) receives a pong\n", 248 "peer #%i (%s) receives a pong\n",
249 mc_peer->peer, 249 mc_peer->peer,
250 GNUNET_i2s (multicast_peers[mc_peer->peer]->id)); 250 GNUNET_i2s (multicast_peers[mc_peer->peer]->id));
251 mc_peer->test_ok = GNUNET_OK; 251 mc_peer->test_ok = GNUNET_OK;
@@ -269,9 +269,9 @@ origin_join_request (void *cls,
269 269
270 uint8_t data_size = ntohs (join_msg->size); 270 uint8_t data_size = ntohs (join_msg->size);
271 271
272 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 272 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
273 "origin got a join request...\n"); 273 "origin got a join request...\n");
274 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 274 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
275 "origin receives: '%s'\n", (char *)&join_msg[1]); 275 "origin receives: '%s'\n", (char *)&join_msg[1]);
276 276
277 char data[] = "Come in!"; 277 char data[] = "Come in!";
@@ -281,7 +281,7 @@ origin_join_request (void *cls,
281 join_resp->type = htons (123); 281 join_resp->type = htons (123);
282 GNUNET_memcpy (&join_resp[1], data, data_size); 282 GNUNET_memcpy (&join_resp[1], data, data_size);
283 283
284 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 284 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
285 "origin sends: '%s'\n", data); 285 "origin sends: '%s'\n", data);
286 286
287 GNUNET_MULTICAST_join_decision (jh, 287 GNUNET_MULTICAST_join_decision (jh,
@@ -311,7 +311,7 @@ origin_replay_msg (void *cls,
311 uint64_t message_id, 311 uint64_t message_id,
312 uint64_t fragment_offset, 312 uint64_t fragment_offset,
313 uint64_t flags, 313 uint64_t flags,
314 struct GNUNET_MULTICAST_ReplayHandle *rh) 314 struct GNUNET_MULTICAST_ReplayHandle *rh)
315{ 315{
316 316
317 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "origin replay msg\n"); 317 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "origin replay msg\n");
@@ -319,8 +319,8 @@ origin_replay_msg (void *cls,
319 319
320 320
321static int 321static int
322origin_notify (void *cls, 322origin_notify (void *cls,
323 size_t *data_size, 323 size_t *data_size,
324 void *data) 324 void *data)
325{ 325{
326 struct pingpong_msg *rcv_pp_msg = (struct pingpong_msg*)cls; 326 struct pingpong_msg *rcv_pp_msg = (struct pingpong_msg*)cls;
@@ -329,11 +329,11 @@ origin_notify (void *cls,
329 pp_msg->peer = rcv_pp_msg->peer; 329 pp_msg->peer = rcv_pp_msg->peer;
330 pp_msg->msg = PONG; 330 pp_msg->msg = PONG;
331 *data_size = sizeof (struct pingpong_msg); 331 *data_size = sizeof (struct pingpong_msg);
332 memcpy(data, pp_msg, *data_size); 332 GNUNET_memcpy(data, pp_msg, *data_size);
333 333
334 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "origin sends pong\n"); 334 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "origin sends pong\n");
335 335
336 return GNUNET_YES; 336 return GNUNET_YES;
337} 337}
338 338
339 339
@@ -345,7 +345,7 @@ origin_request (void *cls,
345 345
346 req++; 346 req++;
347 struct pingpong_msg *pp_msg = (struct pingpong_msg *) req; 347 struct pingpong_msg *pp_msg = (struct pingpong_msg *) req;
348 348
349 if (1 != pp_msg->msg) { 349 if (1 != pp_msg->msg) {
350 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "origin didn't reveice a correct request"); 350 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "origin didn't reveice a correct request");
351 } 351 }
@@ -360,7 +360,7 @@ origin_request (void *cls,
360 360
361static void 361static void
362origin_message (void *cls, 362origin_message (void *cls,
363 const struct GNUNET_MULTICAST_MessageHeader *msg) 363 const struct GNUNET_MULTICAST_MessageHeader *msg)
364{ 364{
365 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "origin message msg\n"); 365 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "origin message msg\n");
366} 366}
@@ -386,7 +386,7 @@ multicast_connect (void *cls,
386 { 386 {
387 group_key = GNUNET_CRYPTO_eddsa_key_create (); 387 group_key = GNUNET_CRYPTO_eddsa_key_create ();
388 GNUNET_CRYPTO_eddsa_key_get_public (group_key, &group_pub_key); 388 GNUNET_CRYPTO_eddsa_key_get_public (group_key, &group_pub_key);
389 389
390 GNUNET_CRYPTO_hash (&group_pub_key, sizeof (group_pub_key), &group_pub_key_hash); 390 GNUNET_CRYPTO_hash (&group_pub_key, sizeof (group_pub_key), &group_pub_key_hash);
391 origin = GNUNET_MULTICAST_origin_start (cfg, 391 origin = GNUNET_MULTICAST_origin_start (cfg,
392 group_key, 392 group_key,
@@ -414,7 +414,7 @@ multicast_connect (void *cls,
414 { 414 {
415 multicast_peer->key = GNUNET_CRYPTO_ecdsa_key_create (); 415 multicast_peer->key = GNUNET_CRYPTO_ecdsa_key_create ();
416 416
417 sprintf(data, "Hi, I am peer #%u (%s). Can I enter?", 417 sprintf(data, "Hi, I am peer #%u (%s). Can I enter?",
418 multicast_peer->peer, 418 multicast_peer->peer,
419 GNUNET_i2s (multicast_peers[multicast_peer->peer]->id)); 419 GNUNET_i2s (multicast_peers[multicast_peer->peer]->id));
420 uint8_t data_size = strlen (data) + 1; 420 uint8_t data_size = strlen (data) + 1;
@@ -424,7 +424,7 @@ multicast_connect (void *cls,
424 GNUNET_memcpy (&join_msg[1], data, data_size); 424 GNUNET_memcpy (&join_msg[1], data, data_size);
425 425
426 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 426 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
427 "Peer #%u (%s) tries to join multicast group %s\n", 427 "Peer #%u (%s) tries to join multicast group %s\n",
428 multicast_peer->peer, 428 multicast_peer->peer,
429 GNUNET_i2s (multicast_peers[multicast_peer->peer]->id), 429 GNUNET_i2s (multicast_peers[multicast_peer->peer]->id),
430 GNUNET_h2s (&group_pub_key_hash)); 430 GNUNET_h2s (&group_pub_key_hash));
@@ -465,12 +465,12 @@ peer_information_cb (void *cls,
465 multicast_peers[mc_peer->peer]->id = pinfo->result.id; 465 multicast_peers[mc_peer->peer]->id = pinfo->result.id;
466 466
467 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 467 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
468 "Got peer information of %s (%s)\n", 468 "Got peer information of %s (%s)\n",
469 (0 == mc_peer->peer)? "origin" : "member", 469 (0 == mc_peer->peer)? "origin" : "member",
470 GNUNET_i2s (pinfo->result.id)); 470 GNUNET_i2s (pinfo->result.id));
471 471
472 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 472 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
473 "Create peer #%u (%s)\n", 473 "Create peer #%u (%s)\n",
474 mc_peer->peer, 474 mc_peer->peer,
475 GNUNET_i2s (multicast_peers[mc_peer->peer]->id)); 475 GNUNET_i2s (multicast_peers[mc_peer->peer]->id));
476 476
@@ -479,7 +479,7 @@ peer_information_cb (void *cls,
479 /* connect to multicast service of members */ 479 /* connect to multicast service of members */
480 op[mc_peer->peer] = 480 op[mc_peer->peer] =
481 GNUNET_TESTBED_service_connect (/* Closure for operation */ 481 GNUNET_TESTBED_service_connect (/* Closure for operation */
482 NULL, 482 NULL,
483 /* The peer whose service to connect to */ 483 /* The peer whose service to connect to */
484 peers[mc_peer->peer], 484 peers[mc_peer->peer],
485 /* The name of the service */ 485 /* The name of the service */
@@ -508,8 +508,8 @@ service_connect (void *cls,
508 508
509 if (NULL == ca_result) 509 if (NULL == ca_result)
510 { 510 {
511 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 511 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
512 "Connection adapter not created for peer #%u (%s)\n", 512 "Connection adapter not created for peer #%u (%s)\n",
513 mc_peer->peer, 513 mc_peer->peer,
514 GNUNET_i2s (multicast_peers[mc_peer->peer]->id)); 514 GNUNET_i2s (multicast_peers[mc_peer->peer]->id));
515 515
@@ -519,8 +519,8 @@ service_connect (void *cls,
519 519
520 if (0 == mc_peer->peer) 520 if (0 == mc_peer->peer)
521 { 521 {
522 // Get GNUnet identity of members 522 // Get GNUnet identity of members
523 for (int i = 0; i<PEERS_REQUESTED; i++) 523 for (int i = 0; i<PEERS_REQUESTED; i++)
524 { 524 {
525 pi_op[i] = GNUNET_TESTBED_peer_get_information (peers[i], 525 pi_op[i] = GNUNET_TESTBED_peer_get_information (peers[i],
526 GNUNET_TESTBED_PIT_IDENTITY, 526 GNUNET_TESTBED_PIT_IDENTITY,
@@ -547,7 +547,7 @@ service_connect (void *cls,
547 * @param PEERS_REQUESTED size of the 'peers' array 547 * @param PEERS_REQUESTED size of the 'peers' array
548 * @param links_succeeded number of links between peers that were created 548 * @param links_succeeded number of links between peers that were created
549 * @param links_failed number of links testbed was unable to establish 549 * @param links_failed number of links testbed was unable to establish
550 */ 550 */
551static void 551static void
552testbed_master (void *cls, 552testbed_master (void *cls,
553 struct GNUNET_TESTBED_RunHandle *h, 553 struct GNUNET_TESTBED_RunHandle *h,
@@ -562,7 +562,7 @@ testbed_master (void *cls,
562 multicast_peers = GNUNET_new_array (PEERS_REQUESTED, struct MulticastPeerContext*); 562 multicast_peers = GNUNET_new_array (PEERS_REQUESTED, struct MulticastPeerContext*);
563 563
564 // Create test contexts for members 564 // Create test contexts for members
565 for (int i = 0; i<PEERS_REQUESTED; i++) 565 for (int i = 0; i<PEERS_REQUESTED; i++)
566 { 566 {
567 multicast_peers[i] = GNUNET_new (struct MulticastPeerContext); 567 multicast_peers[i] = GNUNET_new (struct MulticastPeerContext);
568 multicast_peers[i]->peer = i; 568 multicast_peers[i]->peer = i;
@@ -604,7 +604,7 @@ main (int argc, char *argv[])
604 int ret; 604 int ret;
605 char const *config_file; 605 char const *config_file;
606 606
607 if (strstr (argv[0], "_line") != NULL) 607 if (strstr (argv[0], "_line") != NULL)
608 { 608 {
609 config_file = "test_multicast_line.conf"; 609 config_file = "test_multicast_line.conf";
610 } 610 }
@@ -612,7 +612,7 @@ main (int argc, char *argv[])
612 { 612 {
613 config_file = "test_multicast_star.conf"; 613 config_file = "test_multicast_star.conf";
614 } 614 }
615 else 615 else
616 { 616 {
617 config_file = "test_multicast_star.conf"; 617 config_file = "test_multicast_star.conf";
618 } 618 }
@@ -620,19 +620,19 @@ main (int argc, char *argv[])
620 result = GNUNET_SYSERR; 620 result = GNUNET_SYSERR;
621 ret = 621 ret =
622 GNUNET_TESTBED_test_run ("test-multicast-multipeer", 622 GNUNET_TESTBED_test_run ("test-multicast-multipeer",
623 config_file, 623 config_file,
624 /* number of peers to start */ 624 /* number of peers to start */
625 PEERS_REQUESTED, 625 PEERS_REQUESTED,
626 /* Event mask - set to 0 for no event notifications */ 626 /* Event mask - set to 0 for no event notifications */
627 0LL, 627 0LL,
628 /* Controller event callback */ 628 /* Controller event callback */
629 NULL, 629 NULL,
630 /* Closure for controller event callback */ 630 /* Closure for controller event callback */
631 NULL, 631 NULL,
632 /* called when testbed setup is complete */ 632 /* called when testbed setup is complete */
633 testbed_master, 633 testbed_master,
634 /* Closure for the test_master callback */ 634 /* Closure for the test_master callback */
635 NULL); 635 NULL);
636 if ( (GNUNET_OK != ret) || (GNUNET_OK != result) ) 636 if ( (GNUNET_OK != ret) || (GNUNET_OK != result) )
637 return 1; 637 return 1;
638 return 0; 638 return 0;
diff --git a/src/namestore/gnunet-namestore.c b/src/namestore/gnunet-namestore.c
index 32b1a39d0..753ee79d1 100644
--- a/src/namestore/gnunet-namestore.c
+++ b/src/namestore/gnunet-namestore.c
@@ -80,6 +80,11 @@ static struct GNUNET_NAMESTORE_QueueEntry *add_qe_uri;
80static struct GNUNET_NAMESTORE_QueueEntry *add_qe; 80static struct GNUNET_NAMESTORE_QueueEntry *add_qe;
81 81
82/** 82/**
83 * Queue entry for the 'lookup' operation.
84 */
85static struct GNUNET_NAMESTORE_QueueEntry *get_qe;
86
87/**
83 * Queue entry for the 'reverse lookup' operation (in combination with a name). 88 * Queue entry for the 'reverse lookup' operation (in combination with a name).
84 */ 89 */
85static struct GNUNET_NAMESTORE_QueueEntry *reverse_qe; 90static struct GNUNET_NAMESTORE_QueueEntry *reverse_qe;
@@ -234,6 +239,11 @@ do_shutdown (void *cls)
234 GNUNET_NAMESTORE_cancel (add_qe_uri); 239 GNUNET_NAMESTORE_cancel (add_qe_uri);
235 add_qe_uri = NULL; 240 add_qe_uri = NULL;
236 } 241 }
242 if (NULL != get_qe)
243 {
244 GNUNET_NAMESTORE_cancel (get_qe);
245 get_qe = NULL;
246 }
237 if (NULL != del_qe) 247 if (NULL != del_qe)
238 { 248 {
239 GNUNET_NAMESTORE_cancel (del_qe); 249 GNUNET_NAMESTORE_cancel (del_qe);
@@ -271,6 +281,7 @@ test_finished ()
271{ 281{
272 if ( (NULL == add_qe) && 282 if ( (NULL == add_qe) &&
273 (NULL == add_qe_uri) && 283 (NULL == add_qe_uri) &&
284 (NULL == get_qe) &&
274 (NULL == del_qe) && 285 (NULL == del_qe) &&
275 (NULL == reverse_qe) && 286 (NULL == reverse_qe) &&
276 (NULL == list_it) ) 287 (NULL == list_it) )
@@ -492,6 +503,30 @@ display_record_monitor (void *cls,
492 503
493 504
494/** 505/**
506 * Process a record that was stored in the namestore.
507 *
508 * @param cls closure
509 * @param zone_key private key of the zone
510 * @param rname name that is being mapped (at most 255 characters long)
511 * @param rd_len number of entries in @a rd array
512 * @param rd array of records with data to store
513 */
514static void
515display_record_lookup (void *cls,
516 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
517 const char *rname,
518 unsigned int rd_len,
519 const struct GNUNET_GNSRECORD_Data *rd)
520{
521 get_qe = NULL;
522 display_record (rname,
523 rd_len,
524 rd);
525 test_finished ();
526}
527
528
529/**
495 * Function called once we are in sync in monitor mode. 530 * Function called once we are in sync in monitor mode.
496 * 531 *
497 * @param cls NULL 532 * @param cls NULL
@@ -522,12 +557,29 @@ monitor_error_cb (void *cls)
522 557
523 558
524/** 559/**
525 * Function called if lookup fails. 560 * Function called on errors while monitoring.
561 *
562 * @param cls NULL
526 */ 563 */
527static void 564static void
528lookup_error_cb (void *cls) 565lookup_error_cb (void *cls)
529{ 566{
530 (void) cls; 567 (void) cls;
568 get_qe = NULL;
569 FPRINTF (stderr,
570 "%s",
571 "Failed to lookup record.\n");
572 test_finished ();
573}
574
575
576/**
577 * Function called if lookup fails.
578 */
579static void
580add_error_cb (void *cls)
581{
582 (void) cls;
531 add_qe = NULL; 583 add_qe = NULL;
532 GNUNET_break (0); 584 GNUNET_break (0);
533 ret = 1; 585 ret = 1;
@@ -970,7 +1022,7 @@ identity_cb (void *cls,
970 add_qe = GNUNET_NAMESTORE_records_lookup (ns, 1022 add_qe = GNUNET_NAMESTORE_records_lookup (ns,
971 &zone_pkey, 1023 &zone_pkey,
972 name, 1024 name,
973 &lookup_error_cb, 1025 &add_error_cb,
974 NULL, 1026 NULL,
975 &get_existing_record, 1027 &get_existing_record,
976 NULL); 1028 NULL);
@@ -996,14 +1048,23 @@ identity_cb (void *cls,
996 } 1048 }
997 if (list) 1049 if (list)
998 { 1050 {
999 list_it = GNUNET_NAMESTORE_zone_iteration_start (ns, 1051 if (NULL != name)
1000 &zone_pkey, 1052 get_qe = GNUNET_NAMESTORE_records_lookup (ns,
1001 &zone_iteration_error_cb, 1053 &zone_pkey,
1002 NULL, 1054 name,
1003 &display_record_iterator, 1055 &lookup_error_cb,
1004 NULL, 1056 NULL,
1005 &zone_iteration_finished, 1057 &display_record_lookup,
1006 NULL); 1058 NULL);
1059 else
1060 list_it = GNUNET_NAMESTORE_zone_iteration_start (ns,
1061 &zone_pkey,
1062 &zone_iteration_error_cb,
1063 NULL,
1064 &display_record_iterator,
1065 NULL,
1066 &zone_iteration_finished,
1067 NULL);
1007 } 1068 }
1008 if (NULL != reverse_pkey) 1069 if (NULL != reverse_pkey)
1009 { 1070 {
diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c
index f47c8776b..8e88558de 100644
--- a/src/namestore/gnunet-service-namestore.c
+++ b/src/namestore/gnunet-service-namestore.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2012, 2013, 2014 GNUnet e.V. 3 Copyright (C) 2012, 2013, 2014, 2018 GNUnet e.V.
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -23,6 +23,9 @@
23 * @brief namestore for the GNUnet naming system 23 * @brief namestore for the GNUnet naming system
24 * @author Matthias Wachs 24 * @author Matthias Wachs
25 * @author Christian Grothoff 25 * @author Christian Grothoff
26 *
27 * TODO:
28 * - run testcases, make sure everything works!
26 */ 29 */
27#include "platform.h" 30#include "platform.h"
28#include "gnunet_util_lib.h" 31#include "gnunet_util_lib.h"
@@ -37,6 +40,11 @@
37 40
38#define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file (kind, "util", syscall, filename) 41#define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file (kind, "util", syscall, filename)
39 42
43/**
44 * If a monitor takes more than 1 minute to process an event, print a warning.
45 */
46#define MONITOR_STALL_WARN_DELAY GNUNET_TIME_UNIT_MINUTES
47
40 48
41/** 49/**
42 * A namestore client 50 * A namestore client
@@ -161,6 +169,16 @@ struct ZoneMonitor
161 struct GNUNET_SCHEDULER_Task *task; 169 struct GNUNET_SCHEDULER_Task *task;
162 170
163 /** 171 /**
172 * Task to warn about slow monitors.
173 */
174 struct GNUNET_SCHEDULER_Task *sa_wait_warning;
175
176 /**
177 * Since when are we blocked on this monitor?
178 */
179 struct GNUNET_TIME_Absolute sa_waiting_start;
180
181 /**
164 * Last sequence number in the zone iteration used to address next 182 * Last sequence number in the zone iteration used to address next
165 * result of the zone iteration in the store 183 * result of the zone iteration in the store
166 * 184 *
@@ -175,6 +193,27 @@ struct ZoneMonitor
175 */ 193 */
176 uint64_t limit; 194 uint64_t limit;
177 195
196 /**
197 * How many more requests may we receive from the iterator
198 * before it is at the limit we gave it? Will be below or
199 * equal to @e limit. The effective limit for monitor
200 * events is thus @e iteration_cnt - @e limit!
201 */
202 uint64_t iteration_cnt;
203
204 /**
205 * Are we (still) in the initial iteration pass?
206 */
207 int in_first_iteration;
208
209 /**
210 * Is there a store activity waiting for this monitor? We only raise the
211 * flag when it happens and search the DLL for the store activity when we
212 * had a limit increase. If we cannot find any waiting store activity at
213 * that time, we clear the flag again.
214 */
215 int sa_waiting;
216
178}; 217};
179 218
180 219
@@ -212,6 +251,57 @@ struct CacheOperation
212 251
213 252
214/** 253/**
254 * Information for an ongoing #handle_record_store() operation.
255 * Needed as we may wait for monitors to be ready for the notification.
256 */
257struct StoreActivity
258{
259 /**
260 * Kept in a DLL.
261 */
262 struct StoreActivity *next;
263
264 /**
265 * Kept in a DLL.
266 */
267 struct StoreActivity *prev;
268
269 /**
270 * Which client triggered the store activity?
271 */
272 struct NamestoreClient *nc;
273
274 /**
275 * Copy of the original store message (as data fields in @e rd will
276 * point into it!).
277 */
278 const struct RecordStoreMessage *rsm;
279
280 /**
281 * Array of record data to store (without NICK unless this is about
282 * #GNUNET_GNS_EMPTY_LABEL_AT). Length is in @e rd_count.
283 */
284 struct GNUNET_GNSRECORD_Data *rd;
285
286 /**
287 * Next zone monitor that still needs to be notified about this PUT.
288 */
289 struct ZoneMonitor *zm_pos;
290
291 /**
292 * Label nicely canonicalized (lower case).
293 */
294 char *conv_name;
295
296 /**
297 * How many records do we try to store?
298 */
299 unsigned int rd_count;
300
301};
302
303
304/**
215 * Public key of all zeros. 305 * Public key of all zeros.
216 */ 306 */
217static const struct GNUNET_CRYPTO_EcdsaPrivateKey zero; 307static const struct GNUNET_CRYPTO_EcdsaPrivateKey zero;
@@ -262,6 +352,16 @@ static struct ZoneMonitor *monitor_head;
262static struct ZoneMonitor *monitor_tail; 352static struct ZoneMonitor *monitor_tail;
263 353
264/** 354/**
355 * Head of DLL of monitor-blocked store activities.
356 */
357static struct StoreActivity *sa_head;
358
359/**
360 * Tail of DLL of monitor-blocked store activities.
361 */
362static struct StoreActivity *sa_tail;
363
364/**
265 * Notification context shared by all monitors. 365 * Notification context shared by all monitors.
266 */ 366 */
267static struct GNUNET_NotificationContext *monitor_nc; 367static struct GNUNET_NotificationContext *monitor_nc;
@@ -326,80 +426,21 @@ cleanup_task (void *cls)
326 426
327 427
328/** 428/**
329 * Called whenever a client is disconnected. 429 * Release memory used by @a sa.
330 * Frees our resources associated with that client.
331 * 430 *
332 * @param cls closure 431 * @param sa activity to free
333 * @param client identification of the client
334 * @param app_ctx the `struct NamestoreClient` of @a client
335 */ 432 */
336static void 433static void
337client_disconnect_cb (void *cls, 434free_store_activity (struct StoreActivity *sa)
338 struct GNUNET_SERVICE_Client *client,
339 void *app_ctx)
340{
341 struct NamestoreClient *nc = app_ctx;
342 struct ZoneIteration *no;
343 struct ZoneMonitor *zm;
344 struct CacheOperation *cop;
345
346 (void) cls;
347 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
348 "Client %p disconnected\n",
349 client);
350 for (zm = monitor_head; NULL != zm; zm = zm->next)
351 {
352 if (nc == zm->nc)
353 {
354 GNUNET_CONTAINER_DLL_remove (monitor_head,
355 monitor_tail,
356 zm);
357 if (NULL != zm->task)
358 {
359 GNUNET_SCHEDULER_cancel (zm->task);
360 zm->task = NULL;
361 }
362 GNUNET_free (zm);
363 break;
364 }
365 }
366 while (NULL != (no = nc->op_head))
367 {
368 GNUNET_CONTAINER_DLL_remove (nc->op_head,
369 nc->op_tail,
370 no);
371 GNUNET_free (no);
372 }
373 for (cop = cop_head; NULL != cop; cop = cop->next)
374 if (nc == cop->nc)
375 cop->nc = NULL;
376 GNUNET_free (nc);
377}
378
379
380/**
381 * Add a client to our list of active clients.
382 *
383 * @param cls NULL
384 * @param client client to add
385 * @param mq message queue for @a client
386 * @return internal namestore client structure for this client
387 */
388static void *
389client_connect_cb (void *cls,
390 struct GNUNET_SERVICE_Client *client,
391 struct GNUNET_MQ_Handle *mq)
392{ 435{
393 struct NamestoreClient *nc; 436 GNUNET_CONTAINER_DLL_remove (sa_head,
394 437 sa_tail,
395 (void) cls; 438 sa);
396 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 439 GNUNET_array_grow (sa->rd,
397 "Client %p connected\n", 440 sa->rd_count,
398 client); 441 0);
399 nc = GNUNET_new (struct NamestoreClient); 442 GNUNET_free (sa->conv_name);
400 nc->client = client; 443 GNUNET_free (sa);
401 nc->mq = mq;
402 return nc;
403} 444}
404 445
405 446
@@ -509,18 +550,16 @@ merge_with_nick_records (const struct GNUNET_GNSRECORD_Data *nick_rd,
509 uint64_t latest_expiration; 550 uint64_t latest_expiration;
510 size_t req; 551 size_t req;
511 char *data; 552 char *data;
512 int record_offset;
513 size_t data_offset; 553 size_t data_offset;
514 554
515 (*rdc_res) = 1 + rd2_length; 555 (*rdc_res) = 1 + rd2_length;
516 if (0 == 1 + rd2_length) 556 if (0 == 1 + rd2_length)
517 { 557 {
558 GNUNET_break (0);
518 (*rd_res) = NULL; 559 (*rd_res) = NULL;
519 return; 560 return;
520 } 561 }
521 req = 0; 562 req = sizeof (struct GNUNET_GNSRECORD_Data) + nick_rd->data_size;
522 for (unsigned int c=0; c< 1; c++)
523 req += sizeof (struct GNUNET_GNSRECORD_Data) + nick_rd[c].data_size;
524 for (unsigned int c=0; c< rd2_length; c++) 563 for (unsigned int c=0; c< rd2_length; c++)
525 req += sizeof (struct GNUNET_GNSRECORD_Data) + rd2[c].data_size; 564 req += sizeof (struct GNUNET_GNSRECORD_Data) + rd2[c].data_size;
526 (*rd_res) = GNUNET_malloc (req); 565 (*rd_res) = GNUNET_malloc (req);
@@ -539,20 +578,19 @@ merge_with_nick_records (const struct GNUNET_GNSRECORD_Data *nick_rd,
539 latest_expiration = rd2[c].expiration_time; 578 latest_expiration = rd2[c].expiration_time;
540 (*rd_res)[c] = rd2[c]; 579 (*rd_res)[c] = rd2[c];
541 (*rd_res)[c].data = (void *) &data[data_offset]; 580 (*rd_res)[c].data = (void *) &data[data_offset];
542 GNUNET_memcpy ((void *) (*rd_res)[c].data, 581 GNUNET_memcpy (&data[data_offset],
543 rd2[c].data, 582 rd2[c].data,
544 rd2[c].data_size); 583 rd2[c].data_size);
545 data_offset += (*rd_res)[c].data_size; 584 data_offset += (*rd_res)[c].data_size;
546 } 585 }
547 /* append nick */ 586 /* append nick */
548 record_offset = rd2_length; 587 (*rd_res)[rd2_length] = *nick_rd;
549 (*rd_res)[record_offset] = *nick_rd; 588 (*rd_res)[rd2_length].expiration_time = latest_expiration;
550 (*rd_res)[record_offset].expiration_time = latest_expiration; 589 (*rd_res)[rd2_length].data = (void *) &data[data_offset];
551 (*rd_res)[record_offset].data = (void *) &data[data_offset]; 590 GNUNET_memcpy ((void *) (*rd_res)[rd2_length].data,
552 GNUNET_memcpy ((void *) (*rd_res)[record_offset].data,
553 nick_rd->data, 591 nick_rd->data,
554 nick_rd->data_size); 592 nick_rd->data_size);
555 data_offset += (*rd_res)[record_offset].data_size; 593 data_offset += (*rd_res)[rd2_length].data_size;
556 GNUNET_assert (req == (sizeof (struct GNUNET_GNSRECORD_Data)) * (*rdc_res) + data_offset); 594 GNUNET_assert (req == (sizeof (struct GNUNET_GNSRECORD_Data)) * (*rdc_res) + data_offset);
557} 595}
558 596
@@ -606,7 +644,8 @@ send_lookup_response (struct NamestoreClient *nc,
606 } 644 }
607 645
608 name_len = strlen (name) + 1; 646 name_len = strlen (name) + 1;
609 rd_ser_len = GNUNET_GNSRECORD_records_get_size (res_count, res); 647 rd_ser_len = GNUNET_GNSRECORD_records_get_size (res_count,
648 res);
610 env = GNUNET_MQ_msg_extra (zir_msg, 649 env = GNUNET_MQ_msg_extra (zir_msg,
611 name_len + rd_ser_len, 650 name_len + rd_ser_len,
612 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT); 651 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT);
@@ -655,6 +694,10 @@ send_store_response (struct NamestoreClient *nc,
655 694
656 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 695 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
657 "Sending RECORD_STORE_RESPONSE message\n"); 696 "Sending RECORD_STORE_RESPONSE message\n");
697 GNUNET_STATISTICS_update (statistics,
698 "Store requests completed",
699 1,
700 GNUNET_NO);
658 env = GNUNET_MQ_msg (rcr_msg, 701 env = GNUNET_MQ_msg (rcr_msg,
659 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE); 702 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE);
660 rcr_msg->gns_header.r_id = htonl (rid); 703 rcr_msg->gns_header.r_id = htonl (rid);
@@ -795,6 +838,208 @@ refresh_block (struct NamestoreClient *nc,
795 838
796 839
797/** 840/**
841 * Print a warning that one of our monitors is no longer reacting.
842 *
843 * @param cls a `struct ZoneMonitor` to warn about
844 */
845static void
846warn_monitor_slow (void *cls)
847{
848 struct ZoneMonitor *zm = cls;
849
850 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
851 "No response from monitor since %s\n",
852 GNUNET_STRINGS_absolute_time_to_string (zm->sa_waiting_start));
853 zm->sa_wait_warning = GNUNET_SCHEDULER_add_delayed (MONITOR_STALL_WARN_DELAY,
854 &warn_monitor_slow,
855 zm);
856}
857
858
859/**
860 * Continue processing the @a sa.
861 *
862 * @param sa store activity to process
863 */
864static void
865continue_store_activity (struct StoreActivity *sa)
866{
867 const struct RecordStoreMessage *rp_msg = sa->rsm;
868
869 for (struct ZoneMonitor *zm = sa->zm_pos;
870 NULL != zm;
871 zm = sa->zm_pos)
872 {
873 if ( (0 != memcmp (&rp_msg->private_key,
874 &zm->zone,
875 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) &&
876 (0 != memcmp (&zm->zone,
877 &zero,
878 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) )
879 sa->zm_pos = zm->next; /* not interesting to this monitor */
880 if (zm->limit == zm->iteration_cnt)
881 {
882 zm->sa_waiting = GNUNET_YES;
883 zm->sa_waiting_start = GNUNET_TIME_absolute_get ();
884 if (NULL != zm->sa_wait_warning)
885 GNUNET_SCHEDULER_cancel (zm->sa_wait_warning);
886 zm->sa_wait_warning = GNUNET_SCHEDULER_add_delayed (MONITOR_STALL_WARN_DELAY,
887 &warn_monitor_slow,
888 zm);
889 return; /* blocked on zone monitor */
890 }
891 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
892 "Notifying monitor about changes under label `%s'\n",
893 sa->conv_name);
894 zm->limit--;
895 send_lookup_response (zm->nc,
896 0,
897 &rp_msg->private_key,
898 sa->conv_name,
899 sa->rd_count,
900 sa->rd);
901 sa->zm_pos = zm->next;
902 }
903 /* great, done with the monitors, unpack (again) for refresh_block operation */
904 {
905 size_t name_len;
906 size_t rd_ser_len;
907 uint32_t rid;
908 const char *name_tmp;
909 const char *rd_ser;
910 unsigned int rd_count;
911
912 rid = ntohl (rp_msg->gns_header.r_id);
913 name_len = ntohs (rp_msg->name_len);
914 rd_count = ntohs (rp_msg->rd_count);
915 rd_ser_len = ntohs (rp_msg->rd_len);
916 name_tmp = (const char *) &rp_msg[1];
917 rd_ser = &name_tmp[name_len];
918 {
919 struct GNUNET_GNSRECORD_Data rd[rd_count];
920
921 /* We did this before, must succeed again */
922 GNUNET_assert (GNUNET_OK ==
923 GNUNET_GNSRECORD_records_deserialize (rd_ser_len,
924 rd_ser,
925 rd_count,
926 rd));
927 refresh_block (sa->nc,
928 rid,
929 &rp_msg->private_key,
930 sa->conv_name,
931 rd_count,
932 rd);
933 }
934 }
935 GNUNET_SERVICE_client_continue (sa->nc->client);
936 free_store_activity (sa);
937}
938
939
940/**
941 * Called whenever a client is disconnected.
942 * Frees our resources associated with that client.
943 *
944 * @param cls closure
945 * @param client identification of the client
946 * @param app_ctx the `struct NamestoreClient` of @a client
947 */
948static void
949client_disconnect_cb (void *cls,
950 struct GNUNET_SERVICE_Client *client,
951 void *app_ctx)
952{
953 struct NamestoreClient *nc = app_ctx;
954 struct ZoneIteration *no;
955 struct CacheOperation *cop;
956
957 (void) cls;
958 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
959 "Client %p disconnected\n",
960 client);
961 for (struct ZoneMonitor *zm = monitor_head; NULL != zm; zm = zm->next)
962 {
963 struct StoreActivity *san;
964
965 if (nc != zm->nc)
966 continue;
967 GNUNET_CONTAINER_DLL_remove (monitor_head,
968 monitor_tail,
969 zm);
970 if (NULL != zm->task)
971 {
972 GNUNET_SCHEDULER_cancel (zm->task);
973 zm->task = NULL;
974 }
975 if (NULL != zm->sa_wait_warning)
976 {
977 GNUNET_SCHEDULER_cancel (zm->sa_wait_warning);
978 zm->sa_wait_warning = NULL;
979 }
980 for (struct StoreActivity *sa = sa_head; NULL != sa; sa = san)
981 {
982 san = sa->next;
983 if (zm == sa->zm_pos)
984 {
985 sa->zm_pos = zm->next;
986 /* this may free sa */
987 continue_store_activity (sa);
988 }
989 }
990 GNUNET_free (zm);
991 break;
992 }
993 for (struct StoreActivity *sa = sa_head; NULL != sa; sa = sa->next)
994 {
995 if (sa->nc == nc)
996 {
997 /* this may free sa */
998 free_store_activity (sa);
999 break; /* there can only be one per nc */
1000 }
1001 }
1002 while (NULL != (no = nc->op_head))
1003 {
1004 GNUNET_CONTAINER_DLL_remove (nc->op_head,
1005 nc->op_tail,
1006 no);
1007 GNUNET_free (no);
1008 }
1009 for (cop = cop_head; NULL != cop; cop = cop->next)
1010 if (nc == cop->nc)
1011 cop->nc = NULL;
1012 GNUNET_free (nc);
1013}
1014
1015
1016/**
1017 * Add a client to our list of active clients.
1018 *
1019 * @param cls NULL
1020 * @param client client to add
1021 * @param mq message queue for @a client
1022 * @return internal namestore client structure for this client
1023 */
1024static void *
1025client_connect_cb (void *cls,
1026 struct GNUNET_SERVICE_Client *client,
1027 struct GNUNET_MQ_Handle *mq)
1028{
1029 struct NamestoreClient *nc;
1030
1031 (void) cls;
1032 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1033 "Client %p connected\n",
1034 client);
1035 nc = GNUNET_new (struct NamestoreClient);
1036 nc->client = client;
1037 nc->mq = mq;
1038 return nc;
1039}
1040
1041
1042/**
798 * Closure for #lookup_it(). 1043 * Closure for #lookup_it().
799 */ 1044 */
800struct RecordLookupContext 1045struct RecordLookupContext
@@ -1073,7 +1318,7 @@ handle_record_store (void *cls,
1073 const char *rd_ser; 1318 const char *rd_ser;
1074 unsigned int rd_count; 1319 unsigned int rd_count;
1075 int res; 1320 int res;
1076 struct ZoneMonitor *zm; 1321 struct StoreActivity *sa;
1077 1322
1078 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1323 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1079 "Received NAMESTORE_RECORD_STORE message\n"); 1324 "Received NAMESTORE_RECORD_STORE message\n");
@@ -1085,7 +1330,9 @@ handle_record_store (void *cls,
1085 name_tmp = (const char *) &rp_msg[1]; 1330 name_tmp = (const char *) &rp_msg[1];
1086 rd_ser = &name_tmp[name_len]; 1331 rd_ser = &name_tmp[name_len];
1087 { 1332 {
1088 struct GNUNET_GNSRECORD_Data rd[rd_count]; 1333 struct GNUNET_GNSRECORD_Data rd[GNUNET_NZL(rd_count)];
1334 struct GNUNET_GNSRECORD_Data rd_clean[GNUNET_NZL(rd_count)];
1335 unsigned int rd_clean_off;
1089 1336
1090 if (GNUNET_OK != 1337 if (GNUNET_OK !=
1091 GNUNET_GNSRECORD_records_deserialize (rd_ser_len, 1338 GNUNET_GNSRECORD_records_deserialize (rd_ser_len,
@@ -1108,6 +1355,10 @@ handle_record_store (void *cls,
1108 GNUNET_SERVICE_client_drop (nc->client); 1355 GNUNET_SERVICE_client_drop (nc->client);
1109 return; 1356 return;
1110 } 1357 }
1358 GNUNET_STATISTICS_update (statistics,
1359 "Well-formed store requests received",
1360 1,
1361 GNUNET_NO);
1111 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1362 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1112 "Creating %u records for name `%s'\n", 1363 "Creating %u records for name `%s'\n",
1113 (unsigned int) rd_count, 1364 (unsigned int) rd_count,
@@ -1128,9 +1379,6 @@ handle_record_store (void *cls,
1128 } 1379 }
1129 else 1380 else
1130 { 1381 {
1131 struct GNUNET_GNSRECORD_Data rd_clean[rd_count];
1132 unsigned int rd_clean_off;
1133
1134 /* remove "NICK" records, unless this is for the 1382 /* remove "NICK" records, unless this is for the
1135 #GNUNET_GNS_EMPTY_LABEL_AT label */ 1383 #GNUNET_GNS_EMPTY_LABEL_AT label */
1136 rd_clean_off = 0; 1384 rd_clean_off = 0;
@@ -1147,59 +1395,39 @@ handle_record_store (void *cls,
1147 conv_name, 1395 conv_name,
1148 rd_clean_off, 1396 rd_clean_off,
1149 rd_clean); 1397 rd_clean);
1150 if (GNUNET_OK == res)
1151 {
1152 for (zm = monitor_head; NULL != zm; zm = zm->next)
1153 {
1154 if ( (0 == memcmp (&rp_msg->private_key,
1155 &zm->zone,
1156 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) ||
1157 (0 == memcmp (&zm->zone,
1158 &zero,
1159 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) )
1160 {
1161 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1162 "Notifying monitor about changes under label `%s'\n",
1163 conv_name);
1164 send_lookup_response (zm->nc,
1165 0,
1166 &rp_msg->private_key,
1167 conv_name,
1168 rd_count, rd);
1169 }
1170 else
1171 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1172 "Monitor is for another zone\n");
1173 }
1174 if (NULL == monitor_head)
1175 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1176 "No monitors active\n");
1177 }
1178 else
1179 {
1180 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1181 "Error storing record: %d\n",
1182 res);
1183 }
1184 } 1398 }
1185 if (GNUNET_OK == res) 1399
1400 if (GNUNET_OK != res)
1186 { 1401 {
1187 refresh_block (nc, 1402 /* store not successful, not need to tell monitors */
1188 rid, 1403 send_store_response (nc,
1189 &rp_msg->private_key, 1404 res,
1190 conv_name, 1405 rid);
1191 rd_count,
1192 rd);
1193 GNUNET_SERVICE_client_continue (nc->client); 1406 GNUNET_SERVICE_client_continue (nc->client);
1194 GNUNET_free (conv_name); 1407 GNUNET_free (conv_name);
1195 return; 1408 return;
1196 } 1409 }
1197 GNUNET_free (conv_name); 1410
1411 sa = GNUNET_malloc (sizeof (struct StoreActivity) +
1412 ntohs (rp_msg->gns_header.header.size));
1413 GNUNET_CONTAINER_DLL_insert (sa_head,
1414 sa_tail,
1415 sa);
1416 sa->nc = nc;
1417 sa->rsm = (const struct RecordStoreMessage *) &sa[1];
1418 GNUNET_memcpy (&sa[1],
1419 rp_msg,
1420 ntohs (rp_msg->gns_header.header.size));
1421 sa->zm_pos = monitor_head;
1422 sa->conv_name = conv_name;
1423 GNUNET_array_grow (sa->rd,
1424 sa->rd_count,
1425 rd_clean_off);
1426 GNUNET_memcpy (sa->rd,
1427 rd_clean,
1428 sizeof (struct GNUNET_GNSRECORD_Data) * rd_clean_off);
1429 continue_store_activity (sa);
1198 } 1430 }
1199 send_store_response (nc,
1200 res,
1201 rid);
1202 GNUNET_SERVICE_client_continue (nc->client);
1203} 1431}
1204 1432
1205 1433
@@ -1311,8 +1539,7 @@ handle_zone_to_name (void *cls,
1311 struct ZoneToNameResponseMessage *ztnr_msg; 1539 struct ZoneToNameResponseMessage *ztnr_msg;
1312 1540
1313 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1541 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1314 "Received `%s' message\n", 1542 "Received ZONE_TO_NAME message\n");
1315 "ZONE_TO_NAME");
1316 ztn_ctx.rid = ntohl (ztn_msg->gns_header.r_id); 1543 ztn_ctx.rid = ntohl (ztn_msg->gns_header.r_id);
1317 ztn_ctx.nc = nc; 1544 ztn_ctx.nc = nc;
1318 ztn_ctx.success = GNUNET_NO; 1545 ztn_ctx.success = GNUNET_NO;
@@ -1601,6 +1828,46 @@ handle_iteration_next (void *cls,
1601 1828
1602 1829
1603/** 1830/**
1831 * Function called when the monitor is ready for more data, and we
1832 * should thus unblock PUT operations that were blocked on the
1833 * monitor not being ready.
1834 */
1835static void
1836monitor_unblock (struct ZoneMonitor *zm)
1837{
1838 struct StoreActivity *sa = sa_head;
1839
1840 while ( (NULL != sa) &&
1841 (zm->limit > zm->iteration_cnt) )
1842 {
1843 struct StoreActivity *sn = sa->next;
1844
1845 if (sa->zm_pos == zm)
1846 continue_store_activity (sa);
1847 sa = sn;
1848 }
1849 if (zm->limit > zm->iteration_cnt)
1850 {
1851 zm->sa_waiting = GNUNET_NO;
1852 if (NULL != zm->sa_wait_warning)
1853 {
1854 GNUNET_SCHEDULER_cancel (zm->sa_wait_warning);
1855 zm->sa_wait_warning = NULL;
1856 }
1857 }
1858 else if (GNUNET_YES == zm->sa_waiting)
1859 {
1860 zm->sa_waiting_start = GNUNET_TIME_absolute_get ();
1861 if (NULL != zm->sa_wait_warning)
1862 GNUNET_SCHEDULER_cancel (zm->sa_wait_warning);
1863 zm->sa_wait_warning = GNUNET_SCHEDULER_add_delayed (MONITOR_STALL_WARN_DELAY,
1864 &warn_monitor_slow,
1865 zm);
1866 }
1867}
1868
1869
1870/**
1604 * Send 'sync' message to zone monitor, we're now in sync. 1871 * Send 'sync' message to zone monitor, we're now in sync.
1605 * 1872 *
1606 * @param zm monitor that is now in sync 1873 * @param zm monitor that is now in sync
@@ -1615,16 +1882,22 @@ monitor_sync (struct ZoneMonitor *zm)
1615 GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_SYNC); 1882 GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_SYNC);
1616 GNUNET_MQ_send (zm->nc->mq, 1883 GNUNET_MQ_send (zm->nc->mq,
1617 env); 1884 env);
1885 /* mark iteration done */
1886 zm->in_first_iteration = GNUNET_NO;
1887 zm->iteration_cnt = 0;
1888 if ( (zm->limit > 0) &&
1889 (zm->sa_waiting) )
1890 monitor_unblock (zm);
1618} 1891}
1619 1892
1620 1893
1621/** 1894/**
1622 * Obtain the next datum during the zone monitor's zone intiial iteration. 1895 * Obtain the next datum during the zone monitor's zone initial iteration.
1623 * 1896 *
1624 * @param cls zone monitor that does its initial iteration 1897 * @param cls zone monitor that does its initial iteration
1625 */ 1898 */
1626static void 1899static void
1627monitor_next (void *cls); 1900monitor_iteration_next (void *cls);
1628 1901
1629 1902
1630/** 1903/**
@@ -1658,14 +1931,23 @@ monitor_iterate_cb (void *cls,
1658 "Monitor notifications sent", 1931 "Monitor notifications sent",
1659 1, 1932 1,
1660 GNUNET_NO); 1933 GNUNET_NO);
1934 zm->limit--;
1935 zm->iteration_cnt--;
1661 send_lookup_response (zm->nc, 1936 send_lookup_response (zm->nc,
1662 0, 1937 0,
1663 zone_key, 1938 zone_key,
1664 name, 1939 name,
1665 rd_count, 1940 rd_count,
1666 rd); 1941 rd);
1667 zm->task = GNUNET_SCHEDULER_add_now (&monitor_next, 1942 if ( (0 == zm->iteration_cnt) &&
1668 zm); 1943 (0 != zm->limit) )
1944 {
1945 /* We are done with the current iteration batch, AND the
1946 client would right now accept more, so go again! */
1947 GNUNET_assert (NULL == zm->task);
1948 zm->task = GNUNET_SCHEDULER_add_now (&monitor_iteration_next,
1949 zm);
1950 }
1669} 1951}
1670 1952
1671 1953
@@ -1687,6 +1969,8 @@ handle_monitor_start (void *cls,
1687 zm = GNUNET_new (struct ZoneMonitor); 1969 zm = GNUNET_new (struct ZoneMonitor);
1688 zm->nc = nc; 1970 zm->nc = nc;
1689 zm->zone = zis_msg->zone; 1971 zm->zone = zis_msg->zone;
1972 zm->limit = 1;
1973 zm->in_first_iteration = (GNUNET_YES == ntohl (zis_msg->iterate_first));
1690 GNUNET_CONTAINER_DLL_insert (monitor_head, 1974 GNUNET_CONTAINER_DLL_insert (monitor_head,
1691 monitor_tail, 1975 monitor_tail,
1692 zm); 1976 zm);
@@ -1694,8 +1978,8 @@ handle_monitor_start (void *cls,
1694 GNUNET_SERVICE_client_continue (nc->client); 1978 GNUNET_SERVICE_client_continue (nc->client);
1695 GNUNET_notification_context_add (monitor_nc, 1979 GNUNET_notification_context_add (monitor_nc,
1696 nc->mq); 1980 nc->mq);
1697 if (GNUNET_YES == ntohl (zis_msg->iterate_first)) 1981 if (zm->in_first_iteration)
1698 zm->task = GNUNET_SCHEDULER_add_now (&monitor_next, 1982 zm->task = GNUNET_SCHEDULER_add_now (&monitor_iteration_next,
1699 zm); 1983 zm);
1700 else 1984 else
1701 monitor_sync (zm); 1985 monitor_sync (zm);
@@ -1708,12 +1992,17 @@ handle_monitor_start (void *cls,
1708 * @param cls zone monitor that does its initial iteration 1992 * @param cls zone monitor that does its initial iteration
1709 */ 1993 */
1710static void 1994static void
1711monitor_next (void *cls) 1995monitor_iteration_next (void *cls)
1712{ 1996{
1713 struct ZoneMonitor *zm = cls; 1997 struct ZoneMonitor *zm = cls;
1714 int ret; 1998 int ret;
1715 1999
1716 zm->task = NULL; 2000 zm->task = NULL;
2001 GNUNET_assert (0 == zm->iteration_cnt);
2002 if (zm->limit > 16)
2003 zm->iteration_cnt = zm->limit / 2; /* leave half for monitor events */
2004 else
2005 zm->iteration_cnt = zm->limit; /* use it all */
1717 ret = GSN_database->iterate_records (GSN_database->cls, 2006 ret = GSN_database->iterate_records (GSN_database->cls,
1718 (0 == memcmp (&zm->zone, 2007 (0 == memcmp (&zm->zone,
1719 &zero, 2008 &zero,
@@ -1721,7 +2010,7 @@ monitor_next (void *cls)
1721 ? NULL 2010 ? NULL
1722 : &zm->zone, 2011 : &zm->zone,
1723 zm->seq, 2012 zm->seq,
1724 1, 2013 zm->iteration_cnt,
1725 &monitor_iterate_cb, 2014 &monitor_iterate_cb,
1726 zm); 2015 zm);
1727 if (GNUNET_SYSERR == ret) 2016 if (GNUNET_SYSERR == ret)
@@ -1773,13 +2062,30 @@ handle_monitor_next (void *cls,
1773 return; 2062 return;
1774 } 2063 }
1775 zm->limit += inc; 2064 zm->limit += inc;
1776#if 0 2065 if ( (zm->in_first_iteration) &&
1777 if (GNUNET_YES == ntohl (zis_msg->iterate_first)) 2066 (zm->limit == inc) )
1778 zm->task = GNUNET_SCHEDULER_add_now (&monitor_next, 2067 {
1779 zm); 2068 /* We are still iterating, and the previous iteration must
1780 else 2069 have stopped due to the client's limit, so continue it! */
1781 monitor_sync (zm); 2070 GNUNET_assert (NULL == zm->task);
1782#endif 2071 zm->task = GNUNET_SCHEDULER_add_now (&monitor_iteration_next,
2072 zm);
2073 }
2074 GNUNET_assert (zm->iteration_cnt <= zm->limit);
2075 if ( (zm->limit > zm->iteration_cnt) &&
2076 (zm->sa_waiting) )
2077 {
2078 monitor_unblock (zm);
2079 }
2080 else if (GNUNET_YES == zm->sa_waiting)
2081 {
2082 if (NULL != zm->sa_wait_warning)
2083 GNUNET_SCHEDULER_cancel (zm->sa_wait_warning);
2084 zm->sa_waiting_start = GNUNET_TIME_absolute_get ();
2085 zm->sa_wait_warning = GNUNET_SCHEDULER_add_delayed (MONITOR_STALL_WARN_DELAY,
2086 &warn_monitor_slow,
2087 zm);
2088 }
1783} 2089}
1784 2090
1785 2091
diff --git a/src/namestore/gnunet-zoneimport.c b/src/namestore/gnunet-zoneimport.c
index 0fd0a4ab8..b394178a6 100644
--- a/src/namestore/gnunet-zoneimport.c
+++ b/src/namestore/gnunet-zoneimport.c
@@ -59,6 +59,11 @@
59#define SERIES_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MICROSECONDS, 10) 59#define SERIES_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MICROSECONDS, 10)
60 60
61/** 61/**
62 * How long do DNS records have to last at least after being imported?
63 */
64static struct GNUNET_TIME_Relative minimum_expiration_time;
65
66/**
62 * How many requests do we request from NAMESTORE in one batch 67 * How many requests do we request from NAMESTORE in one batch
63 * during our initial iteration? 68 * during our initial iteration?
64 */ 69 */
@@ -429,9 +434,9 @@ get_label (struct Request *req)
429 GNUNET_break (0); 434 GNUNET_break (0);
430 return NULL; 435 return NULL;
431 } 436 }
432 memcpy (label, 437 GNUNET_memcpy (label,
433 req->hostname, 438 req->hostname,
434 dot - req->hostname); 439 dot - req->hostname);
435 label[dot - req->hostname] = '\0'; 440 label[dot - req->hostname] = '\0';
436 return label; 441 return label;
437} 442}
@@ -486,9 +491,9 @@ build_dns_query (struct Request *req,
486 GNUNET_free (rawp); 491 GNUNET_free (rawp);
487 return NULL; 492 return NULL;
488 } 493 }
489 memcpy (raw, 494 GNUNET_memcpy (raw,
490 rawp, 495 rawp,
491 *raw_size); 496 *raw_size);
492 GNUNET_free (rawp); 497 GNUNET_free (rawp);
493 return raw; 498 return raw;
494} 499}
@@ -632,10 +637,19 @@ check_for_glue (void *cls,
632 size_t off; 637 size_t off;
633 char ip[INET6_ADDRSTRLEN+1]; 638 char ip[INET6_ADDRSTRLEN+1];
634 socklen_t ip_size = (socklen_t) sizeof (ip); 639 socklen_t ip_size = (socklen_t) sizeof (ip);
640 struct GNUNET_TIME_Absolute expiration_time;
641 struct GNUNET_TIME_Relative left;
635 642
636 if (0 != strcasecmp (rec->name, 643 if (0 != strcasecmp (rec->name,
637 gc->ns)) 644 gc->ns))
638 return; 645 return;
646 expiration_time = rec->expiration_time;
647 left = GNUNET_TIME_absolute_get_remaining (expiration_time);
648 if (0 == left.rel_value_us)
649 return; /* ignore expired glue records */
650 /* if expiration window is too short, bump it to configured minimum */
651 if (left.rel_value_us < minimum_expiration_time.rel_value_us)
652 expiration_time = GNUNET_TIME_relative_to_absolute (minimum_expiration_time);
639 dst_len = sizeof (dst); 653 dst_len = sizeof (dst);
640 off = 0; 654 off = 0;
641 switch (rec->type) 655 switch (rec->type)
@@ -668,7 +682,7 @@ check_for_glue (void *cls,
668 { 682 {
669 add_record (gc->req, 683 add_record (gc->req,
670 GNUNET_GNSRECORD_TYPE_GNS2DNS, 684 GNUNET_GNSRECORD_TYPE_GNS2DNS,
671 rec->expiration_time, 685 expiration_time,
672 dst, 686 dst,
673 off); 687 off);
674 gc->found = GNUNET_YES; 688 gc->found = GNUNET_YES;
@@ -702,7 +716,7 @@ check_for_glue (void *cls,
702 { 716 {
703 add_record (gc->req, 717 add_record (gc->req,
704 GNUNET_GNSRECORD_TYPE_GNS2DNS, 718 GNUNET_GNSRECORD_TYPE_GNS2DNS,
705 rec->expiration_time, 719 expiration_time,
706 dst, 720 dst,
707 off); 721 off);
708 gc->found = GNUNET_YES; 722 gc->found = GNUNET_YES;
@@ -722,7 +736,7 @@ check_for_glue (void *cls,
722 { 736 {
723 add_record (gc->req, 737 add_record (gc->req,
724 GNUNET_GNSRECORD_TYPE_GNS2DNS, 738 GNUNET_GNSRECORD_TYPE_GNS2DNS,
725 rec->expiration_time, 739 expiration_time,
726 dst, 740 dst,
727 off); 741 off);
728 gc->found = GNUNET_YES; 742 gc->found = GNUNET_YES;
@@ -768,6 +782,8 @@ process_record (void *cls,
768 char dst[65536]; 782 char dst[65536];
769 size_t dst_len; 783 size_t dst_len;
770 size_t off; 784 size_t off;
785 struct GNUNET_TIME_Absolute expiration_time;
786 struct GNUNET_TIME_Relative left;
771 787
772 dst_len = sizeof (dst); 788 dst_len = sizeof (dst);
773 off = 0; 789 off = 0;
@@ -783,18 +799,27 @@ process_record (void *cls,
783 return; /* does not match hostname, might be glue, but 799 return; /* does not match hostname, might be glue, but
784 not useful for this pass! */ 800 not useful for this pass! */
785 } 801 }
786 if (0 == 802 expiration_time = rec->expiration_time;
787 GNUNET_TIME_absolute_get_remaining (rec->expiration_time).rel_value_us) 803 left = GNUNET_TIME_absolute_get_remaining (expiration_time);
804 if (0 == left.rel_value_us)
788 { 805 {
789 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 806 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
790 "DNS returned expired record for `%s'\n", 807 "DNS returned expired record for `%s'\n",
791 req->hostname); 808 req->hostname);
809 GNUNET_STATISTICS_update (stats,
810 "# expired records obtained from DNS",
811 1,
812 GNUNET_NO);
792 return; /* record expired */ 813 return; /* record expired */
793 } 814 }
815
794 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 816 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
795 "DNS returned record that expires at %s for `%s'\n", 817 "DNS returned record that expires at %s for `%s'\n",
796 GNUNET_STRINGS_absolute_time_to_string (rec->expiration_time), 818 GNUNET_STRINGS_absolute_time_to_string (expiration_time),
797 req->hostname); 819 req->hostname);
820 /* if expiration window is too short, bump it to configured minimum */
821 if (left.rel_value_us < minimum_expiration_time.rel_value_us)
822 expiration_time = GNUNET_TIME_relative_to_absolute (minimum_expiration_time);
798 switch (rec->type) 823 switch (rec->type)
799 { 824 {
800 case GNUNET_DNSPARSER_TYPE_NS: 825 case GNUNET_DNSPARSER_TYPE_NS:
@@ -828,7 +853,7 @@ process_record (void *cls,
828 rec->name); 853 rec->name);
829 add_record (req, 854 add_record (req,
830 GNUNET_GNSRECORD_TYPE_GNS2DNS, 855 GNUNET_GNSRECORD_TYPE_GNS2DNS,
831 rec->expiration_time, 856 expiration_time,
832 dst, 857 dst,
833 off); 858 off);
834 } 859 }
@@ -853,7 +878,7 @@ process_record (void *cls,
853 rec->name); 878 rec->name);
854 add_record (req, 879 add_record (req,
855 rec->type, 880 rec->type,
856 rec->expiration_time, 881 expiration_time,
857 dst, 882 dst,
858 off); 883 off);
859 } 884 }
@@ -878,7 +903,7 @@ process_record (void *cls,
878 rec->name); 903 rec->name);
879 add_record (req, 904 add_record (req,
880 rec->type, 905 rec->type,
881 rec->expiration_time, 906 expiration_time,
882 dst, 907 dst,
883 off); 908 off);
884 } 909 }
@@ -896,7 +921,7 @@ process_record (void *cls,
896 rec->name); 921 rec->name);
897 add_record (req, 922 add_record (req,
898 rec->type, 923 rec->type,
899 rec->expiration_time, 924 expiration_time,
900 dst, 925 dst,
901 off); 926 off);
902 } 927 }
@@ -913,7 +938,7 @@ process_record (void *cls,
913 rec->name); 938 rec->name);
914 add_record (req, 939 add_record (req,
915 rec->type, 940 rec->type,
916 rec->expiration_time, 941 expiration_time,
917 dst, 942 dst,
918 off); 943 off);
919 } 944 }
@@ -931,7 +956,7 @@ process_record (void *cls,
931 rec->name); 956 rec->name);
932 add_record (req, 957 add_record (req,
933 rec->type, 958 rec->type,
934 rec->expiration_time, 959 expiration_time,
935 dst, 960 dst,
936 off); 961 off);
937 } 962 }
@@ -948,7 +973,7 @@ process_record (void *cls,
948 rec->name); 973 rec->name);
949 add_record (req, 974 add_record (req,
950 rec->type, 975 rec->type,
951 rec->expiration_time, 976 expiration_time,
952 dst, 977 dst,
953 off); 978 off);
954 } 979 }
@@ -966,7 +991,7 @@ process_record (void *cls,
966 rec->name); 991 rec->name);
967 add_record (req, 992 add_record (req,
968 rec->type, 993 rec->type,
969 rec->expiration_time, 994 expiration_time,
970 rec->data.raw.data, 995 rec->data.raw.data,
971 rec->data.raw.data_len); 996 rec->data.raw.data_len);
972 break; 997 break;
@@ -1551,7 +1576,17 @@ ns_lookup_result_cb (void *cls,
1551 { 1576 {
1552 struct GNUNET_TIME_Absolute at; 1577 struct GNUNET_TIME_Absolute at;
1553 1578
1554 at.abs_value_us = rd->expiration_time; 1579 if (0 != (rd->flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION))
1580 {
1581 struct GNUNET_TIME_Relative rel;
1582
1583 rel.rel_value_us = rd->expiration_time;
1584 at = GNUNET_TIME_relative_to_absolute (rel);
1585 }
1586 else
1587 {
1588 at.abs_value_us = rd->expiration_time;
1589 }
1555 add_record (req, 1590 add_record (req,
1556 rd->record_type, 1591 rd->record_type,
1557 at, 1592 at,
@@ -1648,9 +1683,9 @@ queue (const char *hostname)
1648 req = GNUNET_malloc (sizeof (struct Request) + hlen); 1683 req = GNUNET_malloc (sizeof (struct Request) + hlen);
1649 req->zone = zone; 1684 req->zone = zone;
1650 req->hostname = (char *) &req[1]; 1685 req->hostname = (char *) &req[1];
1651 memcpy (req->hostname, 1686 GNUNET_memcpy (req->hostname,
1652 hostname, 1687 hostname,
1653 hlen); 1688 hlen);
1654 req->id = (uint16_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, 1689 req->id = (uint16_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE,
1655 UINT16_MAX); 1690 UINT16_MAX);
1656 GNUNET_CRYPTO_hash (req->hostname, 1691 GNUNET_CRYPTO_hash (req->hostname,
@@ -1800,14 +1835,14 @@ process_stdin (void *cls)
1800 if (0 == idot) 1835 if (0 == idot)
1801 last = GNUNET_TIME_absolute_get (); 1836 last = GNUNET_TIME_absolute_get ();
1802 idot++; 1837 idot++;
1803 if (0 == idot % 10000) 1838 if (0 == idot % 100000)
1804 { 1839 {
1805 struct GNUNET_TIME_Relative delta; 1840 struct GNUNET_TIME_Relative delta;
1806 1841
1807 delta = GNUNET_TIME_absolute_get_duration (last); 1842 delta = GNUNET_TIME_absolute_get_duration (last);
1808 last = GNUNET_TIME_absolute_get (); 1843 last = GNUNET_TIME_absolute_get ();
1809 fprintf (stderr, 1844 fprintf (stderr,
1810 "Imported 10000 records in %s\n", 1845 "Read 10000 domain names in %s\n",
1811 GNUNET_STRINGS_relative_time_to_string (delta, 1846 GNUNET_STRINGS_relative_time_to_string (delta,
1812 GNUNET_YES)); 1847 GNUNET_YES));
1813 GNUNET_STATISTICS_set (stats, 1848 GNUNET_STATISTICS_set (stats,
@@ -1986,6 +2021,11 @@ main (int argc,
1986 "MAPSIZE", 2021 "MAPSIZE",
1987 gettext_noop ("size to use for the main hash map"), 2022 gettext_noop ("size to use for the main hash map"),
1988 &map_size), 2023 &map_size),
2024 GNUNET_GETOPT_option_relative_time ('m',
2025 "minimum-expiration",
2026 "RELATIVETIME",
2027 gettext_noop ("minimum expiration time we assume for imported records"),
2028 &minimum_expiration_time),
1989 GNUNET_GETOPT_OPTION_END 2029 GNUNET_GETOPT_OPTION_END
1990 }; 2030 };
1991 2031
diff --git a/src/namestore/namestore_api.c b/src/namestore/namestore_api.c
index ab356838b..57bf8f81b 100644
--- a/src/namestore/namestore_api.c
+++ b/src/namestore/namestore_api.c
@@ -40,6 +40,11 @@
40 40
41#define LOG(kind,...) GNUNET_log_from (kind, "namestore-api",__VA_ARGS__) 41#define LOG(kind,...) GNUNET_log_from (kind, "namestore-api",__VA_ARGS__)
42 42
43/**
44 * We grant the namestore up to 1 minute of latency, if it is slower than
45 * that, store queries will fail.
46 */
47#define NAMESTORE_DELAY_TOLERANCE GNUNET_TIME_UNIT_MINUTES
43 48
44/** 49/**
45 * An QueueEntry used to store information for a pending 50 * An QueueEntry used to store information for a pending
@@ -100,6 +105,11 @@ struct GNUNET_NAMESTORE_QueueEntry
100 struct GNUNET_MQ_Envelope *env; 105 struct GNUNET_MQ_Envelope *env;
101 106
102 /** 107 /**
108 * Task scheduled to warn us if the namestore is way too slow.
109 */
110 struct GNUNET_SCHEDULER_Task *timeout_task;
111
112 /**
103 * The operation id this zone iteration operation has 113 * The operation id this zone iteration operation has
104 */ 114 */
105 uint32_t op_id; 115 uint32_t op_id;
@@ -300,6 +310,8 @@ free_qe (struct GNUNET_NAMESTORE_QueueEntry *qe)
300 qe); 310 qe);
301 if (NULL != qe->env) 311 if (NULL != qe->env)
302 GNUNET_MQ_discard (qe->env); 312 GNUNET_MQ_discard (qe->env);
313 if (NULL != qe->timeout_task)
314 GNUNET_SCHEDULER_cancel (qe->timeout_task);
303 GNUNET_free (qe); 315 GNUNET_free (qe);
304} 316}
305 317
@@ -968,6 +980,33 @@ GNUNET_NAMESTORE_disconnect (struct GNUNET_NAMESTORE_Handle *h)
968 980
969 981
970/** 982/**
983 * Task launched to warn the user that the namestore is
984 * excessively slow and that a query was thus dropped.
985 *
986 * @param cls a `struct GNUNET_NAMESTORE_QueueEntry *`
987 */
988static void
989warn_delay (void *cls)
990{
991 struct GNUNET_NAMESTORE_QueueEntry *qe = cls;
992
993 qe->timeout_task = NULL;
994 LOG (GNUNET_ERROR_TYPE_WARNING,
995 "Did not receive response from namestore after %s!\n",
996 GNUNET_STRINGS_relative_time_to_string (NAMESTORE_DELAY_TOLERANCE,
997 GNUNET_YES));
998 if (NULL != qe->cont)
999 {
1000 qe->cont (qe->cont_cls,
1001 GNUNET_SYSERR,
1002 "timeout");
1003 qe->cont = NULL;
1004 }
1005 GNUNET_NAMESTORE_cancel (qe);
1006}
1007
1008
1009/**
971 * Store an item in the namestore. If the item is already present, 1010 * Store an item in the namestore. If the item is already present,
972 * it is replaced with the new record. Use an empty array to 1011 * it is replaced with the new record. Use an empty array to
973 * remove all records under the given name. 1012 * remove all records under the given name.
@@ -1048,12 +1087,20 @@ GNUNET_NAMESTORE_records_store (struct GNUNET_NAMESTORE_Handle *h,
1048 "Sending NAMESTORE_RECORD_STORE message for name `%s' with %u records\n", 1087 "Sending NAMESTORE_RECORD_STORE message for name `%s' with %u records\n",
1049 label, 1088 label,
1050 rd_count); 1089 rd_count);
1051 1090 qe->timeout_task = GNUNET_SCHEDULER_add_delayed (NAMESTORE_DELAY_TOLERANCE,
1091 &warn_delay,
1092 qe);
1052 if (NULL == h->mq) 1093 if (NULL == h->mq)
1094 {
1053 qe->env = env; 1095 qe->env = env;
1096 LOG (GNUNET_ERROR_TYPE_WARNING,
1097 "Delaying NAMESTORE_RECORD_STORE message as namestore is not ready!\n");
1098 }
1054 else 1099 else
1100 {
1055 GNUNET_MQ_send (h->mq, 1101 GNUNET_MQ_send (h->mq,
1056 env); 1102 env);
1103 }
1057 return qe; 1104 return qe;
1058} 1105}
1059 1106
diff --git a/src/namestore/perf_namestore_api_flat.conf b/src/namestore/perf_namestore_api_flat.conf
index 26e2f2c51..f356e9061 100644
--- a/src/namestore/perf_namestore_api_flat.conf
+++ b/src/namestore/perf_namestore_api_flat.conf
@@ -5,3 +5,6 @@ DATABASE = flat
5 5
6[namecache] 6[namecache]
7DISABLE = YES 7DISABLE = YES
8
9[namestore-flat]
10FILENAME = $GNUNET_TEST_HOME/namestore/flat.db
diff --git a/src/namestore/perf_namestore_api_postgres.conf b/src/namestore/perf_namestore_api_postgres.conf
index 259ce35e7..16f530252 100644
--- a/src/namestore/perf_namestore_api_postgres.conf
+++ b/src/namestore/perf_namestore_api_postgres.conf
@@ -5,3 +5,7 @@ DATABASE = postgres
5 5
6[namecache] 6[namecache]
7DISABLE = YES 7DISABLE = YES
8
9[namestore-postgres]
10CONFIG = connect_timeout=10; dbname=gnunetcheck
11TEMPORARY_TABLE = YES
diff --git a/src/namestore/perf_namestore_api_sqlite.conf b/src/namestore/perf_namestore_api_sqlite.conf
index 72b609226..de0fa3f1f 100644
--- a/src/namestore/perf_namestore_api_sqlite.conf
+++ b/src/namestore/perf_namestore_api_sqlite.conf
@@ -2,3 +2,6 @@
2 2
3[namecache] 3[namecache]
4DISABLE = YES 4DISABLE = YES
5
6[namestore-sqlite]
7FILENAME = $GNUNET_TEST_HOME/namestore/sqlite_test.db
diff --git a/src/namestore/perf_namestore_api_zone_iteration.c b/src/namestore/perf_namestore_api_zone_iteration.c
index 4ef8d3407..55d6fafa0 100644
--- a/src/namestore/perf_namestore_api_zone_iteration.c
+++ b/src/namestore/perf_namestore_api_zone_iteration.c
@@ -69,8 +69,6 @@ static struct GNUNET_NAMESTORE_QueueEntry *qe;
69 69
70static int res; 70static int res;
71 71
72static char *directory;
73
74static unsigned int off; 72static unsigned int off;
75 73
76static unsigned int left_until_next; 74static unsigned int left_until_next;
@@ -333,13 +331,6 @@ run (void *cls,
333 const struct GNUNET_CONFIGURATION_Handle *cfg, 331 const struct GNUNET_CONFIGURATION_Handle *cfg,
334 struct GNUNET_TESTING_Peer *peer) 332 struct GNUNET_TESTING_Peer *peer)
335{ 333{
336 directory = NULL;
337 GNUNET_assert (GNUNET_OK ==
338 GNUNET_CONFIGURATION_get_value_string(cfg,
339 "PATHS",
340 "GNUNET_TEST_HOME",
341 &directory));
342 GNUNET_DISK_directory_remove (directory);
343 GNUNET_SCHEDULER_add_shutdown (&end, 334 GNUNET_SCHEDULER_add_shutdown (&end,
344 NULL); 335 NULL);
345 timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 336 timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
@@ -367,6 +358,8 @@ main (int argc,
367 "perf_namestore_api_%s.conf", 358 "perf_namestore_api_%s.conf",
368 plugin_name); 359 plugin_name);
369 res = 1; 360 res = 1;
361 GNUNET_DISK_purge_cfg_dir (cfg_name,
362 "GNUNET_TEST_HOME");
370 if (0 != 363 if (0 !=
371 GNUNET_TESTING_peer_run ("perf-namestore-api-zone-iteration", 364 GNUNET_TESTING_peer_run ("perf-namestore-api-zone-iteration",
372 cfg_name, 365 cfg_name,
@@ -375,12 +368,9 @@ main (int argc,
375 { 368 {
376 res = 1; 369 res = 1;
377 } 370 }
371 GNUNET_DISK_purge_cfg_dir (cfg_name,
372 "GNUNET_TEST_HOME");
378 GNUNET_free (cfg_name); 373 GNUNET_free (cfg_name);
379 if (NULL != directory)
380 {
381 GNUNET_DISK_directory_remove (directory);
382 GNUNET_free (directory);
383 }
384 return res; 374 return res;
385} 375}
386 376
diff --git a/src/namestore/plugin_namestore_flat.c b/src/namestore/plugin_namestore_flat.c
index bbb9e3c62..35d8424b4 100644
--- a/src/namestore/plugin_namestore_flat.c
+++ b/src/namestore/plugin_namestore_flat.c
@@ -49,41 +49,6 @@ struct Plugin
49 */ 49 */
50 struct GNUNET_CONTAINER_MultiHashMap *hm; 50 struct GNUNET_CONTAINER_MultiHashMap *hm;
51 51
52 /**
53 * Offset
54 */
55 uint32_t offset;
56
57 /**
58 * Target Offset
59 */
60 uint32_t target_offset;
61
62 /**
63 * Iterator closure
64 */
65 void *iter_cls;
66
67 /**
68 * Iterator
69 */
70 GNUNET_NAMESTORE_RecordIterator iter;
71
72 /**
73 * Zone to iterate
74 */
75 const struct GNUNET_CRYPTO_EcdsaPrivateKey *iter_zone;
76
77 /**
78 * PKEY to look for in zone to name
79 */
80 const struct GNUNET_CRYPTO_EcdsaPublicKey *iter_pkey;
81
82 /**
83 * Iteration result found
84 */
85 int iter_result_found;
86
87}; 52};
88 53
89 54
@@ -364,10 +329,10 @@ store_and_free_entries (void *cls,
364 &record_data_b64); 329 &record_data_b64);
365 } 330 }
366 GNUNET_asprintf (&line, 331 GNUNET_asprintf (&line,
367 "%s,%lu,%u,%s,%s\n", 332 "%s,%llu,%u,%s,%s\n",
368 zone_private_key, 333 zone_private_key,
369 entry->rvalue, 334 (unsigned long long) entry->rvalue,
370 entry->record_count, 335 (unsigned int) entry->record_count,
371 record_data_b64, 336 record_data_b64,
372 entry->label); 337 entry->label);
373 GNUNET_free (record_data_b64); 338 GNUNET_free (record_data_b64);
@@ -608,7 +573,6 @@ iterate_zones (void *cls,
608 struct FlatFileEntry *entry = value; 573 struct FlatFileEntry *entry = value;
609 574
610 (void) key; 575 (void) key;
611 ic->pos++;
612 if (0 == ic->limit) 576 if (0 == ic->limit)
613 return GNUNET_NO; 577 return GNUNET_NO;
614 if ( (NULL != ic->zone) && 578 if ( (NULL != ic->zone) &&
@@ -616,6 +580,7 @@ iterate_zones (void *cls,
616 ic->zone, 580 ic->zone,
617 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) ) 581 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) )
618 return GNUNET_YES; 582 return GNUNET_YES;
583 ic->pos++;
619 if (ic->offset > 0) 584 if (ic->offset > 0)
620 { 585 {
621 ic->offset--; 586 ic->offset--;
@@ -670,17 +635,31 @@ namestore_flat_iterate_records (void *cls,
670} 635}
671 636
672 637
638/**
639 * Closure for #zone_to_name.
640 */
641struct ZoneToNameContext
642{
643 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone;
644 const struct GNUNET_CRYPTO_EcdsaPublicKey *value_zone;
645 GNUNET_NAMESTORE_RecordIterator iter;
646 void *iter_cls;
647
648 int result_found;
649};
650
651
673static int 652static int
674zone_to_name (void *cls, 653zone_to_name (void *cls,
675 const struct GNUNET_HashCode *key, 654 const struct GNUNET_HashCode *key,
676 void *value) 655 void *value)
677{ 656{
678 struct Plugin *plugin = cls; 657 struct ZoneToNameContext *ztn = cls;
679 struct FlatFileEntry *entry = value; 658 struct FlatFileEntry *entry = value;
680 659
681 (void) key; 660 (void) key;
682 if (0 != memcmp (entry->private_key, 661 if (0 != memcmp (entry->private_key,
683 plugin->iter_zone, 662 ztn->zone,
684 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) 663 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)))
685 return GNUNET_YES; 664 return GNUNET_YES;
686 665
@@ -688,18 +667,17 @@ zone_to_name (void *cls,
688 { 667 {
689 if (GNUNET_GNSRECORD_TYPE_PKEY != entry->record_data[i].record_type) 668 if (GNUNET_GNSRECORD_TYPE_PKEY != entry->record_data[i].record_type)
690 continue; 669 continue;
691 if (0 == memcmp (plugin->iter_pkey, 670 if (0 == memcmp (ztn->value_zone,
692 entry->record_data[i].data, 671 entry->record_data[i].data,
693 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))) 672 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)))
694 { 673 {
695 plugin->iter (plugin->iter_cls, 674 ztn->iter (ztn->iter_cls,
696 0, 675 0,
697 entry->private_key, 676 entry->private_key,
698 entry->label, 677 entry->label,
699 entry->record_count, 678 entry->record_count,
700 entry->record_data); 679 entry->record_data);
701 plugin->iter_result_found = GNUNET_YES; 680 ztn->result_found = GNUNET_YES;
702
703 } 681 }
704 } 682 }
705 return GNUNET_YES; 683 return GNUNET_YES;
@@ -725,21 +703,21 @@ namestore_flat_zone_to_name (void *cls,
725 void *iter_cls) 703 void *iter_cls)
726{ 704{
727 struct Plugin *plugin = cls; 705 struct Plugin *plugin = cls;
706 struct ZoneToNameContext ztn = {
707 .iter = iter,
708 .iter_cls = iter_cls,
709 .zone = zone,
710 .value_zone = value_zone,
711 .result_found = GNUNET_NO
712 };
728 713
729 /* FIXME: maybe use separate closure to better handle
730 recursive calls? */
731 plugin->iter = iter;
732 plugin->iter_cls = iter_cls;
733 plugin->iter_zone = zone;
734 plugin->iter_pkey = value_zone;
735 plugin->iter_result_found = GNUNET_NO;
736 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 714 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
737 "Performing reverse lookup for `%s'\n", 715 "Performing reverse lookup for `%s'\n",
738 GNUNET_GNSRECORD_z2s (value_zone)); 716 GNUNET_GNSRECORD_z2s (value_zone));
739 GNUNET_CONTAINER_multihashmap_iterate (plugin->hm, 717 GNUNET_CONTAINER_multihashmap_iterate (plugin->hm,
740 &zone_to_name, 718 &zone_to_name,
741 plugin); 719 &ztn);
742 return plugin->iter_result_found; 720 return ztn.result_found;
743} 721}
744 722
745 723
diff --git a/src/namestore/plugin_namestore_sqlite.c b/src/namestore/plugin_namestore_sqlite.c
index f62be1e18..34e548613 100644
--- a/src/namestore/plugin_namestore_sqlite.c
+++ b/src/namestore/plugin_namestore_sqlite.c
@@ -106,72 +106,6 @@ struct Plugin
106 106
107 107
108/** 108/**
109 * @brief Prepare a SQL statement
110 *
111 * @param dbh handle to the database
112 * @param zSql SQL statement, UTF-8 encoded
113 * @param ppStmt set to the prepared statement
114 * @return 0 on success
115 */
116static int
117sq_prepare (sqlite3 *dbh,
118 const char *zSql,
119 sqlite3_stmt **ppStmt)
120{
121 char *dummy;
122 int result;
123
124 result =
125 sqlite3_prepare_v2 (dbh,
126 zSql,
127 strlen (zSql),
128 ppStmt,
129 (const char **) &dummy);
130 LOG (GNUNET_ERROR_TYPE_DEBUG,
131 "Prepared `%s' / %p: %d\n",
132 zSql,
133 *ppStmt,
134 result);
135 return result;
136}
137
138
139/**
140 * Create our database indices.
141 *
142 * @param dbh handle to the database
143 */
144static void
145create_indices (sqlite3 * dbh)
146{
147 /* create indices */
148 if ( (SQLITE_OK !=
149 sqlite3_exec (dbh,
150 "CREATE INDEX IF NOT EXISTS ir_pkey_reverse "
151 "ON ns098records (zone_private_key,pkey)",
152 NULL, NULL, NULL)) ||
153 (SQLITE_OK !=
154 sqlite3_exec (dbh,
155 "CREATE INDEX IF NOT EXISTS ir_pkey_iter "
156 "ON ns098records (zone_private_key,uid)",
157 NULL, NULL, NULL)) )
158 LOG (GNUNET_ERROR_TYPE_ERROR,
159 "Failed to create indices: %s\n",
160 sqlite3_errmsg (dbh));
161}
162
163
164#if 0
165#define CHECK(a) GNUNET_break(a)
166#define ENULL NULL
167#else
168#define ENULL &e
169#define ENULL_DEFINED 1
170#define CHECK(a) if (! (a)) { GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "%s\n", e); sqlite3_free(e); }
171#endif
172
173
174/**
175 * Initialize the database connections and associated 109 * Initialize the database connections and associated
176 * data structures (create tables and indices 110 * data structures (create tables and indices
177 * as needed as well). 111 * as needed as well).
@@ -182,17 +116,66 @@ create_indices (sqlite3 * dbh)
182static int 116static int
183database_setup (struct Plugin *plugin) 117database_setup (struct Plugin *plugin)
184{ 118{
185 sqlite3_stmt *stmt; 119 char *sqlite_filename;
186 char *afsdir; 120 struct GNUNET_SQ_ExecuteStatement es[] = {
187#if ENULL_DEFINED 121 GNUNET_SQ_make_try_execute ("PRAGMA temp_store=MEMORY"),
188 char *e; 122 GNUNET_SQ_make_try_execute ("PRAGMA synchronous=NORMAL"),
189#endif 123 GNUNET_SQ_make_try_execute ("PRAGMA legacy_file_format=OFF"),
124 GNUNET_SQ_make_try_execute ("PRAGMA auto_vacuum=INCREMENTAL"),
125 GNUNET_SQ_make_try_execute ("PRAGMA encoding=\"UTF-8\""),
126 GNUNET_SQ_make_try_execute ("PRAGMA locking_mode=EXCLUSIVE"),
127 GNUNET_SQ_make_try_execute ("PRAGMA page_size=4092"),
128 GNUNET_SQ_make_execute ("CREATE TABLE IF NOT EXISTS ns098records ("
129 " uid INTEGER PRIMARY KEY,"
130 " zone_private_key BLOB NOT NULL,"
131 " pkey BLOB,"
132 " rvalue INT8 NOT NULL,"
133 " record_count INT NOT NULL,"
134 " record_data BLOB NOT NULL,"
135 " label TEXT NOT NULL"
136 ")"),
137 GNUNET_SQ_make_try_execute ("CREATE INDEX IF NOT EXISTS ir_pkey_reverse "
138 "ON ns098records (zone_private_key,pkey)"),
139 GNUNET_SQ_make_try_execute ("CREATE INDEX IF NOT EXISTS ir_pkey_iter "
140 "ON ns098records (zone_private_key,uid)"),
141 GNUNET_SQ_EXECUTE_STATEMENT_END
142 };
143 struct GNUNET_SQ_PrepareStatement ps[] = {
144 GNUNET_SQ_make_prepare ("INSERT INTO ns098records "
145 "(zone_private_key,pkey,rvalue,record_count,record_data,label)"
146 " VALUES (?, ?, ?, ?, ?, ?)",
147 &plugin->store_records),
148 GNUNET_SQ_make_prepare ("DELETE FROM ns098records "
149 "WHERE zone_private_key=? AND label=?",
150 &plugin->delete_records),
151 GNUNET_SQ_make_prepare ("SELECT uid,record_count,record_data,label"
152 " FROM ns098records"
153 " WHERE zone_private_key=? AND pkey=?",
154 &plugin->zone_to_name),
155 GNUNET_SQ_make_prepare ("SELECT uid,record_count,record_data,label"
156 " FROM ns098records"
157 " WHERE zone_private_key=? AND _rowid_ >= ?"
158 " ORDER BY _rowid_ ASC"
159 " LIMIT ?",
160 &plugin->iterate_zone),
161 GNUNET_SQ_make_prepare ("SELECT uid,record_count,record_data,label,zone_private_key"
162 " FROM ns098records"
163 " WHERE _rowid_ >= ?"
164 " ORDER BY _rowid_ ASC"
165 " LIMIT ?",
166 &plugin->iterate_all_zones),
167 GNUNET_SQ_make_prepare ("SELECT uid,record_count,record_data,label,zone_private_key"
168 " FROM ns098records"
169 " WHERE zone_private_key=? AND label=?",
170 &plugin->lookup_label),
171 GNUNET_SQ_PREPARE_END
172 };
190 173
191 if (GNUNET_OK != 174 if (GNUNET_OK !=
192 GNUNET_CONFIGURATION_get_value_filename (plugin->cfg, 175 GNUNET_CONFIGURATION_get_value_filename (plugin->cfg,
193 "namestore-sqlite", 176 "namestore-sqlite",
194 "FILENAME", 177 "FILENAME",
195 &afsdir)) 178 &sqlite_filename))
196 { 179 {
197 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, 180 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
198 "namestore-sqlite", 181 "namestore-sqlite",
@@ -200,132 +183,51 @@ database_setup (struct Plugin *plugin)
200 return GNUNET_SYSERR; 183 return GNUNET_SYSERR;
201 } 184 }
202 if (GNUNET_OK != 185 if (GNUNET_OK !=
203 GNUNET_DISK_file_test (afsdir)) 186 GNUNET_DISK_file_test (sqlite_filename))
204 { 187 {
205 if (GNUNET_OK != 188 if (GNUNET_OK !=
206 GNUNET_DISK_directory_create_for_file (afsdir)) 189 GNUNET_DISK_directory_create_for_file (sqlite_filename))
207 { 190 {
208 GNUNET_break (0); 191 GNUNET_break (0);
209 GNUNET_free (afsdir); 192 GNUNET_free (sqlite_filename);
210 return GNUNET_SYSERR; 193 return GNUNET_SYSERR;
211 } 194 }
212 } 195 }
213 /* afsdir should be UTF-8-encoded. If it isn't, it's a bug */ 196 /* sqlite_filename should be UTF-8-encoded. If it isn't, it's a bug */
214 plugin->fn = afsdir; 197 plugin->fn = sqlite_filename;
215 198
216 /* Open database and precompile statements */ 199 /* Open database and precompile statements */
217 if (sqlite3_open (plugin->fn, &plugin->dbh) != SQLITE_OK) 200 if (SQLITE_OK !=
201 sqlite3_open (plugin->fn,
202 &plugin->dbh))
218 { 203 {
219 LOG (GNUNET_ERROR_TYPE_ERROR, 204 LOG (GNUNET_ERROR_TYPE_ERROR,
220 _("Unable to initialize SQLite: %s.\n"), 205 _("Unable to initialize SQLite: %s.\n"),
221 sqlite3_errmsg (plugin->dbh)); 206 sqlite3_errmsg (plugin->dbh));
222 return GNUNET_SYSERR; 207 return GNUNET_SYSERR;
223 } 208 }
224 CHECK (SQLITE_OK == 209 GNUNET_break (SQLITE_OK ==
225 sqlite3_exec (plugin->dbh, 210 sqlite3_busy_timeout (plugin->dbh,
226 "PRAGMA temp_store=MEMORY", NULL, NULL, 211 BUSY_TIMEOUT_MS));
227 ENULL)); 212 if (GNUNET_OK !=
228 CHECK (SQLITE_OK == 213 GNUNET_SQ_exec_statements (plugin->dbh,
229 sqlite3_exec (plugin->dbh, 214 es))
230 "PRAGMA synchronous=NORMAL", NULL, NULL,
231 ENULL));
232 CHECK (SQLITE_OK ==
233 sqlite3_exec (plugin->dbh,
234 "PRAGMA legacy_file_format=OFF", NULL, NULL,
235 ENULL));
236 CHECK (SQLITE_OK ==
237 sqlite3_exec (plugin->dbh,
238 "PRAGMA auto_vacuum=INCREMENTAL", NULL,
239 NULL, ENULL));
240 CHECK (SQLITE_OK ==
241 sqlite3_exec (plugin->dbh,
242 "PRAGMA encoding=\"UTF-8\"", NULL,
243 NULL, ENULL));
244 CHECK (SQLITE_OK ==
245 sqlite3_exec (plugin->dbh,
246 "PRAGMA locking_mode=EXCLUSIVE", NULL, NULL,
247 ENULL));
248 CHECK (SQLITE_OK ==
249 sqlite3_exec (plugin->dbh,
250 "PRAGMA page_size=4092", NULL, NULL,
251 ENULL));
252
253 CHECK (SQLITE_OK ==
254 sqlite3_busy_timeout (plugin->dbh,
255 BUSY_TIMEOUT_MS));
256
257
258 /* Create table */
259 CHECK (SQLITE_OK ==
260 sq_prepare (plugin->dbh,
261 "SELECT 1 FROM sqlite_master WHERE tbl_name = 'ns098records'",
262 &stmt));
263 if ( (sqlite3_step (stmt) == SQLITE_DONE) &&
264 (SQLITE_OK !=
265 sqlite3_exec (plugin->dbh,
266 "CREATE TABLE ns098records ("
267 " uid INTEGER PRIMARY KEY,"
268 " zone_private_key BLOB NOT NULL,"
269 " pkey BLOB,"
270 " rvalue INT8 NOT NULL,"
271 " record_count INT NOT NULL,"
272 " record_data BLOB NOT NULL,"
273 " label TEXT NOT NULL"
274 ")",
275 NULL, NULL, NULL)) )
276 { 215 {
277 LOG_SQLITE (plugin, 216 GNUNET_break (0);
278 GNUNET_ERROR_TYPE_ERROR, 217 LOG (GNUNET_ERROR_TYPE_ERROR,
279 "sqlite3_exec"); 218 _("Failed to setup database at `%s'\n"),
280 sqlite3_finalize (stmt); 219 plugin->fn);
281 return GNUNET_SYSERR; 220 return GNUNET_SYSERR;
282 } 221 }
283 sqlite3_finalize (stmt); 222
284 223 if (GNUNET_OK !=
285 create_indices (plugin->dbh); 224 GNUNET_SQ_prepare (plugin->dbh,
286 225 ps))
287 if ( (SQLITE_OK !=
288 sq_prepare (plugin->dbh,
289 "INSERT INTO ns098records (zone_private_key, pkey, rvalue, record_count, record_data, label)"
290 " VALUES (?, ?, ?, ?, ?, ?)",
291 &plugin->store_records)) ||
292 (SQLITE_OK !=
293 sq_prepare (plugin->dbh,
294 "DELETE FROM ns098records WHERE zone_private_key=? AND label=?",
295 &plugin->delete_records)) ||
296 (SQLITE_OK !=
297 sq_prepare (plugin->dbh,
298 "SELECT uid,record_count,record_data,label"
299 " FROM ns098records"
300 " WHERE zone_private_key=? AND pkey=?",
301 &plugin->zone_to_name)) ||
302 (SQLITE_OK !=
303 sq_prepare (plugin->dbh,
304 "SELECT uid,record_count,record_data,label"
305 " FROM ns098records"
306 " WHERE zone_private_key=? AND _rowid_ >= ?"
307 " ORDER BY _rowid_ ASC"
308 " LIMIT ?",
309 &plugin->iterate_zone)) ||
310 (SQLITE_OK !=
311 sq_prepare (plugin->dbh,
312 "SELECT uid,record_count,record_data,label,zone_private_key"
313 " FROM ns098records"
314 " WHERE _rowid_ >= ?"
315 " ORDER BY _rowid_ ASC"
316 " LIMIT ?",
317 &plugin->iterate_all_zones)) ||
318 (SQLITE_OK !=
319 sq_prepare (plugin->dbh,
320 "SELECT uid,record_count,record_data,label,zone_private_key"
321 " FROM ns098records"
322 " WHERE zone_private_key=? AND label=?",
323 &plugin->lookup_label))
324 )
325 { 226 {
326 LOG_SQLITE (plugin, 227 GNUNET_break (0);
327 GNUNET_ERROR_TYPE_ERROR, 228 LOG (GNUNET_ERROR_TYPE_ERROR,
328 "precompiling"); 229 _("Failed to setup database at `%s'\n"),
230 plugin->fn);
329 return GNUNET_SYSERR; 231 return GNUNET_SYSERR;
330 } 232 }
331 return GNUNET_OK; 233 return GNUNET_OK;
diff --git a/src/namestore/test_namestore_api.conf b/src/namestore/test_namestore_api.conf
index 1e36c52fe..07409ea2b 100644
--- a/src/namestore/test_namestore_api.conf
+++ b/src/namestore/test_namestore_api.conf
@@ -15,13 +15,6 @@ AUTOSTART = YES
15[identity] 15[identity]
16AUTOSTART = YES 16AUTOSTART = YES
17 17
18[namestore-sqlite]
19FILENAME = $GNUNET_TEST_HOME/namestore/sqlite_test.db
20
21[namestore-postgres]
22CONFIG = connect_timeout=10; dbname=gnunetcheck
23TEMPORARY_TABLE = YES
24
25[nse] 18[nse]
26WORKBITS = 0 19WORKBITS = 0
27 20
diff --git a/src/namestore/test_namestore_api_flat.conf b/src/namestore/test_namestore_api_flat.conf
index 49fe25468..6a28306e3 100644
--- a/src/namestore/test_namestore_api_flat.conf
+++ b/src/namestore/test_namestore_api_flat.conf
@@ -2,3 +2,6 @@
2 2
3[namestore] 3[namestore]
4DATABASE = flat 4DATABASE = flat
5
6[namestore-flat]
7FILENAME = $GNUNET_TEST_HOME/namestore/flat.db
diff --git a/src/namestore/test_namestore_api_lookup_nick.c b/src/namestore/test_namestore_api_lookup_nick.c
index 50d1fd9a9..b9ae93bf2 100644
--- a/src/namestore/test_namestore_api_lookup_nick.c
+++ b/src/namestore/test_namestore_api_lookup_nick.c
@@ -52,7 +52,6 @@ static struct GNUNET_NAMESTORE_QueueEntry *nsqe;
52//static const char * name = "dummy.dummy.gnunet"; 52//static const char * name = "dummy.dummy.gnunet";
53static const char * name = "d"; 53static const char * name = "d";
54 54
55static char *directory;
56 55
57static void 56static void
58cleanup () 57cleanup ()
@@ -283,29 +282,22 @@ run (void *cls,
283 const struct GNUNET_CONFIGURATION_Handle *cfg, 282 const struct GNUNET_CONFIGURATION_Handle *cfg,
284 struct GNUNET_TESTING_Peer *peer) 283 struct GNUNET_TESTING_Peer *peer)
285{ 284{
286 char *hostkey_file;
287
288 directory = NULL;
289 GNUNET_assert (GNUNET_OK ==
290 GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS", "GNUNET_TEST_HOME", &directory));
291 GNUNET_DISK_directory_remove (directory);
292
293 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 285 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
294 &endbadly, NULL); 286 &endbadly,
295 GNUNET_asprintf (&hostkey_file, 287 NULL);
296 "zonefiles%s%s", 288 privkey = GNUNET_CRYPTO_ecdsa_key_create ();
297 DIR_SEPARATOR_STR,
298 "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
299 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
300 privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file);
301 GNUNET_free (hostkey_file);
302 GNUNET_assert (privkey != NULL); 289 GNUNET_assert (privkey != NULL);
303 GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey); 290 GNUNET_CRYPTO_ecdsa_key_get_public (privkey,
291 &pubkey);
304 292
305 nsh = GNUNET_NAMESTORE_connect (cfg); 293 nsh = GNUNET_NAMESTORE_connect (cfg);
306 GNUNET_break (NULL != nsh); 294 GNUNET_break (NULL != nsh);
307 295
308 nsqe = GNUNET_NAMESTORE_set_nick (nsh, privkey, TEST_NICK, &nick_cont, (void *) name); 296 nsqe = GNUNET_NAMESTORE_set_nick (nsh,
297 privkey,
298 TEST_NICK,
299 &nick_cont,
300 (void *) name);
309 if (NULL == nsqe) 301 if (NULL == nsqe)
310 { 302 {
311 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 303 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -324,6 +316,8 @@ main (int argc, char *argv[])
324 GNUNET_asprintf (&cfg_name, 316 GNUNET_asprintf (&cfg_name,
325 "test_namestore_api_%s.conf", 317 "test_namestore_api_%s.conf",
326 plugin_name); 318 plugin_name);
319 GNUNET_DISK_purge_cfg_dir (cfg_name,
320 "GNUNET_TEST_HOME");
327 res = 1; 321 res = 1;
328 if (0 != 322 if (0 !=
329 GNUNET_TESTING_peer_run ("test-namestore-api-lookup-nick", 323 GNUNET_TESTING_peer_run ("test-namestore-api-lookup-nick",
@@ -333,12 +327,9 @@ main (int argc, char *argv[])
333 { 327 {
334 res = 1; 328 res = 1;
335 } 329 }
330 GNUNET_DISK_purge_cfg_dir (cfg_name,
331 "GNUNET_TEST_HOME");
336 GNUNET_free (cfg_name); 332 GNUNET_free (cfg_name);
337 if (NULL != directory)
338 {
339 GNUNET_DISK_directory_remove (directory);
340 GNUNET_free (directory);
341 }
342 return res; 333 return res;
343} 334}
344 335
diff --git a/src/namestore/test_namestore_api_lookup_private.c b/src/namestore/test_namestore_api_lookup_private.c
index 7866749f1..689e73a2e 100644
--- a/src/namestore/test_namestore_api_lookup_private.c
+++ b/src/namestore/test_namestore_api_lookup_private.c
@@ -48,7 +48,6 @@ static struct GNUNET_NAMESTORE_QueueEntry *nsqe;
48//static const char * name = "dummy.dummy.gnunet"; 48//static const char * name = "dummy.dummy.gnunet";
49static const char * name = "d"; 49static const char * name = "d";
50 50
51static char *directory;
52 51
53static void 52static void
54cleanup () 53cleanup ()
@@ -71,11 +70,11 @@ cleanup ()
71 * Re-establish the connection to the service. 70 * Re-establish the connection to the service.
72 * 71 *
73 * @param cls handle to use to re-connect. 72 * @param cls handle to use to re-connect.
74 * @param tc scheduler context
75 */ 73 */
76static void 74static void
77endbadly (void *cls) 75endbadly (void *cls)
78{ 76{
77 endbadly_task = NULL;
79 if (NULL != nsqe) 78 if (NULL != nsqe)
80 { 79 {
81 GNUNET_NAMESTORE_cancel (nsqe); 80 GNUNET_NAMESTORE_cancel (nsqe);
@@ -109,7 +108,7 @@ lookup_it (void *cls,
109 { 108 {
110 GNUNET_break(0); 109 GNUNET_break(0);
111 GNUNET_SCHEDULER_cancel (endbadly_task); 110 GNUNET_SCHEDULER_cancel (endbadly_task);
112 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL ); 111 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
113 return; 112 return;
114 } 113 }
115 114
@@ -118,7 +117,7 @@ lookup_it (void *cls,
118 { 117 {
119 GNUNET_break(0); 118 GNUNET_break(0);
120 GNUNET_SCHEDULER_cancel (endbadly_task); 119 GNUNET_SCHEDULER_cancel (endbadly_task);
121 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL ); 120 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
122 return; 121 return;
123 } 122 }
124 123
@@ -126,7 +125,7 @@ lookup_it (void *cls,
126 { 125 {
127 GNUNET_break(0); 126 GNUNET_break(0);
128 GNUNET_SCHEDULER_cancel (endbadly_task); 127 GNUNET_SCHEDULER_cancel (endbadly_task);
129 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL ); 128 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
130 return; 129 return;
131 } 130 }
132 131
@@ -134,14 +133,14 @@ lookup_it (void *cls,
134 { 133 {
135 GNUNET_break(0); 134 GNUNET_break(0);
136 GNUNET_SCHEDULER_cancel (endbadly_task); 135 GNUNET_SCHEDULER_cancel (endbadly_task);
137 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL ); 136 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
138 return; 137 return;
139 } 138 }
140 139
141 /* Done */ 140 /* Done */
142 GNUNET_SCHEDULER_cancel (endbadly_task); 141 GNUNET_SCHEDULER_cancel (endbadly_task);
143 endbadly_task = NULL; 142 endbadly_task = NULL;
144 GNUNET_SCHEDULER_add_now (&end, NULL ); 143 GNUNET_SCHEDULER_add_now (&end, NULL);
145} 144}
146 145
147 146
@@ -153,7 +152,9 @@ fail_cb (void *cls)
153 152
154 153
155static void 154static void
156put_cont (void *cls, int32_t success, const char *emsg) 155put_cont (void *cls,
156 int32_t success,
157 const char *emsg)
157{ 158{
158 const char *name = cls; 159 const char *name = cls;
159 160
@@ -187,22 +188,11 @@ run (void *cls,
187 struct GNUNET_TESTING_Peer *peer) 188 struct GNUNET_TESTING_Peer *peer)
188{ 189{
189 struct GNUNET_GNSRECORD_Data rd; 190 struct GNUNET_GNSRECORD_Data rd;
190 char *hostkey_file;
191
192 directory = NULL;
193 GNUNET_assert (GNUNET_OK ==
194 GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS", "GNUNET_TEST_HOME", &directory));
195 GNUNET_DISK_directory_remove (directory);
196 191
197 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 192 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
198 &endbadly, NULL); 193 &endbadly,
199 GNUNET_asprintf (&hostkey_file, 194 NULL);
200 "zonefiles%s%s", 195 privkey = GNUNET_CRYPTO_ecdsa_key_create ();
201 DIR_SEPARATOR_STR,
202 "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
203 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
204 privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file);
205 GNUNET_free (hostkey_file);
206 GNUNET_assert (privkey != NULL); 196 GNUNET_assert (privkey != NULL);
207 GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey); 197 GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey);
208 198
@@ -215,8 +205,13 @@ run (void *cls,
215 205
216 nsh = GNUNET_NAMESTORE_connect (cfg); 206 nsh = GNUNET_NAMESTORE_connect (cfg);
217 GNUNET_break (NULL != nsh); 207 GNUNET_break (NULL != nsh);
218 nsqe = GNUNET_NAMESTORE_records_store (nsh, privkey, name, 208 nsqe = GNUNET_NAMESTORE_records_store (nsh,
219 1, &rd, &put_cont, (void *) name); 209 privkey,
210 name,
211 1,
212 &rd,
213 &put_cont,
214 (void *) name);
220 if (NULL == nsqe) 215 if (NULL == nsqe)
221 { 216 {
222 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 217 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -237,6 +232,8 @@ main (int argc, char *argv[])
237 GNUNET_asprintf (&cfg_name, 232 GNUNET_asprintf (&cfg_name,
238 "test_namestore_api_%s.conf", 233 "test_namestore_api_%s.conf",
239 plugin_name); 234 plugin_name);
235 GNUNET_DISK_purge_cfg_dir (cfg_name,
236 "GNUNET_TEST_HOME");
240 res = 1; 237 res = 1;
241 if (0 != 238 if (0 !=
242 GNUNET_TESTING_peer_run ("test-namestore-api-lookup-private", 239 GNUNET_TESTING_peer_run ("test-namestore-api-lookup-private",
@@ -246,12 +243,9 @@ main (int argc, char *argv[])
246 { 243 {
247 res = 1; 244 res = 1;
248 } 245 }
246 GNUNET_DISK_purge_cfg_dir (cfg_name,
247 "GNUNET_TEST_HOME");
249 GNUNET_free (cfg_name); 248 GNUNET_free (cfg_name);
250 if (NULL != directory)
251 {
252 GNUNET_DISK_directory_remove (directory);
253 GNUNET_free (directory);
254 }
255 return res; 249 return res;
256} 250}
257 251
diff --git a/src/namestore/test_namestore_api_lookup_public.c b/src/namestore/test_namestore_api_lookup_public.c
index 02ca16042..28a68daf9 100644
--- a/src/namestore/test_namestore_api_lookup_public.c
+++ b/src/namestore/test_namestore_api_lookup_public.c
@@ -51,7 +51,6 @@ static struct GNUNET_NAMESTORE_QueueEntry *nsqe;
51 51
52static struct GNUNET_NAMECACHE_QueueEntry *ncqe; 52static struct GNUNET_NAMECACHE_QueueEntry *ncqe;
53 53
54static char *directory;
55 54
56static void 55static void
57cleanup () 56cleanup ()
@@ -190,26 +189,15 @@ run (void *cls,
190 struct GNUNET_TESTING_Peer *peer) 189 struct GNUNET_TESTING_Peer *peer)
191{ 190{
192 struct GNUNET_GNSRECORD_Data rd; 191 struct GNUNET_GNSRECORD_Data rd;
193 char *hostkey_file;
194 const char * name = "dummy.dummy.gnunet"; 192 const char * name = "dummy.dummy.gnunet";
195 193
196 directory = NULL;
197 GNUNET_assert (GNUNET_OK ==
198 GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS", "GNUNET_TEST_HOME", &directory));
199 GNUNET_DISK_directory_remove (directory);
200
201 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 194 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
202 &endbadly, NULL); 195 &endbadly,
203 GNUNET_asprintf (&hostkey_file, 196 NULL);
204 "zonefiles%s%s", 197 privkey = GNUNET_CRYPTO_ecdsa_key_create ();
205 DIR_SEPARATOR_STR,
206 "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
207 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
208 privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file);
209 GNUNET_free (hostkey_file);
210 GNUNET_assert (privkey != NULL); 198 GNUNET_assert (privkey != NULL);
211 GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey); 199 GNUNET_CRYPTO_ecdsa_key_get_public (privkey,
212 200 &pubkey);
213 201
214 rd.expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000; 202 rd.expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000;
215 rd.record_type = TEST_RECORD_TYPE; 203 rd.record_type = TEST_RECORD_TYPE;
@@ -244,6 +232,8 @@ main (int argc, char *argv[])
244 GNUNET_asprintf (&cfg_name, 232 GNUNET_asprintf (&cfg_name,
245 "test_namestore_api_%s.conf", 233 "test_namestore_api_%s.conf",
246 plugin_name); 234 plugin_name);
235 GNUNET_DISK_purge_cfg_dir (cfg_name,
236 "GNUNET_TEST_HOME");
247 res = 1; 237 res = 1;
248 if (0 != 238 if (0 !=
249 GNUNET_TESTING_peer_run ("test-namestore-api", 239 GNUNET_TESTING_peer_run ("test-namestore-api",
@@ -253,12 +243,9 @@ main (int argc, char *argv[])
253 { 243 {
254 res = 1; 244 res = 1;
255 } 245 }
246 GNUNET_DISK_purge_cfg_dir (cfg_name,
247 "GNUNET_TEST_HOME");
256 GNUNET_free (cfg_name); 248 GNUNET_free (cfg_name);
257 if (NULL != directory)
258 {
259 GNUNET_DISK_directory_remove (directory);
260 GNUNET_free (directory);
261 }
262 return res; 249 return res;
263} 250}
264 251
diff --git a/src/namestore/test_namestore_api_lookup_shadow.c b/src/namestore/test_namestore_api_lookup_shadow.c
index e80335796..39ce4e564 100644
--- a/src/namestore/test_namestore_api_lookup_shadow.c
+++ b/src/namestore/test_namestore_api_lookup_shadow.c
@@ -53,7 +53,6 @@ static struct GNUNET_NAMESTORE_QueueEntry *nsqe;
53 53
54static struct GNUNET_NAMECACHE_QueueEntry *ncqe; 54static struct GNUNET_NAMECACHE_QueueEntry *ncqe;
55 55
56static char *directory;
57 56
58static void 57static void
59cleanup () 58cleanup ()
@@ -222,26 +221,15 @@ run (void *cls,
222 struct GNUNET_TESTING_Peer *peer) 221 struct GNUNET_TESTING_Peer *peer)
223{ 222{
224 struct GNUNET_GNSRECORD_Data rd; 223 struct GNUNET_GNSRECORD_Data rd;
225 char *hostkey_file;
226 const char * name = "dummy.dummy.gnunet"; 224 const char * name = "dummy.dummy.gnunet";
227 225
228 directory = NULL;
229 GNUNET_assert (GNUNET_OK ==
230 GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS", "GNUNET_TEST_HOME", &directory));
231 GNUNET_DISK_directory_remove (directory);
232
233 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 226 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
234 &endbadly, NULL); 227 &endbadly,
235 GNUNET_asprintf (&hostkey_file, 228 NULL);
236 "zonefiles%s%s", 229 privkey = GNUNET_CRYPTO_ecdsa_key_create ();
237 DIR_SEPARATOR_STR,
238 "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
239 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
240 privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file);
241 GNUNET_free (hostkey_file);
242 GNUNET_assert (privkey != NULL); 230 GNUNET_assert (privkey != NULL);
243 GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey); 231 GNUNET_CRYPTO_ecdsa_key_get_public (privkey,
244 232 &pubkey);
245 rd.expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000; 233 rd.expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000;
246 rd.record_type = TEST_RECORD_TYPE; 234 rd.record_type = TEST_RECORD_TYPE;
247 rd.data_size = TEST_RECORD_DATALEN; 235 rd.data_size = TEST_RECORD_DATALEN;
@@ -253,8 +241,13 @@ run (void *cls,
253 nch = GNUNET_NAMECACHE_connect (cfg); 241 nch = GNUNET_NAMECACHE_connect (cfg);
254 GNUNET_break (NULL != nsh); 242 GNUNET_break (NULL != nsh);
255 GNUNET_break (NULL != nch); 243 GNUNET_break (NULL != nch);
256 nsqe = GNUNET_NAMESTORE_records_store (nsh, privkey, name, 244 nsqe = GNUNET_NAMESTORE_records_store (nsh,
257 1, &rd, &put_cont, (void *) name); 245 privkey,
246 name,
247 1,
248 &rd,
249 &put_cont,
250 (void *) name);
258 if (NULL == nsqe) 251 if (NULL == nsqe)
259 { 252 {
260 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 253 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -274,6 +267,8 @@ main (int argc, char *argv[])
274 GNUNET_asprintf (&cfg_name, 267 GNUNET_asprintf (&cfg_name,
275 "test_namestore_api_%s.conf", 268 "test_namestore_api_%s.conf",
276 plugin_name); 269 plugin_name);
270 GNUNET_DISK_purge_cfg_dir (cfg_name,
271 "GNUNET_TEST_HOME");
277 res = 1; 272 res = 1;
278 if (0 != 273 if (0 !=
279 GNUNET_TESTING_peer_run ("test-namestore-api-lookup-shadow", 274 GNUNET_TESTING_peer_run ("test-namestore-api-lookup-shadow",
@@ -284,11 +279,8 @@ main (int argc, char *argv[])
284 res = 1; 279 res = 1;
285 } 280 }
286 GNUNET_free (cfg_name); 281 GNUNET_free (cfg_name);
287 if (NULL != directory) 282 GNUNET_DISK_purge_cfg_dir (cfg_name,
288 { 283 "GNUNET_TEST_HOME");
289 GNUNET_DISK_directory_remove (directory);
290 GNUNET_free (directory);
291 }
292 return res; 284 return res;
293} 285}
294 286
diff --git a/src/namestore/test_namestore_api_lookup_shadow_filter.c b/src/namestore/test_namestore_api_lookup_shadow_filter.c
index 5b8811a23..09fd8ce07 100644
--- a/src/namestore/test_namestore_api_lookup_shadow_filter.c
+++ b/src/namestore/test_namestore_api_lookup_shadow_filter.c
@@ -66,7 +66,6 @@ static struct GNUNET_HashCode derived_hash;
66 66
67static struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; 67static struct GNUNET_CRYPTO_EcdsaPublicKey pubkey;
68 68
69static char *directory;
70 69
71static void 70static void
72cleanup () 71cleanup ()
@@ -291,26 +290,16 @@ run (void *cls,
291 const struct GNUNET_CONFIGURATION_Handle *cfg, 290 const struct GNUNET_CONFIGURATION_Handle *cfg,
292 struct GNUNET_TESTING_Peer *peer) 291 struct GNUNET_TESTING_Peer *peer)
293{ 292{
294 char *hostkey_file;
295
296 directory = NULL;
297 GNUNET_assert (GNUNET_OK ==
298 GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS", "GNUNET_TEST_HOME", &directory));
299 GNUNET_DISK_directory_remove (directory);
300
301 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 293 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
302 &endbadly, NULL); 294 &endbadly,
303 GNUNET_asprintf (&hostkey_file, 295 NULL);
304 "zonefiles%s%s", 296 privkey = GNUNET_CRYPTO_ecdsa_key_create ();
305 DIR_SEPARATOR_STR,
306 "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
307 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
308 privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file);
309 GNUNET_free (hostkey_file);
310 GNUNET_assert (privkey != NULL); 297 GNUNET_assert (privkey != NULL);
311 GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey); 298 GNUNET_CRYPTO_ecdsa_key_get_public (privkey,
299 &pubkey);
312 300
313 record_expiration = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), EXPIRATION); 301 record_expiration = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get(),
302 EXPIRATION);
314 records[0].expiration_time = record_expiration.abs_value_us; 303 records[0].expiration_time = record_expiration.abs_value_us;
315 records[0].record_type = TEST_RECORD_TYPE; 304 records[0].record_type = TEST_RECORD_TYPE;
316 records[0].data_size = TEST_RECORD_DATALEN; 305 records[0].data_size = TEST_RECORD_DATALEN;
@@ -352,6 +341,8 @@ main (int argc, char *argv[])
352 GNUNET_asprintf (&cfg_name, 341 GNUNET_asprintf (&cfg_name,
353 "test_namestore_api_%s.conf", 342 "test_namestore_api_%s.conf",
354 plugin_name); 343 plugin_name);
344 GNUNET_DISK_purge_cfg_dir (cfg_name,
345 "GNUNET_TEST_HOME");
355 res = 1; 346 res = 1;
356 if (0 != 347 if (0 !=
357 GNUNET_TESTING_peer_run ("test-namestore-api-lookup-shadow-filter", 348 GNUNET_TESTING_peer_run ("test-namestore-api-lookup-shadow-filter",
@@ -362,11 +353,8 @@ main (int argc, char *argv[])
362 res = 1; 353 res = 1;
363 } 354 }
364 GNUNET_free (cfg_name); 355 GNUNET_free (cfg_name);
365 if (NULL != directory) 356 GNUNET_DISK_purge_cfg_dir (cfg_name,
366 { 357 "GNUNET_TEST_HOME");
367 GNUNET_DISK_directory_remove (directory);
368 GNUNET_free (directory);
369 }
370 return res; 358 return res;
371} 359}
372 360
diff --git a/src/namestore/test_namestore_api_monitoring.c b/src/namestore/test_namestore_api_monitoring.c
index cd38b2c80..de202d535 100644
--- a/src/namestore/test_namestore_api_monitoring.c
+++ b/src/namestore/test_namestore_api_monitoring.c
@@ -56,7 +56,6 @@ static struct GNUNET_GNSRECORD_Data *s_rd_3;
56 56
57struct GNUNET_NAMESTORE_QueueEntry * ns_ops[3]; 57struct GNUNET_NAMESTORE_QueueEntry * ns_ops[3];
58 58
59static char *directory;
60 59
61static void 60static void
62do_shutdown () 61do_shutdown ()
@@ -66,7 +65,6 @@ do_shutdown ()
66 GNUNET_NAMESTORE_zone_monitor_stop (zm); 65 GNUNET_NAMESTORE_zone_monitor_stop (zm);
67 zm = NULL; 66 zm = NULL;
68 } 67 }
69
70 if (NULL != ns_ops[0]) 68 if (NULL != ns_ops[0])
71 { 69 {
72 GNUNET_NAMESTORE_cancel(ns_ops[0]); 70 GNUNET_NAMESTORE_cancel(ns_ops[0]);
@@ -82,13 +80,11 @@ do_shutdown ()
82 GNUNET_NAMESTORE_cancel(ns_ops[2]); 80 GNUNET_NAMESTORE_cancel(ns_ops[2]);
83 ns_ops[2] = NULL; 81 ns_ops[2] = NULL;
84 } 82 }
85
86 if (NULL != nsh) 83 if (NULL != nsh)
87 { 84 {
88 GNUNET_NAMESTORE_disconnect (nsh); 85 GNUNET_NAMESTORE_disconnect (nsh);
89 nsh = NULL; 86 nsh = NULL;
90 } 87 }
91
92 GNUNET_free_non_null(s_name_1); 88 GNUNET_free_non_null(s_name_1);
93 GNUNET_free_non_null(s_name_2); 89 GNUNET_free_non_null(s_name_2);
94 GNUNET_free_non_null(s_name_3); 90 GNUNET_free_non_null(s_name_3);
@@ -284,23 +280,8 @@ run (void *cls,
284 const struct GNUNET_CONFIGURATION_Handle *cfg, 280 const struct GNUNET_CONFIGURATION_Handle *cfg,
285 struct GNUNET_TESTING_Peer *peer) 281 struct GNUNET_TESTING_Peer *peer)
286{ 282{
287 char *hostkey_file;
288
289 res = 1; 283 res = 1;
290 284 privkey = GNUNET_CRYPTO_ecdsa_key_create ();
291 directory = NULL;
292 GNUNET_assert (GNUNET_OK ==
293 GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS", "GNUNET_TEST_HOME", &directory));
294 GNUNET_DISK_directory_remove (directory);
295
296 GNUNET_asprintf(&hostkey_file,
297 "zonefiles%s%s",
298 DIR_SEPARATOR_STR,
299 "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
300 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
301 "Using zonekey file `%s' \n", hostkey_file);
302 privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file);
303 GNUNET_free (hostkey_file);
304 GNUNET_assert (privkey != NULL); 285 GNUNET_assert (privkey != NULL);
305 286
306 /* Start monitoring */ 287 /* Start monitoring */
@@ -333,16 +314,12 @@ run (void *cls,
333 return; 314 return;
334 } 315 }
335 316
336 GNUNET_asprintf(&hostkey_file,"zonefiles%s%s", 317 privkey2 = GNUNET_CRYPTO_ecdsa_key_create ();
337 DIR_SEPARATOR_STR,
338 "HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey");
339 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
340 privkey2 = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file);
341 GNUNET_free (hostkey_file);
342 GNUNET_assert (privkey2 != NULL); 318 GNUNET_assert (privkey2 != NULL);
343 319
344 320
345 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 3\n"); 321 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
322 "Created record 3\n");
346 /* name in different zone */ 323 /* name in different zone */
347 GNUNET_asprintf(&s_name_3, "dummy3"); 324 GNUNET_asprintf(&s_name_3, "dummy3");
348 s_rd_3 = create_record(1); 325 s_rd_3 = create_record(1);
@@ -358,22 +335,33 @@ run (void *cls,
358 "Created record 1\n"); 335 "Created record 1\n");
359 GNUNET_asprintf(&s_name_1, "dummy1"); 336 GNUNET_asprintf(&s_name_1, "dummy1");
360 s_rd_1 = create_record(1); 337 s_rd_1 = create_record(1);
361 GNUNET_assert (NULL != (ns_ops[0] = GNUNET_NAMESTORE_records_store(nsh, privkey, s_name_1, 338 GNUNET_assert (NULL != (ns_ops[0] =
362 1, s_rd_1, &put_cont, s_name_1))); 339 GNUNET_NAMESTORE_records_store (nsh,
340 privkey,
341 s_name_1,
342 1,
343 s_rd_1,
344 &put_cont,
345 s_name_1)));
363 346
364 347
365 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 2 \n"); 348 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 2 \n");
366 GNUNET_asprintf(&s_name_2, "dummy2"); 349 GNUNET_asprintf(&s_name_2, "dummy2");
367 s_rd_2 = create_record(1); 350 s_rd_2 = create_record(1);
368 GNUNET_assert (NULL != (ns_ops[1] = GNUNET_NAMESTORE_records_store(nsh, privkey, s_name_2, 351 GNUNET_assert (NULL != (ns_ops[1] =
369 1, s_rd_2, &put_cont, s_name_2))); 352 GNUNET_NAMESTORE_records_store (nsh,
370 353 privkey,
371 354 s_name_2,
355 1,
356 s_rd_2,
357 &put_cont,
358 s_name_2)));
372} 359}
373 360
374 361
375int 362int
376main (int argc, char *argv[]) 363main (int argc,
364 char *argv[])
377{ 365{
378 const char *plugin_name; 366 const char *plugin_name;
379 char *cfg_name; 367 char *cfg_name;
@@ -382,6 +370,8 @@ main (int argc, char *argv[])
382 GNUNET_asprintf (&cfg_name, 370 GNUNET_asprintf (&cfg_name,
383 "test_namestore_api_%s.conf", 371 "test_namestore_api_%s.conf",
384 plugin_name); 372 plugin_name);
373 GNUNET_DISK_purge_cfg_dir (cfg_name,
374 "GNUNET_TEST_HOME");
385 res = 1; 375 res = 1;
386 if (0 != 376 if (0 !=
387 GNUNET_TESTING_peer_run ("test-namestore-api-monitoring", 377 GNUNET_TESTING_peer_run ("test-namestore-api-monitoring",
@@ -391,12 +381,9 @@ main (int argc, char *argv[])
391 { 381 {
392 res = 1; 382 res = 1;
393 } 383 }
384 GNUNET_DISK_purge_cfg_dir (cfg_name,
385 "GNUNET_TEST_HOME");
394 GNUNET_free (cfg_name); 386 GNUNET_free (cfg_name);
395 if (NULL != directory)
396 {
397 GNUNET_DISK_directory_remove (directory);
398 GNUNET_free (directory);
399 }
400 return res; 387 return res;
401} 388}
402 389
diff --git a/src/namestore/test_namestore_api_monitoring_existing.c b/src/namestore/test_namestore_api_monitoring_existing.c
index f6a74609e..449b36d65 100644
--- a/src/namestore/test_namestore_api_monitoring_existing.c
+++ b/src/namestore/test_namestore_api_monitoring_existing.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2013 GNUnet e.V. 3 Copyright (C) 2013, 2018 GNUnet e.V.
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -18,7 +18,7 @@
18 Boston, MA 02110-1301, USA. 18 Boston, MA 02110-1301, USA.
19*/ 19*/
20/** 20/**
21 * @file namestore/test_namestore_api_monitoring.c 21 * @file namestore/test_namestore_api_monitoring_existing.c
22 * @brief testcase for zone monitoring functionality: add records first, then monitor 22 * @brief testcase for zone monitoring functionality: add records first, then monitor
23 */ 23 */
24#include "platform.h" 24#include "platform.h"
@@ -27,7 +27,7 @@
27#include "namestore.h" 27#include "namestore.h"
28 28
29 29
30#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100) 30#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
31 31
32static const struct GNUNET_CONFIGURATION_Handle *cfg; 32static const struct GNUNET_CONFIGURATION_Handle *cfg;
33 33
@@ -57,18 +57,30 @@ static struct GNUNET_GNSRECORD_Data *s_rd_3;
57 57
58struct GNUNET_NAMESTORE_QueueEntry * ns_ops[3]; 58struct GNUNET_NAMESTORE_QueueEntry * ns_ops[3];
59 59
60static char *directory; 60
61/**
62 * Re-establish the connection to the service.
63 *
64 * @param cls handle to use to re-connect.
65 */
66static void
67endbadly (void *cls)
68{
69 endbadly_task = NULL;
70 GNUNET_break (0);
71 GNUNET_SCHEDULER_shutdown ();
72 res = 1;
73}
61 74
62 75
63static void 76static void
64do_shutdown () 77end (void *cls)
65{ 78{
66 if (NULL != zm) 79 if (NULL != zm)
67 { 80 {
68 GNUNET_NAMESTORE_zone_monitor_stop (zm); 81 GNUNET_NAMESTORE_zone_monitor_stop (zm);
69 zm = NULL; 82 zm = NULL;
70 } 83 }
71
72 if (NULL != ns_ops[0]) 84 if (NULL != ns_ops[0])
73 { 85 {
74 GNUNET_NAMESTORE_cancel(ns_ops[0]); 86 GNUNET_NAMESTORE_cancel(ns_ops[0]);
@@ -84,7 +96,11 @@ do_shutdown ()
84 GNUNET_NAMESTORE_cancel(ns_ops[2]); 96 GNUNET_NAMESTORE_cancel(ns_ops[2]);
85 ns_ops[2] = NULL; 97 ns_ops[2] = NULL;
86 } 98 }
87 99 if (NULL != endbadly_task)
100 {
101 GNUNET_SCHEDULER_cancel (endbadly_task);
102 endbadly_task = NULL;
103 }
88 if (NULL != nsh) 104 if (NULL != nsh)
89 { 105 {
90 GNUNET_NAMESTORE_disconnect (nsh); 106 GNUNET_NAMESTORE_disconnect (nsh);
@@ -124,27 +140,6 @@ do_shutdown ()
124} 140}
125 141
126 142
127/**
128 * Re-establish the connection to the service.
129 *
130 * @param cls handle to use to re-connect.
131 */
132static void
133endbadly (void *cls)
134{
135 do_shutdown ();
136 res = 1;
137}
138
139
140static void
141end (void *cls)
142{
143 do_shutdown ();
144 res = 0;
145}
146
147
148static void 143static void
149zone_proc (void *cls, 144zone_proc (void *cls,
150 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, 145 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
@@ -166,9 +161,7 @@ zone_proc (void *cls,
166 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 161 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
167 "Monitoring returned wrong zone key\n"); 162 "Monitoring returned wrong zone key\n");
168 GNUNET_break (0); 163 GNUNET_break (0);
169 GNUNET_SCHEDULER_cancel (endbadly_task); 164 GNUNET_SCHEDULER_shutdown ();
170 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly,
171 NULL);
172 return; 165 return;
173 } 166 }
174 167
@@ -203,17 +196,16 @@ zone_proc (void *cls,
203 1); 196 1);
204 if (2 == ++returned_records) 197 if (2 == ++returned_records)
205 { 198 {
206 if (endbadly_task != NULL) 199 GNUNET_SCHEDULER_shutdown ();
200 if (GNUNET_YES == fail)
207 { 201 {
208 GNUNET_SCHEDULER_cancel (endbadly_task); 202 GNUNET_break (0);
209 endbadly_task = NULL; 203 res = 1;
210 } 204 }
211 if (GNUNET_YES == fail)
212 GNUNET_SCHEDULER_add_now (&endbadly,
213 NULL);
214 else 205 else
215 GNUNET_SCHEDULER_add_now (&end, 206 {
216 NULL); 207 res = 0;
208 }
217 } 209 }
218} 210}
219 211
@@ -260,8 +252,9 @@ put_cont (void *cls,
260 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 252 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
261 "Failed to created records\n"); 253 "Failed to created records\n");
262 GNUNET_break (0); 254 GNUNET_break (0);
263 GNUNET_SCHEDULER_cancel (endbadly_task); 255 res = 1;
264 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); 256 GNUNET_SCHEDULER_shutdown ();
257 return;
265 } 258 }
266 259
267 if (3 == c) 260 if (3 == c)
@@ -281,8 +274,8 @@ put_cont (void *cls,
281 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 274 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
282 "Failed to create zone monitor\n"); 275 "Failed to create zone monitor\n");
283 GNUNET_break (0); 276 GNUNET_break (0);
284 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, 277 res = 1;
285 NULL); 278 GNUNET_SCHEDULER_shutdown ();
286 return; 279 return;
287 } 280 }
288 } 281 }
@@ -316,30 +309,16 @@ run (void *cls,
316 const struct GNUNET_CONFIGURATION_Handle *mycfg, 309 const struct GNUNET_CONFIGURATION_Handle *mycfg,
317 struct GNUNET_TESTING_Peer *peer) 310 struct GNUNET_TESTING_Peer *peer)
318{ 311{
319 char *hostkey_file;
320
321 directory = NULL;
322 GNUNET_assert (GNUNET_OK ==
323 GNUNET_CONFIGURATION_get_value_string (mycfg,
324 "PATHS",
325 "GNUNET_TEST_HOME",
326 &directory));
327 GNUNET_DISK_directory_remove (directory);
328
329 res = 1; 312 res = 1;
330 313 privkey = GNUNET_CRYPTO_ecdsa_key_create ();
331 GNUNET_asprintf(&hostkey_file,
332 "zonefiles%s%s",
333 DIR_SEPARATOR_STR,
334 "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
335 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
336 "Using zonekey file `%s' \n", hostkey_file);
337 privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file);
338 GNUNET_free (hostkey_file);
339 GNUNET_assert (privkey != NULL); 314 GNUNET_assert (privkey != NULL);
340 315
341 cfg = mycfg; 316 cfg = mycfg;
342 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &endbadly, NULL); 317 GNUNET_SCHEDULER_add_shutdown (&end,
318 NULL);
319 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
320 &endbadly,
321 NULL);
343 /* Connect to namestore */ 322 /* Connect to namestore */
344 nsh = GNUNET_NAMESTORE_connect (cfg); 323 nsh = GNUNET_NAMESTORE_connect (cfg);
345 if (NULL == nsh) 324 if (NULL == nsh)
@@ -350,12 +329,7 @@ run (void *cls,
350 return; 329 return;
351 } 330 }
352 331
353 GNUNET_asprintf(&hostkey_file,"zonefiles%s%s", 332 privkey2 = GNUNET_CRYPTO_ecdsa_key_create ();
354 DIR_SEPARATOR_STR,
355 "HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey");
356 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
357 privkey2 = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file);
358 GNUNET_free (hostkey_file);
359 GNUNET_assert (privkey2 != NULL); 333 GNUNET_assert (privkey2 != NULL);
360 334
361 335
@@ -363,16 +337,29 @@ run (void *cls,
363 /* name in different zone */ 337 /* name in different zone */
364 GNUNET_asprintf(&s_name_3, "dummy3"); 338 GNUNET_asprintf(&s_name_3, "dummy3");
365 s_rd_3 = create_record(1); 339 s_rd_3 = create_record(1);
366 GNUNET_assert (NULL != (ns_ops[2] = GNUNET_NAMESTORE_records_store (nsh, privkey2, s_name_3, 340 GNUNET_assert (NULL != (ns_ops[2] =
367 1, s_rd_3, &put_cont, s_name_3))); 341 GNUNET_NAMESTORE_records_store (nsh,
342 privkey2,
343 s_name_3,
344 1,
345 s_rd_3,
346 &put_cont,
347 s_name_3)));
368 348
369 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 1\n"); 349 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
350 "Created record 1\n");
370 GNUNET_asprintf(&s_name_1, "dummy1"); 351 GNUNET_asprintf(&s_name_1, "dummy1");
371 s_rd_1 = create_record(1); 352 s_rd_1 = create_record(1);
372 GNUNET_assert (NULL != (ns_ops[0] = GNUNET_NAMESTORE_records_store(nsh, privkey, s_name_1, 353 GNUNET_assert (NULL != (ns_ops[0] =
373 1, s_rd_1, &put_cont, s_name_1))); 354 GNUNET_NAMESTORE_records_store(nsh,
374 355 privkey,
375 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 2 \n"); 356 s_name_1,
357 1,
358 s_rd_1,
359 &put_cont,
360 s_name_1)));
361 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
362 "Created record 2 \n");
376 GNUNET_asprintf(&s_name_2, "dummy2"); 363 GNUNET_asprintf(&s_name_2, "dummy2");
377 s_rd_2 = create_record(1); 364 s_rd_2 = create_record(1);
378 GNUNET_assert (NULL != (ns_ops[1] = 365 GNUNET_assert (NULL != (ns_ops[1] =
@@ -397,6 +384,8 @@ main (int argc, char *argv[])
397 "test_namestore_api_%s.conf", 384 "test_namestore_api_%s.conf",
398 plugin_name); 385 plugin_name);
399 res = 1; 386 res = 1;
387 GNUNET_DISK_purge_cfg_dir (cfg_name,
388 "GNUNET_TEST_HOME");
400 if (0 != 389 if (0 !=
401 GNUNET_TESTING_peer_run ("test-namestore-api-monitoring-existing", 390 GNUNET_TESTING_peer_run ("test-namestore-api-monitoring-existing",
402 cfg_name, 391 cfg_name,
@@ -405,12 +394,9 @@ main (int argc, char *argv[])
405 { 394 {
406 res = 1; 395 res = 1;
407 } 396 }
397 GNUNET_DISK_purge_cfg_dir (cfg_name,
398 "GNUNET_TEST_HOME");
408 GNUNET_free (cfg_name); 399 GNUNET_free (cfg_name);
409 if (NULL != directory)
410 {
411 GNUNET_DISK_directory_remove (directory);
412 GNUNET_free (directory);
413 }
414 return res; 400 return res;
415} 401}
416 402
diff --git a/src/namestore/test_namestore_api_postgres.conf b/src/namestore/test_namestore_api_postgres.conf
index 397cb4b2f..9960e6315 100644
--- a/src/namestore/test_namestore_api_postgres.conf
+++ b/src/namestore/test_namestore_api_postgres.conf
@@ -2,3 +2,8 @@
2 2
3[namestore] 3[namestore]
4DATABASE = postgres 4DATABASE = postgres
5
6
7[namestore-postgres]
8CONFIG = connect_timeout=10; dbname=gnunetcheck
9TEMPORARY_TABLE = YES
diff --git a/src/namestore/test_namestore_api_remove.c b/src/namestore/test_namestore_api_remove.c
index 532a751da..c9e2802bd 100644
--- a/src/namestore/test_namestore_api_remove.c
+++ b/src/namestore/test_namestore_api_remove.c
@@ -48,7 +48,6 @@ static int removed;
48 48
49static struct GNUNET_NAMESTORE_QueueEntry *nsqe; 49static struct GNUNET_NAMESTORE_QueueEntry *nsqe;
50 50
51static char *directory;
52 51
53static void 52static void
54cleanup () 53cleanup ()
@@ -157,29 +156,12 @@ run (void *cls,
157 struct GNUNET_TESTING_Peer *peer) 156 struct GNUNET_TESTING_Peer *peer)
158{ 157{
159 struct GNUNET_GNSRECORD_Data rd; 158 struct GNUNET_GNSRECORD_Data rd;
160 char *hostkey_file;
161 const char * name = "dummy.dummy.gnunet"; 159 const char * name = "dummy.dummy.gnunet";
162 160
163 directory = NULL;
164 GNUNET_assert (GNUNET_OK ==
165 GNUNET_CONFIGURATION_get_value_string(cfg,
166 "PATHS",
167 "GNUNET_TEST_HOME",
168 &directory));
169 GNUNET_DISK_directory_remove (directory);
170
171 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 161 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
172 &endbadly, 162 &endbadly,
173 NULL); 163 NULL);
174 GNUNET_asprintf (&hostkey_file, 164 privkey = GNUNET_CRYPTO_ecdsa_key_create ();
175 "zonefiles%s%s",
176 DIR_SEPARATOR_STR,
177 "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
178 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
179 "Using zonekey file `%s' \n",
180 hostkey_file);
181 privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file);
182 GNUNET_free (hostkey_file);
183 GNUNET_assert (privkey != NULL); 165 GNUNET_assert (privkey != NULL);
184 GNUNET_CRYPTO_ecdsa_key_get_public (privkey, 166 GNUNET_CRYPTO_ecdsa_key_get_public (privkey,
185 &pubkey); 167 &pubkey);
@@ -191,12 +173,19 @@ run (void *cls,
191 rd.data_size = TEST_RECORD_DATALEN; 173 rd.data_size = TEST_RECORD_DATALEN;
192 rd.data = GNUNET_malloc (TEST_RECORD_DATALEN); 174 rd.data = GNUNET_malloc (TEST_RECORD_DATALEN);
193 rd.flags = 0; 175 rd.flags = 0;
194 memset ((char *) rd.data, 'a', TEST_RECORD_DATALEN); 176 memset ((char *) rd.data,
177 'a',
178 TEST_RECORD_DATALEN);
195 179
196 nsh = GNUNET_NAMESTORE_connect (cfg); 180 nsh = GNUNET_NAMESTORE_connect (cfg);
197 GNUNET_break (NULL != nsh); 181 GNUNET_break (NULL != nsh);
198 nsqe = GNUNET_NAMESTORE_records_store (nsh, privkey, name, 182 nsqe = GNUNET_NAMESTORE_records_store (nsh,
199 1, &rd, &put_cont, (void *) name); 183 privkey,
184 name,
185 1,
186 &rd,
187 &put_cont,
188 (void *) name);
200 if (NULL == nsqe) 189 if (NULL == nsqe)
201 { 190 {
202 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 191 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -216,6 +205,8 @@ main (int argc, char *argv[])
216 GNUNET_asprintf (&cfg_name, 205 GNUNET_asprintf (&cfg_name,
217 "test_namestore_api_%s.conf", 206 "test_namestore_api_%s.conf",
218 plugin_name); 207 plugin_name);
208 GNUNET_DISK_purge_cfg_dir (cfg_name,
209 "GNUNET_TEST_HOME");
219 res = 1; 210 res = 1;
220 if (0 != 211 if (0 !=
221 GNUNET_TESTING_peer_run ("test-namestore-api-remove", 212 GNUNET_TESTING_peer_run ("test-namestore-api-remove",
@@ -225,12 +216,9 @@ main (int argc, char *argv[])
225 { 216 {
226 res = 1; 217 res = 1;
227 } 218 }
219 GNUNET_DISK_purge_cfg_dir (cfg_name,
220 "GNUNET_TEST_HOME");
228 GNUNET_free (cfg_name); 221 GNUNET_free (cfg_name);
229 if (NULL != directory)
230 {
231 GNUNET_DISK_directory_remove (directory);
232 GNUNET_free (directory);
233 }
234 return res; 222 return res;
235} 223}
236 224
diff --git a/src/namestore/test_namestore_api_remove_not_existing_record.c b/src/namestore/test_namestore_api_remove_not_existing_record.c
index 2f20c3636..d0438a7e1 100644
--- a/src/namestore/test_namestore_api_remove_not_existing_record.c
+++ b/src/namestore/test_namestore_api_remove_not_existing_record.c
@@ -46,7 +46,6 @@ static int res;
46 46
47static struct GNUNET_NAMESTORE_QueueEntry *nsqe; 47static struct GNUNET_NAMESTORE_QueueEntry *nsqe;
48 48
49static char *directory;
50 49
51static void 50static void
52cleanup () 51cleanup ()
@@ -92,7 +91,9 @@ end (void *cls)
92 91
93 92
94static void 93static void
95put_cont (void *cls, int32_t success, const char *emsg) 94put_cont (void *cls,
95 int32_t success,
96 const char *emsg)
96{ 97{
97 GNUNET_assert (NULL != cls); 98 GNUNET_assert (NULL != cls);
98 nsqe = NULL; 99 nsqe = NULL;
@@ -101,8 +102,8 @@ put_cont (void *cls, int32_t success, const char *emsg)
101 GNUNET_SCHEDULER_cancel (endbadly_task); 102 GNUNET_SCHEDULER_cancel (endbadly_task);
102 endbadly_task = NULL; 103 endbadly_task = NULL;
103 } 104 }
104 105 switch (success)
105 switch (success) { 106 {
106 case GNUNET_NO: 107 case GNUNET_NO:
107 /* We expected GNUNET_NO, since record was not found */ 108 /* We expected GNUNET_NO, since record was not found */
108 GNUNET_SCHEDULER_add_now (&end, NULL); 109 GNUNET_SCHEDULER_add_now (&end, NULL);
@@ -129,25 +130,12 @@ run (void *cls,
129 const struct GNUNET_CONFIGURATION_Handle *cfg, 130 const struct GNUNET_CONFIGURATION_Handle *cfg,
130 struct GNUNET_TESTING_Peer *peer) 131 struct GNUNET_TESTING_Peer *peer)
131{ 132{
132 char *hostkey_file;
133 const char * name = "dummy.dummy.gnunet"; 133 const char * name = "dummy.dummy.gnunet";
134 134
135 directory = NULL;
136 GNUNET_assert (GNUNET_OK ==
137 GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS", "GNUNET_TEST_HOME", &directory));
138 GNUNET_DISK_directory_remove (directory);
139
140 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 135 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
141 &endbadly, NULL); 136 &endbadly,
142 GNUNET_asprintf (&hostkey_file, 137 NULL);
143 "zonefiles%s%s", 138 privkey = GNUNET_CRYPTO_ecdsa_key_create ();
144 DIR_SEPARATOR_STR,
145 "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
146 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
147 "Using zonekey file `%s' \n",
148 hostkey_file);
149 privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file);
150 GNUNET_free (hostkey_file);
151 GNUNET_assert (privkey != NULL); 139 GNUNET_assert (privkey != NULL);
152 GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey); 140 GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey);
153 141
@@ -174,6 +162,8 @@ main (int argc, char *argv[])
174 GNUNET_asprintf (&cfg_name, 162 GNUNET_asprintf (&cfg_name,
175 "test_namestore_api_%s.conf", 163 "test_namestore_api_%s.conf",
176 plugin_name); 164 plugin_name);
165 GNUNET_DISK_purge_cfg_dir (cfg_name,
166 "GNUNET_TEST_HOME");
177 res = 1; 167 res = 1;
178 if (0 != 168 if (0 !=
179 GNUNET_TESTING_peer_run ("test-namestore-api-remove-non-existing-record", 169 GNUNET_TESTING_peer_run ("test-namestore-api-remove-non-existing-record",
@@ -183,12 +173,9 @@ main (int argc, char *argv[])
183 { 173 {
184 res = 1; 174 res = 1;
185 } 175 }
176 GNUNET_DISK_purge_cfg_dir (cfg_name,
177 "GNUNET_TEST_HOME");
186 GNUNET_free (cfg_name); 178 GNUNET_free (cfg_name);
187 if (NULL != directory)
188 {
189 GNUNET_DISK_directory_remove (directory);
190 GNUNET_free (directory);
191 }
192 return res; 179 return res;
193} 180}
194 181
diff --git a/src/namestore/test_namestore_api_sqlite.conf b/src/namestore/test_namestore_api_sqlite.conf
index 5416daec3..82663400a 100644
--- a/src/namestore/test_namestore_api_sqlite.conf
+++ b/src/namestore/test_namestore_api_sqlite.conf
@@ -2,3 +2,6 @@
2 2
3[namestore] 3[namestore]
4DATABASE = sqlite 4DATABASE = sqlite
5
6[namestore-sqlite]
7FILENAME = $GNUNET_TEST_HOME/namestore/sqlite_test.db
diff --git a/src/namestore/test_namestore_api_store.c b/src/namestore/test_namestore_api_store.c
index 4e51678a1..4abcfa4d3 100644
--- a/src/namestore/test_namestore_api_store.c
+++ b/src/namestore/test_namestore_api_store.c
@@ -46,7 +46,6 @@ static int res;
46 46
47static struct GNUNET_NAMESTORE_QueueEntry *nsqe; 47static struct GNUNET_NAMESTORE_QueueEntry *nsqe;
48 48
49static char *directory;
50 49
51static void 50static void
52cleanup () 51cleanup ()
@@ -114,23 +113,11 @@ run (void *cls,
114 struct GNUNET_TESTING_Peer *peer) 113 struct GNUNET_TESTING_Peer *peer)
115{ 114{
116 struct GNUNET_GNSRECORD_Data rd; 115 struct GNUNET_GNSRECORD_Data rd;
117 char *hostkey_file;
118 const char * name = "dummy.dummy.gnunet"; 116 const char * name = "dummy.dummy.gnunet";
119 117
120 directory = NULL;
121 GNUNET_assert (GNUNET_OK ==
122 GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS", "GNUNET_TEST_HOME", &directory));
123 GNUNET_DISK_directory_remove (directory);
124
125 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 118 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
126 &endbadly, NULL); 119 &endbadly, NULL);
127 GNUNET_asprintf (&hostkey_file, 120 privkey = GNUNET_CRYPTO_ecdsa_key_create ();
128 "zonefiles%s%s",
129 DIR_SEPARATOR_STR,
130 "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
131 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
132 privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file);
133 GNUNET_free (hostkey_file);
134 GNUNET_assert (privkey != NULL); 121 GNUNET_assert (privkey != NULL);
135 GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey); 122 GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey);
136 123
@@ -144,8 +131,13 @@ run (void *cls,
144 131
145 nsh = GNUNET_NAMESTORE_connect (cfg); 132 nsh = GNUNET_NAMESTORE_connect (cfg);
146 GNUNET_break (NULL != nsh); 133 GNUNET_break (NULL != nsh);
147 nsqe = GNUNET_NAMESTORE_records_store (nsh, privkey, name, 134 nsqe = GNUNET_NAMESTORE_records_store (nsh,
148 1, &rd, &put_cont, (void *) name); 135 privkey,
136 name,
137 1,
138 &rd,
139 &put_cont,
140 (void *) name);
149 if (NULL == nsqe) 141 if (NULL == nsqe)
150 { 142 {
151 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 143 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -167,6 +159,8 @@ main (int argc, char *argv[])
167 "test_namestore_api_%s.conf", 159 "test_namestore_api_%s.conf",
168 plugin_name); 160 plugin_name);
169 res = 1; 161 res = 1;
162 GNUNET_DISK_purge_cfg_dir (cfg_name,
163 "GNUNET_TEST_HOME");
170 if (0 != 164 if (0 !=
171 GNUNET_TESTING_peer_run ("test-namestore-api", 165 GNUNET_TESTING_peer_run ("test-namestore-api",
172 cfg_name, 166 cfg_name,
@@ -175,12 +169,9 @@ main (int argc, char *argv[])
175 { 169 {
176 res = 1; 170 res = 1;
177 } 171 }
172 GNUNET_DISK_purge_cfg_dir (cfg_name,
173 "GNUNET_TEST_HOME");
178 GNUNET_free (cfg_name); 174 GNUNET_free (cfg_name);
179 if (NULL != directory)
180 {
181 GNUNET_DISK_directory_remove (directory);
182 GNUNET_free (directory);
183 }
184 return res; 175 return res;
185} 176}
186 177
diff --git a/src/namestore/test_namestore_api_store_update.c b/src/namestore/test_namestore_api_store_update.c
index 0a4551f21..7b13cd9c5 100644
--- a/src/namestore/test_namestore_api_store_update.c
+++ b/src/namestore/test_namestore_api_store_update.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2012, 2013 GNUnet e.V. 3 Copyright (C) 2012, 2013, 2018 GNUnet e.V.
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -21,6 +21,7 @@
21 * @file namestore/test_namestore_api_store_update.c 21 * @file namestore/test_namestore_api_store_update.c
22 * @brief testcase for namestore_api.c: store a record, update it and perform a lookup 22 * @brief testcase for namestore_api.c: store a record, update it and perform a lookup
23 * @author Matthias Wachs 23 * @author Matthias Wachs
24 * @author Christian Grothoff
24 */ 25 */
25#include "platform.h" 26#include "platform.h"
26#include "gnunet_namecache_service.h" 27#include "gnunet_namecache_service.h"
@@ -33,7 +34,6 @@
33 34
34#define TEST_RECORD_DATA 'a' 35#define TEST_RECORD_DATA 'a'
35 36
36
37#define TEST_RECORD_TYPE2 4321 37#define TEST_RECORD_TYPE2 4321
38 38
39#define TEST_RECORD_DATALEN2 234 39#define TEST_RECORD_DATALEN2 234
@@ -63,38 +63,30 @@ static struct GNUNET_NAMECACHE_QueueEntry *ncqe;
63 63
64static const char *name = "dummy"; 64static const char *name = "dummy";
65 65
66static char *directory;
67 66
67/**
68 * Terminate test with error.
69 *
70 * @param cls handle to use to re-connect.
71 */
68static void 72static void
69cleanup () 73endbadly (void *cls)
70{ 74{
71 if (NULL != nsh) 75 GNUNET_break (0);
72 { 76 endbadly_task = NULL;
73 GNUNET_NAMESTORE_disconnect (nsh);
74 nsh = NULL;
75 }
76 if (NULL != nch)
77 {
78 GNUNET_NAMECACHE_disconnect (nch);
79 nch = NULL;
80 }
81 if (NULL != privkey)
82 {
83 GNUNET_free (privkey);
84 privkey = NULL;
85 }
86 GNUNET_SCHEDULER_shutdown (); 77 GNUNET_SCHEDULER_shutdown ();
78 res = 1;
87} 79}
88 80
89 81
90/**
91 * Re-establish the connection to the service.
92 *
93 * @param cls handle to use to re-connect.
94 */
95static void 82static void
96endbadly (void *cls) 83end (void *cls)
97{ 84{
85 if (NULL != endbadly_task)
86 {
87 GNUNET_SCHEDULER_cancel (endbadly_task);
88 endbadly_task = NULL;
89 }
98 if (NULL != nsqe) 90 if (NULL != nsqe)
99 { 91 {
100 GNUNET_NAMESTORE_cancel (nsqe); 92 GNUNET_NAMESTORE_cancel (nsqe);
@@ -105,21 +97,28 @@ endbadly (void *cls)
105 GNUNET_NAMECACHE_cancel (ncqe); 97 GNUNET_NAMECACHE_cancel (ncqe);
106 ncqe = NULL; 98 ncqe = NULL;
107 } 99 }
108 cleanup (); 100 if (NULL != nsh)
109 res = 1; 101 {
110} 102 GNUNET_NAMESTORE_disconnect (nsh);
111 103 nsh = NULL;
112 104 }
113static void 105 if (NULL != nch)
114end (void *cls) 106 {
115{ 107 GNUNET_NAMECACHE_disconnect (nch);
116 cleanup (); 108 nch = NULL;
117 res = 0; 109 }
110 if (NULL != privkey)
111 {
112 GNUNET_free (privkey);
113 privkey = NULL;
114 }
118} 115}
119 116
120 117
121static void 118static void
122put_cont (void *cls, int32_t success, const char *emsg); 119put_cont (void *cls,
120 int32_t success,
121 const char *emsg);
123 122
124 123
125static void 124static void
@@ -135,11 +134,15 @@ rd_decrypt_cb (void *cls,
135 if (GNUNET_NO == update_performed) 134 if (GNUNET_NO == update_performed)
136 { 135 {
137 char rd_cmp_data[TEST_RECORD_DATALEN]; 136 char rd_cmp_data[TEST_RECORD_DATALEN];
138 memset (rd_cmp_data, TEST_RECORD_DATA, TEST_RECORD_DATALEN);
139 137
138 memset (rd_cmp_data,
139 TEST_RECORD_DATA,
140 TEST_RECORD_DATALEN);
140 GNUNET_assert (TEST_RECORD_TYPE == rd[0].record_type); 141 GNUNET_assert (TEST_RECORD_TYPE == rd[0].record_type);
141 GNUNET_assert (TEST_RECORD_DATALEN == rd[0].data_size); 142 GNUNET_assert (TEST_RECORD_DATALEN == rd[0].data_size);
142 GNUNET_assert (0 == memcmp (&rd_cmp_data, rd[0].data, TEST_RECORD_DATALEN)); 143 GNUNET_assert (0 == memcmp (&rd_cmp_data,
144 rd[0].data,
145 TEST_RECORD_DATALEN));
143 146
144 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 147 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
145 "Block was decrypted successfully, updating record \n"); 148 "Block was decrypted successfully, updating record \n");
@@ -149,24 +152,33 @@ rd_decrypt_cb (void *cls,
149 rd_new.record_type = TEST_RECORD_TYPE2; 152 rd_new.record_type = TEST_RECORD_TYPE2;
150 rd_new.data_size = TEST_RECORD_DATALEN2; 153 rd_new.data_size = TEST_RECORD_DATALEN2;
151 rd_new.data = GNUNET_malloc (TEST_RECORD_DATALEN2); 154 rd_new.data = GNUNET_malloc (TEST_RECORD_DATALEN2);
152 memset ((char *) rd_new.data, TEST_RECORD_DATA2, TEST_RECORD_DATALEN2); 155 memset ((char *) rd_new.data,
156 TEST_RECORD_DATA2,
157 TEST_RECORD_DATALEN2);
153 158
154 nsqe = GNUNET_NAMESTORE_records_store (nsh, privkey, name, 159 nsqe = GNUNET_NAMESTORE_records_store (nsh,
155 1, &rd_new, &put_cont, (void *) name); 160 privkey,
161 name,
162 1,
163 &rd_new,
164 &put_cont,
165 (void *) name);
156 update_performed = GNUNET_YES; 166 update_performed = GNUNET_YES;
157 } 167 }
158 else 168 else
159 { 169 {
160 char rd_cmp_data[TEST_RECORD_DATALEN2]; 170 char rd_cmp_data[TEST_RECORD_DATALEN2];
161 memset (rd_cmp_data, TEST_RECORD_DATA2, TEST_RECORD_DATALEN2);
162 171
172 memset (rd_cmp_data,
173 TEST_RECORD_DATA2,
174 TEST_RECORD_DATALEN2);
163 GNUNET_assert (TEST_RECORD_TYPE2 == rd[0].record_type); 175 GNUNET_assert (TEST_RECORD_TYPE2 == rd[0].record_type);
164 GNUNET_assert (TEST_RECORD_DATALEN2 == rd[0].data_size); 176 GNUNET_assert (TEST_RECORD_DATALEN2 == rd[0].data_size);
165 GNUNET_assert (0 == memcmp (&rd_cmp_data, rd[0].data, TEST_RECORD_DATALEN2)); 177 GNUNET_assert (0 == memcmp (&rd_cmp_data,
166 178 rd[0].data,
167 GNUNET_SCHEDULER_cancel (endbadly_task); 179 TEST_RECORD_DATALEN2));
168 endbadly_task = NULL; 180 GNUNET_SCHEDULER_shutdown ();
169 GNUNET_SCHEDULER_add_now (&end, NULL); 181 res = 0;
170 } 182 }
171} 183}
172 184
@@ -184,21 +196,25 @@ name_lookup_proc (void *cls,
184 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 196 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
185 _("Namecache returned no block for `%s'\n"), 197 _("Namecache returned no block for `%s'\n"),
186 name); 198 name);
187 if (endbadly_task != NULL) 199 GNUNET_SCHEDULER_shutdown ();
188 GNUNET_SCHEDULER_cancel (endbadly_task);
189 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
190 return; 200 return;
191 } 201 }
192 202
193 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 203 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
194 "Namecache returned block, decrypting \n"); 204 "Namecache returned block, decrypting \n");
195 GNUNET_assert (GNUNET_OK == GNUNET_GNSRECORD_block_decrypt(block, 205 GNUNET_assert (GNUNET_OK ==
196 &pubkey, name, &rd_decrypt_cb, (void *) name)); 206 GNUNET_GNSRECORD_block_decrypt (block,
207 &pubkey,
208 name,
209 &rd_decrypt_cb,
210 (void *) name));
197} 211}
198 212
199 213
200static void 214static void
201put_cont (void *cls, int32_t success, const char *emsg) 215put_cont (void *cls,
216 int32_t success,
217 const char *emsg)
202{ 218{
203 const char *name = cls; 219 const char *name = cls;
204 struct GNUNET_HashCode derived_hash; 220 struct GNUNET_HashCode derived_hash;
@@ -216,7 +232,8 @@ put_cont (void *cls, int32_t success, const char *emsg)
216 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 232 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
217 "Looking in namecache for `%s'\n", 233 "Looking in namecache for `%s'\n",
218 GNUNET_h2s (&derived_hash)); 234 GNUNET_h2s (&derived_hash));
219 ncqe = GNUNET_NAMECACHE_lookup_block (nch, &derived_hash, 235 ncqe = GNUNET_NAMECACHE_lookup_block (nch,
236 &derived_hash,
220 &name_lookup_proc, (void *) name); 237 &name_lookup_proc, (void *) name);
221} 238}
222 239
@@ -227,41 +244,37 @@ run (void *cls,
227 struct GNUNET_TESTING_Peer *peer) 244 struct GNUNET_TESTING_Peer *peer)
228{ 245{
229 struct GNUNET_GNSRECORD_Data rd; 246 struct GNUNET_GNSRECORD_Data rd;
230 char *hostkey_file;
231
232 directory = NULL;
233 GNUNET_assert (GNUNET_OK ==
234 GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS", "GNUNET_TEST_HOME", &directory));
235 GNUNET_DISK_directory_remove (directory);
236 247
237 update_performed = GNUNET_NO; 248 update_performed = GNUNET_NO;
249 GNUNET_SCHEDULER_add_shutdown (&end,
250 NULL);
238 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 251 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
239 &endbadly, NULL); 252 &endbadly,
240 GNUNET_asprintf (&hostkey_file, 253 NULL);
241 "zonefiles%s%s", 254 privkey = GNUNET_CRYPTO_ecdsa_key_create ();
242 DIR_SEPARATOR_STR,
243 "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
244 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
245 privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file);
246 GNUNET_free (hostkey_file);
247 GNUNET_assert (privkey != NULL); 255 GNUNET_assert (privkey != NULL);
248 GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey); 256 GNUNET_CRYPTO_ecdsa_key_get_public (privkey,
249 257 &pubkey);
250 rd.flags = GNUNET_GNSRECORD_RF_NONE; 258 rd.flags = GNUNET_GNSRECORD_RF_NONE;
251 rd.expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000; 259 rd.expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000;
252 rd.record_type = TEST_RECORD_TYPE; 260 rd.record_type = TEST_RECORD_TYPE;
253 rd.data_size = TEST_RECORD_DATALEN; 261 rd.data_size = TEST_RECORD_DATALEN;
254 rd.data = GNUNET_malloc (TEST_RECORD_DATALEN); 262 rd.data = GNUNET_malloc (TEST_RECORD_DATALEN);
255 memset ((char *) rd.data, TEST_RECORD_DATA, TEST_RECORD_DATALEN); 263 memset ((char *) rd.data,
264 TEST_RECORD_DATA,
265 TEST_RECORD_DATALEN);
256 266
257 nsh = GNUNET_NAMESTORE_connect (cfg); 267 nsh = GNUNET_NAMESTORE_connect (cfg);
258 GNUNET_break (NULL != nsh); 268 GNUNET_break (NULL != nsh);
259 nch = GNUNET_NAMECACHE_connect (cfg); 269 nch = GNUNET_NAMECACHE_connect (cfg);
260 GNUNET_break (NULL != nch); 270 GNUNET_break (NULL != nch);
261 nsqe = GNUNET_NAMESTORE_records_store (nsh, 271 nsqe = GNUNET_NAMESTORE_records_store (nsh,
262 privkey, name, 272 privkey,
263 1, &rd, 273 name,
264 &put_cont, (void *) name); 274 1,
275 &rd,
276 &put_cont,
277 (void *) name);
265 if (NULL == nsqe) 278 if (NULL == nsqe)
266 { 279 {
267 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 280 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -272,7 +285,8 @@ run (void *cls,
272 285
273 286
274int 287int
275main (int argc, char *argv[]) 288main (int argc,
289 char *argv[])
276{ 290{
277 const char *plugin_name; 291 const char *plugin_name;
278 char *cfg_name; 292 char *cfg_name;
@@ -282,6 +296,8 @@ main (int argc, char *argv[])
282 "test_namestore_api_%s.conf", 296 "test_namestore_api_%s.conf",
283 plugin_name); 297 plugin_name);
284 res = 1; 298 res = 1;
299 GNUNET_DISK_purge_cfg_dir (cfg_name,
300 "GNUNET_TEST_HOME");
285 if (0 != 301 if (0 !=
286 GNUNET_TESTING_peer_run ("test-namestore-api-store-update", 302 GNUNET_TESTING_peer_run ("test-namestore-api-store-update",
287 cfg_name, 303 cfg_name,
@@ -290,14 +306,11 @@ main (int argc, char *argv[])
290 { 306 {
291 res = 1; 307 res = 1;
292 } 308 }
309 GNUNET_DISK_purge_cfg_dir (cfg_name,
310 "GNUNET_TEST_HOME");
293 GNUNET_free (cfg_name); 311 GNUNET_free (cfg_name);
294 if (NULL != directory)
295 {
296 GNUNET_DISK_directory_remove (directory);
297 GNUNET_free (directory);
298 }
299 return res; 312 return res;
300} 313}
301 314
302 315
303/* end of test_namestore_api_store_update.c*/ 316/* end of test_namestore_api_store_update.c */
diff --git a/src/namestore/test_namestore_api_zone_iteration.c b/src/namestore/test_namestore_api_zone_iteration.c
index 806605d94..68c3de9b8 100644
--- a/src/namestore/test_namestore_api_zone_iteration.c
+++ b/src/namestore/test_namestore_api_zone_iteration.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2013 GNUnet e.V. 3 Copyright (C) 2013, 2018 GNUnet e.V.
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -56,8 +56,6 @@ static char * s_name_3;
56 56
57static struct GNUNET_GNSRECORD_Data *s_rd_3; 57static struct GNUNET_GNSRECORD_Data *s_rd_3;
58 58
59static char *directory;
60
61 59
62/** 60/**
63 * Re-establish the connection to the service. 61 * Re-establish the connection to the service.
@@ -68,43 +66,8 @@ static char *directory;
68static void 66static void
69endbadly (void *cls) 67endbadly (void *cls)
70{ 68{
71 if (NULL != zi) 69 endbadly_task = NULL;
72 { 70 GNUNET_SCHEDULER_shutdown ();
73 GNUNET_NAMESTORE_zone_iteration_stop (zi);
74 zi = NULL;
75 }
76 if (nsh != NULL)
77 {
78 GNUNET_NAMESTORE_disconnect (nsh);
79 nsh = NULL;
80 }
81 GNUNET_free_non_null(s_name_1);
82 GNUNET_free_non_null(s_name_2);
83 GNUNET_free_non_null(s_name_3);
84
85 if (s_rd_1 != NULL)
86 {
87 GNUNET_free ((void *)s_rd_1->data);
88 GNUNET_free (s_rd_1);
89 }
90 if (s_rd_2 != NULL)
91 {
92 GNUNET_free ((void *)s_rd_2->data);
93 GNUNET_free (s_rd_2);
94 }
95 if (s_rd_3 != NULL)
96 {
97 GNUNET_free ((void *)s_rd_3->data);
98 GNUNET_free (s_rd_3);
99 }
100
101 if (privkey != NULL)
102 GNUNET_free (privkey);
103 privkey = NULL;
104
105 if (privkey2 != NULL)
106 GNUNET_free (privkey2);
107 privkey2 = NULL;
108 res = 1; 71 res = 1;
109} 72}
110 73
@@ -117,41 +80,44 @@ end (void *cls)
117 GNUNET_NAMESTORE_zone_iteration_stop (zi); 80 GNUNET_NAMESTORE_zone_iteration_stop (zi);
118 zi = NULL; 81 zi = NULL;
119 } 82 }
120 if (endbadly_task != NULL) 83 if (NULL != endbadly_task)
121 { 84 {
122 GNUNET_SCHEDULER_cancel (endbadly_task); 85 GNUNET_SCHEDULER_cancel (endbadly_task);
123 endbadly_task = NULL; 86 endbadly_task = NULL;
124 } 87 }
125 88 if (NULL != privkey)
126 if (privkey != NULL) 89 {
127 GNUNET_free (privkey); 90 GNUNET_free (privkey);
128 privkey = NULL; 91 privkey = NULL;
129 92 }
130 if (privkey2 != NULL) 93 if (NULL != privkey2)
94 {
131 GNUNET_free (privkey2); 95 GNUNET_free (privkey2);
132 privkey2 = NULL; 96 privkey2 = NULL;
133 97 }
134 GNUNET_free (s_name_1); 98 GNUNET_free (s_name_1);
135 GNUNET_free (s_name_2); 99 GNUNET_free (s_name_2);
136 GNUNET_free (s_name_3); 100 GNUNET_free (s_name_3);
137 if (s_rd_1 != NULL) 101 if (NULL != s_rd_1)
138 { 102 {
139 GNUNET_free ((void *)s_rd_1->data); 103 GNUNET_free ((void *)s_rd_1->data);
140 GNUNET_free (s_rd_1); 104 GNUNET_free (s_rd_1);
141 } 105 }
142 if (s_rd_2 != NULL) 106 if (NULL != s_rd_2)
143 { 107 {
144 GNUNET_free ((void *)s_rd_2->data); 108 GNUNET_free ((void *)s_rd_2->data);
145 GNUNET_free (s_rd_2); 109 GNUNET_free (s_rd_2);
146 } 110 }
147 if (s_rd_3 != NULL) 111 if (NULL != s_rd_3)
148 { 112 {
149 GNUNET_free ((void *)s_rd_3->data); 113 GNUNET_free ((void *)s_rd_3->data);
150 GNUNET_free (s_rd_3); 114 GNUNET_free (s_rd_3);
151 } 115 }
152 if (nsh != NULL) 116 if (NULL != nsh)
117 {
153 GNUNET_NAMESTORE_disconnect (nsh); 118 GNUNET_NAMESTORE_disconnect (nsh);
154 nsh = NULL; 119 nsh = NULL;
120 }
155} 121}
156 122
157 123
@@ -170,7 +136,7 @@ zone_end (void *cls)
170 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 136 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
171 "Received last result, iteration done after receing %u results\n", 137 "Received last result, iteration done after receing %u results\n",
172 returned_records); 138 returned_records);
173 GNUNET_SCHEDULER_add_now (&end, NULL); 139 GNUNET_SCHEDULER_shutdown ();
174} 140}
175 141
176 142
@@ -191,7 +157,9 @@ zone_proc (void *cls,
191 int failed = GNUNET_NO; 157 int failed = GNUNET_NO;
192 158
193 GNUNET_assert (NULL != zone); 159 GNUNET_assert (NULL != zone);
194 if (0 == memcmp (zone, privkey, sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) 160 if (0 == memcmp (zone,
161 privkey,
162 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)))
195 { 163 {
196 if (0 == strcmp (label, s_name_1)) 164 if (0 == strcmp (label, s_name_1))
197 { 165 {
@@ -230,12 +198,15 @@ zone_proc (void *cls,
230 else 198 else
231 { 199 {
232 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 200 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
233 "Comparing result failed: got name `%s' for first zone\n", label); 201 "Comparing result failed: got name `%s' for first zone\n",
202 label);
234 failed = GNUNET_YES; 203 failed = GNUNET_YES;
235 GNUNET_break (0); 204 GNUNET_break (0);
236 } 205 }
237 } 206 }
238 else if (0 == memcmp (zone, privkey2, sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) 207 else if (0 == memcmp (zone,
208 privkey2,
209 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)))
239 { 210 {
240 if (0 == strcmp (label, s_name_3)) 211 if (0 == strcmp (label, s_name_3))
241 { 212 {
@@ -258,7 +229,8 @@ zone_proc (void *cls,
258 else 229 else
259 { 230 {
260 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 231 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
261 "Comparing result failed: got name `%s' for first zone\n", label); 232 "Comparing result failed: got name `%s' for first zone\n",
233 label);
262 failed = GNUNET_YES; 234 failed = GNUNET_YES;
263 GNUNET_break (0); 235 GNUNET_break (0);
264 } 236 }
@@ -282,29 +254,34 @@ zone_proc (void *cls,
282 else 254 else
283 { 255 {
284 GNUNET_break (0); 256 GNUNET_break (0);
285 GNUNET_SCHEDULER_add_now (&end, NULL); 257 GNUNET_SCHEDULER_shutdown ();
258 res = 1;
286 } 259 }
287} 260}
288 261
289 262
290static void 263static void
291put_cont (void *cls, int32_t success, const char *emsg) 264put_cont (void *cls,
265 int32_t success,
266 const char *emsg)
292{ 267{
293 static int c = 0; 268 static int c = 0;
294 269
295 if (success == GNUNET_OK) 270 if (success == GNUNET_OK)
296 { 271 {
297 c++; 272 c++;
298 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record %u \n", c); 273 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
274 "Created record %u \n",
275 c);
299 } 276 }
300 else 277 else
301 { 278 {
302 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to created records: `%s'\n", 279 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
280 "Failed to created records: `%s'\n",
303 emsg); 281 emsg);
304 GNUNET_break (0); 282 GNUNET_break (0);
305 if (NULL != endbadly_task) 283 GNUNET_SCHEDULER_shutdown ();
306 GNUNET_SCHEDULER_cancel (endbadly_task); 284 res = 1;
307 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
308 return; 285 return;
309 } 286 }
310 287
@@ -312,7 +289,8 @@ put_cont (void *cls, int32_t success, const char *emsg)
312 { 289 {
313 res = 1; 290 res = 1;
314 returned_records = 0; 291 returned_records = 0;
315 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All records created, starting iteration over all zones \n"); 292 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
293 "All records created, starting iteration over all zones \n");
316 zi = GNUNET_NAMESTORE_zone_iteration_start (nsh, 294 zi = GNUNET_NAMESTORE_zone_iteration_start (nsh,
317 NULL, 295 NULL,
318 &fail_cb, 296 &fail_cb,
@@ -323,11 +301,11 @@ put_cont (void *cls, int32_t success, const char *emsg)
323 NULL); 301 NULL);
324 if (zi == NULL) 302 if (zi == NULL)
325 { 303 {
326 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create zone iterator\n"); 304 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
305 "Failed to create zone iterator\n");
327 GNUNET_break (0); 306 GNUNET_break (0);
328 if (NULL != endbadly_task) 307 GNUNET_SCHEDULER_shutdown ();
329 GNUNET_SCHEDULER_cancel (endbadly_task); 308 res = 1;
330 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
331 return; 309 return;
332 } 310 }
333 } 311 }
@@ -337,11 +315,11 @@ put_cont (void *cls, int32_t success, const char *emsg)
337static struct GNUNET_GNSRECORD_Data * 315static struct GNUNET_GNSRECORD_Data *
338create_record (unsigned int count) 316create_record (unsigned int count)
339{ 317{
340 unsigned int c;
341 struct GNUNET_GNSRECORD_Data * rd; 318 struct GNUNET_GNSRECORD_Data * rd;
342 319
343 rd = GNUNET_malloc (count * sizeof (struct GNUNET_GNSRECORD_Data)); 320 rd = GNUNET_new_array (count,
344 for (c = 0; c < count; c++) 321 struct GNUNET_GNSRECORD_Data);
322 for (unsigned int c = 0; c < count; c++)
345 { 323 {
346 rd[c].expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS).abs_value_us; 324 rd[c].expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS).abs_value_us;
347 rd[c].record_type = 1111; 325 rd[c].record_type = 1111;
@@ -372,9 +350,8 @@ empty_zone_proc (void *cls,
372 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 350 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
373 _("Expected empty zone but received zone private key\n")); 351 _("Expected empty zone but received zone private key\n"));
374 GNUNET_break (0); 352 GNUNET_break (0);
375 if (endbadly_task != NULL) 353 GNUNET_SCHEDULER_shutdown ();
376 GNUNET_SCHEDULER_cancel (endbadly_task); 354 res = 1;
377 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
378 return; 355 return;
379 } 356 }
380 if ((NULL != label) || (NULL != rd) || (0 != rd_count)) 357 if ((NULL != label) || (NULL != rd) || (0 != rd_count))
@@ -382,9 +359,8 @@ empty_zone_proc (void *cls,
382 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 359 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
383 _("Expected no zone content but received data\n")); 360 _("Expected no zone content but received data\n"));
384 GNUNET_break (0); 361 GNUNET_break (0);
385 if (endbadly_task != NULL) 362 GNUNET_SCHEDULER_shutdown ();
386 GNUNET_SCHEDULER_cancel (endbadly_task); 363 res = 1;
387 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
388 return; 364 return;
389 } 365 }
390 GNUNET_assert (0); 366 GNUNET_assert (0);
@@ -412,7 +388,9 @@ empty_zone_end (void *cls)
412 "zonefiles%s%s", 388 "zonefiles%s%s",
413 DIR_SEPARATOR_STR, 389 DIR_SEPARATOR_STR,
414 "HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey"); 390 "HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey");
415 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file); 391 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
392 "Using zonekey file `%s' \n",
393 hostkey_file);
416 privkey2 = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file); 394 privkey2 = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file);
417 GNUNET_free (hostkey_file); 395 GNUNET_free (hostkey_file);
418 GNUNET_assert (privkey2 != NULL); 396 GNUNET_assert (privkey2 != NULL);
@@ -425,8 +403,8 @@ empty_zone_end (void *cls)
425 privkey, 403 privkey,
426 s_name_1, 404 s_name_1,
427 1, s_rd_1, 405 1, s_rd_1,
428 &put_cont, NULL); 406 &put_cont,
429 407 NULL);
430 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 408 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
431 "Created record 2 \n"); 409 "Created record 2 \n");
432 GNUNET_asprintf(&s_name_2, "dummy2"); 410 GNUNET_asprintf(&s_name_2, "dummy2");
@@ -437,16 +415,18 @@ empty_zone_end (void *cls)
437 1, s_rd_2, 415 1, s_rd_2,
438 &put_cont, 416 &put_cont,
439 NULL); 417 NULL);
440
441 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 418 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
442 "Created record 3\n"); 419 "Created record 3\n");
443
444 /* name in different zone */ 420 /* name in different zone */
445 GNUNET_asprintf(&s_name_3, "dummy3"); 421 GNUNET_asprintf(&s_name_3, "dummy3");
446 s_rd_3 = create_record(1); 422 s_rd_3 = create_record(1);
447 GNUNET_NAMESTORE_records_store (nsh, privkey2, s_name_3, 423 GNUNET_NAMESTORE_records_store (nsh,
448 1, s_rd_3, 424 privkey2,
449 &put_cont, NULL); 425 s_name_3,
426 1,
427 s_rd_3,
428 &put_cont,
429 NULL);
450} 430}
451 431
452 432
@@ -455,31 +435,30 @@ run (void *cls,
455 const struct GNUNET_CONFIGURATION_Handle *cfg, 435 const struct GNUNET_CONFIGURATION_Handle *cfg,
456 struct GNUNET_TESTING_Peer *peer) 436 struct GNUNET_TESTING_Peer *peer)
457{ 437{
458 directory = NULL; 438 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
459 GNUNET_assert (GNUNET_OK == 439 &endbadly,
460 GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS", 440 NULL);
461 "GNUNET_TEST_HOME", 441 GNUNET_SCHEDULER_add_shutdown (&end,
462 &directory)); 442 NULL);
463 GNUNET_DISK_directory_remove (directory); 443
464
465 endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, &endbadly, NULL);
466 nsh = GNUNET_NAMESTORE_connect (cfg); 444 nsh = GNUNET_NAMESTORE_connect (cfg);
467 GNUNET_break (NULL != nsh); 445 GNUNET_break (NULL != nsh);
468 /* first, iterate over empty namestore */ 446 /* first, iterate over empty namestore */
469 zi = GNUNET_NAMESTORE_zone_iteration_start(nsh, 447 zi = GNUNET_NAMESTORE_zone_iteration_start (nsh,
470 NULL, 448 NULL,
471 &fail_cb, 449 &fail_cb,
472 NULL, 450 NULL,
473 &empty_zone_proc, 451 &empty_zone_proc,
474 nsh, 452 nsh,
475 &empty_zone_end, 453 &empty_zone_end,
476 NULL); 454 NULL);
477 if (NULL == zi) 455 if (NULL == zi)
478 { 456 {
479 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create zone iterator\n"); 457 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
458 "Failed to create zone iterator\n");
480 GNUNET_break (0); 459 GNUNET_break (0);
481 GNUNET_SCHEDULER_cancel (endbadly_task); 460 res = 1;
482 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); 461 GNUNET_SCHEDULER_shutdown ();
483 } 462 }
484} 463}
485 464
@@ -494,6 +473,8 @@ main (int argc, char *argv[])
494 GNUNET_asprintf (&cfg_name, 473 GNUNET_asprintf (&cfg_name,
495 "test_namestore_api_%s.conf", 474 "test_namestore_api_%s.conf",
496 plugin_name); 475 plugin_name);
476 GNUNET_DISK_purge_cfg_dir (cfg_name,
477 "GNUNET_TEST_HOME");
497 res = 1; 478 res = 1;
498 if (0 != 479 if (0 !=
499 GNUNET_TESTING_peer_run ("test-namestore-api-zone-iteration", 480 GNUNET_TESTING_peer_run ("test-namestore-api-zone-iteration",
@@ -503,12 +484,9 @@ main (int argc, char *argv[])
503 { 484 {
504 res = 1; 485 res = 1;
505 } 486 }
487 GNUNET_DISK_purge_cfg_dir (cfg_name,
488 "GNUNET_TEST_HOME");
506 GNUNET_free (cfg_name); 489 GNUNET_free (cfg_name);
507 if (NULL != directory)
508 {
509 GNUNET_DISK_directory_remove (directory);
510 GNUNET_free (directory);
511 }
512 return res; 490 return res;
513} 491}
514 492
diff --git a/src/namestore/test_namestore_api_zone_iteration_nick.c b/src/namestore/test_namestore_api_zone_iteration_nick.c
index a88646864..d950b7e69 100644
--- a/src/namestore/test_namestore_api_zone_iteration_nick.c
+++ b/src/namestore/test_namestore_api_zone_iteration_nick.c
@@ -60,7 +60,6 @@ static struct GNUNET_GNSRECORD_Data *s_rd_3;
60 60
61static struct GNUNET_NAMESTORE_QueueEntry *nsqe; 61static struct GNUNET_NAMESTORE_QueueEntry *nsqe;
62 62
63static char *directory;
64 63
65/** 64/**
66 * Re-establish the connection to the service. 65 * Re-establish the connection to the service.
@@ -265,7 +264,9 @@ fail_cb (void *cls)
265 264
266 265
267static void 266static void
268put_cont (void *cls, int32_t success, const char *emsg) 267put_cont (void *cls,
268 int32_t success,
269 const char *emsg)
269{ 270{
270 static int c = 0; 271 static int c = 0;
271 272
@@ -314,11 +315,11 @@ put_cont (void *cls, int32_t success, const char *emsg)
314static struct GNUNET_GNSRECORD_Data * 315static struct GNUNET_GNSRECORD_Data *
315create_record (unsigned int count) 316create_record (unsigned int count)
316{ 317{
317 unsigned int c;
318 struct GNUNET_GNSRECORD_Data * rd; 318 struct GNUNET_GNSRECORD_Data * rd;
319 319
320 rd = GNUNET_malloc (count * sizeof (struct GNUNET_GNSRECORD_Data)); 320 rd = GNUNET_new_array (count,
321 for (c = 0; c < count; c++) 321 struct GNUNET_GNSRECORD_Data);
322 for (unsigned int c = 0; c < count; c++)
322 { 323 {
323 rd[c].expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS).abs_value_us; 324 rd[c].expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS).abs_value_us;
324 rd[c].record_type = 1111; 325 rd[c].record_type = 1111;
@@ -332,7 +333,9 @@ create_record (unsigned int count)
332 333
333 334
334static void 335static void
335nick_2_cont (void *cls, int32_t success, const char *emsg) 336nick_2_cont (void *cls,
337 int32_t success,
338 const char *emsg)
336{ 339{
337 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 340 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
338 "Nick added : %s\n", 341 "Nick added : %s\n",
@@ -422,25 +425,18 @@ empty_zone_proc (void *cls,
422static void 425static void
423empty_zone_end (void *cls) 426empty_zone_end (void *cls)
424{ 427{
425 char *hostkey_file;
426 GNUNET_assert (nsh == cls); 428 GNUNET_assert (nsh == cls);
427
428 zi = NULL; 429 zi = NULL;
429 GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR, 430 privkey = GNUNET_CRYPTO_ecdsa_key_create ();
430 "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
431 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
432 privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file);
433 GNUNET_free (hostkey_file);
434 GNUNET_assert (privkey != NULL); 431 GNUNET_assert (privkey != NULL);
435 432 privkey2 = GNUNET_CRYPTO_ecdsa_key_create ();
436 GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR,
437 "HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey");
438 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
439 privkey2 = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file);
440 GNUNET_free (hostkey_file);
441 GNUNET_assert (privkey2 != NULL); 433 GNUNET_assert (privkey2 != NULL);
442 434
443 nsqe = GNUNET_NAMESTORE_set_nick (nsh, privkey, ZONE_NICK_1, &nick_1_cont, &privkey); 435 nsqe = GNUNET_NAMESTORE_set_nick (nsh,
436 privkey,
437 ZONE_NICK_1,
438 &nick_1_cont,
439 &privkey);
444 if (NULL == nsqe) 440 if (NULL == nsqe)
445 { 441 {
446 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 442 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -455,15 +451,9 @@ run (void *cls,
455 const struct GNUNET_CONFIGURATION_Handle *cfg, 451 const struct GNUNET_CONFIGURATION_Handle *cfg,
456 struct GNUNET_TESTING_Peer *peer) 452 struct GNUNET_TESTING_Peer *peer)
457{ 453{
458 directory = NULL; 454 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
459 GNUNET_assert (GNUNET_OK == 455 &endbadly,
460 GNUNET_CONFIGURATION_get_value_string (cfg, 456 NULL);
461 "PATHS",
462 "GNUNET_TEST_HOME",
463 &directory));
464 GNUNET_DISK_directory_remove (directory);
465
466 endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, &endbadly, NULL);
467 nsh = GNUNET_NAMESTORE_connect (cfg); 457 nsh = GNUNET_NAMESTORE_connect (cfg);
468 GNUNET_break (NULL != nsh); 458 GNUNET_break (NULL != nsh);
469 459
@@ -498,6 +488,8 @@ main (int argc, char *argv[])
498 "test_namestore_api_%s.conf", 488 "test_namestore_api_%s.conf",
499 plugin_name); 489 plugin_name);
500 res = 1; 490 res = 1;
491 GNUNET_DISK_purge_cfg_dir (cfg_name,
492 "GNUNET_TEST_HOME");
501 if (0 != 493 if (0 !=
502 GNUNET_TESTING_peer_run ("test-namestore-api-zone-iteration-nick", 494 GNUNET_TESTING_peer_run ("test-namestore-api-zone-iteration-nick",
503 cfg_name, 495 cfg_name,
@@ -506,12 +498,9 @@ main (int argc, char *argv[])
506 { 498 {
507 res = 1; 499 res = 1;
508 } 500 }
501 GNUNET_DISK_purge_cfg_dir (cfg_name,
502 "GNUNET_TEST_HOME");
509 GNUNET_free (cfg_name); 503 GNUNET_free (cfg_name);
510 if (NULL != directory)
511 {
512 GNUNET_DISK_directory_remove (directory);
513 GNUNET_free (directory);
514 }
515 return res; 504 return res;
516} 505}
517 506
diff --git a/src/namestore/test_namestore_api_zone_iteration_specific_zone.c b/src/namestore/test_namestore_api_zone_iteration_specific_zone.c
index a4fb320e9..0b137cc62 100644
--- a/src/namestore/test_namestore_api_zone_iteration_specific_zone.c
+++ b/src/namestore/test_namestore_api_zone_iteration_specific_zone.c
@@ -57,53 +57,17 @@ static char * s_name_3;
57 57
58static struct GNUNET_GNSRECORD_Data *s_rd_3; 58static struct GNUNET_GNSRECORD_Data *s_rd_3;
59 59
60static char *directory;
61 60
62/** 61/**
63 * Re-establish the connection to the service. 62 * Handle timeout.
64 * 63 *
65 * @param cls handle to use to re-connect. 64 * @param cls handle to use to re-connect.
66 * @param tc scheduler context
67 */ 65 */
68static void 66static void
69endbadly (void *cls) 67endbadly (void *cls)
70{ 68{
71 if (NULL != zi) 69 endbadly_task = NULL;
72 { 70 GNUNET_SCHEDULER_shutdown ();
73 GNUNET_NAMESTORE_zone_iteration_stop (zi);
74 zi = NULL;
75 }
76 if (nsh != NULL)
77 GNUNET_NAMESTORE_disconnect (nsh);
78 nsh = NULL;
79
80 GNUNET_free_non_null(s_name_1);
81 GNUNET_free_non_null(s_name_2);
82 GNUNET_free_non_null(s_name_3);
83
84 if (s_rd_1 != NULL)
85 {
86 GNUNET_free ((void *)s_rd_1->data);
87 GNUNET_free (s_rd_1);
88 }
89 if (s_rd_2 != NULL)
90 {
91 GNUNET_free ((void *)s_rd_2->data);
92 GNUNET_free (s_rd_2);
93 }
94 if (s_rd_3 != NULL)
95 {
96 GNUNET_free ((void *)s_rd_3->data);
97 GNUNET_free (s_rd_3);
98 }
99
100 if (privkey != NULL)
101 GNUNET_free (privkey);
102 privkey = NULL;
103
104 if (privkey2 != NULL)
105 GNUNET_free (privkey2);
106 privkey2 = NULL;
107 res = 1; 71 res = 1;
108} 72}
109 73
@@ -116,21 +80,21 @@ end (void *cls)
116 GNUNET_NAMESTORE_zone_iteration_stop (zi); 80 GNUNET_NAMESTORE_zone_iteration_stop (zi);
117 zi = NULL; 81 zi = NULL;
118 } 82 }
119 83 if (NULL != endbadly_task)
120 if (endbadly_task != NULL)
121 { 84 {
122 GNUNET_SCHEDULER_cancel (endbadly_task); 85 GNUNET_SCHEDULER_cancel (endbadly_task);
123 endbadly_task = NULL; 86 endbadly_task = NULL;
124 } 87 }
125 88 if (NULL != privkey)
126 if (privkey != NULL) 89 {
127 GNUNET_free (privkey); 90 GNUNET_free (privkey);
128 privkey = NULL; 91 privkey = NULL;
129 92 }
130 if (privkey2 != NULL) 93 if (NULL != privkey2)
94 {
131 GNUNET_free (privkey2); 95 GNUNET_free (privkey2);
132 privkey2 = NULL; 96 privkey2 = NULL;
133 97 }
134 GNUNET_free (s_name_1); 98 GNUNET_free (s_name_1);
135 GNUNET_free (s_name_2); 99 GNUNET_free (s_name_2);
136 GNUNET_free (s_name_3); 100 GNUNET_free (s_name_3);
@@ -150,8 +114,10 @@ end (void *cls)
150 GNUNET_free (s_rd_3); 114 GNUNET_free (s_rd_3);
151 } 115 }
152 if (nsh != NULL) 116 if (nsh != NULL)
117 {
153 GNUNET_NAMESTORE_disconnect (nsh); 118 GNUNET_NAMESTORE_disconnect (nsh);
154 nsh = NULL; 119 nsh = NULL;
120 }
155} 121}
156 122
157 123
@@ -159,6 +125,7 @@ static void
159fail_cb (void *cls) 125fail_cb (void *cls)
160{ 126{
161 GNUNET_assert (0); 127 GNUNET_assert (0);
128 zi = NULL;
162} 129}
163 130
164 131
@@ -244,7 +211,8 @@ zone_proc (void *cls,
244 else 211 else
245 { 212 {
246 GNUNET_break (0); 213 GNUNET_break (0);
247 GNUNET_SCHEDULER_add_now (&end, NULL); 214 res = 2;
215 GNUNET_SCHEDULER_shutdown ();
248 } 216 }
249} 217}
250 218
@@ -252,24 +220,28 @@ zone_proc (void *cls,
252static void 220static void
253zone_proc_end (void *cls) 221zone_proc_end (void *cls)
254{ 222{
223 zi = NULL;
255 GNUNET_break (2 == returned_records); 224 GNUNET_break (2 == returned_records);
256 if (2 == returned_records) 225 if (2 == returned_records)
257 { 226 {
258 res = 0; /* Last iteraterator callback, we are done */ 227 res = 0; /* Last iteraterator callback, we are done */
259 zi = NULL;
260 } 228 }
261 else 229 else
230 {
262 res = 1; 231 res = 1;
232 }
263 233
264 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 234 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
265 "Received last result, iteration done after receing %u results\n", 235 "Received last result, iteration done after receing %u results\n",
266 returned_records); 236 returned_records);
267 GNUNET_SCHEDULER_add_now (&end, NULL); 237 GNUNET_SCHEDULER_shutdown ();
268} 238}
269 239
270 240
271static void 241static void
272put_cont (void *cls, int32_t success, const char *emsg) 242put_cont (void *cls,
243 int32_t success,
244 const char *emsg)
273{ 245{
274 static int c = 0; 246 static int c = 0;
275 247
@@ -285,9 +257,8 @@ put_cont (void *cls, int32_t success, const char *emsg)
285 "Failed to created records: `%s'\n", 257 "Failed to created records: `%s'\n",
286 emsg); 258 emsg);
287 GNUNET_break (0); 259 GNUNET_break (0);
288 if (NULL != endbadly_task) 260 res = 2;
289 GNUNET_SCHEDULER_cancel (endbadly_task); 261 GNUNET_SCHEDULER_shutdown ();
290 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
291 return; 262 return;
292 } 263 }
293 264
@@ -310,9 +281,8 @@ put_cont (void *cls, int32_t success, const char *emsg)
310 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 281 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
311 "Failed to create zone iterator\n"); 282 "Failed to create zone iterator\n");
312 GNUNET_break (0); 283 GNUNET_break (0);
313 if (NULL != endbadly_task) 284 res = 2;
314 GNUNET_SCHEDULER_cancel (endbadly_task); 285 GNUNET_SCHEDULER_shutdown ();
315 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
316 return; 286 return;
317 } 287 }
318 } 288 }
@@ -322,11 +292,11 @@ put_cont (void *cls, int32_t success, const char *emsg)
322static struct GNUNET_GNSRECORD_Data * 292static struct GNUNET_GNSRECORD_Data *
323create_record (unsigned int count) 293create_record (unsigned int count)
324{ 294{
325 unsigned int c; 295 struct GNUNET_GNSRECORD_Data *rd;
326 struct GNUNET_GNSRECORD_Data * rd;
327 296
328 rd = GNUNET_malloc (count * sizeof (struct GNUNET_GNSRECORD_Data)); 297 rd = GNUNET_new_array (count,
329 for (c = 0; c < count; c++) 298 struct GNUNET_GNSRECORD_Data);
299 for (unsigned int c = 0; c < count; c++)
330 { 300 {
331 rd[c].expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS).abs_value_us; 301 rd[c].expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS).abs_value_us;
332 rd[c].record_type = 1111; 302 rd[c].record_type = 1111;
@@ -357,9 +327,8 @@ empty_zone_proc (void *cls,
357 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 327 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
358 _("Expected empty zone but received zone private key\n")); 328 _("Expected empty zone but received zone private key\n"));
359 GNUNET_break (0); 329 GNUNET_break (0);
360 if (endbadly_task != NULL) 330 res = 2;
361 GNUNET_SCHEDULER_cancel (endbadly_task); 331 GNUNET_SCHEDULER_shutdown ();
362 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
363 return; 332 return;
364 } 333 }
365 if ((NULL != label) || (NULL != rd) || (0 != rd_count)) 334 if ((NULL != label) || (NULL != rd) || (0 != rd_count))
@@ -367,9 +336,8 @@ empty_zone_proc (void *cls,
367 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 336 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
368 _("Expected no zone content but received data\n")); 337 _("Expected no zone content but received data\n"));
369 GNUNET_break (0); 338 GNUNET_break (0);
370 if (endbadly_task != NULL) 339 res = 2;
371 GNUNET_SCHEDULER_cancel (endbadly_task); 340 GNUNET_SCHEDULER_shutdown ();
372 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
373 return; 341 return;
374 } 342 }
375 GNUNET_assert (0); 343 GNUNET_assert (0);
@@ -379,35 +347,16 @@ empty_zone_proc (void *cls,
379static void 347static void
380empty_zone_proc_end (void *cls) 348empty_zone_proc_end (void *cls)
381{ 349{
382 char *hostkey_file;
383
384 zi = NULL; 350 zi = NULL;
385 GNUNET_asprintf (&hostkey_file, 351 privkey = GNUNET_CRYPTO_ecdsa_key_create ();
386 "zonefiles%s%s",
387 DIR_SEPARATOR_STR,
388 "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
389 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
390 "Using zonekey file `%s'\n",
391 hostkey_file);
392 privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file);
393 GNUNET_free (hostkey_file);
394 GNUNET_assert (privkey != NULL); 352 GNUNET_assert (privkey != NULL);
395 353 privkey2 = GNUNET_CRYPTO_ecdsa_key_create ();
396 GNUNET_asprintf(&hostkey_file,
397 "zonefiles%s%s",
398 DIR_SEPARATOR_STR,
399 "HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey");
400 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
401 "Using zonekey file `%s' \n",
402 hostkey_file);
403 privkey2 = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file);
404 GNUNET_free (hostkey_file);
405 GNUNET_assert (privkey2 != NULL); 354 GNUNET_assert (privkey2 != NULL);
406 355
407 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 356 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
408 "Created record 1\n"); 357 "Created record 1\n");
409 358 GNUNET_asprintf (&s_name_1,
410 GNUNET_asprintf(&s_name_1, "dummy1"); 359 "dummy1");
411 s_rd_1 = create_record (1); 360 s_rd_1 = create_record (1);
412 GNUNET_NAMESTORE_records_store (nsh, 361 GNUNET_NAMESTORE_records_store (nsh,
413 privkey, 362 privkey,
@@ -419,7 +368,8 @@ empty_zone_proc_end (void *cls)
419 368
420 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 369 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
421 "Created record 2 \n"); 370 "Created record 2 \n");
422 GNUNET_asprintf(&s_name_2, "dummy2"); 371 GNUNET_asprintf (&s_name_2,
372 "dummy2");
423 s_rd_2 = create_record (1); 373 s_rd_2 = create_record (1);
424 GNUNET_NAMESTORE_records_store (nsh, 374 GNUNET_NAMESTORE_records_store (nsh,
425 privkey, 375 privkey,
@@ -433,7 +383,8 @@ empty_zone_proc_end (void *cls)
433 "Created record 3\n"); 383 "Created record 3\n");
434 384
435 /* name in different zone */ 385 /* name in different zone */
436 GNUNET_asprintf(&s_name_3, "dummy3"); 386 GNUNET_asprintf (&s_name_3,
387 "dummy3");
437 s_rd_3 = create_record (1); 388 s_rd_3 = create_record (1);
438 GNUNET_NAMESTORE_records_store (nsh, 389 GNUNET_NAMESTORE_records_store (nsh,
439 privkey2, 390 privkey2,
@@ -449,14 +400,8 @@ run (void *cls,
449 const struct GNUNET_CONFIGURATION_Handle *cfg, 400 const struct GNUNET_CONFIGURATION_Handle *cfg,
450 struct GNUNET_TESTING_Peer *peer) 401 struct GNUNET_TESTING_Peer *peer)
451{ 402{
452 directory = NULL; 403 GNUNET_SCHEDULER_add_shutdown (&end,
453 GNUNET_assert (GNUNET_OK == 404 NULL);
454 GNUNET_CONFIGURATION_get_value_string (cfg,
455 "PATHS",
456 "GNUNET_TEST_HOME",
457 &directory));
458 GNUNET_DISK_directory_remove (directory);
459
460 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 405 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
461 &endbadly, 406 &endbadly,
462 NULL); 407 NULL);
@@ -476,8 +421,7 @@ run (void *cls,
476 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 421 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
477 "Failed to create zone iterator\n"); 422 "Failed to create zone iterator\n");
478 GNUNET_break (0); 423 GNUNET_break (0);
479 GNUNET_SCHEDULER_cancel (endbadly_task); 424 GNUNET_SCHEDULER_shutdown ();
480 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
481 } 425 }
482} 426}
483 427
@@ -493,6 +437,8 @@ main (int argc, char *argv[])
493 "test_namestore_api_%s.conf", 437 "test_namestore_api_%s.conf",
494 plugin_name); 438 plugin_name);
495 res = 1; 439 res = 1;
440 GNUNET_DISK_purge_cfg_dir (cfg_name,
441 "GNUNET_TEST_HOME");
496 if (0 != 442 if (0 !=
497 GNUNET_TESTING_peer_run ("test-namestore-api-zone-iteration-specific-zone", 443 GNUNET_TESTING_peer_run ("test-namestore-api-zone-iteration-specific-zone",
498 cfg_name, 444 cfg_name,
@@ -501,12 +447,9 @@ main (int argc, char *argv[])
501 { 447 {
502 res = 1; 448 res = 1;
503 } 449 }
450 GNUNET_DISK_purge_cfg_dir (cfg_name,
451 "GNUNET_TEST_HOME");
504 GNUNET_free (cfg_name); 452 GNUNET_free (cfg_name);
505 if (NULL != directory)
506 {
507 GNUNET_DISK_directory_remove (directory);
508 GNUNET_free (directory);
509 }
510 return res; 453 return res;
511} 454}
512 455
diff --git a/src/namestore/test_namestore_api_zone_iteration_stop.c b/src/namestore/test_namestore_api_zone_iteration_stop.c
index c7be5fead..c7358fc6e 100644
--- a/src/namestore/test_namestore_api_zone_iteration_stop.c
+++ b/src/namestore/test_namestore_api_zone_iteration_stop.c
@@ -56,7 +56,6 @@ static char * s_name_3;
56 56
57static struct GNUNET_GNSRECORD_Data *s_rd_3; 57static struct GNUNET_GNSRECORD_Data *s_rd_3;
58 58
59static char *directory;
60 59
61 60
62/** 61/**
@@ -475,14 +474,9 @@ run (void *cls,
475 const struct GNUNET_CONFIGURATION_Handle *cfg, 474 const struct GNUNET_CONFIGURATION_Handle *cfg,
476 struct GNUNET_TESTING_Peer *peer) 475 struct GNUNET_TESTING_Peer *peer)
477{ 476{
478 GNUNET_assert (GNUNET_OK == 477 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
479 GNUNET_CONFIGURATION_get_value_string (cfg, 478 &endbadly,
480 "PATHS", 479 NULL);
481 "GNUNET_TEST_HOME",
482 &directory));
483 GNUNET_DISK_directory_remove (directory);
484
485 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &endbadly, NULL);
486 nsh = GNUNET_NAMESTORE_connect (cfg); 480 nsh = GNUNET_NAMESTORE_connect (cfg);
487 GNUNET_break (NULL != nsh); 481 GNUNET_break (NULL != nsh);
488 /* first, iterate over empty namestore */ 482 /* first, iterate over empty namestore */
@@ -515,6 +509,8 @@ main (int argc, char *argv[])
515 GNUNET_asprintf (&cfg_name, 509 GNUNET_asprintf (&cfg_name,
516 "test_namestore_api_%s.conf", 510 "test_namestore_api_%s.conf",
517 plugin_name); 511 plugin_name);
512 GNUNET_DISK_purge_cfg_dir (cfg_name,
513 "GNUNET_TEST_HOME");
518 res = 1; 514 res = 1;
519 if (0 != 515 if (0 !=
520 GNUNET_TESTING_peer_run ("test-namestore-api-zone-iteration-stop", 516 GNUNET_TESTING_peer_run ("test-namestore-api-zone-iteration-stop",
@@ -524,12 +520,10 @@ main (int argc, char *argv[])
524 { 520 {
525 res = 1; 521 res = 1;
526 } 522 }
523 GNUNET_DISK_purge_cfg_dir (cfg_name,
524 "GNUNET_TEST_HOME");
527 GNUNET_free (cfg_name); 525 GNUNET_free (cfg_name);
528 if (NULL != directory) 526
529 {
530 GNUNET_DISK_directory_remove (directory);
531 GNUNET_free (directory);
532 }
533 return res; 527 return res;
534} 528}
535 529
diff --git a/src/namestore/test_namestore_api_zone_to_name.c b/src/namestore/test_namestore_api_zone_to_name.c
index 5b088d90b..292d8f701 100644
--- a/src/namestore/test_namestore_api_zone_to_name.c
+++ b/src/namestore/test_namestore_api_zone_to_name.c
@@ -51,8 +51,6 @@ static char * s_name;
51 51
52static int res; 52static int res;
53 53
54static char *directory;
55
56static struct GNUNET_NAMESTORE_QueueEntry *qe; 54static struct GNUNET_NAMESTORE_QueueEntry *qe;
57 55
58 56
@@ -204,34 +202,13 @@ run (void *cls,
204{ 202{
205 (void) cls; 203 (void) cls;
206 (void) peer; 204 (void) peer;
207 directory = NULL;
208 GNUNET_assert (GNUNET_OK ==
209 GNUNET_CONFIGURATION_get_value_string (cfg,
210 "PATHS",
211 "GNUNET_TEST_HOME",
212 &directory));
213 GNUNET_DISK_directory_remove (directory);
214
215 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 205 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
216 &endbadly, 206 &endbadly,
217 NULL); 207 NULL);
218 GNUNET_SCHEDULER_add_shutdown (&end, 208 GNUNET_SCHEDULER_add_shutdown (&end,
219 NULL); 209 NULL);
220 GNUNET_asprintf (&s_name, "dummy"); 210 GNUNET_asprintf (&s_name, "dummy");
221 /* load privat key */ 211 privkey = GNUNET_CRYPTO_ecdsa_key_create ();
222 {
223 char *zonekey_file;
224
225 GNUNET_asprintf (&zonekey_file,
226 "zonefiles%s%s",
227 DIR_SEPARATOR_STR,
228 "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
229 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
230 "Using zonekey file `%s'\n",
231 zonekey_file);
232 privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (zonekey_file);
233 GNUNET_free (zonekey_file);
234 }
235 GNUNET_assert (NULL != privkey); 212 GNUNET_assert (NULL != privkey);
236 /* get public key */ 213 /* get public key */
237 GNUNET_CRYPTO_ecdsa_key_get_public (privkey, 214 GNUNET_CRYPTO_ecdsa_key_get_public (privkey,
@@ -274,6 +251,8 @@ main (int argc,
274 GNUNET_asprintf (&cfg_name, 251 GNUNET_asprintf (&cfg_name,
275 "test_namestore_api_%s.conf", 252 "test_namestore_api_%s.conf",
276 plugin_name); 253 plugin_name);
254 GNUNET_DISK_purge_cfg_dir (cfg_name,
255 "GNUNET_TEST_HOME");
277 res = 1; 256 res = 1;
278 if (0 != 257 if (0 !=
279 GNUNET_TESTING_peer_run ("test-namestore-api-zone-to-name", 258 GNUNET_TESTING_peer_run ("test-namestore-api-zone-to-name",
@@ -283,12 +262,9 @@ main (int argc,
283 { 262 {
284 res = 1; 263 res = 1;
285 } 264 }
265 GNUNET_DISK_purge_cfg_dir (cfg_name,
266 "GNUNET_TEST_HOME");
286 GNUNET_free (cfg_name); 267 GNUNET_free (cfg_name);
287 if (NULL != directory)
288 {
289 GNUNET_DISK_directory_remove (directory);
290 GNUNET_free (directory);
291 }
292 return res; 268 return res;
293} 269}
294 270
diff --git a/src/namestore/test_plugin_namestore.c b/src/namestore/test_plugin_namestore.c
index 6bccd1706..8732acbcb 100644
--- a/src/namestore/test_plugin_namestore.c
+++ b/src/namestore/test_plugin_namestore.c
@@ -215,6 +215,8 @@ main (int argc,
215 sizeof (cfg_name), 215 sizeof (cfg_name),
216 "test_plugin_namestore_%s.conf", 216 "test_plugin_namestore_%s.conf",
217 plugin_name); 217 plugin_name);
218 GNUNET_DISK_purge_cfg_dir (cfg_name,
219 "GNUNET_TMP");
218 GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, 220 GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1,
219 xargv, 221 xargv,
220 "test-plugin-namestore", 222 "test-plugin-namestore",
@@ -222,6 +224,8 @@ main (int argc,
222 options, 224 options,
223 &run, 225 &run,
224 NULL); 226 NULL);
227 GNUNET_DISK_purge_cfg_dir (cfg_name,
228 "GNUNET_TMP");
225 if (ok != 0) 229 if (ok != 0)
226 FPRINTF (stderr, 230 FPRINTF (stderr,
227 "Missed some testcases: %d\n", 231 "Missed some testcases: %d\n",
diff --git a/src/namestore/test_plugin_namestore_flat.conf b/src/namestore/test_plugin_namestore_flat.conf
index 6a5491df7..5c632f0d1 100644
--- a/src/namestore/test_plugin_namestore_flat.conf
+++ b/src/namestore/test_plugin_namestore_flat.conf
@@ -1,5 +1,2 @@
1[namestore-flat] 1[namestore-flat]
2FILENAME = $GNUNET_TMP/gnunet-test-plugin-namestore-sqlite/flatdb 2FILENAME = $GNUNET_TMP/gnunet-test-plugin-namestore-flat/flatdb
3
4[namestore]
5# PREFIX = valgrind --log-file=/home/schanzen/dev/gnunet/src/namestore/vg_log
diff --git a/src/nat/gnunet-helper-nat-client.c b/src/nat/gnunet-helper-nat-client.c
index d9129afb0..359e529b0 100644
--- a/src/nat/gnunet-helper-nat-client.c
+++ b/src/nat/gnunet-helper-nat-client.c
@@ -67,6 +67,17 @@
67#endif 67#endif
68 68
69/** 69/**
70 * Call memcpy() but check for @a n being 0 first. In the latter
71 * case, it is now safe to pass NULL for @a src or @a dst.
72 * Unlike traditional memcpy(), returns nothing.
73 *
74 * @param dst destination of the copy, may be NULL if @a n is zero
75 * @param src source of the copy, may be NULL if @a n is zero
76 * @param n number of bytes to copy
77 */
78#define GNUNET_memcpy(dst,src,n) do { if (0 != n) { (void) memcpy (dst,src,n); } } while (0)
79
80/**
70 * Must match IP given in the server. 81 * Must match IP given in the server.
71 */ 82 */
72#define DUMMY_IP "192.0.2.86" 83#define DUMMY_IP "192.0.2.86"
@@ -251,14 +262,18 @@ send_icmp_udp (const struct in_addr *my_ip, const struct in_addr *other)
251 ip_pkt.dst_ip = other->s_addr; 262 ip_pkt.dst_ip = other->s_addr;
252 ip_pkt.checksum = 263 ip_pkt.checksum =
253 htons (calc_checksum ((uint16_t *) & ip_pkt, sizeof (struct ip_header))); 264 htons (calc_checksum ((uint16_t *) & ip_pkt, sizeof (struct ip_header)));
254 memcpy (&packet[off], &ip_pkt, sizeof (struct ip_header)); 265 GNUNET_memcpy (&packet[off],
266 &ip_pkt,
267 sizeof (struct ip_header));
255 off += sizeof (struct ip_header); 268 off += sizeof (struct ip_header);
256 269
257 icmp_pkt.type = ICMP_TIME_EXCEEDED; 270 icmp_pkt.type = ICMP_TIME_EXCEEDED;
258 icmp_pkt.code = 0; 271 icmp_pkt.code = 0;
259 icmp_pkt.checksum = 0; 272 icmp_pkt.checksum = 0;
260 icmp_pkt.unused = 0; 273 icmp_pkt.unused = 0;
261 memcpy (&packet[off], &icmp_pkt, sizeof (struct icmp_ttl_exceeded_header)); 274 GNUNET_memcpy (&packet[off],
275 &icmp_pkt,
276 sizeof (struct icmp_ttl_exceeded_header));
262 off += sizeof (struct icmp_ttl_exceeded_header); 277 off += sizeof (struct icmp_ttl_exceeded_header);
263 278
264 /* ip header of the presumably 'lost' udp packet */ 279 /* 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)
275 ip_pkt.dst_ip = dummy.s_addr; 290 ip_pkt.dst_ip = dummy.s_addr;
276 ip_pkt.checksum = 291 ip_pkt.checksum =
277 htons (calc_checksum ((uint16_t *) & ip_pkt, sizeof (struct ip_header))); 292 htons (calc_checksum ((uint16_t *) & ip_pkt, sizeof (struct ip_header)));
278 memcpy (&packet[off], &ip_pkt, sizeof (struct ip_header)); 293 GNUNET_memcpy (&packet[off],
294 &ip_pkt,
295 sizeof (struct ip_header));
279 off += sizeof (struct ip_header); 296 off += sizeof (struct ip_header);
280 297
281 /* build UDP header */ 298 /* build UDP header */
@@ -283,7 +300,9 @@ send_icmp_udp (const struct in_addr *my_ip, const struct in_addr *other)
283 udp_pkt.dst_port = htons (NAT_TRAV_PORT); 300 udp_pkt.dst_port = htons (NAT_TRAV_PORT);
284 udp_pkt.length = htons (port); 301 udp_pkt.length = htons (port);
285 udp_pkt.crc = 0; 302 udp_pkt.crc = 0;
286 memcpy (&packet[off], &udp_pkt, sizeof (struct udp_header)); 303 GNUNET_memcpy (&packet[off],
304 &udp_pkt,
305 sizeof (struct udp_header));
287 off += sizeof (struct udp_header); 306 off += sizeof (struct udp_header);
288 307
289 /* set ICMP checksum */ 308 /* set ICMP checksum */
@@ -292,8 +311,9 @@ send_icmp_udp (const struct in_addr *my_ip, const struct in_addr *other)
292 ((uint16_t *) & packet[sizeof (struct ip_header)], 311 ((uint16_t *) & packet[sizeof (struct ip_header)],
293 sizeof (struct icmp_ttl_exceeded_header) + 312 sizeof (struct icmp_ttl_exceeded_header) +
294 sizeof (struct ip_header) + sizeof (struct udp_header))); 313 sizeof (struct ip_header) + sizeof (struct udp_header)));
295 memcpy (&packet[sizeof (struct ip_header)], &icmp_pkt, 314 GNUNET_memcpy (&packet[sizeof (struct ip_header)],
296 sizeof (struct icmp_ttl_exceeded_header)); 315 &icmp_pkt,
316 sizeof (struct icmp_ttl_exceeded_header));
297 317
298 memset (&dst, 0, sizeof (dst)); 318 memset (&dst, 0, sizeof (dst));
299 dst.sin_family = AF_INET; 319 dst.sin_family = AF_INET;
@@ -352,7 +372,9 @@ send_icmp (const struct in_addr *my_ip, const struct in_addr *other)
352 ip_pkt.dst_ip = other->s_addr; 372 ip_pkt.dst_ip = other->s_addr;
353 ip_pkt.checksum = 373 ip_pkt.checksum =
354 htons (calc_checksum ((uint16_t *) & ip_pkt, sizeof (struct ip_header))); 374 htons (calc_checksum ((uint16_t *) & ip_pkt, sizeof (struct ip_header)));
355 memcpy (&packet[off], &ip_pkt, sizeof (struct ip_header)); 375 GNUNET_memcpy (&packet[off],
376 &ip_pkt,
377 sizeof (struct ip_header));
356 off = sizeof (ip_pkt); 378 off = sizeof (ip_pkt);
357 379
358 /* icmp reply: time exceeded */ 380 /* icmp reply: time exceeded */
@@ -360,7 +382,9 @@ send_icmp (const struct in_addr *my_ip, const struct in_addr *other)
360 icmp_ttl.code = 0; 382 icmp_ttl.code = 0;
361 icmp_ttl.checksum = 0; 383 icmp_ttl.checksum = 0;
362 icmp_ttl.unused = 0; 384 icmp_ttl.unused = 0;
363 memcpy (&packet[off], &icmp_ttl, sizeof (struct icmp_ttl_exceeded_header)); 385 GNUNET_memcpy (&packet[off],
386 &icmp_ttl,
387 sizeof (struct icmp_ttl_exceeded_header));
364 off += sizeof (struct icmp_ttl_exceeded_header); 388 off += sizeof (struct icmp_ttl_exceeded_header);
365 389
366 /* ip header of the presumably 'lost' udp packet */ 390 /* 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)
377 ip_pkt.checksum = 0; 401 ip_pkt.checksum = 0;
378 ip_pkt.checksum = 402 ip_pkt.checksum =
379 htons (calc_checksum ((uint16_t *) & ip_pkt, sizeof (struct ip_header))); 403 htons (calc_checksum ((uint16_t *) & ip_pkt, sizeof (struct ip_header)));
380 memcpy (&packet[off], &ip_pkt, sizeof (struct ip_header)); 404 GNUNET_memcpy (&packet[off],
405 &ip_pkt,
406 sizeof (struct ip_header));
381 off += sizeof (struct ip_header); 407 off += sizeof (struct ip_header);
382 408
383 icmp_echo.type = ICMP_ECHO; 409 icmp_echo.type = ICMP_ECHO;
@@ -386,8 +412,10 @@ send_icmp (const struct in_addr *my_ip, const struct in_addr *other)
386 icmp_echo.checksum = 0; 412 icmp_echo.checksum = 0;
387 icmp_echo.checksum = 413 icmp_echo.checksum =
388 htons (calc_checksum 414 htons (calc_checksum
389 ((uint16_t *) & icmp_echo, sizeof (struct icmp_echo_header))); 415 ((uint16_t *) &icmp_echo, sizeof (struct icmp_echo_header)));
390 memcpy (&packet[off], &icmp_echo, sizeof (struct icmp_echo_header)); 416 GNUNET_memcpy (&packet[off],
417 &icmp_echo,
418 sizeof (struct icmp_echo_header));
391 419
392 /* no go back to calculate ICMP packet checksum */ 420 /* no go back to calculate ICMP packet checksum */
393 off = sizeof (struct ip_header); 421 off = sizeof (struct ip_header);
@@ -396,7 +424,9 @@ send_icmp (const struct in_addr *my_ip, const struct in_addr *other)
396 ((uint16_t *) & packet[off], 424 ((uint16_t *) & packet[off],
397 sizeof (struct icmp_ttl_exceeded_header) + 425 sizeof (struct icmp_ttl_exceeded_header) +
398 sizeof (struct ip_header) + sizeof (struct icmp_echo_header))); 426 sizeof (struct ip_header) + sizeof (struct icmp_echo_header)));
399 memcpy (&packet[off], &icmp_ttl, sizeof (struct icmp_ttl_exceeded_header)); 427 GNUNET_memcpy (&packet[off],
428 &icmp_ttl,
429 sizeof (struct icmp_ttl_exceeded_header));
400 430
401 /* prepare for transmission */ 431 /* prepare for transmission */
402 memset (&dst, 0, sizeof (dst)); 432 memset (&dst, 0, sizeof (dst));
diff --git a/src/nat/gnunet-helper-nat-server.c b/src/nat/gnunet-helper-nat-server.c
index ef8e97482..b8f499b4d 100644
--- a/src/nat/gnunet-helper-nat-server.c
+++ b/src/nat/gnunet-helper-nat-server.c
@@ -71,6 +71,17 @@
71#endif 71#endif
72 72
73/** 73/**
74 * Call memcpy() but check for @a n being 0 first. In the latter
75 * case, it is now safe to pass NULL for @a src or @a dst.
76 * Unlike traditional memcpy(), returns nothing.
77 *
78 * @param dst destination of the copy, may be NULL if @a n is zero
79 * @param src source of the copy, may be NULL if @a n is zero
80 * @param n number of bytes to copy
81 */
82#define GNUNET_memcpy(dst,src,n) do { if (0 != n) { (void) memcpy (dst,src,n); } } while (0)
83
84/**
74 * Should we print some debug output? 85 * Should we print some debug output?
75 */ 86 */
76#define VERBOSE 0 87#define VERBOSE 0
@@ -266,9 +277,9 @@ send_icmp_echo (const struct in_addr *my_ip)
266 ip_pkt.checksum = 277 ip_pkt.checksum =
267 htons (calc_checksum ((uint16_t *) & ip_pkt, 278 htons (calc_checksum ((uint16_t *) & ip_pkt,
268 sizeof (struct ip_header))); 279 sizeof (struct ip_header)));
269 memcpy (&packet[off], 280 GNUNET_memcpy (&packet[off],
270 &ip_pkt, 281 &ip_pkt,
271 sizeof (struct ip_header)); 282 sizeof (struct ip_header));
272 off += sizeof (struct ip_header); 283 off += sizeof (struct ip_header);
273 284
274 icmp_echo.type = ICMP_ECHO; 285 icmp_echo.type = ICMP_ECHO;
@@ -279,9 +290,9 @@ send_icmp_echo (const struct in_addr *my_ip)
279 htons (calc_checksum 290 htons (calc_checksum
280 ((uint16_t *) & icmp_echo, 291 ((uint16_t *) & icmp_echo,
281 sizeof (struct icmp_echo_header))); 292 sizeof (struct icmp_echo_header)));
282 memcpy (&packet[off], 293 GNUNET_memcpy (&packet[off],
283 &icmp_echo, 294 &icmp_echo,
284 sizeof (struct icmp_echo_header)); 295 sizeof (struct icmp_echo_header));
285 off += sizeof (struct icmp_echo_header); 296 off += sizeof (struct icmp_echo_header);
286 297
287 memset (&dst, 0, sizeof (dst)); 298 memset (&dst, 0, sizeof (dst));
@@ -388,9 +399,13 @@ process_icmp_response ()
388 return; 399 return;
389 } 400 }
390 off = 0; 401 off = 0;
391 memcpy (&ip_pkt, &buf[off], sizeof (struct ip_header)); 402 GNUNET_memcpy (&ip_pkt,
403 &buf[off],
404 sizeof (struct ip_header));
392 off += sizeof (struct ip_header); 405 off += sizeof (struct ip_header);
393 memcpy (&icmp_ttl, &buf[off], sizeof (struct icmp_ttl_exceeded_header)); 406 GNUNET_memcpy (&icmp_ttl,
407 &buf[off],
408 sizeof (struct icmp_ttl_exceeded_header));
394 off += sizeof (struct icmp_ttl_exceeded_header); 409 off += sizeof (struct icmp_ttl_exceeded_header);
395 if ((ICMP_TIME_EXCEEDED != icmp_ttl.type) || (0 != icmp_ttl.code)) 410 if ((ICMP_TIME_EXCEEDED != icmp_ttl.type) || (0 != icmp_ttl.code))
396 { 411 {
@@ -401,7 +416,9 @@ process_icmp_response ()
401 source_ip.s_addr = ip_pkt.src_ip; 416 source_ip.s_addr = ip_pkt.src_ip;
402 417
403 /* skip 2nd IP header */ 418 /* skip 2nd IP header */
404 memcpy (&ip_pkt, &buf[off], sizeof (struct ip_header)); 419 GNUNET_memcpy (&ip_pkt,
420 &buf[off],
421 sizeof (struct ip_header));
405 off += sizeof (struct ip_header); 422 off += sizeof (struct ip_header);
406 423
407 switch (ip_pkt.proto) 424 switch (ip_pkt.proto)
@@ -416,7 +433,9 @@ process_icmp_response ()
416 return; 433 return;
417 } 434 }
418 /* grab ICMP ECHO content */ 435 /* grab ICMP ECHO content */
419 memcpy (&icmp_echo, &buf[off], sizeof (struct icmp_echo_header)); 436 GNUNET_memcpy (&icmp_echo,
437 &buf[off],
438 sizeof (struct icmp_echo_header));
420 port = (uint16_t) ntohl (icmp_echo.reserved); 439 port = (uint16_t) ntohl (icmp_echo.reserved);
421 break; 440 break;
422 case IPPROTO_UDP: 441 case IPPROTO_UDP:
@@ -428,7 +447,9 @@ process_icmp_response ()
428 return; 447 return;
429 } 448 }
430 /* grab UDP content */ 449 /* grab UDP content */
431 memcpy (&udp_pkt, &buf[off], sizeof (struct udp_header)); 450 GNUNET_memcpy (&udp_pkt,
451 &buf[off],
452 sizeof (struct udp_header));
432 port = ntohs (udp_pkt.length); 453 port = ntohs (udp_pkt.length);
433 break; 454 break;
434 default: 455 default:
diff --git a/src/nat/gnunet-service-nat.c b/src/nat/gnunet-service-nat.c
index 0695c7ac7..21089890d 100644
--- a/src/nat/gnunet-service-nat.c
+++ b/src/nat/gnunet-service-nat.c
@@ -1234,8 +1234,12 @@ process_external_ip (void *cls,
1234 ch->hole_external); 1234 ch->hole_external);
1235 1235
1236 /* build sockaddr storage with port number */ 1236 /* build sockaddr storage with port number */
1237 memset (&ss, 0, sizeof (ss)); 1237 memset (&ss,
1238 memcpy (&ss, addr, addrlen); 1238 0,
1239 sizeof (ss));
1240 GNUNET_memcpy (&ss,
1241 addr,
1242 addrlen);
1239 switch (addr->sa_family) 1243 switch (addr->sa_family)
1240 { 1244 {
1241 case AF_INET: 1245 case AF_INET:
diff --git a/src/regex/regex_test_lib.c b/src/regex/regex_test_lib.c
index 814380246..c5f9f6cf0 100644
--- a/src/regex/regex_test_lib.c
+++ b/src/regex/regex_test_lib.c
@@ -172,9 +172,9 @@ move_children (struct RegexCombineCtx *dst,
172 size_t array_size; 172 size_t array_size;
173 173
174 array_size = sizeof(struct RegexCombineCtx *) * src->size; 174 array_size = sizeof(struct RegexCombineCtx *) * src->size;
175 memcpy (dst->children, 175 GNUNET_memcpy (dst->children,
176 src->children, 176 src->children,
177 array_size); 177 array_size);
178 for (unsigned int i = 0; i < src->size; i++) 178 for (unsigned int i = 0; i < src->size; i++)
179 { 179 {
180 src->children[i] = NULL; 180 src->children[i] = NULL;
@@ -364,7 +364,9 @@ regex_add_multiple (struct RegexCombineCtx *ctx,
364 newctx = new_regex_ctx(ctx->size); 364 newctx = new_regex_ctx(ctx->size);
365 newctx->s = GNUNET_strdup (tmp); 365 newctx->s = GNUNET_strdup (tmp);
366 if (children != NULL) 366 if (children != NULL)
367 memcpy (newctx->children, children, sizeof (*children) * ctx->size); 367 GNUNET_memcpy (newctx->children,
368 children,
369 sizeof (*children) * ctx->size);
368 ctx->children[c2i(tmp[0], ctx->size)] = newctx; 370 ctx->children[c2i(tmp[0], ctx->size)] = newctx;
369 } 371 }
370 } 372 }
diff --git a/src/rps/test_rps.c b/src/rps/test_rps.c
index 8d31bf50d..b433a51d4 100644
--- a/src/rps/test_rps.c
+++ b/src/rps/test_rps.c
@@ -1836,7 +1836,7 @@ static uint32_t binom (uint32_t n, uint32_t k)
1836 * @param a 1836 * @param a
1837 * @param b 1837 * @param b
1838 * 1838 *
1839 * @return 1839 * @return
1840 */ 1840 */
1841static int is_in_view (uint32_t a, uint32_t b) 1841static int is_in_view (uint32_t a, uint32_t b)
1842{ 1842{
@@ -2172,9 +2172,9 @@ void view_update_cb (void *cls,
2172 rps_peer->cur_view_count, 2172 rps_peer->cur_view_count,
2173 view_size); 2173 view_size);
2174 //*rps_peer->cur_view = *peers; 2174 //*rps_peer->cur_view = *peers;
2175 memcpy (rps_peer->cur_view, 2175 GNUNET_memcpy (rps_peer->cur_view,
2176 peers, 2176 peers,
2177 view_size * sizeof (struct GNUNET_PeerIdentity)); 2177 view_size * sizeof (struct GNUNET_PeerIdentity));
2178 to_file ("/tmp/rps/count_in_views.txt", 2178 to_file ("/tmp/rps/count_in_views.txt",
2179 "%" PRIu64 " %" PRIu32 "", 2179 "%" PRIu64 " %" PRIu32 "",
2180 rps_peer->index, 2180 rps_peer->index,
diff --git a/src/sq/Makefile.am b/src/sq/Makefile.am
index 119a94734..fb9364005 100644
--- a/src/sq/Makefile.am
+++ b/src/sq/Makefile.am
@@ -1,5 +1,5 @@
1# This Makefile.am is in the public domain 1# This Makefile.am is in the public domain
2AM_CPPFLAGS = -I$(top_srcdir)/src/include 2AM_CPPFLAGS = -I$(top_srcdir)/src/include
3 3
4if MINGW 4if MINGW
5 WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols 5 WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols
@@ -15,6 +15,8 @@ endif
15 15
16libgnunetsq_la_SOURCES = \ 16libgnunetsq_la_SOURCES = \
17 sq.c \ 17 sq.c \
18 sq_exec.c \
19 sq_prepare.c \
18 sq_query_helper.c \ 20 sq_query_helper.c \
19 sq_result_helper.c 21 sq_result_helper.c
20libgnunetsq_la_LIBADD = -lsqlite3 \ 22libgnunetsq_la_LIBADD = -lsqlite3 \
diff --git a/src/sq/sq_exec.c b/src/sq/sq_exec.c
new file mode 100644
index 000000000..c40b1fb75
--- /dev/null
+++ b/src/sq/sq_exec.c
@@ -0,0 +1,109 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2018 GNUnet e.V.
4
5 GNUnet is free software; you can redistribute it and/or modify it under the
6 terms of the GNU General Public License as published by the Free Software
7 Foundation; either version 3, or (at your option) any later version.
8
9 GNUnet is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License along with
14 GNUnet; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/>
15*/
16/**
17 * @file sq/sq_exec.c
18 * @brief helper functions for executing SQL statements
19 * @author Christian Grothoff
20 */
21#include "platform.h"
22#include "gnunet_sq_lib.h"
23
24
25/**
26 * Create a `struct GNUNET_SQ_ExecuteStatement` where errors are fatal.
27 *
28 * @param sql actual SQL statement
29 * @return initialized struct
30 */
31struct GNUNET_SQ_ExecuteStatement
32GNUNET_SQ_make_execute (const char *sql)
33 {
34 struct GNUNET_SQ_ExecuteStatement es = {
35 .sql = sql,
36 .ignore_errors = GNUNET_NO
37 };
38
39 return es;
40}
41
42
43
44/**
45 * Create a `struct GNUNET_SQ_ExecuteStatement` where errors should
46 * be tolerated.
47 *
48 * @param sql actual SQL statement
49 * @return initialized struct
50 */
51struct GNUNET_SQ_ExecuteStatement
52GNUNET_SQ_make_try_execute (const char *sql)
53{
54 struct GNUNET_SQ_ExecuteStatement es = {
55 .sql = sql,
56 .ignore_errors = GNUNET_YES
57 };
58
59 return es;
60}
61
62
63/**
64 * Request execution of an array of statements @a es from Postgres.
65 *
66 * @param dbh database to execute the statements over
67 * @param es #GNUNET_PQ_PREPARED_STATEMENT_END-terminated array of prepared
68 * statements.
69 * @return #GNUNET_OK on success (modulo statements where errors can be ignored)
70 * #GNUNET_SYSERR on error
71 */
72int
73GNUNET_SQ_exec_statements (sqlite3 *dbh,
74 const struct GNUNET_SQ_ExecuteStatement *es)
75{
76 for (unsigned int i=0;NULL != es[i].sql;i++)
77 {
78 char *emsg = NULL;
79
80 if (SQLITE_OK !=
81 sqlite3_exec (dbh,
82 es[i].sql,
83 NULL,
84 NULL,
85 &emsg))
86 {
87 if (es[i].ignore_errors)
88 {
89 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
90 "Failed to run SQL `%s': %s\n",
91 es[i].sql,
92 emsg);
93 }
94 else
95 {
96 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
97 "Failed to run SQL `%s': %s\n",
98 es[i].sql,
99 emsg);
100 sqlite3_free (emsg);
101 return GNUNET_SYSERR;
102 }
103 sqlite3_free (emsg);
104 }
105 }
106 return GNUNET_OK;
107}
108
109/* end of sq_exec */
diff --git a/src/sq/sq_prepare.c b/src/sq/sq_prepare.c
new file mode 100644
index 000000000..db1047c75
--- /dev/null
+++ b/src/sq/sq_prepare.c
@@ -0,0 +1,81 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2018 GNUnet e.V.
4
5 GNUnet is free software; you can redistribute it and/or modify it under the
6 terms of the GNU General Public License as published by the Free Software
7 Foundation; either version 3, or (at your option) any later version.
8
9 GNUnet is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License along with
14 GNUnet; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/>
15*/
16/**
17 * @file sq/sq_prepare.c
18 * @brief helper functions for executing SQL statements
19 * @author Christian Grothoff
20 */
21#include "platform.h"
22#include "gnunet_sq_lib.h"
23
24
25/**
26 * Create a `struct GNUNET_SQ_PrepareStatement`
27 *
28 * @param sql actual SQL statement
29 * @param pstmt where to store the handle
30 * @return initialized struct
31 */
32struct GNUNET_SQ_PrepareStatement
33GNUNET_SQ_make_prepare (const char *sql,
34 sqlite3_stmt **pstmt)
35{
36 struct GNUNET_SQ_PrepareStatement ps = {
37 .sql = sql,
38 .pstmt = pstmt
39 };
40
41 return ps;
42}
43
44
45
46/**
47 * Prepare all statements given in the (NULL,NULL)-terminated
48 * array at @a ps
49 *
50 * @param dbh database to use
51 * @param ps array of statements to prepare
52 * @return #GNUNET_OK on success
53 */
54int
55GNUNET_SQ_prepare (sqlite3 *dbh,
56 const struct GNUNET_SQ_PrepareStatement *ps)
57{
58 for (unsigned int i=0;NULL != ps[i].sql;i++)
59 {
60 const char *epos = NULL;
61 int ret;
62
63 if (SQLITE_OK !=
64 (ret = sqlite3_prepare_v2 (dbh,
65 ps[i].sql,
66 strlen (ps[i].sql),
67 ps[i].pstmt,
68 &epos)))
69 {
70 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
71 "Failed to prepare SQL `%s': error %d at %s\n",
72 ps[i].sql,
73 ret,
74 epos);
75 return GNUNET_SYSERR;
76 }
77 }
78 return GNUNET_OK;
79}
80
81/* end of sq_prepare.c */
diff --git a/src/statistics/test_gnunet_statistics.py.in b/src/statistics/test_gnunet_statistics.py.in
index 8f6966b6f..96714cf9a 100644
--- a/src/statistics/test_gnunet_statistics.py.in
+++ b/src/statistics/test_gnunet_statistics.py.in
@@ -8,10 +8,10 @@ import subprocess
8import time 8import time
9 9
10if os.name == "nt": 10if os.name == "nt":
11 tmp = os.getenv ("TEMP") 11 tmp = os.getenv ("TEMP")
12elif os.environ["TMPDIR"]: 12elif None != os.environ.get("TMPDIR"):
13 tmp = os.getenv("TMPDIR") 13 tmp = os.getenv("TMPDIR")
14elif os.environ["TMP"]: 14elif None != os.environ.get("TMP"):
15 tmp = os.getenv("TMP") 15 tmp = os.getenv("TMP")
16else: 16else:
17 tmp = "/tmp" 17 tmp = "/tmp"
diff --git a/src/statistics/test_statistics_api_data.conf b/src/statistics/test_statistics_api_data.conf
index 66555291c..9ef8d0673 100644
--- a/src/statistics/test_statistics_api_data.conf
+++ b/src/statistics/test_statistics_api_data.conf
@@ -1,5 +1,5 @@
1@INLINE@ ../../contrib/no_forcestart.conf 1@INLINE@ ../../contrib/no_forcestart.conf
2@INLINE@ ../../contrib/no_autostart_above_core.conf
2 3
3[PATHS] 4[PATHS]
4GNUNET_TEST_HOME = $GNUNET_TMP/test-gnunet-statistics/ 5GNUNET_TEST_HOME = $GNUNET_TMP/test-gnunet-statistics/
5
diff --git a/src/transport/test_plugin_transport.c b/src/transport/test_plugin_transport.c
index acb3911f0..2ef3a0ceb 100644
--- a/src/transport/test_plugin_transport.c
+++ b/src/transport/test_plugin_transport.c
@@ -566,8 +566,10 @@ handle_helper_message (void *cls,
566 * @param c configuration to use 566 * @param c configuration to use
567 */ 567 */
568static void 568static void
569run (void *cls, char * const *args, const char *cfgfile, 569run (void *cls,
570 const struct GNUNET_CONFIGURATION_Handle *c) 570 char * const *args,
571 const char *cfgfile,
572 const struct GNUNET_CONFIGURATION_Handle *c)
571{ 573{
572 char * const *argv = cls; 574 char * const *argv = cls;
573 unsigned long long tneigh; 575 unsigned long long tneigh;
@@ -575,26 +577,32 @@ run (void *cls, char * const *args, const char *cfgfile,
575 char *plugin; 577 char *plugin;
576 char *sep; 578 char *sep;
577 579
578 timeout_endbadly = GNUNET_SCHEDULER_add_delayed (TIMEOUT, end_badly, &ok); 580 timeout_endbadly = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
579 581 &end_badly,
582 &ok);
580 cfg = c; 583 cfg = c;
581 /* parse configuration */ 584 /* parse configuration */
582 if ((GNUNET_OK 585 if ( (GNUNET_OK !=
583 != GNUNET_CONFIGURATION_get_value_number (c, "TRANSPORT", 586 GNUNET_CONFIGURATION_get_value_number (c,
584 "NEIGHBOUR_LIMIT", &tneigh)) 587 "TRANSPORT",
585 || (GNUNET_OK 588 "NEIGHBOUR_LIMIT",
586 != GNUNET_CONFIGURATION_get_value_filename (c, "PEER", "PRIVATE_KEY", 589 &tneigh)) ||
587 &keyfile))) 590 (GNUNET_OK !=
591 GNUNET_CONFIGURATION_get_value_filename (c,
592 "PEER",
593 "PRIVATE_KEY",
594 &keyfile)))
588 { 595 {
589 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 596 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
590 "Transport service is lacking key configuration settings. Exiting.\n"); 597 "Transport service is lacking key configuration settings. Exiting.\n");
591 return; 598 return;
592 } 599 }
593 600
594 if (NULL == (stats = GNUNET_STATISTICS_create ("transport", cfg))) 601 if (NULL == (stats = GNUNET_STATISTICS_create ("transport",
602 cfg)))
595 { 603 {
596 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 604 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
597 "Could not create statistics. Exiting.\n"); 605 "Could not create statistics. Exiting.\n");
598 GNUNET_free(keyfile); 606 GNUNET_free(keyfile);
599 end_badly_now (); 607 end_badly_now ();
600 return; 608 return;
@@ -602,27 +610,33 @@ run (void *cls, char * const *args, const char *cfgfile,
602 610
603 if (GNUNET_OK != GNUNET_DISK_file_test (HOSTKEY_FILE)) 611 if (GNUNET_OK != GNUNET_DISK_file_test (HOSTKEY_FILE))
604 { 612 {
605 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Hostkey `%s' missing. Exiting.\n", 613 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
606 HOSTKEY_FILE); 614 "Hostkey `%s' missing. Exiting.\n",
615 HOSTKEY_FILE);
607 GNUNET_free(keyfile); 616 GNUNET_free(keyfile);
608 end_badly_now (); 617 end_badly_now ();
609 return; 618 return;
610 } 619 }
611 620
612 if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (keyfile)) 621 if (GNUNET_OK !=
622 GNUNET_DISK_directory_create_for_file (keyfile))
613 { 623 {
614 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 624 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
615 "Could not create a directory for hostkey `%s'. Exiting.\n", keyfile); 625 "Could not create a directory for hostkey `%s'. Exiting.\n",
626 keyfile);
616 GNUNET_free(keyfile); 627 GNUNET_free(keyfile);
617 end_badly_now (); 628 end_badly_now ();
618 return; 629 return;
619 } 630 }
620 631
621 if (GNUNET_OK != GNUNET_DISK_file_copy (HOSTKEY_FILE, keyfile)) 632 if (GNUNET_OK !=
633 GNUNET_DISK_file_copy (HOSTKEY_FILE,
634 keyfile))
622 { 635 {
623 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 636 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
624 "Could not copy hostkey `%s' to destination `%s'. Exiting.\n", 637 "Could not copy hostkey `%s' to destination `%s'. Exiting.\n",
625 HOSTKEY_FILE, keyfile); 638 HOSTKEY_FILE,
639 keyfile);
626 GNUNET_free(keyfile); 640 GNUNET_free(keyfile);
627 end_badly_now (); 641 end_badly_now ();
628 return; 642 return;
@@ -730,9 +744,9 @@ run (void *cls, char * const *args, const char *cfgfile,
730 end_badly_now (); 744 end_badly_now ();
731 return; 745 return;
732 } 746 }
733
734} 747}
735 748
749
736/** 750/**
737 * The main function for the test 751 * The main function for the test
738 * 752 *
@@ -741,23 +755,32 @@ run (void *cls, char * const *args, const char *cfgfile,
741 * @return 0 ok, 1 on error 755 * @return 0 ok, 1 on error
742 */ 756 */
743int 757int
744main (int argc, char * const *argv) 758main (int argc,
759 char * const *argv)
745{ 760{
746 static struct GNUNET_GETOPT_CommandLineOption options[] = { 761 static struct GNUNET_GETOPT_CommandLineOption options[] = {
747 GNUNET_GETOPT_OPTION_END }; 762 GNUNET_GETOPT_OPTION_END
763 };
748 int ret; 764 int ret;
749 765 char * const argv_prog[] = {
750 GNUNET_DISK_directory_remove (GNUNET_DISK_mktemp("test-gnunetd-plugin-transport")); 766 "test_plugin_transport",
751 767 "-c",
752 char * const argv_prog[] = { "test_plugin_transport", "-c", 768 "test_plugin_transport_data.conf",
753 "test_plugin_transport_data.conf", NULL }; 769 NULL
754 GNUNET_log_setup ("test-plugin-transport", "WARNING", NULL ); 770 };
771
772 GNUNET_log_setup ("test-plugin-transport",
773 "WARNING",
774 NULL);
775 GNUNET_DISK_purge_cfg_dir ("test_plugin_transport_data.conf",
776 "GNUNET_TEST_HOME");
755 ok = 1; /* set to fail */ 777 ok = 1; /* set to fail */
756 ret = 778 ret =
757 (GNUNET_OK 779 (GNUNET_OK
758 == GNUNET_PROGRAM_run (3, argv_prog, "test-plugin-transport", 780 == GNUNET_PROGRAM_run (3, argv_prog, "test-plugin-transport",
759 "testcase", options, &run, (void *) argv)) ? ok : 1; 781 "testcase", options, &run, (void *) argv)) ? ok : 1;
760 GNUNET_DISK_directory_remove (GNUNET_DISK_mktemp("test-gnunetd-plugin-transport")); 782 GNUNET_DISK_purge_cfg_dir ("test_plugin_transport_data.conf",
783 "GNUNET_TEST_HOME");
761 return ret; 784 return ret;
762} 785}
763 786
diff --git a/src/util/crypto_abe.c b/src/util/crypto_abe.c
index fcaa826ed..a5cdb2823 100644
--- a/src/util/crypto_abe.c
+++ b/src/util/crypto_abe.c
@@ -53,12 +53,14 @@ init_aes( element_t k, int enc,
53 int rc; 53 int rc;
54 int key_len; 54 int key_len;
55 unsigned char* key_buf; 55 unsigned char* key_buf;
56 56
57 key_len = element_length_in_bytes(k) < 33 ? 3 : element_length_in_bytes(k); 57 key_len = element_length_in_bytes(k) < 33 ? 3 : element_length_in_bytes(k);
58 key_buf = (unsigned char*) malloc(key_len); 58 key_buf = (unsigned char*) malloc(key_len);
59 element_to_bytes(key_buf, k); 59 element_to_bytes(key_buf, k);
60 60
61 memcpy (key->aes_key, key_buf, GNUNET_CRYPTO_AES_KEY_LENGTH); 61 GNUNET_memcpy (key->aes_key,
62 key_buf,
63 GNUNET_CRYPTO_AES_KEY_LENGTH);
62 GNUNET_assert (0 == 64 GNUNET_assert (0 ==
63 gcry_cipher_open (handle, GCRY_CIPHER_AES256, 65 gcry_cipher_open (handle, GCRY_CIPHER_AES256,
64 GCRY_CIPHER_MODE_CFB, 0)); 66 GCRY_CIPHER_MODE_CFB, 0));
@@ -123,16 +125,16 @@ aes_128_cbc_decrypt( char* ct,
123 unsigned char iv[16]; 125 unsigned char iv[16];
124 char* tmp; 126 char* tmp;
125 uint32_t len; 127 uint32_t len;
126 128
127 init_aes(k, 1, &handle, &skey, iv); 129 init_aes(k, 1, &handle, &skey, iv);
128 130
129 tmp = GNUNET_malloc (size); 131 tmp = GNUNET_malloc (size);
130 132
131 //AES_cbc_encrypt(ct->data, pt->data, ct->len, &key, iv, AES_DECRYPT); 133 //AES_cbc_encrypt(ct->data, pt->data, ct->len, &key, iv, AES_DECRYPT);
132 GNUNET_assert (0 == gcry_cipher_decrypt (handle, tmp, size, ct, size)); 134 GNUNET_assert (0 == gcry_cipher_decrypt (handle, tmp, size, ct, size));
133 gcry_cipher_close (handle); 135 gcry_cipher_close (handle);
134 /* TODO make less crufty */ 136 /* TODO make less crufty */
135 137
136 /* get real length */ 138 /* get real length */
137 len = 0; 139 len = 0;
138 len = len 140 len = len
@@ -173,7 +175,7 @@ GNUNET_CRYPTO_cpabe_create_key (struct GNUNET_CRYPTO_AbeMasterKey *key,
173 struct GNUNET_CRYPTO_AbeKey *prv_key; 175 struct GNUNET_CRYPTO_AbeKey *prv_key;
174 int size; 176 int size;
175 char *tmp; 177 char *tmp;
176 178
177 prv_key = GNUNET_new (struct GNUNET_CRYPTO_AbeKey); 179 prv_key = GNUNET_new (struct GNUNET_CRYPTO_AbeKey);
178 prv_key->prv = gabe_keygen(key->pub, key->msk, attrs); 180 prv_key->prv = gabe_keygen(key->pub, key->msk, attrs);
179 size = gabe_pub_serialize(key->pub, &tmp); 181 size = gabe_pub_serialize(key->pub, &tmp);
@@ -204,7 +206,7 @@ write_cpabe (void **result,
204{ 206{
205 char *ptr; 207 char *ptr;
206 uint32_t *len; 208 uint32_t *len;
207 209
208 *result = GNUNET_malloc (12 + cph_buf_len + aes_buf_len); 210 *result = GNUNET_malloc (12 + cph_buf_len + aes_buf_len);
209 ptr = *result; 211 ptr = *result;
210 len = (uint32_t*) ptr; 212 len = (uint32_t*) ptr;
@@ -213,12 +215,12 @@ write_cpabe (void **result,
213 len = (uint32_t*) ptr; 215 len = (uint32_t*) ptr;
214 *len = htonl (aes_buf_len); 216 *len = htonl (aes_buf_len);
215 ptr += 4; 217 ptr += 4;
216 memcpy (ptr, aes_buf, aes_buf_len); 218 GNUNET_memcpy (ptr, aes_buf, aes_buf_len);
217 ptr += aes_buf_len; 219 ptr += aes_buf_len;
218 len = (uint32_t*) ptr; 220 len = (uint32_t*) ptr;
219 *len = htonl (cph_buf_len); 221 *len = htonl (cph_buf_len);
220 ptr += 4; 222 ptr += 4;
221 memcpy (ptr, cph_buf, cph_buf_len); 223 GNUNET_memcpy (ptr, cph_buf, cph_buf_len);
222 return 12 + cph_buf_len + aes_buf_len; 224 return 12 + cph_buf_len + aes_buf_len;
223} 225}
224 226
@@ -241,13 +243,13 @@ read_cpabe (const void *data,
241 *aes_buf_len = ntohl (*len); 243 *aes_buf_len = ntohl (*len);
242 ptr += 4; 244 ptr += 4;
243 *aes_buf = GNUNET_malloc (*aes_buf_len); 245 *aes_buf = GNUNET_malloc (*aes_buf_len);
244 memcpy(*aes_buf, ptr, *aes_buf_len); 246 GNUNET_memcpy (*aes_buf, ptr, *aes_buf_len);
245 ptr += *aes_buf_len; 247 ptr += *aes_buf_len;
246 len = (uint32_t*)ptr; 248 len = (uint32_t*)ptr;
247 *cph_buf_len = ntohl (*len); 249 *cph_buf_len = ntohl (*len);
248 ptr += 4; 250 ptr += 4;
249 *cph_buf = GNUNET_malloc (*cph_buf_len); 251 *cph_buf = GNUNET_malloc (*cph_buf_len);
250 memcpy(*cph_buf, ptr, *cph_buf_len); 252 GNUNET_memcpy (*cph_buf, ptr, *cph_buf_len);
251 253
252 return buf_len; 254 return buf_len;
253} 255}
@@ -362,7 +364,7 @@ GNUNET_CRYPTO_cpabe_deserialize_key (const void *data,
362 &prv_len); 364 &prv_len);
363 key->pub = gabe_pub_unserialize (pub, pub_len); 365 key->pub = gabe_pub_unserialize (pub, pub_len);
364 key->prv = gabe_prv_unserialize (key->pub, prv, prv_len); 366 key->prv = gabe_prv_unserialize (key->pub, prv, prv_len);
365 367
366 GNUNET_free (pub); 368 GNUNET_free (pub);
367 GNUNET_free (prv); 369 GNUNET_free (prv);
368 return key; 370 return key;
@@ -408,7 +410,7 @@ GNUNET_CRYPTO_cpabe_deserialize_master_key (const void *data,
408 &msk_len); 410 &msk_len);
409 key->pub = gabe_pub_unserialize (pub, pub_len); 411 key->pub = gabe_pub_unserialize (pub, pub_len);
410 key->msk = gabe_msk_unserialize (key->pub, msk, msk_len); 412 key->msk = gabe_msk_unserialize (key->pub, msk, msk_len);
411 413
412 GNUNET_free (pub); 414 GNUNET_free (pub);
413 GNUNET_free (msk); 415 GNUNET_free (msk);
414 416
diff --git a/src/util/disk.c b/src/util/disk.c
index 8fd689070..9e542a91c 100644
--- a/src/util/disk.c
+++ b/src/util/disk.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2001--2013, 2016 GNUnet e.V. 3 Copyright (C) 2001--2013, 2016, 2018 GNUnet e.V.
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -1401,13 +1401,28 @@ GNUNET_DISK_file_copy (const char *src,
1401 struct GNUNET_DISK_FileHandle *in; 1401 struct GNUNET_DISK_FileHandle *in;
1402 struct GNUNET_DISK_FileHandle *out; 1402 struct GNUNET_DISK_FileHandle *out;
1403 1403
1404 if (GNUNET_OK != GNUNET_DISK_file_size (src, &size, GNUNET_YES, GNUNET_YES)) 1404 if (GNUNET_OK !=
1405 GNUNET_DISK_file_size (src,
1406 &size,
1407 GNUNET_YES,
1408 GNUNET_YES))
1409 {
1410 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
1411 "stat",
1412 src);
1405 return GNUNET_SYSERR; 1413 return GNUNET_SYSERR;
1414 }
1406 pos = 0; 1415 pos = 0;
1407 in = GNUNET_DISK_file_open (src, GNUNET_DISK_OPEN_READ, 1416 in = GNUNET_DISK_file_open (src,
1417 GNUNET_DISK_OPEN_READ,
1408 GNUNET_DISK_PERM_NONE); 1418 GNUNET_DISK_PERM_NONE);
1409 if (!in) 1419 if (! in)
1420 {
1421 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
1422 "open",
1423 src);
1410 return GNUNET_SYSERR; 1424 return GNUNET_SYSERR;
1425 }
1411 out = 1426 out =
1412 GNUNET_DISK_file_open (dst, 1427 GNUNET_DISK_file_open (dst,
1413 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE | 1428 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE |
@@ -1418,6 +1433,9 @@ GNUNET_DISK_file_copy (const char *src,
1418 GNUNET_DISK_PERM_GROUP_WRITE); 1433 GNUNET_DISK_PERM_GROUP_WRITE);
1419 if (!out) 1434 if (!out)
1420 { 1435 {
1436 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
1437 "open",
1438 dst);
1421 GNUNET_DISK_file_close (in); 1439 GNUNET_DISK_file_close (in);
1422 return GNUNET_SYSERR; 1440 return GNUNET_SYSERR;
1423 } 1441 }
@@ -2641,4 +2659,55 @@ GNUNET_DISK_internal_file_handle_ (const struct GNUNET_DISK_FileHandle *fh,
2641 return GNUNET_OK; 2659 return GNUNET_OK;
2642} 2660}
2643 2661
2662
2663/**
2664 * Remove the directory given under @a option in
2665 * section [PATHS] in configuration under @a cfg_filename
2666 *
2667 * @param cfg_filename configuration file to parse
2668 * @param option option with the dir name to purge
2669 */
2670void
2671GNUNET_DISK_purge_cfg_dir (const char *cfg_filename,
2672 const char *option)
2673{
2674 struct GNUNET_CONFIGURATION_Handle *cfg;
2675 char *tmpname;
2676
2677 cfg = GNUNET_CONFIGURATION_create ();
2678 if (GNUNET_OK !=
2679 GNUNET_CONFIGURATION_load (cfg,
2680 cfg_filename))
2681 {
2682 GNUNET_break (0);
2683 GNUNET_CONFIGURATION_destroy (cfg);
2684 return;
2685 }
2686 if (GNUNET_OK !=
2687 GNUNET_CONFIGURATION_get_value_filename (cfg,
2688 "PATHS",
2689 option,
2690 &tmpname))
2691 {
2692 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
2693 "PATHS",
2694 option);
2695 GNUNET_CONFIGURATION_destroy (cfg);
2696 return;
2697 }
2698 GNUNET_CONFIGURATION_destroy (cfg);
2699 if (GNUNET_SYSERR ==
2700 GNUNET_DISK_directory_remove (tmpname))
2701 {
2702 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
2703 "remove",
2704 tmpname);
2705 GNUNET_free (tmpname);
2706 return;
2707 }
2708 GNUNET_free (tmpname);
2709}
2710
2711
2712
2644/* end of disk.c */ 2713/* end of disk.c */
diff --git a/src/zonemaster/.gitignore b/src/zonemaster/.gitignore
index 1a0e22b66..cde57fa0a 100644
--- a/src/zonemaster/.gitignore
+++ b/src/zonemaster/.gitignore
@@ -1 +1,2 @@
1gnunet-service-zonemaster 1gnunet-service-zonemaster
2gnunet-service-zonemaster-monitor
diff --git a/src/zonemaster/Makefile.am b/src/zonemaster/Makefile.am
index 21f986498..b655b9ef3 100644
--- a/src/zonemaster/Makefile.am
+++ b/src/zonemaster/Makefile.am
@@ -1,5 +1,5 @@
1# This Makefile.am is in the public domain 1# This Makefile.am is in the public domain
2AM_CPPFLAGS = -I$(top_srcdir)/src/include 2AM_CPPFLAGS = -I$(top_srcdir)/src/include
3 3
4plugindir = $(libdir)/gnunet 4plugindir = $(libdir)/gnunet
5 5
@@ -20,11 +20,11 @@ if USE_COVERAGE
20endif 20endif
21 21
22libexec_PROGRAMS = \ 22libexec_PROGRAMS = \
23 gnunet-service-zonemaster 23 gnunet-service-zonemaster \
24 gnunet-service-zonemaster-monitor
24 25
25gnunet_service_zonemaster_SOURCES = \ 26gnunet_service_zonemaster_SOURCES = \
26 gnunet-service-zonemaster.c 27 gnunet-service-zonemaster.c
27
28gnunet_service_zonemaster_LDADD = \ 28gnunet_service_zonemaster_LDADD = \
29 $(top_builddir)/src/dht/libgnunetdht.la \ 29 $(top_builddir)/src/dht/libgnunetdht.la \
30 $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ 30 $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \
@@ -33,3 +33,14 @@ gnunet_service_zonemaster_LDADD = \
33 $(top_builddir)/src/namestore/libgnunetnamestore.la \ 33 $(top_builddir)/src/namestore/libgnunetnamestore.la \
34 $(GN_LIBINTL) 34 $(GN_LIBINTL)
35 35
36
37gnunet_service_zonemaster_monitor_SOURCES = \
38 gnunet-service-zonemaster-monitor.c
39
40gnunet_service_zonemaster_monitor_LDADD = \
41 $(top_builddir)/src/dht/libgnunetdht.la \
42 $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \
43 $(top_builddir)/src/statistics/libgnunetstatistics.la \
44 $(top_builddir)/src/util/libgnunetutil.la \
45 $(top_builddir)/src/namestore/libgnunetnamestore.la \
46 $(GN_LIBINTL)
diff --git a/src/zonemaster/gnunet-service-zonemaster-monitor.c b/src/zonemaster/gnunet-service-zonemaster-monitor.c
new file mode 100644
index 000000000..275a3a593
--- /dev/null
+++ b/src/zonemaster/gnunet-service-zonemaster-monitor.c
@@ -0,0 +1,479 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2012, 2013, 2014, 2017, 2018 GNUnet e.V.
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/
20
21/**
22 * @file zonemaster/gnunet-service-zonemaster-monitor.c
23 * @brief monitor namestore changes and publish them immediately to GNUnet name system
24 * @author Christian Grothoff
25 */
26#include "platform.h"
27#include "gnunet_util_lib.h"
28#include "gnunet_dht_service.h"
29#include "gnunet_namestore_service.h"
30#include "gnunet_statistics_service.h"
31
32
33#define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file (kind, "util", syscall, filename)
34
35
36/**
37 * How often should we (re)publish each record before
38 * it expires?
39 */
40#define PUBLISH_OPS_PER_EXPIRATION 4
41
42/**
43 * How many pending DHT operations do we allow at most?
44 */
45#define DHT_QUEUE_LIMIT 2000
46
47/**
48 * How many events may the namestore give us before it has to wait
49 * for us to keep up?
50 */
51#define NAMESTORE_QUEUE_LIMIT 5
52
53/**
54 * What replication level do we use for DHT PUT operations?
55 */
56#define DHT_GNS_REPLICATION_LEVEL 5
57
58
59/**
60 * Handle for DHT PUT activity triggered from the namestore monitor.
61 */
62struct DhtPutActivity
63{
64 /**
65 * Kept in a DLL.
66 */
67 struct DhtPutActivity *next;
68
69 /**
70 * Kept in a DLL.
71 */
72 struct DhtPutActivity *prev;
73
74 /**
75 * Handle for the DHT PUT operation.
76 */
77 struct GNUNET_DHT_PutHandle *ph;
78
79 /**
80 * When was this PUT initiated?
81 */
82 struct GNUNET_TIME_Absolute start_date;
83};
84
85
86/**
87 * Handle to the statistics service
88 */
89static struct GNUNET_STATISTICS_Handle *statistics;
90
91/**
92 * Our handle to the DHT
93 */
94static struct GNUNET_DHT_Handle *dht_handle;
95
96/**
97 * Our handle to the namestore service
98 */
99static struct GNUNET_NAMESTORE_Handle *namestore_handle;
100
101/**
102 * Handle to monitor namestore changes to instant propagation.
103 */
104static struct GNUNET_NAMESTORE_ZoneMonitor *zmon;
105
106/**
107 * Head of monitor activities; kept in a DLL.
108 */
109static struct DhtPutActivity *ma_head;
110
111/**
112 * Tail of monitor activities; kept in a DLL.
113 */
114static struct DhtPutActivity *ma_tail;
115
116/**
117 * Number of entries in the DHT queue #ma_head.
118 */
119static unsigned int ma_queue_length;
120
121/**
122 * Optimize block insertion by caching map of private keys to
123 * public keys in memory?
124 */
125static int cache_keys;
126
127
128/**
129 * Task run during shutdown.
130 *
131 * @param cls unused
132 * @param tc unused
133 */
134static void
135shutdown_task (void *cls)
136{
137 struct DhtPutActivity *ma;
138
139 (void) cls;
140 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
141 "Shutting down!\n");
142 while (NULL != (ma = ma_head))
143 {
144 GNUNET_DHT_put_cancel (ma->ph);
145 ma_queue_length--;
146 GNUNET_CONTAINER_DLL_remove (ma_head,
147 ma_tail,
148 ma);
149 GNUNET_free (ma);
150 }
151 if (NULL != statistics)
152 {
153 GNUNET_STATISTICS_destroy (statistics,
154 GNUNET_NO);
155 statistics = NULL;
156 }
157 if (NULL != zmon)
158 {
159 GNUNET_NAMESTORE_zone_monitor_stop (zmon);
160 zmon = NULL;
161 }
162 if (NULL != namestore_handle)
163 {
164 GNUNET_NAMESTORE_disconnect (namestore_handle);
165 namestore_handle = NULL;
166 }
167 if (NULL != dht_handle)
168 {
169 GNUNET_DHT_disconnect (dht_handle);
170 dht_handle = NULL;
171 }
172}
173
174
175/**
176 * Continuation called from DHT once the PUT operation triggered
177 * by a monitor is done.
178 *
179 * @param cls a `struct DhtPutActivity`
180 */
181static void
182dht_put_monitor_continuation (void *cls)
183{
184 struct DhtPutActivity *ma = cls;
185
186 GNUNET_NAMESTORE_zone_monitor_next (zmon,
187 1);
188 ma_queue_length--;
189 GNUNET_CONTAINER_DLL_remove (ma_head,
190 ma_tail,
191 ma);
192 GNUNET_free (ma);
193}
194
195
196/**
197 * Convert namestore records from the internal format to that
198 * suitable for publication (removes private records, converts
199 * to absolute expiration time).
200 *
201 * @param rd input records
202 * @param rd_count size of the @a rd and @a rd_public arrays
203 * @param rd_public where to write the converted records
204 * @return number of records written to @a rd_public
205 */
206static unsigned int
207convert_records_for_export (const struct GNUNET_GNSRECORD_Data *rd,
208 unsigned int rd_count,
209 struct GNUNET_GNSRECORD_Data *rd_public)
210{
211 struct GNUNET_TIME_Absolute now;
212 unsigned int rd_public_count;
213
214 rd_public_count = 0;
215 now = GNUNET_TIME_absolute_get ();
216 for (unsigned int i=0;i<rd_count;i++)
217 {
218 if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_PRIVATE))
219 continue;
220 if ( (0 == (rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION)) &&
221 (rd[i].expiration_time < now.abs_value_us) )
222 continue; /* record already expired, skip it */
223 rd_public[rd_public_count++] = rd[i];
224 }
225 return rd_public_count;
226}
227
228
229/**
230 * Store GNS records in the DHT.
231 *
232 * @param key key of the zone
233 * @param label label to store under
234 * @param rd_public public record data
235 * @param rd_public_count number of records in @a rd_public
236 * @param ma handle for the PUT operation
237 * @return DHT PUT handle, NULL on error
238 */
239static struct GNUNET_DHT_PutHandle *
240perform_dht_put (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
241 const char *label,
242 const struct GNUNET_GNSRECORD_Data *rd_public,
243 unsigned int rd_public_count,
244 struct DhtPutActivity *ma)
245{
246 struct GNUNET_GNSRECORD_Block *block;
247 struct GNUNET_HashCode query;
248 struct GNUNET_TIME_Absolute expire;
249 size_t block_size;
250 struct GNUNET_DHT_PutHandle *ret;
251
252 expire = GNUNET_GNSRECORD_record_get_expiration_time (rd_public_count,
253 rd_public);
254 if (cache_keys)
255 block = GNUNET_GNSRECORD_block_create2 (key,
256 expire,
257 label,
258 rd_public,
259 rd_public_count);
260 else
261 block = GNUNET_GNSRECORD_block_create (key,
262 expire,
263 label,
264 rd_public,
265 rd_public_count);
266 if (NULL == block)
267 {
268 GNUNET_break (0);
269 return NULL; /* whoops */
270 }
271 block_size = ntohl (block->purpose.size)
272 + sizeof (struct GNUNET_CRYPTO_EcdsaSignature)
273 + sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey);
274 GNUNET_GNSRECORD_query_from_private_key (key,
275 label,
276 &query);
277 GNUNET_STATISTICS_update (statistics,
278 "DHT put operations initiated",
279 1,
280 GNUNET_NO);
281 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
282 "Storing %u record(s) for label `%s' in DHT with expiration `%s' under key %s\n",
283 rd_public_count,
284 label,
285 GNUNET_STRINGS_absolute_time_to_string (expire),
286 GNUNET_h2s (&query));
287 ret = GNUNET_DHT_put (dht_handle,
288 &query,
289 DHT_GNS_REPLICATION_LEVEL,
290 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
291 GNUNET_BLOCK_TYPE_GNS_NAMERECORD,
292 block_size,
293 block,
294 expire,
295 &dht_put_monitor_continuation,
296 ma);
297 GNUNET_free (block);
298 return ret;
299}
300
301
302/**
303 * Process a record that was stored in the namestore
304 * (invoked by the monitor).
305 *
306 * @param cls closure, NULL
307 * @param zone private key of the zone; NULL on disconnect
308 * @param label label of the records; NULL on disconnect
309 * @param rd_count number of entries in @a rd array, 0 if label was deleted
310 * @param rd array of records with data to store
311 */
312static void
313handle_monitor_event (void *cls,
314 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
315 const char *label,
316 unsigned int rd_count,
317 const struct GNUNET_GNSRECORD_Data *rd)
318{
319 struct GNUNET_GNSRECORD_Data rd_public[rd_count];
320 unsigned int rd_public_count;
321 struct DhtPutActivity *ma;
322
323 (void) cls;
324 GNUNET_STATISTICS_update (statistics,
325 "Namestore monitor events received",
326 1,
327 GNUNET_NO);
328 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
329 "Received %u records for label `%s' via namestore monitor\n",
330 rd_count,
331 label);
332 /* filter out records that are not public, and convert to
333 absolute expiration time. */
334 rd_public_count = convert_records_for_export (rd,
335 rd_count,
336 rd_public);
337 if (0 == rd_public_count)
338 {
339 GNUNET_NAMESTORE_zone_monitor_next (zmon,
340 1);
341 return; /* nothing to do */
342 }
343 ma = GNUNET_new (struct DhtPutActivity);
344 ma->start_date = GNUNET_TIME_absolute_get ();
345 ma->ph = perform_dht_put (zone,
346 label,
347 rd,
348 rd_count,
349 ma);
350 if (NULL == ma->ph)
351 {
352 /* PUT failed, do not remember operation */
353 GNUNET_free (ma);
354 GNUNET_NAMESTORE_zone_monitor_next (zmon,
355 1);
356 return;
357 }
358 GNUNET_CONTAINER_DLL_insert_tail (ma_head,
359 ma_tail,
360 ma);
361 ma_queue_length++;
362 if (ma_queue_length > DHT_QUEUE_LIMIT)
363 {
364 ma = ma_head;
365 GNUNET_CONTAINER_DLL_remove (ma_head,
366 ma_tail,
367 ma);
368 GNUNET_DHT_put_cancel (ma->ph);
369 ma_queue_length--;
370 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
371 "DHT PUT unconfirmed after %s, aborting PUT\n",
372 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (ma->start_date),
373 GNUNET_YES));
374 GNUNET_free (ma);
375 }
376}
377
378
379/**
380 * The zone monitor encountered an IPC error trying to to get in
381 * sync. Restart from the beginning.
382 *
383 * @param cls NULL
384 */
385static void
386handle_monitor_error (void *cls)
387{
388 (void) cls;
389 GNUNET_STATISTICS_update (statistics,
390 "Namestore monitor errors encountered",
391 1,
392 GNUNET_NO);
393}
394
395
396/**
397 * Performe zonemaster duties: watch namestore, publish records.
398 *
399 * @param cls closure
400 * @param server the initialized server
401 * @param c configuration to use
402 */
403static void
404run (void *cls,
405 const struct GNUNET_CONFIGURATION_Handle *c,
406 struct GNUNET_SERVICE_Handle *service)
407{
408 unsigned long long max_parallel_bg_queries = 128;
409
410 (void) cls;
411 (void) service;
412 namestore_handle = GNUNET_NAMESTORE_connect (c);
413 if (NULL == namestore_handle)
414 {
415 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
416 _("Failed to connect to the namestore!\n"));
417 GNUNET_SCHEDULER_shutdown ();
418 return;
419 }
420 cache_keys = GNUNET_CONFIGURATION_get_value_yesno (c,
421 "namestore",
422 "CACHE_KEYS");
423 if (GNUNET_OK ==
424 GNUNET_CONFIGURATION_get_value_number (c,
425 "zonemaster",
426 "MAX_PARALLEL_BACKGROUND_QUERIES",
427 &max_parallel_bg_queries))
428 {
429 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
430 "Number of allowed parallel background queries: %llu\n",
431 max_parallel_bg_queries);
432 }
433 if (0 == max_parallel_bg_queries)
434 max_parallel_bg_queries = 1;
435 dht_handle = GNUNET_DHT_connect (c,
436 (unsigned int) max_parallel_bg_queries);
437 if (NULL == dht_handle)
438 {
439 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
440 _("Could not connect to DHT!\n"));
441 GNUNET_SCHEDULER_add_now (&shutdown_task,
442 NULL);
443 return;
444 }
445
446 /* Schedule periodic put for our records. */
447 statistics = GNUNET_STATISTICS_create ("zonemaster-mon",
448 c);
449 zmon = GNUNET_NAMESTORE_zone_monitor_start (c,
450 NULL,
451 GNUNET_NO,
452 &handle_monitor_error,
453 NULL,
454 &handle_monitor_event,
455 NULL,
456 NULL /* sync_cb */,
457 NULL);
458 GNUNET_NAMESTORE_zone_monitor_next (zmon,
459 NAMESTORE_QUEUE_LIMIT - 1);
460 GNUNET_break (NULL != zmon);
461 GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
462 NULL);
463}
464
465
466/**
467 * Define "main" method using service macro.
468 */
469GNUNET_SERVICE_MAIN
470("zonemaster-monitor",
471 GNUNET_SERVICE_OPTION_NONE,
472 &run,
473 NULL,
474 NULL,
475 NULL,
476 GNUNET_MQ_handler_end());
477
478
479/* end of gnunet-service-zonemaster-monitor.c */
diff --git a/src/zonemaster/gnunet-service-zonemaster.c b/src/zonemaster/gnunet-service-zonemaster.c
index 8220e6eab..81d6fa2d9 100644
--- a/src/zonemaster/gnunet-service-zonemaster.c
+++ b/src/zonemaster/gnunet-service-zonemaster.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2012, 2013, 2014, 2017 GNUnet e.V. 3 Copyright (C) 2012, 2013, 2014, 2017, 2018 GNUnet e.V.
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -29,8 +29,6 @@
29#include "gnunet_dht_service.h" 29#include "gnunet_dht_service.h"
30#include "gnunet_namestore_service.h" 30#include "gnunet_namestore_service.h"
31#include "gnunet_statistics_service.h" 31#include "gnunet_statistics_service.h"
32#include "gnunet_namestore_plugin.h"
33#include "gnunet_signatures.h"
34 32
35 33
36#define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file (kind, "util", syscall, filename) 34#define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file (kind, "util", syscall, filename)
@@ -78,23 +76,12 @@
78#define MAXIMUM_ZONE_ITERATION_INTERVAL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) 76#define MAXIMUM_ZONE_ITERATION_INTERVAL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)
79 77
80/** 78/**
81 * The default put interval for the zone iteration. In case
82 * no option is found
83 */
84#define DEFAULT_ZONE_PUBLISH_TIME_WINDOW GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 4)
85
86/**
87 * The factor the current zone iteration interval is divided by for each 79 * The factor the current zone iteration interval is divided by for each
88 * additional new record 80 * additional new record
89 */ 81 */
90#define LATE_ITERATION_SPEEDUP_FACTOR 2 82#define LATE_ITERATION_SPEEDUP_FACTOR 2
91 83
92/** 84/**
93 * How long until a DHT PUT attempt should time out?
94 */
95#define DHT_OPERATION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
96
97/**
98 * What replication level do we use for DHT PUT operations? 85 * What replication level do we use for DHT PUT operations?
99 */ 86 */
100#define DHT_GNS_REPLICATION_LEVEL 5 87#define DHT_GNS_REPLICATION_LEVEL 5
@@ -148,21 +135,6 @@ static struct GNUNET_NAMESTORE_Handle *namestore_handle;
148static struct GNUNET_NAMESTORE_ZoneIterator *namestore_iter; 135static struct GNUNET_NAMESTORE_ZoneIterator *namestore_iter;
149 136
150/** 137/**
151 * Handle to monitor namestore changes to instant propagation.
152 */
153static struct GNUNET_NAMESTORE_ZoneMonitor *zmon;
154
155/**
156 * Head of monitor activities; kept in a DLL.
157 */
158static struct DhtPutActivity *ma_head;
159
160/**
161 * Tail of monitor activities; kept in a DLL.
162 */
163static struct DhtPutActivity *ma_tail;
164
165/**
166 * Head of iteration put activities; kept in a DLL. 138 * Head of iteration put activities; kept in a DLL.
167 */ 139 */
168static struct DhtPutActivity *it_head; 140static struct DhtPutActivity *it_head;
@@ -178,11 +150,6 @@ static struct DhtPutActivity *it_tail;
178static unsigned int dht_queue_length; 150static unsigned int dht_queue_length;
179 151
180/** 152/**
181 * Number of entries in the DHT queue #ma_head.
182 */
183static unsigned int ma_queue_length;
184
185/**
186 * Useful for zone update for DHT put 153 * Useful for zone update for DHT put
187 */ 154 */
188static unsigned long long num_public_records; 155static unsigned long long num_public_records;
@@ -281,15 +248,6 @@ shutdown_task (void *cls)
281 (void) cls; 248 (void) cls;
282 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 249 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
283 "Shutting down!\n"); 250 "Shutting down!\n");
284 while (NULL != (ma = ma_head))
285 {
286 GNUNET_DHT_put_cancel (ma->ph);
287 ma_queue_length--;
288 GNUNET_CONTAINER_DLL_remove (ma_head,
289 ma_tail,
290 ma);
291 GNUNET_free (ma);
292 }
293 while (NULL != (ma = it_head)) 251 while (NULL != (ma = it_head))
294 { 252 {
295 GNUNET_DHT_put_cancel (ma->ph); 253 GNUNET_DHT_put_cancel (ma->ph);
@@ -316,11 +274,6 @@ shutdown_task (void *cls)
316 GNUNET_NAMESTORE_zone_iteration_stop (namestore_iter); 274 GNUNET_NAMESTORE_zone_iteration_stop (namestore_iter);
317 namestore_iter = NULL; 275 namestore_iter = NULL;
318 } 276 }
319 if (NULL != zmon)
320 {
321 GNUNET_NAMESTORE_zone_monitor_stop (zmon);
322 zmon = NULL;
323 }
324 if (NULL != namestore_handle) 277 if (NULL != namestore_handle)
325 { 278 {
326 GNUNET_NAMESTORE_disconnect (namestore_handle); 279 GNUNET_NAMESTORE_disconnect (namestore_handle);
@@ -362,27 +315,6 @@ publish_zone_dht_start (void *cls);
362 315
363 316
364/** 317/**
365 * Continuation called from DHT once the PUT operation triggered
366 * by a monitor is done.
367 *
368 * @param cls a `struct DhtPutActivity`
369 */
370static void
371dht_put_monitor_continuation (void *cls)
372{
373 struct DhtPutActivity *ma = cls;
374
375 GNUNET_NAMESTORE_zone_monitor_next (zmon,
376 1);
377 ma_queue_length--;
378 GNUNET_CONTAINER_DLL_remove (ma_head,
379 ma_tail,
380 ma);
381 GNUNET_free (ma);
382}
383
384
385/**
386 * Calculate #target_iteration_velocity_per_record. 318 * Calculate #target_iteration_velocity_per_record.
387 */ 319 */
388static void 320static void
@@ -521,10 +453,6 @@ update_velocity (unsigned int cnt)
521 dht_queue_length, 453 dht_queue_length,
522 GNUNET_NO); 454 GNUNET_NO);
523 GNUNET_STATISTICS_set (statistics, 455 GNUNET_STATISTICS_set (statistics,
524 "# size of the DHT queue (mon)",
525 ma_queue_length,
526 GNUNET_NO);
527 GNUNET_STATISTICS_set (statistics,
528 "% speed increase needed for target velocity", 456 "% speed increase needed for target velocity",
529 pct, 457 pct,
530 GNUNET_NO); 458 GNUNET_NO);
@@ -558,6 +486,12 @@ check_zone_namestore_next ()
558 GNUNET_NO); 486 GNUNET_NO);
559 delay = GNUNET_TIME_relative_multiply (delay, 487 delay = GNUNET_TIME_relative_multiply (delay,
560 NS_BLOCK_SIZE); 488 NS_BLOCK_SIZE);
489 /* make sure we do not overshoot because of the #NS_BLOCK_SIZE factor */
490 delay = GNUNET_TIME_relative_min (MAXIMUM_ZONE_ITERATION_INTERVAL,
491 delay);
492 /* no delays on first iteration */
493 if (GNUNET_YES == first_zone_iteration)
494 delay = GNUNET_TIME_UNIT_ZERO;
561 GNUNET_assert (NULL == zone_publish_task); 495 GNUNET_assert (NULL == zone_publish_task);
562 zone_publish_task = GNUNET_SCHEDULER_add_delayed (delay, 496 zone_publish_task = GNUNET_SCHEDULER_add_delayed (delay,
563 &publish_zone_namestore_next, 497 &publish_zone_namestore_next,
@@ -606,24 +540,22 @@ convert_records_for_export (const struct GNUNET_GNSRECORD_Data *rd,
606 rd_public_count = 0; 540 rd_public_count = 0;
607 now = GNUNET_TIME_absolute_get (); 541 now = GNUNET_TIME_absolute_get ();
608 for (unsigned int i=0;i<rd_count;i++) 542 for (unsigned int i=0;i<rd_count;i++)
609 if (0 == (rd[i].flags & GNUNET_GNSRECORD_RF_PRIVATE)) 543 {
544 if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_PRIVATE))
545 continue;
546 if ( (0 == (rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION)) &&
547 (rd[i].expiration_time < now.abs_value_us) )
548 continue; /* record already expired, skip it */
549 if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION))
610 { 550 {
611 rd_public[rd_public_count] = rd[i]; 551 /* GNUNET_GNSRECORD_block_create will convert to absolute time;
612 if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION)) 552 we just need to adjust our iteration frequency */
613 { 553 min_relative_record_time.rel_value_us =
614 /* GNUNET_GNSRECORD_block_create will convert to absolute time; 554 GNUNET_MIN (rd[i].expiration_time,
615 we just need to adjust our iteration frequency */ 555 min_relative_record_time.rel_value_us);
616 min_relative_record_time.rel_value_us =
617 GNUNET_MIN (rd_public[rd_public_count].expiration_time,
618 min_relative_record_time.rel_value_us);
619 }
620 else if (rd_public[rd_public_count].expiration_time < now.abs_value_us)
621 {
622 /* record already expired, skip it */
623 continue;
624 }
625 rd_public_count++;
626 } 556 }
557 rd_public[rd_public_count++] = rd[i];
558 }
627 return rd_public_count; 559 return rd_public_count;
628} 560}
629 561
@@ -635,8 +567,7 @@ convert_records_for_export (const struct GNUNET_GNSRECORD_Data *rd,
635 * @param label label to store under 567 * @param label label to store under
636 * @param rd_public public record data 568 * @param rd_public public record data
637 * @param rd_public_count number of records in @a rd_public 569 * @param rd_public_count number of records in @a rd_public
638 * @param cont function to call with PUT result 570 * @param ma handle for the put operation
639 * @param cont_cls closure for @a cont
640 * @return DHT PUT handle, NULL on error 571 * @return DHT PUT handle, NULL on error
641 */ 572 */
642static struct GNUNET_DHT_PutHandle * 573static struct GNUNET_DHT_PutHandle *
@@ -644,8 +575,7 @@ perform_dht_put (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
644 const char *label, 575 const char *label,
645 const struct GNUNET_GNSRECORD_Data *rd_public, 576 const struct GNUNET_GNSRECORD_Data *rd_public,
646 unsigned int rd_public_count, 577 unsigned int rd_public_count,
647 GNUNET_SCHEDULER_TaskCallback cont, 578 struct DhtPutActivity *ma)
648 void *cont_cls)
649{ 579{
650 struct GNUNET_GNSRECORD_Block *block; 580 struct GNUNET_GNSRECORD_Block *block;
651 struct GNUNET_HashCode query; 581 struct GNUNET_HashCode query;
@@ -697,8 +627,8 @@ perform_dht_put (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
697 block_size, 627 block_size,
698 block, 628 block,
699 expire, 629 expire,
700 cont, 630 &dht_put_continuation,
701 cont_cls); 631 ma);
702 GNUNET_free (block); 632 GNUNET_free (block);
703 return ret; 633 return ret;
704} 634}
@@ -746,8 +676,7 @@ zone_iteration_finished (void *cls)
746 calculate_put_interval (); 676 calculate_put_interval ();
747 /* reset for next iteration */ 677 /* reset for next iteration */
748 min_relative_record_time 678 min_relative_record_time
749 = GNUNET_TIME_relative_multiply (GNUNET_DHT_DEFAULT_REPUBLISH_FREQUENCY, 679 = GNUNET_TIME_UNIT_FOREVER_REL;
750 PUBLISH_OPS_PER_EXPIRATION);
751 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 680 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
752 "Zone iteration finished. Adjusted zone iteration interval to %s\n", 681 "Zone iteration finished. Adjusted zone iteration interval to %s\n",
753 GNUNET_STRINGS_relative_time_to_string (target_iteration_velocity_per_record, 682 GNUNET_STRINGS_relative_time_to_string (target_iteration_velocity_per_record,
@@ -816,7 +745,6 @@ put_gns_record (void *cls,
816 label, 745 label,
817 rd_public, 746 rd_public,
818 rd_public_count, 747 rd_public_count,
819 &dht_put_continuation,
820 ma); 748 ma);
821 put_cnt++; 749 put_cnt++;
822 if (0 == put_cnt % DELTA_INTERVAL) 750 if (0 == put_cnt % DELTA_INTERVAL)
@@ -884,131 +812,6 @@ publish_zone_dht_start (void *cls)
884 812
885 813
886/** 814/**
887 * Process a record that was stored in the namestore
888 * (invoked by the monitor).
889 *
890 * @param cls closure, NULL
891 * @param zone private key of the zone; NULL on disconnect
892 * @param label label of the records; NULL on disconnect
893 * @param rd_count number of entries in @a rd array, 0 if label was deleted
894 * @param rd array of records with data to store
895 */
896static void
897handle_monitor_event (void *cls,
898 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
899 const char *label,
900 unsigned int rd_count,
901 const struct GNUNET_GNSRECORD_Data *rd)
902{
903 struct GNUNET_GNSRECORD_Data rd_public[rd_count];
904 unsigned int rd_public_count;
905 struct DhtPutActivity *ma;
906
907 (void) cls;
908 GNUNET_STATISTICS_update (statistics,
909 "Namestore monitor events received",
910 1,
911 GNUNET_NO);
912 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
913 "Received %u records for label `%s' via namestore monitor\n",
914 rd_count,
915 label);
916 /* filter out records that are not public, and convert to
917 absolute expiration time. */
918 rd_public_count = convert_records_for_export (rd,
919 rd_count,
920 rd_public);
921 if (0 == rd_public_count)
922 {
923 GNUNET_NAMESTORE_zone_monitor_next (zmon,
924 1);
925 return; /* nothing to do */
926 }
927 num_public_records++;
928 ma = GNUNET_new (struct DhtPutActivity);
929 ma->start_date = GNUNET_TIME_absolute_get ();
930 ma->ph = perform_dht_put (zone,
931 label,
932 rd,
933 rd_count,
934 &dht_put_monitor_continuation,
935 ma);
936 if (NULL == ma->ph)
937 {
938 /* PUT failed, do not remember operation */
939 GNUNET_free (ma);
940 GNUNET_NAMESTORE_zone_monitor_next (zmon,
941 1);
942 return;
943 }
944 GNUNET_CONTAINER_DLL_insert_tail (ma_head,
945 ma_tail,
946 ma);
947 ma_queue_length++;
948 if (ma_queue_length > DHT_QUEUE_LIMIT)
949 {
950 ma = ma_head;
951 GNUNET_CONTAINER_DLL_remove (ma_head,
952 ma_tail,
953 ma);
954 GNUNET_DHT_put_cancel (ma->ph);
955 ma_queue_length--;
956 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
957 "DHT PUT unconfirmed after %s, aborting PUT\n",
958 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (ma->start_date),
959 GNUNET_YES));
960 GNUNET_free (ma);
961 }
962}
963
964
965/**
966 * The zone monitor is now in SYNC with the current state of the
967 * name store. Start to perform periodic iterations.
968 *
969 * @param cls NULL
970 */
971static void
972monitor_sync_event (void *cls)
973{
974 (void) cls;
975 if ( (NULL == zone_publish_task) &&
976 (NULL == namestore_iter) )
977 zone_publish_task = GNUNET_SCHEDULER_add_now (&publish_zone_dht_start,
978 NULL);
979}
980
981
982/**
983 * The zone monitor encountered an IPC error trying to to get in
984 * sync. Restart from the beginning.
985 *
986 * @param cls NULL
987 */
988static void
989handle_monitor_error (void *cls)
990{
991 (void) cls;
992 GNUNET_STATISTICS_update (statistics,
993 "Namestore monitor errors encountered",
994 1,
995 GNUNET_NO);
996 if (NULL != zone_publish_task)
997 {
998 GNUNET_SCHEDULER_cancel (zone_publish_task);
999 zone_publish_task = NULL;
1000 }
1001 if (NULL != namestore_iter)
1002 {
1003 GNUNET_NAMESTORE_zone_iteration_stop (namestore_iter);
1004 namestore_iter = NULL;
1005 }
1006 zone_publish_task = GNUNET_SCHEDULER_add_now (&publish_zone_dht_start,
1007 NULL);
1008}
1009
1010
1011/**
1012 * Performe zonemaster duties: watch namestore, publish records. 815 * Performe zonemaster duties: watch namestore, publish records.
1013 * 816 *
1014 * @param cls closure 817 * @param cls closure
@@ -1026,8 +829,7 @@ run (void *cls,
1026 (void) service; 829 (void) service;
1027 last_put_100 = GNUNET_TIME_absolute_get (); /* first time! */ 830 last_put_100 = GNUNET_TIME_absolute_get (); /* first time! */
1028 min_relative_record_time 831 min_relative_record_time
1029 = GNUNET_TIME_relative_multiply (GNUNET_DHT_DEFAULT_REPUBLISH_FREQUENCY, 832 = GNUNET_TIME_UNIT_FOREVER_REL;
1030 PUBLISH_OPS_PER_EXPIRATION);
1031 target_iteration_velocity_per_record = INITIAL_ZONE_ITERATION_INTERVAL; 833 target_iteration_velocity_per_record = INITIAL_ZONE_ITERATION_INTERVAL;
1032 namestore_handle = GNUNET_NAMESTORE_connect (c); 834 namestore_handle = GNUNET_NAMESTORE_connect (c);
1033 if (NULL == namestore_handle) 835 if (NULL == namestore_handle)
@@ -1040,7 +842,7 @@ run (void *cls,
1040 cache_keys = GNUNET_CONFIGURATION_get_value_yesno (c, 842 cache_keys = GNUNET_CONFIGURATION_get_value_yesno (c,
1041 "namestore", 843 "namestore",
1042 "CACHE_KEYS"); 844 "CACHE_KEYS");
1043 zone_publish_time_window_default = DEFAULT_ZONE_PUBLISH_TIME_WINDOW; 845 zone_publish_time_window_default = GNUNET_DHT_DEFAULT_REPUBLISH_FREQUENCY;
1044 if (GNUNET_OK == 846 if (GNUNET_OK ==
1045 GNUNET_CONFIGURATION_get_value_time (c, 847 GNUNET_CONFIGURATION_get_value_time (c,
1046 "zonemaster", 848 "zonemaster",
@@ -1084,18 +886,8 @@ run (void *cls,
1084 "Target zone iteration velocity (μs)", 886 "Target zone iteration velocity (μs)",
1085 target_iteration_velocity_per_record.rel_value_us, 887 target_iteration_velocity_per_record.rel_value_us,
1086 GNUNET_NO); 888 GNUNET_NO);
1087 zmon = GNUNET_NAMESTORE_zone_monitor_start (c, 889 zone_publish_task = GNUNET_SCHEDULER_add_now (&publish_zone_dht_start,
1088 NULL, 890 NULL);
1089 GNUNET_NO,
1090 &handle_monitor_error,
1091 NULL,
1092 &handle_monitor_event,
1093 NULL,
1094 &monitor_sync_event,
1095 NULL);
1096 GNUNET_NAMESTORE_zone_monitor_next (zmon,
1097 NAMESTORE_QUEUE_LIMIT - 1);
1098 GNUNET_break (NULL != zmon);
1099 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, 891 GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
1100 NULL); 892 NULL);
1101} 893}
diff --git a/src/zonemaster/zonemaster.conf.in b/src/zonemaster/zonemaster.conf.in
index 871eb9c8f..6179b87be 100644
--- a/src/zonemaster/zonemaster.conf.in
+++ b/src/zonemaster/zonemaster.conf.in
@@ -23,3 +23,20 @@ ZONE_PUBLISH_TIME_WINDOW = 4 h
23# USE_CACHE = YES 23# USE_CACHE = YES
24 24
25# PREFIX = valgrind --leak-check=full --track-origins=yes 25# PREFIX = valgrind --leak-check=full --track-origins=yes
26
27
28
29[zonemaster-monitor]
30AUTOSTART = @AUTOSTART@
31FORCESTART = YES
32HOSTNAME = localhost
33BINARY = gnunet-service-zonemaster-monitor
34UNIXPATH = $GNUNET_USER_RUNTIME_DIR/gnunet-service-zonemaster-monitor.sock
35@JAVAPORT@PORT = 2124
36
37# Do we require users that want to access GNS to run this process
38# (usually not a good idea)
39UNIX_MATCH_UID = NO
40
41# Do we require users that want to access GNS to be in the 'gnunet' group?
42UNIX_MATCH_GID = NO