diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2012-07-14 23:26:59 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2012-07-14 23:26:59 +0000 |
commit | eefde2a44c9b631fd31c9aaf5c6627cd21020b03 (patch) | |
tree | 147b7bb9a223fe763dbf859da38a80ef17096297 /src/testbed | |
parent | 02a50518aeffa2745489f1b0098304efe4ec6bbb (diff) | |
download | gnunet-eefde2a44c9b631fd31c9aaf5c6627cd21020b03.tar.gz gnunet-eefde2a44c9b631fd31c9aaf5c6627cd21020b03.zip |
init message handling
Diffstat (limited to 'src/testbed')
-rw-r--r-- | src/testbed/gnunet-testbed-helper.c | 113 | ||||
-rw-r--r-- | src/testbed/testbed_helper.h | 5 |
2 files changed, 110 insertions, 8 deletions
diff --git a/src/testbed/gnunet-testbed-helper.c b/src/testbed/gnunet-testbed-helper.c index edef3a52c..5993702dc 100644 --- a/src/testbed/gnunet-testbed-helper.c +++ b/src/testbed/gnunet-testbed-helper.c | |||
@@ -32,14 +32,19 @@ | |||
32 | #include "gnunet_util_lib.h" | 32 | #include "gnunet_util_lib.h" |
33 | #include "gnunet_testing_lib-new.h" | 33 | #include "gnunet_testing_lib-new.h" |
34 | #include "testbed_helper.h" | 34 | #include "testbed_helper.h" |
35 | 35 | #include <zlib.h> | |
36 | 36 | ||
37 | /** | 37 | /** |
38 | * Generic debug logging shortcut | 38 | * Generic logging shortcut |
39 | */ | 39 | */ |
40 | #define LOG_DEBUG(...) \ | 40 | #define LOG(kind, ...) \ |
41 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) | 41 | GNUNET_log (kind, __VA_ARGS__) |
42 | 42 | ||
43 | /** | ||
44 | * Debug logging shorthand | ||
45 | */ | ||
46 | #define LOG_DEBUG(...) \ | ||
47 | LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) | ||
43 | 48 | ||
44 | /** | 49 | /** |
45 | * Handle to the testing system | 50 | * Handle to the testing system |
@@ -57,6 +62,21 @@ struct GNUNET_SERVER_MessageStreamTokenizer *tokenizer; | |||
57 | static struct GNUNET_DISK_FileHandle *stdin_fd; | 62 | static struct GNUNET_DISK_FileHandle *stdin_fd; |
58 | 63 | ||
59 | /** | 64 | /** |
65 | * The process handle to the testbed service | ||
66 | */ | ||
67 | static struct GNUNET_OS_Process *testbed; | ||
68 | |||
69 | /** | ||
70 | * Pipe handle to child's stdin | ||
71 | */ | ||
72 | static struct GNUNET_DISK_PipeHandle *pipe_in; | ||
73 | |||
74 | /** | ||
75 | * Pipe handle to child's stdout | ||
76 | */ | ||
77 | static struct GNUNET_DISK_PipeHandle *pipe_out; | ||
78 | |||
79 | /** | ||
60 | * Task identifier for the read task | 80 | * Task identifier for the read task |
61 | */ | 81 | */ |
62 | static GNUNET_SCHEDULER_TaskIdentifier read_task_id; | 82 | static GNUNET_SCHEDULER_TaskIdentifier read_task_id; |
@@ -66,6 +86,11 @@ static GNUNET_SCHEDULER_TaskIdentifier read_task_id; | |||
66 | */ | 86 | */ |
67 | static int done_reading; | 87 | static int done_reading; |
68 | 88 | ||
89 | /** | ||
90 | * Result to return in case we fail | ||
91 | */ | ||
92 | static int ret; | ||
93 | |||
69 | 94 | ||
70 | /** | 95 | /** |
71 | * Task to shutting down nicely | 96 | * Task to shutting down nicely |
@@ -108,10 +133,82 @@ static int | |||
108 | tokenizer_cb (void *cls, void *client, | 133 | tokenizer_cb (void *cls, void *client, |
109 | const struct GNUNET_MessageHeader *message) | 134 | const struct GNUNET_MessageHeader *message) |
110 | { | 135 | { |
111 | GNUNET_break (0); | 136 | const struct GNUNET_TESTBED_HelperInit *msg; |
112 | // FIXME: write config & start gnunet-service-testbed | 137 | struct GNUNET_CONFIGURATION_Handle *cfg; |
138 | char *controller; | ||
139 | char *config; | ||
140 | uLongf config_size; | ||
141 | uint16_t xconfig_size; | ||
142 | uint16_t cname_size; | ||
143 | |||
144 | if ((sizeof (struct GNUNET_TESTBED_HelperInit) >= ntohs (message->size)) || | ||
145 | (GNUNET_MESSAGE_TYPE_TESTBED_HELPER_INIT != ntohs (message->type))) | ||
146 | { | ||
147 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
148 | "Received unexpected message -- exiting\n"); | ||
149 | goto error; | ||
150 | } | ||
151 | msg = (const struct GNUNET_TESTBED_HelperInit *) message; | ||
152 | cname_size = ntohs (msg->cname_size); | ||
153 | controller = (char *) &msg[1]; | ||
154 | if ('\0' != controller[cname_size]) | ||
155 | { | ||
156 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
157 | "Controller name cannot be empty -- exiting\n"); | ||
158 | goto error; | ||
159 | } | ||
160 | config_size = (uLongf) ntohs (msg->config_size); | ||
161 | config = GNUNET_malloc (config_size); | ||
162 | xconfig_size = ntohs (message->size) - (cname_size + 1); | ||
163 | if (Z_OK != uncompress ((Bytef *) config, &config_size, | ||
164 | (const Bytef *) (controller + cname_size + 1), | ||
165 | (uLongf) xconfig_size)) | ||
166 | { | ||
167 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
168 | "Error while uncompressing config -- exiting\n"); | ||
169 | GNUNET_free (config); | ||
170 | goto error; | ||
171 | } | ||
172 | cfg = GNUNET_CONFIGURATION_create (); | ||
173 | if (GNUNET_OK != GNUNET_CONFIGURATION_deserialize (cfg, config, config_size, | ||
174 | GNUNET_NO)) | ||
175 | { | ||
176 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
177 | "Unable to deserialize config -- exiting\n"); | ||
178 | GNUNET_free (config); | ||
179 | goto error; | ||
180 | } | ||
181 | GNUNET_free (config); | ||
182 | test_system = GNUNET_TESTING_system_create ("testbed-helper", controller); | ||
183 | GNUNET_assert (NULL != test_system); | ||
184 | GNUNET_assert (GNUNET_OK == GNUNET_TESTING_configuration_create | ||
185 | (test_system, cfg)); | ||
186 | pipe_in = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_YES, GNUNET_NO); | ||
187 | pipe_out = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_NO, GNUNET_YES); | ||
188 | if ((NULL == pipe_in) || (NULL == pipe_out)) | ||
189 | { | ||
190 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "pipe"); | ||
191 | GNUNET_free (config); | ||
192 | goto error; | ||
193 | } | ||
194 | testbed = GNUNET_OS_start_process | ||
195 | (GNUNET_YES, GNUNET_OS_INHERIT_STD_ERR /*verbose? */, pipe_in, pipe_out, | ||
196 | "gnunet-service-testbed", "gnunet-service-testbed", "-c", config, NULL); | ||
197 | if (NULL == testbed) | ||
198 | { | ||
199 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
200 | "Unable to deserialize config -- exiting\n"); | ||
201 | goto error; | ||
202 | } | ||
203 | GNUNET_DISK_pipe_close_end (pipe_out, GNUNET_DISK_PIPE_END_WRITE); | ||
204 | GNUNET_DISK_pipe_close_end (pipe_in, GNUNET_DISK_PIPE_END_READ); | ||
113 | done_reading = GNUNET_YES; | 205 | done_reading = GNUNET_YES; |
114 | return GNUNET_OK; | 206 | return GNUNET_OK; |
207 | |||
208 | error: | ||
209 | ret = GNUNET_SYSERR; | ||
210 | GNUNET_SCHEDULER_shutdown (); | ||
211 | return GNUNET_SYSERR; | ||
115 | } | 212 | } |
116 | 213 | ||
117 | 214 | ||
@@ -194,12 +291,14 @@ int main (int argc, char **argv) | |||
194 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 291 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
195 | GNUNET_GETOPT_OPTION_END | 292 | GNUNET_GETOPT_OPTION_END |
196 | }; | 293 | }; |
294 | |||
295 | ret = GNUNET_OK; | ||
197 | if (GNUNET_OK != | 296 | if (GNUNET_OK != |
198 | GNUNET_PROGRAM_run (argc, argv, "gnunet-testbed-helper", | 297 | GNUNET_PROGRAM_run (argc, argv, "gnunet-testbed-helper", |
199 | "Helper for starting gnunet-service-testbed", | 298 | "Helper for starting gnunet-service-testbed", |
200 | options, &run, NULL)) | 299 | options, &run, NULL)) |
201 | return 1; | 300 | return 1; |
202 | return 0; | 301 | return (GNUNET_OK == ret) ? 0 : 1; |
203 | } | 302 | } |
204 | 303 | ||
205 | /* end of gnunet-testbed-helper.c */ | 304 | /* end of gnunet-testbed-helper.c */ |
diff --git a/src/testbed/testbed_helper.h b/src/testbed/testbed_helper.h index f4f8abd39..8780d7e98 100644 --- a/src/testbed/testbed_helper.h +++ b/src/testbed/testbed_helper.h | |||
@@ -28,6 +28,9 @@ | |||
28 | #ifndef TESTBED_HELPER_H | 28 | #ifndef TESTBED_HELPER_H |
29 | #define TESTBED_HELPER_H | 29 | #define TESTBED_HELPER_H |
30 | 30 | ||
31 | /** | ||
32 | * Initialization message for gnunet-testbed-helper to start testbed service | ||
33 | */ | ||
31 | struct GNUNET_TESTBED_HelperInit | 34 | struct GNUNET_TESTBED_HelperInit |
32 | { | 35 | { |
33 | /** | 36 | /** |
@@ -42,7 +45,7 @@ struct GNUNET_TESTBED_HelperInit | |||
42 | uint16_t cname_size GNUNET_PACKED; | 45 | uint16_t cname_size GNUNET_PACKED; |
43 | 46 | ||
44 | /** | 47 | /** |
45 | * The sizeof the configuration following | 48 | * The size of the uncompressed configuration |
46 | */ | 49 | */ |
47 | uint16_t config_size GNUNET_PACKED; | 50 | uint16_t config_size GNUNET_PACKED; |
48 | 51 | ||