2 This file is part of GNUnet.
3 (C) 2009, 2010, 2013 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_util_lib.h"
31 #include "gnunet_transport_service.h"
32 #include "gnunet_statistics_service.h"
35 #define CHECK_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
36 #define STATS_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
37 #define REPEATED_STATS_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
38 #define STATS_VALUES 4
49 static int have_https;
52 static struct GNUNET_TRANSPORT_Handle *th;
53 static struct GNUNET_CORE_Handle *ch;
54 static struct GNUNET_PeerIdentity my_peer_id;
55 static const struct GNUNET_CONFIGURATION_Handle *mycfg;
56 static struct GNUNET_STATISTICS_Handle *stats;
59 static unsigned int transport_connections;
60 static unsigned int core_connections;
62 static GNUNET_SCHEDULER_TaskIdentifier check_task;
63 static GNUNET_SCHEDULER_TaskIdentifier statistics_task;
65 static uint64_t statistics_transport_connections;
66 static uint64_t statistics_transport_tcp_connections;
67 static uint64_t statistics_core_neighbour_entries;
68 static uint64_t statistics_core_entries_session_map;
70 static int stat_check_running;
72 static struct GNUNET_CONTAINER_MultiHashMap *peers;
76 struct GNUNET_PeerIdentity id;
77 int transport_connected;
79 struct GNUNET_TRANSPORT_TransmitHandle *th_ping;
80 struct GNUNET_CORE_TransmitHandle *ch_ping;
82 struct GNUNET_TRANSPORT_TransmitHandle *th_pong;
83 struct GNUNET_CORE_TransmitHandle *ch_pong;
94 struct TransportPlugin
97 * This is a doubly-linked list.
99 struct TransportPlugin *next;
102 * This is a doubly-linked list.
104 struct TransportPlugin *prev;
107 * Short name for the plugin (i.e. "tcp").
117 static struct TransportPlugin *phead;
118 static struct TransportPlugin *ptail;
122 map_check_it (void *cls,
123 const struct 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");
143 map_cleanup_it (void *cls,
144 const struct GNUNET_HashCode * key,
147 struct PeerContainer *pc = value;
148 GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_remove(peers, key, value));
149 if (NULL != pc->th_ping)
151 GNUNET_TRANSPORT_notify_transmit_ready_cancel(pc->th_ping);
154 if (NULL != pc->th_pong)
156 GNUNET_TRANSPORT_notify_transmit_ready_cancel(pc->th_pong);
159 if (NULL != pc->ch_ping)
161 GNUNET_CORE_notify_transmit_ready_cancel (pc->ch_ping);
164 if (NULL != pc->ch_pong)
166 GNUNET_CORE_notify_transmit_ready_cancel(pc->ch_pong);
174 map_cleanup (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
176 GNUNET_CONTAINER_multihashmap_iterate (peers, &map_cleanup_it, NULL);
177 GNUNET_CONTAINER_multihashmap_destroy(peers);
181 map_check (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
184 check_task = GNUNET_SCHEDULER_NO_TASK;
185 GNUNET_CONTAINER_multihashmap_iterate (peers, &map_check_it, &fail);
187 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
188 "Inconsistent peers after connection consistency check: %u\n", fail);
190 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
191 "Inconsistent peers after connection consistency check: %u\n", fail);
196 GNUNET_SCHEDULER_add_now (cls, NULL);
202 stats_check (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
206 check_lowlevel_connections (int port, int protocol)
209 #define DEVNULL "NUL"
211 #define DEVNULL "/dev/null"
248 /* Use netstat to get a numeric list of all connections on port 'port' in state 'ESTABLISHED' */
249 GNUNET_asprintf(&cmdline, "netstat -n %s | grep %u | grep ESTABLISHED", proto, port);
251 if (system ("netstat -n > " DEVNULL " 2> " DEVNULL))
252 if (system ("netstat -n > " DEVNULL " 2> "DEVNULL) == 0)
253 f = popen (cmdline, "r");
257 f = popen (cmdline, "r");
260 GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "ss");
261 GNUNET_free (cmdline);
266 while (NULL != fgets (line, sizeof (line), f))
269 //printf ("%s", line);
273 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
274 "%i TCP connections established with port %u\n",
278 GNUNET_free (cmdline);
283 static struct TransportPlugin *
284 find_plugin (char * name)
286 struct TransportPlugin *cur = NULL;
288 for (cur = phead; cur != NULL; cur = cur->next)
290 if (0 == strcmp(name, cur->short_name))
297 stats_check_cb (void *cls, const char *subsystem,
298 const char *name, uint64_t value,
309 if ((STATS_VALUES == counter) || ((GNUNET_NO == have_tcp) && (STATS_VALUES - 1 == counter)))
311 int fail = GNUNET_NO;
315 int low_level_connections_udp = check_lowlevel_connections (2086, udp);
317 if (transport_connections != core_connections)
319 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
320 "%u transport notifications <-> %u core notifications\n",
321 transport_connections, core_connections);
325 if (transport_connections != statistics_transport_connections)
327 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
328 "%u transport notifications <-> %u in statistics (peers connected)\n",
329 transport_connections, statistics_transport_connections);
333 if (core_connections != statistics_core_entries_session_map)
335 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
336 "%u core notifications <-> %u in statistics (entries session map)\n",
337 core_connections, statistics_core_entries_session_map);
341 if (core_connections != statistics_core_neighbour_entries)
343 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
344 "%u core notifications <-> %u in statistics (neighbour entries allocated)\n",
345 core_connections, statistics_core_neighbour_entries);
349 if (GNUNET_NO == fail)
350 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
351 "Check successful : (%u transport / %u core) connections established\n", transport_connections, core_connections);
353 /* TCP plugin specific checks */
354 if (GNUNET_YES == have_tcp)
356 struct TransportPlugin * p = find_plugin ("tcp");
357 int low_level_connections_tcp = check_lowlevel_connections (p->port, p->protocol);
359 if (low_level_connections_tcp != -1)
361 if (statistics_transport_tcp_connections > low_level_connections_tcp)
363 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
364 "%u transport tcp sessions <-> %i established tcp connections\n",
365 statistics_transport_tcp_connections, low_level_connections_tcp);
367 else if (low_level_connections_tcp != -1)
369 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
370 "%u TCP connections, %u UDP connections \n",
371 low_level_connections_tcp, low_level_connections_udp);
374 if (transport_connections > statistics_transport_tcp_connections)
376 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
377 "%u transport notifications <-> %u in statistics (statistics_transport_tcp_connections)\n",
378 transport_connections, statistics_transport_tcp_connections);
382 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
383 " %u transport notifications <-> %u in statistics (statistics_transport_tcp_connections)\n",
384 transport_connections, statistics_transport_tcp_connections);
388 if (GNUNET_SCHEDULER_NO_TASK == statistics_task)
389 statistics_task = GNUNET_SCHEDULER_add_delayed(REPEATED_STATS_DELAY, &stats_check, NULL);
391 stat_check_running = GNUNET_NO;
398 GNUNET_NETWORK_STRUCT_BEGIN
402 struct GNUNET_MessageHeader header;
409 struct GNUNET_MessageHeader header;
413 GNUNET_NETWORK_STRUCT_END
417 send_transport_ping_cb (void *cls, size_t size, void *buf)
419 struct PeerContainer * pc = cls;
421 size_t mlen = sizeof (struct PING);
429 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
430 "Sending transport ping to `%s'\n", GNUNET_i2s (&pc->id));
431 ping.header.size = htons (mlen);
432 ping.header.type = htons (1234);
433 ping.src = htons (0);
437 memcpy (buf, &ping, mlen);
443 send_core_ping_cb (void *cls, size_t size, void *buf)
445 struct PeerContainer * pc = cls;
447 size_t mlen = sizeof (struct PING);
455 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
456 "Sending core ping to `%s'\n", GNUNET_i2s (&pc->id));
457 ping.header.size = htons (mlen);
458 ping.header.type = htons (1234);
459 ping.src = htons (1);
463 memcpy (buf, &ping, mlen);
469 map_ping_it (void *cls,
470 const struct GNUNET_HashCode * key,
473 struct PeerContainer *pc = value;
475 if (ping == GNUNET_YES)
477 if ((GNUNET_YES == pc->transport_connected) && (NULL == pc->th_ping))
478 pc->th_ping = GNUNET_TRANSPORT_notify_transmit_ready(th, &pc->id,
479 sizeof (struct PING), UINT_MAX,
480 GNUNET_TIME_UNIT_FOREVER_REL, &send_transport_ping_cb, pc);
484 if ((GNUNET_YES == pc->core_connected) && (NULL == pc->ch_ping))
485 pc->ch_ping = GNUNET_CORE_notify_transmit_ready(ch,
487 GNUNET_TIME_UNIT_FOREVER_REL,
489 sizeof (struct PING),
490 send_core_ping_cb, pc);
499 stats_check (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
501 statistics_task = GNUNET_SCHEDULER_NO_TASK;
503 if (GNUNET_YES == stat_check_running)
505 statistics_task = GNUNET_SCHEDULER_add_delayed(STATS_DELAY, &stats_check, NULL);
508 GNUNET_CONTAINER_multihashmap_iterate (peers, &map_ping_it, NULL);
510 stat_check_running = GNUNET_YES;
512 statistics_transport_connections = 0 ;
513 statistics_core_entries_session_map = 0;
514 statistics_core_neighbour_entries = 0;
516 GNUNET_STATISTICS_get (stats, "transport", "# peers connected", GNUNET_TIME_UNIT_MINUTES, NULL, &stats_check_cb, &statistics_transport_connections);
517 GNUNET_STATISTICS_get (stats, "core", "# neighbour entries allocated", GNUNET_TIME_UNIT_MINUTES, NULL, &stats_check_cb, &statistics_core_neighbour_entries);
518 GNUNET_STATISTICS_get (stats, "core", "# peers connected", GNUNET_TIME_UNIT_MINUTES, NULL, &stats_check_cb, &statistics_core_entries_session_map);
520 /* TCP plugin specific checks */
521 if (GNUNET_YES == have_tcp)
522 GNUNET_STATISTICS_get (stats, "transport", "# TCP sessions active", GNUNET_TIME_UNIT_MINUTES, NULL, &stats_check_cb, &statistics_transport_tcp_connections);
527 send_transport_pong_cb (void *cls, size_t size, void *buf)
529 struct PeerContainer * pc = cls;
531 size_t mlen = sizeof (struct PING);
539 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
540 "Sending transport pong to `%s'\n", GNUNET_i2s (&pc->id));
541 ping.header.size = htons (mlen);
542 ping.header.type = htons (4321);
543 ping.src = htons (0);
547 memcpy (buf, &ping, mlen);
553 send_core_pong_cb (void *cls, size_t size, void *buf)
555 struct PeerContainer * pc = cls;
557 size_t mlen = sizeof (struct PING);
565 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
566 "Sending core pong to `%s'\n", GNUNET_i2s (&pc->id));
567 ping.header.size = htons (mlen);
568 ping.header.type = htons (4321);
569 ping.src = htons (1);
573 memcpy (buf, &ping, mlen);
579 map_connect (const struct GNUNET_PeerIdentity *peer, void * source)
581 struct PeerContainer * pc;
582 if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains(peers, &peer->hashPubKey))
584 pc = GNUNET_malloc (sizeof (struct PeerContainer));
586 pc->core_connected = GNUNET_NO;
587 pc->transport_connected = GNUNET_NO;
588 GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put(peers, &peer->hashPubKey, pc, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
591 pc = GNUNET_CONTAINER_multihashmap_get(peers, &peer->hashPubKey);
592 GNUNET_assert (NULL != pc);
596 if (GNUNET_NO == pc->transport_connected)
598 pc->transport_connected = GNUNET_YES;
599 if (GNUNET_YES == ping)
601 if (NULL == pc->th_ping)
602 pc->th_ping = GNUNET_TRANSPORT_notify_transmit_ready(th, peer, sizeof (struct PING), UINT_MAX, GNUNET_TIME_UNIT_FOREVER_REL, &send_transport_ping_cb, pc);
609 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
610 "%s notified multiple times about for peers `%s' (%s : %s)\n",
612 GNUNET_i2s (&pc->id),
613 "CORE", (pc->core_connected == GNUNET_YES) ? "yes" : "no");
619 if (GNUNET_NO == pc->core_connected)
621 pc->core_connected = GNUNET_YES;
622 if (GNUNET_YES == ping)
624 if (NULL == pc->ch_ping)
625 pc->ch_ping = GNUNET_CORE_notify_transmit_ready(ch,
627 GNUNET_TIME_UNIT_FOREVER_REL,
629 sizeof (struct PING),
630 send_core_ping_cb, pc);
637 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
638 "%s notified multiple times about for peers `%s' (%s : %s)\n",
640 GNUNET_i2s (&pc->id),
641 "TRANSPORT", (pc->transport_connected == GNUNET_YES) ? "yes" : "no");
645 if (GNUNET_SCHEDULER_NO_TASK != check_task)
646 GNUNET_SCHEDULER_cancel(check_task);
647 check_task = GNUNET_SCHEDULER_add_delayed(CHECK_DELAY, &map_check, NULL);
649 if (GNUNET_SCHEDULER_NO_TASK != statistics_task)
650 GNUNET_SCHEDULER_cancel(statistics_task);
651 statistics_task = GNUNET_SCHEDULER_add_delayed(STATS_DELAY, &stats_check, NULL);
656 map_disconnect (const struct GNUNET_PeerIdentity * peer, void * source)
659 struct PeerContainer * pc;
660 if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains(peers, &peer->hashPubKey))
664 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
665 "%s disconnect notification for unknown peer `%s'\n",
666 "TRANSPORT", GNUNET_i2s (peer));
672 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
673 "%s disconnect notification for unknown peer `%s'\n",
674 "CORE", GNUNET_i2s (peer));
679 pc = GNUNET_CONTAINER_multihashmap_get(peers, &peer->hashPubKey);
680 GNUNET_assert (NULL != pc);
684 if (NULL != pc->th_ping)
686 GNUNET_TRANSPORT_notify_transmit_ready_cancel(pc->th_ping);
689 if (NULL != pc->th_pong)
691 GNUNET_TRANSPORT_notify_transmit_ready_cancel(pc->th_pong);
695 if (GNUNET_YES == pc->transport_connected)
697 pc->transport_connected = GNUNET_NO;
701 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
702 "%s notified for not connected peer `%s' (%s : %s)\n",
704 GNUNET_i2s (&pc->id),
705 "CORE", (pc->core_connected == GNUNET_YES) ? "yes" : "no");
711 if (NULL != pc->ch_ping)
713 GNUNET_CORE_notify_transmit_ready_cancel (pc->ch_ping);
716 if (NULL != pc->ch_pong)
718 GNUNET_CORE_notify_transmit_ready_cancel (pc->ch_pong);
722 if (GNUNET_YES == pc->core_connected)
724 pc->core_connected = GNUNET_NO;
728 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
729 "%s notified for not connected peer `%s' (%s : %s)\n",
731 GNUNET_i2s (&pc->id),
732 "TRANSPORT", (pc->transport_connected == GNUNET_YES) ? "yes" : "no");
737 if ((GNUNET_NO == pc->core_connected) && (GNUNET_NO == pc->transport_connected))
739 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Removing peer `%s'\n", GNUNET_i2s (&pc->id));
740 GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_remove (peers, &peer->hashPubKey, pc));
746 if (GNUNET_SCHEDULER_NO_TASK != check_task)
747 GNUNET_SCHEDULER_cancel(check_task);
748 check_task = GNUNET_SCHEDULER_add_delayed(CHECK_DELAY, &map_check, NULL);
750 if (GNUNET_SCHEDULER_NO_TASK != statistics_task)
751 GNUNET_SCHEDULER_cancel(statistics_task);
752 statistics_task = GNUNET_SCHEDULER_add_delayed(STATS_DELAY, &stats_check, NULL);
757 cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
759 struct TransportPlugin *cur;
763 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
764 "Disconnecting from transport service\n");
765 GNUNET_TRANSPORT_disconnect (th);
772 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
773 "Disconnecting from core service\n");
774 GNUNET_CORE_disconnect (ch);
778 if (GNUNET_SCHEDULER_NO_TASK != statistics_task)
780 GNUNET_SCHEDULER_cancel(statistics_task);
781 statistics_task = GNUNET_SCHEDULER_NO_TASK;
784 if (GNUNET_SCHEDULER_NO_TASK != check_task)
786 GNUNET_SCHEDULER_cancel(check_task);
787 check_task = GNUNET_SCHEDULER_NO_TASK;
790 for (cur = phead; NULL != cur; cur = phead)
792 GNUNET_CONTAINER_DLL_remove(phead, ptail, cur);
793 GNUNET_free (cur->short_name);
797 check_task = GNUNET_SCHEDULER_add_now (&map_check, &map_cleanup);
802 transport_notify_connect_cb (void *cls,
803 const struct GNUNET_PeerIdentity* peer)
805 transport_connections ++;
806 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
807 "TRANSPORT connect for peer `%s' (%u total)\n",
809 transport_connections);
810 map_connect (peer, th);
815 * Function called to notify transport users that another
816 * peer disconnected from us.
819 * @param peer the peer that disconnected
822 transport_notify_disconnect_cb (void *cls,
823 const struct GNUNET_PeerIdentity *peer)
825 GNUNET_assert (transport_connections > 0);
826 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
827 "TRANSPORT disconnect for peer `%s' (%u total)\n",
829 transport_connections);
830 map_disconnect (peer, th);
831 transport_connections --;
836 transport_notify_receive_cb (void *cls,
838 GNUNET_PeerIdentity * peer,
840 GNUNET_MessageHeader *
843 struct PeerContainer *pc;
845 pc = GNUNET_CONTAINER_multihashmap_get (peers, &peer->hashPubKey);
852 if ((message->size == ntohs (sizeof (struct PING))) &&
853 (message->type == ntohs (1234)))
855 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
856 "Received %s %s from peer `%s'\n",
860 if (GNUNET_YES == ping)
862 if (NULL == pc->th_pong)
863 pc->th_pong = GNUNET_TRANSPORT_notify_transmit_ready(th,
864 peer, sizeof (struct PONG),
865 UINT_MAX, GNUNET_TIME_UNIT_FOREVER_REL,
866 &send_transport_pong_cb, pc);
872 if ((message->size == ntohs (sizeof (struct PONG))) && (message->type == ntohs (4321)))
874 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Received %s %s from peer `%s'\n",
882 core_notify_receive_cb (void *cls,
883 const struct GNUNET_PeerIdentity * peer,
884 const struct GNUNET_MessageHeader * message)
886 struct PeerContainer *pc = NULL;
888 pc = GNUNET_CONTAINER_multihashmap_get(peers, &peer->hashPubKey);
892 if (0 == memcmp (peer, &my_peer_id, sizeof (my_peer_id)))
895 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Received unexpected message type %u from unknown peer `%s'\n",
896 ntohs (message->type),
903 if ((message->size == ntohs (sizeof (struct PING))) && (message->type == ntohs (1234)))
905 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Received %s %s from peer `%s'\n",
909 if (GNUNET_YES == ping)
911 if (NULL == pc->ch_pong)
912 pc->ch_pong = GNUNET_CORE_notify_transmit_ready(ch,
914 GNUNET_TIME_UNIT_FOREVER_REL,
916 sizeof (struct PONG),
917 send_core_pong_cb, pc);
923 if ((message->size == ntohs (sizeof (struct PONG))) && (message->type == ntohs (4321)))
925 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Received %s %s from peer `%s'\n",
936 core_connect_cb (void *cls, const struct GNUNET_PeerIdentity *peer)
938 if (0 != memcmp (peer, &my_peer_id, sizeof (struct GNUNET_PeerIdentity)))
941 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "CORE connect for peer `%s' (%u total)\n",
942 GNUNET_i2s (peer), core_connections);
943 map_connect (peer, ch);
947 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "CORE connect for myself `%s' (%u total)\n",
948 GNUNET_i2s (peer), core_connections);
953 core_disconnect_cb (void *cls,
955 GNUNET_PeerIdentity * peer)
957 if (0 != memcmp (peer, &my_peer_id, sizeof (struct GNUNET_PeerIdentity)))
959 GNUNET_assert (core_connections > 0);
960 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "CORE disconnect for peer `%s' (%u total)\n",
961 GNUNET_i2s (peer), core_connections);
962 map_disconnect (peer, ch);
967 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "CORE disconnect for myself `%s' (%u total)\n",
968 GNUNET_i2s (peer), core_connections);
974 core_init_cb (void *cls,
975 const struct GNUNET_PeerIdentity *my_identity)
977 my_peer_id = *my_identity;
978 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Connected to core service\n");
985 struct TransportPlugin * cur;
990 unsigned long long port;
992 have_tcp = GNUNET_NO;
993 have_udp = GNUNET_NO;
994 have_http = GNUNET_NO;
995 have_https = GNUNET_NO;
996 have_unix = GNUNET_NO;
998 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (mycfg, "TRANSPORT", "PLUGINS", &plugs))
1001 for (pos = strtok (plugs, " "); pos != NULL; pos = strtok (NULL, " "))
1005 GNUNET_asprintf(&secname, "transport-%s", pos);
1007 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (mycfg, secname, "PORT", &port))
1009 GNUNET_free (secname);
1013 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Transport plugin: `%s' port %llu\n"), pos, port);
1014 cur = GNUNET_malloc(sizeof (struct TransportPlugin));
1015 cur->short_name = GNUNET_strdup (pos);
1017 if (0 == strcmp("tcp", pos))
1019 have_tcp = GNUNET_YES;
1020 cur->protocol = tcp;
1022 if (0 == strcmp("udp", pos))
1024 have_udp = GNUNET_YES;
1025 cur->protocol = udp;
1027 if (0 == strcmp("http", pos))
1029 have_http = GNUNET_YES;
1030 cur->protocol = tcp;
1032 if (0 == strcmp("https", pos))
1034 have_https = GNUNET_YES;
1035 cur->protocol = tcp;
1037 if (0 == strcmp("unix", pos))
1039 have_unix = GNUNET_YES;
1040 cur->protocol = unixdomain;
1043 GNUNET_CONTAINER_DLL_insert(phead, ptail, cur);
1044 GNUNET_free (secname);
1046 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Found %u transport plugins: `%s'\n"),
1049 GNUNET_free (plugs);
1054 * Main function that will be run by the scheduler.
1056 * @param cls closure
1057 * @param args remaining command-line arguments
1058 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
1059 * @param cfg configuration
1062 run (void *cls, char *const *args, const char *cfgfile,
1063 const struct GNUNET_CONFIGURATION_Handle *cfg)
1065 transport_connections = 0;
1066 core_connections = 0;
1071 stats = GNUNET_STATISTICS_create ("watchdog", cfg);
1072 peers = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_NO);
1074 th = GNUNET_TRANSPORT_connect(cfg, NULL, NULL,
1075 &transport_notify_receive_cb,
1076 &transport_notify_connect_cb,
1077 &transport_notify_disconnect_cb);
1078 GNUNET_assert (th != NULL);
1079 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Connected to transport service\n");
1080 ch = GNUNET_CORE_connect (cfg, NULL,
1083 &core_disconnect_cb,
1084 &core_notify_receive_cb, GNUNET_NO,
1087 GNUNET_assert (ch != NULL);
1089 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup_task, NULL);
1095 * The main function.
1097 * @param argc number of arguments from the command line
1098 * @param argv command line arguments
1099 * @return 0 ok, 1 on error
1102 main (int argc, char *const *argv)
1105 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
1106 {'p', "ping", NULL, gettext_noop ("Send ping messages to test connectivity (default == NO)"),
1107 GNUNET_NO, &GNUNET_GETOPT_set_one, &ping},
1108 GNUNET_GETOPT_OPTION_END
1111 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
1114 GNUNET_PROGRAM_run (argc, argv, "cn",
1115 gettext_noop ("help text"), options, &run,
1117 GNUNET_free ((void*) argv);
1121 /* end of connection_watchdog.c */