/* 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__)
struct MeshChannel *ch;
MESH_ChannelNumber chid;
- LOG (GNUNET_ERROR_TYPE_DEBUG, "\n\nGot a DESTROY CHANNEL from client!\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Got a DESTROY CHANNEL from client!\n");
/* Sanity check for client registration */
if (NULL == (c = GML_client_get (client)))
size_t size;
int fwd;
- LOG (GNUNET_ERROR_TYPE_DEBUG, "\n\nGot data from a client!\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Got data from a client!\n");
/* Sanity check for client registration */
if (NULL == (c = GML_client_get (client)))
}
+
+/**
+ * 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 = htons (GMP_count_paths (p));
+ msg.tunnel = htons (NULL != GMP_get_tunnel (p));
+
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "sending info about peer %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.
*
* @return #GNUNET_YES, to keep iterating.
*/
static int
-monitor_all_tunnels_iterator (void *cls,
- const struct GNUNET_PeerIdentity * peer,
- void *value)
+get_all_tunnels_iterator (void *cls,
+ const struct GNUNET_PeerIdentity * peer,
+ void *value)
{
struct GNUNET_SERVER_Client *client = cls;
struct MeshTunnel3 *t = value;
"Received get tunnels request from client %u (%p)\n",
c->id, client);
- GMT_iterate_all (client, monitor_all_tunnels_iterator);
+ GMT_iterate_all (get_all_tunnels_iterator, client);
reply.size = htons (sizeof (reply));
reply.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNELS);
GNUNET_SERVER_notification_context_unicast (nc, client, &reply, GNUNET_NO);
iter_connection (void *cls, struct MeshConnection *c)
{
struct GNUNET_MESH_LocalInfoTunnel *msg = cls;
- struct GNUNET_HashCode *h = (struct GNUNET_HashCode *) &msg[1];
+ struct GNUNET_MeshHash *h = (struct GNUNET_MeshHash *) &msg[1];
h[msg->connections] = *(GMC_get_id (c));
msg->connections++;
/* We don't know the tunnel */
struct GNUNET_MESH_LocalInfoTunnel warn;
+ LOG (GNUNET_ERROR_TYPE_INFO, "Tunnel %s unknown %u\n",
+ GNUNET_i2s_full(&msg->peer), sizeof (warn));
warn.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNEL);
warn.header.size = htons (sizeof (warn));
warn.destination = msg->peer;
ch_n = GMT_count_channels (t);
c_n = GMT_count_connections (t);
- size = sizeof (struct GNUNET_MESH_LocalInfo);
+ size = sizeof (struct GNUNET_MESH_LocalInfoTunnel);
size += c_n * sizeof (struct GNUNET_HashCode);
size += ch_n * sizeof (MESH_ChannelNumber);
GMT_iterate_connections (t, &iter_connection, resp);
GMT_iterate_channels (t, &iter_channel, resp);
/* Do not interleave with iterators, iter_channel needs conn in HBO */
+ resp->destination = msg->peer;
resp->connections = htonl (resp->connections);
resp->channels = htonl (resp->channels);
resp->cstate = htons (GMT_get_cstate (t));
GNUNET_free (resp);
LOG (GNUNET_ERROR_TYPE_INFO,
- "Show tunnel request from client %u completed\n",
- c->id);
+ "Show tunnel request from client %u completed. %u conn, %u ch\n",
+ c->id, c_n, ch_n);
GNUNET_SERVER_receive_done (client, GNUNET_OK);
}
{&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,