aboutsummaryrefslogtreecommitdiff
path: root/src/namestore
diff options
context:
space:
mode:
authorMartin Schanzenbach <schanzen@gnunet.org>2022-10-20 00:26:00 +0900
committerMartin Schanzenbach <schanzen@gnunet.org>2022-10-20 00:26:00 +0900
commitf03070c1d052acb48bf635b44cf16963c041dbaf (patch)
treee137d07c0a81e74e50abc027b9274d2108bb7039 /src/namestore
parent3683f556df1324b1ce575dd5932d174d75512f7a (diff)
downloadgnunet-f03070c1d052acb48bf635b44cf16963c041dbaf.tar.gz
gnunet-f03070c1d052acb48bf635b44cf16963c041dbaf.zip
-fix tests; add zonefile test
Diffstat (limited to 'src/namestore')
-rw-r--r--src/namestore/Makefile.am4
-rw-r--r--src/namestore/example_zonefile17
-rw-r--r--src/namestore/gnunet-namestore-zonefile.c68
-rw-r--r--src/namestore/gnunet-service-namestore.c24
-rw-r--r--src/namestore/namestore_api.c2
-rw-r--r--src/namestore/test_namestore_api.conf1
-rw-r--r--src/namestore/test_namestore_api_remove.c4
-rwxr-xr-xsrc/namestore/test_namestore_zonefile_import.sh33
8 files changed, 132 insertions, 21 deletions
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 = \
514check_SCRIPTS = \ 514check_SCRIPTS = \
515 test_namestore_put.sh \ 515 test_namestore_put.sh \
516 test_namestore_lookup.sh \ 516 test_namestore_lookup.sh \
517 test_namestore_delete.sh 517 test_namestore_delete.sh \
518 test_namestore_zonefile_import.sh
518 519
519# FIXME 520# FIXME
520#check_SCRIPTS += \ 521#check_SCRIPTS += \
@@ -530,4 +531,5 @@ EXTRA_DIST = \
530 test_plugin_namestore_sqlite.conf \ 531 test_plugin_namestore_sqlite.conf \
531 test_plugin_namestore_postgres.conf \ 532 test_plugin_namestore_postgres.conf \
532 test_hostkey \ 533 test_hostkey \
534 example_zonefile \
533 $(check_SCRIPTS) 535 $(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 @@
1$ORIGIN example.com. ; designates the start of this zone file in the namespace
2$TTL 3600 ; default expiration time (in seconds) of all RRs without their own TTL value
3example.com. IN SOA ns.example.com. username.example.com. ( 2020091025 7200 3600 1209600 3600 )
4example.com. IN NS ns ; ns.example.com is a nameserver for example.com
5example.com. IN NS ns.somewhere.example. ; ns.somewhere.example is a backup nameserver for example.com
6example.com. IN MX 10 mail.example.com. ; mail.example.com is the mailserver for example.com
7@ IN MX 20 mail2.example.com. ; equivalent to above line, "@" represents zone origin
8@ IN MX 50 mail3 ; equivalent to above line, but using a relative host name
9b.example.com. IN A 192.0.2.1 ; IPv4 address for example.com
10 IN AAAA 2001:db8:10::1 ; IPv6 address for example.com
11ns IN A 192.0.2.2 ; IPv4 address for ns.example.com
12 IN AAAA 2001:db8:10::2 ; IPv6 address for ns.example.com
13www IN CNAME example.com. ; www.example.com is an alias for example.com
14wwwtest IN CNAME www ; wwwtest.example.com is another alias for www.example.com
15mail IN A 192.0.2.3 ; IPv4 address for mail.example.com
16mail2 IN A 192.0.2.4 ; IPv4 address for mail2.example.com
17mail3 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)
96 GNUNET_SCHEDULER_shutdown (); 96 GNUNET_SCHEDULER_shutdown ();
97} 97}
98 98
99static void
100parse (void *cls);
101
102static void
103add_continuation (void *cls, int32_t success, const char *emsg)
104{
105 ns_qe = NULL;
106 if (GNUNET_SYSERR == success)
107 {
108 fprintf (stderr,
109 _ ("Failed to store records...\n"));
110 GNUNET_SCHEDULER_shutdown ();
111 ret = -1;
112 }
113 GNUNET_SCHEDULER_add_now (&parse, NULL);
114}
99 115
100/** 116/**
101 * Main function that will be run. 117 * Main function that will be run.
@@ -120,21 +136,22 @@ tx_end (void *cls, int32_t success, const char *emsg)
120static void 136static void
121parse (void *cls) 137parse (void *cls)
122{ 138{
123 struct GNUNET_GNSRECORD_Data rd[50]; // Let's hope we do not need more 139 static struct GNUNET_GNSRECORD_Data rd[50]; // Let's hope we do not need more
124 struct GNUNET_GNSRECORD_Data *cur_rd = rd;
125 char buf[5000]; /* buffer to hold entire line (adjust MAXC as needed) */ 140 char buf[5000]; /* buffer to hold entire line (adjust MAXC as needed) */
126 char *next; 141 char *next;
127 char *token; 142 char *token;
128 char origin[255]; 143 char origin[255];
129 char lastname[255]; 144 static char lastname[255];
145 char newname[255];
130 void *data; 146 void *data;
131 size_t data_size; 147 size_t data_size;
132 struct GNUNET_TIME_Relative ttl; 148 struct GNUNET_TIME_Relative ttl;
133 int origin_line = 0; 149 int origin_line = 0;
134 int ttl_line = 0; 150 int ttl_line = 0;
135 int type; 151 int type;
136 unsigned int rd_count = 0; 152 static unsigned int rd_count = 0;
137 uint32_t ttl_tmp; 153 uint32_t ttl_tmp;
154 int publish_rd = GNUNET_NO;
138 155
139/* use filename provided as 1st argument (stdin by default) */ 156/* use filename provided as 1st argument (stdin by default) */
140 int i = 0; 157 int i = 0;
@@ -163,16 +180,17 @@ parse (void *cls)
163 if (0 == strlen (buf)) // Inherit name from before 180 if (0 == strlen (buf)) // Inherit name from before
164 { 181 {
165 printf ("Old name: %s\n", lastname); 182 printf ("Old name: %s\n", lastname);
183 strcpy (newname, lastname);
166 } 184 }
167 else if (buf[strlen (buf) - 1] != '.') // no fqdn 185 else if (buf[strlen (buf) - 1] != '.') // no fqdn
168 { 186 {
169 printf ("New name: %s\n", buf); 187 printf ("New name: %s\n", buf);
170 strcpy (lastname, buf); 188 strcpy (newname, buf);
171 } 189 }
172 else if (0 == strcmp (buf, origin)) 190 else if (0 == strcmp (buf, origin))
173 { 191 {
174 printf ("New name: @\n"); 192 printf ("New name: @\n");
175 strcpy (lastname, "@"); 193 strcpy (newname, "@");
176 } 194 }
177 else 195 else
178 { 196 {
@@ -188,8 +206,18 @@ parse (void *cls)
188 } 206 }
189 buf[strlen (buf) - strlen (origin) - 1] = '\0'; 207 buf[strlen (buf) - strlen (origin) - 1] = '\0';
190 printf ("New name: %s\n", buf); 208 printf ("New name: %s\n", buf);
191 strcpy (lastname, buf); 209 strcpy (newname, buf);
210 }
211 if (0 != strcmp (newname, lastname) &&
212 (0 < rd_count))
213 {
214 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
215 "Name changed %s->%s, storing record set of %u elements\n",
216 lastname, newname,
217 rd_count);
218 publish_rd = GNUNET_YES;
192 } 219 }
220 strcpy (lastname, newname);
193 } 221 }
194 while (*next == ' ') 222 while (*next == ' ')
195 next++; 223 next++;
@@ -225,8 +253,8 @@ parse (void *cls)
225 continue; 253 continue;
226 } 254 }
227 // This is a record, let's go 255 // This is a record, let's go
228 cur_rd->flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; 256 rd[rd_count].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
229 cur_rd->expiration_time = ttl.rel_value_us; 257 rd[rd_count].expiration_time = ttl.rel_value_us;
230 next = strchr (token, ' '); 258 next = strchr (token, ' ');
231 if (NULL == next) 259 if (NULL == next)
232 { 260 {
@@ -249,7 +277,7 @@ parse (void *cls)
249 next++; 277 next++;
250 printf ("type is: %s\n", token); 278 printf ("type is: %s\n", token);
251 type = GNUNET_GNSRECORD_typename_to_number (token); 279 type = GNUNET_GNSRECORD_typename_to_number (token);
252 cur_rd->record_type = type; 280 rd[rd_count].record_type = type;
253 while (*next == ' ') 281 while (*next == ' ')
254 next++; 282 next++;
255 token = next; 283 token = next;
@@ -264,6 +292,7 @@ parse (void *cls)
264 &data, 292 &data,
265 &data_size)) 293 &data_size))
266 { 294 {
295 // FIXME free rd
267 fprintf (stderr, 296 fprintf (stderr,
268 _ ("Data `%s' invalid\n"), 297 _ ("Data `%s' invalid\n"),
269 token); 298 token);
@@ -271,6 +300,25 @@ parse (void *cls)
271 GNUNET_SCHEDULER_shutdown (); 300 GNUNET_SCHEDULER_shutdown ();
272 return; 301 return;
273 } 302 }
303 rd[rd_count].data = data;
304 rd[rd_count].data_size = data_size;
305 if (GNUNET_YES == publish_rd)
306 break;
307 rd_count++;
308 }
309 if (GNUNET_YES == publish_rd)
310 {
311 ns_qe = GNUNET_NAMESTORE_records_store (ns,
312 &zone_pkey,
313 lastname,
314 rd_count,
315 rd,
316 &add_continuation,
317 NULL);
318 // FIXME cleanup rd
319 rd[0] = rd[rd_count]; // recover last rd parsed.
320 rd_count = 1;
321 return;
274 } 322 }
275 ns_qe = GNUNET_NAMESTORE_transaction_commit (ns, 323 ns_qe = GNUNET_NAMESTORE_transaction_commit (ns,
276 &tx_end, 324 &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;
449static struct GNUNET_NotificationContext *monitor_nc; 449static struct GNUNET_NotificationContext *monitor_nc;
450 450
451/** 451/**
452 * Optimize block insertion by caching map of private keys to 452 * Returned orphaned records?
453 * public keys in memory?
454 */ 453 */
455static int cache_keys; 454static int return_orphaned;
456 455
457/** 456/**
458 * Task run during shutdown. 457 * Task run during shutdown.
@@ -519,6 +518,8 @@ is_orphaned (const struct GNUNET_IDENTITY_PrivateKey *zone)
519 GNUNET_IDENTITY_key_get_public (zone, &pk); 518 GNUNET_IDENTITY_key_get_public (zone, &pk);
520 keystring = GNUNET_IDENTITY_public_key_to_string (&pk); 519 keystring = GNUNET_IDENTITY_public_key_to_string (&pk);
521 520
521 if (GNUNET_YES == return_orphaned)
522 return GNUNET_NO;
522 for (ego_entry = ego_head; NULL != ego_entry; 523 for (ego_entry = ego_head; NULL != ego_entry;
523 ego_entry = ego_entry->next) 524 ego_entry = ego_entry->next)
524 { 525 {
@@ -1493,7 +1494,7 @@ handle_record_lookup (void *cls, const struct LabelLookupMessage *ll_msg)
1493 name_len = strlen (conv_name) + 1; 1494 name_len = strlen (conv_name) + 1;
1494 rlc.label = conv_name; 1495 rlc.label = conv_name;
1495 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1496 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1496 "Looking up with filter %u\n", ntohs(ll_msg->filter)); 1497 "Looking up with filter %u\n", ntohs (ll_msg->filter));
1497 rlc.filter = ntohs (ll_msg->filter); 1498 rlc.filter = ntohs (ll_msg->filter);
1498 rlc.found = GNUNET_NO; 1499 rlc.found = GNUNET_NO;
1499 rlc.res_rd_count = 0; 1500 rlc.res_rd_count = 0;
@@ -1759,6 +1760,8 @@ store_record_set (struct NamestoreClient *nc,
1759 GNUNET_free (conv_name); 1760 GNUNET_free (conv_name);
1760 return GNUNET_SYSERR; 1761 return GNUNET_SYSERR;
1761 } 1762 }
1763 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1764 "%u/%u records before tombstone\n", rd_nf_count, rd_clean_off);
1762 /* 1765 /*
1763 * If existing_block_exp is 0, then there was no record set 1766 * If existing_block_exp is 0, then there was no record set
1764 * and no tombstone. 1767 * and no tombstone.
@@ -1794,10 +1797,16 @@ store_record_set (struct NamestoreClient *nc,
1794 * through res != GNUNET_NO) then we should return "NOT FOUND" == GNUNET_NO 1797 * through res != GNUNET_NO) then we should return "NOT FOUND" == GNUNET_NO
1795 */ 1798 */
1796 if ((GNUNET_SYSERR != res) && 1799 if ((GNUNET_SYSERR != res) &&
1800 (0 == rd_count) &&
1797 (1 == rd_nf_count) && 1801 (1 == rd_nf_count) &&
1798 (GNUNET_GNSRECORD_TYPE_TOMBSTONE == rd_nf[0].record_type) && 1802 (GNUNET_GNSRECORD_TYPE_TOMBSTONE == rd_nf[0].record_type) &&
1799 (lctx.only_tombstone)) 1803 (GNUNET_YES == lctx.only_tombstone))
1804 {
1805 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1806 "Client tried to remove non-existant record\n");
1807 *emsg = GNUNET_strdup (_("Not records to delete."));
1800 res = GNUNET_NO; 1808 res = GNUNET_NO;
1809 }
1801 } 1810 }
1802 1811
1803 if (GNUNET_SYSERR == res) 1812 if (GNUNET_SYSERR == res)
@@ -2708,8 +2717,9 @@ run (void *cls,
2708 char *database; 2717 char *database;
2709 (void) cls; 2718 (void) cls;
2710 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting namestore service\n"); 2719 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting namestore service\n");
2711 cache_keys = 2720 return_orphaned = GNUNET_CONFIGURATION_get_value_yesno (cfg,
2712 GNUNET_CONFIGURATION_get_value_yesno (cfg, "namestore", "CACHE_KEYS"); 2721 "namestore",
2722 "RETURN_ORPHANED");
2713 GSN_cfg = cfg; 2723 GSN_cfg = cfg;
2714 monitor_nc = GNUNET_notification_context_create (1); 2724 monitor_nc = GNUNET_notification_context_create (1);
2715 statistics = GNUNET_STATISTICS_create ("namestore", cfg); 2725 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 (
1164 } 1164 }
1165 *rds_sent = i; 1165 *rds_sent = i;
1166 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1166 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1167 "Sending %u of %u records!\n", *rds_sent, rd_count); 1167 "Sending %u of %u records!\n", *rds_sent, rd_set_count);
1168 rid = get_op_id (h); 1168 rid = get_op_id (h);
1169 qe = GNUNET_new (struct GNUNET_NAMESTORE_QueueEntry); 1169 qe = GNUNET_new (struct GNUNET_NAMESTORE_QueueEntry);
1170 qe->h = h; 1170 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/
8DATABASE = sqlite 8DATABASE = sqlite
9START_ON_DEMAND = YES 9START_ON_DEMAND = YES
10#PREFIX = valgrind --track-origins=yes --log-file=/tmp/ns_tx.log 10#PREFIX = valgrind --track-origins=yes --log-file=/tmp/ns_tx.log
11RETURN_ORPHANED = YES
11 12
12[namecache] 13[namecache]
13DATABASE = sqlite 14DATABASE = 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,
165 165
166 removed = GNUNET_NO; 166 removed = GNUNET_NO;
167 167
168 rd.expiration_time = GNUNET_TIME_absolute_get ().abs_value_us; 168 rd.expiration_time = GNUNET_TIME_UNIT_MINUTES.rel_value_us;
169 rd.record_type = TEST_RECORD_TYPE; 169 rd.record_type = TEST_RECORD_TYPE;
170 rd.data_size = TEST_RECORD_DATALEN; 170 rd.data_size = TEST_RECORD_DATALEN;
171 rd.data = GNUNET_malloc (TEST_RECORD_DATALEN); 171 rd.data = GNUNET_malloc (TEST_RECORD_DATALEN);
172 rd.flags = 0; 172 rd.flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
173 memset ((char *) rd.data, 173 memset ((char *) rd.data,
174 'a', 174 'a',
175 TEST_RECORD_DATALEN); 175 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 @@
1#!/bin/sh
2# This file is in the public domain.
3trap "gnunet-arm -e -c test_namestore_api.conf" INT
4
5LOCATION=$(which gnunet-config)
6if [ -z $LOCATION ]
7then
8 LOCATION="gnunet-config"
9fi
10$LOCATION --version 1> /dev/null
11if test $? != 0
12then
13 echo "GNUnet command line tools cannot be found, check environmental variables PATH and GNUNET_PREFIX"
14 exit 77
15fi
16
17rm -rf `gnunet-config -c test_namestore_api.conf -f -s paths -o GNUNET_TEST_HOME`
18which timeout > /dev/null 2>&1 && DO_TIMEOUT="timeout 5"
19
20MY_EGO="myego"
21gnunet-arm -s -c test_namestore_api.conf
22gnunet-identity -C $MY_EGO -c test_namestore_api.conf
23gnunet-namestore-zonefile -c test_namestore_api.conf -z $MY_EGO < example_zonefile
24res=$?
25gnunet-identity -D $MY_EGO -c test_namestore_api.conf
26gnunet-arm -e -c test_namestore_api.conf
27
28if [ $res != 0 ]; then
29 echo "FAIL: Zone import failed."
30 exit 1
31fi
32
33