2 This file is part of GNUnet.
3 (C) 2009, 2013 Christian Grothoff (and other contributing authors)
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., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
21 * @file dv/test_transport_dv.c
22 * @brief base testcase for testing distance vector transport
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_IDENTITY_Handle *idh;
37 const struct GNUNET_CONFIGURATION_Handle *cfg;
38 const struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey;
39 struct GNUNET_CRYPTO_EcdsaPublicKey pubkey;
40 struct GNUNET_CRYPTO_EcdsaSignature sig;
44 struct TestPeer testpeers[2];
49 * Return value from main, set to 0 on success.
54 do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
57 for (c = 0; c < NUM_TEST_PEERS; c++)
59 GNUNET_TESTBED_operation_done (testpeers[c].identity_op);
60 testpeers[c].identity_op = NULL;
62 GNUNET_SCHEDULER_shutdown ();
67 do_shutdown_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
69 do_shutdown (NULL, NULL);
74 identity_connect_adapter (void *cls,
75 const struct GNUNET_CONFIGURATION_Handle *cfg)
77 struct TestPeer *me = cls;
79 me->idh = GNUNET_IDENTITY_connect(cfg, NULL, NULL);
81 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
82 "Failed to create IDENTITY handle \n");
87 identity_disconnect_adapter (void *cls, void *op_result)
89 struct TestPeer *me = cls;
90 GNUNET_IDENTITY_disconnect(me->idh);
94 static void check_revocation ();
96 static void revocation_remote_cb (void *cls,
99 static int repeat = 0;
100 if (GNUNET_NO == is_valid)
102 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Local revocation successful\n");
103 GNUNET_SCHEDULER_add_now(&do_shutdown, NULL);
105 else if (repeat < 10)
107 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, &check_revocation, NULL);
111 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Flooding of revocation failed\n");
112 GNUNET_SCHEDULER_add_now(&do_shutdown_badly, NULL);
117 static void check_revocation ()
119 GNUNET_REVOCATION_query (testpeers[0].cfg, &testpeers[1].pubkey, &revocation_remote_cb, NULL);
122 static void revocation_cb (void *cls,
125 if (GNUNET_NO == is_valid)
127 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Revocation successful\n");
132 static void ego_cb (void *cls, const struct GNUNET_IDENTITY_Ego *ego)
134 static int completed = 0;
135 if ((NULL != ego) && (cls == &testpeers[0]))
137 testpeers[0].privkey = GNUNET_IDENTITY_ego_get_private_key(ego);
138 GNUNET_IDENTITY_ego_get_public_key(ego, &testpeers[0].pubkey);
141 if ((NULL != ego) && (cls == &testpeers[1]))
143 testpeers[1].privkey = GNUNET_IDENTITY_ego_get_private_key(ego);
144 GNUNET_IDENTITY_ego_get_public_key(ego, &testpeers[1].pubkey);
145 GNUNET_REVOCATION_sign_revocation(testpeers[1].privkey, &testpeers[1].sig);
147 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Calculating proof of work...\n");
148 testpeers[1].pow = 0;
149 int res = GNUNET_REVOCATION_check_pow (&testpeers[1].pubkey, testpeers[1].pow, 5);
150 while (GNUNET_OK != res)
153 res = GNUNET_REVOCATION_check_pow (&testpeers[1].pubkey, testpeers[1].pow, 5);
155 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Done calculating proof of work\n");
160 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Egos retrieved\n");
161 GNUNET_REVOCATION_revoke (testpeers[1].cfg, &testpeers[1].pubkey, &testpeers[1].sig, testpeers[1].pow, revocation_cb, NULL);
165 void identity_create_cb (void *cls, const char *emsg)
167 static int completed = 0;
168 if ((NULL == emsg) && (cls == &testpeers[0]))
172 if ((NULL == emsg) && (cls == &testpeers[1]))
178 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Identities created\n");
179 GNUNET_IDENTITY_ego_lookup (testpeers[0].cfg, "client", ego_cb, &testpeers[0]);
180 GNUNET_IDENTITY_ego_lookup (testpeers[1].cfg, "toberevoked", ego_cb, &testpeers[1]);
186 identity_completion_cb (void *cls, struct GNUNET_TESTBED_Operation *op,
187 void *ca_result, const char *emsg)
189 static int completed = 0;
191 if (NUM_TEST_PEERS == completed)
193 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Connected to identity\n");
194 GNUNET_IDENTITY_create (testpeers[0].idh, "client", identity_create_cb, &testpeers[0]);
195 GNUNET_IDENTITY_create (testpeers[1].idh, "toberevoked", identity_create_cb, &testpeers[1]);
200 test_connection (void *cls,
201 struct GNUNET_TESTBED_RunHandle *h,
202 unsigned int num_peers,
203 struct GNUNET_TESTBED_Peer **peers,
204 unsigned int links_succeeded,
205 unsigned int links_failed)
208 if (NUM_TEST_PEERS != num_peers)
211 fprintf (stderr, "Only %u out of 2 peers were started ...\n",
215 if (0 == links_failed)
217 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Testbed connected peers\n");
218 for (c = 0; c< num_peers; c++)
220 testpeers[c].p = peers[c];
222 /* Connect to identity service */
223 testpeers[c].identity_op = GNUNET_TESTBED_service_connect (NULL, testpeers[c].p,
224 "identity", identity_completion_cb, NULL, &identity_connect_adapter,
225 &identity_disconnect_adapter, &testpeers[c]);
232 main (int argc, char *argv[])
235 /* Connecting initial topology */
236 (void) GNUNET_TESTBED_test_run ("test-revocation",
237 "test_revocation.conf",
240 &test_connection, NULL);
244 /* end of test_transport_dv.c */