X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Frps%2Ftest_rps.c;h=8c0be24fbcb5757ea0f3c2fbf886baecc641e036;hb=56c021a3748c30b93e4ac3a03b6dc685400960d4;hp=146be4c2c2403466b6e93318bf332de616d5c206;hpb=113ffe7f6ccbbfec1e18cff41004c7b65242a5f9;p=oweals%2Fgnunet.git diff --git a/src/rps/test_rps.c b/src/rps/test_rps.c index 146be4c2c..8c0be24fb 100644 --- a/src/rps/test_rps.c +++ b/src/rps/test_rps.c @@ -501,8 +501,9 @@ shutdown_op (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) if (NULL != churn_task) GNUNET_SCHEDULER_cancel (churn_task); - for (i = 0 ; i < num_peers ; i++) - GNUNET_TESTBED_operation_done (rps_peers[i].op); + for (i = 0; i < num_peers; i++) + if (NULL != rps_peers[i].op) + GNUNET_TESTBED_operation_done (rps_peers[i].op); GNUNET_SCHEDULER_shutdown (); } @@ -529,6 +530,39 @@ seed_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_RPS_seed_ids (peer->rps_handle, amount, rps_peer_ids); } +/** + * Seed peers. + */ + void +seed_peers_big (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) +{ + struct RPSPeer *peer = (struct RPSPeer *) cls; + unsigned int seed_msg_size; + uint32_t num_peers_max; + unsigned int amount; + unsigned int i; + + seed_msg_size = 8; /* sizeof (struct GNUNET_RPS_CS_SeedMessage) */ + num_peers_max = (GNUNET_SERVER_MAX_MESSAGE_SIZE - seed_msg_size) / + sizeof (struct GNUNET_PeerIdentity); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Peers that fit in one seed msg; %u\n", + num_peers_max); + amount = num_peers_max + (0.5 * num_peers_max); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Seeding many (%u) peers:\n", + amount); + struct GNUNET_PeerIdentity ids_to_seed[amount]; + for (i = 0; i < amount; i++) + { + ids_to_seed[i] = *peer->peer_id; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Seeding %u. peer: %s\n", + i, + GNUNET_i2s (&ids_to_seed[i])); + } + + GNUNET_RPS_seed_ids (peer->rps_handle, amount, ids_to_seed); +} /** * Get the id of peer i. @@ -544,6 +578,7 @@ info_cb (void *cb_cls, if (NULL == pinfo || NULL != emsg) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Got Error: %s\n", emsg); + GNUNET_TESTBED_operation_done (entry->op); return; } @@ -554,8 +589,6 @@ info_cb (void *cb_cls, rps_peer_ids[entry->index] = *(pinfo->result.id); rps_peers[entry->index].peer_id = &rps_peer_ids[entry->index]; - rps_peers[entry->index].rec_ids = NULL; - rps_peers[entry->index].num_rec_ids = 0; GNUNET_CONTAINER_multipeermap_put (peer_map, &rps_peer_ids[entry->index], @@ -566,11 +599,8 @@ info_cb (void *cb_cls, entry->index, GNUNET_i2s_full (&rps_peer_ids[entry->index])); - if (NULL != cur_test_run.init_peer) - cur_test_run.init_peer (&rps_peers[entry->index]); - - GNUNET_TESTBED_operation_done (entry->op); GNUNET_CONTAINER_DLL_remove (oplist_head, oplist_tail, entry); + GNUNET_TESTBED_operation_done (entry->op); GNUNET_free (entry); } @@ -938,8 +968,9 @@ delay_req_cb (struct RPSPeer *rps_peer) static void seed_cb (struct RPSPeer *rps_peer) { - GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10), - seed_peers, rps_peer); + GNUNET_SCHEDULER_add_delayed ( + GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10), + seed_peers, rps_peer); } /*********************************** @@ -949,6 +980,9 @@ static void seed_big_cb (struct RPSPeer *rps_peer) { // TODO test seeding > GNUNET_SERVER_MAX_MESSAGE_SIZE peers + GNUNET_SCHEDULER_add_delayed ( + GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2), + seed_peers_big, rps_peer); } /*********************************** @@ -966,8 +1000,9 @@ single_peer_seed_cb (struct RPSPeer *rps_peer) static void seed_req_cb (struct RPSPeer *rps_peer) { - GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2), - seed_peers, rps_peer); + GNUNET_SCHEDULER_add_delayed ( + GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2), + seed_peers, rps_peer); schedule_missing_requests (rps_peer); } @@ -1312,32 +1347,41 @@ run (void *cls, { unsigned int i; struct OpListEntry *entry; + uint32_t num_mal_peers; testbed_peers = peers; num_peers_online = 0; - for (i = 0 ; i < num_peers ; i++) + for (i = 0; i < num_peers; i++) { entry = make_oplist_entry (); entry->index = i; + rps_peers[i].index = i; + if (NULL != cur_test_run.init_peer) + cur_test_run.init_peer (&rps_peers[i]); entry->op = GNUNET_TESTBED_peer_get_information (peers[i], GNUNET_TESTBED_PIT_IDENTITY, &info_cb, entry); } + num_mal_peers = round (portion * num_peers); GNUNET_assert (num_peers == n_peers); - for (i = 0 ; i < n_peers ; i++) + for (i = 0; i < n_peers; i++) { rps_peers[i].index = i; - rps_peers[i].op = - GNUNET_TESTBED_service_connect (&rps_peers[i], - peers[i], - "rps", - &rps_connect_complete_cb, - &rps_peers[i], - &rps_connect_adapter, - &rps_disconnect_adapter, - &rps_peers[i]); + if ( (rps_peers[i].num_recv_ids < rps_peers[i].num_ids_to_request) || + (i < num_mal_peers) ) + { + rps_peers[i].op = + GNUNET_TESTBED_service_connect (&rps_peers[i], + peers[i], + "rps", + &rps_connect_complete_cb, + &rps_peers[i], + &rps_connect_adapter, + &rps_disconnect_adapter, + &rps_peers[i]); + } } if (NULL != churn_task) @@ -1410,8 +1454,11 @@ main (int argc, char *argv[]) else if (strstr (argv[0], "_seed_big") != NULL) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test seeding (num_peers > GNUNET_SERVER_MAX_MESSAGE_SIZE)\n"); + num_peers = 1; cur_test_run.name = "test-rps-seed-big"; cur_test_run.main_test = seed_big_cb; + cur_test_run.eval_cb = no_eval; + timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10); } else if (strstr (argv[0], "_single_peer_seed") != NULL)