2 This file is part of GNUnet.
3 Copyright (C) 2011, 2012, 2014 GNUnet e.V.
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., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
22 * @file core/gnunet-core.c
23 * @brief Print information about other peers known to CORE.
24 * @author Nathan Evans
27 #include "gnunet_util_lib.h"
28 #include "gnunet_core_service.h"
34 static int monitor_connections;
37 * Handle to the CORE monitor.
39 static struct GNUNET_CORE_MonitorHandle *mh;
43 * Task run in monitor mode when the user presses CTRL-C to abort.
44 * Stops monitoring activity.
49 shutdown_task (void *cls)
53 GNUNET_CORE_monitor_stop (mh);
60 * Function called to notify core users that another
61 * peer changed its state with us.
64 * @param peer the peer that changed state
65 * @param state new state of the peer
66 * @param timeout timeout for the new state
69 monitor_cb (void *cls,
70 const struct GNUNET_PeerIdentity *peer,
71 enum GNUNET_CORE_KxState state,
72 struct GNUNET_TIME_Absolute timeout)
74 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get();
76 const char *state_str;
78 if ( ( (NULL == peer) ||
79 (GNUNET_CORE_KX_ITERATION_FINISHED == state) ) &&
80 (GNUNET_NO == monitor_connections) )
82 GNUNET_SCHEDULER_shutdown ();
88 case GNUNET_CORE_KX_STATE_DOWN:
89 /* should never happen, as we immediately send the key */
90 state_str = _("fresh connection");
92 case GNUNET_CORE_KX_STATE_KEY_SENT:
93 state_str = _("key sent");
95 case GNUNET_CORE_KX_STATE_KEY_RECEIVED:
96 state_str = _("key received");
98 case GNUNET_CORE_KX_STATE_UP:
99 state_str = _("connection established");
101 case GNUNET_CORE_KX_STATE_REKEY_SENT:
102 state_str = _("rekeying");
104 case GNUNET_CORE_KX_PEER_DISCONNECT:
105 state_str = _("disconnected");
107 case GNUNET_CORE_KX_ITERATION_FINISHED:
109 case GNUNET_CORE_KX_CORE_DISCONNECT:
112 _("Connection to CORE service lost (reconnecting)"));
115 state_str = _("unknown state");
118 now_str = GNUNET_STRINGS_absolute_time_to_string (now);
120 _("%24s: %-30s %4s (timeout in %6s)\n"),
124 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_remaining (timeout),
130 * Main function that will be run by the scheduler.
133 * @param args remaining command-line arguments
134 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
135 * @param cfg configuration
138 run (void *cls, char *const *args, const char *cfgfile,
139 const struct GNUNET_CONFIGURATION_Handle *cfg)
144 _("Invalid command line argument `%s'\n"),
148 mh = GNUNET_CORE_monitor_start (cfg,
155 _("Failed to connect to CORE service!\n"));
158 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
163 * The main function to obtain peer information from CORE.
165 * @param argc number of arguments from the command line
166 * @param argv command line arguments
167 * @return 0 ok, 1 on error
174 struct GNUNET_GETOPT_CommandLineOption options[] = {
175 GNUNET_GETOPT_option_flag ('m',
177 gettext_noop ("provide information about all current connections (continuously)"),
178 &monitor_connections),
179 GNUNET_GETOPT_OPTION_END
182 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
184 res = GNUNET_PROGRAM_run (argc, argv, "gnunet-core",
186 ("Print information about connected peers."),
187 options, &run, NULL);
189 GNUNET_free ((void *) argv);
190 if (GNUNET_OK == res)
195 /* end of gnunet-core.c */