#include "platform.h"
#include "gnunet_util_lib.h"
+#include "gnunet_statistics_service.h"
+
#include "mesh_protocol_enc.h"
#include "gnunet-service-mesh_tunnel.h"
#include "gnunet-service-mesh_connection.h"
#include "gnunet-service-mesh_channel.h"
+#include "gnunet-service-mesh_peer.h"
#include "mesh_path.h"
#define LOG(level, ...) GNUNET_log_from(level,"mesh-tun",__VA_ARGS__)
/******************************* GLOBALS ***********************************/
/******************************************************************************/
+/**
+ * Global handle to the statistics service.
+ */
+extern struct GNUNET_STATISTICS_Handle *stats;
+
/**
* Default TTL for payload packets.
*/
/******************************** STATIC ***********************************/
/******************************************************************************/
-
/**
* Get string description for tunnel state.
*
for (c = t->connection_head; NULL != c; c = c->next)
{
LOG (GNUNET_ERROR_TYPE_DEBUG, " connection %s: %u\n",
- GNUNET_h2s (&c->id), c->state);
+ GNUNET_h2s (GMC_get_id (c)), c->state);
if (MESH_CONNECTION_READY == c->state)
{
fc = fwd ? &c->fwd_fc : &c->bck_fc;
}
+/******************************************************************************/
+/******************************** API ***********************************/
+/******************************************************************************/
+
/**
* Cache a message to be sent once tunnel is online.
*
}
-
-/******************************************************************************/
-/******************************** API ***********************************/
-/******************************************************************************/
-
/**
* Initialize the tunnel subsystem.
*
void
GMT_destroy_if_empty (struct MeshTunnel2 *t)
{
- if (1 <= GMCH_count (t->channel_head))
+ if (1 < GMCH_count (t->channel_head))
return;
GMT_destroy_empty (t);
}
GNUNET_STATISTICS_update (stats, "# tunnels", -1, GNUNET_NO);
- t->peer->tunnel = NULL;
+ GMP_set_tunnel (t->peer, NULL);
GNUNET_free (t);
}
{
case GNUNET_MESSAGE_TYPE_MESH_DATA:
/* Don't send hop ACK, wait for client to ACK */
- handle_data (t, (struct GNUNET_MESH_Data *) msgh, fwd);
+ GMCH_handle_data (t, (struct GNUNET_MESH_Data *) msgh, fwd);
break;
case GNUNET_MESSAGE_TYPE_MESH_DATA_ACK:
- handle_data_ack (t, (struct GNUNET_MESH_DataACK *) msgh, fwd);
+ GMCH_handle_data_ack (t, (struct GNUNET_MESH_DataACK *) msgh, fwd);
break;
case GNUNET_MESSAGE_TYPE_MESH_CHANNEL_CREATE:
- handle_channel_create (t,
- (struct GNUNET_MESH_ChannelCreate *) msgh,
- fwd);
+ GMCH_handle_create (t,
+ (struct GNUNET_MESH_ChannelCreate *) msgh,
+ fwd);
break;
case GNUNET_MESSAGE_TYPE_MESH_CHANNEL_ACK:
- handle_channel_ack (t,
- (struct GNUNET_MESH_ChannelManage *) msgh,
- fwd);
+ GMCH_handle_ack (t,
+ (struct GNUNET_MESH_ChannelManage *) msgh,
+ fwd);
break;
case GNUNET_MESSAGE_TYPE_MESH_CHANNEL_DESTROY:
- handle_channel_destroy (t,
- (struct GNUNET_MESH_ChannelManage *) msgh,
- fwd);
+ GMCH_handle_destroy (t,
+ (struct GNUNET_MESH_ChannelManage *) msgh,
+ fwd);
break;
default:
+ GNUNET_break_op (0);
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "end-to-end message not known (%u)\n",
- ntohs (msgh->type));
+ "end-to-end message not known (%u)\n",
+ ntohs (msgh->type));
}
}
{
struct MeshConnection *c;
struct GNUNET_HashCode cid;
- struct MeshPeer *peer;
unsigned int own_pos;
if (NULL == t || NULL == p)
return NULL;
}
- GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_NONCE, &cid);
-
- c = GMC_new (&cid);
- c->t = t;
- GNUNET_CONTAINER_DLL_insert (t->connection_head, t->connection_tail, c);
for (own_pos = 0; own_pos < p->length; own_pos++)
{
- if (p->peers[own_pos] == myid)
+ if (p->peers[own_pos] == my_short_id)
break;
}
if (own_pos > p->length - 1)
{
GNUNET_break (0);
- connection_destroy (c);
return NULL;
}
- c->own_pos = own_pos;
- c->path = p;
-
- if (0 == own_pos)
- {
- c->fwd_maintenance_task =
- GNUNET_SCHEDULER_add_delayed (refresh_connection_time,
- &connection_fwd_keepalive, c);
- }
- peer = connection_get_next_hop (c);
- if (NULL == peer->connections)
- {
- connection_destroy (c);
- return NULL;
- }
- GNUNET_CONTAINER_multihashmap_put (peer->connections, &c->id, c,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
- peer = connection_get_prev_hop (c);
- if (NULL == peer->connections)
- {
- connection_destroy (c);
- return NULL;
- }
- GNUNET_CONTAINER_multihashmap_put (peer->connections, &c->id, c,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
+ GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_NONCE, &cid);
+ c = GMC_new (&cid, t, p, own_pos);
+ GNUNET_CONTAINER_DLL_insert (t->connection_head, t->connection_tail, c);
return c;
}
case GNUNET_MESSAGE_TYPE_MESH_BCK:
case GNUNET_MESSAGE_TYPE_MESH_CHANNEL_CREATE:
case GNUNET_MESSAGE_TYPE_MESH_CHANNEL_DESTROY:
- msg->cid = c->id;
+ msg->cid = *GMC_get_id (c);
msg->ttl = htonl (default_ttl);
break;
default: