aboutsummaryrefslogtreecommitdiff
path: root/src/nat/nat_api.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-10-24 21:14:02 +0000
committerChristian Grothoff <christian@grothoff.org>2016-10-24 21:14:02 +0000
commit3943f53ff830af8f856114969a7f59127d4e0366 (patch)
treeddc52a31b87b4a624e6829959dc58e117a36a3c4 /src/nat/nat_api.c
parent9a1762b01cc122bd15817f267f6d08fd0f96b73e (diff)
downloadgnunet-3943f53ff830af8f856114969a7f59127d4e0366.tar.gz
gnunet-3943f53ff830af8f856114969a7f59127d4e0366.zip
towards implementing autoconfig part of NAT lib
Diffstat (limited to 'src/nat/nat_api.c')
-rw-r--r--src/nat/nat_api.c124
1 files changed, 120 insertions, 4 deletions
diff --git a/src/nat/nat_api.c b/src/nat/nat_api.c
index e0c83f41e..1dde627aa 100644
--- a/src/nat/nat_api.c
+++ b/src/nat/nat_api.c
@@ -715,7 +715,7 @@ handle_test_result (void *cls,
715 715
716 716
717/** 717/**
718 * Handle queue errors by reconnecting to NAT. 718 * Handle queue errors by reporting test failure.
719 * 719 *
720 * @param cls the `struct GNUNET_NAT_Test *` 720 * @param cls the `struct GNUNET_NAT_Test *`
721 * @param error details about the error 721 * @param error details about the error
@@ -845,8 +845,101 @@ struct GNUNET_NAT_AutoHandle
845const char * 845const char *
846GNUNET_NAT_status2string (enum GNUNET_NAT_StatusCode err) 846GNUNET_NAT_status2string (enum GNUNET_NAT_StatusCode err)
847{ 847{
848 switch (err)
849 {
850 case GNUNET_NAT_ERROR_SUCCESS:
851 return _ ("Operation Successful");
852 case GNUNET_NAT_ERROR_IPC_FAILURE:
853 return _ ("Internal Failure (IPC, ...)");
854 case GNUNET_NAT_ERROR_INTERNAL_NETWORK_ERROR:
855 return _ ("Failure in network subsystem, check permissions.");
856 case GNUNET_NAT_ERROR_TIMEOUT:
857 return _ ("Encountered timeout while performing operation");
858 case GNUNET_NAT_ERROR_NOT_ONLINE:
859 return _ ("detected that we are offline");
860 case GNUNET_NAT_ERROR_UPNPC_NOT_FOUND:
861 return _ ("`upnpc` command not found");
862 case GNUNET_NAT_ERROR_UPNPC_FAILED:
863 return _ ("Failed to run `upnpc` command");
864 case GNUNET_NAT_ERROR_UPNPC_TIMEOUT:
865 return _ ("`upnpc' command took too long, process killed");
866 case GNUNET_NAT_ERROR_UPNPC_PORTMAP_FAILED:
867 return _ ("`upnpc' command failed to establish port mapping");
868 case GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_NOT_FOUND:
869 return _ ("`external-ip' command not found");
870 case GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_FAILED:
871 return _ ("Failed to run `external-ip` command");
872 case GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_OUTPUT_INVALID:
873 return _ ("`external-ip' command output invalid");
874 case GNUNET_NAT_ERROR_EXTERNAL_IP_ADDRESS_INVALID:
875 return _ ("no valid address was returned by `external-ip'");
876 case GNUNET_NAT_ERROR_NO_VALID_IF_IP_COMBO:
877 return _ ("Could not determine interface with internal/local network address");
878 case GNUNET_NAT_ERROR_HELPER_NAT_SERVER_NOT_FOUND:
879 return _ ("No functioning gnunet-helper-nat-server installation found");
880 case GNUNET_NAT_ERROR_NAT_TEST_START_FAILED:
881 return _ ("NAT test could not be initialized");
882 case GNUNET_NAT_ERROR_NAT_TEST_TIMEOUT:
883 return _ ("NAT test timeout reached");
884 case GNUNET_NAT_ERROR_NAT_REGISTER_FAILED:
885 return _ ("could not register NAT");
886 case GNUNET_NAT_ERROR_HELPER_NAT_CLIENT_NOT_FOUND:
887 return _ ("No working gnunet-helper-nat-client installation found");
888 default:
889 return "unknown status code";
890 }
891}
892
893
894/**
895 * Check result from autoconfiguration attempt.
896 *
897 * @param cls the `struct GNUNET_NAT_AutoHandle`
898 * @param res the result
899 * @return #GNUNET_OK if @a res is well-formed (always for now)
900 */
901static int
902check_auto_result (void *cls,
903 const struct GNUNET_NAT_AutoconfigResultMessage *res)
904{
905 return GNUNET_OK;
906}
907
908
909/**
910 * Handle result from autoconfiguration attempt.
911 *
912 * @param cls the `struct GNUNET_NAT_AutoHandle`
913 * @param res the result
914 */
915static void
916handle_auto_result (void *cls,
917 const struct GNUNET_NAT_AutoconfigResultMessage *res)
918{
919 struct GNUNET_NAT_AutoHandle *ah = cls;
920
848 GNUNET_break (0); 921 GNUNET_break (0);
849 return NULL; 922 GNUNET_NAT_autoconfig_cancel (ah);
923}
924
925
926/**
927 * Handle queue errors by reporting autoconfiguration failure.
928 *
929 * @param cls the `struct GNUNET_NAT_AutoHandle *`
930 * @param error details about the error
931 */
932static void
933ah_error_handler (void *cls,
934 enum GNUNET_MQ_Error error)
935{
936 struct GNUNET_NAT_AutoHandle *ah = cls;
937
938 ah->arc (ah->arc_cls,
939 NULL,
940 GNUNET_NAT_ERROR_IPC_FAILURE,
941 GNUNET_NAT_TYPE_UNKNOWN);
942 GNUNET_NAT_autoconfig_cancel (ah);
850} 943}
851 944
852 945
@@ -865,11 +958,35 @@ GNUNET_NAT_autoconfig_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
865 void *cb_cls) 958 void *cb_cls)
866{ 959{
867 struct GNUNET_NAT_AutoHandle *ah = GNUNET_new (struct GNUNET_NAT_AutoHandle); 960 struct GNUNET_NAT_AutoHandle *ah = GNUNET_new (struct GNUNET_NAT_AutoHandle);
961 struct GNUNET_MQ_MessageHandler handlers[] = {
962 GNUNET_MQ_hd_var_size (auto_result,
963 GNUNET_MESSAGE_TYPE_NAT_AUTO_CFG_RESULT,
964 struct GNUNET_NAT_AutoconfigResultMessage,
965 ah),
966 GNUNET_MQ_handler_end ()
967 };
968 struct GNUNET_MQ_Envelope *env;
969 struct GNUNET_NAT_AutoconfigRequestMessage *req;
868 970
869 ah->cfg = cfg; 971 ah->cfg = cfg;
870 ah->arc = cb; 972 ah->arc = cb;
871 ah->arc_cls = cb_cls; 973 ah->arc_cls = cb_cls;
872 GNUNET_break (0); 974 ah->mq = GNUNET_CLIENT_connecT (cfg,
975 "nat",
976 handlers,
977 &ah_error_handler,
978 ah);
979 if (NULL == ah->mq)
980 {
981 GNUNET_break (0);
982 GNUNET_free (ah);
983 return NULL;
984 }
985 env = GNUNET_MQ_msg_extra (req,
986 0,
987 GNUNET_MESSAGE_TYPE_NAT_REQUEST_AUTO_CFG);
988 GNUNET_MQ_send (ah->mq,
989 env);
873 return ah; 990 return ah;
874} 991}
875 992
@@ -882,7 +999,6 @@ GNUNET_NAT_autoconfig_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
882void 999void
883GNUNET_NAT_autoconfig_cancel (struct GNUNET_NAT_AutoHandle *ah) 1000GNUNET_NAT_autoconfig_cancel (struct GNUNET_NAT_AutoHandle *ah)
884{ 1001{
885 GNUNET_break (0);
886 GNUNET_MQ_destroy (ah->mq); 1002 GNUNET_MQ_destroy (ah->mq);
887 GNUNET_free (ah); 1003 GNUNET_free (ah);
888} 1004}