summaryrefslogtreecommitdiff
path: root/src/rps/test_rps.c
diff options
context:
space:
mode:
authorJulius Bünger <buenger@mytum.de>2015-03-27 12:40:57 +0000
committerJulius Bünger <buenger@mytum.de>2015-03-27 12:40:57 +0000
commit56b7edba342e4f753ab19042446f9b50668a10fe (patch)
tree7109c2e9a3bd3c8942302c90d5f325a5d4001ef2 /src/rps/test_rps.c
parent63e39ecc935e2476dcb0bdb54c3ed35188617628 (diff)
downloadgnunet-56b7edba342e4f753ab19042446f9b50668a10fe.tar.gz
gnunet-56b7edba342e4f753ab19042446f9b50668a10fe.zip
-further refined tests
Diffstat (limited to 'src/rps/test_rps.c')
-rw-r--r--src/rps/test_rps.c213
1 files changed, 189 insertions, 24 deletions
diff --git a/src/rps/test_rps.c b/src/rps/test_rps.c
index dd50893c6..06df22583 100644
--- a/src/rps/test_rps.c
+++ b/src/rps/test_rps.c
@@ -25,6 +25,7 @@
25 * for one message from each peer. 25 * for one message from each peer.
26 */ 26 */
27#include "platform.h" 27#include "platform.h"
28#include "gnunet_util_lib.h"
28#include "gnunet_testbed_service.h" 29#include "gnunet_testbed_service.h"
29#include "gnunet_rps_service.h" 30#include "gnunet_rps_service.h"
30 31
@@ -39,7 +40,25 @@
39/** 40/**
40 * How long do we run the test? 41 * How long do we run the test?
41 */ 42 */
42#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) 43#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 40)
44
45
46/**
47 * Different tests to run
48 */
49#define SINGLE_REQUEST 1
50#define DELAYED_REQUESTS 2
51#define SEED 3
52#define SEED_BIG 4
53#define SINGLE_PEER_SEED 5
54#define SEED_REQUEST 6
55#define REQUEST_CANCEL 7
56//TODO start big mal
57
58/**
59 * What test are we running?
60 */
61unsigned int test_type = 0;
43 62
44 63
45/** 64/**
@@ -77,6 +96,21 @@ struct RPSPeer
77 * ID of the peer. 96 * ID of the peer.
78 */ 97 */
79 struct GNUNET_PeerIdentity *peer_id; 98 struct GNUNET_PeerIdentity *peer_id;
99
100 /**
101 * A request handle to check for an request
102 */
103 struct GNUNET_RPS_Request_Handle *req_handle;
104
105 /**
106 * Received PeerIDs
107 */
108 struct GNUNET_PeerIdentity *rec_ids;
109
110 /**
111 * Number of received PeerIDs
112 */
113 unsigned int num_rec_ids;
80}; 114};
81 115
82 116
@@ -97,6 +131,34 @@ static int ok;
97 131
98 132
99/** 133/**
134 * Test the success of a single test
135 */
136static int
137evaluate (struct RPSPeer *loc_rps_peers,
138 unsigned int num_loc_rps_peers,
139 unsigned int expected_recv)
140{
141 unsigned int i;
142 int tmp_ok;
143
144 tmp_ok = (1 == loc_rps_peers[0].num_rec_ids);
145
146 for (i = 0 ; i < num_loc_rps_peers ; i++)
147 {
148 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
149 "%u. peer [%s] received %u of %u expected peer_ids: %i\n",
150 i,
151 GNUNET_i2s (loc_rps_peers[i].peer_id),
152 loc_rps_peers[i].num_rec_ids,
153 expected_recv,
154 (1 == loc_rps_peers[i].num_rec_ids));
155 tmp_ok &= (1 == loc_rps_peers[i].num_rec_ids);
156 }
157 return tmp_ok? 0 : 1;
158}
159
160
161/**
100 * Task run on timeout to shut everything down. 162 * Task run on timeout to shut everything down.
101 */ 163 */
102static void 164static void
@@ -121,11 +183,25 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
121 * 183 *
122 */ 184 */
123static void 185static void
124handle_reply (void *cls, uint64_t n, const struct GNUNET_PeerIdentity *peers) 186handle_reply (void *cls, uint64_t n, const struct GNUNET_PeerIdentity *recv_peers)
125{ 187{
126 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got peer %s\n", GNUNET_i2s (peers)); 188 struct RPSPeer *rps_peer = (struct RPSPeer *) cls;
189 unsigned int i;
190
191 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
192 "[%s] got %" PRIu64 " peers:\n",
193 GNUNET_i2s (rps_peer->peer_id),
194 n);
127 195
128 ok = 0; 196 for (i = 0 ; i < n ; i++)
197 {
198 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
199 "%u: %s\n",
200 i,
201 GNUNET_i2s (&recv_peers[i]));
202
203 GNUNET_array_append (rps_peer->rec_ids, rps_peer->num_rec_ids, recv_peers[i]);
204 }
129} 205}
130 206
131 207
@@ -136,11 +212,13 @@ handle_reply (void *cls, uint64_t n, const struct GNUNET_PeerIdentity *peers)
136request_peers (void *cls, 212request_peers (void *cls,
137 const struct GNUNET_SCHEDULER_TaskContext *tc) 213 const struct GNUNET_SCHEDULER_TaskContext *tc)
138{ 214{
139 struct RPSPeer *peer = (struct RPSPeer *) cls; 215 struct RPSPeer *rps_peer = (struct RPSPeer *) cls;
140 struct GNUNET_RPS_Request_Handle *req_handle;
141 216
142 req_handle = GNUNET_RPS_request_peers (peer->rps_handle, 1, handle_reply, NULL); 217 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
143 GNUNET_free (req_handle); 218 "Requesting one peer\n");
219
220 (void) GNUNET_RPS_request_peers (rps_peer->rps_handle, 1, handle_reply, rps_peer);
221 //rps_peer->req_handle = GNUNET_RPS_request_peers (rps_peer->rps_handle, 1, handle_reply, rps_peer);
144} 222}
145 223
146 224
@@ -154,10 +232,8 @@ seed_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
154 struct RPSPeer *peer = (struct RPSPeer *) cls; 232 struct RPSPeer *peer = (struct RPSPeer *) cls;
155 unsigned int i; 233 unsigned int i;
156 234
157 GNUNET_assert (1 >= portion 235 // TODO if malicious don't seed mal peers
158 && 0 < portion); 236 amount = round (.5 * NUM_PEERS);
159
160 amount = round (portion * NUM_PEERS);
161 237
162 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Seeding peers:\n"); 238 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Seeding peers:\n");
163 for (i = 0 ; i < amount ; i++) 239 for (i = 0 ; i < amount ; i++)
@@ -190,6 +266,8 @@ info_cb (void *cb_cls,
190 266
191 rps_peer_ids[i] = *(pinfo->result.id); 267 rps_peer_ids[i] = *(pinfo->result.id);
192 rps_peers[i].peer_id = &rps_peer_ids[i]; 268 rps_peers[i].peer_id = &rps_peer_ids[i];
269 rps_peers[i].rec_ids = NULL;
270 rps_peers[i].num_rec_ids = 0;
193 271
194} 272}
195 273
@@ -211,7 +289,7 @@ rps_connect_complete_cb (void *cls,
211{ 289{
212 struct RPSPeer *rps_peer = cls; 290 struct RPSPeer *rps_peer = cls;
213 struct GNUNET_RPS_Handle *rps = ca_result; 291 struct GNUNET_RPS_Handle *rps = ca_result;
214 struct GNUNET_RPS_Request_Handle *req_handle; 292 //struct GNUNET_RPS_Request_Handle *req_handle;
215 uint32_t num_mal_peers; 293 uint32_t num_mal_peers;
216 294
217 rps_peer->rps_handle = rps; 295 rps_peer->rps_handle = rps;
@@ -240,20 +318,49 @@ rps_connect_complete_cb (void *cls,
240 if (rps_peer->index >= num_mal_peers) 318 if (rps_peer->index >= num_mal_peers)
241 { /* It's useless to ask a malicious peer about a random sample - 319 { /* It's useless to ask a malicious peer about a random sample -
242 it's not sampling */ 320 it's not sampling */
243 req_handle = GNUNET_RPS_request_peers (rps, 1, handle_reply, NULL); 321 (void) GNUNET_RPS_request_peers (rps, 1, handle_reply, NULL);
244 GNUNET_free (req_handle);
245 } 322 }
246 return; 323 return;
247 } 324 }
248 #endif /* ENABLE_MALICIOUS */ 325 #endif /* ENABLE_MALICIOUS */
249 326
250 req_handle = GNUNET_RPS_request_peers (rps, 1, handle_reply, NULL); 327 if (SINGLE_REQUEST == test_type)
251 GNUNET_free (req_handle); 328 {
329 //(void) GNUNET_RPS_request_peers (rps, 1, handle_reply, NULL);
330 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5),
331 request_peers, rps_peer);
332 }
333 else if (DELAYED_REQUESTS == test_type)
334 {
335 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5),
336 request_peers, rps_peer);
252 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10), 337 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10),
253 request_peers, rps_peer); 338 request_peers, rps_peer);
339 }
340 else if (SEED == test_type)
341 {
254 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10), 342 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10),
255 seed_peers, rps_peer); 343 seed_peers, rps_peer);
344 }
345 else if (SEED_BIG == test_type)
346 {
256 // TODO test seeding > GNUNET_SERVER_MAX_MESSAGE_SIZE peers 347 // TODO test seeding > GNUNET_SERVER_MAX_MESSAGE_SIZE peers
348 }
349 else if (SINGLE_PEER_SEED == test_type)
350 {
351 // TODO
352 }
353 else if (SEED_REQUEST == test_type)
354 {
355 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2),
356 seed_peers, rps_peer);
357 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15),
358 request_peers, rps_peer);
359 }
360 else if (REQUEST_CANCEL == test_type)
361 {
362 // TODO
363 }
257} 364}
258 365
259 366
@@ -350,6 +457,9 @@ run (void *cls,
350 tmp_i); 457 tmp_i);
351 } 458 }
352 459
460 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
461 "Type %i\n",
462 test_type);
353 463
354 GNUNET_assert (NUM_PEERS == num_peers); 464 GNUNET_assert (NUM_PEERS == num_peers);
355 for (i = 0 ; i < num_peers ; i++) 465 for (i = 0 ; i < num_peers ; i++)
@@ -381,18 +491,48 @@ main (int argc, char *argv[])
381{ 491{
382 if (strstr (argv[0], "malicious_1") != NULL) 492 if (strstr (argv[0], "malicious_1") != NULL)
383 { 493 {
384 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Malicious type 1\n"); 494 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test malicious peer type 1\n");
385 mal_type = 1; 495 mal_type = 1;
386 } 496 }
387 else if (strstr (argv[0], "malicious_2") != NULL) 497 else if (strstr (argv[0], "malicious_2") != NULL)
388 { 498 {
389 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Malicious type 2\n"); 499 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test malicious peer type 2\n");
390 mal_type = 2; 500 mal_type = 2;
501 }
502 else if (strstr (argv[0], "_single_req") != NULL)
503 {
504 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Test single request\n");
505 test_type = SINGLE_REQUEST;
506 }
507 else if (strstr (argv[0], "_delayed_reqs") != NULL)
508 {
509 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test delayed requests\n");
510 test_type = DELAYED_REQUESTS;
511 }
512 else if (strstr (argv[0], "_seed_big") != NULL)
513 {
514 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test seeding (num_peers > GNUNET_SERVER_MAX_MESSAGE_SIZE)\n");
515 test_type = SEED_BIG;
516 }
517 else if (strstr (argv[0], "_single_peer_seed") != NULL)
518 {
519 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test seeding and requesting on a single peer\n");
520 test_type = SINGLE_PEER_SEED;
521 }
522 else if (strstr (argv[0], "_seed_request") != NULL)
523 {
524 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test seeding and requesting on multiple peers\n");
525 test_type = SEED_REQUEST;
526 }
527 else if (strstr (argv[0], "_seed") != NULL)
528 {
529 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test seeding\n");
530 test_type = SEED;
391 } 531 }
392 else 532 else if (strstr (argv[0], "_req_cancel") != NULL)
393 { 533 {
394 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Type unknown using type 0 - no malicious behaviour\n"); 534 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test cancelling a request\n");
395 mal_type = 0; 535 test_type = REQUEST_CANCEL;
396 } 536 }
397 537
398 ok = 1; 538 ok = 1;
@@ -401,6 +541,31 @@ main (int argc, char *argv[])
401 NUM_PEERS, 541 NUM_PEERS,
402 0, NULL, NULL, 542 0, NULL, NULL,
403 &run, NULL); 543 &run, NULL);
544
545 unsigned int num_mal_peers;
546 if (1 == mal_type)
547 {
548 num_mal_peers = NUM_PEERS * portion;
549 ok = evaluate (&rps_peers[num_mal_peers],
550 NUM_PEERS - (num_mal_peers),
551 1);
552 }
553 else if (2 == mal_type)
554 {
555 num_mal_peers = NUM_PEERS * portion;
556 ok = evaluate (&rps_peers[num_mal_peers],
557 NUM_PEERS - (num_mal_peers),
558 1);
559 }
560 else if (SINGLE_REQUEST == test_type)
561 {
562 ok = evaluate (rps_peers, NUM_PEERS, 1);
563 }
564 else if (SEED_REQUEST == test_type)
565 {
566 ok = evaluate (rps_peers, NUM_PEERS, 1);
567 }
568
404 return ok; 569 return ok;
405} 570}
406 571