diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-08-22 07:12:16 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-08-22 07:12:16 +0000 |
commit | aa590fa228c0efd30c5d6523bb064b4d4421752e (patch) | |
tree | bb488d834fa3dc29d83869bf129e2e238ce49d17 /src/integration-tests | |
parent | 98de9a1b4cbdf9f90d81c4278417c2a1e21365ec (diff) | |
download | gnunet-aa590fa228c0efd30c5d6523bb064b4d4421752e.tar.gz gnunet-aa590fa228c0efd30c5d6523bb064b4d4421752e.zip |
-code cleanup
Diffstat (limited to 'src/integration-tests')
-rw-r--r-- | src/integration-tests/connection_watchdog.c | 201 |
1 files changed, 106 insertions, 95 deletions
diff --git a/src/integration-tests/connection_watchdog.c b/src/integration-tests/connection_watchdog.c index 9e8b3f751..e519f0f82 100644 --- a/src/integration-tests/connection_watchdog.c +++ b/src/integration-tests/connection_watchdog.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | (C) 2009, 2010 Christian Grothoff (and other contributing authors) | 3 | (C) 2009, 2010, 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 |
@@ -27,10 +27,7 @@ | |||
27 | #include "gnunet_constants.h" | 27 | #include "gnunet_constants.h" |
28 | #include "gnunet_arm_service.h" | 28 | #include "gnunet_arm_service.h" |
29 | #include "gnunet_core_service.h" | 29 | #include "gnunet_core_service.h" |
30 | #include "gnunet_getopt_lib.h" | 30 | #include "gnunet_util_lib.h" |
31 | #include "gnunet_os_lib.h" | ||
32 | #include "gnunet_program_lib.h" | ||
33 | #include "gnunet_scheduler_lib.h" | ||
34 | #include "gnunet_transport_service.h" | 31 | #include "gnunet_transport_service.h" |
35 | #include "gnunet_statistics_service.h" | 32 | #include "gnunet_statistics_service.h" |
36 | 33 | ||
@@ -70,7 +67,7 @@ static uint64_t statistics_transport_tcp_connections; | |||
70 | static uint64_t statistics_core_neighbour_entries; | 67 | static uint64_t statistics_core_neighbour_entries; |
71 | static uint64_t statistics_core_entries_session_map; | 68 | static uint64_t statistics_core_entries_session_map; |
72 | 69 | ||
73 | int stat_check_running; | 70 | static int stat_check_running; |
74 | 71 | ||
75 | static struct GNUNET_CONTAINER_MultiHashMap *peers; | 72 | static struct GNUNET_CONTAINER_MultiHashMap *peers; |
76 | 73 | ||
@@ -116,8 +113,10 @@ struct TransportPlugin | |||
116 | int protocol; | 113 | int protocol; |
117 | }; | 114 | }; |
118 | 115 | ||
119 | struct TransportPlugin *phead; | 116 | |
120 | struct TransportPlugin *ptail; | 117 | static struct TransportPlugin *phead; |
118 | static struct TransportPlugin *ptail; | ||
119 | |||
121 | 120 | ||
122 | static int | 121 | static int |
123 | map_check_it (void *cls, | 122 | map_check_it (void *cls, |
@@ -202,6 +201,7 @@ map_check (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
202 | static void | 201 | static void |
203 | stats_check (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | 202 | stats_check (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); |
204 | 203 | ||
204 | |||
205 | static int | 205 | static int |
206 | check_lowlevel_connections (int port, int protocol) | 206 | check_lowlevel_connections (int port, int protocol) |
207 | { | 207 | { |
@@ -401,56 +401,59 @@ GNUNET_NETWORK_STRUCT_END | |||
401 | static size_t | 401 | static size_t |
402 | send_transport_ping_cb (void *cls, size_t size, void *buf) | 402 | send_transport_ping_cb (void *cls, size_t size, void *buf) |
403 | { | 403 | { |
404 | struct PeerContainer * pc = cls; | 404 | struct PeerContainer * pc = cls; |
405 | struct PING ping; | 405 | struct PING ping; |
406 | size_t mlen = sizeof (struct PING); | 406 | size_t mlen = sizeof (struct PING); |
407 | 407 | ||
408 | if (size < mlen) | 408 | if (size < mlen) |
409 | { | 409 | { |
410 | GNUNET_break (0); | 410 | GNUNET_break (0); |
411 | return 0; | 411 | return 0; |
412 | } | 412 | } |
413 | 413 | ||
414 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 414 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
415 | "Sending transport ping to `%s'\n", GNUNET_i2s (&pc->id)); | 415 | "Sending transport ping to `%s'\n", GNUNET_i2s (&pc->id)); |
416 | ping.header.size = htons (mlen); | 416 | ping.header.size = htons (mlen); |
417 | ping.header.type = htons (1234); | 417 | ping.header.type = htons (1234); |
418 | ping.src = htons (0); | 418 | ping.src = htons (0); |
419 | 419 | ||
420 | pc->th_ping = NULL; | 420 | pc->th_ping = NULL; |
421 | 421 | ||
422 | memcpy (buf, &ping, mlen); | 422 | memcpy (buf, &ping, mlen); |
423 | return mlen; | 423 | return mlen; |
424 | } | 424 | } |
425 | 425 | ||
426 | size_t send_core_ping_cb (void *cls, size_t size, void *buf) | ||
427 | { | ||
428 | struct PeerContainer * pc = cls; | ||
429 | struct PING ping; | ||
430 | size_t mlen = sizeof (struct PING); | ||
431 | 426 | ||
432 | if (size < mlen) | 427 | static size_t |
428 | send_core_ping_cb (void *cls, size_t size, void *buf) | ||
433 | { | 429 | { |
434 | GNUNET_break (0); | 430 | struct PeerContainer * pc = cls; |
435 | return 0; | 431 | struct PING ping; |
436 | } | 432 | size_t mlen = sizeof (struct PING); |
437 | |||
438 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
439 | "Sending core ping to `%s'\n", GNUNET_i2s (&pc->id)); | ||
440 | ping.header.size = htons (mlen); | ||
441 | ping.header.type = htons (1234); | ||
442 | ping.src = htons (1); | ||
443 | |||
444 | pc->ch_ping = NULL; | ||
445 | 433 | ||
446 | memcpy (buf, &ping, mlen); | 434 | if (size < mlen) |
447 | return mlen; | 435 | { |
436 | GNUNET_break (0); | ||
437 | return 0; | ||
438 | } | ||
439 | |||
440 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
441 | "Sending core ping to `%s'\n", GNUNET_i2s (&pc->id)); | ||
442 | ping.header.size = htons (mlen); | ||
443 | ping.header.type = htons (1234); | ||
444 | ping.src = htons (1); | ||
445 | |||
446 | pc->ch_ping = NULL; | ||
447 | |||
448 | memcpy (buf, &ping, mlen); | ||
449 | return mlen; | ||
448 | } | 450 | } |
449 | 451 | ||
450 | 452 | ||
451 | int map_ping_it (void *cls, | 453 | static int |
452 | const struct GNUNET_HashCode * key, | 454 | map_ping_it (void *cls, |
453 | void *value) | 455 | const struct GNUNET_HashCode * key, |
456 | void *value) | ||
454 | { | 457 | { |
455 | struct PeerContainer *pc = value; | 458 | struct PeerContainer *pc = value; |
456 | 459 | ||
@@ -505,8 +508,8 @@ stats_check (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
505 | } | 508 | } |
506 | 509 | ||
507 | 510 | ||
508 | 511 | static size_t | |
509 | size_t send_transport_pong_cb (void *cls, size_t size, void *buf) | 512 | send_transport_pong_cb (void *cls, size_t size, void *buf) |
510 | { | 513 | { |
511 | struct PeerContainer * pc = cls; | 514 | struct PeerContainer * pc = cls; |
512 | struct PING ping; | 515 | struct PING ping; |
@@ -530,29 +533,30 @@ size_t send_transport_pong_cb (void *cls, size_t size, void *buf) | |||
530 | return mlen; | 533 | return mlen; |
531 | } | 534 | } |
532 | 535 | ||
536 | |||
533 | static size_t | 537 | static size_t |
534 | send_core_pong_cb (void *cls, size_t size, void *buf) | 538 | send_core_pong_cb (void *cls, size_t size, void *buf) |
535 | { | 539 | { |
536 | struct PeerContainer * pc = cls; | 540 | struct PeerContainer * pc = cls; |
537 | struct PING ping; | 541 | struct PING ping; |
538 | size_t mlen = sizeof (struct PING); | 542 | size_t mlen = sizeof (struct PING); |
539 | 543 | ||
540 | if (size < mlen) | 544 | if (size < mlen) |
541 | { | 545 | { |
542 | GNUNET_break (0); | 546 | GNUNET_break (0); |
543 | return 0; | 547 | return 0; |
544 | } | 548 | } |
545 | 549 | ||
546 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 550 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
547 | "Sending core pong to `%s'\n", GNUNET_i2s (&pc->id)); | 551 | "Sending core pong to `%s'\n", GNUNET_i2s (&pc->id)); |
548 | ping.header.size = htons (mlen); | 552 | ping.header.size = htons (mlen); |
549 | ping.header.type = htons (4321); | 553 | ping.header.type = htons (4321); |
550 | ping.src = htons (1); | 554 | ping.src = htons (1); |
551 | 555 | ||
552 | pc->ch_pong = NULL; | 556 | pc->ch_pong = NULL; |
553 | 557 | ||
554 | memcpy (buf, &ping, mlen); | 558 | memcpy (buf, &ping, mlen); |
555 | return mlen; | 559 | return mlen; |
556 | } | 560 | } |
557 | 561 | ||
558 | 562 | ||
@@ -737,11 +741,12 @@ map_disconnect (const struct GNUNET_PeerIdentity * peer, void * source) | |||
737 | static void | 741 | static void |
738 | cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 742 | cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
739 | { | 743 | { |
740 | struct TransportPlugin * cur = phead; | 744 | struct TransportPlugin *cur; |
741 | 745 | ||
742 | if (NULL != th) | 746 | if (NULL != th) |
743 | { | 747 | { |
744 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Disconnecting from transport service\n"); | 748 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
749 | "Disconnecting from transport service\n"); | ||
745 | GNUNET_TRANSPORT_disconnect (th); | 750 | GNUNET_TRANSPORT_disconnect (th); |
746 | th = NULL; | 751 | th = NULL; |
747 | } | 752 | } |
@@ -749,7 +754,8 @@ cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
749 | 754 | ||
750 | if (NULL != ch) | 755 | if (NULL != ch) |
751 | { | 756 | { |
752 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Disconnecting from core service\n"); | 757 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
758 | "Disconnecting from core service\n"); | ||
753 | GNUNET_CORE_disconnect (ch); | 759 | GNUNET_CORE_disconnect (ch); |
754 | ch = NULL; | 760 | ch = NULL; |
755 | } | 761 | } |
@@ -766,7 +772,7 @@ cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
766 | check_task = GNUNET_SCHEDULER_NO_TASK; | 772 | check_task = GNUNET_SCHEDULER_NO_TASK; |
767 | } | 773 | } |
768 | 774 | ||
769 | for (cur = phead; cur != NULL; cur = phead) | 775 | for (cur = phead; NULL != cur; cur = phead) |
770 | { | 776 | { |
771 | GNUNET_CONTAINER_DLL_remove(phead, ptail, cur); | 777 | GNUNET_CONTAINER_DLL_remove(phead, ptail, cur); |
772 | GNUNET_free (cur->short_name); | 778 | GNUNET_free (cur->short_name); |
@@ -776,16 +782,20 @@ cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
776 | check_task = GNUNET_SCHEDULER_add_now (&map_check, &map_cleanup); | 782 | check_task = GNUNET_SCHEDULER_add_now (&map_check, &map_cleanup); |
777 | } | 783 | } |
778 | 784 | ||
785 | |||
779 | static void | 786 | static void |
780 | transport_notify_connect_cb (void *cls, | 787 | transport_notify_connect_cb (void *cls, |
781 | const struct GNUNET_PeerIdentity* peer) | 788 | const struct GNUNET_PeerIdentity* peer) |
782 | { | 789 | { |
783 | transport_connections ++; | 790 | transport_connections ++; |
784 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "TRANSPORT connect for peer `%s' (%u total)\n", | 791 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
785 | GNUNET_i2s (peer), transport_connections); | 792 | "TRANSPORT connect for peer `%s' (%u total)\n", |
793 | GNUNET_i2s (peer), | ||
794 | transport_connections); | ||
786 | map_connect (peer, th); | 795 | map_connect (peer, th); |
787 | } | 796 | } |
788 | 797 | ||
798 | |||
789 | /** | 799 | /** |
790 | * Function called to notify transport users that another | 800 | * Function called to notify transport users that another |
791 | * peer disconnected from us. | 801 | * peer disconnected from us. |
@@ -795,17 +805,18 @@ transport_notify_connect_cb (void *cls, | |||
795 | */ | 805 | */ |
796 | static void | 806 | static void |
797 | transport_notify_disconnect_cb (void *cls, | 807 | transport_notify_disconnect_cb (void *cls, |
798 | const struct | 808 | const struct GNUNET_PeerIdentity *peer) |
799 | GNUNET_PeerIdentity * peer) | ||
800 | { | 809 | { |
801 | GNUNET_assert (transport_connections > 0); | 810 | GNUNET_assert (transport_connections > 0); |
802 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "TRANSPORT disconnect for peer `%s' (%u total)\n", | 811 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
803 | GNUNET_i2s (peer), transport_connections) ; | 812 | "TRANSPORT disconnect for peer `%s' (%u total)\n", |
813 | GNUNET_i2s (peer), | ||
814 | transport_connections); | ||
804 | map_disconnect (peer, th); | 815 | map_disconnect (peer, th); |
805 | transport_connections --; | 816 | transport_connections --; |
806 | |||
807 | } | 817 | } |
808 | 818 | ||
819 | |||
809 | static void | 820 | static void |
810 | transport_notify_receive_cb (void *cls, | 821 | transport_notify_receive_cb (void *cls, |
811 | const struct | 822 | const struct |
@@ -814,24 +825,23 @@ transport_notify_receive_cb (void *cls, | |||
814 | GNUNET_MessageHeader * | 825 | GNUNET_MessageHeader * |
815 | message) | 826 | message) |
816 | { | 827 | { |
828 | struct PeerContainer *pc; | ||
817 | 829 | ||
818 | 830 | pc = GNUNET_CONTAINER_multihashmap_get (peers, &peer->hashPubKey); | |
819 | struct PeerContainer *pc = NULL; | ||
820 | |||
821 | pc = GNUNET_CONTAINER_multihashmap_get(peers, &peer->hashPubKey); | ||
822 | |||
823 | if (NULL == pc) | 831 | if (NULL == pc) |
824 | { | 832 | { |
825 | GNUNET_break (0); | 833 | GNUNET_break (0); |
826 | return; | 834 | return; |
827 | } | 835 | } |
828 | 836 | ||
829 | if ((message->size == ntohs (sizeof (struct PING))) && (message->type == ntohs (1234))) | 837 | if ((message->size == ntohs (sizeof (struct PING))) && |
838 | (message->type == ntohs (1234))) | ||
830 | { | 839 | { |
831 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Received %s %s from peer `%s'\n", | 840 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
832 | "TRANSPORT", | 841 | "Received %s %s from peer `%s'\n", |
833 | "PING", | 842 | "TRANSPORT", |
834 | GNUNET_i2s (peer)) ; | 843 | "PING", |
844 | GNUNET_i2s (peer)) ; | ||
835 | if (GNUNET_YES == ping) | 845 | if (GNUNET_YES == ping) |
836 | { | 846 | { |
837 | if (NULL == pc->th_pong) | 847 | if (NULL == pc->th_pong) |
@@ -942,9 +952,9 @@ core_disconnect_cb (void *cls, | |||
942 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "CORE disconnect for myself `%s' (%u total)\n", | 952 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "CORE disconnect for myself `%s' (%u total)\n", |
943 | GNUNET_i2s (peer), core_connections); | 953 | GNUNET_i2s (peer), core_connections); |
944 | } | 954 | } |
945 | |||
946 | } | 955 | } |
947 | 956 | ||
957 | |||
948 | static void | 958 | static void |
949 | core_init_cb (void *cls, | 959 | core_init_cb (void *cls, |
950 | const struct GNUNET_PeerIdentity *my_identity) | 960 | const struct GNUNET_PeerIdentity *my_identity) |
@@ -1024,6 +1034,7 @@ init () | |||
1024 | GNUNET_free (plugs); | 1034 | GNUNET_free (plugs); |
1025 | } | 1035 | } |
1026 | 1036 | ||
1037 | |||
1027 | /** | 1038 | /** |
1028 | * Main function that will be run by the scheduler. | 1039 | * Main function that will be run by the scheduler. |
1029 | * | 1040 | * |