diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/mesh/gnunet-service-mesh.c | 53 | ||||
-rw-r--r-- | src/mesh/mesh.h | 2 | ||||
-rw-r--r-- | src/mesh/test_mesh.conf | 2 | ||||
-rw-r--r-- | src/mesh/test_mesh_api.c | 120 |
4 files changed, 126 insertions, 51 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); |
diff --git a/src/mesh/mesh.h b/src/mesh/mesh.h index d317e8054..88106ca9a 100644 --- a/src/mesh/mesh.h +++ b/src/mesh/mesh.h | |||
@@ -78,6 +78,8 @@ struct GNUNET_MESH_ClientConnect { | |||
78 | struct GNUNET_MessageHeader header; | 78 | struct GNUNET_MessageHeader header; |
79 | uint16_t types GNUNET_PACKED; | 79 | uint16_t types GNUNET_PACKED; |
80 | uint16_t applications GNUNET_PACKED; | 80 | uint16_t applications GNUNET_PACKED; |
81 | /* uint16_t list_types[types] */ | ||
82 | /* uint16_t list_apps[applications] */ | ||
81 | }; | 83 | }; |
82 | 84 | ||
83 | 85 | ||
diff --git a/src/mesh/test_mesh.conf b/src/mesh/test_mesh.conf index 49da05129..bd8f199c8 100644 --- a/src/mesh/test_mesh.conf +++ b/src/mesh/test_mesh.conf | |||
@@ -5,7 +5,7 @@ AUTOSTART = NO | |||
5 | AUTOSTART = NO | 5 | AUTOSTART = NO |
6 | 6 | ||
7 | [mesh] | 7 | [mesh] |
8 | DEBUG = YES | 8 | DEBUG = NO |
9 | AUTOSTART = YES | 9 | AUTOSTART = YES |
10 | ACCEPT_FROM = 127.0.0.1; | 10 | ACCEPT_FROM = 127.0.0.1; |
11 | HOSTNAME = localhost | 11 | HOSTNAME = localhost |
diff --git a/src/mesh/test_mesh_api.c b/src/mesh/test_mesh_api.c index 6c3bd60a9..4c4bf9c4c 100644 --- a/src/mesh/test_mesh_api.c +++ b/src/mesh/test_mesh_api.c | |||
@@ -1,20 +1,47 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2011 Christian Grothoff (and other contributing authors) | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file mesh/test_mesh_api.c | ||
23 | * @brief test mesh api: dummy test of callbacks | ||
24 | * @author Bartlomiej Polot | ||
25 | */ | ||
26 | |||
1 | #include "platform.h" | 27 | #include "platform.h" |
2 | #include "gnunet_util_lib.h" | 28 | #include "gnunet_util_lib.h" |
3 | #include "gnunet_dht_service.h" | 29 | #include "gnunet_dht_service.h" |
4 | #include "gnunet_mesh_service_new.h" | 30 | #include "gnunet_mesh_service_new.h" |
5 | 31 | ||
6 | static struct GNUNET_MESH_MessageHandler handlers[] = { | 32 | static struct GNUNET_MESH_MessageHandler handlers[] = {{NULL, 0, 0}}; |
7 | {NULL, 0, 0} | 33 | static struct GNUNET_OS_Process *arm_pid; |
8 | }; | 34 | static struct GNUNET_MESH_Handle *mesh; |
9 | 35 | static int result; | |
10 | static struct GNUNET_OS_Process *arm_pid; | 36 | GNUNET_SCHEDULER_TaskIdentifier abort_task; |
11 | 37 | GNUNET_SCHEDULER_TaskIdentifier test_task; | |
12 | static struct GNUNET_MESH_Handle *mesh; | ||
13 | 38 | ||
14 | static void | 39 | static void |
15 | do_shutdown (void *cls, | 40 | do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
16 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
17 | { | 41 | { |
42 | if (0 != abort_task) { | ||
43 | GNUNET_SCHEDULER_cancel(abort_task); | ||
44 | } | ||
18 | if (NULL != mesh) { | 45 | if (NULL != mesh) { |
19 | GNUNET_MESH_disconnect (mesh); | 46 | GNUNET_MESH_disconnect (mesh); |
20 | } | 47 | } |
@@ -25,50 +52,67 @@ do_shutdown (void *cls, | |||
25 | GNUNET_OS_process_close (arm_pid); | 52 | GNUNET_OS_process_close (arm_pid); |
26 | } | 53 | } |
27 | 54 | ||
28 | |||
29 | static void | 55 | static void |
30 | error_shutdown (void *cls, | 56 | do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
31 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
32 | { | 57 | { |
33 | if (NULL != mesh) { | 58 | if (0 != test_task) { |
34 | GNUNET_MESH_disconnect (mesh); | 59 | GNUNET_SCHEDULER_cancel(test_task); |
35 | } | 60 | } |
36 | if (0 != GNUNET_OS_process_kill (arm_pid, SIGTERM)) { | 61 | result = GNUNET_SYSERR; |
37 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | 62 | abort_task = 0; |
38 | } | 63 | do_shutdown(cls, tc); |
39 | GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (arm_pid)); | ||
40 | GNUNET_OS_process_close (arm_pid); | ||
41 | } | 64 | } |
42 | 65 | ||
43 | static void | 66 | static void |
44 | run (void *cls, | 67 | test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
45 | char *const *args, | 68 | { |
46 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) { | 69 | struct GNUNET_CONFIGURATION_Handle *cfg = cls; |
47 | GNUNET_MESH_ApplicationType app; | 70 | GNUNET_MESH_ApplicationType app; |
48 | 71 | ||
49 | arm_pid = GNUNET_OS_start_process (NULL, NULL, | 72 | test_task = 0; |
50 | "gnunet-service-arm", | ||
51 | "gnunet-service-arm", | ||
52 | "-L", "DEBUG", | ||
53 | "-c", "test_mesh.conf", | ||
54 | NULL); | ||
55 | app = 0; | 73 | app = 0; |
56 | mesh = GNUNET_MESH_connect(cfg, NULL, NULL, handlers, &app); | 74 | mesh = GNUNET_MESH_connect(cfg, NULL, NULL, handlers, &app); |
57 | if(NULL == mesh) { | 75 | if(NULL == mesh) { |
58 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Couldn't connect to mesh :(\n"); | 76 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Couldn't connect to mesh :(\n"); |
77 | return; | ||
59 | } else { | 78 | } else { |
60 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "YAY! CONNECTED TO MESH :D\n"); | 79 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "YAY! CONNECTED TO MESH :D\n"); |
61 | } | 80 | } |
62 | 81 | ||
63 | /* do real test work here */ | ||
64 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply( | 82 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply( |
65 | GNUNET_TIME_UNIT_SECONDS, 5), | 83 | GNUNET_TIME_UNIT_SECONDS, 1), |
66 | &do_shutdown, | 84 | &do_shutdown, |
67 | NULL); | 85 | NULL); |
86 | } | ||
87 | |||
88 | |||
89 | static void | ||
90 | run (void *cls, | ||
91 | char *const *args, | ||
92 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
93 | { | ||
94 | arm_pid = GNUNET_OS_start_process (NULL, NULL, | ||
95 | "gnunet-service-arm", | ||
96 | "gnunet-service-arm", | ||
97 | "-L", "DEBUG", | ||
98 | "-c", "test_mesh.conf", | ||
99 | NULL); | ||
100 | |||
101 | abort_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply( | ||
102 | GNUNET_TIME_UNIT_SECONDS, 5), | ||
103 | &do_abort, | ||
104 | NULL); | ||
105 | test_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply( | ||
106 | GNUNET_TIME_UNIT_SECONDS, 1), | ||
107 | &test, | ||
108 | (void *)cfg); | ||
109 | |||
68 | } | 110 | } |
69 | 111 | ||
70 | 112 | ||
71 | int main (int argc, char *argv[]) { | 113 | int |
114 | main (int argc, char *argv[]) | ||
115 | { | ||
72 | int ret; | 116 | int ret; |
73 | char *const argv2[] = {"test-mesh-api", | 117 | char *const argv2[] = {"test-mesh-api", |
74 | "-c", "test_mesh.conf", | 118 | "-c", "test_mesh.conf", |
@@ -82,9 +126,15 @@ int main (int argc, char *argv[]) { | |||
82 | ret = GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, | 126 | ret = GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, |
83 | argv2, "test-mesh-api", "nohelp", | 127 | argv2, "test-mesh-api", "nohelp", |
84 | options, &run, NULL); | 128 | options, &run, NULL); |
85 | if (ret != GNUNET_OK) { | 129 | |
130 | if ( GNUNET_OK != ret ) { | ||
131 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | ||
132 | "test-mesh-api': run failed with error code %d\n", ret); | ||
133 | return 1; | ||
134 | } | ||
135 | if ( GNUNET_SYSERR == result ) { | ||
86 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 136 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
87 | "test-mesh-api': Failed with error code %d\n", ret); | 137 | "test-mesh-api': test failed\n"); |
88 | return 1; | 138 | return 1; |
89 | } | 139 | } |
90 | return 0; | 140 | return 0; |