2 This file is part of GNUnet.
3 Copyright (C) 2013 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your 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 Affero General Public License for more details.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 * @file dv/gnunet-dv.c
20 * @brief DV monitoring command line tool
21 * @author Christian Grothoff
24 #include "gnunet_util_lib.h"
25 #include "gnunet_dv_service.h"
28 * Handle to DV service.
30 static struct GNUNET_DV_ServiceHandle *sh;
33 * Was verbose specified?
35 static unsigned int verbose;
39 * Function called if DV starts to be able to talk to a peer.
42 * @param peer newly connected peer
43 * @param distance distance to the peer
44 * @param network the network the next hop is located in
47 connect_cb (void *cls,
48 const struct GNUNET_PeerIdentity *peer,
50 enum GNUNET_ATS_Network_Type network)
52 fprintf (stderr, "Connect: %s at %u\n",
54 (unsigned int) distance);
59 * Function called if DV distance to a peer is changed.
62 * @param peer connected peer
63 * @param distance new distance to the peer
64 * @param network network used on first hop to peer
68 const struct GNUNET_PeerIdentity *peer,
70 enum GNUNET_ATS_Network_Type network)
72 fprintf (stderr, "Change: %s at %u\n",
74 (unsigned int) distance);
79 * Function called if DV is no longer able to talk to a peer.
82 * @param peer peer that disconnected
85 disconnect_cb (void *cls,
86 const struct GNUNET_PeerIdentity *peer)
88 fprintf (stderr, "Disconnect: %s\n",
94 * Function called if DV receives a message for this peer.
97 * @param sender sender of the message
98 * @param distance how far did the message travel
99 * @param msg actual message payload
102 message_cb (void *cls,
103 const struct GNUNET_PeerIdentity *sender,
105 const struct GNUNET_MessageHeader *msg)
108 fprintf (stderr, "Message: %s at %u sends %u bytes of type %u\n",
110 (unsigned int) distance,
111 (unsigned int) ntohs (msg->size),
112 (unsigned int) ntohs (msg->type));
117 * Task run on shutdown.
122 shutdown_task (void *cls)
124 GNUNET_DV_service_disconnect (sh);
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)
141 sh = GNUNET_DV_service_connect (cfg, NULL,
146 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
153 * @param argc number of arguments from the command line
154 * @param argv command line arguments
155 * @return 0 ok, 1 on error
158 main (int argc, char *const *argv)
162 struct GNUNET_GETOPT_CommandLineOption options[] = {
164 GNUNET_GETOPT_option_verbose (&verbose),
166 GNUNET_GETOPT_OPTION_END
169 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
172 res = GNUNET_PROGRAM_run (argc, argv, "gnunet-dv",
173 gettext_noop ("Print information about DV state"),
176 GNUNET_free ((void *) argv);
178 if (GNUNET_OK != res)
183 /* end of gnunet-dv.c */