- struct MeshTunnel3Queue *q;
- struct MeshConnection *c;
- struct GNUNET_MESH_Encrypted *msg;
- size_t size = ntohs (message->size);
- size_t encrypted_size;
- char cbuf[sizeof (struct GNUNET_MESH_Encrypted) + size];
- uint32_t iv;
- uint16_t type;
-
- LOG (GNUNET_ERROR_TYPE_DEBUG, "GMT Send on Tunnel %s\n", GMT_2s (t));
-
- if (GNUNET_NO == is_ready (t))
- {
- queue_data (t, ch, message);
- /* FIXME */
- return NULL;
- }
-
- if (GMT_is_loopback (t))
- {
- LOG (GNUNET_ERROR_TYPE_DEBUG, " loopback!\n");
- handle_decrypted (t, message, fwd);
- /* FIXME: call cont? */
- return NULL; /* Already delivered, cannot cancel */
- }
-
- iv = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX);
- msg = (struct GNUNET_MESH_Encrypted *) cbuf;
- msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_ENCRYPTED);
- msg->iv = iv;
- encrypted_size = t_encrypt (t, &msg[1], message, size, iv);
- msg->header.size = htons (sizeof (struct GNUNET_MESH_Encrypted) + encrypted_size);
- c = tunnel_get_connection (t);
- if (NULL == c)
- {
- GNUNET_break (GNUNET_YES == t->destroy);
- return NULL;
- }
- type = ntohs (message->type);
- switch (type)
- {
- case GNUNET_MESSAGE_TYPE_MESH_DATA:
- case GNUNET_MESSAGE_TYPE_MESH_DATA_ACK:
- case GNUNET_MESSAGE_TYPE_MESH_CHANNEL_CREATE:
- case GNUNET_MESSAGE_TYPE_MESH_CHANNEL_DESTROY:
- case GNUNET_MESSAGE_TYPE_MESH_CHANNEL_ACK:
- msg->cid = *GMC_get_id (c);
- msg->ttl = htonl (default_ttl);
- break;
- default:
- LOG (GNUNET_ERROR_TYPE_DEBUG, "unkown type %s\n",
- GNUNET_MESH_DEBUG_M2S (type));
- GNUNET_break (0);
- }
-
- fwd = GMC_is_origin (c, GNUNET_YES);
-
- if (NULL == cont)
- {
- (void) GMC_send_prebuilt_message (&msg->header, c, fwd, NULL, NULL);
- return NULL;
- }
- q = GNUNET_new (struct MeshTunnel3Queue); /* FIXME valgrind: leak*/
- q->q = GMC_send_prebuilt_message (&msg->header, c, fwd, &message_sent, q);
- q->cont = cont;
- q->cont_cls = cont_cls;
-
- return q;