[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r31760 - gnunet/src/mesh
From: |
gnunet |
Subject: |
[GNUnet-SVN] r31760 - gnunet/src/mesh |
Date: |
Sat, 28 Dec 2013 15:30:51 +0100 |
Author: bartpolot
Date: 2013-12-28 15:30:51 +0100 (Sat, 28 Dec 2013)
New Revision: 31760
Modified:
gnunet/src/mesh/gnunet-service-mesh_channel.c
gnunet/src/mesh/gnunet-service-mesh_channel.h
gnunet/src/mesh/gnunet-service-mesh_local.c
gnunet/src/mesh/gnunet-service-mesh_tunnel.c
gnunet/src/mesh/gnunet-service-mesh_tunnel.h
gnunet/src/mesh/mesh.h
gnunet/src/mesh/mesh_api.c
Log:
- Add some of the tunnel introscpecion back
Modified: gnunet/src/mesh/gnunet-service-mesh_channel.c
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh_channel.c 2013-12-28 11:35:17 UTC
(rev 31759)
+++ gnunet/src/mesh/gnunet-service-mesh_channel.c 2013-12-28 14:30:51 UTC
(rev 31760)
@@ -1351,11 +1351,11 @@
/**
- * Get channel ID.
+ * Get the channel's public ID.
*
* @param ch Channel.
*
- * @return ID
+ * @return ID used to identify the channel with the remote peer.
*/
MESH_ChannelNumber
GMCH_get_id (const struct MeshChannel *ch)
Modified: gnunet/src/mesh/gnunet-service-mesh_channel.h
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh_channel.h 2013-12-28 11:35:17 UTC
(rev 31759)
+++ gnunet/src/mesh/gnunet-service-mesh_channel.h 2013-12-28 14:30:51 UTC
(rev 31760)
@@ -61,12 +61,13 @@
void
GMCH_destroy (struct MeshChannel *ch);
+
/**
- * Get channel ID.
+ * Get the channel's public ID.
*
* @param ch Channel.
*
- * @return ID
+ * @return ID used to identify the channel with the remote peer.
*/
MESH_ChannelNumber
GMCH_get_id (const struct MeshChannel *ch);
Modified: gnunet/src/mesh/gnunet-service-mesh_local.c
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh_local.c 2013-12-28 11:35:17 UTC (rev
31759)
+++ gnunet/src/mesh/gnunet-service-mesh_local.c 2013-12-28 14:30:51 UTC (rev
31760)
@@ -30,6 +30,9 @@
#include "gnunet-service-mesh_local.h"
#include "gnunet-service-mesh_channel.h"
+/* INFO DEBUG */
+#include "gnunet-service-mesh_tunnel.h"
+
#define LOG(level, ...) GNUNET_log_from(level,"mesh-loc",__VA_ARGS__)
/******************************************************************************/
@@ -575,41 +578,41 @@
}
-/*
+/**
* Iterator over all tunnels to send a monitoring client info about each
tunnel.
*
* @param cls Closure (client handle).
- * @param key Key (hashed tunnel ID, unused).
+ * @param peer Peer ID (tunnel remote peer).
* @param value Tunnel info.
*
* @return #GNUNET_YES, to keep iterating.
*/
-// static int
-// monitor_all_tunnels_iterator (void *cls,
-// const struct GNUNET_HashCode * key,
-// void *value)
-// {
-// struct GNUNET_SERVER_Client *client = cls;
-// struct MeshChannel *ch = value;
-// struct GNUNET_MESH_LocalMonitor *msg;
-//
-// msg = GNUNET_new (struct GNUNET_MESH_LocalMonitor);
-// msg->channel_id = htonl (ch->gid);
-// msg->header.size = htons (sizeof (struct GNUNET_MESH_LocalMonitor));
-// msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNELS);
-//
-// LOG (GNUNET_ERROR_TYPE_INFO,
-// "* sending info about tunnel %s\n",
-// GNUNET_i2s (&msg->owner));
-//
-// GNUNET_SERVER_notification_context_unicast (nc, client,
-// &msg->header, GNUNET_NO);
-// return GNUNET_YES;
-// }
+static int
+monitor_all_tunnels_iterator (void *cls,
+ const struct GNUNET_PeerIdentity * peer,
+ void *value)
+{
+ struct GNUNET_SERVER_Client *client = cls;
+ struct MeshChannel *ch = value;
+ struct GNUNET_MESH_LocalInfo *msg;
+ msg = GNUNET_new (struct GNUNET_MESH_LocalInfo);
+ msg->channel_id = htonl (GMCH_get_id (ch));
+ msg->header.size = htons (sizeof (struct GNUNET_MESH_LocalInfo));
+ msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNELS);
+ LOG (GNUNET_ERROR_TYPE_INFO,
+ "* sending info about tunnel %s\n",
+ GNUNET_i2s (&msg->owner));
+
+ GNUNET_SERVER_notification_context_unicast (nc, client,
+ &msg->header, GNUNET_NO);
+ return GNUNET_YES;
+}
+
+
/**
- * Handler for client's MONITOR request.
+ * Handler for client's INFO TUNNELS request.
*
* @param cls Closure (unused).
* @param client Identification of the client.
@@ -620,6 +623,8 @@
const struct GNUNET_MessageHeader *message)
{
struct MeshClient *c;
+ size_t size;
+ struct GNUNET_MessageHeader *reply;
/* Sanity check for client registration */
if (NULL == (c = GML_client_get (client)))
@@ -629,13 +634,19 @@
return;
}
+ LOG (GNUNET_ERROR_TYPE_INFO, "Received get tunnels request from client %u\n",
+ c->id);
+
+ size = GMT_count_all () + 1; /* Last one is all \0 to mark 'end' */
+ size *= sizeof (struct GNUNET_PeerIdentity);
+ size += sizeof (*reply);
+ reply = GNUNET_malloc (size);
+ GMT_iterate_all (reply, monitor_all_tunnels_iterator);
+ reply->size = htons (size);
+ reply->type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNELS);
+ GNUNET_SERVER_notification_context_unicast (nc, client, reply, GNUNET_NO);
+
LOG (GNUNET_ERROR_TYPE_INFO,
- "Received get tunnels request from client %u\n",
- c->id);
-// GNUNET_CONTAINER_multihashmap_iterate (tunnels,
-// monitor_all_tunnels_iterator,
-// client);
- LOG (GNUNET_ERROR_TYPE_INFO,
"Get tunnels request from client %u completed\n",
c->id);
GNUNET_SERVER_receive_done (client, GNUNET_OK);
@@ -653,8 +664,8 @@
handle_show_tunnel (void *cls, struct GNUNET_SERVER_Client *client,
const struct GNUNET_MessageHeader *message)
{
- const struct GNUNET_MESH_LocalMonitor *msg;
- struct GNUNET_MESH_LocalMonitor *resp;
+ const struct GNUNET_MESH_LocalInfo *msg;
+ struct GNUNET_MESH_LocalInfo *resp;
struct MeshClient *c;
struct MeshChannel *ch;
@@ -666,7 +677,7 @@
return;
}
- msg = (struct GNUNET_MESH_LocalMonitor *) message;
+ msg = (struct GNUNET_MESH_LocalInfo *) message;
LOG (GNUNET_ERROR_TYPE_INFO,
"Received tunnel info request from client %u for tunnel
%s[%X]\n",
c->id,
@@ -677,7 +688,7 @@
if (NULL == ch)
{
/* We don't know the tunnel */
- struct GNUNET_MESH_LocalMonitor warn;
+ struct GNUNET_MESH_LocalInfo warn;
warn = *msg;
GNUNET_SERVER_notification_context_unicast (nc, client,
@@ -688,9 +699,9 @@
}
/* Initialize context */
- resp = GNUNET_new (struct GNUNET_MESH_LocalMonitor);
+ resp = GNUNET_new (struct GNUNET_MESH_LocalInfo);
*resp = *msg;
- resp->header.size = htons (sizeof (struct GNUNET_MESH_LocalMonitor));
+ resp->header.size = htons (sizeof (struct GNUNET_MESH_LocalInfo));
GNUNET_SERVER_notification_context_unicast (nc, c->handle,
&resp->header, GNUNET_NO);
GNUNET_free (resp);
@@ -717,7 +728,7 @@
{&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,
- sizeof (struct GNUNET_MESH_LocalMonitor)},
+ sizeof (struct GNUNET_MESH_LocalInfo)},
{NULL, NULL, 0, 0}
};
Modified: gnunet/src/mesh/gnunet-service-mesh_tunnel.c
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh_tunnel.c 2013-12-28 11:35:17 UTC
(rev 31759)
+++ gnunet/src/mesh/gnunet-service-mesh_tunnel.c 2013-12-28 14:30:51 UTC
(rev 31760)
@@ -2542,6 +2542,11 @@
}
+/******************************************************************************/
+/***************************** INFO/DEBUG
*******************************/
+/******************************************************************************/
+
+
/**
* Log all possible info about the tunnel state.
*
@@ -2581,3 +2586,16 @@
LOG (GNUNET_ERROR_TYPE_DEBUG, "DEBUG TUNNEL END\n");
}
+
+
+void
+GMT_iterate_all (void *cls, GNUNET_CONTAINER_PeerMapIterator iter)
+{
+ GNUNET_CONTAINER_multipeermap_iterate (tunnels, iter, cls);
+}
+
+unsigned int
+GMT_count_all (void)
+{
+ return GNUNET_CONTAINER_multipeermap_size (tunnels);
+}
Modified: gnunet/src/mesh/gnunet-service-mesh_tunnel.h
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh_tunnel.h 2013-12-28 11:35:17 UTC
(rev 31759)
+++ gnunet/src/mesh/gnunet-service-mesh_tunnel.h 2013-12-28 14:30:51 UTC
(rev 31760)
@@ -463,6 +463,12 @@
void
GMT_debug (const struct MeshTunnel3 *t);
+void
+GMT_iterate_all (void *cls, GNUNET_CONTAINER_PeerMapIterator iter);
+
+unsigned int
+GMT_count_all (void);
+
#if 0 /* keep Emacsens' auto-indent happy */
{
#endif
Modified: gnunet/src/mesh/mesh.h
===================================================================
--- gnunet/src/mesh/mesh.h 2013-12-28 11:35:17 UTC (rev 31759)
+++ gnunet/src/mesh/mesh.h 2013-12-28 14:30:51 UTC (rev 31760)
@@ -166,10 +166,10 @@
/**
* Message to inform the client about channels in the service.
*/
-struct GNUNET_MESH_LocalMonitor
+struct GNUNET_MESH_LocalInfo
{
/**
- * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_MONITOR[_TUNNEL]
+ * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO[_TUNNEL]
*/
struct GNUNET_MessageHeader header;
Modified: gnunet/src/mesh/mesh_api.c
===================================================================
--- gnunet/src/mesh/mesh_api.c 2013-12-28 11:35:17 UTC (rev 31759)
+++ gnunet/src/mesh/mesh_api.c 2013-12-28 14:30:51 UTC (rev 31760)
@@ -203,6 +203,26 @@
* Channel callback closure.
*/
void *channel_cls;
+
+ /**
+ * Monitor callback
+ */
+ GNUNET_MESH_TunnelsCB tunnels_cb;
+
+ /**
+ * Monitor callback closure.
+ */
+ void *tunnels_cls;
+
+ /**
+ * Tunnel callback.
+ */
+ GNUNET_MESH_TunnelCB tunnel_cb;
+
+ /**
+ * Tunnel callback closure.
+ */
+ void *tunnel_cls;
};
@@ -927,7 +947,7 @@
// process_get_channels (struct GNUNET_MESH_Handle *h,
// const struct GNUNET_MessageHeader *message)
// {
-// struct GNUNET_MESH_LocalMonitor *msg;
+// struct GNUNET_MESH_LocalInfo *msg;
//
// GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Get Channels messasge received\n");
//
@@ -937,16 +957,16 @@
// return;
// }
//
-// msg = (struct GNUNET_MESH_LocalMonitor *) message;
+// msg = (struct GNUNET_MESH_LocalInfo *) message;
// if (ntohs (message->size) !=
-// (sizeof (struct GNUNET_MESH_LocalMonitor) +
+// (sizeof (struct GNUNET_MESH_LocalInfo) +
// sizeof (struct GNUNET_PeerIdentity)))
// {
// GNUNET_break_op (0);
// GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
// "Get channels message: size %hu - expected %u\n",
// ntohs (message->size),
-// sizeof (struct GNUNET_MESH_LocalMonitor));
+// sizeof (struct GNUNET_MESH_LocalInfo));
// return;
// }
// h->channels_cb (h->channels_cls,
@@ -967,7 +987,7 @@
// process_show_channel (struct GNUNET_MESH_Handle *h,
// const struct GNUNET_MessageHeader *message)
// {
-// struct GNUNET_MESH_LocalMonitor *msg;
+// struct GNUNET_MESH_LocalInfo *msg;
// size_t esize;
//
// GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Show Channel messasge received\n");
@@ -979,8 +999,8 @@
// }
//
// /* Verify message sanity */
-// msg = (struct GNUNET_MESH_LocalMonitor *) message;
-// esize = sizeof (struct GNUNET_MESH_LocalMonitor);
+// msg = (struct GNUNET_MESH_LocalInfo *) message;
+// esize = sizeof (struct GNUNET_MESH_LocalInfo);
// if (ntohs (message->size) != esize)
// {
// GNUNET_break_op (0);
@@ -1002,6 +1022,88 @@
// }
+
+
+/*
+ * Process a local reply about info on all tunnels, pass info to the user.
+ *
+ * @param h Mesh handle.
+ * @param message Message itself.
+ */
+static void
+process_get_tunnels (struct GNUNET_MESH_Handle *h,
+ const struct GNUNET_MessageHeader *message)
+{
+ struct GNUNET_PeerIdentity *id;
+ uint16_t size;
+ unsigned int i;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Get Tunnels messasge received\n");
+
+ if (NULL == h->tunnels_cb)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, " ignored\n");
+ return;
+ }
+
+ size = ntohs (message->size);
+ size /= sizeof (struct GNUNET_PeerIdentity);
+ id = (struct GNUNET_PeerIdentity *) &message[1];
+
+ for (i = 0; i < size; i++)
+ h->tunnels_cb (h->tunnels_cls, &id[i]);
+ h->tunnels_cb (h->tunnels_cls, NULL);
+
+ h->tunnels_cb = NULL;
+ h->tunnels_cls = NULL;
+}
+
+
+
+/*
+ * Process a local monitor_channel reply, pass info to the user.
+ *
+ * @param h Mesh handle.
+ * @param message Message itself.
+ */
+// static void
+// process_show_channel (struct GNUNET_MESH_Handle *h,
+// const struct GNUNET_MessageHeader *message)
+// {
+// struct GNUNET_MESH_LocalInfo *msg;
+// size_t esize;
+//
+// GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Show Channel messasge received\n");
+//
+// if (NULL == h->channel_cb)
+// {
+// GNUNET_log (GNUNET_ERROR_TYPE_ERROR, " ignored\n");
+// return;
+// }
+//
+// /* Verify message sanity */
+// msg = (struct GNUNET_MESH_LocalInfo *) message;
+// esize = sizeof (struct GNUNET_MESH_LocalInfo);
+// if (ntohs (message->size) != esize)
+// {
+// GNUNET_break_op (0);
+// GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+// "Show channel message: size %hu - expected %u\n",
+// ntohs (message->size),
+// esize);
+//
+// h->channel_cb (h->channel_cls, NULL, NULL);
+// h->channel_cb = NULL;
+// h->channel_cls = NULL;
+//
+// return;
+// }
+//
+// h->channel_cb (h->channel_cls,
+// &msg->destination,
+// &msg->owner);
+// }
+
/**
* Function to process all messages received from the service
*
@@ -1042,12 +1144,18 @@
case GNUNET_MESSAGE_TYPE_MESH_LOCAL_ACK:
process_ack (h, msg);
break;
-// case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_CHANNELS: DEPRECATED
+// case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_CHANNELS:
// process_get_channels (h, msg);
// break;
-// case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_CHANNEL: DEPRECATED
+// case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_CHANNEL:
// process_show_channel (h, msg);
// break;
+ case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNELS:
+ process_get_tunnels (h, msg);
+ break;
+// case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_CHANNEL:
+// process_show_channel (h, msg);
+// break;
default:
/* We shouldn't get any other packages, log and ignore */
LOG (GNUNET_ERROR_TYPE_WARNING,
@@ -1550,6 +1658,16 @@
}
+static void
+send_info_request (struct GNUNET_MESH_Handle *h, uint16_t type)
+{
+ struct GNUNET_MessageHeader msg;
+
+ msg.size = htons (sizeof (msg));
+ msg.type = htons (type);
+ send_packet (h, &msg, NULL);
+}
+
/**
* Request information about the running mesh peer.
* The callback will be called for every channel known to the service,
@@ -1570,11 +1688,7 @@
GNUNET_MESH_ChannelsCB callback,
void *callback_cls)
{
- struct GNUNET_MessageHeader msg;
-
- msg.size = htons (sizeof (msg));
- msg.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_CHANNELS);
- send_packet (h, &msg, NULL);
+ send_info_request (h, GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_CHANNELS);
h->channels_cb = callback;
h->channels_cls = callback_cls;
}
@@ -1583,6 +1697,8 @@
/**
* Cancel a monitor request. The monitor callback will not be called.
*
+ * WARNING: unstable API, likely to change in the future!
+ *
* @param h Mesh handle.
*
* @return Closure given to GNUNET_MESH_monitor, if any.
@@ -1600,6 +1716,84 @@
/**
+ * 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.
+ *
+ * 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)
+{
+ send_info_request (h, GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNELS);
+ h->tunnels_cb = callback;
+ h->tunnels_cls = callback_cls;
+}
+
+
+/**
+ * Cancel a monitor request. The monitor callback will not be called.
+ *
+ * @param h Mesh handle.
+ *
+ * @return Closure given to GNUNET_MESH_monitor, if any.
+ */
+void *
+GNUNET_MESH_get_tunnels_cancel (struct GNUNET_MESH_Handle *h)
+{
+ void *cls;
+
+ h->tunnels_cb = NULL;
+ cls = h->tunnels_cls;
+ h->tunnels_cls = NULL;
+
+ return 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.
+ *
+ * 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_tunnel (struct GNUNET_MESH_Handle *h,
+ const struct GNUNET_PeerIdentity *id,
+ GNUNET_MESH_TunnelsCB callback,
+ void *callback_cls)
+{
+ struct GNUNET_MESH_LocalInfo msg;
+
+ memset (&msg, 0, sizeof (msg));
+ msg.header.size = htons (sizeof (msg));
+ msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNEL);
+ msg.destination = *id;
+ send_packet (h, &msg.header, NULL);
+}
+
+
+/**
* Request information about a specific channel of the running mesh peer.
*
* WARNING: unstable API, likely to change in the future!
@@ -1618,7 +1812,7 @@
GNUNET_MESH_ChannelCB callback,
void *callback_cls)
{
- struct GNUNET_MESH_LocalMonitor msg;
+ struct GNUNET_MESH_LocalInfo msg;
msg.header.size = htons (sizeof (msg));
msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_CHANNEL);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r31760 - gnunet/src/mesh,
gnunet <=