diff options
author | Gabor X Toth <*@tg-x.net> | 2015-09-26 17:09:57 +0000 |
---|---|---|
committer | Gabor X Toth <*@tg-x.net> | 2015-09-26 17:09:57 +0000 |
commit | 5a042e00e06de726a21d9db05ddeb2ac16ca7c0c (patch) | |
tree | 9b2f504796b72a50d061eb812be4aa87efbf6584 /src/multicast/test_multicast.c | |
parent | 0c5cea1c26efb8b53f643a6ce6b162d9c9fe2b8f (diff) | |
download | gnunet-5a042e00e06de726a21d9db05ddeb2ac16ca7c0c.tar.gz gnunet-5a042e00e06de726a21d9db05ddeb2ac16ca7c0c.zip |
multicast: replay
Diffstat (limited to 'src/multicast/test_multicast.c')
-rw-r--r-- | src/multicast/test_multicast.c | 211 |
1 files changed, 143 insertions, 68 deletions
diff --git a/src/multicast/test_multicast.c b/src/multicast/test_multicast.c index 528033452..d9b9ce0df 100644 --- a/src/multicast/test_multicast.c +++ b/src/multicast/test_multicast.c | |||
@@ -84,17 +84,21 @@ struct GNUNET_MessageHeader *join_req, *join_resp; | |||
84 | 84 | ||
85 | enum | 85 | enum |
86 | { | 86 | { |
87 | TEST_NONE = 0, | 87 | TEST_NONE = 0, |
88 | TEST_ORIGIN_START = 1, | 88 | TEST_ORIGIN_START = 1, |
89 | TEST_MEMBER_JOIN_REFUSE = 2, | 89 | TEST_MEMBER_JOIN_REFUSE = 2, |
90 | TEST_MEMBER_JOIN_ADMIT = 3, | 90 | TEST_MEMBER_JOIN_ADMIT = 3, |
91 | TEST_ORIGIN_TO_ALL = 4, | 91 | TEST_ORIGIN_TO_ALL = 4, |
92 | TEST_ORIGIN_TO_ALL_RECV = 5, | 92 | TEST_ORIGIN_TO_ALL_RECV = 5, |
93 | TEST_MEMBER_TO_ORIGIN = 6, | 93 | TEST_MEMBER_TO_ORIGIN = 6, |
94 | TEST_MEMBER_PART = 7, | 94 | TEST_MEMBER_REPLAY_ERROR = 7, |
95 | TEST_ORIGIN_STOP = 8, | 95 | TEST_MEMBER_REPLAY_OK = 8, |
96 | TEST_MEMBER_PART = 9, | ||
97 | TEST_ORIGIN_STOP = 10, | ||
96 | } test; | 98 | } test; |
97 | 99 | ||
100 | uint64_t replay_fragment_id; | ||
101 | uint64_t replay_flags; | ||
98 | 102 | ||
99 | static void | 103 | static void |
100 | member_join (int t); | 104 | member_join (int t); |
@@ -230,56 +234,6 @@ tmit_notify (void *cls, size_t *data_size, void *data) | |||
230 | 234 | ||
231 | 235 | ||
232 | static void | 236 | static void |
233 | origin_recv_replay_msg (void *cls, | ||
234 | const struct GNUNET_CRYPTO_EcdsaPublicKey *member_key, | ||
235 | uint64_t message_id, | ||
236 | uint64_t fragment_offset, | ||
237 | uint64_t flags, | ||
238 | struct GNUNET_MULTICAST_ReplayHandle *rh) | ||
239 | { | ||
240 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
241 | "Test #%u: origin_recv_replay_msg()\n", test); | ||
242 | } | ||
243 | |||
244 | |||
245 | static void | ||
246 | member_recv_replay_msg (void *cls, | ||
247 | const struct GNUNET_CRYPTO_EcdsaPublicKey *member_key, | ||
248 | uint64_t message_id, | ||
249 | uint64_t fragment_offset, | ||
250 | uint64_t flags, | ||
251 | struct GNUNET_MULTICAST_ReplayHandle *rh) | ||
252 | { | ||
253 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
254 | "Test #%u: member_recv_replay_msg()\n", test); | ||
255 | } | ||
256 | |||
257 | |||
258 | static void | ||
259 | origin_recv_replay_frag (void *cls, | ||
260 | const struct GNUNET_CRYPTO_EcdsaPublicKey *member_key, | ||
261 | uint64_t fragment_id, | ||
262 | uint64_t flags, | ||
263 | struct GNUNET_MULTICAST_ReplayHandle *rh) | ||
264 | { | ||
265 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
266 | "Test #%u: origin_recv_replay_frag()\n", test); | ||
267 | } | ||
268 | |||
269 | |||
270 | static void | ||
271 | member_recv_replay_frag (void *cls, | ||
272 | const struct GNUNET_CRYPTO_EcdsaPublicKey *member_key, | ||
273 | uint64_t fragment_id, | ||
274 | uint64_t flags, | ||
275 | struct GNUNET_MULTICAST_ReplayHandle *rh) | ||
276 | { | ||
277 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
278 | "Test #%u: member_recv_replay_frag()\n", test); | ||
279 | } | ||
280 | |||
281 | |||
282 | static void | ||
283 | origin_recv_membership_test (void *cls, | 237 | origin_recv_membership_test (void *cls, |
284 | const struct GNUNET_CRYPTO_EcdsaPublicKey *member_key, | 238 | const struct GNUNET_CRYPTO_EcdsaPublicKey *member_key, |
285 | uint64_t message_id, | 239 | uint64_t message_id, |
@@ -339,6 +293,7 @@ member_parted (void *cls) | |||
339 | { | 293 | { |
340 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 294 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
341 | "Test #%u: member_parted()\n", test); | 295 | "Test #%u: member_parted()\n", test); |
296 | member = NULL; | ||
342 | 297 | ||
343 | switch (test) | 298 | switch (test) |
344 | { | 299 | { |
@@ -359,20 +314,135 @@ member_parted (void *cls) | |||
359 | 314 | ||
360 | 315 | ||
361 | static void | 316 | static void |
317 | schedule_member_part (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
318 | { | ||
319 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
320 | "Test #%u: schedule_member_part()\n", test); | ||
321 | GNUNET_MULTICAST_member_part (member, member_parted, NULL); | ||
322 | } | ||
323 | |||
324 | |||
325 | static void | ||
362 | member_part () | 326 | member_part () |
363 | { | 327 | { |
364 | test = TEST_MEMBER_PART; | 328 | test = TEST_MEMBER_PART; |
365 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 329 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
366 | "Test #%u: member_part()\n", test); | 330 | "Test #%u: member_part()\n", test); |
367 | GNUNET_MULTICAST_member_part (member, member_parted, NULL); | 331 | GNUNET_SCHEDULER_add_now (schedule_member_part, NULL); |
368 | member = NULL; | ||
369 | } | 332 | } |
370 | 333 | ||
371 | 334 | ||
372 | static void | 335 | static void |
373 | schedule_member_part (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 336 | member_replay_ok () |
374 | { | 337 | { |
375 | GNUNET_MULTICAST_member_part (member, member_parted, NULL); | 338 | test = TEST_MEMBER_REPLAY_OK; |
339 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
340 | "Test #%u: member_replay_ok()\n", test); | ||
341 | replay_fragment_id = 1; | ||
342 | replay_flags = 1 | 1<<11; | ||
343 | GNUNET_MULTICAST_member_replay_fragment (member, replay_fragment_id, | ||
344 | replay_flags, NULL, NULL); | ||
345 | } | ||
346 | |||
347 | |||
348 | static void | ||
349 | member_replay_error () | ||
350 | { | ||
351 | test = TEST_MEMBER_REPLAY_ERROR; | ||
352 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
353 | "Test #%u: member_replay_error()\n", test); | ||
354 | replay_fragment_id = 1234; | ||
355 | replay_flags = 11 | 1<<11; | ||
356 | GNUNET_MULTICAST_member_replay_fragment (member, replay_fragment_id, | ||
357 | replay_flags, NULL, NULL); | ||
358 | } | ||
359 | |||
360 | |||
361 | static void | ||
362 | origin_recv_replay_msg (void *cls, | ||
363 | const struct GNUNET_CRYPTO_EcdsaPublicKey *member_key, | ||
364 | uint64_t message_id, | ||
365 | uint64_t fragment_offset, | ||
366 | uint64_t flags, | ||
367 | struct GNUNET_MULTICAST_ReplayHandle *rh) | ||
368 | { | ||
369 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
370 | "Test #%u: origin_recv_replay_msg()\n", test); | ||
371 | GNUNET_assert (0); | ||
372 | } | ||
373 | |||
374 | |||
375 | static void | ||
376 | member_recv_replay_msg (void *cls, | ||
377 | const struct GNUNET_CRYPTO_EcdsaPublicKey *member_key, | ||
378 | uint64_t message_id, | ||
379 | uint64_t fragment_offset, | ||
380 | uint64_t flags, | ||
381 | struct GNUNET_MULTICAST_ReplayHandle *rh) | ||
382 | { | ||
383 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
384 | "Test #%u: member_recv_replay_msg()\n", test); | ||
385 | GNUNET_assert (0); | ||
386 | } | ||
387 | |||
388 | |||
389 | static void | ||
390 | origin_recv_replay_frag (void *cls, | ||
391 | const struct GNUNET_CRYPTO_EcdsaPublicKey *member_key, | ||
392 | uint64_t fragment_id, | ||
393 | uint64_t flags, | ||
394 | struct GNUNET_MULTICAST_ReplayHandle *rh) | ||
395 | { | ||
396 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
397 | "Test #%u: origin_recv_replay_frag()" | ||
398 | " - fragment_id=%" PRIu64 " flags=%" PRIu64 "\n", | ||
399 | test, fragment_id, flags); | ||
400 | GNUNET_assert (replay_fragment_id == fragment_id && replay_flags == flags); | ||
401 | switch (test) | ||
402 | { | ||
403 | case TEST_MEMBER_REPLAY_ERROR: | ||
404 | GNUNET_MULTICAST_replay_response (rh, NULL, GNUNET_SYSERR); | ||
405 | member_replay_ok (); | ||
406 | break; | ||
407 | |||
408 | case TEST_MEMBER_REPLAY_OK: | ||
409 | { | ||
410 | struct GNUNET_MULTICAST_MessageHeader mmsg = { | ||
411 | .header = { | ||
412 | .type = htons (GNUNET_MESSAGE_TYPE_MULTICAST_MESSAGE), | ||
413 | .size = htons (sizeof (mmsg)), | ||
414 | }, | ||
415 | .fragment_id = GNUNET_htonll (1), | ||
416 | .message_id = GNUNET_htonll (1), | ||
417 | .fragment_offset = 0, | ||
418 | .group_generation = GNUNET_htonll (1), | ||
419 | .flags = 0, | ||
420 | }; | ||
421 | member_cls.n = 0; | ||
422 | member_cls.msgs_expected = 1; | ||
423 | GNUNET_MULTICAST_replay_response (rh, &mmsg.header, GNUNET_MULTICAST_REC_OK); | ||
424 | GNUNET_MULTICAST_replay_response_end (rh); | ||
425 | break; | ||
426 | } | ||
427 | |||
428 | default: | ||
429 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
430 | "Invalid test #%d in origin_recv_replay_frag()\n", test); | ||
431 | GNUNET_assert (0); | ||
432 | } | ||
433 | } | ||
434 | |||
435 | |||
436 | static void | ||
437 | member_recv_replay_frag (void *cls, | ||
438 | const struct GNUNET_CRYPTO_EcdsaPublicKey *member_key, | ||
439 | uint64_t fragment_id, | ||
440 | uint64_t flags, | ||
441 | struct GNUNET_MULTICAST_ReplayHandle *rh) | ||
442 | { | ||
443 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
444 | "Test #%u: member_recv_replay_frag()\n", test); | ||
445 | GNUNET_assert (0); | ||
376 | } | 446 | } |
377 | 447 | ||
378 | 448 | ||
@@ -385,14 +455,14 @@ origin_recv_request (void *cls, | |||
385 | "Test #%u: origin_recv_request()\n", test); | 455 | "Test #%u: origin_recv_request()\n", test); |
386 | if (++ocls->n != ocls->msgs_expected) | 456 | if (++ocls->n != ocls->msgs_expected) |
387 | return; | 457 | return; |
388 | 458 | ||
389 | GNUNET_assert (0 == memcmp (&req->member_key, | 459 | GNUNET_assert (0 == memcmp (&req->member_key, |
390 | &member_pub_key, sizeof (member_pub_key))); | 460 | &member_pub_key, sizeof (member_pub_key))); |
391 | 461 | ||
392 | 462 | ||
393 | // FIXME: check message content | 463 | // FIXME: check message content |
394 | 464 | ||
395 | member_part (); | 465 | member_replay_error (); |
396 | } | 466 | } |
397 | 467 | ||
398 | 468 | ||
@@ -437,6 +507,11 @@ member_recv_message (void *cls, | |||
437 | member_to_origin (); | 507 | member_to_origin (); |
438 | break; | 508 | break; |
439 | 509 | ||
510 | case TEST_MEMBER_REPLAY_OK: | ||
511 | GNUNET_assert (replay_fragment_id == GNUNET_ntohll (msg->fragment_id)); | ||
512 | member_part (); | ||
513 | break; | ||
514 | |||
440 | default: | 515 | default: |
441 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 516 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
442 | "Invalid test #%d in origin_recv_message()\n", test); | 517 | "Invalid test #%d in origin_recv_message()\n", test); |
@@ -516,7 +591,7 @@ member_recv_join_decision (void *cls, | |||
516 | GNUNET_assert (0 == relay_count); | 591 | GNUNET_assert (0 == relay_count); |
517 | GNUNET_SCHEDULER_add_now (schedule_member_part, NULL); | 592 | GNUNET_SCHEDULER_add_now (schedule_member_part, NULL); |
518 | break; | 593 | break; |
519 | 594 | ||
520 | case TEST_MEMBER_JOIN_ADMIT: | 595 | case TEST_MEMBER_JOIN_ADMIT: |
521 | GNUNET_assert (1 == relay_count); | 596 | GNUNET_assert (1 == relay_count); |
522 | GNUNET_assert (0 == memcmp (relays, &this_peer, sizeof (this_peer))); | 597 | GNUNET_assert (0 == memcmp (relays, &this_peer, sizeof (this_peer))); |
@@ -551,13 +626,13 @@ origin_recv_join_request (void *cls, | |||
551 | join_resp->size = htons (sizeof (join_resp) + data_size); | 626 | join_resp->size = htons (sizeof (join_resp) + data_size); |
552 | join_resp->type = htons (456); | 627 | join_resp->type = htons (456); |
553 | memcpy (&join_resp[1], data, data_size); | 628 | memcpy (&join_resp[1], data, data_size); |
554 | 629 | ||
555 | switch (test) | 630 | switch (test) |
556 | { | 631 | { |
557 | case TEST_MEMBER_JOIN_REFUSE: | 632 | case TEST_MEMBER_JOIN_REFUSE: |
558 | GNUNET_MULTICAST_join_decision (jh, GNUNET_NO, 0, NULL, join_resp); | 633 | GNUNET_MULTICAST_join_decision (jh, GNUNET_NO, 0, NULL, join_resp); |
559 | break; | 634 | break; |
560 | 635 | ||
561 | case TEST_MEMBER_JOIN_ADMIT: | 636 | case TEST_MEMBER_JOIN_ADMIT: |
562 | GNUNET_MULTICAST_join_decision (jh, GNUNET_YES, 1, &this_peer, join_resp); | 637 | GNUNET_MULTICAST_join_decision (jh, GNUNET_YES, 1, &this_peer, join_resp); |
563 | break; | 638 | break; |