aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2013-05-15 12:52:16 +0000
committerBart Polot <bart@net.in.tum.de>2013-05-15 12:52:16 +0000
commit80417c48637b498d62f2c6eefb5e1a6fc8d5ed50 (patch)
tree5248d5c056603116ae7ddd356094a27e10095dd1
parent653905eb0e2ada9c3c5832d7e1a36c71f8b9f02e (diff)
downloadgnunet-80417c48637b498d62f2c6eefb5e1a6fc8d5ed50.tar.gz
gnunet-80417c48637b498d62f2c6eefb5e1a6fc8d5ed50.zip
- stop using message types of payload on service side
-rw-r--r--src/mesh/gnunet-service-mesh-new.c59
-rw-r--r--src/mesh/mesh2.h5
-rw-r--r--src/mesh/mesh2_api.c18
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
398/** 398/**
399 * Struct containing information about a client of the service 399 * Struct containing information about a client of the service
400 * 400 *
401 * TODO: add a list of 'waiting' types 401 * TODO: add a list of 'waiting' ports
402 */ 402 */
403struct MeshClient 403struct MeshClient
404{ 404{
@@ -428,12 +428,6 @@ struct MeshClient
428 struct GNUNET_SERVER_Client *handle; 428 struct GNUNET_SERVER_Client *handle;
429 429
430 /** 430 /**
431 * Messages that this client has declared interest in.
432 * Indexed by a GMC_hash32 (type), contains *Client.
433 */
434 struct GNUNET_CONTAINER_MultiHashMap *types;
435
436 /**
437 * Ports that this client has declared interest in. 431 * Ports that this client has declared interest in.
438 * Indexed by a GMC_hash32 (type), contains *Client. 432 * Indexed by a GMC_hash32 (type), contains *Client.
439 */ 433 */
@@ -632,11 +626,6 @@ static MESH_TunnelNumber next_tid;
632static MESH_TunnelNumber next_local_tid; 626static MESH_TunnelNumber next_local_tid;
633 627
634/** 628/**
635 * All message types clients of this peer are interested in.
636 */
637static struct GNUNET_CONTAINER_MultiHashMap *types;
638
639/**
640 * All ports clients of this peer have opened. 629 * All ports clients of this peer have opened.
641 */ 630 */
642static struct GNUNET_CONTAINER_MultiHashMap *ports; 631static struct GNUNET_CONTAINER_MultiHashMap *ports;
@@ -3823,8 +3812,8 @@ handle_local_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
3823 GNUNET_CONTAINER_multihashmap_destroy (c->own_tunnels); 3812 GNUNET_CONTAINER_multihashmap_destroy (c->own_tunnels);
3824 GNUNET_CONTAINER_multihashmap_destroy (c->incoming_tunnels); 3813 GNUNET_CONTAINER_multihashmap_destroy (c->incoming_tunnels);
3825 3814
3826 if (NULL != c->types) 3815 if (NULL != c->ports)
3827 GNUNET_CONTAINER_multihashmap_destroy (c->types); 3816 GNUNET_CONTAINER_multihashmap_destroy (c->ports);
3828 next = c->next; 3817 next = c->next;
3829 GNUNET_CONTAINER_DLL_remove (clients_head, clients_tail, c); 3818 GNUNET_CONTAINER_DLL_remove (clients_head, clients_tail, c);
3830 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " CLIENT FREE at %p\n", c); 3819 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,
3851 struct GNUNET_MESH_ClientConnect *cc_msg; 3840 struct GNUNET_MESH_ClientConnect *cc_msg;
3852 struct MeshClient *c; 3841 struct MeshClient *c;
3853 unsigned int size; 3842 unsigned int size;
3854 uint16_t ntypes;
3855 uint16_t nports;
3856 uint16_t *t;
3857 uint32_t *p; 3843 uint32_t *p;
3858 unsigned int i; 3844 unsigned int i;
3859 3845
@@ -3862,51 +3848,29 @@ handle_local_new_client (void *cls, struct GNUNET_SERVER_Client *client,
3862 /* Check data sanity */ 3848 /* Check data sanity */
3863 size = ntohs (message->size) - sizeof (struct GNUNET_MESH_ClientConnect); 3849 size = ntohs (message->size) - sizeof (struct GNUNET_MESH_ClientConnect);
3864 cc_msg = (struct GNUNET_MESH_ClientConnect *) message; 3850 cc_msg = (struct GNUNET_MESH_ClientConnect *) message;
3865 ntypes = ntohs (cc_msg->types); 3851 if (0 != (size % sizeof (uint32_t)))
3866 nports = ntohs (cc_msg->ports);
3867 if (size != ntypes * sizeof (uint16_t))
3868 { 3852 {
3869 GNUNET_break (0); 3853 GNUNET_break (0);
3870 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 3854 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
3871 return; 3855 return;
3872 } 3856 }
3857 size /= sizeof (uint32_t);
3873 3858
3874 /* Create new client structure */ 3859 /* Create new client structure */
3875 c = GNUNET_malloc (sizeof (struct MeshClient)); 3860 c = GNUNET_malloc (sizeof (struct MeshClient));
3876 c->id = next_client_id++; /* overflow not important: just for debug */ 3861 c->id = next_client_id++; /* overflow not important: just for debug */
3877 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " CLIENT NEW %u\n", c->id); 3862 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " client id %u\n", c->id);
3878 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " client has %u types\n", ntypes); 3863 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " client has %u ports\n", size);
3879 c->handle = client; 3864 c->handle = client;
3880 GNUNET_SERVER_client_keep (client); 3865 GNUNET_SERVER_client_keep (client);
3881 t = (uint16_t *) &cc_msg[1]; 3866 if (size > 0)
3882 if (ntypes > 0)
3883 {
3884 uint16_t u16;
3885 struct GNUNET_HashCode hc;
3886
3887 c->types = GNUNET_CONTAINER_multihashmap_create (ntypes, GNUNET_NO);
3888 for (i = 0; i < ntypes; i++)
3889 {
3890 u16 = ntohs (t[i]);
3891 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " msg type: %u\n", u16);
3892 GMC_hash32 ((uint32_t) u16, &hc);
3893
3894 /* store in client's hashmap */
3895 GNUNET_CONTAINER_multihashmap_put (c->types, &hc, c,
3896 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
3897 /* store in global hashmap */
3898 GNUNET_CONTAINER_multihashmap_put (types, &hc, c,
3899 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
3900 }
3901 }
3902 if (nports > 0)
3903 { 3867 {
3904 uint32_t u32; 3868 uint32_t u32;
3905 struct GNUNET_HashCode hc; 3869 struct GNUNET_HashCode hc;
3906 3870
3907 p = (uint32_t *) &t[ntypes]; 3871 p = (uint32_t *) &cc_msg[1];
3908 c->ports = GNUNET_CONTAINER_multihashmap_create (nports, GNUNET_NO); 3872 c->ports = GNUNET_CONTAINER_multihashmap_create (size, GNUNET_NO);
3909 for (i = 0; i < nports; i++) 3873 for (i = 0; i < size; i++)
3910 { 3874 {
3911 u32 = ntohl (p[i]); 3875 u32 = ntohl (p[i]);
3912 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " port: %u\n", u32); 3876 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " port: %u\n", u32);
@@ -4983,7 +4947,6 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
4983 tunnels = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_NO); 4947 tunnels = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_NO);
4984 incoming_tunnels = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_NO); 4948 incoming_tunnels = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_NO);
4985 peers = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_NO); 4949 peers = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_NO);
4986 types = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_NO);
4987 ports = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_NO); 4950 ports = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_NO);
4988 4951
4989 dht_handle = GNUNET_DHT_connect (c, 64); 4952 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
112 * sizeof(uint16_t) * types 112 * sizeof(uint16_t) * types
113 */ 113 */
114 struct GNUNET_MessageHeader header; 114 struct GNUNET_MessageHeader header;
115 uint16_t types GNUNET_PACKED; 115 /* uint32_t list_ports[] */
116 uint16_t ports GNUNET_PACKED;
117 /* uint16_t list_types[types] */
118 /* uint32_t list_ports[ports] */
119}; 116};
120 117
121 118
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)
643 size_t size; 643 size_t size;
644 644
645 size = sizeof (struct GNUNET_MESH_ClientConnect); 645 size = sizeof (struct GNUNET_MESH_ClientConnect);
646 size += h->n_handlers * sizeof (uint16_t); 646 size += h->n_ports * sizeof (uint32_t);
647 { 647 {
648 char buf[size] GNUNET_ALIGN; 648 char buf[size] GNUNET_ALIGN;
649 struct GNUNET_MESH_ClientConnect *msg; 649 struct GNUNET_MESH_ClientConnect *msg;
650 uint16_t *types;
651 uint32_t *ports; 650 uint32_t *ports;
652 uint16_t i; 651 uint16_t i;
653 652
@@ -655,16 +654,7 @@ send_connect (struct GNUNET_MESH_Handle *h)
655 msg = (struct GNUNET_MESH_ClientConnect *) buf; 654 msg = (struct GNUNET_MESH_ClientConnect *) buf;
656 msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT); 655 msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT);
657 msg->header.size = htons (size); 656 msg->header.size = htons (size);
658 msg->types = htons (h->n_handlers); 657 ports = (uint32_t *) &msg[1];
659 msg->ports = htons (h->n_ports);
660 types = (uint16_t *) &msg[1];
661 for (i = 0; i < h->n_handlers; i++)
662 {
663 types[i] = htons (h->message_handlers[i].type);
664 LOG (GNUNET_ERROR_TYPE_DEBUG, " type %u\n",
665 h->message_handlers[i].type);
666 }
667 ports = (uint32_t *) &types[h->n_handlers];
668 for (i = 0; i < h->n_ports; i++) 658 for (i = 0; i < h->n_ports; i++)
669 { 659 {
670 ports[i] = htonl (h->ports[i]); 660 ports[i] = htonl (h->ports[i]);
@@ -672,8 +662,8 @@ send_connect (struct GNUNET_MESH_Handle *h)
672 h->ports[i]); 662 h->ports[i]);
673 } 663 }
674 LOG (GNUNET_ERROR_TYPE_DEBUG, 664 LOG (GNUNET_ERROR_TYPE_DEBUG,
675 "Sending %lu bytes long message %u types and %u ports\n", 665 "Sending %lu bytes long message with %u ports\n",
676 ntohs (msg->header.size), h->n_handlers, h->n_ports); 666 ntohs (msg->header.size), h->n_ports);
677 send_packet (h, &msg->header, NULL); 667 send_packet (h, &msg->header, NULL);
678 } 668 }
679} 669}