aboutsummaryrefslogtreecommitdiff
path: root/src/integration-tests
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-08-22 07:12:16 +0000
committerChristian Grothoff <christian@grothoff.org>2013-08-22 07:12:16 +0000
commitaa590fa228c0efd30c5d6523bb064b4d4421752e (patch)
treebb488d834fa3dc29d83869bf129e2e238ce49d17 /src/integration-tests
parent98de9a1b4cbdf9f90d81c4278417c2a1e21365ec (diff)
downloadgnunet-aa590fa228c0efd30c5d6523bb064b4d4421752e.tar.gz
gnunet-aa590fa228c0efd30c5d6523bb064b4d4421752e.zip
-code cleanup
Diffstat (limited to 'src/integration-tests')
-rw-r--r--src/integration-tests/connection_watchdog.c201
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;
70static uint64_t statistics_core_neighbour_entries; 67static uint64_t statistics_core_neighbour_entries;
71static uint64_t statistics_core_entries_session_map; 68static uint64_t statistics_core_entries_session_map;
72 69
73int stat_check_running; 70static int stat_check_running;
74 71
75static struct GNUNET_CONTAINER_MultiHashMap *peers; 72static struct GNUNET_CONTAINER_MultiHashMap *peers;
76 73
@@ -116,8 +113,10 @@ struct TransportPlugin
116 int protocol; 113 int protocol;
117}; 114};
118 115
119struct TransportPlugin *phead; 116
120struct TransportPlugin *ptail; 117static struct TransportPlugin *phead;
118static struct TransportPlugin *ptail;
119
121 120
122static int 121static int
123map_check_it (void *cls, 122map_check_it (void *cls,
@@ -202,6 +201,7 @@ map_check (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
202static void 201static void
203stats_check (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); 202stats_check (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
204 203
204
205static int 205static int
206check_lowlevel_connections (int port, int protocol) 206check_lowlevel_connections (int port, int protocol)
207{ 207{
@@ -401,56 +401,59 @@ GNUNET_NETWORK_STRUCT_END
401static size_t 401static size_t
402send_transport_ping_cb (void *cls, size_t size, void *buf) 402send_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
426size_t send_core_ping_cb (void *cls, size_t size, void *buf)
427{
428struct PeerContainer * pc = cls;
429struct PING ping;
430size_t mlen = sizeof (struct PING);
431 426
432if (size < mlen) 427static size_t
428send_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
438GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
439 "Sending core ping to `%s'\n", GNUNET_i2s (&pc->id));
440ping.header.size = htons (mlen);
441ping.header.type = htons (1234);
442ping.src = htons (1);
443
444pc->ch_ping = NULL;
445 433
446memcpy (buf, &ping, mlen); 434 if (size < mlen)
447return 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
451int map_ping_it (void *cls, 453static int
452 const struct GNUNET_HashCode * key, 454map_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 511static size_t
509size_t send_transport_pong_cb (void *cls, size_t size, void *buf) 512send_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
533static size_t 537static size_t
534send_core_pong_cb (void *cls, size_t size, void *buf) 538send_core_pong_cb (void *cls, size_t size, void *buf)
535{ 539{
536struct PeerContainer * pc = cls; 540 struct PeerContainer * pc = cls;
537struct PING ping; 541 struct PING ping;
538size_t mlen = sizeof (struct PING); 542 size_t mlen = sizeof (struct PING);
539 543
540if (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
546GNUNET_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));
548ping.header.size = htons (mlen); 552 ping.header.size = htons (mlen);
549ping.header.type = htons (4321); 553 ping.header.type = htons (4321);
550ping.src = htons (1); 554 ping.src = htons (1);
551 555
552pc->ch_pong = NULL; 556 pc->ch_pong = NULL;
553 557
554memcpy (buf, &ping, mlen); 558 memcpy (buf, &ping, mlen);
555return mlen; 559 return mlen;
556} 560}
557 561
558 562
@@ -737,11 +741,12 @@ map_disconnect (const struct GNUNET_PeerIdentity * peer, void * source)
737static void 741static void
738cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 742cleanup_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
779static void 786static void
780transport_notify_connect_cb (void *cls, 787transport_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 */
796static void 806static void
797transport_notify_disconnect_cb (void *cls, 807transport_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
809static void 820static void
810transport_notify_receive_cb (void *cls, 821transport_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
948static void 958static void
949core_init_cb (void *cls, 959core_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 *