diff options
author | Julius Bünger <buenger@mytum.de> | 2015-03-26 15:29:39 +0000 |
---|---|---|
committer | Julius Bünger <buenger@mytum.de> | 2015-03-26 15:29:39 +0000 |
commit | 9982f58b45230373960cea1fe1fb294602bdd56d (patch) | |
tree | 2a48a548b201d72b29f00e262fc8ba413c989865 /src | |
parent | b68a1cacd29fb91dee84f736085c48db4ea5acaf (diff) | |
download | gnunet-9982f58b45230373960cea1fe1fb294602bdd56d.tar.gz gnunet-9982f58b45230373960cea1fe1fb294602bdd56d.zip |
-restructured code
Diffstat (limited to 'src')
-rw-r--r-- | src/rps/Makefile.am | 9 | ||||
-rw-r--r-- | src/rps/gnunet-service-rps.c | 5 | ||||
-rw-r--r-- | src/rps/rps.h | 6 | ||||
-rw-r--r-- | src/rps/rps_api.c | 19 | ||||
-rw-r--r-- | src/rps/test_rps_malicious_1.c | 383 | ||||
-rw-r--r-- | src/rps/test_rps_multipeer.c | 2 |
6 files changed, 30 insertions, 394 deletions
diff --git a/src/rps/Makefile.am b/src/rps/Makefile.am index fe086e59c..b1e62eb12 100644 --- a/src/rps/Makefile.am +++ b/src/rps/Makefile.am | |||
@@ -59,7 +59,8 @@ gnunet_service_rps_LDADD = \ | |||
59 | if HAVE_TESTING | 59 | if HAVE_TESTING |
60 | check_PROGRAMS = \ | 60 | check_PROGRAMS = \ |
61 | test_rps_multipeer \ | 61 | test_rps_multipeer \ |
62 | test_rps_malicious_1 | 62 | test_rps_malicious_1 \ |
63 | test_rps_malicious_2 | ||
63 | endif | 64 | endif |
64 | 65 | ||
65 | ld_rps_test_lib = \ | 66 | ld_rps_test_lib = \ |
@@ -79,9 +80,13 @@ test_rps_multipeer_SOURCES = \ | |||
79 | test_rps_multipeer_LDADD = $(ld_rps_test_lib) | 80 | test_rps_multipeer_LDADD = $(ld_rps_test_lib) |
80 | 81 | ||
81 | test_rps_malicious_1_SOURCES = \ | 82 | test_rps_malicious_1_SOURCES = \ |
82 | test_rps_malicious_1.c | 83 | test_rps_malicious.c |
83 | test_rps_malicious_1_LDADD = $(ld_rps_test_lib) | 84 | test_rps_malicious_1_LDADD = $(ld_rps_test_lib) |
84 | 85 | ||
86 | test_rps_malicious_2_SOURCES = \ | ||
87 | test_rps_malicious.c | ||
88 | test_rps_malicious_2_LDADD = $(ld_rps_test_lib) | ||
89 | |||
85 | EXTRA_DIST = \ | 90 | EXTRA_DIST = \ |
86 | test_rps.conf | 91 | test_rps.conf |
87 | 92 | ||
diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c index 243d54f7d..08d647781 100644 --- a/src/rps/gnunet-service-rps.c +++ b/src/rps/gnunet-service-rps.c | |||
@@ -1056,7 +1056,7 @@ add_peer_array_to_set (const struct GNUNET_PeerIdentity *peer_array, | |||
1056 | { | 1056 | { |
1057 | unsigned int i; | 1057 | unsigned int i; |
1058 | if (NULL == peer_map) | 1058 | if (NULL == peer_map) |
1059 | peer_map = GNUNET_CONTAINER_multipeermap_create (num_peers, | 1059 | peer_map = GNUNET_CONTAINER_multipeermap_create (num_peers + 1, |
1060 | GNUNET_NO); | 1060 | GNUNET_NO); |
1061 | for (i = 0 ; i < num_peers ; i++) | 1061 | for (i = 0 ; i < num_peers ; i++) |
1062 | { | 1062 | { |
@@ -1672,6 +1672,7 @@ handle_client_act_malicious (void *cls, | |||
1672 | 1672 | ||
1673 | 1673 | ||
1674 | /* Do actual logic */ | 1674 | /* Do actual logic */ |
1675 | // FIXME ingore own id | ||
1675 | peers = (struct GNUNET_PeerIdentity *) &msg[1]; | 1676 | peers = (struct GNUNET_PeerIdentity *) &msg[1]; |
1676 | mal_type = ntohl (in_msg->type); | 1677 | mal_type = ntohl (in_msg->type); |
1677 | 1678 | ||
@@ -1721,7 +1722,7 @@ handle_client_act_malicious (void *cls, | |||
1721 | 1722 | ||
1722 | /* Store the one attacked peer */ | 1723 | /* Store the one attacked peer */ |
1723 | memcpy (&attacked_peer, | 1724 | memcpy (&attacked_peer, |
1724 | &peers[num_mal_peers_sent], | 1725 | &in_msg->attacked_peer, |
1725 | sizeof (struct GNUNET_PeerIdentity)); | 1726 | sizeof (struct GNUNET_PeerIdentity)); |
1726 | 1727 | ||
1727 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1728 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
diff --git a/src/rps/rps.h b/src/rps/rps.h index 3c5713bdc..ad255acab 100644 --- a/src/rps/rps.h +++ b/src/rps/rps.h | |||
@@ -135,6 +135,12 @@ struct GNUNET_RPS_CS_ActMaliciousMessage | |||
135 | struct GNUNET_MessageHeader header; | 135 | struct GNUNET_MessageHeader header; |
136 | 136 | ||
137 | /** | 137 | /** |
138 | * If the type is 2 this is the attacked peer, | ||
139 | * empty otherwise. | ||
140 | */ | ||
141 | struct GNUNET_PeerIdentity attacked_peer; | ||
142 | |||
143 | /** | ||
138 | * Type of malicious behaviour. | 144 | * Type of malicious behaviour. |
139 | * | 145 | * |
140 | * 0 No malicious bahaviour at all | 146 | * 0 No malicious bahaviour at all |
diff --git a/src/rps/rps_api.c b/src/rps/rps_api.c index 3afff58e6..c46851fe9 100644 --- a/src/rps/rps_api.c +++ b/src/rps/rps_api.c | |||
@@ -311,7 +311,7 @@ GNUNET_RPS_seed_ids (struct GNUNET_RPS_Handle *h, | |||
311 | GNUNET_RPS_act_malicious (struct GNUNET_RPS_Handle *h, | 311 | GNUNET_RPS_act_malicious (struct GNUNET_RPS_Handle *h, |
312 | uint32_t type, | 312 | uint32_t type, |
313 | uint32_t num_peers, | 313 | uint32_t num_peers, |
314 | const struct GNUNET_PeerIdentity *ids) | 314 | const struct GNUNET_PeerIdentity *peer_ids) |
315 | { | 315 | { |
316 | size_t size_needed; | 316 | size_t size_needed; |
317 | uint32_t num_peers_max; | 317 | uint32_t num_peers_max; |
@@ -329,9 +329,9 @@ GNUNET_RPS_act_malicious (struct GNUNET_RPS_Handle *h, | |||
329 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 329 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
330 | "%u. peer: %s\n", | 330 | "%u. peer: %s\n", |
331 | i, | 331 | i, |
332 | GNUNET_i2s (&ids[i])); | 332 | GNUNET_i2s (&peer_ids[i])); |
333 | 333 | ||
334 | /* The actual size the message occupies */ | 334 | /* The actual size the message would occupy */ |
335 | size_needed = sizeof (struct GNUNET_RPS_CS_SeedMessage) + | 335 | size_needed = sizeof (struct GNUNET_RPS_CS_SeedMessage) + |
336 | num_peers * sizeof (struct GNUNET_PeerIdentity); | 336 | num_peers * sizeof (struct GNUNET_PeerIdentity); |
337 | /* The number of peers that fit in one message together with | 337 | /* The number of peers that fit in one message together with |
@@ -339,7 +339,7 @@ GNUNET_RPS_act_malicious (struct GNUNET_RPS_Handle *h, | |||
339 | num_peers_max = (GNUNET_SERVER_MAX_MESSAGE_SIZE - | 339 | num_peers_max = (GNUNET_SERVER_MAX_MESSAGE_SIZE - |
340 | sizeof (struct GNUNET_RPS_CS_SeedMessage)) / | 340 | sizeof (struct GNUNET_RPS_CS_SeedMessage)) / |
341 | sizeof (struct GNUNET_PeerIdentity); | 341 | sizeof (struct GNUNET_PeerIdentity); |
342 | tmp_peer_pointer = ids; | 342 | tmp_peer_pointer = peer_ids; |
343 | 343 | ||
344 | while (GNUNET_SERVER_MAX_MESSAGE_SIZE < size_needed) | 344 | while (GNUNET_SERVER_MAX_MESSAGE_SIZE < size_needed) |
345 | { | 345 | { |
@@ -351,14 +351,19 @@ GNUNET_RPS_act_malicious (struct GNUNET_RPS_Handle *h, | |||
351 | GNUNET_MESSAGE_TYPE_RPS_ACT_MALICIOUS); | 351 | GNUNET_MESSAGE_TYPE_RPS_ACT_MALICIOUS); |
352 | msg->type = htonl (type); | 352 | msg->type = htonl (type); |
353 | msg->num_peers = htonl (num_peers_max); | 353 | msg->num_peers = htonl (num_peers_max); |
354 | memcpy (&msg[1], tmp_peer_pointer, num_peers_max * sizeof (struct GNUNET_PeerIdentity)); | 354 | if (2 == type) |
355 | msg->attacked_peer = peer_ids[num_peers]; | ||
356 | memcpy (&msg[1], | ||
357 | tmp_peer_pointer, | ||
358 | num_peers_max * sizeof (struct GNUNET_PeerIdentity)); | ||
359 | |||
355 | GNUNET_MQ_send (h->mq, ev); | 360 | GNUNET_MQ_send (h->mq, ev); |
356 | 361 | ||
357 | num_peers -= num_peers_max; | 362 | num_peers -= num_peers_max; |
358 | size_needed = sizeof (struct GNUNET_RPS_CS_SeedMessage) + | 363 | size_needed = sizeof (struct GNUNET_RPS_CS_SeedMessage) + |
359 | num_peers * sizeof (struct GNUNET_PeerIdentity); | 364 | num_peers * sizeof (struct GNUNET_PeerIdentity); |
360 | /* Set pointer to beginning of next block of num_peers_max peers */ | 365 | /* Set pointer to beginning of next block of num_peers_max peers */ |
361 | tmp_peer_pointer = &ids[num_peers_max]; | 366 | tmp_peer_pointer = &peer_ids[num_peers_max]; |
362 | } | 367 | } |
363 | 368 | ||
364 | ev = GNUNET_MQ_msg_extra (msg, | 369 | ev = GNUNET_MQ_msg_extra (msg, |
@@ -366,6 +371,8 @@ GNUNET_RPS_act_malicious (struct GNUNET_RPS_Handle *h, | |||
366 | GNUNET_MESSAGE_TYPE_RPS_ACT_MALICIOUS); | 371 | GNUNET_MESSAGE_TYPE_RPS_ACT_MALICIOUS); |
367 | msg->type = htonl (type); | 372 | msg->type = htonl (type); |
368 | msg->num_peers = htonl (num_peers); | 373 | msg->num_peers = htonl (num_peers); |
374 | if (2 == type) | ||
375 | msg->attacked_peer = peer_ids[num_peers]; | ||
369 | memcpy (&msg[1], tmp_peer_pointer, num_peers * sizeof (struct GNUNET_PeerIdentity)); | 376 | memcpy (&msg[1], tmp_peer_pointer, num_peers * sizeof (struct GNUNET_PeerIdentity)); |
370 | 377 | ||
371 | GNUNET_MQ_send (h->mq, ev); | 378 | GNUNET_MQ_send (h->mq, ev); |
diff --git a/src/rps/test_rps_malicious_1.c b/src/rps/test_rps_malicious_1.c deleted file mode 100644 index 50ae2ac86..000000000 --- a/src/rps/test_rps_malicious_1.c +++ /dev/null | |||
@@ -1,383 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2009, 2012 Christian Grothoff (and other contributing authors) | ||
4 | |||
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. | ||
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 | General Public License for more details. | ||
14 | |||
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. | ||
19 | */ | ||
20 | /** | ||
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. | ||
26 | */ | ||
27 | #include "platform.h" | ||
28 | #include "gnunet_testbed_service.h" | ||
29 | #include "gnunet_rps_service.h" | ||
30 | |||
31 | #include <inttypes.h> | ||
32 | |||
33 | |||
34 | /** | ||
35 | * How many peers do we start? | ||
36 | */ | ||
37 | #define NUM_PEERS 10 | ||
38 | |||
39 | /** | ||
40 | * How long do we run the test? | ||
41 | */ | ||
42 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) | ||
43 | |||
44 | |||
45 | /** | ||
46 | * Portion of malicious peers | ||
47 | */ | ||
48 | static double portion = .1; | ||
49 | |||
50 | |||
51 | /** | ||
52 | * Information we track for each peer. | ||
53 | */ | ||
54 | struct RPSPeer | ||
55 | { | ||
56 | /** | ||
57 | * Index of the peer. | ||
58 | */ | ||
59 | unsigned int index; | ||
60 | |||
61 | /** | ||
62 | * Handle for RPS connect operation. | ||
63 | */ | ||
64 | struct GNUNET_TESTBED_Operation *op; | ||
65 | |||
66 | /** | ||
67 | * Handle to RPS service. | ||
68 | */ | ||
69 | struct GNUNET_RPS_Handle *rps_handle; | ||
70 | |||
71 | /** | ||
72 | * ID of the peer. | ||
73 | */ | ||
74 | struct GNUNET_PeerIdentity *peer_id; | ||
75 | }; | ||
76 | |||
77 | |||
78 | /** | ||
79 | * Information for all the peers. | ||
80 | */ | ||
81 | static struct RPSPeer rps_peers[NUM_PEERS]; | ||
82 | |||
83 | /** | ||
84 | * IDs of the peers. | ||
85 | */ | ||
86 | static struct GNUNET_PeerIdentity rps_peer_ids[NUM_PEERS]; | ||
87 | |||
88 | /** | ||
89 | * Return value from 'main'. | ||
90 | */ | ||
91 | static int ok; | ||
92 | |||
93 | |||
94 | /** | ||
95 | * Task run on timeout to shut everything down. | ||
96 | */ | ||
97 | static void | ||
98 | shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
99 | { | ||
100 | unsigned int i; | ||
101 | |||
102 | for (i=0;i<NUM_PEERS;i++) | ||
103 | GNUNET_TESTBED_operation_done (rps_peers[i].op); | ||
104 | GNUNET_SCHEDULER_shutdown (); | ||
105 | } | ||
106 | |||
107 | |||
108 | /** | ||
109 | * Callback to call when network size estimate is updated. | ||
110 | * | ||
111 | * @param cls closure | ||
112 | * @param timestamp server timestamp | ||
113 | * @param estimate the value of the current network size estimate | ||
114 | * @param std_dev standard deviation (rounded down to nearest integer) | ||
115 | * of the size estimation values seen | ||
116 | * | ||
117 | */ | ||
118 | static void | ||
119 | handle_reply (void *cls, uint64_t n, const struct GNUNET_PeerIdentity *peers) | ||
120 | { | ||
121 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got peer %s\n", GNUNET_i2s (peers)); | ||
122 | |||
123 | ok = 0; | ||
124 | } | ||
125 | |||
126 | |||
127 | /** | ||
128 | * (Randomly) request random peers. | ||
129 | */ | ||
130 | void | ||
131 | request_peers (void *cls, | ||
132 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
133 | { | ||
134 | struct RPSPeer *peer = (struct RPSPeer *) cls; | ||
135 | struct GNUNET_RPS_Request_Handle *req_handle; | ||
136 | |||
137 | req_handle = GNUNET_RPS_request_peers (peer->rps_handle, 1, handle_reply, NULL); | ||
138 | GNUNET_free (req_handle); | ||
139 | } | ||
140 | |||
141 | |||
142 | /** | ||
143 | * Seed peers. | ||
144 | */ | ||
145 | void | ||
146 | seed_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
147 | { | ||
148 | unsigned int amount; | ||
149 | struct RPSPeer *peer = (struct RPSPeer *) cls; | ||
150 | unsigned int i; | ||
151 | |||
152 | GNUNET_assert (1 >= portion | ||
153 | && 0 < portion); | ||
154 | |||
155 | amount = round (portion * NUM_PEERS); | ||
156 | |||
157 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Seeding peers:\n"); | ||
158 | for (i = 0 ; i < amount ; i++) | ||
159 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Seeding %u. peer: %s\n", | ||
160 | i, | ||
161 | GNUNET_i2s (&rps_peer_ids[i])); | ||
162 | |||
163 | GNUNET_RPS_seed_ids (peer->rps_handle, amount, rps_peer_ids); | ||
164 | } | ||
165 | |||
166 | |||
167 | /** | ||
168 | * Get the id of peer i. | ||
169 | */ | ||
170 | void | ||
171 | info_cb (void *cb_cls, | ||
172 | struct GNUNET_TESTBED_Operation *op, | ||
173 | const struct GNUNET_TESTBED_PeerInformation *pinfo, | ||
174 | const char *emsg) | ||
175 | { | ||
176 | unsigned int i = *((unsigned int *) cb_cls); | ||
177 | |||
178 | if (NULL == pinfo || NULL != emsg) | ||
179 | { | ||
180 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Got Error: %s\n", emsg); | ||
181 | return; | ||
182 | } | ||
183 | |||
184 | GNUNET_free (cb_cls); | ||
185 | |||
186 | rps_peer_ids[i] = *(pinfo->result.id); | ||
187 | rps_peers[i].peer_id = &rps_peer_ids[i]; | ||
188 | |||
189 | } | ||
190 | |||
191 | |||
192 | /** | ||
193 | * Callback to be called when RPS service connect operation is completed | ||
194 | * | ||
195 | * @param cls the callback closure from functions generating an operation | ||
196 | * @param op the operation that has been finished | ||
197 | * @param ca_result the RPS service handle returned from rps_connect_adapter | ||
198 | * @param emsg error message in case the operation has failed; will be NULL if | ||
199 | * operation has executed successfully. | ||
200 | */ | ||
201 | static void | ||
202 | rps_connect_complete_cb (void *cls, | ||
203 | struct GNUNET_TESTBED_Operation *op, | ||
204 | void *ca_result, | ||
205 | const char *emsg) | ||
206 | { | ||
207 | struct RPSPeer *rps_peer = cls; | ||
208 | struct GNUNET_RPS_Handle *rps = ca_result; | ||
209 | struct GNUNET_RPS_Request_Handle *req_handle; | ||
210 | uint32_t num_mal_peers; | ||
211 | |||
212 | rps_peer->rps_handle = rps; | ||
213 | |||
214 | GNUNET_assert (op == rps_peer->op); | ||
215 | if (NULL != emsg) | ||
216 | { | ||
217 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
218 | "Failed to connect to RPS service: %s\n", | ||
219 | emsg); | ||
220 | ok = 1; | ||
221 | GNUNET_SCHEDULER_shutdown (); | ||
222 | return; | ||
223 | } | ||
224 | |||
225 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started client successfully\n"); | ||
226 | |||
227 | #ifdef ENABLE_MALICIOUS | ||
228 | GNUNET_assert (1 >= portion | ||
229 | && 0 < portion); | ||
230 | num_mal_peers = round (portion * NUM_PEERS); | ||
231 | |||
232 | if (rps_peer->index >= num_mal_peers) | ||
233 | { | ||
234 | req_handle = GNUNET_RPS_request_peers (rps, 1, handle_reply, NULL); | ||
235 | GNUNET_free (req_handle); | ||
236 | } | ||
237 | #else /* ENABLE_MALICIOUS */ | ||
238 | req_handle = GNUNET_RPS_request_peers (rps, 1, handle_reply, NULL); | ||
239 | GNUNET_free (req_handle); | ||
240 | #endif /* ENABLE_MALICIOUS */ | ||
241 | |||
242 | //GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10), | ||
243 | // request_peers, peer); | ||
244 | //GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10), | ||
245 | // seed_peers, peer); | ||
246 | // TODO test seeding > GNUNET_SERVER_MAX_MESSAGE_SIZE peers | ||
247 | } | ||
248 | |||
249 | |||
250 | /** | ||
251 | * Adapter function called to establish a connection to | ||
252 | * the RPS service. | ||
253 | * | ||
254 | * @param cls closure | ||
255 | * @param cfg configuration of the peer to connect to; will be available until | ||
256 | * GNUNET_TESTBED_operation_done() is called on the operation returned | ||
257 | * from GNUNET_TESTBED_service_connect() | ||
258 | * @return service handle to return in 'op_result', NULL on error | ||
259 | */ | ||
260 | static void * | ||
261 | rps_connect_adapter (void *cls, | ||
262 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
263 | { | ||
264 | struct GNUNET_RPS_Handle *h; | ||
265 | #ifdef ENABLE_MALICIOUS | ||
266 | uint32_t num_mal_peers; | ||
267 | struct RPSPeer *rps_peer = (struct RPSPeer *) cls; | ||
268 | #endif /* ENABLE_MALICIOUS */ | ||
269 | |||
270 | h = GNUNET_RPS_connect (cfg); | ||
271 | |||
272 | #ifdef ENABLE_MALICIOUS | ||
273 | GNUNET_assert (1 >= portion | ||
274 | && 0 < portion); | ||
275 | num_mal_peers = round (portion * NUM_PEERS); | ||
276 | |||
277 | if (rps_peer->index < num_mal_peers) | ||
278 | { | ||
279 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
280 | "%u. peer [%s] of %" PRIu32 " malicious peers turning malicious\n", | ||
281 | rps_peer->index, | ||
282 | GNUNET_i2s (rps_peer->peer_id), | ||
283 | num_mal_peers); | ||
284 | |||
285 | GNUNET_RPS_act_malicious (h, 1, num_mal_peers, rps_peer_ids); | ||
286 | #endif /* ENABLE_MALICIOUS */ | ||
287 | } | ||
288 | |||
289 | return h; | ||
290 | } | ||
291 | |||
292 | |||
293 | /** | ||
294 | * Adapter function called to destroy connection to | ||
295 | * RPS service. | ||
296 | * | ||
297 | * @param cls closure | ||
298 | * @param op_result service handle returned from the connect adapter | ||
299 | */ | ||
300 | static void | ||
301 | rps_disconnect_adapter (void *cls, | ||
302 | void *op_result) | ||
303 | { | ||
304 | struct GNUNET_RPS_Handle *h = op_result; | ||
305 | GNUNET_RPS_disconnect (h); | ||
306 | } | ||
307 | |||
308 | |||
309 | /** | ||
310 | * Actual "main" function for the testcase. | ||
311 | * | ||
312 | * @param cls closure | ||
313 | * @param h the run handle | ||
314 | * @param num_peers number of peers in 'peers' | ||
315 | * @param peers handle to peers run in the testbed | ||
316 | * @param links_succeeded the number of overlay link connection attempts that | ||
317 | * succeeded | ||
318 | * @param links_failed the number of overlay link connection attempts that | ||
319 | * failed | ||
320 | */ | ||
321 | static void | ||
322 | run (void *cls, | ||
323 | struct GNUNET_TESTBED_RunHandle *h, | ||
324 | unsigned int num_peers, | ||
325 | struct GNUNET_TESTBED_Peer **peers, | ||
326 | unsigned int links_succeeded, | ||
327 | unsigned int links_failed) | ||
328 | { | ||
329 | unsigned int i; | ||
330 | unsigned int *tmp_i; | ||
331 | |||
332 | tmp_i = GNUNET_new (unsigned int); | ||
333 | |||
334 | for (i = 0 ; i < NUM_PEERS ; i++) | ||
335 | { | ||
336 | tmp_i = GNUNET_new (unsigned int); | ||
337 | *tmp_i = i; | ||
338 | |||
339 | (void) GNUNET_TESTBED_peer_get_information (peers[i], | ||
340 | GNUNET_TESTBED_PIT_IDENTITY, | ||
341 | &info_cb, | ||
342 | tmp_i); | ||
343 | } | ||
344 | |||
345 | |||
346 | GNUNET_assert (NUM_PEERS == num_peers); | ||
347 | for (i = 0 ; i < num_peers ; i++) | ||
348 | { | ||
349 | rps_peers[i].index = i; | ||
350 | rps_peers[i].op = | ||
351 | GNUNET_TESTBED_service_connect (&rps_peers[i], | ||
352 | peers[i], | ||
353 | "rps", | ||
354 | &rps_connect_complete_cb, | ||
355 | &rps_peers[i], | ||
356 | &rps_connect_adapter, | ||
357 | &rps_disconnect_adapter, | ||
358 | &rps_peers[i]); | ||
359 | } | ||
360 | GNUNET_SCHEDULER_add_delayed (TIMEOUT, &shutdown_task, NULL); | ||
361 | } | ||
362 | |||
363 | |||
364 | /** | ||
365 | * Entry point for the testcase, sets up the testbed. | ||
366 | * | ||
367 | * @param argc unused | ||
368 | * @param argv unused | ||
369 | * @return 0 on success | ||
370 | */ | ||
371 | int | ||
372 | main (int argc, char *argv[]) | ||
373 | { | ||
374 | ok = 1; | ||
375 | (void) GNUNET_TESTBED_test_run ("test-rps-multipeer", | ||
376 | "test_rps.conf", | ||
377 | NUM_PEERS, | ||
378 | 0, NULL, NULL, | ||
379 | &run, NULL); | ||
380 | return ok; | ||
381 | } | ||
382 | |||
383 | /* end of test_rps_multipeer.c */ | ||
diff --git a/src/rps/test_rps_multipeer.c b/src/rps/test_rps_multipeer.c index df897b13d..94f709595 100644 --- a/src/rps/test_rps_multipeer.c +++ b/src/rps/test_rps_multipeer.c | |||
@@ -38,7 +38,7 @@ | |||
38 | /** | 38 | /** |
39 | * How long do we run the test? | 39 | * How long do we run the test? |
40 | */ | 40 | */ |
41 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) | 41 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) |
42 | 42 | ||
43 | 43 | ||
44 | /** | 44 | /** |