diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2011-03-28 15:46:25 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2011-03-28 15:46:25 +0000 |
commit | d2d6687abfa7dc47ef7e8208522a835d4b852ef6 (patch) | |
tree | 19524c6c73b196dc90031920a5c6c79494a744c8 /src/transport/test_transport_ats.c | |
parent | fc78e1f97f9dbbf64d21c1477b737428d85e461a (diff) | |
download | gnunet-d2d6687abfa7dc47ef7e8208522a835d4b852ef6.tar.gz gnunet-d2d6687abfa7dc47ef7e8208522a835d4b852ef6.zip |
ats
Diffstat (limited to 'src/transport/test_transport_ats.c')
-rw-r--r-- | src/transport/test_transport_ats.c | 138 |
1 files changed, 32 insertions, 106 deletions
diff --git a/src/transport/test_transport_ats.c b/src/transport/test_transport_ats.c index 88e9706ec..ef33e0f8b 100644 --- a/src/transport/test_transport_ats.c +++ b/src/transport/test_transport_ats.c | |||
@@ -34,7 +34,9 @@ | |||
34 | #include "gnunet_program_lib.h" | 34 | #include "gnunet_program_lib.h" |
35 | #include "gnunet_scheduler_lib.h" | 35 | #include "gnunet_scheduler_lib.h" |
36 | #include "gnunet_transport_service.h" | 36 | #include "gnunet_transport_service.h" |
37 | #include "gnunet_statistics_service.h" | ||
37 | #include "transport.h" | 38 | #include "transport.h" |
39 | #include "gauger.h" | ||
38 | 40 | ||
39 | #define VERBOSE GNUNET_NO | 41 | #define VERBOSE GNUNET_NO |
40 | 42 | ||
@@ -45,7 +47,7 @@ | |||
45 | /** | 47 | /** |
46 | * How long until we give up on transmitting the message? | 48 | * How long until we give up on transmitting the message? |
47 | */ | 49 | */ |
48 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) | 50 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) |
49 | 51 | ||
50 | /** | 52 | /** |
51 | * How long until we give up on transmitting the message? | 53 | * How long until we give up on transmitting the message? |
@@ -59,6 +61,7 @@ struct PeerContext | |||
59 | struct GNUNET_CONFIGURATION_Handle *cfg; | 61 | struct GNUNET_CONFIGURATION_Handle *cfg; |
60 | struct GNUNET_TRANSPORT_Handle *th; | 62 | struct GNUNET_TRANSPORT_Handle *th; |
61 | struct GNUNET_PeerIdentity id; | 63 | struct GNUNET_PeerIdentity id; |
64 | struct GNUNET_STATISTICS_Handle *stats; | ||
62 | #if START_ARM | 65 | #if START_ARM |
63 | struct GNUNET_OS_Process *arm_proc; | 66 | struct GNUNET_OS_Process *arm_proc; |
64 | #endif | 67 | #endif |
@@ -66,6 +69,12 @@ struct PeerContext | |||
66 | 69 | ||
67 | static struct PeerContext p1; | 70 | static struct PeerContext p1; |
68 | 71 | ||
72 | /** | ||
73 | * Handle for reporting statistics. | ||
74 | */ | ||
75 | |||
76 | |||
77 | |||
69 | static struct PeerContext p2; | 78 | static struct PeerContext p2; |
70 | 79 | ||
71 | static int ok; | 80 | static int ok; |
@@ -90,11 +99,6 @@ static int is_wlan; | |||
90 | 99 | ||
91 | static GNUNET_SCHEDULER_TaskIdentifier die_task; | 100 | static GNUNET_SCHEDULER_TaskIdentifier die_task; |
92 | 101 | ||
93 | static char * key_file_p1; | ||
94 | static char * cert_file_p1; | ||
95 | |||
96 | static char * key_file_p2; | ||
97 | static char * cert_file_p2; | ||
98 | 102 | ||
99 | #if VERBOSE | 103 | #if VERBOSE |
100 | #define OKPP do { ok++; fprintf (stderr, "Now at stage %u at %s:%u\n", ok, __FILE__, __LINE__); } while (0) | 104 | #define OKPP do { ok++; fprintf (stderr, "Now at stage %u at %s:%u\n", ok, __FILE__, __LINE__); } while (0) |
@@ -112,7 +116,8 @@ end () | |||
112 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from transports!\n"); | 116 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from transports!\n"); |
113 | GNUNET_TRANSPORT_disconnect (p1.th); | 117 | GNUNET_TRANSPORT_disconnect (p1.th); |
114 | GNUNET_TRANSPORT_disconnect (p2.th); | 118 | GNUNET_TRANSPORT_disconnect (p2.th); |
115 | 119 | if (p1.stats != NULL) | |
120 | GNUNET_STATISTICS_destroy (p1.stats, GNUNET_NO); | ||
116 | die_task = GNUNET_SCHEDULER_NO_TASK; | 121 | die_task = GNUNET_SCHEDULER_NO_TASK; |
117 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transports disconnected, returning success!\n"); | 122 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transports disconnected, returning success!\n"); |
118 | ok = 0; | 123 | ok = 0; |
@@ -138,6 +143,8 @@ end_badly () | |||
138 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from transports!\n"); | 143 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from transports!\n"); |
139 | //GNUNET_break (0); | 144 | //GNUNET_break (0); |
140 | GNUNET_TRANSPORT_disconnect (p1.th); | 145 | GNUNET_TRANSPORT_disconnect (p1.th); |
146 | if (p1.stats != NULL) | ||
147 | GNUNET_STATISTICS_destroy (p1.stats, GNUNET_NO); | ||
141 | //GNUNET_TRANSPORT_disconnect (p2.th); | 148 | //GNUNET_TRANSPORT_disconnect (p2.th); |
142 | ok = 1; | 149 | ok = 1; |
143 | } | 150 | } |
@@ -203,9 +210,6 @@ notify_connect (void *cls, | |||
203 | { | 210 | { |
204 | if (cls == &p1) | 211 | if (cls == &p1) |
205 | { | 212 | { |
206 | GNUNET_SCHEDULER_cancel (die_task); | ||
207 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT_TRANSMIT, | ||
208 | &end_badly, NULL); | ||
209 | 213 | ||
210 | GNUNET_TRANSPORT_notify_transmit_ready (p1.th, | 214 | GNUNET_TRANSPORT_notify_transmit_ready (p1.th, |
211 | &p2.id, | 215 | &p2.id, |
@@ -225,6 +229,17 @@ notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) | |||
225 | GNUNET_i2s (peer), cls); | 229 | GNUNET_i2s (peer), cls); |
226 | } | 230 | } |
227 | 231 | ||
232 | int stat_cb (void *cls, | ||
233 | const char *subsystem, | ||
234 | const char *name, | ||
235 | uint64_t value, | ||
236 | int is_persistent) | ||
237 | { | ||
238 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
239 | "Execution time for 100 Peers: %llu\n",value); | ||
240 | return GNUNET_NO; | ||
241 | } | ||
242 | |||
228 | 243 | ||
229 | static void | 244 | static void |
230 | setup_peer (struct PeerContext *p, const char *cfgname) | 245 | setup_peer (struct PeerContext *p, const char *cfgname) |
@@ -239,69 +254,19 @@ setup_peer (struct PeerContext *p, const char *cfgname) | |||
239 | "-c", cfgname, NULL); | 254 | "-c", cfgname, NULL); |
240 | #endif | 255 | #endif |
241 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); | 256 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); |
242 | 257 | p->stats = GNUNET_STATISTICS_create ("transport", p->cfg); | |
243 | if (is_https) | 258 | GNUNET_assert (p->stats != NULL); |
244 | { | 259 | GNUNET_assert (GNUNET_OK == GNUNET_STATISTICS_watch (p->stats,"transport","ATS execution time 100 peers", stat_cb, NULL)); |
245 | struct stat sbuf; | ||
246 | if (p==&p1) | ||
247 | { | ||
248 | if (GNUNET_CONFIGURATION_have_value (p->cfg, | ||
249 | "transport-https", "KEY_FILE")) | ||
250 | GNUNET_CONFIGURATION_get_value_string (p->cfg, "transport-https", "KEY_FILE", &key_file_p1); | ||
251 | if (key_file_p1==NULL) | ||
252 | GNUNET_asprintf(&key_file_p1,"https.key"); | ||
253 | if (0 == stat (key_file_p1, &sbuf )) | ||
254 | { | ||
255 | if (0 == remove(key_file_p1)) | ||
256 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Successfully removed existing private key file `%s'\n",key_file_p1); | ||
257 | else | ||
258 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to remove private key file `%s'\n",key_file_p1); | ||
259 | } | ||
260 | if (GNUNET_CONFIGURATION_have_value (p->cfg,"transport-https", "CERT_FILE")) | ||
261 | GNUNET_CONFIGURATION_get_value_string (p->cfg, "transport-https", "CERT_FILE", &cert_file_p1); | ||
262 | if (cert_file_p1==NULL) | ||
263 | GNUNET_asprintf(&cert_file_p1,"https.cert"); | ||
264 | if (0 == stat (cert_file_p1, &sbuf )) | ||
265 | { | ||
266 | if (0 == remove(cert_file_p1)) | ||
267 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Successfully removed existing certificate file `%s'\n",cert_file_p1); | ||
268 | else | ||
269 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to remove existing certificate file `%s'\n",cert_file_p1); | ||
270 | } | ||
271 | } | ||
272 | else if (p==&p2) | ||
273 | { | ||
274 | if (GNUNET_CONFIGURATION_have_value (p->cfg, | ||
275 | "transport-https", "KEY_FILE")) | ||
276 | GNUNET_CONFIGURATION_get_value_string (p->cfg, "transport-https", "KEY_FILE", &key_file_p2); | ||
277 | if (key_file_p2==NULL) | ||
278 | GNUNET_asprintf(&key_file_p2,"https.key"); | ||
279 | if (0 == stat (key_file_p2, &sbuf )) | ||
280 | { | ||
281 | if (0 == remove(key_file_p2)) | ||
282 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Successfully removed existing private key file `%s'\n",key_file_p2); | ||
283 | else | ||
284 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to remove private key file `%s'\n",key_file_p2); | ||
285 | } | ||
286 | if (GNUNET_CONFIGURATION_have_value (p->cfg,"transport-https", "CERT_FILE")) | ||
287 | GNUNET_CONFIGURATION_get_value_string (p->cfg, "transport-https", "CERT_FILE", &cert_file_p2); | ||
288 | if (cert_file_p2==NULL) | ||
289 | GNUNET_asprintf(&cert_file_p2,"https.cert"); | ||
290 | if (0 == stat (cert_file_p2, &sbuf )) | ||
291 | { | ||
292 | if (0 == remove(cert_file_p2)) | ||
293 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Successfully removed existing certificate file `%s'\n",cert_file_p2); | ||
294 | else | ||
295 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to remove existing certificate file `%s'\n",cert_file_p2); | ||
296 | } | ||
297 | } | ||
298 | } | ||
299 | 260 | ||
300 | p->th = GNUNET_TRANSPORT_connect (p->cfg, | 261 | p->th = GNUNET_TRANSPORT_connect (p->cfg, |
301 | NULL, p, | 262 | NULL, p, |
302 | ¬ify_receive, | 263 | ¬ify_receive, |
303 | ¬ify_connect, ¬ify_disconnect); | 264 | ¬ify_connect, ¬ify_disconnect); |
304 | GNUNET_assert (p->th != NULL); | 265 | GNUNET_assert (p->th != NULL); |
266 | |||
267 | GNUNET_SCHEDULER_cancel (die_task); | ||
268 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT_TRANSMIT, | ||
269 | &end_badly, NULL); | ||
305 | } | 270 | } |
306 | 271 | ||
307 | 272 | ||
@@ -400,45 +365,6 @@ check () | |||
400 | stop_arm (&p1); | 365 | stop_arm (&p1); |
401 | // stop_arm (&p2); | 366 | // stop_arm (&p2); |
402 | 367 | ||
403 | if (is_https) | ||
404 | { | ||
405 | struct stat sbuf; | ||
406 | if (0 == stat (cert_file_p1, &sbuf )) | ||
407 | { | ||
408 | if (0 == remove(cert_file_p1)) | ||
409 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Successfully removed existing certificate file `%s'\n",cert_file_p1); | ||
410 | else | ||
411 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to remove certfile `%s'\n",cert_file_p1); | ||
412 | } | ||
413 | |||
414 | if (0 == stat (key_file_p1, &sbuf )) | ||
415 | { | ||
416 | if (0 == remove(key_file_p1)) | ||
417 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Successfully removed private key file `%s'\n",key_file_p1); | ||
418 | else | ||
419 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to private key file `%s'\n",key_file_p1); | ||
420 | } | ||
421 | |||
422 | if (0 == stat (cert_file_p2, &sbuf )) | ||
423 | { | ||
424 | if (0 == remove(cert_file_p2)) | ||
425 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Successfully removed existing certificate file `%s'\n",cert_file_p2); | ||
426 | else | ||
427 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to remove certfile `%s'\n",cert_file_p2); | ||
428 | } | ||
429 | |||
430 | if (0 == stat (key_file_p2, &sbuf )) | ||
431 | { | ||
432 | if (0 == remove(key_file_p2)) | ||
433 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Successfully removed private key file `%s'\n",key_file_p2); | ||
434 | else | ||
435 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to private key file `%s'\n",key_file_p2); | ||
436 | } | ||
437 | GNUNET_free(key_file_p1); | ||
438 | GNUNET_free(key_file_p2); | ||
439 | GNUNET_free(cert_file_p1); | ||
440 | GNUNET_free(cert_file_p2); | ||
441 | } | ||
442 | return ok; | 368 | return ok; |
443 | } | 369 | } |
444 | 370 | ||