From 4ef920e458c83feb09f599c6fa8b1b3d8505cee8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Julius=20B=C3=BCnger?= Date: Wed, 25 Mar 2015 17:17:13 +0000 Subject: [PATCH] -only turn portion of peers malicious --- src/rps/test_rps_malicious_1.c | 99 ++++++++++++++++++++++++---------- 1 file changed, 71 insertions(+), 28 deletions(-) diff --git a/src/rps/test_rps_malicious_1.c b/src/rps/test_rps_malicious_1.c index a30607d87..50ae2ac86 100644 --- a/src/rps/test_rps_malicious_1.c +++ b/src/rps/test_rps_malicious_1.c @@ -27,13 +27,14 @@ #include "platform.h" #include "gnunet_testbed_service.h" #include "gnunet_rps_service.h" -#include + +#include /** * How many peers do we start? */ -#define NUM_PEERS 5 +#define NUM_PEERS 10 /** * How long do we run the test? @@ -52,6 +53,11 @@ static double portion = .1; */ struct RPSPeer { + /** + * Index of the peer. + */ + unsigned int index; + /** * Handle for RPS connect operation. */ @@ -61,6 +67,11 @@ struct RPSPeer * Handle to RPS service. */ struct GNUNET_RPS_Handle *rps_handle; + + /** + * ID of the peer. + */ + struct GNUNET_PeerIdentity *peer_id; }; @@ -162,7 +173,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 +181,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 +204,45 @@ 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 + GNUNET_assert (1 >= portion + && 0 < portion); + num_mal_peers = round (portion * NUM_PEERS); + + if (rps_peer->index >= num_mal_peers) + { + req_handle = GNUNET_RPS_request_peers (rps, 1, handle_reply, NULL); + GNUNET_free (req_handle); + } + #else /* ENABLE_MALICIOUS */ req_handle = GNUNET_RPS_request_peers (rps, 1, handle_reply, NULL); GNUNET_free (req_handle); + #endif /* ENABLE_MALICIOUS */ - GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10), - request_peers, peer); - GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10), - seed_peers, peer); + //GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10), + // request_peers, peer); + //GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10), + // seed_peers, peer); // TODO test seeding > GNUNET_SERVER_MAX_MESSAGE_SIZE peers } @@ -235,19 +262,29 @@ rps_connect_adapter (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) { struct GNUNET_RPS_Handle *h; - #if ENABLE_MALICIOUS - uint64_t num_mal_peers; + #ifdef ENABLE_MALICIOUS + uint32_t num_mal_peers; + struct RPSPeer *rps_peer = (struct RPSPeer *) cls; #endif /* ENABLE_MALICIOUS */ h = GNUNET_RPS_connect (cfg); - #if ENABLE_MALICIOUS + #ifdef ENABLE_MALICIOUS GNUNET_assert (1 >= portion && 0 < portion); - num_mal_peers = round (portion * NUM_PEERS); - GNUNET_RPS_act_malicious (h, htonl (1), num_mal_peers, rps_peer_ids); - #endif /* ENABLE_MALICIOUS */ + + 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, 1, num_mal_peers, rps_peer_ids); + #endif /* ENABLE_MALICIOUS */ + } return h; } @@ -292,6 +329,8 @@ run (void *cls, unsigned int i; unsigned int *tmp_i; + tmp_i = GNUNET_new (unsigned int); + for (i = 0 ; i < NUM_PEERS ; i++) { tmp_i = GNUNET_new (unsigned int); @@ -299,12 +338,15 @@ run (void *cls, (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 < num_peers ; i++) - //rps_peers[i].peer_index = i; + { + rps_peers[i].index = i; rps_peers[i].op = GNUNET_TESTBED_service_connect (&rps_peers[i], peers[i], @@ -314,6 +356,7 @@ run (void *cls, &rps_connect_adapter, &rps_disconnect_adapter, &rps_peers[i]); + } GNUNET_SCHEDULER_add_delayed (TIMEOUT, &shutdown_task, NULL); } -- 2.25.1