tolerate additional IPv4 address now available for gnunet.org
[oweals/gnunet.git] / src / transport / plugin_transport_http_client.c
index 2b0b8939e8614f9b0284522d98ed34cd0b5f1e40..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,22 +218,22 @@ struct GNUNET_ATS_Session
   /**
    * Message stream tokenizer for incoming data
    */
-  struct GNUNET_SERVER_MessageStreamTokenizer *msg_tk;
+  struct GNUNET_MessageStreamTokenizer *msg_tk;
 
   /**
    * Session timeout task
    */
-  struct GNUNET_SCHEDULER_Task * put_disconnect_task;
+  struct GNUNET_SCHEDULER_Task *put_disconnect_task;
 
   /**
    * Session timeout task
    */
-  struct GNUNET_SCHEDULER_Task * timeout_task;
+  struct GNUNET_SCHEDULER_Task *timeout_task;
 
   /**
    * Task to wake up client receive handle when receiving is allowed again
    */
-  struct GNUNET_SCHEDULER_Task * recv_wakeup_task;
+  struct GNUNET_SCHEDULER_Task *recv_wakeup_task;
 
   /**
    * Absolute time when to receive data again.
@@ -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);
@@ -681,7 +678,7 @@ client_log (CURL *curl,
     ttype = "UNSPECIFIED";
     break;
   }
-  memcpy (text, data, size);
+  GNUNET_memcpy (text, data, size);
   if (text[size - 1] == '\n')
   {
     text[size] = '\0';
@@ -774,7 +771,7 @@ http_client_plugin_send (void *cls,
   msg->buf = (char *) &msg[1];
   msg->transmit_cont = cont;
   msg->transmit_cont_cls = cont_cls;
-  memcpy (msg->buf,
+  GNUNET_memcpy (msg->buf,
           msgbuf,
           msgbuf_size);
   GNUNET_CONTAINER_DLL_insert_tail (s->msg_head,
@@ -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);
-  memcpy (stream, &msg->buf[msg->pos], len);
+  GNUNET_memcpy (stream,
+                &msg->buf[msg->pos],
+                len);
   msg->pos += len;
   if (msg->pos == msg->size)
   {
@@ -1130,12 +1131,8 @@ static void
 client_wake_up (void *cls)
 {
   struct GNUNET_ATS_Session *s = cls;
-  const struct GNUNET_SCHEDULER_TaskContext *tc;
 
   s->recv_wakeup_task = NULL;
-  tc = GNUNET_SCHEDULER_get_task_context ();
-  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
-    return;
   LOG (GNUNET_ERROR_TYPE_DEBUG,
        "Session %p/request %p: Waking up GET handle\n",
        s, s->get.easyhandle);
@@ -1158,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;
@@ -1274,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;
 }
 
@@ -1301,13 +1295,8 @@ client_run (void *cls)
   CURLMsg *msg;
   int put_request; /* GNUNET_YES if easy handle is put, GNUNET_NO for get */
   int msgs_left;
-  const struct GNUNET_SCHEDULER_TaskContext *tc;
 
   plugin->client_perform_task = NULL;
-  tc = GNUNET_SCHEDULER_get_task_context ();
-  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
-    return;
-
   /* While data are available or timeouts occured */
   do
   {
@@ -1646,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,
@@ -1823,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
@@ -1930,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)
 {
@@ -1945,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)
 {
@@ -2007,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;
 
@@ -2030,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);
@@ -2053,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;
@@ -2379,8 +2368,10 @@ http_client_plugin_update_inbound_delay (void *cls,
   if (s->recv_wakeup_task != NULL)
   {
     GNUNET_SCHEDULER_cancel (s->recv_wakeup_task);
-    s->recv_wakeup_task = GNUNET_SCHEDULER_add_delayed (delay,
-        &client_wake_up, s);
+    s->recv_wakeup_task
+      = GNUNET_SCHEDULER_add_delayed (delay,
+                                     &client_wake_up,
+                                     s);
   }
 }