* is skewed by the retransmission, count only for the
* retransmitted message.
*/
-static void
+static int
rel_message_free (struct MeshReliableMessage *copy, int update_time);
/**
+/**
+ * Test if the channel is loopback: both root and dest are on the local peer.
+ *
+ * @param ch Channel to test.
+ *
+ * @return #GNUNET_YES if channel is loopback, #GNUNET_NO otherwise.
+ */
+static int
+is_loopback (const struct MeshChannel *ch)
+{
+ if (NULL != ch->t)
+ return GMT_is_loopback (ch->t);
+
+ return (NULL != ch->root && NULL != ch->dest);
+}
+
+
/**
* We have received a message out of order, or the client is not ready.
* Buffer it until we receive an ACK from the client or the missing
LOG (GNUNET_ERROR_TYPE_DEBUG, "add_buffered_data END\n");
}
+
/**
* Add a destination client to a channel, initializing all data structures
* in the channel and the client.
rel = copy->rel;
if (GNUNET_SCHEDULER_NO_TASK == rel->retry_task)
{
- LOG (GNUNET_ERROR_TYPE_DEBUG, "!! scheduling retry %u\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "!! scheduling retry in %s\n",
+ GNUNET_STRINGS_relative_time_to_string (rel->expected_delay,
+ GNUNET_YES));
if (0 != rel->expected_delay.rel_value_us)
{
LOG (GNUNET_ERROR_TYPE_DEBUG, "!! delay != 0\n");
}
else
{
- LOG (GNUNET_ERROR_TYPE_DEBUG, "!! delay 0\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "!! delay reset\n");
rel->retry_timer = MESH_RETRANSMIT_TIME;
}
LOG (GNUNET_ERROR_TYPE_DEBUG, "!! using delay %s\n",
struct MeshChannel *ch,
int force)
{
- GNUNET_break (NULL == GMT_send_prebuilt_message (msg, ch->t, ch, force,
+ GNUNET_break (NULL == GMT_send_prebuilt_message (msg, ch->t, force,
NULL, NULL));
}
next = copy->next;
GNUNET_CONTAINER_DLL_remove (rel->head_recv, rel->tail_recv, copy);
LOG (GNUNET_ERROR_TYPE_DEBUG, " COPYFREE BATCH RECV %p\n", copy);
+ GNUNET_break (NULL == copy->q);
GNUNET_free (copy);
}
for (copy = rel->head_sent; NULL != copy; copy = next)
next = copy->next;
GNUNET_CONTAINER_DLL_remove (rel->head_sent, rel->tail_sent, copy);
LOG (GNUNET_ERROR_TYPE_DEBUG, " COPYFREE BATCH %p\n", copy);
+ if (NULL != copy->q)
+ {
+ if (NULL != copy->q->q)
+ {
+ GMT_cancel (copy->q->q);
+ /* ch_message_sent will free copy->q */
+ }
+ else
+ {
+ GNUNET_free (copy->q);
+ GNUNET_break (0);
+ }
+ }
GNUNET_free (copy);
}
+ if (NULL != rel->uniq && NULL != rel->uniq->q)
+ {
+ GMT_cancel (rel->uniq->q);
+ /* ch_message_sent is called freeing uniq */
+ }
if (GNUNET_SCHEDULER_NO_TASK != rel->retry_task)
{
GNUNET_SCHEDULER_cancel (rel->retry_task);
+ rel->retry_task = GNUNET_SCHEDULER_NO_TASK;
}
- if (NULL != rel->uniq && NULL != rel->uniq->q)
- GMT_cancel (rel->uniq->q);
GNUNET_free (rel);
}
/* Now copy->mid == target, free it */
next = copy->next;
- rel_message_free (copy, GNUNET_YES);
+ GNUNET_break (GNUNET_YES != rel_message_free (copy, GNUNET_YES));
copy = next;
}
LOG (GNUNET_ERROR_TYPE_DEBUG, "free_sent_reliable END\n");
* 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 void
+static int
rel_message_free (struct MeshReliableMessage *copy, int update_time)
{
struct MeshChannelReliability *rel;
struct MeshTunnel3 *t = rel->ch->t;
GMCH_destroy (rel->ch);
GMT_destroy_if_empty (t);
+ return GNUNET_YES;
}
+ return GNUNET_NO;
}
enum MeshChannelState oldstate;
LOG (GNUNET_ERROR_TYPE_DEBUG,
- " channel confirm %s %s:%X\n",
- GM_f2s (fwd), GMT_2s (ch->t), ch->gid);
+ " channel confirm %s %s\n",
+ GM_f2s (fwd), GMCH_2s (ch));
oldstate = ch->state;
ch->state = MESH_CHANNEL_READY;
else if (NULL != rel->uniq)
{
GMT_cancel (rel->uniq->q);
- /* ch_sent_message will free and NULL uniq */
+ /* ch_message_sent will free and NULL uniq */
}
else
{
- /* We SHOULD have been trying to retransmit this! */
- GNUNET_break (oldstate == MESH_CHANNEL_READY);
+ if (GNUNET_NO == is_loopback (ch))
+ {
+ /* We SHOULD have been trying to retransmit this! */
+ GNUNET_break (oldstate == MESH_CHANNEL_READY);
+ }
}
/* In case of a FWD ACK (SYNACK) send a BCK ACK (ACK). */
}
-/**
- * Test if the channel is loopback: both root and dest are on the local peer.
- *
- * @param ch Channel to test.
- *
- * @return #GNUNET_YES if channel is loopback, #NGUNET_NO otherwise.
- */
-static int
-is_loopback (const struct MeshChannel *ch)
-{
- if (NULL != ch->t)
- return GMT_is_loopback (ch->t);
-
- return (NULL != ch->root && NULL != ch->dest);
-}
-
-
/**
* Handle a loopback message: call the appropriate handler for the message type.
*
if (NULL == ch)
return;
+ if (2 == ch->destroy)
+ return; /* recursive call */
+ ch->destroy = 2;
LOG (GNUNET_ERROR_TYPE_DEBUG, "destroying channel %s:%u\n",
GMT_2s (ch->t), ch->gid);
GNUNET_break (GNUNET_NO != ch->destroy);
return;
}
- if (NULL != rel->head_sent && 64 <= rel->mid_send - rel->head_sent->mid)
+ if (NULL != rel->head_sent)
{
- LOG (GNUNET_ERROR_TYPE_DEBUG, " too big MID gap! Wait for ACK.\n");
- return;
+ if (64 <= rel->mid_send - rel->head_sent->mid)
+ {
+ LOG (GNUNET_ERROR_TYPE_DEBUG, " too big MID gap! Wait for ACK.\n");
+ return;
+ }
+ else
+ LOG (GNUNET_ERROR_TYPE_DEBUG, " gap ok: %u - %u\n",
+ rel->head_sent->mid, rel->mid_send);
+ }
+ else
+ {
+ LOG (GNUNET_ERROR_TYPE_DEBUG, " head sent is NULL\n");
}
}
if (is_loopback (ch))
{
if (GMCH_get_buffer (ch, fwd) > 0)
- send_client_ack (ch, fwd);
+ GMCH_allow_client (ch, fwd);
return GNUNET_OK;
}
if (GMT_get_connections_buffer (ch->t) > 0)
{
- send_client_ack (ch, fwd);
+ GMCH_allow_client (ch, fwd);
}
return GNUNET_OK;
work = GNUNET_YES;
LOG (GNUNET_ERROR_TYPE_DEBUG, " !! id %u\n", copy->mid);
next = copy->next;
- rel_message_free (copy, GNUNET_YES);
+ if (GNUNET_YES == rel_message_free (copy, GNUNET_YES))
+ return;
}
/* ACK client if needed */
if (GNUNET_SCHEDULER_NO_TASK != rel->retry_task)
{
GNUNET_SCHEDULER_cancel (rel->retry_task);
+ rel->retry_task = GNUNET_SCHEDULER_NO_TASK;
if (NULL != rel->head_sent && NULL == rel->head_sent->q)
{
struct GNUNET_TIME_Absolute new_target;
&channel_retransmit_message,
rel);
}
- else /* either no more traffic to ack or traffic has just been queued */
- {
- rel->retry_task = GNUNET_SCHEDULER_NO_TASK;
- }
}
else /* work was done but no task was pending? shouldn't happen! */
{
}
LOG (GNUNET_ERROR_TYPE_DEBUG, " new q: %p\n", q);
q->copy->q = q;
- q->q = GMT_send_prebuilt_message (message, ch->t, ch,
+ q->q = GMT_send_prebuilt_message (message, ch->t,
NULL != existing_copy,
&ch_message_sent, q);
/* q itself is stored in copy */
+ GNUNET_assert (NULL != q->q || GNUNET_NO != ch->destroy);
}
else
{
GNUNET_free (q->rel->uniq);
}
}
- q->q = GMT_send_prebuilt_message (message, ch->t, ch, GNUNET_YES,
+ q->q = GMT_send_prebuilt_message (message, ch->t, GNUNET_YES,
&ch_message_sent, q);
q->rel->uniq = q;
break;