working version
authorMatthias Wachs <wachs@net.in.tum.de>
Tue, 27 Sep 2011 10:59:27 +0000 (10:59 +0000)
committerMatthias Wachs <wachs@net.in.tum.de>
Tue, 27 Sep 2011 10:59:27 +0000 (10:59 +0000)
src/transport/plugin_transport_http.h
src/transport/plugin_transport_http_client.c
src/transport/plugin_transport_http_new.c
src/transport/plugin_transport_http_server.c

index 7120accfb6b9089942140de144c5e2a3c41d5a42..16e480a67a7b06f5b7ea5cffcf1ce9eb46ea8884 100644 (file)
 #include <curl/curl.h>
 
 
-#define DEBUG_HTTP GNUNET_YES
-#define VERBOSE_SERVER GNUNET_YES
-#define VERBOSE_CLIENT GNUNET_YES
-#define VERBOSE_CURL GNUNET_YES
+#define DEBUG_HTTP GNUNET_NO
+#define VERBOSE_SERVER GNUNET_NO
+#define VERBOSE_CLIENT GNUNET_NO
+#define VERBOSE_CURL GNUNET_NO
 
 #if BUILD_HTTPS
 #define LIBGNUNET_PLUGIN_TRANSPORT_INIT libgnunet_plugin_transport_https_init
@@ -248,7 +248,7 @@ struct Session
 
   void *server_recv;
   void *server_send;
-  struct GNUNET_TIME_Absolute delay;
+  struct GNUNET_TIME_Absolute next_receive;
   GNUNET_SCHEDULER_TaskIdentifier recv_wakeup_task;
   uint32_t tag;
 
index cd68a00693632f612822bbae90df6fce252eaadc..bc2051eef16a1d9fb9901d5eb6b1a213019aeea5 100644 (file)
@@ -146,7 +146,9 @@ client_send (struct Session *s, struct HTTP_Message *msg)
 
   if ((s != NULL) && (s->client_put_paused == GNUNET_YES))
   {
+#if VERBOSE_CLIENT
     GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, s->plugin->name, "Client: %X was suspended, unpausing\n", s->client_put);
+#endif
     s->client_put_paused = GNUNET_NO;
     curl_easy_pause(s->client_put, CURLPAUSE_CONT);
   }
@@ -306,10 +308,13 @@ client_receive_mst_cb (void *cls, void *client,
   struct GNUNET_TIME_Relative delay;
 
   delay = http_plugin_receive (s, &s->target, message, s, s->addr, s->addrlen);
+  GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, "CLIENT: CLIENT DELAY %llu ms\n",
+              delay.rel_value);
+
 
-  s->delay = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), delay);
+  s->next_receive = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), delay);
 
-  if (GNUNET_TIME_absolute_get().abs_value < s->delay.abs_value)
+  if (GNUNET_TIME_absolute_get().abs_value < s->next_receive.abs_value)
   {
 #if VERBOSE_CLIENT
     GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, "Client: peer `%s' address `%s' next read delayed for %llu ms\n",
@@ -343,32 +348,32 @@ static size_t
 client_receive (void *stream, size_t size, size_t nmemb, void *cls)
 {
   struct Session *s = cls;
-  struct Plugin *plugin = s->plugin;
   struct GNUNET_TIME_Absolute now;
   size_t len = size * nmemb;
 
 
 #if VERBOSE_CLIENT
+  struct Plugin *plugin = s->plugin;
   GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, "Client: Received %Zu bytes from peer `%s'\n",
                    len,
                    GNUNET_i2s (&s->target));
 #endif
 
   now = GNUNET_TIME_absolute_get();
-  if (now.abs_value < s->delay.abs_value)
+  if (now.abs_value < s->next_receive.abs_value)
   {
-#if 0
 #if DEBUG_CLIENT
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "No inbound bandwidth available! Next read was delayed for  %llu ms\n",
-                s, GNUNET_TIME_absolute_get_difference(s->delay, GNUNET_TIME_absolute_get()).rel_value);
+                s, GNUNET_TIME_absolute_get_difference(s->next_receive, GNUNET_TIME_absolute_get()).rel_value);
 #endif
+#if 0
     if (s->recv_wakeup_task != GNUNET_SCHEDULER_NO_TASK)
     {
       GNUNET_SCHEDULER_cancel (s->recv_wakeup_task);
       s->recv_wakeup_task = GNUNET_SCHEDULER_NO_TASK;
     }
-    s->recv_wakeup_task = GNUNET_SCHEDULER_add_delayed( GNUNET_TIME_absolute_get_difference(s->delay, now), &client_wake_up, s);
+    s->recv_wakeup_task = GNUNET_SCHEDULER_add_delayed( GNUNET_TIME_absolute_get_difference(s->next_receive, now), &client_wake_up, s);
     return CURLPAUSE_ALL;
 #endif
   }
@@ -398,27 +403,19 @@ static size_t
 client_send_cb (void *stream, size_t size, size_t nmemb, void *cls)
 {
   struct Session *s = cls;
+#if VERBOSE_CLIENT
   struct Plugin *plugin = s->plugin;
+#endif
   size_t bytes_sent = 0;
   size_t len;
 
   struct HTTP_Message *msg = s->msg_head;
-/*
-  if (s->put_paused == GNUNET_NO)
-    return CURL_READFUNC_PAUSE;
-  if ((s->msg_head == NULL) && (s->put_paused == GNUNET_YES))
-  {
-#if VERBOSE_CLIENT
-    GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, "Suspending handle `%s' `%s'\n",
-                     GNUNET_i2s (&s->target),GNUNET_a2s (s->addr, s->addrlen));
-#endif
-    s->put_paused = GNUNET_NO;
-    return CURL_READFUNC_PAUSE;
-  }
-*/
+
   if (msg == NULL)
   {
+#if VERBOSE_CLIENT
     GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, "Client: %X Nothing to send! Suspending PUT handle!\n", s->client_put);
+#endif
     s->client_put_paused = GNUNET_YES;
     return CURL_READFUNC_PAUSE;
   }
index 042c977f555eacd141b40f0d809c5a2c7ef03058..66f79b3c4f318267d09feb229eac0ad5deb5a08f 100644 (file)
@@ -420,7 +420,7 @@ create_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target,
   s->transmit_cont = cont;
   s->transmit_cont_cls = cont_cls;
   s->next = NULL;
-  s->delay = GNUNET_TIME_absolute_get_forever();
+  s->next_receive = GNUNET_TIME_absolute_get_forever();
   return s;
 }
 
@@ -487,7 +487,7 @@ http_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target,
   int res = GNUNET_SYSERR;
 
 #if DEBUG_HTTP
-  GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
+  GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
                    "Sending %u bytes to peer `%s' on address `%s' %X %i\n", msgbuf_size,
                    GNUNET_i2s (target), ((addr != NULL) && (addrlen != 0)) ? http_plugin_address_to_string(plugin, addr, addrlen) : "<inbound>", session, force_address);
 #endif
@@ -497,7 +497,7 @@ http_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target,
   /* look for existing connection */
   s = lookup_session (plugin, target, session, addr, addrlen, 1);
 #if DEBUG_HTTP
-  GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
+  GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
                    "%s existing session: %s\n", (s!=NULL) ? "Found" : "NOT Found", ((s != NULL) && (s->inbound == GNUNET_YES)) ? "inbound" : "outbound");
 #endif
 
@@ -514,7 +514,7 @@ http_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target,
     }
 
 #if DEBUG_HTTP
-    GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
+    GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
                      "Initiiating new connection to peer `%s'\n",
                      GNUNET_i2s (target));
 #endif
@@ -541,7 +541,7 @@ http_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target,
   if (s->inbound == GNUNET_NO)
   {
 #if DEBUG_HTTP
-    GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
+    GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
                      "Using outbound client session to send to `%s'\n",
                      GNUNET_i2s (target));
 #endif
@@ -553,7 +553,7 @@ http_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target,
     server_send (s, msg);
     res = msgbuf_size;
 #if DEBUG_HTTP
-    GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
+    GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
                      "Using inbound server session to send to `%s'\n",
                      GNUNET_i2s (target));
 #endif
@@ -754,7 +754,9 @@ nat_port_map_callback (void *cls, int add_remove, const struct sockaddr *addr,
                        socklen_t addrlen)
 {
   GNUNET_assert (cls != NULL);
+#if DEBUG_HTTP
   struct Plugin *plugin = cls;
+#endif
   static int limit;
 #if DEBUG_HTTP
   GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
@@ -790,7 +792,7 @@ start_report_addresses (struct Plugin *plugin)
       GNUNET_SERVICE_get_server_addresses (plugin->name, plugin->env->cfg,
                                            &addrs, &addrlens);
 #if 0
-  GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
+  GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
                    _("FOUND %u addresses\n"),res);
 #endif
 
index 596ac4925fe2e45d184dc7c879f1b87795b84444..6781b07457d371c8f470a0dbc2dba95efca0ce82 100644 (file)
@@ -242,16 +242,16 @@ server_receive_mst_cb (void *cls, void *client,
                   const struct GNUNET_MessageHeader *message)
 {
   struct Session *s = cls;
+#if VERBOSE_SERVER
   struct Plugin *plugin = s->plugin;
+#endif
   struct GNUNET_TIME_Relative delay;
 
   delay = http_plugin_receive (s, &s->target, message, s, s->addr, s->addrlen);
 
-  s->delay = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), delay);
-  GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, "Server: SERVER DELAY %llu ms\n",
-              delay.rel_value);
+  s->next_receive = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), delay);
 
-  if (GNUNET_TIME_absolute_get().abs_value < s->delay.abs_value)
+  if (delay.rel_value > 0)
   {
 #if VERBOSE_CLIENT
     GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, "Server: peer `%s' address `%s' next read delayed for %llu ms\n",
@@ -272,7 +272,7 @@ static ssize_t
 server_send_callback (void *cls, uint64_t pos, char *buf, size_t max)
 {
   struct Session *s = cls;
-  struct Plugin *plugin = s->plugin;
+
   struct HTTP_Message *msg;
   int bytes_read = 0;
   //static int c = 0;
@@ -304,6 +304,7 @@ server_send_callback (void *cls, uint64_t pos, char *buf, size_t max)
   }
 
 #if VERBOSE_CLIENT
+  struct Plugin *plugin = s->plugin;
   GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
                    "Server: %X: sent %u bytes\n",
                    s, bytes_read);
@@ -324,6 +325,7 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection,
                   const char *upload_data, size_t * upload_data_size,
                   void **httpSessionCache)
 {
+
   struct Plugin *plugin = cls;
   struct ServerConnection *sc = *httpSessionCache;
   struct Session *s = NULL;
@@ -477,7 +479,7 @@ create:
                         NULL);
 
     s->inbound = GNUNET_YES;
-    s->delay = GNUNET_TIME_absolute_get_zero();
+    s->next_receive = GNUNET_TIME_absolute_get_zero();
     s->tag= tag;
     if (0 == strcmp (MHD_HTTP_METHOD_PUT, method))
       s->server_recv = s;
@@ -563,7 +565,7 @@ found:
                    GNUNET_i2s (&s->target), GNUNET_a2s (s->addr, s->addrlen), *upload_data_size);
 #endif
       struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get();
-      if (( s->delay.abs_value < now.abs_value))
+      if (( s->next_receive.abs_value <= now.abs_value))
       {
 #if VERBOSE_SERVER
         GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
@@ -575,19 +577,18 @@ found:
           s->msg_tk = GNUNET_SERVER_mst_create (&server_receive_mst_cb, s);
         }
         res = GNUNET_SERVER_mst_receive (s->msg_tk, s, upload_data, *upload_data_size, GNUNET_NO, GNUNET_NO);
+#if VERBOSE_SERVER
         GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
-                         "Server: Received %Zu bytes\n",
-                    *upload_data_size);
+                         "Server: Received %Zu bytes\n", *upload_data_size);
+#endif
         (*upload_data_size) = 0;
       }
       else
       {
-
 #if DEBUG_HTTP
        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                  "Connection %X: no inbound bandwidth available! Next read was delayed by %llu ms\n", s, now.abs_value - s->delay.abs_value);
+                  "Server: %X no inbound bandwidth available! Next read was delayed by %llu ms\n", s, now.abs_value - s->next_receive.abs_value);
 #endif
-
       }
       return MHD_YES;
     }