diff options
author | Bart Polot <bart@net.in.tum.de> | 2011-05-13 01:05:22 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2011-05-13 01:05:22 +0000 |
commit | d8c0c8836e4c00318f48ef71b0d1647851f51b9c (patch) | |
tree | a625503495ae2754d51b59b80e768845aaa226e0 /src/mesh/gnunet-service-mesh.c | |
parent | bb0f1a9c37476ebe08b2de7b6fb7f8b2ed0514b5 (diff) | |
download | gnunet-d8c0c8836e4c00318f48ef71b0d1647851f51b9c.tar.gz gnunet-d8c0c8836e4c00318f48ef71b0d1647851f51b9c.zip |
Finished basic connect/disconnect test
Diffstat (limited to 'src/mesh/gnunet-service-mesh.c')
-rw-r--r-- | src/mesh/gnunet-service-mesh.c | 53 |
1 files changed, 38 insertions, 15 deletions
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c index 2080a375f..77e09e88c 100644 --- a/src/mesh/gnunet-service-mesh.c +++ b/src/mesh/gnunet-service-mesh.c | |||
@@ -295,10 +295,16 @@ struct MeshClient | |||
295 | struct GNUNET_SERVER_Client *handle; | 295 | struct GNUNET_SERVER_Client *handle; |
296 | 296 | ||
297 | /** | 297 | /** |
298 | * Applications that this client has claimed to provide | ||
299 | */ | ||
300 | GNUNET_MESH_ApplicationType *apps; | ||
301 | unsigned int app_counter; | ||
302 | |||
303 | /** | ||
298 | * Messages that this client has declared interest in | 304 | * Messages that this client has declared interest in |
299 | */ | 305 | */ |
300 | GNUNET_MESH_ApplicationType *messages_subscribed; | 306 | uint16_t *types; |
301 | unsigned int subscription_counter; | 307 | unsigned int type_counter; |
302 | 308 | ||
303 | }; | 309 | }; |
304 | 310 | ||
@@ -681,12 +687,13 @@ handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client) | |||
681 | while (NULL != c) { | 687 | while (NULL != c) { |
682 | if (c->handle == client) { | 688 | if (c->handle == client) { |
683 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 689 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
684 | "MESH: cleaning client structures\n"); | 690 | "MESH: matching client found, cleaning\n"); |
685 | GNUNET_CONTAINER_DLL_remove (clients_head, clients_tail, c); | 691 | GNUNET_CONTAINER_DLL_remove (clients_head, clients_tail, c); |
686 | while (NULL != (t = c->tunnels_head)) { | 692 | while (NULL != (t = c->tunnels_head)) { |
687 | destroy_tunnel(c, t); | 693 | destroy_tunnel(c, t); |
688 | } | 694 | } |
689 | GNUNET_free (c->messages_subscribed); | 695 | if(0 != c->app_counter) GNUNET_free (c->apps); |
696 | if(0 != c->type_counter) GNUNET_free (c->types); | ||
690 | next = c->next; | 697 | next = c->next; |
691 | GNUNET_free (c); | 698 | GNUNET_free (c); |
692 | c = next; | 699 | c = next; |
@@ -710,14 +717,23 @@ handle_local_new_client (void *cls, | |||
710 | struct GNUNET_SERVER_Client *client, | 717 | struct GNUNET_SERVER_Client *client, |
711 | const struct GNUNET_MessageHeader *message) | 718 | const struct GNUNET_MessageHeader *message) |
712 | { | 719 | { |
713 | struct MeshClient *c; | 720 | struct GNUNET_MESH_ClientConnect *cc_msg; |
714 | unsigned int payload_size; | 721 | struct MeshClient *c; |
722 | unsigned int payload_size; | ||
723 | uint16_t types; | ||
724 | uint16_t apps; | ||
715 | 725 | ||
716 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 726 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
717 | "MESH: new client connected\n"); | 727 | "MESH: new client connected\n"); |
718 | /* Check data sanity */ | 728 | /* Check data sanity */ |
719 | payload_size = ntohs(message->size) - sizeof(struct GNUNET_MessageHeader); | 729 | payload_size = ntohs(message->size) |
720 | if (0 != payload_size % sizeof(GNUNET_MESH_ApplicationType)) { | 730 | - sizeof(struct GNUNET_MESH_ClientConnect); |
731 | cc_msg = (struct GNUNET_MESH_ClientConnect *) message; | ||
732 | types = ntohs(cc_msg->types); | ||
733 | apps = ntohs(cc_msg->applications); | ||
734 | if (payload_size != | ||
735 | types * sizeof(uint16_t) + apps * sizeof(GNUNET_MESH_ApplicationType)) | ||
736 | { | ||
721 | GNUNET_break(0); | 737 | GNUNET_break(0); |
722 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | 738 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); |
723 | return; | 739 | return; |
@@ -726,15 +742,22 @@ handle_local_new_client (void *cls, | |||
726 | /* Create new client structure */ | 742 | /* Create new client structure */ |
727 | c = GNUNET_malloc(sizeof(struct MeshClient)); | 743 | c = GNUNET_malloc(sizeof(struct MeshClient)); |
728 | c->handle = client; | 744 | c->handle = client; |
729 | if (payload_size != 0) { | 745 | if (types != 0) { |
730 | c->messages_subscribed = GNUNET_malloc(payload_size); | 746 | c->type_counter = types; |
731 | memcpy(c->messages_subscribed, &message[1], payload_size); | 747 | c->types = GNUNET_malloc(types * sizeof(uint16_t)); |
732 | } else { | 748 | memcpy(c->types, &message[1], types * sizeof(uint16_t)); |
733 | c->messages_subscribed = NULL; | 749 | } |
750 | if (apps != 0) { | ||
751 | c->app_counter = apps; | ||
752 | c->apps = GNUNET_malloc(apps * sizeof(GNUNET_MESH_ApplicationType)); | ||
753 | memcpy(c->apps, | ||
754 | &message[1] + types * sizeof(uint16_t), | ||
755 | apps * sizeof(GNUNET_MESH_ApplicationType)); | ||
734 | } | 756 | } |
735 | c->subscription_counter = payload_size/sizeof(GNUNET_MESH_ApplicationType); | ||
736 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 757 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
737 | "MESH: client has %u subscriptions\n", c->subscription_counter); | 758 | "MESH: client has %u+%u subscriptions\n", |
759 | c->type_counter, | ||
760 | c->app_counter); | ||
738 | 761 | ||
739 | /* Insert new client in DLL */ | 762 | /* Insert new client in DLL */ |
740 | GNUNET_CONTAINER_DLL_insert (clients_head, clients_tail, c); | 763 | GNUNET_CONTAINER_DLL_insert (clients_head, clients_tail, c); |