aboutsummaryrefslogtreecommitdiff
path: root/src/revocation/test_revocation.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/revocation/test_revocation.c')
-rw-r--r--src/revocation/test_revocation.c421
1 files changed, 211 insertions, 210 deletions
diff --git a/src/revocation/test_revocation.c b/src/revocation/test_revocation.c
index 22cb98887..44d6c6ec8 100644
--- a/src/revocation/test_revocation.c
+++ b/src/revocation/test_revocation.c
@@ -31,7 +31,8 @@
31 31
32#define NUM_TEST_PEERS 2 32#define NUM_TEST_PEERS 2
33 33
34struct TestPeer { 34struct TestPeer
35{
35 struct GNUNET_TESTBED_Peer *p; 36 struct GNUNET_TESTBED_Peer *p;
36 struct GNUNET_TESTBED_Operation *identity_op; 37 struct GNUNET_TESTBED_Operation *identity_op;
37 struct GNUNET_TESTBED_Operation *core_op; 38 struct GNUNET_TESTBED_Operation *core_op;
@@ -56,352 +57,352 @@ static int ok;
56 57
57 58
58static void 59static void
59do_shutdown(void *cls) 60do_shutdown (void *cls)
60{ 61{
61 for (unsigned int c = 0; c < NUM_TEST_PEERS; c++) 62 for (unsigned int c = 0; c < NUM_TEST_PEERS; c++)
63 {
64 if (NULL != testpeers[c].create_id_op)
65 {
66 GNUNET_IDENTITY_cancel (testpeers[c].create_id_op);
67 testpeers[c].create_id_op = NULL;
68 }
69 if (NULL != testpeers[c].ego_lookup)
70 {
71 GNUNET_IDENTITY_ego_lookup_cancel (testpeers[c].ego_lookup);
72 testpeers[c].ego_lookup = NULL;
73 }
74 if (NULL != testpeers[c].revok_handle)
75 {
76 GNUNET_REVOCATION_revoke_cancel (testpeers[c].revok_handle);
77 testpeers[c].revok_handle = NULL;
78 }
79 if (NULL != testpeers[c].identity_op)
80 {
81 GNUNET_TESTBED_operation_done (testpeers[c].identity_op);
82 testpeers[c].identity_op = NULL;
83 }
84 if (NULL != testpeers[c].core_op)
62 { 85 {
63 if (NULL != testpeers[c].create_id_op) 86 GNUNET_TESTBED_operation_done (testpeers[c].core_op);
64 { 87 testpeers[c].core_op = NULL;
65 GNUNET_IDENTITY_cancel(testpeers[c].create_id_op);
66 testpeers[c].create_id_op = NULL;
67 }
68 if (NULL != testpeers[c].ego_lookup)
69 {
70 GNUNET_IDENTITY_ego_lookup_cancel(testpeers[c].ego_lookup);
71 testpeers[c].ego_lookup = NULL;
72 }
73 if (NULL != testpeers[c].revok_handle)
74 {
75 GNUNET_REVOCATION_revoke_cancel(testpeers[c].revok_handle);
76 testpeers[c].revok_handle = NULL;
77 }
78 if (NULL != testpeers[c].identity_op)
79 {
80 GNUNET_TESTBED_operation_done(testpeers[c].identity_op);
81 testpeers[c].identity_op = NULL;
82 }
83 if (NULL != testpeers[c].core_op)
84 {
85 GNUNET_TESTBED_operation_done(testpeers[c].core_op);
86 testpeers[c].core_op = NULL;
87 }
88 } 88 }
89 }
89} 90}
90 91
91 92
92static void 93static void
93check_revocation(void *cls); 94check_revocation (void *cls);
94 95
95 96
96static void 97static void
97revocation_remote_cb(void *cls, int is_valid) 98revocation_remote_cb (void *cls, int is_valid)
98{ 99{
99 static int repeat = 0; 100 static int repeat = 0;
100 101
101 if (GNUNET_NO == is_valid) 102 if (GNUNET_NO == is_valid)
102 { 103 {
103 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Local revocation successful\n"); 104 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Local revocation successful\n");
104 ok = 0; 105 ok = 0;
105 GNUNET_SCHEDULER_shutdown(); 106 GNUNET_SCHEDULER_shutdown ();
106 return; 107 return;
107 } 108 }
108 if (repeat < 10) 109 if (repeat < 10)
109 { 110 {
110 repeat++; 111 repeat++;
111 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, 112 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
112 &check_revocation, 113 &check_revocation,
113 NULL); 114 NULL);
114 return; 115 return;
115 } 116 }
116 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Flooding of revocation failed\n"); 117 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Flooding of revocation failed\n");
117 ok = 2; 118 ok = 2;
118 GNUNET_SCHEDULER_shutdown(); 119 GNUNET_SCHEDULER_shutdown ();
119} 120}
120 121
121 122
122static void 123static void
123check_revocation(void *cls) 124check_revocation (void *cls)
124{ 125{
125 GNUNET_REVOCATION_query(testpeers[0].cfg, 126 GNUNET_REVOCATION_query (testpeers[0].cfg,
126 &testpeers[1].pubkey, 127 &testpeers[1].pubkey,
127 &revocation_remote_cb, 128 &revocation_remote_cb,
128 NULL); 129 NULL);
129} 130}
130 131
131 132
132static void 133static void
133revocation_cb(void *cls, int is_valid) 134revocation_cb (void *cls, int is_valid)
134{ 135{
135 testpeers[1].revok_handle = NULL; 136 testpeers[1].revok_handle = NULL;
136 if (GNUNET_NO == is_valid) 137 if (GNUNET_NO == is_valid)
137 { 138 {
138 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Revocation successful\n"); 139 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Revocation successful\n");
139 check_revocation(NULL); 140 check_revocation (NULL);
140 } 141 }
141} 142}
142 143
143 144
144static void 145static void
145ego_cb(void *cls, const struct GNUNET_IDENTITY_Ego *ego) 146ego_cb (void *cls, const struct GNUNET_IDENTITY_Ego *ego)
146{ 147{
147 static int completed = 0; 148 static int completed = 0;
148 149
149 if ((NULL != ego) && (cls == &testpeers[0])) 150 if ((NULL != ego) && (cls == &testpeers[0]))
150 { 151 {
151 testpeers[0].ego_lookup = NULL; 152 testpeers[0].ego_lookup = NULL;
152 testpeers[0].privkey = GNUNET_IDENTITY_ego_get_private_key(ego); 153 testpeers[0].privkey = GNUNET_IDENTITY_ego_get_private_key (ego);
153 GNUNET_IDENTITY_ego_get_public_key(ego, &testpeers[0].pubkey); 154 GNUNET_IDENTITY_ego_get_public_key (ego, &testpeers[0].pubkey);
154 completed++; 155 completed++;
155 } 156 }
156 if ((NULL != ego) && (cls == &testpeers[1])) 157 if ((NULL != ego) && (cls == &testpeers[1]))
158 {
159 testpeers[1].ego_lookup = NULL;
160 testpeers[1].privkey = GNUNET_IDENTITY_ego_get_private_key (ego);
161 GNUNET_IDENTITY_ego_get_public_key (ego, &testpeers[1].pubkey);
162 GNUNET_REVOCATION_sign_revocation (testpeers[1].privkey, &testpeers[1].sig);
163
164 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Calculating proof of work...\n");
165 testpeers[1].pow = 0;
166 int res =
167 GNUNET_REVOCATION_check_pow (&testpeers[1].pubkey, testpeers[1].pow, 5);
168 while (GNUNET_OK != res)
157 { 169 {
158 testpeers[1].ego_lookup = NULL; 170 testpeers[1].pow++;
159 testpeers[1].privkey = GNUNET_IDENTITY_ego_get_private_key(ego); 171 res =
160 GNUNET_IDENTITY_ego_get_public_key(ego, &testpeers[1].pubkey); 172 GNUNET_REVOCATION_check_pow (&testpeers[1].pubkey, testpeers[1].pow, 5);
161 GNUNET_REVOCATION_sign_revocation(testpeers[1].privkey, &testpeers[1].sig);
162
163 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Calculating proof of work...\n");
164 testpeers[1].pow = 0;
165 int res =
166 GNUNET_REVOCATION_check_pow(&testpeers[1].pubkey, testpeers[1].pow, 5);
167 while (GNUNET_OK != res)
168 {
169 testpeers[1].pow++;
170 res =
171 GNUNET_REVOCATION_check_pow(&testpeers[1].pubkey, testpeers[1].pow, 5);
172 }
173 fprintf(stderr, "Done calculating proof of work\n");
174 completed++;
175 } 173 }
174 fprintf (stderr, "Done calculating proof of work\n");
175 completed++;
176 }
176 if (2 == completed) 177 if (2 == completed)
177 { 178 {
178 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Egos retrieved\n"); 179 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Egos retrieved\n");
179 testpeers[1].revok_handle = GNUNET_REVOCATION_revoke(testpeers[1].cfg, 180 testpeers[1].revok_handle = GNUNET_REVOCATION_revoke (testpeers[1].cfg,
180 &testpeers[1].pubkey, 181 &testpeers[1].pubkey,
181 &testpeers[1].sig, 182 &testpeers[1].sig,
182 testpeers[1].pow, 183 testpeers[1].pow,
183 &revocation_cb, 184 &revocation_cb,
184 NULL); 185 NULL);
185 } 186 }
186} 187}
187 188
188 189
189static void 190static void
190identity_create_cb(void *cls, 191identity_create_cb (void *cls,
191 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, 192 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk,
192 const char *emsg) 193 const char *emsg)
193{ 194{
194 static int completed = 0; 195 static int completed = 0;
195 196
196 if ((NULL == emsg) && (cls == &testpeers[0])) 197 if ((NULL == emsg) && (cls == &testpeers[0]))
197 { 198 {
198 testpeers[0].create_id_op = NULL; 199 testpeers[0].create_id_op = NULL;
199 completed++; 200 completed++;
200 } 201 }
201 if ((NULL == emsg) && (cls == &testpeers[1])) 202 if ((NULL == emsg) && (cls == &testpeers[1]))
202 { 203 {
203 testpeers[1].create_id_op = NULL; 204 testpeers[1].create_id_op = NULL;
204 completed++; 205 completed++;
205 } 206 }
206 if (2 != completed) 207 if (2 != completed)
207 return; 208 return;
208 fprintf(stderr, "Identities created\n"); 209 fprintf (stderr, "Identities created\n");
209 testpeers[0].ego_lookup = GNUNET_IDENTITY_ego_lookup(testpeers[0].cfg, 210 testpeers[0].ego_lookup = GNUNET_IDENTITY_ego_lookup (testpeers[0].cfg,
210 "client", 211 "client",
211 &ego_cb, 212 &ego_cb,
212 &testpeers[0]); 213 &testpeers[0]);
213 testpeers[1].ego_lookup = GNUNET_IDENTITY_ego_lookup(testpeers[1].cfg, 214 testpeers[1].ego_lookup = GNUNET_IDENTITY_ego_lookup (testpeers[1].cfg,
214 "toberevoked", 215 "toberevoked",
215 &ego_cb, 216 &ego_cb,
216 &testpeers[1]); 217 &testpeers[1]);
217} 218}
218 219
219 220
220static void 221static void
221identity_completion_cb(void *cls, 222identity_completion_cb (void *cls,
222 struct GNUNET_TESTBED_Operation *op, 223 struct GNUNET_TESTBED_Operation *op,
223 void *ca_result, 224 void *ca_result,
224 const char *emsg) 225 const char *emsg)
225{ 226{
226 static int completed = 0; 227 static int completed = 0;
227 228
228 completed++; 229 completed++;
229 if (NUM_TEST_PEERS != completed) 230 if (NUM_TEST_PEERS != completed)
230 return; 231 return;
231 fprintf(stderr, "All peers connected @ IDENTITY ...\n"); 232 fprintf (stderr, "All peers connected @ IDENTITY ...\n");
232 testpeers[0].create_id_op = GNUNET_IDENTITY_create(testpeers[0].idh, 233 testpeers[0].create_id_op = GNUNET_IDENTITY_create (testpeers[0].idh,
233 "client", 234 "client",
234 &identity_create_cb, 235 &identity_create_cb,
235 &testpeers[0]); 236 &testpeers[0]);
236 testpeers[1].create_id_op = GNUNET_IDENTITY_create(testpeers[1].idh, 237 testpeers[1].create_id_op = GNUNET_IDENTITY_create (testpeers[1].idh,
237 "toberevoked", 238 "toberevoked",
238 &identity_create_cb, 239 &identity_create_cb,
239 &testpeers[1]); 240 &testpeers[1]);
240} 241}
241 242
242 243
243static void * 244static void *
244identity_connect_adapter(void *cls, 245identity_connect_adapter (void *cls,
245 const struct GNUNET_CONFIGURATION_Handle *cfg) 246 const struct GNUNET_CONFIGURATION_Handle *cfg)
246{ 247{
247 struct TestPeer *me = cls; 248 struct TestPeer *me = cls;
248 249
249 me->cfg = cfg; 250 me->cfg = cfg;
250 me->idh = GNUNET_IDENTITY_connect(cfg, NULL, NULL); 251 me->idh = GNUNET_IDENTITY_connect (cfg, NULL, NULL);
251 if (NULL == me->idh) 252 if (NULL == me->idh)
252 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to create IDENTITY handle \n"); 253 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create IDENTITY handle \n");
253 return me->idh; 254 return me->idh;
254} 255}
255 256
256 257
257static void 258static void
258identity_disconnect_adapter(void *cls, void *op_result) 259identity_disconnect_adapter (void *cls, void *op_result)
259{ 260{
260 struct TestPeer *me = cls; 261 struct TestPeer *me = cls;
261 262
262 GNUNET_IDENTITY_disconnect(me->idh); 263 GNUNET_IDENTITY_disconnect (me->idh);
263 me->idh = NULL; 264 me->idh = NULL;
264} 265}
265 266
266 267
267static void * 268static void *
268connect_cb(void *cls, 269connect_cb (void *cls,
269 const struct GNUNET_PeerIdentity *peer, 270 const struct GNUNET_PeerIdentity *peer,
270 struct GNUNET_MQ_Handle *mq) 271 struct GNUNET_MQ_Handle *mq)
271{ 272{
272 static int connects = 0; 273 static int connects = 0;
273 274
274 connects++; 275 connects++;
275 if (NUM_TEST_PEERS * NUM_TEST_PEERS == connects) 276 if (NUM_TEST_PEERS * NUM_TEST_PEERS == connects)
276 { 277 {
277 fprintf(stderr, "All peers connected @ CORE ...\n"); 278 fprintf (stderr, "All peers connected @ CORE ...\n");
278 279
279 /* Connect to identity service */ 280 /* Connect to identity service */
280 testpeers[0].identity_op = 281 testpeers[0].identity_op =
281 GNUNET_TESTBED_service_connect(NULL, 282 GNUNET_TESTBED_service_connect (NULL,
282 testpeers[0].p, 283 testpeers[0].p,
283 "identity", 284 "identity",
284 &identity_completion_cb, 285 &identity_completion_cb,
285 NULL, 286 NULL,
286 &identity_connect_adapter, 287 &identity_connect_adapter,
287 &identity_disconnect_adapter, 288 &identity_disconnect_adapter,
288 &testpeers[0]); 289 &testpeers[0]);
289 testpeers[1].identity_op = 290 testpeers[1].identity_op =
290 GNUNET_TESTBED_service_connect(NULL, 291 GNUNET_TESTBED_service_connect (NULL,
291 testpeers[1].p, 292 testpeers[1].p,
292 "identity", 293 "identity",
293 *identity_completion_cb, 294 *identity_completion_cb,
294 NULL, 295 NULL,
295 &identity_connect_adapter, 296 &identity_connect_adapter,
296 &identity_disconnect_adapter, 297 &identity_disconnect_adapter,
297 &testpeers[1]); 298 &testpeers[1]);
298 } 299 }
299 return NULL; 300 return NULL;
300} 301}
301 302
302 303
303static void 304static void
304core_completion_cb(void *cls, 305core_completion_cb (void *cls,
305 struct GNUNET_TESTBED_Operation *op, 306 struct GNUNET_TESTBED_Operation *op,
306 void *ca_result, 307 void *ca_result,
307 const char *emsg) 308 const char *emsg)
308{ 309{
309 static int completed = 0; 310 static int completed = 0;
310 311
311 completed++; 312 completed++;
312 if (NUM_TEST_PEERS == completed) 313 if (NUM_TEST_PEERS == completed)
313 { 314 {
314 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Connected to CORE\n"); 315 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Connected to CORE\n");
315 } 316 }
316} 317}
317 318
318 319
319static void * 320static void *
320core_connect_adapter(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) 321core_connect_adapter (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
321{ 322{
322 struct TestPeer *me = cls; 323 struct TestPeer *me = cls;
323 324
324 me->cfg = cfg; 325 me->cfg = cfg;
325 me->ch = GNUNET_CORE_connect(cfg, me, NULL, &connect_cb, NULL, NULL); 326 me->ch = GNUNET_CORE_connect (cfg, me, NULL, &connect_cb, NULL, NULL);
326 if (NULL == me->ch) 327 if (NULL == me->ch)
327 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to create CORE handle \n"); 328 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create CORE handle \n");
328 return me->ch; 329 return me->ch;
329} 330}
330 331
331 332
332static void 333static void
333core_disconnect_adapter(void *cls, void *op_result) 334core_disconnect_adapter (void *cls, void *op_result)
334{ 335{
335 struct TestPeer *me = cls; 336 struct TestPeer *me = cls;
336 337
337 GNUNET_CORE_disconnect(me->ch); 338 GNUNET_CORE_disconnect (me->ch);
338 me->ch = NULL; 339 me->ch = NULL;
339} 340}
340 341
341 342
342static void 343static void
343test_connection(void *cls, 344test_connection (void *cls,
344 struct GNUNET_TESTBED_RunHandle *h, 345 struct GNUNET_TESTBED_RunHandle *h,
345 unsigned int num_peers, 346 unsigned int num_peers,
346 struct GNUNET_TESTBED_Peer **peers, 347 struct GNUNET_TESTBED_Peer **peers,
347 unsigned int links_succeeded, 348 unsigned int links_succeeded,
348 unsigned int links_failed) 349 unsigned int links_failed)
349{ 350{
350 unsigned int c; 351 unsigned int c;
351 352
352 GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL); 353 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
353 if (NUM_TEST_PEERS != num_peers) 354 if (NUM_TEST_PEERS != num_peers)
354 { 355 {
355 ok = 4; 356 ok = 4;
356 fprintf(stderr, 357 fprintf (stderr,
357 "Only %u out of %u peers were started ...\n", 358 "Only %u out of %u peers were started ...\n",
358 num_peers, 359 num_peers,
359 NUM_TEST_PEERS); 360 NUM_TEST_PEERS);
360 GNUNET_SCHEDULER_shutdown(); 361 GNUNET_SCHEDULER_shutdown ();
361 return; 362 return;
362 } 363 }
363 /* We are generating a CLIQUE */ 364 /* We are generating a CLIQUE */
364 if (NUM_TEST_PEERS * (NUM_TEST_PEERS - 1) == links_succeeded) 365 if (NUM_TEST_PEERS * (NUM_TEST_PEERS - 1) == links_succeeded)
366 {
367 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
368 "Testbed connected peers, initializing test\n");
369 for (c = 0; c < num_peers; c++)
365 { 370 {
366 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 371 testpeers[c].p = peers[c];
367 "Testbed connected peers, initializing test\n"); 372 testpeers[c].core_op =
368 for (c = 0; c < num_peers; c++) 373 GNUNET_TESTBED_service_connect (NULL,
369 { 374 testpeers[c].p,
370 testpeers[c].p = peers[c]; 375 "core",
371 testpeers[c].core_op = 376 &core_completion_cb,
372 GNUNET_TESTBED_service_connect(NULL, 377 NULL,
373 testpeers[c].p, 378 &core_connect_adapter,
374 "core", 379 &core_disconnect_adapter,
375 &core_completion_cb, 380 &testpeers[c]);
376 NULL,
377 &core_connect_adapter,
378 &core_disconnect_adapter,
379 &testpeers[c]);
380 }
381 } 381 }
382 }
382 else 383 else
383 { 384 {
384 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Testbed failed to connect peers\n"); 385 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Testbed failed to connect peers\n");
385 ok = 5; 386 ok = 5;
386 GNUNET_SCHEDULER_shutdown(); 387 GNUNET_SCHEDULER_shutdown ();
387 return; 388 return;
388 } 389 }
389} 390}
390 391
391 392
392int 393int
393main(int argc, char *argv[]) 394main (int argc, char *argv[])
394{ 395{
395 ok = 1; 396 ok = 1;
396 /* Connecting initial topology */ 397 /* Connecting initial topology */
397 (void)GNUNET_TESTBED_test_run("test-revocation", 398 (void) GNUNET_TESTBED_test_run ("test-revocation",
398 "test_revocation.conf", 399 "test_revocation.conf",
399 NUM_TEST_PEERS, 400 NUM_TEST_PEERS,
400 0, 401 0,
401 NULL, 402 NULL,
402 NULL, 403 NULL,
403 &test_connection, 404 &test_connection,
404 NULL); 405 NULL);
405 return ok; 406 return ok;
406} 407}
407 408