From: Bart Polot Date: Mon, 6 Jan 2014 05:18:30 +0000 (+0000) Subject: - more tunnels info for CLI X-Git-Tag: initial-import-from-subversion-38251~5135 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=0ccd26a719e7f197ccfb053b9517162f51c9da2c;p=oweals%2Fgnunet.git - more tunnels info for CLI --- diff --git a/src/mesh/gnunet-mesh.c b/src/mesh/gnunet-mesh.c index eaa9c09fd..afdd94a9c 100644 --- a/src/mesh/gnunet-mesh.c +++ b/src/mesh/gnunet-mesh.c @@ -122,6 +122,7 @@ static void shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown\n"); if (NULL != ch) { GNUNET_MESH_channel_destroy (ch); @@ -439,10 +440,18 @@ tunnels_callback (void *cls, const struct GNUNET_PeerIdentity *peer, unsigned int channels, unsigned int connections, - unsigned int estate, - unsigned int cstate) + uint16_t estate, + uint16_t cstate) { - FPRINTF (stdout, "%s [%u, %u] CH: %u, C: %u\n", + if (NULL == peer) + { + if (GNUNET_YES != monitor_connections) + { + GNUNET_SCHEDULER_shutdown(); + } + return; + } + FPRINTF (stdout, "%s [ENC: %u, CON: %u] CHs: %u, CONNs: %u\n", GNUNET_i2s_full (peer), estate, cstate, channels, connections); } @@ -483,15 +492,12 @@ tunnel_callback (void *cls, static void get_tunnels (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown\n"); if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) { return; } GNUNET_MESH_get_tunnels (mh, &tunnels_callback, NULL); - if (GNUNET_YES != monitor_connections) - { - GNUNET_SCHEDULER_shutdown(); - } } diff --git a/src/mesh/gnunet-service-mesh_local.c b/src/mesh/gnunet-service-mesh_local.c index 8fc01f929..0470d982d 100644 --- a/src/mesh/gnunet-service-mesh_local.c +++ b/src/mesh/gnunet-service-mesh_local.c @@ -298,7 +298,8 @@ handle_new_client (void *cls, struct GNUNET_SERVER_Client *client, uint32_t *p; unsigned int i; - LOG (GNUNET_ERROR_TYPE_DEBUG, "\n\nnew client connected %p\n", client); + LOG (GNUNET_ERROR_TYPE_DEBUG, "\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, "new client connected %p\n", client); /* Check data sanity */ size = ntohs (message->size) - sizeof (struct GNUNET_MESH_ClientConnect); @@ -581,7 +582,7 @@ handle_ack (void *cls, struct GNUNET_SERVER_Client *client, /** * Iterator over all tunnels to send a monitoring client info about each tunnel. * - * @param cls Closure (client handle). + * @param cls Closure (). * @param peer Peer ID (tunnel remote peer). * @param value Tunnel info. * @@ -599,10 +600,10 @@ monitor_all_tunnels_iterator (void *cls, 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); + msg.channels = htonl (GMT_count_channels (t)); + msg.connections = htonl (GMT_count_connections (t)); + msg.cstate = htons ((uint16_t) GMT_get_cstate (t)); + msg.estate = htons ((uint16_t) GMT_get_estate (t)); LOG (GNUNET_ERROR_TYPE_DEBUG, "sending info about tunnel ->%s\n", GNUNET_i2s (peer)); @@ -625,8 +626,7 @@ handle_get_tunnels (void *cls, struct GNUNET_SERVER_Client *client, const struct GNUNET_MessageHeader *message) { struct MeshClient *c; - size_t size; - struct GNUNET_MessageHeader *reply; + struct GNUNET_MessageHeader reply; /* Sanity check for client registration */ if (NULL == (c = GML_client_get (client))) @@ -636,21 +636,17 @@ handle_get_tunnels (void *cls, struct GNUNET_SERVER_Client *client, return; } - LOG (GNUNET_ERROR_TYPE_INFO, "Received get tunnels request from client %u\n", - c->id); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Received get tunnels request from client %u (%p)\n", + c->id, client); - 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); + GMT_iterate_all (client, monitor_all_tunnels_iterator); + 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); - LOG (GNUNET_ERROR_TYPE_INFO, - "Get tunnels request from client %u completed\n", - c->id); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Get tunnels request from client %u completed\n", c->id); GNUNET_SERVER_receive_done (client, GNUNET_OK); } diff --git a/src/mesh/gnunet-service-mesh_tunnel.c b/src/mesh/gnunet-service-mesh_tunnel.c index 3224c9939..07375a43c 100644 --- a/src/mesh/gnunet-service-mesh_tunnel.c +++ b/src/mesh/gnunet-service-mesh_tunnel.c @@ -2182,6 +2182,24 @@ GMT_get_cstate (struct MeshTunnel3 *t) } +/** + * Get the encryption state of a tunnel. + * + * @param t Tunnel. + * + * @return Tunnel's encryption state. + */ +enum MeshTunnel3EState +GMT_get_estate (struct MeshTunnel3 *t) +{ + if (NULL == t) + { + GNUNET_assert (0); + return (enum MeshTunnel3EState) -1; + } + return t->estate; +} + /** * Get the maximum buffer space for a tunnel towards a local client. * @@ -2387,7 +2405,9 @@ GMT_send_connection_acks (struct MeshTunnel3 *t) /* Authorize connections to send more data */ to_allow = buffer; /* - allowed; */ - for (iter = t->connection_head; NULL != iter && to_allow > 0; iter = iter->next) + for (iter = t->connection_head; + NULL != iter && to_allow > 0; + iter = iter->next) { allow_per_connection = to_allow/cs; to_allow -= allow_per_connection; diff --git a/src/mesh/gnunet-service-mesh_tunnel.h b/src/mesh/gnunet-service-mesh_tunnel.h index 19431e346..e38d313cb 100644 --- a/src/mesh/gnunet-service-mesh_tunnel.h +++ b/src/mesh/gnunet-service-mesh_tunnel.h @@ -325,6 +325,16 @@ GMT_count_channels (struct MeshTunnel3 *t); enum MeshTunnel3CState GMT_get_cstate (struct MeshTunnel3 *t); +/** + * Get the encryption state of a tunnel. + * + * @param t Tunnel. + * + * @return Tunnel's encryption state. + */ +enum MeshTunnel3EState +GMT_get_estate (struct MeshTunnel3 *t); + /** * Get the maximum buffer space for a tunnel towards a local client. * diff --git a/src/mesh/mesh_api.c b/src/mesh/mesh_api.c index 5f3f2da51..6d16be08e 100644 --- a/src/mesh/mesh_api.c +++ b/src/mesh/mesh_api.c @@ -1059,8 +1059,8 @@ process_get_tunnels (struct GNUNET_MESH_Handle *h, &msg->destination, ntohl (msg->channels), ntohl (msg->connections), - ntohl (msg->estate), - ntohl (msg->cstate)); + ntohs (msg->estate), + ntohs (msg->cstate)); }