[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnunet] branch master updated: -fix tests; add zonefile test
From: |
gnunet |
Subject: |
[gnunet] branch master updated: -fix tests; add zonefile test |
Date: |
Wed, 19 Oct 2022 17:26:36 +0200 |
This is an automated email from the git hooks/post-receive script.
martin-schanzenbach pushed a commit to branch master
in repository gnunet.
The following commit(s) were added to refs/heads/master by this push:
new f03070c1d -fix tests; add zonefile test
new 0cf50c859 Merge branch 'master' of git+ssh://git.gnunet.org/gnunet
f03070c1d is described below
commit f03070c1d052acb48bf635b44cf16963c041dbaf
Author: Martin Schanzenbach <schanzen@gnunet.org>
AuthorDate: Thu Oct 20 00:26:00 2022 +0900
-fix tests; add zonefile test
---
src/gnsrecord/gnsrecord_misc.c | 12 ++++-
src/namestore/Makefile.am | 4 +-
src/namestore/example_zonefile | 17 +++++++
src/namestore/gnunet-namestore-zonefile.c | 68 +++++++++++++++++++++----
src/namestore/gnunet-service-namestore.c | 24 ++++++---
src/namestore/namestore_api.c | 2 +-
src/namestore/test_namestore_api.conf | 1 +
src/namestore/test_namestore_api_remove.c | 4 +-
src/namestore/test_namestore_zonefile_import.sh | 33 ++++++++++++
9 files changed, 142 insertions(+), 23 deletions(-)
diff --git a/src/gnsrecord/gnsrecord_misc.c b/src/gnsrecord/gnsrecord_misc.c
index 990c46bcc..742eaf186 100644
--- a/src/gnsrecord/gnsrecord_misc.c
+++ b/src/gnsrecord/gnsrecord_misc.c
@@ -433,13 +433,21 @@ GNUNET_GNSRECORD_normalize_record_set (const char *label,
/* Ignore private records for public record set */
if ((0 != (filter & GNUNET_GNSRECORD_FILTER_OMIT_PRIVATE)) &&
(0 != (rd[i].flags & GNUNET_GNSRECORD_RF_PRIVATE)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Filtering private record filter=%u...\n", filter);
continue;
+ }
/* Skip expired records */
if ((0 == (rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION)) &&
(rd[i].expiration_time < now.abs_value_us))
- continue; /* record already expired, skip it */
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Filtering expired record...\n");
+ continue; /* record already expired, skip it */
+ }
/* Ignore the tombstone unless filter permits explicitly.
- * Remember expiration time. */
+ * Remember expiration time. */
if (GNUNET_GNSRECORD_TYPE_TOMBSTONE == rd[i].record_type)
{
minimum_expiration.abs_value_us = rd[i].expiration_time;
diff --git a/src/namestore/Makefile.am b/src/namestore/Makefile.am
index 8abe6560f..9bd725546 100644
--- a/src/namestore/Makefile.am
+++ b/src/namestore/Makefile.am
@@ -514,7 +514,8 @@ test_plugin_namestore_postgres_LDADD = \
check_SCRIPTS = \
test_namestore_put.sh \
test_namestore_lookup.sh \
- test_namestore_delete.sh
+ test_namestore_delete.sh \
+ test_namestore_zonefile_import.sh
# FIXME
#check_SCRIPTS += \
@@ -530,4 +531,5 @@ EXTRA_DIST = \
test_plugin_namestore_sqlite.conf \
test_plugin_namestore_postgres.conf \
test_hostkey \
+ example_zonefile \
$(check_SCRIPTS)
diff --git a/src/namestore/example_zonefile b/src/namestore/example_zonefile
new file mode 100644
index 000000000..3a2324eec
--- /dev/null
+++ b/src/namestore/example_zonefile
@@ -0,0 +1,17 @@
+$ORIGIN example.com. ; designates the start of this zone file in the
namespace
+$TTL 3600 ; default expiration time (in seconds) of all RRs
without their own TTL value
+example.com. IN SOA ns.example.com. username.example.com. ( 2020091025
7200 3600 1209600 3600 )
+example.com. IN NS ns ; ns.example.com is a
nameserver for example.com
+example.com. IN NS ns.somewhere.example. ; ns.somewhere.example is a
backup nameserver for example.com
+example.com. IN MX 10 mail.example.com. ; mail.example.com is the
mailserver for example.com
+@ IN MX 20 mail2.example.com. ; equivalent to above line,
"@" represents zone origin
+@ IN MX 50 mail3 ; equivalent to above line,
but using a relative host name
+b.example.com. IN A 192.0.2.1 ; IPv4 address for example.com
+ IN AAAA 2001:db8:10::1 ; IPv6 address for example.com
+ns IN A 192.0.2.2 ; IPv4 address for
ns.example.com
+ IN AAAA 2001:db8:10::2 ; IPv6 address for
ns.example.com
+www IN CNAME example.com. ; www.example.com is an alias
for example.com
+wwwtest IN CNAME www ; wwwtest.example.com is
another alias for www.example.com
+mail IN A 192.0.2.3 ; IPv4 address for
mail.example.com
+mail2 IN A 192.0.2.4 ; IPv4 address for
mail2.example.com
+mail3 IN A 192.0.2.5 ; IPv4 address for
mail3.example.com
diff --git a/src/namestore/gnunet-namestore-zonefile.c
b/src/namestore/gnunet-namestore-zonefile.c
index d8ac7c234..f2eb17297 100644
--- a/src/namestore/gnunet-namestore-zonefile.c
+++ b/src/namestore/gnunet-namestore-zonefile.c
@@ -96,6 +96,22 @@ tx_end (void *cls, int32_t success, const char *emsg)
GNUNET_SCHEDULER_shutdown ();
}
+static void
+parse (void *cls);
+
+static void
+add_continuation (void *cls, int32_t success, const char *emsg)
+{
+ ns_qe = NULL;
+ if (GNUNET_SYSERR == success)
+ {
+ fprintf (stderr,
+ _ ("Failed to store records...\n"));
+ GNUNET_SCHEDULER_shutdown ();
+ ret = -1;
+ }
+ GNUNET_SCHEDULER_add_now (&parse, NULL);
+}
/**
* Main function that will be run.
@@ -120,21 +136,22 @@ tx_end (void *cls, int32_t success, const char *emsg)
static void
parse (void *cls)
{
- struct GNUNET_GNSRECORD_Data rd[50]; // Let's hope we do not need more
- struct GNUNET_GNSRECORD_Data *cur_rd = rd;
+ static struct GNUNET_GNSRECORD_Data rd[50]; // Let's hope we do not need more
char buf[5000]; /* buffer to hold entire line (adjust MAXC as needed) */
char *next;
char *token;
char origin[255];
- char lastname[255];
+ static char lastname[255];
+ char newname[255];
void *data;
size_t data_size;
struct GNUNET_TIME_Relative ttl;
int origin_line = 0;
int ttl_line = 0;
int type;
- unsigned int rd_count = 0;
+ static unsigned int rd_count = 0;
uint32_t ttl_tmp;
+ int publish_rd = GNUNET_NO;
/* use filename provided as 1st argument (stdin by default) */
int i = 0;
@@ -163,16 +180,17 @@ parse (void *cls)
if (0 == strlen (buf)) // Inherit name from before
{
printf ("Old name: %s\n", lastname);
+ strcpy (newname, lastname);
}
else if (buf[strlen (buf) - 1] != '.') // no fqdn
{
printf ("New name: %s\n", buf);
- strcpy (lastname, buf);
+ strcpy (newname, buf);
}
else if (0 == strcmp (buf, origin))
{
printf ("New name: @\n");
- strcpy (lastname, "@");
+ strcpy (newname, "@");
}
else
{
@@ -188,8 +206,18 @@ parse (void *cls)
}
buf[strlen (buf) - strlen (origin) - 1] = '\0';
printf ("New name: %s\n", buf);
- strcpy (lastname, buf);
+ strcpy (newname, buf);
+ }
+ if (0 != strcmp (newname, lastname) &&
+ (0 < rd_count))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Name changed %s->%s, storing record set of %u elements\n",
+ lastname, newname,
+ rd_count);
+ publish_rd = GNUNET_YES;
}
+ strcpy (lastname, newname);
}
while (*next == ' ')
next++;
@@ -225,8 +253,8 @@ parse (void *cls)
continue;
}
// This is a record, let's go
- cur_rd->flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
- cur_rd->expiration_time = ttl.rel_value_us;
+ rd[rd_count].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
+ rd[rd_count].expiration_time = ttl.rel_value_us;
next = strchr (token, ' ');
if (NULL == next)
{
@@ -249,7 +277,7 @@ parse (void *cls)
next++;
printf ("type is: %s\n", token);
type = GNUNET_GNSRECORD_typename_to_number (token);
- cur_rd->record_type = type;
+ rd[rd_count].record_type = type;
while (*next == ' ')
next++;
token = next;
@@ -264,6 +292,7 @@ parse (void *cls)
&data,
&data_size))
{
+ // FIXME free rd
fprintf (stderr,
_ ("Data `%s' invalid\n"),
token);
@@ -271,6 +300,25 @@ parse (void *cls)
GNUNET_SCHEDULER_shutdown ();
return;
}
+ rd[rd_count].data = data;
+ rd[rd_count].data_size = data_size;
+ if (GNUNET_YES == publish_rd)
+ break;
+ rd_count++;
+ }
+ if (GNUNET_YES == publish_rd)
+ {
+ ns_qe = GNUNET_NAMESTORE_records_store (ns,
+ &zone_pkey,
+ lastname,
+ rd_count,
+ rd,
+ &add_continuation,
+ NULL);
+ // FIXME cleanup rd
+ rd[0] = rd[rd_count]; // recover last rd parsed.
+ rd_count = 1;
+ return;
}
ns_qe = GNUNET_NAMESTORE_transaction_commit (ns,
&tx_end,
diff --git a/src/namestore/gnunet-service-namestore.c
b/src/namestore/gnunet-service-namestore.c
index c39dab53e..6b93c1973 100644
--- a/src/namestore/gnunet-service-namestore.c
+++ b/src/namestore/gnunet-service-namestore.c
@@ -449,10 +449,9 @@ static struct StoreActivity *sa_tail;
static struct GNUNET_NotificationContext *monitor_nc;
/**
- * Optimize block insertion by caching map of private keys to
- * public keys in memory?
+ * Returned orphaned records?
*/
-static int cache_keys;
+static int return_orphaned;
/**
* Task run during shutdown.
@@ -519,6 +518,8 @@ is_orphaned (const struct GNUNET_IDENTITY_PrivateKey *zone)
GNUNET_IDENTITY_key_get_public (zone, &pk);
keystring = GNUNET_IDENTITY_public_key_to_string (&pk);
+ if (GNUNET_YES == return_orphaned)
+ return GNUNET_NO;
for (ego_entry = ego_head; NULL != ego_entry;
ego_entry = ego_entry->next)
{
@@ -1493,7 +1494,7 @@ handle_record_lookup (void *cls, const struct
LabelLookupMessage *ll_msg)
name_len = strlen (conv_name) + 1;
rlc.label = conv_name;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Looking up with filter %u\n", ntohs(ll_msg->filter));
+ "Looking up with filter %u\n", ntohs (ll_msg->filter));
rlc.filter = ntohs (ll_msg->filter);
rlc.found = GNUNET_NO;
rlc.res_rd_count = 0;
@@ -1759,6 +1760,8 @@ store_record_set (struct NamestoreClient *nc,
GNUNET_free (conv_name);
return GNUNET_SYSERR;
}
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "%u/%u records before tombstone\n", rd_nf_count,
rd_clean_off);
/*
* If existing_block_exp is 0, then there was no record set
* and no tombstone.
@@ -1794,10 +1797,16 @@ store_record_set (struct NamestoreClient *nc,
* through res != GNUNET_NO) then we should return "NOT FOUND" ==
GNUNET_NO
*/
if ((GNUNET_SYSERR != res) &&
+ (0 == rd_count) &&
(1 == rd_nf_count) &&
(GNUNET_GNSRECORD_TYPE_TOMBSTONE == rd_nf[0].record_type) &&
- (lctx.only_tombstone))
+ (GNUNET_YES == lctx.only_tombstone))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Client tried to remove non-existant record\n");
+ *emsg = GNUNET_strdup (_("Not records to delete."));
res = GNUNET_NO;
+ }
}
if (GNUNET_SYSERR == res)
@@ -2708,8 +2717,9 @@ run (void *cls,
char *database;
(void) cls;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting namestore service\n");
- cache_keys =
- GNUNET_CONFIGURATION_get_value_yesno (cfg, "namestore", "CACHE_KEYS");
+ return_orphaned = GNUNET_CONFIGURATION_get_value_yesno (cfg,
+ "namestore",
+ "RETURN_ORPHANED");
GSN_cfg = cfg;
monitor_nc = GNUNET_notification_context_create (1);
statistics = GNUNET_STATISTICS_create ("namestore", cfg);
diff --git a/src/namestore/namestore_api.c b/src/namestore/namestore_api.c
index f92e6ef41..5111deee9 100644
--- a/src/namestore/namestore_api.c
+++ b/src/namestore/namestore_api.c
@@ -1164,7 +1164,7 @@ GNUNET_NAMESTORE_records_store2 (
}
*rds_sent = i;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sending %u of %u records!\n", *rds_sent, rd_count);
+ "Sending %u of %u records!\n", *rds_sent, rd_set_count);
rid = get_op_id (h);
qe = GNUNET_new (struct GNUNET_NAMESTORE_QueueEntry);
qe->h = h;
diff --git a/src/namestore/test_namestore_api.conf
b/src/namestore/test_namestore_api.conf
index e718196fc..1648c7cae 100644
--- a/src/namestore/test_namestore_api.conf
+++ b/src/namestore/test_namestore_api.conf
@@ -8,6 +8,7 @@ GNUNET_TEST_HOME = $GNUNET_TMP/test-gnunet-namestore/
DATABASE = sqlite
START_ON_DEMAND = YES
#PREFIX = valgrind --track-origins=yes --log-file=/tmp/ns_tx.log
+RETURN_ORPHANED = YES
[namecache]
DATABASE = sqlite
diff --git a/src/namestore/test_namestore_api_remove.c
b/src/namestore/test_namestore_api_remove.c
index e8124c595..c2b70f64a 100644
--- a/src/namestore/test_namestore_api_remove.c
+++ b/src/namestore/test_namestore_api_remove.c
@@ -165,11 +165,11 @@ run (void *cls,
removed = GNUNET_NO;
- rd.expiration_time = GNUNET_TIME_absolute_get ().abs_value_us;
+ rd.expiration_time = GNUNET_TIME_UNIT_MINUTES.rel_value_us;
rd.record_type = TEST_RECORD_TYPE;
rd.data_size = TEST_RECORD_DATALEN;
rd.data = GNUNET_malloc (TEST_RECORD_DATALEN);
- rd.flags = 0;
+ rd.flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
memset ((char *) rd.data,
'a',
TEST_RECORD_DATALEN);
diff --git a/src/namestore/test_namestore_zonefile_import.sh
b/src/namestore/test_namestore_zonefile_import.sh
new file mode 100755
index 000000000..9f156e9c9
--- /dev/null
+++ b/src/namestore/test_namestore_zonefile_import.sh
@@ -0,0 +1,33 @@
+#!/bin/sh
+# This file is in the public domain.
+trap "gnunet-arm -e -c test_namestore_api.conf" INT
+
+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
+
+rm -rf `gnunet-config -c test_namestore_api.conf -f -s paths -o
GNUNET_TEST_HOME`
+which timeout > /dev/null 2>&1 && DO_TIMEOUT="timeout 5"
+
+MY_EGO="myego"
+gnunet-arm -s -c test_namestore_api.conf
+gnunet-identity -C $MY_EGO -c test_namestore_api.conf
+gnunet-namestore-zonefile -c test_namestore_api.conf -z $MY_EGO <
example_zonefile
+res=$?
+gnunet-identity -D $MY_EGO -c test_namestore_api.conf
+gnunet-arm -e -c test_namestore_api.conf
+
+if [ $res != 0 ]; then
+ echo "FAIL: Zone import failed."
+ exit 1
+fi
+
+
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnunet] branch master updated: -fix tests; add zonefile test,
gnunet <=