From: Bart Polot Date: Mon, 13 Jan 2014 19:33:49 +0000 (+0000) Subject: - various CLI fixes X-Git-Tag: initial-import-from-subversion-38251~5064 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=bcc04f0a5babd8283ff50c5dd13e0afccdb2e5f4;p=oweals%2Fgnunet.git - various CLI fixes --- diff --git a/src/mesh/gnunet-mesh.c b/src/mesh/gnunet-mesh.c index afdd94a9c..b1071b344 100644 --- a/src/mesh/gnunet-mesh.c +++ b/src/mesh/gnunet-mesh.c @@ -659,21 +659,21 @@ main (int argc, char *const *argv) int res; const char helpstr[] = "Create channels and retreive info about meshs status."; static const struct GNUNET_GETOPT_CommandLineOption options[] = { - {'a', "channel", "TUNNEL_ID:CHANNEL_ID", - gettext_noop ("provide information about a particular channel"), - GNUNET_YES, &GNUNET_GETOPT_set_string, &channel_id}, - {'b', "connection", "TUNNEL_ID:CONNECTION_ID", - gettext_noop ("provide information about a particular connection"), - GNUNET_YES, &GNUNET_GETOPT_set_string, &conn_id}, +// {'a', "channel", "TUNNEL_ID:CHANNEL_ID", +// gettext_noop ("provide information about a particular channel"), +// GNUNET_YES, &GNUNET_GETOPT_set_string, &channel_id}, +// {'b', "connection", "TUNNEL_ID:CONNECTION_ID", +// gettext_noop ("provide information about a particular connection"), +// GNUNET_YES, &GNUNET_GETOPT_set_string, &conn_id}, {'e', "echo", NULL, gettext_noop ("activate echo mode"), GNUNET_NO, &GNUNET_GETOPT_set_one, &echo}, {'i', "info", NULL, gettext_noop ("provide information about all tunnels"), GNUNET_NO, &GNUNET_GETOPT_set_one, &get_info}, - {'m', "monitor", NULL, - gettext_noop ("provide information about all tunnels (continuously) NOT IMPLEMENTED"), /* FIXME */ - GNUNET_NO, &GNUNET_GETOPT_set_one, &monitor_connections}, +// {'m', "monitor", NULL, +// gettext_noop ("provide information about all tunnels (continuously) NOT IMPLEMENTED"), /* FIXME */ +// GNUNET_NO, &GNUNET_GETOPT_set_one, &monitor_connections}, {'p', "port", NULL, gettext_noop ("port to listen to (default; 0)"), GNUNET_YES, &GNUNET_GETOPT_set_uint, &listen_port}, diff --git a/src/mesh/gnunet-service-mesh_local.c b/src/mesh/gnunet-service-mesh_local.c index 0470d982d..11812de79 100644 --- a/src/mesh/gnunet-service-mesh_local.c +++ b/src/mesh/gnunet-service-mesh_local.c @@ -651,8 +651,19 @@ handle_get_tunnels (void *cls, struct GNUNET_SERVER_Client *client, } +static void +iter_connection (void *cls, struct MeshConnection *c) +{ +} + +static void +iter_channel (void *cls, struct MeshChannel *ch) +{ +} + + /** - * Handler for client's MONITOR_TUNNEL request. + * Handler for client's SHOW_TUNNEL request. * * @param cls Closure (unused). * @param client Identification of the client. @@ -663,9 +674,12 @@ handle_show_tunnel (void *cls, struct GNUNET_SERVER_Client *client, const struct GNUNET_MessageHeader *message) { const struct GNUNET_MESH_LocalInfo *msg; - struct GNUNET_MESH_LocalInfo *resp; + struct GNUNET_MESH_LocalInfoTunnel *resp; struct MeshClient *c; - struct MeshChannel *ch; + struct MeshTunnel3 *t; + unsigned int ch_n; + unsigned int c_n; + size_t size; /* Sanity check for client registration */ if (NULL == (c = GML_client_get (client))) @@ -677,18 +691,23 @@ handle_show_tunnel (void *cls, struct GNUNET_SERVER_Client *client, 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, - &msg->owner, - ntohl (msg->channel_id)); -// ch = channel_get (&msg->owner, ntohl (msg->channel_id)); - ch = NULL; // FIXME - if (NULL == ch) + "Received tunnel info request from client %u for tunnel %s\n", + c->id, GNUNET_i2s_full(&msg->peer)); + + t = GMP_get_tunnel (GMP_get (&msg->peer)); + if (NULL == t) { /* We don't know the tunnel */ - struct GNUNET_MESH_LocalInfo warn; + struct GNUNET_MESH_LocalInfoTunnel warn; + + warn.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNEL); + warn.header.size = htons (sizeof (warn)); + warn.destination = msg->peer; + warn.channels = htonl (0); + warn.connections = htonl (0); + warn.cstate = htons (0); + warn.estate = htons (0); - warn = *msg; GNUNET_SERVER_notification_context_unicast (nc, client, &warn.header, GNUNET_NO); @@ -697,16 +716,27 @@ handle_show_tunnel (void *cls, struct GNUNET_SERVER_Client *client, } /* Initialize context */ - resp = GNUNET_new (struct GNUNET_MESH_LocalInfo); - *resp = *msg; - resp->header.size = htons (sizeof (struct GNUNET_MESH_LocalInfo)); + ch_n = GMT_count_channels (t); + c_n = GMT_count_connections (t); + + size = sizeof (struct GNUNET_MESH_LocalInfo); + size += c_n * sizeof (struct GNUNET_HashCode); + size += ch_n * sizeof (uint32_t); + + resp = GNUNET_malloc (size); + resp->header.size = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNEL); + resp->header.size = htons (size); + GMT_iterate_connections (t, &iter_connection, resp); + GMT_iterate_channels (t, &iter_channel, resp); + resp->cstate = htons (GMT_get_cstate (t)); + resp->estate = htons (GMT_get_estate (t)); GNUNET_SERVER_notification_context_unicast (nc, c->handle, &resp->header, GNUNET_NO); GNUNET_free (resp); LOG (GNUNET_ERROR_TYPE_INFO, - "Monitor tunnel request from client %u completed\n", - c->id); + "Show tunnel request from client %u completed\n", + c->id); GNUNET_SERVER_receive_done (client, GNUNET_OK); } diff --git a/src/mesh/gnunet-service-mesh_peer.c b/src/mesh/gnunet-service-mesh_peer.c index daefa31fa..f801a9e4e 100644 --- a/src/mesh/gnunet-service-mesh_peer.c +++ b/src/mesh/gnunet-service-mesh_peer.c @@ -1787,7 +1787,6 @@ GMP_get_short_id (const struct MeshPeer *peer) struct MeshTunnel3 * GMP_get_tunnel (const struct MeshPeer *peer) { - GNUNET_assert (NULL != peer->tunnel); return peer->tunnel; } diff --git a/src/mesh/gnunet-service-mesh_tunnel.c b/src/mesh/gnunet-service-mesh_tunnel.c index b8350ca04..7b51106af 100644 --- a/src/mesh/gnunet-service-mesh_tunnel.c +++ b/src/mesh/gnunet-service-mesh_tunnel.c @@ -2660,3 +2660,21 @@ GMT_count_all (void) { return GNUNET_CONTAINER_multipeermap_size (tunnels); } + +void +GMT_iterate_connections (struct MeshTunnel3 *t, GMT_conn_iter iter, void *cls) +{ + struct MeshTConnection *ct; + + for (ct = t->connection_head; NULL != ct; ct = ct->next) + iter (cls, ct->c); +} + +void +GMT_iterate_channels (struct MeshTunnel3 *t, GMT_chan_iter iter, void *cls) +{ + struct MeshTChannel *cht; + + for (cht = t->channel_head; NULL != cht; cht = cht->next) + iter (cls, cht->ch); +} diff --git a/src/mesh/gnunet-service-mesh_tunnel.h b/src/mesh/gnunet-service-mesh_tunnel.h index e38d313cb..3a6f9fdc1 100644 --- a/src/mesh/gnunet-service-mesh_tunnel.h +++ b/src/mesh/gnunet-service-mesh_tunnel.h @@ -123,6 +123,9 @@ typedef void (*GMT_sent) (void *cls, struct MeshTunnel3Queue *q, uint16_t type, size_t size); +typedef void (*GMT_conn_iter) (void *cls, struct MeshConnection *c); +typedef void (*GMT_chan_iter) (void *cls, struct MeshChannel *ch); + /******************************************************************************/ /******************************** API ***********************************/ @@ -479,6 +482,12 @@ GMT_iterate_all (void *cls, GNUNET_CONTAINER_PeerMapIterator iter); unsigned int GMT_count_all (void); +void +GMT_iterate_connections (struct MeshTunnel3 *t, GMT_conn_iter iter, void *cls); + +void +GMT_iterate_channels (struct MeshTunnel3 *t, GMT_chan_iter iter, void *cls); + #if 0 /* keep Emacsens' auto-indent happy */ { #endif diff --git a/src/mesh/mesh.h b/src/mesh/mesh.h index bb71d1668..7011bd51a 100644 --- a/src/mesh/mesh.h +++ b/src/mesh/mesh.h @@ -181,12 +181,12 @@ struct GNUNET_MESH_LocalInfo /** * ID of the owner of the channel (can be local peer). */ - struct GNUNET_PeerIdentity owner; +// struct GNUNET_PeerIdentity owner; /** * ID of the destination of the channel (can be local peer). */ - struct GNUNET_PeerIdentity destination; + struct GNUNET_PeerIdentity peer; }; /** diff --git a/src/mesh/mesh_api.c b/src/mesh/mesh_api.c index 878d7a2b8..96f25617f 100644 --- a/src/mesh/mesh_api.c +++ b/src/mesh/mesh_api.c @@ -1804,7 +1804,7 @@ GNUNET_MESH_get_tunnel (struct GNUNET_MESH_Handle *h, 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; + msg.peer = *id; send_packet (h, &msg.header, NULL); h->tunnel_cb = callback; h->tunnel_cls = callback_cls; @@ -1834,7 +1834,7 @@ GNUNET_MESH_show_channel (struct GNUNET_MESH_Handle *h, msg.header.size = htons (sizeof (msg)); msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_CHANNEL); - msg.owner = *initiator; + msg.peer = *initiator; msg.channel_id = htonl (channel_number); // msg.reserved = 0; send_packet (h, &msg.header, NULL);