}
+/**
+ * Notify the root that the destination rejected the channel.
+ *
+ * @param ch Rejected channel.
+ */
+static void
+send_client_nack (struct MeshChannel *ch)
+{
+ if (NULL == ch->root)
+ {
+ GNUNET_break (0);
+ return;
+ }
+ GML_send_nack (ch->root, ch->lid_root);
+}
+
+
/**
* Destroy all reliable messages queued for a channel,
* during a channel destruction.
}
+/**
+ * Notify that a channel create didn't succeed.
+ *
+ * @param ch The channel to reject.
+ */
+static void
+channel_send_nack (struct MeshChannel *ch)
+{
+ struct GNUNET_MESH_ChannelManage msg;
+
+ msg.header.size = htons (sizeof (msg));
+ msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_CHANNEL_NACK);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ " sending channel NACK for channel %s\n",
+ GMCH_2s (ch));
+
+ msg.chid = htonl (ch->gid);
+ GMCH_send_prebuilt_message (&msg.header, ch, GNUNET_NO);
+}
+
+
/**
* Channel was ACK'd by remote peer, mark as ready and cancel retransmission.
*
GNUNET_YES : GNUNET_NO;
}
+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.
fwd);
break;
+ case GNUNET_MESSAGE_TYPE_MESH_CHANNEL_NACK:
+ GMCH_handle_nack (ch);
+ break;
+
case GNUNET_MESSAGE_TYPE_MESH_CHANNEL_DESTROY:
GMCH_handle_destroy (ch,
(struct GNUNET_MESH_ChannelManage *) msgh,
* Mark client as ready and send him any buffered data we could have for him.
*
* @param ch Channel.
- * @param fwd Is this a "FWD ACK"? (FWD ACKs are sent by root and go BCK)
+ * @param fwd Is this a "FWD ACK"? (FWD ACKs are sent by dest and go BCK)
*/
void
GMCH_handle_local_ack (struct MeshChannel *ch, int fwd)
rel->client_ready = GNUNET_YES;
send_client_buffered_data (ch, c, fwd);
- GMT_send_acks (ch->t, fwd);
+ if (is_loopback (ch))
+ {
+ unsigned int buffer;
+
+ buffer = GMCH_get_buffer (ch, fwd);
+ if (0 < buffer)
+ GMCH_allow_client (ch, fwd);
+
+ return;
+ }
+ GMT_send_connection_acks (ch->t);
}
channel_save_copy (ch, &payload->header, fwd);
GMCH_send_prebuilt_message (&payload->header, ch, fwd);
- if (GMT_get_buffer (ch->t, fwd) > 0)
+ if (is_loopback (ch))
+ {
+ if (GMCH_get_buffer (ch, fwd) > 0);
+ send_client_ack (ch, fwd);
+
+ return GNUNET_OK;
+ }
+
+ if (GMT_get_connections_buffer (ch->t) > 0)
{
send_client_ack (ch, fwd);
}
/* If this is a remote (non-loopback) channel, find 'fwd'. */
if (GNUNET_SYSERR == fwd)
{
- if (NULL != ch->dest && NULL != ch->root)
+ if (is_loopback (ch))
{
/* It is a loopback channel after all... */
GNUNET_break (0);
/* If this is a remote (non-loopback) channel, find 'fwd'. */
if (GNUNET_SYSERR == fwd)
{
- if (NULL != ch->dest && NULL != ch->root)
+ if (is_loopback (ch))
{
/* It is a loopback channel after all... */
GNUNET_break (0);
{
/* TODO send reject */
LOG (GNUNET_ERROR_TYPE_DEBUG, " no client has port registered\n");
- channel_destroy (ch);
+ if (is_loopback (ch))
+ {
+ channel_send_nack (ch);
+ }
+ else
+ {
+ channel_send_nack (ch);
+ channel_destroy (ch);
+ }
return NULL;
}
else
}
+/**
+ * Handler for channel NACK messages.
+ *
+ * NACK messages always go dest -> root, no need for 'fwd' or 'msg' parameter.
+ *
+ * @param ch Channel.
+ */
+void
+GMCH_handle_nack (struct MeshChannel *ch)
+{
+ send_client_nack (ch);
+ channel_destroy (ch);
+}
+
+
/**
* Handler for channel ack messages.
*
/* If this is a remote (non-loopback) channel, find 'fwd'. */
if (GNUNET_SYSERR == fwd)
{
- if (NULL != ch->dest && NULL != ch->root)
+ if (is_loopback (ch))
{
/* It is a loopback channel after all... */
GNUNET_break (0);
/* If this is a remote (non-loopback) channel, find 'fwd'. */
if (GNUNET_SYSERR == fwd)
{
- if (NULL != ch->dest && NULL != ch->root)
+ if (is_loopback (ch))
{
/* It is a loopback channel after all... */
GNUNET_break (0);