2 This file is part of GNUnet.
3 (C) 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 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
48 connect_cb (void *cls,
49 const struct GNUNET_PeerIdentity *peer,
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
67 const struct GNUNET_PeerIdentity *peer,
70 fprintf (stderr, "Change: %s at %u\n",
72 (unsigned int) distance);
77 * Function called if DV is no longer able to talk to a peer.
80 * @param peer peer that disconnected
83 disconnect_cb (void *cls,
84 const struct GNUNET_PeerIdentity *peer)
86 fprintf (stderr, "Disconnect: %s\n",
92 * Function called if DV receives a message for this peer.
95 * @param sender sender of the message
96 * @param distance how far did the message travel
97 * @param msg actual message payload
100 message_cb (void *cls,
101 const struct GNUNET_PeerIdentity *sender,
103 const struct GNUNET_MessageHeader *msg)
106 fprintf (stderr, "Message: %s at %u sends %u bytes of type %u\n",
108 (unsigned int) distance,
109 (unsigned int) ntohs (msg->size),
110 (unsigned int) ntohs (msg->type));
115 * Task run on shutdown.
121 shutdown_task (void *cls,
122 const struct GNUNET_SCHEDULER_TaskContext *tc)
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_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
147 &shutdown_task, NULL);
154 * @param argc number of arguments from the command line
155 * @param argv command line arguments
156 * @return 0 ok, 1 on error
159 main (int argc, char *const *argv)
163 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
164 {'V', "verbose", NULL,
165 gettext_noop ("verbose output"),
166 0, &GNUNET_GETOPT_set_one, &verbose},
167 GNUNET_GETOPT_OPTION_END
170 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
173 res = GNUNET_PROGRAM_run (argc, argv, "gnunet-dv",
174 gettext_noop ("Print information about DV state"),
177 GNUNET_free ((void *) argv);
179 if (GNUNET_OK != res)
184 /* end of gnunet-dv.c */