From 54fa2add0f3ed4941e7f7c1d7e9a8d11f4d1c3fc Mon Sep 17 00:00:00 2001 From: Bart Polot Date: Mon, 6 Jan 2014 04:38:54 +0000 Subject: [PATCH] - add -i function back to CLI --- src/mesh/gnunet-mesh.c | 55 +++++++----- src/mesh/gnunet-service-mesh_local.c | 22 ++--- src/mesh/mesh_api.c | 122 +++++++++++++++------------ 3 files changed, 116 insertions(+), 83 deletions(-) diff --git a/src/mesh/gnunet-mesh.c b/src/mesh/gnunet-mesh.c index 340f03821..eaa9c09fd 100644 --- a/src/mesh/gnunet-mesh.c +++ b/src/mesh/gnunet-mesh.c @@ -425,40 +425,52 @@ data_callback (void *cls, /** - * 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); } @@ -475,7 +487,7 @@ get_tunnels (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { 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(); @@ -505,7 +517,7 @@ show_tunnel (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_SCHEDULER_shutdown(); return; } -// GNUNET_MESH_show_tunnel (mh, &pid, 0, tunnel_callback, NULL); + GNUNET_MESH_get_tunnel (mh, &pid, tunnel_callback, NULL); } @@ -662,6 +674,7 @@ main (int argc, char *const *argv) {'t', "tunnel", "TUNNEL_ID", gettext_noop ("provide information about a particular tunnel"), GNUNET_YES, &GNUNET_GETOPT_set_string, &tunnel_id}, + GNUNET_GETOPT_OPTION_END }; diff --git a/src/mesh/gnunet-service-mesh_local.c b/src/mesh/gnunet-service-mesh_local.c index 82743c892..f6b4b8149 100644 --- a/src/mesh/gnunet-service-mesh_local.c +++ b/src/mesh/gnunet-service-mesh_local.c @@ -593,20 +593,22 @@ monitor_all_tunnels_iterator (void *cls, 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; } diff --git a/src/mesh/mesh_api.c b/src/mesh/mesh_api.c index 926feb8af..f27e86b71 100644 --- a/src/mesh/mesh_api.c +++ b/src/mesh/mesh_api.c @@ -1034,28 +1034,34 @@ static void 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; } @@ -1066,43 +1072,48 @@ process_get_tunnels (struct GNUNET_MESH_Handle *h, * @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 @@ -1153,6 +1164,9 @@ msg_received (void *cls, const struct GNUNET_MessageHeader *msg) 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; @@ -1161,7 +1175,7 @@ msg_received (void *cls, const struct GNUNET_MessageHeader *msg) 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) { @@ -1435,6 +1449,8 @@ GNUNET_MESH_disconnect (struct GNUNET_MESH_Handle *handle) 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); @@ -1756,7 +1772,7 @@ GNUNET_MESH_get_tunnels_cancel (struct GNUNET_MESH_Handle *h) h->tunnels_cb = NULL; cls = h->tunnels_cls; h->tunnels_cls = NULL; - + return cls; } @@ -1780,7 +1796,7 @@ GNUNET_MESH_get_tunnels_cancel (struct GNUNET_MESH_Handle *h) 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; @@ -1790,6 +1806,8 @@ GNUNET_MESH_get_tunnel (struct GNUNET_MESH_Handle *h, 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; } @@ -1818,7 +1836,7 @@ GNUNET_MESH_show_channel (struct GNUNET_MESH_Handle *h, 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; -- 2.25.1