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 it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your 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 Affero General Public License for more details.
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/>.
19 * @file revocation/test_revocation.c
20 * @brief base testcase for revocation exchange
21 * @author Matthias Wachs
22 * @author Christian Grothoff
25 #include "gnunet_core_service.h"
26 #include "gnunet_identity_service.h"
27 #include "gnunet_revocation_service.h"
28 #include "gnunet_testbed_service.h"
30 #define NUM_TEST_PEERS 2
34 struct GNUNET_TESTBED_Peer *p;
35 struct GNUNET_TESTBED_Operation *identity_op;
36 struct GNUNET_TESTBED_Operation *core_op;
37 struct GNUNET_IDENTITY_Handle *idh;
38 const struct GNUNET_CONFIGURATION_Handle *cfg;
39 const struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey;
40 struct GNUNET_CRYPTO_EcdsaPublicKey pubkey;
41 struct GNUNET_CRYPTO_EcdsaSignature sig;
42 struct GNUNET_IDENTITY_Operation *create_id_op;
43 struct GNUNET_IDENTITY_EgoLookup *ego_lookup;
44 struct GNUNET_REVOCATION_Handle *revok_handle;
45 struct GNUNET_CORE_Handle *ch;
49 static struct TestPeer testpeers[2];
52 * Return value from main, set to 0 on success.
58 do_shutdown (void *cls)
60 for (unsigned int c = 0; c < NUM_TEST_PEERS; c++)
62 if (NULL != testpeers[c].create_id_op)
64 GNUNET_IDENTITY_cancel (testpeers[c].create_id_op);
65 testpeers[c].create_id_op = NULL;
67 if (NULL != testpeers[c].ego_lookup)
69 GNUNET_IDENTITY_ego_lookup_cancel (testpeers[c].ego_lookup);
70 testpeers[c].ego_lookup = NULL;
72 if (NULL != testpeers[c].revok_handle)
74 GNUNET_REVOCATION_revoke_cancel (testpeers[c].revok_handle);
75 testpeers[c].revok_handle = NULL;
77 if (NULL != testpeers[c].identity_op)
79 GNUNET_TESTBED_operation_done (testpeers[c].identity_op);
80 testpeers[c].identity_op = NULL;
82 if (NULL != testpeers[c].core_op)
84 GNUNET_TESTBED_operation_done (testpeers[c].core_op);
85 testpeers[c].core_op = NULL;
92 check_revocation (void *cls);
96 revocation_remote_cb (void *cls,
99 static int repeat = 0;
101 if (GNUNET_NO == is_valid)
103 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
104 "Local revocation successful\n");
106 GNUNET_SCHEDULER_shutdown ();
112 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
117 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
118 "Flooding of revocation failed\n");
120 GNUNET_SCHEDULER_shutdown ();
125 check_revocation (void *cls)
127 GNUNET_REVOCATION_query (testpeers[0].cfg,
128 &testpeers[1].pubkey,
129 &revocation_remote_cb, NULL);
134 revocation_cb (void *cls,
137 testpeers[1].revok_handle = NULL;
138 if (GNUNET_NO == is_valid)
140 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
141 "Revocation successful\n");
142 check_revocation (NULL);
149 const struct GNUNET_IDENTITY_Ego *ego)
151 static int completed = 0;
153 if ((NULL != ego) && (cls == &testpeers[0]))
155 testpeers[0].ego_lookup = NULL;
156 testpeers[0].privkey = GNUNET_IDENTITY_ego_get_private_key (ego);
157 GNUNET_IDENTITY_ego_get_public_key (ego, &testpeers[0].pubkey);
160 if ((NULL != ego) && (cls == &testpeers[1]))
162 testpeers[1].ego_lookup = NULL;
163 testpeers[1].privkey = GNUNET_IDENTITY_ego_get_private_key (ego);
164 GNUNET_IDENTITY_ego_get_public_key (ego, &testpeers[1].pubkey);
165 GNUNET_REVOCATION_sign_revocation (testpeers[1].privkey, &testpeers[1].sig);
167 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
168 "Calculating proof of work...\n");
169 testpeers[1].pow = 0;
170 int res = GNUNET_REVOCATION_check_pow (&testpeers[1].pubkey,
171 testpeers[1].pow, 5);
172 while (GNUNET_OK != res)
175 res = GNUNET_REVOCATION_check_pow (&testpeers[1].pubkey,
180 "Done calculating proof of work\n");
185 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
187 testpeers[1].revok_handle
188 = GNUNET_REVOCATION_revoke (testpeers[1].cfg,
189 &testpeers[1].pubkey,
192 &revocation_cb, NULL);
198 identity_create_cb (void *cls,
201 static int completed = 0;
203 if ((NULL == emsg) && (cls == &testpeers[0]))
205 testpeers[0].create_id_op = NULL;
208 if ((NULL == emsg) && (cls == &testpeers[1]))
210 testpeers[1].create_id_op = NULL;
216 "Identities created\n");
217 testpeers[0].ego_lookup = GNUNET_IDENTITY_ego_lookup (testpeers[0].cfg,
221 testpeers[1].ego_lookup = GNUNET_IDENTITY_ego_lookup (testpeers[1].cfg,
229 identity_completion_cb (void *cls,
230 struct GNUNET_TESTBED_Operation *op,
234 static int completed = 0;
237 if (NUM_TEST_PEERS != completed)
240 "All peers connected @ IDENTITY ...\n");
241 testpeers[0].create_id_op
242 = GNUNET_IDENTITY_create (testpeers[0].idh,
246 testpeers[1].create_id_op
247 = GNUNET_IDENTITY_create (testpeers[1].idh,
255 identity_connect_adapter (void *cls,
256 const struct GNUNET_CONFIGURATION_Handle *cfg)
258 struct TestPeer *me = cls;
261 me->idh = GNUNET_IDENTITY_connect (cfg, NULL, NULL);
263 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
264 "Failed to create IDENTITY handle \n");
270 identity_disconnect_adapter (void *cls,
273 struct TestPeer *me = cls;
274 GNUNET_IDENTITY_disconnect (me->idh);
280 connect_cb (void *cls,
281 const struct GNUNET_PeerIdentity *peer,
282 struct GNUNET_MQ_Handle *mq)
284 static int connects = 0;
287 if (NUM_TEST_PEERS * NUM_TEST_PEERS == connects)
290 "All peers connected @ CORE ...\n");
292 /* Connect to identity service */
293 testpeers[0].identity_op
294 = GNUNET_TESTBED_service_connect (NULL,
295 testpeers[0].p, "identity",
296 &identity_completion_cb, NULL,
297 &identity_connect_adapter,
298 &identity_disconnect_adapter,
300 testpeers[1].identity_op
301 = GNUNET_TESTBED_service_connect (NULL,
302 testpeers[1].p, "identity",
303 *identity_completion_cb, NULL,
304 &identity_connect_adapter,
305 &identity_disconnect_adapter,
313 core_completion_cb (void *cls,
314 struct GNUNET_TESTBED_Operation *op,
318 static int completed = 0;
321 if (NUM_TEST_PEERS == completed)
323 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
324 "Connected to CORE\n");
330 core_connect_adapter (void *cls,
331 const struct GNUNET_CONFIGURATION_Handle *cfg)
333 struct TestPeer *me = cls;
336 me->ch = GNUNET_CORE_connect (cfg,
343 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
344 "Failed to create CORE handle \n");
350 core_disconnect_adapter (void *cls,
353 struct TestPeer *me = cls;
355 GNUNET_CORE_disconnect (me->ch);
361 test_connection (void *cls,
362 struct GNUNET_TESTBED_RunHandle *h,
363 unsigned int num_peers,
364 struct GNUNET_TESTBED_Peer **peers,
365 unsigned int links_succeeded,
366 unsigned int links_failed)
370 GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
372 if (NUM_TEST_PEERS != num_peers)
376 "Only %u out of %u peers were started ...\n",
379 GNUNET_SCHEDULER_shutdown ();
382 /* We are generating a CLIQUE */
383 if (NUM_TEST_PEERS * (NUM_TEST_PEERS -1) == links_succeeded)
385 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
386 "Testbed connected peers, initializing test\n");
387 for (c = 0; c < num_peers; c++)
389 testpeers[c].p = peers[c];
391 = GNUNET_TESTBED_service_connect (NULL,
394 &core_completion_cb, NULL,
395 &core_connect_adapter,
396 &core_disconnect_adapter,
402 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
403 "Testbed failed to connect peers\n");
405 GNUNET_SCHEDULER_shutdown ();
416 /* Connecting initial topology */
417 (void) GNUNET_TESTBED_test_run ("test-revocation",
418 "test_revocation.conf",
421 &test_connection, NULL);
425 /* end of test_revocation.c */