$(top_builddir)/src/testbed/libgnunettestbed.la \
-lm
+rps_test_src = \
+ test_rps.c \
+ rps-test_util.h rps-test_util.c \
+ gnunet-service-rps_sampler_elem.h gnunet-service-rps_sampler_elem.c
if ENABLE_TEST_RUN
AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;
TESTS = $(check_PROGRAMS)
endif
-test_rps_malicious_1_SOURCES = \
- test_rps.c
+test_rps_malicious_1_SOURCES = $(rps_test_src)
test_rps_malicious_1_LDADD = $(ld_rps_test_lib)
-test_rps_malicious_2_SOURCES = \
- test_rps.c
+test_rps_malicious_2_SOURCES = $(rps_test_src)
test_rps_malicious_2_LDADD = $(ld_rps_test_lib)
-test_rps_malicious_3_SOURCES = \
- test_rps.c
+test_rps_malicious_3_SOURCES = $(rps_test_src)
test_rps_malicious_3_LDADD = $(ld_rps_test_lib)
-test_rps_single_req_SOURCES = \
- test_rps.c
+test_rps_single_req_SOURCES = $(rps_test_src)
test_rps_single_req_LDADD = $(ld_rps_test_lib)
-test_rps_seed_request_SOURCES = \
- test_rps.c
+test_rps_seed_request_SOURCES = $(rps_test_src)
test_rps_seed_request_LDADD = $(ld_rps_test_lib)
-gnunet_rps_profiler_SOURCES = \
- test_rps.c
+gnunet_rps_profiler_SOURCES = $(rps_test_src)
gnunet_rps_profiler_LDADD = $(ld_rps_test_lib)
EXTRA_DIST = \
GNUNET_i2s_full (&s_elem->peer_id));
}
+/**
+ * Initialise the min-wise independent function of the given sampler element.
+ *
+ * @param s_elem the sampler element
+ * @param auth_key the key to use
+ */
+void
+RPS_sampler_elem_set (struct RPS_SamplerElement *s_elem,
+ struct GNUNET_CRYPTO_AuthKey auth_key)
+{
+ s_elem->auth_key = auth_key;
+
+ #ifdef TO_FILE
+ /* Create a file(-name) to store internals to */
+ char *name_buf;
+ name_buf = auth_key_to_string (s_elem->auth_key);
+
+ s_elem->file_name = create_file (name_buf);
+ GNUNET_free (name_buf);
+ #endif /* TO_FILE */
+}
+
/* end of gnunet-service-rps.c */
RPS_sampler_elem_next (struct RPS_SamplerElement *s_elem,
const struct GNUNET_PeerIdentity *new_ID);
+/**
+ * Initialise the min-wise independent function of the given sampler element.
+ *
+ * @param s_elem the sampler element
+ * @param auth_key the key to use
+ */
+void
+RPS_sampler_elem_set (struct RPS_SamplerElement *s_elem,
+ struct GNUNET_CRYPTO_AuthKey auth_key);
+
#endif /* RPS_SAMPLER_ELEM_H */
/* end of gnunet-service-rps.c */
*end = '\0';
}
- size = GNUNET_snprintf (name_buf, name_buf_size, "sampler_el-%s-", buf);
+ size = GNUNET_snprintf (name_buf, name_buf_size, "sampler_el-%s", buf);
if (0 > size)
LOG (GNUNET_ERROR_TYPE_WARNING, "Failed to create name_buf\n");
return name_buf;
}
+
+struct GNUNET_CRYPTO_AuthKey
+string_to_auth_key (const char *str)
+{
+ struct GNUNET_CRYPTO_AuthKey auth_key;
+
+ if (GNUNET_OK !=
+ GNUNET_STRINGS_string_to_data (str,
+ strlen (str),
+ &auth_key.key,
+ sizeof (struct GNUNET_CRYPTO_AuthKey)))
+ {
+ LOG (GNUNET_ERROR_TYPE_WARNING, "Failed to convert string to data\n");
+ }
+
+ return auth_key;
+}
+
+
char *
create_file (const char *name)
{
name_buf_size = (strlen (prefix) + strlen (name) + 2) * sizeof (char);
name_buf = GNUNET_malloc (name_buf_size);
- size = GNUNET_snprintf (name_buf, name_buf_size, "%s%s-", prefix, name);
+ size = GNUNET_snprintf (name_buf, name_buf_size, "%s%s", prefix, name);
if (0 > size)
LOG (GNUNET_ERROR_TYPE_WARNING, "Failed to create name_buf\n");
prefix);
}
- if (NULL == (file_name = GNUNET_DISK_mktemp (name_buf)))
- LOG (GNUNET_ERROR_TYPE_WARNING, "Could not create file\n");
+ if (NULL == strstr (name, "sampler_el"))
+ {/* only append random string to sampler */
+ if (NULL == (file_name = GNUNET_DISK_mktemp (name_buf)))
+ LOG (GNUNET_ERROR_TYPE_WARNING, "Could not create file\n");
GNUNET_free (name_buf);
-
return file_name;
+ }
+
+ return name_buf;
}
#endif /* TO_FILE */
char *
auth_key_to_string (struct GNUNET_CRYPTO_AuthKey auth_key);
+struct GNUNET_CRYPTO_AuthKey
+string_to_auth_key (const char *str);
+
char *
create_file (const char *name);
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_testbed_service.h"
+
#include "gnunet_rps_service.h"
+#include "rps-test_util.h"
+#include "gnunet-service-rps_sampler_elem.h"
#include <inttypes.h>
* Append arguments to file
*/
static void
-to_file_ (char *file_name, char *line)
+tofile_ (const char *file_name, char *line)
{
struct GNUNET_DISK_FileHandle *f;
/* char output_buffer[512]; */
/**
* This function is used to facilitate writing important information to disk
*/
-#define to_file(file_name, ...) do {\
+#define tofile(file_name, ...) do {\
char tmp_buf[512];\
int size;\
size = GNUNET_snprintf(tmp_buf,sizeof(tmp_buf),__VA_ARGS__);\
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,\
"Failed to create tmp_buf\n");\
else\
- to_file_(file_name,tmp_buf);\
+ tofile_(file_name,tmp_buf);\
} while (0);
/**
/**
- * Callback to be called when NSE service is started or stopped at peers
+ * Callback to be called when RPS service is started or stopped at peers
*
* @param cls NULL
* @param op the operation handle
rps_peers[entry->index].rec_ids = NULL;
rps_peers[entry->index].num_rec_ids = 0;
- to_file ("/tmp/rps/peer_ids",
+ tofile ("/tmp/rps/peer_ids",
"%u\t%s\n",
entry->index,
GNUNET_i2s_full (&rps_peer_ids[entry->index]));
GNUNET_i2s (&recv_peers[i]));
/* GNUNET_array_append (rps_peer->rec_ids, rps_peer->num_rec_ids, recv_peers[i]); */
- to_file (file_name,
+ tofile (file_name,
"%s\n",
GNUNET_i2s_full (&recv_peers[i]));
}
}
}
+/**
+ * Function called from #profiler_eval with a filename.
+ *
+ * @param cls closure
+ * @param filename complete filename (absolute path)
+ * @return #GNUNET_OK to continue to iterate,
+ * #GNUNET_NO to stop iteration with no error,
+ * #GNUNET_SYSERR to abort iteration with error!
+ */
+int
+file_name_cb (void *cls, const char *filename)
+{
+ if (NULL != strstr (filename, "sampler_el"))
+ {
+ struct RPS_SamplerElement *s_elem;
+ struct GNUNET_CRYPTO_AuthKey auth_key;
+ const char *key_char;
+ uint32_t i;
+
+ key_char = filename + 20; /* Length of "/tmp/rps/sampler_el-" */
+ tofile (filename, "--------------------------\n");
+
+ auth_key = string_to_auth_key (key_char);
+ s_elem = RPS_sampler_elem_create ();
+ RPS_sampler_elem_set (s_elem, auth_key);
+
+ for (i = 0; i < num_peers; i++)
+ {
+ RPS_sampler_elem_next (s_elem, &rps_peer_ids[i]);
+ }
+ }
+ return GNUNET_OK;
+}
+
+/**
+ * This is run after the test finished.
+ *
+ * Compute all perfect samples.
+ */
+int
+profiler_eval (void)
+{
+ /* Compute perfect sample for each sampler element */
+ if (-1 == GNUNET_DISK_directory_scan ("/tmp/rps/", file_name_cb, NULL))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Scan of directory failed\n");
+ }
+
+ return 0;
+}
+
/***********************************************************************
* /Definition of tests
cur_test_run.pre_test = profiler_pre;
cur_test_run.main_test = profiler_cb;
cur_test_run.reply_handle = profiler_reply_handle;
- cur_test_run.eval_cb = no_eval;
+ cur_test_run.eval_cb = profiler_eval;
cur_test_run.request_interval = 2;
cur_test_run.num_requests = 50;