[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r32088 - gnunet/src/mesh
From: |
gnunet |
Subject: |
[GNUnet-SVN] r32088 - gnunet/src/mesh |
Date: |
Thu, 30 Jan 2014 03:11:21 +0100 |
Author: bartpolot
Date: 2014-01-30 03:11:21 +0100 (Thu, 30 Jan 2014)
New Revision: 32088
Modified:
gnunet/src/mesh/gnunet-service-mesh_local.c
gnunet/src/mesh/gnunet-service-mesh_peer.c
gnunet/src/mesh/gnunet-service-mesh_peer.h
gnunet/src/mesh/mesh.h
Log:
- service-side implementation of peer queries
Modified: gnunet/src/mesh/gnunet-service-mesh_local.c
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh_local.c 2014-01-30 02:11:20 UTC (rev
32087)
+++ gnunet/src/mesh/gnunet-service-mesh_local.c 2014-01-30 02:11:21 UTC (rev
32088)
@@ -32,6 +32,7 @@
/* INFO DEBUG */
#include "gnunet-service-mesh_tunnel.h"
+#include "gnunet-service-mesh_peer.h"
#define LOG(level, ...) GNUNET_log_from(level,"mesh-loc",__VA_ARGS__)
@@ -579,7 +580,78 @@
}
+
/**
+ * Iterator over all peers to send a monitoring client info about each peer.
+ *
+ * @param cls Closure ().
+ * @param peer Peer ID (tunnel remote peer).
+ * @param value Peer info.
+ *
+ * @return #GNUNET_YES, to keep iterating.
+ */
+static int
+get_all_peers_iterator (void *cls,
+ const struct GNUNET_PeerIdentity * peer,
+ void *value)
+{
+ struct GNUNET_SERVER_Client *client = cls;
+ struct MeshPeer *p = value;
+ struct GNUNET_MESH_LocalInfoPeer msg;
+
+ msg.header.size = htons (sizeof (msg));
+ msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_PEERS);
+ msg.destination = *peer;
+ msg.paths = GMP_count_paths (p);
+ msg.tunnel = NULL != GMP_get_tunnel (p);
+
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "sending info about tunnel ->%s\n",
+ GNUNET_i2s (peer));
+
+ GNUNET_SERVER_notification_context_unicast (nc, client,
+ &msg.header, GNUNET_NO);
+ return GNUNET_YES;
+}
+
+
+/**
+ * Handler for client's INFO PEERS request.
+ *
+ * @param cls Closure (unused).
+ * @param client Identification of the client.
+ * @param message The actual message.
+ */
+static void
+handle_get_peers (void *cls, struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message)
+{
+ struct MeshClient *c;
+ struct GNUNET_MessageHeader reply;
+
+ /* Sanity check for client registration */
+ if (NULL == (c = GML_client_get (client)))
+ {
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
+
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Received get peers request from client %u (%p)\n",
+ c->id, client);
+
+ GMP_iterate_all (get_all_peers_iterator, client);
+ reply.size = htons (sizeof (reply));
+ reply.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_PEERS);
+ GNUNET_SERVER_notification_context_unicast (nc, client, &reply, GNUNET_NO);
+
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Get peers request from client %u completed\n", c->id);
+ GNUNET_SERVER_receive_done (client, GNUNET_OK);
+}
+
+
+/**
* Iterator over all tunnels to send a monitoring client info about each
tunnel.
*
* @param cls Closure ().
@@ -590,8 +662,8 @@
*/
static int
get_all_tunnels_iterator (void *cls,
- const struct GNUNET_PeerIdentity * peer,
- void *value)
+ const struct GNUNET_PeerIdentity * peer,
+ void *value)
{
struct GNUNET_SERVER_Client *client = cls;
struct MeshTunnel3 *t = value;
@@ -770,6 +842,8 @@
{&handle_data, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_DATA, 0},
{&handle_ack, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_ACK,
sizeof (struct GNUNET_MESH_LocalAck)},
+ {&handle_get_peers, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_PEERS,
+ sizeof (struct GNUNET_MessageHeader)},
{&handle_get_tunnels, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNELS,
sizeof (struct GNUNET_MessageHeader)},
{&handle_show_tunnel, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNEL,
Modified: gnunet/src/mesh/gnunet-service-mesh_peer.c
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh_peer.c 2014-01-30 02:11:20 UTC (rev
32087)
+++ gnunet/src/mesh/gnunet-service-mesh_peer.c 2014-01-30 02:11:21 UTC (rev
32088)
@@ -1792,6 +1792,39 @@
/**
+ * Count the number of known paths toward the peer.
+ *
+ * @param peer Peer to get path info.
+ *
+ * @return Number of known paths.
+ */
+unsigned int
+GMP_count_paths (const struct MeshPeer *peer)
+{
+ struct MeshPeerPath *iter;
+ unsigned int i;
+
+ for (iter = peer->path_head, i = 0; NULL != iter; iter = iter->next)
+ i++;
+
+ return i;
+}
+
+
+/**
+ * Iterate all known peers.
+ *
+ * @param iter Iterator.
+ * @param cls Closure for @c iter.
+ */
+void
+GMP_iterate_all (GNUNET_CONTAINER_PeerMapIterator iter, void *cls)
+{
+ GNUNET_CONTAINER_multipeermap_iterate (peers, iter, cls);
+}
+
+
+/**
* Get the static string for a peer ID.
*
* @param peer Peer.
Modified: gnunet/src/mesh/gnunet-service-mesh_peer.h
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh_peer.h 2014-01-30 02:11:20 UTC (rev
32087)
+++ gnunet/src/mesh/gnunet-service-mesh_peer.h 2014-01-30 02:11:21 UTC (rev
32088)
@@ -319,6 +319,25 @@
GMP_get_tunnel (const struct MeshPeer *peer);
/**
+ * Count the number of known paths toward the peer.
+ *
+ * @param peer Peer to get path info.
+ *
+ * @return Number of known paths.
+ */
+unsigned int
+GMP_count_paths (const struct MeshPeer *peer);
+
+/**
+ * Iterate all known peers.
+ *
+ * @param iter Iterator.
+ * @param cls Closure for @c iter.
+ */
+void
+GMP_iterate_all (GNUNET_CONTAINER_PeerMapIterator iter, void *cls);
+
+/**
* Get the static string for a peer ID.
*
* @param peer Peer.
Modified: gnunet/src/mesh/mesh.h
===================================================================
--- gnunet/src/mesh/mesh.h 2014-01-30 02:11:20 UTC (rev 32087)
+++ gnunet/src/mesh/mesh.h 2014-01-30 02:11:21 UTC (rev 32088)
@@ -169,7 +169,7 @@
struct GNUNET_MESH_LocalInfo
{
/**
- * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO[_TUNNEL]
+ * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO[_TUNNEL,_PEER]
*/
struct GNUNET_MessageHeader header;
@@ -189,7 +189,37 @@
struct GNUNET_PeerIdentity peer;
};
+
/**
+ * Message to inform the client about one of the peers in the service.
+ */
+struct GNUNET_MESH_LocalInfoPeer
+{
+ /**
+ * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_PEER[S]
+ */
+ struct GNUNET_MessageHeader header;
+
+ /**
+ * Number of paths.
+ */
+ uint16_t paths GNUNET_PACKED;
+
+ /**
+ * Do we have a tunnel toward this peer?
+ */
+ uint16_t tunnel GNUNET_PACKED;
+
+ /**
+ * ID of the destination of the tunnel (can be local peer).
+ */
+ struct GNUNET_PeerIdentity destination;
+
+ /* If type == PEER (no 'S'): GNUNET_PeerIdentity paths[]
+ * (each path ends in destination) */
+};
+
+/**
* Message to inform the client about one of the tunnels in the service.
*/
struct GNUNET_MESH_LocalInfoTunnel
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r32088 - gnunet/src/mesh,
gnunet <=