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_util_lib.h"
27 #include "gnunet_constants.h"
28 #include "gnunet_arm_service.h"
29 #include "gnunet_core_service.h"
30 #include "gnunet_transport_service.h"
31 #include "gnunet_statistics_service.h"
34 #define CHECK_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
35 #define STATS_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
36 #define REPEATED_STATS_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
37 #define STATS_VALUES 4
48 static int have_https;
51 static struct GNUNET_TRANSPORT_Handle *th;
52 static struct GNUNET_CORE_Handle *ch;
53 static struct GNUNET_PeerIdentity my_peer_id;
54 static const struct GNUNET_CONFIGURATION_Handle *mycfg;
55 static struct GNUNET_STATISTICS_Handle *stats;
58 static unsigned int transport_connections;
59 static unsigned int core_connections;
61 static GNUNET_SCHEDULER_TaskIdentifier check_task;
62 static GNUNET_SCHEDULER_TaskIdentifier statistics_task;
64 static uint64_t statistics_transport_connections;
65 static uint64_t statistics_transport_tcp_connections;
66 static uint64_t statistics_core_neighbour_entries;
67 static uint64_t statistics_core_entries_session_map;
69 static int stat_check_running;
71 static struct GNUNET_CONTAINER_MultiPeerMap *peers;
75 struct GNUNET_PeerIdentity id;
76 int transport_connected;
78 struct GNUNET_TRANSPORT_TransmitHandle *th_ping;
79 struct GNUNET_CORE_TransmitHandle *ch_ping;
81 struct GNUNET_TRANSPORT_TransmitHandle *th_pong;
82 struct GNUNET_CORE_TransmitHandle *ch_pong;
93 struct TransportPlugin
96 * This is a doubly-linked list.
98 struct TransportPlugin *next;
101 * This is a doubly-linked list.
103 struct TransportPlugin *prev;
106 * Short name for the plugin (i.e. "tcp").
116 static struct TransportPlugin *phead;
117 static struct TransportPlugin *ptail;
121 map_check_it (void *cls,
122 const struct GNUNET_PeerIdentity * key,
126 struct PeerContainer *pc = value;
127 if (pc->core_connected != pc->transport_connected)
129 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
130 "Inconsistent peer `%s': TRANSPORT %s <-> CORE %s\n",
131 GNUNET_i2s (&pc->id),
132 (GNUNET_YES == pc->transport_connected) ? "YES" : "NO",
133 (GNUNET_YES == pc->core_connected) ? "YES" : "NO");
142 map_cleanup_it (void *cls,
143 const struct GNUNET_PeerIdentity * key,
146 struct PeerContainer *pc = value;
147 GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multipeermap_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_multipeermap_iterate (peers, &map_cleanup_it, NULL);
176 GNUNET_CONTAINER_multipeermap_destroy(peers);
180 map_check (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
183 check_task = GNUNET_SCHEDULER_NO_TASK;
184 GNUNET_CONTAINER_multipeermap_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);
205 check_lowlevel_connections (int port, int protocol)
208 #define DEVNULL "NUL"
210 #define DEVNULL "/dev/null"
247 /* Use netstat to get a numeric list of all connections on port 'port' in state 'ESTABLISHED' */
248 GNUNET_asprintf(&cmdline, "netstat -n %s | grep %u | grep ESTABLISHED", proto, port);
250 if (system ("netstat -n > " DEVNULL " 2> " DEVNULL))
251 if (system ("netstat -n > " DEVNULL " 2> "DEVNULL) == 0)
252 f = popen (cmdline, "r");
256 f = popen (cmdline, "r");
259 GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "ss");
260 GNUNET_free (cmdline);
265 while (NULL != fgets (line, sizeof (line), f))
268 //printf ("%s", line);
272 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
273 "%i TCP connections established with port %u\n",
277 GNUNET_free (cmdline);
282 static struct TransportPlugin *
283 find_plugin (char * name)
285 struct TransportPlugin *cur = NULL;
287 for (cur = phead; cur != NULL; cur = cur->next)
289 if (0 == strcmp(name, cur->short_name))
296 stats_check_cb (void *cls, const char *subsystem,
297 const char *name, uint64_t value,
308 if ((STATS_VALUES == counter) || ((GNUNET_NO == have_tcp) && (STATS_VALUES - 1 == counter)))
310 int fail = GNUNET_NO;
314 int low_level_connections_udp = check_lowlevel_connections (2086, udp);
316 if (transport_connections != core_connections)
318 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
319 "%u transport notifications <-> %u core notifications\n",
320 transport_connections, core_connections);
324 if (transport_connections != statistics_transport_connections)
326 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
327 "%u transport notifications <-> %u in statistics (peers connected)\n",
328 transport_connections, statistics_transport_connections);
332 if (core_connections != statistics_core_entries_session_map)
334 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
335 "%u core notifications <-> %u in statistics (entries session map)\n",
336 core_connections, statistics_core_entries_session_map);
340 if (core_connections != statistics_core_neighbour_entries)
342 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
343 "%u core notifications <-> %u in statistics (neighbour entries allocated)\n",
344 core_connections, statistics_core_neighbour_entries);
348 if (GNUNET_NO == fail)
349 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
350 "Check successful : (%u transport / %u core) connections established\n", transport_connections, core_connections);
352 /* TCP plugin specific checks */
353 if (GNUNET_YES == have_tcp)
355 struct TransportPlugin * p = find_plugin ("tcp");
356 int low_level_connections_tcp = check_lowlevel_connections (p->port, p->protocol);
358 if (low_level_connections_tcp != -1)
360 if (statistics_transport_tcp_connections > low_level_connections_tcp)
362 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
363 "%u transport tcp sessions <-> %i established tcp connections\n",
364 statistics_transport_tcp_connections, low_level_connections_tcp);
366 else if (low_level_connections_tcp != -1)
368 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
369 "%u TCP connections, %u UDP connections \n",
370 low_level_connections_tcp, low_level_connections_udp);
373 if (transport_connections > statistics_transport_tcp_connections)
375 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
376 "%u transport notifications <-> %u in statistics (statistics_transport_tcp_connections)\n",
377 transport_connections, statistics_transport_tcp_connections);
381 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
382 " %u transport notifications <-> %u in statistics (statistics_transport_tcp_connections)\n",
383 transport_connections, statistics_transport_tcp_connections);
387 if (GNUNET_SCHEDULER_NO_TASK == statistics_task)
388 statistics_task = GNUNET_SCHEDULER_add_delayed(REPEATED_STATS_DELAY, &stats_check, NULL);
390 stat_check_running = GNUNET_NO;
397 GNUNET_NETWORK_STRUCT_BEGIN
401 struct GNUNET_MessageHeader header;
408 struct GNUNET_MessageHeader header;
412 GNUNET_NETWORK_STRUCT_END
416 send_transport_ping_cb (void *cls, size_t size, void *buf)
418 struct PeerContainer * pc = cls;
420 size_t mlen = sizeof (struct PING);
428 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
429 "Sending transport ping to `%s'\n", GNUNET_i2s (&pc->id));
430 ping.header.size = htons (mlen);
431 ping.header.type = htons (1234);
432 ping.src = htons (0);
436 memcpy (buf, &ping, mlen);
442 send_core_ping_cb (void *cls, size_t size, void *buf)
444 struct PeerContainer * pc = cls;
446 size_t mlen = sizeof (struct PING);
454 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
455 "Sending core ping to `%s'\n", GNUNET_i2s (&pc->id));
456 ping.header.size = htons (mlen);
457 ping.header.type = htons (1234);
458 ping.src = htons (1);
462 memcpy (buf, &ping, mlen);
468 map_ping_it (void *cls,
469 const struct GNUNET_PeerIdentity * key,
472 struct PeerContainer *pc = value;
474 if (ping == GNUNET_YES)
476 if ((GNUNET_YES == pc->transport_connected) && (NULL == pc->th_ping))
477 pc->th_ping = GNUNET_TRANSPORT_notify_transmit_ready(th, &pc->id,
478 sizeof (struct PING), UINT_MAX,
479 GNUNET_TIME_UNIT_FOREVER_REL, &send_transport_ping_cb, pc);
483 if ((GNUNET_YES == pc->core_connected) && (NULL == pc->ch_ping))
484 pc->ch_ping = GNUNET_CORE_notify_transmit_ready(ch,
486 GNUNET_TIME_UNIT_FOREVER_REL,
488 sizeof (struct PING),
489 send_core_ping_cb, pc);
498 stats_check (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
500 statistics_task = GNUNET_SCHEDULER_NO_TASK;
502 if (GNUNET_YES == stat_check_running)
504 statistics_task = GNUNET_SCHEDULER_add_delayed(STATS_DELAY, &stats_check, NULL);
507 GNUNET_CONTAINER_multipeermap_iterate (peers, &map_ping_it, NULL);
509 stat_check_running = GNUNET_YES;
511 statistics_transport_connections = 0 ;
512 statistics_core_entries_session_map = 0;
513 statistics_core_neighbour_entries = 0;
515 GNUNET_STATISTICS_get (stats, "transport", "# peers connected", GNUNET_TIME_UNIT_MINUTES, NULL, &stats_check_cb, &statistics_transport_connections);
516 GNUNET_STATISTICS_get (stats, "core", "# neighbour entries allocated", GNUNET_TIME_UNIT_MINUTES, NULL, &stats_check_cb, &statistics_core_neighbour_entries);
517 GNUNET_STATISTICS_get (stats, "core", "# peers connected", GNUNET_TIME_UNIT_MINUTES, NULL, &stats_check_cb, &statistics_core_entries_session_map);
519 /* TCP plugin specific checks */
520 if (GNUNET_YES == have_tcp)
521 GNUNET_STATISTICS_get (stats, "transport", "# TCP sessions active", GNUNET_TIME_UNIT_MINUTES, NULL, &stats_check_cb, &statistics_transport_tcp_connections);
526 send_transport_pong_cb (void *cls, size_t size, void *buf)
528 struct PeerContainer * pc = cls;
530 size_t mlen = sizeof (struct PING);
538 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
539 "Sending transport pong to `%s'\n", GNUNET_i2s (&pc->id));
540 ping.header.size = htons (mlen);
541 ping.header.type = htons (4321);
542 ping.src = htons (0);
546 memcpy (buf, &ping, mlen);
552 send_core_pong_cb (void *cls, size_t size, void *buf)
554 struct PeerContainer * pc = cls;
556 size_t mlen = sizeof (struct PING);
564 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
565 "Sending core pong to `%s'\n", GNUNET_i2s (&pc->id));
566 ping.header.size = htons (mlen);
567 ping.header.type = htons (4321);
568 ping.src = htons (1);
572 memcpy (buf, &ping, mlen);
578 map_connect (const struct GNUNET_PeerIdentity *peer, void * source)
580 struct PeerContainer * pc;
581 if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains(peers, peer))
583 pc = GNUNET_malloc (sizeof (struct PeerContainer));
585 pc->core_connected = GNUNET_NO;
586 pc->transport_connected = GNUNET_NO;
587 GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multipeermap_put(peers, peer, pc, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
590 pc = GNUNET_CONTAINER_multipeermap_get(peers, peer);
591 GNUNET_assert (NULL != pc);
595 if (GNUNET_NO == pc->transport_connected)
597 pc->transport_connected = GNUNET_YES;
598 if (GNUNET_YES == ping)
600 if (NULL == pc->th_ping)
601 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);
608 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
609 "%s notified multiple times about for peers `%s' (%s : %s)\n",
611 GNUNET_i2s (&pc->id),
612 "CORE", (pc->core_connected == GNUNET_YES) ? "yes" : "no");
618 if (GNUNET_NO == pc->core_connected)
620 pc->core_connected = GNUNET_YES;
621 if (GNUNET_YES == ping)
623 if (NULL == pc->ch_ping)
624 pc->ch_ping = GNUNET_CORE_notify_transmit_ready(ch,
626 GNUNET_TIME_UNIT_FOREVER_REL,
628 sizeof (struct PING),
629 send_core_ping_cb, pc);
636 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
637 "%s notified multiple times about for peers `%s' (%s : %s)\n",
639 GNUNET_i2s (&pc->id),
640 "TRANSPORT", (pc->transport_connected == GNUNET_YES) ? "yes" : "no");
644 if (GNUNET_SCHEDULER_NO_TASK != check_task)
645 GNUNET_SCHEDULER_cancel(check_task);
646 check_task = GNUNET_SCHEDULER_add_delayed(CHECK_DELAY, &map_check, NULL);
648 if (GNUNET_SCHEDULER_NO_TASK != statistics_task)
649 GNUNET_SCHEDULER_cancel(statistics_task);
650 statistics_task = GNUNET_SCHEDULER_add_delayed(STATS_DELAY, &stats_check, NULL);
655 map_disconnect (const struct GNUNET_PeerIdentity * peer, void * source)
658 struct PeerContainer * pc;
659 if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains(peers, peer))
663 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
664 "%s disconnect notification for unknown peer `%s'\n",
665 "TRANSPORT", GNUNET_i2s (peer));
671 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
672 "%s disconnect notification for unknown peer `%s'\n",
673 "CORE", GNUNET_i2s (peer));
678 pc = GNUNET_CONTAINER_multipeermap_get(peers, peer);
679 GNUNET_assert (NULL != pc);
683 if (NULL != pc->th_ping)
685 GNUNET_TRANSPORT_notify_transmit_ready_cancel(pc->th_ping);
688 if (NULL != pc->th_pong)
690 GNUNET_TRANSPORT_notify_transmit_ready_cancel(pc->th_pong);
694 if (GNUNET_YES == pc->transport_connected)
696 pc->transport_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 "CORE", (pc->core_connected == GNUNET_YES) ? "yes" : "no");
710 if (NULL != pc->ch_ping)
712 GNUNET_CORE_notify_transmit_ready_cancel (pc->ch_ping);
715 if (NULL != pc->ch_pong)
717 GNUNET_CORE_notify_transmit_ready_cancel (pc->ch_pong);
721 if (GNUNET_YES == pc->core_connected)
723 pc->core_connected = GNUNET_NO;
727 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
728 "%s notified for not connected peer `%s' (%s : %s)\n",
730 GNUNET_i2s (&pc->id),
731 "TRANSPORT", (pc->transport_connected == GNUNET_YES) ? "yes" : "no");
736 if ((GNUNET_NO == pc->core_connected) && (GNUNET_NO == pc->transport_connected))
738 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Removing peer `%s'\n", GNUNET_i2s (&pc->id));
739 GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multipeermap_remove (peers, peer, pc));
745 if (GNUNET_SCHEDULER_NO_TASK != check_task)
746 GNUNET_SCHEDULER_cancel(check_task);
747 check_task = GNUNET_SCHEDULER_add_delayed(CHECK_DELAY, &map_check, NULL);
749 if (GNUNET_SCHEDULER_NO_TASK != statistics_task)
750 GNUNET_SCHEDULER_cancel(statistics_task);
751 statistics_task = GNUNET_SCHEDULER_add_delayed(STATS_DELAY, &stats_check, NULL);
756 cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
758 struct TransportPlugin *cur;
762 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
763 "Disconnecting from transport service\n");
764 GNUNET_TRANSPORT_disconnect (th);
771 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
772 "Disconnecting from core service\n");
773 GNUNET_CORE_disconnect (ch);
777 if (GNUNET_SCHEDULER_NO_TASK != statistics_task)
779 GNUNET_SCHEDULER_cancel(statistics_task);
780 statistics_task = GNUNET_SCHEDULER_NO_TASK;
783 if (GNUNET_SCHEDULER_NO_TASK != check_task)
785 GNUNET_SCHEDULER_cancel(check_task);
786 check_task = GNUNET_SCHEDULER_NO_TASK;
789 for (cur = phead; NULL != cur; cur = phead)
791 GNUNET_CONTAINER_DLL_remove(phead, ptail, cur);
792 GNUNET_free (cur->short_name);
796 check_task = GNUNET_SCHEDULER_add_now (&map_check, &map_cleanup);
801 transport_notify_connect_cb (void *cls,
802 const struct GNUNET_PeerIdentity* peer)
804 transport_connections ++;
805 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
806 "TRANSPORT connect for peer `%s' (%u total)\n",
808 transport_connections);
809 map_connect (peer, th);
814 * Function called to notify transport users that another
815 * peer disconnected from us.
818 * @param peer the peer that disconnected
821 transport_notify_disconnect_cb (void *cls,
822 const struct GNUNET_PeerIdentity *peer)
824 GNUNET_assert (transport_connections > 0);
825 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
826 "TRANSPORT disconnect for peer `%s' (%u total)\n",
828 transport_connections);
829 map_disconnect (peer, th);
830 transport_connections --;
835 transport_notify_receive_cb (void *cls,
837 GNUNET_PeerIdentity * peer,
839 GNUNET_MessageHeader *
842 struct PeerContainer *pc;
844 pc = GNUNET_CONTAINER_multipeermap_get (peers, peer);
851 if ((message->size == ntohs (sizeof (struct PING))) &&
852 (message->type == ntohs (1234)))
854 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
855 "Received %s %s from peer `%s'\n",
859 if (GNUNET_YES == ping)
861 if (NULL == pc->th_pong)
862 pc->th_pong = GNUNET_TRANSPORT_notify_transmit_ready(th,
863 peer, sizeof (struct PONG),
864 UINT_MAX, GNUNET_TIME_UNIT_FOREVER_REL,
865 &send_transport_pong_cb, pc);
871 if ((message->size == ntohs (sizeof (struct PONG))) && (message->type == ntohs (4321)))
873 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Received %s %s from peer `%s'\n",
881 core_notify_receive_cb (void *cls,
882 const struct GNUNET_PeerIdentity * peer,
883 const struct GNUNET_MessageHeader * message)
885 struct PeerContainer *pc = NULL;
887 pc = GNUNET_CONTAINER_multipeermap_get(peers, peer);
891 if (0 == memcmp (peer, &my_peer_id, sizeof (my_peer_id)))
894 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Received unexpected message type %u from unknown peer `%s'\n",
895 ntohs (message->type),
902 if ((message->size == ntohs (sizeof (struct PING))) && (message->type == ntohs (1234)))
904 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Received %s %s from peer `%s'\n",
908 if (GNUNET_YES == ping)
910 if (NULL == pc->ch_pong)
911 pc->ch_pong = GNUNET_CORE_notify_transmit_ready(ch,
913 GNUNET_TIME_UNIT_FOREVER_REL,
915 sizeof (struct PONG),
916 send_core_pong_cb, pc);
922 if ((message->size == ntohs (sizeof (struct PONG))) && (message->type == ntohs (4321)))
924 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Received %s %s from peer `%s'\n",
935 core_connect_cb (void *cls, const struct GNUNET_PeerIdentity *peer)
937 if (0 != memcmp (peer, &my_peer_id, sizeof (struct GNUNET_PeerIdentity)))
940 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "CORE connect for peer `%s' (%u total)\n",
941 GNUNET_i2s (peer), core_connections);
942 map_connect (peer, ch);
946 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "CORE connect for myself `%s' (%u total)\n",
947 GNUNET_i2s (peer), core_connections);
952 core_disconnect_cb (void *cls,
954 GNUNET_PeerIdentity * peer)
956 if (0 != memcmp (peer, &my_peer_id, sizeof (struct GNUNET_PeerIdentity)))
958 GNUNET_assert (core_connections > 0);
959 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "CORE disconnect for peer `%s' (%u total)\n",
960 GNUNET_i2s (peer), core_connections);
961 map_disconnect (peer, ch);
966 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "CORE disconnect for myself `%s' (%u total)\n",
967 GNUNET_i2s (peer), core_connections);
973 core_init_cb (void *cls,
974 const struct GNUNET_PeerIdentity *my_identity)
976 my_peer_id = *my_identity;
977 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Connected to core service\n");
984 struct TransportPlugin * cur;
989 unsigned long long port;
991 have_tcp = GNUNET_NO;
992 have_udp = GNUNET_NO;
993 have_http = GNUNET_NO;
994 have_https = GNUNET_NO;
995 have_unix = GNUNET_NO;
997 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (mycfg, "TRANSPORT", "PLUGINS", &plugs))
1000 for (pos = strtok (plugs, " "); pos != NULL; pos = strtok (NULL, " "))
1004 GNUNET_asprintf(&secname, "transport-%s", pos);
1006 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (mycfg, secname, "PORT", &port))
1008 GNUNET_free (secname);
1012 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Transport plugin: `%s' port %llu\n"), pos, port);
1013 cur = GNUNET_malloc(sizeof (struct TransportPlugin));
1014 cur->short_name = GNUNET_strdup (pos);
1016 if (0 == strcmp("tcp", pos))
1018 have_tcp = GNUNET_YES;
1019 cur->protocol = tcp;
1021 if (0 == strcmp("udp", pos))
1023 have_udp = GNUNET_YES;
1024 cur->protocol = udp;
1026 if (0 == strcmp("http", pos))
1028 have_http = GNUNET_YES;
1029 cur->protocol = tcp;
1031 if (0 == strcmp("https", pos))
1033 have_https = GNUNET_YES;
1034 cur->protocol = tcp;
1036 if (0 == strcmp("unix", pos))
1038 have_unix = GNUNET_YES;
1039 cur->protocol = unixdomain;
1042 GNUNET_CONTAINER_DLL_insert(phead, ptail, cur);
1043 GNUNET_free (secname);
1045 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Found %u transport plugins: `%s'\n"),
1048 GNUNET_free (plugs);
1053 * Main function that will be run by the scheduler.
1055 * @param cls closure
1056 * @param args remaining command-line arguments
1057 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
1058 * @param cfg configuration
1061 run (void *cls, char *const *args, const char *cfgfile,
1062 const struct GNUNET_CONFIGURATION_Handle *cfg)
1064 transport_connections = 0;
1065 core_connections = 0;
1070 stats = GNUNET_STATISTICS_create ("watchdog", cfg);
1071 peers = GNUNET_CONTAINER_multipeermap_create (32, GNUNET_NO);
1073 th = GNUNET_TRANSPORT_connect(cfg, NULL, NULL,
1074 &transport_notify_receive_cb,
1075 &transport_notify_connect_cb,
1076 &transport_notify_disconnect_cb);
1077 GNUNET_assert (th != NULL);
1078 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Connected to transport service\n");
1079 ch = GNUNET_CORE_connect (cfg, NULL,
1082 &core_disconnect_cb,
1083 &core_notify_receive_cb, GNUNET_NO,
1086 GNUNET_assert (ch != NULL);
1088 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup_task, NULL);
1094 * The main function.
1096 * @param argc number of arguments from the command line
1097 * @param argv command line arguments
1098 * @return 0 ok, 1 on error
1101 main (int argc, char *const *argv)
1104 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
1105 {'p', "ping", NULL, gettext_noop ("Send ping messages to test connectivity (default == NO)"),
1106 GNUNET_NO, &GNUNET_GETOPT_set_one, &ping},
1107 GNUNET_GETOPT_OPTION_END
1110 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
1113 GNUNET_PROGRAM_run (argc, argv, "cn",
1114 gettext_noop ("help text"), options, &run,
1116 GNUNET_free ((void*) argv);
1120 /* end of connection_watchdog.c */