aboutsummaryrefslogtreecommitdiff
path: root/src/transport
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2017-01-07 16:28:52 +0100
committerChristian Grothoff <christian@grothoff.org>2017-01-07 16:28:52 +0100
commitaf3af9eee2a0e4b2791d8c5f6b60d3eb943a1be2 (patch)
treee4bed0d5a4b0a21b8b721bcb67712f55977369d3 /src/transport
parentc6bf6b89b5c1556590eadc3d64676d2f023e6da4 (diff)
downloadgnunet-af3af9eee2a0e4b2791d8c5f6b60d3eb943a1be2.tar.gz
gnunet-af3af9eee2a0e4b2791d8c5f6b60d3eb943a1be2.zip
remove dependency on old NAT logic from gnunet-transport
Diffstat (limited to 'src/transport')
-rw-r--r--src/transport/Makefile.am1
-rw-r--r--src/transport/gnunet-transport.c244
2 files changed, 10 insertions, 235 deletions
diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am
index 57ea18493..8f2df40a1 100644
--- a/src/transport/Makefile.am
+++ b/src/transport/Makefile.am
@@ -245,7 +245,6 @@ gnunet_transport_SOURCES = \
245 gnunet-transport.c 245 gnunet-transport.c
246gnunet_transport_LDADD = \ 246gnunet_transport_LDADD = \
247 libgnunettransport.la \ 247 libgnunettransport.la \
248 $(top_builddir)/src/nat/libgnunetnat.la \
249 $(top_builddir)/src/hello/libgnunethello.la \ 248 $(top_builddir)/src/hello/libgnunethello.la \
250 $(top_builddir)/src/util/libgnunetutil.la \ 249 $(top_builddir)/src/util/libgnunetutil.la \
251 $(GN_LIBINTL) 250 $(GN_LIBINTL)
diff --git a/src/transport/gnunet-transport.c b/src/transport/gnunet-transport.c
index c5eb58361..fcfc94ac8 100644
--- a/src/transport/gnunet-transport.c
+++ b/src/transport/gnunet-transport.c
@@ -23,9 +23,6 @@
23 * @brief Tool to help configure, measure and control the transport subsystem. 23 * @brief Tool to help configure, measure and control the transport subsystem.
24 * @author Christian Grothoff 24 * @author Christian Grothoff
25 * @author Nathan Evans 25 * @author Nathan Evans
26 *
27 * This utility can be used to test if a transport mechanism for
28 * GNUnet is properly configured.
29 */ 26 */
30#include "platform.h" 27#include "platform.h"
31#include "gnunet_util_lib.h" 28#include "gnunet_util_lib.h"
@@ -33,13 +30,6 @@
33#include "gnunet_protocols.h" 30#include "gnunet_protocols.h"
34#include "gnunet_transport_service.h" 31#include "gnunet_transport_service.h"
35#include "gnunet_transport_core_service.h" 32#include "gnunet_transport_core_service.h"
36#include "gnunet_nat_lib.h"
37
38/**
39 * How long do we wait for the NAT test to report success?
40 * Should match NAT_SERVER_TIMEOUT in 'nat_test.c'.
41 */
42#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 20)
43 33
44/** 34/**
45 * Timeout for a name resolution 35 * Timeout for a name resolution
@@ -172,49 +162,6 @@ struct PeerResolutionContext
172 162
173 163
174/** 164/**
175 * Context for a plugin test.
176 */
177struct TestContext
178{
179 /**
180 * Previous in DLL
181 */
182 struct TestContext *prev;
183
184 /**
185 * Next in DLL
186 */
187 struct TestContext *next;
188
189 /**
190 * Handle to the active NAT test.
191 */
192 struct GNUNET_NAT_Test *tst;
193
194 /**
195 * Task identifier for the timeout.
196 */
197 struct GNUNET_SCHEDULER_Task *tsk;
198
199 /**
200 * Name of plugin under test.
201 */
202 char *name;
203
204 /**
205 * Bound port
206 */
207 unsigned long long bnd_port;
208
209 /**
210 * Advertised ports
211 */
212 unsigned long long adv_port;
213
214};
215
216
217/**
218 * Benchmarking block size in KB 165 * Benchmarking block size in KB
219 */ 166 */
220#define BLOCKSIZE 4 167#define BLOCKSIZE 4
@@ -265,11 +212,6 @@ static int iterate_connections;
265static int iterate_all; 212static int iterate_all;
266 213
267/** 214/**
268 * Option -t.
269 */
270static int test_configuration;
271
272/**
273 * Option -c. 215 * Option -c.
274 */ 216 */
275static int monitor_connects; 217static int monitor_connects;
@@ -366,16 +308,6 @@ struct GNUNET_OS_Process *resolver;
366static unsigned int address_resolutions; 308static unsigned int address_resolutions;
367 309
368/** 310/**
369 * DLL for NAT Test Contexts: head
370 */
371static struct TestContext *head;
372
373/**
374 * DLL for NAT Test Contexts: tail
375 */
376static struct TestContext *tail;
377
378/**
379 * DLL: head of validation resolution entries 311 * DLL: head of validation resolution entries
380 */ 312 */
381static struct ValidationResolutionContext *vc_head; 313static struct ValidationResolutionContext *vc_head;
@@ -553,11 +485,13 @@ operation_timeout (void *cls)
553 _("Failed to resolve address for peer `%s'\n"), 485 _("Failed to resolve address for peer `%s'\n"),
554 GNUNET_i2s (&cur->addrcp->peer)); 486 GNUNET_i2s (&cur->addrcp->peer));
555 487
556 GNUNET_CONTAINER_DLL_remove(rc_head, rc_tail, cur); 488 GNUNET_CONTAINER_DLL_remove(rc_head,
489 rc_tail,
490 cur);
557 GNUNET_TRANSPORT_address_to_string_cancel (cur->asc); 491 GNUNET_TRANSPORT_address_to_string_cancel (cur->asc);
558 GNUNET_free(cur->transport); 492 GNUNET_free (cur->transport);
559 GNUNET_free(cur->addrcp); 493 GNUNET_free (cur->addrcp);
560 GNUNET_free(cur); 494 GNUNET_free (cur);
561 495
562 } 496 }
563 FPRINTF (stdout, 497 FPRINTF (stdout,
@@ -570,158 +504,6 @@ operation_timeout (void *cls)
570} 504}
571 505
572 506
573static void
574run_nat_test (void);
575
576
577/**
578 * Display the result of the test.
579 *
580 * @param tc test context
581 * @param result #GNUNET_YES on success
582 */
583static void
584display_test_result (struct TestContext *tc,
585 enum GNUNET_NAT_StatusCode result)
586{
587 FPRINTF (stderr,
588 _("NAT plugin `%s' reports: %s\n"),
589 tc->name,
590 GNUNET_NAT_status2string (result));
591 if (NULL != tc->tsk)
592 {
593 GNUNET_SCHEDULER_cancel (tc->tsk);
594 tc->tsk = NULL;
595 }
596 if (NULL != tc->tst)
597 {
598 GNUNET_NAT_test_stop (tc->tst);
599 tc->tst = NULL;
600 }
601
602 GNUNET_CONTAINER_DLL_remove (head, tail, tc);
603 GNUNET_free (tc->name);
604 GNUNET_free (tc);
605
606 if ((NULL == head) && (NULL != resolver))
607 {
608 GNUNET_break (0 == GNUNET_OS_process_kill (resolver,
609 GNUNET_TERM_SIG));
610 GNUNET_OS_process_destroy (resolver);
611 resolver = NULL;
612 }
613 if (NULL != head)
614 run_nat_test ();
615}
616
617
618/**
619 * Function called by NAT to report the outcome of the nat-test.
620 * Clean up and update GUI.
621 *
622 * @param cls test context
623 * @param result status code
624 */
625static void
626result_callback (void *cls,
627 enum GNUNET_NAT_StatusCode result)
628{
629 struct TestContext *tc = cls;
630
631 display_test_result (tc,
632 result);
633}
634
635
636static void
637run_nat_test ()
638{
639 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
640 "Running test for plugin `%s' using bind port %u and advertised port %u \n",
641 head->name,
642 (uint16_t) head->bnd_port,
643 (uint16_t) head->adv_port);
644
645 head->tst = GNUNET_NAT_test_start (cfg,
646 (0 == strcasecmp (head->name, "udp"))
647 ? GNUNET_NO : GNUNET_YES,
648 (uint16_t) head->bnd_port,
649 (uint16_t) head->adv_port,
650 TIMEOUT,
651 &result_callback, head);
652}
653
654
655/**
656 * Test our plugin's configuration (NAT traversal, etc.).
657 *
658 * @param cfg configuration to test
659 */
660static void
661do_test_configuration (const struct GNUNET_CONFIGURATION_Handle *cfg)
662{
663 char *plugins;
664 char *tok;
665 unsigned long long bnd_port;
666 unsigned long long adv_port;
667 struct TestContext *tc;
668 char *binary;
669
670 if (GNUNET_OK
671 != GNUNET_CONFIGURATION_get_value_string (cfg, "transport", "plugins",
672 &plugins))
673 {
674 FPRINTF (stderr, "%s", _
675 ("No transport plugins configured, peer will never communicate\n"));
676 ret = 4;
677 return;
678 }
679
680 for (tok = strtok (plugins, " "); tok != NULL ; tok = strtok (NULL, " "))
681 {
682 char section[12 + strlen (tok)];
683 GNUNET_snprintf (section, sizeof(section), "transport-%s", tok);
684 if (GNUNET_OK
685 != GNUNET_CONFIGURATION_get_value_number (cfg, section, "PORT",
686 &bnd_port))
687 {
688 FPRINTF (stderr,
689 _("No port configured for plugin `%s', cannot test it\n"), tok);
690 continue;
691 }
692 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, section,
693 "ADVERTISED_PORT", &adv_port))
694 adv_port = bnd_port;
695
696 tc = GNUNET_new (struct TestContext);
697 tc->name = GNUNET_strdup (tok);
698 tc->adv_port = adv_port;
699 tc->bnd_port = bnd_port;
700 GNUNET_CONTAINER_DLL_insert_tail (head, tail, tc);
701 }
702 GNUNET_free(plugins);
703
704 if ((NULL != head) && (NULL == resolver))
705 {
706 binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-resolver");
707 resolver = GNUNET_OS_start_process (GNUNET_YES,
708 GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
709 NULL, NULL, NULL,
710 binary,
711 "gnunet-service-resolver", NULL);
712 if (NULL == resolver)
713 {
714 FPRINTF (stderr, _("Failed to start resolver!\n"));
715 return;
716 }
717
718 GNUNET_free(binary);
719 GNUNET_RESOLVER_connect (cfg);
720 run_nat_test ();
721 }
722}
723
724
725/** 507/**
726 * Function called to notify a client about the socket 508 * Function called to notify a client about the socket
727 * begin ready to queue more data. Sends another message. 509 * begin ready to queue more data. Sends another message.
@@ -1041,7 +823,9 @@ process_peer_string (void *cls,
1041 } 823 }
1042 GNUNET_free (rc->transport); 824 GNUNET_free (rc->transport);
1043 GNUNET_free (rc->addrcp); 825 GNUNET_free (rc->addrcp);
1044 GNUNET_CONTAINER_DLL_remove (rc_head, rc_tail, rc); 826 GNUNET_CONTAINER_DLL_remove (rc_head,
827 rc_tail,
828 rc);
1045 GNUNET_free (rc); 829 GNUNET_free (rc);
1046 if ((0 == address_resolutions) && (iterate_connections)) 830 if ((0 == address_resolutions) && (iterate_connections))
1047 { 831 {
@@ -1461,11 +1245,6 @@ run (void *cls,
1461 ret = 1; 1245 ret = 1;
1462 1246
1463 cfg = (struct GNUNET_CONFIGURATION_Handle *) mycfg; 1247 cfg = (struct GNUNET_CONFIGURATION_Handle *) mycfg;
1464 if (test_configuration)
1465 {
1466 do_test_configuration (cfg);
1467 return;
1468 }
1469 if ( (NULL != cpid) && 1248 if ( (NULL != cpid) &&
1470 (GNUNET_OK != 1249 (GNUNET_OK !=
1471 GNUNET_CRYPTO_eddsa_public_key_from_string (cpid, 1250 GNUNET_CRYPTO_eddsa_public_key_from_string (cpid,
@@ -1691,9 +1470,6 @@ main (int argc,
1691 { 's', "send", NULL, gettext_noop 1470 { 's', "send", NULL, gettext_noop
1692 ("send data for benchmarking to the other peer (until CTRL-C)"), 0, 1471 ("send data for benchmarking to the other peer (until CTRL-C)"), 0,
1693 &GNUNET_GETOPT_set_one, &benchmark_send }, 1472 &GNUNET_GETOPT_set_one, &benchmark_send },
1694 { 't', "test", NULL,
1695 gettext_noop ("test transport configuration (involves external server)"),
1696 0, &GNUNET_GETOPT_set_one, &test_configuration },
1697 GNUNET_GETOPT_OPTION_VERBOSE (&verbosity), 1473 GNUNET_GETOPT_OPTION_VERBOSE (&verbosity),
1698 GNUNET_GETOPT_OPTION_END 1474 GNUNET_GETOPT_OPTION_END
1699 }; 1475 };
@@ -1706,7 +1482,7 @@ main (int argc,
1706 gettext_noop ("Direct access to transport service."), 1482 gettext_noop ("Direct access to transport service."),
1707 options, 1483 options,
1708 &run, NULL); 1484 &run, NULL);
1709 GNUNET_free((void *) argv); 1485 GNUNET_free ((void *) argv);
1710 if (GNUNET_OK == res) 1486 if (GNUNET_OK == res)
1711 return ret; 1487 return ret;
1712 return 1; 1488 return 1;