#include "gnunet-service-mesh_peer.h"
-/******************************************************************************/
-/************************ DATA STRUCTURES ****************************/
-/******************************************************************************/
-
-
-
-/******************************************************************************/
-/************************ DEBUG FUNCTIONS ****************************/
-/******************************************************************************/
-
-
/******************************************************************************/
/*********************** GLOBAL VARIABLES ****************************/
/******************************************************************************/
static struct GNUNET_CRYPTO_EddsaPrivateKey *my_private_key;
-/******************************************************************************/
-/*********************** DECLARATIONS **************************/
-/******************************************************************************/
-
-
-/******************************************************************************/
-/****************** GENERAL HELPER FUNCTIONS ************************/
-/******************************************************************************/
-
-
-
-/******************************************************************************/
-/**************** MESH NETWORK HANDLER HELPERS ***********************/
-/******************************************************************************/
-
-
-
-/******************************************************************************/
-/******************** MESH NETWORK HANDLERS **************************/
-/******************************************************************************/
-
-
/******************************************************************************/
/************************ MAIN FUNCTIONS ****************************/
/******************************************************************************/
-
/**
* Task run during shutdown.
*
}
+/**
+ * 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.
*
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,
{
/* 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.
*
GMCH_handle_create (struct MeshTunnel3 *t,
const struct GNUNET_MESH_ChannelCreate *msg);
+/**
+ * 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);
+
/**
* Handler for channel ack messages.
*
}
+/**
+ * Build a local channel NACK message and send it to a local client.
+ *
+ * @param c Client to whom send the NACK.
+ * @param id Channel ID to use
+ */
+void
+GML_send_nack (struct MeshClient *c, MESH_ChannelNumber id)
+{
+ struct GNUNET_MESH_LocalAck msg;
+
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "send local nack on %X towards %p\n",
+ id, c);
+
+ msg.header.size = htons (sizeof (msg));
+ msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_NACK);
+ msg.channel_id = htonl (id);
+ GNUNET_SERVER_notification_context_unicast (nc,
+ c->handle,
+ &msg.header,
+ GNUNET_NO);
+
+}
+
+
/**
* Notify the client that a new incoming channel was created.
*
void
GML_send_ack (struct MeshClient *c, MESH_ChannelNumber id);
+/**
+ * Build a local channel NACK message and send it to a local client.
+ *
+ * @param c Client to whom send the NACK.
+ * @param id Channel ID to use
+ */
+void
+GML_send_nack (struct MeshClient *c, MESH_ChannelNumber id);
+
/**
* Notify the appropriate client that a new incoming channel was created.
*
* #GNUNET_NO if message is BCK on the respective channel (loopback)
* #GNUNET_SYSERR if message on a one-ended channel (remote)
*/
-void
+static void
handle_data (struct MeshTunnel3 *t,
const struct GNUNET_MESH_Data *msg,
int fwd)
* #GNUNET_NO if message is BCK on the respective channel (loopback)
* #GNUNET_SYSERR if message on a one-ended channel (remote)
*/
-void
+static void
handle_data_ack (struct MeshTunnel3 *t,
const struct GNUNET_MESH_DataACK *msg,
int fwd)
* @param t Tunnel on which the data came.
* @param msg Data message.
*/
-void
+static void
handle_ch_create (struct MeshTunnel3 *t,
const struct GNUNET_MESH_ChannelCreate *msg)
{
}
+
+/**
+ * Handle channel NACK.
+ *
+ * @param t Tunnel on which the data came.
+ * @param msg Data message.
+ */
+static void
+handle_ch_nack (struct MeshTunnel3 *t,
+ const struct GNUNET_MESH_ChannelManage *msg)
+{
+ struct MeshChannel *ch;
+ size_t size;
+
+ /* Check size */
+ size = ntohs (msg->header.size);
+ if (size != sizeof (struct GNUNET_MESH_ChannelManage))
+ {
+ GNUNET_break (0);
+ return;
+ }
+
+ /* Check channel */
+ ch = GMT_get_channel (t, ntohl (msg->chid));
+ if (NULL != ch && ! GMT_is_loopback (t))
+ {
+ GNUNET_STATISTICS_update (stats, "# channel NACK on unknown channel",
+ 1, GNUNET_NO);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "WARNING channel %u unknown\n",
+ ntohl (msg->chid));
+ return;
+ }
+
+ GMCH_handle_nack (ch);
+}
+
+
/**
* Handle a CHANNEL ACK (SYNACK/ACK).
*
* #GNUNET_NO if message is BCK on the respective channel (loopback)
* #GNUNET_SYSERR if message on a one-ended channel (remote)
*/
-void
+static void
handle_ch_ack (struct MeshTunnel3 *t,
const struct GNUNET_MESH_ChannelManage *msg,
int fwd)
* #GNUNET_NO if message is BCK on the respective channel (loopback)
* #GNUNET_SYSERR if message on a one-ended channel (remote)
*/
-void
+static void
handle_ch_destroy (struct MeshTunnel3 *t,
const struct GNUNET_MESH_ChannelManage *msg,
int fwd)
(struct GNUNET_MESH_ChannelCreate *) msgh);
break;
+ case GNUNET_MESSAGE_TYPE_MESH_CHANNEL_NACK:
+ handle_ch_nack (t,
+ (struct GNUNET_MESH_ChannelManage *) msgh);
+ break;
+
case GNUNET_MESSAGE_TYPE_MESH_CHANNEL_ACK:
handle_ch_ack (t,
(struct GNUNET_MESH_ChannelManage *) msgh,
continue;
/* Clients should have aborted their requests already.
* Management traffic should be ok, as clients can't cancel that */
- GNUNET_break (GNUNET_NO == th_is_payload(th));
+ GNUNET_break (GNUNET_NO == th_is_payload (th));
GNUNET_CONTAINER_DLL_remove (h->th_head, h->th_tail, th);
/* clean up request */
* @param h Mesh handle.
* @param message Message itself.
*/
-static void
-process_get_channels (struct GNUNET_MESH_Handle *h,
- const struct GNUNET_MessageHeader *message)
-{
- struct GNUNET_MESH_LocalMonitor *msg;
-
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Get Channels messasge received\n");
-
- if (NULL == h->channels_cb)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, " ignored\n");
- return;
- }
-
- msg = (struct GNUNET_MESH_LocalMonitor *) message;
- if (ntohs (message->size) !=
- (sizeof (struct GNUNET_MESH_LocalMonitor) +
- sizeof (struct GNUNET_PeerIdentity)))
- {
- GNUNET_break_op (0);
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Get channels message: size %hu - expected %u\n",
- ntohs (message->size),
- sizeof (struct GNUNET_MESH_LocalMonitor));
- return;
- }
- h->channels_cb (h->channels_cls,
- ntohl (msg->channel_id),
- &msg->owner,
- &msg->destination);
-}
+// static void
+// process_get_channels (struct GNUNET_MESH_Handle *h,
+// const struct GNUNET_MessageHeader *message)
+// {
+// struct GNUNET_MESH_LocalMonitor *msg;
+//
+// GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Get Channels messasge received\n");
+//
+// if (NULL == h->channels_cb)
+// {
+// GNUNET_log (GNUNET_ERROR_TYPE_ERROR, " ignored\n");
+// return;
+// }
+//
+// msg = (struct GNUNET_MESH_LocalMonitor *) message;
+// if (ntohs (message->size) !=
+// (sizeof (struct GNUNET_MESH_LocalMonitor) +
+// sizeof (struct GNUNET_PeerIdentity)))
+// {
+// GNUNET_break_op (0);
+// GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+// "Get channels message: size %hu - expected %u\n",
+// ntohs (message->size),
+// sizeof (struct GNUNET_MESH_LocalMonitor));
+// return;
+// }
+// h->channels_cb (h->channels_cls,
+// ntohl (msg->channel_id),
+// &msg->owner,
+// &msg->destination);
+// }
* @param h Mesh handle.
* @param message Message itself.
*/
-static void
-process_show_channel (struct GNUNET_MESH_Handle *h,
- const struct GNUNET_MessageHeader *message)
-{
- struct GNUNET_MESH_LocalMonitor *msg;
- size_t esize;
-
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Show Channel messasge received\n");
-
- if (NULL == h->channel_cb)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, " ignored\n");
- return;
- }
-
- /* Verify message sanity */
- msg = (struct GNUNET_MESH_LocalMonitor *) message;
- esize = sizeof (struct GNUNET_MESH_LocalMonitor);
- if (ntohs (message->size) != esize)
- {
- GNUNET_break_op (0);
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Show channel message: size %hu - expected %u\n",
- ntohs (message->size),
- esize);
-
- h->channel_cb (h->channel_cls, NULL, NULL);
- h->channel_cb = NULL;
- h->channel_cls = NULL;
-
- return;
- }
-
- h->channel_cb (h->channel_cls,
- &msg->destination,
- &msg->owner);
-}
+// static void
+// process_show_channel (struct GNUNET_MESH_Handle *h,
+// const struct GNUNET_MessageHeader *message)
+// {
+// struct GNUNET_MESH_LocalMonitor *msg;
+// size_t esize;
+//
+// GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Show Channel messasge received\n");
+//
+// if (NULL == h->channel_cb)
+// {
+// GNUNET_log (GNUNET_ERROR_TYPE_ERROR, " ignored\n");
+// return;
+// }
+//
+// /* Verify message sanity */
+// msg = (struct GNUNET_MESH_LocalMonitor *) message;
+// esize = sizeof (struct GNUNET_MESH_LocalMonitor);
+// if (ntohs (message->size) != esize)
+// {
+// GNUNET_break_op (0);
+// GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+// "Show channel message: size %hu - expected %u\n",
+// ntohs (message->size),
+// esize);
+//
+// h->channel_cb (h->channel_cls, NULL, NULL);
+// h->channel_cb = NULL;
+// h->channel_cls = NULL;
+//
+// return;
+// }
+//
+// h->channel_cb (h->channel_cls,
+// &msg->destination,
+// &msg->owner);
+// }
/**
break;
/* Notify of a channel disconnection */
case GNUNET_MESSAGE_TYPE_MESH_CHANNEL_DESTROY:
+ case GNUNET_MESSAGE_TYPE_MESH_LOCAL_NACK:
process_channel_destroy (h, (struct GNUNET_MESH_ChannelMessage *) msg);
break;
- /* Notify of a new data packet in the channel */
case GNUNET_MESSAGE_TYPE_MESH_LOCAL_DATA:
process_incoming_data (h, msg);
break;
case GNUNET_MESSAGE_TYPE_MESH_LOCAL_ACK:
process_ack (h, msg);
break;
- case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_CHANNELS:
- process_get_channels (h, msg);
- break;
- case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_CHANNEL:
- process_show_channel (h, msg);
- break;
+// case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_CHANNELS: DEPRECATED
+// process_get_channels (h, msg);
+// break;
+// case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_CHANNEL: DEPRECATED
+// process_show_channel (h, msg);
+// break;
default:
/* We shouldn't get any other packages, log and ignore */
LOG (GNUNET_ERROR_TYPE_WARNING,
struct GNUNET_MESH_ChannelManage
{
/**
- * Type: GNUNET_MESSAGE_TYPE_MESH_CHANNEL_{ACK|DESTROY}
+ * Type: GNUNET_MESSAGE_TYPE_MESH_CHANNEL_{ACK|NACK|DESTROY}
*/
struct GNUNET_MessageHeader header;