From 591481d3f75d691858f2dc07c7f3ea3374f5d60d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Julius=20B=C3=BCnger?= Date: Thu, 26 Mar 2015 22:04:21 +0000 Subject: [PATCH] -unified testing --- src/rps/Makefile.am | 6 +- src/rps/gnunet-service-rps.c | 18 ++- src/rps/{test_rps_multipeer.c => test_rps.c} | 149 +++++++++++++++---- 3 files changed, 130 insertions(+), 43 deletions(-) rename src/rps/{test_rps_multipeer.c => test_rps.c} (69%) 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) endif test_rps_multipeer_SOURCES = \ - test_rps_multipeer.c + test_rps.c test_rps_multipeer_LDADD = $(ld_rps_test_lib) test_rps_malicious_1_SOURCES = \ - test_rps_malicious.c + test_rps.c test_rps_malicious_1_LDADD = $(ld_rps_test_lib) test_rps_malicious_2_SOURCES = \ - test_rps_malicious.c + test_rps.c test_rps_malicious_2_LDADD = $(ld_rps_test_lib) EXTRA_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, void client_respond (void *cls, struct GNUNET_PeerIdentity *ids, uint32_t num_peers) { - LOG (GNUNET_ERROR_TYPE_DEBUG, "sampler returned %" PRIX32 " peers\n", num_peers); + LOG (GNUNET_ERROR_TYPE_DEBUG, "sampler returned %" PRIu32 " peers\n", num_peers); struct GNUNET_MQ_Envelope *ev; struct GNUNET_RPS_CS_ReplyMessage *out_msg; struct GNUNET_SERVER_Client *client; @@ -1236,7 +1236,7 @@ handle_client_request (void *cls, for (i = 0 ; i < num_peers ; i++) est_request_rate(); - LOG (GNUNET_ERROR_TYPE_DEBUG, "Client requested %" PRIX32 " random peer(s).\n", num_peers); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Client requested %" PRIu32 " random peer(s).\n", num_peers); RPS_sampler_get_n_rand_peers (client_sampler, client_respond, client, num_peers, GNUNET_YES); @@ -1293,7 +1293,7 @@ handle_client_seed (void *cls, for (i = 0 ; i < num_peers ; i++) { LOG (GNUNET_ERROR_TYPE_DEBUG, - "Updating samplers with seed %" PRIX32 ": %s\n", + "Updating samplers with seed %" PRIu32 ": %s\n", i, GNUNET_i2s (&peers[i])); @@ -1479,11 +1479,12 @@ handle_peer_pull_reply (void *cls, return GNUNET_OK; } -#ifdef ENABLE_MALICIOUS + + #ifdef ENABLE_MALICIOUS // We shouldn't even receive pull replies as we're not sending if (2 == mal_type) return GNUNET_OK; -#endif /* ENABLE_MALICIOUS */ + #endif /* ENABLE_MALICIOUS */ /* Do actual logic */ peers = (struct GNUNET_PeerIdentity *) &msg[1]; @@ -1497,7 +1498,9 @@ handle_peer_pull_reply (void *cls, if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (att_peer_set, &peers[i]) && GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (mal_peer_set, - &peers[i])) + &peers[i]) + && GNUNET_NO == GNUNET_CRYPTO_cmp_peer_identity (&peers[i], + &own_identity)) { tmp_att_peer = GNUNET_new (struct AttackedPeer); tmp_att_peer->peer_id = peers[i]; @@ -1736,7 +1739,8 @@ handle_client_act_malicious (void *cls, else if (0 == mal_type) { /* Stop acting malicious */ num_mal_peers = 0; - GNUNET_free (mal_peers); + if (NULL != mal_peers) + GNUNET_free (mal_peers); /* Substitute do_mal_round () with do_round () */ GNUNET_SCHEDULER_cancel (do_round_task); diff --git a/src/rps/test_rps_multipeer.c b/src/rps/test_rps.c similarity index 69% rename from src/rps/test_rps_multipeer.c rename to 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 @@ #include "platform.h" #include "gnunet_testbed_service.h" #include "gnunet_rps_service.h" -#include + +#include /** @@ -46,12 +47,22 @@ */ static double portion = .1; +/** + * Type of malicious peer to test + */ +static unsigned int mal_type = 0; + /** * Information we track for each peer. */ struct RPSPeer { + /** + * Index of the peer. + */ + unsigned int index; + /** * Handle for RPS connect operation. */ @@ -61,6 +72,11 @@ struct RPSPeer * Handle to RPS service. */ struct GNUNET_RPS_Handle *rps_handle; + + /** + * ID of the peer. + */ + struct GNUNET_PeerIdentity *peer_id; }; @@ -162,7 +178,7 @@ info_cb (void *cb_cls, const struct GNUNET_TESTBED_PeerInformation *pinfo, const char *emsg) { - unsigned int *i = (unsigned int *) cb_cls; + unsigned int i = *((unsigned int *) cb_cls); if (NULL == pinfo || NULL != emsg) { @@ -170,9 +186,11 @@ info_cb (void *cb_cls, return; } - rps_peer_ids[*i] = *(pinfo->result.id); - GNUNET_free (cb_cls); + + rps_peer_ids[i] = *(pinfo->result.id); + rps_peers[i].peer_id = &rps_peer_ids[i]; + } @@ -191,31 +209,50 @@ rps_connect_complete_cb (void *cls, void *ca_result, const char *emsg) { - struct RPSPeer *peer = cls; + struct RPSPeer *rps_peer = cls; struct GNUNET_RPS_Handle *rps = ca_result; struct GNUNET_RPS_Request_Handle *req_handle; + uint32_t num_mal_peers; - peer->rps_handle = rps; + rps_peer->rps_handle = rps; - GNUNET_assert (op == peer->op); + GNUNET_assert (op == rps_peer->op); if (NULL != emsg) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Failed to connect to RPS service: %s\n", - emsg); - ok = 1; - GNUNET_SCHEDULER_shutdown (); - return; - } + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Failed to connect to RPS service: %s\n", + emsg); + ok = 1; + GNUNET_SCHEDULER_shutdown (); + return; + } + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started client successfully\n"); + #ifdef ENABLE_MALICIOUS + if (1 == mal_type + || 1 == mal_type) + { + GNUNET_assert (1 >= portion + && 0 < portion); + num_mal_peers = round (portion * NUM_PEERS); + + if (rps_peer->index >= num_mal_peers) + { /* It's useless to ask a malicious peer about a random sample - + it's not sampling */ + req_handle = GNUNET_RPS_request_peers (rps, 1, handle_reply, NULL); + GNUNET_free (req_handle); + } + return; + } + #endif /* ENABLE_MALICIOUS */ + req_handle = GNUNET_RPS_request_peers (rps, 1, handle_reply, NULL); GNUNET_free (req_handle); - GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10), - request_peers, peer); + request_peers, rps_peer); GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10), - seed_peers, peer); + seed_peers, rps_peer); // TODO test seeding > GNUNET_SERVER_MAX_MESSAGE_SIZE peers } @@ -232,9 +269,34 @@ rps_connect_complete_cb (void *cls, */ static void * rps_connect_adapter (void *cls, - const struct GNUNET_CONFIGURATION_Handle *cfg) + const struct GNUNET_CONFIGURATION_Handle *cfg) { - return GNUNET_RPS_connect (cfg); + struct GNUNET_RPS_Handle *h; + #ifdef ENABLE_MALICIOUS + uint32_t num_mal_peers; + struct RPSPeer *rps_peer = (struct RPSPeer *) cls; + #endif /* ENABLE_MALICIOUS */ + + h = GNUNET_RPS_connect (cfg); + + #ifdef ENABLE_MALICIOUS + GNUNET_assert (1 >= portion + && 0 < portion); + num_mal_peers = round (portion * NUM_PEERS); + + if (rps_peer->index < num_mal_peers) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "%u. peer [%s] of %" PRIu32 " malicious peers turning malicious\n", + rps_peer->index, + GNUNET_i2s (rps_peer->peer_id), + num_mal_peers); + + GNUNET_RPS_act_malicious (h, mal_type, num_mal_peers, rps_peer_ids); + } + #endif /* ENABLE_MALICIOUS */ + + return h; } @@ -247,7 +309,7 @@ rps_connect_adapter (void *cls, */ static void rps_disconnect_adapter (void *cls, - void *op_result) + void *op_result) { struct GNUNET_RPS_Handle *h = op_result; GNUNET_RPS_disconnect (h); @@ -277,27 +339,32 @@ run (void *cls, unsigned int i; unsigned int *tmp_i; - for ( i = 0 ; i < NUM_PEERS ; i++ ) + for (i = 0 ; i < NUM_PEERS ; i++) { tmp_i = GNUNET_new (unsigned int); *tmp_i = i; (void) GNUNET_TESTBED_peer_get_information (peers[i], GNUNET_TESTBED_PIT_IDENTITY, - &info_cb, tmp_i); + &info_cb, + tmp_i); } + GNUNET_assert (NUM_PEERS == num_peers); - for (i=0;i