aboutsummaryrefslogtreecommitdiff
path: root/src/revocation/test_revocation.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2013-11-27 10:43:27 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2013-11-27 10:43:27 +0000
commit794bcbefaf5093869f68e3d22f9502676121d328 (patch)
tree915e50b14b1485ca73957f5539f21b1885548d8e /src/revocation/test_revocation.c
parentbcd4854aff18242d19aab6c07bb432799542a1a9 (diff)
downloadgnunet-794bcbefaf5093869f68e3d22f9502676121d328.tar.gz
gnunet-794bcbefaf5093869f68e3d22f9502676121d328.zip
clean up test
Diffstat (limited to 'src/revocation/test_revocation.c')
-rw-r--r--src/revocation/test_revocation.c223
1 files changed, 136 insertions, 87 deletions
diff --git a/src/revocation/test_revocation.c b/src/revocation/test_revocation.c
index 23c370bbf..a04e1ecd5 100644
--- a/src/revocation/test_revocation.c
+++ b/src/revocation/test_revocation.c
@@ -1,22 +1,22 @@
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 dv/test_transport_dv.c 21 * @file dv/test_transport_dv.c
22 * @brief base testcase for testing distance vector transport 22 * @brief base testcase for testing distance vector transport
@@ -38,12 +38,15 @@ struct TestPeer
38 const struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey; 38 const struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey;
39 struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; 39 struct GNUNET_CRYPTO_EcdsaPublicKey pubkey;
40 struct GNUNET_CRYPTO_EcdsaSignature sig; 40 struct GNUNET_CRYPTO_EcdsaSignature sig;
41 struct GNUNET_IDENTITY_Operation *create_id_op;
42 struct GNUNET_IDENTITY_EgoLookup *ego_lookup;
43 struct GNUNET_REVOCATION_Handle *revok_handle;
41 uint64_t pow; 44 uint64_t pow;
42}; 45};
43 46
44struct TestPeer testpeers[2]; 47static struct TestPeer testpeers[2];
45
46 48
49static GNUNET_SCHEDULER_TaskIdentifier die_task;
47 50
48/** 51/**
49 * Return value from main, set to 0 on success. 52 * Return value from main, set to 0 on success.
@@ -54,10 +57,36 @@ static void
54do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 57do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
55{ 58{
56 int c; 59 int c;
60
61 if (GNUNET_SCHEDULER_NO_TASK != die_task)
62 {
63 GNUNET_SCHEDULER_cancel (die_task);
64 die_task = GNUNET_SCHEDULER_NO_TASK;
65 }
66
57 for (c = 0; c < NUM_TEST_PEERS; c++) 67 for (c = 0; c < NUM_TEST_PEERS; c++)
58 { 68 {
59 GNUNET_TESTBED_operation_done (testpeers[c].identity_op); 69 if (NULL != testpeers[c].create_id_op)
60 testpeers[c].identity_op = NULL; 70 {
71 GNUNET_IDENTITY_cancel (testpeers[c].create_id_op);
72 testpeers[c].create_id_op = NULL;
73 }
74 if (NULL != testpeers[c].ego_lookup)
75 {
76 GNUNET_IDENTITY_ego_lookup_cancel (testpeers[c].ego_lookup);
77 testpeers[c].ego_lookup = NULL;
78 }
79
80 if (NULL != testpeers[c].revok_handle)
81 {
82 GNUNET_REVOCATION_revoke_cancel (testpeers[c].revok_handle);
83 testpeers[c].revok_handle = NULL;
84 }
85 if (NULL != testpeers[c].identity_op)
86 {
87 GNUNET_TESTBED_operation_done (testpeers[c].identity_op);
88 testpeers[c].identity_op = NULL;
89 }
61 } 90 }
62 GNUNET_SCHEDULER_shutdown (); 91 GNUNET_SCHEDULER_shutdown ();
63 ok = 0; 92 ok = 0;
@@ -66,7 +95,9 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
66static void 95static void
67do_shutdown_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 96do_shutdown_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
68{ 97{
69 do_shutdown (NULL, NULL); 98 if (GNUNET_SCHEDULER_NO_TASK != die_task)
99 die_task = GNUNET_SCHEDULER_NO_TASK;
100 do_shutdown (NULL, NULL );
70 ok = 1; 101 ok = 1;
71} 102}
72 103
@@ -76,10 +107,9 @@ identity_connect_adapter (void *cls,
76{ 107{
77 struct TestPeer *me = cls; 108 struct TestPeer *me = cls;
78 me->cfg = cfg; 109 me->cfg = cfg;
79 me->idh = GNUNET_IDENTITY_connect(cfg, NULL, NULL); 110 me->idh = GNUNET_IDENTITY_connect (cfg, NULL, NULL );
80 if (NULL == me->idh) 111 if (NULL == me->idh)
81 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 112 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to create IDENTITY handle \n");
82 "Failed to create IDENTITY handle \n");
83 return me->idh; 113 return me->idh;
84} 114}
85 115
@@ -87,157 +117,176 @@ static void
87identity_disconnect_adapter (void *cls, void *op_result) 117identity_disconnect_adapter (void *cls, void *op_result)
88{ 118{
89 struct TestPeer *me = cls; 119 struct TestPeer *me = cls;
90 GNUNET_IDENTITY_disconnect(me->idh); 120 GNUNET_IDENTITY_disconnect (me->idh);
91 me->idh = NULL; 121 me->idh = NULL;
92} 122}
93 123
94static void check_revocation (); 124static void
125check_revocation ();
95 126
96static void revocation_remote_cb (void *cls, 127static void
97 int is_valid) 128revocation_remote_cb (void *cls, int is_valid)
98{ 129{
99 static int repeat = 0; 130 static int repeat = 0;
100 if (GNUNET_NO == is_valid) 131 if (GNUNET_NO == is_valid)
101 { 132 {
102 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Local revocation successful\n"); 133 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Local revocation successful\n");
103 GNUNET_SCHEDULER_add_now(&do_shutdown, NULL); 134 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL );
104 } 135 }
105 else if (repeat < 10) 136 else if (repeat < 10)
106 { 137 {
107 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, &check_revocation, NULL); 138 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &check_revocation,
139 NULL );
108 } 140 }
109 else 141 else
110 { 142 {
111 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Flooding of revocation failed\n"); 143 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Flooding of revocation failed\n");
112 GNUNET_SCHEDULER_add_now(&do_shutdown_badly, NULL); 144 if (GNUNET_SCHEDULER_NO_TASK != die_task)
145 {
146 GNUNET_SCHEDULER_cancel (die_task);
147 die_task = GNUNET_SCHEDULER_NO_TASK;
148 }
149 GNUNET_SCHEDULER_add_now (&do_shutdown_badly, NULL );
113 } 150 }
114 repeat++; 151 repeat++;
115} 152}
116 153
117static void check_revocation () 154static void
155check_revocation ()
118{ 156{
119 GNUNET_REVOCATION_query (testpeers[0].cfg, &testpeers[1].pubkey, &revocation_remote_cb, NULL); 157 GNUNET_REVOCATION_query (testpeers[0].cfg, &testpeers[1].pubkey,
158 &revocation_remote_cb, NULL );
120} 159}
121 160
122static void revocation_cb (void *cls, 161static void
123 int is_valid) 162revocation_cb (void *cls, int is_valid)
124{ 163{
125 if (GNUNET_NO == is_valid) 164 testpeers[1].revok_handle = NULL;
165 if (GNUNET_NO == is_valid)
126 { 166 {
127 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Revocation successful\n"); 167 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Revocation successful\n");
128 check_revocation(); 168 check_revocation ();
129 } 169 }
130} 170}
131 171
132static void ego_cb (void *cls, const struct GNUNET_IDENTITY_Ego *ego) 172static void
173ego_cb (void *cls, const struct GNUNET_IDENTITY_Ego *ego)
133{ 174{
134 static int completed = 0; 175 static int completed = 0;
135 if ((NULL != ego) && (cls == &testpeers[0])) 176 if ((NULL != ego) && (cls == &testpeers[0]))
136 { 177 {
137 testpeers[0].privkey = GNUNET_IDENTITY_ego_get_private_key(ego); 178 testpeers[0].ego_lookup = NULL;
138 GNUNET_IDENTITY_ego_get_public_key(ego, &testpeers[0].pubkey); 179 testpeers[0].privkey = GNUNET_IDENTITY_ego_get_private_key (ego);
139 completed ++; 180 GNUNET_IDENTITY_ego_get_public_key (ego, &testpeers[0].pubkey);
181 completed++;
140 } 182 }
141 if ((NULL != ego) && (cls == &testpeers[1])) 183 if ((NULL != ego) && (cls == &testpeers[1]))
142 { 184 {
143 testpeers[1].privkey = GNUNET_IDENTITY_ego_get_private_key(ego); 185 testpeers[1].ego_lookup = NULL;
144 GNUNET_IDENTITY_ego_get_public_key(ego, &testpeers[1].pubkey); 186 testpeers[1].privkey = GNUNET_IDENTITY_ego_get_private_key (ego);
145 GNUNET_REVOCATION_sign_revocation(testpeers[1].privkey, &testpeers[1].sig); 187 GNUNET_IDENTITY_ego_get_public_key (ego, &testpeers[1].pubkey);
188 GNUNET_REVOCATION_sign_revocation (testpeers[1].privkey, &testpeers[1].sig);
146 189
147 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Calculating proof of work...\n"); 190 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Calculating proof of work...\n");
148 testpeers[1].pow = 0; 191 testpeers[1].pow = 0;
149 int res = GNUNET_REVOCATION_check_pow (&testpeers[1].pubkey, testpeers[1].pow, 5); 192 int res = GNUNET_REVOCATION_check_pow (&testpeers[1].pubkey,
193 testpeers[1].pow, 5);
150 while (GNUNET_OK != res) 194 while (GNUNET_OK != res)
151 { 195 {
152 testpeers[1].pow++; 196 testpeers[1].pow++;
153 res = GNUNET_REVOCATION_check_pow (&testpeers[1].pubkey, testpeers[1].pow, 5); 197 res = GNUNET_REVOCATION_check_pow (&testpeers[1].pubkey, testpeers[1].pow,
198 5);
154 } 199 }
155 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Done calculating proof of work\n"); 200 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Done calculating proof of work\n");
156 completed ++; 201 completed++;
157 } 202 }
158 if (2 == completed) 203 if (2 == completed)
159 { 204 {
160 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Egos retrieved\n"); 205 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); 206 testpeers[1].revok_handle = GNUNET_REVOCATION_revoke (testpeers[1].cfg,
207 &testpeers[1].pubkey, &testpeers[1].sig, testpeers[1].pow,
208 revocation_cb, NULL );
162 } 209 }
163} 210}
164 211
165void identity_create_cb (void *cls, const char *emsg) 212void
213identity_create_cb (void *cls, const char *emsg)
166{ 214{
167 static int completed = 0; 215 static int completed = 0;
168 if ((NULL == emsg) && (cls == &testpeers[0])) 216 if ((NULL == emsg) && (cls == &testpeers[0]))
169 { 217 {
170 completed ++; 218 testpeers[0].create_id_op = NULL;
219 completed++;
171 } 220 }
172 if ((NULL == emsg) && (cls == &testpeers[1])) 221 if ((NULL == emsg) && (cls == &testpeers[1]))
173 { 222 {
174 completed ++; 223 testpeers[1].create_id_op = NULL;
224 completed++;
175 } 225 }
176 if (2 == completed) 226 if (2 == completed)
177 { 227 {
178 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Identities created\n"); 228 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Identities created\n");
179 GNUNET_IDENTITY_ego_lookup (testpeers[0].cfg, "client", ego_cb, &testpeers[0]); 229 testpeers[0].ego_lookup = GNUNET_IDENTITY_ego_lookup (testpeers[0].cfg,
180 GNUNET_IDENTITY_ego_lookup (testpeers[1].cfg, "toberevoked", ego_cb, &testpeers[1]); 230 "client", ego_cb, &testpeers[0]);
231 testpeers[1].ego_lookup = GNUNET_IDENTITY_ego_lookup (testpeers[1].cfg,
232 "toberevoked", ego_cb, &testpeers[1]);
181 } 233 }
182} 234}
183 235
184
185static void 236static void
186identity_completion_cb (void *cls, struct GNUNET_TESTBED_Operation *op, 237identity_completion_cb (void *cls, struct GNUNET_TESTBED_Operation *op,
187 void *ca_result, const char *emsg) 238 void *ca_result, const char *emsg)
188{ 239{
189 static int completed = 0; 240 static int completed = 0;
190 completed ++; 241 completed++;
191 if (NUM_TEST_PEERS == completed) 242 if (NUM_TEST_PEERS == completed)
192 { 243 {
193 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Connected to identity\n"); 244 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Connected to identity\n");
194 GNUNET_IDENTITY_create (testpeers[0].idh, "client", identity_create_cb, &testpeers[0]); 245 testpeers[0].create_id_op = GNUNET_IDENTITY_create (testpeers[0].idh,
195 GNUNET_IDENTITY_create (testpeers[1].idh, "toberevoked", identity_create_cb, &testpeers[1]); 246 "client", identity_create_cb, &testpeers[0]);
247 testpeers[1].create_id_op = GNUNET_IDENTITY_create (testpeers[1].idh,
248 "toberevoked", identity_create_cb, &testpeers[1]);
196 } 249 }
197} 250}
198 251
199static void 252static void
200test_connection (void *cls, 253test_connection (void *cls, struct GNUNET_TESTBED_RunHandle *h,
201 struct GNUNET_TESTBED_RunHandle *h, 254 unsigned int num_peers, struct GNUNET_TESTBED_Peer **peers,
202 unsigned int num_peers, 255 unsigned int links_succeeded, unsigned int links_failed)
203 struct GNUNET_TESTBED_Peer **peers,
204 unsigned int links_succeeded,
205 unsigned int links_failed)
206{ 256{
207 int c; 257 int c;
258
259 die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
260 &do_shutdown_badly, NULL );
208 if (NUM_TEST_PEERS != num_peers) 261 if (NUM_TEST_PEERS != num_peers)
209 { 262 {
210 ok = 1; 263 ok = 1;
211 fprintf (stderr, "Only %u out of 2 peers were started ...\n", 264 fprintf (stderr, "Only %u out of 2 peers were started ...\n", num_peers);
212 num_peers);
213 } 265 }
214 266
215 if (0 == links_failed) 267 if (0 == links_failed)
216 { 268 {
217 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Testbed connected peers\n"); 269 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Testbed connected peers\n");
218 for (c = 0; c< num_peers; c++) 270 for (c = 0; c < num_peers; c++)
219 { 271 {
220 testpeers[c].p = peers[c]; 272 testpeers[c].p = peers[c];
221 273
222 /* Connect to identity service */ 274 /* Connect to identity service */
223 testpeers[c].identity_op = GNUNET_TESTBED_service_connect (NULL, testpeers[c].p, 275 testpeers[c].identity_op = GNUNET_TESTBED_service_connect (NULL,
224 "identity", identity_completion_cb, NULL, &identity_connect_adapter, 276 testpeers[c].p, "identity", identity_completion_cb, NULL,
225 &identity_disconnect_adapter, &testpeers[c]); 277 &identity_connect_adapter, &identity_disconnect_adapter,
278 &testpeers[c]);
226 } 279 }
227 } 280 }
228} 281}
229 282
230
231int 283int
232main (int argc, char *argv[]) 284main (int argc, char *argv[])
233{ 285{
234 ok = 1; 286 ok = 1;
235 /* Connecting initial topology */ 287 /* Connecting initial topology */
236 (void) GNUNET_TESTBED_test_run ("test-revocation", 288 (void) GNUNET_TESTBED_test_run ("test-revocation", "test_revocation.conf",
237 "test_revocation.conf", 289 NUM_TEST_PEERS, 0, NULL, NULL, &test_connection, NULL );
238 NUM_TEST_PEERS,
239 0, NULL, NULL,
240 &test_connection, NULL);
241 return ok; 290 return ok;
242} 291}
243 292