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.
+ *
+ * @param ch Channel to which add the destination.
+ * @param c Client which to add to the channel.
+ */
+static void
+add_destination (struct MeshChannel *ch, struct MeshClient *c)
+{
+ if (NULL != ch->dest)
+ {
+ GNUNET_break (0);
+ return;
+ }
+
+ /* Assign local id as destination */
+ ch->lid_dest = GML_get_next_chid (c);
+
+ /* Store in client's hashmap */
+ GML_channel_add (c, ch->lid_dest, ch);
+
+ GNUNET_break (NULL == ch->dest_rel);
+ ch->dest_rel = GNUNET_new (struct MeshChannelReliability);
+ ch->dest_rel->ch = ch;
+ ch->dest_rel->expected_delay = MESH_RETRANSMIT_TIME;
+
+ ch->dest = c;
+}
+
/**
* Send data to a client.
/**
- * Add a client to a channel, initializing all needed data structures.
+ * Send a buffered message to the client, for in order delivery or
+ * as result of client ACK.
*
- * @param ch Channel to which add the client.
- * @param c Client which to add to the channel.
+ * @param ch Channel on which to empty the message buffer.
+ * @param c Client to send to.
+ * @param fwd Is this to send FWD data?.
*/
-void
-GMCH_add_client (struct MeshChannel *ch, struct MeshClient *c)
+static void
+send_client_buffered_data (struct MeshChannel *ch,
+ struct MeshClient *c,
+ int fwd)
{
- if (NULL != ch->dest)
+ struct MeshReliableMessage *copy;
+ struct MeshChannelReliability *rel;
+
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "send_buffered_data\n");
+ rel = fwd ? ch->dest_rel : ch->root_rel;
+ if (GNUNET_NO == rel->client_ready)
{
- GNUNET_break (0);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "client not ready\n");
return;
}
- /* Assign local id as destination */
- ch->lid_dest = GML_get_next_chid (c);
+ copy = rel->head_recv;
+ /* We never buffer channel management messages */
+ if (NULL != copy)
+ {
+ if (copy->mid == rel->mid_recv || GNUNET_NO == ch->reliable)
+ {
+ struct GNUNET_MESH_Data *msg = (struct GNUNET_MESH_Data *) ©[1];
- /* Store in client's hashmap */
- GML_channel_add (c, ch->lid_dest, ch);
+ 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);
+ GNUNET_free (copy);
+ }
+ else
+ {
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ " reliable && don't have %u, next is %u\n",
+ rel->mid_recv,
+ copy->mid);
+ return;
+ }
+ }
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "send_buffered_data END\n");
+}
- GNUNET_break (NULL == ch->dest_rel);
- ch->dest_rel = GNUNET_new (struct MeshChannelReliability);
- ch->dest_rel->ch = ch;
- ch->dest_rel->expected_delay = MESH_RETRANSMIT_TIME;
- ch->dest = c;
+/**
+ * Allow a client to send more data.
+ *
+ * In case the client was already allowed to send data, do nothing.
+ *
+ * @param ch Channel.
+ * @param fwd Is this a FWD ACK? (FWD ACKs are sent to root)
+ */
+static void
+send_client_ack (struct MeshChannel *ch, int fwd)
+{
+ struct MeshChannelReliability *rel = fwd ? ch->root_rel : ch->dest_rel;
+
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ " sending %s ack to client on channel %s\n",
+ fwd ? "FWD" : "BCK", GMCH_2s (ch));
+
+ if (NULL == rel)
+ {
+ GNUNET_break (0);
+ return;
+ }
+
+ GML_send_ack (fwd ? ch->root : ch->dest, fwd ? ch->lid_root : ch->lid_dest);
}
ch->state = MESH_CHANNEL_READY;
rel = fwd ? ch->root_rel : ch->dest_rel;
+ rel->client_ready = GNUNET_YES;
for (copy = rel->head_sent; NULL != copy; copy = next)
{
struct GNUNET_MessageHeader *msg;
/* TODO return? */
}
}
- GMCH_send_data_ack (ch, fwd);
+ send_client_ack (ch, fwd);
- /* In case of a FWD ACk (SYNACK) send a BCK ACK (ACK). */
+ /* In case of a FWD ACK (SYNACK) send a BCK ACK (ACK). */
if (fwd)
channel_send_ack (ch, !fwd);
}
}
-
-/**
- * Send a buffered message to the client, for in order delivery or
- * as result of client ACK.
- *
- * @param ch Channel on which to empty the message buffer.
- * @param c Client to send to.
- * @param fwd Is this to send FWD data?.
- */
-static void
-send_client_buffered_data (struct MeshChannel *ch,
- struct MeshClient *c,
- int fwd)
-{
- struct MeshReliableMessage *copy;
- struct MeshChannelReliability *rel;
-
- LOG (GNUNET_ERROR_TYPE_DEBUG, "send_buffered_data\n");
- rel = fwd ? ch->dest_rel : ch->root_rel;
- if (GNUNET_NO == rel->client_ready)
- {
- LOG (GNUNET_ERROR_TYPE_DEBUG, "client not ready\n");
- return;
- }
-
- copy = rel->head_recv;
- /* We never buffer channel management messages */
- if (NULL != copy)
- {
- if (copy->mid == rel->mid_recv || GNUNET_NO == ch->reliable)
- {
- struct GNUNET_MESH_Data *msg = (struct GNUNET_MESH_Data *) ©[1];
-
- 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);
- GNUNET_free (copy);
- }
- else
- {
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- " reliable && don't have %u, next is %u\n",
- rel->mid_recv,
- copy->mid);
- return;
- }
- }
- LOG (GNUNET_ERROR_TYPE_DEBUG, "send_buffered_data END\n");
-}
-
-
-
-
/**
* Destroy a channel and free all resources.
*
/******************************** API ***********************************/
/******************************************************************************/
+
/**
* Get channel ID.
*
payload->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_DATA);
payload->chid = htonl (ch->gid);
LOG (GNUNET_ERROR_TYPE_DEBUG, " sending on channel...\n");
- GMCH_send_prebuilt_message (&payload->header, ch, fwd);
-
if (GNUNET_YES == ch->reliable)
channel_save_copy (ch, &payload->header, fwd);
+ GMCH_send_prebuilt_message (&payload->header, ch, fwd);
+
if (GMT_get_buffer (ch->t, fwd) > 0)
- GML_send_ack (c, fwd ? ch->lid_root : ch->lid_dest);
+ {
+ send_client_ack (ch, fwd);
+ }
return GNUNET_OK;
}
channel_destroy (ch);
return NULL;
}
+ else
+ {
+ LOG (GNUNET_ERROR_TYPE_DEBUG, " client %p has port registered\n", c);
+ }
- GMCH_add_client (ch, c);
+ add_destination (ch, c);
if (GNUNET_YES == ch->reliable)
LOG (GNUNET_ERROR_TYPE_DEBUG, "!!! Reliable\n");
+ else
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "!!! Not Reliable\n");
GMCH_send_create (ch);
channel_send_ack (ch, fwd);
- if (GNUNET_NO == ch->dest_rel->client_ready)
- {
- GML_send_ack (ch->dest, ch->lid_dest);
- ch->dest_rel->client_ready = GNUNET_YES;
- }
-
return ch;
}
GMCH_send_prebuilt_message (const struct GNUNET_MessageHeader *message,
struct MeshChannel *ch, int fwd)
{
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Send %s on channel %s\n",
- fwd ? "FWD" : "BCK", GMCH_2s (ch));
- LOG (GNUNET_ERROR_TYPE_DEBUG, " %s\n",
- GNUNET_MESH_DEBUG_M2S (ntohs (message->type)));
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "GMCH Send %s %s on channel %s\n",
+ fwd ? "FWD" : "BCK", GNUNET_MESH_DEBUG_M2S (ntohs (message->type)),
+ GMCH_2s (ch));
if (GMT_is_loopback (ch->t))
{