aboutsummaryrefslogtreecommitdiff
path: root/src/service/namestore/test_namestore_api_edit_records.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/service/namestore/test_namestore_api_edit_records.c')
-rw-r--r--src/service/namestore/test_namestore_api_edit_records.c238
1 files changed, 38 insertions, 200 deletions
diff --git a/src/service/namestore/test_namestore_api_edit_records.c b/src/service/namestore/test_namestore_api_edit_records.c
index 94b4f4fc1..9dce13e33 100644
--- a/src/service/namestore/test_namestore_api_edit_records.c
+++ b/src/service/namestore/test_namestore_api_edit_records.c
@@ -21,7 +21,6 @@
21 * @file namestore/test_namestore_api_edit_records.c 21 * @file namestore/test_namestore_api_edit_records.c
22 * @brief testcase for namestore_api.c: Multiple clients work with record set. 22 * @brief testcase for namestore_api.c: Multiple clients work with record set.
23 */ 23 */
24#include "platform.h"
25#include "gnunet_namestore_service.h" 24#include "gnunet_namestore_service.h"
26#include "gnunet_testing_lib.h" 25#include "gnunet_testing_lib.h"
27 26
@@ -50,8 +49,6 @@ static int removed;
50 49
51static struct GNUNET_NAMESTORE_QueueEntry *nsqe; 50static struct GNUNET_NAMESTORE_QueueEntry *nsqe;
52 51
53static int nonce = 0;
54
55static void 52static void
56cleanup () 53cleanup ()
57{ 54{
@@ -60,6 +57,11 @@ cleanup ()
60 GNUNET_NAMESTORE_disconnect (nsh); 57 GNUNET_NAMESTORE_disconnect (nsh);
61 nsh = NULL; 58 nsh = NULL;
62 } 59 }
60 if (NULL != nsh2)
61 {
62 GNUNET_NAMESTORE_disconnect (nsh2);
63 nsh2 = NULL;
64 }
63 GNUNET_SCHEDULER_shutdown (); 65 GNUNET_SCHEDULER_shutdown ();
64} 66}
65 67
@@ -85,195 +87,50 @@ endbadly (void *cls)
85static void 87static void
86end (void *cls) 88end (void *cls)
87{ 89{
88 cleanup ();
89 res = 0;
90}
91
92static void
93lookup_it (void *cls,
94 const struct GNUNET_CRYPTO_PrivateKey *zone,
95 const char *label,
96 unsigned int rd_count,
97 const struct GNUNET_GNSRECORD_Data *rd)
98{
99 GNUNET_assert (0 == rd_count);
100 GNUNET_SCHEDULER_add_now (&end, NULL);
101}
102
103static void
104fail_cb (void *cls)
105{
106 if (endbadly_task != NULL) 90 if (endbadly_task != NULL)
107 GNUNET_SCHEDULER_cancel (endbadly_task); 91 GNUNET_SCHEDULER_cancel (endbadly_task);
108 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); 92 cleanup ();
109 return; 93 res = 0;
110}
111
112static void
113remove_cont (void *cls,
114 enum GNUNET_ErrorCode ec)
115{
116 nsqe = NULL;
117 if (GNUNET_EC_NONE != ec)
118 {
119 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
120 _ ("Unable to roll back: `%s'\n"),
121 GNUNET_ErrorCode_get_hint (ec));
122 if (NULL != endbadly_task)
123 GNUNET_SCHEDULER_cancel (endbadly_task);
124 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly,
125 NULL);
126 return;
127 }
128 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
129 "Rolled back, perform lookup\n");
130 removed = GNUNET_YES;
131 if (NULL != endbadly_task)
132 GNUNET_SCHEDULER_cancel (endbadly_task);
133 GNUNET_SCHEDULER_add_now (&end, NULL);
134}
135
136static void
137fail_cb_lock (void *cls);
138
139static void
140edit_cont_b (void *cls,
141 const struct GNUNET_CRYPTO_PrivateKey *zone,
142 const char *label,
143 unsigned int rd_count,
144 const struct GNUNET_GNSRECORD_Data *rd)
145{
146 const char *name = cls;
147 /**
148 * We should probably never get here right at first.
149 * We may want to change the blocking of nsh2 so that we do get this
150 * eventually instead of the error callback above when locked.
151 */
152 if (0 == nonce)
153 {
154 if (endbadly_task != NULL)
155 GNUNET_SCHEDULER_cancel (endbadly_task);
156 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
157 return;
158
159 }
160 /* Abort transaction for B */
161 nsqe = GNUNET_NAMESTORE_transaction_rollback (nsh2, remove_cont,
162 (void *) name);
163}
164
165
166static void
167commit_cont_a (void *cls,
168 enum GNUNET_ErrorCode ec)
169{
170 const char *name = cls;
171
172 GNUNET_assert (NULL != cls);
173 nsqe = NULL;
174 if (GNUNET_EC_NONE != ec)
175 {
176 GNUNET_break (0);
177 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
178 "Namestore could not store record: `%s'\n",
179 GNUNET_ErrorCode_get_hint (ec));
180 if (endbadly_task != NULL)
181 GNUNET_SCHEDULER_cancel (endbadly_task);
182 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
183 return;
184 }
185
186 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
187 "Name store added record for `%s': %s\n",
188 name,
189 (GNUNET_EC_NONE == ec) ? "SUCCESS" : "FAIL");
190 /**
191 * Try again for B
192 */
193 nsqe = GNUNET_NAMESTORE_records_edit (nsh2,
194 &privkey,
195 name,
196 &fail_cb_lock,
197 (void *) name,
198 &edit_cont_b,
199 (void *) name);
200
201 GNUNET_assert (NULL != nsqe);
202}
203
204static void
205fail_cb_lock (void *cls)
206{
207 const char *name = cls;
208 if (1 == nonce)
209 {
210 if (endbadly_task != NULL)
211 GNUNET_SCHEDULER_cancel (endbadly_task);
212 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
213 return;
214 }
215 nonce = 1;
216 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
217 "Failed to aquire additional lock\n");
218 /* Now, we stop the transaction for B */
219 nsqe = GNUNET_NAMESTORE_transaction_commit (nsh, commit_cont_a,
220 (void *) name);
221} 94}
222 95
223 96
224static void 97static void
225begin_cont_b (void *cls, 98begin_cont_b (void *cls,
226 enum GNUNET_ErrorCode ec) 99 enum GNUNET_ErrorCode ec,
100 unsigned int rd_count,
101 const struct
102 GNUNET_GNSRECORD_Data *rd,
103 const char *editor_hint)
227{ 104{
228 const char *name = cls; 105 const char *name = cls;
229 106
230 GNUNET_assert (GNUNET_EC_NONE == ec); 107 GNUNET_assert (GNUNET_EC_NONE == ec);
231 /** Now, we expect this to "hang" let's see how this behaves in practice. */ 108 GNUNET_assert (0 != strcmp (editor_hint, "B"));
232 nsqe = GNUNET_NAMESTORE_records_edit (nsh2, 109 GNUNET_SCHEDULER_add_now (&end, NULL);
233 &privkey,
234 name,
235 &fail_cb_lock,
236 (void *) name,
237 &edit_cont_b,
238 (void *) name);
239
240 GNUNET_assert (NULL != nsqe);
241}
242
243
244static void
245edit_cont (void *cls,
246 const struct GNUNET_CRYPTO_PrivateKey *zone,
247 const char *label,
248 unsigned int rd_count,
249 const struct GNUNET_GNSRECORD_Data *rd)
250{
251 const char *name = cls;
252
253 GNUNET_assert (1 == rd_count);
254 /* Now, we start a transaction for B */
255 nsqe = GNUNET_NAMESTORE_transaction_begin (nsh2, begin_cont_b, (void *) name);
256} 110}
257 111
258 112
259static void 113static void
260begin_cont (void *cls, 114begin_cont (void *cls,
261 enum GNUNET_ErrorCode ec) 115 enum GNUNET_ErrorCode ec,
116 unsigned int rd_count,
117 const struct
118 GNUNET_GNSRECORD_Data *rd,
119 const char *editor_hint)
262{ 120{
263 const char *name = cls; 121 const char *name = cls;
264 122
265 GNUNET_assert (GNUNET_EC_NONE == ec); 123 GNUNET_assert (GNUNET_EC_NONE == ec);
266 nsqe = GNUNET_NAMESTORE_records_edit (nsh, 124 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
267 &privkey, 125 "records: `%u'\n",
268 name, 126 rd_count);
269 &fail_cb, 127 GNUNET_assert (1 == rd_count);
270 (void *) name, 128 nsqe = GNUNET_NAMESTORE_record_set_edit_begin (nsh2, &privkey, name, "B",
271 &edit_cont, 129 &begin_cont_b, name);
272 (void *) name);
273
274 GNUNET_assert (NULL != nsqe); 130 GNUNET_assert (NULL != nsqe);
275} 131}
276 132
133
277static void 134static void
278preload_cont (void *cls, 135preload_cont (void *cls,
279 enum GNUNET_ErrorCode ec) 136 enum GNUNET_ErrorCode ec)
@@ -299,7 +156,8 @@ preload_cont (void *cls,
299 name, 156 name,
300 (GNUNET_EC_NONE == ec) ? "SUCCESS" : "FAIL"); 157 (GNUNET_EC_NONE == ec) ? "SUCCESS" : "FAIL");
301 /* We start transaction for A */ 158 /* We start transaction for A */
302 nsqe = GNUNET_NAMESTORE_transaction_begin (nsh, begin_cont, (void *) name); 159 nsqe = GNUNET_NAMESTORE_record_set_edit_begin (nsh, &privkey, name, "A",
160 &begin_cont, name);
303 161
304} 162}
305 163
@@ -323,11 +181,12 @@ run (void *cls,
323 privkey.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); 181 privkey.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY);
324 GNUNET_CRYPTO_ecdsa_key_create (&privkey.ecdsa_key); 182 GNUNET_CRYPTO_ecdsa_key_create (&privkey.ecdsa_key);
325 GNUNET_CRYPTO_key_get_public (&privkey, 183 GNUNET_CRYPTO_key_get_public (&privkey,
326 &pubkey); 184 &pubkey);
327 185
328 removed = GNUNET_NO; 186 removed = GNUNET_NO;
329 187
330 rd.expiration_time = GNUNET_TIME_absolute_get ().abs_value_us; 188 rd.expiration_time = GNUNET_TIME_absolute_get ().abs_value_us
189 + GNUNET_TIME_UNIT_DAYS.rel_value_us;
331 rd.record_type = TEST_RECORD_TYPE; 190 rd.record_type = TEST_RECORD_TYPE;
332 rd.data_size = TEST_RECORD_DATALEN; 191 rd.data_size = TEST_RECORD_DATALEN;
333 rd.data = GNUNET_malloc (TEST_RECORD_DATALEN); 192 rd.data = GNUNET_malloc (TEST_RECORD_DATALEN);
@@ -335,36 +194,15 @@ run (void *cls,
335 memset ((char *) rd.data, 194 memset ((char *) rd.data,
336 'a', 195 'a',
337 TEST_RECORD_DATALEN); 196 TEST_RECORD_DATALEN);
338 nsqe = GNUNET_NAMESTORE_records_store (nsh, 197 nsqe = GNUNET_NAMESTORE_record_set_store (nsh,
339 &privkey, 198 &privkey,
340 name, 199 name,
341 1, 200 1,
342 &rd, 201 &rd,
343 &preload_cont, 202 &preload_cont,
344 (void *) name); 203 (void *) name);
345 GNUNET_assert (NULL != nsqe); 204 GNUNET_assert (NULL != nsqe);
346 GNUNET_free_nz ((void *) rd.data); 205 GNUNET_free_nz ((void *) rd.data);
347
348 /*nsqe = GNUNET_NAMESTORE_transaction_commit (nsh, commit_cont);
349 nsqe = GNUNET_NAMESTORE_transaction_rollback (nsh, rollback_cont); Must also happen on disconnect
350 nsqe = GNUNET_NAMESTORE_records_edit (nsh,
351 &privkey,
352 name,
353 1,
354 &rd,
355 &edit_cont,
356 (void *) name);
357 nsqe = GNUNET_NAMESTORE_records_insert_bulk (nsh,
358 count,
359 &rd,
360 &
361 nsqe = GNUNET_NAMESTORE_records_store (nsh,
362 &privkey,
363 name,
364 1,
365 &rd,
366 &put_cont,
367 (void *) name);*/
368 GNUNET_assert (NULL != nsqe); 206 GNUNET_assert (NULL != nsqe);
369} 207}
370 208