aboutsummaryrefslogtreecommitdiff
path: root/src/revocation/test_revocation.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2014-11-30 19:29:54 +0000
committerChristian Grothoff <christian@grothoff.org>2014-11-30 19:29:54 +0000
commit147e93e5a3a8d35748665b6b3adb4ea72988d9c6 (patch)
treeb5e68d42fdad642d7b857d7af693b8234e764fc2 /src/revocation/test_revocation.c
parent9a69e771a2e599e1710e9696fc571a499071a124 (diff)
downloadgnunet-147e93e5a3a8d35748665b6b3adb4ea72988d9c6.tar.gz
gnunet-147e93e5a3a8d35748665b6b3adb4ea72988d9c6.zip
-fix #3510, ensure revocation test times out
Diffstat (limited to 'src/revocation/test_revocation.c')
-rw-r--r--src/revocation/test_revocation.c293
1 files changed, 151 insertions, 142 deletions
diff --git a/src/revocation/test_revocation.c b/src/revocation/test_revocation.c
index f9eadfbb4..d015ed152 100644
--- a/src/revocation/test_revocation.c
+++ b/src/revocation/test_revocation.c
@@ -1,25 +1,27 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 (C) 2009, 2013 Christian Grothoff (and other contributing authors) 3 (C) 2009, 2013 Christian Grothoff (and other contributing authors)
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your 7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version. 8 option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
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 General Public License for more details. 13 General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the 16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19 */ 19*/
20/** 20/**
21 * @file revocation/test_revocation.c 21 * @file revocation/test_revocation.c
22 * @brief base testcase for revocation exchange 22 * @brief base testcase for revocation exchange
23 * @author Matthias Wachs
24 * @author Christian Grothoff
23 */ 25 */
24#include "platform.h" 26#include "platform.h"
25#include "gnunet_core_service.h" 27#include "gnunet_core_service.h"
@@ -48,8 +50,6 @@ struct TestPeer
48 50
49static struct TestPeer testpeers[2]; 51static struct TestPeer testpeers[2];
50 52
51static GNUNET_SCHEDULER_TaskIdentifier die_task;
52
53/** 53/**
54 * Return value from main, set to 0 on success. 54 * Return value from main, set to 0 on success.
55 */ 55 */
@@ -60,13 +60,7 @@ static void
60do_shutdown (void *cls, 60do_shutdown (void *cls,
61 const struct GNUNET_SCHEDULER_TaskContext *tc) 61 const struct GNUNET_SCHEDULER_TaskContext *tc)
62{ 62{
63 int c; 63 unsigned int c;
64
65 if (GNUNET_SCHEDULER_NO_TASK != die_task)
66 {
67 GNUNET_SCHEDULER_cancel (die_task);
68 die_task = GNUNET_SCHEDULER_NO_TASK;
69 }
70 64
71 for (c = 0; c < NUM_TEST_PEERS; c++) 65 for (c = 0; c < NUM_TEST_PEERS; c++)
72 { 66 {
@@ -80,7 +74,6 @@ do_shutdown (void *cls,
80 GNUNET_IDENTITY_ego_lookup_cancel (testpeers[c].ego_lookup); 74 GNUNET_IDENTITY_ego_lookup_cancel (testpeers[c].ego_lookup);
81 testpeers[c].ego_lookup = NULL; 75 testpeers[c].ego_lookup = NULL;
82 } 76 }
83
84 if (NULL != testpeers[c].revok_handle) 77 if (NULL != testpeers[c].revok_handle)
85 { 78 {
86 GNUNET_REVOCATION_revoke_cancel (testpeers[c].revok_handle); 79 GNUNET_REVOCATION_revoke_cancel (testpeers[c].revok_handle);
@@ -97,42 +90,6 @@ do_shutdown (void *cls,
97 testpeers[c].core_op = NULL; 90 testpeers[c].core_op = NULL;
98 } 91 }
99 } 92 }
100 GNUNET_SCHEDULER_shutdown ();
101 ok = 0;
102}
103
104
105static void
106do_shutdown_badly (void *cls,
107 const struct GNUNET_SCHEDULER_TaskContext *tc)
108{
109 if (GNUNET_SCHEDULER_NO_TASK != die_task)
110 die_task = GNUNET_SCHEDULER_NO_TASK;
111 do_shutdown (NULL, NULL );
112 ok = 1;
113}
114
115
116static void *
117identity_connect_adapter (void *cls,
118 const struct GNUNET_CONFIGURATION_Handle *cfg)
119{
120 struct TestPeer *me = cls;
121 me->cfg = cfg;
122 me->idh = GNUNET_IDENTITY_connect (cfg, NULL, NULL );
123 if (NULL == me->idh)
124 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
125 "Failed to create IDENTITY handle \n");
126 return me->idh;
127}
128
129
130static void
131identity_disconnect_adapter (void *cls, void *op_result)
132{
133 struct TestPeer *me = cls;
134 GNUNET_IDENTITY_disconnect (me->idh);
135 me->idh = NULL;
136} 93}
137 94
138 95
@@ -146,30 +103,27 @@ revocation_remote_cb (void *cls,
146 int is_valid) 103 int is_valid)
147{ 104{
148 static int repeat = 0; 105 static int repeat = 0;
106
149 if (GNUNET_NO == is_valid) 107 if (GNUNET_NO == is_valid)
150 { 108 {
151 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 109 fprintf (stderr,
152 "Local revocation successful\n"); 110 "Local revocation successful\n");
153 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL ); 111 ok = 0;
112 GNUNET_SCHEDULER_shutdown ();
113 return;
154 } 114 }
155 else if (repeat < 10) 115 if (repeat < 10)
156 { 116 {
117 repeat++;
157 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 118 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
158 &check_revocation, 119 &check_revocation,
159 NULL ); 120 NULL);
160 } 121 return;
161 else
162 {
163 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
164 "Flooding of revocation failed\n");
165 if (GNUNET_SCHEDULER_NO_TASK != die_task)
166 {
167 GNUNET_SCHEDULER_cancel (die_task);
168 die_task = GNUNET_SCHEDULER_NO_TASK;
169 }
170 GNUNET_SCHEDULER_add_now (&do_shutdown_badly, NULL );
171 } 122 }
172 repeat++; 123 fprintf (stderr,
124 "Flooding of revocation failed\n");
125 ok = 2;
126 GNUNET_SCHEDULER_shutdown ();
173} 127}
174 128
175 129
@@ -190,8 +144,8 @@ revocation_cb (void *cls,
190 testpeers[1].revok_handle = NULL; 144 testpeers[1].revok_handle = NULL;
191 if (GNUNET_NO == is_valid) 145 if (GNUNET_NO == is_valid)
192 { 146 {
193 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 147 fprintf (stderr,
194 "Revocation successful\n"); 148 "Revocation successful\n");
195 check_revocation (NULL, NULL); 149 check_revocation (NULL, NULL);
196 } 150 }
197} 151}
@@ -229,19 +183,20 @@ ego_cb (void *cls,
229 testpeers[1].pow, 183 testpeers[1].pow,
230 5); 184 5);
231 } 185 }
232 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 186 fprintf (stderr,
233 "Done calculating proof of work\n"); 187 "Done calculating proof of work\n");
234 completed++; 188 completed++;
235 } 189 }
236 if (2 == completed) 190 if (2 == completed)
237 { 191 {
238 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 192 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
239 "Egos retrieved\n"); 193 "Egos retrieved\n");
240 testpeers[1].revok_handle = GNUNET_REVOCATION_revoke (testpeers[1].cfg, 194 testpeers[1].revok_handle
241 &testpeers[1].pubkey, 195 = GNUNET_REVOCATION_revoke (testpeers[1].cfg,
242 &testpeers[1].sig, 196 &testpeers[1].pubkey,
243 testpeers[1].pow, 197 &testpeers[1].sig,
244 revocation_cb, NULL); 198 testpeers[1].pow,
199 &revocation_cb, NULL);
245 } 200 }
246} 201}
247 202
@@ -262,19 +217,18 @@ identity_create_cb (void *cls,
262 testpeers[1].create_id_op = NULL; 217 testpeers[1].create_id_op = NULL;
263 completed++; 218 completed++;
264 } 219 }
265 if (2 == completed) 220 if (2 != completed)
266 { 221 return;
267 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 222 fprintf (stderr,
268 "Identities created\n"); 223 "Identities created\n");
269 testpeers[0].ego_lookup = GNUNET_IDENTITY_ego_lookup (testpeers[0].cfg, 224 testpeers[0].ego_lookup = GNUNET_IDENTITY_ego_lookup (testpeers[0].cfg,
270 "client", 225 "client",
271 ego_cb, 226 &ego_cb,
272 &testpeers[0]); 227 &testpeers[0]);
273 testpeers[1].ego_lookup = GNUNET_IDENTITY_ego_lookup (testpeers[1].cfg, 228 testpeers[1].ego_lookup = GNUNET_IDENTITY_ego_lookup (testpeers[1].cfg,
274 "toberevoked", 229 "toberevoked",
275 ego_cb, 230 &ego_cb,
276 &testpeers[1]); 231 &testpeers[1]);
277 }
278} 232}
279 233
280 234
@@ -285,16 +239,46 @@ identity_completion_cb (void *cls,
285 const char *emsg) 239 const char *emsg)
286{ 240{
287 static int completed = 0; 241 static int completed = 0;
242
288 completed++; 243 completed++;
289 if (NUM_TEST_PEERS == completed) 244 if (NUM_TEST_PEERS != completed)
290 { 245 return;
291 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 246 fprintf (stderr,
292 "Connected to identity\n"); 247 "All peers connected @ IDENTITY ...\n");
293 testpeers[0].create_id_op = GNUNET_IDENTITY_create (testpeers[0].idh, 248 testpeers[0].create_id_op
294 "client", identity_create_cb, &testpeers[0]); 249 = GNUNET_IDENTITY_create (testpeers[0].idh,
295 testpeers[1].create_id_op = GNUNET_IDENTITY_create (testpeers[1].idh, 250 "client",
296 "toberevoked", identity_create_cb, &testpeers[1]); 251 &identity_create_cb,
297 } 252 &testpeers[0]);
253 testpeers[1].create_id_op
254 = GNUNET_IDENTITY_create (testpeers[1].idh,
255 "toberevoked",
256 &identity_create_cb,
257 &testpeers[1]);
258}
259
260
261static void *
262identity_connect_adapter (void *cls,
263 const struct GNUNET_CONFIGURATION_Handle *cfg)
264{
265 struct TestPeer *me = cls;
266 me->cfg = cfg;
267 me->idh = GNUNET_IDENTITY_connect (cfg, NULL, NULL );
268 if (NULL == me->idh)
269 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
270 "Failed to create IDENTITY handle \n");
271 return me->idh;
272}
273
274
275static void
276identity_disconnect_adapter (void *cls,
277 void *op_result)
278{
279 struct TestPeer *me = cls;
280 GNUNET_IDENTITY_disconnect (me->idh);
281 me->idh = NULL;
298} 282}
299 283
300 284
@@ -305,20 +289,26 @@ connect_cb (void *cls,
305 static int connects = 0; 289 static int connects = 0;
306 290
307 connects++; 291 connects++;
308 if (4 == connects) 292 if (NUM_TEST_PEERS * NUM_TEST_PEERS == connects)
309 { 293 {
310 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 294 fprintf (stderr,
311 "All peers connected ...\n"); 295 "All peers connected @ CORE ...\n");
312 296
313 /* Connect to identity service */ 297 /* Connect to identity service */
314 testpeers[0].identity_op = GNUNET_TESTBED_service_connect (NULL, 298 testpeers[0].identity_op
315 testpeers[0].p, "identity", identity_completion_cb, NULL, 299 = GNUNET_TESTBED_service_connect (NULL,
316 &identity_connect_adapter, &identity_disconnect_adapter, 300 testpeers[0].p, "identity",
317 &testpeers[0]); 301 &identity_completion_cb, NULL,
318 testpeers[1].identity_op = GNUNET_TESTBED_service_connect (NULL, 302 &identity_connect_adapter,
319 testpeers[1].p, "identity", identity_completion_cb, NULL, 303 &identity_disconnect_adapter,
320 &identity_connect_adapter, &identity_disconnect_adapter, 304 &testpeers[0]);
321 &testpeers[1]); 305 testpeers[1].identity_op
306 = GNUNET_TESTBED_service_connect (NULL,
307 testpeers[1].p, "identity",
308 *identity_completion_cb, NULL,
309 &identity_connect_adapter,
310 &identity_disconnect_adapter,
311 &testpeers[1]);
322 } 312 }
323} 313}
324 314
@@ -330,25 +320,28 @@ core_completion_cb (void *cls,
330 const char *emsg) 320 const char *emsg)
331{ 321{
332 static int completed = 0; 322 static int completed = 0;
323
333 completed++; 324 completed++;
334 if (NUM_TEST_PEERS == completed) 325 if (NUM_TEST_PEERS == completed)
335 { 326 {
336 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 327 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
337 "Connected to CORE\n"); 328 "Connected to CORE\n");
338 } 329 }
339} 330}
340 331
341 332
342static void * 333static void *
343core_connect_adapter (void *cls, 334core_connect_adapter (void *cls,
344 const struct GNUNET_CONFIGURATION_Handle *cfg) 335 const struct GNUNET_CONFIGURATION_Handle *cfg)
345{ 336{
346 struct TestPeer *me = cls; 337 struct TestPeer *me = cls;
338
347 me->cfg = cfg; 339 me->cfg = cfg;
348 me->ch = GNUNET_CORE_connect (cfg, me, NULL, 340 me->ch = GNUNET_CORE_connect (cfg, me, NULL,
349 &connect_cb, NULL, 341 &connect_cb, NULL,
350 NULL, GNUNET_NO, 342 NULL, GNUNET_NO,
351 NULL, GNUNET_NO, NULL); 343 NULL, GNUNET_NO,
344 NULL);
352 if (NULL == me->ch) 345 if (NULL == me->ch)
353 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 346 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
354 "Failed to create CORE handle \n"); 347 "Failed to create CORE handle \n");
@@ -361,6 +354,7 @@ core_disconnect_adapter (void *cls,
361 void *op_result) 354 void *op_result)
362{ 355{
363 struct TestPeer *me = cls; 356 struct TestPeer *me = cls;
357
364 GNUNET_CORE_disconnect (me->ch); 358 GNUNET_CORE_disconnect (me->ch);
365 me->ch = NULL; 359 me->ch = NULL;
366} 360}
@@ -374,45 +368,60 @@ test_connection (void *cls,
374 unsigned int links_succeeded, 368 unsigned int links_succeeded,
375 unsigned int links_failed) 369 unsigned int links_failed)
376{ 370{
377 int c; 371 unsigned int c;
372
373 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
374 &do_shutdown, NULL);
378 375
379 die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
380 &do_shutdown_badly, NULL);
381 if (NUM_TEST_PEERS != num_peers) 376 if (NUM_TEST_PEERS != num_peers)
382 { 377 {
383 ok = 1; 378 ok = 4;
384 fprintf (stderr, 379 fprintf (stderr,
385 "Only %u out of %u peers were started ...\n", 380 "Only %u out of %u peers were started ...\n",
386 num_peers, 381 num_peers,
387 NUM_TEST_PEERS); 382 NUM_TEST_PEERS);
383 GNUNET_SCHEDULER_shutdown ();
384 return;
388 } 385 }
389
390 if (0 == links_failed) 386 if (0 == links_failed)
391 { 387 {
392 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 388 fprintf (stderr,
393 "Testbed connected peers\n"); 389 "Testbed connected peers, initializing test\n");
394 for (c = 0; c < num_peers; c++) 390 for (c = 0; c < num_peers; c++)
395 { 391 {
396 testpeers[c].p = peers[c]; 392 testpeers[c].p = peers[c];
397 393 testpeers[c].core_op
398 testpeers[c].core_op = GNUNET_TESTBED_service_connect (NULL, 394 = GNUNET_TESTBED_service_connect (NULL,
399 testpeers[c].p, "core", &core_completion_cb, NULL, 395 testpeers[c].p,
400 &core_connect_adapter, &core_disconnect_adapter, 396 "core",
401 &testpeers[c]); 397 &core_completion_cb, NULL,
398 &core_connect_adapter,
399 &core_disconnect_adapter,
400 &testpeers[c]);
402 } 401 }
403 } 402 }
403 else
404 {
405 fprintf (stderr,
406 "Testbed failed to connect peers\n");
407 ok = 5;
408 GNUNET_SCHEDULER_shutdown ();
409 return;
410 }
404} 411}
405 412
406 413
407int 414int
408main (int argc, char *argv[]) 415main (int argc,
416 char *argv[])
409{ 417{
410 ok = 1; 418 ok = 1;
411 /* Connecting initial topology */ 419 /* Connecting initial topology */
412 (void) GNUNET_TESTBED_test_run ("test-revocation", 420 (void) GNUNET_TESTBED_test_run ("test-revocation",
413 "test_revocation.conf", 421 "test_revocation.conf",
414 NUM_TEST_PEERS, 0, NULL, NULL, 422 NUM_TEST_PEERS, 0,
415 &test_connection, NULL ); 423 NULL, NULL,
424 &test_connection, NULL);
416 return ok; 425 return ok;
417} 426}
418 427