2 This file is part of GNUnet.
3 (C) 2009, 2010 Christian Grothoff (and other contributing authors)
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
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
21 * @file integration-tests/connection_watchdog.c
22 * @brief tool to monitor core and transport connections for consistency
23 * @author Matthias Wachs
26 #include "gnunet_common.h"
27 #include "gnunet_constants.h"
28 #include "gnunet_arm_service.h"
29 #include "gnunet_core_service.h"
30 #include "gnunet_getopt_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"
35 #include "gnunet_statistics_service.h"
38 #define CHECK_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
39 #define STATS_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
40 #define REPEATED_STATS_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
41 #define STATS_VALUES 4
52 static int have_https;
55 static struct GNUNET_TRANSPORT_Handle *th;
56 static struct GNUNET_CORE_Handle *ch;
57 static struct GNUNET_PeerIdentity my_peer_id;
58 static const struct GNUNET_CONFIGURATION_Handle *mycfg;
59 static struct GNUNET_STATISTICS_Handle *stats;
62 static unsigned int transport_connections;
63 static unsigned int core_connections;
65 static GNUNET_SCHEDULER_TaskIdentifier check_task;
66 static GNUNET_SCHEDULER_TaskIdentifier statistics_task;
68 static uint64_t statistics_transport_connections;
69 static uint64_t statistics_transport_tcp_connections;
70 static uint64_t statistics_core_neighbour_entries;
71 static uint64_t statistics_core_entries_session_map;
73 int stat_check_running;
75 static struct GNUNET_CONTAINER_MultiHashMap *peers;
79 struct GNUNET_PeerIdentity id;
80 int transport_connected;
82 struct GNUNET_TRANSPORT_TransmitHandle *th_ping;
83 struct GNUNET_CORE_TransmitHandle *ch_ping;
85 struct GNUNET_TRANSPORT_TransmitHandle *th_pong;
86 struct GNUNET_CORE_TransmitHandle *ch_pong;
97 struct TransportPlugin
100 * This is a doubly-linked list.
102 struct TransportPlugin *next;
105 * This is a doubly-linked list.
107 struct TransportPlugin *prev;
110 * Short name for the plugin (i.e. "tcp").
119 struct TransportPlugin *phead;
120 struct TransportPlugin *ptail;
122 int map_check_it (void *cls,
123 const GNUNET_HashCode * key,
127 struct PeerContainer *pc = value;
128 if (pc->core_connected != pc->transport_connected)
130 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
131 "Inconsistent peer `%s': TRANSPORT %s <-> CORE %s\n",
132 GNUNET_i2s (&pc->id),
133 (GNUNET_YES == pc->transport_connected) ? "YES" : "NO",
134 (GNUNET_YES == pc->core_connected) ? "YES" : "NO");
142 int map_cleanup_it (void *cls,
143 const GNUNET_HashCode * key,
146 struct PeerContainer *pc = value;
147 GNUNET_CONTAINER_multihashmap_remove(peers, key, value);
148 if (NULL != pc->th_ping)
150 GNUNET_TRANSPORT_notify_transmit_ready_cancel(pc->th_ping);
153 if (NULL != pc->th_pong)
155 GNUNET_TRANSPORT_notify_transmit_ready_cancel(pc->th_pong);
158 if (NULL != pc->ch_ping)
160 GNUNET_CORE_notify_transmit_ready_cancel (pc->ch_ping);
163 if (NULL != pc->ch_pong)
165 GNUNET_CORE_notify_transmit_ready_cancel(pc->ch_pong);
173 map_cleanup (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
175 GNUNET_CONTAINER_multihashmap_iterate (peers, &map_cleanup_it, NULL);
176 GNUNET_CONTAINER_multihashmap_destroy(peers);
180 map_check (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
183 check_task = GNUNET_SCHEDULER_NO_TASK;
184 GNUNET_CONTAINER_multihashmap_iterate (peers, &map_check_it, &fail);
186 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
187 "Inconsistent peers after connection consistency check: %u\n", fail);
189 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
190 "Inconsistent peers after connection consistency check: %u\n", fail);
195 GNUNET_SCHEDULER_add_now (cls, NULL);
201 stats_check (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
204 check_lowlevel_connections (int port, int protocol)
232 GNUNET_asprintf(&cmdline, "netstat -n %s | grep %u", proto, port);
234 if (system ("netstat -n > /dev/null 2> /dev/null"))
235 if (system ("netstat -n > /dev/null 2> /dev/null") == 0)
236 f = popen (cmdline, "r");
240 f = popen (cmdline, "r");
243 GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "ss");
244 GNUNET_free (cmdline);
249 while (NULL != fgets (line, sizeof (line), f))
252 //printf ("%s", line);
256 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%i TCP connections established with port %u\n",
260 GNUNET_free (cmdline);
266 static struct TransportPlugin *
267 find_plugin (char * name)
269 struct TransportPlugin *cur = NULL;
271 for (cur = phead; cur != NULL; cur = phead)
273 if (0 == strcmp(name, cur->short_name))
279 int stats_check_cb (void *cls, const char *subsystem,
280 const char *name, uint64_t value,
291 if ((STATS_VALUES == counter) || ((GNUNET_NO == have_tcp) && (STATS_VALUES - 1 == counter)))
293 int fail = GNUNET_NO;
297 int low_level_connections_udp = check_lowlevel_connections (2086, udp);
299 if (transport_connections != core_connections)
301 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
302 "%u transport notifications <-> %u core notifications\n",
303 transport_connections, core_connections);
307 if (transport_connections != statistics_transport_connections)
309 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
310 "%u transport notifications <-> %u in statistics (peers connected)\n",
311 transport_connections, statistics_transport_connections);
315 if (core_connections != statistics_core_entries_session_map)
317 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
318 "%u core notifications <-> %u in statistics (entries session map)\n",
319 core_connections, statistics_core_entries_session_map);
323 if (core_connections != statistics_core_neighbour_entries)
325 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
326 "%u core notifications <-> %u in statistics (neighbour entries allocated)\n",
327 core_connections, statistics_core_neighbour_entries);
331 if (GNUNET_NO == fail)
332 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
333 "Check successful : (%u transport / %u core) connections established\n", transport_connections, core_connections);
335 /* TCP plugin specific checks */
336 if (GNUNET_YES == have_tcp)
338 struct TransportPlugin * p = find_plugin ("tcp");
339 int low_level_connections_tcp = check_lowlevel_connections (p->port, p->protocol);
341 if (low_level_connections_tcp != -1)
343 if (statistics_transport_tcp_connections > low_level_connections_tcp)
345 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
346 "%u transport tcp sessions <-> %i established tcp connections\n",
347 statistics_transport_tcp_connections, low_level_connections_tcp);
350 else if (low_level_connections_tcp != -1)
352 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
353 "%u TCP connections, %u UDP connections \n",
354 low_level_connections_tcp, low_level_connections_udp);
357 if (transport_connections > statistics_transport_tcp_connections)
359 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
360 "%u transport notifications <-> %u in statistics (statistics_transport_tcp_connections)\n",
361 transport_connections, statistics_transport_tcp_connections);
366 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
367 " %u transport notifications <-> %u in statistics (statistics_transport_tcp_connections)\n",
368 transport_connections, statistics_transport_tcp_connections);
372 if (GNUNET_SCHEDULER_NO_TASK == statistics_task)
373 statistics_task = GNUNET_SCHEDULER_add_delayed(REPEATED_STATS_DELAY, &stats_check, NULL);
375 stat_check_running = GNUNET_NO;
382 GNUNET_NETWORK_STRUCT_BEGIN
386 struct GNUNET_MessageHeader header;
393 struct GNUNET_MessageHeader header;
397 GNUNET_NETWORK_STRUCT_END
400 size_t send_transport_ping_cb (void *cls, size_t size, void *buf)
402 struct PeerContainer * pc = cls;
404 size_t mlen = sizeof (struct PING);
412 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
413 "Sending transport ping to `%s'\n", GNUNET_i2s (&pc->id));
414 ping.header.size = htons (mlen);
415 ping.header.type = htons (1234);
416 ping.src = htons (0);
420 memcpy (buf, &ping, mlen);
424 size_t send_core_ping_cb (void *cls, size_t size, void *buf)
426 struct PeerContainer * pc = cls;
428 size_t mlen = sizeof (struct PING);
436 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
437 "Sending core ping to `%s'\n", GNUNET_i2s (&pc->id));
438 ping.header.size = htons (mlen);
439 ping.header.type = htons (1234);
440 ping.src = htons (1);
444 memcpy (buf, &ping, mlen);
449 int map_ping_it (void *cls,
450 const GNUNET_HashCode * key,
453 struct PeerContainer *pc = value;
455 if ((GNUNET_YES == pc->transport_connected) && (NULL == pc->th_ping))
456 pc->th_ping = GNUNET_TRANSPORT_notify_transmit_ready(th, &pc->id,
457 sizeof (struct PING), UINT_MAX,
458 GNUNET_TIME_relative_get_forever(), &send_transport_ping_cb, pc);
462 if ((GNUNET_YES == pc->core_connected) && (NULL == pc->ch_ping))
463 pc->ch_ping = GNUNET_CORE_notify_transmit_ready(ch,
465 GNUNET_TIME_relative_get_forever(),
467 sizeof (struct PING),
468 send_core_ping_cb, pc);
477 stats_check (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
479 statistics_task = GNUNET_SCHEDULER_NO_TASK;
481 if (GNUNET_YES == stat_check_running)
483 statistics_task = GNUNET_SCHEDULER_add_delayed(STATS_DELAY, &stats_check, NULL);
486 GNUNET_CONTAINER_multihashmap_iterate (peers, &map_ping_it, NULL);
488 stat_check_running = GNUNET_YES;
490 statistics_transport_connections = 0 ;
491 statistics_core_entries_session_map = 0;
492 statistics_core_neighbour_entries = 0;
494 GNUNET_STATISTICS_get (stats, "transport", "# peers connected", GNUNET_TIME_UNIT_MINUTES, NULL, &stats_check_cb, &statistics_transport_connections);
495 GNUNET_STATISTICS_get (stats, "core", "# neighbour entries allocated", GNUNET_TIME_UNIT_MINUTES, NULL, &stats_check_cb, &statistics_core_neighbour_entries);
496 GNUNET_STATISTICS_get (stats, "core", "# entries in session map", GNUNET_TIME_UNIT_MINUTES, NULL, &stats_check_cb, &statistics_core_entries_session_map);
498 /* TCP plugin specific checks */
499 if (GNUNET_YES == have_tcp)
500 GNUNET_STATISTICS_get (stats, "transport", "# TCP sessions active", GNUNET_TIME_UNIT_MINUTES, NULL, &stats_check_cb, &statistics_transport_tcp_connections);
505 size_t send_transport_pong_cb (void *cls, size_t size, void *buf)
507 struct PeerContainer * pc = cls;
509 size_t mlen = sizeof (struct PING);
517 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
518 "Sending transport pong to `%s'\n", GNUNET_i2s (&pc->id));
519 ping.header.size = htons (mlen);
520 ping.header.type = htons (4321);
521 ping.src = htons (0);
525 memcpy (buf, &ping, mlen);
529 size_t send_core_pong_cb (void *cls, size_t size, void *buf)
531 struct PeerContainer * pc = cls;
533 size_t mlen = sizeof (struct PING);
541 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
542 "Sending core pong to `%s'\n", GNUNET_i2s (&pc->id));
543 ping.header.size = htons (mlen);
544 ping.header.type = htons (4321);
545 ping.src = htons (1);
549 memcpy (buf, &ping, mlen);
555 map_connect (const struct GNUNET_PeerIdentity *peer, void * source)
557 struct PeerContainer * pc;
558 if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains(peers, &peer->hashPubKey))
560 pc = GNUNET_malloc (sizeof (struct PeerContainer));
562 pc->core_connected = GNUNET_NO;
563 pc->transport_connected = GNUNET_NO;
564 GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put(peers, &peer->hashPubKey, pc, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
567 pc = GNUNET_CONTAINER_multihashmap_get(peers, &peer->hashPubKey);
570 if (GNUNET_NO == pc->transport_connected)
572 pc->transport_connected = GNUNET_YES;
573 if (GNUNET_YES == ping)
575 if (NULL == pc->th_ping)
576 pc->th_ping = GNUNET_TRANSPORT_notify_transmit_ready(th, peer, sizeof (struct PING), UINT_MAX, GNUNET_TIME_relative_get_forever(), &send_transport_ping_cb, pc);
583 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
584 "%s notified multiple times about for peers `%s' (%s : %s)\n",
586 GNUNET_i2s (&pc->id),
587 "CORE", (pc->core_connected == GNUNET_YES) ? "yes" : "no");
593 if (GNUNET_NO == pc->core_connected)
595 pc->core_connected = GNUNET_YES;
596 if (GNUNET_YES == ping)
598 if (NULL == pc->ch_ping)
599 pc->ch_ping = GNUNET_CORE_notify_transmit_ready(ch,
601 GNUNET_TIME_relative_get_forever(),
603 sizeof (struct PING),
604 send_core_ping_cb, pc);
611 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
612 "%s notified multiple times about for peers `%s' (%s : %s)\n",
614 GNUNET_i2s (&pc->id),
615 "TRANSPORT", (pc->transport_connected == GNUNET_YES) ? "yes" : "no");
619 if (GNUNET_SCHEDULER_NO_TASK != check_task)
620 GNUNET_SCHEDULER_cancel(check_task);
621 check_task = GNUNET_SCHEDULER_add_delayed(CHECK_DELAY, &map_check, NULL);
623 if (GNUNET_SCHEDULER_NO_TASK != statistics_task)
624 GNUNET_SCHEDULER_cancel(statistics_task);
625 statistics_task = GNUNET_SCHEDULER_add_delayed(STATS_DELAY, &stats_check, NULL);
630 map_disconnect (const struct GNUNET_PeerIdentity * peer, void * source)
633 struct PeerContainer * pc;
634 if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains(peers, &peer->hashPubKey))
638 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
639 "%s disconnect notification for unknown peer `%s'\n",
640 "TRANSPORT", GNUNET_i2s (peer));
646 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
647 "%s disconnect notification for unknown peer `%s'\n",
648 "CORE", GNUNET_i2s (peer));
653 pc = GNUNET_CONTAINER_multihashmap_get(peers, &peer->hashPubKey);
656 if (NULL != pc->th_ping)
658 GNUNET_TRANSPORT_notify_transmit_ready_cancel(pc->th_ping);
661 if (NULL != pc->th_pong)
663 GNUNET_TRANSPORT_notify_transmit_ready_cancel(pc->th_pong);
667 if (GNUNET_YES == pc->transport_connected)
669 pc->transport_connected = GNUNET_NO;
673 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
674 "%s notified for not connected peer `%s' (%s : %s)\n",
676 GNUNET_i2s (&pc->id),
677 "CORE", (pc->core_connected == GNUNET_YES) ? "yes" : "no");
683 if (NULL != pc->ch_ping)
685 GNUNET_CORE_notify_transmit_ready_cancel (pc->ch_ping);
688 if (NULL != pc->ch_pong)
690 GNUNET_CORE_notify_transmit_ready_cancel (pc->ch_pong);
694 if (GNUNET_YES == pc->core_connected)
696 pc->core_connected = GNUNET_NO;
700 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
701 "%s notified for not connected peer `%s' (%s : %s)\n",
703 GNUNET_i2s (&pc->id),
704 "TRANSPORT", (pc->transport_connected == GNUNET_YES) ? "yes" : "no");
709 if ((GNUNET_NO == pc->core_connected) && (GNUNET_NO == pc->transport_connected))
711 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Removing peer `%s'\n", GNUNET_i2s (&pc->id));
712 GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_remove (peers, &peer->hashPubKey, pc));
718 if (GNUNET_SCHEDULER_NO_TASK != check_task)
719 GNUNET_SCHEDULER_cancel(check_task);
720 check_task = GNUNET_SCHEDULER_add_delayed(CHECK_DELAY, &map_check, NULL);
722 if (GNUNET_SCHEDULER_NO_TASK != statistics_task)
723 GNUNET_SCHEDULER_cancel(statistics_task);
724 statistics_task = GNUNET_SCHEDULER_add_delayed(STATS_DELAY, &stats_check, NULL);
729 cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
731 struct TransportPlugin * cur = phead;
735 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Disconnecting from transport service\n");
736 GNUNET_TRANSPORT_disconnect (th);
743 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Disconnecting from core service\n");
744 GNUNET_CORE_disconnect (ch);
748 if (GNUNET_SCHEDULER_NO_TASK != statistics_task)
750 GNUNET_SCHEDULER_cancel(statistics_task);
751 statistics_task = GNUNET_SCHEDULER_NO_TASK;
754 if (GNUNET_SCHEDULER_NO_TASK != check_task)
756 GNUNET_SCHEDULER_cancel(check_task);
757 check_task = GNUNET_SCHEDULER_NO_TASK;
760 for (cur = phead; cur != NULL; cur = phead)
762 GNUNET_CONTAINER_DLL_remove(phead, ptail, cur);
763 GNUNET_free (cur->short_name);
767 check_task = GNUNET_SCHEDULER_add_now (&map_check, &map_cleanup);
771 transport_notify_connect_cb (void *cls,
772 const struct GNUNET_PeerIdentity
775 GNUNET_ATS_Information * ats,
778 transport_connections ++;
779 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "TRANSPORT connect for peer `%s' (%u total)\n",
780 GNUNET_i2s (peer), transport_connections);
781 map_connect (peer, th);
785 * Function called to notify transport users that another
786 * peer disconnected from us.
789 * @param peer the peer that disconnected
792 transport_notify_disconnect_cb (void *cls,
794 GNUNET_PeerIdentity * peer)
796 GNUNET_assert (transport_connections > 0);
797 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "TRANSPORT disconnect for peer `%s' (%u total)\n",
798 GNUNET_i2s (peer), transport_connections) ;
799 map_disconnect (peer, th);
800 transport_connections --;
805 transport_notify_receive_cb (void *cls,
807 GNUNET_PeerIdentity * peer,
809 GNUNET_MessageHeader *
812 GNUNET_ATS_Information * ats,
817 struct PeerContainer *pc = NULL;
819 pc = GNUNET_CONTAINER_multihashmap_get(peers, &peer->hashPubKey);
827 if ((message->size == ntohs (sizeof (struct PING))) && (message->type == ntohs (1234)))
829 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Received %s %s from peer `%s'\n",
833 if (GNUNET_YES == ping)
835 if (NULL == pc->th_pong)
836 pc->th_pong = GNUNET_TRANSPORT_notify_transmit_ready(th,
837 peer, sizeof (struct PONG),
838 UINT_MAX, GNUNET_TIME_relative_get_forever(),
839 &send_transport_pong_cb, pc);
845 if ((message->size == ntohs (sizeof (struct PONG))) && (message->type == ntohs (4321)))
847 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Received %s %s from peer `%s'\n",
854 int core_notify_receive_cb (void *cls,
855 const struct GNUNET_PeerIdentity * peer,
856 const struct GNUNET_MessageHeader * message,
857 const struct GNUNET_ATS_Information* atsi,
858 unsigned int atsi_count)
860 struct PeerContainer *pc = NULL;
862 pc = GNUNET_CONTAINER_multihashmap_get(peers, &peer->hashPubKey);
870 if ((message->size == ntohs (sizeof (struct PING))) && (message->type == ntohs (1234)))
872 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Received %s %s from peer `%s'\n",
876 if (GNUNET_YES == ping)
878 if (NULL == pc->ch_pong)
879 pc->ch_pong = GNUNET_CORE_notify_transmit_ready(ch,
881 GNUNET_TIME_relative_get_forever(),
883 sizeof (struct PONG),
884 send_core_pong_cb, pc);
890 if ((message->size == ntohs (sizeof (struct PONG))) && (message->type == ntohs (4321)))
892 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Received %s %s from peer `%s'\n",
903 core_connect_cb (void *cls, const struct GNUNET_PeerIdentity *peer,
904 const struct GNUNET_ATS_Information *atsi,
905 unsigned int atsi_count)
907 if (0 != memcmp (peer, &my_peer_id, sizeof (struct GNUNET_PeerIdentity)))
910 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "CORE connect for peer `%s' (%u total)\n",
911 GNUNET_i2s (peer), core_connections);
912 map_connect (peer, ch);
916 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "CORE connect for myself `%s' (%u total)\n",
917 GNUNET_i2s (peer), core_connections);
922 core_disconnect_cb (void *cls,
924 GNUNET_PeerIdentity * peer)
926 if (0 != memcmp (peer, &my_peer_id, sizeof (struct GNUNET_PeerIdentity)))
928 GNUNET_assert (core_connections >= 0);
929 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "CORE disconnect for peer `%s' (%u total)\n",
930 GNUNET_i2s (peer), core_connections);
931 map_disconnect (peer, ch);
936 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "CORE disconnect for myself `%s' (%u total)\n",
937 GNUNET_i2s (peer), core_connections);
943 core_init_cb (void *cls, struct GNUNET_CORE_Handle *server,
944 const struct GNUNET_PeerIdentity *my_identity)
946 my_peer_id = *my_identity;
947 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Connected to core service\n");
954 struct TransportPlugin * cur;
959 long long unsigned int port;
961 have_tcp = GNUNET_NO;
962 have_udp = GNUNET_NO;
963 have_http = GNUNET_NO;
964 have_https = GNUNET_NO;
965 have_unix = GNUNET_NO;
967 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (mycfg, "TRANSPORT", "PLUGINS", &plugs))
970 for (pos = strtok (plugs, " "); pos != NULL; pos = strtok (NULL, " "))
974 GNUNET_asprintf(&secname, "transport-%s", pos);
976 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (mycfg, secname, "PORT", &port))
978 GNUNET_free (secname);
982 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Transport plugin: `%s' port %llu\n"), pos, port);
983 cur = GNUNET_malloc(sizeof (struct TransportPlugin));
984 cur->short_name = strdup (pos);
986 if (0 == strcmp("tcp", pos))
988 have_tcp = GNUNET_YES;
991 if (0 == strcmp("udp", pos))
993 have_udp = GNUNET_YES;
996 if (0 == strcmp("http", pos))
998 have_http = GNUNET_YES;
1001 if (0 == strcmp("https", pos))
1003 have_https = GNUNET_YES;
1004 cur->protocol = tcp;
1006 if (0 == strcmp("unix", pos))
1008 have_unix = GNUNET_YES;
1009 cur->protocol = unixdomain;
1012 GNUNET_CONTAINER_DLL_insert(phead, ptail, cur);
1013 GNUNET_free (secname);
1015 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Found %u transport plugins: `%s'\n"),
1018 GNUNET_free (plugs);
1022 * Main function that will be run by the scheduler.
1024 * @param cls closure
1025 * @param args remaining command-line arguments
1026 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
1027 * @param cfg configuration
1030 run (void *cls, char *const *args, const char *cfgfile,
1031 const struct GNUNET_CONFIGURATION_Handle *cfg)
1033 transport_connections = 0;
1034 core_connections = 0;
1039 stats = GNUNET_STATISTICS_create ("watchdog", cfg);
1040 peers = GNUNET_CONTAINER_multihashmap_create (20);
1042 th = GNUNET_TRANSPORT_connect(cfg, NULL, NULL,
1043 &transport_notify_receive_cb,
1044 &transport_notify_connect_cb,
1045 &transport_notify_disconnect_cb);
1046 GNUNET_assert (th != NULL);
1047 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Connected to transport service\n");
1048 ch = GNUNET_CORE_connect (cfg, 1, NULL,
1051 &core_disconnect_cb,
1052 &core_notify_receive_cb, GNUNET_NO,
1055 GNUNET_assert (ch != NULL);
1057 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup_task, NULL);
1063 * The main function.
1065 * @param argc number of arguments from the command line
1066 * @param argv command line arguments
1067 * @return 0 ok, 1 on error
1070 main (int argc, char *const *argv)
1073 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
1074 {'p', "ping", NULL, gettext_noop ("Send ping messages to test connectivity (default == NO)"),
1075 GNUNET_NO, &GNUNET_GETOPT_set_one, &ping},
1076 GNUNET_GETOPT_OPTION_END
1078 return (GNUNET_OK ==
1079 GNUNET_PROGRAM_run (argc, argv, "cn",
1080 gettext_noop ("help text"), options, &run,
1084 /* end of connection_watchdog.c */