[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r32853 - in gnunet/src: include mesh
From: |
gnunet |
Subject: |
[GNUnet-SVN] r32853 - in gnunet/src: include mesh |
Date: |
Tue, 1 Apr 2014 02:16:26 +0200 |
Author: bartpolot
Date: 2014-04-01 02:16:26 +0200 (Tue, 01 Apr 2014)
New Revision: 32853
Modified:
gnunet/src/include/gnunet_mesh_service.h
gnunet/src/mesh/gnunet-mesh.c
gnunet/src/mesh/mesh_api.c
Log:
- implement client-side peer_id info request
Modified: gnunet/src/include/gnunet_mesh_service.h
===================================================================
--- gnunet/src/include/gnunet_mesh_service.h 2014-04-01 00:16:22 UTC (rev
32852)
+++ gnunet/src/include/gnunet_mesh_service.h 2014-04-01 00:16:26 UTC (rev
32853)
@@ -410,7 +410,27 @@
int tunnel, unsigned int n_paths,
unsigned int best_path);
+/**
+ * Method called to retrieve information about a specific peer
+ * known to the service.
+ *
+ * @param cls Closure.
+ * @param peer Peer ID.
+ * @param tunnel Do we have a tunnel towards this peer? #GNUNET_YES/#GNUNET_NO
+ * @param neighbor Is this a direct neighbor? #GNUNET_YES/#GNUNET_NO
+ * @param n_paths Number of paths known towards peer.
+ * @param paths Array of PEER_IDs representing all paths to reach the peer.
+ * Each path starts with the local peer.
+ * Each path ends with the destination peer (given in @c peer).
+ */
+typedef void (*GNUNET_MESH_PeerCB) (void *cls,
+ const struct GNUNET_PeerIdentity *peer,
+ int tunnel,
+ int neighbor,
+ unsigned int n_paths,
+ struct GNUNET_PeerIdentity *paths);
+
/**
* Method called to retrieve information about all tunnels in MESH, called
* once per tunnel.
@@ -505,7 +525,28 @@
void *
GNUNET_MESH_get_peers_cancel (struct GNUNET_MESH_Handle *h);
+
/**
+ * Request information about a peer known to the running mesh peer.
+ * The callback will be called for the tunnel once.
+ * Only one info request (of any kind) can be active at once.
+ *
+ * WARNING: unstable API, likely to change in the future!
+ *
+ * @param h Handle to the mesh peer.
+ * @param id Peer whose tunnel to examine.
+ * @param callback Function to call with the requested data.
+ * @param callback_cls Closure for @c callback.
+ *
+ * @return #GNUNET_OK / #GNUNET_SYSERR
+ */
+int
+GNUNET_MESH_get_peer (struct GNUNET_MESH_Handle *h,
+ const struct GNUNET_PeerIdentity *id,
+ GNUNET_MESH_PeerCB callback,
+ void *callback_cls);
+
+/**
* Request information about tunnels of the running mesh peer.
* The callback will be called for every tunnel of the service.
* Only one info request (of any kind) can be active at once.
Modified: gnunet/src/mesh/gnunet-mesh.c
===================================================================
--- gnunet/src/mesh/gnunet-mesh.c 2014-04-01 00:16:22 UTC (rev 32852)
+++ gnunet/src/mesh/gnunet-mesh.c 2014-04-01 00:16:26 UTC (rev 32853)
@@ -465,7 +465,30 @@
GNUNET_i2s_full (peer), tunnel ? 'Y' : 'N', n_paths);
}
+/**
+ * Method called to retrieve information about a specific peer
+ * known to the service.
+ *
+ * @param cls Closure.
+ * @param peer Peer ID.
+ * @param tunnel Do we have a tunnel towards this peer? #GNUNET_YES/#GNUNET_NO
+ * @param neighbor Is this a direct neighbor? #GNUNET_YES/#GNUNET_NO
+ * @param n_paths Number of paths known towards peer.
+ * @param paths Array of PEER_IDs representing all paths to reach the peer.
+ * Each path starts with the local peer.
+ * Each path ends with the destination peer (given in @c peer).
+ */
+void
+peer_callback (void *cls,
+ const struct GNUNET_PeerIdentity *peer,
+ int tunnel,
+ int neighbor,
+ unsigned int n_paths,
+ struct GNUNET_PeerIdentity *paths)
+{
+}
+
/**
* Method called to retrieve information about all tunnels in MESH.
*
@@ -560,7 +583,33 @@
GNUNET_MESH_get_peers (mh, &peers_callback, NULL);
}
+
/**
+ * Call MESH's monitor API, get info of one peer.
+ *
+ * @param cls Closure (unused).
+ * @param tc TaskContext
+ */
+static void
+show_peer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ struct GNUNET_PeerIdentity pid;
+
+ if (GNUNET_OK !=
+ GNUNET_CRYPTO_eddsa_public_key_from_string (peer_id,
+ strlen (peer_id),
+ &pid.public_key))
+ {
+ fprintf (stderr,
+ _("Invalid peer ID `%s'\n"),
+ peer_id);
+ GNUNET_SCHEDULER_shutdown();
+ return;
+ }
+ GNUNET_MESH_get_peer (mh, &pid, peer_callback, NULL);
+}
+
+/**
* Call MESH's meta API, get all tunnels known to a peer.
*
* @param cls Closure (unused).
@@ -682,6 +731,11 @@
ports = GNUNET_malloc (sizeof (uint32_t) * 2);
ports[0] = listen_port;
}
+ else if (NULL != peer_id)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show peer\n");
+ GNUNET_SCHEDULER_add_now (&show_peer, NULL);
+ }
else if (NULL != tunnel_id)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show tunnel\n");
Modified: gnunet/src/mesh/mesh_api.c
===================================================================
--- gnunet/src/mesh/mesh_api.c 2014-04-01 00:16:22 UTC (rev 32852)
+++ gnunet/src/mesh/mesh_api.c 2014-04-01 00:16:26 UTC (rev 32853)
@@ -101,6 +101,11 @@
/**
* Monitor callback
*/
+ GNUNET_MESH_PeerCB peer_cb;
+
+ /**
+ * Monitor callback
+ */
GNUNET_MESH_TunnelsCB tunnels_cb;
/**
@@ -1784,6 +1789,45 @@
/**
+ * Request information about a peer known to the running mesh peer.
+ * The callback will be called for the tunnel once.
+ * Only one info request (of any kind) can be active at once.
+ *
+ * WARNING: unstable API, likely to change in the future!
+ *
+ * @param h Handle to the mesh peer.
+ * @param id Peer whose tunnel to examine.
+ * @param callback Function to call with the requested data.
+ * @param callback_cls Closure for @c callback.
+ *
+ * @return #GNUNET_OK / #GNUNET_SYSERR
+ */
+int
+GNUNET_MESH_get_peer (struct GNUNET_MESH_Handle *h,
+ const struct GNUNET_PeerIdentity *id,
+ GNUNET_MESH_PeerCB callback,
+ void *callback_cls)
+{
+ struct GNUNET_MESH_LocalInfo msg;
+
+ if (NULL != h->info_cb.peer_cb)
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+
+ memset (&msg, 0, sizeof (msg));
+ msg.header.size = htons (sizeof (msg));
+ msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_PEER);
+ msg.peer = *id;
+ send_packet (h, &msg.header, NULL);
+ h->info_cb.peer_cb = callback;
+ h->info_cls = callback_cls;
+ return GNUNET_OK;
+}
+
+
+/**
* Request information about tunnels of the running mesh peer.
* The callback will be called for every tunnel of the service.
* Only one info request (of any kind) can be active at once.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r32853 - in gnunet/src: include mesh,
gnunet <=