diff options
Diffstat (limited to 'src/core/test_core_api.c')
-rw-r--r-- | src/core/test_core_api.c | 207 |
1 files changed, 83 insertions, 124 deletions
diff --git a/src/core/test_core_api.c b/src/core/test_core_api.c index 0cf88a324..1e268c3a6 100644 --- a/src/core/test_core_api.c +++ b/src/core/test_core_api.c | |||
@@ -11,7 +11,7 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
@@ -54,7 +54,16 @@ static struct GNUNET_SCHEDULER_Task *err_task; | |||
54 | 54 | ||
55 | static int ok; | 55 | static int ok; |
56 | 56 | ||
57 | #define OKPP do { ok++; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Now at stage %u at %s:%u\n", ok, __FILE__, __LINE__); } while (0) | 57 | #define OKPP \ |
58 | do \ | ||
59 | { \ | ||
60 | ok++; \ | ||
61 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, \ | ||
62 | "Now at stage %u at %s:%u\n", \ | ||
63 | ok, \ | ||
64 | __FILE__, \ | ||
65 | __LINE__); \ | ||
66 | } while (0) | ||
58 | 67 | ||
59 | 68 | ||
60 | static void | 69 | static void |
@@ -67,8 +76,7 @@ offer_hello_done (void *cls) | |||
67 | 76 | ||
68 | 77 | ||
69 | static void | 78 | static void |
70 | process_hello (void *cls, | 79 | process_hello (void *cls, const struct GNUNET_MessageHeader *message) |
71 | const struct GNUNET_MessageHeader *message) | ||
72 | { | 80 | { |
73 | struct PeerContext *p = cls; | 81 | struct PeerContext *p = cls; |
74 | 82 | ||
@@ -76,14 +84,11 @@ process_hello (void *cls, | |||
76 | "Received (my) HELLO from transport service\n"); | 84 | "Received (my) HELLO from transport service\n"); |
77 | GNUNET_assert (message != NULL); | 85 | GNUNET_assert (message != NULL); |
78 | if ((p == &p1) && (NULL == p2.oh)) | 86 | if ((p == &p1) && (NULL == p2.oh)) |
79 | p2.oh = GNUNET_TRANSPORT_offer_hello (p2.cfg, message, | 87 | p2.oh = |
80 | &offer_hello_done, | 88 | GNUNET_TRANSPORT_offer_hello (p2.cfg, message, &offer_hello_done, &p2); |
81 | &p2); | ||
82 | if ((p == &p2) && (NULL == p1.oh)) | 89 | if ((p == &p2) && (NULL == p1.oh)) |
83 | p1.oh = GNUNET_TRANSPORT_offer_hello (p1.cfg, | 90 | p1.oh = |
84 | message, | 91 | GNUNET_TRANSPORT_offer_hello (p1.cfg, message, &offer_hello_done, &p1); |
85 | &offer_hello_done, | ||
86 | &p1); | ||
87 | } | 92 | } |
88 | 93 | ||
89 | 94 | ||
@@ -131,9 +136,7 @@ terminate_task (void *cls) | |||
131 | static void | 136 | static void |
132 | terminate_task_error (void *cls) | 137 | terminate_task_error (void *cls) |
133 | { | 138 | { |
134 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 139 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ENDING ANGRILY %u\n", ok); |
135 | "ENDING ANGRILY %u\n", | ||
136 | ok); | ||
137 | GNUNET_break (0); | 140 | GNUNET_break (0); |
138 | terminate_peer (&p1); | 141 | terminate_peer (&p1); |
139 | terminate_peer (&p2); | 142 | terminate_peer (&p2); |
@@ -144,15 +147,13 @@ terminate_task_error (void *cls) | |||
144 | static void * | 147 | static void * |
145 | connect_notify (void *cls, | 148 | connect_notify (void *cls, |
146 | const struct GNUNET_PeerIdentity *peer, | 149 | const struct GNUNET_PeerIdentity *peer, |
147 | struct GNUNET_MQ_Handle *mq) | 150 | struct GNUNET_MQ_Handle *mq) |
148 | { | 151 | { |
149 | struct PeerContext *pc = cls; | 152 | struct PeerContext *pc = cls; |
150 | struct GNUNET_MQ_Envelope *env; | 153 | struct GNUNET_MQ_Envelope *env; |
151 | struct GNUNET_MessageHeader *msg; | 154 | struct GNUNET_MessageHeader *msg; |
152 | 155 | ||
153 | if (0 == memcmp (&pc->id, | 156 | if (0 == memcmp (&pc->id, peer, sizeof (struct GNUNET_PeerIdentity))) |
154 | peer, | ||
155 | sizeof (struct GNUNET_PeerIdentity))) | ||
156 | return (void *) peer; | 157 | return (void *) peer; |
157 | GNUNET_assert (pc->connect_status == 0); | 158 | GNUNET_assert (pc->connect_status == 0); |
158 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 159 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -161,26 +162,18 @@ connect_notify (void *cls, | |||
161 | pc->connect_status = 1; | 162 | pc->connect_status = 1; |
162 | if (pc == &p1) | 163 | if (pc == &p1) |
163 | { | 164 | { |
164 | uint64_t flags; | ||
165 | const void *extra; | ||
166 | |||
167 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 165 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
168 | "Asking core (1) for transmission to peer `%s'\n", | 166 | "Asking core (1) for transmission to peer `%s'\n", |
169 | GNUNET_i2s (&p2.id)); | 167 | GNUNET_i2s (&p2.id)); |
170 | env = GNUNET_MQ_msg (msg, | 168 | env = GNUNET_MQ_msg (msg, MTYPE); |
171 | MTYPE); | ||
172 | /* enable corking for this test */ | 169 | /* enable corking for this test */ |
173 | extra = GNUNET_CORE_get_mq_options (GNUNET_YES, | ||
174 | GNUNET_CORE_PRIO_BEST_EFFORT, | ||
175 | &flags); | ||
176 | GNUNET_MQ_env_set_options (env, | 170 | GNUNET_MQ_env_set_options (env, |
177 | flags, | 171 | GNUNET_MQ_PRIO_BEST_EFFORT | |
178 | extra); | 172 | GNUNET_MQ_PREF_CORK_ALLOWED); |
179 | /* now actually transmit message */ | 173 | /* now actually transmit message */ |
180 | GNUNET_assert (ok == 4); | 174 | GNUNET_assert (ok == 4); |
181 | OKPP; | 175 | OKPP; |
182 | GNUNET_MQ_send (mq, | 176 | GNUNET_MQ_send (mq, env); |
183 | env); | ||
184 | } | 177 | } |
185 | return (void *) peer; | 178 | return (void *) peer; |
186 | } | 179 | } |
@@ -188,25 +181,22 @@ connect_notify (void *cls, | |||
188 | 181 | ||
189 | static void | 182 | static void |
190 | disconnect_notify (void *cls, | 183 | disconnect_notify (void *cls, |
191 | const struct GNUNET_PeerIdentity *peer, | 184 | const struct GNUNET_PeerIdentity *peer, |
192 | void *internal_cls) | 185 | void *internal_cls) |
193 | { | 186 | { |
194 | struct PeerContext *pc = cls; | 187 | struct PeerContext *pc = cls; |
195 | 188 | ||
196 | if (0 == memcmp (&pc->id, | 189 | if (0 == memcmp (&pc->id, peer, sizeof (struct GNUNET_PeerIdentity))) |
197 | peer, | ||
198 | sizeof (struct GNUNET_PeerIdentity))) | ||
199 | return; | 190 | return; |
200 | pc->connect_status = 0; | 191 | pc->connect_status = 0; |
201 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 192 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
202 | "Encrypted connection to `%s' cut\n", | 193 | "Encrypted connection to `%s' cut\n", |
203 | GNUNET_i2s (peer)); | 194 | GNUNET_i2s (peer)); |
204 | } | 195 | } |
205 | 196 | ||
206 | 197 | ||
207 | static void | 198 | static void |
208 | handle_test (void *cls, | 199 | handle_test (void *cls, const struct GNUNET_MessageHeader *message) |
209 | const struct GNUNET_MessageHeader *message) | ||
210 | { | 200 | { |
211 | const struct GNUNET_PeerIdentity *peer = cls; | 201 | const struct GNUNET_PeerIdentity *peer = cls; |
212 | 202 | ||
@@ -216,23 +206,17 @@ handle_test (void *cls, | |||
216 | GNUNET_assert (ok == 5); | 206 | GNUNET_assert (ok == 5); |
217 | OKPP; | 207 | OKPP; |
218 | GNUNET_SCHEDULER_cancel (err_task); | 208 | GNUNET_SCHEDULER_cancel (err_task); |
219 | err_task = GNUNET_SCHEDULER_add_now (&terminate_task, | 209 | err_task = GNUNET_SCHEDULER_add_now (&terminate_task, NULL); |
220 | NULL); | ||
221 | } | 210 | } |
222 | 211 | ||
223 | 212 | ||
224 | static void | 213 | static void |
225 | init_notify (void *cls, | 214 | init_notify (void *cls, const struct GNUNET_PeerIdentity *my_identity) |
226 | const struct GNUNET_PeerIdentity *my_identity) | ||
227 | { | 215 | { |
228 | struct PeerContext *p = cls; | 216 | struct PeerContext *p = cls; |
229 | struct GNUNET_MQ_MessageHandler handlers[] = { | 217 | struct GNUNET_MQ_MessageHandler handlers[] = |
230 | GNUNET_MQ_hd_fixed_size (test, | 218 | {GNUNET_MQ_hd_fixed_size (test, MTYPE, struct GNUNET_MessageHeader, NULL), |
231 | MTYPE, | 219 | GNUNET_MQ_handler_end ()}; |
232 | struct GNUNET_MessageHeader, | ||
233 | NULL), | ||
234 | GNUNET_MQ_handler_end () | ||
235 | }; | ||
236 | 220 | ||
237 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 221 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
238 | "Core connection to `%s' established\n", | 222 | "Core connection to `%s' established\n", |
@@ -244,50 +228,46 @@ init_notify (void *cls, | |||
244 | OKPP; | 228 | OKPP; |
245 | /* connect p2 */ | 229 | /* connect p2 */ |
246 | p2.ch = GNUNET_CORE_connect (p2.cfg, | 230 | p2.ch = GNUNET_CORE_connect (p2.cfg, |
247 | &p2, | 231 | &p2, |
248 | &init_notify, | 232 | &init_notify, |
249 | &connect_notify, | 233 | &connect_notify, |
250 | &disconnect_notify, | 234 | &disconnect_notify, |
251 | handlers); | 235 | handlers); |
252 | } | 236 | } |
253 | else | 237 | else |
254 | { | 238 | { |
255 | GNUNET_assert (ok == 3); | 239 | GNUNET_assert (ok == 3); |
256 | OKPP; | 240 | OKPP; |
257 | GNUNET_assert (cls == &p2); | 241 | GNUNET_assert (cls == &p2); |
258 | p1.ats_sh = GNUNET_ATS_connectivity_suggest (p1.ats, | 242 | p1.ats_sh = GNUNET_ATS_connectivity_suggest (p1.ats, &p2.id, 1); |
259 | &p2.id, | ||
260 | 1); | ||
261 | } | 243 | } |
262 | } | 244 | } |
263 | 245 | ||
264 | 246 | ||
265 | static void | 247 | static void |
266 | setup_peer (struct PeerContext *p, | 248 | setup_peer (struct PeerContext *p, const char *cfgname) |
267 | const char *cfgname) | ||
268 | { | 249 | { |
269 | char *binary; | 250 | char *binary; |
270 | 251 | ||
271 | binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm"); | 252 | binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm"); |
272 | p->cfg = GNUNET_CONFIGURATION_create (); | 253 | p->cfg = GNUNET_CONFIGURATION_create (); |
273 | p->arm_proc = | 254 | p->arm_proc = GNUNET_OS_start_process (GNUNET_YES, |
274 | GNUNET_OS_start_process (GNUNET_YES, | 255 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, |
275 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, | 256 | NULL, |
276 | NULL, NULL, NULL, | 257 | NULL, |
277 | binary, | 258 | NULL, |
278 | "gnunet-service-arm", | 259 | binary, |
279 | "-c", | 260 | "gnunet-service-arm", |
280 | cfgname, | 261 | "-c", |
281 | NULL); | 262 | cfgname, |
282 | GNUNET_assert (GNUNET_OK == | 263 | NULL); |
283 | GNUNET_CONFIGURATION_load (p->cfg, | 264 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); |
284 | cfgname)); | ||
285 | p->ats = GNUNET_ATS_connectivity_init (p->cfg); | 265 | p->ats = GNUNET_ATS_connectivity_init (p->cfg); |
286 | GNUNET_assert (NULL != p->ats); | 266 | GNUNET_assert (NULL != p->ats); |
287 | p->ghh = GNUNET_TRANSPORT_hello_get (p->cfg, | 267 | p->ghh = GNUNET_TRANSPORT_hello_get (p->cfg, |
288 | GNUNET_TRANSPORT_AC_ANY, | 268 | GNUNET_TRANSPORT_AC_ANY, |
289 | &process_hello, | 269 | &process_hello, |
290 | p); | 270 | p); |
291 | GNUNET_free (binary); | 271 | GNUNET_free (binary); |
292 | } | 272 | } |
293 | 273 | ||
@@ -298,47 +278,36 @@ run (void *cls, | |||
298 | const char *cfgfile, | 278 | const char *cfgfile, |
299 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 279 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
300 | { | 280 | { |
301 | struct GNUNET_MQ_MessageHandler handlers[] = { | 281 | struct GNUNET_MQ_MessageHandler handlers[] = |
302 | GNUNET_MQ_hd_fixed_size (test, | 282 | {GNUNET_MQ_hd_fixed_size (test, MTYPE, struct GNUNET_MessageHeader, NULL), |
303 | MTYPE, | 283 | GNUNET_MQ_handler_end ()}; |
304 | struct GNUNET_MessageHeader, | ||
305 | NULL), | ||
306 | GNUNET_MQ_handler_end () | ||
307 | }; | ||
308 | 284 | ||
309 | GNUNET_assert (ok == 1); | 285 | GNUNET_assert (ok == 1); |
310 | OKPP; | 286 | OKPP; |
311 | setup_peer (&p1, | 287 | setup_peer (&p1, "test_core_api_peer1.conf"); |
312 | "test_core_api_peer1.conf"); | 288 | setup_peer (&p2, "test_core_api_peer2.conf"); |
313 | setup_peer (&p2, | 289 | err_task = GNUNET_SCHEDULER_add_delayed ( |
314 | "test_core_api_peer2.conf"); | 290 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300), |
315 | err_task = | 291 | &terminate_task_error, |
316 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 292 | NULL); |
317 | (GNUNET_TIME_UNIT_SECONDS, 300), | 293 | p1.ch = GNUNET_CORE_connect (p1.cfg, |
318 | &terminate_task_error, NULL); | 294 | &p1, |
319 | p1.ch = | 295 | &init_notify, |
320 | GNUNET_CORE_connect (p1.cfg, | 296 | &connect_notify, |
321 | &p1, | 297 | &disconnect_notify, |
322 | &init_notify, | 298 | handlers); |
323 | &connect_notify, | ||
324 | &disconnect_notify, | ||
325 | handlers); | ||
326 | } | 299 | } |
327 | 300 | ||
328 | 301 | ||
329 | static void | 302 | static void |
330 | stop_arm (struct PeerContext *p) | 303 | stop_arm (struct PeerContext *p) |
331 | { | 304 | { |
332 | if (0 != GNUNET_OS_process_kill (p->arm_proc, | 305 | if (0 != GNUNET_OS_process_kill (p->arm_proc, GNUNET_TERM_SIG)) |
333 | GNUNET_TERM_SIG)) | 306 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); |
334 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, | 307 | if (GNUNET_OK != GNUNET_OS_process_wait (p->arm_proc)) |
335 | "kill"); | 308 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); |
336 | if (GNUNET_OK != | ||
337 | GNUNET_OS_process_wait (p->arm_proc)) | ||
338 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, | ||
339 | "waitpid"); | ||
340 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 309 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
341 | "ARM process %u stopped\n", | 310 | "ARM process %u stopped\n", |
342 | GNUNET_OS_process_get_pid (p->arm_proc)); | 311 | GNUNET_OS_process_get_pid (p->arm_proc)); |
343 | GNUNET_OS_process_destroy (p->arm_proc); | 312 | GNUNET_OS_process_destroy (p->arm_proc); |
344 | p->arm_proc = NULL; | 313 | p->arm_proc = NULL; |
@@ -347,29 +316,19 @@ stop_arm (struct PeerContext *p) | |||
347 | 316 | ||
348 | 317 | ||
349 | int | 318 | int |
350 | main (int argc, | 319 | main (int argc, char *argv1[]) |
351 | char *argv1[]) | ||
352 | { | 320 | { |
353 | char *const argv[] = { | 321 | char *const argv[] = {"test-core-api", "-c", "test_core_api_data.conf", NULL}; |
354 | "test-core-api", | 322 | struct GNUNET_GETOPT_CommandLineOption options[] = {GNUNET_GETOPT_OPTION_END}; |
355 | "-c", | ||
356 | "test_core_api_data.conf", | ||
357 | NULL | ||
358 | }; | ||
359 | struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
360 | GNUNET_GETOPT_OPTION_END | ||
361 | }; | ||
362 | ok = 1; | 323 | ok = 1; |
363 | GNUNET_log_setup ("test-core-api", | 324 | GNUNET_log_setup ("test-core-api", "WARNING", NULL); |
364 | "WARNING", | ||
365 | NULL); | ||
366 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, | 325 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, |
367 | argv, | 326 | argv, |
368 | "test-core-api", | 327 | "test-core-api", |
369 | "nohelp", | 328 | "nohelp", |
370 | options, | 329 | options, |
371 | &run, | 330 | &run, |
372 | &ok); | 331 | &ok); |
373 | stop_arm (&p1); | 332 | stop_arm (&p1); |
374 | stop_arm (&p2); | 333 | stop_arm (&p2); |
375 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-1"); | 334 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-1"); |