tolerate additional IPv4 address now available for gnunet.org
[oweals/gnunet.git] / src / transport / plugin_transport_http_client.c
index 4e0cde998810ae912345bd10ab22d2ba31a9e901..c4d70d4c364ae6209499b00fc0920604990f51c3 100644 (file)
@@ -2,20 +2,20 @@
      This file is part of GNUnet
      Copyright (C) 2002-2014 GNUnet e.V.
 
-     GNUnet is free software; you can redistribute it and/or modify
-     it under the terms of the GNU General Public License as published
-     by the Free Software Foundation; either version 3, or (at your
-     option) any later version.
+     GNUnet is free software: you can redistribute it and/or modify it
+     under the terms of the GNU Affero General Public License as published
+     by the Free Software Foundation, either version 3 of the License,
+     or (at your option) any later version.
 
      GNUnet is distributed in the hope that it will be useful, but
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-     General Public License for more details.
+     Affero General Public License for more details.
+    
+     You should have received a copy of the GNU Affero General Public License
+     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-     You should have received a copy of the GNU General Public License
-     along with GNUnet; see the file COPYING.  If not, write to the
-     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-     Boston, MA 02110-1301, USA.
+     SPDX-License-Identifier: AGPL3.0-or-later
 */
 
 /**
 #include "gnunet_protocols.h"
 #include "gnunet_transport_plugin.h"
 #include "plugin_transport_http_common.h"
-#if HAVE_CURL_CURL_H
-#include <curl/curl.h>
-#elif HAVE_GNURL_CURL_H
-#include <gnurl/curl.h>
-#endif
+/* Just included for the right curl.h */
+#include "gnunet_curl_lib.h"
 
 
 #define LOG(kind,...) GNUNET_log_from(kind, PLUGIN_NAME, __VA_ARGS__)
@@ -221,7 +218,7 @@ struct GNUNET_ATS_Session
   /**
    * Message stream tokenizer for incoming data
    */
-  struct GNUNET_SERVER_MessageStreamTokenizer *msg_tk;
+  struct GNUNET_MessageStreamTokenizer *msg_tk;
 
   /**
    * Session timeout task
@@ -268,7 +265,7 @@ struct GNUNET_ATS_Session
   /**
    * ATS network type.
    */
-  enum GNUNET_ATS_Network_Type scope;
+  enum GNUNET_NetworkType scope;
 };
 
 
@@ -528,7 +525,7 @@ client_delete_session (struct GNUNET_ATS_Session *s)
                           GNUNET_TRANSPORT_SS_DONE);
   if (NULL != s->msg_tk)
   {
-    GNUNET_SERVER_mst_destroy (s->msg_tk);
+    GNUNET_MST_destroy (s->msg_tk);
     s->msg_tk = NULL;
   }
   GNUNET_HELLO_address_free (s->address);
@@ -1061,8 +1058,10 @@ client_send_cb (void *stream,
          "Session %p/request %p: nothing to send, suspending\n",
          s,
          s->put.easyhandle);
-    s->put_disconnect_task = GNUNET_SCHEDULER_add_delayed (PUT_DISCONNECT_TIMEOUT,
-        &client_put_disconnect, s);
+    s->put_disconnect_task
+      = GNUNET_SCHEDULER_add_delayed (PUT_DISCONNECT_TIMEOUT,
+                                     &client_put_disconnect,
+                                     s);
     s->put.state = H_PAUSED;
     return CURL_READFUNC_PAUSE;
   }
@@ -1071,7 +1070,9 @@ client_send_cb (void *stream,
   /* calculate how much fits in buffer */
   len = GNUNET_MIN (msg->size - msg->pos,
                     size * nmemb);
-  GNUNET_memcpy (stream, &msg->buf[msg->pos], len);
+  GNUNET_memcpy (stream,
+                &msg->buf[msg->pos],
+                len);
   msg->pos += len;
   if (msg->pos == msg->size)
   {
@@ -1154,13 +1155,11 @@ client_wake_up (void *cls)
  * Callback for message stream tokenizer
  *
  * @param cls the session
- * @param client not used
  * @param message the message received
  * @return always #GNUNET_OK
  */
 static int
 client_receive_mst_cb (void *cls,
-                       void *client,
                        const struct GNUNET_MessageHeader *message)
 {
   struct GNUNET_ATS_Session *s = cls;
@@ -1270,14 +1269,13 @@ client_receive (void *stream,
     return CURL_WRITEFUNC_PAUSE;
   }
   if (NULL == s->msg_tk)
-    s->msg_tk = GNUNET_SERVER_mst_create (&client_receive_mst_cb,
-                                          s);
-  GNUNET_SERVER_mst_receive (s->msg_tk,
-                             s,
-                             stream,
-                             len,
-                             GNUNET_NO,
-                             GNUNET_NO);
+    s->msg_tk = GNUNET_MST_create (&client_receive_mst_cb,
+                                   s);
+  GNUNET_MST_from_buffer (s->msg_tk,
+                          stream,
+                          len,
+                          GNUNET_NO,
+                          GNUNET_NO);
   return len;
 }
 
@@ -1637,7 +1635,7 @@ client_connect_get (struct GNUNET_ATS_Session *s)
                     CURLOPT_CONNECTTIMEOUT_MS,
                     (long) (HTTP_CLIENT_NOT_VALIDATED_TIMEOUT.rel_value_us / 1000LL));
   curl_easy_setopt (s->get.easyhandle, CURLOPT_BUFFERSIZE,
-                    2 * GNUNET_SERVER_MAX_MESSAGE_SIZE);
+                    2 * GNUNET_MAX_MESSAGE_SIZE);
 #if CURL_TCP_NODELAY
   curl_easy_setopt (ps->recv_endpoint,
                     CURLOPT_TCP_NODELAY,
@@ -1814,7 +1812,7 @@ client_connect_put (struct GNUNET_ATS_Session *s)
                     CURLOPT_CONNECTTIMEOUT_MS,
                     (long) (HTTP_CLIENT_NOT_VALIDATED_TIMEOUT.rel_value_us / 1000LL));
   curl_easy_setopt (s->put.easyhandle, CURLOPT_BUFFERSIZE,
-                    2 * GNUNET_SERVER_MAX_MESSAGE_SIZE);
+                    2 * GNUNET_MAX_MESSAGE_SIZE);
 #if CURL_TCP_NODELAY
   curl_easy_setopt (s->put.easyhandle, CURLOPT_TCP_NODELAY, 1);
 #endif
@@ -1921,7 +1919,7 @@ client_connect (struct GNUNET_ATS_Session *s)
  * @param session the session
  * @return the network type
  */
-static enum GNUNET_ATS_Network_Type
+static enum GNUNET_NetworkType
 http_client_plugin_get_network (void *cls,
                                 struct GNUNET_ATS_Session *session)
 {
@@ -1936,7 +1934,7 @@ http_client_plugin_get_network (void *cls,
  * @param address the address
  * @return the network type
  */
-static enum GNUNET_ATS_Network_Type
+static enum GNUNET_NetworkType
 http_client_plugin_get_network_for_address (void *cls,
                                             const struct GNUNET_HELLO_Address *address)
 {
@@ -1998,7 +1996,7 @@ http_client_plugin_get_session (void *cls,
   struct HTTP_Client_Plugin *plugin = cls;
   struct GNUNET_ATS_Session *s;
   struct sockaddr *sa;
-  enum GNUNET_ATS_Network_Type net_type;
+  enum GNUNET_NetworkType net_type;
   size_t salen = 0;
   int res;
 
@@ -2021,7 +2019,7 @@ http_client_plugin_get_session (void *cls,
   }
 
   /* Determine network location */
-  net_type = GNUNET_ATS_NET_UNSPECIFIED;
+  net_type = GNUNET_NT_UNSPECIFIED;
   sa = http_common_socket_from_address (address->address,
                                         address->address_length,
                                         &res);
@@ -2044,9 +2042,9 @@ http_client_plugin_get_session (void *cls,
   else if (GNUNET_NO == res)
   {
     /* Cannot convert to sockaddr -> is external hostname */
-    net_type = GNUNET_ATS_NET_WAN;
+    net_type = GNUNET_NT_WAN;
   }
-  if (GNUNET_ATS_NET_UNSPECIFIED == net_type)
+  if (GNUNET_NT_UNSPECIFIED == net_type)
   {
     GNUNET_break (0);
     return NULL;