undo 17963, better solution ahead
[oweals/gnunet.git] / src / transport / plugin_transport_tcp.c
index d85d5fc821703eb6196da25ecf9972b90d8415cc..5a77f25b57acee860475c677afaa245e57e07add 100644 (file)
@@ -696,12 +696,16 @@ do_transmit (void *cls, size_t size, void *buf)
     GNUNET_CONTAINER_DLL_remove (session->pending_messages_head,
                                  session->pending_messages_tail, pos);
     GNUNET_assert (size >= pos->message_size);
+    GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
+                    "tcp",
+                    "Transmitting message of type %u\n",
+                    ntohs (((struct GNUNET_MessageHeader*)pos->msg)->type));
     /* FIXME: this memcpy can be up to 7% of our total runtime */
     memcpy (cbuf, pos->msg, pos->message_size);
     cbuf += pos->message_size;
     ret += pos->message_size;
     size -= pos->message_size;
-    GNUNET_CONTAINER_DLL_insert_after (hd, tl, tl, pos);
+    GNUNET_CONTAINER_DLL_insert_tail (hd, tl, pos);
   }
   /* schedule 'continuation' before callbacks so that callbacks that
    * cancel everything don't cause us to use a session that no longer
@@ -981,7 +985,7 @@ tcp_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target,
     }
     session = cand_session;
   }
-  if ((session == NULL) && (addr == NULL))
+  if ((session == NULL) && (addrlen == 0))
   {
 #if DEBUG_TCP
     GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp",
@@ -1066,8 +1070,7 @@ tcp_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target,
       pm->transmit_cont_cls = cont_cls;
 
       /* append pm to pending_messages list */
-      GNUNET_CONTAINER_DLL_insert_after (session->pending_messages_head,
-                                         session->pending_messages_tail,
+      GNUNET_CONTAINER_DLL_insert_tail (session->pending_messages_head,
                                          session->pending_messages_tail, pm);
 
       GNUNET_assert (GNUNET_CONTAINER_multihashmap_put
@@ -1124,6 +1127,19 @@ tcp_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target,
     /* check if session is valid */
     struct Session *ses = plugin->sessions;
 
+    if (0 != memcmp (target,
+                    &session->target,
+                    sizeof (struct GNUNET_PeerIdentity)))
+    {
+      GNUNET_break (0);
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                 "Got session %p for `%s', but should be for peer `%s'!\n",
+                 session,
+                 GNUNET_i2s (&session->target),
+                 GNUNET_h2s (&target->hashPubKey));
+      return -1;
+    }
+
     while ((ses != NULL) && (ses != session))
       ses = ses->next;
     if (ses == NULL)
@@ -1151,9 +1167,8 @@ tcp_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target,
   pm->transmit_cont_cls = cont_cls;
 
   /* append pm to pending_messages list */
-  GNUNET_CONTAINER_DLL_insert_after (session->pending_messages_head,
-                                     session->pending_messages_tail,
-                                     session->pending_messages_tail, pm);
+  GNUNET_CONTAINER_DLL_insert_tail (session->pending_messages_head,
+                                   session->pending_messages_tail, pm);
 #if DEBUG_TCP
   GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp",
                    "Asked to transmit %u bytes to `%s', added message to list.\n",
@@ -1661,7 +1676,7 @@ delayed_done (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   struct Session *session = cls;
   struct GNUNET_TIME_Relative delay;
-  struct GNUNET_TRANSPORT_ATS_Information ats;
+  struct GNUNET_ATS_Information ats;
 
   session->receive_delay_task = GNUNET_SCHEDULER_NO_TASK;
   delay =
@@ -1708,7 +1723,7 @@ handle_tcp_data (void *cls, struct GNUNET_SERVER_Client *client,
     return;
   }
   session->last_activity = GNUNET_TIME_absolute_get ();
-#if DEBUG_TCP > 1
+#if DEBUG_TCP
   GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp",
                    "Passing %u bytes of type %u from `%4s' to transport service.\n",
                    (unsigned int) ntohs (message->size),
@@ -1718,13 +1733,13 @@ handle_tcp_data (void *cls, struct GNUNET_SERVER_Client *client,
   GNUNET_STATISTICS_update (plugin->env->stats,
                             gettext_noop ("# bytes received via TCP"),
                             ntohs (message->size), GNUNET_NO);
-  struct GNUNET_TRANSPORT_ATS_Information distance;
+  struct GNUNET_ATS_Information distance;
 
-  distance.type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE);
+  distance.type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE);
   distance.value = htonl (1);
   delay =
       plugin->env->receive (plugin->env->cls, &session->target, message,
-                            (const struct GNUNET_TRANSPORT_ATS_Information *)
+                            (const struct GNUNET_ATS_Information *)
                             &distance, 1, session,
                             (GNUNET_YES ==
                              session->inbound) ? NULL : session->connect_addr,