- due to incompatibilities in the representation of the ECC public key for ECDH and...
[oweals/gnunet.git] / src / cadet / gnunet-service-cadet_channel.c
index c859004564acfb2d0ede3482bf66b51cd3abe1ba..2fd0a8e099fb028fdbfc29f60a93036fb0a4adce 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     (C) 2013 Christian Grothoff (and other contributing authors)
+     Copyright (C) 2013 Christian Grothoff (and other contributing authors)
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -69,7 +69,7 @@ struct CadetChannelQueue
   /**
    * Tunnel Queue.
    */
-  struct CadetTunnel3Queue *tq;
+  struct CadetTunnelQueue *tq;
 
   /**
    * Message type (DATA/DATA_ACK)
@@ -183,7 +183,7 @@ struct CadetChannelReliability
     /**
      * Task to resend/poll in case no ACK is received.
      */
-  GNUNET_SCHEDULER_TaskIdentifier   retry_task;
+  struct GNUNET_SCHEDULER_Task *   retry_task;
 
     /**
      * Counter for exponential backoff.
@@ -205,7 +205,7 @@ struct CadetChannel
     /**
      * Tunnel this channel is in.
      */
-  struct CadetTunnel3 *t;
+  struct CadetTunnel *t;
 
     /**
      * Destination port of the channel.
@@ -305,6 +305,7 @@ extern GNUNET_PEER_Id myid;
 /********************************   STATIC  ***********************************/
 /******************************************************************************/
 
+
 /**
  * Destroy a reliable message after it has been acknowledged, either by
  * direct mid ACK or bitfield. Updates the appropriate data structures and
@@ -315,6 +316,9 @@ extern GNUNET_PEER_Id myid;
  *                    If this message is ACK in a batch the timing information
  *                    is skewed by the retransmission, count only for the
  *                    retransmitted message.
+ *
+ * @return #GNUNET_YES if channel was destroyed as a result of the call,
+ *         #GNUNET_NO otherwise.
  */
 static int
 rel_message_free (struct CadetReliableMessage *copy, int update_time);
@@ -332,10 +336,9 @@ send_create (struct CadetChannel *ch);
  *
  * @param ch The channel to confirm.
  * @param fwd Should we send a FWD ACK? (going dest->root)
- * @param reaction This ACK is a reaction to a duplicate CREATE, don't save.
  */
 static void
-send_ack (struct CadetChannel *ch, int fwd, int reaction);
+send_ack (struct CadetChannel *ch, int fwd);
 
 
 
@@ -570,14 +573,22 @@ send_client_data (struct CadetChannel *ch,
   if (fwd)
   {
     if (ch->dest_rel->client_ready)
+    {
       GML_send_data (ch->dest, msg, ch->lid_dest);
+      ch->dest_rel->client_ready = GNUNET_NO;
+      ch->dest_rel->mid_recv++;
+    }
     else
       add_buffered_data (msg, ch->dest_rel);
   }
   else
   {
     if (ch->root_rel->client_ready)
+    {
       GML_send_data (ch->root, msg, ch->lid_root);
+      ch->root_rel->client_ready = GNUNET_NO;
+      ch->root_rel->mid_recv++;
+    }
     else
       add_buffered_data (msg, ch->root_rel);
   }
@@ -616,22 +627,19 @@ send_client_buffered_data (struct CadetChannel *ch,
     {
       struct GNUNET_CADET_Data *msg = (struct GNUNET_CADET_Data *) &copy[1];
 
-      LOG (GNUNET_ERROR_TYPE_DEBUG,
-           " have %u! now expecting %u\n",
+      LOG (GNUNET_ERROR_TYPE_DEBUG, " have %u! now expecting %u\n",
            copy->mid, rel->mid_recv + 1);
       send_client_data (ch, msg, fwd);
       rel->n_recv--;
-      rel->mid_recv++;
       GNUNET_CONTAINER_DLL_remove (rel->head_recv, rel->tail_recv, copy);
       LOG (GNUNET_ERROR_TYPE_DEBUG, " COPYFREE RECV %p\n", copy);
       GNUNET_free (copy);
+      GCCH_send_data_ack (ch, fwd);
     }
     else
     {
-      LOG (GNUNET_ERROR_TYPE_DEBUG,
-           " reliable && don't have %u, next is %u\n",
-           rel->mid_recv,
-           copy->mid);
+      LOG (GNUNET_ERROR_TYPE_DEBUG, " reliable && don't have %u, next is %u\n",
+           rel->mid_recv, copy->mid);
       if (GNUNET_YES == ch->destroy)
       {
         /* We don't have the next data piece and the remote peer has closed the
@@ -721,7 +729,7 @@ channel_retransmit_message (void *cls,
   struct GNUNET_CADET_Data *payload;
   int fwd;
 
-  rel->retry_task = GNUNET_SCHEDULER_NO_TASK;
+  rel->retry_task = NULL;
   if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
     return;
 
@@ -729,7 +737,7 @@ channel_retransmit_message (void *cls,
   copy = rel->head_sent;
   if (NULL == copy)
   {
-    GNUNET_break (0);
+    GNUNET_break (0); // FIXME tripped in rps testcase
     return;
   }
 
@@ -755,7 +763,7 @@ channel_recreate (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   struct CadetChannelReliability *rel = cls;
 
-  rel->retry_task = GNUNET_SCHEDULER_NO_TASK;
+  rel->retry_task = NULL;
   if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
     return;
 
@@ -768,7 +776,7 @@ channel_recreate (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   }
   else if (rel == rel->ch->dest_rel)
   {
-    send_ack (rel->ch, GNUNET_YES, GNUNET_NO);
+    send_ack (rel->ch, GNUNET_YES);
   }
   else
   {
@@ -789,8 +797,8 @@ channel_recreate (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
  */
 static void
 ch_message_sent (void *cls,
-                 struct CadetTunnel3 *t,
-                 struct CadetTunnel3Queue *q,
+                 struct CadetTunnel *t,
+                 struct CadetTunnelQueue *q,
                  uint16_t type, size_t size)
 {
   struct CadetChannelQueue *chq = cls;
@@ -807,7 +815,7 @@ ch_message_sent (void *cls,
       GNUNET_assert (chq == copy->chq);
       copy->timestamp = GNUNET_TIME_absolute_get ();
       rel = copy->rel;
-      if (GNUNET_SCHEDULER_NO_TASK == rel->retry_task)
+      if (NULL == rel->retry_task)
       {
         LOG (GNUNET_ERROR_TYPE_DEBUG, "!! scheduling retry in 4 * %s\n",
              GNUNET_STRINGS_relative_time_to_string (rel->expected_delay,
@@ -851,7 +859,7 @@ ch_message_sent (void *cls,
           && GNUNET_MESSAGE_TYPE_CADET_DATA_ACK != type
           && GNUNET_NO == rel->ch->destroy)
       {
-        GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == rel->retry_task);
+        GNUNET_assert (NULL == rel->retry_task);
         LOG (GNUNET_ERROR_TYPE_DEBUG, "!!! STD BACKOFF %s\n",
              GNUNET_STRINGS_relative_time_to_string (rel->retry_timer,
                                                      GNUNET_NO));
@@ -894,10 +902,9 @@ send_create (struct CadetChannel *ch)
  *
  * @param ch The channel to confirm.
  * @param fwd Should we send a FWD ACK? (going dest->root)
- * @param reaction This ACK is a reaction to a duplicate CREATE, don't save.
  */
 static void
-send_ack (struct CadetChannel *ch, int fwd, int reaction)
+send_ack (struct CadetChannel *ch, int fwd)
 {
   struct GNUNET_CADET_ChannelManage msg;
 
@@ -907,7 +914,7 @@ send_ack (struct CadetChannel *ch, int fwd, int reaction)
        GC_f2s (fwd), GCCH_2s (ch));
 
   msg.chid = htonl (ch->gid);
-  GCCH_send_prebuilt_message (&msg.header, ch, !fwd, reaction ? &msg : NULL);
+  GCCH_send_prebuilt_message (&msg.header, ch, !fwd, NULL);
 }
 
 
@@ -999,10 +1006,10 @@ channel_rel_free_all (struct CadetChannelReliability *rel)
     GCT_cancel (rel->uniq->tq);
     /* ch_message_sent is called freeing uniq */
   }
-  if (GNUNET_SCHEDULER_NO_TASK != rel->retry_task)
+  if (NULL != rel->retry_task)
   {
     GNUNET_SCHEDULER_cancel (rel->retry_task);
-    rel->retry_task = GNUNET_SCHEDULER_NO_TASK;
+    rel->retry_task = NULL;
   }
   GNUNET_free (rel);
 }
@@ -1028,19 +1035,13 @@ channel_rel_free_sent (struct CadetChannelReliability *rel,
 
   bitfield = msg->futures;
   mid = ntohl (msg->mid);
-  LOG (GNUNET_ERROR_TYPE_DEBUG,
-              "!!! free_sent_reliable %u %llX\n",
-              mid, bitfield);
-  LOG (GNUNET_ERROR_TYPE_DEBUG,
-              " rel %p, head %p\n",
-              rel, rel->head_sent);
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "free_sent_reliable %u %llX\n", mid, bitfield);
+  LOG (GNUNET_ERROR_TYPE_DEBUG, " rel %p, head %p\n", rel, rel->head_sent);
   for (i = 0, copy = rel->head_sent;
        i < 64 && NULL != copy && 0 != bitfield;
        i++)
   {
-    LOG (GNUNET_ERROR_TYPE_DEBUG,
-                " trying bit %u (mid %u)\n",
-                i, mid + i + 1);
+    LOG (GNUNET_ERROR_TYPE_DEBUG, " trying bit %u (mid %u)\n", i, mid + i + 1);
     mask = 0x1LL << i;
     if (0 == (bitfield & mask))
      continue;
@@ -1173,29 +1174,26 @@ channel_confirm (struct CadetChannel *ch, int fwd)
     if (GCT_get_connections_buffer (ch->t) > 0 || GCT_is_loopback (ch->t))
       send_client_ack (ch, fwd);
 
-    if (GNUNET_SCHEDULER_NO_TASK != rel->retry_task)
+    if (NULL != rel->retry_task)
     {
       GNUNET_SCHEDULER_cancel (rel->retry_task);
-      rel->retry_task = GNUNET_SCHEDULER_NO_TASK;
+      rel->retry_task = NULL;
     }
     else if (NULL != rel->uniq)
     {
       GCT_cancel (rel->uniq->tq);
       /* ch_message_sent will free and NULL uniq */
     }
-    else
+    else if (GNUNET_NO == is_loopback (ch))
     {
-      if (GNUNET_NO == is_loopback (ch))
-      {
-        /* We SHOULD have been trying to retransmit this! */
-        GNUNET_break (0);
-      }
+      /* We SHOULD have been trying to retransmit this! */
+      GNUNET_break (0);
     }
   }
 
   /* In case of a FWD ACK (SYNACK) send a BCK ACK (ACK). */
   if (GNUNET_YES == fwd)
-    send_ack (ch, GNUNET_NO, GNUNET_NO);
+    send_ack (ch, GNUNET_NO);
 }
 
 
@@ -1248,7 +1246,7 @@ channel_save_copy (struct CadetChannel *ch,
  * @return A new initialized channel. NULL on error.
  */
 static struct CadetChannel *
-channel_new (struct CadetTunnel3 *t,
+channel_new (struct CadetTunnel *t,
              struct CadetClient *owner,
              CADET_ChannelNumber lid_root)
 {
@@ -1348,7 +1346,7 @@ void
 GCCH_destroy (struct CadetChannel *ch)
 {
   struct CadetClient *c;
-  struct CadetTunnel3 *t;
+  struct CadetTunnel *t;
 
   if (NULL == ch)
     return;
@@ -1405,7 +1403,7 @@ GCCH_get_id (const struct CadetChannel *ch)
  *
  * @return tunnel of the channel.
  */
-struct CadetTunnel3 *
+struct CadetTunnel *
 GCCH_get_tunnel (const struct CadetChannel *ch)
 {
   return ch->t;
@@ -1426,13 +1424,17 @@ GCCH_get_buffer (struct CadetChannel *ch, int fwd)
   struct CadetChannelReliability *rel;
 
   rel = fwd ? ch->dest_rel : ch->root_rel;
-
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "   get buffer, channel %s\n", GCCH_2s (ch));
+  GCCH_debug (ch);
   /* If rel is NULL it means that the end is not yet created,
    * most probably is a loopback channel at the point of sending
    * the ChannelCreate to itself.
    */
   if (NULL == rel)
+  {
+    LOG (GNUNET_ERROR_TYPE_DEBUG, "  rel is NULL: max\n");
     return 64;
+  }
 
   return (64 - rel->n_recv);
 }
@@ -1519,43 +1521,36 @@ GCCH_send_data_ack (struct CadetChannel *ch, int fwd)
   uint32_t ack;
 
   if (GNUNET_NO == ch->reliable)
-  {
     return;
-  }
+
   rel = fwd ? ch->dest_rel : ch->root_rel;
   ack = rel->mid_recv - 1;
-  LOG (GNUNET_ERROR_TYPE_INFO, "===> DATA_ACK for %u\n", ack);
 
   msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_DATA_ACK);
   msg.header.size = htons (sizeof (msg));
   msg.chid = htonl (ch->gid);
-  msg.futures = 0;
+  msg.mid = htonl (ack);
+
+  msg.futures = 0LL;
   for (copy = rel->head_recv; NULL != copy; copy = copy->next)
   {
     if (copy->type != GNUNET_MESSAGE_TYPE_CADET_DATA)
     {
-      LOG (GNUNET_ERROR_TYPE_DEBUG,
-           "!!  Type %s, expected DATA\n",
+      LOG (GNUNET_ERROR_TYPE_DEBUG, " Type %s, expected DATA\n",
            GC_m2s (copy->type));
       continue;
     }
-    if (copy->mid == ack + 1)
-    {
-      ack++;
-      continue;
-    }
+    GNUNET_assert (GC_is_pid_bigger(copy->mid, ack));
     delta = copy->mid - (ack + 1);
     if (63 < delta)
       break;
     mask = 0x1LL << delta;
     msg.futures |= mask;
     LOG (GNUNET_ERROR_TYPE_DEBUG,
-         " !! setting bit for %u (delta %u) (%llX) -> %llX\n",
+         " setting bit for %u (delta %u) (%llX) -> %llX\n",
          copy->mid, delta, mask, msg.futures);
   }
-  msg.mid = htonl (ack);
-  LOG (GNUNET_ERROR_TYPE_DEBUG,
-       "!!! ACK for %u, futures %llX\n",
+  LOG (GNUNET_ERROR_TYPE_INFO, "===> DATA_ACK for %u + %llX\n",
        ack, msg.futures);
 
   GCCH_send_prebuilt_message (&msg.header, ch, !fwd, NULL);
@@ -1599,8 +1594,15 @@ GCCH_allow_client (struct CadetChannel *ch, int fwd)
         return;
       }
       else
+      {
         LOG (GNUNET_ERROR_TYPE_DEBUG, " gap ok: %u - %u\n",
              rel->head_sent->mid, rel->mid_send);
+        struct CadetReliableMessage *aux;
+        for (aux = rel->head_sent; NULL != aux; aux = aux->next)
+        {
+          LOG (GNUNET_ERROR_TYPE_DEBUG, "   - sent MID %u\n", aux->mid);
+        }
+      }
     }
     else
     {
@@ -1684,6 +1686,7 @@ GCCH_handle_local_ack (struct CadetChannel *ch, int fwd)
   {
     send_destroy (ch, GNUNET_YES);
     GCCH_destroy (ch);
+    return;
   }
   /* if loopback is marked for destruction, no need to ACK to the other peer,
    * it requested the destruction and is already gone, therefore, else if.
@@ -1711,20 +1714,20 @@ GCCH_handle_local_ack (struct CadetChannel *ch, int fwd)
  *
  * @param ch Channel.
  * @param c Client which sent the data.
- * @param message Message.
  * @param fwd Is this a FWD data?
+ * @param message Data message.
+ * @param size Size of data.
  *
  * @return GNUNET_OK if everything goes well, GNUNET_SYSERR in case of en error.
  */
 int
 GCCH_handle_local_data (struct CadetChannel *ch,
-                        struct CadetClient *c,
-                        struct GNUNET_MessageHeader *message,
-                        int fwd)
+                        struct CadetClient *c, int fwd,
+                        const struct GNUNET_MessageHeader *message,
+                        size_t size)
 {
   struct CadetChannelReliability *rel;
   struct GNUNET_CADET_Data *payload;
-  size_t size = ntohs (message->size);
   uint16_t p2p_size = sizeof(struct GNUNET_CADET_Data) + size;
   unsigned char cbuf[p2p_size];
 
@@ -1780,6 +1783,8 @@ GCCH_handle_local_data (struct CadetChannel *ch,
 /**
  * Handle a channel destroy requested by a client.
  *
+ * TODO: add "reason" field
+ *
  * Destroy the channel and the tunnel in case this was the last channel.
  *
  * @param ch Channel.
@@ -1827,7 +1832,7 @@ GCCH_handle_local_create (struct CadetClient *c,
                           struct GNUNET_CADET_ChannelMessage *msg)
 {
   struct CadetChannel *ch;
-  struct CadetTunnel3 *t;
+  struct CadetTunnel *t;
   struct CadetPeer *peer;
   CADET_ChannelNumber chid;
 
@@ -1848,7 +1853,7 @@ GCCH_handle_local_create (struct CadetClient *c,
 
   if (GCP_get_short_id (peer) == myid)
   {
-    GCT_change_cstate (t, CADET_TUNNEL3_READY);
+    GCT_change_cstate (t, CADET_TUNNEL_READY);
   }
   else
   {
@@ -1955,8 +1960,7 @@ GCCH_handle_data (struct CadetChannel *ch,
       /* Is this the exact next expected messasge? */
       if (mid == rel->mid_recv)
       {
-        LOG (GNUNET_ERROR_TYPE_DEBUG, "as expected\n");
-        rel->mid_recv++;
+        LOG (GNUNET_ERROR_TYPE_DEBUG, "as expected, sending to client\n");
         send_client_data (ch, msg, fwd);
       }
       else
@@ -1975,10 +1979,26 @@ GCCH_handle_data (struct CadetChannel *ch,
   }
   else
   {
-    GNUNET_break_op (GC_is_pid_bigger (rel->mid_recv, mid));
-    LOG (GNUNET_ERROR_TYPE_WARNING,
-         "MID %u not expected (%u - %u), dropping!\n",
-         mid, rel->mid_recv, rel->mid_recv + 63);
+    if (GC_is_pid_bigger (rel->mid_recv, mid))
+    {
+      GNUNET_break_op (0);
+      LOG (GNUNET_ERROR_TYPE_WARNING,
+          "MID %u on channel %s not expected (window: %u - %u). Dropping!\n",
+          mid, GCCH_2s (ch), rel->mid_recv, rel->mid_recv + 63);
+    }
+    else
+    {
+      LOG (GNUNET_ERROR_TYPE_WARNING,
+           "Duplicate MID %u, channel %s (expecting MID %u). Re-sending ACK!\n",
+           mid, GCCH_2s (ch), rel->mid_recv);
+      if (NULL != rel->uniq)
+      {
+        LOG (GNUNET_ERROR_TYPE_WARNING,
+            "We are trying to send an ACK, but don't seem have the "
+            "bandwidth. Try to increase your ats QUOTA in you config file\n");
+      }
+
+    }
   }
 
   GCCH_send_data_ack (ch, fwd);
@@ -2020,7 +2040,8 @@ GCCH_handle_data_ack (struct CadetChannel *ch,
   }
 
   ack = ntohl (msg->mid);
-  LOG (GNUNET_ERROR_TYPE_INFO, "<=== %s ACK %u\n", GC_f2s (fwd), ack);
+  LOG (GNUNET_ERROR_TYPE_INFO, "<=== %s ACK %u + %llX\n",
+       GC_f2s (fwd), ack, msg->futures);
 
   if (GNUNET_YES == fwd)
   {
@@ -2058,10 +2079,10 @@ GCCH_handle_data_ack (struct CadetChannel *ch,
   /* If some message was free'd, update the retransmission delay */
   if (GNUNET_YES == work)
   {
-    if (GNUNET_SCHEDULER_NO_TASK != rel->retry_task)
+    if (NULL != rel->retry_task)
     {
       GNUNET_SCHEDULER_cancel (rel->retry_task);
-      rel->retry_task = GNUNET_SCHEDULER_NO_TASK;
+      rel->retry_task = NULL;
       if (NULL != rel->head_sent && NULL == rel->head_sent->chq)
       {
         struct GNUNET_TIME_Absolute new_target;
@@ -2096,16 +2117,14 @@ GCCH_handle_data_ack (struct CadetChannel *ch,
  * @param msg Channel crate message.
  */
 struct CadetChannel *
-GCCH_handle_create (struct CadetTunnel3 *t,
+GCCH_handle_create (struct CadetTunnel *t,
                     const struct GNUNET_CADET_ChannelCreate *msg)
 {
   CADET_ChannelNumber chid;
   struct CadetChannel *ch;
   struct CadetClient *c;
   int new_channel;
-  int reaction;
 
-  reaction = GNUNET_NO;
   chid = ntohl (msg->chid);
   ch = GCT_get_channel (t, chid);
   if (NULL == ch)
@@ -2160,16 +2179,20 @@ GCCH_handle_create (struct CadetTunnel3 *t,
   else
   {
     LOG (GNUNET_ERROR_TYPE_DEBUG, "  duplicate create channel\n");
-    reaction = GNUNET_YES;
-    if (GNUNET_SCHEDULER_NO_TASK != ch->dest_rel->retry_task)
+    if (NULL != ch->dest_rel->retry_task)
     {
       LOG (GNUNET_ERROR_TYPE_DEBUG, "  clearing retry task\n");
       /* we were waiting to re-send our 'SYNACK', wait no more! */
       GNUNET_SCHEDULER_cancel (ch->dest_rel->retry_task);
-      ch->dest_rel->retry_task = GNUNET_SCHEDULER_NO_TASK;
+      ch->dest_rel->retry_task = NULL;
+    }
+    else if (NULL != ch->dest_rel->uniq)
+    {
+      /* we are waiting to for our 'SYNACK' to leave the queue, all done! */
+      return ch;
     }
   }
-  send_ack (ch, GNUNET_YES, reaction);
+  send_ack (ch, GNUNET_YES);
 
   return ch;
 }
@@ -2343,10 +2366,10 @@ GCCH_send_prebuilt_message (const struct GNUNET_MessageHeader *message,
                chq->copy->rel, chq->copy->chq, chq->copy->type);
         }
         LOG (GNUNET_ERROR_TYPE_DEBUG, "  new chq: %p\n", chq);
-            chq->copy->chq = chq;
-            chq->tq = GCT_send_prebuilt_message (message, ch->t, NULL,
-                                                 NULL != existing_copy,
-                                                 &ch_message_sent, chq);
+        chq->copy->chq = chq;
+        chq->tq = GCT_send_prebuilt_message (message, ch->t, NULL,
+                                             GNUNET_YES,
+                                             &ch_message_sent, chq);
         /* q itself is stored in copy */
         GNUNET_assert (NULL != chq->tq || GNUNET_NO != ch->destroy);
       }
@@ -2357,16 +2380,9 @@ GCCH_send_prebuilt_message (const struct GNUNET_MessageHeader *message,
       break;
 
 
-    case GNUNET_MESSAGE_TYPE_CADET_CHANNEL_ACK:
-      if (GNUNET_YES == fwd || NULL != existing_copy)
-      {
-        /* BCK ACK (going FWD) is just a response for a SYNACK, don't keep*/
-        fire_and_forget (message, ch, GNUNET_YES);
-        return;
-      }
-      /* fall-trough */
     case GNUNET_MESSAGE_TYPE_CADET_DATA_ACK:
     case GNUNET_MESSAGE_TYPE_CADET_CHANNEL_CREATE:
+    case GNUNET_MESSAGE_TYPE_CADET_CHANNEL_ACK:
       chq = GNUNET_new (struct CadetChannelQueue);
       chq->type = type;
       chq->rel = fwd ? ch->root_rel : ch->dest_rel;
@@ -2376,6 +2392,7 @@ GCCH_send_prebuilt_message (const struct GNUNET_MessageHeader *message,
         {
           GCT_cancel (chq->rel->uniq->tq);
           /* ch_message_sent is called, freeing and NULLing uniq */
+          GNUNET_break (NULL == chq->rel->uniq);
         }
         else
         {
@@ -2383,11 +2400,13 @@ GCCH_send_prebuilt_message (const struct GNUNET_MessageHeader *message,
           GNUNET_free (chq->rel->uniq);
         }
       }
+
       chq->tq = GCT_send_prebuilt_message (message, ch->t, NULL, GNUNET_YES,
                                            &ch_message_sent, chq);
       if (NULL == chq->tq)
       {
         GNUNET_break (0);
+        GCT_debug (ch->t, GNUNET_ERROR_TYPE_ERROR);
         GNUNET_free (chq);
         chq = NULL;
         return;
@@ -2425,7 +2444,7 @@ GCCH_2s (const struct CadetChannel *ch)
   if (NULL == ch)
     return "(NULL Channel)";
 
-  sprintf (buf, "%s:%u gid:%X (%X / %X)",
+  SPRINTF (buf, "%s:%u gid:%X (%X / %X)",
            GCT_2s (ch->t), ch->port, ch->gid, ch->lid_root, ch->lid_dest);
 
   return buf;