[sensor]
AUTOSTART = NO
+
+[zonemaster-monitor]
+AUTOSTART = NO
FORCESTART = NO
[zonemaster]
-FORCESTART = NO
\ No newline at end of file
+FORCESTART = NO
+
+[zonemaster-monitor]
+FORCESTART = NO
NOW=`date +%s`
RELAT=$[$NOW-$STARTTIME]
gnunet-statistics | while read KEY VALUE; do
-
+ KEY=`echo $KEY | tr / .`
# Collect stats of previous round
if [ -e "$STATDIR/$KEY.dat" ]; then
PREV=`tail --lines=1 "$STATDIR/$KEY.dat" | sed -e "s/.* //g"`
--- /dev/null
+#!/bin/sh
+# This script is in the public domain.
+# Converts the output of gnunet-zonewalk (DNS resolutions)
+# into a proper input for gnunet-gns-benchmark.
+
+NUM_CLIENTS=3
+# How many different groups of names should we
+# create? 1/N will be in the 'shared' group.
+
+# FILE ($1) contains results from DNS lookup; strip
+# everything but the hostnames, remove duplicates
+# and then randomize the order.
+cat $1 | awk '{print $1}' | sort | uniq | shuf > $1.tmp
+TOTAL=`cat $1.tmp | wc -l`
+GROUP_SIZE=`expr $TOTAL / \( $NUM_TYPES + 1 \)`
+
+# First group (0) is to be shared among all clients
+for i in `seq 1 $NUM_CLIENTS`
+do
+ cat $1.tmp | head -n $GROUP_SIZE | awk "{print 0 \" \" \$1}" > $1.$i.tmp
+done
+
+# Second group (1) is unique per client
+OFF=0
+for i in `seq 1 $NUM_CLIENTS`
+do
+ END=`expr $OFF + $GROUP_SIZE`
+ cat $1.tmp | head -n $END | tail -n $GROUP_SIZE | awk "{print 1 \" \" \$1}" >> $1.$i.tmp
+# Shuffle again, so we mix the different request categories in terms of
+# when we issue the queries.
+ cat $1.$i.tmp | shuf > $1.$i
+ OFF="$END"
+ rm $1.$i.tmp
+done
+rm $1.tmp
struct GNUNET_MessageHeader *msg;
env = GNUNET_MQ_msg_extra (msg, payload_size, GNUNET_MY_MESSAGE_TYPE);
-memcpy (&msg[1], &payload, payload_size);
+GNUNET_memcpy (&msg[1],
+ &payload,
+ payload_size);
// Send message via message queue 'mq'
GNUNET_mq_send (mq, env);
-
.IP "\-h, \-\-help"
Print short help on options.
.B
+.IP "\-m RELATIVETIME, \-\-minimum-expiration=RELATIVETIME"
+.B
+Ensure that imported DNS records never have an expiration time that
+is less than RELATIVETIME into the future. RELATIVETIME is a time
+given like "1 week" or "1 h". If DNS returns records with a shorter
+lifetime, gnunet\-zoneimport will simply bump the lifetime to the
+specified value (relative to the time of the import). Default is zero.
+
.IP "\-s MAPSIZE, \-\-size=MAPSIZE"
Specifies the size (in number of entries) to use for the main hash
map. The value provided should be at least twice the number of domain
int rc;
int key_len;
unsigned char* key_buf;
-
+
key_len = element_length_in_bytes(k) < 33 ? 3 : element_length_in_bytes(k);
key_buf = (unsigned char*) malloc(key_len);
element_to_bytes(key_buf, k);
- memcpy (key->aes_key, key_buf, GNUNET_CRYPTO_AES_KEY_LENGTH);
+ GNUNET_memcpy (key->aes_key, key_buf, GNUNET_CRYPTO_AES_KEY_LENGTH);
GNUNET_assert (0 ==
gcry_cipher_open (handle, GCRY_CIPHER_AES256,
GCRY_CIPHER_MODE_CFB, 0));
unsigned char iv[16];
char* tmp;
uint32_t len;
-
+
init_aes(k, 1, &handle, &skey, iv);
tmp = GNUNET_malloc (size);
//AES_cbc_encrypt(ct->data, pt->data, ct->len, &key, iv, AES_DECRYPT);
- GNUNET_assert (0 == gcry_cipher_decrypt (handle, tmp, size, ct, size));
+ GNUNET_assert (0 == gcry_cipher_decrypt (handle, tmp, size, ct, size));
gcry_cipher_close (handle);
/* TODO make less crufty */
-
+
/* get real length */
len = 0;
len = len
struct GNUNET_ABE_AbeKey *prv_key;
int size;
char *tmp;
-
+
prv_key = GNUNET_new (struct GNUNET_ABE_AbeKey);
prv_key->prv = gabe_keygen(key->pub, key->msk, attrs);
size = gabe_pub_serialize(key->pub, &tmp);
{
char *ptr;
uint32_t *len;
-
+
*result = GNUNET_malloc (12 + cph_buf_len + aes_buf_len);
ptr = *result;
len = (uint32_t*) ptr;
len = (uint32_t*) ptr;
*len = htonl (aes_buf_len);
ptr += 4;
- memcpy (ptr, aes_buf, aes_buf_len);
+ GNUNET_memcpy (ptr, aes_buf, aes_buf_len);
ptr += aes_buf_len;
len = (uint32_t*) ptr;
*len = htonl (cph_buf_len);
ptr += 4;
- memcpy (ptr, cph_buf, cph_buf_len);
+ GNUNET_memcpy (ptr, cph_buf, cph_buf_len);
return 12 + cph_buf_len + aes_buf_len;
}
*aes_buf_len = ntohl (*len);
ptr += 4;
*aes_buf = GNUNET_malloc (*aes_buf_len);
- memcpy(*aes_buf, ptr, *aes_buf_len);
+ GNUNET_memcpy(*aes_buf, ptr, *aes_buf_len);
ptr += *aes_buf_len;
len = (uint32_t*)ptr;
*cph_buf_len = ntohl (*len);
ptr += 4;
*cph_buf = GNUNET_malloc (*cph_buf_len);
- memcpy(*cph_buf, ptr, *cph_buf_len);
+ GNUNET_memcpy(*cph_buf, ptr, *cph_buf_len);
return buf_len;
}
&prv_len);
key->pub = gabe_pub_unserialize (pub, pub_len);
key->prv = gabe_prv_unserialize (key->pub, prv, prv_len);
-
+
GNUNET_free (pub);
GNUNET_free (prv);
return key;
&msk_len);
key->pub = gabe_pub_unserialize (pub, pub_len);
key->msk = gabe_msk_unserialize (key->pub, msk, msk_len);
-
+
GNUNET_free (pub);
GNUNET_free (msk);
* The issuer
*/
struct GNUNET_CRYPTO_EcdsaPublicKey issuer_key;
-
+
/**
* The subject
*/
struct GNUNET_CRYPTO_EcdsaPublicKey subject_key;
-
+
/**
* The issued attribute
*/
char *issuer_attribute;
-
+
/**
* The delegated attribute
*/
* DLL
*/
struct CredentialRecordEntry *prev;
-
+
/**
* Number of references in delegation chains
*/
}
cleanup_delegation_set (vrh->root_set);
GNUNET_free_non_null (vrh->issuer_attribute);
- for (cr_entry = vrh->cred_chain_head;
+ for (cr_entry = vrh->cred_chain_head;
NULL != vrh->cred_chain_head;
cr_entry = vrh->cred_chain_head)
{
else
rmsg->cred_found = htonl (GNUNET_NO);
- GNUNET_assert (-1 !=
+ GNUNET_assert (-1 !=
GNUNET_CREDENTIAL_delegation_chain_serialize (vrh->delegation_chain_size,
dd,
vrh->cred_chain_size,
"Got %d attrs\n", rd_count);
// Each OR
- for (uint32_t i=0; i < rd_count; i++)
+ for (uint32_t i=0; i < rd_count; i++)
{
if (GNUNET_GNSRECORD_TYPE_ATTRIBUTE != rd[i].record_type)
continue;
/**
* Check if this delegation already matches one of our credentials
*/
- for(cred_pointer = vrh->cred_chain_head; cred_pointer != NULL;
+ for(cred_pointer = vrh->cred_chain_head; cred_pointer != NULL;
cred_pointer = cred_pointer->next)
{
- if(0 != memcmp (&set->subject_key,
+ if(0 != memcmp (&set->subject_key,
&cred_pointer->credential->issuer_key,
sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)))
continue;
return;
}
-}
+}
/**
}
/**
- * Check for attributes from the issuer and follow the chain
+ * Check for attributes from the issuer and follow the chain
* till you get the required subject's attributes
*/
char issuer_attribute_name[strlen (vrh->issuer_attribute) + strlen (".gnu") + 1];
"Looking up %s\n", issuer_attribute_name);
ds_entry = GNUNET_new (struct DelegationSetQueueEntry);
ds_entry->issuer_key = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPublicKey);
- memcpy (ds_entry->issuer_key,
- &vrh->issuer_key,
- sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey));
+ GNUNET_memcpy (ds_entry->issuer_key,
+ &vrh->issuer_key,
+ sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey));
ds_entry->issuer_attribute = GNUNET_strdup (vrh->issuer_attribute);
ds_entry->handle = vrh;
ds_entry->lookup_attribute = GNUNET_strdup (vrh->issuer_attribute);
static void
handle_verify (void *cls,
- const struct VerifyMessage *v_msg)
+ const struct VerifyMessage *v_msg)
{
struct VerifyRequestHandle *vrh;
struct GNUNET_SERVICE_Client *client = cls;
"Received VERIFY message\n");
utf_in = (const char *) &v_msg[1];
GNUNET_STRINGS_utf8_tolower (utf_in, attrptr);
- GNUNET_memcpy (issuer_attribute, attr, ntohs (v_msg->issuer_attribute_len));
+ GNUNET_memcpy (issuer_attribute,
+ attr,
+ ntohs (v_msg->issuer_attribute_len));
issuer_attribute[ntohs (v_msg->issuer_attribute_len)] = '\0';
vrh = GNUNET_new (struct VerifyRequestHandle);
GNUNET_CONTAINER_DLL_insert (vrh_head, vrh_tail, vrh);
vrh->issuer_attribute = GNUNET_strdup (issuer_attribute);
if (0 == strlen (issuer_attribute))
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"No issuer attribute provided!\n");
send_lookup_response (vrh);
return;
* TODO: cleanup!
*/
credentials_count = ntohl(v_msg->c_count);
- credential_data_size = ntohs (v_msg->header.size)
+ credential_data_size = ntohs (v_msg->header.size)
- sizeof (struct VerifyMessage)
- ntohs (v_msg->issuer_attribute_len)
- 1;
credentials_count,
credentials))
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Cannot deserialize credentials!\n");
send_lookup_response (vrh);
return;
static void
handle_collect (void *cls,
- const struct CollectMessage *c_msg)
+ const struct CollectMessage *c_msg)
{
char attr[GNUNET_CREDENTIAL_MAX_LENGTH + 1];
char issuer_attribute[GNUNET_CREDENTIAL_MAX_LENGTH + 1];
utf_in = (const char *) &c_msg[1];
GNUNET_STRINGS_utf8_tolower (utf_in, attrptr);
- GNUNET_memcpy (issuer_attribute, attr, ntohs (c_msg->issuer_attribute_len));
+ GNUNET_memcpy (issuer_attribute,
+ attr,
+ ntohs (c_msg->issuer_attribute_len));
issuer_attribute[ntohs (c_msg->issuer_attribute_len)] = '\0';
vrh = GNUNET_new (struct VerifyRequestHandle);
GNUNET_CONTAINER_DLL_insert (vrh_head, vrh_tail, vrh);
if (0 == strlen (issuer_attribute))
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"No issuer attribute provided!\n");
send_lookup_response (vrh);
return;
int i;
if (data_size < sizeof (struct GNUNET_CREDENTIAL_DelegationRecord))
return NULL; /* malformed */
- memcpy (&sets,
- data,
- sizeof (sets));
+ GNUNET_memcpy (&sets,
+ data,
+ sizeof (sets));
cdata = data;
struct GNUNET_CREDENTIAL_DelegationSet set[ntohl(sets.set_count)];
if (GNUNET_OK != GNUNET_CREDENTIAL_delegation_set_deserialize (GNUNET_ntohll (sets.data_size),
}
tmp_data_size = GNUNET_CREDENTIAL_delegation_set_get_size (entries,
set);
-
+
if (-1 == tmp_data_size)
{
GNUNET_free (tmp_str);
return GNUNET_OK;
}
case GNUNET_GNSRECORD_TYPE_CREDENTIAL:
- {
+ {
struct GNUNET_CREDENTIAL_Credential *cred;
cred = GNUNET_CREDENTIAL_credential_from_string (s);
sig,
sizeof (struct GNUNET_CRYPTO_EcdsaSignature));
GNUNET_free (sig);
-
+
tmp = json_object_get (res, "expiration");
if (0 == json_is_integer (tmp))
{
GNUNET_free (cred);
return NULL;
}
- cred->expiration.abs_value_us = json_integer_value (tmp);
+ cred->expiration.abs_value_us = json_integer_value (tmp);
return cred;
}
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Issuer in credential malformed\n");
return NULL;
- }
+ }
subject = GNUNET_CRYPTO_ecdsa_public_key_to_string (&cred->subject_key);
if (NULL == subject)
{
GNUNET_STRINGS_base64_encode ((char*)&cred->signature,
sizeof (struct GNUNET_CRYPTO_EcdsaSignature),
&signature);
- memcpy (attribute,
- cred->issuer_attribute,
- cred->issuer_attribute_len);
+ GNUNET_memcpy (attribute,
+ cred->issuer_attribute,
+ cred->issuer_attribute_len);
attribute[cred->issuer_attribute_len] = '\0';
cred_obj = json_object ();
json_object_set_new (cred_obj, "issuer", json_string (issuer));
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Missing issuer attribute\n");
- GNUNET_SCHEDULER_add_now (&do_error, handle);
+ GNUNET_SCHEDULER_add_now (&do_error, handle);
return;
}
tmp = GNUNET_CONTAINER_multihashmap_get (conndata_handle->url_param_map,
GNUNET_SCHEDULER_add_now (&do_error, handle);
return;
}
- if (GNUNET_OK !=
+ if (GNUNET_OK !=
GNUNET_CRYPTO_ecdsa_public_key_from_string (tmp,
strlen (tmp),
&handle->issuer_key))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Malformed subject\n");
- GNUNET_SCHEDULER_add_now (&do_error, handle);
+ GNUNET_SCHEDULER_add_now (&do_error, handle);
return;
}
handle->ego_lookup = GNUNET_IDENTITY_ego_lookup (cfg,
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Missing issuer attribute\n");
- GNUNET_SCHEDULER_add_now (&do_error, handle);
+ GNUNET_SCHEDULER_add_now (&do_error, handle);
return;
}
tmp = GNUNET_CONTAINER_multihashmap_get (conndata_handle->url_param_map,
GNUNET_SCHEDULER_add_now (&do_error, handle);
return;
}
- if (GNUNET_OK !=
+ if (GNUNET_OK !=
GNUNET_CRYPTO_ecdsa_public_key_from_string (tmp,
strlen (tmp),
&handle->issuer_key))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Malformed subject\n");
- GNUNET_SCHEDULER_add_now (&do_error, handle);
+ GNUNET_SCHEDULER_add_now (&do_error, handle);
return;
}
if (GNUNET_OK !=
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Missing expiration\n");
- GNUNET_SCHEDULER_add_now (&do_error, handle);
+ GNUNET_SCHEDULER_add_now (&do_error, handle);
return;
}
expiration_str = GNUNET_CONTAINER_multihashmap_get (handle->rest_handle->url_param_map,
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Expiration malformed\n");
- GNUNET_SCHEDULER_add_now (&do_error, handle);
+ GNUNET_SCHEDULER_add_now (&do_error, handle);
return;
}
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Malformed expiration: %s\n", expiration_str);
- GNUNET_SCHEDULER_add_now (&do_error, handle);
+ GNUNET_SCHEDULER_add_now (&do_error, handle);
return;
}
GNUNET_CRYPTO_hash (GNUNET_REST_JSONAPI_CREDENTIAL_ISSUER_ATTR,
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Missing issuer attribute\n");
- GNUNET_SCHEDULER_add_now (&do_error, handle);
+ GNUNET_SCHEDULER_add_now (&do_error, handle);
return;
}
- handle->issuer_attr = GNUNET_strdup(GNUNET_CONTAINER_multihashmap_get
+ handle->issuer_attr = GNUNET_strdup(GNUNET_CONTAINER_multihashmap_get
(handle->rest_handle->url_param_map,
&key));
GNUNET_CRYPTO_hash (GNUNET_REST_JSONAPI_CREDENTIAL_SUBJECT_KEY,
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Malformed subject\n");
- GNUNET_SCHEDULER_add_now (&do_error, handle);
+ GNUNET_SCHEDULER_add_now (&do_error, handle);
return;
}
if (GNUNET_OK !=
noinst_PROGRAMS = \
gnunet-dns-monitor \
gnunet-dns-redirector \
- gnunet-zoneimport
+ gnunet-zonewalk
plugin_LTLIBRARIES = \
libgnunet_plugin_block_dns.la
$(top_builddir)/src/util/libgnunetutil.la \
$(GN_LIBINTL)
-gnunet_zoneimport_SOURCES = \
- gnunet-zoneimport.c
-gnunet_zoneimport_LDADD = \
+gnunet_zonewalk_SOURCES = \
+ gnunet-zonewalk.c
+gnunet_zonewalk_LDADD = \
libgnunetdnsparser.la \
libgnunetdnsstub.la \
$(top_builddir)/src/util/libgnunetutil.la \
return GNUNET_SYSERR;
if (IDNA_SUCCESS !=
- (rc = idna_to_ascii_8z (name, &idna_start, IDNA_ALLOW_UNASSIGNED)))
+ (rc = idna_to_ascii_8z (name,
+ &idna_start,
+ IDNA_ALLOW_UNASSIGNED)))
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
_("Failed to convert UTF-8 name `%s' to DNS IDNA format: %s\n"),
goto fail; /* segment too long or empty */
}
dst[pos++] = (char) (uint8_t) len;
- GNUNET_memcpy (&dst[pos], idna_name, len);
+ GNUNET_memcpy (&dst[pos],
+ idna_name,
+ len);
pos += len;
idna_name += len + 1; /* also skip dot */
}
sa,
salen))
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Failed to send DNS request to %s\n"),
+ _("Failed to send DNS request to %s: %s\n"),
GNUNET_a2s (sa,
- salen));
+ salen),
+ STRERROR (errno));
else
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
_("Sent DNS request to %s\n"),
switch (sa->sa_family)
{
case AF_INET:
- memcpy (&ds->ss,
- sa,
- sizeof (struct sockaddr_in));
+ GNUNET_memcpy (&ds->ss,
+ sa,
+ sizeof (struct sockaddr_in));
break;
case AF_INET6:
- memcpy (&ds->ss,
- sa,
- sizeof (struct sockaddr_in6));
+ GNUNET_memcpy (&ds->ss,
+ sa,
+ sizeof (struct sockaddr_in6));
break;
default:
GNUNET_break (0);
+++ /dev/null
-/*
- This file is part of GNUnet
- Copyright (C) 2018 GNUnet e.V.
-
- GNUnet is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published
- by the Free Software Foundation; either version 3, or (at your
- option) any later version.
-
- GNUnet is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with GNUnet; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- Boston, MA 02110-1301, USA.
-*/
-
-/**
- * @file src/dns/gnunet-zoneimport.c
- * @brief import a DNS zone for analysis, brute force
- * @author Christian Grothoff
- */
-#include "platform.h"
-#include <gnunet_util_lib.h>
-#include <gnunet_dnsstub_lib.h>
-#include <gnunet_dnsparser_lib.h>
-
-/**
- * Request we should make.
- */
-struct Request
-{
- /**
- * Requests are kept in a DLL.
- */
- struct Request *next;
-
- /**
- * Requests are kept in a DLL.
- */
- struct Request *prev;
-
- /**
- * Socket used to make the request, NULL if not active.
- */
- struct GNUNET_DNSSTUB_RequestSocket *rs;
-
- /**
- * Raw DNS query.
- */
- void *raw;
-
- /**
- * Number of bytes in @e raw.
- */
- size_t raw_len;
-
- /**
- * Hostname we are resolving.
- */
- char *hostname;
-
- /**
- * When did we last issue this request?
- */
- time_t time;
-
- /**
- * How often did we issue this query?
- */
- int issue_num;
-
- /**
- * random 16-bit DNS query identifier.
- */
- uint16_t id;
-};
-
-
-/**
- * Context for DNS resolution.
- */
-static struct GNUNET_DNSSTUB_Context *ctx;
-
-/**
- * The number of queries that are outstanding
- */
-static unsigned int pending;
-
-/**
- * Number of lookups we performed overall.
- */
-static unsigned int lookups;
-
-/**
- * Number of lookups that failed.
- */
-static unsigned int failures;
-
-/**
- * Number of records we found.
- */
-static unsigned int records;
-
-/**
- * Head of DLL of all requests to perform.
- */
-static struct Request *req_head;
-
-/**
- * Tail of DLL of all requests to perform.
- */
-static struct Request *req_tail;
-
-/**
- * Main task.
- */
-static struct GNUNET_SCHEDULER_Task *t;
-
-/**
- * Maximum number of queries pending at the same time.
- */
-#define THRESH 20
-
-/**
- * TIME_THRESH is in usecs. How quickly do we submit fresh queries.
- * Used as an additional throttle.
- */
-#define TIME_THRESH 10
-
-/**
- * How often do we retry a query before giving up for good?
- */
-#define MAX_RETRIES 5
-
-
-/**
- * We received @a rec for @a req. Remember the answer.
- *
- * @param req request
- * @param rec response
- */
-static void
-process_record (struct Request *req,
- struct GNUNET_DNSPARSER_Record *rec)
-{
- char buf[INET6_ADDRSTRLEN];
-
- records++;
- switch (rec->type)
- {
- case GNUNET_DNSPARSER_TYPE_A:
- fprintf (stdout,
- "%s A %s\n",
- req->hostname,
- inet_ntop (AF_INET,
- rec->data.raw.data,
- buf,
- sizeof (buf)));
- break;
- case GNUNET_DNSPARSER_TYPE_AAAA:
- fprintf (stdout,
- "%s AAAA %s\n",
- req->hostname,
- inet_ntop (AF_INET6,
- rec->data.raw.data,
- buf,
- sizeof (buf)));
- break;
- case GNUNET_DNSPARSER_TYPE_NS:
- fprintf (stdout,
- "%s NS %s\n",
- req->hostname,
- rec->data.hostname);
- break;
- case GNUNET_DNSPARSER_TYPE_CNAME:
- fprintf (stdout,
- "%s CNAME %s\n",
- req->hostname,
- rec->data.hostname);
- break;
- case GNUNET_DNSPARSER_TYPE_MX:
- fprintf (stdout,
- "%s MX %u %s\n",
- req->hostname,
- (unsigned int) rec->data.mx->preference,
- rec->data.mx->mxhost);
- break;
- case GNUNET_DNSPARSER_TYPE_SOA:
- fprintf (stdout,
- "%s SOA %s %s %u %u %u %u %u\n",
- req->hostname,
- rec->data.soa->mname,
- rec->data.soa->rname,
- (unsigned int) rec->data.soa->serial,
- (unsigned int) rec->data.soa->refresh,
- (unsigned int) rec->data.soa->retry,
- (unsigned int) rec->data.soa->expire,
- (unsigned int) rec->data.soa->minimum_ttl);
- break;
- case GNUNET_DNSPARSER_TYPE_SRV:
- fprintf (stdout,
- "%s SRV %s %u %u %u\n",
- req->hostname,
- rec->data.srv->target,
- rec->data.srv->priority,
- rec->data.srv->weight,
- rec->data.srv->port);
- break;
- case GNUNET_DNSPARSER_TYPE_PTR:
- fprintf (stdout,
- "%s PTR %s\n",
- req->hostname,
- rec->data.hostname);
- break;
- case GNUNET_DNSPARSER_TYPE_TXT:
- fprintf (stdout,
- "%s TXT %.*s\n",
- req->hostname,
- (int) rec->data.raw.data_len,
- (char *) rec->data.raw.data);
- break;
- case GNUNET_DNSPARSER_TYPE_DNAME:
- fprintf (stdout,
- "%s DNAME %s\n",
- req->hostname,
- rec->data.hostname);
- break;
-
- /* obscure records */
- case GNUNET_DNSPARSER_TYPE_AFSDB:
- case GNUNET_DNSPARSER_TYPE_NAPTR:
- case GNUNET_DNSPARSER_TYPE_APL:
- case GNUNET_DNSPARSER_TYPE_DHCID:
- case GNUNET_DNSPARSER_TYPE_HIP:
- case GNUNET_DNSPARSER_TYPE_LOC:
- case GNUNET_DNSPARSER_TYPE_RP:
- case GNUNET_DNSPARSER_TYPE_TKEY:
- case GNUNET_DNSPARSER_TYPE_TSIG:
- case GNUNET_DNSPARSER_TYPE_URI:
- case GNUNET_DNSPARSER_TYPE_TA:
-
- /* DNSSEC */
- case GNUNET_DNSPARSER_TYPE_DS:
- case GNUNET_DNSPARSER_TYPE_RRSIG:
- case GNUNET_DNSPARSER_TYPE_NSEC:
- case GNUNET_DNSPARSER_TYPE_DNSKEY:
- case GNUNET_DNSPARSER_TYPE_NSEC3:
- case GNUNET_DNSPARSER_TYPE_NSEC3PARAM:
- case GNUNET_DNSPARSER_TYPE_CDS:
- case GNUNET_DNSPARSER_TYPE_CDNSKEY:
-
- /* DNSSEC payload */
- case GNUNET_DNSPARSER_TYPE_CERT:
- case GNUNET_DNSPARSER_TYPE_SSHFP:
- case GNUNET_DNSPARSER_TYPE_IPSECKEY:
- case GNUNET_DNSPARSER_TYPE_TLSA:
- case GNUNET_DNSPARSER_TYPE_OPENPGPKEY:
-
- /* obsolete records */
- case GNUNET_DNSPARSER_TYPE_SIG:
- case GNUNET_DNSPARSER_TYPE_KEY:
- case GNUNET_DNSPARSER_TYPE_KX:
- {
- char *base32;
-
- base32 = GNUNET_STRINGS_data_to_string_alloc (rec->data.raw.data,
- rec->data.raw.data_len);
- fprintf (stdout,
- "%s (%u) %s\n",
- req->hostname,
- rec->type,
- base32);
- GNUNET_free (base32);
- }
- break;
- default:
- fprintf (stderr,
- "Unsupported type %u\n",
- (unsigned int) rec->type);
- break;
- }
-}
-
-
-/**
- * Function called with the result of a DNS resolution.
- *
- * @param cls closure with the `struct Request`
- * @param dns dns response, never NULL
- * @param dns_len number of bytes in @a dns
- */
-static void
-process_result (void *cls,
- const struct GNUNET_TUN_DnsHeader *dns,
- size_t dns_len)
-{
- struct Request *req = cls;
- struct GNUNET_DNSPARSER_Packet *p;
-
- if (NULL == dns)
- {
- /* stub gave up */
- pending--;
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Stub gave up on DNS reply for `%s'\n",
- req->hostname);
- GNUNET_CONTAINER_DLL_remove (req_head,
- req_tail,
- req);
- if (req->issue_num > MAX_RETRIES)
- {
- failures++;
- GNUNET_free (req->hostname);
- GNUNET_free (req->raw);
- GNUNET_free (req);
- return;
- }
- GNUNET_CONTAINER_DLL_insert_tail (req_head,
- req_tail,
- req);
- req->rs = NULL;
- return;
- }
- if (req->id != dns->id)
- return;
- pending--;
- GNUNET_DNSSTUB_resolve_cancel (req->rs);
- req->rs = NULL;
- GNUNET_CONTAINER_DLL_remove (req_head,
- req_tail,
- req);
- p = GNUNET_DNSPARSER_parse ((const char *) dns,
- dns_len);
- if (NULL == p)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to parse DNS reply for `%s'\n",
- req->hostname);
- if (req->issue_num > MAX_RETRIES)
- {
- failures++;
- GNUNET_free (req->hostname);
- GNUNET_free (req->raw);
- GNUNET_free (req);
- return;
- }
- GNUNET_CONTAINER_DLL_insert_tail (req_head,
- req_tail,
- req);
- return;
- }
- for (unsigned int i=0;i<p->num_answers;i++)
- {
- struct GNUNET_DNSPARSER_Record *rs = &p->answers[i];
-
- process_record (req,
- rs);
- }
- for (unsigned int i=0;i<p->num_authority_records;i++)
- {
- struct GNUNET_DNSPARSER_Record *rs = &p->authority_records[i];
-
- process_record (req,
- rs);
- }
- for (unsigned int i=0;i<p->num_additional_records;i++)
- {
- struct GNUNET_DNSPARSER_Record *rs = &p->additional_records[i];
-
- process_record (req,
- rs);
- }
- GNUNET_DNSPARSER_free_packet (p);
- GNUNET_free (req->hostname);
- GNUNET_free (req->raw);
- GNUNET_free (req);
-}
-
-
-/**
- * Submit a request to DNS unless we need to slow down because
- * we are at the rate limit.
- *
- * @param req request to submit
- * @return #GNUNET_OK if request was submitted
- * #GNUNET_NO if request was already submitted
- * #GNUNET_SYSERR if we are at the rate limit
- */
-static int
-submit_req (struct Request *req)
-{
- static struct timeval last_request;
- struct timeval now;
-
- if (NULL != req->rs)
- return GNUNET_NO; /* already submitted */
- gettimeofday (&now,
- NULL);
- if ( ( ( (now.tv_sec - last_request.tv_sec) == 0) &&
- ( (now.tv_usec - last_request.tv_usec) < TIME_THRESH) ) ||
- (pending >= THRESH) )
- return GNUNET_SYSERR;
- GNUNET_assert (NULL == req->rs);
- req->rs = GNUNET_DNSSTUB_resolve (ctx,
- req->raw,
- req->raw_len,
- &process_result,
- req);
- GNUNET_assert (NULL != req->rs);
- req->issue_num++;
- last_request = now;
- lookups++;
- pending++;
- req->time = time (NULL);
- return GNUNET_OK;
-}
-
-
-/**
- * Process as many requests as possible from the queue.
- *
- * @param cls NULL
- */
-static void
-process_queue(void *cls)
-{
- (void) cls;
- t = NULL;
- for (struct Request *req = req_head;
- NULL != req;
- req = req->next)
- {
- if (GNUNET_SYSERR == submit_req (req))
- break;
- }
- if (NULL != req_head)
- t = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS,
- &process_queue,
- NULL);
- else
- GNUNET_SCHEDULER_shutdown ();
-}
-
-
-/**
- * Clean up and terminate the process.
- *
- * @param cls NULL
- */
-static void
-do_shutdown (void *cls)
-{
- (void) cls;
- if (NULL != t)
- {
- GNUNET_SCHEDULER_cancel (t);
- t = NULL;
- }
- GNUNET_DNSSTUB_stop (ctx);
- ctx = NULL;
-}
-
-
-/**
- * Process requests from the queue, then if the queue is
- * not empty, try again.
- *
- * @param cls NULL
- */
-static void
-run (void *cls)
-{
- (void) cls;
-
- GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
- NULL);
- t = GNUNET_SCHEDULER_add_now (&process_queue,
- NULL);
-}
-
-
-/**
- * Add @a hostname to the list of requests to be made.
- *
- * @param hostname name to resolve
- */
-static void
-queue (const char *hostname)
-{
- struct GNUNET_DNSPARSER_Packet p;
- struct GNUNET_DNSPARSER_Query q;
- struct Request *req;
- char *raw;
- size_t raw_size;
-
- if (GNUNET_OK !=
- GNUNET_DNSPARSER_check_name (hostname))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Refusing invalid hostname `%s'\n",
- hostname);
- return;
- }
- q.name = (char *) hostname;
- q.type = GNUNET_DNSPARSER_TYPE_NS;
- q.dns_traffic_class = GNUNET_TUN_DNS_CLASS_INTERNET;
-
- memset (&p,
- 0,
- sizeof (p));
- p.num_queries = 1;
- p.queries = &q;
- p.id = (uint16_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE,
- UINT16_MAX);
-
- if (GNUNET_OK !=
- GNUNET_DNSPARSER_pack (&p,
- UINT16_MAX,
- &raw,
- &raw_size))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to pack query for hostname `%s'\n",
- hostname);
- return;
- }
-
- req = GNUNET_new (struct Request);
- req->hostname = strdup (hostname);
- req->raw = raw;
- req->raw_len = raw_size;
- req->id = p.id;
- GNUNET_CONTAINER_DLL_insert_tail (req_head,
- req_tail,
- req);
-}
-
-
-/**
- * Call with IP address of resolver to query.
- *
- * @param argc should be 2
- * @param argv[1] should contain IP address
- * @return 0 on success
- */
-int
-main (int argc,
- char **argv)
-{
- char hn[256];
-
- if (2 != argc)
- {
- fprintf (stderr,
- "Missing required configuration argument\n");
- return -1;
- }
- ctx = GNUNET_DNSSTUB_start (256);
- if (NULL == ctx)
- {
- fprintf (stderr,
- "Failed to initialize GNUnet DNS STUB\n");
- return 1;
- }
- if (GNUNET_OK !=
- GNUNET_DNSSTUB_add_dns_ip (ctx,
- argv[1]))
- {
- fprintf (stderr,
- "Failed to use `%s' for DNS resolver\n",
- argv[1]);
- return 1;
- }
-
- while (NULL !=
- fgets (hn,
- sizeof (hn),
- stdin))
- {
- if (strlen(hn) > 0)
- hn[strlen(hn)-1] = '\0'; /* eat newline */
- queue (hn);
- }
- GNUNET_SCHEDULER_run (&run,
- NULL);
- fprintf (stderr,
- "Did %u lookups, found %u records, %u lookups failed, %u pending on shutdown\n",
- lookups,
- records,
- failures,
- pending);
- return 0;
-}
--- /dev/null
+/*
+ This file is part of GNUnet
+ Copyright (C) 2018 GNUnet e.V.
+
+ GNUnet is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3, or (at your
+ option) any later version.
+
+ GNUnet is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GNUnet; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+/**
+ * @file src/dns/gnunet-zoneimport.c
+ * @brief import a DNS zone for analysis, brute force
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include <gnunet_util_lib.h>
+#include <gnunet_dnsstub_lib.h>
+#include <gnunet_dnsparser_lib.h>
+
+/**
+ * Request we should make.
+ */
+struct Request
+{
+ /**
+ * Requests are kept in a DLL.
+ */
+ struct Request *next;
+
+ /**
+ * Requests are kept in a DLL.
+ */
+ struct Request *prev;
+
+ /**
+ * Socket used to make the request, NULL if not active.
+ */
+ struct GNUNET_DNSSTUB_RequestSocket *rs;
+
+ /**
+ * Raw DNS query.
+ */
+ void *raw;
+
+ /**
+ * Number of bytes in @e raw.
+ */
+ size_t raw_len;
+
+ /**
+ * Hostname we are resolving.
+ */
+ char *hostname;
+
+ /**
+ * When did we last issue this request?
+ */
+ time_t time;
+
+ /**
+ * How often did we issue this query?
+ */
+ int issue_num;
+
+ /**
+ * random 16-bit DNS query identifier.
+ */
+ uint16_t id;
+};
+
+
+/**
+ * Context for DNS resolution.
+ */
+static struct GNUNET_DNSSTUB_Context *ctx;
+
+/**
+ * The number of queries that are outstanding
+ */
+static unsigned int pending;
+
+/**
+ * Number of lookups we performed overall.
+ */
+static unsigned int lookups;
+
+/**
+ * Number of lookups that failed.
+ */
+static unsigned int failures;
+
+/**
+ * Number of records we found.
+ */
+static unsigned int records;
+
+/**
+ * Head of DLL of all requests to perform.
+ */
+static struct Request *req_head;
+
+/**
+ * Tail of DLL of all requests to perform.
+ */
+static struct Request *req_tail;
+
+/**
+ * Main task.
+ */
+static struct GNUNET_SCHEDULER_Task *t;
+
+/**
+ * Maximum number of queries pending at the same time.
+ */
+#define THRESH 20
+
+/**
+ * TIME_THRESH is in usecs. How quickly do we submit fresh queries.
+ * Used as an additional throttle.
+ */
+#define TIME_THRESH 10
+
+/**
+ * How often do we retry a query before giving up for good?
+ */
+#define MAX_RETRIES 5
+
+
+/**
+ * We received @a rec for @a req. Remember the answer.
+ *
+ * @param req request
+ * @param rec response
+ */
+static void
+process_record (struct Request *req,
+ struct GNUNET_DNSPARSER_Record *rec)
+{
+ char buf[INET6_ADDRSTRLEN];
+
+ records++;
+ switch (rec->type)
+ {
+ case GNUNET_DNSPARSER_TYPE_A:
+ fprintf (stdout,
+ "%s A %s\n",
+ req->hostname,
+ inet_ntop (AF_INET,
+ rec->data.raw.data,
+ buf,
+ sizeof (buf)));
+ break;
+ case GNUNET_DNSPARSER_TYPE_AAAA:
+ fprintf (stdout,
+ "%s AAAA %s\n",
+ req->hostname,
+ inet_ntop (AF_INET6,
+ rec->data.raw.data,
+ buf,
+ sizeof (buf)));
+ break;
+ case GNUNET_DNSPARSER_TYPE_NS:
+ fprintf (stdout,
+ "%s NS %s\n",
+ req->hostname,
+ rec->data.hostname);
+ break;
+ case GNUNET_DNSPARSER_TYPE_CNAME:
+ fprintf (stdout,
+ "%s CNAME %s\n",
+ req->hostname,
+ rec->data.hostname);
+ break;
+ case GNUNET_DNSPARSER_TYPE_MX:
+ fprintf (stdout,
+ "%s MX %u %s\n",
+ req->hostname,
+ (unsigned int) rec->data.mx->preference,
+ rec->data.mx->mxhost);
+ break;
+ case GNUNET_DNSPARSER_TYPE_SOA:
+ fprintf (stdout,
+ "%s SOA %s %s %u %u %u %u %u\n",
+ req->hostname,
+ rec->data.soa->mname,
+ rec->data.soa->rname,
+ (unsigned int) rec->data.soa->serial,
+ (unsigned int) rec->data.soa->refresh,
+ (unsigned int) rec->data.soa->retry,
+ (unsigned int) rec->data.soa->expire,
+ (unsigned int) rec->data.soa->minimum_ttl);
+ break;
+ case GNUNET_DNSPARSER_TYPE_SRV:
+ fprintf (stdout,
+ "%s SRV %s %u %u %u\n",
+ req->hostname,
+ rec->data.srv->target,
+ rec->data.srv->priority,
+ rec->data.srv->weight,
+ rec->data.srv->port);
+ break;
+ case GNUNET_DNSPARSER_TYPE_PTR:
+ fprintf (stdout,
+ "%s PTR %s\n",
+ req->hostname,
+ rec->data.hostname);
+ break;
+ case GNUNET_DNSPARSER_TYPE_TXT:
+ fprintf (stdout,
+ "%s TXT %.*s\n",
+ req->hostname,
+ (int) rec->data.raw.data_len,
+ (char *) rec->data.raw.data);
+ break;
+ case GNUNET_DNSPARSER_TYPE_DNAME:
+ fprintf (stdout,
+ "%s DNAME %s\n",
+ req->hostname,
+ rec->data.hostname);
+ break;
+
+ /* obscure records */
+ case GNUNET_DNSPARSER_TYPE_AFSDB:
+ case GNUNET_DNSPARSER_TYPE_NAPTR:
+ case GNUNET_DNSPARSER_TYPE_APL:
+ case GNUNET_DNSPARSER_TYPE_DHCID:
+ case GNUNET_DNSPARSER_TYPE_HIP:
+ case GNUNET_DNSPARSER_TYPE_LOC:
+ case GNUNET_DNSPARSER_TYPE_RP:
+ case GNUNET_DNSPARSER_TYPE_TKEY:
+ case GNUNET_DNSPARSER_TYPE_TSIG:
+ case GNUNET_DNSPARSER_TYPE_URI:
+ case GNUNET_DNSPARSER_TYPE_TA:
+
+ /* DNSSEC */
+ case GNUNET_DNSPARSER_TYPE_DS:
+ case GNUNET_DNSPARSER_TYPE_RRSIG:
+ case GNUNET_DNSPARSER_TYPE_NSEC:
+ case GNUNET_DNSPARSER_TYPE_DNSKEY:
+ case GNUNET_DNSPARSER_TYPE_NSEC3:
+ case GNUNET_DNSPARSER_TYPE_NSEC3PARAM:
+ case GNUNET_DNSPARSER_TYPE_CDS:
+ case GNUNET_DNSPARSER_TYPE_CDNSKEY:
+
+ /* DNSSEC payload */
+ case GNUNET_DNSPARSER_TYPE_CERT:
+ case GNUNET_DNSPARSER_TYPE_SSHFP:
+ case GNUNET_DNSPARSER_TYPE_IPSECKEY:
+ case GNUNET_DNSPARSER_TYPE_TLSA:
+ case GNUNET_DNSPARSER_TYPE_OPENPGPKEY:
+
+ /* obsolete records */
+ case GNUNET_DNSPARSER_TYPE_SIG:
+ case GNUNET_DNSPARSER_TYPE_KEY:
+ case GNUNET_DNSPARSER_TYPE_KX:
+ {
+ char *base32;
+
+ base32 = GNUNET_STRINGS_data_to_string_alloc (rec->data.raw.data,
+ rec->data.raw.data_len);
+ fprintf (stdout,
+ "%s (%u) %s\n",
+ req->hostname,
+ rec->type,
+ base32);
+ GNUNET_free (base32);
+ }
+ break;
+ default:
+ fprintf (stderr,
+ "Unsupported type %u\n",
+ (unsigned int) rec->type);
+ break;
+ }
+}
+
+
+/**
+ * Function called with the result of a DNS resolution.
+ *
+ * @param cls closure with the `struct Request`
+ * @param dns dns response, never NULL
+ * @param dns_len number of bytes in @a dns
+ */
+static void
+process_result (void *cls,
+ const struct GNUNET_TUN_DnsHeader *dns,
+ size_t dns_len)
+{
+ struct Request *req = cls;
+ struct GNUNET_DNSPARSER_Packet *p;
+
+ if (NULL == dns)
+ {
+ /* stub gave up */
+ pending--;
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Stub gave up on DNS reply for `%s'\n",
+ req->hostname);
+ GNUNET_CONTAINER_DLL_remove (req_head,
+ req_tail,
+ req);
+ if (req->issue_num > MAX_RETRIES)
+ {
+ failures++;
+ GNUNET_free (req->hostname);
+ GNUNET_free (req->raw);
+ GNUNET_free (req);
+ return;
+ }
+ GNUNET_CONTAINER_DLL_insert_tail (req_head,
+ req_tail,
+ req);
+ req->rs = NULL;
+ return;
+ }
+ if (req->id != dns->id)
+ return;
+ pending--;
+ GNUNET_DNSSTUB_resolve_cancel (req->rs);
+ req->rs = NULL;
+ GNUNET_CONTAINER_DLL_remove (req_head,
+ req_tail,
+ req);
+ p = GNUNET_DNSPARSER_parse ((const char *) dns,
+ dns_len);
+ if (NULL == p)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to parse DNS reply for `%s'\n",
+ req->hostname);
+ if (req->issue_num > MAX_RETRIES)
+ {
+ failures++;
+ GNUNET_free (req->hostname);
+ GNUNET_free (req->raw);
+ GNUNET_free (req);
+ return;
+ }
+ GNUNET_CONTAINER_DLL_insert_tail (req_head,
+ req_tail,
+ req);
+ return;
+ }
+ for (unsigned int i=0;i<p->num_answers;i++)
+ {
+ struct GNUNET_DNSPARSER_Record *rs = &p->answers[i];
+
+ process_record (req,
+ rs);
+ }
+ for (unsigned int i=0;i<p->num_authority_records;i++)
+ {
+ struct GNUNET_DNSPARSER_Record *rs = &p->authority_records[i];
+
+ process_record (req,
+ rs);
+ }
+ for (unsigned int i=0;i<p->num_additional_records;i++)
+ {
+ struct GNUNET_DNSPARSER_Record *rs = &p->additional_records[i];
+
+ process_record (req,
+ rs);
+ }
+ GNUNET_DNSPARSER_free_packet (p);
+ GNUNET_free (req->hostname);
+ GNUNET_free (req->raw);
+ GNUNET_free (req);
+}
+
+
+/**
+ * Submit a request to DNS unless we need to slow down because
+ * we are at the rate limit.
+ *
+ * @param req request to submit
+ * @return #GNUNET_OK if request was submitted
+ * #GNUNET_NO if request was already submitted
+ * #GNUNET_SYSERR if we are at the rate limit
+ */
+static int
+submit_req (struct Request *req)
+{
+ static struct timeval last_request;
+ struct timeval now;
+
+ if (NULL != req->rs)
+ return GNUNET_NO; /* already submitted */
+ gettimeofday (&now,
+ NULL);
+ if ( ( ( (now.tv_sec - last_request.tv_sec) == 0) &&
+ ( (now.tv_usec - last_request.tv_usec) < TIME_THRESH) ) ||
+ (pending >= THRESH) )
+ return GNUNET_SYSERR;
+ GNUNET_assert (NULL == req->rs);
+ req->rs = GNUNET_DNSSTUB_resolve (ctx,
+ req->raw,
+ req->raw_len,
+ &process_result,
+ req);
+ GNUNET_assert (NULL != req->rs);
+ req->issue_num++;
+ last_request = now;
+ lookups++;
+ pending++;
+ req->time = time (NULL);
+ return GNUNET_OK;
+}
+
+
+/**
+ * Process as many requests as possible from the queue.
+ *
+ * @param cls NULL
+ */
+static void
+process_queue(void *cls)
+{
+ (void) cls;
+ t = NULL;
+ for (struct Request *req = req_head;
+ NULL != req;
+ req = req->next)
+ {
+ if (GNUNET_SYSERR == submit_req (req))
+ break;
+ }
+ if (NULL != req_head)
+ t = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS,
+ &process_queue,
+ NULL);
+ else
+ GNUNET_SCHEDULER_shutdown ();
+}
+
+
+/**
+ * Clean up and terminate the process.
+ *
+ * @param cls NULL
+ */
+static void
+do_shutdown (void *cls)
+{
+ (void) cls;
+ if (NULL != t)
+ {
+ GNUNET_SCHEDULER_cancel (t);
+ t = NULL;
+ }
+ GNUNET_DNSSTUB_stop (ctx);
+ ctx = NULL;
+}
+
+
+/**
+ * Process requests from the queue, then if the queue is
+ * not empty, try again.
+ *
+ * @param cls NULL
+ */
+static void
+run (void *cls)
+{
+ (void) cls;
+
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
+ NULL);
+ t = GNUNET_SCHEDULER_add_now (&process_queue,
+ NULL);
+}
+
+
+/**
+ * Add @a hostname to the list of requests to be made.
+ *
+ * @param hostname name to resolve
+ */
+static void
+queue (const char *hostname)
+{
+ struct GNUNET_DNSPARSER_Packet p;
+ struct GNUNET_DNSPARSER_Query q;
+ struct Request *req;
+ char *raw;
+ size_t raw_size;
+
+ if (GNUNET_OK !=
+ GNUNET_DNSPARSER_check_name (hostname))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Refusing invalid hostname `%s'\n",
+ hostname);
+ return;
+ }
+ q.name = (char *) hostname;
+ q.type = GNUNET_DNSPARSER_TYPE_NS;
+ q.dns_traffic_class = GNUNET_TUN_DNS_CLASS_INTERNET;
+
+ memset (&p,
+ 0,
+ sizeof (p));
+ p.num_queries = 1;
+ p.queries = &q;
+ p.id = (uint16_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE,
+ UINT16_MAX);
+
+ if (GNUNET_OK !=
+ GNUNET_DNSPARSER_pack (&p,
+ UINT16_MAX,
+ &raw,
+ &raw_size))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to pack query for hostname `%s'\n",
+ hostname);
+ return;
+ }
+
+ req = GNUNET_new (struct Request);
+ req->hostname = strdup (hostname);
+ req->raw = raw;
+ req->raw_len = raw_size;
+ req->id = p.id;
+ GNUNET_CONTAINER_DLL_insert_tail (req_head,
+ req_tail,
+ req);
+}
+
+
+/**
+ * Call with IP address of resolver to query.
+ *
+ * @param argc should be 2
+ * @param argv[1] should contain IP address
+ * @return 0 on success
+ */
+int
+main (int argc,
+ char **argv)
+{
+ char hn[256];
+
+ if (2 != argc)
+ {
+ fprintf (stderr,
+ "Missing required configuration argument\n");
+ return -1;
+ }
+ ctx = GNUNET_DNSSTUB_start (256);
+ if (NULL == ctx)
+ {
+ fprintf (stderr,
+ "Failed to initialize GNUnet DNS STUB\n");
+ return 1;
+ }
+ if (GNUNET_OK !=
+ GNUNET_DNSSTUB_add_dns_ip (ctx,
+ argv[1]))
+ {
+ fprintf (stderr,
+ "Failed to use `%s' for DNS resolver\n",
+ argv[1]);
+ return 1;
+ }
+
+ while (NULL !=
+ fgets (hn,
+ sizeof (hn),
+ stdin))
+ {
+ if (strlen(hn) > 0)
+ hn[strlen(hn)-1] = '\0'; /* eat newline */
+ queue (hn);
+ }
+ GNUNET_SCHEDULER_run (&run,
+ NULL);
+ fprintf (stderr,
+ "Did %u lookups, found %u records, %u lookups failed, %u pending on shutdown\n",
+ lookups,
+ records,
+ failures,
+ pending);
+ return 0;
+}
ii = GNUNET_malloc (sizeof (struct IndexInfo) + slen);
ii->file_id = *file_id;
ii->filename = (const char *) &ii[1];
- memcpy (&ii[1],
- filename,
- slen);
+ GNUNET_memcpy (&ii[1],
+ filename,
+ slen);
GNUNET_CONTAINER_DLL_insert (indexed_files_head,
indexed_files_tail,
ii);
gnunet-dns2gns
gnunet-gns
gnunet-gns-proxy
+gnunet-gns-benchmark
$(DO_NONPOSIX_GNSIMPORT) \
gnunet-gns
+noinst_PROGRAMS = \
+ gnunet-gns-benchmark
+
if HAVE_MHD
if LINUX
bin_PROGRAMS += gnunet-bcd
$(top_builddir)/src/util/libgnunetutil.la \
$(GN_LIBINTL)
+gnunet_gns_benchmark_SOURCES = \
+ gnunet-gns-benchmark.c
+gnunet_gns_benchmark_LDADD = \
+ libgnunetgns.la \
+ $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \
+ $(top_builddir)/src/util/libgnunetutil.la \
+ $(GN_LIBINTL)
+
gnunet_bcd_SOURCES = \
gnunet-bcd.c
test_gns_gns2dns_lookup.sh \
test_gns_dht_lookup.sh\
test_gns_delegated_lookup.sh \
- test_gns_plus_lookup.sh\
+ test_gns_at_lookup.sh\
test_gns_zkey_lookup.sh\
test_gns_rel_expiration.sh\
test_gns_soa_lookup.sh\
# Zones
.pin = DWJASSPE33MRN8T6Q0PENRNBTQY0E6ZYGTRCDP5DGPBF2CRJMJEG
-
+.fr = TFDAXBXMAN40MCG4E8Y9Y1C6D16JCMDPH2VMD30KMB92SECEMYGG
[gns-proxy]
BINARY = gnunet-gns-proxy
size_t mlen = ntohs (lookup_msg->header.size) - sizeof (*lookup_msg);
uint32_t rd_count = ntohl (lookup_msg->rd_count);
struct GNUNET_GNSRECORD_Data rd[rd_count];
-
+
(void) cls;
if (GNUNET_SYSERR ==
GNUNET_GNSRECORD_records_deserialize (mlen,
return;
proc = lr->lookup_proc;
proc_cls = lr->proc_cls;
-
+
GNUNET_assert (GNUNET_OK ==
GNUNET_GNSRECORD_records_deserialize (mlen,
(const char*) &lookup_msg[1],
--- /dev/null
+/*
+ This file is part of GNUnet
+ Copyright (C) 2018 GNUnet e.V.
+
+ GNUnet is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3, or (at your
+ option) any later version.
+
+ GNUnet is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GNUnet; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+/**
+ * @file src/gns/gnunet-gns-benchmark.c
+ * @brief issue many queries to GNS and compute performance statistics
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include <gnunet_util_lib.h>
+#include <gnunet_gnsrecord_lib.h>
+#include <gnunet_gns_service.h>
+
+
+/**
+ * How long do we wait at least between requests by default?
+ */
+#define DEF_REQUEST_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 1)
+
+/**
+ * How long do we wait until we consider a request failed by default?
+ */
+#define DEF_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 1)
+
+
+/**
+ * We distinguish between different categories of
+ * requests, for which we track statistics separately.
+ * However, this process does not change how it acts
+ * based on the category.
+ */
+enum RequestCategory
+{
+ RC_SHARED = 0,
+ RC_PRIVATE = 1,
+ /**
+ * Must be last and match number of categories.
+ */
+ RC_MAX = 2
+};
+
+
+/**
+ * Request we should make. We keep this struct in memory per request,
+ * thus optimizing it is crucial for the overall memory consumption of
+ * the zone importer.
+ */
+struct Request
+{
+
+ /**
+ * Active requests are kept in a DLL.
+ */
+ struct Request *next;
+
+ /**
+ * Active requests are kept in a DLL.
+ */
+ struct Request *prev;
+
+ /**
+ * Socket used to make the request, NULL if not active.
+ */
+ struct GNUNET_GNS_LookupWithTldRequest *lr;
+
+ /**
+ * Hostname we are resolving, allocated at the end of
+ * this struct (optimizing memory consumption by reducing
+ * total number of allocations).
+ */
+ char *hostname;
+
+ /**
+ * While we are fetching the record, the value is set to the
+ * starting time of the GNS operation.
+ */
+ struct GNUNET_TIME_Absolute op_start_time;
+
+ /**
+ * Observed latency, set once we got a reply.
+ */
+ struct GNUNET_TIME_Relative latency;
+
+ /**
+ * Category of the request.
+ */
+ enum RequestCategory cat;
+
+};
+
+
+/**
+ * GNS handle.
+ */
+static struct GNUNET_GNS_Handle *gns;
+
+/**
+ * Number of lookups we performed overall per category.
+ */
+static unsigned int lookups[RC_MAX];
+
+/**
+ * Number of replies we got per category.
+ */
+static unsigned int replies[RC_MAX];
+
+/**
+ * Number of replies we got per category.
+ */
+static unsigned int failures[RC_MAX];
+
+/**
+ * Sum of the observed latencies of successful queries,
+ * per category.
+ */
+static struct GNUNET_TIME_Relative latency_sum[RC_MAX];
+
+/**
+ * Active requests are kept in a DLL.
+ */
+static struct Request *act_head;
+
+/**
+ * Active requests are kept in a DLL.
+ */
+static struct Request *act_tail;
+
+/**
+ * Completed successful requests are kept in a DLL.
+ */
+static struct Request *succ_head;
+
+/**
+ * Completed successful requests are kept in a DLL.
+ */
+static struct Request *succ_tail;
+
+/**
+ * Yet to be started requests are kept in a DLL.
+ */
+static struct Request *todo_head;
+
+/**
+ * Yet to be started requests are kept in a DLL.
+ */
+static struct Request *todo_tail;
+
+/**
+ * Main task.
+ */
+static struct GNUNET_SCHEDULER_Task *t;
+
+/**
+ * Delay between requests.
+ */
+static struct GNUNET_TIME_Relative request_delay;
+
+/**
+ * Timeout for requests.
+ */
+static struct GNUNET_TIME_Relative timeout;
+
+
+/**
+ * Free @a req and data structures reachable from it.
+ *
+ * @param req request to free
+ */
+static void
+free_request (struct Request *req)
+{
+ if (NULL != req->lr)
+ GNUNET_GNS_lookup_with_tld_cancel (req->lr);
+ GNUNET_free (req);
+}
+
+
+/**
+ * Function called with the result of a GNS resolution.
+ *
+ * @param cls closure with the `struct Request`
+ * @param gns_tld #GNUNET_YES if GNS lookup was attempted
+ * @param rd_count number of records in @a rd
+ * @param rd the records in reply
+ */
+static void
+process_result (void *cls,
+ int gns_tld,
+ uint32_t rd_count,
+ const struct GNUNET_GNSRECORD_Data *rd)
+{
+ struct Request *req = cls;
+
+ (void) gns_tld;
+ (void) rd_count;
+ (void) rd;
+ req->lr = NULL;
+ req->latency = GNUNET_TIME_absolute_get_duration (req->op_start_time);
+ GNUNET_CONTAINER_DLL_remove (act_head,
+ act_tail,
+ req);
+ GNUNET_CONTAINER_DLL_insert (succ_head,
+ succ_tail,
+ req);
+ replies[req->cat]++;
+ latency_sum[req->cat]
+ = GNUNET_TIME_relative_add (latency_sum[req->cat],
+ req->latency);
+}
+
+
+/**
+ * Process request from the queue.
+ *
+ * @param cls NULL
+ */
+static void
+process_queue (void *cls)
+{
+ struct Request *req;
+ struct GNUNET_TIME_Relative duration;
+
+ (void) cls;
+ t = NULL;
+ /* check for expired requests */
+ while (NULL != (req = act_head))
+ {
+ duration = GNUNET_TIME_absolute_get_duration (req->op_start_time);
+ if (duration.rel_value_us < timeout.rel_value_us)
+ break;
+ GNUNET_CONTAINER_DLL_remove (act_head,
+ act_tail,
+ req);
+ failures[req->cat]++;
+ free_request (req);
+ }
+ if (NULL == (req = todo_head))
+ {
+ struct GNUNET_TIME_Absolute at;
+
+ if (NULL == (req = act_head))
+ {
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+ at = GNUNET_TIME_absolute_add (req->op_start_time,
+ timeout);
+ t = GNUNET_SCHEDULER_add_at (at,
+ &process_queue,
+ NULL);
+ return;
+ }
+ GNUNET_CONTAINER_DLL_remove (todo_head,
+ todo_tail,
+ req);
+ GNUNET_CONTAINER_DLL_insert_tail (act_head,
+ act_tail,
+ req);
+ lookups[req->cat]++;
+ req->op_start_time = GNUNET_TIME_absolute_get ();
+ req->lr = GNUNET_GNS_lookup_with_tld (gns,
+ req->hostname,
+ GNUNET_GNSRECORD_TYPE_ANY,
+ GNUNET_GNS_LO_DEFAULT,
+ &process_result,
+ req);
+ t = GNUNET_SCHEDULER_add_delayed (request_delay,
+ &process_queue,
+ NULL);
+}
+
+
+/**
+ * Compare two requests by latency for qsort().
+ *
+ * @param c1 pointer to `struct Request *`
+ * @param c2 pointer to `struct Request *`
+ * @return -1 if c1<c2, 1 if c1>c2, 0 if c1==c2.
+ */
+static int
+compare_req (const void *c1,
+ const void *c2)
+{
+ const struct Request *r1 = *(void **) c1;
+ const struct Request *r2 = *(void **) c2;
+
+ if (r1->latency.rel_value_us < r2->latency.rel_value_us)
+ return -1;
+ if (r1->latency.rel_value_us > r2->latency.rel_value_us)
+ return 1;
+ return 0;
+}
+
+
+/**
+ * Output statistics, then clean up and terminate the process.
+ *
+ * @param cls NULL
+ */
+static void
+do_shutdown (void *cls)
+{
+ struct Request *req;
+ struct Request **ra[RC_MAX];
+ unsigned int rp[RC_MAX];
+
+ (void) cls;
+ for (enum RequestCategory rc = 0;rc < RC_MAX;rc++)
+ {
+ ra[rc] = GNUNET_new_array (replies[rc],
+ struct Request *);
+ rp[rc] = 0;
+ }
+ for (req = succ_head;NULL != req; req = req->next)
+ {
+ GNUNET_assert (rp[req->cat] < replies[req->cat]);
+ ra[req->cat][rp[req->cat]++] = req;
+ }
+ for (enum RequestCategory rc = 0;rc < RC_MAX;rc++)
+ {
+ unsigned int off;
+
+ fprintf (stdout,
+ "Category %u\n",
+ rc);
+ fprintf (stdout,
+ "\tlookups: %u replies: %u failures: %u\n",
+ lookups[rc],
+ replies[rc],
+ failures[rc]);
+ if (0 == rp[rc])
+ continue;
+ qsort (ra[rc],
+ rp[rc],
+ sizeof (struct Request *),
+ &compare_req);
+ latency_sum[rc] = GNUNET_TIME_relative_divide (latency_sum[rc],
+ replies[rc]);
+ fprintf (stdout,
+ "\taverage: %s\n",
+ GNUNET_STRINGS_relative_time_to_string (latency_sum[rc],
+ GNUNET_YES));
+ off = rp[rc] * 50 / 100;
+ fprintf (stdout,
+ "\tmedian(50): %s\n",
+ GNUNET_STRINGS_relative_time_to_string (ra[rc][off]->latency,
+ GNUNET_YES));
+ off = rp[rc] * 75 / 100;
+ fprintf (stdout,
+ "\tquantile(75): %s\n",
+ GNUNET_STRINGS_relative_time_to_string (ra[rc][off]->latency,
+ GNUNET_YES));
+ off = rp[rc] * 90 / 100;
+ fprintf (stdout,
+ "\tquantile(90): %s\n",
+ GNUNET_STRINGS_relative_time_to_string (ra[rc][off]->latency,
+ GNUNET_YES));
+ off = rp[rc] * 99 / 100;
+ fprintf (stdout,
+ "\tquantile(99): %s\n",
+ GNUNET_STRINGS_relative_time_to_string (ra[rc][off]->latency,
+ GNUNET_YES));
+ GNUNET_free (ra[rc]);
+ }
+ if (NULL != t)
+ {
+ GNUNET_SCHEDULER_cancel (t);
+ t = NULL;
+ }
+ while (NULL != (req = act_head))
+ {
+ GNUNET_CONTAINER_DLL_remove (act_head,
+ act_tail,
+ req);
+ free_request (req);
+ }
+ while (NULL != (req = succ_head))
+ {
+ GNUNET_CONTAINER_DLL_remove (succ_head,
+ succ_tail,
+ req);
+ free_request (req);
+ }
+ while (NULL != (req = todo_head))
+ {
+ GNUNET_CONTAINER_DLL_remove (todo_head,
+ todo_tail,
+ req);
+ free_request (req);
+ }
+ if (NULL != gns)
+ {
+ GNUNET_GNS_disconnect (gns);
+ gns = NULL;
+ }
+}
+
+
+/**
+ * Add @a hostname to the list of requests to be made.
+ *
+ * @param hostname name to resolve
+ * @param cat category of the @a hostname
+ */
+static void
+queue (const char *hostname,
+ enum RequestCategory cat)
+{
+ struct Request *req;
+ const char *dot;
+ size_t hlen;
+
+ dot = strchr (hostname,
+ (unsigned char) '.');
+ if (NULL == dot)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Refusing invalid hostname `%s' (lacks '.')\n",
+ hostname);
+ return;
+ }
+ hlen = strlen (hostname) + 1;
+ req = GNUNET_malloc (sizeof (struct Request) + hlen);
+ req->cat = cat;
+ req->hostname = (char *) &req[1];
+ GNUNET_memcpy (req->hostname,
+ hostname,
+ hlen);
+ GNUNET_CONTAINER_DLL_insert (todo_head,
+ todo_tail,
+ req);
+}
+
+
+/**
+ * Begin processing hostnames from stdin.
+ *
+ * @param cls NULL
+ */
+static void
+process_stdin (void *cls)
+{
+ static struct GNUNET_TIME_Absolute last;
+ static uint64_t idot;
+ unsigned int cat;
+ char hn[256];
+ char in[270];
+
+ (void) cls;
+ t = NULL;
+ while (NULL !=
+ fgets (in,
+ sizeof (in),
+ stdin))
+ {
+ if (strlen(in) > 0)
+ hn[strlen(in)-1] = '\0'; /* eat newline */
+ if ( (2 != sscanf (in,
+ "%u %255s",
+ &cat,
+ hn)) ||
+ (cat >= RC_MAX) )
+ {
+ fprintf (stderr,
+ "Malformed input line `%s', skipping\n",
+ in);
+ continue;
+ }
+ if (0 == idot)
+ last = GNUNET_TIME_absolute_get ();
+ idot++;
+ if (0 == idot % 100000)
+ {
+ struct GNUNET_TIME_Relative delta;
+
+ delta = GNUNET_TIME_absolute_get_duration (last);
+ last = GNUNET_TIME_absolute_get ();
+ fprintf (stderr,
+ "Read 10000 domain names in %s\n",
+ GNUNET_STRINGS_relative_time_to_string (delta,
+ GNUNET_YES));
+ }
+ queue (hn,
+ (enum RequestCategory) cat);
+ }
+ fprintf (stderr,
+ "Done reading %llu domain names\n",
+ (unsigned long long) idot);
+ t = GNUNET_SCHEDULER_add_now (&process_queue,
+ NULL);
+}
+
+
+/**
+ * Process requests from the queue, then if the queue is
+ * not empty, try again.
+ *
+ * @param cls NULL
+ * @param args remaining command-line arguments
+ * @param cfgfile name of the configuration file used (for saving, can be NULL!)
+ * @param cfg configuration
+ */
+static void
+run (void *cls,
+ char *const *args,
+ const char *cfgfile,
+ const struct GNUNET_CONFIGURATION_Handle *cfg)
+{
+ (void) cls;
+ (void) args;
+ (void) cfgfile;
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
+ NULL);
+ gns = GNUNET_GNS_connect (cfg);
+ if (NULL == gns)
+ {
+ GNUNET_break (0);
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+ t = GNUNET_SCHEDULER_add_now (&process_stdin,
+ NULL);
+}
+
+
+/**
+ * Call with list of names with numeric category to query.
+ *
+ * @param argc unused
+ * @param argv unused
+ * @return 0 on success
+ */
+int
+main (int argc,
+ char *const*argv)
+{
+ int ret = 0;
+ struct GNUNET_GETOPT_CommandLineOption options[] = {
+ GNUNET_GETOPT_option_relative_time ('d',
+ "delay",
+ "RELATIVETIME",
+ gettext_noop ("how long to wait between queries"),
+ &request_delay),
+ GNUNET_GETOPT_option_relative_time ('t',
+ "timeout",
+ "RELATIVETIME",
+ gettext_noop ("how long to wait for an answer"),
+ &timeout),
+ GNUNET_GETOPT_OPTION_END
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_STRINGS_get_utf8_args (argc, argv,
+ &argc, &argv))
+ return 2;
+ timeout = DEF_TIMEOUT;
+ request_delay = DEF_REQUEST_DELAY;
+ if (GNUNET_OK !=
+ GNUNET_PROGRAM_run (argc,
+ argv,
+ "gnunet-gns-benchmark",
+ "resolve GNS names and measure performance",
+ options,
+ &run,
+ NULL))
+ ret = 1;
+ GNUNET_free ((void*) argv);
+ return ret;
+}
+
+/* end of gnunet-gns-benchmark.c */
* Handle for DNS resolution of the DNS nameserver.
*/
struct GNUNET_RESOLVER_RequestHandle *dns_rh;
+
+ /**
+ * How many results did we get?
+ */
+ unsigned int num_results;
};
res->data_size = data_size;
res->record_type = record_type;
res->data = &res[1];
- GNUNET_memcpy (&res[1], data, data_size);
+ GNUNET_memcpy (&res[1],
+ data,
+ data_size);
GNUNET_CONTAINER_DLL_insert (rh->dns_result_head,
rh->dns_result_tail,
res);
{
struct Gns2DnsPending *gp = cls;
struct AuthorityChain *ac = gp->ac;
+ struct sockaddr_storage ss;
+ struct sockaddr_in *v4;
+ struct sockaddr_in6 *v6;
- GNUNET_RESOLVER_request_cancel (gp->dns_rh);
- GNUNET_CONTAINER_DLL_remove (ac->authority_info.dns_authority.gp_head,
- ac->authority_info.dns_authority.gp_tail,
- gp);
- GNUNET_free (gp);
if (NULL == addr)
{
- /* DNS resolution failed */
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Failed to use DNS to resolve name of DNS resolver\n");
+ /* DNS resolution finished */
+ if (0 == gp->num_results)
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failed to use DNS to resolve name of DNS resolver\n");
+ GNUNET_CONTAINER_DLL_remove (ac->authority_info.dns_authority.gp_head,
+ ac->authority_info.dns_authority.gp_tail,
+ gp);
+ GNUNET_free (gp);
+ continue_with_gns2dns (ac);
+ return;
}
- else
+ GNUNET_memcpy (&ss,
+ addr,
+ addrlen);
+ switch (ss.ss_family)
{
- if (GNUNET_OK ==
- GNUNET_DNSSTUB_add_dns_sa (ac->authority_info.dns_authority.dns_handle,
- addr))
- ac->authority_info.dns_authority.found = GNUNET_YES;
+ case AF_INET:
+ v4 = (struct sockaddr_in *) &ss;
+ v4->sin_port = htons (53);
+ gp->num_results++;
+ break;
+ case AF_INET6:
+ v6 = (struct sockaddr_in6 *) &ss;
+ v6->sin6_port = htons (53);
+ gp->num_results++;
+ break;
+ default:
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Unsupported AF %d\n",
+ ss.ss_family);
+ return;
}
- continue_with_gns2dns (ac);
+ if (GNUNET_OK ==
+ GNUNET_DNSSTUB_add_dns_sa (ac->authority_info.dns_authority.dns_handle,
+ (struct sockaddr *) &ss))
+ ac->authority_info.dns_authority.found = GNUNET_YES;
}
('\0' != cdata[data_size - 1]) )
return NULL; /* malformed */
/* need to memcpy for alignment */
- memcpy (&vpn,
- data,
- sizeof (vpn));
+ GNUNET_memcpy (&vpn,
+ data,
+ sizeof (vpn));
GNUNET_asprintf (&vpn_str,
"%u %s %s",
(unsigned int) ntohs (vpn.proto),
cdata = data;
if (data_size < sizeof (struct GNUNET_GNSRECORD_BoxRecord))
return NULL; /* malformed */
- memcpy (&box,
- data,
- sizeof (box));
+ GNUNET_memcpy (&box,
+ data,
+ sizeof (box));
rt = ntohl (box.record_type);
ival = GNUNET_GNSRECORD_value_to_string (rt,
&cdata[sizeof (box)],
--- /dev/null
+#!/bin/bash
+trap "gnunet-arm -e -c test_gns_lookup.conf" SIGINT
+
+LOCATION=$(which gnunet-config)
+if [ -z $LOCATION ]
+then
+ LOCATION="gnunet-config"
+fi
+$LOCATION --version 1> /dev/null
+if test $? != 0
+then
+ echo "GNUnet command line tools cannot be found, check environmental variables PATH and GNUNET_PREFIX"
+ exit 77
+fi
+
+which timeout &> /dev/null && DO_TIMEOUT="timeout 5"
+rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
+
+TEST_IP="127.0.0.1"
+MY_EGO="myego"
+gnunet-arm -s -c test_gns_lookup.conf
+gnunet-identity -C delegatedego -c test_gns_lookup.conf
+DELEGATED_PKEY=$(gnunet-identity -d -c test_gns_lookup.conf | grep delegatedego | awk '{print $3}')
+gnunet-identity -C $MY_EGO -c test_gns_lookup.conf
+gnunet-namestore -p -z $MY_EGO -a -n b -t PKEY -V $DELEGATED_PKEY -e never -c test_gns_lookup.conf
+gnunet-namestore -p -z delegatedego -a -n '@' -t A -V $TEST_IP -e never -c test_gns_lookup.conf
+RES_IP=`$DO_TIMEOUT gnunet-gns --raw -u b.$MY_EGO -t A -c test_gns_lookup.conf`
+gnunet-namestore -z $MY_EGO -d -n b -t PKEY -V $DELEGATED_PKEY -e never -c test_gns_lookup.conf
+gnunet-namestore -z delegatedego -d -n '@' -t A -V $TEST_IP -e never -c test_gns_lookup.conf
+gnunet-arm -e -c test_gns_lookup.conf
+rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
+
+if [ "$RES_IP" == "$TEST_IP" ]
+then
+ exit 0
+else
+ echo "Failed to resolve to proper IP, got $RES_IP."
+ exit 1
+fi
fi
-rm -rf /tmp/test-gnunet-gns-peer-1/
+rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
TEST_IP_PLUS="127.0.0.1"
TEST_IP_DNS="131.159.74.67"
gnunet-namestore -p -z $MY_EGO -d -n $TEST_RECORD_CNAME_SERVER -t A -V $TEST_IP_PLUS -e never -c test_gns_lookup.conf
gnunet-identity -D $MY_EGO -c test_gns_lookup.conf
gnunet-arm -e -c test_gns_lookup.conf
-rm -rf /tmp/test-gnunet-gns-peer-1/
+rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
if [ "$RES_CNAME_RAW" == "server.$TESTEGOZONE" ]
then
exit 77
fi
-rm -rf /tmp/test-gnunet-gns-peer-1/
+rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
MY_EGO="myego"
OTHER_EGO="delegatedego"
FINAL_LABEL="www"
gnunet-namestore -z $OTHER_EGO -d -n $FINAL_LABEL -t A -V $TEST_IP -e never -c test_gns_lookup.conf
gnunet-arm -e -c test_gns_lookup.conf
-rm -rf /tmp/test-gnunet-gns-peer-1/
+rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
if [ "$RES_IP" == "$TEST_IP" ]
then
MY_EGO="myego"
OTHER_EGO="delegatedego"
-
+rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
gnunet-arm -s -c test_gns_lookup.conf
gnunet-identity -C $OTHER_EGO -c test_gns_lookup.conf
DELEGATED_PKEY=$(gnunet-identity -d -c test_gns_lookup.conf | grep $OTHER_EGO | awk '{print $3}')
RES_IP=`$DO_TIMEOUT gnunet-gns --raw -u www.b.$MY_EGO -t A -c test_gns_lookup.conf`
gnunet-namestore -z $MY_EGO -d -n b -t PKEY -V $DELEGATED_PKEY -e never -c test_gns_lookup.conf
gnunet-arm -e -c test_gns_lookup.conf
-rm -rf /tmp/test-gnunet-gns-peer-1/
+rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
if [ "$RES_IP" == "$TEST_IP" ]
then
exit 77
fi
-rm -r rm -rf /tmp/test-gnunet-gns-peer-1/
+rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
# IP address of 'uk.gnunet.org'
TEST_IP_ALT2="81.187.252.184"
# IP address of 'www.gnunet.org'
gnunet-namestore -z $MY_EGO -d -n $TEST_RECORD_NAME -t GNS2DNS -V $TEST_RECORD_GNS2DNS -e never -c test_gns_lookup.conf
gnunet-identity -D $MY_EGO -c test_gns_lookup.conf
gnunet-arm -e -c test_gns_lookup.conf
-rm -rf /tmp/test-gnunet-gns-peer-1/
+rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
ret=0
if [ "$RES_IP" == "$TEST_IP" ]
gnunet-namestore -z $MY_EGO -d -n www -t AAAA -V $TEST_IP -e never -c test_gns_lookup.conf
gnunet-identity -D $MY_EGO -c test_gns_lookup.conf
gnunet-arm -e -c test_gns_lookup.conf
-rm -rf /tmp/test-gnunet-gns-peer-1/
+rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
if [ "$RES_IP" == "$TEST_IP" ]
then
exit 77
fi
-rm -rf /tmp/test-gnunet-gns-peer-1/
+rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
which timeout &> /dev/null && DO_TIMEOUT="timeout 5"
MY_EGO="myego"
gnunet-namestore -z $MY_EGO -d -n www -t MX -V "$TEST_MX" -e never -c test_gns_lookup.conf
gnunet-identity -D $MY_EGO -c test_gns_lookup.conf
gnunet-arm -e -c test_gns_lookup.conf
-rm -rf /tmp/test-gnunet-gns-peer-1/
+rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
if [ "$RES_MX" == "$WANT_MX" ]
then
+++ /dev/null
-#!/bin/bash
-trap "gnunet-arm -e -c test_gns_lookup.conf" SIGINT
-
-LOCATION=$(which gnunet-config)
-if [ -z $LOCATION ]
-then
- LOCATION="gnunet-config"
-fi
-$LOCATION --version 1> /dev/null
-if test $? != 0
-then
- echo "GNUnet command line tools cannot be found, check environmental variables PATH and GNUNET_PREFIX"
- exit 77
-fi
-
-which timeout &> /dev/null && DO_TIMEOUT="timeout 5"
-rm -rf /tmp/test-gnunet-gns-peer-1/
-
-TEST_IP="127.0.0.1"
-MY_EGO="myego"
-gnunet-arm -s -c test_gns_lookup.conf
-gnunet-identity -C delegatedego -c test_gns_lookup.conf
-DELEGATED_PKEY=$(gnunet-identity -d -c test_gns_lookup.conf | grep delegatedego | awk '{print $3}')
-gnunet-identity -C $MY_EGO -c test_gns_lookup.conf
-gnunet-namestore -p -z $MY_EGO -a -n b -t PKEY -V $DELEGATED_PKEY -e never -c test_gns_lookup.conf
-gnunet-namestore -p -z delegatedego -a -n '+' -t A -V $TEST_IP -e never -c test_gns_lookup.conf
-RES_IP=`$DO_TIMEOUT gnunet-gns --raw -u b.$MY_EGO -t A -c test_gns_lookup.conf`
-gnunet-namestore -z $MY_EGO -d -n b -t PKEY -V $DELEGATED_PKEY -e never -c test_gns_lookup.conf
-gnunet-namestore -z delegatedego -d -n '+' -t A -V $TEST_IP -e never -c test_gns_lookup.conf
-gnunet-arm -e -c test_gns_lookup.conf
-rm -rf /tmp/test-gnunet-gns-peer-1/
-
-if [ "$RES_IP" == "$TEST_IP" ]
-then
- exit 0
-else
- echo "Failed to resolve to proper IP, got $RES_IP."
- exit 1
-fi
OTHER_EGO="delegatedego"
-rm -rf /tmp/test-gnunet-gns-peer-1/
+rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
which timeout &> /dev/null && DO_TIMEOUT="timeout 5"
TEST_IP="127.0.0.1"
gnunet-arm -s -c test_gns_lookup.conf
gnunet-identity -D $MY_EGO -c test_gns_lookup.conf
gnunet-identity -D $OTHER_EGO -c test_gns_lookup.conf
gnunet-arm -e -c test_gns_lookup.conf
-rm -rf /tmp/test-gnunet-gns-peer-1/
+rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
if [ "$RES_IP" == "$TEST_IP" ]
then
MY_EGO="myego"
OTHER_EGO="delegatedego"
-rm -rf /tmp/test-gnunet-gns-peer-1/
+rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
which timeout &> /dev/null && DO_TIMEOUT="timeout 5"
TEST_IP="127.0.0.1"
gnunet-arm -s -c test_gns_lookup.conf
gnunet-identity -D $MY_EGO -c test_gns_lookup.conf
gnunet-identity -D $OTHER_EGO -c test_gns_lookup.conf
gnunet-arm -e -c test_gns_lookup.conf
-rm -rf /tmp/test-gnunet-gns-peer-1/
+rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
if [ "$RES_IP_EXP" == "$TEST_IP" ]
then
exit 77
fi
-rm -rf /tmp/test-gnunet-gns-peer-1/
+rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
MY_EGO="myego"
OTHER_EGO="delegatedego"
TEST_IP="127.0.0.1"
gnunet-namestore -z $MY_EGO -d -n b -t PKEY -V $DELEGATED_PKEY -e never -c test_gns_lookup.conf
gnunet-namestore -z $OTHER_EGO -d -n www -t A -V $TEST_IP -e never -c test_gns_lookup.conf
gnunet-arm -e -c test_gns_lookup.conf
-rm -rf /tmp/test-gnunet-gns-peer-1/
+rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
if [ "$RES_IP" != "$TEST_IP" ]
then
which timeout &> /dev/null && DO_TIMEOUT="timeout 5"
-rm -rf /tmp/test-gnunet-gns-peer-1/
+rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
MY_EGO="myego"
TEST_DOMAIN="homepage.$MY_EGO"
# some public DNS resolver we can use
gnunet-namestore -z $MY_EGO -d -n $TEST_RECORD_NAME -t GNS2DNS -V ${TEST_RECORD_GNS2DNS}@${TEST_IP_GNS2DNS} -e never -c test_gns_lookup.conf &> /dev/null
gnunet-identity -D $MY_EGO -c test_gns_lookup.conf
gnunet-arm -e -c test_gns_lookup.conf
-rm -rf /tmp/test-gnunet-gns-peer-1/
+rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
if [ "x$RES_SOA" != "x" ]
then
exit 77
fi
-rm -rf /tmp/test-gnunet-gns-peer-1/
+rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
which timeout &> /dev/null && DO_TIMEOUT="timeout 30"
TEST_TXT="GNS powered txt record data"
MY_EGO="myego"
gnunet-namestore -z $MY_EGO -d -n $LABEL -t TXT -V "$TEST_TXT" -e never -c test_gns_lookup.conf
gnunet-identity -D $MY_EGO -c test_gns_lookup.conf
gnunet-arm -e -c test_gns_lookup.conf
-rm -rf /tmp/test-gnunet-gns-peer-1/
+rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
if [ "$RES_TXT" == "$TEST_TXT" ]
then
exit 77
fi
-rm -rf /tmp/test-gnunet-gns-peer-1/
+rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
TEST_IP="127.0.0.1"
gnunet-arm -s -c test_gns_lookup.conf
gnunet-namestore -z testego -d -n b -t PKEY -V $DELEGATED_PKEY -e never -c test_gns_lookup.conf
gnunet-namestore -z delegatedego -d -n www -t A -V $TEST_IP -e never -c test_gns_lookup.conf
gnunet-arm -e -c test_gns_lookup.conf
-rm -rf /tmp/test-gnunet-gns-peer-1/
+rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
if [ "$RES_IP" == "$TEST_IP" ]
then
test_gnsrecord_crypto
test_gnsrecord_serialization
zonefiles
+perf_gnsrecord_crypto
check_PROGRAMS = \
test_gnsrecord_crypto \
test_gnsrecord_serialization \
- test_gnsrecord_block_expiration
+ test_gnsrecord_block_expiration \
+ perf_gnsrecord_crypto
if ENABLE_TEST_RUN
AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset XDG_CONFIG_HOME;
libgnunetgnsrecord.la \
$(top_builddir)/src/util/libgnunetutil.la
+
+perf_gnsrecord_crypto_SOURCES = \
+ perf_gnsrecord_crypto.c
+perf_gnsrecord_crypto_LDADD = \
+ $(top_builddir)/src/testing/libgnunettesting.la \
+ libgnunetgnsrecord.la \
+ $(top_builddir)/src/util/libgnunetutil.la
void __attribute__ ((destructor))
GNSRECORD_fini ()
{
- unsigned int i;
struct Plugin *plugin;
- for (i = 0; i < num_plugins; i++)
+ for (unsigned int i = 0; i < num_plugins; i++)
{
plugin = gns_plugins[i];
GNUNET_break (NULL ==
const void *data,
size_t data_size)
{
- unsigned int i;
struct Plugin *plugin;
char *ret;
init ();
- for (i = 0; i < num_plugins; i++)
+ for (unsigned int i = 0; i < num_plugins; i++)
{
plugin = gns_plugins[i];
if (NULL != (ret = plugin->api->value_to_string (plugin->api->cls,
void **data,
size_t *data_size)
{
- unsigned int i;
struct Plugin *plugin;
init ();
- for (i = 0; i < num_plugins; i++)
+ for (unsigned int i = 0; i < num_plugins; i++)
{
plugin = gns_plugins[i];
if (GNUNET_OK == plugin->api->string_to_value (plugin->api->cls,
uint32_t
GNUNET_GNSRECORD_typename_to_number (const char *dns_typename)
{
- unsigned int i;
struct Plugin *plugin;
uint32_t ret;
"ANY"))
return GNUNET_GNSRECORD_TYPE_ANY;
init ();
- for (i = 0; i < num_plugins; i++)
+ for (unsigned int i = 0; i < num_plugins; i++)
{
plugin = gns_plugins[i];
if (UINT32_MAX != (ret = plugin->api->typename_to_number (plugin->api->cls,
const char *
GNUNET_GNSRECORD_number_to_typename (uint32_t type)
{
- unsigned int i;
struct Plugin *plugin;
const char * ret;
if (GNUNET_GNSRECORD_TYPE_ANY == type)
return "ANY";
init ();
- for (i = 0; i < num_plugins; i++)
+ for (unsigned int i = 0; i < num_plugins; i++)
{
plugin = gns_plugins[i];
if (NULL != (ret = plugin->api->number_to_typename (plugin->api->cls,
/*
This file is part of GNUnet.
- Copyright (C) 2009-2013 GNUnet e.V.
+ Copyright (C) 2009-2013, 2018 GNUnet e.V.
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
struct GNUNET_CRYPTO_EcdsaPrivateKey *dkey;
struct GNUNET_CRYPTO_SymmetricInitializationVector iv;
struct GNUNET_CRYPTO_SymmetricSessionKey skey;
- struct GNUNET_GNSRECORD_Data rdc[rd_count];
+ struct GNUNET_GNSRECORD_Data rdc[GNUNET_NZL(rd_count)];
uint32_t rd_count_nbo;
struct GNUNET_TIME_Absolute now;
GNUNET_CRYPTO_ecdsa_key_get_public (key,
&line->pkey);
}
+#undef CSIZE
return block_create (key,
&line->pkey,
expire,
GNUNET_break_op (0);
return GNUNET_SYSERR;
}
- derive_block_aes_key (&iv, &skey, label, zone_key);
+ derive_block_aes_key (&iv,
+ &skey,
+ label,
+ zone_key);
{
char payload[payload_len];
uint32_t rd_count;
GNUNET_break (payload_len ==
GNUNET_CRYPTO_symmetric_decrypt (&block[1], payload_len,
- &skey, &iv,
- payload));
+ &skey, &iv,
+ payload));
GNUNET_memcpy (&rd_count,
- payload,
- sizeof (uint32_t));
+ payload,
+ sizeof (uint32_t));
rd_count = ntohl (rd_count);
if (rd_count > 2048)
{
return GNUNET_SYSERR;
}
{
- struct GNUNET_GNSRECORD_Data rd[rd_count];
+ struct GNUNET_GNSRECORD_Data rd[GNUNET_NZL(rd_count)];
unsigned int j;
struct GNUNET_TIME_Absolute now;
continue;
if (rd[i].expiration_time < now.abs_value_us)
include_record = GNUNET_NO; /* Shadow record is expired */
- if ((rd[k].record_type == rd[i].record_type)
- && (rd[k].expiration_time >= now.abs_value_us)
- && (0 == (rd[k].flags & GNUNET_GNSRECORD_RF_SHADOW_RECORD)))
+ if ( (rd[k].record_type == rd[i].record_type) &&
+ (rd[k].expiration_time >= now.abs_value_us) &&
+ (0 == (rd[k].flags & GNUNET_GNSRECORD_RF_SHADOW_RECORD)) )
+ {
include_record = GNUNET_NO; /* We have a non-expired, non-shadow record of the same type */
+ break;
+ }
}
if (GNUNET_YES == include_record)
{
GNUNET_GNSRECORD_records_get_size (unsigned int rd_count,
const struct GNUNET_GNSRECORD_Data *rd)
{
- unsigned int i;
size_t ret;
ret = sizeof (struct NetworkRecord) * rd_count;
- for (i=0;i<rd_count;i++)
+ for (unsigned int i=0;i<rd_count;i++)
{
GNUNET_assert ((ret + rd[i].data_size) >= ret);
ret += rd[i].data_size;
char *dest)
{
struct NetworkRecord rec;
- unsigned int i;
size_t off;
off = 0;
- for (i=0;i<rd_count;i++)
+ for (unsigned int i=0;i<rd_count;i++)
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Serializing record %u with flags %d and expiration time %llu\n",
rec.record_type = htonl (rd[i].record_type);
rec.flags = htonl (rd[i].flags);
if (off + sizeof (rec) > dest_size)
+ {
+ GNUNET_break (0);
return -1;
+ }
GNUNET_memcpy (&dest[off],
&rec,
sizeof (rec));
off += sizeof (rec);
if (off + rd[i].data_size > dest_size)
+ {
+ GNUNET_break (0);
return -1;
+ }
GNUNET_memcpy (&dest[off],
rd[i].data,
rd[i].data_size);
off += rd[i].data_size;
+#if GNUNET_EXTRA_LOGGING
+ {
+ char *str;
+
+ str = GNUNET_GNSRECORD_value_to_string (rd[i].record_type,
+ rd[i].data,
+ rd[i].data_size);
+ if (NULL == str)
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ GNUNET_free (str);
+ }
+#endif
}
return off;
}
struct GNUNET_GNSRECORD_Data *dest)
{
struct NetworkRecord rec;
- unsigned int i;
size_t off;
off = 0;
- for (i=0;i<rd_count;i++)
+ for (unsigned int i=0;i<rd_count;i++)
{
if (off + sizeof (rec) > len)
+ {
+ GNUNET_break_op (0);
return GNUNET_SYSERR;
- GNUNET_memcpy (&rec, &src[off], sizeof (rec));
+ }
+ GNUNET_memcpy (&rec,
+ &src[off],
+ sizeof (rec));
dest[i].expiration_time = GNUNET_ntohll (rec.expiration_time);
dest[i].data_size = ntohl ((uint32_t) rec.data_size);
dest[i].record_type = ntohl (rec.record_type);
dest[i].flags = ntohl (rec.flags);
off += sizeof (rec);
if (off + dest[i].data_size > len)
+ {
+ GNUNET_break_op (0);
return GNUNET_SYSERR;
+ }
dest[i].data = &src[off];
off += dest[i].data_size;
+#if GNUNET_EXTRA_LOGGING
+ {
+ char *str;
+
+ str = GNUNET_GNSRECORD_value_to_string (dest[i].record_type,
+ dest[i].data,
+ dest[i].data_size);
+ if (NULL == str)
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ GNUNET_free (str);
+ }
+#endif
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Deserialized record %u with flags %d and expiration time %llu\n",
i,
--- /dev/null
+/*
+ This file is part of GNUnet.
+ Copyright (C) 2018 GNUnet e.V.
+
+ GNUnet is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3, or (at your
+ option) any later version.
+
+ GNUnet is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GNUnet; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+/**
+ * @file gnsrecord/test_gnsrecord_crypto.c
+ * @brief testcase for block creation, verification and decryption
+ */
+#include "platform.h"
+#include "gnunet_util_lib.h"
+#include "gnunet_gnsrecord_lib.h"
+
+#define ROUNDS 1000
+
+#define RECORDS 5
+
+#define TEST_RECORD_TYPE 1234
+
+#define TEST_RECORD_DATALEN 123
+
+#define TEST_RECORD_DATA 'a'
+
+#define TEST_REMOVE_RECORD_TYPE 4321
+
+#define TEST_REMOVE_RECORD_DATALEN 255
+
+#define TEST_REMOVE_RECORD_DATA 'b'
+
+
+static struct GNUNET_GNSRECORD_Data *
+create_record (int count)
+{
+ struct GNUNET_GNSRECORD_Data *rd;
+
+ rd = GNUNET_new_array (count,
+ struct GNUNET_GNSRECORD_Data);
+ for (unsigned int c = 0; c < count; c++)
+ {
+ rd[c].expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000;
+ rd[c].record_type = TEST_RECORD_TYPE;
+ rd[c].data_size = TEST_RECORD_DATALEN;
+ rd[c].data = GNUNET_malloc(TEST_RECORD_DATALEN);
+ memset ((char *) rd[c].data, TEST_RECORD_DATA, TEST_RECORD_DATALEN);
+ }
+ return rd;
+}
+
+
+static void
+run (void *cls,
+ char *const *args,
+ const char *cfgfile,
+ const struct GNUNET_CONFIGURATION_Handle *cfg)
+{
+ struct GNUNET_GNSRECORD_Block *block;
+ struct GNUNET_HashCode query;
+ struct GNUNET_GNSRECORD_Data *s_rd;
+ const char *s_name;
+ struct GNUNET_TIME_Absolute start_time;
+ struct GNUNET_CRYPTO_EcdsaPrivateKey * privkey;
+ struct GNUNET_TIME_Absolute expire;
+
+ (void) cls;
+ (void) args;
+ (void) cfgfile;
+ (void) cfg;
+ expire = GNUNET_TIME_absolute_get();
+ privkey = GNUNET_CRYPTO_ecdsa_key_create ();
+ GNUNET_assert (NULL != privkey);
+
+ /* test block creation */
+ s_name = "DUMMY.dummy.gnunet";
+ s_rd = create_record (RECORDS);
+ start_time = GNUNET_TIME_absolute_get ();
+ for (unsigned int i=0;i<ROUNDS;i++)
+ {
+ GNUNET_assert (NULL != (block =
+ GNUNET_GNSRECORD_block_create2 (privkey,
+ expire,
+ s_name,
+ s_rd,
+ RECORDS)));
+ GNUNET_GNSRECORD_query_from_private_key (privkey,
+ s_name,
+ &query);
+ GNUNET_free (block);
+ }
+ fprintf (stderr,
+ "Took %s to produce %u GNS blocks for the DHT\n",
+ GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start_time),
+ GNUNET_YES),
+ ROUNDS);
+ for (unsigned int i=0;i<RECORDS;i++)
+ GNUNET_free ((void *) s_rd[i].data);
+ GNUNET_free (s_rd);
+ GNUNET_free (privkey);
+}
+
+
+int
+main (int argc, char *argv[])
+{
+ static char *const argvx[] = {
+ "perf-gnsrecord-crypto",
+ NULL
+ };
+ static struct GNUNET_GETOPT_CommandLineOption options[] = {
+ GNUNET_GETOPT_OPTION_END
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
+ argvx,
+ "perf-gnsrecord-crypto",
+ "nohelp", options,
+ &run,
+ NULL))
+ return 1;
+ return 0;
+}
+
+/* end of test_gnsrecord_crypto.c */
{
struct GNUNET_GNSRECORD_Data *rd;
- rd = GNUNET_malloc (count * sizeof (struct GNUNET_GNSRECORD_Data));
+ rd = GNUNET_new_array (count, struct GNUNET_GNSRECORD_Data);
for (unsigned int c = 0; c < count; c++)
{
rd[c].expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000;
struct GNUNET_CRYPTO_EcdsaPublicKey pubkey;
struct GNUNET_HashCode query_pub;
struct GNUNET_HashCode query_priv;
+ struct GNUNET_TIME_Absolute expire = GNUNET_TIME_absolute_get();
privkey = GNUNET_CRYPTO_ecdsa_key_create ();
GNUNET_assert (NULL != privkey);
- struct GNUNET_TIME_Absolute expire = GNUNET_TIME_absolute_get();
-
/* get public key */
GNUNET_CRYPTO_ecdsa_key_get_public (privkey,
&pubkey);
&rd_decrypt_cb,
s_name));
GNUNET_free (block);
+ GNUNET_free (privkey);
}
{
int ret;
- GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-1");
- GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-2");
- GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist");
+ GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_peer1.conf",
+ "GNUNET_TEST_HOME");
+ GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_peer2.conf",
+ "GNUNET_TEST_HOME");
+ GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_data.conf",
+ "GNUNET_TEST_HOME");
GNUNET_log_setup ("test-gnunet-daemon-hostlist",
"WARNING",
NULL);
ret = check ();
- GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-1");
- GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-2");
- GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist");
+ GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_peer1.conf",
+ "GNUNET_TEST_HOME");
+ GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_peer2.conf",
+ "GNUNET_TEST_HOME");
+ GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_data.conf",
+ "GNUNET_TEST_HOME");
return ret;
}
{
int ret;
- GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-1");
- GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-2");
+ GNUNET_DISK_purge_cfg_dir ("test_learning_learn_peer.conf",
+ "GNUNET_TEST_HOME");
+ GNUNET_DISK_purge_cfg_dir ("test_learning_adv_peer.conf",
+ "GNUNET_TEST_HOME");
GNUNET_log_setup ("test-gnunet-daemon-hostlist",
"WARNING",
NULL);
ret = check ();
- GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-1");
- GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-2");
+ GNUNET_DISK_purge_cfg_dir ("test_learning_learn_peer.conf",
+ "GNUNET_TEST_HOME");
+ GNUNET_DISK_purge_cfg_dir ("test_learning_adv_peer.conf",
+ "GNUNET_TEST_HOME");
if (GNUNET_YES ==
GNUNET_DISK_file_test ("hostlists_learn_peer.file"))
{
GNUNET_GETOPT_OPTION_END
};
- GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-1");
- GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-2");
- GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-3");
+ GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_peer1.conf",
+ "GNUNET_TEST_HOME");
+ GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_peer2.conf",
+ "GNUNET_TEST_HOME");
+ GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_data.conf",
+ "GNUNET_TEST_HOME");
GNUNET_log_setup ("test-gnunet-daemon-hostlist",
"WARNING",
NULL);
"%s",
".\n");
}
- GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-1");
- GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-2");
- GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-3");
+ GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_peer1.conf",
+ "GNUNET_TEST_HOME");
+ GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_peer2.conf",
+ "GNUNET_TEST_HOME");
+ GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_data.conf",
+ "GNUNET_TEST_HOME");
return ok;
}
* Attribute result callback
*/
GNUNET_IDENTITY_PROVIDER_AttributeResult ar_cb;
-
+
/**
* Revocation result callback
*/
it->finish_cb (it->finish_cb_cls);
free_it (it);
}
- if (NULL != op)
+ if (NULL != op)
{
if (NULL != op->ar_cb)
op->ar_cb (op->cls,
/**
- * List all attributes for a local identity.
+ * List all attributes for a local identity.
* This MUST lock the `struct GNUNET_IDENTITY_PROVIDER_Handle`
* for any other calls than #GNUNET_IDENTITY_PROVIDER_get_attributes_next() and
* #GNUNET_IDENTITY_PROVIDER_get_attributes_stop. @a proc will be called once
GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_REVOKE_TICKET);
msg->id = htonl (rid);
msg->identity = *identity;
- memcpy (&msg[1],
- ticket,
- sizeof (struct GNUNET_IDENTITY_PROVIDER_Ticket));
+ GNUNET_memcpy (&msg[1],
+ ticket,
+ sizeof (struct GNUNET_IDENTITY_PROVIDER_Ticket));
if (NULL == h->mq)
op->env = env;
else
GNUNET_DISK_directory_remove (const char *filename);
+/**
+ * Remove the directory given under @a option in
+ * section [PATHS] in configuration under @a cfg_filename
+ *
+ * @param cfg_filename configuration file to parse
+ * @param option option with the dir name to purge
+ */
+void
+GNUNET_DISK_purge_cfg_dir (const char *cfg_filename,
+ const char *option);
+
+
/**
* Implementation of "mkdir -p"
*
GNUNET_SQ_cleanup_result (struct GNUNET_SQ_ResultSpec *rs);
+
+/* ******************** sq_prepare.c functions ************** */
+
+
+/**
+ * Information needed to run a list of SQL statements using
+ * #GNUNET_SQ_exec_statements().
+ */
+struct GNUNET_SQ_PrepareStatement {
+
+ /**
+ * Actual SQL statement.
+ */
+ const char *sql;
+
+ /**
+ * Where to store handle?
+ */
+ sqlite3_stmt **pstmt;
+
+};
+
+
+/**
+ * Terminator for executable statement list.
+ */
+#define GNUNET_SQ_PREPARE_END { NULL, NULL }
+
+
+/**
+ * Create a `struct GNUNET_SQ_PrepareStatement`
+ *
+ * @param sql actual SQL statement
+ * @param pstmt where to store the handle
+ * @return initialized struct
+ */
+struct GNUNET_SQ_PrepareStatement
+GNUNET_SQ_make_prepare (const char *sql,
+ sqlite3_stmt **pstmt);
+
+
+
+/**
+ * Prepare all statements given in the (NULL,NULL)-terminated
+ * array at @a ps
+ *
+ * @param dbh database handle
+ * @param ps array of statements to prepare
+ * @return #GNUNET_OK on success
+ */
+int
+GNUNET_SQ_prepare (sqlite3 *dbh,
+ const struct GNUNET_SQ_PrepareStatement *ps);
+
+
+/* ******************** sq_exec.c functions ************** */
+
+
+/**
+ * Information needed to run a list of SQL statements using
+ * #GNUNET_SQ_exec_statements().
+ */
+struct GNUNET_SQ_ExecuteStatement {
+
+ /**
+ * Actual SQL statement.
+ */
+ const char *sql;
+
+ /**
+ * Should we ignore errors?
+ */
+ int ignore_errors;
+
+};
+
+
+/**
+ * Terminator for executable statement list.
+ */
+#define GNUNET_SQ_EXECUTE_STATEMENT_END { NULL, GNUNET_SYSERR }
+
+
+/**
+ * Create a `struct GNUNET_SQ_ExecuteStatement` where errors are fatal.
+ *
+ * @param sql actual SQL statement
+ * @return initialized struct
+ */
+struct GNUNET_SQ_ExecuteStatement
+GNUNET_SQ_make_execute (const char *sql);
+
+
+/**
+ * Create a `struct GNUNET_SQ_ExecuteStatement` where errors should
+ * be tolerated.
+ *
+ * @param sql actual SQL statement
+ * @return initialized struct
+ */
+struct GNUNET_SQ_ExecuteStatement
+GNUNET_SQ_make_try_execute (const char *sql);
+
+
+/**
+ * Request execution of an array of statements @a es from Postgres.
+ *
+ * @param dbh database to execute the statements over
+ * @param es #GNUNET_PQ_PREPARED_STATEMENT_END-terminated array of prepared
+ * statements.
+ * @return #GNUNET_OK on success (modulo statements where errors can be ignored)
+ * #GNUNET_SYSERR on error
+ */
+int
+GNUNET_SQ_exec_statements (sqlite3 *dbh,
+ const struct GNUNET_SQ_ExecuteStatement *es);
+
+
+
#endif /* GNUNET_SQ_LIB_H_ */
/* end of include/gnunet_sq_lib.h */
void *data)
{
char text[] = "pong";
+
*data_size = strlen(text)+1;
- memcpy(data, text, *data_size);
+ GNUNET_memcpy (data,
+ text,
+ *data_size);
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "origin sends (to all): %s\n", text);
struct pingpong_msg
{
int peer;
- enum pingpong msg;
+ enum pingpong msg;
};
static void service_connect (void *cls,
{
struct MulticastPeerContext *mc_peer = (struct MulticastPeerContext*)cls;
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Peer #%u (%s) sent a join request.\n",
- mc_peer->peer,
+ "Peer #%u (%s) sent a join request.\n",
+ mc_peer->peer,
GNUNET_i2s (multicast_peers[mc_peer->peer]->id));
}
-static int
+static int
notify (void *cls,
size_t *data_size,
void *data)
*data_size = sizeof (struct pingpong_msg);
GNUNET_memcpy(data, pp_msg, *data_size);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Peer #%u sents ping to origin\n", mc_peer->peer);
return GNUNET_YES;
const struct GNUNET_MessageHeader *join_msg)
{
struct MulticastPeerContext *mc_peer = (struct MulticastPeerContext*)cls;
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Peer #%u (%s) received a decision from origin: %s\n",
- mc_peer->peer,
+
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Peer #%u (%s) received a decision from origin: %s\n",
+ mc_peer->peer,
GNUNET_i2s (multicast_peers[mc_peer->peer]->id),
(GNUNET_YES == is_admitted)?"accepted":"rejected");
-
+
if (GNUNET_YES == is_admitted)
{
GNUNET_MULTICAST_member_to_origin (members[mc_peer->peer],
0,
notify,
cls);
-
+
}
}
static void
-member_message (void *cls,
+member_message (void *cls,
const struct GNUNET_MULTICAST_MessageHeader *msg)
{
struct MulticastPeerContext *mc_peer = (struct MulticastPeerContext*)cls;
if (PONG == pp_msg->msg && mc_peer->peer == pp_msg->peer)
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "peer #%i (%s) receives a pong\n",
+ "peer #%i (%s) receives a pong\n",
mc_peer->peer,
GNUNET_i2s (multicast_peers[mc_peer->peer]->id));
mc_peer->test_ok = GNUNET_OK;
uint8_t data_size = ntohs (join_msg->size);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"origin got a join request...\n");
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"origin receives: '%s'\n", (char *)&join_msg[1]);
char data[] = "Come in!";
join_resp->type = htons (123);
GNUNET_memcpy (&join_resp[1], data, data_size);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"origin sends: '%s'\n", data);
GNUNET_MULTICAST_join_decision (jh,
uint64_t message_id,
uint64_t fragment_offset,
uint64_t flags,
- struct GNUNET_MULTICAST_ReplayHandle *rh)
+ struct GNUNET_MULTICAST_ReplayHandle *rh)
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "origin replay msg\n");
static int
-origin_notify (void *cls,
- size_t *data_size,
+origin_notify (void *cls,
+ size_t *data_size,
void *data)
{
struct pingpong_msg *rcv_pp_msg = (struct pingpong_msg*)cls;
pp_msg->peer = rcv_pp_msg->peer;
pp_msg->msg = PONG;
*data_size = sizeof (struct pingpong_msg);
- memcpy(data, pp_msg, *data_size);
+ GNUNET_memcpy(data, pp_msg, *data_size);
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "origin sends pong\n");
- return GNUNET_YES;
+ return GNUNET_YES;
}
req++;
struct pingpong_msg *pp_msg = (struct pingpong_msg *) req;
-
+
if (1 != pp_msg->msg) {
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "origin didn't reveice a correct request");
}
static void
origin_message (void *cls,
- const struct GNUNET_MULTICAST_MessageHeader *msg)
+ const struct GNUNET_MULTICAST_MessageHeader *msg)
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "origin message msg\n");
}
{
group_key = GNUNET_CRYPTO_eddsa_key_create ();
GNUNET_CRYPTO_eddsa_key_get_public (group_key, &group_pub_key);
-
+
GNUNET_CRYPTO_hash (&group_pub_key, sizeof (group_pub_key), &group_pub_key_hash);
origin = GNUNET_MULTICAST_origin_start (cfg,
group_key,
{
multicast_peer->key = GNUNET_CRYPTO_ecdsa_key_create ();
- sprintf(data, "Hi, I am peer #%u (%s). Can I enter?",
+ sprintf(data, "Hi, I am peer #%u (%s). Can I enter?",
multicast_peer->peer,
GNUNET_i2s (multicast_peers[multicast_peer->peer]->id));
uint8_t data_size = strlen (data) + 1;
GNUNET_memcpy (&join_msg[1], data, data_size);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Peer #%u (%s) tries to join multicast group %s\n",
+ "Peer #%u (%s) tries to join multicast group %s\n",
multicast_peer->peer,
GNUNET_i2s (multicast_peers[multicast_peer->peer]->id),
GNUNET_h2s (&group_pub_key_hash));
multicast_peers[mc_peer->peer]->id = pinfo->result.id;
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Got peer information of %s (%s)\n",
- (0 == mc_peer->peer)? "origin" : "member",
+ "Got peer information of %s (%s)\n",
+ (0 == mc_peer->peer)? "origin" : "member",
GNUNET_i2s (pinfo->result.id));
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Create peer #%u (%s)\n",
+ "Create peer #%u (%s)\n",
mc_peer->peer,
GNUNET_i2s (multicast_peers[mc_peer->peer]->id));
/* connect to multicast service of members */
op[mc_peer->peer] =
GNUNET_TESTBED_service_connect (/* Closure for operation */
- NULL,
+ NULL,
/* The peer whose service to connect to */
peers[mc_peer->peer],
/* The name of the service */
if (NULL == ca_result)
{
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Connection adapter not created for peer #%u (%s)\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Connection adapter not created for peer #%u (%s)\n",
mc_peer->peer,
GNUNET_i2s (multicast_peers[mc_peer->peer]->id));
if (0 == mc_peer->peer)
{
- // Get GNUnet identity of members
- for (int i = 0; i<PEERS_REQUESTED; i++)
+ // Get GNUnet identity of members
+ for (int i = 0; i<PEERS_REQUESTED; i++)
{
pi_op[i] = GNUNET_TESTBED_peer_get_information (peers[i],
GNUNET_TESTBED_PIT_IDENTITY,
* @param PEERS_REQUESTED size of the 'peers' array
* @param links_succeeded number of links between peers that were created
* @param links_failed number of links testbed was unable to establish
- */
+ */
static void
testbed_master (void *cls,
struct GNUNET_TESTBED_RunHandle *h,
multicast_peers = GNUNET_new_array (PEERS_REQUESTED, struct MulticastPeerContext*);
// Create test contexts for members
- for (int i = 0; i<PEERS_REQUESTED; i++)
+ for (int i = 0; i<PEERS_REQUESTED; i++)
{
multicast_peers[i] = GNUNET_new (struct MulticastPeerContext);
multicast_peers[i]->peer = i;
int ret;
char const *config_file;
- if (strstr (argv[0], "_line") != NULL)
+ if (strstr (argv[0], "_line") != NULL)
{
config_file = "test_multicast_line.conf";
}
{
config_file = "test_multicast_star.conf";
}
- else
+ else
{
config_file = "test_multicast_star.conf";
}
result = GNUNET_SYSERR;
ret =
GNUNET_TESTBED_test_run ("test-multicast-multipeer",
- config_file,
+ config_file,
/* number of peers to start */
- PEERS_REQUESTED,
+ PEERS_REQUESTED,
/* Event mask - set to 0 for no event notifications */
- 0LL,
+ 0LL,
/* Controller event callback */
- NULL,
+ NULL,
/* Closure for controller event callback */
- NULL,
+ NULL,
/* called when testbed setup is complete */
- testbed_master,
+ testbed_master,
/* Closure for the test_master callback */
- NULL);
+ NULL);
if ( (GNUNET_OK != ret) || (GNUNET_OK != result) )
return 1;
return 0;
*/
static struct GNUNET_NAMESTORE_QueueEntry *add_qe;
+/**
+ * Queue entry for the 'lookup' operation.
+ */
+static struct GNUNET_NAMESTORE_QueueEntry *get_qe;
+
/**
* Queue entry for the 'reverse lookup' operation (in combination with a name).
*/
GNUNET_NAMESTORE_cancel (add_qe_uri);
add_qe_uri = NULL;
}
+ if (NULL != get_qe)
+ {
+ GNUNET_NAMESTORE_cancel (get_qe);
+ get_qe = NULL;
+ }
if (NULL != del_qe)
{
GNUNET_NAMESTORE_cancel (del_qe);
{
if ( (NULL == add_qe) &&
(NULL == add_qe_uri) &&
+ (NULL == get_qe) &&
(NULL == del_qe) &&
(NULL == reverse_qe) &&
(NULL == list_it) )
}
+/**
+ * Process a record that was stored in the namestore.
+ *
+ * @param cls closure
+ * @param zone_key private key of the zone
+ * @param rname name that is being mapped (at most 255 characters long)
+ * @param rd_len number of entries in @a rd array
+ * @param rd array of records with data to store
+ */
+static void
+display_record_lookup (void *cls,
+ const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
+ const char *rname,
+ unsigned int rd_len,
+ const struct GNUNET_GNSRECORD_Data *rd)
+{
+ get_qe = NULL;
+ display_record (rname,
+ rd_len,
+ rd);
+ test_finished ();
+}
+
+
/**
* Function called once we are in sync in monitor mode.
*
/**
- * Function called if lookup fails.
+ * Function called on errors while monitoring.
+ *
+ * @param cls NULL
*/
static void
lookup_error_cb (void *cls)
+{
+ (void) cls;
+ get_qe = NULL;
+ FPRINTF (stderr,
+ "%s",
+ "Failed to lookup record.\n");
+ test_finished ();
+}
+
+
+/**
+ * Function called if lookup fails.
+ */
+static void
+add_error_cb (void *cls)
{
(void) cls;
add_qe = NULL;
add_qe = GNUNET_NAMESTORE_records_lookup (ns,
&zone_pkey,
name,
- &lookup_error_cb,
+ &add_error_cb,
NULL,
&get_existing_record,
NULL);
}
if (list)
{
- list_it = GNUNET_NAMESTORE_zone_iteration_start (ns,
- &zone_pkey,
- &zone_iteration_error_cb,
- NULL,
- &display_record_iterator,
- NULL,
- &zone_iteration_finished,
- NULL);
+ if (NULL != name)
+ get_qe = GNUNET_NAMESTORE_records_lookup (ns,
+ &zone_pkey,
+ name,
+ &lookup_error_cb,
+ NULL,
+ &display_record_lookup,
+ NULL);
+ else
+ list_it = GNUNET_NAMESTORE_zone_iteration_start (ns,
+ &zone_pkey,
+ &zone_iteration_error_cb,
+ NULL,
+ &display_record_iterator,
+ NULL,
+ &zone_iteration_finished,
+ NULL);
}
if (NULL != reverse_pkey)
{
/*
This file is part of GNUnet.
- Copyright (C) 2012, 2013, 2014 GNUnet e.V.
+ Copyright (C) 2012, 2013, 2014, 2018 GNUnet e.V.
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
* @brief namestore for the GNUnet naming system
* @author Matthias Wachs
* @author Christian Grothoff
+ *
+ * TODO:
+ * - run testcases, make sure everything works!
*/
#include "platform.h"
#include "gnunet_util_lib.h"
#define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file (kind, "util", syscall, filename)
+/**
+ * If a monitor takes more than 1 minute to process an event, print a warning.
+ */
+#define MONITOR_STALL_WARN_DELAY GNUNET_TIME_UNIT_MINUTES
+
/**
* A namestore client
*/
struct GNUNET_SCHEDULER_Task *task;
+ /**
+ * Task to warn about slow monitors.
+ */
+ struct GNUNET_SCHEDULER_Task *sa_wait_warning;
+
+ /**
+ * Since when are we blocked on this monitor?
+ */
+ struct GNUNET_TIME_Absolute sa_waiting_start;
+
/**
* Last sequence number in the zone iteration used to address next
* result of the zone iteration in the store
*/
uint64_t limit;
+ /**
+ * How many more requests may we receive from the iterator
+ * before it is at the limit we gave it? Will be below or
+ * equal to @e limit. The effective limit for monitor
+ * events is thus @e iteration_cnt - @e limit!
+ */
+ uint64_t iteration_cnt;
+
+ /**
+ * Are we (still) in the initial iteration pass?
+ */
+ int in_first_iteration;
+
+ /**
+ * Is there a store activity waiting for this monitor? We only raise the
+ * flag when it happens and search the DLL for the store activity when we
+ * had a limit increase. If we cannot find any waiting store activity at
+ * that time, we clear the flag again.
+ */
+ int sa_waiting;
+
};
};
+/**
+ * Information for an ongoing #handle_record_store() operation.
+ * Needed as we may wait for monitors to be ready for the notification.
+ */
+struct StoreActivity
+{
+ /**
+ * Kept in a DLL.
+ */
+ struct StoreActivity *next;
+
+ /**
+ * Kept in a DLL.
+ */
+ struct StoreActivity *prev;
+
+ /**
+ * Which client triggered the store activity?
+ */
+ struct NamestoreClient *nc;
+
+ /**
+ * Copy of the original store message (as data fields in @e rd will
+ * point into it!).
+ */
+ const struct RecordStoreMessage *rsm;
+
+ /**
+ * Array of record data to store (without NICK unless this is about
+ * #GNUNET_GNS_EMPTY_LABEL_AT). Length is in @e rd_count.
+ */
+ struct GNUNET_GNSRECORD_Data *rd;
+
+ /**
+ * Next zone monitor that still needs to be notified about this PUT.
+ */
+ struct ZoneMonitor *zm_pos;
+
+ /**
+ * Label nicely canonicalized (lower case).
+ */
+ char *conv_name;
+
+ /**
+ * How many records do we try to store?
+ */
+ unsigned int rd_count;
+
+};
+
+
/**
* Public key of all zeros.
*/
*/
static struct ZoneMonitor *monitor_tail;
+/**
+ * Head of DLL of monitor-blocked store activities.
+ */
+static struct StoreActivity *sa_head;
+
+/**
+ * Tail of DLL of monitor-blocked store activities.
+ */
+static struct StoreActivity *sa_tail;
+
/**
* Notification context shared by all monitors.
*/
/**
- * Called whenever a client is disconnected.
- * Frees our resources associated with that client.
+ * Release memory used by @a sa.
*
- * @param cls closure
- * @param client identification of the client
- * @param app_ctx the `struct NamestoreClient` of @a client
+ * @param sa activity to free
*/
static void
-client_disconnect_cb (void *cls,
- struct GNUNET_SERVICE_Client *client,
- void *app_ctx)
-{
- struct NamestoreClient *nc = app_ctx;
- struct ZoneIteration *no;
- struct ZoneMonitor *zm;
- struct CacheOperation *cop;
-
- (void) cls;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Client %p disconnected\n",
- client);
- for (zm = monitor_head; NULL != zm; zm = zm->next)
- {
- if (nc == zm->nc)
- {
- GNUNET_CONTAINER_DLL_remove (monitor_head,
- monitor_tail,
- zm);
- if (NULL != zm->task)
- {
- GNUNET_SCHEDULER_cancel (zm->task);
- zm->task = NULL;
- }
- GNUNET_free (zm);
- break;
- }
- }
- while (NULL != (no = nc->op_head))
- {
- GNUNET_CONTAINER_DLL_remove (nc->op_head,
- nc->op_tail,
- no);
- GNUNET_free (no);
- }
- for (cop = cop_head; NULL != cop; cop = cop->next)
- if (nc == cop->nc)
- cop->nc = NULL;
- GNUNET_free (nc);
-}
-
-
-/**
- * Add a client to our list of active clients.
- *
- * @param cls NULL
- * @param client client to add
- * @param mq message queue for @a client
- * @return internal namestore client structure for this client
- */
-static void *
-client_connect_cb (void *cls,
- struct GNUNET_SERVICE_Client *client,
- struct GNUNET_MQ_Handle *mq)
+free_store_activity (struct StoreActivity *sa)
{
- struct NamestoreClient *nc;
-
- (void) cls;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Client %p connected\n",
- client);
- nc = GNUNET_new (struct NamestoreClient);
- nc->client = client;
- nc->mq = mq;
- return nc;
+ GNUNET_CONTAINER_DLL_remove (sa_head,
+ sa_tail,
+ sa);
+ GNUNET_array_grow (sa->rd,
+ sa->rd_count,
+ 0);
+ GNUNET_free (sa->conv_name);
+ GNUNET_free (sa);
}
uint64_t latest_expiration;
size_t req;
char *data;
- int record_offset;
size_t data_offset;
(*rdc_res) = 1 + rd2_length;
if (0 == 1 + rd2_length)
{
+ GNUNET_break (0);
(*rd_res) = NULL;
return;
}
- req = 0;
- for (unsigned int c=0; c< 1; c++)
- req += sizeof (struct GNUNET_GNSRECORD_Data) + nick_rd[c].data_size;
+ req = sizeof (struct GNUNET_GNSRECORD_Data) + nick_rd->data_size;
for (unsigned int c=0; c< rd2_length; c++)
req += sizeof (struct GNUNET_GNSRECORD_Data) + rd2[c].data_size;
(*rd_res) = GNUNET_malloc (req);
latest_expiration = rd2[c].expiration_time;
(*rd_res)[c] = rd2[c];
(*rd_res)[c].data = (void *) &data[data_offset];
- GNUNET_memcpy ((void *) (*rd_res)[c].data,
+ GNUNET_memcpy (&data[data_offset],
rd2[c].data,
rd2[c].data_size);
data_offset += (*rd_res)[c].data_size;
}
/* append nick */
- record_offset = rd2_length;
- (*rd_res)[record_offset] = *nick_rd;
- (*rd_res)[record_offset].expiration_time = latest_expiration;
- (*rd_res)[record_offset].data = (void *) &data[data_offset];
- GNUNET_memcpy ((void *) (*rd_res)[record_offset].data,
+ (*rd_res)[rd2_length] = *nick_rd;
+ (*rd_res)[rd2_length].expiration_time = latest_expiration;
+ (*rd_res)[rd2_length].data = (void *) &data[data_offset];
+ GNUNET_memcpy ((void *) (*rd_res)[rd2_length].data,
nick_rd->data,
nick_rd->data_size);
- data_offset += (*rd_res)[record_offset].data_size;
+ data_offset += (*rd_res)[rd2_length].data_size;
GNUNET_assert (req == (sizeof (struct GNUNET_GNSRECORD_Data)) * (*rdc_res) + data_offset);
}
}
name_len = strlen (name) + 1;
- rd_ser_len = GNUNET_GNSRECORD_records_get_size (res_count, res);
+ rd_ser_len = GNUNET_GNSRECORD_records_get_size (res_count,
+ res);
env = GNUNET_MQ_msg_extra (zir_msg,
name_len + rd_ser_len,
GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Sending RECORD_STORE_RESPONSE message\n");
+ GNUNET_STATISTICS_update (statistics,
+ "Store requests completed",
+ 1,
+ GNUNET_NO);
env = GNUNET_MQ_msg (rcr_msg,
GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE);
rcr_msg->gns_header.r_id = htonl (rid);
}
+/**
+ * Print a warning that one of our monitors is no longer reacting.
+ *
+ * @param cls a `struct ZoneMonitor` to warn about
+ */
+static void
+warn_monitor_slow (void *cls)
+{
+ struct ZoneMonitor *zm = cls;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "No response from monitor since %s\n",
+ GNUNET_STRINGS_absolute_time_to_string (zm->sa_waiting_start));
+ zm->sa_wait_warning = GNUNET_SCHEDULER_add_delayed (MONITOR_STALL_WARN_DELAY,
+ &warn_monitor_slow,
+ zm);
+}
+
+
+/**
+ * Continue processing the @a sa.
+ *
+ * @param sa store activity to process
+ */
+static void
+continue_store_activity (struct StoreActivity *sa)
+{
+ const struct RecordStoreMessage *rp_msg = sa->rsm;
+
+ for (struct ZoneMonitor *zm = sa->zm_pos;
+ NULL != zm;
+ zm = sa->zm_pos)
+ {
+ if ( (0 != memcmp (&rp_msg->private_key,
+ &zm->zone,
+ sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) &&
+ (0 != memcmp (&zm->zone,
+ &zero,
+ sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) )
+ sa->zm_pos = zm->next; /* not interesting to this monitor */
+ if (zm->limit == zm->iteration_cnt)
+ {
+ zm->sa_waiting = GNUNET_YES;
+ zm->sa_waiting_start = GNUNET_TIME_absolute_get ();
+ if (NULL != zm->sa_wait_warning)
+ GNUNET_SCHEDULER_cancel (zm->sa_wait_warning);
+ zm->sa_wait_warning = GNUNET_SCHEDULER_add_delayed (MONITOR_STALL_WARN_DELAY,
+ &warn_monitor_slow,
+ zm);
+ return; /* blocked on zone monitor */
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Notifying monitor about changes under label `%s'\n",
+ sa->conv_name);
+ zm->limit--;
+ send_lookup_response (zm->nc,
+ 0,
+ &rp_msg->private_key,
+ sa->conv_name,
+ sa->rd_count,
+ sa->rd);
+ sa->zm_pos = zm->next;
+ }
+ /* great, done with the monitors, unpack (again) for refresh_block operation */
+ {
+ size_t name_len;
+ size_t rd_ser_len;
+ uint32_t rid;
+ const char *name_tmp;
+ const char *rd_ser;
+ unsigned int rd_count;
+
+ rid = ntohl (rp_msg->gns_header.r_id);
+ name_len = ntohs (rp_msg->name_len);
+ rd_count = ntohs (rp_msg->rd_count);
+ rd_ser_len = ntohs (rp_msg->rd_len);
+ name_tmp = (const char *) &rp_msg[1];
+ rd_ser = &name_tmp[name_len];
+ {
+ struct GNUNET_GNSRECORD_Data rd[rd_count];
+
+ /* We did this before, must succeed again */
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_GNSRECORD_records_deserialize (rd_ser_len,
+ rd_ser,
+ rd_count,
+ rd));
+ refresh_block (sa->nc,
+ rid,
+ &rp_msg->private_key,
+ sa->conv_name,
+ rd_count,
+ rd);
+ }
+ }
+ GNUNET_SERVICE_client_continue (sa->nc->client);
+ free_store_activity (sa);
+}
+
+
+/**
+ * Called whenever a client is disconnected.
+ * Frees our resources associated with that client.
+ *
+ * @param cls closure
+ * @param client identification of the client
+ * @param app_ctx the `struct NamestoreClient` of @a client
+ */
+static void
+client_disconnect_cb (void *cls,
+ struct GNUNET_SERVICE_Client *client,
+ void *app_ctx)
+{
+ struct NamestoreClient *nc = app_ctx;
+ struct ZoneIteration *no;
+ struct CacheOperation *cop;
+
+ (void) cls;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Client %p disconnected\n",
+ client);
+ for (struct ZoneMonitor *zm = monitor_head; NULL != zm; zm = zm->next)
+ {
+ struct StoreActivity *san;
+
+ if (nc != zm->nc)
+ continue;
+ GNUNET_CONTAINER_DLL_remove (monitor_head,
+ monitor_tail,
+ zm);
+ if (NULL != zm->task)
+ {
+ GNUNET_SCHEDULER_cancel (zm->task);
+ zm->task = NULL;
+ }
+ if (NULL != zm->sa_wait_warning)
+ {
+ GNUNET_SCHEDULER_cancel (zm->sa_wait_warning);
+ zm->sa_wait_warning = NULL;
+ }
+ for (struct StoreActivity *sa = sa_head; NULL != sa; sa = san)
+ {
+ san = sa->next;
+ if (zm == sa->zm_pos)
+ {
+ sa->zm_pos = zm->next;
+ /* this may free sa */
+ continue_store_activity (sa);
+ }
+ }
+ GNUNET_free (zm);
+ break;
+ }
+ for (struct StoreActivity *sa = sa_head; NULL != sa; sa = sa->next)
+ {
+ if (sa->nc == nc)
+ {
+ /* this may free sa */
+ free_store_activity (sa);
+ break; /* there can only be one per nc */
+ }
+ }
+ while (NULL != (no = nc->op_head))
+ {
+ GNUNET_CONTAINER_DLL_remove (nc->op_head,
+ nc->op_tail,
+ no);
+ GNUNET_free (no);
+ }
+ for (cop = cop_head; NULL != cop; cop = cop->next)
+ if (nc == cop->nc)
+ cop->nc = NULL;
+ GNUNET_free (nc);
+}
+
+
+/**
+ * Add a client to our list of active clients.
+ *
+ * @param cls NULL
+ * @param client client to add
+ * @param mq message queue for @a client
+ * @return internal namestore client structure for this client
+ */
+static void *
+client_connect_cb (void *cls,
+ struct GNUNET_SERVICE_Client *client,
+ struct GNUNET_MQ_Handle *mq)
+{
+ struct NamestoreClient *nc;
+
+ (void) cls;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Client %p connected\n",
+ client);
+ nc = GNUNET_new (struct NamestoreClient);
+ nc->client = client;
+ nc->mq = mq;
+ return nc;
+}
+
+
/**
* Closure for #lookup_it().
*/
const char *rd_ser;
unsigned int rd_count;
int res;
- struct ZoneMonitor *zm;
+ struct StoreActivity *sa;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Received NAMESTORE_RECORD_STORE message\n");
name_tmp = (const char *) &rp_msg[1];
rd_ser = &name_tmp[name_len];
{
- struct GNUNET_GNSRECORD_Data rd[rd_count];
+ struct GNUNET_GNSRECORD_Data rd[GNUNET_NZL(rd_count)];
+ struct GNUNET_GNSRECORD_Data rd_clean[GNUNET_NZL(rd_count)];
+ unsigned int rd_clean_off;
if (GNUNET_OK !=
GNUNET_GNSRECORD_records_deserialize (rd_ser_len,
GNUNET_SERVICE_client_drop (nc->client);
return;
}
+ GNUNET_STATISTICS_update (statistics,
+ "Well-formed store requests received",
+ 1,
+ GNUNET_NO);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Creating %u records for name `%s'\n",
(unsigned int) rd_count,
}
else
{
- struct GNUNET_GNSRECORD_Data rd_clean[rd_count];
- unsigned int rd_clean_off;
-
/* remove "NICK" records, unless this is for the
#GNUNET_GNS_EMPTY_LABEL_AT label */
rd_clean_off = 0;
conv_name,
rd_clean_off,
rd_clean);
- if (GNUNET_OK == res)
- {
- for (zm = monitor_head; NULL != zm; zm = zm->next)
- {
- if ( (0 == memcmp (&rp_msg->private_key,
- &zm->zone,
- sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) ||
- (0 == memcmp (&zm->zone,
- &zero,
- sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) )
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Notifying monitor about changes under label `%s'\n",
- conv_name);
- send_lookup_response (zm->nc,
- 0,
- &rp_msg->private_key,
- conv_name,
- rd_count, rd);
- }
- else
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Monitor is for another zone\n");
- }
- if (NULL == monitor_head)
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "No monitors active\n");
- }
- else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Error storing record: %d\n",
- res);
- }
}
- if (GNUNET_OK == res)
+
+ if (GNUNET_OK != res)
{
- refresh_block (nc,
- rid,
- &rp_msg->private_key,
- conv_name,
- rd_count,
- rd);
+ /* store not successful, not need to tell monitors */
+ send_store_response (nc,
+ res,
+ rid);
GNUNET_SERVICE_client_continue (nc->client);
GNUNET_free (conv_name);
return;
}
- GNUNET_free (conv_name);
+
+ sa = GNUNET_malloc (sizeof (struct StoreActivity) +
+ ntohs (rp_msg->gns_header.header.size));
+ GNUNET_CONTAINER_DLL_insert (sa_head,
+ sa_tail,
+ sa);
+ sa->nc = nc;
+ sa->rsm = (const struct RecordStoreMessage *) &sa[1];
+ GNUNET_memcpy (&sa[1],
+ rp_msg,
+ ntohs (rp_msg->gns_header.header.size));
+ sa->zm_pos = monitor_head;
+ sa->conv_name = conv_name;
+ GNUNET_array_grow (sa->rd,
+ sa->rd_count,
+ rd_clean_off);
+ GNUNET_memcpy (sa->rd,
+ rd_clean,
+ sizeof (struct GNUNET_GNSRECORD_Data) * rd_clean_off);
+ continue_store_activity (sa);
}
- send_store_response (nc,
- res,
- rid);
- GNUNET_SERVICE_client_continue (nc->client);
}
struct ZoneToNameResponseMessage *ztnr_msg;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received `%s' message\n",
- "ZONE_TO_NAME");
+ "Received ZONE_TO_NAME message\n");
ztn_ctx.rid = ntohl (ztn_msg->gns_header.r_id);
ztn_ctx.nc = nc;
ztn_ctx.success = GNUNET_NO;
}
+/**
+ * Function called when the monitor is ready for more data, and we
+ * should thus unblock PUT operations that were blocked on the
+ * monitor not being ready.
+ */
+static void
+monitor_unblock (struct ZoneMonitor *zm)
+{
+ struct StoreActivity *sa = sa_head;
+
+ while ( (NULL != sa) &&
+ (zm->limit > zm->iteration_cnt) )
+ {
+ struct StoreActivity *sn = sa->next;
+
+ if (sa->zm_pos == zm)
+ continue_store_activity (sa);
+ sa = sn;
+ }
+ if (zm->limit > zm->iteration_cnt)
+ {
+ zm->sa_waiting = GNUNET_NO;
+ if (NULL != zm->sa_wait_warning)
+ {
+ GNUNET_SCHEDULER_cancel (zm->sa_wait_warning);
+ zm->sa_wait_warning = NULL;
+ }
+ }
+ else if (GNUNET_YES == zm->sa_waiting)
+ {
+ zm->sa_waiting_start = GNUNET_TIME_absolute_get ();
+ if (NULL != zm->sa_wait_warning)
+ GNUNET_SCHEDULER_cancel (zm->sa_wait_warning);
+ zm->sa_wait_warning = GNUNET_SCHEDULER_add_delayed (MONITOR_STALL_WARN_DELAY,
+ &warn_monitor_slow,
+ zm);
+ }
+}
+
+
/**
* Send 'sync' message to zone monitor, we're now in sync.
*
GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_SYNC);
GNUNET_MQ_send (zm->nc->mq,
env);
+ /* mark iteration done */
+ zm->in_first_iteration = GNUNET_NO;
+ zm->iteration_cnt = 0;
+ if ( (zm->limit > 0) &&
+ (zm->sa_waiting) )
+ monitor_unblock (zm);
}
/**
- * Obtain the next datum during the zone monitor's zone intiial iteration.
+ * Obtain the next datum during the zone monitor's zone initial iteration.
*
* @param cls zone monitor that does its initial iteration
*/
static void
-monitor_next (void *cls);
+monitor_iteration_next (void *cls);
/**
"Monitor notifications sent",
1,
GNUNET_NO);
+ zm->limit--;
+ zm->iteration_cnt--;
send_lookup_response (zm->nc,
0,
zone_key,
name,
rd_count,
rd);
- zm->task = GNUNET_SCHEDULER_add_now (&monitor_next,
- zm);
+ if ( (0 == zm->iteration_cnt) &&
+ (0 != zm->limit) )
+ {
+ /* We are done with the current iteration batch, AND the
+ client would right now accept more, so go again! */
+ GNUNET_assert (NULL == zm->task);
+ zm->task = GNUNET_SCHEDULER_add_now (&monitor_iteration_next,
+ zm);
+ }
}
zm = GNUNET_new (struct ZoneMonitor);
zm->nc = nc;
zm->zone = zis_msg->zone;
+ zm->limit = 1;
+ zm->in_first_iteration = (GNUNET_YES == ntohl (zis_msg->iterate_first));
GNUNET_CONTAINER_DLL_insert (monitor_head,
monitor_tail,
zm);
GNUNET_SERVICE_client_continue (nc->client);
GNUNET_notification_context_add (monitor_nc,
nc->mq);
- if (GNUNET_YES == ntohl (zis_msg->iterate_first))
- zm->task = GNUNET_SCHEDULER_add_now (&monitor_next,
+ if (zm->in_first_iteration)
+ zm->task = GNUNET_SCHEDULER_add_now (&monitor_iteration_next,
zm);
else
monitor_sync (zm);
* @param cls zone monitor that does its initial iteration
*/
static void
-monitor_next (void *cls)
+monitor_iteration_next (void *cls)
{
struct ZoneMonitor *zm = cls;
int ret;
zm->task = NULL;
+ GNUNET_assert (0 == zm->iteration_cnt);
+ if (zm->limit > 16)
+ zm->iteration_cnt = zm->limit / 2; /* leave half for monitor events */
+ else
+ zm->iteration_cnt = zm->limit; /* use it all */
ret = GSN_database->iterate_records (GSN_database->cls,
(0 == memcmp (&zm->zone,
&zero,
? NULL
: &zm->zone,
zm->seq,
- 1,
+ zm->iteration_cnt,
&monitor_iterate_cb,
zm);
if (GNUNET_SYSERR == ret)
return;
}
zm->limit += inc;
-#if 0
- if (GNUNET_YES == ntohl (zis_msg->iterate_first))
- zm->task = GNUNET_SCHEDULER_add_now (&monitor_next,
- zm);
- else
- monitor_sync (zm);
-#endif
+ if ( (zm->in_first_iteration) &&
+ (zm->limit == inc) )
+ {
+ /* We are still iterating, and the previous iteration must
+ have stopped due to the client's limit, so continue it! */
+ GNUNET_assert (NULL == zm->task);
+ zm->task = GNUNET_SCHEDULER_add_now (&monitor_iteration_next,
+ zm);
+ }
+ GNUNET_assert (zm->iteration_cnt <= zm->limit);
+ if ( (zm->limit > zm->iteration_cnt) &&
+ (zm->sa_waiting) )
+ {
+ monitor_unblock (zm);
+ }
+ else if (GNUNET_YES == zm->sa_waiting)
+ {
+ if (NULL != zm->sa_wait_warning)
+ GNUNET_SCHEDULER_cancel (zm->sa_wait_warning);
+ zm->sa_waiting_start = GNUNET_TIME_absolute_get ();
+ zm->sa_wait_warning = GNUNET_SCHEDULER_add_delayed (MONITOR_STALL_WARN_DELAY,
+ &warn_monitor_slow,
+ zm);
+ }
}
*/
#define SERIES_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MICROSECONDS, 10)
+/**
+ * How long do DNS records have to last at least after being imported?
+ */
+static struct GNUNET_TIME_Relative minimum_expiration_time;
+
/**
* How many requests do we request from NAMESTORE in one batch
* during our initial iteration?
GNUNET_break (0);
return NULL;
}
- memcpy (label,
- req->hostname,
- dot - req->hostname);
+ GNUNET_memcpy (label,
+ req->hostname,
+ dot - req->hostname);
label[dot - req->hostname] = '\0';
return label;
}
GNUNET_free (rawp);
return NULL;
}
- memcpy (raw,
- rawp,
- *raw_size);
+ GNUNET_memcpy (raw,
+ rawp,
+ *raw_size);
GNUNET_free (rawp);
return raw;
}
size_t off;
char ip[INET6_ADDRSTRLEN+1];
socklen_t ip_size = (socklen_t) sizeof (ip);
+ struct GNUNET_TIME_Absolute expiration_time;
+ struct GNUNET_TIME_Relative left;
if (0 != strcasecmp (rec->name,
gc->ns))
return;
+ expiration_time = rec->expiration_time;
+ left = GNUNET_TIME_absolute_get_remaining (expiration_time);
+ if (0 == left.rel_value_us)
+ return; /* ignore expired glue records */
+ /* if expiration window is too short, bump it to configured minimum */
+ if (left.rel_value_us < minimum_expiration_time.rel_value_us)
+ expiration_time = GNUNET_TIME_relative_to_absolute (minimum_expiration_time);
dst_len = sizeof (dst);
off = 0;
switch (rec->type)
{
add_record (gc->req,
GNUNET_GNSRECORD_TYPE_GNS2DNS,
- rec->expiration_time,
+ expiration_time,
dst,
off);
gc->found = GNUNET_YES;
{
add_record (gc->req,
GNUNET_GNSRECORD_TYPE_GNS2DNS,
- rec->expiration_time,
+ expiration_time,
dst,
off);
gc->found = GNUNET_YES;
{
add_record (gc->req,
GNUNET_GNSRECORD_TYPE_GNS2DNS,
- rec->expiration_time,
+ expiration_time,
dst,
off);
gc->found = GNUNET_YES;
char dst[65536];
size_t dst_len;
size_t off;
+ struct GNUNET_TIME_Absolute expiration_time;
+ struct GNUNET_TIME_Relative left;
dst_len = sizeof (dst);
off = 0;
return; /* does not match hostname, might be glue, but
not useful for this pass! */
}
- if (0 ==
- GNUNET_TIME_absolute_get_remaining (rec->expiration_time).rel_value_us)
+ expiration_time = rec->expiration_time;
+ left = GNUNET_TIME_absolute_get_remaining (expiration_time);
+ if (0 == left.rel_value_us)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"DNS returned expired record for `%s'\n",
req->hostname);
+ GNUNET_STATISTICS_update (stats,
+ "# expired records obtained from DNS",
+ 1,
+ GNUNET_NO);
return; /* record expired */
}
+
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"DNS returned record that expires at %s for `%s'\n",
- GNUNET_STRINGS_absolute_time_to_string (rec->expiration_time),
+ GNUNET_STRINGS_absolute_time_to_string (expiration_time),
req->hostname);
+ /* if expiration window is too short, bump it to configured minimum */
+ if (left.rel_value_us < minimum_expiration_time.rel_value_us)
+ expiration_time = GNUNET_TIME_relative_to_absolute (minimum_expiration_time);
switch (rec->type)
{
case GNUNET_DNSPARSER_TYPE_NS:
rec->name);
add_record (req,
GNUNET_GNSRECORD_TYPE_GNS2DNS,
- rec->expiration_time,
+ expiration_time,
dst,
off);
}
rec->name);
add_record (req,
rec->type,
- rec->expiration_time,
+ expiration_time,
dst,
off);
}
rec->name);
add_record (req,
rec->type,
- rec->expiration_time,
+ expiration_time,
dst,
off);
}
rec->name);
add_record (req,
rec->type,
- rec->expiration_time,
+ expiration_time,
dst,
off);
}
rec->name);
add_record (req,
rec->type,
- rec->expiration_time,
+ expiration_time,
dst,
off);
}
rec->name);
add_record (req,
rec->type,
- rec->expiration_time,
+ expiration_time,
dst,
off);
}
rec->name);
add_record (req,
rec->type,
- rec->expiration_time,
+ expiration_time,
dst,
off);
}
rec->name);
add_record (req,
rec->type,
- rec->expiration_time,
+ expiration_time,
rec->data.raw.data,
rec->data.raw.data_len);
break;
{
struct GNUNET_TIME_Absolute at;
- at.abs_value_us = rd->expiration_time;
+ if (0 != (rd->flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION))
+ {
+ struct GNUNET_TIME_Relative rel;
+
+ rel.rel_value_us = rd->expiration_time;
+ at = GNUNET_TIME_relative_to_absolute (rel);
+ }
+ else
+ {
+ at.abs_value_us = rd->expiration_time;
+ }
add_record (req,
rd->record_type,
at,
req = GNUNET_malloc (sizeof (struct Request) + hlen);
req->zone = zone;
req->hostname = (char *) &req[1];
- memcpy (req->hostname,
- hostname,
- hlen);
+ GNUNET_memcpy (req->hostname,
+ hostname,
+ hlen);
req->id = (uint16_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE,
UINT16_MAX);
GNUNET_CRYPTO_hash (req->hostname,
if (0 == idot)
last = GNUNET_TIME_absolute_get ();
idot++;
- if (0 == idot % 10000)
+ if (0 == idot % 100000)
{
struct GNUNET_TIME_Relative delta;
delta = GNUNET_TIME_absolute_get_duration (last);
last = GNUNET_TIME_absolute_get ();
fprintf (stderr,
- "Imported 10000 records in %s\n",
+ "Read 10000 domain names in %s\n",
GNUNET_STRINGS_relative_time_to_string (delta,
GNUNET_YES));
GNUNET_STATISTICS_set (stats,
"MAPSIZE",
gettext_noop ("size to use for the main hash map"),
&map_size),
+ GNUNET_GETOPT_option_relative_time ('m',
+ "minimum-expiration",
+ "RELATIVETIME",
+ gettext_noop ("minimum expiration time we assume for imported records"),
+ &minimum_expiration_time),
GNUNET_GETOPT_OPTION_END
};
#define LOG(kind,...) GNUNET_log_from (kind, "namestore-api",__VA_ARGS__)
+/**
+ * We grant the namestore up to 1 minute of latency, if it is slower than
+ * that, store queries will fail.
+ */
+#define NAMESTORE_DELAY_TOLERANCE GNUNET_TIME_UNIT_MINUTES
/**
* An QueueEntry used to store information for a pending
*/
struct GNUNET_MQ_Envelope *env;
+ /**
+ * Task scheduled to warn us if the namestore is way too slow.
+ */
+ struct GNUNET_SCHEDULER_Task *timeout_task;
+
/**
* The operation id this zone iteration operation has
*/
qe);
if (NULL != qe->env)
GNUNET_MQ_discard (qe->env);
+ if (NULL != qe->timeout_task)
+ GNUNET_SCHEDULER_cancel (qe->timeout_task);
GNUNET_free (qe);
}
}
+/**
+ * Task launched to warn the user that the namestore is
+ * excessively slow and that a query was thus dropped.
+ *
+ * @param cls a `struct GNUNET_NAMESTORE_QueueEntry *`
+ */
+static void
+warn_delay (void *cls)
+{
+ struct GNUNET_NAMESTORE_QueueEntry *qe = cls;
+
+ qe->timeout_task = NULL;
+ LOG (GNUNET_ERROR_TYPE_WARNING,
+ "Did not receive response from namestore after %s!\n",
+ GNUNET_STRINGS_relative_time_to_string (NAMESTORE_DELAY_TOLERANCE,
+ GNUNET_YES));
+ if (NULL != qe->cont)
+ {
+ qe->cont (qe->cont_cls,
+ GNUNET_SYSERR,
+ "timeout");
+ qe->cont = NULL;
+ }
+ GNUNET_NAMESTORE_cancel (qe);
+}
+
+
/**
* Store an item in the namestore. If the item is already present,
* it is replaced with the new record. Use an empty array to
"Sending NAMESTORE_RECORD_STORE message for name `%s' with %u records\n",
label,
rd_count);
-
+ qe->timeout_task = GNUNET_SCHEDULER_add_delayed (NAMESTORE_DELAY_TOLERANCE,
+ &warn_delay,
+ qe);
if (NULL == h->mq)
+ {
qe->env = env;
+ LOG (GNUNET_ERROR_TYPE_WARNING,
+ "Delaying NAMESTORE_RECORD_STORE message as namestore is not ready!\n");
+ }
else
+ {
GNUNET_MQ_send (h->mq,
env);
+ }
return qe;
}
[namecache]
DISABLE = YES
+
+[namestore-flat]
+FILENAME = $GNUNET_TEST_HOME/namestore/flat.db
[namecache]
DISABLE = YES
+
+[namestore-postgres]
+CONFIG = connect_timeout=10; dbname=gnunetcheck
+TEMPORARY_TABLE = YES
[namecache]
DISABLE = YES
+
+[namestore-sqlite]
+FILENAME = $GNUNET_TEST_HOME/namestore/sqlite_test.db
static int res;
-static char *directory;
-
static unsigned int off;
static unsigned int left_until_next;
const struct GNUNET_CONFIGURATION_Handle *cfg,
struct GNUNET_TESTING_Peer *peer)
{
- directory = NULL;
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string(cfg,
- "PATHS",
- "GNUNET_TEST_HOME",
- &directory));
- GNUNET_DISK_directory_remove (directory);
GNUNET_SCHEDULER_add_shutdown (&end,
NULL);
timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
"perf_namestore_api_%s.conf",
plugin_name);
res = 1;
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
if (0 !=
GNUNET_TESTING_peer_run ("perf-namestore-api-zone-iteration",
cfg_name,
{
res = 1;
}
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
GNUNET_free (cfg_name);
- if (NULL != directory)
- {
- GNUNET_DISK_directory_remove (directory);
- GNUNET_free (directory);
- }
return res;
}
*/
struct GNUNET_CONTAINER_MultiHashMap *hm;
- /**
- * Offset
- */
- uint32_t offset;
-
- /**
- * Target Offset
- */
- uint32_t target_offset;
-
- /**
- * Iterator closure
- */
- void *iter_cls;
-
- /**
- * Iterator
- */
- GNUNET_NAMESTORE_RecordIterator iter;
-
- /**
- * Zone to iterate
- */
- const struct GNUNET_CRYPTO_EcdsaPrivateKey *iter_zone;
-
- /**
- * PKEY to look for in zone to name
- */
- const struct GNUNET_CRYPTO_EcdsaPublicKey *iter_pkey;
-
- /**
- * Iteration result found
- */
- int iter_result_found;
-
};
&record_data_b64);
}
GNUNET_asprintf (&line,
- "%s,%lu,%u,%s,%s\n",
+ "%s,%llu,%u,%s,%s\n",
zone_private_key,
- entry->rvalue,
- entry->record_count,
+ (unsigned long long) entry->rvalue,
+ (unsigned int) entry->record_count,
record_data_b64,
entry->label);
GNUNET_free (record_data_b64);
struct FlatFileEntry *entry = value;
(void) key;
- ic->pos++;
if (0 == ic->limit)
return GNUNET_NO;
if ( (NULL != ic->zone) &&
ic->zone,
sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) )
return GNUNET_YES;
+ ic->pos++;
if (ic->offset > 0)
{
ic->offset--;
}
+/**
+ * Closure for #zone_to_name.
+ */
+struct ZoneToNameContext
+{
+ const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone;
+ const struct GNUNET_CRYPTO_EcdsaPublicKey *value_zone;
+ GNUNET_NAMESTORE_RecordIterator iter;
+ void *iter_cls;
+
+ int result_found;
+};
+
+
static int
zone_to_name (void *cls,
const struct GNUNET_HashCode *key,
void *value)
{
- struct Plugin *plugin = cls;
+ struct ZoneToNameContext *ztn = cls;
struct FlatFileEntry *entry = value;
(void) key;
if (0 != memcmp (entry->private_key,
- plugin->iter_zone,
+ ztn->zone,
sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)))
return GNUNET_YES;
{
if (GNUNET_GNSRECORD_TYPE_PKEY != entry->record_data[i].record_type)
continue;
- if (0 == memcmp (plugin->iter_pkey,
+ if (0 == memcmp (ztn->value_zone,
entry->record_data[i].data,
sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)))
{
- plugin->iter (plugin->iter_cls,
- 0,
- entry->private_key,
- entry->label,
- entry->record_count,
- entry->record_data);
- plugin->iter_result_found = GNUNET_YES;
-
+ ztn->iter (ztn->iter_cls,
+ 0,
+ entry->private_key,
+ entry->label,
+ entry->record_count,
+ entry->record_data);
+ ztn->result_found = GNUNET_YES;
}
}
return GNUNET_YES;
void *iter_cls)
{
struct Plugin *plugin = cls;
+ struct ZoneToNameContext ztn = {
+ .iter = iter,
+ .iter_cls = iter_cls,
+ .zone = zone,
+ .value_zone = value_zone,
+ .result_found = GNUNET_NO
+ };
- /* FIXME: maybe use separate closure to better handle
- recursive calls? */
- plugin->iter = iter;
- plugin->iter_cls = iter_cls;
- plugin->iter_zone = zone;
- plugin->iter_pkey = value_zone;
- plugin->iter_result_found = GNUNET_NO;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Performing reverse lookup for `%s'\n",
GNUNET_GNSRECORD_z2s (value_zone));
GNUNET_CONTAINER_multihashmap_iterate (plugin->hm,
&zone_to_name,
- plugin);
- return plugin->iter_result_found;
+ &ztn);
+ return ztn.result_found;
}
};
-/**
- * @brief Prepare a SQL statement
- *
- * @param dbh handle to the database
- * @param zSql SQL statement, UTF-8 encoded
- * @param ppStmt set to the prepared statement
- * @return 0 on success
- */
-static int
-sq_prepare (sqlite3 *dbh,
- const char *zSql,
- sqlite3_stmt **ppStmt)
-{
- char *dummy;
- int result;
-
- result =
- sqlite3_prepare_v2 (dbh,
- zSql,
- strlen (zSql),
- ppStmt,
- (const char **) &dummy);
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Prepared `%s' / %p: %d\n",
- zSql,
- *ppStmt,
- result);
- return result;
-}
-
-
-/**
- * Create our database indices.
- *
- * @param dbh handle to the database
- */
-static void
-create_indices (sqlite3 * dbh)
-{
- /* create indices */
- if ( (SQLITE_OK !=
- sqlite3_exec (dbh,
- "CREATE INDEX IF NOT EXISTS ir_pkey_reverse "
- "ON ns098records (zone_private_key,pkey)",
- NULL, NULL, NULL)) ||
- (SQLITE_OK !=
- sqlite3_exec (dbh,
- "CREATE INDEX IF NOT EXISTS ir_pkey_iter "
- "ON ns098records (zone_private_key,uid)",
- NULL, NULL, NULL)) )
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "Failed to create indices: %s\n",
- sqlite3_errmsg (dbh));
-}
-
-
-#if 0
-#define CHECK(a) GNUNET_break(a)
-#define ENULL NULL
-#else
-#define ENULL &e
-#define ENULL_DEFINED 1
-#define CHECK(a) if (! (a)) { GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "%s\n", e); sqlite3_free(e); }
-#endif
-
-
/**
* Initialize the database connections and associated
* data structures (create tables and indices
static int
database_setup (struct Plugin *plugin)
{
- sqlite3_stmt *stmt;
- char *afsdir;
-#if ENULL_DEFINED
- char *e;
-#endif
+ char *sqlite_filename;
+ struct GNUNET_SQ_ExecuteStatement es[] = {
+ GNUNET_SQ_make_try_execute ("PRAGMA temp_store=MEMORY"),
+ GNUNET_SQ_make_try_execute ("PRAGMA synchronous=NORMAL"),
+ GNUNET_SQ_make_try_execute ("PRAGMA legacy_file_format=OFF"),
+ GNUNET_SQ_make_try_execute ("PRAGMA auto_vacuum=INCREMENTAL"),
+ GNUNET_SQ_make_try_execute ("PRAGMA encoding=\"UTF-8\""),
+ GNUNET_SQ_make_try_execute ("PRAGMA locking_mode=EXCLUSIVE"),
+ GNUNET_SQ_make_try_execute ("PRAGMA page_size=4092"),
+ GNUNET_SQ_make_execute ("CREATE TABLE IF NOT EXISTS ns098records ("
+ " uid INTEGER PRIMARY KEY,"
+ " zone_private_key BLOB NOT NULL,"
+ " pkey BLOB,"
+ " rvalue INT8 NOT NULL,"
+ " record_count INT NOT NULL,"
+ " record_data BLOB NOT NULL,"
+ " label TEXT NOT NULL"
+ ")"),
+ GNUNET_SQ_make_try_execute ("CREATE INDEX IF NOT EXISTS ir_pkey_reverse "
+ "ON ns098records (zone_private_key,pkey)"),
+ GNUNET_SQ_make_try_execute ("CREATE INDEX IF NOT EXISTS ir_pkey_iter "
+ "ON ns098records (zone_private_key,uid)"),
+ GNUNET_SQ_EXECUTE_STATEMENT_END
+ };
+ struct GNUNET_SQ_PrepareStatement ps[] = {
+ GNUNET_SQ_make_prepare ("INSERT INTO ns098records "
+ "(zone_private_key,pkey,rvalue,record_count,record_data,label)"
+ " VALUES (?, ?, ?, ?, ?, ?)",
+ &plugin->store_records),
+ GNUNET_SQ_make_prepare ("DELETE FROM ns098records "
+ "WHERE zone_private_key=? AND label=?",
+ &plugin->delete_records),
+ GNUNET_SQ_make_prepare ("SELECT uid,record_count,record_data,label"
+ " FROM ns098records"
+ " WHERE zone_private_key=? AND pkey=?",
+ &plugin->zone_to_name),
+ GNUNET_SQ_make_prepare ("SELECT uid,record_count,record_data,label"
+ " FROM ns098records"
+ " WHERE zone_private_key=? AND _rowid_ >= ?"
+ " ORDER BY _rowid_ ASC"
+ " LIMIT ?",
+ &plugin->iterate_zone),
+ GNUNET_SQ_make_prepare ("SELECT uid,record_count,record_data,label,zone_private_key"
+ " FROM ns098records"
+ " WHERE _rowid_ >= ?"
+ " ORDER BY _rowid_ ASC"
+ " LIMIT ?",
+ &plugin->iterate_all_zones),
+ GNUNET_SQ_make_prepare ("SELECT uid,record_count,record_data,label,zone_private_key"
+ " FROM ns098records"
+ " WHERE zone_private_key=? AND label=?",
+ &plugin->lookup_label),
+ GNUNET_SQ_PREPARE_END
+ };
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_filename (plugin->cfg,
"namestore-sqlite",
"FILENAME",
- &afsdir))
+ &sqlite_filename))
{
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
"namestore-sqlite",
return GNUNET_SYSERR;
}
if (GNUNET_OK !=
- GNUNET_DISK_file_test (afsdir))
+ GNUNET_DISK_file_test (sqlite_filename))
{
if (GNUNET_OK !=
- GNUNET_DISK_directory_create_for_file (afsdir))
+ GNUNET_DISK_directory_create_for_file (sqlite_filename))
{
GNUNET_break (0);
- GNUNET_free (afsdir);
+ GNUNET_free (sqlite_filename);
return GNUNET_SYSERR;
}
}
- /* afsdir should be UTF-8-encoded. If it isn't, it's a bug */
- plugin->fn = afsdir;
+ /* sqlite_filename should be UTF-8-encoded. If it isn't, it's a bug */
+ plugin->fn = sqlite_filename;
/* Open database and precompile statements */
- if (sqlite3_open (plugin->fn, &plugin->dbh) != SQLITE_OK)
+ if (SQLITE_OK !=
+ sqlite3_open (plugin->fn,
+ &plugin->dbh))
{
LOG (GNUNET_ERROR_TYPE_ERROR,
_("Unable to initialize SQLite: %s.\n"),
sqlite3_errmsg (plugin->dbh));
return GNUNET_SYSERR;
}
- CHECK (SQLITE_OK ==
- sqlite3_exec (plugin->dbh,
- "PRAGMA temp_store=MEMORY", NULL, NULL,
- ENULL));
- CHECK (SQLITE_OK ==
- sqlite3_exec (plugin->dbh,
- "PRAGMA synchronous=NORMAL", NULL, NULL,
- ENULL));
- CHECK (SQLITE_OK ==
- sqlite3_exec (plugin->dbh,
- "PRAGMA legacy_file_format=OFF", NULL, NULL,
- ENULL));
- CHECK (SQLITE_OK ==
- sqlite3_exec (plugin->dbh,
- "PRAGMA auto_vacuum=INCREMENTAL", NULL,
- NULL, ENULL));
- CHECK (SQLITE_OK ==
- sqlite3_exec (plugin->dbh,
- "PRAGMA encoding=\"UTF-8\"", NULL,
- NULL, ENULL));
- CHECK (SQLITE_OK ==
- sqlite3_exec (plugin->dbh,
- "PRAGMA locking_mode=EXCLUSIVE", NULL, NULL,
- ENULL));
- CHECK (SQLITE_OK ==
- sqlite3_exec (plugin->dbh,
- "PRAGMA page_size=4092", NULL, NULL,
- ENULL));
-
- CHECK (SQLITE_OK ==
- sqlite3_busy_timeout (plugin->dbh,
- BUSY_TIMEOUT_MS));
-
-
- /* Create table */
- CHECK (SQLITE_OK ==
- sq_prepare (plugin->dbh,
- "SELECT 1 FROM sqlite_master WHERE tbl_name = 'ns098records'",
- &stmt));
- if ( (sqlite3_step (stmt) == SQLITE_DONE) &&
- (SQLITE_OK !=
- sqlite3_exec (plugin->dbh,
- "CREATE TABLE ns098records ("
- " uid INTEGER PRIMARY KEY,"
- " zone_private_key BLOB NOT NULL,"
- " pkey BLOB,"
- " rvalue INT8 NOT NULL,"
- " record_count INT NOT NULL,"
- " record_data BLOB NOT NULL,"
- " label TEXT NOT NULL"
- ")",
- NULL, NULL, NULL)) )
+ GNUNET_break (SQLITE_OK ==
+ sqlite3_busy_timeout (plugin->dbh,
+ BUSY_TIMEOUT_MS));
+ if (GNUNET_OK !=
+ GNUNET_SQ_exec_statements (plugin->dbh,
+ es))
{
- LOG_SQLITE (plugin,
- GNUNET_ERROR_TYPE_ERROR,
- "sqlite3_exec");
- sqlite3_finalize (stmt);
+ GNUNET_break (0);
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ _("Failed to setup database at `%s'\n"),
+ plugin->fn);
return GNUNET_SYSERR;
}
- sqlite3_finalize (stmt);
-
- create_indices (plugin->dbh);
-
- if ( (SQLITE_OK !=
- sq_prepare (plugin->dbh,
- "INSERT INTO ns098records (zone_private_key, pkey, rvalue, record_count, record_data, label)"
- " VALUES (?, ?, ?, ?, ?, ?)",
- &plugin->store_records)) ||
- (SQLITE_OK !=
- sq_prepare (plugin->dbh,
- "DELETE FROM ns098records WHERE zone_private_key=? AND label=?",
- &plugin->delete_records)) ||
- (SQLITE_OK !=
- sq_prepare (plugin->dbh,
- "SELECT uid,record_count,record_data,label"
- " FROM ns098records"
- " WHERE zone_private_key=? AND pkey=?",
- &plugin->zone_to_name)) ||
- (SQLITE_OK !=
- sq_prepare (plugin->dbh,
- "SELECT uid,record_count,record_data,label"
- " FROM ns098records"
- " WHERE zone_private_key=? AND _rowid_ >= ?"
- " ORDER BY _rowid_ ASC"
- " LIMIT ?",
- &plugin->iterate_zone)) ||
- (SQLITE_OK !=
- sq_prepare (plugin->dbh,
- "SELECT uid,record_count,record_data,label,zone_private_key"
- " FROM ns098records"
- " WHERE _rowid_ >= ?"
- " ORDER BY _rowid_ ASC"
- " LIMIT ?",
- &plugin->iterate_all_zones)) ||
- (SQLITE_OK !=
- sq_prepare (plugin->dbh,
- "SELECT uid,record_count,record_data,label,zone_private_key"
- " FROM ns098records"
- " WHERE zone_private_key=? AND label=?",
- &plugin->lookup_label))
- )
+
+ if (GNUNET_OK !=
+ GNUNET_SQ_prepare (plugin->dbh,
+ ps))
{
- LOG_SQLITE (plugin,
- GNUNET_ERROR_TYPE_ERROR,
- "precompiling");
+ GNUNET_break (0);
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ _("Failed to setup database at `%s'\n"),
+ plugin->fn);
return GNUNET_SYSERR;
}
return GNUNET_OK;
[identity]
AUTOSTART = YES
-[namestore-sqlite]
-FILENAME = $GNUNET_TEST_HOME/namestore/sqlite_test.db
-
-[namestore-postgres]
-CONFIG = connect_timeout=10; dbname=gnunetcheck
-TEMPORARY_TABLE = YES
-
[nse]
WORKBITS = 0
[namestore]
DATABASE = flat
+
+[namestore-flat]
+FILENAME = $GNUNET_TEST_HOME/namestore/flat.db
//static const char * name = "dummy.dummy.gnunet";
static const char * name = "d";
-static char *directory;
static void
cleanup ()
const struct GNUNET_CONFIGURATION_Handle *cfg,
struct GNUNET_TESTING_Peer *peer)
{
- char *hostkey_file;
-
- directory = NULL;
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS", "GNUNET_TEST_HOME", &directory));
- GNUNET_DISK_directory_remove (directory);
-
endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
- &endbadly, NULL);
- GNUNET_asprintf (&hostkey_file,
- "zonefiles%s%s",
- DIR_SEPARATOR_STR,
- "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
- privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file);
- GNUNET_free (hostkey_file);
+ &endbadly,
+ NULL);
+ privkey = GNUNET_CRYPTO_ecdsa_key_create ();
GNUNET_assert (privkey != NULL);
- GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey);
+ GNUNET_CRYPTO_ecdsa_key_get_public (privkey,
+ &pubkey);
nsh = GNUNET_NAMESTORE_connect (cfg);
GNUNET_break (NULL != nsh);
- nsqe = GNUNET_NAMESTORE_set_nick (nsh, privkey, TEST_NICK, &nick_cont, (void *) name);
+ nsqe = GNUNET_NAMESTORE_set_nick (nsh,
+ privkey,
+ TEST_NICK,
+ &nick_cont,
+ (void *) name);
if (NULL == nsqe)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
GNUNET_asprintf (&cfg_name,
"test_namestore_api_%s.conf",
plugin_name);
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
res = 1;
if (0 !=
GNUNET_TESTING_peer_run ("test-namestore-api-lookup-nick",
{
res = 1;
}
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
GNUNET_free (cfg_name);
- if (NULL != directory)
- {
- GNUNET_DISK_directory_remove (directory);
- GNUNET_free (directory);
- }
return res;
}
//static const char * name = "dummy.dummy.gnunet";
static const char * name = "d";
-static char *directory;
static void
cleanup ()
* Re-establish the connection to the service.
*
* @param cls handle to use to re-connect.
- * @param tc scheduler context
*/
static void
endbadly (void *cls)
{
+ endbadly_task = NULL;
if (NULL != nsqe)
{
GNUNET_NAMESTORE_cancel (nsqe);
{
GNUNET_break(0);
GNUNET_SCHEDULER_cancel (endbadly_task);
- endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL );
+ endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
return;
}
{
GNUNET_break(0);
GNUNET_SCHEDULER_cancel (endbadly_task);
- endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL );
+ endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
return;
}
{
GNUNET_break(0);
GNUNET_SCHEDULER_cancel (endbadly_task);
- endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL );
+ endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
return;
}
{
GNUNET_break(0);
GNUNET_SCHEDULER_cancel (endbadly_task);
- endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL );
+ endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
return;
}
/* Done */
GNUNET_SCHEDULER_cancel (endbadly_task);
endbadly_task = NULL;
- GNUNET_SCHEDULER_add_now (&end, NULL );
+ GNUNET_SCHEDULER_add_now (&end, NULL);
}
static void
-put_cont (void *cls, int32_t success, const char *emsg)
+put_cont (void *cls,
+ int32_t success,
+ const char *emsg)
{
const char *name = cls;
struct GNUNET_TESTING_Peer *peer)
{
struct GNUNET_GNSRECORD_Data rd;
- char *hostkey_file;
-
- directory = NULL;
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS", "GNUNET_TEST_HOME", &directory));
- GNUNET_DISK_directory_remove (directory);
endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
- &endbadly, NULL);
- GNUNET_asprintf (&hostkey_file,
- "zonefiles%s%s",
- DIR_SEPARATOR_STR,
- "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
- privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file);
- GNUNET_free (hostkey_file);
+ &endbadly,
+ NULL);
+ privkey = GNUNET_CRYPTO_ecdsa_key_create ();
GNUNET_assert (privkey != NULL);
GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey);
nsh = GNUNET_NAMESTORE_connect (cfg);
GNUNET_break (NULL != nsh);
- nsqe = GNUNET_NAMESTORE_records_store (nsh, privkey, name,
- 1, &rd, &put_cont, (void *) name);
+ nsqe = GNUNET_NAMESTORE_records_store (nsh,
+ privkey,
+ name,
+ 1,
+ &rd,
+ &put_cont,
+ (void *) name);
if (NULL == nsqe)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
GNUNET_asprintf (&cfg_name,
"test_namestore_api_%s.conf",
plugin_name);
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
res = 1;
if (0 !=
GNUNET_TESTING_peer_run ("test-namestore-api-lookup-private",
{
res = 1;
}
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
GNUNET_free (cfg_name);
- if (NULL != directory)
- {
- GNUNET_DISK_directory_remove (directory);
- GNUNET_free (directory);
- }
return res;
}
static struct GNUNET_NAMECACHE_QueueEntry *ncqe;
-static char *directory;
static void
cleanup ()
struct GNUNET_TESTING_Peer *peer)
{
struct GNUNET_GNSRECORD_Data rd;
- char *hostkey_file;
const char * name = "dummy.dummy.gnunet";
- directory = NULL;
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS", "GNUNET_TEST_HOME", &directory));
- GNUNET_DISK_directory_remove (directory);
-
endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
- &endbadly, NULL);
- GNUNET_asprintf (&hostkey_file,
- "zonefiles%s%s",
- DIR_SEPARATOR_STR,
- "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
- privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file);
- GNUNET_free (hostkey_file);
+ &endbadly,
+ NULL);
+ privkey = GNUNET_CRYPTO_ecdsa_key_create ();
GNUNET_assert (privkey != NULL);
- GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey);
-
+ GNUNET_CRYPTO_ecdsa_key_get_public (privkey,
+ &pubkey);
rd.expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000;
rd.record_type = TEST_RECORD_TYPE;
GNUNET_asprintf (&cfg_name,
"test_namestore_api_%s.conf",
plugin_name);
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
res = 1;
if (0 !=
GNUNET_TESTING_peer_run ("test-namestore-api",
{
res = 1;
}
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
GNUNET_free (cfg_name);
- if (NULL != directory)
- {
- GNUNET_DISK_directory_remove (directory);
- GNUNET_free (directory);
- }
return res;
}
static struct GNUNET_NAMECACHE_QueueEntry *ncqe;
-static char *directory;
static void
cleanup ()
struct GNUNET_TESTING_Peer *peer)
{
struct GNUNET_GNSRECORD_Data rd;
- char *hostkey_file;
const char * name = "dummy.dummy.gnunet";
- directory = NULL;
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS", "GNUNET_TEST_HOME", &directory));
- GNUNET_DISK_directory_remove (directory);
-
endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
- &endbadly, NULL);
- GNUNET_asprintf (&hostkey_file,
- "zonefiles%s%s",
- DIR_SEPARATOR_STR,
- "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
- privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file);
- GNUNET_free (hostkey_file);
+ &endbadly,
+ NULL);
+ privkey = GNUNET_CRYPTO_ecdsa_key_create ();
GNUNET_assert (privkey != NULL);
- GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey);
-
+ GNUNET_CRYPTO_ecdsa_key_get_public (privkey,
+ &pubkey);
rd.expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000;
rd.record_type = TEST_RECORD_TYPE;
rd.data_size = TEST_RECORD_DATALEN;
nch = GNUNET_NAMECACHE_connect (cfg);
GNUNET_break (NULL != nsh);
GNUNET_break (NULL != nch);
- nsqe = GNUNET_NAMESTORE_records_store (nsh, privkey, name,
- 1, &rd, &put_cont, (void *) name);
+ nsqe = GNUNET_NAMESTORE_records_store (nsh,
+ privkey,
+ name,
+ 1,
+ &rd,
+ &put_cont,
+ (void *) name);
if (NULL == nsqe)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
GNUNET_asprintf (&cfg_name,
"test_namestore_api_%s.conf",
plugin_name);
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
res = 1;
if (0 !=
GNUNET_TESTING_peer_run ("test-namestore-api-lookup-shadow",
res = 1;
}
GNUNET_free (cfg_name);
- if (NULL != directory)
- {
- GNUNET_DISK_directory_remove (directory);
- GNUNET_free (directory);
- }
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
return res;
}
static struct GNUNET_CRYPTO_EcdsaPublicKey pubkey;
-static char *directory;
static void
cleanup ()
const struct GNUNET_CONFIGURATION_Handle *cfg,
struct GNUNET_TESTING_Peer *peer)
{
- char *hostkey_file;
-
- directory = NULL;
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS", "GNUNET_TEST_HOME", &directory));
- GNUNET_DISK_directory_remove (directory);
-
endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
- &endbadly, NULL);
- GNUNET_asprintf (&hostkey_file,
- "zonefiles%s%s",
- DIR_SEPARATOR_STR,
- "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
- privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file);
- GNUNET_free (hostkey_file);
+ &endbadly,
+ NULL);
+ privkey = GNUNET_CRYPTO_ecdsa_key_create ();
GNUNET_assert (privkey != NULL);
- GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey);
+ GNUNET_CRYPTO_ecdsa_key_get_public (privkey,
+ &pubkey);
- record_expiration = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), EXPIRATION);
+ record_expiration = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get(),
+ EXPIRATION);
records[0].expiration_time = record_expiration.abs_value_us;
records[0].record_type = TEST_RECORD_TYPE;
records[0].data_size = TEST_RECORD_DATALEN;
GNUNET_asprintf (&cfg_name,
"test_namestore_api_%s.conf",
plugin_name);
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
res = 1;
if (0 !=
GNUNET_TESTING_peer_run ("test-namestore-api-lookup-shadow-filter",
res = 1;
}
GNUNET_free (cfg_name);
- if (NULL != directory)
- {
- GNUNET_DISK_directory_remove (directory);
- GNUNET_free (directory);
- }
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
return res;
}
struct GNUNET_NAMESTORE_QueueEntry * ns_ops[3];
-static char *directory;
static void
do_shutdown ()
GNUNET_NAMESTORE_zone_monitor_stop (zm);
zm = NULL;
}
-
if (NULL != ns_ops[0])
{
GNUNET_NAMESTORE_cancel(ns_ops[0]);
GNUNET_NAMESTORE_cancel(ns_ops[2]);
ns_ops[2] = NULL;
}
-
if (NULL != nsh)
{
GNUNET_NAMESTORE_disconnect (nsh);
nsh = NULL;
}
-
GNUNET_free_non_null(s_name_1);
GNUNET_free_non_null(s_name_2);
GNUNET_free_non_null(s_name_3);
const struct GNUNET_CONFIGURATION_Handle *cfg,
struct GNUNET_TESTING_Peer *peer)
{
- char *hostkey_file;
-
res = 1;
-
- directory = NULL;
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS", "GNUNET_TEST_HOME", &directory));
- GNUNET_DISK_directory_remove (directory);
-
- GNUNET_asprintf(&hostkey_file,
- "zonefiles%s%s",
- DIR_SEPARATOR_STR,
- "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Using zonekey file `%s' \n", hostkey_file);
- privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file);
- GNUNET_free (hostkey_file);
+ privkey = GNUNET_CRYPTO_ecdsa_key_create ();
GNUNET_assert (privkey != NULL);
/* Start monitoring */
return;
}
- GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",
- DIR_SEPARATOR_STR,
- "HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
- privkey2 = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file);
- GNUNET_free (hostkey_file);
+ privkey2 = GNUNET_CRYPTO_ecdsa_key_create ();
GNUNET_assert (privkey2 != NULL);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 3\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Created record 3\n");
/* name in different zone */
GNUNET_asprintf(&s_name_3, "dummy3");
s_rd_3 = create_record(1);
"Created record 1\n");
GNUNET_asprintf(&s_name_1, "dummy1");
s_rd_1 = create_record(1);
- GNUNET_assert (NULL != (ns_ops[0] = GNUNET_NAMESTORE_records_store(nsh, privkey, s_name_1,
- 1, s_rd_1, &put_cont, s_name_1)));
+ GNUNET_assert (NULL != (ns_ops[0] =
+ GNUNET_NAMESTORE_records_store (nsh,
+ privkey,
+ s_name_1,
+ 1,
+ s_rd_1,
+ &put_cont,
+ s_name_1)));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 2 \n");
GNUNET_asprintf(&s_name_2, "dummy2");
s_rd_2 = create_record(1);
- GNUNET_assert (NULL != (ns_ops[1] = GNUNET_NAMESTORE_records_store(nsh, privkey, s_name_2,
- 1, s_rd_2, &put_cont, s_name_2)));
-
-
+ GNUNET_assert (NULL != (ns_ops[1] =
+ GNUNET_NAMESTORE_records_store (nsh,
+ privkey,
+ s_name_2,
+ 1,
+ s_rd_2,
+ &put_cont,
+ s_name_2)));
}
int
-main (int argc, char *argv[])
+main (int argc,
+ char *argv[])
{
const char *plugin_name;
char *cfg_name;
GNUNET_asprintf (&cfg_name,
"test_namestore_api_%s.conf",
plugin_name);
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
res = 1;
if (0 !=
GNUNET_TESTING_peer_run ("test-namestore-api-monitoring",
{
res = 1;
}
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
GNUNET_free (cfg_name);
- if (NULL != directory)
- {
- GNUNET_DISK_directory_remove (directory);
- GNUNET_free (directory);
- }
return res;
}
/*
This file is part of GNUnet.
- Copyright (C) 2013 GNUnet e.V.
+ Copyright (C) 2013, 2018 GNUnet e.V.
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
Boston, MA 02110-1301, USA.
*/
/**
- * @file namestore/test_namestore_api_monitoring.c
+ * @file namestore/test_namestore_api_monitoring_existing.c
* @brief testcase for zone monitoring functionality: add records first, then monitor
*/
#include "platform.h"
#include "namestore.h"
-#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100)
+#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
static const struct GNUNET_CONFIGURATION_Handle *cfg;
struct GNUNET_NAMESTORE_QueueEntry * ns_ops[3];
-static char *directory;
+
+/**
+ * Re-establish the connection to the service.
+ *
+ * @param cls handle to use to re-connect.
+ */
+static void
+endbadly (void *cls)
+{
+ endbadly_task = NULL;
+ GNUNET_break (0);
+ GNUNET_SCHEDULER_shutdown ();
+ res = 1;
+}
static void
-do_shutdown ()
+end (void *cls)
{
if (NULL != zm)
{
GNUNET_NAMESTORE_zone_monitor_stop (zm);
zm = NULL;
}
-
if (NULL != ns_ops[0])
{
GNUNET_NAMESTORE_cancel(ns_ops[0]);
GNUNET_NAMESTORE_cancel(ns_ops[2]);
ns_ops[2] = NULL;
}
-
+ if (NULL != endbadly_task)
+ {
+ GNUNET_SCHEDULER_cancel (endbadly_task);
+ endbadly_task = NULL;
+ }
if (NULL != nsh)
{
GNUNET_NAMESTORE_disconnect (nsh);
}
-/**
- * Re-establish the connection to the service.
- *
- * @param cls handle to use to re-connect.
- */
-static void
-endbadly (void *cls)
-{
- do_shutdown ();
- res = 1;
-}
-
-
-static void
-end (void *cls)
-{
- do_shutdown ();
- res = 0;
-}
-
-
static void
zone_proc (void *cls,
const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Monitoring returned wrong zone key\n");
GNUNET_break (0);
- GNUNET_SCHEDULER_cancel (endbadly_task);
- endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly,
- NULL);
+ GNUNET_SCHEDULER_shutdown ();
return;
}
1);
if (2 == ++returned_records)
{
- if (endbadly_task != NULL)
+ GNUNET_SCHEDULER_shutdown ();
+ if (GNUNET_YES == fail)
{
- GNUNET_SCHEDULER_cancel (endbadly_task);
- endbadly_task = NULL;
+ GNUNET_break (0);
+ res = 1;
}
- if (GNUNET_YES == fail)
- GNUNET_SCHEDULER_add_now (&endbadly,
- NULL);
else
- GNUNET_SCHEDULER_add_now (&end,
- NULL);
+ {
+ res = 0;
+ }
}
}
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Failed to created records\n");
GNUNET_break (0);
- GNUNET_SCHEDULER_cancel (endbadly_task);
- endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
+ res = 1;
+ GNUNET_SCHEDULER_shutdown ();
+ return;
}
if (3 == c)
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Failed to create zone monitor\n");
GNUNET_break (0);
- endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly,
- NULL);
+ res = 1;
+ GNUNET_SCHEDULER_shutdown ();
return;
}
}
const struct GNUNET_CONFIGURATION_Handle *mycfg,
struct GNUNET_TESTING_Peer *peer)
{
- char *hostkey_file;
-
- directory = NULL;
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string (mycfg,
- "PATHS",
- "GNUNET_TEST_HOME",
- &directory));
- GNUNET_DISK_directory_remove (directory);
-
res = 1;
-
- GNUNET_asprintf(&hostkey_file,
- "zonefiles%s%s",
- DIR_SEPARATOR_STR,
- "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Using zonekey file `%s' \n", hostkey_file);
- privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file);
- GNUNET_free (hostkey_file);
+ privkey = GNUNET_CRYPTO_ecdsa_key_create ();
GNUNET_assert (privkey != NULL);
cfg = mycfg;
- endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &endbadly, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&end,
+ NULL);
+ endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
+ &endbadly,
+ NULL);
/* Connect to namestore */
nsh = GNUNET_NAMESTORE_connect (cfg);
if (NULL == nsh)
return;
}
- GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",
- DIR_SEPARATOR_STR,
- "HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
- privkey2 = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file);
- GNUNET_free (hostkey_file);
+ privkey2 = GNUNET_CRYPTO_ecdsa_key_create ();
GNUNET_assert (privkey2 != NULL);
/* name in different zone */
GNUNET_asprintf(&s_name_3, "dummy3");
s_rd_3 = create_record(1);
- GNUNET_assert (NULL != (ns_ops[2] = GNUNET_NAMESTORE_records_store (nsh, privkey2, s_name_3,
- 1, s_rd_3, &put_cont, s_name_3)));
+ GNUNET_assert (NULL != (ns_ops[2] =
+ GNUNET_NAMESTORE_records_store (nsh,
+ privkey2,
+ s_name_3,
+ 1,
+ s_rd_3,
+ &put_cont,
+ s_name_3)));
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 1\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Created record 1\n");
GNUNET_asprintf(&s_name_1, "dummy1");
s_rd_1 = create_record(1);
- GNUNET_assert (NULL != (ns_ops[0] = GNUNET_NAMESTORE_records_store(nsh, privkey, s_name_1,
- 1, s_rd_1, &put_cont, s_name_1)));
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 2 \n");
+ GNUNET_assert (NULL != (ns_ops[0] =
+ GNUNET_NAMESTORE_records_store(nsh,
+ privkey,
+ s_name_1,
+ 1,
+ s_rd_1,
+ &put_cont,
+ s_name_1)));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Created record 2 \n");
GNUNET_asprintf(&s_name_2, "dummy2");
s_rd_2 = create_record(1);
GNUNET_assert (NULL != (ns_ops[1] =
"test_namestore_api_%s.conf",
plugin_name);
res = 1;
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
if (0 !=
GNUNET_TESTING_peer_run ("test-namestore-api-monitoring-existing",
cfg_name,
{
res = 1;
}
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
GNUNET_free (cfg_name);
- if (NULL != directory)
- {
- GNUNET_DISK_directory_remove (directory);
- GNUNET_free (directory);
- }
return res;
}
[namestore]
DATABASE = postgres
+
+
+[namestore-postgres]
+CONFIG = connect_timeout=10; dbname=gnunetcheck
+TEMPORARY_TABLE = YES
static struct GNUNET_NAMESTORE_QueueEntry *nsqe;
-static char *directory;
static void
cleanup ()
struct GNUNET_TESTING_Peer *peer)
{
struct GNUNET_GNSRECORD_Data rd;
- char *hostkey_file;
const char * name = "dummy.dummy.gnunet";
- directory = NULL;
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string(cfg,
- "PATHS",
- "GNUNET_TEST_HOME",
- &directory));
- GNUNET_DISK_directory_remove (directory);
-
endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
&endbadly,
NULL);
- GNUNET_asprintf (&hostkey_file,
- "zonefiles%s%s",
- DIR_SEPARATOR_STR,
- "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Using zonekey file `%s' \n",
- hostkey_file);
- privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file);
- GNUNET_free (hostkey_file);
+ privkey = GNUNET_CRYPTO_ecdsa_key_create ();
GNUNET_assert (privkey != NULL);
GNUNET_CRYPTO_ecdsa_key_get_public (privkey,
&pubkey);
rd.data_size = TEST_RECORD_DATALEN;
rd.data = GNUNET_malloc (TEST_RECORD_DATALEN);
rd.flags = 0;
- memset ((char *) rd.data, 'a', TEST_RECORD_DATALEN);
+ memset ((char *) rd.data,
+ 'a',
+ TEST_RECORD_DATALEN);
nsh = GNUNET_NAMESTORE_connect (cfg);
GNUNET_break (NULL != nsh);
- nsqe = GNUNET_NAMESTORE_records_store (nsh, privkey, name,
- 1, &rd, &put_cont, (void *) name);
+ nsqe = GNUNET_NAMESTORE_records_store (nsh,
+ privkey,
+ name,
+ 1,
+ &rd,
+ &put_cont,
+ (void *) name);
if (NULL == nsqe)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
GNUNET_asprintf (&cfg_name,
"test_namestore_api_%s.conf",
plugin_name);
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
res = 1;
if (0 !=
GNUNET_TESTING_peer_run ("test-namestore-api-remove",
{
res = 1;
}
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
GNUNET_free (cfg_name);
- if (NULL != directory)
- {
- GNUNET_DISK_directory_remove (directory);
- GNUNET_free (directory);
- }
return res;
}
static struct GNUNET_NAMESTORE_QueueEntry *nsqe;
-static char *directory;
static void
cleanup ()
static void
-put_cont (void *cls, int32_t success, const char *emsg)
+put_cont (void *cls,
+ int32_t success,
+ const char *emsg)
{
GNUNET_assert (NULL != cls);
nsqe = NULL;
GNUNET_SCHEDULER_cancel (endbadly_task);
endbadly_task = NULL;
}
-
- switch (success) {
+ switch (success)
+ {
case GNUNET_NO:
/* We expected GNUNET_NO, since record was not found */
GNUNET_SCHEDULER_add_now (&end, NULL);
const struct GNUNET_CONFIGURATION_Handle *cfg,
struct GNUNET_TESTING_Peer *peer)
{
- char *hostkey_file;
const char * name = "dummy.dummy.gnunet";
- directory = NULL;
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS", "GNUNET_TEST_HOME", &directory));
- GNUNET_DISK_directory_remove (directory);
-
endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
- &endbadly, NULL);
- GNUNET_asprintf (&hostkey_file,
- "zonefiles%s%s",
- DIR_SEPARATOR_STR,
- "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Using zonekey file `%s' \n",
- hostkey_file);
- privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file);
- GNUNET_free (hostkey_file);
+ &endbadly,
+ NULL);
+ privkey = GNUNET_CRYPTO_ecdsa_key_create ();
GNUNET_assert (privkey != NULL);
GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey);
GNUNET_asprintf (&cfg_name,
"test_namestore_api_%s.conf",
plugin_name);
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
res = 1;
if (0 !=
GNUNET_TESTING_peer_run ("test-namestore-api-remove-non-existing-record",
{
res = 1;
}
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
GNUNET_free (cfg_name);
- if (NULL != directory)
- {
- GNUNET_DISK_directory_remove (directory);
- GNUNET_free (directory);
- }
return res;
}
[namestore]
DATABASE = sqlite
+
+[namestore-sqlite]
+FILENAME = $GNUNET_TEST_HOME/namestore/sqlite_test.db
static struct GNUNET_NAMESTORE_QueueEntry *nsqe;
-static char *directory;
static void
cleanup ()
struct GNUNET_TESTING_Peer *peer)
{
struct GNUNET_GNSRECORD_Data rd;
- char *hostkey_file;
const char * name = "dummy.dummy.gnunet";
- directory = NULL;
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS", "GNUNET_TEST_HOME", &directory));
- GNUNET_DISK_directory_remove (directory);
-
endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
&endbadly, NULL);
- GNUNET_asprintf (&hostkey_file,
- "zonefiles%s%s",
- DIR_SEPARATOR_STR,
- "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
- privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file);
- GNUNET_free (hostkey_file);
+ privkey = GNUNET_CRYPTO_ecdsa_key_create ();
GNUNET_assert (privkey != NULL);
GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey);
nsh = GNUNET_NAMESTORE_connect (cfg);
GNUNET_break (NULL != nsh);
- nsqe = GNUNET_NAMESTORE_records_store (nsh, privkey, name,
- 1, &rd, &put_cont, (void *) name);
+ nsqe = GNUNET_NAMESTORE_records_store (nsh,
+ privkey,
+ name,
+ 1,
+ &rd,
+ &put_cont,
+ (void *) name);
if (NULL == nsqe)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"test_namestore_api_%s.conf",
plugin_name);
res = 1;
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
if (0 !=
GNUNET_TESTING_peer_run ("test-namestore-api",
cfg_name,
{
res = 1;
}
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
GNUNET_free (cfg_name);
- if (NULL != directory)
- {
- GNUNET_DISK_directory_remove (directory);
- GNUNET_free (directory);
- }
return res;
}
/*
This file is part of GNUnet.
- Copyright (C) 2012, 2013 GNUnet e.V.
+ Copyright (C) 2012, 2013, 2018 GNUnet e.V.
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
* @file namestore/test_namestore_api_store_update.c
* @brief testcase for namestore_api.c: store a record, update it and perform a lookup
* @author Matthias Wachs
+ * @author Christian Grothoff
*/
#include "platform.h"
#include "gnunet_namecache_service.h"
#define TEST_RECORD_DATA 'a'
-
#define TEST_RECORD_TYPE2 4321
#define TEST_RECORD_DATALEN2 234
static const char *name = "dummy";
-static char *directory;
+/**
+ * Terminate test with error.
+ *
+ * @param cls handle to use to re-connect.
+ */
static void
-cleanup ()
+endbadly (void *cls)
{
- if (NULL != nsh)
- {
- GNUNET_NAMESTORE_disconnect (nsh);
- nsh = NULL;
- }
- if (NULL != nch)
- {
- GNUNET_NAMECACHE_disconnect (nch);
- nch = NULL;
- }
- if (NULL != privkey)
- {
- GNUNET_free (privkey);
- privkey = NULL;
- }
+ GNUNET_break (0);
+ endbadly_task = NULL;
GNUNET_SCHEDULER_shutdown ();
+ res = 1;
}
-/**
- * Re-establish the connection to the service.
- *
- * @param cls handle to use to re-connect.
- */
static void
-endbadly (void *cls)
+end (void *cls)
{
+ if (NULL != endbadly_task)
+ {
+ GNUNET_SCHEDULER_cancel (endbadly_task);
+ endbadly_task = NULL;
+ }
if (NULL != nsqe)
{
GNUNET_NAMESTORE_cancel (nsqe);
GNUNET_NAMECACHE_cancel (ncqe);
ncqe = NULL;
}
- cleanup ();
- res = 1;
-}
-
-
-static void
-end (void *cls)
-{
- cleanup ();
- res = 0;
+ if (NULL != nsh)
+ {
+ GNUNET_NAMESTORE_disconnect (nsh);
+ nsh = NULL;
+ }
+ if (NULL != nch)
+ {
+ GNUNET_NAMECACHE_disconnect (nch);
+ nch = NULL;
+ }
+ if (NULL != privkey)
+ {
+ GNUNET_free (privkey);
+ privkey = NULL;
+ }
}
static void
-put_cont (void *cls, int32_t success, const char *emsg);
+put_cont (void *cls,
+ int32_t success,
+ const char *emsg);
static void
if (GNUNET_NO == update_performed)
{
char rd_cmp_data[TEST_RECORD_DATALEN];
- memset (rd_cmp_data, TEST_RECORD_DATA, TEST_RECORD_DATALEN);
+ memset (rd_cmp_data,
+ TEST_RECORD_DATA,
+ TEST_RECORD_DATALEN);
GNUNET_assert (TEST_RECORD_TYPE == rd[0].record_type);
GNUNET_assert (TEST_RECORD_DATALEN == rd[0].data_size);
- GNUNET_assert (0 == memcmp (&rd_cmp_data, rd[0].data, TEST_RECORD_DATALEN));
+ GNUNET_assert (0 == memcmp (&rd_cmp_data,
+ rd[0].data,
+ TEST_RECORD_DATALEN));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Block was decrypted successfully, updating record \n");
rd_new.record_type = TEST_RECORD_TYPE2;
rd_new.data_size = TEST_RECORD_DATALEN2;
rd_new.data = GNUNET_malloc (TEST_RECORD_DATALEN2);
- memset ((char *) rd_new.data, TEST_RECORD_DATA2, TEST_RECORD_DATALEN2);
+ memset ((char *) rd_new.data,
+ TEST_RECORD_DATA2,
+ TEST_RECORD_DATALEN2);
- nsqe = GNUNET_NAMESTORE_records_store (nsh, privkey, name,
- 1, &rd_new, &put_cont, (void *) name);
+ nsqe = GNUNET_NAMESTORE_records_store (nsh,
+ privkey,
+ name,
+ 1,
+ &rd_new,
+ &put_cont,
+ (void *) name);
update_performed = GNUNET_YES;
}
else
{
char rd_cmp_data[TEST_RECORD_DATALEN2];
- memset (rd_cmp_data, TEST_RECORD_DATA2, TEST_RECORD_DATALEN2);
+ memset (rd_cmp_data,
+ TEST_RECORD_DATA2,
+ TEST_RECORD_DATALEN2);
GNUNET_assert (TEST_RECORD_TYPE2 == rd[0].record_type);
GNUNET_assert (TEST_RECORD_DATALEN2 == rd[0].data_size);
- GNUNET_assert (0 == memcmp (&rd_cmp_data, rd[0].data, TEST_RECORD_DATALEN2));
-
- GNUNET_SCHEDULER_cancel (endbadly_task);
- endbadly_task = NULL;
- GNUNET_SCHEDULER_add_now (&end, NULL);
+ GNUNET_assert (0 == memcmp (&rd_cmp_data,
+ rd[0].data,
+ TEST_RECORD_DATALEN2));
+ GNUNET_SCHEDULER_shutdown ();
+ res = 0;
}
}
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_("Namecache returned no block for `%s'\n"),
name);
- if (endbadly_task != NULL)
- GNUNET_SCHEDULER_cancel (endbadly_task);
- endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
+ GNUNET_SCHEDULER_shutdown ();
return;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Namecache returned block, decrypting \n");
- GNUNET_assert (GNUNET_OK == GNUNET_GNSRECORD_block_decrypt(block,
- &pubkey, name, &rd_decrypt_cb, (void *) name));
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_GNSRECORD_block_decrypt (block,
+ &pubkey,
+ name,
+ &rd_decrypt_cb,
+ (void *) name));
}
static void
-put_cont (void *cls, int32_t success, const char *emsg)
+put_cont (void *cls,
+ int32_t success,
+ const char *emsg)
{
const char *name = cls;
struct GNUNET_HashCode derived_hash;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Looking in namecache for `%s'\n",
GNUNET_h2s (&derived_hash));
- ncqe = GNUNET_NAMECACHE_lookup_block (nch, &derived_hash,
+ ncqe = GNUNET_NAMECACHE_lookup_block (nch,
+ &derived_hash,
&name_lookup_proc, (void *) name);
}
struct GNUNET_TESTING_Peer *peer)
{
struct GNUNET_GNSRECORD_Data rd;
- char *hostkey_file;
-
- directory = NULL;
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS", "GNUNET_TEST_HOME", &directory));
- GNUNET_DISK_directory_remove (directory);
update_performed = GNUNET_NO;
+ GNUNET_SCHEDULER_add_shutdown (&end,
+ NULL);
endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
- &endbadly, NULL);
- GNUNET_asprintf (&hostkey_file,
- "zonefiles%s%s",
- DIR_SEPARATOR_STR,
- "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
- privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file);
- GNUNET_free (hostkey_file);
+ &endbadly,
+ NULL);
+ privkey = GNUNET_CRYPTO_ecdsa_key_create ();
GNUNET_assert (privkey != NULL);
- GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey);
-
+ GNUNET_CRYPTO_ecdsa_key_get_public (privkey,
+ &pubkey);
rd.flags = GNUNET_GNSRECORD_RF_NONE;
rd.expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000;
rd.record_type = TEST_RECORD_TYPE;
rd.data_size = TEST_RECORD_DATALEN;
rd.data = GNUNET_malloc (TEST_RECORD_DATALEN);
- memset ((char *) rd.data, TEST_RECORD_DATA, TEST_RECORD_DATALEN);
+ memset ((char *) rd.data,
+ TEST_RECORD_DATA,
+ TEST_RECORD_DATALEN);
nsh = GNUNET_NAMESTORE_connect (cfg);
GNUNET_break (NULL != nsh);
nch = GNUNET_NAMECACHE_connect (cfg);
GNUNET_break (NULL != nch);
nsqe = GNUNET_NAMESTORE_records_store (nsh,
- privkey, name,
- 1, &rd,
- &put_cont, (void *) name);
+ privkey,
+ name,
+ 1,
+ &rd,
+ &put_cont,
+ (void *) name);
if (NULL == nsqe)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
int
-main (int argc, char *argv[])
+main (int argc,
+ char *argv[])
{
const char *plugin_name;
char *cfg_name;
"test_namestore_api_%s.conf",
plugin_name);
res = 1;
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
if (0 !=
GNUNET_TESTING_peer_run ("test-namestore-api-store-update",
cfg_name,
{
res = 1;
}
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
GNUNET_free (cfg_name);
- if (NULL != directory)
- {
- GNUNET_DISK_directory_remove (directory);
- GNUNET_free (directory);
- }
return res;
}
-/* end of test_namestore_api_store_update.c*/
+/* end of test_namestore_api_store_update.c */
/*
This file is part of GNUnet.
- Copyright (C) 2013 GNUnet e.V.
+ Copyright (C) 2013, 2018 GNUnet e.V.
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
static struct GNUNET_GNSRECORD_Data *s_rd_3;
-static char *directory;
-
/**
* Re-establish the connection to the service.
static void
endbadly (void *cls)
{
- if (NULL != zi)
- {
- GNUNET_NAMESTORE_zone_iteration_stop (zi);
- zi = NULL;
- }
- if (nsh != NULL)
- {
- GNUNET_NAMESTORE_disconnect (nsh);
- nsh = NULL;
- }
- GNUNET_free_non_null(s_name_1);
- GNUNET_free_non_null(s_name_2);
- GNUNET_free_non_null(s_name_3);
-
- if (s_rd_1 != NULL)
- {
- GNUNET_free ((void *)s_rd_1->data);
- GNUNET_free (s_rd_1);
- }
- if (s_rd_2 != NULL)
- {
- GNUNET_free ((void *)s_rd_2->data);
- GNUNET_free (s_rd_2);
- }
- if (s_rd_3 != NULL)
- {
- GNUNET_free ((void *)s_rd_3->data);
- GNUNET_free (s_rd_3);
- }
-
- if (privkey != NULL)
- GNUNET_free (privkey);
- privkey = NULL;
-
- if (privkey2 != NULL)
- GNUNET_free (privkey2);
- privkey2 = NULL;
+ endbadly_task = NULL;
+ GNUNET_SCHEDULER_shutdown ();
res = 1;
}
GNUNET_NAMESTORE_zone_iteration_stop (zi);
zi = NULL;
}
- if (endbadly_task != NULL)
+ if (NULL != endbadly_task)
{
GNUNET_SCHEDULER_cancel (endbadly_task);
endbadly_task = NULL;
}
-
- if (privkey != NULL)
+ if (NULL != privkey)
+ {
GNUNET_free (privkey);
- privkey = NULL;
-
- if (privkey2 != NULL)
+ privkey = NULL;
+ }
+ if (NULL != privkey2)
+ {
GNUNET_free (privkey2);
- privkey2 = NULL;
-
+ privkey2 = NULL;
+ }
GNUNET_free (s_name_1);
GNUNET_free (s_name_2);
GNUNET_free (s_name_3);
- if (s_rd_1 != NULL)
+ if (NULL != s_rd_1)
{
GNUNET_free ((void *)s_rd_1->data);
GNUNET_free (s_rd_1);
}
- if (s_rd_2 != NULL)
+ if (NULL != s_rd_2)
{
GNUNET_free ((void *)s_rd_2->data);
GNUNET_free (s_rd_2);
}
- if (s_rd_3 != NULL)
+ if (NULL != s_rd_3)
{
GNUNET_free ((void *)s_rd_3->data);
GNUNET_free (s_rd_3);
}
- if (nsh != NULL)
+ if (NULL != nsh)
+ {
GNUNET_NAMESTORE_disconnect (nsh);
- nsh = NULL;
+ nsh = NULL;
+ }
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Received last result, iteration done after receing %u results\n",
returned_records);
- GNUNET_SCHEDULER_add_now (&end, NULL);
+ GNUNET_SCHEDULER_shutdown ();
}
int failed = GNUNET_NO;
GNUNET_assert (NULL != zone);
- if (0 == memcmp (zone, privkey, sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)))
+ if (0 == memcmp (zone,
+ privkey,
+ sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)))
{
if (0 == strcmp (label, s_name_1))
{
else
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Comparing result failed: got name `%s' for first zone\n", label);
+ "Comparing result failed: got name `%s' for first zone\n",
+ label);
failed = GNUNET_YES;
GNUNET_break (0);
}
}
- else if (0 == memcmp (zone, privkey2, sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)))
+ else if (0 == memcmp (zone,
+ privkey2,
+ sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)))
{
if (0 == strcmp (label, s_name_3))
{
else
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Comparing result failed: got name `%s' for first zone\n", label);
+ "Comparing result failed: got name `%s' for first zone\n",
+ label);
failed = GNUNET_YES;
GNUNET_break (0);
}
else
{
GNUNET_break (0);
- GNUNET_SCHEDULER_add_now (&end, NULL);
+ GNUNET_SCHEDULER_shutdown ();
+ res = 1;
}
}
static void
-put_cont (void *cls, int32_t success, const char *emsg)
+put_cont (void *cls,
+ int32_t success,
+ const char *emsg)
{
static int c = 0;
if (success == GNUNET_OK)
{
c++;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record %u \n", c);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Created record %u \n",
+ c);
}
else
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to created records: `%s'\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to created records: `%s'\n",
emsg);
GNUNET_break (0);
- if (NULL != endbadly_task)
- GNUNET_SCHEDULER_cancel (endbadly_task);
- endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
+ GNUNET_SCHEDULER_shutdown ();
+ res = 1;
return;
}
{
res = 1;
returned_records = 0;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All records created, starting iteration over all zones \n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "All records created, starting iteration over all zones \n");
zi = GNUNET_NAMESTORE_zone_iteration_start (nsh,
NULL,
&fail_cb,
NULL);
if (zi == NULL)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create zone iterator\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to create zone iterator\n");
GNUNET_break (0);
- if (NULL != endbadly_task)
- GNUNET_SCHEDULER_cancel (endbadly_task);
- endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
+ GNUNET_SCHEDULER_shutdown ();
+ res = 1;
return;
}
}
static struct GNUNET_GNSRECORD_Data *
create_record (unsigned int count)
{
- unsigned int c;
struct GNUNET_GNSRECORD_Data * rd;
- rd = GNUNET_malloc (count * sizeof (struct GNUNET_GNSRECORD_Data));
- for (c = 0; c < count; c++)
+ rd = GNUNET_new_array (count,
+ struct GNUNET_GNSRECORD_Data);
+ for (unsigned int c = 0; c < count; c++)
{
rd[c].expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS).abs_value_us;
rd[c].record_type = 1111;
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_("Expected empty zone but received zone private key\n"));
GNUNET_break (0);
- if (endbadly_task != NULL)
- GNUNET_SCHEDULER_cancel (endbadly_task);
- endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
+ GNUNET_SCHEDULER_shutdown ();
+ res = 1;
return;
}
if ((NULL != label) || (NULL != rd) || (0 != rd_count))
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_("Expected no zone content but received data\n"));
GNUNET_break (0);
- if (endbadly_task != NULL)
- GNUNET_SCHEDULER_cancel (endbadly_task);
- endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
+ GNUNET_SCHEDULER_shutdown ();
+ res = 1;
return;
}
GNUNET_assert (0);
"zonefiles%s%s",
DIR_SEPARATOR_STR,
"HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Using zonekey file `%s' \n",
+ hostkey_file);
privkey2 = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file);
GNUNET_free (hostkey_file);
GNUNET_assert (privkey2 != NULL);
privkey,
s_name_1,
1, s_rd_1,
- &put_cont, NULL);
-
+ &put_cont,
+ NULL);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Created record 2 \n");
GNUNET_asprintf(&s_name_2, "dummy2");
1, s_rd_2,
&put_cont,
NULL);
-
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Created record 3\n");
-
/* name in different zone */
GNUNET_asprintf(&s_name_3, "dummy3");
s_rd_3 = create_record(1);
- GNUNET_NAMESTORE_records_store (nsh, privkey2, s_name_3,
- 1, s_rd_3,
- &put_cont, NULL);
+ GNUNET_NAMESTORE_records_store (nsh,
+ privkey2,
+ s_name_3,
+ 1,
+ s_rd_3,
+ &put_cont,
+ NULL);
}
const struct GNUNET_CONFIGURATION_Handle *cfg,
struct GNUNET_TESTING_Peer *peer)
{
- directory = NULL;
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS",
- "GNUNET_TEST_HOME",
- &directory));
- GNUNET_DISK_directory_remove (directory);
-
- endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, &endbadly, NULL);
+ endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
+ &endbadly,
+ NULL);
+ GNUNET_SCHEDULER_add_shutdown (&end,
+ NULL);
+
nsh = GNUNET_NAMESTORE_connect (cfg);
GNUNET_break (NULL != nsh);
/* first, iterate over empty namestore */
- zi = GNUNET_NAMESTORE_zone_iteration_start(nsh,
- NULL,
- &fail_cb,
- NULL,
- &empty_zone_proc,
- nsh,
- &empty_zone_end,
- NULL);
+ zi = GNUNET_NAMESTORE_zone_iteration_start (nsh,
+ NULL,
+ &fail_cb,
+ NULL,
+ &empty_zone_proc,
+ nsh,
+ &empty_zone_end,
+ NULL);
if (NULL == zi)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create zone iterator\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to create zone iterator\n");
GNUNET_break (0);
- GNUNET_SCHEDULER_cancel (endbadly_task);
- endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
+ res = 1;
+ GNUNET_SCHEDULER_shutdown ();
}
}
GNUNET_asprintf (&cfg_name,
"test_namestore_api_%s.conf",
plugin_name);
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
res = 1;
if (0 !=
GNUNET_TESTING_peer_run ("test-namestore-api-zone-iteration",
{
res = 1;
}
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
GNUNET_free (cfg_name);
- if (NULL != directory)
- {
- GNUNET_DISK_directory_remove (directory);
- GNUNET_free (directory);
- }
return res;
}
static struct GNUNET_NAMESTORE_QueueEntry *nsqe;
-static char *directory;
/**
* Re-establish the connection to the service.
static void
-put_cont (void *cls, int32_t success, const char *emsg)
+put_cont (void *cls,
+ int32_t success,
+ const char *emsg)
{
static int c = 0;
static struct GNUNET_GNSRECORD_Data *
create_record (unsigned int count)
{
- unsigned int c;
struct GNUNET_GNSRECORD_Data * rd;
- rd = GNUNET_malloc (count * sizeof (struct GNUNET_GNSRECORD_Data));
- for (c = 0; c < count; c++)
+ rd = GNUNET_new_array (count,
+ struct GNUNET_GNSRECORD_Data);
+ for (unsigned int c = 0; c < count; c++)
{
rd[c].expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS).abs_value_us;
rd[c].record_type = 1111;
static void
-nick_2_cont (void *cls, int32_t success, const char *emsg)
+nick_2_cont (void *cls,
+ int32_t success,
+ const char *emsg)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Nick added : %s\n",
static void
empty_zone_end (void *cls)
{
- char *hostkey_file;
GNUNET_assert (nsh == cls);
-
zi = NULL;
- GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR,
- "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
- privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file);
- GNUNET_free (hostkey_file);
+ privkey = GNUNET_CRYPTO_ecdsa_key_create ();
GNUNET_assert (privkey != NULL);
-
- GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR,
- "HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
- privkey2 = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file);
- GNUNET_free (hostkey_file);
+ privkey2 = GNUNET_CRYPTO_ecdsa_key_create ();
GNUNET_assert (privkey2 != NULL);
- nsqe = GNUNET_NAMESTORE_set_nick (nsh, privkey, ZONE_NICK_1, &nick_1_cont, &privkey);
+ nsqe = GNUNET_NAMESTORE_set_nick (nsh,
+ privkey,
+ ZONE_NICK_1,
+ &nick_1_cont,
+ &privkey);
if (NULL == nsqe)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
const struct GNUNET_CONFIGURATION_Handle *cfg,
struct GNUNET_TESTING_Peer *peer)
{
- directory = NULL;
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string (cfg,
- "PATHS",
- "GNUNET_TEST_HOME",
- &directory));
- GNUNET_DISK_directory_remove (directory);
-
- endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, &endbadly, NULL);
+ endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
+ &endbadly,
+ NULL);
nsh = GNUNET_NAMESTORE_connect (cfg);
GNUNET_break (NULL != nsh);
"test_namestore_api_%s.conf",
plugin_name);
res = 1;
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
if (0 !=
GNUNET_TESTING_peer_run ("test-namestore-api-zone-iteration-nick",
cfg_name,
{
res = 1;
}
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
GNUNET_free (cfg_name);
- if (NULL != directory)
- {
- GNUNET_DISK_directory_remove (directory);
- GNUNET_free (directory);
- }
return res;
}
static struct GNUNET_GNSRECORD_Data *s_rd_3;
-static char *directory;
/**
- * Re-establish the connection to the service.
+ * Handle timeout.
*
* @param cls handle to use to re-connect.
- * @param tc scheduler context
*/
static void
endbadly (void *cls)
{
- if (NULL != zi)
- {
- GNUNET_NAMESTORE_zone_iteration_stop (zi);
- zi = NULL;
- }
- if (nsh != NULL)
- GNUNET_NAMESTORE_disconnect (nsh);
- nsh = NULL;
-
- GNUNET_free_non_null(s_name_1);
- GNUNET_free_non_null(s_name_2);
- GNUNET_free_non_null(s_name_3);
-
- if (s_rd_1 != NULL)
- {
- GNUNET_free ((void *)s_rd_1->data);
- GNUNET_free (s_rd_1);
- }
- if (s_rd_2 != NULL)
- {
- GNUNET_free ((void *)s_rd_2->data);
- GNUNET_free (s_rd_2);
- }
- if (s_rd_3 != NULL)
- {
- GNUNET_free ((void *)s_rd_3->data);
- GNUNET_free (s_rd_3);
- }
-
- if (privkey != NULL)
- GNUNET_free (privkey);
- privkey = NULL;
-
- if (privkey2 != NULL)
- GNUNET_free (privkey2);
- privkey2 = NULL;
+ endbadly_task = NULL;
+ GNUNET_SCHEDULER_shutdown ();
res = 1;
}
GNUNET_NAMESTORE_zone_iteration_stop (zi);
zi = NULL;
}
-
- if (endbadly_task != NULL)
+ if (NULL != endbadly_task)
{
GNUNET_SCHEDULER_cancel (endbadly_task);
endbadly_task = NULL;
}
-
- if (privkey != NULL)
+ if (NULL != privkey)
+ {
GNUNET_free (privkey);
- privkey = NULL;
-
- if (privkey2 != NULL)
+ privkey = NULL;
+ }
+ if (NULL != privkey2)
+ {
GNUNET_free (privkey2);
- privkey2 = NULL;
-
+ privkey2 = NULL;
+ }
GNUNET_free (s_name_1);
GNUNET_free (s_name_2);
GNUNET_free (s_name_3);
GNUNET_free (s_rd_3);
}
if (nsh != NULL)
+ {
GNUNET_NAMESTORE_disconnect (nsh);
- nsh = NULL;
+ nsh = NULL;
+ }
}
fail_cb (void *cls)
{
GNUNET_assert (0);
+ zi = NULL;
}
else
{
GNUNET_break (0);
- GNUNET_SCHEDULER_add_now (&end, NULL);
+ res = 2;
+ GNUNET_SCHEDULER_shutdown ();
}
}
static void
zone_proc_end (void *cls)
{
+ zi = NULL;
GNUNET_break (2 == returned_records);
if (2 == returned_records)
{
res = 0; /* Last iteraterator callback, we are done */
- zi = NULL;
}
else
+ {
res = 1;
+ }
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Received last result, iteration done after receing %u results\n",
returned_records);
- GNUNET_SCHEDULER_add_now (&end, NULL);
+ GNUNET_SCHEDULER_shutdown ();
}
static void
-put_cont (void *cls, int32_t success, const char *emsg)
+put_cont (void *cls,
+ int32_t success,
+ const char *emsg)
{
static int c = 0;
"Failed to created records: `%s'\n",
emsg);
GNUNET_break (0);
- if (NULL != endbadly_task)
- GNUNET_SCHEDULER_cancel (endbadly_task);
- endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
+ res = 2;
+ GNUNET_SCHEDULER_shutdown ();
return;
}
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Failed to create zone iterator\n");
GNUNET_break (0);
- if (NULL != endbadly_task)
- GNUNET_SCHEDULER_cancel (endbadly_task);
- endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
+ res = 2;
+ GNUNET_SCHEDULER_shutdown ();
return;
}
}
static struct GNUNET_GNSRECORD_Data *
create_record (unsigned int count)
{
- unsigned int c;
- struct GNUNET_GNSRECORD_Data * rd;
+ struct GNUNET_GNSRECORD_Data *rd;
- rd = GNUNET_malloc (count * sizeof (struct GNUNET_GNSRECORD_Data));
- for (c = 0; c < count; c++)
+ rd = GNUNET_new_array (count,
+ struct GNUNET_GNSRECORD_Data);
+ for (unsigned int c = 0; c < count; c++)
{
rd[c].expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS).abs_value_us;
rd[c].record_type = 1111;
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_("Expected empty zone but received zone private key\n"));
GNUNET_break (0);
- if (endbadly_task != NULL)
- GNUNET_SCHEDULER_cancel (endbadly_task);
- endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
+ res = 2;
+ GNUNET_SCHEDULER_shutdown ();
return;
}
if ((NULL != label) || (NULL != rd) || (0 != rd_count))
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_("Expected no zone content but received data\n"));
GNUNET_break (0);
- if (endbadly_task != NULL)
- GNUNET_SCHEDULER_cancel (endbadly_task);
- endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
+ res = 2;
+ GNUNET_SCHEDULER_shutdown ();
return;
}
GNUNET_assert (0);
static void
empty_zone_proc_end (void *cls)
{
- char *hostkey_file;
-
zi = NULL;
- GNUNET_asprintf (&hostkey_file,
- "zonefiles%s%s",
- DIR_SEPARATOR_STR,
- "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Using zonekey file `%s'\n",
- hostkey_file);
- privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file);
- GNUNET_free (hostkey_file);
+ privkey = GNUNET_CRYPTO_ecdsa_key_create ();
GNUNET_assert (privkey != NULL);
-
- GNUNET_asprintf(&hostkey_file,
- "zonefiles%s%s",
- DIR_SEPARATOR_STR,
- "HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Using zonekey file `%s' \n",
- hostkey_file);
- privkey2 = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file);
- GNUNET_free (hostkey_file);
+ privkey2 = GNUNET_CRYPTO_ecdsa_key_create ();
GNUNET_assert (privkey2 != NULL);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Created record 1\n");
-
- GNUNET_asprintf(&s_name_1, "dummy1");
+ GNUNET_asprintf (&s_name_1,
+ "dummy1");
s_rd_1 = create_record (1);
GNUNET_NAMESTORE_records_store (nsh,
privkey,
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Created record 2 \n");
- GNUNET_asprintf(&s_name_2, "dummy2");
+ GNUNET_asprintf (&s_name_2,
+ "dummy2");
s_rd_2 = create_record (1);
GNUNET_NAMESTORE_records_store (nsh,
privkey,
"Created record 3\n");
/* name in different zone */
- GNUNET_asprintf(&s_name_3, "dummy3");
+ GNUNET_asprintf (&s_name_3,
+ "dummy3");
s_rd_3 = create_record (1);
GNUNET_NAMESTORE_records_store (nsh,
privkey2,
const struct GNUNET_CONFIGURATION_Handle *cfg,
struct GNUNET_TESTING_Peer *peer)
{
- directory = NULL;
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string (cfg,
- "PATHS",
- "GNUNET_TEST_HOME",
- &directory));
- GNUNET_DISK_directory_remove (directory);
-
+ GNUNET_SCHEDULER_add_shutdown (&end,
+ NULL);
endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
&endbadly,
NULL);
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Failed to create zone iterator\n");
GNUNET_break (0);
- GNUNET_SCHEDULER_cancel (endbadly_task);
- endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
+ GNUNET_SCHEDULER_shutdown ();
}
}
"test_namestore_api_%s.conf",
plugin_name);
res = 1;
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
if (0 !=
GNUNET_TESTING_peer_run ("test-namestore-api-zone-iteration-specific-zone",
cfg_name,
{
res = 1;
}
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
GNUNET_free (cfg_name);
- if (NULL != directory)
- {
- GNUNET_DISK_directory_remove (directory);
- GNUNET_free (directory);
- }
return res;
}
static struct GNUNET_GNSRECORD_Data *s_rd_3;
-static char *directory;
/**
const struct GNUNET_CONFIGURATION_Handle *cfg,
struct GNUNET_TESTING_Peer *peer)
{
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string (cfg,
- "PATHS",
- "GNUNET_TEST_HOME",
- &directory));
- GNUNET_DISK_directory_remove (directory);
-
- endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &endbadly, NULL);
+ endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
+ &endbadly,
+ NULL);
nsh = GNUNET_NAMESTORE_connect (cfg);
GNUNET_break (NULL != nsh);
/* first, iterate over empty namestore */
GNUNET_asprintf (&cfg_name,
"test_namestore_api_%s.conf",
plugin_name);
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
res = 1;
if (0 !=
GNUNET_TESTING_peer_run ("test-namestore-api-zone-iteration-stop",
{
res = 1;
}
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
GNUNET_free (cfg_name);
- if (NULL != directory)
- {
- GNUNET_DISK_directory_remove (directory);
- GNUNET_free (directory);
- }
+
return res;
}
static int res;
-static char *directory;
-
static struct GNUNET_NAMESTORE_QueueEntry *qe;
{
(void) cls;
(void) peer;
- directory = NULL;
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string (cfg,
- "PATHS",
- "GNUNET_TEST_HOME",
- &directory));
- GNUNET_DISK_directory_remove (directory);
-
endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
&endbadly,
NULL);
GNUNET_SCHEDULER_add_shutdown (&end,
NULL);
GNUNET_asprintf (&s_name, "dummy");
- /* load privat key */
- {
- char *zonekey_file;
-
- GNUNET_asprintf (&zonekey_file,
- "zonefiles%s%s",
- DIR_SEPARATOR_STR,
- "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Using zonekey file `%s'\n",
- zonekey_file);
- privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (zonekey_file);
- GNUNET_free (zonekey_file);
- }
+ privkey = GNUNET_CRYPTO_ecdsa_key_create ();
GNUNET_assert (NULL != privkey);
/* get public key */
GNUNET_CRYPTO_ecdsa_key_get_public (privkey,
GNUNET_asprintf (&cfg_name,
"test_namestore_api_%s.conf",
plugin_name);
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
res = 1;
if (0 !=
GNUNET_TESTING_peer_run ("test-namestore-api-zone-to-name",
{
res = 1;
}
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
GNUNET_free (cfg_name);
- if (NULL != directory)
- {
- GNUNET_DISK_directory_remove (directory);
- GNUNET_free (directory);
- }
return res;
}
sizeof (cfg_name),
"test_plugin_namestore_%s.conf",
plugin_name);
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TMP");
GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1,
xargv,
"test-plugin-namestore",
options,
&run,
NULL);
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TMP");
if (ok != 0)
FPRINTF (stderr,
"Missed some testcases: %d\n",
[namestore-flat]
-FILENAME = $GNUNET_TMP/gnunet-test-plugin-namestore-sqlite/flatdb
-
-[namestore]
-# PREFIX = valgrind --log-file=/home/schanzen/dev/gnunet/src/namestore/vg_log
+FILENAME = $GNUNET_TMP/gnunet-test-plugin-namestore-flat/flatdb
#define ICMP_TIME_EXCEEDED 11
#endif
+/**
+ * Call memcpy() but check for @a n being 0 first. In the latter
+ * case, it is now safe to pass NULL for @a src or @a dst.
+ * Unlike traditional memcpy(), returns nothing.
+ *
+ * @param dst destination of the copy, may be NULL if @a n is zero
+ * @param src source of the copy, may be NULL if @a n is zero
+ * @param n number of bytes to copy
+ */
+#define GNUNET_memcpy(dst,src,n) do { if (0 != n) { (void) memcpy (dst,src,n); } } while (0)
+
/**
* Must match IP given in the server.
*/
ip_pkt.dst_ip = other->s_addr;
ip_pkt.checksum =
htons (calc_checksum ((uint16_t *) & ip_pkt, sizeof (struct ip_header)));
- memcpy (&packet[off], &ip_pkt, sizeof (struct ip_header));
+ GNUNET_memcpy (&packet[off],
+ &ip_pkt,
+ sizeof (struct ip_header));
off += sizeof (struct ip_header);
icmp_pkt.type = ICMP_TIME_EXCEEDED;
icmp_pkt.code = 0;
icmp_pkt.checksum = 0;
icmp_pkt.unused = 0;
- memcpy (&packet[off], &icmp_pkt, sizeof (struct icmp_ttl_exceeded_header));
+ GNUNET_memcpy (&packet[off],
+ &icmp_pkt,
+ sizeof (struct icmp_ttl_exceeded_header));
off += sizeof (struct icmp_ttl_exceeded_header);
/* ip header of the presumably 'lost' udp packet */
ip_pkt.dst_ip = dummy.s_addr;
ip_pkt.checksum =
htons (calc_checksum ((uint16_t *) & ip_pkt, sizeof (struct ip_header)));
- memcpy (&packet[off], &ip_pkt, sizeof (struct ip_header));
+ GNUNET_memcpy (&packet[off],
+ &ip_pkt,
+ sizeof (struct ip_header));
off += sizeof (struct ip_header);
/* build UDP header */
udp_pkt.dst_port = htons (NAT_TRAV_PORT);
udp_pkt.length = htons (port);
udp_pkt.crc = 0;
- memcpy (&packet[off], &udp_pkt, sizeof (struct udp_header));
+ GNUNET_memcpy (&packet[off],
+ &udp_pkt,
+ sizeof (struct udp_header));
off += sizeof (struct udp_header);
/* set ICMP checksum */
((uint16_t *) & packet[sizeof (struct ip_header)],
sizeof (struct icmp_ttl_exceeded_header) +
sizeof (struct ip_header) + sizeof (struct udp_header)));
- memcpy (&packet[sizeof (struct ip_header)], &icmp_pkt,
- sizeof (struct icmp_ttl_exceeded_header));
+ GNUNET_memcpy (&packet[sizeof (struct ip_header)],
+ &icmp_pkt,
+ sizeof (struct icmp_ttl_exceeded_header));
memset (&dst, 0, sizeof (dst));
dst.sin_family = AF_INET;
ip_pkt.dst_ip = other->s_addr;
ip_pkt.checksum =
htons (calc_checksum ((uint16_t *) & ip_pkt, sizeof (struct ip_header)));
- memcpy (&packet[off], &ip_pkt, sizeof (struct ip_header));
+ GNUNET_memcpy (&packet[off],
+ &ip_pkt,
+ sizeof (struct ip_header));
off = sizeof (ip_pkt);
/* icmp reply: time exceeded */
icmp_ttl.code = 0;
icmp_ttl.checksum = 0;
icmp_ttl.unused = 0;
- memcpy (&packet[off], &icmp_ttl, sizeof (struct icmp_ttl_exceeded_header));
+ GNUNET_memcpy (&packet[off],
+ &icmp_ttl,
+ sizeof (struct icmp_ttl_exceeded_header));
off += sizeof (struct icmp_ttl_exceeded_header);
/* ip header of the presumably 'lost' udp packet */
ip_pkt.checksum = 0;
ip_pkt.checksum =
htons (calc_checksum ((uint16_t *) & ip_pkt, sizeof (struct ip_header)));
- memcpy (&packet[off], &ip_pkt, sizeof (struct ip_header));
+ GNUNET_memcpy (&packet[off],
+ &ip_pkt,
+ sizeof (struct ip_header));
off += sizeof (struct ip_header);
icmp_echo.type = ICMP_ECHO;
icmp_echo.checksum = 0;
icmp_echo.checksum =
htons (calc_checksum
- ((uint16_t *) & icmp_echo, sizeof (struct icmp_echo_header)));
- memcpy (&packet[off], &icmp_echo, sizeof (struct icmp_echo_header));
+ ((uint16_t *) &icmp_echo, sizeof (struct icmp_echo_header)));
+ GNUNET_memcpy (&packet[off],
+ &icmp_echo,
+ sizeof (struct icmp_echo_header));
/* no go back to calculate ICMP packet checksum */
off = sizeof (struct ip_header);
((uint16_t *) & packet[off],
sizeof (struct icmp_ttl_exceeded_header) +
sizeof (struct ip_header) + sizeof (struct icmp_echo_header)));
- memcpy (&packet[off], &icmp_ttl, sizeof (struct icmp_ttl_exceeded_header));
+ GNUNET_memcpy (&packet[off],
+ &icmp_ttl,
+ sizeof (struct icmp_ttl_exceeded_header));
/* prepare for transmission */
memset (&dst, 0, sizeof (dst));
#define ICMP_TIME_EXCEEDED 11
#endif
+/**
+ * Call memcpy() but check for @a n being 0 first. In the latter
+ * case, it is now safe to pass NULL for @a src or @a dst.
+ * Unlike traditional memcpy(), returns nothing.
+ *
+ * @param dst destination of the copy, may be NULL if @a n is zero
+ * @param src source of the copy, may be NULL if @a n is zero
+ * @param n number of bytes to copy
+ */
+#define GNUNET_memcpy(dst,src,n) do { if (0 != n) { (void) memcpy (dst,src,n); } } while (0)
+
/**
* Should we print some debug output?
*/
ip_pkt.checksum =
htons (calc_checksum ((uint16_t *) & ip_pkt,
sizeof (struct ip_header)));
- memcpy (&packet[off],
- &ip_pkt,
- sizeof (struct ip_header));
+ GNUNET_memcpy (&packet[off],
+ &ip_pkt,
+ sizeof (struct ip_header));
off += sizeof (struct ip_header);
icmp_echo.type = ICMP_ECHO;
htons (calc_checksum
((uint16_t *) & icmp_echo,
sizeof (struct icmp_echo_header)));
- memcpy (&packet[off],
- &icmp_echo,
- sizeof (struct icmp_echo_header));
+ GNUNET_memcpy (&packet[off],
+ &icmp_echo,
+ sizeof (struct icmp_echo_header));
off += sizeof (struct icmp_echo_header);
memset (&dst, 0, sizeof (dst));
return;
}
off = 0;
- memcpy (&ip_pkt, &buf[off], sizeof (struct ip_header));
+ GNUNET_memcpy (&ip_pkt,
+ &buf[off],
+ sizeof (struct ip_header));
off += sizeof (struct ip_header);
- memcpy (&icmp_ttl, &buf[off], sizeof (struct icmp_ttl_exceeded_header));
+ GNUNET_memcpy (&icmp_ttl,
+ &buf[off],
+ sizeof (struct icmp_ttl_exceeded_header));
off += sizeof (struct icmp_ttl_exceeded_header);
if ((ICMP_TIME_EXCEEDED != icmp_ttl.type) || (0 != icmp_ttl.code))
{
source_ip.s_addr = ip_pkt.src_ip;
/* skip 2nd IP header */
- memcpy (&ip_pkt, &buf[off], sizeof (struct ip_header));
+ GNUNET_memcpy (&ip_pkt,
+ &buf[off],
+ sizeof (struct ip_header));
off += sizeof (struct ip_header);
switch (ip_pkt.proto)
return;
}
/* grab ICMP ECHO content */
- memcpy (&icmp_echo, &buf[off], sizeof (struct icmp_echo_header));
+ GNUNET_memcpy (&icmp_echo,
+ &buf[off],
+ sizeof (struct icmp_echo_header));
port = (uint16_t) ntohl (icmp_echo.reserved);
break;
case IPPROTO_UDP:
return;
}
/* grab UDP content */
- memcpy (&udp_pkt, &buf[off], sizeof (struct udp_header));
+ GNUNET_memcpy (&udp_pkt,
+ &buf[off],
+ sizeof (struct udp_header));
port = ntohs (udp_pkt.length);
break;
default:
ch->hole_external);
/* build sockaddr storage with port number */
- memset (&ss, 0, sizeof (ss));
- memcpy (&ss, addr, addrlen);
+ memset (&ss,
+ 0,
+ sizeof (ss));
+ GNUNET_memcpy (&ss,
+ addr,
+ addrlen);
switch (addr->sa_family)
{
case AF_INET:
size_t array_size;
array_size = sizeof(struct RegexCombineCtx *) * src->size;
- memcpy (dst->children,
- src->children,
- array_size);
+ GNUNET_memcpy (dst->children,
+ src->children,
+ array_size);
for (unsigned int i = 0; i < src->size; i++)
{
src->children[i] = NULL;
newctx = new_regex_ctx(ctx->size);
newctx->s = GNUNET_strdup (tmp);
if (children != NULL)
- memcpy (newctx->children, children, sizeof (*children) * ctx->size);
+ GNUNET_memcpy (newctx->children,
+ children,
+ sizeof (*children) * ctx->size);
ctx->children[c2i(tmp[0], ctx->size)] = newctx;
}
}
* @param a
* @param b
*
- * @return
+ * @return
*/
static int is_in_view (uint32_t a, uint32_t b)
{
rps_peer->cur_view_count,
view_size);
//*rps_peer->cur_view = *peers;
- memcpy (rps_peer->cur_view,
- peers,
- view_size * sizeof (struct GNUNET_PeerIdentity));
+ GNUNET_memcpy (rps_peer->cur_view,
+ peers,
+ view_size * sizeof (struct GNUNET_PeerIdentity));
to_file ("/tmp/rps/count_in_views.txt",
"%" PRIu64 " %" PRIu32 "",
rps_peer->index,
# This Makefile.am is in the public domain
-AM_CPPFLAGS = -I$(top_srcdir)/src/include
+AM_CPPFLAGS = -I$(top_srcdir)/src/include
if MINGW
WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols
libgnunetsq_la_SOURCES = \
sq.c \
+ sq_exec.c \
+ sq_prepare.c \
sq_query_helper.c \
sq_result_helper.c
libgnunetsq_la_LIBADD = -lsqlite3 \
--- /dev/null
+/*
+ This file is part of GNUnet
+ Copyright (C) 2018 GNUnet e.V.
+
+ GNUnet is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ GNUnet is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ GNUnet; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file sq/sq_exec.c
+ * @brief helper functions for executing SQL statements
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "gnunet_sq_lib.h"
+
+
+/**
+ * Create a `struct GNUNET_SQ_ExecuteStatement` where errors are fatal.
+ *
+ * @param sql actual SQL statement
+ * @return initialized struct
+ */
+struct GNUNET_SQ_ExecuteStatement
+GNUNET_SQ_make_execute (const char *sql)
+ {
+ struct GNUNET_SQ_ExecuteStatement es = {
+ .sql = sql,
+ .ignore_errors = GNUNET_NO
+ };
+
+ return es;
+}
+
+
+
+/**
+ * Create a `struct GNUNET_SQ_ExecuteStatement` where errors should
+ * be tolerated.
+ *
+ * @param sql actual SQL statement
+ * @return initialized struct
+ */
+struct GNUNET_SQ_ExecuteStatement
+GNUNET_SQ_make_try_execute (const char *sql)
+{
+ struct GNUNET_SQ_ExecuteStatement es = {
+ .sql = sql,
+ .ignore_errors = GNUNET_YES
+ };
+
+ return es;
+}
+
+
+/**
+ * Request execution of an array of statements @a es from Postgres.
+ *
+ * @param dbh database to execute the statements over
+ * @param es #GNUNET_PQ_PREPARED_STATEMENT_END-terminated array of prepared
+ * statements.
+ * @return #GNUNET_OK on success (modulo statements where errors can be ignored)
+ * #GNUNET_SYSERR on error
+ */
+int
+GNUNET_SQ_exec_statements (sqlite3 *dbh,
+ const struct GNUNET_SQ_ExecuteStatement *es)
+{
+ for (unsigned int i=0;NULL != es[i].sql;i++)
+ {
+ char *emsg = NULL;
+
+ if (SQLITE_OK !=
+ sqlite3_exec (dbh,
+ es[i].sql,
+ NULL,
+ NULL,
+ &emsg))
+ {
+ if (es[i].ignore_errors)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Failed to run SQL `%s': %s\n",
+ es[i].sql,
+ emsg);
+ }
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to run SQL `%s': %s\n",
+ es[i].sql,
+ emsg);
+ sqlite3_free (emsg);
+ return GNUNET_SYSERR;
+ }
+ sqlite3_free (emsg);
+ }
+ }
+ return GNUNET_OK;
+}
+
+/* end of sq_exec */
--- /dev/null
+/*
+ This file is part of GNUnet
+ Copyright (C) 2018 GNUnet e.V.
+
+ GNUnet is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ GNUnet is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ GNUnet; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file sq/sq_prepare.c
+ * @brief helper functions for executing SQL statements
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "gnunet_sq_lib.h"
+
+
+/**
+ * Create a `struct GNUNET_SQ_PrepareStatement`
+ *
+ * @param sql actual SQL statement
+ * @param pstmt where to store the handle
+ * @return initialized struct
+ */
+struct GNUNET_SQ_PrepareStatement
+GNUNET_SQ_make_prepare (const char *sql,
+ sqlite3_stmt **pstmt)
+{
+ struct GNUNET_SQ_PrepareStatement ps = {
+ .sql = sql,
+ .pstmt = pstmt
+ };
+
+ return ps;
+}
+
+
+
+/**
+ * Prepare all statements given in the (NULL,NULL)-terminated
+ * array at @a ps
+ *
+ * @param dbh database to use
+ * @param ps array of statements to prepare
+ * @return #GNUNET_OK on success
+ */
+int
+GNUNET_SQ_prepare (sqlite3 *dbh,
+ const struct GNUNET_SQ_PrepareStatement *ps)
+{
+ for (unsigned int i=0;NULL != ps[i].sql;i++)
+ {
+ const char *epos = NULL;
+ int ret;
+
+ if (SQLITE_OK !=
+ (ret = sqlite3_prepare_v2 (dbh,
+ ps[i].sql,
+ strlen (ps[i].sql),
+ ps[i].pstmt,
+ &epos)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to prepare SQL `%s': error %d at %s\n",
+ ps[i].sql,
+ ret,
+ epos);
+ return GNUNET_SYSERR;
+ }
+ }
+ return GNUNET_OK;
+}
+
+/* end of sq_prepare.c */
import time
if os.name == "nt":
- tmp = os.getenv ("TEMP")
-elif os.environ["TMPDIR"]:
+ tmp = os.getenv ("TEMP")
+elif None != os.environ.get("TMPDIR"):
tmp = os.getenv("TMPDIR")
-elif os.environ["TMP"]:
+elif None != os.environ.get("TMP"):
tmp = os.getenv("TMP")
else:
tmp = "/tmp"
@INLINE@ ../../contrib/no_forcestart.conf
+@INLINE@ ../../contrib/no_autostart_above_core.conf
[PATHS]
GNUNET_TEST_HOME = $GNUNET_TMP/test-gnunet-statistics/
-
* @param c configuration to use
*/
static void
-run (void *cls, char * const *args, const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *c)
+run (void *cls,
+ char * const *args,
+ const char *cfgfile,
+ const struct GNUNET_CONFIGURATION_Handle *c)
{
char * const *argv = cls;
unsigned long long tneigh;
char *plugin;
char *sep;
- timeout_endbadly = GNUNET_SCHEDULER_add_delayed (TIMEOUT, end_badly, &ok);
-
+ timeout_endbadly = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
+ &end_badly,
+ &ok);
cfg = c;
/* parse configuration */
- if ((GNUNET_OK
- != GNUNET_CONFIGURATION_get_value_number (c, "TRANSPORT",
- "NEIGHBOUR_LIMIT", &tneigh))
- || (GNUNET_OK
- != GNUNET_CONFIGURATION_get_value_filename (c, "PEER", "PRIVATE_KEY",
- &keyfile)))
+ if ( (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_number (c,
+ "TRANSPORT",
+ "NEIGHBOUR_LIMIT",
+ &tneigh)) ||
+ (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_filename (c,
+ "PEER",
+ "PRIVATE_KEY",
+ &keyfile)))
{
GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
"Transport service is lacking key configuration settings. Exiting.\n");
return;
}
- if (NULL == (stats = GNUNET_STATISTICS_create ("transport", cfg)))
+ if (NULL == (stats = GNUNET_STATISTICS_create ("transport",
+ cfg)))
{
GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
- "Could not create statistics. Exiting.\n");
+ "Could not create statistics. Exiting.\n");
GNUNET_free(keyfile);
end_badly_now ();
return;
if (GNUNET_OK != GNUNET_DISK_file_test (HOSTKEY_FILE))
{
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Hostkey `%s' missing. Exiting.\n",
- HOSTKEY_FILE);
+ GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
+ "Hostkey `%s' missing. Exiting.\n",
+ HOSTKEY_FILE);
GNUNET_free(keyfile);
end_badly_now ();
return;
}
- if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (keyfile))
+ if (GNUNET_OK !=
+ GNUNET_DISK_directory_create_for_file (keyfile))
{
GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
- "Could not create a directory for hostkey `%s'. Exiting.\n", keyfile);
+ "Could not create a directory for hostkey `%s'. Exiting.\n",
+ keyfile);
GNUNET_free(keyfile);
end_badly_now ();
return;
}
- if (GNUNET_OK != GNUNET_DISK_file_copy (HOSTKEY_FILE, keyfile))
+ if (GNUNET_OK !=
+ GNUNET_DISK_file_copy (HOSTKEY_FILE,
+ keyfile))
{
GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
- "Could not copy hostkey `%s' to destination `%s'. Exiting.\n",
- HOSTKEY_FILE, keyfile);
+ "Could not copy hostkey `%s' to destination `%s'. Exiting.\n",
+ HOSTKEY_FILE,
+ keyfile);
GNUNET_free(keyfile);
end_badly_now ();
return;
end_badly_now ();
return;
}
-
}
+
/**
* The main function for the test
*
* @return 0 ok, 1 on error
*/
int
-main (int argc, char * const *argv)
+main (int argc,
+ char * const *argv)
{
static struct GNUNET_GETOPT_CommandLineOption options[] = {
- GNUNET_GETOPT_OPTION_END };
+ GNUNET_GETOPT_OPTION_END
+ };
int ret;
-
- GNUNET_DISK_directory_remove (GNUNET_DISK_mktemp("test-gnunetd-plugin-transport"));
-
- char * const argv_prog[] = { "test_plugin_transport", "-c",
- "test_plugin_transport_data.conf", NULL };
- GNUNET_log_setup ("test-plugin-transport", "WARNING", NULL );
+ char * const argv_prog[] = {
+ "test_plugin_transport",
+ "-c",
+ "test_plugin_transport_data.conf",
+ NULL
+ };
+
+ GNUNET_log_setup ("test-plugin-transport",
+ "WARNING",
+ NULL);
+ GNUNET_DISK_purge_cfg_dir ("test_plugin_transport_data.conf",
+ "GNUNET_TEST_HOME");
ok = 1; /* set to fail */
ret =
(GNUNET_OK
== GNUNET_PROGRAM_run (3, argv_prog, "test-plugin-transport",
"testcase", options, &run, (void *) argv)) ? ok : 1;
- GNUNET_DISK_directory_remove (GNUNET_DISK_mktemp("test-gnunetd-plugin-transport"));
+ GNUNET_DISK_purge_cfg_dir ("test_plugin_transport_data.conf",
+ "GNUNET_TEST_HOME");
return ret;
}
int rc;
int key_len;
unsigned char* key_buf;
-
+
key_len = element_length_in_bytes(k) < 33 ? 3 : element_length_in_bytes(k);
key_buf = (unsigned char*) malloc(key_len);
element_to_bytes(key_buf, k);
- memcpy (key->aes_key, key_buf, GNUNET_CRYPTO_AES_KEY_LENGTH);
+ GNUNET_memcpy (key->aes_key,
+ key_buf,
+ GNUNET_CRYPTO_AES_KEY_LENGTH);
GNUNET_assert (0 ==
gcry_cipher_open (handle, GCRY_CIPHER_AES256,
GCRY_CIPHER_MODE_CFB, 0));
unsigned char iv[16];
char* tmp;
uint32_t len;
-
+
init_aes(k, 1, &handle, &skey, iv);
tmp = GNUNET_malloc (size);
//AES_cbc_encrypt(ct->data, pt->data, ct->len, &key, iv, AES_DECRYPT);
- GNUNET_assert (0 == gcry_cipher_decrypt (handle, tmp, size, ct, size));
+ GNUNET_assert (0 == gcry_cipher_decrypt (handle, tmp, size, ct, size));
gcry_cipher_close (handle);
/* TODO make less crufty */
-
+
/* get real length */
len = 0;
len = len
struct GNUNET_CRYPTO_AbeKey *prv_key;
int size;
char *tmp;
-
+
prv_key = GNUNET_new (struct GNUNET_CRYPTO_AbeKey);
prv_key->prv = gabe_keygen(key->pub, key->msk, attrs);
size = gabe_pub_serialize(key->pub, &tmp);
{
char *ptr;
uint32_t *len;
-
+
*result = GNUNET_malloc (12 + cph_buf_len + aes_buf_len);
ptr = *result;
len = (uint32_t*) ptr;
len = (uint32_t*) ptr;
*len = htonl (aes_buf_len);
ptr += 4;
- memcpy (ptr, aes_buf, aes_buf_len);
+ GNUNET_memcpy (ptr, aes_buf, aes_buf_len);
ptr += aes_buf_len;
len = (uint32_t*) ptr;
*len = htonl (cph_buf_len);
ptr += 4;
- memcpy (ptr, cph_buf, cph_buf_len);
+ GNUNET_memcpy (ptr, cph_buf, cph_buf_len);
return 12 + cph_buf_len + aes_buf_len;
}
*aes_buf_len = ntohl (*len);
ptr += 4;
*aes_buf = GNUNET_malloc (*aes_buf_len);
- memcpy(*aes_buf, ptr, *aes_buf_len);
+ GNUNET_memcpy (*aes_buf, ptr, *aes_buf_len);
ptr += *aes_buf_len;
len = (uint32_t*)ptr;
*cph_buf_len = ntohl (*len);
ptr += 4;
*cph_buf = GNUNET_malloc (*cph_buf_len);
- memcpy(*cph_buf, ptr, *cph_buf_len);
+ GNUNET_memcpy (*cph_buf, ptr, *cph_buf_len);
return buf_len;
}
&prv_len);
key->pub = gabe_pub_unserialize (pub, pub_len);
key->prv = gabe_prv_unserialize (key->pub, prv, prv_len);
-
+
GNUNET_free (pub);
GNUNET_free (prv);
return key;
&msk_len);
key->pub = gabe_pub_unserialize (pub, pub_len);
key->msk = gabe_msk_unserialize (key->pub, msk, msk_len);
-
+
GNUNET_free (pub);
GNUNET_free (msk);
/*
This file is part of GNUnet.
- Copyright (C) 2001--2013, 2016 GNUnet e.V.
+ Copyright (C) 2001--2013, 2016, 2018 GNUnet e.V.
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
struct GNUNET_DISK_FileHandle *in;
struct GNUNET_DISK_FileHandle *out;
- if (GNUNET_OK != GNUNET_DISK_file_size (src, &size, GNUNET_YES, GNUNET_YES))
+ if (GNUNET_OK !=
+ GNUNET_DISK_file_size (src,
+ &size,
+ GNUNET_YES,
+ GNUNET_YES))
+ {
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
+ "stat",
+ src);
return GNUNET_SYSERR;
+ }
pos = 0;
- in = GNUNET_DISK_file_open (src, GNUNET_DISK_OPEN_READ,
+ in = GNUNET_DISK_file_open (src,
+ GNUNET_DISK_OPEN_READ,
GNUNET_DISK_PERM_NONE);
- if (!in)
+ if (! in)
+ {
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
+ "open",
+ src);
return GNUNET_SYSERR;
+ }
out =
GNUNET_DISK_file_open (dst,
GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE |
GNUNET_DISK_PERM_GROUP_WRITE);
if (!out)
{
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
+ "open",
+ dst);
GNUNET_DISK_file_close (in);
return GNUNET_SYSERR;
}
return GNUNET_OK;
}
+
+/**
+ * Remove the directory given under @a option in
+ * section [PATHS] in configuration under @a cfg_filename
+ *
+ * @param cfg_filename configuration file to parse
+ * @param option option with the dir name to purge
+ */
+void
+GNUNET_DISK_purge_cfg_dir (const char *cfg_filename,
+ const char *option)
+{
+ struct GNUNET_CONFIGURATION_Handle *cfg;
+ char *tmpname;
+
+ cfg = GNUNET_CONFIGURATION_create ();
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_load (cfg,
+ cfg_filename))
+ {
+ GNUNET_break (0);
+ GNUNET_CONFIGURATION_destroy (cfg);
+ return;
+ }
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_filename (cfg,
+ "PATHS",
+ option,
+ &tmpname))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ "PATHS",
+ option);
+ GNUNET_CONFIGURATION_destroy (cfg);
+ return;
+ }
+ GNUNET_CONFIGURATION_destroy (cfg);
+ if (GNUNET_SYSERR ==
+ GNUNET_DISK_directory_remove (tmpname))
+ {
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
+ "remove",
+ tmpname);
+ GNUNET_free (tmpname);
+ return;
+ }
+ GNUNET_free (tmpname);
+}
+
+
+
/* end of disk.c */
gnunet-service-zonemaster
+gnunet-service-zonemaster-monitor
# This Makefile.am is in the public domain
-AM_CPPFLAGS = -I$(top_srcdir)/src/include
+AM_CPPFLAGS = -I$(top_srcdir)/src/include
plugindir = $(libdir)/gnunet
endif
libexec_PROGRAMS = \
- gnunet-service-zonemaster
+ gnunet-service-zonemaster \
+ gnunet-service-zonemaster-monitor
gnunet_service_zonemaster_SOURCES = \
gnunet-service-zonemaster.c
-
gnunet_service_zonemaster_LDADD = \
$(top_builddir)/src/dht/libgnunetdht.la \
$(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \
$(top_builddir)/src/namestore/libgnunetnamestore.la \
$(GN_LIBINTL)
+
+gnunet_service_zonemaster_monitor_SOURCES = \
+ gnunet-service-zonemaster-monitor.c
+
+gnunet_service_zonemaster_monitor_LDADD = \
+ $(top_builddir)/src/dht/libgnunetdht.la \
+ $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \
+ $(top_builddir)/src/statistics/libgnunetstatistics.la \
+ $(top_builddir)/src/util/libgnunetutil.la \
+ $(top_builddir)/src/namestore/libgnunetnamestore.la \
+ $(GN_LIBINTL)
--- /dev/null
+/*
+ This file is part of GNUnet.
+ Copyright (C) 2012, 2013, 2014, 2017, 2018 GNUnet e.V.
+
+ GNUnet is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3, or (at your
+ option) any later version.
+
+ GNUnet is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GNUnet; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+/**
+ * @file zonemaster/gnunet-service-zonemaster-monitor.c
+ * @brief monitor namestore changes and publish them immediately to GNUnet name system
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "gnunet_util_lib.h"
+#include "gnunet_dht_service.h"
+#include "gnunet_namestore_service.h"
+#include "gnunet_statistics_service.h"
+
+
+#define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file (kind, "util", syscall, filename)
+
+
+/**
+ * How often should we (re)publish each record before
+ * it expires?
+ */
+#define PUBLISH_OPS_PER_EXPIRATION 4
+
+/**
+ * How many pending DHT operations do we allow at most?
+ */
+#define DHT_QUEUE_LIMIT 2000
+
+/**
+ * How many events may the namestore give us before it has to wait
+ * for us to keep up?
+ */
+#define NAMESTORE_QUEUE_LIMIT 5
+
+/**
+ * What replication level do we use for DHT PUT operations?
+ */
+#define DHT_GNS_REPLICATION_LEVEL 5
+
+
+/**
+ * Handle for DHT PUT activity triggered from the namestore monitor.
+ */
+struct DhtPutActivity
+{
+ /**
+ * Kept in a DLL.
+ */
+ struct DhtPutActivity *next;
+
+ /**
+ * Kept in a DLL.
+ */
+ struct DhtPutActivity *prev;
+
+ /**
+ * Handle for the DHT PUT operation.
+ */
+ struct GNUNET_DHT_PutHandle *ph;
+
+ /**
+ * When was this PUT initiated?
+ */
+ struct GNUNET_TIME_Absolute start_date;
+};
+
+
+/**
+ * Handle to the statistics service
+ */
+static struct GNUNET_STATISTICS_Handle *statistics;
+
+/**
+ * Our handle to the DHT
+ */
+static struct GNUNET_DHT_Handle *dht_handle;
+
+/**
+ * Our handle to the namestore service
+ */
+static struct GNUNET_NAMESTORE_Handle *namestore_handle;
+
+/**
+ * Handle to monitor namestore changes to instant propagation.
+ */
+static struct GNUNET_NAMESTORE_ZoneMonitor *zmon;
+
+/**
+ * Head of monitor activities; kept in a DLL.
+ */
+static struct DhtPutActivity *ma_head;
+
+/**
+ * Tail of monitor activities; kept in a DLL.
+ */
+static struct DhtPutActivity *ma_tail;
+
+/**
+ * Number of entries in the DHT queue #ma_head.
+ */
+static unsigned int ma_queue_length;
+
+/**
+ * Optimize block insertion by caching map of private keys to
+ * public keys in memory?
+ */
+static int cache_keys;
+
+
+/**
+ * Task run during shutdown.
+ *
+ * @param cls unused
+ * @param tc unused
+ */
+static void
+shutdown_task (void *cls)
+{
+ struct DhtPutActivity *ma;
+
+ (void) cls;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Shutting down!\n");
+ while (NULL != (ma = ma_head))
+ {
+ GNUNET_DHT_put_cancel (ma->ph);
+ ma_queue_length--;
+ GNUNET_CONTAINER_DLL_remove (ma_head,
+ ma_tail,
+ ma);
+ GNUNET_free (ma);
+ }
+ if (NULL != statistics)
+ {
+ GNUNET_STATISTICS_destroy (statistics,
+ GNUNET_NO);
+ statistics = NULL;
+ }
+ if (NULL != zmon)
+ {
+ GNUNET_NAMESTORE_zone_monitor_stop (zmon);
+ zmon = NULL;
+ }
+ if (NULL != namestore_handle)
+ {
+ GNUNET_NAMESTORE_disconnect (namestore_handle);
+ namestore_handle = NULL;
+ }
+ if (NULL != dht_handle)
+ {
+ GNUNET_DHT_disconnect (dht_handle);
+ dht_handle = NULL;
+ }
+}
+
+
+/**
+ * Continuation called from DHT once the PUT operation triggered
+ * by a monitor is done.
+ *
+ * @param cls a `struct DhtPutActivity`
+ */
+static void
+dht_put_monitor_continuation (void *cls)
+{
+ struct DhtPutActivity *ma = cls;
+
+ GNUNET_NAMESTORE_zone_monitor_next (zmon,
+ 1);
+ ma_queue_length--;
+ GNUNET_CONTAINER_DLL_remove (ma_head,
+ ma_tail,
+ ma);
+ GNUNET_free (ma);
+}
+
+
+/**
+ * Convert namestore records from the internal format to that
+ * suitable for publication (removes private records, converts
+ * to absolute expiration time).
+ *
+ * @param rd input records
+ * @param rd_count size of the @a rd and @a rd_public arrays
+ * @param rd_public where to write the converted records
+ * @return number of records written to @a rd_public
+ */
+static unsigned int
+convert_records_for_export (const struct GNUNET_GNSRECORD_Data *rd,
+ unsigned int rd_count,
+ struct GNUNET_GNSRECORD_Data *rd_public)
+{
+ struct GNUNET_TIME_Absolute now;
+ unsigned int rd_public_count;
+
+ rd_public_count = 0;
+ now = GNUNET_TIME_absolute_get ();
+ for (unsigned int i=0;i<rd_count;i++)
+ {
+ if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_PRIVATE))
+ continue;
+ if ( (0 == (rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION)) &&
+ (rd[i].expiration_time < now.abs_value_us) )
+ continue; /* record already expired, skip it */
+ rd_public[rd_public_count++] = rd[i];
+ }
+ return rd_public_count;
+}
+
+
+/**
+ * Store GNS records in the DHT.
+ *
+ * @param key key of the zone
+ * @param label label to store under
+ * @param rd_public public record data
+ * @param rd_public_count number of records in @a rd_public
+ * @param ma handle for the PUT operation
+ * @return DHT PUT handle, NULL on error
+ */
+static struct GNUNET_DHT_PutHandle *
+perform_dht_put (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
+ const char *label,
+ const struct GNUNET_GNSRECORD_Data *rd_public,
+ unsigned int rd_public_count,
+ struct DhtPutActivity *ma)
+{
+ struct GNUNET_GNSRECORD_Block *block;
+ struct GNUNET_HashCode query;
+ struct GNUNET_TIME_Absolute expire;
+ size_t block_size;
+ struct GNUNET_DHT_PutHandle *ret;
+
+ expire = GNUNET_GNSRECORD_record_get_expiration_time (rd_public_count,
+ rd_public);
+ if (cache_keys)
+ block = GNUNET_GNSRECORD_block_create2 (key,
+ expire,
+ label,
+ rd_public,
+ rd_public_count);
+ else
+ block = GNUNET_GNSRECORD_block_create (key,
+ expire,
+ label,
+ rd_public,
+ rd_public_count);
+ if (NULL == block)
+ {
+ GNUNET_break (0);
+ return NULL; /* whoops */
+ }
+ block_size = ntohl (block->purpose.size)
+ + sizeof (struct GNUNET_CRYPTO_EcdsaSignature)
+ + sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey);
+ GNUNET_GNSRECORD_query_from_private_key (key,
+ label,
+ &query);
+ GNUNET_STATISTICS_update (statistics,
+ "DHT put operations initiated",
+ 1,
+ GNUNET_NO);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Storing %u record(s) for label `%s' in DHT with expiration `%s' under key %s\n",
+ rd_public_count,
+ label,
+ GNUNET_STRINGS_absolute_time_to_string (expire),
+ GNUNET_h2s (&query));
+ ret = GNUNET_DHT_put (dht_handle,
+ &query,
+ DHT_GNS_REPLICATION_LEVEL,
+ GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
+ GNUNET_BLOCK_TYPE_GNS_NAMERECORD,
+ block_size,
+ block,
+ expire,
+ &dht_put_monitor_continuation,
+ ma);
+ GNUNET_free (block);
+ return ret;
+}
+
+
+/**
+ * Process a record that was stored in the namestore
+ * (invoked by the monitor).
+ *
+ * @param cls closure, NULL
+ * @param zone private key of the zone; NULL on disconnect
+ * @param label label of the records; NULL on disconnect
+ * @param rd_count number of entries in @a rd array, 0 if label was deleted
+ * @param rd array of records with data to store
+ */
+static void
+handle_monitor_event (void *cls,
+ const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
+ const char *label,
+ unsigned int rd_count,
+ const struct GNUNET_GNSRECORD_Data *rd)
+{
+ struct GNUNET_GNSRECORD_Data rd_public[rd_count];
+ unsigned int rd_public_count;
+ struct DhtPutActivity *ma;
+
+ (void) cls;
+ GNUNET_STATISTICS_update (statistics,
+ "Namestore monitor events received",
+ 1,
+ GNUNET_NO);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received %u records for label `%s' via namestore monitor\n",
+ rd_count,
+ label);
+ /* filter out records that are not public, and convert to
+ absolute expiration time. */
+ rd_public_count = convert_records_for_export (rd,
+ rd_count,
+ rd_public);
+ if (0 == rd_public_count)
+ {
+ GNUNET_NAMESTORE_zone_monitor_next (zmon,
+ 1);
+ return; /* nothing to do */
+ }
+ ma = GNUNET_new (struct DhtPutActivity);
+ ma->start_date = GNUNET_TIME_absolute_get ();
+ ma->ph = perform_dht_put (zone,
+ label,
+ rd,
+ rd_count,
+ ma);
+ if (NULL == ma->ph)
+ {
+ /* PUT failed, do not remember operation */
+ GNUNET_free (ma);
+ GNUNET_NAMESTORE_zone_monitor_next (zmon,
+ 1);
+ return;
+ }
+ GNUNET_CONTAINER_DLL_insert_tail (ma_head,
+ ma_tail,
+ ma);
+ ma_queue_length++;
+ if (ma_queue_length > DHT_QUEUE_LIMIT)
+ {
+ ma = ma_head;
+ GNUNET_CONTAINER_DLL_remove (ma_head,
+ ma_tail,
+ ma);
+ GNUNET_DHT_put_cancel (ma->ph);
+ ma_queue_length--;
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "DHT PUT unconfirmed after %s, aborting PUT\n",
+ GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (ma->start_date),
+ GNUNET_YES));
+ GNUNET_free (ma);
+ }
+}
+
+
+/**
+ * The zone monitor encountered an IPC error trying to to get in
+ * sync. Restart from the beginning.
+ *
+ * @param cls NULL
+ */
+static void
+handle_monitor_error (void *cls)
+{
+ (void) cls;
+ GNUNET_STATISTICS_update (statistics,
+ "Namestore monitor errors encountered",
+ 1,
+ GNUNET_NO);
+}
+
+
+/**
+ * Performe zonemaster duties: watch namestore, publish records.
+ *
+ * @param cls closure
+ * @param server the initialized server
+ * @param c configuration to use
+ */
+static void
+run (void *cls,
+ const struct GNUNET_CONFIGURATION_Handle *c,
+ struct GNUNET_SERVICE_Handle *service)
+{
+ unsigned long long max_parallel_bg_queries = 128;
+
+ (void) cls;
+ (void) service;
+ namestore_handle = GNUNET_NAMESTORE_connect (c);
+ if (NULL == namestore_handle)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Failed to connect to the namestore!\n"));
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+ cache_keys = GNUNET_CONFIGURATION_get_value_yesno (c,
+ "namestore",
+ "CACHE_KEYS");
+ if (GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_number (c,
+ "zonemaster",
+ "MAX_PARALLEL_BACKGROUND_QUERIES",
+ &max_parallel_bg_queries))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Number of allowed parallel background queries: %llu\n",
+ max_parallel_bg_queries);
+ }
+ if (0 == max_parallel_bg_queries)
+ max_parallel_bg_queries = 1;
+ dht_handle = GNUNET_DHT_connect (c,
+ (unsigned int) max_parallel_bg_queries);
+ if (NULL == dht_handle)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Could not connect to DHT!\n"));
+ GNUNET_SCHEDULER_add_now (&shutdown_task,
+ NULL);
+ return;
+ }
+
+ /* Schedule periodic put for our records. */
+ statistics = GNUNET_STATISTICS_create ("zonemaster-mon",
+ c);
+ zmon = GNUNET_NAMESTORE_zone_monitor_start (c,
+ NULL,
+ GNUNET_NO,
+ &handle_monitor_error,
+ NULL,
+ &handle_monitor_event,
+ NULL,
+ NULL /* sync_cb */,
+ NULL);
+ GNUNET_NAMESTORE_zone_monitor_next (zmon,
+ NAMESTORE_QUEUE_LIMIT - 1);
+ GNUNET_break (NULL != zmon);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ NULL);
+}
+
+
+/**
+ * Define "main" method using service macro.
+ */
+GNUNET_SERVICE_MAIN
+("zonemaster-monitor",
+ GNUNET_SERVICE_OPTION_NONE,
+ &run,
+ NULL,
+ NULL,
+ NULL,
+ GNUNET_MQ_handler_end());
+
+
+/* end of gnunet-service-zonemaster-monitor.c */
/*
This file is part of GNUnet.
- Copyright (C) 2012, 2013, 2014, 2017 GNUnet e.V.
+ Copyright (C) 2012, 2013, 2014, 2017, 2018 GNUnet e.V.
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
#include "gnunet_dht_service.h"
#include "gnunet_namestore_service.h"
#include "gnunet_statistics_service.h"
-#include "gnunet_namestore_plugin.h"
-#include "gnunet_signatures.h"
#define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file (kind, "util", syscall, filename)
*/
#define MAXIMUM_ZONE_ITERATION_INTERVAL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)
-/**
- * The default put interval for the zone iteration. In case
- * no option is found
- */
-#define DEFAULT_ZONE_PUBLISH_TIME_WINDOW GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 4)
-
/**
* The factor the current zone iteration interval is divided by for each
* additional new record
*/
#define LATE_ITERATION_SPEEDUP_FACTOR 2
-/**
- * How long until a DHT PUT attempt should time out?
- */
-#define DHT_OPERATION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
-
/**
* What replication level do we use for DHT PUT operations?
*/
*/
static struct GNUNET_NAMESTORE_ZoneIterator *namestore_iter;
-/**
- * Handle to monitor namestore changes to instant propagation.
- */
-static struct GNUNET_NAMESTORE_ZoneMonitor *zmon;
-
-/**
- * Head of monitor activities; kept in a DLL.
- */
-static struct DhtPutActivity *ma_head;
-
-/**
- * Tail of monitor activities; kept in a DLL.
- */
-static struct DhtPutActivity *ma_tail;
-
/**
* Head of iteration put activities; kept in a DLL.
*/
*/
static unsigned int dht_queue_length;
-/**
- * Number of entries in the DHT queue #ma_head.
- */
-static unsigned int ma_queue_length;
-
/**
* Useful for zone update for DHT put
*/
(void) cls;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Shutting down!\n");
- while (NULL != (ma = ma_head))
- {
- GNUNET_DHT_put_cancel (ma->ph);
- ma_queue_length--;
- GNUNET_CONTAINER_DLL_remove (ma_head,
- ma_tail,
- ma);
- GNUNET_free (ma);
- }
while (NULL != (ma = it_head))
{
GNUNET_DHT_put_cancel (ma->ph);
GNUNET_NAMESTORE_zone_iteration_stop (namestore_iter);
namestore_iter = NULL;
}
- if (NULL != zmon)
- {
- GNUNET_NAMESTORE_zone_monitor_stop (zmon);
- zmon = NULL;
- }
if (NULL != namestore_handle)
{
GNUNET_NAMESTORE_disconnect (namestore_handle);
publish_zone_dht_start (void *cls);
-/**
- * Continuation called from DHT once the PUT operation triggered
- * by a monitor is done.
- *
- * @param cls a `struct DhtPutActivity`
- */
-static void
-dht_put_monitor_continuation (void *cls)
-{
- struct DhtPutActivity *ma = cls;
-
- GNUNET_NAMESTORE_zone_monitor_next (zmon,
- 1);
- ma_queue_length--;
- GNUNET_CONTAINER_DLL_remove (ma_head,
- ma_tail,
- ma);
- GNUNET_free (ma);
-}
-
-
/**
* Calculate #target_iteration_velocity_per_record.
*/
"# size of the DHT queue (it)",
dht_queue_length,
GNUNET_NO);
- GNUNET_STATISTICS_set (statistics,
- "# size of the DHT queue (mon)",
- ma_queue_length,
- GNUNET_NO);
GNUNET_STATISTICS_set (statistics,
"% speed increase needed for target velocity",
pct,
GNUNET_NO);
delay = GNUNET_TIME_relative_multiply (delay,
NS_BLOCK_SIZE);
+ /* make sure we do not overshoot because of the #NS_BLOCK_SIZE factor */
+ delay = GNUNET_TIME_relative_min (MAXIMUM_ZONE_ITERATION_INTERVAL,
+ delay);
+ /* no delays on first iteration */
+ if (GNUNET_YES == first_zone_iteration)
+ delay = GNUNET_TIME_UNIT_ZERO;
GNUNET_assert (NULL == zone_publish_task);
zone_publish_task = GNUNET_SCHEDULER_add_delayed (delay,
&publish_zone_namestore_next,
rd_public_count = 0;
now = GNUNET_TIME_absolute_get ();
for (unsigned int i=0;i<rd_count;i++)
- if (0 == (rd[i].flags & GNUNET_GNSRECORD_RF_PRIVATE))
+ {
+ if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_PRIVATE))
+ continue;
+ if ( (0 == (rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION)) &&
+ (rd[i].expiration_time < now.abs_value_us) )
+ continue; /* record already expired, skip it */
+ if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION))
{
- rd_public[rd_public_count] = rd[i];
- if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION))
- {
- /* GNUNET_GNSRECORD_block_create will convert to absolute time;
- we just need to adjust our iteration frequency */
- min_relative_record_time.rel_value_us =
- GNUNET_MIN (rd_public[rd_public_count].expiration_time,
- min_relative_record_time.rel_value_us);
- }
- else if (rd_public[rd_public_count].expiration_time < now.abs_value_us)
- {
- /* record already expired, skip it */
- continue;
- }
- rd_public_count++;
+ /* GNUNET_GNSRECORD_block_create will convert to absolute time;
+ we just need to adjust our iteration frequency */
+ min_relative_record_time.rel_value_us =
+ GNUNET_MIN (rd[i].expiration_time,
+ min_relative_record_time.rel_value_us);
}
+ rd_public[rd_public_count++] = rd[i];
+ }
return rd_public_count;
}
* @param label label to store under
* @param rd_public public record data
* @param rd_public_count number of records in @a rd_public
- * @param cont function to call with PUT result
- * @param cont_cls closure for @a cont
+ * @param ma handle for the put operation
* @return DHT PUT handle, NULL on error
*/
static struct GNUNET_DHT_PutHandle *
const char *label,
const struct GNUNET_GNSRECORD_Data *rd_public,
unsigned int rd_public_count,
- GNUNET_SCHEDULER_TaskCallback cont,
- void *cont_cls)
+ struct DhtPutActivity *ma)
{
struct GNUNET_GNSRECORD_Block *block;
struct GNUNET_HashCode query;
block_size,
block,
expire,
- cont,
- cont_cls);
+ &dht_put_continuation,
+ ma);
GNUNET_free (block);
return ret;
}
calculate_put_interval ();
/* reset for next iteration */
min_relative_record_time
- = GNUNET_TIME_relative_multiply (GNUNET_DHT_DEFAULT_REPUBLISH_FREQUENCY,
- PUBLISH_OPS_PER_EXPIRATION);
+ = GNUNET_TIME_UNIT_FOREVER_REL;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Zone iteration finished. Adjusted zone iteration interval to %s\n",
GNUNET_STRINGS_relative_time_to_string (target_iteration_velocity_per_record,
label,
rd_public,
rd_public_count,
- &dht_put_continuation,
ma);
put_cnt++;
if (0 == put_cnt % DELTA_INTERVAL)
}
-/**
- * Process a record that was stored in the namestore
- * (invoked by the monitor).
- *
- * @param cls closure, NULL
- * @param zone private key of the zone; NULL on disconnect
- * @param label label of the records; NULL on disconnect
- * @param rd_count number of entries in @a rd array, 0 if label was deleted
- * @param rd array of records with data to store
- */
-static void
-handle_monitor_event (void *cls,
- const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
- const char *label,
- unsigned int rd_count,
- const struct GNUNET_GNSRECORD_Data *rd)
-{
- struct GNUNET_GNSRECORD_Data rd_public[rd_count];
- unsigned int rd_public_count;
- struct DhtPutActivity *ma;
-
- (void) cls;
- GNUNET_STATISTICS_update (statistics,
- "Namestore monitor events received",
- 1,
- GNUNET_NO);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received %u records for label `%s' via namestore monitor\n",
- rd_count,
- label);
- /* filter out records that are not public, and convert to
- absolute expiration time. */
- rd_public_count = convert_records_for_export (rd,
- rd_count,
- rd_public);
- if (0 == rd_public_count)
- {
- GNUNET_NAMESTORE_zone_monitor_next (zmon,
- 1);
- return; /* nothing to do */
- }
- num_public_records++;
- ma = GNUNET_new (struct DhtPutActivity);
- ma->start_date = GNUNET_TIME_absolute_get ();
- ma->ph = perform_dht_put (zone,
- label,
- rd,
- rd_count,
- &dht_put_monitor_continuation,
- ma);
- if (NULL == ma->ph)
- {
- /* PUT failed, do not remember operation */
- GNUNET_free (ma);
- GNUNET_NAMESTORE_zone_monitor_next (zmon,
- 1);
- return;
- }
- GNUNET_CONTAINER_DLL_insert_tail (ma_head,
- ma_tail,
- ma);
- ma_queue_length++;
- if (ma_queue_length > DHT_QUEUE_LIMIT)
- {
- ma = ma_head;
- GNUNET_CONTAINER_DLL_remove (ma_head,
- ma_tail,
- ma);
- GNUNET_DHT_put_cancel (ma->ph);
- ma_queue_length--;
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "DHT PUT unconfirmed after %s, aborting PUT\n",
- GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (ma->start_date),
- GNUNET_YES));
- GNUNET_free (ma);
- }
-}
-
-
-/**
- * The zone monitor is now in SYNC with the current state of the
- * name store. Start to perform periodic iterations.
- *
- * @param cls NULL
- */
-static void
-monitor_sync_event (void *cls)
-{
- (void) cls;
- if ( (NULL == zone_publish_task) &&
- (NULL == namestore_iter) )
- zone_publish_task = GNUNET_SCHEDULER_add_now (&publish_zone_dht_start,
- NULL);
-}
-
-
-/**
- * The zone monitor encountered an IPC error trying to to get in
- * sync. Restart from the beginning.
- *
- * @param cls NULL
- */
-static void
-handle_monitor_error (void *cls)
-{
- (void) cls;
- GNUNET_STATISTICS_update (statistics,
- "Namestore monitor errors encountered",
- 1,
- GNUNET_NO);
- if (NULL != zone_publish_task)
- {
- GNUNET_SCHEDULER_cancel (zone_publish_task);
- zone_publish_task = NULL;
- }
- if (NULL != namestore_iter)
- {
- GNUNET_NAMESTORE_zone_iteration_stop (namestore_iter);
- namestore_iter = NULL;
- }
- zone_publish_task = GNUNET_SCHEDULER_add_now (&publish_zone_dht_start,
- NULL);
-}
-
-
/**
* Performe zonemaster duties: watch namestore, publish records.
*
(void) service;
last_put_100 = GNUNET_TIME_absolute_get (); /* first time! */
min_relative_record_time
- = GNUNET_TIME_relative_multiply (GNUNET_DHT_DEFAULT_REPUBLISH_FREQUENCY,
- PUBLISH_OPS_PER_EXPIRATION);
+ = GNUNET_TIME_UNIT_FOREVER_REL;
target_iteration_velocity_per_record = INITIAL_ZONE_ITERATION_INTERVAL;
namestore_handle = GNUNET_NAMESTORE_connect (c);
if (NULL == namestore_handle)
cache_keys = GNUNET_CONFIGURATION_get_value_yesno (c,
"namestore",
"CACHE_KEYS");
- zone_publish_time_window_default = DEFAULT_ZONE_PUBLISH_TIME_WINDOW;
+ zone_publish_time_window_default = GNUNET_DHT_DEFAULT_REPUBLISH_FREQUENCY;
if (GNUNET_OK ==
GNUNET_CONFIGURATION_get_value_time (c,
"zonemaster",
"Target zone iteration velocity (μs)",
target_iteration_velocity_per_record.rel_value_us,
GNUNET_NO);
- zmon = GNUNET_NAMESTORE_zone_monitor_start (c,
- NULL,
- GNUNET_NO,
- &handle_monitor_error,
- NULL,
- &handle_monitor_event,
- NULL,
- &monitor_sync_event,
- NULL);
- GNUNET_NAMESTORE_zone_monitor_next (zmon,
- NAMESTORE_QUEUE_LIMIT - 1);
- GNUNET_break (NULL != zmon);
+ zone_publish_task = GNUNET_SCHEDULER_add_now (&publish_zone_dht_start,
+ NULL);
GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
NULL);
}
# USE_CACHE = YES
# PREFIX = valgrind --leak-check=full --track-origins=yes
+
+
+
+[zonemaster-monitor]
+AUTOSTART = @AUTOSTART@
+FORCESTART = YES
+HOSTNAME = localhost
+BINARY = gnunet-service-zonemaster-monitor
+UNIXPATH = $GNUNET_USER_RUNTIME_DIR/gnunet-service-zonemaster-monitor.sock
+@JAVAPORT@PORT = 2124
+
+# Do we require users that want to access GNS to run this process
+# (usually not a good idea)
+UNIX_MATCH_UID = NO
+
+# Do we require users that want to access GNS to be in the 'gnunet' group?
+UNIX_MATCH_GID = NO