aboutsummaryrefslogtreecommitdiff
path: root/src/dv/gnunet-dv.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/dv/gnunet-dv.c')
-rw-r--r--src/dv/gnunet-dv.c185
1 files changed, 0 insertions, 185 deletions
diff --git a/src/dv/gnunet-dv.c b/src/dv/gnunet-dv.c
deleted file mode 100644
index 90d8144e5..000000000
--- a/src/dv/gnunet-dv.c
+++ /dev/null
@@ -1,185 +0,0 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2013 GNUnet e.V.
4
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.
9
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.
14
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/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19*/
20/**
21 * @file dv/gnunet-dv.c
22 * @brief DV monitoring command line tool
23 * @author Christian Grothoff
24 */
25#include "platform.h"
26#include "gnunet_util_lib.h"
27#include "gnunet_dv_service.h"
28
29/**
30 * Handle to DV service.
31 */
32static struct GNUNET_DV_ServiceHandle *sh;
33
34/**
35 * Was verbose specified?
36 */
37static unsigned int verbose;
38
39
40/**
41 * Function called if DV starts to be able to talk to a peer.
42 *
43 * @param cls closure
44 * @param peer newly connected peer
45 * @param distance distance to the peer
46 * @param network the network the next hop is located in
47 */
48static void
49connect_cb (void *cls,
50 const struct GNUNET_PeerIdentity *peer,
51 uint32_t distance,
52 enum GNUNET_NetworkType network)
53{
54 fprintf (stderr, "Connect: %s at %u\n",
55 GNUNET_i2s (peer),
56 (unsigned int) distance);
57}
58
59
60/**
61 * Function called if DV distance to a peer is changed.
62 *
63 * @param cls closure
64 * @param peer connected peer
65 * @param distance new distance to the peer
66 * @param network network used on first hop to peer
67 */
68static void
69change_cb (void *cls,
70 const struct GNUNET_PeerIdentity *peer,
71 uint32_t distance,
72 enum GNUNET_NetworkType network)
73{
74 fprintf (stderr, "Change: %s at %u\n",
75 GNUNET_i2s (peer),
76 (unsigned int) distance);
77}
78
79
80/**
81 * Function called if DV is no longer able to talk to a peer.
82 *
83 * @param cls closure
84 * @param peer peer that disconnected
85 */
86static void
87disconnect_cb (void *cls,
88 const struct GNUNET_PeerIdentity *peer)
89{
90 fprintf (stderr, "Disconnect: %s\n",
91 GNUNET_i2s (peer));
92}
93
94
95/**
96 * Function called if DV receives a message for this peer.
97 *
98 * @param cls closure
99 * @param sender sender of the message
100 * @param distance how far did the message travel
101 * @param msg actual message payload
102 */
103static void
104message_cb (void *cls,
105 const struct GNUNET_PeerIdentity *sender,
106 uint32_t distance,
107 const struct GNUNET_MessageHeader *msg)
108{
109 if (verbose)
110 fprintf (stderr, "Message: %s at %u sends %u bytes of type %u\n",
111 GNUNET_i2s (sender),
112 (unsigned int) distance,
113 (unsigned int) ntohs (msg->size),
114 (unsigned int) ntohs (msg->type));
115}
116
117
118/**
119 * Task run on shutdown.
120 *
121 * @param cls NULL
122 */
123static void
124shutdown_task (void *cls)
125{
126 GNUNET_DV_service_disconnect (sh);
127 sh = NULL;
128}
129
130
131/**
132 * Main function that will be run by the scheduler.
133 *
134 * @param cls closure
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
138 */
139static void
140run (void *cls, char *const *args, const char *cfgfile,
141 const struct GNUNET_CONFIGURATION_Handle *cfg)
142{
143 sh = GNUNET_DV_service_connect (cfg, NULL,
144 &connect_cb,
145 &change_cb,
146 &disconnect_cb,
147 &message_cb);
148 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
149}
150
151
152/**
153 * The main function.
154 *
155 * @param argc number of arguments from the command line
156 * @param argv command line arguments
157 * @return 0 ok, 1 on error
158 */
159int
160main (int argc, char *const *argv)
161{
162 int res;
163
164 struct GNUNET_GETOPT_CommandLineOption options[] = {
165
166 GNUNET_GETOPT_option_verbose (&verbose),
167
168 GNUNET_GETOPT_OPTION_END
169 };
170
171 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
172 return 2;
173
174 res = GNUNET_PROGRAM_run (argc, argv, "gnunet-dv",
175 gettext_noop ("Print information about DV state"),
176 options, &run,
177 NULL);
178 GNUNET_free ((void *) argv);
179
180 if (GNUNET_OK != res)
181 return 1;
182 return 0;
183}
184
185/* end of gnunet-dv.c */