aboutsummaryrefslogtreecommitdiff
path: root/src/transport/test_transport_ats.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2011-03-29 19:46:58 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2011-03-29 19:46:58 +0000
commitff5e94e712ab79a7c4347450f05f52986a22391a (patch)
treec13124325039add4621fd33df786c328f2a73989 /src/transport/test_transport_ats.c
parentea7acd3217a45c4d3e6794ca51252cc4be3c36e8 (diff)
downloadgnunet-ff5e94e712ab79a7c4347450f05f52986a22391a.tar.gz
gnunet-ff5e94e712ab79a7c4347450f05f52986a22391a.zip
more changes
Diffstat (limited to 'src/transport/test_transport_ats.c')
-rw-r--r--src/transport/test_transport_ats.c262
1 files changed, 19 insertions, 243 deletions
diff --git a/src/transport/test_transport_ats.c b/src/transport/test_transport_ats.c
index 1f7c74ec0..a8012da29 100644
--- a/src/transport/test_transport_ats.c
+++ b/src/transport/test_transport_ats.c
@@ -18,7 +18,7 @@
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20/** 20/**
21 * @file transport/test_transport_ats.c 21 * @file transport/test_transport_api.c
22 * @brief base test case for transport implementations 22 * @brief base test case for transport implementations
23 * 23 *
24 * This test case serves as a base for tcp, udp, and udp-nat 24 * This test case serves as a base for tcp, udp, and udp-nat
@@ -34,9 +34,7 @@
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"
38#include "transport.h" 37#include "transport.h"
39#include "gauger.h"
40 38
41#define VERBOSE GNUNET_NO 39#define VERBOSE GNUNET_NO
42 40
@@ -47,12 +45,12 @@
47/** 45/**
48 * How long until we give up on transmitting the message? 46 * How long until we give up on transmitting the message?
49 */ 47 */
50#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 20) 48#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
51 49
52/** 50/**
53 * How long until we give up on transmitting the message? 51 * How long until we give up on transmitting the message?
54 */ 52 */
55#define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) 53#define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
56 54
57#define MTYPE 12345 55#define MTYPE 12345
58 56
@@ -61,7 +59,6 @@ struct PeerContext
61 struct GNUNET_CONFIGURATION_Handle *cfg; 59 struct GNUNET_CONFIGURATION_Handle *cfg;
62 struct GNUNET_TRANSPORT_Handle *th; 60 struct GNUNET_TRANSPORT_Handle *th;
63 struct GNUNET_PeerIdentity id; 61 struct GNUNET_PeerIdentity id;
64 struct GNUNET_STATISTICS_Handle *stats;
65#if START_ARM 62#if START_ARM
66 struct GNUNET_OS_Process *arm_proc; 63 struct GNUNET_OS_Process *arm_proc;
67#endif 64#endif
@@ -69,37 +66,14 @@ struct PeerContext
69 66
70static struct PeerContext p1; 67static struct PeerContext p1;
71 68
72/**
73 * Handle for reporting statistics.
74 */
75
76
77
78static struct PeerContext p2; 69static struct PeerContext p2;
79 70
80static int ok; 71static int ok;
81 72
82static int is_tcp;
83
84static int is_tcp_nat;
85
86static int is_udp;
87
88static int is_unix;
89
90static int is_udp_nat;
91
92static int is_http;
93
94static int is_https;
95 73
96static int is_multi_protocol;
97
98static int is_wlan;
99 74
100static GNUNET_SCHEDULER_TaskIdentifier die_task; 75static GNUNET_SCHEDULER_TaskIdentifier die_task;
101 76
102
103#if VERBOSE 77#if VERBOSE
104#define OKPP do { ok++; fprintf (stderr, "Now at stage %u at %s:%u\n", ok, __FILE__, __LINE__); } while (0) 78#define OKPP do { ok++; fprintf (stderr, "Now at stage %u at %s:%u\n", ok, __FILE__, __LINE__); } while (0)
105#else 79#else
@@ -116,8 +90,7 @@ end ()
116 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from transports!\n"); 90 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from transports!\n");
117 GNUNET_TRANSPORT_disconnect (p1.th); 91 GNUNET_TRANSPORT_disconnect (p1.th);
118 GNUNET_TRANSPORT_disconnect (p2.th); 92 GNUNET_TRANSPORT_disconnect (p2.th);
119 if (p1.stats != NULL) 93
120 GNUNET_STATISTICS_destroy (p1.stats, GNUNET_NO);
121 die_task = GNUNET_SCHEDULER_NO_TASK; 94 die_task = GNUNET_SCHEDULER_NO_TASK;
122 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transports disconnected, returning success!\n"); 95 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transports disconnected, returning success!\n");
123 ok = 0; 96 ok = 0;
@@ -141,11 +114,9 @@ static void
141end_badly () 114end_badly ()
142{ 115{
143 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from transports!\n"); 116 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from transports!\n");
144 //GNUNET_break (0); 117 GNUNET_break (0);
145 GNUNET_TRANSPORT_disconnect (p1.th); 118 GNUNET_TRANSPORT_disconnect (p1.th);
146 if (p1.stats != NULL) 119 GNUNET_TRANSPORT_disconnect (p2.th);
147 GNUNET_STATISTICS_destroy (p1.stats, GNUNET_NO);
148 //GNUNET_TRANSPORT_disconnect (p2.th);
149 ok = 1; 120 ok = 1;
150} 121}
151 122
@@ -170,6 +141,7 @@ notify_receive (void *cls,
170 ntohs (message->size)); 141 ntohs (message->size));
171 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received message from peer (%p)!\n", 142 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received message from peer (%p)!\n",
172 cls); 143 cls);
144 sleep(5);
173 end (); 145 end ();
174} 146}
175 147
@@ -210,6 +182,9 @@ notify_connect (void *cls,
210{ 182{
211 if (cls == &p1) 183 if (cls == &p1)
212 { 184 {
185 GNUNET_SCHEDULER_cancel (die_task);
186 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT_TRANSMIT,
187 &end_badly, NULL);
213 188
214 GNUNET_TRANSPORT_notify_transmit_ready (p1.th, 189 GNUNET_TRANSPORT_notify_transmit_ready (p1.th,
215 &p2.id, 190 &p2.id,
@@ -229,17 +204,6 @@ notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
229 GNUNET_i2s (peer), cls); 204 GNUNET_i2s (peer), cls);
230} 205}
231 206
232int 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
243 207
244static void 208static void
245setup_peer (struct PeerContext *p, const char *cfgname) 209setup_peer (struct PeerContext *p, const char *cfgname)
@@ -254,19 +218,12 @@ setup_peer (struct PeerContext *p, const char *cfgname)
254 "-c", cfgname, NULL); 218 "-c", cfgname, NULL);
255#endif 219#endif
256 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); 220 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
257 p->stats = GNUNET_STATISTICS_create ("transport", p->cfg);
258 GNUNET_assert (p->stats != NULL);
259 GNUNET_assert (GNUNET_OK == GNUNET_STATISTICS_watch (p->stats,"transport","ATS execution time 100 peers", stat_cb, NULL));
260 221
261 p->th = GNUNET_TRANSPORT_connect (p->cfg, 222 p->th = GNUNET_TRANSPORT_connect (p->cfg,
262 NULL, p, 223 NULL, p,
263 &notify_receive, 224 &notify_receive,
264 &notify_connect, &notify_disconnect); 225 &notify_connect, &notify_disconnect);
265 GNUNET_assert (p->th != NULL); 226 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);
270} 227}
271 228
272 229
@@ -332,11 +289,10 @@ run (void *cls,
332 &end_badly, NULL); 289 &end_badly, NULL);
333 290
334 setup_peer (&p1, "test_transport_ats_peer1.conf"); 291 setup_peer (&p1, "test_transport_ats_peer1.conf");
335 //setup_peer (&p2, "test_transport_ats_peer2.conf"); 292 setup_peer (&p2, "test_transport_ats_peer2.conf");
336
337 GNUNET_assert(p1.th != NULL); 293 GNUNET_assert(p1.th != NULL);
338 //GNUNET_assert(p2.th != NULL); 294 GNUNET_assert(p2.th != NULL);
339 return; 295
340 GNUNET_TRANSPORT_get_hello (p1.th, &exchange_hello, &p1); 296 GNUNET_TRANSPORT_get_hello (p1.th, &exchange_hello, &p1);
341} 297}
342 298
@@ -363,121 +319,11 @@ check ()
363 argv, "test-transport-api", "nohelp", 319 argv, "test-transport-api", "nohelp",
364 options, &run, &ok); 320 options, &run, &ok);
365 stop_arm (&p1); 321 stop_arm (&p1);
366 // stop_arm (&p2); 322 stop_arm (&p2);
367
368 return ok; 323 return ok;
369} 324}
370 325
371/**
372 * Return the actual path to a file found in the current
373 * PATH environment variable.
374 *
375 * @param binary the name of the file to find
376 */
377static char *
378get_path_from_PATH (char *binary)
379{
380 char *path;
381 char *pos;
382 char *end;
383 char *buf;
384 const char *p;
385
386 p = getenv ("PATH");
387 if (p == NULL)
388 {
389 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
390 _("PATH environment variable is unset.\n"));
391 return NULL;
392 }
393 path = GNUNET_strdup (p); /* because we write on it */
394 buf = GNUNET_malloc (strlen (path) + 20);
395 pos = path;
396
397 while (NULL != (end = strchr (pos, PATH_SEPARATOR)))
398 {
399 *end = '\0';
400 sprintf (buf, "%s/%s", pos, binary);
401 if (GNUNET_DISK_file_test (buf) == GNUNET_YES)
402 {
403 GNUNET_free (path);
404 return buf;
405 }
406 pos = end + 1;
407 }
408 sprintf (buf, "%s/%s", pos, binary);
409 if (GNUNET_DISK_file_test (buf) == GNUNET_YES)
410 {
411 GNUNET_free (path);
412 return buf;
413 }
414 GNUNET_free (buf);
415 GNUNET_free (path);
416 return NULL;
417}
418
419/**
420 * Check whether the suid bit is set on a file.
421 * Attempts to find the file using the current
422 * PATH environment variable as a search path.
423 *
424 * @param binary the name of the file to check
425 *
426 * @return GNUNET_YES if the binary is found and
427 * can be run properly, GNUNET_NO otherwise
428 */
429static int
430check_gnunet_nat_binary(char *binary)
431{
432 struct stat statbuf;
433 char *p;
434#ifdef MINGW
435 SOCKET rawsock;
436#endif
437 326
438#ifdef MINGW
439 char *binaryexe;
440 GNUNET_asprintf (&binaryexe, "%s.exe", binary);
441 p = get_path_from_PATH (binaryexe);
442 free (binaryexe);
443#else
444 p = get_path_from_PATH (binary);
445#endif
446 if (p == NULL)
447 {
448 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
449 _("Could not find binary `%s' in PATH!\n"),
450 binary);
451 return GNUNET_NO;
452 }
453 if (0 != STAT (p, &statbuf))
454 {
455 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
456 _("stat (%s) failed: %s\n"),
457 p,
458 STRERROR (errno));
459 GNUNET_free (p);
460 return GNUNET_SYSERR;
461 }
462 GNUNET_free (p);
463#ifndef MINGW
464 if ( (0 != (statbuf.st_mode & S_ISUID)) &&
465 (statbuf.st_uid == 0) )
466 return GNUNET_YES;
467 return GNUNET_NO;
468#else
469 rawsock = socket (AF_INET, SOCK_RAW, IPPROTO_ICMP);
470 if (INVALID_SOCKET == rawsock)
471 {
472 DWORD err = GetLastError ();
473 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
474 "socket (AF_INET, SOCK_RAW, IPPROTO_ICMP) have failed! GLE = %d\n", err);
475 return GNUNET_NO; /* not running as administrator */
476 }
477 closesocket (rawsock);
478 return GNUNET_YES;
479#endif
480}
481 327
482int 328int
483main (int argc, char *argv[]) 329main (int argc, char *argv[])
@@ -487,89 +333,19 @@ main (int argc, char *argv[])
487 return GNUNET_SYSERR; 333 return GNUNET_SYSERR;
488#endif 334#endif
489 335
490 GNUNET_log_setup ("test-transport-ats", 336 GNUNET_log_setup ("test-transport-api",
491#if VERBOSE 337#if VERBOSE
492 "DEBUG", 338 "DEBUG",
493#else 339#else
494 "WARNING", 340 "WARNING",
495#endif 341#endif
496 NULL); 342 NULL);
497#ifdef HAVE_LIBGLPK
498 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
499 "GLPK is installed\n");
500#else
501 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
502 "GLPK is not installed\n");
503 return 0;
504
505#endif
506
507 if (strstr(argv[0], "tcp_nat") != NULL)
508 {
509 is_tcp_nat = GNUNET_YES;
510 if (GNUNET_YES != check_gnunet_nat_binary("gnunet-nat-server"))
511 {
512 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
513 "`%s' not properly installed, cannot run NAT test!\n",
514 "gnunet-nat-server");
515 return 0;
516 }
517 }
518 else if (strstr(argv[0], "tcp") != NULL)
519 {
520 is_tcp = GNUNET_YES;
521 }
522 else if (strstr(argv[0], "udp_nat") != NULL)
523 {
524 is_udp_nat = GNUNET_YES;
525 if (GNUNET_YES != check_gnunet_nat_binary("gnunet-nat-server"))
526 {
527 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
528 "`%s' not properly installed, cannot run NAT test!\n",
529 "gnunet-nat-server");
530 return 0;
531 }
532 }
533 else if (strstr(argv[0], "udp") != NULL)
534 {
535 is_udp = GNUNET_YES;
536 }
537 else if (strstr(argv[0], "unix") != NULL)
538 {
539 is_unix = GNUNET_YES;
540 }
541 else if (strstr(argv[0], "https") != NULL)
542 {
543 is_https = GNUNET_YES;
544 }
545 else if (strstr(argv[0], "http") != NULL)
546 {
547 is_http = GNUNET_YES;
548 }
549 else if (strstr(argv[0], "wlan") != NULL)
550 {
551 is_wlan = GNUNET_YES;
552 }
553 else if (strstr(argv[0], "multi") != NULL)
554 {
555 is_multi_protocol = GNUNET_YES;
556 }
557 343
558 ret = check (); 344 ret = check ();
559 if (is_multi_protocol) 345 GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-transport-peer-1");
560 { 346 GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-transport-peer-2");
561 GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-transport-multi-peer-1/");
562 GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-transport-multi-peer-2/");
563 }
564 else
565 {
566 GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-transport-peer-1");
567 GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-transport-peer-2");
568 }
569 347
570 //return ret; 348 return ret;
571 /* GGG */
572 return 0;
573} 349}
574 350
575/* end of test_transport_ats.c */ 351/* end of test_transport_api.c */