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)
234 /* Use netstat to get a numeric list of all connections on port 'port' in state 'ESTABLISHED' */
235 GNUNET_asprintf(&cmdline, "netstat -n %s | grep %u | grep ESTABLISHED", proto, port);
237 if (system ("netstat -n > /dev/null 2> /dev/null"))
238 if (system ("netstat -n > /dev/null 2> /dev/null") == 0)
239 f = popen (cmdline, "r");
243 f = popen (cmdline, "r");
246 GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "ss");
247 GNUNET_free (cmdline);
252 while (NULL != fgets (line, sizeof (line), f))
255 //printf ("%s", line);
259 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
260 "%i TCP connections established with port %u\n",
264 GNUNET_free (cmdline);
270 static struct TransportPlugin *
271 find_plugin (char * name)
273 struct TransportPlugin *cur = NULL;
275 for (cur = phead; cur != NULL; cur = cur->next)
277 if (0 == strcmp(name, cur->short_name))
284 stats_check_cb (void *cls, const char *subsystem,
285 const char *name, uint64_t value,
296 if ((STATS_VALUES == counter) || ((GNUNET_NO == have_tcp) && (STATS_VALUES - 1 == counter)))
298 int fail = GNUNET_NO;
302 int low_level_connections_udp = check_lowlevel_connections (2086, udp);
304 if (transport_connections != core_connections)
306 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
307 "%u transport notifications <-> %u core notifications\n",
308 transport_connections, core_connections);
312 if (transport_connections != statistics_transport_connections)
314 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
315 "%u transport notifications <-> %u in statistics (peers connected)\n",
316 transport_connections, statistics_transport_connections);
320 if (core_connections != statistics_core_entries_session_map)
322 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
323 "%u core notifications <-> %u in statistics (entries session map)\n",
324 core_connections, statistics_core_entries_session_map);
328 if (core_connections != statistics_core_neighbour_entries)
330 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
331 "%u core notifications <-> %u in statistics (neighbour entries allocated)\n",
332 core_connections, statistics_core_neighbour_entries);
336 if (GNUNET_NO == fail)
337 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
338 "Check successful : (%u transport / %u core) connections established\n", transport_connections, core_connections);
340 /* TCP plugin specific checks */
341 if (GNUNET_YES == have_tcp)
343 struct TransportPlugin * p = find_plugin ("tcp");
344 int low_level_connections_tcp = check_lowlevel_connections (p->port, p->protocol);
346 if (low_level_connections_tcp != -1)
348 if (statistics_transport_tcp_connections > low_level_connections_tcp)
350 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
351 "%u transport tcp sessions <-> %i established tcp connections\n",
352 statistics_transport_tcp_connections, low_level_connections_tcp);
354 else if (low_level_connections_tcp != -1)
356 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
357 "%u TCP connections, %u UDP connections \n",
358 low_level_connections_tcp, low_level_connections_udp);
361 if (transport_connections > statistics_transport_tcp_connections)
363 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
364 "%u transport notifications <-> %u in statistics (statistics_transport_tcp_connections)\n",
365 transport_connections, statistics_transport_tcp_connections);
369 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
370 " %u transport notifications <-> %u in statistics (statistics_transport_tcp_connections)\n",
371 transport_connections, statistics_transport_tcp_connections);
375 if (GNUNET_SCHEDULER_NO_TASK == statistics_task)
376 statistics_task = GNUNET_SCHEDULER_add_delayed(REPEATED_STATS_DELAY, &stats_check, NULL);
378 stat_check_running = GNUNET_NO;
385 GNUNET_NETWORK_STRUCT_BEGIN
389 struct GNUNET_MessageHeader header;
396 struct GNUNET_MessageHeader header;
400 GNUNET_NETWORK_STRUCT_END
404 send_transport_ping_cb (void *cls, size_t size, void *buf)
406 struct PeerContainer * pc = cls;
408 size_t mlen = sizeof (struct PING);
416 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
417 "Sending transport ping to `%s'\n", GNUNET_i2s (&pc->id));
418 ping.header.size = htons (mlen);
419 ping.header.type = htons (1234);
420 ping.src = htons (0);
424 memcpy (buf, &ping, mlen);
430 send_core_ping_cb (void *cls, size_t size, void *buf)
432 struct PeerContainer * pc = cls;
434 size_t mlen = sizeof (struct PING);
442 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
443 "Sending core ping to `%s'\n", GNUNET_i2s (&pc->id));
444 ping.header.size = htons (mlen);
445 ping.header.type = htons (1234);
446 ping.src = htons (1);
450 memcpy (buf, &ping, mlen);
456 map_ping_it (void *cls,
457 const struct GNUNET_HashCode * key,
460 struct PeerContainer *pc = value;
462 if (ping == GNUNET_YES)
464 if ((GNUNET_YES == pc->transport_connected) && (NULL == pc->th_ping))
465 pc->th_ping = GNUNET_TRANSPORT_notify_transmit_ready(th, &pc->id,
466 sizeof (struct PING), UINT_MAX,
467 GNUNET_TIME_UNIT_FOREVER_REL, &send_transport_ping_cb, pc);
471 if ((GNUNET_YES == pc->core_connected) && (NULL == pc->ch_ping))
472 pc->ch_ping = GNUNET_CORE_notify_transmit_ready(ch,
474 GNUNET_TIME_UNIT_FOREVER_REL,
476 sizeof (struct PING),
477 send_core_ping_cb, pc);
486 stats_check (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
488 statistics_task = GNUNET_SCHEDULER_NO_TASK;
490 if (GNUNET_YES == stat_check_running)
492 statistics_task = GNUNET_SCHEDULER_add_delayed(STATS_DELAY, &stats_check, NULL);
495 GNUNET_CONTAINER_multihashmap_iterate (peers, &map_ping_it, NULL);
497 stat_check_running = GNUNET_YES;
499 statistics_transport_connections = 0 ;
500 statistics_core_entries_session_map = 0;
501 statistics_core_neighbour_entries = 0;
503 GNUNET_STATISTICS_get (stats, "transport", "# peers connected", GNUNET_TIME_UNIT_MINUTES, NULL, &stats_check_cb, &statistics_transport_connections);
504 GNUNET_STATISTICS_get (stats, "core", "# neighbour entries allocated", GNUNET_TIME_UNIT_MINUTES, NULL, &stats_check_cb, &statistics_core_neighbour_entries);
505 GNUNET_STATISTICS_get (stats, "core", "# peers connected", GNUNET_TIME_UNIT_MINUTES, NULL, &stats_check_cb, &statistics_core_entries_session_map);
507 /* TCP plugin specific checks */
508 if (GNUNET_YES == have_tcp)
509 GNUNET_STATISTICS_get (stats, "transport", "# TCP sessions active", GNUNET_TIME_UNIT_MINUTES, NULL, &stats_check_cb, &statistics_transport_tcp_connections);
514 send_transport_pong_cb (void *cls, size_t size, void *buf)
516 struct PeerContainer * pc = cls;
518 size_t mlen = sizeof (struct PING);
526 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
527 "Sending transport pong to `%s'\n", GNUNET_i2s (&pc->id));
528 ping.header.size = htons (mlen);
529 ping.header.type = htons (4321);
530 ping.src = htons (0);
534 memcpy (buf, &ping, mlen);
540 send_core_pong_cb (void *cls, size_t size, void *buf)
542 struct PeerContainer * pc = cls;
544 size_t mlen = sizeof (struct PING);
552 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
553 "Sending core pong to `%s'\n", GNUNET_i2s (&pc->id));
554 ping.header.size = htons (mlen);
555 ping.header.type = htons (4321);
556 ping.src = htons (1);
560 memcpy (buf, &ping, mlen);
566 map_connect (const struct GNUNET_PeerIdentity *peer, void * source)
568 struct PeerContainer * pc;
569 if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains(peers, &peer->hashPubKey))
571 pc = GNUNET_malloc (sizeof (struct PeerContainer));
573 pc->core_connected = GNUNET_NO;
574 pc->transport_connected = GNUNET_NO;
575 GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put(peers, &peer->hashPubKey, pc, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
578 pc = GNUNET_CONTAINER_multihashmap_get(peers, &peer->hashPubKey);
579 GNUNET_assert (NULL != pc);
583 if (GNUNET_NO == pc->transport_connected)
585 pc->transport_connected = GNUNET_YES;
586 if (GNUNET_YES == ping)
588 if (NULL == pc->th_ping)
589 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);
596 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
597 "%s notified multiple times about for peers `%s' (%s : %s)\n",
599 GNUNET_i2s (&pc->id),
600 "CORE", (pc->core_connected == GNUNET_YES) ? "yes" : "no");
606 if (GNUNET_NO == pc->core_connected)
608 pc->core_connected = GNUNET_YES;
609 if (GNUNET_YES == ping)
611 if (NULL == pc->ch_ping)
612 pc->ch_ping = GNUNET_CORE_notify_transmit_ready(ch,
614 GNUNET_TIME_UNIT_FOREVER_REL,
616 sizeof (struct PING),
617 send_core_ping_cb, pc);
624 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
625 "%s notified multiple times about for peers `%s' (%s : %s)\n",
627 GNUNET_i2s (&pc->id),
628 "TRANSPORT", (pc->transport_connected == GNUNET_YES) ? "yes" : "no");
632 if (GNUNET_SCHEDULER_NO_TASK != check_task)
633 GNUNET_SCHEDULER_cancel(check_task);
634 check_task = GNUNET_SCHEDULER_add_delayed(CHECK_DELAY, &map_check, NULL);
636 if (GNUNET_SCHEDULER_NO_TASK != statistics_task)
637 GNUNET_SCHEDULER_cancel(statistics_task);
638 statistics_task = GNUNET_SCHEDULER_add_delayed(STATS_DELAY, &stats_check, NULL);
643 map_disconnect (const struct GNUNET_PeerIdentity * peer, void * source)
646 struct PeerContainer * pc;
647 if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains(peers, &peer->hashPubKey))
651 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
652 "%s disconnect notification for unknown peer `%s'\n",
653 "TRANSPORT", GNUNET_i2s (peer));
659 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
660 "%s disconnect notification for unknown peer `%s'\n",
661 "CORE", GNUNET_i2s (peer));
666 pc = GNUNET_CONTAINER_multihashmap_get(peers, &peer->hashPubKey);
667 GNUNET_assert (NULL != pc);
671 if (NULL != pc->th_ping)
673 GNUNET_TRANSPORT_notify_transmit_ready_cancel(pc->th_ping);
676 if (NULL != pc->th_pong)
678 GNUNET_TRANSPORT_notify_transmit_ready_cancel(pc->th_pong);
682 if (GNUNET_YES == pc->transport_connected)
684 pc->transport_connected = GNUNET_NO;
688 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
689 "%s notified for not connected peer `%s' (%s : %s)\n",
691 GNUNET_i2s (&pc->id),
692 "CORE", (pc->core_connected == GNUNET_YES) ? "yes" : "no");
698 if (NULL != pc->ch_ping)
700 GNUNET_CORE_notify_transmit_ready_cancel (pc->ch_ping);
703 if (NULL != pc->ch_pong)
705 GNUNET_CORE_notify_transmit_ready_cancel (pc->ch_pong);
709 if (GNUNET_YES == pc->core_connected)
711 pc->core_connected = GNUNET_NO;
715 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
716 "%s notified for not connected peer `%s' (%s : %s)\n",
718 GNUNET_i2s (&pc->id),
719 "TRANSPORT", (pc->transport_connected == GNUNET_YES) ? "yes" : "no");
724 if ((GNUNET_NO == pc->core_connected) && (GNUNET_NO == pc->transport_connected))
726 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Removing peer `%s'\n", GNUNET_i2s (&pc->id));
727 GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_remove (peers, &peer->hashPubKey, pc));
733 if (GNUNET_SCHEDULER_NO_TASK != check_task)
734 GNUNET_SCHEDULER_cancel(check_task);
735 check_task = GNUNET_SCHEDULER_add_delayed(CHECK_DELAY, &map_check, NULL);
737 if (GNUNET_SCHEDULER_NO_TASK != statistics_task)
738 GNUNET_SCHEDULER_cancel(statistics_task);
739 statistics_task = GNUNET_SCHEDULER_add_delayed(STATS_DELAY, &stats_check, NULL);
744 cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
746 struct TransportPlugin *cur;
750 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
751 "Disconnecting from transport service\n");
752 GNUNET_TRANSPORT_disconnect (th);
759 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
760 "Disconnecting from core service\n");
761 GNUNET_CORE_disconnect (ch);
765 if (GNUNET_SCHEDULER_NO_TASK != statistics_task)
767 GNUNET_SCHEDULER_cancel(statistics_task);
768 statistics_task = GNUNET_SCHEDULER_NO_TASK;
771 if (GNUNET_SCHEDULER_NO_TASK != check_task)
773 GNUNET_SCHEDULER_cancel(check_task);
774 check_task = GNUNET_SCHEDULER_NO_TASK;
777 for (cur = phead; NULL != cur; cur = phead)
779 GNUNET_CONTAINER_DLL_remove(phead, ptail, cur);
780 GNUNET_free (cur->short_name);
784 check_task = GNUNET_SCHEDULER_add_now (&map_check, &map_cleanup);
789 transport_notify_connect_cb (void *cls,
790 const struct GNUNET_PeerIdentity* peer)
792 transport_connections ++;
793 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
794 "TRANSPORT connect for peer `%s' (%u total)\n",
796 transport_connections);
797 map_connect (peer, th);
802 * Function called to notify transport users that another
803 * peer disconnected from us.
806 * @param peer the peer that disconnected
809 transport_notify_disconnect_cb (void *cls,
810 const struct GNUNET_PeerIdentity *peer)
812 GNUNET_assert (transport_connections > 0);
813 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
814 "TRANSPORT disconnect for peer `%s' (%u total)\n",
816 transport_connections);
817 map_disconnect (peer, th);
818 transport_connections --;
823 transport_notify_receive_cb (void *cls,
825 GNUNET_PeerIdentity * peer,
827 GNUNET_MessageHeader *
830 struct PeerContainer *pc;
832 pc = GNUNET_CONTAINER_multihashmap_get (peers, &peer->hashPubKey);
839 if ((message->size == ntohs (sizeof (struct PING))) &&
840 (message->type == ntohs (1234)))
842 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
843 "Received %s %s from peer `%s'\n",
847 if (GNUNET_YES == ping)
849 if (NULL == pc->th_pong)
850 pc->th_pong = GNUNET_TRANSPORT_notify_transmit_ready(th,
851 peer, sizeof (struct PONG),
852 UINT_MAX, GNUNET_TIME_UNIT_FOREVER_REL,
853 &send_transport_pong_cb, pc);
859 if ((message->size == ntohs (sizeof (struct PONG))) && (message->type == ntohs (4321)))
861 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Received %s %s from peer `%s'\n",
869 core_notify_receive_cb (void *cls,
870 const struct GNUNET_PeerIdentity * peer,
871 const struct GNUNET_MessageHeader * message)
873 struct PeerContainer *pc = NULL;
875 pc = GNUNET_CONTAINER_multihashmap_get(peers, &peer->hashPubKey);
879 if (0 == memcmp (peer, &my_peer_id, sizeof (my_peer_id)))
882 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Received unexpected message type %u from unknown peer `%s'\n",
883 ntohs (message->type),
890 if ((message->size == ntohs (sizeof (struct PING))) && (message->type == ntohs (1234)))
892 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Received %s %s from peer `%s'\n",
896 if (GNUNET_YES == ping)
898 if (NULL == pc->ch_pong)
899 pc->ch_pong = GNUNET_CORE_notify_transmit_ready(ch,
901 GNUNET_TIME_UNIT_FOREVER_REL,
903 sizeof (struct PONG),
904 send_core_pong_cb, pc);
910 if ((message->size == ntohs (sizeof (struct PONG))) && (message->type == ntohs (4321)))
912 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Received %s %s from peer `%s'\n",
923 core_connect_cb (void *cls, const struct GNUNET_PeerIdentity *peer)
925 if (0 != memcmp (peer, &my_peer_id, sizeof (struct GNUNET_PeerIdentity)))
928 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "CORE connect for peer `%s' (%u total)\n",
929 GNUNET_i2s (peer), core_connections);
930 map_connect (peer, ch);
934 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "CORE connect for myself `%s' (%u total)\n",
935 GNUNET_i2s (peer), core_connections);
940 core_disconnect_cb (void *cls,
942 GNUNET_PeerIdentity * peer)
944 if (0 != memcmp (peer, &my_peer_id, sizeof (struct GNUNET_PeerIdentity)))
946 GNUNET_assert (core_connections > 0);
947 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "CORE disconnect for peer `%s' (%u total)\n",
948 GNUNET_i2s (peer), core_connections);
949 map_disconnect (peer, ch);
954 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "CORE disconnect for myself `%s' (%u total)\n",
955 GNUNET_i2s (peer), core_connections);
961 core_init_cb (void *cls,
962 const struct GNUNET_PeerIdentity *my_identity)
964 my_peer_id = *my_identity;
965 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Connected to core service\n");
972 struct TransportPlugin * cur;
977 unsigned long long port;
979 have_tcp = GNUNET_NO;
980 have_udp = GNUNET_NO;
981 have_http = GNUNET_NO;
982 have_https = GNUNET_NO;
983 have_unix = GNUNET_NO;
985 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (mycfg, "TRANSPORT", "PLUGINS", &plugs))
988 for (pos = strtok (plugs, " "); pos != NULL; pos = strtok (NULL, " "))
992 GNUNET_asprintf(&secname, "transport-%s", pos);
994 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (mycfg, secname, "PORT", &port))
996 GNUNET_free (secname);
1000 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Transport plugin: `%s' port %llu\n"), pos, port);
1001 cur = GNUNET_malloc(sizeof (struct TransportPlugin));
1002 cur->short_name = GNUNET_strdup (pos);
1004 if (0 == strcmp("tcp", pos))
1006 have_tcp = GNUNET_YES;
1007 cur->protocol = tcp;
1009 if (0 == strcmp("udp", pos))
1011 have_udp = GNUNET_YES;
1012 cur->protocol = udp;
1014 if (0 == strcmp("http", pos))
1016 have_http = GNUNET_YES;
1017 cur->protocol = tcp;
1019 if (0 == strcmp("https", pos))
1021 have_https = GNUNET_YES;
1022 cur->protocol = tcp;
1024 if (0 == strcmp("unix", pos))
1026 have_unix = GNUNET_YES;
1027 cur->protocol = unixdomain;
1030 GNUNET_CONTAINER_DLL_insert(phead, ptail, cur);
1031 GNUNET_free (secname);
1033 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Found %u transport plugins: `%s'\n"),
1036 GNUNET_free (plugs);
1041 * Main function that will be run by the scheduler.
1043 * @param cls closure
1044 * @param args remaining command-line arguments
1045 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
1046 * @param cfg configuration
1049 run (void *cls, char *const *args, const char *cfgfile,
1050 const struct GNUNET_CONFIGURATION_Handle *cfg)
1052 transport_connections = 0;
1053 core_connections = 0;
1058 stats = GNUNET_STATISTICS_create ("watchdog", cfg);
1059 peers = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_NO);
1061 th = GNUNET_TRANSPORT_connect(cfg, NULL, NULL,
1062 &transport_notify_receive_cb,
1063 &transport_notify_connect_cb,
1064 &transport_notify_disconnect_cb);
1065 GNUNET_assert (th != NULL);
1066 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Connected to transport service\n");
1067 ch = GNUNET_CORE_connect (cfg, NULL,
1070 &core_disconnect_cb,
1071 &core_notify_receive_cb, GNUNET_NO,
1074 GNUNET_assert (ch != NULL);
1076 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup_task, NULL);
1082 * The main function.
1084 * @param argc number of arguments from the command line
1085 * @param argv command line arguments
1086 * @return 0 ok, 1 on error
1089 main (int argc, char *const *argv)
1092 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
1093 {'p', "ping", NULL, gettext_noop ("Send ping messages to test connectivity (default == NO)"),
1094 GNUNET_NO, &GNUNET_GETOPT_set_one, &ping},
1095 GNUNET_GETOPT_OPTION_END
1098 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
1101 GNUNET_PROGRAM_run (argc, argv, "cn",
1102 gettext_noop ("help text"), options, &run,
1104 GNUNET_free ((void*) argv);
1108 /* end of connection_watchdog.c */