diff options
author | Bart Polot <bart@net.in.tum.de> | 2011-08-22 17:35:24 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2011-08-22 17:35:24 +0000 |
commit | 6aae69bbb5a389a2e47478b46fa1d5620c2cfbcd (patch) | |
tree | 0c5fcbe071884d54d02b149483854152c314845b /src/mesh/test_mesh_small.c | |
parent | f38f964610d4abe9e8b8aa8d20ce5bd6af67da15 (diff) | |
download | gnunet-6aae69bbb5a389a2e47478b46fa1d5620c2cfbcd.tar.gz gnunet-6aae69bbb5a389a2e47478b46fa1d5620c2cfbcd.zip |
Various changes, can't get indent to work
Diffstat (limited to 'src/mesh/test_mesh_small.c')
-rw-r--r-- | src/mesh/test_mesh_small.c | 370 |
1 files changed, 233 insertions, 137 deletions
diff --git a/src/mesh/test_mesh_small.c b/src/mesh/test_mesh_small.c index 0fd6b0813..30b2d8aef 100644 --- a/src/mesh/test_mesh_small.c +++ b/src/mesh/test_mesh_small.c | |||
@@ -24,9 +24,10 @@ | |||
24 | */ | 24 | */ |
25 | #include "platform.h" | 25 | #include "platform.h" |
26 | #include "gnunet_testing_lib.h" | 26 | #include "gnunet_testing_lib.h" |
27 | #include "gnunet_mesh_service.h" | 27 | #include "gnunet_mesh_service_new.h" |
28 | 28 | ||
29 | #define VERBOSE GNUNET_NO | 29 | #define VERBOSE GNUNET_YES |
30 | #define REMOVE_DIR GNUNET_YES | ||
30 | 31 | ||
31 | struct MeshPeer | 32 | struct MeshPeer |
32 | { | 33 | { |
@@ -179,37 +180,105 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
179 | if (data_file != NULL) | 180 | if (data_file != NULL) |
180 | GNUNET_DISK_file_close (data_file); | 181 | GNUNET_DISK_file_close (data_file); |
181 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); | 182 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); |
183 | GNUNET_CONFIGURATION_destroy(testing_cfg); | ||
182 | } | 184 | } |
183 | 185 | ||
184 | 186 | ||
187 | /** | ||
188 | * Handlers, for diverse services | ||
189 | */ | ||
190 | static struct GNUNET_MESH_MessageHandler handlers[] = { | ||
191 | // {&callback, 1, 0}, | ||
192 | {NULL, 0, 0} | ||
193 | }; | ||
194 | |||
195 | |||
196 | /** | ||
197 | * Function called whenever an inbound tunnel is destroyed. Should clean up | ||
198 | * any associated state. | ||
199 | * | ||
200 | * @param cls closure (set from GNUNET_MESH_connect) | ||
201 | * @param tunnel connection to the other end (henceforth invalid) | ||
202 | * @param tunnel_ctx place where local state associated | ||
203 | * with the tunnel is stored | ||
204 | */ | ||
205 | static void | ||
206 | tunnel_cleaner (void *cls, | ||
207 | const struct GNUNET_MESH_Tunnel * tunnel, | ||
208 | void **tunnel_ctx) | ||
209 | { | ||
210 | #if VERBOSE | ||
211 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
212 | "tunnel disconnected\n"); | ||
213 | #endif | ||
214 | return; | ||
215 | } | ||
216 | |||
217 | /** | ||
218 | * Method called whenever a tunnel falls apart. | ||
219 | * | ||
220 | * @param cls closure | ||
221 | * @param peer peer identity the tunnel stopped working with | ||
222 | */ | ||
223 | static void | ||
224 | dh (void *cls, const struct GNUNET_PeerIdentity *peer) | ||
225 | { | ||
226 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
227 | "peer disconnected\n"); | ||
228 | return; | ||
229 | } | ||
230 | |||
231 | |||
232 | /** | ||
233 | * Method called whenever a tunnel is established. | ||
234 | * | ||
235 | * @param cls closure | ||
236 | * @param peer peer identity the tunnel was created to, NULL on timeout | ||
237 | * @param atsi performance data for the connection | ||
238 | */ | ||
239 | static void | ||
240 | ch (void *cls, | ||
241 | const struct GNUNET_PeerIdentity * peer, | ||
242 | const struct GNUNET_TRANSPORT_ATS_Information * atsi) | ||
243 | { | ||
244 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
245 | "peer connected\n"); | ||
246 | return; | ||
247 | } | ||
248 | |||
249 | |||
250 | /** | ||
251 | * connect_mesh_service: connect to the mesh service of one of the peers | ||
252 | * | ||
253 | */ | ||
185 | static void | 254 | static void |
186 | connect_mesh_service (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 255 | connect_mesh_service (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
187 | { | 256 | { |
188 | // struct NSEPeer *current_peer; | 257 | struct GNUNET_TESTING_Daemon *d; |
189 | unsigned int i; | 258 | struct GNUNET_MESH_Handle *h; |
259 | struct GNUNET_MESH_Tunnel *t; | ||
260 | GNUNET_MESH_ApplicationType app; | ||
261 | |||
262 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
263 | "connect_mesh_service\n"); | ||
264 | |||
265 | d = GNUNET_TESTING_daemon_get(pg, 1); | ||
266 | app = (GNUNET_MESH_ApplicationType) 0; | ||
190 | 267 | ||
191 | #if VERBOSE | 268 | #if VERBOSE |
192 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting to mesh service of peers\n"); | 269 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
270 | "connecting to mesh service of peer %s\n", | ||
271 | GNUNET_i2s(&d->id)); | ||
193 | #endif | 272 | #endif |
194 | for (i = 0; i < num_peers; i++) | 273 | h = GNUNET_MESH_connect(d->cfg, NULL, &tunnel_cleaner, handlers, &app); |
195 | { | ||
196 | // if ((connection_limit > 0) && (i % (num_peers / connection_limit) != 0)) | ||
197 | continue; | ||
198 | #if VERBOSE | 274 | #if VERBOSE |
199 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 275 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
200 | "test_mesh_small: connecting to mesh service of peer %d\n", i); | 276 | "connected to mesh service of peer %s\n", |
277 | GNUNET_i2s(&d->id)); | ||
201 | #endif | 278 | #endif |
202 | /* current_peer = GNUNET_malloc(sizeof(struct NSEPeer)); | 279 | t = GNUNET_MESH_tunnel_create(h, &ch, &dh, NULL); |
203 | current_peer->daemon = GNUNET_TESTING_daemon_get(pg, i); | 280 | GNUNET_MESH_tunnel_destroy(t); |
204 | if (GNUNET_YES == GNUNET_TESTING_daemon_running(GNUNET_TESTING_daemon_get(pg, i))) | 281 | GNUNET_MESH_disconnect(h); |
205 | { | ||
206 | current_peer->nse_handle = GNUNET_NSE_connect (current_peer->daemon->cfg, | ||
207 | &handle_estimate, | ||
208 | current_peer); | ||
209 | GNUNET_assert(current_peer->nse_handle != NULL); | ||
210 | } | ||
211 | GNUNET_CONTAINER_DLL_insert (peer_head, peer_tail, current_peer);*/ | ||
212 | } | ||
213 | } | 282 | } |
214 | 283 | ||
215 | 284 | ||
@@ -412,39 +481,46 @@ churn_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
412 | } | 481 | } |
413 | 482 | ||
414 | 483 | ||
484 | /** | ||
485 | * peergroup_ready: start test when all peers are connected | ||
486 | * @param cls closure | ||
487 | * @param emsg error message | ||
488 | */ | ||
415 | static void | 489 | static void |
416 | my_cb (void *cls, const char *emsg) | 490 | peergroup_ready (void *cls, const char *emsg) |
417 | { | 491 | { |
418 | char *buf; | 492 | char *buf; |
419 | int buf_len; | 493 | int buf_len; |
494 | |||
495 | if (emsg != NULL) | ||
496 | { | ||
497 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
498 | "Peergroup callback called with error, aborting test!\n"); | ||
499 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Error from testing: `%s'\n"); | ||
500 | ok = 1; | ||
501 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); | ||
502 | return; | ||
503 | } | ||
420 | 504 | ||
421 | if (emsg != NULL) | ||
422 | { | ||
423 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
424 | "Peergroup callback called with error, aborting test!\n"); | ||
425 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Error from testing: `%s'\n"); | ||
426 | ok = 1; | ||
427 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); | ||
428 | return; | ||
429 | } | ||
430 | #if VERBOSE | 505 | #if VERBOSE |
431 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer Group started successfully!\n"); | 506 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer Group started successfully!\n"); |
432 | #endif | 507 | #endif |
433 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Have %u connections\n", | ||
434 | total_connections); | ||
435 | if (data_file != NULL) | ||
436 | { | ||
437 | buf = NULL; | ||
438 | buf_len = GNUNET_asprintf (&buf, "CONNECTIONS_0: %u\n", total_connections); | ||
439 | if (buf_len > 0) | ||
440 | GNUNET_DISK_file_write (data_file, buf, buf_len); | ||
441 | GNUNET_free (buf); | ||
442 | } | ||
443 | peers_running = GNUNET_TESTING_daemons_running (pg); | ||
444 | 508 | ||
445 | GNUNET_SCHEDULER_add_now (&connect_mesh_service, NULL); | 509 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Have %u connections\n", |
446 | disconnect_task = | 510 | total_connections); |
447 | GNUNET_SCHEDULER_add_delayed (wait_time, &disconnect_mesh_peers, NULL); | 511 | if (data_file != NULL) |
512 | { | ||
513 | buf = NULL; | ||
514 | buf_len = GNUNET_asprintf (&buf, "CONNECTIONS_0: %u\n", total_connections); | ||
515 | if (buf_len > 0) | ||
516 | GNUNET_DISK_file_write (data_file, buf, buf_len); | ||
517 | GNUNET_free (buf); | ||
518 | } | ||
519 | peers_running = GNUNET_TESTING_daemons_running (pg); | ||
520 | |||
521 | GNUNET_SCHEDULER_add_now (&connect_mesh_service, NULL); | ||
522 | disconnect_task = | ||
523 | GNUNET_SCHEDULER_add_delayed (wait_time, &disconnect_mesh_peers, NULL); | ||
448 | 524 | ||
449 | } | 525 | } |
450 | 526 | ||
@@ -476,97 +552,121 @@ connect_cb (void *cls, const struct GNUNET_PeerIdentity *first, | |||
476 | } | 552 | } |
477 | 553 | ||
478 | 554 | ||
555 | /** | ||
556 | * run: load configuration options and schedule test to run (start peergroup) | ||
557 | * @param cls closure | ||
558 | * @param args argv | ||
559 | * @param cfgfile configuration file name (can be NULL) | ||
560 | * @param cfg configuration handle | ||
561 | */ | ||
479 | static void | 562 | static void |
480 | run (void *cls, char *const *args, const char *cfgfile, | 563 | run (void *cls, char *const *args, const char *cfgfile, |
481 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 564 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
482 | { | 565 | { |
483 | char *temp_str; | 566 | char *temp_str; |
484 | unsigned long long temp_wait; | 567 | unsigned long long temp_wait; |
485 | struct GNUNET_TESTING_Host *hosts; | 568 | struct GNUNET_TESTING_Host *hosts; |
486 | 569 | ||
487 | ok = 1; | 570 | ok = 1; |
488 | testing_cfg = (struct GNUNET_CONFIGURATION_Handle *) cfg; // GNUNET_CONFIGURATION_create(); | 571 | testing_cfg = GNUNET_CONFIGURATION_dup(cfg); |
572 | |||
573 | GNUNET_log_setup ("test_mesh_small", | ||
489 | #if VERBOSE | 574 | #if VERBOSE |
490 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting daemons.\n"); | 575 | "DEBUG", |
491 | GNUNET_CONFIGURATION_set_value_string (testing_cfg, "testing", | 576 | #else |
492 | "use_progressbars", "YES"); | 577 | "WARNING", |
493 | #endif | 578 | #endif |
494 | if (GNUNET_OK != | 579 | NULL); |
495 | GNUNET_CONFIGURATION_get_value_number (testing_cfg, "testing", | ||
496 | "num_peers", &num_peers)) | ||
497 | { | ||
498 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
499 | "Option TESTING:NUM_PEERS is required!\n"); | ||
500 | return; | ||
501 | } | ||
502 | 580 | ||
503 | if (GNUNET_OK != | 581 | #if VERBOSE |
504 | GNUNET_CONFIGURATION_get_value_number (testing_cfg, "test_mesh_small", | 582 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting daemons.\n"); |
505 | "wait_time", &temp_wait)) | 583 | GNUNET_CONFIGURATION_set_value_string (testing_cfg, "testing", |
506 | { | 584 | "use_progressbars", "YES"); |
507 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 585 | #endif |
508 | "Option nsetest_mesh_small:wait_time is required!\n"); | ||
509 | return; | ||
510 | } | ||
511 | 586 | ||
512 | if (GNUNET_OK != | 587 | if (GNUNET_OK != |
513 | GNUNET_CONFIGURATION_get_value_string (testing_cfg, "testing", | 588 | GNUNET_CONFIGURATION_get_value_number (testing_cfg, "testing", |
514 | "topology_output_file", | 589 | "num_peers", &num_peers)) |
515 | &topology_file)) | 590 | { |
516 | { | 591 | GNUNET_CONFIGURATION_load(testing_cfg, "test_mesh_small.conf"); |
517 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 592 | if (GNUNET_OK != |
518 | "Option test_mesh_small:topology_output_file is required!\n"); | 593 | GNUNET_CONFIGURATION_get_value_number (testing_cfg, "testing", |
519 | return; | 594 | "num_peers", &num_peers)) |
520 | } | 595 | { |
596 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
597 | "Option TESTING:NUM_PEERS is required!\n"); | ||
598 | return; | ||
599 | } | ||
600 | } | ||
521 | 601 | ||
522 | if (GNUNET_OK != | 602 | if (GNUNET_OK != |
523 | GNUNET_CONFIGURATION_get_value_string (testing_cfg, "test_mesh_small", | 603 | GNUNET_CONFIGURATION_get_value_number (testing_cfg, "test_mesh_small", |
524 | "data_output_file", | 604 | "wait_time", &temp_wait)) |
525 | &data_filename)) | 605 | { |
526 | { | 606 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
527 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 607 | "Option nsetest_mesh_small:wait_time is required!\n"); |
528 | "Option test_mesh_small:data_output_file is required!\n"); | 608 | return; |
529 | return; | 609 | } |
530 | } | ||
531 | 610 | ||
532 | data_file = | 611 | if (GNUNET_OK != |
533 | GNUNET_DISK_file_open (data_filename, | 612 | GNUNET_CONFIGURATION_get_value_string (testing_cfg, "testing", |
534 | GNUNET_DISK_OPEN_READWRITE | | 613 | "topology_output_file", |
535 | GNUNET_DISK_OPEN_CREATE, | 614 | &topology_file)) |
536 | GNUNET_DISK_PERM_USER_READ | | 615 | { |
537 | GNUNET_DISK_PERM_USER_WRITE); | 616 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
538 | if (data_file == NULL) | 617 | "Option test_mesh_small:topology_output_file is required!\n"); |
539 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to open %s for output!\n", | 618 | return; |
540 | data_filename); | 619 | } |
541 | GNUNET_free (data_filename); | 620 | |
542 | 621 | if (GNUNET_OK != | |
543 | wait_time = | 622 | GNUNET_CONFIGURATION_get_value_string (testing_cfg, "test_mesh_small", |
544 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, temp_wait); | 623 | "data_output_file", |
545 | 624 | &data_filename)) | |
546 | if (GNUNET_YES == | 625 | { |
547 | GNUNET_CONFIGURATION_get_value_string (cfg, "test_mesh_small", | 626 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
548 | "output_file", &temp_str)) | 627 | "Option test_mesh_small:data_output_file is required!\n"); |
549 | { | 628 | return; |
550 | output_file = | 629 | } |
551 | GNUNET_DISK_file_open (temp_str, | ||
552 | GNUNET_DISK_OPEN_READWRITE | | ||
553 | GNUNET_DISK_OPEN_CREATE, | ||
554 | GNUNET_DISK_PERM_USER_READ | | ||
555 | GNUNET_DISK_PERM_USER_WRITE); | ||
556 | if (output_file == NULL) | ||
557 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to open %s for output!\n", | ||
558 | temp_str); | ||
559 | } | ||
560 | GNUNET_free_non_null (temp_str); | ||
561 | 630 | ||
562 | hosts = GNUNET_TESTING_hosts_load (testing_cfg); | 631 | data_file = GNUNET_DISK_file_open (data_filename, |
632 | GNUNET_DISK_OPEN_READWRITE | | ||
633 | GNUNET_DISK_OPEN_CREATE, | ||
634 | GNUNET_DISK_PERM_USER_READ | | ||
635 | GNUNET_DISK_PERM_USER_WRITE); | ||
636 | if (data_file == NULL) { | ||
637 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
638 | "Failed to open %s for output!\n", | ||
639 | data_filename); | ||
640 | GNUNET_free (data_filename); | ||
641 | } | ||
642 | |||
643 | wait_time = | ||
644 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, temp_wait); | ||
563 | 645 | ||
564 | pg = GNUNET_TESTING_peergroup_start (testing_cfg, num_peers, TIMEOUT, | 646 | if (GNUNET_YES == |
565 | &connect_cb, &my_cb, NULL, hosts); | 647 | GNUNET_CONFIGURATION_get_value_string (cfg, "test_mesh_small", |
566 | GNUNET_assert (pg != NULL); | 648 | "output_file", &temp_str)) |
567 | shutdown_handle = | 649 | { |
568 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_get_forever (), | 650 | output_file = GNUNET_DISK_file_open (temp_str, |
569 | &shutdown_task, NULL); | 651 | GNUNET_DISK_OPEN_READWRITE | |
652 | GNUNET_DISK_OPEN_CREATE, | ||
653 | GNUNET_DISK_PERM_USER_READ | | ||
654 | GNUNET_DISK_PERM_USER_WRITE); | ||
655 | if (output_file == NULL) | ||
656 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
657 | "Failed to open %s for output!\n", | ||
658 | temp_str); | ||
659 | } | ||
660 | GNUNET_free_non_null (temp_str); | ||
661 | |||
662 | hosts = GNUNET_TESTING_hosts_load (testing_cfg); | ||
663 | |||
664 | pg = GNUNET_TESTING_peergroup_start (testing_cfg, num_peers, TIMEOUT, | ||
665 | &connect_cb, &peergroup_ready, NULL, hosts); | ||
666 | GNUNET_assert (pg != NULL); | ||
667 | shutdown_handle = GNUNET_SCHEDULER_add_delayed ( | ||
668 | GNUNET_TIME_relative_get_forever (), | ||
669 | &shutdown_task, NULL); | ||
570 | } | 670 | } |
571 | 671 | ||
572 | 672 | ||
@@ -582,23 +682,19 @@ static struct GNUNET_GETOPT_CommandLineOption options[] = { | |||
582 | }; | 682 | }; |
583 | 683 | ||
584 | 684 | ||
685 | /** | ||
686 | * Main: start test | ||
687 | */ | ||
585 | int | 688 | int |
586 | main (int argc, char *argv[]) | 689 | main (int argc, char *argv[]) |
587 | { | 690 | { |
588 | GNUNET_log_setup ("test_mesh_small", | 691 | GNUNET_PROGRAM_run (argc, argv, "test_mesh_small", |
589 | #if VERBOSE | ||
590 | "DEBUG", | ||
591 | #else | ||
592 | "WARNING", | ||
593 | #endif | ||
594 | NULL); | ||
595 | GNUNET_PROGRAM_run (argc, argv, "test_mesh_small", | ||
596 | gettext_noop ("Test mesh in a small network."), options, | 692 | gettext_noop ("Test mesh in a small network."), options, |
597 | &run, NULL); | 693 | &run, NULL); |
598 | #if REMOVE_DIR | 694 | #if REMOVE_DIR |
599 | GNUNET_DISK_directory_remove ("/tmp/test_mesh_small"); | 695 | GNUNET_DISK_directory_remove ("/tmp/test_mesh_small"); |
600 | #endif | 696 | #endif |
601 | return ok; | 697 | return ok; |
602 | } | 698 | } |
603 | 699 | ||
604 | /* end of test_mesh_small.c */ | 700 | /* end of test_mesh_small.c */ |