[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r35450 - gnunet/src/rps
From: |
gnunet |
Subject: |
[GNUnet-SVN] r35450 - gnunet/src/rps |
Date: |
Wed, 25 Mar 2015 18:17:13 +0100 |
Author: ch3
Date: 2015-03-25 18:17:13 +0100 (Wed, 25 Mar 2015)
New Revision: 35450
Modified:
gnunet/src/rps/test_rps_malicious_1.c
Log:
-only turn portion of peers malicious
Modified: gnunet/src/rps/test_rps_malicious_1.c
===================================================================
--- gnunet/src/rps/test_rps_malicious_1.c 2015-03-25 17:17:09 UTC (rev
35449)
+++ gnunet/src/rps/test_rps_malicious_1.c 2015-03-25 17:17:13 UTC (rev
35450)
@@ -27,13 +27,14 @@
#include "platform.h"
#include "gnunet_testbed_service.h"
#include "gnunet_rps_service.h"
-#include <time.h>
+#include <inttypes.h>
+
/**
* How many peers do we start?
*/
-#define NUM_PEERS 5
+#define NUM_PEERS 10
/**
* How long do we run the test?
@@ -53,6 +54,11 @@
struct RPSPeer
{
/**
+ * Index of the peer.
+ */
+ unsigned int index;
+
+ /**
* Handle for RPS connect operation.
*/
struct GNUNET_TESTBED_Operation *op;
@@ -61,6 +67,11 @@
* Handle to RPS service.
*/
struct GNUNET_RPS_Handle *rps_handle;
+
+ /**
+ * ID of the peer.
+ */
+ struct GNUNET_PeerIdentity *peer_id;
};
@@ -162,7 +173,7 @@
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 @@
return;
}
- rps_peer_ids[*i] = *(pinfo->result.id);
+ GNUNET_free (cb_cls);
- GNUNET_free (cb_cls);
+ rps_peer_ids[i] = *(pinfo->result.id);
+ rps_peers[i].peer_id = &rps_peer_ids[i];
+
}
@@ -191,31 +204,45 @@
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,20 +262,30 @@
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 @@
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 @@
(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 @@
&rps_connect_adapter,
&rps_disconnect_adapter,
&rps_peers[i]);
+ }
GNUNET_SCHEDULER_add_delayed (TIMEOUT, &shutdown_task, NULL);
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r35450 - gnunet/src/rps,
gnunet <=