diff options
author | Julius Bünger <buenger@mytum.de> | 2015-07-23 18:21:49 +0000 |
---|---|---|
committer | Julius Bünger <buenger@mytum.de> | 2015-07-23 18:21:49 +0000 |
commit | ff073fe2f2c6a0fe0532061533c570acfba60e7d (patch) | |
tree | 43bd8220c5414f04ba20ec8362e1cc2cd15057a4 /src/rps | |
parent | 66fa52570d0d9f29d8b6bf8bd4667c18931b3806 (diff) | |
download | gnunet-ff073fe2f2c6a0fe0532061533c570acfba60e7d.tar.gz gnunet-ff073fe2f2c6a0fe0532061533c570acfba60e7d.zip |
get perfect sample of each sampler element
Diffstat (limited to 'src/rps')
-rw-r--r-- | src/rps/Makefile.am | 22 | ||||
-rw-r--r-- | src/rps/gnunet-service-rps_sampler_elem.c | 22 | ||||
-rw-r--r-- | src/rps/gnunet-service-rps_sampler_elem.h | 10 | ||||
-rw-r--r-- | src/rps/rps-test_util.c | 33 | ||||
-rw-r--r-- | src/rps/rps-test_util.h | 3 | ||||
-rw-r--r-- | src/rps/test_rps.c | 68 |
6 files changed, 134 insertions, 24 deletions
diff --git a/src/rps/Makefile.am b/src/rps/Makefile.am index fc0b9848d..b1ebffee4 100644 --- a/src/rps/Makefile.am +++ b/src/rps/Makefile.am | |||
@@ -81,34 +81,32 @@ ld_rps_test_lib = \ | |||
81 | $(top_builddir)/src/testbed/libgnunettestbed.la \ | 81 | $(top_builddir)/src/testbed/libgnunettestbed.la \ |
82 | -lm | 82 | -lm |
83 | 83 | ||
84 | rps_test_src = \ | ||
85 | test_rps.c \ | ||
86 | rps-test_util.h rps-test_util.c \ | ||
87 | gnunet-service-rps_sampler_elem.h gnunet-service-rps_sampler_elem.c | ||
84 | 88 | ||
85 | if ENABLE_TEST_RUN | 89 | if ENABLE_TEST_RUN |
86 | AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH; | 90 | AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH; |
87 | TESTS = $(check_PROGRAMS) | 91 | TESTS = $(check_PROGRAMS) |
88 | endif | 92 | endif |
89 | 93 | ||
90 | test_rps_malicious_1_SOURCES = \ | 94 | test_rps_malicious_1_SOURCES = $(rps_test_src) |
91 | test_rps.c | ||
92 | test_rps_malicious_1_LDADD = $(ld_rps_test_lib) | 95 | test_rps_malicious_1_LDADD = $(ld_rps_test_lib) |
93 | 96 | ||
94 | test_rps_malicious_2_SOURCES = \ | 97 | test_rps_malicious_2_SOURCES = $(rps_test_src) |
95 | test_rps.c | ||
96 | test_rps_malicious_2_LDADD = $(ld_rps_test_lib) | 98 | test_rps_malicious_2_LDADD = $(ld_rps_test_lib) |
97 | 99 | ||
98 | test_rps_malicious_3_SOURCES = \ | 100 | test_rps_malicious_3_SOURCES = $(rps_test_src) |
99 | test_rps.c | ||
100 | test_rps_malicious_3_LDADD = $(ld_rps_test_lib) | 101 | test_rps_malicious_3_LDADD = $(ld_rps_test_lib) |
101 | 102 | ||
102 | test_rps_single_req_SOURCES = \ | 103 | test_rps_single_req_SOURCES = $(rps_test_src) |
103 | test_rps.c | ||
104 | test_rps_single_req_LDADD = $(ld_rps_test_lib) | 104 | test_rps_single_req_LDADD = $(ld_rps_test_lib) |
105 | 105 | ||
106 | test_rps_seed_request_SOURCES = \ | 106 | test_rps_seed_request_SOURCES = $(rps_test_src) |
107 | test_rps.c | ||
108 | test_rps_seed_request_LDADD = $(ld_rps_test_lib) | 107 | test_rps_seed_request_LDADD = $(ld_rps_test_lib) |
109 | 108 | ||
110 | gnunet_rps_profiler_SOURCES = \ | 109 | gnunet_rps_profiler_SOURCES = $(rps_test_src) |
111 | test_rps.c | ||
112 | gnunet_rps_profiler_LDADD = $(ld_rps_test_lib) | 110 | gnunet_rps_profiler_LDADD = $(ld_rps_test_lib) |
113 | 111 | ||
114 | EXTRA_DIST = \ | 112 | EXTRA_DIST = \ |
diff --git a/src/rps/gnunet-service-rps_sampler_elem.c b/src/rps/gnunet-service-rps_sampler_elem.c index 16b9cb39e..5354c8081 100644 --- a/src/rps/gnunet-service-rps_sampler_elem.c +++ b/src/rps/gnunet-service-rps_sampler_elem.c | |||
@@ -166,4 +166,26 @@ RPS_sampler_elem_next (struct RPS_SamplerElement *s_elem, | |||
166 | GNUNET_i2s_full (&s_elem->peer_id)); | 166 | GNUNET_i2s_full (&s_elem->peer_id)); |
167 | } | 167 | } |
168 | 168 | ||
169 | /** | ||
170 | * Initialise the min-wise independent function of the given sampler element. | ||
171 | * | ||
172 | * @param s_elem the sampler element | ||
173 | * @param auth_key the key to use | ||
174 | */ | ||
175 | void | ||
176 | RPS_sampler_elem_set (struct RPS_SamplerElement *s_elem, | ||
177 | struct GNUNET_CRYPTO_AuthKey auth_key) | ||
178 | { | ||
179 | s_elem->auth_key = auth_key; | ||
180 | |||
181 | #ifdef TO_FILE | ||
182 | /* Create a file(-name) to store internals to */ | ||
183 | char *name_buf; | ||
184 | name_buf = auth_key_to_string (s_elem->auth_key); | ||
185 | |||
186 | s_elem->file_name = create_file (name_buf); | ||
187 | GNUNET_free (name_buf); | ||
188 | #endif /* TO_FILE */ | ||
189 | } | ||
190 | |||
169 | /* end of gnunet-service-rps.c */ | 191 | /* end of gnunet-service-rps.c */ |
diff --git a/src/rps/gnunet-service-rps_sampler_elem.h b/src/rps/gnunet-service-rps_sampler_elem.h index cb9506d69..b7224331d 100644 --- a/src/rps/gnunet-service-rps_sampler_elem.h +++ b/src/rps/gnunet-service-rps_sampler_elem.h | |||
@@ -129,6 +129,16 @@ void | |||
129 | RPS_sampler_elem_next (struct RPS_SamplerElement *s_elem, | 129 | RPS_sampler_elem_next (struct RPS_SamplerElement *s_elem, |
130 | const struct GNUNET_PeerIdentity *new_ID); | 130 | const struct GNUNET_PeerIdentity *new_ID); |
131 | 131 | ||
132 | /** | ||
133 | * Initialise the min-wise independent function of the given sampler element. | ||
134 | * | ||
135 | * @param s_elem the sampler element | ||
136 | * @param auth_key the key to use | ||
137 | */ | ||
138 | void | ||
139 | RPS_sampler_elem_set (struct RPS_SamplerElement *s_elem, | ||
140 | struct GNUNET_CRYPTO_AuthKey auth_key); | ||
141 | |||
132 | 142 | ||
133 | #endif /* RPS_SAMPLER_ELEM_H */ | 143 | #endif /* RPS_SAMPLER_ELEM_H */ |
134 | /* end of gnunet-service-rps.c */ | 144 | /* end of gnunet-service-rps.c */ |
diff --git a/src/rps/rps-test_util.c b/src/rps/rps-test_util.c index 7af2071b5..882f945c9 100644 --- a/src/rps/rps-test_util.c +++ b/src/rps/rps-test_util.c | |||
@@ -128,7 +128,7 @@ auth_key_to_string (struct GNUNET_CRYPTO_AuthKey auth_key) | |||
128 | *end = '\0'; | 128 | *end = '\0'; |
129 | } | 129 | } |
130 | 130 | ||
131 | size = GNUNET_snprintf (name_buf, name_buf_size, "sampler_el-%s-", buf); | 131 | size = GNUNET_snprintf (name_buf, name_buf_size, "sampler_el-%s", buf); |
132 | if (0 > size) | 132 | if (0 > size) |
133 | LOG (GNUNET_ERROR_TYPE_WARNING, "Failed to create name_buf\n"); | 133 | LOG (GNUNET_ERROR_TYPE_WARNING, "Failed to create name_buf\n"); |
134 | 134 | ||
@@ -137,6 +137,25 @@ auth_key_to_string (struct GNUNET_CRYPTO_AuthKey auth_key) | |||
137 | return name_buf; | 137 | return name_buf; |
138 | } | 138 | } |
139 | 139 | ||
140 | |||
141 | struct GNUNET_CRYPTO_AuthKey | ||
142 | string_to_auth_key (const char *str) | ||
143 | { | ||
144 | struct GNUNET_CRYPTO_AuthKey auth_key; | ||
145 | |||
146 | if (GNUNET_OK != | ||
147 | GNUNET_STRINGS_string_to_data (str, | ||
148 | strlen (str), | ||
149 | &auth_key.key, | ||
150 | sizeof (struct GNUNET_CRYPTO_AuthKey))) | ||
151 | { | ||
152 | LOG (GNUNET_ERROR_TYPE_WARNING, "Failed to convert string to data\n"); | ||
153 | } | ||
154 | |||
155 | return auth_key; | ||
156 | } | ||
157 | |||
158 | |||
140 | char * | 159 | char * |
141 | create_file (const char *name) | 160 | create_file (const char *name) |
142 | { | 161 | { |
@@ -150,7 +169,7 @@ create_file (const char *name) | |||
150 | name_buf_size = (strlen (prefix) + strlen (name) + 2) * sizeof (char); | 169 | name_buf_size = (strlen (prefix) + strlen (name) + 2) * sizeof (char); |
151 | name_buf = GNUNET_malloc (name_buf_size); | 170 | name_buf = GNUNET_malloc (name_buf_size); |
152 | 171 | ||
153 | size = GNUNET_snprintf (name_buf, name_buf_size, "%s%s-", prefix, name); | 172 | size = GNUNET_snprintf (name_buf, name_buf_size, "%s%s", prefix, name); |
154 | if (0 > size) | 173 | if (0 > size) |
155 | LOG (GNUNET_ERROR_TYPE_WARNING, "Failed to create name_buf\n"); | 174 | LOG (GNUNET_ERROR_TYPE_WARNING, "Failed to create name_buf\n"); |
156 | 175 | ||
@@ -161,12 +180,16 @@ create_file (const char *name) | |||
161 | prefix); | 180 | prefix); |
162 | } | 181 | } |
163 | 182 | ||
164 | if (NULL == (file_name = GNUNET_DISK_mktemp (name_buf))) | 183 | if (NULL == strstr (name, "sampler_el")) |
165 | LOG (GNUNET_ERROR_TYPE_WARNING, "Could not create file\n"); | 184 | {/* only append random string to sampler */ |
185 | if (NULL == (file_name = GNUNET_DISK_mktemp (name_buf))) | ||
186 | LOG (GNUNET_ERROR_TYPE_WARNING, "Could not create file\n"); | ||
166 | 187 | ||
167 | GNUNET_free (name_buf); | 188 | GNUNET_free (name_buf); |
168 | |||
169 | return file_name; | 189 | return file_name; |
190 | } | ||
191 | |||
192 | return name_buf; | ||
170 | } | 193 | } |
171 | 194 | ||
172 | #endif /* TO_FILE */ | 195 | #endif /* TO_FILE */ |
diff --git a/src/rps/rps-test_util.h b/src/rps/rps-test_util.h index 831ab64ee..209152151 100644 --- a/src/rps/rps-test_util.h +++ b/src/rps/rps-test_util.h | |||
@@ -39,6 +39,9 @@ to_file_ (char *file_name, char *line); | |||
39 | char * | 39 | char * |
40 | auth_key_to_string (struct GNUNET_CRYPTO_AuthKey auth_key); | 40 | auth_key_to_string (struct GNUNET_CRYPTO_AuthKey auth_key); |
41 | 41 | ||
42 | struct GNUNET_CRYPTO_AuthKey | ||
43 | string_to_auth_key (const char *str); | ||
44 | |||
42 | char * | 45 | char * |
43 | create_file (const char *name); | 46 | create_file (const char *name); |
44 | 47 | ||
diff --git a/src/rps/test_rps.c b/src/rps/test_rps.c index f6db147f9..47abe668a 100644 --- a/src/rps/test_rps.c +++ b/src/rps/test_rps.c | |||
@@ -27,7 +27,10 @@ | |||
27 | #include "platform.h" | 27 | #include "platform.h" |
28 | #include "gnunet_util_lib.h" | 28 | #include "gnunet_util_lib.h" |
29 | #include "gnunet_testbed_service.h" | 29 | #include "gnunet_testbed_service.h" |
30 | |||
30 | #include "gnunet_rps_service.h" | 31 | #include "gnunet_rps_service.h" |
32 | #include "rps-test_util.h" | ||
33 | #include "gnunet-service-rps_sampler_elem.h" | ||
31 | 34 | ||
32 | #include <inttypes.h> | 35 | #include <inttypes.h> |
33 | 36 | ||
@@ -257,7 +260,7 @@ struct SingleTestRun | |||
257 | * Append arguments to file | 260 | * Append arguments to file |
258 | */ | 261 | */ |
259 | static void | 262 | static void |
260 | to_file_ (char *file_name, char *line) | 263 | tofile_ (const char *file_name, char *line) |
261 | { | 264 | { |
262 | struct GNUNET_DISK_FileHandle *f; | 265 | struct GNUNET_DISK_FileHandle *f; |
263 | /* char output_buffer[512]; */ | 266 | /* char output_buffer[512]; */ |
@@ -312,7 +315,7 @@ to_file_ (char *file_name, char *line) | |||
312 | /** | 315 | /** |
313 | * This function is used to facilitate writing important information to disk | 316 | * This function is used to facilitate writing important information to disk |
314 | */ | 317 | */ |
315 | #define to_file(file_name, ...) do {\ | 318 | #define tofile(file_name, ...) do {\ |
316 | char tmp_buf[512];\ | 319 | char tmp_buf[512];\ |
317 | int size;\ | 320 | int size;\ |
318 | size = GNUNET_snprintf(tmp_buf,sizeof(tmp_buf),__VA_ARGS__);\ | 321 | size = GNUNET_snprintf(tmp_buf,sizeof(tmp_buf),__VA_ARGS__);\ |
@@ -320,7 +323,7 @@ to_file_ (char *file_name, char *line) | |||
320 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING,\ | 323 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING,\ |
321 | "Failed to create tmp_buf\n");\ | 324 | "Failed to create tmp_buf\n");\ |
322 | else\ | 325 | else\ |
323 | to_file_(file_name,tmp_buf);\ | 326 | tofile_(file_name,tmp_buf);\ |
324 | } while (0); | 327 | } while (0); |
325 | 328 | ||
326 | /** | 329 | /** |
@@ -386,7 +389,7 @@ make_oplist_entry () | |||
386 | 389 | ||
387 | 390 | ||
388 | /** | 391 | /** |
389 | * Callback to be called when NSE service is started or stopped at peers | 392 | * Callback to be called when RPS service is started or stopped at peers |
390 | * | 393 | * |
391 | * @param cls NULL | 394 | * @param cls NULL |
392 | * @param op the operation handle | 395 | * @param op the operation handle |
@@ -521,7 +524,7 @@ info_cb (void *cb_cls, | |||
521 | rps_peers[entry->index].rec_ids = NULL; | 524 | rps_peers[entry->index].rec_ids = NULL; |
522 | rps_peers[entry->index].num_rec_ids = 0; | 525 | rps_peers[entry->index].num_rec_ids = 0; |
523 | 526 | ||
524 | to_file ("/tmp/rps/peer_ids", | 527 | tofile ("/tmp/rps/peer_ids", |
525 | "%u\t%s\n", | 528 | "%u\t%s\n", |
526 | entry->index, | 529 | entry->index, |
527 | GNUNET_i2s_full (&rps_peer_ids[entry->index])); | 530 | GNUNET_i2s_full (&rps_peer_ids[entry->index])); |
@@ -972,7 +975,7 @@ profiler_reply_handle (void *cls, | |||
972 | GNUNET_i2s (&recv_peers[i])); | 975 | GNUNET_i2s (&recv_peers[i])); |
973 | 976 | ||
974 | /* GNUNET_array_append (rps_peer->rec_ids, rps_peer->num_rec_ids, recv_peers[i]); */ | 977 | /* GNUNET_array_append (rps_peer->rec_ids, rps_peer->num_rec_ids, recv_peers[i]); */ |
975 | to_file (file_name, | 978 | tofile (file_name, |
976 | "%s\n", | 979 | "%s\n", |
977 | GNUNET_i2s_full (&recv_peers[i])); | 980 | GNUNET_i2s_full (&recv_peers[i])); |
978 | } | 981 | } |
@@ -1010,6 +1013,57 @@ profiler_cb (struct RPSPeer *rps_peer) | |||
1010 | } | 1013 | } |
1011 | } | 1014 | } |
1012 | 1015 | ||
1016 | /** | ||
1017 | * Function called from #profiler_eval with a filename. | ||
1018 | * | ||
1019 | * @param cls closure | ||
1020 | * @param filename complete filename (absolute path) | ||
1021 | * @return #GNUNET_OK to continue to iterate, | ||
1022 | * #GNUNET_NO to stop iteration with no error, | ||
1023 | * #GNUNET_SYSERR to abort iteration with error! | ||
1024 | */ | ||
1025 | int | ||
1026 | file_name_cb (void *cls, const char *filename) | ||
1027 | { | ||
1028 | if (NULL != strstr (filename, "sampler_el")) | ||
1029 | { | ||
1030 | struct RPS_SamplerElement *s_elem; | ||
1031 | struct GNUNET_CRYPTO_AuthKey auth_key; | ||
1032 | const char *key_char; | ||
1033 | uint32_t i; | ||
1034 | |||
1035 | key_char = filename + 20; /* Length of "/tmp/rps/sampler_el-" */ | ||
1036 | tofile (filename, "--------------------------\n"); | ||
1037 | |||
1038 | auth_key = string_to_auth_key (key_char); | ||
1039 | s_elem = RPS_sampler_elem_create (); | ||
1040 | RPS_sampler_elem_set (s_elem, auth_key); | ||
1041 | |||
1042 | for (i = 0; i < num_peers; i++) | ||
1043 | { | ||
1044 | RPS_sampler_elem_next (s_elem, &rps_peer_ids[i]); | ||
1045 | } | ||
1046 | } | ||
1047 | return GNUNET_OK; | ||
1048 | } | ||
1049 | |||
1050 | /** | ||
1051 | * This is run after the test finished. | ||
1052 | * | ||
1053 | * Compute all perfect samples. | ||
1054 | */ | ||
1055 | int | ||
1056 | profiler_eval (void) | ||
1057 | { | ||
1058 | /* Compute perfect sample for each sampler element */ | ||
1059 | if (-1 == GNUNET_DISK_directory_scan ("/tmp/rps/", file_name_cb, NULL)) | ||
1060 | { | ||
1061 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Scan of directory failed\n"); | ||
1062 | } | ||
1063 | |||
1064 | return 0; | ||
1065 | } | ||
1066 | |||
1013 | 1067 | ||
1014 | /*********************************************************************** | 1068 | /*********************************************************************** |
1015 | * /Definition of tests | 1069 | * /Definition of tests |
@@ -1187,7 +1241,7 @@ main (int argc, char *argv[]) | |||
1187 | cur_test_run.pre_test = profiler_pre; | 1241 | cur_test_run.pre_test = profiler_pre; |
1188 | cur_test_run.main_test = profiler_cb; | 1242 | cur_test_run.main_test = profiler_cb; |
1189 | cur_test_run.reply_handle = profiler_reply_handle; | 1243 | cur_test_run.reply_handle = profiler_reply_handle; |
1190 | cur_test_run.eval_cb = no_eval; | 1244 | cur_test_run.eval_cb = profiler_eval; |
1191 | cur_test_run.request_interval = 2; | 1245 | cur_test_run.request_interval = 2; |
1192 | cur_test_run.num_requests = 50; | 1246 | cur_test_run.num_requests = 50; |
1193 | 1247 | ||