/**
- * Method called to retrieve information about each tunnel the mesh peer
- * is aware of.
+ * Method called to retrieve information about all tunnels in MESH.
*
* @param cls Closure.
- * @param tunnel_number Tunnel number.
- * @param origin that started the tunnel (owner).
- * @param target other endpoint of the tunnel
+ * @param peer Destination peer.
+ * @param channels Number of channels.
+ * @param connections Number of connections.
+ * @param estate Encryption state.
+ * @param cstate Connectivity state.
*/
-void /* FIXME static */
+void
tunnels_callback (void *cls,
- uint32_t tunnel_number,
- const struct GNUNET_PeerIdentity *origin,
- const struct GNUNET_PeerIdentity *target)
+ const struct GNUNET_PeerIdentity *peer,
+ unsigned int channels,
+ unsigned int connections,
+ unsigned int estate,
+ unsigned int cstate)
{
- FPRINTF (stdout, "Tunnel %s [%u]\n",
- GNUNET_i2s_full (origin), tunnel_number);
- FPRINTF (stdout, "\n");
+ FPRINTF (stdout, "%s [%u, %u] CH: %u, C: %u\n",
+ GNUNET_i2s_full (peer), estate, cstate, channels, connections);
}
/**
- * Method called to retrieve information about each tunnel the mesh peer
- * is aware of.
+ * Method called to retrieve information about a specific tunnel the mesh peer
+ * has established, o`r is trying to establish.
*
* @param cls Closure.
- * @param peer Peer in the tunnel's tree.
- * @param parent Parent of the current peer. All 0 when peer is root.
- *
+ * @param peer Peer towards whom the tunnel is directed.
+ * @param channels Number of channels.
+ * @param connections Number of connections.
+ * @param estate Encryption status.
+ * @param cstate Connectivity status.
*/
-void /* FIXME static */
+void
tunnel_callback (void *cls,
const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_PeerIdentity *parent)
+ unsigned int channels,
+ unsigned int connections,
+ unsigned int estate,
+ unsigned int cstate)
{
+ FPRINTF (stdout, "Tunnel %s\n", GNUNET_i2s_full (peer));
+ FPRINTF (stdout, "- %u channels\n", channels);
+ FPRINTF (stdout, "- %u connections\n", connections);
+ FPRINTF (stdout, "- enc state: %u\n", estate);
+ FPRINTF (stdout, "- con state: %u\n", cstate);
}
{
return;
}
-// GNUNET_MESH_get_tunnels (mh, &tunnels_callback, NULL);
+ GNUNET_MESH_get_tunnels (mh, &tunnels_callback, NULL);
if (GNUNET_YES != monitor_connections)
{
GNUNET_SCHEDULER_shutdown();
GNUNET_SCHEDULER_shutdown();
return;
}
-// GNUNET_MESH_show_tunnel (mh, &pid, 0, tunnel_callback, NULL);
+ GNUNET_MESH_get_tunnel (mh, &pid, tunnel_callback, NULL);
}
{'t', "tunnel", "TUNNEL_ID",
gettext_noop ("provide information about a particular tunnel"),
GNUNET_YES, &GNUNET_GETOPT_set_string, &tunnel_id},
+
GNUNET_GETOPT_OPTION_END
};
void *value)
{
struct GNUNET_SERVER_Client *client = cls;
- struct MeshChannel *ch = value;
- struct GNUNET_MESH_LocalInfo *msg;
+ struct MeshTunnel3 *t = value;
+ struct GNUNET_MESH_LocalInfoTunnel 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);
+ msg.header.size = htons (sizeof (msg));
+ msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNELS);
+ msg.destination = *peer;
+ msg.channels = htons (42);
+ msg.connections = htons (42);
+ msg.cstate = htons (GMT_get_cstate (t));
+ msg.estate = htons (42);
- LOG (GNUNET_ERROR_TYPE_INFO,
- "* sending info about tunnel %s\n",
- GNUNET_i2s (&msg->owner));
+ 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);
+ &msg.header, GNUNET_NO);
return GNUNET_YES;
}
process_get_tunnels (struct GNUNET_MESH_Handle *h,
const struct GNUNET_MessageHeader *message)
{
- struct GNUNET_PeerIdentity *id;
+ struct GNUNET_MESH_LocalInfoTunnel *msg;
uint16_t size;
- unsigned int i;
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Get Tunnels messasge received\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Get Tunnels messasge received\n");
if (NULL == h->tunnels_cb)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, " ignored\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " ignored\n");
return;
}
size = ntohs (message->size);
- size /= sizeof (struct GNUNET_PeerIdentity);
- id = (struct GNUNET_PeerIdentity *) &message[1];
+ if (sizeof (struct GNUNET_MESH_LocalInfoTunnel) > size)
+ {
+ h->tunnels_cb (h->tunnel_cls, NULL, 0, 0, 0, 0);
+ h->tunnels_cb = NULL;
+ h->tunnels_cls = NULL;
+ return;
+ }
- for (i = 0; i < size; i++)
- h->tunnels_cb (h->tunnels_cls, &id[i]);
- h->tunnels_cb (h->tunnels_cls, NULL);
+ msg = (struct GNUNET_MESH_LocalInfoTunnel *) message;
+ h->tunnels_cb (h->tunnel_cls,
+ &msg->destination,
+ ntohl (msg->channels),
+ ntohl (msg->connections),
+ ntohl (msg->estate),
+ ntohl (msg->cstate));
- h->tunnels_cb = NULL;
- h->tunnels_cls = NULL;
}
* @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);
-// }
+static void
+process_get_tunnel (struct GNUNET_MESH_Handle *h,
+ const struct GNUNET_MessageHeader *message)
+{
+ struct GNUNET_MESH_LocalInfoTunnel *msg;
+ size_t esize;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Get Tunnel messasge received\n");
+
+ if (NULL == h->tunnel_cb)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, " ignored\n");
+ return;
+ }
+
+ /* Verify message sanity */
+ msg = (struct GNUNET_MESH_LocalInfoTunnel *) message;
+ esize = sizeof (struct GNUNET_MESH_LocalInfo);
+ if (ntohs (message->size) != esize)
+ {
+ GNUNET_break_op (0);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Get Tunnel message: size %hu - expected %u\n",
+ ntohs (message->size),
+ esize);
+
+ h->tunnel_cb (h->tunnel_cls, NULL, 0, 0, 0, 0);
+ h->tunnel_cb = NULL;
+ h->tunnel_cls = NULL;
+
+ return;
+ }
+
+ h->tunnel_cb (h->tunnel_cls,
+ &msg->destination,
+ ntohl (msg->channels),
+ ntohl (msg->connections),
+ ntohl (msg->estate),
+ ntohl (msg->cstate));
+ h->tunnel_cb = NULL;
+ h->tunnel_cls = NULL;
+}
/**
* Function to process all messages received from the service
case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNELS:
process_get_tunnels (h, msg);
break;
+ case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNEL:
+ process_get_tunnel (h, msg);
+ break;
// case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_CHANNEL:
// process_show_channel (h, msg);
// break;
LOG (GNUNET_ERROR_TYPE_WARNING,
"unsolicited message form service (type %s)\n",
GM_m2s (ntohs (msg->type)));
- }
+ } FPRINTF (stdout, "\n");
LOG (GNUNET_ERROR_TYPE_DEBUG, "message processed\n");
if (GNUNET_YES == h->in_receive)
{
case GNUNET_MESSAGE_TYPE_MESH_CHANNEL_DESTROY:
case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_CHANNELS:
case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_CHANNEL:
+ case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNEL:
+ case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNELS:
break;
default:
GNUNET_break (0);
h->tunnels_cb = NULL;
cls = h->tunnels_cls;
h->tunnels_cls = NULL;
-
+
return cls;
}
void
GNUNET_MESH_get_tunnel (struct GNUNET_MESH_Handle *h,
const struct GNUNET_PeerIdentity *id,
- GNUNET_MESH_TunnelsCB callback,
+ GNUNET_MESH_TunnelCB callback,
void *callback_cls)
{
struct GNUNET_MESH_LocalInfo msg;
msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNEL);
msg.destination = *id;
send_packet (h, &msg.header, NULL);
+ h->tunnel_cb = callback;
+ h->tunnel_cls = callback_cls;
}
msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_CHANNEL);
msg.owner = *initiator;
msg.channel_id = htonl (channel_number);
- msg.reserved = 0;
+// msg.reserved = 0;
send_packet (h, &msg.header, NULL);
h->channel_cb = callback;
h->channel_cls = callback_cls;