diff options
author | Gabor X Toth <*@tg-x.net> | 2015-09-13 07:49:59 +0000 |
---|---|---|
committer | Gabor X Toth <*@tg-x.net> | 2015-09-13 07:49:59 +0000 |
commit | 646e102680bff31286fa731aa5393f0eea19afe2 (patch) | |
tree | 4d1a39d33aef2e15f3c8ecd9d7b0c0a747a34ec2 /src/multicast | |
parent | c547a9dbe17b3566556557b9d88971cdc2b02ac2 (diff) | |
download | gnunet-646e102680bff31286fa731aa5393f0eea19afe2.tar.gz gnunet-646e102680bff31286fa731aa5393f0eea19afe2.zip |
multicast tests
Diffstat (limited to 'src/multicast')
-rw-r--r-- | src/multicast/Makefile.am | 4 | ||||
-rw-r--r-- | src/multicast/gnunet-service-multicast.c | 2 | ||||
-rw-r--r-- | src/multicast/multicast_api.c | 19 | ||||
-rw-r--r-- | src/multicast/test_multicast.c | 538 |
4 files changed, 551 insertions, 12 deletions
diff --git a/src/multicast/Makefile.am b/src/multicast/Makefile.am index cbd4081a5..fd1df191d 100644 --- a/src/multicast/Makefile.am +++ b/src/multicast/Makefile.am | |||
@@ -64,5 +64,5 @@ test_multicast_SOURCES = \ | |||
64 | test_multicast_LDADD = \ | 64 | test_multicast_LDADD = \ |
65 | libgnunetmulticast.la \ | 65 | libgnunetmulticast.la \ |
66 | $(top_builddir)/src/testing/libgnunettesting.la \ | 66 | $(top_builddir)/src/testing/libgnunettesting.la \ |
67 | $(top_builddir)/src/util/libgnunetutil.la | 67 | $(top_builddir)/src/util/libgnunetutil.la \ |
68 | 68 | $(top_builddir)/src/core/libgnunetcore.la | |
diff --git a/src/multicast/gnunet-service-multicast.c b/src/multicast/gnunet-service-multicast.c index fbf3c159c..dee573848 100644 --- a/src/multicast/gnunet-service-multicast.c +++ b/src/multicast/gnunet-service-multicast.c | |||
@@ -878,6 +878,7 @@ client_send_join_decision (struct Member *mem, | |||
878 | } | 878 | } |
879 | else | 879 | else |
880 | { /* Refused entry, disconnect clients. */ | 880 | { /* Refused entry, disconnect clients. */ |
881 | #if FIXME | ||
881 | struct ClientList *cl = mem->grp.clients_head; | 882 | struct ClientList *cl = mem->grp.clients_head; |
882 | while (NULL != cl) | 883 | while (NULL != cl) |
883 | { | 884 | { |
@@ -885,6 +886,7 @@ client_send_join_decision (struct Member *mem, | |||
885 | cl = cl->next; | 886 | cl = cl->next; |
886 | GNUNET_SERVER_client_disconnect (client); | 887 | GNUNET_SERVER_client_disconnect (client); |
887 | } | 888 | } |
889 | #endif | ||
888 | } | 890 | } |
889 | } | 891 | } |
890 | 892 | ||
diff --git a/src/multicast/multicast_api.c b/src/multicast/multicast_api.c index c8d82e892..ef4cc73e7 100644 --- a/src/multicast/multicast_api.c +++ b/src/multicast/multicast_api.c | |||
@@ -327,18 +327,29 @@ member_recv_join_decision (void *cls, | |||
327 | uint16_t relay_count = ntohl (dcsn->relay_count); | 327 | uint16_t relay_count = ntohl (dcsn->relay_count); |
328 | const struct GNUNET_PeerIdentity *relays = NULL; | 328 | const struct GNUNET_PeerIdentity *relays = NULL; |
329 | uint16_t relay_size = relay_count * sizeof (*relays); | 329 | uint16_t relay_size = relay_count * sizeof (*relays); |
330 | if (0 < relay_count && dcsn_size < sizeof (*dcsn) + relay_size) | 330 | if (0 < relay_count) |
331 | relays = (struct GNUNET_PeerIdentity *) &dcsn[1]; | 331 | { |
332 | if (dcsn_size < sizeof (*dcsn) + relay_size) | ||
333 | { | ||
334 | GNUNET_break_op (0); | ||
335 | is_admitted = GNUNET_SYSERR; | ||
336 | } | ||
337 | else | ||
338 | { | ||
339 | relays = (struct GNUNET_PeerIdentity *) &dcsn[1]; | ||
340 | } | ||
341 | } | ||
332 | 342 | ||
333 | if (sizeof (*dcsn) + relay_size + sizeof (*join_resp) <= dcsn_size) | 343 | if (sizeof (*dcsn) + relay_size + sizeof (*join_resp) <= dcsn_size) |
334 | { | 344 | { |
335 | join_resp = (const struct GNUNET_MessageHeader *) &dcsn[1]; | 345 | join_resp = (const struct GNUNET_MessageHeader *) ((char *) &dcsn[1] + relay_size); |
336 | join_resp_size = ntohs (join_resp->size); | 346 | join_resp_size = ntohs (join_resp->size); |
337 | } | 347 | } |
338 | if (dcsn_size < sizeof (*dcsn) + relay_size + join_resp_size) | 348 | if (dcsn_size < sizeof (*dcsn) + relay_size + join_resp_size) |
339 | { | 349 | { |
340 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 350 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
341 | "Received invalid join decision message from multicast.\n"); | 351 | "Received invalid join decision message from multicast: %u < %u + %u + %u\n", |
352 | dcsn_size , sizeof (*dcsn), relay_size, join_resp_size); | ||
342 | GNUNET_break_op (0); | 353 | GNUNET_break_op (0); |
343 | is_admitted = GNUNET_SYSERR; | 354 | is_admitted = GNUNET_SYSERR; |
344 | } | 355 | } |
diff --git a/src/multicast/test_multicast.c b/src/multicast/test_multicast.c index 472d8bbf7..528033452 100644 --- a/src/multicast/test_multicast.c +++ b/src/multicast/test_multicast.c | |||
@@ -31,6 +31,7 @@ | |||
31 | #include "gnunet_common.h" | 31 | #include "gnunet_common.h" |
32 | #include "gnunet_util_lib.h" | 32 | #include "gnunet_util_lib.h" |
33 | #include "gnunet_testing_lib.h" | 33 | #include "gnunet_testing_lib.h" |
34 | #include "gnunet_core_service.h" | ||
34 | #include "gnunet_multicast_service.h" | 35 | #include "gnunet_multicast_service.h" |
35 | 36 | ||
36 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) | 37 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) |
@@ -40,13 +41,64 @@ | |||
40 | */ | 41 | */ |
41 | static int res; | 42 | static int res; |
42 | 43 | ||
43 | static const struct GNUNET_CONFIGURATION_Handle *cfg; | ||
44 | |||
45 | /** | 44 | /** |
46 | * Handle for task for timeout termination. | 45 | * Handle for task for timeout termination. |
47 | */ | 46 | */ |
48 | static struct GNUNET_SCHEDULER_Task * end_badly_task; | 47 | static struct GNUNET_SCHEDULER_Task * end_badly_task; |
49 | 48 | ||
49 | static const struct GNUNET_CONFIGURATION_Handle *cfg; | ||
50 | |||
51 | struct GNUNET_CORE_Handle *core; | ||
52 | struct GNUNET_PeerIdentity this_peer; | ||
53 | |||
54 | struct GNUNET_MULTICAST_Origin *origin; | ||
55 | struct GNUNET_MULTICAST_Member *member; | ||
56 | |||
57 | struct GNUNET_CRYPTO_EddsaPrivateKey *group_key; | ||
58 | struct GNUNET_CRYPTO_EddsaPublicKey group_pub_key; | ||
59 | |||
60 | struct GNUNET_CRYPTO_EcdsaPrivateKey *member_key; | ||
61 | struct GNUNET_CRYPTO_EcdsaPublicKey member_pub_key; | ||
62 | |||
63 | struct TransmitClosure { | ||
64 | struct GNUNET_MULTICAST_OriginTransmitHandle *orig_tmit; | ||
65 | struct GNUNET_MULTICAST_MemberTransmitHandle *mem_tmit; | ||
66 | char * data[16]; | ||
67 | uint8_t data_delay[16]; | ||
68 | uint8_t data_count; | ||
69 | uint8_t paused; | ||
70 | uint8_t n; | ||
71 | } tmit_cls; | ||
72 | |||
73 | struct OriginClosure { | ||
74 | uint8_t msgs_expected; | ||
75 | uint8_t n; | ||
76 | } origin_cls; | ||
77 | |||
78 | struct MemberClosure { | ||
79 | uint8_t msgs_expected; | ||
80 | size_t n; | ||
81 | } member_cls; | ||
82 | |||
83 | struct GNUNET_MessageHeader *join_req, *join_resp; | ||
84 | |||
85 | enum | ||
86 | { | ||
87 | TEST_NONE = 0, | ||
88 | TEST_ORIGIN_START = 1, | ||
89 | TEST_MEMBER_JOIN_REFUSE = 2, | ||
90 | TEST_MEMBER_JOIN_ADMIT = 3, | ||
91 | TEST_ORIGIN_TO_ALL = 4, | ||
92 | TEST_ORIGIN_TO_ALL_RECV = 5, | ||
93 | TEST_MEMBER_TO_ORIGIN = 6, | ||
94 | TEST_MEMBER_PART = 7, | ||
95 | TEST_ORIGIN_STOP = 8, | ||
96 | } test; | ||
97 | |||
98 | |||
99 | static void | ||
100 | member_join (int t); | ||
101 | |||
50 | 102 | ||
51 | /** | 103 | /** |
52 | * Clean up all resources used. | 104 | * Clean up all resources used. |
@@ -54,7 +106,21 @@ static struct GNUNET_SCHEDULER_Task * end_badly_task; | |||
54 | static void | 106 | static void |
55 | cleanup () | 107 | cleanup () |
56 | { | 108 | { |
57 | 109 | if (NULL != core) | |
110 | { | ||
111 | GNUNET_CORE_disconnect (core); | ||
112 | core = NULL; | ||
113 | } | ||
114 | if (NULL != member) | ||
115 | { | ||
116 | GNUNET_MULTICAST_member_part (member, NULL, NULL); | ||
117 | member = NULL; | ||
118 | } | ||
119 | if (NULL != origin) | ||
120 | { | ||
121 | GNUNET_MULTICAST_origin_stop (origin, NULL, NULL); | ||
122 | origin = NULL; | ||
123 | } | ||
58 | } | 124 | } |
59 | 125 | ||
60 | 126 | ||
@@ -106,6 +172,467 @@ end () | |||
106 | } | 172 | } |
107 | 173 | ||
108 | 174 | ||
175 | void | ||
176 | tmit_resume (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
177 | { | ||
178 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmission resumed.\n"); | ||
179 | struct TransmitClosure *tmit = cls; | ||
180 | if (NULL != tmit->orig_tmit) | ||
181 | GNUNET_MULTICAST_origin_to_all_resume (tmit->orig_tmit); | ||
182 | else | ||
183 | GNUNET_MULTICAST_member_to_origin_resume (tmit->mem_tmit); | ||
184 | } | ||
185 | |||
186 | |||
187 | static int | ||
188 | tmit_notify (void *cls, size_t *data_size, void *data) | ||
189 | { | ||
190 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
191 | "Test #%u: origin_tmit_notify()\n", test); | ||
192 | struct TransmitClosure *tmit = cls; | ||
193 | |||
194 | if (0 == tmit->data_count) | ||
195 | { | ||
196 | *data_size = 0; | ||
197 | return GNUNET_YES; | ||
198 | } | ||
199 | |||
200 | uint16_t size = strlen (tmit->data[tmit->n]); | ||
201 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
202 | "Transmit notify data: %u bytes available, " | ||
203 | "processing fragment %u/%u (size %u).\n", | ||
204 | *data_size, tmit->n + 1, tmit->data_count, size); | ||
205 | if (*data_size < size) | ||
206 | { | ||
207 | *data_size = 0; | ||
208 | GNUNET_assert (0); | ||
209 | return GNUNET_SYSERR; | ||
210 | } | ||
211 | |||
212 | if (GNUNET_YES != tmit->paused && 0 < tmit->data_delay[tmit->n]) | ||
213 | { | ||
214 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmission paused.\n"); | ||
215 | tmit->paused = GNUNET_YES; | ||
216 | GNUNET_SCHEDULER_add_delayed ( | ||
217 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, | ||
218 | tmit->data_delay[tmit->n]), | ||
219 | tmit_resume, tmit); | ||
220 | *data_size = 0; | ||
221 | return GNUNET_NO; | ||
222 | } | ||
223 | tmit->paused = GNUNET_NO; | ||
224 | |||
225 | *data_size = size; | ||
226 | memcpy (data, tmit->data[tmit->n], size); | ||
227 | |||
228 | return ++tmit->n < tmit->data_count ? GNUNET_NO : GNUNET_YES; | ||
229 | } | ||
230 | |||
231 | |||
232 | 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, | ||
284 | const struct GNUNET_CRYPTO_EcdsaPublicKey *member_key, | ||
285 | uint64_t message_id, | ||
286 | uint64_t group_generation, | ||
287 | struct GNUNET_MULTICAST_MembershipTestHandle *mth) | ||
288 | { | ||
289 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
290 | "Test #%u: origin_recv_membership_test()\n", test); | ||
291 | } | ||
292 | |||
293 | |||
294 | static void | ||
295 | member_recv_membership_test (void *cls, | ||
296 | const struct GNUNET_CRYPTO_EcdsaPublicKey *member_key, | ||
297 | uint64_t message_id, | ||
298 | uint64_t group_generation, | ||
299 | struct GNUNET_MULTICAST_MembershipTestHandle *mth) | ||
300 | { | ||
301 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
302 | "Test #%u: member_recv_membership_test()\n", test); | ||
303 | } | ||
304 | |||
305 | |||
306 | static void | ||
307 | member_recv_join_request (void *cls, | ||
308 | const struct GNUNET_CRYPTO_EcdsaPublicKey *member_key, | ||
309 | const struct GNUNET_MessageHeader *join_msg, | ||
310 | struct GNUNET_MULTICAST_JoinHandle *jh) | ||
311 | { | ||
312 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
313 | "Test #%u: member_recv_join_request()\n", test); | ||
314 | } | ||
315 | |||
316 | |||
317 | static void | ||
318 | origin_stopped (void *cls) | ||
319 | { | ||
320 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
321 | "Test #%u: origin_stopped()\n", test); | ||
322 | end (); | ||
323 | } | ||
324 | |||
325 | |||
326 | static void | ||
327 | schedule_origin_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
328 | { | ||
329 | test = TEST_ORIGIN_STOP; | ||
330 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
331 | "Test #%u: origin_stop()\n", test); | ||
332 | GNUNET_MULTICAST_origin_stop (origin, origin_stopped, NULL); | ||
333 | origin = NULL; | ||
334 | } | ||
335 | |||
336 | |||
337 | static void | ||
338 | member_parted (void *cls) | ||
339 | { | ||
340 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
341 | "Test #%u: member_parted()\n", test); | ||
342 | |||
343 | switch (test) | ||
344 | { | ||
345 | case TEST_MEMBER_JOIN_REFUSE: | ||
346 | member_join (TEST_MEMBER_JOIN_ADMIT); | ||
347 | break; | ||
348 | |||
349 | case TEST_MEMBER_PART: | ||
350 | GNUNET_SCHEDULER_add_now (schedule_origin_stop, NULL); | ||
351 | break; | ||
352 | |||
353 | default: | ||
354 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
355 | "Invalid test #%d in member_recv_join_decision()\n", test); | ||
356 | GNUNET_assert (0); | ||
357 | } | ||
358 | } | ||
359 | |||
360 | |||
361 | static void | ||
362 | member_part () | ||
363 | { | ||
364 | test = TEST_MEMBER_PART; | ||
365 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
366 | "Test #%u: member_part()\n", test); | ||
367 | GNUNET_MULTICAST_member_part (member, member_parted, NULL); | ||
368 | member = NULL; | ||
369 | } | ||
370 | |||
371 | |||
372 | static void | ||
373 | schedule_member_part (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
374 | { | ||
375 | GNUNET_MULTICAST_member_part (member, member_parted, NULL); | ||
376 | } | ||
377 | |||
378 | |||
379 | static void | ||
380 | origin_recv_request (void *cls, | ||
381 | const struct GNUNET_MULTICAST_RequestHeader *req) | ||
382 | { | ||
383 | struct OriginClosure *ocls = cls; | ||
384 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
385 | "Test #%u: origin_recv_request()\n", test); | ||
386 | if (++ocls->n != ocls->msgs_expected) | ||
387 | return; | ||
388 | |||
389 | GNUNET_assert (0 == memcmp (&req->member_key, | ||
390 | &member_pub_key, sizeof (member_pub_key))); | ||
391 | |||
392 | |||
393 | // FIXME: check message content | ||
394 | |||
395 | member_part (); | ||
396 | } | ||
397 | |||
398 | |||
399 | static void | ||
400 | member_to_origin () | ||
401 | { | ||
402 | test = TEST_MEMBER_TO_ORIGIN; | ||
403 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
404 | "Test #%u: member_to_origin()\n", test); | ||
405 | |||
406 | struct TransmitClosure *tmit = &tmit_cls; | ||
407 | *tmit = (struct TransmitClosure) {}; | ||
408 | tmit->data[0] = "abc def"; | ||
409 | tmit->data[1] = "ghi jkl mno"; | ||
410 | tmit->data_delay[1] = 1; | ||
411 | tmit->data[2] = "pqr stuw xyz"; | ||
412 | tmit->data_count = 3; | ||
413 | |||
414 | origin_cls.n = 0; | ||
415 | origin_cls.msgs_expected = 1; | ||
416 | |||
417 | GNUNET_MULTICAST_member_to_origin (member, 1, tmit_notify, tmit); | ||
418 | } | ||
419 | |||
420 | |||
421 | static void | ||
422 | member_recv_message (void *cls, | ||
423 | const struct GNUNET_MULTICAST_MessageHeader *msg) | ||
424 | { | ||
425 | struct MemberClosure *mcls = cls; | ||
426 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
427 | "Test #%u: member_recv_message() %u/%u\n", | ||
428 | test, mcls->n + 1, mcls->msgs_expected); | ||
429 | if (++mcls->n != mcls->msgs_expected) | ||
430 | return; | ||
431 | |||
432 | // FIXME: check message content | ||
433 | |||
434 | switch (test) | ||
435 | { | ||
436 | case TEST_ORIGIN_TO_ALL_RECV: | ||
437 | member_to_origin (); | ||
438 | break; | ||
439 | |||
440 | default: | ||
441 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
442 | "Invalid test #%d in origin_recv_message()\n", test); | ||
443 | GNUNET_assert (0); | ||
444 | } | ||
445 | } | ||
446 | |||
447 | |||
448 | static void | ||
449 | origin_recv_message (void *cls, | ||
450 | const struct GNUNET_MULTICAST_MessageHeader *msg) | ||
451 | { | ||
452 | struct OriginClosure *ocls = cls; | ||
453 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
454 | "Test #%u: origin_recv_message() %u/%u\n", | ||
455 | test, ocls->n + 1, ocls->msgs_expected); | ||
456 | if (++ocls->n != ocls->msgs_expected) | ||
457 | return; | ||
458 | |||
459 | // FIXME: check message content | ||
460 | |||
461 | switch (test) | ||
462 | { | ||
463 | case TEST_ORIGIN_TO_ALL: | ||
464 | test = TEST_ORIGIN_TO_ALL_RECV; | ||
465 | break; | ||
466 | |||
467 | default: | ||
468 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
469 | "Invalid test #%d in origin_recv_message()\n", test); | ||
470 | GNUNET_assert (0); | ||
471 | } | ||
472 | } | ||
473 | |||
474 | |||
475 | static void | ||
476 | origin_to_all () | ||
477 | { | ||
478 | test = TEST_ORIGIN_TO_ALL; | ||
479 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
480 | "Test #%u: origin_to_all()\n", test); | ||
481 | |||
482 | struct TransmitClosure *tmit = &tmit_cls; | ||
483 | *tmit = (struct TransmitClosure) {}; | ||
484 | tmit->data[0] = "ABC DEF"; | ||
485 | tmit->data[1] = "GHI JKL MNO"; | ||
486 | tmit->data_delay[1] = 1; | ||
487 | tmit->data[2] = "PQR STUW XYZ"; | ||
488 | tmit->data_count = 3; | ||
489 | |||
490 | origin_cls.n = member_cls.n = 0; | ||
491 | origin_cls.msgs_expected = member_cls.msgs_expected = 1; | ||
492 | |||
493 | GNUNET_MULTICAST_origin_to_all (origin, 1, 1, tmit_notify, tmit); | ||
494 | } | ||
495 | |||
496 | |||
497 | static void | ||
498 | member_recv_join_decision (void *cls, | ||
499 | int is_admitted, | ||
500 | const struct GNUNET_PeerIdentity *peer, | ||
501 | uint16_t relay_count, | ||
502 | const struct GNUNET_PeerIdentity *relays, | ||
503 | const struct GNUNET_MessageHeader *join_msg) | ||
504 | { | ||
505 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
506 | "Test #%u: member_recv_join_decision() - is_admitted: %d\n", | ||
507 | test, is_admitted); | ||
508 | |||
509 | GNUNET_assert (join_msg->size == join_resp->size); | ||
510 | GNUNET_assert (join_msg->type == join_resp->type); | ||
511 | GNUNET_assert (0 == memcmp (join_msg, join_resp, ntohs (join_resp->size))); | ||
512 | |||
513 | switch (test) | ||
514 | { | ||
515 | case TEST_MEMBER_JOIN_REFUSE: | ||
516 | GNUNET_assert (0 == relay_count); | ||
517 | GNUNET_SCHEDULER_add_now (schedule_member_part, NULL); | ||
518 | break; | ||
519 | |||
520 | case TEST_MEMBER_JOIN_ADMIT: | ||
521 | GNUNET_assert (1 == relay_count); | ||
522 | GNUNET_assert (0 == memcmp (relays, &this_peer, sizeof (this_peer))); | ||
523 | origin_to_all (); | ||
524 | break; | ||
525 | |||
526 | default: | ||
527 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
528 | "Invalid test #%d in member_recv_join_decision()\n", test); | ||
529 | GNUNET_assert (0); | ||
530 | } | ||
531 | } | ||
532 | |||
533 | |||
534 | static void | ||
535 | origin_recv_join_request (void *cls, | ||
536 | const struct GNUNET_CRYPTO_EcdsaPublicKey *mem_key, | ||
537 | const struct GNUNET_MessageHeader *join_msg, | ||
538 | struct GNUNET_MULTICAST_JoinHandle *jh) | ||
539 | { | ||
540 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
541 | "Test #%u: origin_recv_join_request()\n", test); | ||
542 | |||
543 | GNUNET_assert (0 == memcmp (mem_key, &member_pub_key, sizeof (member_pub_key))); | ||
544 | GNUNET_assert (join_msg->size == join_req->size); | ||
545 | GNUNET_assert (join_msg->type == join_req->type); | ||
546 | GNUNET_assert (0 == memcmp (join_msg, join_req, ntohs (join_req->size))); | ||
547 | |||
548 | char data[] = "here's the decision"; | ||
549 | uint8_t data_size = strlen (data) + 1; | ||
550 | join_resp = GNUNET_malloc (sizeof (join_resp) + data_size); | ||
551 | join_resp->size = htons (sizeof (join_resp) + data_size); | ||
552 | join_resp->type = htons (456); | ||
553 | memcpy (&join_resp[1], data, data_size); | ||
554 | |||
555 | switch (test) | ||
556 | { | ||
557 | case TEST_MEMBER_JOIN_REFUSE: | ||
558 | GNUNET_MULTICAST_join_decision (jh, GNUNET_NO, 0, NULL, join_resp); | ||
559 | break; | ||
560 | |||
561 | case TEST_MEMBER_JOIN_ADMIT: | ||
562 | GNUNET_MULTICAST_join_decision (jh, GNUNET_YES, 1, &this_peer, join_resp); | ||
563 | break; | ||
564 | |||
565 | default: | ||
566 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
567 | "Invalid test #%d in origin_recv_join_request()\n", test); | ||
568 | GNUNET_assert (0); | ||
569 | break; | ||
570 | } | ||
571 | } | ||
572 | |||
573 | |||
574 | static void | ||
575 | member_join (int t) | ||
576 | { | ||
577 | test = t; | ||
578 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
579 | "Test #%u: member_join()\n", test); | ||
580 | |||
581 | member_key = GNUNET_CRYPTO_ecdsa_key_create (); | ||
582 | GNUNET_CRYPTO_ecdsa_key_get_public (member_key, &member_pub_key); | ||
583 | |||
584 | if (NULL != join_req) | ||
585 | GNUNET_free (join_req); | ||
586 | |||
587 | char data[] = "let me in!"; | ||
588 | uint8_t data_size = strlen (data) + 1; | ||
589 | join_req = GNUNET_malloc (sizeof (join_req) + data_size); | ||
590 | join_req->size = htons (sizeof (join_req) + data_size); | ||
591 | join_req->type = htons (123); | ||
592 | memcpy (&join_req[1], data, data_size); | ||
593 | |||
594 | member = GNUNET_MULTICAST_member_join (cfg, &group_pub_key, member_key, | ||
595 | &this_peer, 1, &this_peer, join_req, | ||
596 | member_recv_join_request, | ||
597 | member_recv_join_decision, | ||
598 | member_recv_membership_test, | ||
599 | member_recv_replay_frag, | ||
600 | member_recv_replay_msg, | ||
601 | member_recv_message, | ||
602 | &member_cls); | ||
603 | } | ||
604 | |||
605 | |||
606 | static void | ||
607 | origin_start () | ||
608 | { | ||
609 | test = TEST_ORIGIN_START; | ||
610 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
611 | "Test #%u: origin_start()\n", test); | ||
612 | |||
613 | group_key = GNUNET_CRYPTO_eddsa_key_create (); | ||
614 | GNUNET_CRYPTO_eddsa_key_get_public (group_key, &group_pub_key); | ||
615 | |||
616 | origin = GNUNET_MULTICAST_origin_start (cfg, group_key, 0, | ||
617 | origin_recv_join_request, | ||
618 | origin_recv_membership_test, | ||
619 | origin_recv_replay_frag, | ||
620 | origin_recv_replay_msg, | ||
621 | origin_recv_request, | ||
622 | origin_recv_message, | ||
623 | &origin_cls); | ||
624 | member_join (TEST_MEMBER_JOIN_REFUSE); | ||
625 | } | ||
626 | |||
627 | |||
628 | static void | ||
629 | core_connected (void *cls, const struct GNUNET_PeerIdentity *my_identity) | ||
630 | { | ||
631 | this_peer = *my_identity; | ||
632 | origin_start (); | ||
633 | } | ||
634 | |||
635 | |||
109 | /** | 636 | /** |
110 | * Main function of the test, run from scheduler. | 637 | * Main function of the test, run from scheduler. |
111 | * | 638 | * |
@@ -126,9 +653,8 @@ run (void *cls, | |||
126 | cfg = c; | 653 | cfg = c; |
127 | end_badly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); | 654 | end_badly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); |
128 | 655 | ||
129 | /* FIXME: add tests */ | 656 | core = GNUNET_CORE_connect (cfg, NULL, &core_connected, NULL, NULL, |
130 | 657 | NULL, GNUNET_NO, NULL, GNUNET_NO, NULL); | |
131 | end (); | ||
132 | } | 658 | } |
133 | 659 | ||
134 | 660 | ||