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
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.
21 * @file dv/gnunet-dv.c
22 * @brief DV monitoring command line tool
23 * @author Christian Grothoff
26 #include "gnunet_util_lib.h"
27 #include "gnunet_dv_service.h"
30 * Handle to DV service.
32 static struct GNUNET_DV_ServiceHandle *sh;
35 * Was verbose specified?
41 * Function called if DV starts to be able to talk to a peer.
44 * @param peer newly connected peer
45 * @param distance distance to the peer
46 * @param network the network the next hop is located in
49 connect_cb (void *cls,
50 const struct GNUNET_PeerIdentity *peer,
52 enum GNUNET_ATS_Network_Type network)
54 fprintf (stderr, "Connect: %s at %u\n",
56 (unsigned int) distance);
61 * Function called if DV distance to a peer is changed.
64 * @param peer connected peer
65 * @param distance new distance to the peer
66 * @param network network used on first hop to peer
70 const struct GNUNET_PeerIdentity *peer,
72 enum GNUNET_ATS_Network_Type network)
74 fprintf (stderr, "Change: %s at %u\n",
76 (unsigned int) distance);
81 * Function called if DV is no longer able to talk to a peer.
84 * @param peer peer that disconnected
87 disconnect_cb (void *cls,
88 const struct GNUNET_PeerIdentity *peer)
90 fprintf (stderr, "Disconnect: %s\n",
96 * Function called if DV receives a message for this peer.
99 * @param sender sender of the message
100 * @param distance how far did the message travel
101 * @param msg actual message payload
104 message_cb (void *cls,
105 const struct GNUNET_PeerIdentity *sender,
107 const struct GNUNET_MessageHeader *msg)
110 fprintf (stderr, "Message: %s at %u sends %u bytes of type %u\n",
112 (unsigned int) distance,
113 (unsigned int) ntohs (msg->size),
114 (unsigned int) ntohs (msg->type));
119 * Task run on shutdown.
124 shutdown_task (void *cls)
126 GNUNET_DV_service_disconnect (sh);
132 * Main function that will be run by the scheduler.
135 * @param args remaining command-line arguments
136 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
137 * @param cfg configuration
140 run (void *cls, char *const *args, const char *cfgfile,
141 const struct GNUNET_CONFIGURATION_Handle *cfg)
143 sh = GNUNET_DV_service_connect (cfg, NULL,
148 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
155 * @param argc number of arguments from the command line
156 * @param argv command line arguments
157 * @return 0 ok, 1 on error
160 main (int argc, char *const *argv)
164 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
165 {'V', "verbose", NULL,
166 gettext_noop ("verbose output"),
167 0, &GNUNET_GETOPT_set_one, &verbose},
168 GNUNET_GETOPT_OPTION_END
171 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
174 res = GNUNET_PROGRAM_run (argc, argv, "gnunet-dv",
175 gettext_noop ("Print information about DV state"),
178 GNUNET_free ((void *) argv);
180 if (GNUNET_OK != res)
185 /* end of gnunet-dv.c */