aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJulius Bünger <buenger@mytum.de>2015-03-26 22:04:21 +0000
committerJulius Bünger <buenger@mytum.de>2015-03-26 22:04:21 +0000
commit591481d3f75d691858f2dc07c7f3ea3374f5d60d (patch)
treeda0567e08117cb4c80dcce74f406a0b859bc50a2 /src
parent569c29270cb9fdc4c236795ecef2d895a3ecbd76 (diff)
downloadgnunet-591481d3f75d691858f2dc07c7f3ea3374f5d60d.tar.gz
gnunet-591481d3f75d691858f2dc07c7f3ea3374f5d60d.zip
-unified testing
Diffstat (limited to 'src')
-rw-r--r--src/rps/Makefile.am6
-rw-r--r--src/rps/gnunet-service-rps.c18
-rw-r--r--src/rps/test_rps.c (renamed from src/rps/test_rps_multipeer.c)149
3 files changed, 130 insertions, 43 deletions
diff --git a/src/rps/Makefile.am b/src/rps/Makefile.am
index b1e62eb12..ad2a739fb 100644
--- a/src/rps/Makefile.am
+++ b/src/rps/Makefile.am
@@ -76,15 +76,15 @@ TESTS = $(check_PROGRAMS)
76endif 76endif
77 77
78test_rps_multipeer_SOURCES = \ 78test_rps_multipeer_SOURCES = \
79 test_rps_multipeer.c 79 test_rps.c
80test_rps_multipeer_LDADD = $(ld_rps_test_lib) 80test_rps_multipeer_LDADD = $(ld_rps_test_lib)
81 81
82test_rps_malicious_1_SOURCES = \ 82test_rps_malicious_1_SOURCES = \
83 test_rps_malicious.c 83 test_rps.c
84test_rps_malicious_1_LDADD = $(ld_rps_test_lib) 84test_rps_malicious_1_LDADD = $(ld_rps_test_lib)
85 85
86test_rps_malicious_2_SOURCES = \ 86test_rps_malicious_2_SOURCES = \
87 test_rps_malicious.c 87 test_rps.c
88test_rps_malicious_2_LDADD = $(ld_rps_test_lib) 88test_rps_malicious_2_LDADD = $(ld_rps_test_lib)
89 89
90EXTRA_DIST = \ 90EXTRA_DIST = \
diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c
index 08d647781..b3151a567 100644
--- a/src/rps/gnunet-service-rps.c
+++ b/src/rps/gnunet-service-rps.c
@@ -1169,7 +1169,7 @@ nse_callback (void *cls, struct GNUNET_TIME_Absolute timestamp,
1169void client_respond (void *cls, 1169void client_respond (void *cls,
1170 struct GNUNET_PeerIdentity *ids, uint32_t num_peers) 1170 struct GNUNET_PeerIdentity *ids, uint32_t num_peers)
1171{ 1171{
1172 LOG (GNUNET_ERROR_TYPE_DEBUG, "sampler returned %" PRIX32 " peers\n", num_peers); 1172 LOG (GNUNET_ERROR_TYPE_DEBUG, "sampler returned %" PRIu32 " peers\n", num_peers);
1173 struct GNUNET_MQ_Envelope *ev; 1173 struct GNUNET_MQ_Envelope *ev;
1174 struct GNUNET_RPS_CS_ReplyMessage *out_msg; 1174 struct GNUNET_RPS_CS_ReplyMessage *out_msg;
1175 struct GNUNET_SERVER_Client *client; 1175 struct GNUNET_SERVER_Client *client;
@@ -1236,7 +1236,7 @@ handle_client_request (void *cls,
1236 for (i = 0 ; i < num_peers ; i++) 1236 for (i = 0 ; i < num_peers ; i++)
1237 est_request_rate(); 1237 est_request_rate();
1238 1238
1239 LOG (GNUNET_ERROR_TYPE_DEBUG, "Client requested %" PRIX32 " random peer(s).\n", num_peers); 1239 LOG (GNUNET_ERROR_TYPE_DEBUG, "Client requested %" PRIu32 " random peer(s).\n", num_peers);
1240 1240
1241 RPS_sampler_get_n_rand_peers (client_sampler, client_respond, 1241 RPS_sampler_get_n_rand_peers (client_sampler, client_respond,
1242 client, num_peers, GNUNET_YES); 1242 client, num_peers, GNUNET_YES);
@@ -1293,7 +1293,7 @@ handle_client_seed (void *cls,
1293 for (i = 0 ; i < num_peers ; i++) 1293 for (i = 0 ; i < num_peers ; i++)
1294 { 1294 {
1295 LOG (GNUNET_ERROR_TYPE_DEBUG, 1295 LOG (GNUNET_ERROR_TYPE_DEBUG,
1296 "Updating samplers with seed %" PRIX32 ": %s\n", 1296 "Updating samplers with seed %" PRIu32 ": %s\n",
1297 i, 1297 i,
1298 GNUNET_i2s (&peers[i])); 1298 GNUNET_i2s (&peers[i]));
1299 1299
@@ -1479,11 +1479,12 @@ handle_peer_pull_reply (void *cls,
1479 return GNUNET_OK; 1479 return GNUNET_OK;
1480 } 1480 }
1481 1481
1482#ifdef ENABLE_MALICIOUS 1482
1483 #ifdef ENABLE_MALICIOUS
1483 // We shouldn't even receive pull replies as we're not sending 1484 // We shouldn't even receive pull replies as we're not sending
1484 if (2 == mal_type) 1485 if (2 == mal_type)
1485 return GNUNET_OK; 1486 return GNUNET_OK;
1486#endif /* ENABLE_MALICIOUS */ 1487 #endif /* ENABLE_MALICIOUS */
1487 1488
1488 /* Do actual logic */ 1489 /* Do actual logic */
1489 peers = (struct GNUNET_PeerIdentity *) &msg[1]; 1490 peers = (struct GNUNET_PeerIdentity *) &msg[1];
@@ -1497,7 +1498,9 @@ handle_peer_pull_reply (void *cls,
1497 if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (att_peer_set, 1498 if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (att_peer_set,
1498 &peers[i]) 1499 &peers[i])
1499 && GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (mal_peer_set, 1500 && GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (mal_peer_set,
1500 &peers[i])) 1501 &peers[i])
1502 && GNUNET_NO == GNUNET_CRYPTO_cmp_peer_identity (&peers[i],
1503 &own_identity))
1501 { 1504 {
1502 tmp_att_peer = GNUNET_new (struct AttackedPeer); 1505 tmp_att_peer = GNUNET_new (struct AttackedPeer);
1503 tmp_att_peer->peer_id = peers[i]; 1506 tmp_att_peer->peer_id = peers[i];
@@ -1736,7 +1739,8 @@ handle_client_act_malicious (void *cls,
1736 else if (0 == mal_type) 1739 else if (0 == mal_type)
1737 { /* Stop acting malicious */ 1740 { /* Stop acting malicious */
1738 num_mal_peers = 0; 1741 num_mal_peers = 0;
1739 GNUNET_free (mal_peers); 1742 if (NULL != mal_peers)
1743 GNUNET_free (mal_peers);
1740 1744
1741 /* Substitute do_mal_round () with do_round () */ 1745 /* Substitute do_mal_round () with do_round () */
1742 GNUNET_SCHEDULER_cancel (do_round_task); 1746 GNUNET_SCHEDULER_cancel (do_round_task);
diff --git a/src/rps/test_rps_multipeer.c b/src/rps/test_rps.c
index 94f709595..dd50893c6 100644
--- a/src/rps/test_rps_multipeer.c
+++ b/src/rps/test_rps.c
@@ -27,7 +27,8 @@
27#include "platform.h" 27#include "platform.h"
28#include "gnunet_testbed_service.h" 28#include "gnunet_testbed_service.h"
29#include "gnunet_rps_service.h" 29#include "gnunet_rps_service.h"
30#include <time.h> 30
31#include <inttypes.h>
31 32
32 33
33/** 34/**
@@ -46,6 +47,11 @@
46 */ 47 */
47static double portion = .1; 48static double portion = .1;
48 49
50/**
51 * Type of malicious peer to test
52 */
53static unsigned int mal_type = 0;
54
49 55
50/** 56/**
51 * Information we track for each peer. 57 * Information we track for each peer.
@@ -53,6 +59,11 @@ static double portion = .1;
53struct RPSPeer 59struct RPSPeer
54{ 60{
55 /** 61 /**
62 * Index of the peer.
63 */
64 unsigned int index;
65
66 /**
56 * Handle for RPS connect operation. 67 * Handle for RPS connect operation.
57 */ 68 */
58 struct GNUNET_TESTBED_Operation *op; 69 struct GNUNET_TESTBED_Operation *op;
@@ -61,6 +72,11 @@ struct RPSPeer
61 * Handle to RPS service. 72 * Handle to RPS service.
62 */ 73 */
63 struct GNUNET_RPS_Handle *rps_handle; 74 struct GNUNET_RPS_Handle *rps_handle;
75
76 /**
77 * ID of the peer.
78 */
79 struct GNUNET_PeerIdentity *peer_id;
64}; 80};
65 81
66 82
@@ -162,7 +178,7 @@ info_cb (void *cb_cls,
162 const struct GNUNET_TESTBED_PeerInformation *pinfo, 178 const struct GNUNET_TESTBED_PeerInformation *pinfo,
163 const char *emsg) 179 const char *emsg)
164{ 180{
165 unsigned int *i = (unsigned int *) cb_cls; 181 unsigned int i = *((unsigned int *) cb_cls);
166 182
167 if (NULL == pinfo || NULL != emsg) 183 if (NULL == pinfo || NULL != emsg)
168 { 184 {
@@ -170,9 +186,11 @@ info_cb (void *cb_cls,
170 return; 186 return;
171 } 187 }
172 188
173 rps_peer_ids[*i] = *(pinfo->result.id);
174
175 GNUNET_free (cb_cls); 189 GNUNET_free (cb_cls);
190
191 rps_peer_ids[i] = *(pinfo->result.id);
192 rps_peers[i].peer_id = &rps_peer_ids[i];
193
176} 194}
177 195
178 196
@@ -191,31 +209,50 @@ rps_connect_complete_cb (void *cls,
191 void *ca_result, 209 void *ca_result,
192 const char *emsg) 210 const char *emsg)
193{ 211{
194 struct RPSPeer *peer = cls; 212 struct RPSPeer *rps_peer = cls;
195 struct GNUNET_RPS_Handle *rps = ca_result; 213 struct GNUNET_RPS_Handle *rps = ca_result;
196 struct GNUNET_RPS_Request_Handle *req_handle; 214 struct GNUNET_RPS_Request_Handle *req_handle;
215 uint32_t num_mal_peers;
197 216
198 peer->rps_handle = rps; 217 rps_peer->rps_handle = rps;
199 218
200 GNUNET_assert (op == peer->op); 219 GNUNET_assert (op == rps_peer->op);
201 if (NULL != emsg) 220 if (NULL != emsg)
202 { 221 {
203 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 222 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
204 "Failed to connect to RPS service: %s\n", 223 "Failed to connect to RPS service: %s\n",
205 emsg); 224 emsg);
206 ok = 1; 225 ok = 1;
207 GNUNET_SCHEDULER_shutdown (); 226 GNUNET_SCHEDULER_shutdown ();
208 return; 227 return;
209 } 228 }
229
210 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started client successfully\n"); 230 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started client successfully\n");
211 231
232 #ifdef ENABLE_MALICIOUS
233 if (1 == mal_type
234 || 1 == mal_type)
235 {
236 GNUNET_assert (1 >= portion
237 && 0 < portion);
238 num_mal_peers = round (portion * NUM_PEERS);
239
240 if (rps_peer->index >= num_mal_peers)
241 { /* It's useless to ask a malicious peer about a random sample -
242 it's not sampling */
243 req_handle = GNUNET_RPS_request_peers (rps, 1, handle_reply, NULL);
244 GNUNET_free (req_handle);
245 }
246 return;
247 }
248 #endif /* ENABLE_MALICIOUS */
249
212 req_handle = GNUNET_RPS_request_peers (rps, 1, handle_reply, NULL); 250 req_handle = GNUNET_RPS_request_peers (rps, 1, handle_reply, NULL);
213 GNUNET_free (req_handle); 251 GNUNET_free (req_handle);
214
215 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10), 252 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10),
216 request_peers, peer); 253 request_peers, rps_peer);
217 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10), 254 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10),
218 seed_peers, peer); 255 seed_peers, rps_peer);
219 // TODO test seeding > GNUNET_SERVER_MAX_MESSAGE_SIZE peers 256 // TODO test seeding > GNUNET_SERVER_MAX_MESSAGE_SIZE peers
220} 257}
221 258
@@ -232,9 +269,34 @@ rps_connect_complete_cb (void *cls,
232 */ 269 */
233static void * 270static void *
234rps_connect_adapter (void *cls, 271rps_connect_adapter (void *cls,
235 const struct GNUNET_CONFIGURATION_Handle *cfg) 272 const struct GNUNET_CONFIGURATION_Handle *cfg)
236{ 273{
237 return GNUNET_RPS_connect (cfg); 274 struct GNUNET_RPS_Handle *h;
275 #ifdef ENABLE_MALICIOUS
276 uint32_t num_mal_peers;
277 struct RPSPeer *rps_peer = (struct RPSPeer *) cls;
278 #endif /* ENABLE_MALICIOUS */
279
280 h = GNUNET_RPS_connect (cfg);
281
282 #ifdef ENABLE_MALICIOUS
283 GNUNET_assert (1 >= portion
284 && 0 < portion);
285 num_mal_peers = round (portion * NUM_PEERS);
286
287 if (rps_peer->index < num_mal_peers)
288 {
289 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
290 "%u. peer [%s] of %" PRIu32 " malicious peers turning malicious\n",
291 rps_peer->index,
292 GNUNET_i2s (rps_peer->peer_id),
293 num_mal_peers);
294
295 GNUNET_RPS_act_malicious (h, mal_type, num_mal_peers, rps_peer_ids);
296 }
297 #endif /* ENABLE_MALICIOUS */
298
299 return h;
238} 300}
239 301
240 302
@@ -247,7 +309,7 @@ rps_connect_adapter (void *cls,
247 */ 309 */
248static void 310static void
249rps_disconnect_adapter (void *cls, 311rps_disconnect_adapter (void *cls,
250 void *op_result) 312 void *op_result)
251{ 313{
252 struct GNUNET_RPS_Handle *h = op_result; 314 struct GNUNET_RPS_Handle *h = op_result;
253 GNUNET_RPS_disconnect (h); 315 GNUNET_RPS_disconnect (h);
@@ -277,27 +339,32 @@ run (void *cls,
277 unsigned int i; 339 unsigned int i;
278 unsigned int *tmp_i; 340 unsigned int *tmp_i;
279 341
280 for ( i = 0 ; i < NUM_PEERS ; i++ ) 342 for (i = 0 ; i < NUM_PEERS ; i++)
281 { 343 {
282 tmp_i = GNUNET_new (unsigned int); 344 tmp_i = GNUNET_new (unsigned int);
283 *tmp_i = i; 345 *tmp_i = i;
284 346
285 (void) GNUNET_TESTBED_peer_get_information (peers[i], 347 (void) GNUNET_TESTBED_peer_get_information (peers[i],
286 GNUNET_TESTBED_PIT_IDENTITY, 348 GNUNET_TESTBED_PIT_IDENTITY,
287 &info_cb, tmp_i); 349 &info_cb,
350 tmp_i);
288 } 351 }
289 352
353
290 GNUNET_assert (NUM_PEERS == num_peers); 354 GNUNET_assert (NUM_PEERS == num_peers);
291 for (i=0;i<num_peers;i++) 355 for (i = 0 ; i < num_peers ; i++)
292 //rps_peers[i].peer_index = i; 356 {
293 rps_peers[i].op = GNUNET_TESTBED_service_connect (&rps_peers[i], 357 rps_peers[i].index = i;
294 peers[i], 358 rps_peers[i].op =
295 "rps", 359 GNUNET_TESTBED_service_connect (&rps_peers[i],
296 &rps_connect_complete_cb, 360 peers[i],
297 &rps_peers[i], 361 "rps",
298 &rps_connect_adapter, 362 &rps_connect_complete_cb,
299 &rps_disconnect_adapter, 363 &rps_peers[i],
300 &rps_peers[i]); 364 &rps_connect_adapter,
365 &rps_disconnect_adapter,
366 &rps_peers[i]);
367 }
301 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &shutdown_task, NULL); 368 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &shutdown_task, NULL);
302} 369}
303 370
@@ -312,6 +379,22 @@ run (void *cls,
312int 379int
313main (int argc, char *argv[]) 380main (int argc, char *argv[])
314{ 381{
382 if (strstr (argv[0], "malicious_1") != NULL)
383 {
384 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Malicious type 1\n");
385 mal_type = 1;
386 }
387 else if (strstr (argv[0], "malicious_2") != NULL)
388 {
389 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Malicious type 2\n");
390 mal_type = 2;
391 }
392 else
393 {
394 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Type unknown using type 0 - no malicious behaviour\n");
395 mal_type = 0;
396 }
397
315 ok = 1; 398 ok = 1;
316 (void) GNUNET_TESTBED_test_run ("test-rps-multipeer", 399 (void) GNUNET_TESTBED_test_run ("test-rps-multipeer",
317 "test_rps.conf", 400 "test_rps.conf",