aboutsummaryrefslogtreecommitdiff
path: root/src/nat/nat_api.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-11-30 09:51:25 +0100
committerChristian Grothoff <christian@grothoff.org>2016-11-30 09:51:25 +0100
commit1466de299c038c5ef738271bd8040276f029e695 (patch)
tree50dfaa6cb9dadd31a1693aa3855686248161e6f4 /src/nat/nat_api.c
parent738cbe38dec2f275994c822631bf3aba02a6e6d0 (diff)
downloadgnunet-1466de299c038c5ef738271bd8040276f029e695.tar.gz
gnunet-1466de299c038c5ef738271bd8040276f029e695.zip
decided to keep NAT test logic in client library
Diffstat (limited to 'src/nat/nat_api.c')
-rw-r--r--src/nat/nat_api.c142
1 files changed, 0 insertions, 142 deletions
diff --git a/src/nat/nat_api.c b/src/nat/nat_api.c
index 4c324376b..cab2b657e 100644
--- a/src/nat/nat_api.c
+++ b/src/nat/nat_api.c
@@ -693,148 +693,6 @@ GNUNET_NAT_unregister (struct GNUNET_NAT_Handle *nh)
693} 693}
694 694
695 695
696/**
697 * Handle to a NAT test.
698 */
699struct GNUNET_NAT_Test
700{
701
702 /**
703 * Configuration we use.
704 */
705 const struct GNUNET_CONFIGURATION_Handle *cfg;
706
707 /**
708 * Message queue for communicating with the NAT service.
709 */
710 struct GNUNET_MQ_Handle *mq;
711
712 /**
713 * Function called to report success or failure for
714 * NAT configuration test.
715 */
716 GNUNET_NAT_TestCallback cb;
717
718 /**
719 * Closure for @e cb.
720 */
721 void *cb_cls;
722
723};
724
725
726/**
727 * Handle result for a NAT test from the service.
728 *
729 * @param cls our `struct GNUNET_NAT_Test *`
730 * @param rm message with the result of the test
731 */
732static void
733handle_test_result (void *cls,
734 const struct GNUNET_NAT_TestResultMessage *rm)
735{
736 struct GNUNET_NAT_Test *tst = cls;
737 enum GNUNET_NAT_StatusCode sc;
738
739 sc = (enum GNUNET_NAT_StatusCode) ntohl (rm->status_code);
740 tst->cb (tst->cb_cls,
741 sc);
742 GNUNET_NAT_test_stop (tst);
743}
744
745
746/**
747 * Handle queue errors by reporting test failure.
748 *
749 * @param cls the `struct GNUNET_NAT_Test *`
750 * @param error details about the error
751 */
752static void
753tst_error_handler (void *cls,
754 enum GNUNET_MQ_Error error)
755{
756 struct GNUNET_NAT_Test *tst = cls;
757
758 tst->cb (tst->cb_cls,
759 GNUNET_NAT_ERROR_IPC_FAILURE);
760 GNUNET_NAT_test_stop (tst);
761}
762
763
764/**
765 * Start testing if NAT traversal works using the given configuration
766 * (IPv4-only). The transport adapters should be down while using
767 * this function.
768 *
769 * @param cfg configuration for the NAT traversal
770 * @param proto protocol to test, i.e. IPPROTO_TCP or IPPROTO_UDP
771 * @param bind_ip IPv4 address to bind to
772 * @param bnd_port port to bind to, 0 to test connection reversal
773 * @param extern_ip IPv4 address to externally advertise
774 * @param extern_port externally advertised port to use
775 * @param report function to call with the result of the test
776 * @param report_cls closure for @a report
777 * @return handle to cancel NAT test
778 */
779struct GNUNET_NAT_Test *
780GNUNET_NAT_test_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
781 uint8_t proto,
782 struct in_addr bind_ip,
783 uint16_t bnd_port,
784 struct in_addr extern_ip,
785 uint16_t extern_port,
786 GNUNET_NAT_TestCallback report,
787 void *report_cls)
788{
789 struct GNUNET_NAT_Test *tst = GNUNET_new (struct GNUNET_NAT_Test);
790 struct GNUNET_MQ_MessageHandler handlers[] = {
791 GNUNET_MQ_hd_fixed_size (test_result,
792 GNUNET_MESSAGE_TYPE_NAT_TEST_RESULT,
793 struct GNUNET_NAT_TestResultMessage,
794 tst),
795 GNUNET_MQ_handler_end ()
796 };
797 struct GNUNET_MQ_Envelope *env;
798 struct GNUNET_NAT_RequestTestMessage *req;
799
800 tst->cb = report;
801 tst->cb_cls = report_cls;
802 tst->mq = GNUNET_CLIENT_connecT (cfg,
803 "nat",
804 handlers,
805 &tst_error_handler,
806 tst);
807 if (NULL == tst->mq)
808 {
809 GNUNET_break (0);
810 GNUNET_free (tst);
811 return NULL;
812 }
813 env = GNUNET_MQ_msg (req,
814 GNUNET_MESSAGE_TYPE_NAT_REQUEST_TEST);
815 req->bind_port = htons (bnd_port);
816 req->extern_port = htons (extern_port);
817 req->bind_ip = bind_ip;
818 req->extern_ip = extern_ip;
819 req->proto = proto;
820 GNUNET_MQ_send (tst->mq,
821 env);
822 return tst;
823}
824
825
826/**
827 * Stop an active NAT test.
828 *
829 * @param tst test to stop.
830 */
831void
832GNUNET_NAT_test_stop (struct GNUNET_NAT_Test *tst)
833{
834 GNUNET_MQ_destroy (tst->mq);
835 GNUNET_free (tst);
836}
837
838 696
839/** 697/**
840 * Handle to auto-configuration in progress. 698 * Handle to auto-configuration in progress.