aboutsummaryrefslogtreecommitdiff
path: root/src/revocation
diff options
context:
space:
mode:
Diffstat (limited to 'src/revocation')
-rw-r--r--src/revocation/test_revocation.c179
1 files changed, 80 insertions, 99 deletions
diff --git a/src/revocation/test_revocation.c b/src/revocation/test_revocation.c
index e384d309a..22df26165 100644
--- a/src/revocation/test_revocation.c
+++ b/src/revocation/test_revocation.c
@@ -11,7 +11,7 @@
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 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 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/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
@@ -95,15 +95,13 @@ check_revocation (void *cls);
95 95
96 96
97static void 97static void
98revocation_remote_cb (void *cls, 98revocation_remote_cb (void *cls, int is_valid)
99 int is_valid)
100{ 99{
101 static int repeat = 0; 100 static int repeat = 0;
102 101
103 if (GNUNET_NO == is_valid) 102 if (GNUNET_NO == is_valid)
104 { 103 {
105 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 104 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Local revocation successful\n");
106 "Local revocation successful\n");
107 ok = 0; 105 ok = 0;
108 GNUNET_SCHEDULER_shutdown (); 106 GNUNET_SCHEDULER_shutdown ();
109 return; 107 return;
@@ -116,8 +114,7 @@ revocation_remote_cb (void *cls,
116 NULL); 114 NULL);
117 return; 115 return;
118 } 116 }
119 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 117 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Flooding of revocation failed\n");
120 "Flooding of revocation failed\n");
121 ok = 2; 118 ok = 2;
122 GNUNET_SCHEDULER_shutdown (); 119 GNUNET_SCHEDULER_shutdown ();
123} 120}
@@ -128,27 +125,25 @@ check_revocation (void *cls)
128{ 125{
129 GNUNET_REVOCATION_query (testpeers[0].cfg, 126 GNUNET_REVOCATION_query (testpeers[0].cfg,
130 &testpeers[1].pubkey, 127 &testpeers[1].pubkey,
131 &revocation_remote_cb, NULL); 128 &revocation_remote_cb,
129 NULL);
132} 130}
133 131
134 132
135static void 133static void
136revocation_cb (void *cls, 134revocation_cb (void *cls, int is_valid)
137 int is_valid)
138{ 135{
139 testpeers[1].revok_handle = NULL; 136 testpeers[1].revok_handle = NULL;
140 if (GNUNET_NO == is_valid) 137 if (GNUNET_NO == is_valid)
141 { 138 {
142 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 139 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Revocation successful\n");
143 "Revocation successful\n");
144 check_revocation (NULL); 140 check_revocation (NULL);
145 } 141 }
146} 142}
147 143
148 144
149static void 145static void
150ego_cb (void *cls, 146ego_cb (void *cls, const struct GNUNET_IDENTITY_Ego *ego)
151 const struct GNUNET_IDENTITY_Ego *ego)
152{ 147{
153 static int completed = 0; 148 static int completed = 0;
154 149
@@ -166,38 +161,35 @@ ego_cb (void *cls,
166 GNUNET_IDENTITY_ego_get_public_key (ego, &testpeers[1].pubkey); 161 GNUNET_IDENTITY_ego_get_public_key (ego, &testpeers[1].pubkey);
167 GNUNET_REVOCATION_sign_revocation (testpeers[1].privkey, &testpeers[1].sig); 162 GNUNET_REVOCATION_sign_revocation (testpeers[1].privkey, &testpeers[1].sig);
168 163
169 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 164 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Calculating proof of work...\n");
170 "Calculating proof of work...\n");
171 testpeers[1].pow = 0; 165 testpeers[1].pow = 0;
172 int res = GNUNET_REVOCATION_check_pow (&testpeers[1].pubkey, 166 int res =
173 testpeers[1].pow, 5); 167 GNUNET_REVOCATION_check_pow (&testpeers[1].pubkey, testpeers[1].pow, 5);
174 while (GNUNET_OK != res) 168 while (GNUNET_OK != res)
175 { 169 {
176 testpeers[1].pow++; 170 testpeers[1].pow++;
177 res = GNUNET_REVOCATION_check_pow (&testpeers[1].pubkey, 171 res =
178 testpeers[1].pow, 172 GNUNET_REVOCATION_check_pow (&testpeers[1].pubkey, testpeers[1].pow, 5);
179 5);
180 } 173 }
181 fprintf (stderr, 174 fprintf (stderr, "Done calculating proof of work\n");
182 "Done calculating proof of work\n");
183 completed++; 175 completed++;
184 } 176 }
185 if (2 == completed) 177 if (2 == completed)
186 { 178 {
187 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 179 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Egos retrieved\n");
188 "Egos retrieved\n"); 180 testpeers[1].revok_handle = GNUNET_REVOCATION_revoke (testpeers[1].cfg,
189 testpeers[1].revok_handle 181 &testpeers[1].pubkey,
190 = GNUNET_REVOCATION_revoke (testpeers[1].cfg, 182 &testpeers[1].sig,
191 &testpeers[1].pubkey, 183 testpeers[1].pow,
192 &testpeers[1].sig, 184 &revocation_cb,
193 testpeers[1].pow, 185 NULL);
194 &revocation_cb, NULL);
195 } 186 }
196} 187}
197 188
198 189
199static void 190static void
200identity_create_cb (void *cls, 191identity_create_cb (void *cls,
192 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk,
201 const char *emsg) 193 const char *emsg)
202{ 194{
203 static int completed = 0; 195 static int completed = 0;
@@ -214,8 +206,7 @@ identity_create_cb (void *cls,
214 } 206 }
215 if (2 != completed) 207 if (2 != completed)
216 return; 208 return;
217 fprintf (stderr, 209 fprintf (stderr, "Identities created\n");
218 "Identities created\n");
219 testpeers[0].ego_lookup = GNUNET_IDENTITY_ego_lookup (testpeers[0].cfg, 210 testpeers[0].ego_lookup = GNUNET_IDENTITY_ego_lookup (testpeers[0].cfg,
220 "client", 211 "client",
221 &ego_cb, 212 &ego_cb,
@@ -238,18 +229,15 @@ identity_completion_cb (void *cls,
238 completed++; 229 completed++;
239 if (NUM_TEST_PEERS != completed) 230 if (NUM_TEST_PEERS != completed)
240 return; 231 return;
241 fprintf (stderr, 232 fprintf (stderr, "All peers connected @ IDENTITY ...\n");
242 "All peers connected @ IDENTITY ...\n"); 233 testpeers[0].create_id_op = GNUNET_IDENTITY_create (testpeers[0].idh,
243 testpeers[0].create_id_op 234 "client",
244 = GNUNET_IDENTITY_create (testpeers[0].idh, 235 &identity_create_cb,
245 "client", 236 &testpeers[0]);
246 &identity_create_cb, 237 testpeers[1].create_id_op = GNUNET_IDENTITY_create (testpeers[1].idh,
247 &testpeers[0]); 238 "toberevoked",
248 testpeers[1].create_id_op 239 &identity_create_cb,
249 = GNUNET_IDENTITY_create (testpeers[1].idh, 240 &testpeers[1]);
250 "toberevoked",
251 &identity_create_cb,
252 &testpeers[1]);
253} 241}
254 242
255 243
@@ -262,15 +250,13 @@ identity_connect_adapter (void *cls,
262 me->cfg = cfg; 250 me->cfg = cfg;
263 me->idh = GNUNET_IDENTITY_connect (cfg, NULL, NULL); 251 me->idh = GNUNET_IDENTITY_connect (cfg, NULL, NULL);
264 if (NULL == me->idh) 252 if (NULL == me->idh)
265 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 253 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create IDENTITY handle \n");
266 "Failed to create IDENTITY handle \n");
267 return me->idh; 254 return me->idh;
268} 255}
269 256
270 257
271static void 258static void
272identity_disconnect_adapter (void *cls, 259identity_disconnect_adapter (void *cls, void *op_result)
273 void *op_result)
274{ 260{
275 struct TestPeer *me = cls; 261 struct TestPeer *me = cls;
276 GNUNET_IDENTITY_disconnect (me->idh); 262 GNUNET_IDENTITY_disconnect (me->idh);
@@ -281,31 +267,34 @@ identity_disconnect_adapter (void *cls,
281static void * 267static void *
282connect_cb (void *cls, 268connect_cb (void *cls,
283 const struct GNUNET_PeerIdentity *peer, 269 const struct GNUNET_PeerIdentity *peer,
284 struct GNUNET_MQ_Handle *mq) 270 struct GNUNET_MQ_Handle *mq)
285{ 271{
286 static int connects = 0; 272 static int connects = 0;
287 273
288 connects++; 274 connects++;
289 if (NUM_TEST_PEERS * NUM_TEST_PEERS == connects) 275 if (NUM_TEST_PEERS * NUM_TEST_PEERS == connects)
290 { 276 {
291 fprintf (stderr, 277 fprintf (stderr, "All peers connected @ CORE ...\n");
292 "All peers connected @ CORE ...\n");
293 278
294 /* Connect to identity service */ 279 /* Connect to identity service */
295 testpeers[0].identity_op 280 testpeers[0].identity_op =
296 = GNUNET_TESTBED_service_connect (NULL, 281 GNUNET_TESTBED_service_connect (NULL,
297 testpeers[0].p, "identity", 282 testpeers[0].p,
298 &identity_completion_cb, NULL, 283 "identity",
299 &identity_connect_adapter, 284 &identity_completion_cb,
300 &identity_disconnect_adapter, 285 NULL,
301 &testpeers[0]); 286 &identity_connect_adapter,
302 testpeers[1].identity_op 287 &identity_disconnect_adapter,
303 = GNUNET_TESTBED_service_connect (NULL, 288 &testpeers[0]);
304 testpeers[1].p, "identity", 289 testpeers[1].identity_op =
305 *identity_completion_cb, NULL, 290 GNUNET_TESTBED_service_connect (NULL,
306 &identity_connect_adapter, 291 testpeers[1].p,
307 &identity_disconnect_adapter, 292 "identity",
308 &testpeers[1]); 293 *identity_completion_cb,
294 NULL,
295 &identity_connect_adapter,
296 &identity_disconnect_adapter,
297 &testpeers[1]);
309 } 298 }
310 return NULL; 299 return NULL;
311} 300}
@@ -322,35 +311,26 @@ core_completion_cb (void *cls,
322 completed++; 311 completed++;
323 if (NUM_TEST_PEERS == completed) 312 if (NUM_TEST_PEERS == completed)
324 { 313 {
325 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 314 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Connected to CORE\n");
326 "Connected to CORE\n");
327 } 315 }
328} 316}
329 317
330 318
331static void * 319static void *
332core_connect_adapter (void *cls, 320core_connect_adapter (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
333 const struct GNUNET_CONFIGURATION_Handle *cfg)
334{ 321{
335 struct TestPeer *me = cls; 322 struct TestPeer *me = cls;
336 323
337 me->cfg = cfg; 324 me->cfg = cfg;
338 me->ch = GNUNET_CORE_connect (cfg, 325 me->ch = GNUNET_CORE_connect (cfg, me, NULL, &connect_cb, NULL, NULL);
339 me,
340 NULL,
341 &connect_cb,
342 NULL,
343 NULL);
344 if (NULL == me->ch) 326 if (NULL == me->ch)
345 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 327 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create CORE handle \n");
346 "Failed to create CORE handle \n");
347 return me->ch; 328 return me->ch;
348} 329}
349 330
350 331
351static void 332static void
352core_disconnect_adapter (void *cls, 333core_disconnect_adapter (void *cls, void *op_result)
353 void *op_result)
354{ 334{
355 struct TestPeer *me = cls; 335 struct TestPeer *me = cls;
356 336
@@ -369,8 +349,7 @@ test_connection (void *cls,
369{ 349{
370 unsigned int c; 350 unsigned int c;
371 351
372 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, 352 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
373 NULL);
374 if (NUM_TEST_PEERS != num_peers) 353 if (NUM_TEST_PEERS != num_peers)
375 { 354 {
376 ok = 4; 355 ok = 4;
@@ -381,28 +360,28 @@ test_connection (void *cls,
381 GNUNET_SCHEDULER_shutdown (); 360 GNUNET_SCHEDULER_shutdown ();
382 return; 361 return;
383 } 362 }
384 /* We are generating a CLIQUE */ 363 /* We are generating a CLIQUE */
385 if (NUM_TEST_PEERS * (NUM_TEST_PEERS -1) == links_succeeded) 364 if (NUM_TEST_PEERS * (NUM_TEST_PEERS - 1) == links_succeeded)
386 { 365 {
387 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 366 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
388 "Testbed connected peers, initializing test\n"); 367 "Testbed connected peers, initializing test\n");
389 for (c = 0; c < num_peers; c++) 368 for (c = 0; c < num_peers; c++)
390 { 369 {
391 testpeers[c].p = peers[c]; 370 testpeers[c].p = peers[c];
392 testpeers[c].core_op 371 testpeers[c].core_op =
393 = GNUNET_TESTBED_service_connect (NULL, 372 GNUNET_TESTBED_service_connect (NULL,
394 testpeers[c].p, 373 testpeers[c].p,
395 "core", 374 "core",
396 &core_completion_cb, NULL, 375 &core_completion_cb,
397 &core_connect_adapter, 376 NULL,
398 &core_disconnect_adapter, 377 &core_connect_adapter,
399 &testpeers[c]); 378 &core_disconnect_adapter,
379 &testpeers[c]);
400 } 380 }
401 } 381 }
402 else 382 else
403 { 383 {
404 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 384 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Testbed failed to connect peers\n");
405 "Testbed failed to connect peers\n");
406 ok = 5; 385 ok = 5;
407 GNUNET_SCHEDULER_shutdown (); 386 GNUNET_SCHEDULER_shutdown ();
408 return; 387 return;
@@ -411,16 +390,18 @@ test_connection (void *cls,
411 390
412 391
413int 392int
414main (int argc, 393main (int argc, char *argv[])
415 char *argv[])
416{ 394{
417 ok = 1; 395 ok = 1;
418 /* Connecting initial topology */ 396 /* Connecting initial topology */
419 (void) GNUNET_TESTBED_test_run ("test-revocation", 397 (void) GNUNET_TESTBED_test_run ("test-revocation",
420 "test_revocation.conf", 398 "test_revocation.conf",
421 NUM_TEST_PEERS, 0, 399 NUM_TEST_PEERS,
422 NULL, NULL, 400 0,
423 &test_connection, NULL); 401 NULL,
402 NULL,
403 &test_connection,
404 NULL);
424 return ok; 405 return ok;
425} 406}
426 407