diff options
Diffstat (limited to 'src/fs/perf_gnunet_service_fs_p2p.c')
-rw-r--r-- | src/fs/perf_gnunet_service_fs_p2p.c | 269 |
1 files changed, 136 insertions, 133 deletions
diff --git a/src/fs/perf_gnunet_service_fs_p2p.c b/src/fs/perf_gnunet_service_fs_p2p.c index 515144eb1..39563dfa4 100644 --- a/src/fs/perf_gnunet_service_fs_p2p.c +++ b/src/fs/perf_gnunet_service_fs_p2p.c | |||
@@ -37,7 +37,7 @@ | |||
37 | /** | 37 | /** |
38 | * How long until we give up on transmitting the message? | 38 | * How long until we give up on transmitting the message? |
39 | */ | 39 | */ |
40 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 30) | 40 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 30) |
41 | 41 | ||
42 | #define NUM_DAEMONS 2 | 42 | #define NUM_DAEMONS 2 |
43 | 43 | ||
@@ -57,14 +57,16 @@ static struct GNUNET_TIME_Absolute start_time; | |||
57 | /** | 57 | /** |
58 | * Master context for 'stat_run'. | 58 | * Master context for 'stat_run'. |
59 | */ | 59 | */ |
60 | struct StatMaster { | 60 | struct StatMaster |
61 | { | ||
61 | struct GNUNET_STATISTICS_Handle *stat; | 62 | struct GNUNET_STATISTICS_Handle *stat; |
62 | struct GNUNET_TESTBED_Operation *op; | 63 | struct GNUNET_TESTBED_Operation *op; |
63 | unsigned int daemon; | 64 | unsigned int daemon; |
64 | unsigned int value; | 65 | unsigned int value; |
65 | }; | 66 | }; |
66 | 67 | ||
67 | struct StatValues { | 68 | struct StatValues |
69 | { | ||
68 | const char *subsystem; | 70 | const char *subsystem; |
69 | const char *name; | 71 | const char *name; |
70 | }; | 72 | }; |
@@ -109,17 +111,17 @@ static struct StatValues stats[] = { | |||
109 | * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration | 111 | * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration |
110 | */ | 112 | */ |
111 | static int | 113 | static int |
112 | print_stat(void *cls, const char *subsystem, const char *name, uint64_t value, | 114 | print_stat (void *cls, const char *subsystem, const char *name, uint64_t value, |
113 | int is_persistent) | 115 | int is_persistent) |
114 | { | 116 | { |
115 | struct StatMaster *sm = cls; | 117 | struct StatMaster *sm = cls; |
116 | 118 | ||
117 | fprintf(stderr, | 119 | fprintf (stderr, |
118 | "Peer %2u: %12s/%50s = %12llu\n", | 120 | "Peer %2u: %12s/%50s = %12llu\n", |
119 | sm->daemon, | 121 | sm->daemon, |
120 | subsystem, | 122 | subsystem, |
121 | name, | 123 | name, |
122 | (unsigned long long)value); | 124 | (unsigned long long) value); |
123 | return GNUNET_OK; | 125 | return GNUNET_OK; |
124 | } | 126 | } |
125 | 127 | ||
@@ -128,23 +130,23 @@ print_stat(void *cls, const char *subsystem, const char *name, uint64_t value, | |||
128 | * Function that gathers stats from all daemons. | 130 | * Function that gathers stats from all daemons. |
129 | */ | 131 | */ |
130 | static void | 132 | static void |
131 | stat_run(void *cls, | 133 | stat_run (void *cls, |
132 | struct GNUNET_TESTBED_Operation *op, | 134 | struct GNUNET_TESTBED_Operation *op, |
133 | void *ca_result, | 135 | void *ca_result, |
134 | const char *emsg); | 136 | const char *emsg); |
135 | 137 | ||
136 | 138 | ||
137 | /** | 139 | /** |
138 | * Function called when GET operation on stats is done. | 140 | * Function called when GET operation on stats is done. |
139 | */ | 141 | */ |
140 | static void | 142 | static void |
141 | get_done(void *cls, int success) | 143 | get_done (void *cls, int success) |
142 | { | 144 | { |
143 | struct StatMaster *sm = cls; | 145 | struct StatMaster *sm = cls; |
144 | 146 | ||
145 | GNUNET_break(GNUNET_OK == success); | 147 | GNUNET_break (GNUNET_OK == success); |
146 | sm->value++; | 148 | sm->value++; |
147 | stat_run(sm, sm->op, sm->stat, NULL); | 149 | stat_run (sm, sm->op, sm->stat, NULL); |
148 | } | 150 | } |
149 | 151 | ||
150 | 152 | ||
@@ -159,11 +161,11 @@ get_done(void *cls, int success) | |||
159 | * @return service handle to return in 'op_result', NULL on error | 161 | * @return service handle to return in 'op_result', NULL on error |
160 | */ | 162 | */ |
161 | static void * | 163 | static void * |
162 | statistics_connect_adapter(void *cls, | 164 | statistics_connect_adapter (void *cls, |
163 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 165 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
164 | { | 166 | { |
165 | return GNUNET_STATISTICS_create("<driver>", | 167 | return GNUNET_STATISTICS_create ("<driver>", |
166 | cfg); | 168 | cfg); |
167 | } | 169 | } |
168 | 170 | ||
169 | 171 | ||
@@ -175,10 +177,10 @@ statistics_connect_adapter(void *cls, | |||
175 | * @param op_result service handle returned from the connect adapter | 177 | * @param op_result service handle returned from the connect adapter |
176 | */ | 178 | */ |
177 | static void | 179 | static void |
178 | statistics_disconnect_adapter(void *cls, | 180 | statistics_disconnect_adapter (void *cls, |
179 | void *op_result) | 181 | void *op_result) |
180 | { | 182 | { |
181 | GNUNET_STATISTICS_destroy(op_result, GNUNET_NO); | 183 | GNUNET_STATISTICS_destroy (op_result, GNUNET_NO); |
182 | } | 184 | } |
183 | 185 | ||
184 | 186 | ||
@@ -186,57 +188,57 @@ statistics_disconnect_adapter(void *cls, | |||
186 | * Function that gathers stats from all daemons. | 188 | * Function that gathers stats from all daemons. |
187 | */ | 189 | */ |
188 | static void | 190 | static void |
189 | stat_run(void *cls, | 191 | stat_run (void *cls, |
190 | struct GNUNET_TESTBED_Operation *op, | 192 | struct GNUNET_TESTBED_Operation *op, |
191 | void *ca_result, | 193 | void *ca_result, |
192 | const char *emsg) | 194 | const char *emsg) |
193 | { | 195 | { |
194 | struct StatMaster *sm = cls; | 196 | struct StatMaster *sm = cls; |
195 | 197 | ||
196 | if (NULL != emsg) | 198 | if (NULL != emsg) |
197 | { | 199 | { |
198 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 200 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
199 | "Failed to statistics service: %s\n", | 201 | "Failed to statistics service: %s\n", |
200 | emsg); | 202 | emsg); |
201 | GNUNET_SCHEDULER_shutdown(); | 203 | GNUNET_SCHEDULER_shutdown (); |
202 | return; | 204 | return; |
203 | } | 205 | } |
204 | sm->stat = ca_result; | 206 | sm->stat = ca_result; |
205 | 207 | ||
206 | if (stats[sm->value].name != NULL) | 208 | if (stats[sm->value].name != NULL) |
207 | { | 209 | { |
208 | GNUNET_STATISTICS_get(sm->stat, | 210 | GNUNET_STATISTICS_get (sm->stat, |
209 | #if 0 | 211 | #if 0 |
210 | NULL, NULL, | 212 | NULL, NULL, |
211 | #else | 213 | #else |
212 | stats[sm->value].subsystem, stats[sm->value].name, | 214 | stats[sm->value].subsystem, stats[sm->value].name, |
213 | #endif | 215 | #endif |
214 | &get_done, &print_stat, | 216 | &get_done, &print_stat, |
215 | sm); | 217 | sm); |
216 | return; | 218 | return; |
217 | } | 219 | } |
218 | GNUNET_TESTBED_operation_done(sm->op); | 220 | GNUNET_TESTBED_operation_done (sm->op); |
219 | sm->value = 0; | 221 | sm->value = 0; |
220 | sm->daemon++; | 222 | sm->daemon++; |
221 | if (NUM_DAEMONS == sm->daemon) | 223 | if (NUM_DAEMONS == sm->daemon) |
222 | { | 224 | { |
223 | GNUNET_free(sm); | 225 | GNUNET_free (sm); |
224 | GNUNET_SCHEDULER_shutdown(); | 226 | GNUNET_SCHEDULER_shutdown (); |
225 | return; | 227 | return; |
226 | } | 228 | } |
227 | sm->op = | 229 | sm->op = |
228 | GNUNET_TESTBED_service_connect(NULL, | 230 | GNUNET_TESTBED_service_connect (NULL, |
229 | daemons[sm->daemon], | 231 | daemons[sm->daemon], |
230 | "statistics", | 232 | "statistics", |
231 | &stat_run, sm, | 233 | &stat_run, sm, |
232 | &statistics_connect_adapter, | 234 | &statistics_connect_adapter, |
233 | &statistics_disconnect_adapter, | 235 | &statistics_disconnect_adapter, |
234 | NULL); | 236 | NULL); |
235 | } | 237 | } |
236 | 238 | ||
237 | 239 | ||
238 | static void | 240 | static void |
239 | do_report(void *cls) | 241 | do_report (void *cls) |
240 | { | 242 | { |
241 | char *fn = cls; | 243 | char *fn = cls; |
242 | struct GNUNET_TIME_Relative del; | 244 | struct GNUNET_TIME_Relative del; |
@@ -244,120 +246,121 @@ do_report(void *cls) | |||
244 | struct StatMaster *sm; | 246 | struct StatMaster *sm; |
245 | 247 | ||
246 | if (NULL != fn) | 248 | if (NULL != fn) |
247 | { | 249 | { |
248 | GNUNET_DISK_directory_remove(fn); | 250 | GNUNET_DISK_directory_remove (fn); |
249 | GNUNET_free(fn); | 251 | GNUNET_free (fn); |
250 | } | 252 | } |
251 | if (0 == | 253 | if (0 == |
252 | GNUNET_TIME_absolute_get_remaining(GNUNET_TIME_absolute_add(start_time, | 254 | GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_add (start_time, |
253 | TIMEOUT)).rel_value_us) | 255 | TIMEOUT)). |
254 | { | 256 | rel_value_us) |
255 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 257 | { |
256 | "Timeout during download, shutting down with error\n"); | 258 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
257 | ok = 1; | 259 | "Timeout during download, shutting down with error\n"); |
258 | GNUNET_SCHEDULER_shutdown(); | 260 | ok = 1; |
259 | return; | 261 | GNUNET_SCHEDULER_shutdown (); |
260 | } | 262 | return; |
261 | 263 | } | |
262 | del = GNUNET_TIME_absolute_get_duration(start_time); | 264 | |
265 | del = GNUNET_TIME_absolute_get_duration (start_time); | ||
263 | if (del.rel_value_us == 0) | 266 | if (del.rel_value_us == 0) |
264 | del.rel_value_us = 1; | 267 | del.rel_value_us = 1; |
265 | fancy = | 268 | fancy = |
266 | GNUNET_STRINGS_byte_size_fancy(((unsigned long long)FILESIZE) * | 269 | GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) |
267 | 1000000LL / del.rel_value_us); | 270 | * 1000000LL / del.rel_value_us); |
268 | fprintf(stdout, | 271 | fprintf (stdout, |
269 | "Download speed was %s/s\n", | 272 | "Download speed was %s/s\n", |
270 | fancy); | 273 | fancy); |
271 | GNUNET_free(fancy); | 274 | GNUNET_free (fancy); |
272 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 275 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
273 | "Finished download, shutting down\n"); | 276 | "Finished download, shutting down\n"); |
274 | sm = GNUNET_new(struct StatMaster); | 277 | sm = GNUNET_new (struct StatMaster); |
275 | sm->op = | 278 | sm->op = |
276 | GNUNET_TESTBED_service_connect(NULL, | 279 | GNUNET_TESTBED_service_connect (NULL, |
277 | daemons[sm->daemon], | 280 | daemons[sm->daemon], |
278 | "statistics", | 281 | "statistics", |
279 | &stat_run, sm, | 282 | &stat_run, sm, |
280 | &statistics_connect_adapter, | 283 | &statistics_connect_adapter, |
281 | &statistics_disconnect_adapter, | 284 | &statistics_disconnect_adapter, |
282 | NULL); | 285 | NULL); |
283 | } | 286 | } |
284 | 287 | ||
285 | 288 | ||
286 | static void | 289 | static void |
287 | do_download(void *cls, | 290 | do_download (void *cls, |
288 | const struct GNUNET_FS_Uri *uri, | 291 | const struct GNUNET_FS_Uri *uri, |
289 | const char *fn) | 292 | const char *fn) |
290 | { | 293 | { |
291 | int anonymity; | 294 | int anonymity; |
292 | 295 | ||
293 | if (NULL == uri) | 296 | if (NULL == uri) |
294 | { | 297 | { |
295 | GNUNET_SCHEDULER_shutdown(); | 298 | GNUNET_SCHEDULER_shutdown (); |
296 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 299 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
297 | "Timeout during upload attempt, shutting down with error\n"); | 300 | "Timeout during upload attempt, shutting down with error\n"); |
298 | ok = 1; | 301 | ok = 1; |
299 | return; | 302 | return; |
300 | } | 303 | } |
301 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Downloading %llu bytes\n", | 304 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Downloading %llu bytes\n", |
302 | (unsigned long long)FILESIZE); | 305 | (unsigned long long) FILESIZE); |
303 | start_time = GNUNET_TIME_absolute_get(); | 306 | start_time = GNUNET_TIME_absolute_get (); |
304 | if (NULL != strstr(progname, "dht")) | 307 | if (NULL != strstr (progname, "dht")) |
305 | anonymity = 0; | 308 | anonymity = 0; |
306 | else | 309 | else |
307 | anonymity = 1; | 310 | anonymity = 1; |
308 | start_time = GNUNET_TIME_absolute_get(); | 311 | start_time = GNUNET_TIME_absolute_get (); |
309 | GNUNET_FS_TEST_download(daemons[0], | 312 | GNUNET_FS_TEST_download (daemons[0], |
310 | TIMEOUT, | 313 | TIMEOUT, |
311 | anonymity, | 314 | anonymity, |
312 | SEED, | 315 | SEED, |
313 | uri, | 316 | uri, |
314 | VERBOSE, | 317 | VERBOSE, |
315 | &do_report, | 318 | &do_report, |
316 | (NULL == fn) ? NULL : GNUNET_strdup(fn)); | 319 | (NULL == fn) ? NULL : GNUNET_strdup (fn)); |
317 | } | 320 | } |
318 | 321 | ||
319 | 322 | ||
320 | static void | 323 | static void |
321 | do_publish(void *cls, | 324 | do_publish (void *cls, |
322 | struct GNUNET_TESTBED_RunHandle *h, | 325 | struct GNUNET_TESTBED_RunHandle *h, |
323 | unsigned int num_peers, | 326 | unsigned int num_peers, |
324 | struct GNUNET_TESTBED_Peer **peers, | 327 | struct GNUNET_TESTBED_Peer **peers, |
325 | unsigned int links_succeeded, | 328 | unsigned int links_succeeded, |
326 | unsigned int links_failed) | 329 | unsigned int links_failed) |
327 | { | 330 | { |
328 | unsigned int i; | 331 | unsigned int i; |
329 | int do_index; | 332 | int do_index; |
330 | int anonymity; | 333 | int anonymity; |
331 | 334 | ||
332 | GNUNET_assert(NUM_DAEMONS == num_peers); | 335 | GNUNET_assert (NUM_DAEMONS == num_peers); |
333 | for (i = 0; i < num_peers; i++) | 336 | for (i = 0; i < num_peers; i++) |
334 | daemons[i] = peers[i]; | 337 | daemons[i] = peers[i]; |
335 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Publishing %llu bytes\n", | 338 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Publishing %llu bytes\n", |
336 | (unsigned long long)FILESIZE); | 339 | (unsigned long long) FILESIZE); |
337 | if (NULL != strstr(progname, "index")) | 340 | if (NULL != strstr (progname, "index")) |
338 | do_index = GNUNET_YES; | 341 | do_index = GNUNET_YES; |
339 | else | 342 | else |
340 | do_index = GNUNET_NO; | 343 | do_index = GNUNET_NO; |
341 | if (NULL != strstr(progname, "dht")) | 344 | if (NULL != strstr (progname, "dht")) |
342 | anonymity = 0; | 345 | anonymity = 0; |
343 | else | 346 | else |
344 | anonymity = 1; | 347 | anonymity = 1; |
345 | GNUNET_FS_TEST_publish(daemons[NUM_DAEMONS - 1], TIMEOUT, anonymity, | 348 | GNUNET_FS_TEST_publish (daemons[NUM_DAEMONS - 1], TIMEOUT, anonymity, |
346 | do_index, FILESIZE, SEED, VERBOSE, &do_download, | 349 | do_index, FILESIZE, SEED, VERBOSE, &do_download, |
347 | NULL); | 350 | NULL); |
348 | } | 351 | } |
349 | 352 | ||
350 | 353 | ||
351 | int | 354 | int |
352 | main(int argc, char *argv[]) | 355 | main (int argc, char *argv[]) |
353 | { | 356 | { |
354 | progname = argv[0]; | 357 | progname = argv[0]; |
355 | (void)GNUNET_TESTBED_test_run("perf-gnunet-service-fs-p2p", | 358 | (void) GNUNET_TESTBED_test_run ("perf-gnunet-service-fs-p2p", |
356 | "perf_gnunet_service_fs_p2p.conf", | 359 | "perf_gnunet_service_fs_p2p.conf", |
357 | NUM_DAEMONS, | 360 | NUM_DAEMONS, |
358 | 0, NULL, NULL, | 361 | 0, NULL, NULL, |
359 | &do_publish, NULL); | 362 | &do_publish, NULL); |
360 | GNUNET_DISK_directory_remove("/tmp/gnunet-test-fs-lib/"); | 363 | GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/"); |
361 | return ok; | 364 | return ok; |
362 | } | 365 | } |
363 | 366 | ||