[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r32016 - in gnunet/src: include mesh
From: |
gnunet |
Subject: |
[GNUnet-SVN] r32016 - in gnunet/src: include mesh |
Date: |
Thu, 23 Jan 2014 13:44:35 +0100 |
Author: bartpolot
Date: 2014-01-23 13:44:35 +0100 (Thu, 23 Jan 2014)
New Revision: 32016
Modified:
gnunet/src/include/gnunet_mesh_service.h
gnunet/src/include/gnunet_protocols.h
gnunet/src/mesh/gnunet-mesh.c
gnunet/src/mesh/mesh_api.c
Log:
- add peers info to mesh CLI and API
Modified: gnunet/src/include/gnunet_mesh_service.h
===================================================================
--- gnunet/src/include/gnunet_mesh_service.h 2014-01-23 12:44:33 UTC (rev
32015)
+++ gnunet/src/include/gnunet_mesh_service.h 2014-01-23 12:44:35 UTC (rev
32016)
@@ -391,7 +391,23 @@
const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_PeerIdentity
*parent);
+/**
+ * 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 best_path How long is the best path?
+ * (0 = unknown, 1 = ourselves, 2 = neighbor)
+ */
+typedef void (*GNUNET_MESH_PeersCB) (void *cls,
+ const struct GNUNET_PeerIdentity *peer,
+ int tunnel, unsigned int best_path);
+
/**
* Method called to retrieve information about all tunnels in MESH, called
* once per tunnel.
@@ -486,8 +502,29 @@
GNUNET_MESH_get_channels_cancel (struct GNUNET_MESH_Handle *h);
+
/**
* Request information about the running mesh peer.
+ * The callback will be called for every peer known to the service.
+ *
+ * If called again on the same handle, it will overwrite the previous
+ * callback and cls. To retrieve the cls, monitor_cancel must be
+ * called first.
+ *
+ * WARNING: unstable API, likely to change in the future!
+ *
+ * @param h Handle to the mesh peer.
+ * @param callback Function to call with the requested data.
+ * @param callback_cls Closure for @c callback.
+ */
+void
+GNUNET_MESH_get_peers (struct GNUNET_MESH_Handle *h,
+ GNUNET_MESH_PeersCB callback,
+ void *callback_cls);
+
+
+/**
+ * Request information about the running mesh peer.
* The callback will be called for every channel known to the service,
* listing all active peers that blong to the channel.
*
Modified: gnunet/src/include/gnunet_protocols.h
===================================================================
--- gnunet/src/include/gnunet_protocols.h 2014-01-23 12:44:33 UTC (rev
32015)
+++ gnunet/src/include/gnunet_protocols.h 2014-01-23 12:44:35 UTC (rev
32016)
@@ -612,7 +612,7 @@
#define GNUNET_MESSAGE_TYPE_DHT_P2P_TRAIL_SETUP 157
/**
- * Trail to a particular peer is returned to this peer.
+ * Trail to a particular peer is returned to this peer.
*/
#define GNUNET_MESSAGE_TYPE_DHT_P2P_TRAIL_SETUP_RESULT 158
@@ -933,6 +933,16 @@
#define GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_CONNECTION 295
/**
+ * Local information about all peers known to the service.
+ */
+#define GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_PEERS 296
+
+/**
+ * Local information of service about a specific peer.
+ */
+#define GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_PEER 297
+
+/**
* Traffic (net-cat style) used by the Command Line Interface.
*/
#define GNUNET_MESSAGE_TYPE_MESH_CLI 298
Modified: gnunet/src/mesh/gnunet-mesh.c
===================================================================
--- gnunet/src/mesh/gnunet-mesh.c 2014-01-23 12:44:33 UTC (rev 32015)
+++ gnunet/src/mesh/gnunet-mesh.c 2014-01-23 12:44:35 UTC (rev 32016)
@@ -34,6 +34,11 @@
static int monitor_connections;
/**
+ * Option -P.
+ */
+static int request_peers;
+
+/**
* Option -T.
*/
static int request_tunnels;
@@ -426,6 +431,35 @@
/**
+ * 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 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 best_path)
+{
+ if (NULL == peer)
+ {
+ if (GNUNET_YES != monitor_connections)
+ {
+ GNUNET_SCHEDULER_shutdown();
+ }
+ return;
+ }
+ FPRINTF (stdout, "%s tunnel: %c, best path %u hops]\n",
+ GNUNET_i2s_full (peer), tunnel ? 'Y' : 'N', best_path);
+}
+
+
+/**
* Method called to retrieve information about all tunnels in MESH.
*
* @param cls Closure.
@@ -484,12 +518,29 @@
/**
- * 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_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_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))
@@ -576,7 +627,7 @@
target_id = args[0];
target_port = args[0] && args[1] ? atoi(args[1]) : 0;
- if ( (0 != request_tunnels
+ if ( (0 != (request_peers | request_tunnels)
|| 0 != monitor_connections
|| NULL != tunnel_id
|| NULL != conn_id
@@ -620,6 +671,11 @@
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show connection\n");
GNUNET_SCHEDULER_add_now (&show_connection, NULL);
}
+ 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");
@@ -676,6 +732,9 @@
{'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},
Modified: gnunet/src/mesh/mesh_api.c
===================================================================
--- gnunet/src/mesh/mesh_api.c 2014-01-23 12:44:33 UTC (rev 32015)
+++ gnunet/src/mesh/mesh_api.c 2014-01-23 12:44:35 UTC (rev 32016)
@@ -207,6 +207,16 @@
/**
* Monitor callback
*/
+ GNUNET_MESH_PeersCB peers_cb;
+
+ /**
+ * Monitor callback closure.
+ */
+ void *peers_cls;
+
+ /**
+ * Monitor callback
+ */
GNUNET_MESH_TunnelsCB tunnels_cb;
/**
@@ -1733,8 +1743,7 @@
/**
* Request information about the running mesh peer.
- * The callback will be called for every channel known to the service,
- * listing all active peers that blong to the channel.
+ * The callback will be called for every peer known to the service.
*
* If called again on the same handle, it will overwrite the previous
* callback and cls. To retrieve the cls, monitor_cancel must be
@@ -1747,6 +1756,32 @@
* @param callback_cls Closure for @c callback.
*/
void
+GNUNET_MESH_get_peers (struct GNUNET_MESH_Handle *h,
+ GNUNET_MESH_PeersCB callback,
+ void *callback_cls)
+{
+ send_info_request (h, GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_PEERS);
+ h->peers_cb = callback;
+ h->peers_cls = callback_cls;
+}
+
+
+
+/**
+ * Request information about the running mesh peer.
+ * The callback will be called for every tunnel known to the service.
+ *
+ * If called again on the same handle, it will overwrite the previous
+ * callback and cls. To retrieve the cls, monitor_cancel must be
+ * called first.
+ *
+ * WARNING: unstable API, likely to change in the future!
+ *
+ * @param h Handle to the mesh peer.
+ * @param callback Function to call with the requested data.
+ * @param callback_cls Closure for @c callback.
+ */
+void
GNUNET_MESH_get_tunnels (struct GNUNET_MESH_Handle *h,
GNUNET_MESH_TunnelsCB callback,
void *callback_cls)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r32016 - in gnunet/src: include mesh,
gnunet <=