static int monitor_connections;
/**
- * Option -i.
+ * Option -P.
*/
-static int get_info;
+static int request_peers;
+
+/**
+ * Option -T.
+ */
+static int request_tunnels;
/**
* Option --tunnel
shutdown_task (void *cls,
const struct GNUNET_SCHEDULER_TaskContext *tc)
{
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown\n");
if (NULL != ch)
{
GNUNET_MESH_channel_destroy (ch);
}
+/**
+ * Method called to retrieve information about all peers in MESH, called
+ * once per peer.
+ *
+ * After last peer has been reported, an additional call with NULL is done.
+ *
+ * @param cls Closure.
+ * @param peer Peer, or NULL on "EOF".
+ * @param tunnel Do we have a tunnel towards this peer?
+ * @param n_paths Number of known paths towards this peer.
+ * @param best_path How long is the best path?
+ * (0 = unknown, 1 = ourselves, 2 = neighbor)
+ */
+static void
+peers_callback (void *cls, const struct GNUNET_PeerIdentity *peer,
+ int tunnel, unsigned int n_paths, unsigned int best_path)
+{
+ if (NULL == peer)
+ {
+ if (GNUNET_YES != monitor_connections)
+ {
+ GNUNET_SCHEDULER_shutdown();
+ }
+ return;
+ }
+ FPRINTF (stdout, "%s tunnel: %c, paths: %u\n",
+ GNUNET_i2s_full (peer), tunnel ? 'Y' : 'N', n_paths);
+}
+
+
/**
* Method called to retrieve information about all tunnels in MESH.
*
const struct GNUNET_PeerIdentity *peer,
unsigned int channels,
unsigned int connections,
- unsigned int estate,
- unsigned int cstate)
+ uint16_t estate,
+ uint16_t cstate)
{
- FPRINTF (stdout, "%s [%u, %u] CH: %u, C: %u\n",
+ if (NULL == peer)
+ {
+ if (GNUNET_YES != monitor_connections)
+ {
+ GNUNET_SCHEDULER_shutdown();
+ }
+ return;
+ }
+ FPRINTF (stdout, "%s [ENC: %u, CON: %u] CHs: %u, CONNs: %u\n",
GNUNET_i2s_full (peer), estate, cstate, channels, connections);
}
*
* @param cls Closure.
* @param peer Peer towards whom the tunnel is directed.
- * @param channels Number of channels.
- * @param connections Number of connections.
+ * @param n_channels Number of channels.
+ * @param n_connections Number of connections.
+ * @param channels Channels.
+ * @param connections Connections.
* @param estate Encryption status.
* @param cstate Connectivity status.
*/
void
tunnel_callback (void *cls,
const struct GNUNET_PeerIdentity *peer,
- unsigned int channels,
- unsigned int connections,
+ unsigned int n_channels,
+ unsigned int n_connections,
+ uint32_t *channels,
+ struct GNUNET_HashCode *connections,
unsigned int estate,
unsigned int cstate)
{
- FPRINTF (stdout, "Tunnel %s\n", GNUNET_i2s_full (peer));
- FPRINTF (stdout, "- %u channels\n", channels);
- FPRINTF (stdout, "- %u connections\n", connections);
- FPRINTF (stdout, "- enc state: %u\n", estate);
- FPRINTF (stdout, "- con state: %u\n", cstate);
+ unsigned int i;
+
+ if (NULL != peer)
+ {
+ FPRINTF (stdout, "Tunnel %s\n", GNUNET_i2s_full (peer));
+ FPRINTF (stdout, "- %u channels\n", n_channels);
+ for (i = 0; i < n_channels; i++)
+ FPRINTF (stdout, " %u\n", channels[i]);
+ FPRINTF (stdout, "- %u connections\n", n_connections);
+ for (i = 0; i < n_connections; i++)
+ FPRINTF (stdout, " %s\n", GNUNET_h2s_full (&connections[i]));
+ FPRINTF (stdout, "- enc state: %u\n", estate);
+ FPRINTF (stdout, "- con state: %u\n", cstate);
+ }
+ if (GNUNET_YES != monitor_connections)
+ {
+ GNUNET_SCHEDULER_shutdown();
+ }
+ return;
+
}
/**
- * Call MESH's monitor API, get all tunnels known to peer.
+ * Call MESH's meta API, get all peers known to a peer.
*
* @param cls Closure (unused).
* @param tc TaskContext
*/
static void
-get_tunnels (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+get_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
{
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown\n");
return;
}
- GNUNET_MESH_get_tunnels (mh, &tunnels_callback, NULL);
- if (GNUNET_YES != monitor_connections)
+ GNUNET_MESH_get_peers (mh, &peers_callback, NULL);
+}
+
+/**
+ * Call MESH's meta API, get all tunnels known to a peer.
+ *
+ * @param cls Closure (unused).
+ * @param tc TaskContext
+ */
+static void
+get_tunnels (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
{
- GNUNET_SCHEDULER_shutdown();
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown\n");
+ return;
}
+ GNUNET_MESH_get_tunnels (mh, &tunnels_callback, NULL);
}
target_id = args[0];
target_port = args[0] && args[1] ? atoi(args[1]) : 0;
- if ( (0 != get_info
+ if ( (0 != (request_peers | request_tunnels)
|| 0 != monitor_connections
|| NULL != tunnel_id
|| NULL != conn_id
|| NULL != channel_id)
&& target_id != NULL)
{
- FPRINTF (stderr, _("You must NOT give a TARGET when using options\n"));
+ FPRINTF (stderr,
+ _("You must NOT give a TARGET"
+ "when using 'request all' options\n"));
return;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show connection\n");
GNUNET_SCHEDULER_add_now (&show_connection, NULL);
}
- else if (GNUNET_YES == get_info)
+ else if (GNUNET_YES == request_peers)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show all peers\n");
+ GNUNET_SCHEDULER_add_now (&get_peers, NULL);
+ }
+ else if (GNUNET_YES == request_tunnels)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show all tunnels\n");
GNUNET_SCHEDULER_add_now (&get_tunnels, NULL);
int res;
const char helpstr[] = "Create channels and retreive info about meshs status.";
static const struct GNUNET_GETOPT_CommandLineOption options[] = {
- {'a', "channel", "TUNNEL_ID:CHANNEL_ID",
- gettext_noop ("provide information about a particular channel"),
- GNUNET_YES, &GNUNET_GETOPT_set_string, &channel_id},
- {'b', "connection", "TUNNEL_ID:CONNECTION_ID",
- gettext_noop ("provide information about a particular connection"),
- GNUNET_YES, &GNUNET_GETOPT_set_string, &conn_id},
+// {'a', "channel", "TUNNEL_ID:CHANNEL_ID",
+// gettext_noop ("provide information about a particular channel"),
+// GNUNET_YES, &GNUNET_GETOPT_set_string, &channel_id},
+// {'b', "connection", "TUNNEL_ID:CONNECTION_ID",
+// gettext_noop ("provide information about a particular connection"),
+// GNUNET_YES, &GNUNET_GETOPT_set_string, &conn_id},
{'e', "echo", NULL,
gettext_noop ("activate echo mode"),
GNUNET_NO, &GNUNET_GETOPT_set_one, &echo},
- {'i', "info", NULL,
- gettext_noop ("provide information about all tunnels"),
- GNUNET_NO, &GNUNET_GETOPT_set_one, &get_info},
- {'m', "monitor", NULL,
- gettext_noop ("provide information about all tunnels (continuously) NOT IMPLEMENTED"), /* FIXME */
- GNUNET_NO, &GNUNET_GETOPT_set_one, &monitor_connections},
+// {'m', "monitor", NULL,
+// gettext_noop ("provide information about all tunnels (continuously) NOT IMPLEMENTED"), /* FIXME */
+// GNUNET_NO, &GNUNET_GETOPT_set_one, &monitor_connections},
{'p', "port", NULL,
gettext_noop ("port to listen to (default; 0)"),
GNUNET_YES, &GNUNET_GETOPT_set_uint, &listen_port},
+ {'P', "peers", NULL,
+ gettext_noop ("provide information about all peers"),
+ GNUNET_NO, &GNUNET_GETOPT_set_one, &request_peers},
{'t', "tunnel", "TUNNEL_ID",
gettext_noop ("provide information about a particular tunnel"),
GNUNET_YES, &GNUNET_GETOPT_set_string, &tunnel_id},
+ {'T', "tunnels", NULL,
+ gettext_noop ("provide information about all tunnels"),
+ GNUNET_NO, &GNUNET_GETOPT_set_one, &request_tunnels},
GNUNET_GETOPT_OPTION_END
};
+ monitor_connections = GNUNET_NO;
+
if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
return 2;