aboutsummaryrefslogtreecommitdiff
path: root/src/nse/test_nse_multipeer.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nse/test_nse_multipeer.c')
-rw-r--r--src/nse/test_nse_multipeer.c115
1 files changed, 57 insertions, 58 deletions
diff --git a/src/nse/test_nse_multipeer.c b/src/nse/test_nse_multipeer.c
index ec5a94f76..88ced26d2 100644
--- a/src/nse/test_nse_multipeer.c
+++ b/src/nse/test_nse_multipeer.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 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/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file nse/test_nse_multipeer.c 21 * @file nse/test_nse_multipeer.c
22 * @brief Testcase for the network size estimation service. Starts 22 * @brief Testcase for the network size estimation service. Starts
@@ -37,14 +37,13 @@
37/** 37/**
38 * How long do we run the test? 38 * How long do we run the test?
39 */ 39 */
40#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300) 40#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 300)
41 41
42 42
43/** 43/**
44 * Information we track for each peer. 44 * Information we track for each peer.
45 */ 45 */
46struct NSEPeer 46struct NSEPeer {
47{
48 /** 47 /**
49 * Handle for NSE connect operation. 48 * Handle for NSE connect operation.
50 */ 49 */
@@ -72,13 +71,13 @@ static int ok;
72 * Task run on timeout to shut everything down. 71 * Task run on timeout to shut everything down.
73 */ 72 */
74static void 73static void
75shutdown_task (void *cls) 74shutdown_task(void *cls)
76{ 75{
77 unsigned int i; 76 unsigned int i;
78 77
79 for (i=0;i<NUM_PEERS;i++) 78 for (i = 0; i < NUM_PEERS; i++)
80 GNUNET_TESTBED_operation_done (nse_peers[i].op); 79 GNUNET_TESTBED_operation_done(nse_peers[i].op);
81 GNUNET_SCHEDULER_shutdown (); 80 GNUNET_SCHEDULER_shutdown();
82} 81}
83 82
84 83
@@ -93,17 +92,17 @@ shutdown_task (void *cls)
93 * 92 *
94 */ 93 */
95static void 94static void
96handle_estimate (void *cls, struct GNUNET_TIME_Absolute timestamp, 95handle_estimate(void *cls, struct GNUNET_TIME_Absolute timestamp,
97 double estimate, double std_dev) 96 double estimate, double std_dev)
98{ 97{
99 struct NSEPeer *peer = cls; 98 struct NSEPeer *peer = cls;
100 99
101 fprintf (stderr, 100 fprintf(stderr,
102 "Received network size estimate from peer %u. logSize: %f std.dev. %f (%f/%u)\n", 101 "Received network size estimate from peer %u. logSize: %f std.dev. %f (%f/%u)\n",
103 (unsigned int) (peer - nse_peers), 102 (unsigned int)(peer - nse_peers),
104 estimate, std_dev, 103 estimate, std_dev,
105 GNUNET_NSE_log_estimate_to_n (estimate), 104 GNUNET_NSE_log_estimate_to_n(estimate),
106 NUM_PEERS); 105 NUM_PEERS);
107 ok = 0; 106 ok = 0;
108} 107}
109 108
@@ -118,22 +117,22 @@ handle_estimate (void *cls, struct GNUNET_TIME_Absolute timestamp,
118 * operation has executed successfully. 117 * operation has executed successfully.
119 */ 118 */
120static void 119static void
121nse_connect_complete_cb (void *cls, 120nse_connect_complete_cb(void *cls,
122 struct GNUNET_TESTBED_Operation *op, 121 struct GNUNET_TESTBED_Operation *op,
123 void *ca_result, 122 void *ca_result,
124 const char *emsg) 123 const char *emsg)
125{ 124{
126 struct NSEPeer *peer = cls; 125 struct NSEPeer *peer = cls;
127 struct GNUNET_NSE_Handle *nse = ca_result; 126 struct GNUNET_NSE_Handle *nse = ca_result;
128 127
129 GNUNET_assert (op == peer->op); 128 GNUNET_assert(op == peer->op);
130 if (NULL != emsg) 129 if (NULL != emsg)
131 { 130 {
132 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 131 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
133 "Failed to connect to NSE service: %s\n", 132 "Failed to connect to NSE service: %s\n",
134 emsg); 133 emsg);
135 ok = 1; 134 ok = 1;
136 GNUNET_SCHEDULER_shutdown (); 135 GNUNET_SCHEDULER_shutdown();
137 return; 136 return;
138 } 137 }
139 peer->nse_handle = nse; 138 peer->nse_handle = nse;
@@ -151,12 +150,12 @@ nse_connect_complete_cb (void *cls,
151 * @return service handle to return in 'op_result', NULL on error 150 * @return service handle to return in 'op_result', NULL on error
152 */ 151 */
153static void * 152static void *
154nse_connect_adapter (void *cls, 153nse_connect_adapter(void *cls,
155 const struct GNUNET_CONFIGURATION_Handle *cfg) 154 const struct GNUNET_CONFIGURATION_Handle *cfg)
156{ 155{
157 return GNUNET_NSE_connect (cfg, 156 return GNUNET_NSE_connect(cfg,
158 &handle_estimate, 157 &handle_estimate,
159 cls); 158 cls);
160} 159}
161 160
162 161
@@ -168,10 +167,10 @@ nse_connect_adapter (void *cls,
168 * @param op_result service handle returned from the connect adapter 167 * @param op_result service handle returned from the connect adapter
169 */ 168 */
170static void 169static void
171nse_disconnect_adapter (void *cls, 170nse_disconnect_adapter(void *cls,
172 void *op_result) 171 void *op_result)
173{ 172{
174 GNUNET_NSE_disconnect (op_result); 173 GNUNET_NSE_disconnect(op_result);
175} 174}
176 175
177 176
@@ -188,27 +187,27 @@ nse_disconnect_adapter (void *cls,
188 * failed 187 * failed
189 */ 188 */
190static void 189static void
191run (void *cls, 190run(void *cls,
192 struct GNUNET_TESTBED_RunHandle *h, 191 struct GNUNET_TESTBED_RunHandle *h,
193 unsigned int num_peers, 192 unsigned int num_peers,
194 struct GNUNET_TESTBED_Peer **peers, 193 struct GNUNET_TESTBED_Peer **peers,
195 unsigned int links_succeeded, 194 unsigned int links_succeeded,
196 unsigned int links_failed) 195 unsigned int links_failed)
197{ 196{
198 unsigned int i; 197 unsigned int i;
199 198
200 GNUNET_assert (NUM_PEERS == num_peers); 199 GNUNET_assert(NUM_PEERS == num_peers);
201 for (i=0;i<num_peers;i++) 200 for (i = 0; i < num_peers; i++)
202 nse_peers[i].op = GNUNET_TESTBED_service_connect (&nse_peers[i], 201 nse_peers[i].op = GNUNET_TESTBED_service_connect(&nse_peers[i],
203 peers[i], 202 peers[i],
204 "nse", 203 "nse",
205 &nse_connect_complete_cb, 204 &nse_connect_complete_cb,
206 &nse_peers[i], 205 &nse_peers[i],
207 &nse_connect_adapter, 206 &nse_connect_adapter,
208 &nse_disconnect_adapter, 207 &nse_disconnect_adapter,
209 &nse_peers[i]); 208 &nse_peers[i]);
210 GNUNET_SCHEDULER_add_delayed (TIMEOUT, 209 GNUNET_SCHEDULER_add_delayed(TIMEOUT,
211 &shutdown_task, NULL); 210 &shutdown_task, NULL);
212} 211}
213 212
214 213
@@ -220,14 +219,14 @@ run (void *cls,
220 * @return 0 on success 219 * @return 0 on success
221 */ 220 */
222int 221int
223main (int argc, char *argv[]) 222main(int argc, char *argv[])
224{ 223{
225 ok = 1; 224 ok = 1;
226 (void) GNUNET_TESTBED_test_run ("test-nse-multipeer", 225 (void)GNUNET_TESTBED_test_run("test-nse-multipeer",
227 "test_nse.conf", 226 "test_nse.conf",
228 NUM_PEERS, 227 NUM_PEERS,
229 0, NULL, NULL, 228 0, NULL, NULL,
230 &run, NULL); 229 &run, NULL);
231 return ok; 230 return ok;
232} 231}
233 232