diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-07-14 18:49:49 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-07-14 18:49:49 +0000 |
commit | 6db03408c6a8edb45c6636fb5e75ce0df72dab42 (patch) | |
tree | ec31210e0655ec2135fbd9f8efb2a461452e012e | |
parent | 3fe84176dfb6b14ecb7995126145060bec0c1269 (diff) | |
download | gnunet-6db03408c6a8edb45c6636fb5e75ce0df72dab42.tar.gz gnunet-6db03408c6a8edb45c6636fb5e75ce0df72dab42.zip |
-code cleanup
-rw-r--r-- | src/testbed/gnunet-testbed-helper.c | 89 | ||||
-rw-r--r-- | src/testbed/test_gnunet_testbed_helper.c | 26 |
2 files changed, 56 insertions, 59 deletions
diff --git a/src/testbed/gnunet-testbed-helper.c b/src/testbed/gnunet-testbed-helper.c index 371ac8951..edef3a52c 100644 --- a/src/testbed/gnunet-testbed-helper.c +++ b/src/testbed/gnunet-testbed-helper.c | |||
@@ -28,12 +28,9 @@ | |||
28 | * should the connection from the remote controller is dropped | 28 | * should the connection from the remote controller is dropped |
29 | * @author Sree Harsha Totakura <sreeharsha@totakura.in> | 29 | * @author Sree Harsha Totakura <sreeharsha@totakura.in> |
30 | */ | 30 | */ |
31 | |||
32 | |||
33 | #include "platform.h" | 31 | #include "platform.h" |
34 | #include "gnunet_util_lib.h" | 32 | #include "gnunet_util_lib.h" |
35 | #include "gnunet_testing_lib-new.h" | 33 | #include "gnunet_testing_lib-new.h" |
36 | |||
37 | #include "testbed_helper.h" | 34 | #include "testbed_helper.h" |
38 | 35 | ||
39 | 36 | ||
@@ -60,24 +57,15 @@ struct GNUNET_SERVER_MessageStreamTokenizer *tokenizer; | |||
60 | static struct GNUNET_DISK_FileHandle *stdin_fd; | 57 | static struct GNUNET_DISK_FileHandle *stdin_fd; |
61 | 58 | ||
62 | /** | 59 | /** |
63 | * Message receive buffer | ||
64 | */ | ||
65 | static void *buf; | ||
66 | |||
67 | /** | ||
68 | * The size of the above buffer | ||
69 | */ | ||
70 | static size_t buf_size; | ||
71 | |||
72 | /** | ||
73 | * Task identifier for the read task | 60 | * Task identifier for the read task |
74 | */ | 61 | */ |
75 | static GNUNET_SCHEDULER_TaskIdentifier read_task_id; | 62 | static GNUNET_SCHEDULER_TaskIdentifier read_task_id; |
76 | 63 | ||
77 | /** | 64 | /** |
78 | * Task identifier for the shutdown task | 65 | * Are we done reading messages from stdin? |
79 | */ | 66 | */ |
80 | static GNUNET_SCHEDULER_TaskIdentifier shutdown_task_id; | 67 | static int done_reading; |
68 | |||
81 | 69 | ||
82 | /** | 70 | /** |
83 | * Task to shutting down nicely | 71 | * Task to shutting down nicely |
@@ -89,12 +77,18 @@ static void | |||
89 | shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 77 | shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
90 | { | 78 | { |
91 | if (GNUNET_SCHEDULER_NO_TASK != read_task_id) | 79 | if (GNUNET_SCHEDULER_NO_TASK != read_task_id) |
80 | { | ||
92 | GNUNET_SCHEDULER_cancel (read_task_id); | 81 | GNUNET_SCHEDULER_cancel (read_task_id); |
82 | read_task_id = GNUNET_SCHEDULER_NO_TASK; | ||
83 | } | ||
93 | (void) GNUNET_DISK_file_close (stdin_fd); | 84 | (void) GNUNET_DISK_file_close (stdin_fd); |
94 | GNUNET_free_non_null (buf); | ||
95 | GNUNET_SERVER_mst_destroy (tokenizer); | 85 | GNUNET_SERVER_mst_destroy (tokenizer); |
86 | tokenizer = NULL; | ||
96 | if (NULL != test_system) | 87 | if (NULL != test_system) |
88 | { | ||
97 | GNUNET_TESTING_system_destroy (test_system, GNUNET_YES); | 89 | GNUNET_TESTING_system_destroy (test_system, GNUNET_YES); |
90 | test_system = NULL; | ||
91 | } | ||
98 | } | 92 | } |
99 | 93 | ||
100 | 94 | ||
@@ -115,6 +109,8 @@ tokenizer_cb (void *cls, void *client, | |||
115 | const struct GNUNET_MessageHeader *message) | 109 | const struct GNUNET_MessageHeader *message) |
116 | { | 110 | { |
117 | GNUNET_break (0); | 111 | GNUNET_break (0); |
112 | // FIXME: write config & start gnunet-service-testbed | ||
113 | done_reading = GNUNET_YES; | ||
118 | return GNUNET_OK; | 114 | return GNUNET_OK; |
119 | } | 115 | } |
120 | 116 | ||
@@ -128,35 +124,38 @@ tokenizer_cb (void *cls, void *client, | |||
128 | static void | 124 | static void |
129 | read_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 125 | read_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
130 | { | 126 | { |
127 | char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE]; | ||
131 | ssize_t sread; | 128 | ssize_t sread; |
132 | static int ignore_reading = GNUNET_NO; | ||
133 | int ret; | ||
134 | 129 | ||
135 | read_task_id = GNUNET_SCHEDULER_NO_TASK; | 130 | read_task_id = GNUNET_SCHEDULER_NO_TASK; |
136 | if (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) | 131 | if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason)) |
137 | return; | 132 | return; |
138 | sread = GNUNET_DISK_file_read (stdin_fd, buf, buf_size); | 133 | sread = GNUNET_DISK_file_read (stdin_fd, buf, sizeof (buf)); |
139 | if (GNUNET_SYSERR == sread) | 134 | if (GNUNET_SYSERR == sread) |
140 | { | 135 | { |
141 | GNUNET_break (0); /* FIXME: stdin closed - kill child */ | 136 | GNUNET_break (0); /* FIXME: stdin closed - kill child */ |
142 | GNUNET_SCHEDULER_cancel (shutdown_task_id); | 137 | GNUNET_SCHEDULER_shutdown (); |
143 | shutdown_task_id = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); | 138 | return; |
139 | } | ||
140 | if (GNUNET_YES == done_reading) | ||
141 | { | ||
142 | /* didn't expect any more data! */ | ||
143 | GNUNET_break (0); | ||
144 | GNUNET_SCHEDULER_shutdown (); | ||
144 | return; | 145 | return; |
145 | } | 146 | } |
146 | LOG_DEBUG ("Read %u bytes\n", sread); | 147 | LOG_DEBUG ("Read %u bytes\n", sread); |
148 | if (GNUNET_OK != | ||
149 | GNUNET_SERVER_mst_receive (tokenizer, NULL, buf, sread, | ||
150 | GNUNET_NO, GNUNET_NO)) | ||
151 | { | ||
152 | GNUNET_break (0); | ||
153 | GNUNET_SCHEDULER_shutdown (); | ||
154 | return; | ||
155 | } | ||
147 | read_task_id = /* No timeout while reading */ | 156 | read_task_id = /* No timeout while reading */ |
148 | GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, | 157 | GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, |
149 | stdin_fd, &read_task, NULL); | 158 | stdin_fd, &read_task, NULL); |
150 | if (GNUNET_YES == ignore_reading) | ||
151 | return; | ||
152 | ret = GNUNET_SERVER_mst_receive (tokenizer, NULL, buf, sread, | ||
153 | GNUNET_NO, GNUNET_NO); | ||
154 | GNUNET_assert (GNUNET_SYSERR != ret); | ||
155 | if (GNUNET_NO == ret) | ||
156 | { | ||
157 | LOG_DEBUG ("We only listen for 1 message -- ignoring others\n"); | ||
158 | ignore_reading = GNUNET_YES; | ||
159 | } | ||
160 | } | 159 | } |
161 | 160 | ||
162 | 161 | ||
@@ -175,14 +174,11 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
175 | LOG_DEBUG ("Starting testbed helper...\n"); | 174 | LOG_DEBUG ("Starting testbed helper...\n"); |
176 | tokenizer = GNUNET_SERVER_mst_create (&tokenizer_cb, NULL); | 175 | tokenizer = GNUNET_SERVER_mst_create (&tokenizer_cb, NULL); |
177 | stdin_fd = GNUNET_DISK_get_handle_from_native (stdin); | 176 | stdin_fd = GNUNET_DISK_get_handle_from_native (stdin); |
178 | buf_size = sizeof (struct GNUNET_TESTBED_HelperInit) + 8 * 1024; | 177 | read_task_id = |
179 | buf = GNUNET_malloc (buf_size); | ||
180 | read_task_id = /* No timeout while reading */ | ||
181 | GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, | 178 | GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, |
182 | stdin_fd, &read_task, NULL); | 179 | stdin_fd, &read_task, NULL); |
183 | shutdown_task_id = | 180 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, |
184 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, | 181 | &shutdown_task, NULL); |
185 | &shutdown_task, NULL); | ||
186 | } | 182 | } |
187 | 183 | ||
188 | 184 | ||
@@ -195,14 +191,15 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
195 | */ | 191 | */ |
196 | int main (int argc, char **argv) | 192 | int main (int argc, char **argv) |
197 | { | 193 | { |
198 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 194 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
199 | GNUNET_GETOPT_OPTION_END | 195 | GNUNET_GETOPT_OPTION_END |
200 | }; | 196 | }; |
201 | 197 | if (GNUNET_OK != | |
202 | if (GNUNET_OK != | 198 | GNUNET_PROGRAM_run (argc, argv, "gnunet-testbed-helper", |
203 | GNUNET_PROGRAM_run ( argc, argv, "gnunet-testbed-helper", | 199 | "Helper for starting gnunet-service-testbed", |
204 | "Helper for starting gnunet-service-testbed", | 200 | options, &run, NULL)) |
205 | options, &run, NULL)) | 201 | return 1; |
206 | return 1; | 202 | return 0; |
207 | else return 0; | ||
208 | } | 203 | } |
204 | |||
205 | /* end of gnunet-testbed-helper.c */ | ||
diff --git a/src/testbed/test_gnunet_testbed_helper.c b/src/testbed/test_gnunet_testbed_helper.c index b41410ce9..30f562bad 100644 --- a/src/testbed/test_gnunet_testbed_helper.c +++ b/src/testbed/test_gnunet_testbed_helper.c | |||
@@ -45,7 +45,6 @@ static struct GNUNET_HELPER_Handle *helper; | |||
45 | */ | 45 | */ |
46 | static struct GNUNET_TESTBED_HelperInit msg; | 46 | static struct GNUNET_TESTBED_HelperInit msg; |
47 | 47 | ||
48 | |||
49 | /** | 48 | /** |
50 | * Message send handle | 49 | * Message send handle |
51 | */ | 50 | */ |
@@ -115,7 +114,6 @@ cont_cb (void *cls, int result) | |||
115 | } | 114 | } |
116 | 115 | ||
117 | 116 | ||
118 | |||
119 | /** | 117 | /** |
120 | * Main function that will be run. | 118 | * Main function that will be run. |
121 | * | 119 | * |
@@ -128,12 +126,12 @@ static void | |||
128 | run (void *cls, char *const *args, const char *cfgfile, | 126 | run (void *cls, char *const *args, const char *cfgfile, |
129 | const struct GNUNET_CONFIGURATION_Handle * cfg) | 127 | const struct GNUNET_CONFIGURATION_Handle * cfg) |
130 | { | 128 | { |
131 | char * const binary_argv[] = { | 129 | static char * const binary_argv[] = { |
132 | "gnunet-testbed-helper", | 130 | "gnunet-testbed-helper", |
133 | NULL | 131 | NULL |
134 | }; | 132 | }; |
135 | 133 | helper = GNUNET_HELPER_start ("gnunet-testbed-helper", | |
136 | helper = GNUNET_HELPER_start ("gnunet-testbed-helper", binary_argv, | 134 | binary_argv, |
137 | NULL, NULL); | 135 | NULL, NULL); |
138 | GNUNET_assert (NULL != helper); | 136 | GNUNET_assert (NULL != helper); |
139 | msg.header.size = htons (sizeof (struct GNUNET_TESTBED_HelperInit)); | 137 | msg.header.size = htons (sizeof (struct GNUNET_TESTBED_HelperInit)); |
@@ -141,8 +139,8 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
141 | msg.cname_size = htons (0); | 139 | msg.cname_size = htons (0); |
142 | msg.config_size = htons (0); | 140 | msg.config_size = htons (0); |
143 | shandle = GNUNET_HELPER_send (helper, | 141 | shandle = GNUNET_HELPER_send (helper, |
144 | (const struct GNUNET_MessageHeader *) &msg, | 142 | &msg.header, |
145 | GNUNET_NO, cont_cb, NULL); | 143 | GNUNET_NO, &cont_cb, NULL); |
146 | GNUNET_assert (NULL != shandle); | 144 | GNUNET_assert (NULL != shandle); |
147 | abort_task = GNUNET_SCHEDULER_add_delayed | 145 | abort_task = GNUNET_SCHEDULER_add_delayed |
148 | (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 1), &do_abort, NULL); | 146 | (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 1), &do_abort, NULL); |
@@ -162,10 +160,12 @@ int main (int argc, char **argv) | |||
162 | GNUNET_GETOPT_OPTION_END | 160 | GNUNET_GETOPT_OPTION_END |
163 | }; | 161 | }; |
164 | 162 | ||
165 | if (GNUNET_OK != | 163 | if (GNUNET_OK != |
166 | GNUNET_PROGRAM_run (argc, argv, "test_gnunet_testbed_helper", | 164 | GNUNET_PROGRAM_run (argc, argv, "test_gnunet_testbed_helper", |
167 | "Testcase for testing gnunet-testbed-helper.c", | 165 | "Testcase for testing gnunet-testbed-helper.c", |
168 | options, &run, NULL)) | 166 | options, &run, NULL)) |
169 | return 1; | 167 | return 1; |
170 | else return 0; | 168 | return 0; |
171 | } | 169 | } |
170 | |||
171 | /* end of test_gnunet_testbed_helper.c */ | ||