aboutsummaryrefslogtreecommitdiff
path: root/src/namestore/test_namestore_api_lookup_private.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/namestore/test_namestore_api_lookup_private.c')
-rw-r--r--src/namestore/test_namestore_api_lookup_private.c230
1 files changed, 115 insertions, 115 deletions
diff --git a/src/namestore/test_namestore_api_lookup_private.c b/src/namestore/test_namestore_api_lookup_private.c
index cf9bfc20c..a387720a0 100644
--- a/src/namestore/test_namestore_api_lookup_private.c
+++ b/src/namestore/test_namestore_api_lookup_private.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 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/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file namestore/test_namestore_api_store.c 21 * @file namestore/test_namestore_api_store.c
22 * @brief testcase for namestore_api.c: store a record 22 * @brief testcase for namestore_api.c: store a record
@@ -32,7 +32,7 @@
32 32
33#define TEST_RECORD_DATA 'a' 33#define TEST_RECORD_DATA 'a'
34 34
35#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) 35#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5)
36 36
37static struct GNUNET_NAMESTORE_Handle *nsh; 37static struct GNUNET_NAMESTORE_Handle *nsh;
38 38
@@ -51,19 +51,19 @@ static const char * name = "d";
51 51
52 52
53static void 53static void
54cleanup () 54cleanup()
55{ 55{
56 if (NULL != nsh) 56 if (NULL != nsh)
57 { 57 {
58 GNUNET_NAMESTORE_disconnect (nsh); 58 GNUNET_NAMESTORE_disconnect(nsh);
59 nsh = NULL; 59 nsh = NULL;
60 } 60 }
61 if (NULL != privkey) 61 if (NULL != privkey)
62 { 62 {
63 GNUNET_free (privkey); 63 GNUNET_free(privkey);
64 privkey = NULL; 64 privkey = NULL;
65 } 65 }
66 GNUNET_SCHEDULER_shutdown (); 66 GNUNET_SCHEDULER_shutdown();
67} 67}
68 68
69 69
@@ -73,152 +73,152 @@ cleanup ()
73 * @param cls handle to use to re-connect. 73 * @param cls handle to use to re-connect.
74 */ 74 */
75static void 75static void
76endbadly (void *cls) 76endbadly(void *cls)
77{ 77{
78 endbadly_task = NULL; 78 endbadly_task = NULL;
79 if (NULL != nsqe) 79 if (NULL != nsqe)
80 { 80 {
81 GNUNET_NAMESTORE_cancel (nsqe); 81 GNUNET_NAMESTORE_cancel(nsqe);
82 nsqe = NULL; 82 nsqe = NULL;
83 } 83 }
84 cleanup (); 84 cleanup();
85 res = 1; 85 res = 1;
86} 86}
87 87
88 88
89static void 89static void
90end (void *cls) 90end(void *cls)
91{ 91{
92 cleanup (); 92 cleanup();
93 res = 0; 93 res = 0;
94} 94}
95 95
96 96
97static void 97static void
98lookup_it (void *cls, 98lookup_it(void *cls,
99 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, 99 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
100 const char *label, 100 const char *label,
101 unsigned int rd_count, 101 unsigned int rd_count,
102 const struct GNUNET_GNSRECORD_Data *rd) 102 const struct GNUNET_GNSRECORD_Data *rd)
103{ 103{
104 nsqe = NULL; 104 nsqe = NULL;
105 105
106 if (0 != GNUNET_memcmp (privkey, 106 if (0 != GNUNET_memcmp(privkey,
107 zone)) 107 zone))
108 { 108 {
109 GNUNET_break(0); 109 GNUNET_break(0);
110 GNUNET_SCHEDULER_cancel (endbadly_task); 110 GNUNET_SCHEDULER_cancel(endbadly_task);
111 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); 111 endbadly_task = GNUNET_SCHEDULER_add_now(&endbadly, NULL);
112 return; 112 return;
113 } 113 }
114 114
115 115
116 if (NULL == label) 116 if (NULL == label)
117 { 117 {
118 GNUNET_break(0); 118 GNUNET_break(0);
119 GNUNET_SCHEDULER_cancel (endbadly_task); 119 GNUNET_SCHEDULER_cancel(endbadly_task);
120 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); 120 endbadly_task = GNUNET_SCHEDULER_add_now(&endbadly, NULL);
121 return; 121 return;
122 } 122 }
123 123
124 if (0 != strcmp (label, name)) 124 if (0 != strcmp(label, name))
125 { 125 {
126 GNUNET_break(0); 126 GNUNET_break(0);
127 GNUNET_SCHEDULER_cancel (endbadly_task); 127 GNUNET_SCHEDULER_cancel(endbadly_task);
128 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); 128 endbadly_task = GNUNET_SCHEDULER_add_now(&endbadly, NULL);
129 return; 129 return;
130 } 130 }
131 131
132 if (1 != rd_count) 132 if (1 != rd_count)
133 { 133 {
134 GNUNET_break(0); 134 GNUNET_break(0);
135 GNUNET_SCHEDULER_cancel (endbadly_task); 135 GNUNET_SCHEDULER_cancel(endbadly_task);
136 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); 136 endbadly_task = GNUNET_SCHEDULER_add_now(&endbadly, NULL);
137 return; 137 return;
138 } 138 }
139 139
140 /* Done */ 140 /* Done */
141 GNUNET_SCHEDULER_cancel (endbadly_task); 141 GNUNET_SCHEDULER_cancel(endbadly_task);
142 endbadly_task = NULL; 142 endbadly_task = NULL;
143 GNUNET_SCHEDULER_add_now (&end, NULL); 143 GNUNET_SCHEDULER_add_now(&end, NULL);
144} 144}
145 145
146 146
147static void 147static void
148fail_cb (void *cls) 148fail_cb(void *cls)
149{ 149{
150 GNUNET_assert (0); 150 GNUNET_assert(0);
151} 151}
152 152
153 153
154static void 154static void
155put_cont (void *cls, 155put_cont(void *cls,
156 int32_t success, 156 int32_t success,
157 const char *emsg) 157 const char *emsg)
158{ 158{
159 const char *name = cls; 159 const char *name = cls;
160 160
161 nsqe = NULL; 161 nsqe = NULL;
162 GNUNET_assert (NULL != cls); 162 GNUNET_assert(NULL != cls);
163 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 163 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
164 "Name store added record for `%s': %s\n", 164 "Name store added record for `%s': %s\n",
165 name, 165 name,
166 (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); 166 (success == GNUNET_OK) ? "SUCCESS" : "FAIL");
167 167
168 if (GNUNET_OK != success) 168 if (GNUNET_OK != success)
169 { 169 {
170 GNUNET_SCHEDULER_cancel (endbadly_task); 170 GNUNET_SCHEDULER_cancel(endbadly_task);
171 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); 171 endbadly_task = GNUNET_SCHEDULER_add_now(&endbadly, NULL);
172 return; 172 return;
173 } 173 }
174 /* Lookup */ 174 /* Lookup */
175 nsqe = GNUNET_NAMESTORE_records_lookup (nsh, 175 nsqe = GNUNET_NAMESTORE_records_lookup(nsh,
176 privkey, 176 privkey,
177 name, 177 name,
178 &fail_cb, 178 &fail_cb,
179 NULL, 179 NULL,
180 &lookup_it, 180 &lookup_it,
181 NULL); 181 NULL);
182} 182}
183 183
184 184
185static void 185static void
186run (void *cls, 186run(void *cls,
187 const struct GNUNET_CONFIGURATION_Handle *cfg, 187 const struct GNUNET_CONFIGURATION_Handle *cfg,
188 struct GNUNET_TESTING_Peer *peer) 188 struct GNUNET_TESTING_Peer *peer)
189{ 189{
190 struct GNUNET_GNSRECORD_Data rd; 190 struct GNUNET_GNSRECORD_Data rd;
191 191
192 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 192 endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,
193 &endbadly, 193 &endbadly,
194 NULL); 194 NULL);
195 privkey = GNUNET_CRYPTO_ecdsa_key_create (); 195 privkey = GNUNET_CRYPTO_ecdsa_key_create();
196 GNUNET_assert (privkey != NULL); 196 GNUNET_assert(privkey != NULL);
197 GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey); 197 GNUNET_CRYPTO_ecdsa_key_get_public(privkey, &pubkey);
198 198
199 rd.expiration_time = GNUNET_TIME_absolute_get().abs_value_us; 199 rd.expiration_time = GNUNET_TIME_absolute_get().abs_value_us;
200 rd.record_type = TEST_RECORD_TYPE; 200 rd.record_type = TEST_RECORD_TYPE;
201 rd.data_size = TEST_RECORD_DATALEN; 201 rd.data_size = TEST_RECORD_DATALEN;
202 rd.data = GNUNET_malloc (TEST_RECORD_DATALEN); 202 rd.data = GNUNET_malloc(TEST_RECORD_DATALEN);
203 rd.flags = 0; 203 rd.flags = 0;
204 memset ((char *) rd.data, 'a', TEST_RECORD_DATALEN); 204 memset((char *)rd.data, 'a', TEST_RECORD_DATALEN);
205 205
206 nsh = GNUNET_NAMESTORE_connect (cfg); 206 nsh = GNUNET_NAMESTORE_connect(cfg);
207 GNUNET_break (NULL != nsh); 207 GNUNET_break(NULL != nsh);
208 nsqe = GNUNET_NAMESTORE_records_store (nsh, 208 nsqe = GNUNET_NAMESTORE_records_store(nsh,
209 privkey, 209 privkey,
210 name, 210 name,
211 1, 211 1,
212 &rd, 212 &rd,
213 &put_cont, 213 &put_cont,
214 (void *) name); 214 (void *)name);
215 if (NULL == nsqe) 215 if (NULL == nsqe)
216 { 216 {
217 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 217 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
218 _("Namestore cannot store no block\n")); 218 _("Namestore cannot store no block\n"));
219 } 219 }
220 220
221 GNUNET_free ((void *)rd.data); 221 GNUNET_free((void *)rd.data);
222} 222}
223 223
224 224
@@ -226,7 +226,7 @@ run (void *cls,
226 226
227 227
228int 228int
229main (int argc, char *argv[]) 229main(int argc, char *argv[])
230{ 230{
231 const char *plugin_name; 231 const char *plugin_name;
232 char *cfg_name; 232 char *cfg_name;
@@ -234,16 +234,16 @@ main (int argc, char *argv[])
234 SETUP_CFG(plugin_name, cfg_name); 234 SETUP_CFG(plugin_name, cfg_name);
235 res = 1; 235 res = 1;
236 if (0 != 236 if (0 !=
237 GNUNET_TESTING_peer_run ("test-namestore-api-lookup-private", 237 GNUNET_TESTING_peer_run("test-namestore-api-lookup-private",
238 cfg_name, 238 cfg_name,
239 &run, 239 &run,
240 NULL)) 240 NULL))
241 { 241 {
242 res = 1; 242 res = 1;
243 } 243 }
244 GNUNET_DISK_purge_cfg_dir (cfg_name, 244 GNUNET_DISK_purge_cfg_dir(cfg_name,
245 "GNUNET_TEST_HOME"); 245 "GNUNET_TEST_HOME");
246 GNUNET_free (cfg_name); 246 GNUNET_free(cfg_name);
247 return res; 247 return res;
248} 248}
249 249