summaryrefslogtreecommitdiff
path: root/src/namestore/test_namestore_api_lookup_shadow.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/namestore/test_namestore_api_lookup_shadow.c')
-rw-r--r--src/namestore/test_namestore_api_lookup_shadow.c276
1 files changed, 138 insertions, 138 deletions
diff --git a/src/namestore/test_namestore_api_lookup_shadow.c b/src/namestore/test_namestore_api_lookup_shadow.c
index 1938054d4..d25cdcdbb 100644
--- a/src/namestore/test_namestore_api_lookup_shadow.c
+++ b/src/namestore/test_namestore_api_lookup_shadow.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_lookup_shadow.c 21 * @file namestore/test_namestore_api_lookup_shadow.c
22 * @brief testcase for namestore_api.c: store a shadow record and perform a lookup 22 * @brief testcase for namestore_api.c: store a shadow record and perform a lookup
@@ -35,7 +35,7 @@
35 35
36#define TEST_RECORD_DATA 'a' 36#define TEST_RECORD_DATA 'a'
37 37
38#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100) 38#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 100)
39 39
40 40
41static struct GNUNET_NAMESTORE_Handle *nsh; 41static struct GNUNET_NAMESTORE_Handle *nsh;
@@ -56,24 +56,24 @@ static struct GNUNET_NAMECACHE_QueueEntry *ncqe;
56 56
57 57
58static void 58static void
59cleanup () 59cleanup()
60{ 60{
61 if (NULL != nsh) 61 if (NULL != nsh)
62 { 62 {
63 GNUNET_NAMESTORE_disconnect (nsh); 63 GNUNET_NAMESTORE_disconnect(nsh);
64 nsh = NULL; 64 nsh = NULL;
65 } 65 }
66 if (NULL != nch) 66 if (NULL != nch)
67 { 67 {
68 GNUNET_NAMECACHE_disconnect (nch); 68 GNUNET_NAMECACHE_disconnect(nch);
69 nch = NULL; 69 nch = NULL;
70 } 70 }
71 if (NULL != privkey) 71 if (NULL != privkey)
72 { 72 {
73 GNUNET_free (privkey); 73 GNUNET_free(privkey);
74 privkey = NULL; 74 privkey = NULL;
75 } 75 }
76 GNUNET_SCHEDULER_shutdown (); 76 GNUNET_SCHEDULER_shutdown();
77} 77}
78 78
79 79
@@ -83,178 +83,178 @@ cleanup ()
83 * @param cls handle to use to re-connect. 83 * @param cls handle to use to re-connect.
84 */ 84 */
85static void 85static void
86endbadly (void *cls) 86endbadly(void *cls)
87{ 87{
88 if (NULL != nsqe) 88 if (NULL != nsqe)
89 { 89 {
90 GNUNET_NAMESTORE_cancel (nsqe); 90 GNUNET_NAMESTORE_cancel(nsqe);
91 nsqe = NULL; 91 nsqe = NULL;
92 } 92 }
93 if (NULL != ncqe) 93 if (NULL != ncqe)
94 { 94 {
95 GNUNET_NAMECACHE_cancel (ncqe); 95 GNUNET_NAMECACHE_cancel(ncqe);
96 ncqe = NULL; 96 ncqe = NULL;
97 } 97 }
98 cleanup (); 98 cleanup();
99 res = 1; 99 res = 1;
100} 100}
101 101
102 102
103static void 103static void
104end (void *cls) 104end(void *cls)
105{ 105{
106 cleanup (); 106 cleanup();
107 res = 0; 107 res = 0;
108} 108}
109 109
110 110
111static void 111static void
112rd_decrypt_cb (void *cls, 112rd_decrypt_cb(void *cls,
113 unsigned int rd_count, 113 unsigned int rd_count,
114 const struct GNUNET_GNSRECORD_Data *rd) 114 const struct GNUNET_GNSRECORD_Data *rd)
115{ 115{
116 char rd_cmp_data[TEST_RECORD_DATALEN]; 116 char rd_cmp_data[TEST_RECORD_DATALEN];
117 117
118 if (1 != rd_count) 118 if (1 != rd_count)
119 { 119 {
120 GNUNET_SCHEDULER_add_now (&endbadly, NULL); 120 GNUNET_SCHEDULER_add_now(&endbadly, NULL);
121 GNUNET_break (0); 121 GNUNET_break(0);
122 return; 122 return;
123 } 123 }
124 if (NULL == rd) 124 if (NULL == rd)
125 { 125 {
126 GNUNET_SCHEDULER_add_now (&endbadly, NULL); 126 GNUNET_SCHEDULER_add_now(&endbadly, NULL);
127 GNUNET_break (0); 127 GNUNET_break(0);
128 return; 128 return;
129 } 129 }
130 memset (rd_cmp_data, 'a', TEST_RECORD_DATALEN); 130 memset(rd_cmp_data, 'a', TEST_RECORD_DATALEN);
131 131
132 if (TEST_RECORD_TYPE != rd[0].record_type) 132 if (TEST_RECORD_TYPE != rd[0].record_type)
133 { 133 {
134 GNUNET_SCHEDULER_add_now (&endbadly, NULL); 134 GNUNET_SCHEDULER_add_now(&endbadly, NULL);
135 GNUNET_break (0); 135 GNUNET_break(0);
136 return; 136 return;
137 } 137 }
138 if (TEST_RECORD_DATALEN != rd[0].data_size) 138 if (TEST_RECORD_DATALEN != rd[0].data_size)
139 { 139 {
140 GNUNET_SCHEDULER_add_now (&endbadly, NULL); 140 GNUNET_SCHEDULER_add_now(&endbadly, NULL);
141 GNUNET_break (0); 141 GNUNET_break(0);
142 return; 142 return;
143 } 143 }
144 if (0 != memcmp (&rd_cmp_data, rd[0].data, TEST_RECORD_DATALEN)) 144 if (0 != memcmp(&rd_cmp_data, rd[0].data, TEST_RECORD_DATALEN))
145 { 145 {
146 GNUNET_SCHEDULER_add_now (&endbadly, NULL); 146 GNUNET_SCHEDULER_add_now(&endbadly, NULL);
147 GNUNET_break (0); 147 GNUNET_break(0);
148 return; 148 return;
149 } 149 }
150 if (0 != (GNUNET_GNSRECORD_RF_SHADOW_RECORD & rd[0].flags)) 150 if (0 != (GNUNET_GNSRECORD_RF_SHADOW_RECORD & rd[0].flags))
151 { 151 {
152 GNUNET_SCHEDULER_add_now (&endbadly, NULL); 152 GNUNET_SCHEDULER_add_now(&endbadly, NULL);
153 GNUNET_break (0); 153 GNUNET_break(0);
154 return; 154 return;
155 } 155 }
156 156
157 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 157 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
158 "Block was decrypted successfully \n"); 158 "Block was decrypted successfully \n");
159 159
160 GNUNET_SCHEDULER_add_now (&end, NULL); 160 GNUNET_SCHEDULER_add_now(&end, NULL);
161} 161}
162 162
163 163
164static void 164static void
165name_lookup_proc (void *cls, 165name_lookup_proc(void *cls,
166 const struct GNUNET_GNSRECORD_Block *block) 166 const struct GNUNET_GNSRECORD_Block *block)
167{ 167{
168 const char *name = cls; 168 const char *name = cls;
169 169
170 ncqe = NULL; 170 ncqe = NULL;
171 GNUNET_assert (NULL != cls); 171 GNUNET_assert(NULL != cls);
172 172
173 if (endbadly_task != NULL) 173 if (endbadly_task != NULL)
174 { 174 {
175 GNUNET_SCHEDULER_cancel (endbadly_task); 175 GNUNET_SCHEDULER_cancel(endbadly_task);
176 endbadly_task = NULL; 176 endbadly_task = NULL;
177 } 177 }
178 178
179 if (NULL == block) 179 if (NULL == block)
180 { 180 {
181 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 181 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
182 _("Namestore returned no block\n")); 182 _("Namestore returned no block\n"));
183 if (endbadly_task != NULL) 183 if (endbadly_task != NULL)
184 GNUNET_SCHEDULER_cancel (endbadly_task); 184 GNUNET_SCHEDULER_cancel(endbadly_task);
185 endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); 185 endbadly_task = GNUNET_SCHEDULER_add_now(&endbadly, NULL);
186 return; 186 return;
187 } 187 }
188 188
189 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 189 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
190 "Namestore returned block, decrypting \n"); 190 "Namestore returned block, decrypting \n");
191 GNUNET_assert (GNUNET_OK == GNUNET_GNSRECORD_block_decrypt(block, 191 GNUNET_assert(GNUNET_OK == GNUNET_GNSRECORD_block_decrypt(block,
192 &pubkey, name, &rd_decrypt_cb, (void *) name)); 192 &pubkey, name, &rd_decrypt_cb, (void *)name));
193} 193}
194 194
195 195
196static void 196static void
197put_cont (void *cls, int32_t success, const char *emsg) 197put_cont(void *cls, int32_t success, const char *emsg)
198{ 198{
199 const char *name = cls; 199 const char *name = cls;
200 struct GNUNET_HashCode derived_hash; 200 struct GNUNET_HashCode derived_hash;
201 struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; 201 struct GNUNET_CRYPTO_EcdsaPublicKey pubkey;
202 202
203 nsqe = NULL; 203 nsqe = NULL;
204 GNUNET_assert (NULL != cls); 204 GNUNET_assert(NULL != cls);
205 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 205 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
206 "Name store added record for `%s': %s\n", 206 "Name store added record for `%s': %s\n",
207 name, 207 name,
208 (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); 208 (success == GNUNET_OK) ? "SUCCESS" : "FAIL");
209 209
210 /* Create derived hash */ 210 /* Create derived hash */
211 GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey); 211 GNUNET_CRYPTO_ecdsa_key_get_public(privkey, &pubkey);
212 GNUNET_GNSRECORD_query_from_public_key (&pubkey, name, &derived_hash); 212 GNUNET_GNSRECORD_query_from_public_key(&pubkey, name, &derived_hash);
213 213
214 ncqe = GNUNET_NAMECACHE_lookup_block (nch, &derived_hash, 214 ncqe = GNUNET_NAMECACHE_lookup_block(nch, &derived_hash,
215 &name_lookup_proc, (void *) name); 215 &name_lookup_proc, (void *)name);
216} 216}
217 217
218 218
219static void 219static void
220run (void *cls, 220run(void *cls,
221 const struct GNUNET_CONFIGURATION_Handle *cfg, 221 const struct GNUNET_CONFIGURATION_Handle *cfg,
222 struct GNUNET_TESTING_Peer *peer) 222 struct GNUNET_TESTING_Peer *peer)
223{ 223{
224 struct GNUNET_GNSRECORD_Data rd; 224 struct GNUNET_GNSRECORD_Data rd;
225 const char * name = "dummy.dummy.gnunet"; 225 const char * name = "dummy.dummy.gnunet";
226 226
227 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 227 endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,
228 &endbadly, 228 &endbadly,
229 NULL); 229 NULL);
230 privkey = GNUNET_CRYPTO_ecdsa_key_create (); 230 privkey = GNUNET_CRYPTO_ecdsa_key_create();
231 GNUNET_assert (privkey != NULL); 231 GNUNET_assert(privkey != NULL);
232 GNUNET_CRYPTO_ecdsa_key_get_public (privkey, 232 GNUNET_CRYPTO_ecdsa_key_get_public(privkey,
233 &pubkey); 233 &pubkey);
234 rd.expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000; 234 rd.expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000;
235 rd.record_type = TEST_RECORD_TYPE; 235 rd.record_type = TEST_RECORD_TYPE;
236 rd.data_size = TEST_RECORD_DATALEN; 236 rd.data_size = TEST_RECORD_DATALEN;
237 rd.data = GNUNET_malloc (TEST_RECORD_DATALEN); 237 rd.data = GNUNET_malloc(TEST_RECORD_DATALEN);
238 rd.flags = GNUNET_GNSRECORD_RF_SHADOW_RECORD; 238 rd.flags = GNUNET_GNSRECORD_RF_SHADOW_RECORD;
239 memset ((char *) rd.data, 'a', TEST_RECORD_DATALEN); 239 memset((char *)rd.data, 'a', TEST_RECORD_DATALEN);
240 240
241 nsh = GNUNET_NAMESTORE_connect (cfg); 241 nsh = GNUNET_NAMESTORE_connect(cfg);
242 nch = GNUNET_NAMECACHE_connect (cfg); 242 nch = GNUNET_NAMECACHE_connect(cfg);
243 GNUNET_break (NULL != nsh); 243 GNUNET_break(NULL != nsh);
244 GNUNET_break (NULL != nch); 244 GNUNET_break(NULL != nch);
245 nsqe = GNUNET_NAMESTORE_records_store (nsh, 245 nsqe = GNUNET_NAMESTORE_records_store(nsh,
246 privkey, 246 privkey,
247 name, 247 name,
248 1, 248 1,
249 &rd, 249 &rd,
250 &put_cont, 250 &put_cont,
251 (void *) name); 251 (void *)name);
252 if (NULL == nsqe) 252 if (NULL == nsqe)
253 { 253 {
254 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 254 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
255 _("Namestore cannot store no block\n")); 255 _("Namestore cannot store no block\n"));
256 } 256 }
257 GNUNET_free ((void *)rd.data); 257 GNUNET_free((void *)rd.data);
258} 258}
259 259
260 260
@@ -262,24 +262,24 @@ run (void *cls,
262 262
263 263
264int 264int
265main (int argc, char *argv[]) 265main(int argc, char *argv[])
266{ 266{
267 const char *plugin_name; 267 const char *plugin_name;
268 char *cfg_name; 268 char *cfg_name;
269 269
270 SETUP_CFG (plugin_name, cfg_name); 270 SETUP_CFG(plugin_name, cfg_name);
271 res = 1; 271 res = 1;
272 if (0 != 272 if (0 !=
273 GNUNET_TESTING_peer_run ("test-namestore-api-lookup-shadow", 273 GNUNET_TESTING_peer_run("test-namestore-api-lookup-shadow",
274 cfg_name, 274 cfg_name,
275 &run, 275 &run,
276 NULL)) 276 NULL))
277 { 277 {
278 res = 1; 278 res = 1;
279 } 279 }
280 GNUNET_DISK_purge_cfg_dir (cfg_name, 280 GNUNET_DISK_purge_cfg_dir(cfg_name,
281 "GNUNET_TEST_HOME"); 281 "GNUNET_TEST_HOME");
282 GNUNET_free (cfg_name); 282 GNUNET_free(cfg_name);
283 return res; 283 return res;
284} 284}
285 285