}
+/**
+ * Confirm we got a channel create.
+ *
+ * @param ch The channel to confirm.
+ * @param fwd Should we send a FWD ACK? (going dest->root)
+ */
+static void
+channel_send_ack (struct MeshChannel *ch, int fwd)
+{
+ struct GNUNET_MESH_ChannelManage msg;
+
+ msg.header.size = htons (sizeof (msg));
+ msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_CHANNEL_ACK);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ " sending channel %s ack for channel %s\n",
+ fwd ? "FWD" : "BCK", GMCH_2s (ch));
+
+ msg.chid = htonl (ch->gid);
+ GMCH_send_prebuilt_message (&msg.header, ch, !fwd);
+}
+
/**
* Channel was ACK'd by remote peer, mark as ready and cancel retransmission.
/* TODO return? */
}
}
- send_ack (NULL, ch, fwd);
+
+ /* In case of a FWD ACk (SYNACK) send a BCK ACK (ACK). */
+ if (fwd)
+ channel_send_ack (ch, !fwd);
}
*/
static struct MeshChannel *
channel_new (struct MeshTunnel3 *t,
- struct MeshClient *owner, MESH_ChannelNumber lid_root)
+ struct MeshClient *owner,
+ MESH_ChannelNumber lid_root)
{
struct MeshChannel *ch;
}
-
-/**
- * Confirm we got a channel create.
- *
- * @param ch The channel to confirm.
- * @param fwd Should we send the ACK fwd?
- */
-static void
-channel_send_ack (struct MeshChannel *ch, int fwd)
-{
- struct GNUNET_MESH_ChannelManage msg;
-
- msg.header.size = htons (sizeof (msg));
- msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_CHANNEL_ACK);
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- " sending channel %s ack for channel %s:%X\n",
- fwd ? "FWD" : "BCK", GMT_2s (ch->t),
- ch->gid);
-
- msg.chid = htonl (ch->gid);
- GMCH_send_prebuilt_message (&msg.header, ch, !fwd);
-}
-
-
/**
* Handle a loopback message: call the appropriate handler for the message type.
*
type = ntohs (msgh->type);
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Loopback %s message!\n",
- GNUNET_MESH_DEBUG_M2S (type));
+ "Loopback %s %s message!\n",
+ fwd ? "FWD" : "BCK", GNUNET_MESH_DEBUG_M2S (type));
switch (type)
{
break;
case GNUNET_MESSAGE_TYPE_MESH_CHANNEL_CREATE:
- // FIXME store channel in loopback tunnel?
- GMCH_handle_create ((struct GNUNET_MESH_ChannelCreate *) msgh,
+ GMCH_handle_create (ch->t,
+ (struct GNUNET_MESH_ChannelCreate *) msgh,
fwd);
break;
const struct GNUNET_MESH_Data *msg,
int fwd)
{
+ if (GMCH_is_terminal (ch, fwd))
+ {
+ GML_send_data (fwd ? ch->dest : ch->root,
+ msg,
+ fwd ? ch->lid_dest : ch->lid_root);
+ }
+ else
+ {
+ GMT_send_prebuilt_message (&msg->header, ch->t, ch, fwd);
+ }
}
* @param fwd Is for FWD traffic? (ACK dest->owner)
*/
void
-GMCH_send_ack (struct MeshChannel *ch, int fwd)
+GMCH_send_data_ack (struct MeshChannel *ch, int fwd)
{
struct GNUNET_MESH_DataACK msg;
struct MeshChannelReliability *rel;
rel->client_ready = GNUNET_YES;
send_client_buffered_data (ch, c, fwd);
- send_ack (NULL, ch, fwd);
+ GMC_send_ack (NULL, ch, fwd);
}
ch->root_rel->ch = ch;
ch->root_rel->expected_delay = MESH_RETRANSMIT_TIME;
- LOG (GNUNET_ERROR_TYPE_DEBUG, "CREATED CHANNEL %s[%x]:%u (%x)\n",
- GMT_2s (t), ch->gid, ch->port, ch->lid_root);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "CREATED CHANNEL %s\n", GMCH_2s (ch));
/* Send create channel */
{
mid, rel->mid_recv, rel->mid_recv + 64);
}
- GMCH_send_ack (ch, fwd);
+ GMCH_send_data_ack (ch, fwd);
}
/**
* Handler for channel create messages.
*
+ * @param t Tunnel this channel will be in.
* @param msg Message.
* @param fwd Is this FWD traffic? GNUNET_YES : GNUNET_NO;
*/
struct MeshChannel *
-GMCH_handle_create (const struct GNUNET_MESH_ChannelCreate *msg,
+GMCH_handle_create (struct MeshTunnel3 *t,
+ const struct GNUNET_MESH_ChannelCreate *msg,
int fwd)
{
MESH_ChannelNumber chid;
chid = ntohl (msg->chid);
- /* Create channel */
- ch = channel_new (NULL, NULL, 0); /* FIXME pass t */
- ch->gid = chid;
+ ch = GMT_get_channel (t, chid);
+ if (NULL == ch)
+ {
+ /* Create channel */
+ ch = channel_new (t, NULL, 0);
+ ch->gid = chid;
+ }
channel_set_options (ch, ntohl (msg->opt));
/* Find a destination client */
LOG (GNUNET_ERROR_TYPE_DEBUG, "!!! Reliable\n");
GMCH_send_create (ch);
- GMCH_send_ack (ch, fwd);
+ channel_send_ack (ch, fwd);
+ GMCH_send_data_ack (ch, fwd);
if (GNUNET_NO == ch->dest_rel->client_ready)
{
GMCH_send_prebuilt_message (const struct GNUNET_MessageHeader *message,
struct MeshChannel *ch, int fwd)
{
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Send on Channel %s:%X %s\n",
- GMT_2s (ch->t), ch->gid, fwd ? "FWD" : "BCK");
+ 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)));