fix div by zero
[oweals/gnunet.git] / src / transport / transport_api_core.c
index 0705552f9cf292d8e96e8f1e787360b11729fb68..b7edc3cc1a1b150ee78cfd08bf31473b9fb14b20 100644 (file)
@@ -2,20 +2,18 @@
      This file is part of GNUnet.
      Copyright (C) 2009-2013, 2016 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.
-
-     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.
+     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/>.
 */
 
 /**
@@ -345,6 +343,25 @@ handle_hello (void *cls,
 }
 
 
+/**
+ * A message from the handler's message queue to a neighbour was
+ * transmitted.  Now trigger (possibly delayed) notification of the
+ * neighbour's message queue that we are done and thus ready for
+ * the next message.
+ *
+ * @param cls the `struct Neighbour` where the message was sent
+ */
+static void
+notify_send_done_fin (void *cls)
+{
+  struct Neighbour *n = cls;
+
+  n->timeout_task = NULL;
+  n->is_ready = GNUNET_YES;
+  GNUNET_MQ_impl_send_continue (n->mq);
+}
+
+
 /**
  * A message from the handler's message queue to a neighbour was
  * transmitted.  Now trigger (possibly delayed) notification of the
@@ -364,8 +381,8 @@ notify_send_done (void *cls)
   {
     GNUNET_BANDWIDTH_tracker_consume (&n->out_tracker,
                                       n->env_size + n->traffic_overhead);
-    n->traffic_overhead = 0;
     n->env = NULL;
+    n->traffic_overhead = 0;
   }
   delay = GNUNET_BANDWIDTH_tracker_get_delay (&n->out_tracker,
                                               128);
@@ -375,10 +392,11 @@ notify_send_done (void *cls)
     GNUNET_MQ_impl_send_continue (n->mq);
     return;
   }
+  GNUNET_MQ_impl_send_in_flight (n->mq);
   /* cannot send even a small message without violating
-     quota, wait a before notifying MQ */
+     quota, wait a before allowing MQ to send next message */
   n->timeout_task = GNUNET_SCHEDULER_add_delayed (delay,
-                                                  &notify_send_done,
+                                                  &notify_send_done_fin,
                                                   n);
 }
 
@@ -405,12 +423,13 @@ mq_send_impl (struct GNUNET_MQ_Handle *mq,
 
   GNUNET_assert (GNUNET_YES == n->is_ready);
   msize = ntohs (msg->size);
-  if (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (*obm))
+  if (msize >= GNUNET_MAX_MESSAGE_SIZE - sizeof (*obm))
   {
     GNUNET_break (0);
     GNUNET_MQ_impl_send_continue (mq);
     return;
   }
+  GNUNET_assert (NULL == n->env);
   n->env = GNUNET_MQ_msg_nested_mh (obm,
                                     GNUNET_MESSAGE_TYPE_TRANSPORT_SEND,
                                     msg);
@@ -426,7 +445,8 @@ mq_send_impl (struct GNUNET_MQ_Handle *mq,
   GNUNET_MQ_send (h->mq,
                   n->env);
   LOG (GNUNET_ERROR_TYPE_DEBUG,
-       "Queued message for neighbour `%s'.\n",
+       "Queued message of type %u for neighbour `%s'.\n",
+       ntohs (msg->type),
        GNUNET_i2s (&n->id));
 }
 
@@ -784,7 +804,7 @@ reconnect (void *cls)
   LOG (GNUNET_ERROR_TYPE_DEBUG,
        "Connecting to transport service.\n");
   GNUNET_assert (NULL == h->mq);
-  h->mq = GNUNET_CLIENT_connecT (h->cfg,
+  h->mq = GNUNET_CLIENT_connect (h->cfg,
                                  "transport",
                                  handlers,
                                  &mq_error_handler,
@@ -923,7 +943,7 @@ GNUNET_TRANSPORT_core_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
 /**
  * Disconnect from the transport service.
  *
- * @param handle handle to the service as returned from #GNUNET_TRANSPORT_connect()
+ * @param handle handle to the service as returned from #GNUNET_TRANSPORT_core_connect()
  */
 void
 GNUNET_TRANSPORT_core_disconnect (struct GNUNET_TRANSPORT_CoreHandle *handle)