aboutsummaryrefslogtreecommitdiff
path: root/src/dht/test_dht_twopeer_put_get.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-08-15 21:54:06 +0000
committerChristian Grothoff <christian@grothoff.org>2011-08-15 21:54:06 +0000
commit5746309cb4be2073d550ad7a6885e918631dbc38 (patch)
tree89455bc4aadf977816b38df13f990372cd81d71a /src/dht/test_dht_twopeer_put_get.c
parent6fd3e715cae09fa6e657c96f1c6f9711ee51f42f (diff)
downloadgnunet-5746309cb4be2073d550ad7a6885e918631dbc38.tar.gz
gnunet-5746309cb4be2073d550ad7a6885e918631dbc38.zip
indentation
Diffstat (limited to 'src/dht/test_dht_twopeer_put_get.c')
-rw-r--r--src/dht/test_dht_twopeer_put_get.c103
1 files changed, 40 insertions, 63 deletions
diff --git a/src/dht/test_dht_twopeer_put_get.c b/src/dht/test_dht_twopeer_put_get.c
index 9db0ca385..8e77837b2 100644
--- a/src/dht/test_dht_twopeer_put_get.c
+++ b/src/dht/test_dht_twopeer_put_get.c
@@ -210,13 +210,12 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
210 * @param data pointer to the result data 210 * @param data pointer to the result data
211 */ 211 */
212void 212void
213get_result_iterator (void *cls, 213get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp,
214 struct GNUNET_TIME_Absolute exp,
215 const GNUNET_HashCode * key, 214 const GNUNET_HashCode * key,
216 const struct GNUNET_PeerIdentity *const *get_path, 215 const struct GNUNET_PeerIdentity *const *get_path,
217 const struct GNUNET_PeerIdentity *const *put_path, 216 const struct GNUNET_PeerIdentity *const *put_path,
218 enum GNUNET_BLOCK_Type type, 217 enum GNUNET_BLOCK_Type type, size_t size,
219 size_t size, const void *result_data) 218 const void *result_data)
220{ 219{
221 GNUNET_HashCode original_key; /* Key data was stored data under */ 220 GNUNET_HashCode original_key; /* Key data was stored data under */
222 char original_data[4]; /* Made up data that was stored */ 221 char original_data[4]; /* Made up data that was stored */
@@ -273,9 +272,7 @@ do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
273#else 272#else
274 GNUNET_BLOCK_TYPE_TEST, 273 GNUNET_BLOCK_TYPE_TEST,
275#endif 274#endif
276 &key, 275 &key, DEFAULT_GET_REPLICATION, GNUNET_DHT_RO_NONE,
277 DEFAULT_GET_REPLICATION,
278 GNUNET_DHT_RO_NONE,
279 NULL, 0, NULL, 0, &get_result_iterator, NULL); 276 NULL, 0, NULL, 0, &get_result_iterator, NULL);
280} 277}
281 278
@@ -287,9 +284,9 @@ static void
287put_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 284put_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
288{ 285{
289 GNUNET_SCHEDULER_cancel (die_task); 286 GNUNET_SCHEDULER_cancel (die_task);
290 die_task = GNUNET_SCHEDULER_add_delayed (GET_TIMEOUT, 287 die_task =
291 &end_badly, 288 GNUNET_SCHEDULER_add_delayed (GET_TIMEOUT, &end_badly,
292 "waiting for get response (data not found)"); 289 "waiting for get response (data not found)");
293 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 290 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
294 (GNUNET_TIME_UNIT_SECONDS, 10), &do_get, NULL); 291 (GNUNET_TIME_UNIT_SECONDS, 10), &do_get, NULL);
295} 292}
@@ -309,14 +306,10 @@ do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
309 memset (data, 43, sizeof (data)); 306 memset (data, 43, sizeof (data));
310 307
311 /* Insert the data at the first peer */ 308 /* Insert the data at the first peer */
312 GNUNET_DHT_put (peer1dht, 309 GNUNET_DHT_put (peer1dht, &key, DEFAULT_PUT_REPLICATION, GNUNET_DHT_RO_NONE,
313 &key, 310 GNUNET_BLOCK_TYPE_TEST, sizeof (data), data,
314 DEFAULT_PUT_REPLICATION, 311 GNUNET_TIME_UNIT_FOREVER_ABS, GNUNET_TIME_UNIT_FOREVER_REL,
315 GNUNET_DHT_RO_NONE, 312 &put_finished, NULL);
316 GNUNET_BLOCK_TYPE_TEST,
317 sizeof (data), data,
318 GNUNET_TIME_UNIT_FOREVER_ABS,
319 GNUNET_TIME_UNIT_FOREVER_REL, &put_finished, NULL);
320} 313}
321#else 314#else
322 315
@@ -353,24 +346,19 @@ do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
353 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS); 346 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS);
354 347
355 /* Sign the block */ 348 /* Sign the block */
356 if (GNUNET_OK != GNUNET_CRYPTO_rsa_sign (my_private_key, 349 if (GNUNET_OK !=
357 &data.purpose, &data.signature)) 350 GNUNET_CRYPTO_rsa_sign (my_private_key, &data.purpose, &data.signature))
358 { 351 {
359 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "could not sign DNS_Record\n"); 352 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "could not sign DNS_Record\n");
360 return; 353 return;
361 } 354 }
362 GNUNET_CRYPTO_rsa_key_free (my_private_key); 355 GNUNET_CRYPTO_rsa_key_free (my_private_key);
363 356
364 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 357 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Putting with key %08x\n",
365 "Putting with key %08x\n",
366 *((unsigned int *) &data.service_descriptor)); 358 *((unsigned int *) &data.service_descriptor));
367 359
368 GNUNET_DHT_put (peer1dht, 360 GNUNET_DHT_put (peer1dht, &data.service_descriptor, DEFAULT_PUT_REPLICATION,
369 &data.service_descriptor, 361 GNUNET_DHT_RO_NONE, GNUNET_BLOCK_TYPE_DNS, size,
370 DEFAULT_PUT_REPLICATION,
371 GNUNET_DHT_RO_NONE,
372 GNUNET_BLOCK_TYPE_DNS,
373 size,
374 (char *) &data, 362 (char *) &data,
375 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS), 363 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS),
376 GNUNET_TIME_UNIT_MINUTES, &put_finished, NULL); 364 GNUNET_TIME_UNIT_MINUTES, &put_finished, NULL);
@@ -387,10 +375,8 @@ do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
387 * failure (peers failed to connect). 375 * failure (peers failed to connect).
388 */ 376 */
389void 377void
390topology_callback (void *cls, 378topology_callback (void *cls, const struct GNUNET_PeerIdentity *first,
391 const struct GNUNET_PeerIdentity *first, 379 const struct GNUNET_PeerIdentity *second, uint32_t distance,
392 const struct GNUNET_PeerIdentity *second,
393 uint32_t distance,
394 const struct GNUNET_CONFIGURATION_Handle *first_cfg, 380 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
395 const struct GNUNET_CONFIGURATION_Handle *second_cfg, 381 const struct GNUNET_CONFIGURATION_Handle *second_cfg,
396 struct GNUNET_TESTING_Daemon *first_daemon, 382 struct GNUNET_TESTING_Daemon *first_daemon,
@@ -424,8 +410,8 @@ topology_callback (void *cls,
424 total_connections); 410 total_connections);
425#endif 411#endif
426 GNUNET_SCHEDULER_cancel (die_task); 412 GNUNET_SCHEDULER_cancel (die_task);
427 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 413 die_task =
428 &end_badly, "from test gets"); 414 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, "from test gets");
429 415
430 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 416 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
431 (GNUNET_TIME_UNIT_SECONDS, 2), &do_put, NULL); 417 (GNUNET_TIME_UNIT_SECONDS, 2), &do_put, NULL);
@@ -452,8 +438,7 @@ topology_callback (void *cls,
452 * @param emsg NULL if peer started, non-NULL on error 438 * @param emsg NULL if peer started, non-NULL on error
453 */ 439 */
454static void 440static void
455peers_started_callback (void *cls, 441peers_started_callback (void *cls, const struct GNUNET_PeerIdentity *id,
456 const struct GNUNET_PeerIdentity *id,
457 const struct GNUNET_CONFIGURATION_Handle *cfg, 442 const struct GNUNET_CONFIGURATION_Handle *cfg,
458 struct GNUNET_TESTING_Daemon *d, const char *emsg) 443 struct GNUNET_TESTING_Daemon *d, const char *emsg)
459{ 444{
@@ -500,12 +485,10 @@ peers_started_callback (void *cls,
500 if ((pg != NULL)) /* Sanity check */ 485 if ((pg != NULL)) /* Sanity check */
501 { 486 {
502 /* Connect peers in a "straight line" topology, return the number of expected connections */ 487 /* Connect peers in a "straight line" topology, return the number of expected connections */
503 expected_connections = GNUNET_TESTING_connect_topology (pg, 488 expected_connections =
504 GNUNET_TESTING_TOPOLOGY_LINE, 489 GNUNET_TESTING_connect_topology (pg, GNUNET_TESTING_TOPOLOGY_LINE,
505 GNUNET_TESTING_TOPOLOGY_OPTION_ALL, 490 GNUNET_TESTING_TOPOLOGY_OPTION_ALL,
506 0.0, 491 0.0, TIMEOUT, 12, NULL, NULL);
507 TIMEOUT,
508 12, NULL, NULL);
509 } 492 }
510 493
511 /* Cancel current timeout fail task */ 494 /* Cancel current timeout fail task */
@@ -516,17 +499,16 @@ peers_started_callback (void *cls,
516 "from connect topology (bad return)"); 499 "from connect topology (bad return)");
517 500
518 /* Schedule timeout on failure task */ 501 /* Schedule timeout on failure task */
519 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 502 die_task =
520 &end_badly, 503 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly,
521 "from connect topology (timeout)"); 504 "from connect topology (timeout)");
522 ok = 0; 505 ok = 0;
523 } 506 }
524} 507}
525 508
526static void 509static void
527run (void *cls, 510run (void *cls, char *const *args, const char *cfgfile,
528 char *const *args, 511 const struct GNUNET_CONFIGURATION_Handle *cfg)
529 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
530{ 512{
531 513
532 /* Get path from configuration file */ 514 /* Get path from configuration file */
@@ -548,21 +530,15 @@ run (void *cls,
548 peers_left = num_peers; 530 peers_left = num_peers;
549 531
550 /* Set up a task to end testing if peer start fails */ 532 /* Set up a task to end testing if peer start fails */
551 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 533 die_task =
552 &end_badly, 534 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly,
553 "didn't start all daemons in reasonable amount of time!!!"); 535 "didn't start all daemons in reasonable amount of time!!!");
554 536
555 /* Start num_peers peers, call peers_started_callback on peer start, topology_callback on peer connect */ 537 /* Start num_peers peers, call peers_started_callback on peer start, topology_callback on peer connect */
556 /* Read the API documentation for other parameters! */ 538 /* Read the API documentation for other parameters! */
557 pg = GNUNET_TESTING_daemons_start (cfg, 539 pg = GNUNET_TESTING_daemons_start (cfg, num_peers, 2, 2, TIMEOUT, NULL, NULL,
558 num_peers, 540 &peers_started_callback, NULL,
559 2, 541 &topology_callback, NULL, NULL);
560 2,
561 TIMEOUT,
562 NULL,
563 NULL,
564 &peers_started_callback,
565 NULL, &topology_callback, NULL, NULL);
566 542
567} 543}
568 544
@@ -584,9 +560,10 @@ check ()
584 GNUNET_GETOPT_OPTION_END 560 GNUNET_GETOPT_OPTION_END
585 }; 561 };
586 /* Run the run function as a new program */ 562 /* Run the run function as a new program */
587 ret = GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 563 ret =
588 argv, "test-dht-twopeer-put-get", "nohelp", 564 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
589 options, &run, &ok); 565 "test-dht-twopeer-put-get", "nohelp", options, &run,
566 &ok);
590 if (ret != GNUNET_OK) 567 if (ret != GNUNET_OK)
591 { 568 {
592 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 569 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,