/*
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
/**
* Tunnel Queue.
*/
- struct CadetTunnel3Queue *tq;
+ struct CadetTunnelQueue *tq;
/**
* Message type (DATA/DATA_ACK)
/**
* 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.
/**
* Tunnel this channel is in.
*/
- struct CadetTunnel3 *t;
+ struct CadetTunnel *t;
/**
* Destination port of the channel.
/******************************** STATIC ***********************************/
/******************************************************************************/
+
/**
* Destroy a reliable message after it has been acknowledged, either by
* direct mid ACK or bitfield. Updates the appropriate data structures and
* 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);
*
* @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);
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);
}
{
struct GNUNET_CADET_Data *msg = (struct GNUNET_CADET_Data *) ©[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
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;
copy = rel->head_sent;
if (NULL == copy)
{
- GNUNET_break (0);
+ GNUNET_break (0); // FIXME tripped in rps testcase
return;
}
{
struct CadetChannelReliability *rel = cls;
- rel->retry_task = GNUNET_SCHEDULER_NO_TASK;
+ rel->retry_task = NULL;
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
return;
}
else if (rel == rel->ch->dest_rel)
{
- send_ack (rel->ch, GNUNET_YES, GNUNET_NO);
+ send_ack (rel->ch, GNUNET_YES);
}
else
{
*/
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;
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,
&& 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));
*
* @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;
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);
}
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);
}
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;
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);
}
* @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)
{
GCCH_destroy (struct CadetChannel *ch)
{
struct CadetClient *c;
- struct CadetTunnel3 *t;
+ struct CadetTunnel *t;
if (NULL == ch)
return;
*
* @return tunnel of the channel.
*/
-struct CadetTunnel3 *
+struct CadetTunnel *
GCCH_get_tunnel (const struct CadetChannel *ch)
{
return ch->t;
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);
}
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);
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
{
{
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.
*
* @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];
/**
* 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.
struct GNUNET_CADET_ChannelMessage *msg)
{
struct CadetChannel *ch;
- struct CadetTunnel3 *t;
+ struct CadetTunnel *t;
struct CadetPeer *peer;
CADET_ChannelNumber chid;
if (GCP_get_short_id (peer) == myid)
{
- GCT_change_cstate (t, CADET_TUNNEL3_READY);
+ GCT_change_cstate (t, CADET_TUNNEL_READY);
}
else
{
/* 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
}
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);
}
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)
{
/* 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;
* @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)
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;
}
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);
}
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;
{
GCT_cancel (chq->rel->uniq->tq);
/* ch_message_sent is called, freeing and NULLing uniq */
+ GNUNET_break (NULL == chq->rel->uniq);
}
else
{
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;
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;