summaryrefslogtreecommitdiff
path: root/src/rps
diff options
context:
space:
mode:
Diffstat (limited to 'src/rps')
-rw-r--r--src/rps/gnunet-rps-profiler.c212
-rw-r--r--src/rps/gnunet-service-rps.c117
-rw-r--r--src/rps/rps-sampler_client.c69
-rw-r--r--src/rps/rps-test_util.c6
-rw-r--r--src/rps/rps-test_util.h5
-rw-r--r--src/rps/test_service_rps_custommap.c2
6 files changed, 182 insertions, 229 deletions
diff --git a/src/rps/gnunet-rps-profiler.c b/src/rps/gnunet-rps-profiler.c
index 392a3c18f..0ec2fec71 100644
--- a/src/rps/gnunet-rps-profiler.c
+++ b/src/rps/gnunet-rps-profiler.c
@@ -59,10 +59,10 @@ static struct GNUNET_TIME_Relative duration;
static struct GNUNET_TIME_Relative timeout;
-/**
- * Portion of malicious peers
- */
-static double portion = .1;
+// /**
+// * Portion of malicious peers
+// */
+// static double portion = .1;
/**
* Type of malicious peer to test
@@ -1229,29 +1229,6 @@ post_test_op (void *cls)
/**
- * Seed peers.
- */
-static void
-seed_peers (void *cls)
-{
- struct RPSPeer *peer = cls;
- unsigned int amount;
- unsigned int i;
-
- // TODO if malicious don't seed mal peers
- amount = round (.5 * num_peers);
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Seeding peers:\n");
- for (i = 0; i < amount; i++)
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Seeding %u. peer: %s\n",
- i,
- GNUNET_i2s (&rps_peer_ids[i]));
-
- GNUNET_RPS_seed_ids (peer->rps_handle, amount, rps_peer_ids);
-}
-
-
-/**
* Get the id of peer i.
*/
void
@@ -1635,76 +1612,76 @@ cancel_pending_req_rep (struct RPSPeer *rps_peer)
* MALICIOUS
***********************************/
-/**
- * Initialise only non-mal RPSPeers
- */
-static void
-mal_init_peer (struct RPSPeer *rps_peer)
-{
- if (rps_peer->index >= round (portion * num_peers))
- rps_peer->num_ids_to_request = 1;
-}
-
-
-/**
- * @brief Set peers to (non-)malicious before execution
- *
- * Of signature #PreTest
- *
- * @param rps_peer the peer to set (non-) malicious
- * @param h the handle to the service
- */
-static void
-mal_pre (struct RPSPeer *rps_peer, struct GNUNET_RPS_Handle *h)
-{
- #if ENABLE_MALICIOUS
- uint32_t num_mal_peers;
-
- 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, target_peer);
- }
- #endif /* ENABLE_MALICIOUS */
-}
-
-
-static void
-mal_cb (struct RPSPeer *rps_peer)
-{
- if ((GNUNET_YES == in_shutdown) || (GNUNET_YES == post_test))
- {
- return;
- }
-
- #if ENABLE_MALICIOUS
- uint32_t num_mal_peers;
-
- 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 */
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (
- GNUNET_TIME_UNIT_SECONDS, 2),
- seed_peers, rps_peer);
- schedule_missing_requests (rps_peer);
- }
- #endif /* ENABLE_MALICIOUS */
-}
+///**
+// * Initialise only non-mal RPSPeers
+// */
+//static void
+//mal_init_peer (struct RPSPeer *rps_peer)
+//{
+// if (rps_peer->index >= round (portion * num_peers))
+// rps_peer->num_ids_to_request = 1;
+//}
+
+
+///**
+// * @brief Set peers to (non-)malicious before execution
+// *
+// * Of signature #PreTest
+// *
+// * @param rps_peer the peer to set (non-) malicious
+// * @param h the handle to the service
+// */
+//static void
+//mal_pre (struct RPSPeer *rps_peer, struct GNUNET_RPS_Handle *h)
+//{
+// #if ENABLE_MALICIOUS
+// uint32_t num_mal_peers;
+//
+// 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, target_peer);
+// }
+// #endif /* ENABLE_MALICIOUS */
+//}
+
+
+// static void
+// mal_cb (struct RPSPeer *rps_peer)
+// {
+// if ((GNUNET_YES == in_shutdown) || (GNUNET_YES == post_test))
+// {
+// return;
+// }
+//
+// #if ENABLE_MALICIOUS
+// uint32_t num_mal_peers;
+//
+// 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 */
+// GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (
+// GNUNET_TIME_UNIT_SECONDS, 2),
+// seed_peers, rps_peer);
+// schedule_missing_requests (rps_peer);
+// }
+// #endif /* ENABLE_MALICIOUS */
+// }
/***********************************
@@ -1714,44 +1691,6 @@ mal_cb (struct RPSPeer *rps_peer)
static void
churn (void *cls);
-/**
- * @brief Starts churn
- *
- * Has signature of #MainTest
- *
- * This is not implemented too nicely as this is called for each peer, but we
- * only need to call it once. (Yes we check that we only schedule the task
- * once.)
- *
- * @param rps_peer The peer it's called for
- */
-static void
-churn_test_cb (struct RPSPeer *rps_peer)
-{
- if ((GNUNET_YES == in_shutdown) || (GNUNET_YES == post_test))
- {
- return;
- }
-
- /* Start churn */
- if ((HAVE_CHURN == cur_test_run.have_churn) && (NULL == churn_task))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Starting churn task\n");
- churn_task = GNUNET_SCHEDULER_add_delayed (
- GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5),
- churn,
- NULL);
- }
- else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Not starting churn task\n");
- }
-
- schedule_missing_requests (rps_peer);
-}
-
/***********************************
* PROFILER
@@ -2652,10 +2591,11 @@ pre_profiler (struct RPSPeer *rps_peer, struct GNUNET_RPS_Handle *h)
store_prefix_file_name (rps_peer->index, "probs");
rps_peer->file_name_probs_hist =
store_prefix_file_name (rps_peer->index, "probs_hist");
+ rps_peer->eval_probs_cache = GNUNET_new_array (num_peers, double);
+ memset (rps_peer->eval_probs_cache, 0, num_peers * sizeof (double));
GNUNET_RPS_view_request (h, 0, view_update_cb, rps_peer);
}
-
void
write_final_stats (void)
{
diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c
index ecbc8e208..dc4c5dab7 100644
--- a/src/rps/gnunet-service-rps.c
+++ b/src/rps/gnunet-service-rps.c
@@ -596,8 +596,10 @@ static const uint32_t num_valid_peers_max = UINT32_MAX;
static void
do_round (void *cls);
+#if ENABLE_MALICIOUS
static void
do_mal_round (void *cls);
+#endif /* ENABLE_MALICIOUS */
/**
@@ -2464,6 +2466,7 @@ resize_wrapper (struct RPS_Sampler *sampler, uint32_t new_size)
}
+#if ENABLE_MALICIOUS
/**
* Add all peers in @a peer_array to @a peer_map used as set.
*
@@ -2500,6 +2503,7 @@ add_peer_array_to_set (const struct GNUNET_PeerIdentity *peer_array,
}
}
}
+#endif /* ENABLE_MALICIOUS */
/**
@@ -2948,12 +2952,16 @@ new_sub (const struct GNUNET_HashCode *hash,
/* Logging of internals */
#ifdef TO_FILE_FULL
- sub->file_name_view_log = store_prefix_file_name (&own_identity, "view");
+ // FIXME: The service cannot know the index, which is required by this
+ // function:
+ // sub->file_name_view_log = store_prefix_file_name (&own_identity, "view");
#endif /* TO_FILE_FULL */
#ifdef TO_FILE
#ifdef TO_FILE_FULL
- sub->file_name_observed_log = store_prefix_file_name (&own_identity,
- "observed");
+ // FIXME: The service cannot know the index, which is required by this
+ // function:
+ // sub->file_name_observed_log = store_prefix_file_name (&own_identity,
+ // "observed");
#endif /* TO_FILE_FULL */
sub->num_observed_peers = 0;
sub->observed_unique_peers = GNUNET_CONTAINER_multipeermap_create (1,
@@ -2981,46 +2989,50 @@ new_sub (const struct GNUNET_HashCode *hash,
#ifdef TO_FILE
-/**
- * @brief Write all numbers in the given array into the given file
- *
- * Single numbers devided by a newline
- *
- * @param hist_array[] the array to dump
- * @param file_name file to dump into
- */
-static void
-write_histogram_to_file (const uint32_t hist_array[],
- const char *file_name)
-{
- char collect_str[SIZE_DUMP_FILE + 1] = "";
- char *recv_str_iter;
- char *file_name_full;
-
- recv_str_iter = collect_str;
- file_name_full = store_prefix_file_name (&own_identity,
- file_name);
- for (uint32_t i = 0; i < HISTOGRAM_FILE_SLOTS; i++)
- {
- char collect_str_tmp[8];
-
- GNUNET_snprintf (collect_str_tmp,
- sizeof(collect_str_tmp),
- "%" PRIu32 "\n",
- hist_array[i]);
- recv_str_iter = stpncpy (recv_str_iter,
- collect_str_tmp,
- 6);
- }
- (void) stpcpy (recv_str_iter,
- "\n");
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Writing push stats to disk\n");
- to_file_w_len (file_name_full,
- SIZE_DUMP_FILE, "%s",
- collect_str);
- GNUNET_free (file_name_full);
-}
+// /**
+// * @brief Write all numbers in the given array into the given file
+// *
+// * Single numbers devided by a newline
+// *
+// * FIXME: The call to store_prefix_file_name expects the index of the peer,
+// * which cannot be known to the service.
+// * Write a dedicated function that uses the peer id.
+// *
+// * @param hist_array[] the array to dump
+// * @param file_name file to dump into
+// */
+// static void
+// write_histogram_to_file (const uint32_t hist_array[],
+// const char *file_name)
+// {
+// char collect_str[SIZE_DUMP_FILE + 1] = "";
+// char *recv_str_iter;
+// char *file_name_full;
+//
+// recv_str_iter = collect_str;
+// file_name_full = store_prefix_file_name (&own_identity,
+// file_name);
+// for (uint32_t i = 0; i < HISTOGRAM_FILE_SLOTS; i++)
+// {
+// char collect_str_tmp[8];
+//
+// GNUNET_snprintf (collect_str_tmp,
+// sizeof(collect_str_tmp),
+// "%" PRIu32 "\n",
+// hist_array[i]);
+// recv_str_iter = stpncpy (recv_str_iter,
+// collect_str_tmp,
+// 6);
+// }
+// (void) stpcpy (recv_str_iter,
+// "\n");
+// LOG (GNUNET_ERROR_TYPE_DEBUG,
+// "Writing push stats to disk\n");
+// to_file_w_len (file_name_full,
+// SIZE_DUMP_FILE, "%s",
+// collect_str);
+// GNUNET_free (file_name_full);
+// }
#endif /* TO_FILE */
@@ -3065,17 +3077,18 @@ destroy_sub (struct Sub *sub)
sub->file_name_observed_log = NULL;
#endif /* TO_FILE_FULL */
- /* Write push frequencies to disk */
- write_histogram_to_file (sub->push_recv,
- "push_recv");
+ // FIXME: Currently this calls malfunctionning code
+ // /* Write push frequencies to disk */
+ // write_histogram_to_file (sub->push_recv,
+ // "push_recv");
- /* Write push deltas to disk */
- write_histogram_to_file (sub->push_delta,
- "push_delta");
+ // /* Write push deltas to disk */
+ // write_histogram_to_file (sub->push_delta,
+ // "push_delta");
- /* Write pull delays to disk */
- write_histogram_to_file (sub->pull_delays,
- "pull_delays");
+ // /* Write pull delays to disk */
+ // write_histogram_to_file (sub->pull_delays,
+ // "pull_delays");
GNUNET_CONTAINER_multipeermap_destroy (sub->observed_unique_peers);
sub->observed_unique_peers = NULL;
diff --git a/src/rps/rps-sampler_client.c b/src/rps/rps-sampler_client.c
index 5ab854e01..f6e98ce29 100644
--- a/src/rps/rps-sampler_client.c
+++ b/src/rps/rps-sampler_client.c
@@ -258,39 +258,39 @@ RPS_sampler_mod_init (size_t init_size,
}
-/**
- * @brief Compute the probability that we already observed all peers from a
- * biased stream of peer ids.
- *
- * Deficiency factor:
- * As introduced by Brahms: Factor between the number of unique ids in a
- * truly random stream and number of unique ids in the gossip stream.
- *
- * @param num_peers_estim The estimated number of peers in the network
- * @param num_peers_observed The number of peers the given element has observed
- * @param deficiency_factor A factor that catches the 'bias' of a random stream
- * of peer ids
- *
- * @return The estimated probability
- */
-static double
-prob_observed_n_peers (uint32_t num_peers_estim,
- uint32_t num_peers_observed,
- double deficiency_factor)
-{
- uint32_t num_peers = num_peers_estim * (1 / deficiency_factor);
- uint64_t sum = 0;
-
- for (uint32_t i = 0; i < num_peers; i++)
- {
- uint64_t a = pow (-1, num_peers - i);
- uint64_t b = binom (num_peers, i);
- uint64_t c = pow (i, num_peers_observed);
- sum += a * b * c;
- }
-
- return sum / (double) pow (num_peers, num_peers_observed);
-}
+// /**
+// * @brief Compute the probability that we already observed all peers from a
+// * biased stream of peer ids.
+// *
+// * Deficiency factor:
+// * As introduced by Brahms: Factor between the number of unique ids in a
+// * truly random stream and number of unique ids in the gossip stream.
+// *
+// * @param num_peers_estim The estimated number of peers in the network
+// * @param num_peers_observed The number of peers the given element has observed
+// * @param deficiency_factor A factor that catches the 'bias' of a random stream
+// * of peer ids
+// *
+// * @return The estimated probability
+// */
+// static double
+// prob_observed_n_peers (uint32_t num_peers_estim,
+// uint32_t num_peers_observed,
+// double deficiency_factor)
+// {
+// uint32_t num_peers = num_peers_estim * (1 / deficiency_factor);
+// uint64_t sum = 0;
+//
+// for (uint32_t i = 0; i < num_peers; i++)
+// {
+// uint64_t a = pow (-1, num_peers - i);
+// uint64_t b = binom (num_peers, i);
+// uint64_t c = pow (i, num_peers_observed);
+// sum += a * b * c;
+// }
+//
+// return sum / (double) pow (num_peers, num_peers_observed);
+// }
/**
@@ -379,7 +379,8 @@ sampler_mod_get_rand_peer (void *cls)
return;
}
/* compute probability */
- /* Currently disabled due to numerical limitations */
+ /* FIXME: Currently disabled due to numerical limitations */
+ prob_observed_n = 0; // Inititialise to some value
// prob_observed_n = prob_observed_n_peers (sampler->num_peers_estim,
// s_elem->num_peers,
// sampler->deficiency_factor);
diff --git a/src/rps/rps-test_util.c b/src/rps/rps-test_util.c
index d2cdd3aa7..b73be3457 100644
--- a/src/rps/rps-test_util.c
+++ b/src/rps/rps-test_util.c
@@ -186,7 +186,7 @@ to_file_raw (const char *file_name, const char *buf, size_t size_buf)
if (size_buf != size_written)
{
LOG (GNUNET_ERROR_TYPE_WARNING,
- "Unable to write to file! (Size: %u, size_written: %u)\n",
+ "Unable to write to file! (Size: %zu, size_written: %zu)\n",
size_buf,
size_written);
@@ -197,7 +197,7 @@ to_file_raw (const char *file_name, const char *buf, size_t size_buf)
return;
}
LOG (GNUNET_ERROR_TYPE_WARNING,
- "Wrote %u bytes raw.\n",
+ "Wrote %zu bytes raw.\n",
size_written);
if (GNUNET_YES != GNUNET_DISK_file_close (f))
LOG (GNUNET_ERROR_TYPE_WARNING,
@@ -238,7 +238,7 @@ to_file_raw_unaligned (const char *file_name,
"num_bits_buf_unaligned: %u\n",
num_bits_buf_unaligned);
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "ua args: size_buf: %u, bits_needed: %u -> iter: %u\n",
+ "ua args: size_buf: %zu, bits_needed: %u -> iter: %u\n",
size_buf,
bits_needed,
bytes_iter);
diff --git a/src/rps/rps-test_util.h b/src/rps/rps-test_util.h
index 2f11f0105..72aa78803 100644
--- a/src/rps/rps-test_util.h
+++ b/src/rps/rps-test_util.h
@@ -73,7 +73,7 @@ close_all_files ();
"Failed to create tmp_buf\n"); \
break; \
} \
- (void) strncat (tmp_buf, "\n", 512); \
+ (void) strncat (tmp_buf, "\n", 511); \
GNUNET_DISK_file_write (get_file_handle (file_name), \
tmp_buf, \
strnlen (tmp_buf, 512)); \
@@ -94,8 +94,7 @@ close_all_files ();
"Failed to create tmp_buf\n"); \
break; \
} \
- (void) strncat (tmp_buf, "\n", \
- len); \
+ (void) strncat (tmp_buf, "\n", 2); \
GNUNET_DISK_file_write ( \
get_file_handle (file_name), \
tmp_buf, \
diff --git a/src/rps/test_service_rps_custommap.c b/src/rps/test_service_rps_custommap.c
index 05590b097..3d885ca6b 100644
--- a/src/rps/test_service_rps_custommap.c
+++ b/src/rps/test_service_rps_custommap.c
@@ -35,7 +35,7 @@ check ()
struct CustomPeerMap *c_m;
struct GNUNET_PeerIdentity k1;
struct GNUNET_PeerIdentity k2;
- int j;
+ unsigned int j;
CHECK (NULL != (c_m = CustomPeerMap_create (4)));
memset (&k1, 0, sizeof(k1));