2 This file is part of GNUnet.
3 (C) 2009, 2012 Christian Grothoff (and other contributing authors)
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., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
21 * @file rps/test_rps_multipeer.c
22 * @brief Testcase for the random peer sampling service. Starts
23 * a peergroup with a given number of peers, then waits to
24 * receive size pushes/pulls from each peer. Expects to wait
25 * for one message from each peer.
28 #include "gnunet_testbed_service.h"
29 #include "gnunet_rps_service.h"
34 * How many peers do we start?
39 * How long do we run the test?
41 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120)
45 * Information we track for each peer.
50 * Handle for RPS connect operation.
52 struct GNUNET_TESTBED_Operation *op;
55 * Handle to RPS service.
57 struct GNUNET_RPS_Handle *rps_handle;
62 * Information for all the peers.
64 static struct RPSPeer rps_peers[NUM_PEERS];
67 * Return value from 'main'.
73 * Task run on timeout to shut everything down.
76 shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
80 for (i=0;i<NUM_PEERS;i++)
81 GNUNET_TESTBED_operation_done (rps_peers[i].op);
82 GNUNET_SCHEDULER_shutdown ();
87 * Callback to call when network size estimate is updated.
90 * @param timestamp server timestamp
91 * @param estimate the value of the current network size estimate
92 * @param std_dev standard deviation (rounded down to nearest integer)
93 * of the size estimation values seen
97 handle_reply (void *cls, uint64_t n, const struct GNUNET_PeerIdentity *peers)
100 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got peer %s\n", GNUNET_i2s(peers));
107 * Callback to be called when RPS service connect operation is completed
109 * @param cls the callback closure from functions generating an operation
110 * @param op the operation that has been finished
111 * @param ca_result the RPS service handle returned from rps_connect_adapter
112 * @param emsg error message in case the operation has failed; will be NULL if
113 * operation has executed successfully.
116 rps_connect_complete_cb (void *cls,
117 struct GNUNET_TESTBED_Operation *op,
121 struct RPSPeer *peer = cls;
122 struct GNUNET_RPS_Handle *rps = ca_result;
124 GNUNET_assert (op == peer->op);
127 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
128 "Failed to connect to RPS service: %s\n",
131 GNUNET_SCHEDULER_shutdown ();
134 peer->rps_handle = rps;
135 GNUNET_RPS_request_peers(rps, 1, handle_reply, NULL);
136 GNUNET_RPS_request_peers(rps, 1, handle_reply, NULL);
141 * Adapter function called to establish a connection to
145 * @param cfg configuration of the peer to connect to; will be available until
146 * GNUNET_TESTBED_operation_done() is called on the operation returned
147 * from GNUNET_TESTBED_service_connect()
148 * @return service handle to return in 'op_result', NULL on error
151 rps_connect_adapter (void *cls,
152 const struct GNUNET_CONFIGURATION_Handle *cfg)
154 return GNUNET_RPS_connect (cfg);
159 * Adapter function called to destroy connection to
163 * @param op_result service handle returned from the connect adapter
166 rps_disconnect_adapter (void *cls,
169 struct GNUNET_RPS_Handle *h = op_result;
170 GNUNET_RPS_disconnect (h);
175 * Actual "main" function for the testcase.
178 * @param h the run handle
179 * @param num_peers number of peers in 'peers'
180 * @param peers handle to peers run in the testbed
181 * @param links_succeeded the number of overlay link connection attempts that
183 * @param links_failed the number of overlay link connection attempts that
188 struct GNUNET_TESTBED_RunHandle *h,
189 unsigned int num_peers,
190 struct GNUNET_TESTBED_Peer **peers,
191 unsigned int links_succeeded,
192 unsigned int links_failed)
196 GNUNET_assert (NUM_PEERS == num_peers);
197 for (i=0;i<num_peers;i++)
198 rps_peers[i].op = GNUNET_TESTBED_service_connect (&rps_peers[i],
201 &rps_connect_complete_cb,
203 &rps_connect_adapter,
204 &rps_disconnect_adapter,
206 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &shutdown_task, NULL);
211 * Entry point for the testcase, sets up the testbed.
215 * @return 0 on success
218 main (int argc, char *argv[])
221 (void) GNUNET_TESTBED_test_run ("test-rps-multipeer",
229 /* end of test_rps_multipeer.c */