2 * This file is part of GNUnet
3 * Copyright (C) 2013 GNUnet e.V.
5 * GNUnet is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published
7 * by the Free Software Foundation; either version 3, or (at your
8 * option) any later version.
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 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with GNUnet; see the file COPYING. If not, write to the
17 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
22 * @file multicast/test_multicast_multipeers.c
23 * @brief Tests for the Multicast API with multiple peers.
30 #include "gnunet_crypto_lib.h"
31 #include "gnunet_common.h"
32 #include "gnunet_util_lib.h"
33 #include "gnunet_testbed_service.h"
34 #include "gnunet_multicast_service.h"
38 static struct GNUNET_TESTBED_Operation *peer0;
39 static struct GNUNET_TESTBED_Operation *peer1;
41 static struct GNUNET_SCHEDULER_Task *timeout_tid;
43 struct GNUNET_CRYPTO_EddsaPrivateKey *group_key;
44 struct GNUNET_CRYPTO_EddsaPublicKey group_pub_key;
46 struct GNUNET_CRYPTO_EcdsaPrivateKey *member1_key;
47 struct GNUNET_CRYPTO_EcdsaPublicKey member1_pub_key;
53 TEST_ORIGIN_START = 1,
59 * Global result for testcase.
65 * Function run on CTRL-C or shutdown (i.e. success/timeout/etc.).
69 shutdown_task (void *cls)
73 GNUNET_TESTBED_operation_done (peer0);
76 if (NULL != timeout_tid)
78 GNUNET_SCHEDULER_cancel (timeout_tid);
85 timeout_task (void *cls)
88 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
90 result = GNUNET_SYSERR;
91 GNUNET_SCHEDULER_shutdown ();
96 origin_recv_replay_msg (void *cls,
97 const struct GNUNET_CRYPTO_EcdsaPublicKey *member_key,
99 uint64_t fragment_offset,
101 struct GNUNET_MULTICAST_ReplayHandle *rh)
103 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
104 "Test #%u: origin_recv_replay_msg()\n", test);
110 member_recv_replay_msg (void *cls,
111 const struct GNUNET_CRYPTO_EcdsaPublicKey *member_key,
113 uint64_t fragment_offset,
115 struct GNUNET_MULTICAST_ReplayHandle *rh)
117 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
118 "Test #%u: member_recv_replay_msg()\n", test);
124 origin_recv_replay_frag (void *cls,
125 const struct GNUNET_CRYPTO_EcdsaPublicKey *member_key,
126 uint64_t fragment_id,
128 struct GNUNET_MULTICAST_ReplayHandle *rh)
130 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
131 "Test #%u: origin_recv_replay_frag()"
132 " - fragment_id=%" PRIu64 " flags=%" PRIu64 "\n",
133 test, fragment_id, flags);
138 * Test: origin receives join request
141 origin_recv_join_request (void *cls,
142 const struct GNUNET_CRYPTO_EcdsaPublicKey *mem_key,
143 const struct GNUNET_MessageHeader *join_msg,
144 struct GNUNET_MULTICAST_JoinHandle *jh)
146 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
147 "Test #%u: origin_recv_join_request()\n", test);
152 origin_recv_request (void *cls,
153 const struct GNUNET_MULTICAST_RequestHeader *req)
155 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
156 "Test #%u: origin_recv_request()\n",
162 origin_recv_message (void *cls,
163 const struct GNUNET_MULTICAST_MessageHeader *msg)
165 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
166 "Test #%u: origin_recv_message()\n",
172 service_close_peer0 (void *cls,
175 struct GNUNET_MULTICAST_Origin *orig = op_result;
177 GNUNET_MULTICAST_origin_stop (orig, NULL, NULL);
182 * Function run when service multicast has started and is providing us
183 * with a configuration file.
186 service_conf_peer0 (void *cls,
187 const struct GNUNET_CONFIGURATION_Handle *cfg)
189 group_key = GNUNET_CRYPTO_eddsa_key_create ();
190 GNUNET_CRYPTO_eddsa_key_get_public (group_key, &group_pub_key);
192 return GNUNET_MULTICAST_origin_start (cfg, group_key, 0,
193 origin_recv_join_request,
194 origin_recv_replay_frag,
195 origin_recv_replay_msg,
203 * Test logic of peer "0" being origin starts here.
205 * @param cls closure, for the example: NULL
206 * @param op should be equal to "dht_op"
207 * @param ca_result result of the connect operation, the
208 * connection to the DHT service
209 * @param emsg error message, if testbed somehow failed to
210 * connect to the DHT.
213 service_connect_peer0 (void *cls,
214 struct GNUNET_TESTBED_Operation *op,
218 struct GNUNET_MULTICAST_Origin *orig = ca_result;
220 /* Connection to service successful. Here we'd usually do something with
223 GNUNET_SCHEDULER_shutdown (); /* Also kills the testbed */
228 * Main function inovked from TESTBED once all of the
229 * peers are up and running. This one then connects
230 * just to the multicast service of peer 0 and 1.
231 * Peer 0 is going to be origin.
232 * Peer 1 is going to be one member.
233 * Origin will start a multicast group and the member will try to join it.
234 * After that we execute some multicast test.
237 * @param h the run handle
238 * @param peers started peers for the test
239 * @param num_peers size of the 'peers' array
240 * @param links_succeeded number of links between peers that were created
241 * @param links_failed number of links testbed was unable to establish
245 struct GNUNET_TESTBED_RunHandle *h,
246 unsigned int num_peers,
247 struct GNUNET_TESTBED_Peer **peers,
248 unsigned int links_succeeded,
249 unsigned int links_failed)
251 /* Testbed is ready with peers running and connected in a pre-defined overlay
254 /* connect to a peers service */
255 peer0 = GNUNET_TESTBED_service_connect
256 (NULL, /* Closure for operation */
257 peers[0], /* The peer whose service to connect to */
258 "multicast", /* The name of the service */
259 &service_connect_peer0, /* callback to call after a handle to service
261 NULL, /* closure for the above callback */
262 &service_conf_peer0, /* callback to call with peer's configuration;
263 this should open the needed service connection */
264 &service_close_peer0, /* callback to be called when closing the
265 opened service connection */
266 NULL); /* closure for the above two callbacks */
267 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
268 timeout_tid = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
269 &timeout_task, NULL);
274 main (int argc, char *argv[])
278 result = GNUNET_SYSERR;
279 ret = GNUNET_TESTBED_test_run
280 ("test-multicast-multipeer", /* test case name */
281 "test_multicast.conf", /* template configuration */
282 NUM_PEERS, /* number of peers to start */
283 0LL, /* Event mask - set to 0 for no event notifications */
284 NULL, /* Controller event callback */
285 NULL, /* Closure for controller event callback */
286 run, /* continuation callback to be called when testbed setup is complete */
287 NULL); /* Closure for the test_master callback */
288 if ( (GNUNET_OK != ret) || (GNUNET_OK != result) )
293 /* end of test_multicast_multipeer.c */