From 80417c48637b498d62f2c6eefb5e1a6fc8d5ed50 Mon Sep 17 00:00:00 2001 From: Bart Polot Date: Wed, 15 May 2013 12:52:16 +0000 Subject: [PATCH] - stop using message types of payload on service side --- src/mesh/gnunet-service-mesh-new.c | 59 ++++++------------------------ src/mesh/mesh2.h | 5 +-- src/mesh/mesh2_api.c | 18 ++------- 3 files changed, 16 insertions(+), 66 deletions(-) diff --git a/src/mesh/gnunet-service-mesh-new.c b/src/mesh/gnunet-service-mesh-new.c index 729b536a4..6a1eb8b33 100644 --- a/src/mesh/gnunet-service-mesh-new.c +++ b/src/mesh/gnunet-service-mesh-new.c @@ -398,7 +398,7 @@ struct MeshTunnel /** * Struct containing information about a client of the service * - * TODO: add a list of 'waiting' types + * TODO: add a list of 'waiting' ports */ struct MeshClient { @@ -427,12 +427,6 @@ struct MeshClient */ struct GNUNET_SERVER_Client *handle; - /** - * Messages that this client has declared interest in. - * Indexed by a GMC_hash32 (type), contains *Client. - */ - struct GNUNET_CONTAINER_MultiHashMap *types; - /** * Ports that this client has declared interest in. * Indexed by a GMC_hash32 (type), contains *Client. @@ -631,11 +625,6 @@ static MESH_TunnelNumber next_tid; */ static MESH_TunnelNumber next_local_tid; -/** - * All message types clients of this peer are interested in. - */ -static struct GNUNET_CONTAINER_MultiHashMap *types; - /** * All ports clients of this peer have opened. */ @@ -3823,8 +3812,8 @@ handle_local_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client) GNUNET_CONTAINER_multihashmap_destroy (c->own_tunnels); GNUNET_CONTAINER_multihashmap_destroy (c->incoming_tunnels); - if (NULL != c->types) - GNUNET_CONTAINER_multihashmap_destroy (c->types); + if (NULL != c->ports) + GNUNET_CONTAINER_multihashmap_destroy (c->ports); next = c->next; GNUNET_CONTAINER_DLL_remove (clients_head, clients_tail, c); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " CLIENT FREE at %p\n", c); @@ -3851,9 +3840,6 @@ handle_local_new_client (void *cls, struct GNUNET_SERVER_Client *client, struct GNUNET_MESH_ClientConnect *cc_msg; struct MeshClient *c; unsigned int size; - uint16_t ntypes; - uint16_t nports; - uint16_t *t; uint32_t *p; unsigned int i; @@ -3862,51 +3848,29 @@ handle_local_new_client (void *cls, struct GNUNET_SERVER_Client *client, /* Check data sanity */ size = ntohs (message->size) - sizeof (struct GNUNET_MESH_ClientConnect); cc_msg = (struct GNUNET_MESH_ClientConnect *) message; - ntypes = ntohs (cc_msg->types); - nports = ntohs (cc_msg->ports); - if (size != ntypes * sizeof (uint16_t)) + if (0 != (size % sizeof (uint32_t))) { GNUNET_break (0); GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); return; } + size /= sizeof (uint32_t); /* Create new client structure */ c = GNUNET_malloc (sizeof (struct MeshClient)); c->id = next_client_id++; /* overflow not important: just for debug */ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " CLIENT NEW %u\n", c->id); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " client has %u types\n", ntypes); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " client id %u\n", c->id); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " client has %u ports\n", size); c->handle = client; GNUNET_SERVER_client_keep (client); - t = (uint16_t *) &cc_msg[1]; - if (ntypes > 0) - { - uint16_t u16; - struct GNUNET_HashCode hc; - - c->types = GNUNET_CONTAINER_multihashmap_create (ntypes, GNUNET_NO); - for (i = 0; i < ntypes; i++) - { - u16 = ntohs (t[i]); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " msg type: %u\n", u16); - GMC_hash32 ((uint32_t) u16, &hc); - - /* store in client's hashmap */ - GNUNET_CONTAINER_multihashmap_put (c->types, &hc, c, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); - /* store in global hashmap */ - GNUNET_CONTAINER_multihashmap_put (types, &hc, c, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); - } - } - if (nports > 0) + if (size > 0) { uint32_t u32; struct GNUNET_HashCode hc; - p = (uint32_t *) &t[ntypes]; - c->ports = GNUNET_CONTAINER_multihashmap_create (nports, GNUNET_NO); - for (i = 0; i < nports; i++) + p = (uint32_t *) &cc_msg[1]; + c->ports = GNUNET_CONTAINER_multihashmap_create (size, GNUNET_NO); + for (i = 0; i < size; i++) { u32 = ntohl (p[i]); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " port: %u\n", u32); @@ -4983,7 +4947,6 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, tunnels = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_NO); incoming_tunnels = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_NO); peers = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_NO); - types = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_NO); ports = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_NO); dht_handle = GNUNET_DHT_connect (c, 64); diff --git a/src/mesh/mesh2.h b/src/mesh/mesh2.h index d42a630a0..c66a810a1 100644 --- a/src/mesh/mesh2.h +++ b/src/mesh/mesh2.h @@ -112,10 +112,7 @@ struct GNUNET_MESH_ClientConnect * sizeof(uint16_t) * types */ struct GNUNET_MessageHeader header; - uint16_t types GNUNET_PACKED; - uint16_t ports GNUNET_PACKED; - /* uint16_t list_types[types] */ - /* uint32_t list_ports[ports] */ + /* uint32_t list_ports[] */ }; diff --git a/src/mesh/mesh2_api.c b/src/mesh/mesh2_api.c index 31681bec1..57a5ce1ed 100644 --- a/src/mesh/mesh2_api.c +++ b/src/mesh/mesh2_api.c @@ -643,11 +643,10 @@ send_connect (struct GNUNET_MESH_Handle *h) size_t size; size = sizeof (struct GNUNET_MESH_ClientConnect); - size += h->n_handlers * sizeof (uint16_t); + size += h->n_ports * sizeof (uint32_t); { char buf[size] GNUNET_ALIGN; struct GNUNET_MESH_ClientConnect *msg; - uint16_t *types; uint32_t *ports; uint16_t i; @@ -655,16 +654,7 @@ send_connect (struct GNUNET_MESH_Handle *h) msg = (struct GNUNET_MESH_ClientConnect *) buf; msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT); msg->header.size = htons (size); - msg->types = htons (h->n_handlers); - msg->ports = htons (h->n_ports); - types = (uint16_t *) &msg[1]; - for (i = 0; i < h->n_handlers; i++) - { - types[i] = htons (h->message_handlers[i].type); - LOG (GNUNET_ERROR_TYPE_DEBUG, " type %u\n", - h->message_handlers[i].type); - } - ports = (uint32_t *) &types[h->n_handlers]; + ports = (uint32_t *) &msg[1]; for (i = 0; i < h->n_ports; i++) { ports[i] = htonl (h->ports[i]); @@ -672,8 +662,8 @@ send_connect (struct GNUNET_MESH_Handle *h) h->ports[i]); } LOG (GNUNET_ERROR_TYPE_DEBUG, - "Sending %lu bytes long message %u types and %u ports\n", - ntohs (msg->header.size), h->n_handlers, h->n_ports); + "Sending %lu bytes long message with %u ports\n", + ntohs (msg->header.size), h->n_ports); send_packet (h, &msg->header, NULL); } } -- 2.25.1