#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?
*/
struct RPSPeer
{
+ /**
+ * Index of the peer.
+ */
+ unsigned int index;
+
/**
* Handle for RPS connect operation.
*/
* Handle to RPS service.
*/
struct GNUNET_RPS_Handle *rps_handle;
+
+ /**
+ * ID of the peer.
+ */
+ struct GNUNET_PeerIdentity *peer_id;
};
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)
{
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];
+
}
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
}
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;
}
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);
(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],
&rps_connect_adapter,
&rps_disconnect_adapter,
&rps_peers[i]);
+ }
GNUNET_SCHEDULER_add_delayed (TIMEOUT, &shutdown_task, NULL);
}