aboutsummaryrefslogtreecommitdiff
path: root/src/nat/nat_api.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-10-24 21:32:22 +0000
committerChristian Grothoff <christian@grothoff.org>2016-10-24 21:32:22 +0000
commit5c3a3274ff2298ace3eb53e26401eaf1a1bceb3e (patch)
tree04aba3346bd7900eeac86adf13d1c805c3039ceb /src/nat/nat_api.c
parent3943f53ff830af8f856114969a7f59127d4e0366 (diff)
downloadgnunet-5c3a3274ff2298ace3eb53e26401eaf1a1bceb3e.tar.gz
gnunet-5c3a3274ff2298ace3eb53e26401eaf1a1bceb3e.zip
finish (untested) new NAT client library
Diffstat (limited to 'src/nat/nat_api.c')
-rw-r--r--src/nat/nat_api.c50
1 files changed, 46 insertions, 4 deletions
diff --git a/src/nat/nat_api.c b/src/nat/nat_api.c
index 1dde627aa..e567368d2 100644
--- a/src/nat/nat_api.c
+++ b/src/nat/nat_api.c
@@ -917,8 +917,35 @@ handle_auto_result (void *cls,
917 const struct GNUNET_NAT_AutoconfigResultMessage *res) 917 const struct GNUNET_NAT_AutoconfigResultMessage *res)
918{ 918{
919 struct GNUNET_NAT_AutoHandle *ah = cls; 919 struct GNUNET_NAT_AutoHandle *ah = cls;
920 920 size_t left;
921 GNUNET_break (0); 921 struct GNUNET_CONFIGURATION_Handle *cfg;
922 enum GNUNET_NAT_Type type
923 = (enum GNUNET_NAT_Type) ntohl (res->type);
924 enum GNUNET_NAT_StatusCode status
925 = (enum GNUNET_NAT_StatusCode) ntohl (res->status_code);
926
927 left = ntohs (res->header.size) - sizeof (*res);
928 cfg = GNUNET_CONFIGURATION_create ();
929 if (GNUNET_OK !=
930 GNUNET_CONFIGURATION_deserialize (cfg,
931 (const char *) &res[1],
932 left,
933 GNUNET_NO))
934 {
935 GNUNET_break (0);
936 ah->arc (ah->arc_cls,
937 NULL,
938 GNUNET_NAT_ERROR_IPC_FAILURE,
939 type);
940 }
941 else
942 {
943 ah->arc (ah->arc_cls,
944 cfg,
945 status,
946 type);
947 }
948 GNUNET_CONFIGURATION_destroy (cfg);
922 GNUNET_NAT_autoconfig_cancel (ah); 949 GNUNET_NAT_autoconfig_cancel (ah);
923} 950}
924 951
@@ -967,8 +994,18 @@ GNUNET_NAT_autoconfig_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
967 }; 994 };
968 struct GNUNET_MQ_Envelope *env; 995 struct GNUNET_MQ_Envelope *env;
969 struct GNUNET_NAT_AutoconfigRequestMessage *req; 996 struct GNUNET_NAT_AutoconfigRequestMessage *req;
997 char *buf;
998 size_t size;
970 999
971 ah->cfg = cfg; 1000 buf = GNUNET_CONFIGURATION_serialize (cfg,
1001 &size);
1002 if (size > GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (*req))
1003 {
1004 GNUNET_break (0);
1005 GNUNET_free (buf);
1006 GNUNET_free (ah);
1007 return NULL;
1008 }
972 ah->arc = cb; 1009 ah->arc = cb;
973 ah->arc_cls = cb_cls; 1010 ah->arc_cls = cb_cls;
974 ah->mq = GNUNET_CLIENT_connecT (cfg, 1011 ah->mq = GNUNET_CLIENT_connecT (cfg,
@@ -979,12 +1016,17 @@ GNUNET_NAT_autoconfig_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
979 if (NULL == ah->mq) 1016 if (NULL == ah->mq)
980 { 1017 {
981 GNUNET_break (0); 1018 GNUNET_break (0);
1019 GNUNET_free (buf);
982 GNUNET_free (ah); 1020 GNUNET_free (ah);
983 return NULL; 1021 return NULL;
984 } 1022 }
985 env = GNUNET_MQ_msg_extra (req, 1023 env = GNUNET_MQ_msg_extra (req,
986 0, 1024 size,
987 GNUNET_MESSAGE_TYPE_NAT_REQUEST_AUTO_CFG); 1025 GNUNET_MESSAGE_TYPE_NAT_REQUEST_AUTO_CFG);
1026 GNUNET_memcpy (&req[1],
1027 buf,
1028 size);
1029 GNUNET_free (buf);
988 GNUNET_MQ_send (ah->mq, 1030 GNUNET_MQ_send (ah->mq,
989 env); 1031 env);
990 return ah; 1032 return ah;