2 This file is part of GNUnet.
3 Copyright (C) 2009, 2013, 2016 GNUnet e.V.
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
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
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 General Public License for more details.
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
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
21 * @file revocation/test_revocation.c
22 * @brief base testcase for revocation exchange
23 * @author Matthias Wachs
24 * @author Christian Grothoff
27 #include "gnunet_core_service.h"
28 #include "gnunet_identity_service.h"
29 #include "gnunet_revocation_service.h"
30 #include "gnunet_testbed_service.h"
32 #define NUM_TEST_PEERS 2
36 struct GNUNET_TESTBED_Peer *p;
37 struct GNUNET_TESTBED_Operation *identity_op;
38 struct GNUNET_TESTBED_Operation *core_op;
39 struct GNUNET_IDENTITY_Handle *idh;
40 const struct GNUNET_CONFIGURATION_Handle *cfg;
41 const struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey;
42 struct GNUNET_CRYPTO_EcdsaPublicKey pubkey;
43 struct GNUNET_CRYPTO_EcdsaSignature sig;
44 struct GNUNET_IDENTITY_Operation *create_id_op;
45 struct GNUNET_IDENTITY_EgoLookup *ego_lookup;
46 struct GNUNET_REVOCATION_Handle *revok_handle;
47 struct GNUNET_CORE_Handle *ch;
51 static struct TestPeer testpeers[2];
54 * Return value from main, set to 0 on success.
60 do_shutdown (void *cls)
64 for (c = 0; c < NUM_TEST_PEERS; c++)
66 if (NULL != testpeers[c].create_id_op)
68 GNUNET_IDENTITY_cancel (testpeers[c].create_id_op);
69 testpeers[c].create_id_op = NULL;
71 if (NULL != testpeers[c].ego_lookup)
73 GNUNET_IDENTITY_ego_lookup_cancel (testpeers[c].ego_lookup);
74 testpeers[c].ego_lookup = NULL;
76 if (NULL != testpeers[c].revok_handle)
78 GNUNET_REVOCATION_revoke_cancel (testpeers[c].revok_handle);
79 testpeers[c].revok_handle = NULL;
81 if (NULL != testpeers[c].identity_op)
83 GNUNET_TESTBED_operation_done (testpeers[c].identity_op);
84 testpeers[c].identity_op = NULL;
86 if (NULL != testpeers[c].core_op)
88 GNUNET_TESTBED_operation_done (testpeers[c].core_op);
89 testpeers[c].core_op = NULL;
96 check_revocation (void *cls);
100 revocation_remote_cb (void *cls,
103 static int repeat = 0;
105 if (GNUNET_NO == is_valid)
108 "Local revocation successful\n");
110 GNUNET_SCHEDULER_shutdown ();
116 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
122 "Flooding of revocation failed\n");
124 GNUNET_SCHEDULER_shutdown ();
129 check_revocation (void *cls)
131 GNUNET_REVOCATION_query (testpeers[0].cfg,
132 &testpeers[1].pubkey,
133 &revocation_remote_cb, NULL);
138 revocation_cb (void *cls,
141 testpeers[1].revok_handle = NULL;
142 if (GNUNET_NO == is_valid)
145 "Revocation successful\n");
146 check_revocation (NULL);
153 const struct GNUNET_IDENTITY_Ego *ego)
155 static int completed = 0;
157 if ((NULL != ego) && (cls == &testpeers[0]))
159 testpeers[0].ego_lookup = NULL;
160 testpeers[0].privkey = GNUNET_IDENTITY_ego_get_private_key (ego);
161 GNUNET_IDENTITY_ego_get_public_key (ego, &testpeers[0].pubkey);
164 if ((NULL != ego) && (cls == &testpeers[1]))
166 testpeers[1].ego_lookup = NULL;
167 testpeers[1].privkey = GNUNET_IDENTITY_ego_get_private_key (ego);
168 GNUNET_IDENTITY_ego_get_public_key (ego, &testpeers[1].pubkey);
169 GNUNET_REVOCATION_sign_revocation (testpeers[1].privkey, &testpeers[1].sig);
171 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
172 "Calculating proof of work...\n");
173 testpeers[1].pow = 0;
174 int res = GNUNET_REVOCATION_check_pow (&testpeers[1].pubkey,
175 testpeers[1].pow, 5);
176 while (GNUNET_OK != res)
179 res = GNUNET_REVOCATION_check_pow (&testpeers[1].pubkey,
184 "Done calculating proof of work\n");
189 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
191 testpeers[1].revok_handle
192 = GNUNET_REVOCATION_revoke (testpeers[1].cfg,
193 &testpeers[1].pubkey,
196 &revocation_cb, NULL);
202 identity_create_cb (void *cls,
205 static int completed = 0;
207 if ((NULL == emsg) && (cls == &testpeers[0]))
209 testpeers[0].create_id_op = NULL;
212 if ((NULL == emsg) && (cls == &testpeers[1]))
214 testpeers[1].create_id_op = NULL;
220 "Identities created\n");
221 testpeers[0].ego_lookup = GNUNET_IDENTITY_ego_lookup (testpeers[0].cfg,
225 testpeers[1].ego_lookup = GNUNET_IDENTITY_ego_lookup (testpeers[1].cfg,
233 identity_completion_cb (void *cls,
234 struct GNUNET_TESTBED_Operation *op,
238 static int completed = 0;
241 if (NUM_TEST_PEERS != completed)
244 "All peers connected @ IDENTITY ...\n");
245 testpeers[0].create_id_op
246 = GNUNET_IDENTITY_create (testpeers[0].idh,
250 testpeers[1].create_id_op
251 = GNUNET_IDENTITY_create (testpeers[1].idh,
259 identity_connect_adapter (void *cls,
260 const struct GNUNET_CONFIGURATION_Handle *cfg)
262 struct TestPeer *me = cls;
265 me->idh = GNUNET_IDENTITY_connect (cfg, NULL, NULL);
267 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
268 "Failed to create IDENTITY handle \n");
274 identity_disconnect_adapter (void *cls,
277 struct TestPeer *me = cls;
278 GNUNET_IDENTITY_disconnect (me->idh);
284 connect_cb (void *cls,
285 const struct GNUNET_PeerIdentity *peer,
286 struct GNUNET_MQ_Handle *mq)
288 static int connects = 0;
291 if (NUM_TEST_PEERS * NUM_TEST_PEERS == connects)
294 "All peers connected @ CORE ...\n");
296 /* Connect to identity service */
297 testpeers[0].identity_op
298 = GNUNET_TESTBED_service_connect (NULL,
299 testpeers[0].p, "identity",
300 &identity_completion_cb, NULL,
301 &identity_connect_adapter,
302 &identity_disconnect_adapter,
304 testpeers[1].identity_op
305 = GNUNET_TESTBED_service_connect (NULL,
306 testpeers[1].p, "identity",
307 *identity_completion_cb, NULL,
308 &identity_connect_adapter,
309 &identity_disconnect_adapter,
317 core_completion_cb (void *cls,
318 struct GNUNET_TESTBED_Operation *op,
322 static int completed = 0;
325 if (NUM_TEST_PEERS == completed)
327 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
328 "Connected to CORE\n");
334 core_connect_adapter (void *cls,
335 const struct GNUNET_CONFIGURATION_Handle *cfg)
337 struct TestPeer *me = cls;
340 me->ch = GNUNET_CORE_connecT (cfg,
347 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
348 "Failed to create CORE handle \n");
354 core_disconnect_adapter (void *cls,
357 struct TestPeer *me = cls;
359 GNUNET_CORE_disconnecT (me->ch);
365 test_connection (void *cls,
366 struct GNUNET_TESTBED_RunHandle *h,
367 unsigned int num_peers,
368 struct GNUNET_TESTBED_Peer **peers,
369 unsigned int links_succeeded,
370 unsigned int links_failed)
374 GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
376 if (NUM_TEST_PEERS != num_peers)
380 "Only %u out of %u peers were started ...\n",
383 GNUNET_SCHEDULER_shutdown ();
386 /* We are generating a CLIQUE */
387 if (NUM_TEST_PEERS * (NUM_TEST_PEERS -1) == links_succeeded)
390 "Testbed connected peers, initializing test\n");
391 for (c = 0; c < num_peers; c++)
393 testpeers[c].p = peers[c];
395 = GNUNET_TESTBED_service_connect (NULL,
398 &core_completion_cb, NULL,
399 &core_connect_adapter,
400 &core_disconnect_adapter,
407 "Testbed failed to connect peers\n");
409 GNUNET_SCHEDULER_shutdown ();
420 /* Connecting initial topology */
421 (void) GNUNET_TESTBED_test_run ("test-revocation",
422 "test_revocation.conf",
425 &test_connection, NULL);
429 /* end of test_revocation.c */