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_core_service.h"
35 #include "gnunet_multicast_service.h"
39 static struct GNUNET_TESTBED_Operation *multicast_peer0;
40 static struct GNUNET_TESTBED_Operation *multicast_peer1;
42 static struct GNUNET_SCHEDULER_Task *timeout_tid;
46 * Global result for testcase.
52 * Function run on CTRL-C or shutdown (i.e. success/timeout/etc.).
56 shutdown_task (void *cls)
58 if (NULL != multicast_peer0)
60 GNUNET_TESTBED_operation_done (multicast_peer0);
61 multicast_peer0 = NULL;
63 if (NULL != timeout_tid)
65 GNUNET_SCHEDULER_cancel (timeout_tid);
72 timeout_task (void *cls)
75 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
77 result = GNUNET_SYSERR;
78 GNUNET_SCHEDULER_shutdown ();
83 service_close_peer0 (void *cls,
86 struct GNUNET_MULTICAST_Origin *orig = op_result;
88 GNUNET_MULTICAST_origin_stop (orig,
95 * Function run when service multicast has started and is providing us
96 * with a configuration file.
99 service_conf_peer0 (void *cls,
100 const struct GNUNET_CONFIGURATION_Handle *cfg)
103 return GNUNET_MULTICAST_origin_start (cfg,
120 * Test logic of peer "0" being origin starts here.
122 * @param cls closure, for the example: NULL
123 * @param op should be equal to "dht_op"
124 * @param ca_result result of the connect operation, the
125 * connection to the DHT service
126 * @param emsg error message, if testbed somehow failed to
127 * connect to the DHT.
130 service_connect_peer0 (void *cls,
131 struct GNUNET_TESTBED_Operation *op,
135 struct GNUNET_MULTICAST_Origin *orig = ca_result;
137 /* Connection to service successful. Here we'd usually do something with
140 GNUNET_SCHEDULER_shutdown (); /* Also kills the testbed */
145 * Main function inovked from TESTBED once all of the
146 * peers are up and running. This one then connects
147 * just to the multicast service of peer 0 and 1.
148 * Peer 0 is going to be origin.
149 * Peer 1 is going to be one member.
150 * Origin will start a multicast group and the member will try to join it.
151 * After that we execute some multicast test.
154 * @param h the run handle
155 * @param peers started peers for the test
156 * @param num_peers size of the 'peers' array
157 * @param links_succeeded number of links between peers that were created
158 * @param links_failed number of links testbed was unable to establish
161 test_master (void *cls,
162 struct GNUNET_TESTBED_RunHandle *h,
163 unsigned int num_peers,
164 struct GNUNET_TESTBED_Peer **peers,
165 unsigned int links_succeeded,
166 unsigned int links_failed)
168 /* Testbed is ready with peers running and connected in a pre-defined overlay
171 /* connect to a peers service */
172 multicast_peer0 = GNUNET_TESTBED_service_connect
173 (NULL, /* Closure for operation */
174 peers[0], /* The peer whose service to connect to */
175 "multicast", /* The name of the service */
176 &service_connect_peer0, /* callback to call after a handle to service
178 NULL, /* closure for the above callback */
179 &service_conf_peer0, /* callback to call with peer's configuration;
180 this should open the needed service connection */
181 &service_close_peer0, /* callback to be called when closing the
182 opened service connection */
183 NULL); /* closure for the above two callbacks */
184 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
185 timeout_tid = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
186 &timeout_task, NULL);
191 main (int argc, char *argv[])
195 result = GNUNET_SYSERR;
196 ret = GNUNET_TESTBED_test_run
197 ("test-multicast-multipeer", /* test case name */
198 "test_multicast.conf", /* template configuration */
199 NUM_PEERS, /* number of peers to start */
200 0LL, /* Event mask - set to 0 for no event notifications */
201 NULL, /* Controller event callback */
202 NULL, /* Closure for controller event callback */
203 &test_master, /* continuation callback to be called when testbed setup is
205 NULL); /* Closure for the test_master callback */
206 if ( (GNUNET_OK != ret) || (GNUNET_OK != result) )
211 /* end of test_multicast_multipeer.c */