gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r38197 - gnunet/src/nat


From: gnunet
Subject: [GNUnet-SVN] r38197 - gnunet/src/nat
Date: Mon, 24 Oct 2016 23:32:23 +0200

Author: grothoff
Date: 2016-10-24 23:32:22 +0200 (Mon, 24 Oct 2016)
New Revision: 38197

Modified:
   gnunet/src/nat/nat_api.c
Log:
finish (untested) new NAT client library

Modified: gnunet/src/nat/nat_api.c
===================================================================
--- gnunet/src/nat/nat_api.c    2016-10-24 21:14:02 UTC (rev 38196)
+++ gnunet/src/nat/nat_api.c    2016-10-24 21:32:22 UTC (rev 38197)
@@ -917,8 +917,35 @@
                    const struct GNUNET_NAT_AutoconfigResultMessage *res)
 {
   struct GNUNET_NAT_AutoHandle *ah = cls;
+  size_t left;
+  struct GNUNET_CONFIGURATION_Handle *cfg;
+  enum GNUNET_NAT_Type type
+    = (enum GNUNET_NAT_Type) ntohl (res->type);
+  enum GNUNET_NAT_StatusCode status
+    = (enum GNUNET_NAT_StatusCode) ntohl (res->status_code);
 
-  GNUNET_break (0);
+  left = ntohs (res->header.size) - sizeof (*res);
+  cfg = GNUNET_CONFIGURATION_create ();
+  if (GNUNET_OK !=
+      GNUNET_CONFIGURATION_deserialize (cfg,
+                                       (const char *) &res[1],
+                                       left,
+                                       GNUNET_NO))
+  {
+    GNUNET_break (0);
+    ah->arc (ah->arc_cls,
+            NULL,
+            GNUNET_NAT_ERROR_IPC_FAILURE,
+            type);
+  }
+  else
+  {
+    ah->arc (ah->arc_cls,
+            cfg,
+            status,
+            type);
+  }
+  GNUNET_CONFIGURATION_destroy (cfg);
   GNUNET_NAT_autoconfig_cancel (ah);
 }
 
@@ -967,8 +994,18 @@
   };
   struct GNUNET_MQ_Envelope *env;
   struct GNUNET_NAT_AutoconfigRequestMessage *req;
+  char *buf;
+  size_t size;
 
-  ah->cfg = cfg;
+  buf = GNUNET_CONFIGURATION_serialize (cfg,
+                                       &size);
+  if (size > GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (*req))
+  {
+    GNUNET_break (0);
+    GNUNET_free (buf);
+    GNUNET_free (ah);
+    return NULL;
+  }
   ah->arc = cb;
   ah->arc_cls = cb_cls;
   ah->mq = GNUNET_CLIENT_connecT (cfg,
@@ -979,12 +1016,17 @@
   if (NULL == ah->mq)
   {
     GNUNET_break (0);
+    GNUNET_free (buf);
     GNUNET_free (ah);
     return NULL;
   }
   env = GNUNET_MQ_msg_extra (req,
-                            0,
+                            size,
                             GNUNET_MESSAGE_TYPE_NAT_REQUEST_AUTO_CFG);
+  GNUNET_memcpy (&req[1],
+                buf,
+                size);
+  GNUNET_free (buf);
   GNUNET_MQ_send (ah->mq,
                  env);
   return ah;




reply via email to

[Prev in Thread] Current Thread [Next in Thread]