#define LOG(level, ...) GNUNET_log_from(level,"mesh-tun",__VA_ARGS__)
+#define START_FUNCTION LOG(GNUNET_ERROR_TYPE_DEBUG, "%s start\n", __FUNCTION__)
+#define END_FUNCTION LOG(GNUNET_ERROR_TYPE_DEBUG, "%s end\n", __FUNCTION__)
+
/******************************************************************************/
/******************************** STRUCTS **********************************/
/**
* FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME
* Encrypt data with the tunnel key.
- * Make static?
*
* @param t Tunnel whose key to use.
* @param dst Destination for the GMT_encrypted data.
/**
* FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME
* Decrypt data with the tunnel key.
- * Make static?
*
* @param t Tunnel whose key to use.
* @param dst Destination for the plaintext.
const struct GNUNET_MESH_ChannelCreate *msg,
int fwd)
{
+ ;
+
struct MeshTChannel *tch;
struct MeshChannel *ch;
size_t size;
}
else
{
- ch = GMCH_handle_create (msg, fwd);
+ ch = GMCH_handle_create (t, msg, fwd);
}
tch = GNUNET_new (struct MeshTChannel);
tch->ch = ch;
GNUNET_CONTAINER_DLL_insert (t->channel_head, t->channel_tail, tch);
+
+ ;
}
void
* @param fwd Is this message fwd?
*/
void
-GMT_handle_GMT_encrypted (struct MeshTunnel3 *t,
+GMT_handle_encrypted (struct MeshTunnel3 *t,
const struct GNUNET_MESH_Encrypted *msg,
int fwd)
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
"GMT_send_queued_data on tunnel %s\n",
- GMP_2s (t->peer));
+ GMT_2s (t));
room = GMT_get_buffer (t, fwd);
LOG (GNUNET_ERROR_TYPE_DEBUG, " buffer space: %u\n", room);
for (tq = t->tq_head; NULL != tq && room > 0; tq = next)
{
+ LOG (GNUNET_ERROR_TYPE_DEBUG, " data on channel %s\n", GMCH_2s (tq->ch));
next = tq->next;
room--;
GNUNET_CONTAINER_DLL_remove (t->tq_head, t->tq_tail, tq);
GNUNET_free (tq);
}
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "GMT_send_queued_data end\n",
+ GMP_2s (t->peer));
}
GMT_init (const struct GNUNET_CONFIGURATION_Handle *c,
const struct GNUNET_CRYPTO_EddsaPrivateKey *key)
{
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "init\n");
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_number (c, "MESH", "DEFAULT_TTL",
&default_ttl))
void
GMT_shutdown (void)
{
- GNUNET_PEER_change_rc (myid, -1);
}
unsigned int ch_buf;
if (NULL == t->channel_head)
+ {
+ /* Probably getting buffer for a channel create. */
return 64;
+ }
for (iter_ch = t->channel_head; NULL != iter_ch; iter_ch = iter_ch->next)
{
}
+/**
+ * Send ACK on one or more connections due to buffer space to the client.
+ *
+ * Iterates all connections of the tunnel and sends ACKs appropriately.
+ *
+ * @param ch Channel which has some free buffer space.
+ * @param fwd Is this in for FWD traffic? (ACK goes dest->root)
+ */
+void
+GMT_send_acks (struct MeshTunnel3 *t, unsigned int buffer, int fwd)
+{
+ struct MeshTConnection *iter;
+ uint32_t allowed;
+ uint32_t to_allow;
+ uint32_t allow_per_connection;
+ unsigned int cs;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Tunnel send acks on %s:%X\n",
+ fwd ? "FWD" : "BCK", GMT_2s (t));
+
+ if (NULL == t)
+ {
+ GNUNET_break (0);
+ return;
+ }
+ if (NULL == t->channel_head ||
+ GNUNET_NO == GMCH_is_origin (t->channel_head->ch, fwd))
+ {
+ GNUNET_break (0);
+ return;
+ }
+
+ /* Count connections, how many messages are already allowed */
+ cs = GMT_count_connections (t);
+ for (allowed = 0, iter = t->connection_head; NULL != iter; iter = iter->next)
+ {
+ allowed += GMC_get_allowed (iter->c, fwd);
+ }
+
+ /* Make sure there is no overflow */
+ if (allowed > buffer)
+ {
+ GNUNET_break (0);
+ return;
+ }
+
+ /* Authorize connections to send more data */
+ to_allow = buffer; /* - allowed; */
+
+ for (iter = t->connection_head; NULL != iter && to_allow > 0; iter = iter->next)
+ {
+ allow_per_connection = to_allow/cs;
+ to_allow -= allow_per_connection;
+ cs--;
+ if (GMC_get_allowed (iter->c, fwd) > 64 / 3)
+ {
+ continue;
+ }
+ GMC_allow (iter->c, buffer, fwd);
+ }
+
+ GNUNET_break (to_allow == 0);
+}
+
+
/**
* Sends an already built message on a tunnel, GMT_encrypting it and
* choosing the best connection.
uint64_t iv;
uint16_t type;
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Send on Tunnel %s\n", GMP_2s (t->peer));
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "GMT Send on Tunnel %s\n", GMP_2s (t->peer));
iv = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_NONCE, UINT64_MAX);
msg = (struct GNUNET_MESH_Encrypted *) cbuf;
type = ntohs (message->type);
switch (type)
{
- case GNUNET_MESSAGE_TYPE_MESH_FWD:
- case GNUNET_MESSAGE_TYPE_MESH_BCK:
+ case GNUNET_MESSAGE_TYPE_MESH_DATA:
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;