You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

759 lines
20 KiB

  1. /*
  2. * This file is part of GNUnet
  3. * Copyright (C) 2013 GNUnet e.V.
  4. *
  5. * GNUnet is free software: you can redistribute it and/or modify it
  6. * under the terms of the GNU Affero General Public License as published
  7. * by the Free Software Foundation, either version 3 of the License,
  8. * or (at your option) any later version.
  9. *
  10. * GNUnet is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Affero General Public License for more details.
  14. *
  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/>.
  17. SPDX-License-Identifier: AGPL3.0-or-later
  18. */
  19. /**
  20. * @file multicast/test_multicast.c
  21. * @brief Tests for the Multicast API.
  22. * @author Gabor X Toth
  23. */
  24. #include <inttypes.h>
  25. #include "platform.h"
  26. #include "gnunet_crypto_lib.h"
  27. #include "gnunet_common.h"
  28. #include "gnunet_util_lib.h"
  29. #include "gnunet_testing_lib.h"
  30. #include "gnunet_multicast_service.h"
  31. #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
  32. /**
  33. * Return value from 'main'.
  34. */
  35. static int res;
  36. /**
  37. * Handle for task for timeout termination.
  38. */
  39. static struct GNUNET_SCHEDULER_Task * end_badly_task;
  40. static const struct GNUNET_CONFIGURATION_Handle *cfg;
  41. struct GNUNET_PeerIdentity this_peer;
  42. struct GNUNET_MULTICAST_Origin *origin;
  43. struct GNUNET_MULTICAST_Member *member;
  44. struct GNUNET_CRYPTO_EddsaPrivateKey *group_key;
  45. struct GNUNET_CRYPTO_EddsaPublicKey group_pub_key;
  46. struct GNUNET_CRYPTO_EcdsaPrivateKey *member_key;
  47. struct GNUNET_CRYPTO_EcdsaPublicKey member_pub_key;
  48. struct TransmitClosure {
  49. struct GNUNET_MULTICAST_OriginTransmitHandle *orig_tmit;
  50. struct GNUNET_MULTICAST_MemberTransmitHandle *mem_tmit;
  51. char * data[16];
  52. uint8_t data_delay[16];
  53. uint8_t data_count;
  54. uint8_t paused;
  55. uint8_t n;
  56. } tmit_cls;
  57. struct OriginClosure {
  58. uint8_t msgs_expected;
  59. uint8_t n;
  60. } origin_cls;
  61. struct MemberClosure {
  62. uint8_t msgs_expected;
  63. size_t n;
  64. } member_cls;
  65. struct GNUNET_MessageHeader *join_req, *join_resp;
  66. enum
  67. {
  68. TEST_NONE = 0,
  69. TEST_ORIGIN_START = 1,
  70. TEST_MEMBER_JOIN_REFUSE = 2,
  71. TEST_MEMBER_JOIN_ADMIT = 3,
  72. TEST_ORIGIN_TO_ALL = 4,
  73. TEST_ORIGIN_TO_ALL_RECV = 5,
  74. TEST_MEMBER_TO_ORIGIN = 6,
  75. TEST_MEMBER_REPLAY_ERROR = 7,
  76. TEST_MEMBER_REPLAY_OK = 8,
  77. TEST_MEMBER_PART = 9,
  78. TEST_ORIGIN_STOP = 10,
  79. } test;
  80. uint64_t replay_fragment_id;
  81. uint64_t replay_flags;
  82. static void
  83. member_join (int t);
  84. /**
  85. * Clean up all resources used.
  86. */
  87. static void
  88. cleanup ()
  89. {
  90. if (NULL != member)
  91. {
  92. GNUNET_MULTICAST_member_part (member, NULL, NULL);
  93. member = NULL;
  94. }
  95. if (NULL != origin)
  96. {
  97. GNUNET_MULTICAST_origin_stop (origin, NULL, NULL);
  98. origin = NULL;
  99. }
  100. }
  101. /**
  102. * Terminate the test case (failure).
  103. *
  104. * @param cls NULL
  105. */
  106. static void
  107. end_badly (void *cls)
  108. {
  109. res = 1;
  110. cleanup ();
  111. GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Test FAILED.\n");
  112. }
  113. /**
  114. * Terminate the test case (success).
  115. *
  116. * @param cls NULL
  117. */
  118. static void
  119. end_normally (void *cls)
  120. {
  121. res = 0;
  122. cleanup ();
  123. GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Test PASSED.\n");
  124. }
  125. /**
  126. * Finish the test case (successfully).
  127. */
  128. static void
  129. end ()
  130. {
  131. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ending tests.\n");
  132. if (end_badly_task != NULL)
  133. {
  134. GNUNET_SCHEDULER_cancel (end_badly_task);
  135. end_badly_task = NULL;
  136. }
  137. GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS,
  138. &end_normally, NULL);
  139. }
  140. static void
  141. tmit_resume (void *cls)
  142. {
  143. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmission resumed.\n");
  144. struct TransmitClosure *tmit = cls;
  145. if (NULL != tmit->orig_tmit)
  146. GNUNET_MULTICAST_origin_to_all_resume (tmit->orig_tmit);
  147. else if (NULL != tmit->mem_tmit)
  148. GNUNET_MULTICAST_member_to_origin_resume (tmit->mem_tmit);
  149. }
  150. static int
  151. tmit_notify (void *cls, size_t *data_size, void *data)
  152. {
  153. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
  154. "Test #%u: origin_tmit_notify()\n", test);
  155. struct TransmitClosure *tmit = cls;
  156. if (0 == tmit->data_count)
  157. {
  158. *data_size = 0;
  159. return GNUNET_YES;
  160. }
  161. uint16_t size = strlen (tmit->data[tmit->n]);
  162. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
  163. "Transmit notify data: %u bytes available, processing fragment %u/%u (size %u).\n",
  164. (unsigned int) *data_size,
  165. tmit->n + 1,
  166. tmit->data_count,
  167. size);
  168. if (*data_size < size)
  169. {
  170. *data_size = 0;
  171. GNUNET_assert (0);
  172. return GNUNET_SYSERR;
  173. }
  174. if (GNUNET_YES != tmit->paused && 0 < tmit->data_delay[tmit->n])
  175. {
  176. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmission paused.\n");
  177. tmit->paused = GNUNET_YES;
  178. GNUNET_SCHEDULER_add_delayed (
  179. GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
  180. tmit->data_delay[tmit->n]),
  181. tmit_resume, tmit);
  182. *data_size = 0;
  183. return GNUNET_NO;
  184. }
  185. tmit->paused = GNUNET_NO;
  186. *data_size = size;
  187. GNUNET_memcpy (data, tmit->data[tmit->n], size);
  188. return ++tmit->n < tmit->data_count ? GNUNET_NO : GNUNET_YES;
  189. }
  190. static void
  191. member_recv_join_request (void *cls,
  192. const struct GNUNET_CRYPTO_EcdsaPublicKey *member_key,
  193. const struct GNUNET_MessageHeader *join_msg,
  194. struct GNUNET_MULTICAST_JoinHandle *jh)
  195. {
  196. GNUNET_log (GNUNET_ERROR_TYPE_INFO,
  197. "Test #%u: member_recv_join_request()\n", test);
  198. }
  199. static void
  200. origin_stopped (void *cls)
  201. {
  202. GNUNET_log (GNUNET_ERROR_TYPE_INFO,
  203. "Test #%u: origin_stopped()\n", test);
  204. end ();
  205. }
  206. static void
  207. schedule_origin_stop (void *cls)
  208. {
  209. test = TEST_ORIGIN_STOP;
  210. GNUNET_log (GNUNET_ERROR_TYPE_INFO,
  211. "Test #%u: origin_stop()\n", test);
  212. GNUNET_MULTICAST_origin_stop (origin, origin_stopped, NULL);
  213. origin = NULL;
  214. }
  215. static void
  216. member_parted (void *cls)
  217. {
  218. GNUNET_log (GNUNET_ERROR_TYPE_INFO,
  219. "Test #%u: member_parted()\n", test);
  220. member = NULL;
  221. switch (test)
  222. {
  223. case TEST_MEMBER_JOIN_REFUSE:
  224. // Test 3 starts here
  225. member_join (TEST_MEMBER_JOIN_ADMIT);
  226. break;
  227. case TEST_MEMBER_PART:
  228. GNUNET_SCHEDULER_add_now (&schedule_origin_stop, NULL);
  229. break;
  230. default:
  231. GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
  232. "Invalid test #%d in member_parted()\n", test);
  233. GNUNET_assert (0);
  234. }
  235. }
  236. static void
  237. schedule_member_part (void *cls)
  238. {
  239. GNUNET_log (GNUNET_ERROR_TYPE_INFO,
  240. "Test #%u: schedule_member_part()\n", test);
  241. GNUNET_MULTICAST_member_part (member, member_parted, NULL);
  242. }
  243. static void
  244. member_part ()
  245. {
  246. test = TEST_MEMBER_PART;
  247. GNUNET_log (GNUNET_ERROR_TYPE_INFO,
  248. "Test #%u: member_part()\n", test);
  249. // Test 10 starts here
  250. GNUNET_SCHEDULER_add_now (&schedule_member_part, NULL);
  251. }
  252. static void
  253. member_replay_ok ()
  254. {
  255. // Execution of test 8 here
  256. test = TEST_MEMBER_REPLAY_OK;
  257. GNUNET_log (GNUNET_ERROR_TYPE_INFO,
  258. "Test #%u: member_replay_ok()\n", test);
  259. replay_fragment_id = 1;
  260. replay_flags = 1 | 1<<11;
  261. GNUNET_MULTICAST_member_replay_fragment (member, replay_fragment_id,
  262. replay_flags);
  263. }
  264. static void
  265. member_replay_error ()
  266. {
  267. test = TEST_MEMBER_REPLAY_ERROR;
  268. GNUNET_log (GNUNET_ERROR_TYPE_INFO,
  269. "Test #%u: member_replay_error()\n", test);
  270. replay_fragment_id = 1234;
  271. replay_flags = 11 | 1<<11;
  272. GNUNET_MULTICAST_member_replay_fragment (member, replay_fragment_id,
  273. replay_flags);
  274. }
  275. static void
  276. origin_recv_replay_msg (void *cls,
  277. const struct GNUNET_CRYPTO_EcdsaPublicKey *member_key,
  278. uint64_t message_id,
  279. uint64_t fragment_offset,
  280. uint64_t flags,
  281. struct GNUNET_MULTICAST_ReplayHandle *rh)
  282. {
  283. GNUNET_log (GNUNET_ERROR_TYPE_INFO,
  284. "Test #%u: origin_recv_replay_msg()\n", test);
  285. GNUNET_assert (0);
  286. }
  287. static void
  288. member_recv_replay_msg (void *cls,
  289. const struct GNUNET_CRYPTO_EcdsaPublicKey *member_key,
  290. uint64_t message_id,
  291. uint64_t fragment_offset,
  292. uint64_t flags,
  293. struct GNUNET_MULTICAST_ReplayHandle *rh)
  294. {
  295. GNUNET_log (GNUNET_ERROR_TYPE_INFO,
  296. "Test #%u: member_recv_replay_msg()\n", test);
  297. GNUNET_assert (0);
  298. }
  299. static void
  300. origin_recv_replay_frag (void *cls,
  301. const struct GNUNET_CRYPTO_EcdsaPublicKey *member_key,
  302. uint64_t fragment_id,
  303. uint64_t flags,
  304. struct GNUNET_MULTICAST_ReplayHandle *rh)
  305. {
  306. GNUNET_log (GNUNET_ERROR_TYPE_INFO,
  307. "Test #%u: origin_recv_replay_frag()"
  308. " - fragment_id=%" PRIu64 " flags=%" PRIu64 "\n",
  309. test, fragment_id, flags);
  310. GNUNET_assert (replay_fragment_id == fragment_id && replay_flags == flags);
  311. switch (test)
  312. {
  313. case TEST_MEMBER_REPLAY_ERROR:
  314. // Test 8 starts here
  315. GNUNET_MULTICAST_replay_response (rh, NULL, GNUNET_SYSERR);
  316. member_replay_ok ();
  317. break;
  318. case TEST_MEMBER_REPLAY_OK:
  319. {
  320. struct GNUNET_MULTICAST_MessageHeader mmsg = {
  321. .header = {
  322. .type = htons (GNUNET_MESSAGE_TYPE_MULTICAST_MESSAGE),
  323. .size = htons (sizeof (mmsg)),
  324. },
  325. .fragment_id = GNUNET_htonll (1),
  326. .message_id = GNUNET_htonll (1),
  327. .fragment_offset = 0,
  328. .group_generation = GNUNET_htonll (1),
  329. .flags = 0,
  330. };
  331. member_cls.n = 0;
  332. member_cls.msgs_expected = 1;
  333. GNUNET_MULTICAST_replay_response (rh, &mmsg.header, GNUNET_MULTICAST_REC_OK);
  334. GNUNET_MULTICAST_replay_response_end (rh);
  335. break;
  336. }
  337. default:
  338. GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
  339. "Invalid test #%d in origin_recv_replay_frag()\n", test);
  340. GNUNET_assert (0);
  341. }
  342. }
  343. static void
  344. member_recv_replay_frag (void *cls,
  345. const struct GNUNET_CRYPTO_EcdsaPublicKey *member_key,
  346. uint64_t fragment_id,
  347. uint64_t flags,
  348. struct GNUNET_MULTICAST_ReplayHandle *rh)
  349. {
  350. GNUNET_log (GNUNET_ERROR_TYPE_INFO,
  351. "Test #%u: member_recv_replay_frag()\n", test);
  352. GNUNET_assert (0);
  353. }
  354. static void
  355. origin_recv_request (void *cls,
  356. const struct GNUNET_MULTICAST_RequestHeader *req)
  357. {
  358. struct OriginClosure *ocls = cls;
  359. GNUNET_log (GNUNET_ERROR_TYPE_INFO,
  360. "Test #%u: origin_recv_request()\n", test);
  361. if (++ocls->n != ocls->msgs_expected)
  362. return;
  363. GNUNET_assert (0 == memcmp (&req->member_pub_key,
  364. &member_pub_key, sizeof (member_pub_key)));
  365. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
  366. "Test #%u: verify message content, take first 3 bytes: %.3s\n",
  367. test, (char *)&req[1]);
  368. GNUNET_assert (0 == memcmp (&req[1], "abc", 3));
  369. // Test 7 starts here
  370. member_replay_error ();
  371. }
  372. static void
  373. member_to_origin ()
  374. {
  375. test = TEST_MEMBER_TO_ORIGIN;
  376. GNUNET_log (GNUNET_ERROR_TYPE_INFO,
  377. "Test #%u: member_to_origin()\n", test);
  378. struct TransmitClosure *tmit = &tmit_cls;
  379. *tmit = (struct TransmitClosure) {};
  380. tmit->data[0] = "abc def";
  381. tmit->data[1] = "ghi jkl mno";
  382. tmit->data_delay[1] = 2;
  383. tmit->data[2] = "pqr stuw xyz";
  384. tmit->data_count = 3;
  385. origin_cls.n = 0;
  386. origin_cls.msgs_expected = 1;
  387. tmit->mem_tmit = GNUNET_MULTICAST_member_to_origin (member, 1,
  388. tmit_notify, tmit);
  389. }
  390. static void
  391. member_recv_message (void *cls,
  392. const struct GNUNET_MULTICAST_MessageHeader *msg)
  393. {
  394. struct MemberClosure *mcls = cls;
  395. // Test 5 starts here after message has been received from origin
  396. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
  397. "Test #%u: member_recv_message() %u/%u\n",
  398. test,
  399. (unsigned int) (mcls->n + 1),
  400. mcls->msgs_expected);
  401. if (++mcls->n != mcls->msgs_expected)
  402. return;
  403. // FIXME: check message content
  404. switch (test)
  405. {
  406. case TEST_ORIGIN_TO_ALL:
  407. test = TEST_ORIGIN_TO_ALL_RECV;
  408. break;
  409. case TEST_ORIGIN_TO_ALL_RECV:
  410. // Test 6 starts here
  411. member_to_origin ();
  412. break;
  413. case TEST_MEMBER_REPLAY_OK:
  414. // Test 9 starts here
  415. GNUNET_assert (replay_fragment_id == GNUNET_ntohll (msg->fragment_id));
  416. member_part ();
  417. break;
  418. default:
  419. GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
  420. "Invalid test #%d in origin_recv_message()\n", test);
  421. GNUNET_assert (0);
  422. }
  423. }
  424. static void
  425. origin_recv_message (void *cls,
  426. const struct GNUNET_MULTICAST_MessageHeader *msg)
  427. {
  428. struct OriginClosure *ocls = cls;
  429. GNUNET_log (GNUNET_ERROR_TYPE_INFO,
  430. "Test #%u: origin_recv_message() %u/%u\n",
  431. test, ocls->n + 1, ocls->msgs_expected);
  432. if (++ocls->n != ocls->msgs_expected)
  433. return;
  434. // FIXME: check message content
  435. switch (test)
  436. {
  437. case TEST_ORIGIN_TO_ALL:
  438. // Prepare to execute test 5
  439. test = TEST_ORIGIN_TO_ALL_RECV;
  440. break;
  441. case TEST_ORIGIN_TO_ALL_RECV:
  442. // Test 6 starts here
  443. member_to_origin ();
  444. break;
  445. default:
  446. GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
  447. "Invalid test #%d in origin_recv_message()\n", test);
  448. GNUNET_assert (0);
  449. }
  450. }
  451. static void
  452. origin_to_all ()
  453. {
  454. test = TEST_ORIGIN_TO_ALL;
  455. GNUNET_log (GNUNET_ERROR_TYPE_INFO,
  456. "Test #%u: origin_to_all()\n", test);
  457. struct TransmitClosure *tmit = &tmit_cls;
  458. *tmit = (struct TransmitClosure) {};
  459. tmit->data[0] = "ABC DEF";
  460. tmit->data[1] = GNUNET_malloc (GNUNET_MULTICAST_FRAGMENT_MAX_PAYLOAD + 1);
  461. uint16_t i;
  462. for (i = 0; i < GNUNET_MULTICAST_FRAGMENT_MAX_PAYLOAD; i++)
  463. tmit->data[1][i] = (0 == i % 10000) ? '0' + i / 10000 : '_';
  464. tmit->data[2] = "GHI JKL MNO";
  465. tmit->data_delay[2] = 2;
  466. tmit->data[3] = "PQR STUW XYZ";
  467. tmit->data_count = 4;
  468. origin_cls.n = member_cls.n = 0;
  469. origin_cls.msgs_expected = member_cls.msgs_expected = tmit->data_count;
  470. tmit->orig_tmit = GNUNET_MULTICAST_origin_to_all (origin, 1, 1,
  471. tmit_notify, tmit);
  472. }
  473. static void
  474. member_recv_join_decision (void *cls,
  475. int is_admitted,
  476. const struct GNUNET_PeerIdentity *peer,
  477. uint16_t relay_count,
  478. const struct GNUNET_PeerIdentity *relays,
  479. const struct GNUNET_MessageHeader *join_msg)
  480. {
  481. GNUNET_log (GNUNET_ERROR_TYPE_INFO,
  482. "Test #%u: member_recv_join_decision() - is_admitted: %d\n",
  483. test, is_admitted);
  484. GNUNET_assert (join_msg->size == join_resp->size);
  485. GNUNET_assert (join_msg->type == join_resp->type);
  486. GNUNET_assert (0 == memcmp (join_msg, join_resp, ntohs (join_resp->size)));
  487. switch (test)
  488. {
  489. case TEST_MEMBER_JOIN_REFUSE:
  490. GNUNET_assert (0 == relay_count);
  491. // Test 3 starts here
  492. GNUNET_SCHEDULER_add_now (&schedule_member_part, NULL);
  493. break;
  494. case TEST_MEMBER_JOIN_ADMIT:
  495. GNUNET_assert (1 == relay_count);
  496. GNUNET_assert (0 == memcmp (relays, &this_peer, sizeof (this_peer)));
  497. // Test 4 starts here
  498. origin_to_all ();
  499. break;
  500. default:
  501. GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
  502. "Invalid test #%d in member_recv_join_decision()\n", test);
  503. GNUNET_assert (0);
  504. }
  505. }
  506. /**
  507. * Test: origin receives join request
  508. */
  509. static void
  510. origin_recv_join_request (void *cls,
  511. const struct GNUNET_CRYPTO_EcdsaPublicKey *mem_key,
  512. const struct GNUNET_MessageHeader *join_msg,
  513. struct GNUNET_MULTICAST_JoinHandle *jh)
  514. {
  515. GNUNET_log (GNUNET_ERROR_TYPE_INFO,
  516. "Test #%u: origin_recv_join_request()\n", test);
  517. GNUNET_assert (0 == memcmp (mem_key, &member_pub_key, sizeof (member_pub_key)));
  518. GNUNET_assert (join_msg->size == join_req->size);
  519. GNUNET_assert (join_msg->type == join_req->type);
  520. GNUNET_assert (0 == memcmp (join_msg, join_req, ntohs (join_req->size)));
  521. char data[] = "here's the decision";
  522. uint8_t data_size = strlen (data) + 1;
  523. join_resp = GNUNET_malloc (sizeof (join_resp) + data_size);
  524. join_resp->size = htons (sizeof (join_resp) + data_size);
  525. join_resp->type = htons (456);
  526. GNUNET_memcpy (&join_resp[1], data, data_size);
  527. switch (test)
  528. {
  529. case TEST_MEMBER_JOIN_REFUSE:
  530. // Test 3 starts here
  531. GNUNET_MULTICAST_join_decision (jh, GNUNET_NO, 0, NULL, join_resp);
  532. break;
  533. case TEST_MEMBER_JOIN_ADMIT:
  534. // Test 3 is running
  535. GNUNET_MULTICAST_join_decision (jh, GNUNET_YES, 1, &this_peer, join_resp);
  536. break;
  537. default:
  538. GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
  539. "Invalid test #%d in origin_recv_join_request()\n", test);
  540. GNUNET_assert (0);
  541. break;
  542. }
  543. }
  544. /**
  545. * Test: member joins multicast group
  546. */
  547. static void
  548. member_join (int t)
  549. {
  550. test = t;
  551. GNUNET_log (GNUNET_ERROR_TYPE_INFO,
  552. "Test #%u: member_join()\n", test);
  553. member_key = GNUNET_CRYPTO_ecdsa_key_create ();
  554. GNUNET_CRYPTO_ecdsa_key_get_public (member_key, &member_pub_key);
  555. if (NULL != join_req)
  556. GNUNET_free (join_req);
  557. char data[] = "let me in!";
  558. uint8_t data_size = strlen (data) + 1;
  559. join_req = GNUNET_malloc (sizeof (join_req) + data_size);
  560. join_req->size = htons (sizeof (join_req) + data_size);
  561. join_req->type = htons (123);
  562. GNUNET_memcpy (&join_req[1], data, data_size);
  563. member = GNUNET_MULTICAST_member_join (cfg, &group_pub_key, member_key,
  564. &this_peer, 1, &this_peer, join_req,
  565. member_recv_join_request,
  566. member_recv_join_decision,
  567. member_recv_replay_frag,
  568. member_recv_replay_msg,
  569. member_recv_message,
  570. &member_cls);
  571. }
  572. /**
  573. * Test: Start a multicast group as origin
  574. */
  575. static void
  576. origin_start ()
  577. {
  578. test = TEST_ORIGIN_START;
  579. GNUNET_log (GNUNET_ERROR_TYPE_INFO,
  580. "Test #%u: origin_start()\n", test);
  581. group_key = GNUNET_CRYPTO_eddsa_key_create ();
  582. GNUNET_CRYPTO_eddsa_key_get_public (group_key, &group_pub_key);
  583. origin = GNUNET_MULTICAST_origin_start (cfg, group_key, 0,
  584. origin_recv_join_request,
  585. origin_recv_replay_frag,
  586. origin_recv_replay_msg,
  587. origin_recv_request,
  588. origin_recv_message,
  589. &origin_cls);
  590. // Test 2 starts here
  591. member_join (TEST_MEMBER_JOIN_REFUSE);
  592. }
  593. /**
  594. * Main function of the test, run from scheduler.
  595. *
  596. * @param cls NULL
  597. * @param cfg configuration we use (also to connect to Multicast service)
  598. * @param peer handle to access more of the peer (not used)
  599. */
  600. static void
  601. #if DEBUG_TEST_MULTICAST
  602. run (void *cls,
  603. char *const *args,
  604. const char *cfgfile,
  605. const struct GNUNET_CONFIGURATION_Handle *c)
  606. #else
  607. run (void *cls,
  608. const struct GNUNET_CONFIGURATION_Handle *c,
  609. struct GNUNET_TESTING_Peer *peer)
  610. #endif
  611. {
  612. cfg = c;
  613. end_badly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
  614. &end_badly, NULL);
  615. GNUNET_CRYPTO_get_peer_identity (cfg, &this_peer);
  616. // Test 1 starts here
  617. origin_start ();
  618. }
  619. int
  620. main (int argc, char *argv[])
  621. {
  622. res = 1;
  623. #if DEBUG_TEST_MULTICAST
  624. const struct GNUNET_GETOPT_CommandLineOption opts[] = {
  625. GNUNET_GETOPT_OPTION_END
  626. };
  627. if (GNUNET_OK != GNUNET_PROGRAM_run (argc, argv, "test-multicast",
  628. "test-multicast [options]",
  629. opts, &run, NULL))
  630. return 1;
  631. #else
  632. if (0 != GNUNET_TESTING_peer_run ("test-multicast", "test_multicast.conf", &run, NULL))
  633. return 1;
  634. #endif
  635. return res;
  636. }
  637. /* end of test_multicast.c */