#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__)
/******************************************************************************/
}
-/*
+/**
* 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.
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)))
return;
}
- 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, "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,
"Get tunnels request from client %u completed\n",
c->id);
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;
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,
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,
}
/* 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);
{&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}
};
* 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;
};
// 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");
//
// 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,
// 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");
// }
//
// /* 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);
// }
+
+
+/*
+ * 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
*
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:
}
+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,
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;
}
/**
* 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.
}
+/**
+ * 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.
*
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);