2 This file is part of GNUnet.
3 (C) 2012 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.
22 * @file mesh/gnunet-mesh.c
23 * @brief Print information about mesh tunnels and peers.
24 * @author Bartlomiej Polot
27 #include "gnunet_util_lib.h"
28 #include "gnunet_mesh_service.h"
34 static int monitor_connections;
44 static char *tunnel_id;
54 static char *channel_id;
57 * Port to listen on (-p).
59 static uint32_t listen_port;
64 static char *target_id;
69 static uint32_t target_port;
74 static struct GNUNET_MESH_Handle *mh;
77 * Shutdown task handle.
79 GNUNET_SCHEDULER_TaskIdentifier sd;
82 * Task run in monitor mode when the user presses CTRL-C to abort.
83 * Stops monitoring activity.
85 * @param cls Closure (unused).
86 * @param tc scheduler context
89 shutdown_task (void *cls,
90 const struct GNUNET_SCHEDULER_TaskContext *tc)
94 GNUNET_MESH_disconnect (mh);
101 * Method called to retrieve information about each tunnel the mesh peer
104 * @param cls Closure.
105 * @param tunnel_number Tunnel number.
106 * @param origin that started the tunnel (owner).
107 * @param target other endpoint of the tunnel
109 void /* FIXME static */
110 tunnels_callback (void *cls,
111 uint32_t tunnel_number,
112 const struct GNUNET_PeerIdentity *origin,
113 const struct GNUNET_PeerIdentity *target)
115 fprintf (stdout, "Tunnel %s [%u]\n",
116 GNUNET_i2s_full (origin), tunnel_number);
117 fprintf (stdout, "\n");
122 * Method called to retrieve information about each tunnel the mesh peer
125 * @param cls Closure.
126 * @param peer Peer in the tunnel's tree.
127 * @param parent Parent of the current peer. All 0 when peer is root.
130 void /* FIXME static */
131 tunnel_callback (void *cls,
132 const struct GNUNET_PeerIdentity *peer,
133 const struct GNUNET_PeerIdentity *parent)
139 * Call MESH's monitor API, get all tunnels known to peer.
141 * @param cls Closure (unused).
142 * @param tc TaskContext
145 get_tunnels (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
147 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
151 // GNUNET_MESH_get_tunnels (mh, &tunnels_callback, NULL);
152 if (GNUNET_YES != monitor_connections)
154 GNUNET_SCHEDULER_shutdown();
160 * Call MESH's monitor API, get info of one tunnel.
162 * @param cls Closure (unused).
163 * @param tc TaskContext
166 show_tunnel (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
168 struct GNUNET_PeerIdentity pid;
171 GNUNET_CRYPTO_eddsa_public_key_from_string (tunnel_id,
176 _("Invalid tunnel owner `%s'\n"),
178 GNUNET_SCHEDULER_shutdown();
181 // GNUNET_MESH_show_tunnel (mh, &pid, 0, tunnel_callback, NULL);
186 * Main function that will be run by the scheduler.
189 * @param args remaining command-line arguments
190 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
191 * @param cfg configuration
194 run (void *cls, char *const *args, const char *cfgfile,
195 const struct GNUNET_CONFIGURATION_Handle *cfg)
197 static const struct GNUNET_MESH_MessageHandler handlers[] = {
198 {NULL, 0, 0} /* FIXME add option to monitor msg types */
200 /* FIXME add option to monitor apps */
202 for (i = 0; args[i]; i++)
204 FPRINTF (stderr, "Parameter %u `%s'\n", i, args[i]);
208 target_port = args[0] && args[1] ? atoi(args[1]) : 0;
210 || 0 != monitor_connections
213 || NULL != channel_id)
214 && target_id != NULL)
216 FPRINTF (stderr, _("You must NOT give a TARGET when using options\n"));
219 mh = GNUNET_MESH_connect (cfg,
221 NULL, /* new tunnel */
226 GNUNET_SCHEDULER_add_now (shutdown_task, NULL);
228 sd = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
229 shutdown_task, NULL);
231 if (NULL != tunnel_id)
232 GNUNET_SCHEDULER_add_now (&show_tunnel, NULL);
234 GNUNET_SCHEDULER_add_now (&get_tunnels, NULL);
239 * The main function to obtain peer information.
241 * @param argc number of arguments from the command line
242 * @param argv command line arguments
243 * @return 0 ok, 1 on error
246 main (int argc, char *const *argv)
249 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
250 {'m', "monitor", NULL,
251 gettext_noop ("provide information about all tunnels (continuously) NOT IMPLEMENTED"), /* FIXME */
252 GNUNET_NO, &GNUNET_GETOPT_set_one, &monitor_connections},
254 gettext_noop ("provide information about all tunnels"),
255 GNUNET_NO, &GNUNET_GETOPT_set_one, &get_info},
257 gettext_noop ("listen on this port"),
258 GNUNET_NO, &GNUNET_GETOPT_set_uint, &listen_port},
259 {'t', "tunnel", "TUNNEL_ID",
260 gettext_noop ("provide information about a particular tunnel"),
261 GNUNET_YES, &GNUNET_GETOPT_set_string, &tunnel_id},
262 {'n', "connection", "TUNNEL_ID:CONNECTION_ID",
263 gettext_noop ("provide information about a particular connection"),
264 GNUNET_YES, &GNUNET_GETOPT_set_string, &conn_id},
265 {'a', "channel", "TUNNEL_ID:CHANNEL_ID",
266 gettext_noop ("provide information about a particular channel"),
267 GNUNET_YES, &GNUNET_GETOPT_set_string, &channel_id},
268 GNUNET_GETOPT_OPTION_END
271 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
274 res = GNUNET_PROGRAM_run (argc, argv, "gnunet-mesh (OPTIONS | TARGET PORT)",
276 ("Create channels and retreive info about meshs status."),
277 options, &run, NULL);
279 GNUNET_free ((void *) argv);
281 if (GNUNET_OK == res)
287 /* end of gnunet-mesh.c */