aboutsummaryrefslogtreecommitdiff
path: root/src/service/namestore/test_namestore_api_tx_rollback.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/service/namestore/test_namestore_api_tx_rollback.c')
-rw-r--r--src/service/namestore/test_namestore_api_tx_rollback.c264
1 files changed, 0 insertions, 264 deletions
diff --git a/src/service/namestore/test_namestore_api_tx_rollback.c b/src/service/namestore/test_namestore_api_tx_rollback.c
deleted file mode 100644
index 0c334d374..000000000
--- a/src/service/namestore/test_namestore_api_tx_rollback.c
+++ /dev/null
@@ -1,264 +0,0 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2022 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20/**
21 * @file namestore/test_namestore_api_tx_rollback.c
22 * @brief testcase for namestore_api_tx_rollback.c to: rollback changes in TX
23 */
24#include "platform.h"
25#include "gnunet_namestore_service.h"
26#include "gnunet_testing_lib.h"
27
28#define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT
29
30#define TEST_RECORD_DATALEN 123
31
32#define TEST_RECORD_DATA 'a'
33
34#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100)
35
36
37static struct GNUNET_NAMESTORE_Handle *nsh;
38
39static struct GNUNET_SCHEDULER_Task *endbadly_task;
40
41static struct GNUNET_CRYPTO_PrivateKey privkey;
42
43static struct GNUNET_CRYPTO_PublicKey pubkey;
44
45static int res;
46
47static int removed;
48
49static struct GNUNET_NAMESTORE_QueueEntry *nsqe;
50
51
52static void
53cleanup ()
54{
55 if (NULL != nsh)
56 {
57 GNUNET_NAMESTORE_disconnect (nsh);
58 nsh = NULL;
59 }
60 GNUNET_SCHEDULER_shutdown ();
61}
62
63
64/**
65 * Re-establish the connection to the service.
66 *
67 * @param cls handle to use to re-connect.
68 */
69static void
70endbadly (void *cls)
71{
72 if (NULL != nsqe)
73 {
74 GNUNET_NAMESTORE_cancel (nsqe);
75 nsqe = NULL;
76 }
77 cleanup ();
78 res = 1;
79}
80
81
82static void
83end (void *cls)
84{
85 cleanup ();
86 res = 0;
87}
88
89static void
90lookup_it (void *cls,
91 const struct GNUNET_CRYPTO_PrivateKey *zone,
92 const char *label,
93 unsigned int rd_count,
94 const struct GNUNET_GNSRECORD_Data *rd)
95{
96 GNUNET_assert (0 == rd_count);
97 GNUNET_SCHEDULER_add_now (&end, NULL);
98}
99
100static void
101fail_cb (void *cls)
102{
103 GNUNET_assert (0);
104}
105
106static void
107remove_cont (void *cls,
108 enum GNUNET_ErrorCode ec)
109{
110 nsqe = NULL;
111 if (GNUNET_EC_NONE != ec)
112 {
113 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
114 _ ("Unable to roll back: `%s'\n"),
115 GNUNET_ErrorCode_get_hint (ec));
116 if (NULL != endbadly_task)
117 GNUNET_SCHEDULER_cancel (endbadly_task);
118 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly,
119 NULL);
120 return;
121 }
122 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
123 "Rolled back, perform lookup\n");
124 removed = GNUNET_YES;
125 if (NULL != endbadly_task)
126 GNUNET_SCHEDULER_cancel (endbadly_task);
127 /* FIXME not actually doing lookup here */
128 nsqe = GNUNET_NAMESTORE_records_lookup (nsh,
129 &privkey,
130 (char*) cls,
131 &fail_cb,
132 NULL,
133 &lookup_it,
134 NULL);
135}
136
137
138static void
139put_cont (void *cls,
140 enum GNUNET_ErrorCode ec)
141{
142 const char *name = cls;
143
144 GNUNET_assert (NULL != cls);
145 nsqe = NULL;
146 if (GNUNET_EC_NONE != ec)
147 {
148 GNUNET_break (0);
149 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
150 "Namestore could not store record: `%s'\n",
151 GNUNET_ErrorCode_get_hint (ec));
152 if (endbadly_task != NULL)
153 GNUNET_SCHEDULER_cancel (endbadly_task);
154 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
155 return;
156 }
157
158 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
159 "Name store added record for `%s': %s\n",
160 name,
161 (GNUNET_EC_NONE == ec) ? "SUCCESS" : "FAIL");
162 nsqe = GNUNET_NAMESTORE_transaction_rollback (nsh, remove_cont,
163 (void *) name);
164}
165
166static void
167begin_cont (void *cls,
168 enum GNUNET_ErrorCode ec)
169{
170 struct GNUNET_GNSRECORD_Data rd;
171 const char *name = cls;
172
173 GNUNET_assert (GNUNET_EC_NONE == ec);
174 privkey.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY);
175 GNUNET_CRYPTO_ecdsa_key_create (&privkey.ecdsa_key);
176 GNUNET_CRYPTO_key_get_public (&privkey,
177 &pubkey);
178
179 removed = GNUNET_NO;
180
181 rd.expiration_time = GNUNET_TIME_absolute_get ().abs_value_us;
182 rd.record_type = TEST_RECORD_TYPE;
183 rd.data_size = TEST_RECORD_DATALEN;
184 rd.data = GNUNET_malloc (TEST_RECORD_DATALEN);
185 rd.flags = 0;
186 memset ((char *) rd.data,
187 'a',
188 TEST_RECORD_DATALEN);
189 nsqe = GNUNET_NAMESTORE_records_store (nsh,
190 &privkey,
191 name,
192 1,
193 &rd,
194 &put_cont,
195 (void *) name);
196 GNUNET_assert (NULL != nsqe);
197 GNUNET_free_nz ((void *) rd.data);
198}
199
200static void
201run (void *cls,
202 const struct GNUNET_CONFIGURATION_Handle *cfg,
203 struct GNUNET_TESTING_Peer *peer)
204{
205 const char *name = "dummy";
206
207 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
208 &endbadly,
209 NULL);
210 nsh = GNUNET_NAMESTORE_connect (cfg);
211 GNUNET_break (NULL != nsh);
212 nsqe = GNUNET_NAMESTORE_transaction_begin (nsh, begin_cont, (void *) name);
213 /*nsqe = GNUNET_NAMESTORE_transaction_commit (nsh, commit_cont);
214 nsqe = GNUNET_NAMESTORE_transaction_rollback (nsh, rollback_cont); Must also happen on disconnect
215 nsqe = GNUNET_NAMESTORE_records_edit (nsh,
216 &privkey,
217 name,
218 1,
219 &rd,
220 &edit_cont,
221 (void *) name);
222 nsqe = GNUNET_NAMESTORE_records_insert_bulk (nsh,
223 count,
224 &rd,
225 &
226 nsqe = GNUNET_NAMESTORE_records_store (nsh,
227 &privkey,
228 name,
229 1,
230 &rd,
231 &put_cont,
232 (void *) name);*/
233 GNUNET_assert (NULL != nsqe);
234}
235
236
237#include "test_common.c"
238
239
240int
241main (int argc, char *argv[])
242{
243 char *plugin_name;
244 char *cfg_name;
245
246 SETUP_CFG (plugin_name, cfg_name);
247 res = 1;
248 if (0 !=
249 GNUNET_TESTING_peer_run ("test-namestore-api-remove",
250 cfg_name,
251 &run,
252 NULL))
253 {
254 res = 1;
255 }
256 GNUNET_DISK_purge_cfg_dir (cfg_name,
257 "GNUNET_TEST_HOME");
258 GNUNET_free (plugin_name);
259 GNUNET_free (cfg_name);
260 return res;
261}
262
263
264/* end of test_namestore_api_remove.c */