diff options
Diffstat (limited to 'src/namestore/test_namestore_api_remove.c')
-rw-r--r-- | src/namestore/test_namestore_api_remove.c | 221 |
1 files changed, 0 insertions, 221 deletions
diff --git a/src/namestore/test_namestore_api_remove.c b/src/namestore/test_namestore_api_remove.c deleted file mode 100644 index e8124c595..000000000 --- a/src/namestore/test_namestore_api_remove.c +++ /dev/null | |||
@@ -1,221 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2013 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.c | ||
22 | * @brief testcase for namestore_api.c to: remove record | ||
23 | */ | ||
24 | #include "platform.h" | ||
25 | #include "gnunet_namestore_service.h" | ||
26 | #include "gnunet_testing_lib.h" | ||
27 | #include "gnunet_dnsparser_lib.h" | ||
28 | |||
29 | #define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT | ||
30 | |||
31 | #define TEST_RECORD_DATALEN 123 | ||
32 | |||
33 | #define TEST_RECORD_DATA 'a' | ||
34 | |||
35 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100) | ||
36 | |||
37 | |||
38 | static struct GNUNET_NAMESTORE_Handle *nsh; | ||
39 | |||
40 | static struct GNUNET_SCHEDULER_Task *endbadly_task; | ||
41 | |||
42 | static struct GNUNET_IDENTITY_PrivateKey privkey; | ||
43 | |||
44 | static struct GNUNET_IDENTITY_PublicKey pubkey; | ||
45 | |||
46 | static int res; | ||
47 | |||
48 | static int removed; | ||
49 | |||
50 | static struct GNUNET_NAMESTORE_QueueEntry *nsqe; | ||
51 | |||
52 | |||
53 | static void | ||
54 | cleanup () | ||
55 | { | ||
56 | if (NULL != nsh) | ||
57 | { | ||
58 | GNUNET_NAMESTORE_disconnect (nsh); | ||
59 | nsh = NULL; | ||
60 | } | ||
61 | GNUNET_SCHEDULER_shutdown (); | ||
62 | } | ||
63 | |||
64 | |||
65 | /** | ||
66 | * Re-establish the connection to the service. | ||
67 | * | ||
68 | * @param cls handle to use to re-connect. | ||
69 | */ | ||
70 | static void | ||
71 | endbadly (void *cls) | ||
72 | { | ||
73 | if (NULL != nsqe) | ||
74 | { | ||
75 | GNUNET_NAMESTORE_cancel (nsqe); | ||
76 | nsqe = NULL; | ||
77 | } | ||
78 | cleanup (); | ||
79 | res = 1; | ||
80 | } | ||
81 | |||
82 | |||
83 | static void | ||
84 | end (void *cls) | ||
85 | { | ||
86 | cleanup (); | ||
87 | res = 0; | ||
88 | } | ||
89 | |||
90 | |||
91 | static void | ||
92 | remove_cont (void *cls, | ||
93 | int32_t success, | ||
94 | const char *emsg) | ||
95 | { | ||
96 | nsqe = NULL; | ||
97 | if (GNUNET_YES != success) | ||
98 | { | ||
99 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
100 | _ ("Records could not be removed: `%s'\n"), | ||
101 | emsg); | ||
102 | if (NULL != endbadly_task) | ||
103 | GNUNET_SCHEDULER_cancel (endbadly_task); | ||
104 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, | ||
105 | NULL); | ||
106 | return; | ||
107 | } | ||
108 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
109 | "Records were removed, perform lookup\n"); | ||
110 | removed = GNUNET_YES; | ||
111 | if (NULL != endbadly_task) | ||
112 | GNUNET_SCHEDULER_cancel (endbadly_task); | ||
113 | GNUNET_SCHEDULER_add_now (&end, NULL); | ||
114 | } | ||
115 | |||
116 | |||
117 | static void | ||
118 | put_cont (void *cls, | ||
119 | int32_t success, | ||
120 | const char *emsg) | ||
121 | { | ||
122 | const char *name = cls; | ||
123 | |||
124 | GNUNET_assert (NULL != cls); | ||
125 | nsqe = NULL; | ||
126 | if (GNUNET_SYSERR == success) | ||
127 | { | ||
128 | GNUNET_break (0); | ||
129 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
130 | "Namestore could not store record: `%s'\n", | ||
131 | emsg); | ||
132 | if (endbadly_task != NULL) | ||
133 | GNUNET_SCHEDULER_cancel (endbadly_task); | ||
134 | endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); | ||
135 | return; | ||
136 | } | ||
137 | |||
138 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
139 | "Name store added record for `%s': %s\n", | ||
140 | name, | ||
141 | (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); | ||
142 | nsqe = GNUNET_NAMESTORE_records_store (nsh, | ||
143 | &privkey, | ||
144 | name, | ||
145 | 0, NULL, | ||
146 | &remove_cont, (void *) name); | ||
147 | } | ||
148 | |||
149 | |||
150 | static void | ||
151 | run (void *cls, | ||
152 | const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
153 | struct GNUNET_TESTING_Peer *peer) | ||
154 | { | ||
155 | struct GNUNET_GNSRECORD_Data rd; | ||
156 | const char *name = "dummy"; | ||
157 | |||
158 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | ||
159 | &endbadly, | ||
160 | NULL); | ||
161 | privkey.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); | ||
162 | GNUNET_CRYPTO_ecdsa_key_create (&privkey.ecdsa_key); | ||
163 | GNUNET_IDENTITY_key_get_public (&privkey, | ||
164 | &pubkey); | ||
165 | |||
166 | removed = GNUNET_NO; | ||
167 | |||
168 | rd.expiration_time = GNUNET_TIME_absolute_get ().abs_value_us; | ||
169 | rd.record_type = TEST_RECORD_TYPE; | ||
170 | rd.data_size = TEST_RECORD_DATALEN; | ||
171 | rd.data = GNUNET_malloc (TEST_RECORD_DATALEN); | ||
172 | rd.flags = 0; | ||
173 | memset ((char *) rd.data, | ||
174 | 'a', | ||
175 | TEST_RECORD_DATALEN); | ||
176 | |||
177 | nsh = GNUNET_NAMESTORE_connect (cfg); | ||
178 | GNUNET_break (NULL != nsh); | ||
179 | nsqe = GNUNET_NAMESTORE_records_store (nsh, | ||
180 | &privkey, | ||
181 | name, | ||
182 | 1, | ||
183 | &rd, | ||
184 | &put_cont, | ||
185 | (void *) name); | ||
186 | if (NULL == nsqe) | ||
187 | { | ||
188 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
189 | _ ("Namestore cannot store no block\n")); | ||
190 | } | ||
191 | GNUNET_free_nz ((void *) rd.data); | ||
192 | } | ||
193 | |||
194 | |||
195 | #include "test_common.c" | ||
196 | |||
197 | |||
198 | int | ||
199 | main (int argc, char *argv[]) | ||
200 | { | ||
201 | const char *plugin_name; | ||
202 | char *cfg_name; | ||
203 | |||
204 | SETUP_CFG (plugin_name, cfg_name); | ||
205 | res = 1; | ||
206 | if (0 != | ||
207 | GNUNET_TESTING_peer_run ("test-namestore-api-remove", | ||
208 | cfg_name, | ||
209 | &run, | ||
210 | NULL)) | ||
211 | { | ||
212 | res = 1; | ||
213 | } | ||
214 | GNUNET_DISK_purge_cfg_dir (cfg_name, | ||
215 | "GNUNET_TEST_HOME"); | ||
216 | GNUNET_free (cfg_name); | ||
217 | return res; | ||
218 | } | ||
219 | |||
220 | |||
221 | /* end of test_namestore_api_remove.c */ | ||