[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r36120 - gnunet/src/rps
From: |
gnunet |
Subject: |
[GNUnet-SVN] r36120 - gnunet/src/rps |
Date: |
Thu, 23 Jul 2015 20:21:49 +0200 |
Author: ch3
Date: 2015-07-23 20:21:49 +0200 (Thu, 23 Jul 2015)
New Revision: 36120
Modified:
gnunet/src/rps/Makefile.am
gnunet/src/rps/gnunet-service-rps_sampler_elem.c
gnunet/src/rps/gnunet-service-rps_sampler_elem.h
gnunet/src/rps/rps-test_util.c
gnunet/src/rps/rps-test_util.h
gnunet/src/rps/test_rps.c
Log:
get perfect sample of each sampler element
Modified: gnunet/src/rps/Makefile.am
===================================================================
--- gnunet/src/rps/Makefile.am 2015-07-23 18:21:45 UTC (rev 36119)
+++ gnunet/src/rps/Makefile.am 2015-07-23 18:21:49 UTC (rev 36120)
@@ -81,6 +81,10 @@
$(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:address@hidden@};export
PATH=$${GNUNET_PREFIX:address@hidden@}/bin:$$PATH;
@@ -87,28 +91,22 @@
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 = \
Modified: gnunet/src/rps/gnunet-service-rps_sampler_elem.c
===================================================================
--- gnunet/src/rps/gnunet-service-rps_sampler_elem.c 2015-07-23 18:21:45 UTC
(rev 36119)
+++ gnunet/src/rps/gnunet-service-rps_sampler_elem.c 2015-07-23 18:21:49 UTC
(rev 36120)
@@ -166,4 +166,26 @@
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 */
Modified: gnunet/src/rps/gnunet-service-rps_sampler_elem.h
===================================================================
--- gnunet/src/rps/gnunet-service-rps_sampler_elem.h 2015-07-23 18:21:45 UTC
(rev 36119)
+++ gnunet/src/rps/gnunet-service-rps_sampler_elem.h 2015-07-23 18:21:49 UTC
(rev 36120)
@@ -129,6 +129,16 @@
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 */
Modified: gnunet/src/rps/rps-test_util.c
===================================================================
--- gnunet/src/rps/rps-test_util.c 2015-07-23 18:21:45 UTC (rev 36119)
+++ gnunet/src/rps/rps-test_util.c 2015-07-23 18:21:49 UTC (rev 36120)
@@ -128,7 +128,7 @@
*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");
@@ -137,6 +137,25 @@
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)
{
@@ -150,7 +169,7 @@
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");
@@ -161,12 +180,16 @@
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 file_name;
+ return name_buf;
}
#endif /* TO_FILE */
Modified: gnunet/src/rps/rps-test_util.h
===================================================================
--- gnunet/src/rps/rps-test_util.h 2015-07-23 18:21:45 UTC (rev 36119)
+++ gnunet/src/rps/rps-test_util.h 2015-07-23 18:21:49 UTC (rev 36120)
@@ -39,6 +39,9 @@
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);
Modified: gnunet/src/rps/test_rps.c
===================================================================
--- gnunet/src/rps/test_rps.c 2015-07-23 18:21:45 UTC (rev 36119)
+++ gnunet/src/rps/test_rps.c 2015-07-23 18:21:49 UTC (rev 36120)
@@ -27,7 +27,10 @@
#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>
@@ -257,7 +260,7 @@
* 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]; */
@@ -312,7 +315,7 @@
/**
* 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__);\
@@ -320,7 +323,7 @@
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);
/**
@@ -386,7 +389,7 @@
/**
- * 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
@@ -521,7 +524,7 @@
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]));
@@ -972,7 +975,7 @@
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]));
}
@@ -1010,7 +1013,58 @@
}
}
+/**
+ * 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
***********************************************************************/
@@ -1187,7 +1241,7 @@
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;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r36120 - gnunet/src/rps,
gnunet <=