#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__)
/**
* All the states a tunnel can be in.
/******************************* 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.
*
struct MeshFlowControl *fc;
unsigned int lowest_q;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tunnel_get_connection %s\n",
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "tunnel_get_connection %s\n",
peer2s (t->peer));
best = NULL;
lowest_q = UINT_MAX;
for (c = t->connection_head; NULL != c; c = c->next)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " connection %s: %u\n",
- GNUNET_h2s (&c->id), c->state);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, " connection %s: %u\n",
+ GNUNET_h2s (GMC_get_id (c)), c->state);
if (MESH_CONNECTION_READY == c->state)
{
fc = fwd ? &c->fwd_fc : &c->bck_fc;
GNUNET_break (0);
continue;
}
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " q_n %u, \n", fc->queue_n);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, " q_n %u, \n", fc->queue_n);
if (fc->queue_n < lowest_q)
{
best = c;
struct MeshTunnelQueue *next;
unsigned int room;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
"tunnel_send_queued_data on tunnel %s\n",
peer2s (t->peer));
room = tunnel_get_buffer (t, fwd);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " buffer space: %u\n", room);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, " buffer space: %u\n", room);
for (tq = t->tq_head; NULL != tq && room > 0; tq = next)
{
next = tq->next;
}
+/******************************************************************************/
+/******************************** API ***********************************/
+/******************************************************************************/
+
/**
* Cache a message to be sent once tunnel is online.
*
}
-
-/******************************************************************************/
-/******************************** API ***********************************/
-/******************************************************************************/
-
/**
* Initialize the tunnel subsystem.
*
GNUNET_CONFIGURATION_get_value_number (c, "MESH", "DEFAULT_TTL",
&default_ttl))
{
- GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_WARNING,
+ LOG_config_invalid (GNUNET_ERROR_TYPE_WARNING,
"MESH", "DEFAULT_TTL", "USING DEFAULT");
default_ttl = 64;
}
{
if (NULL == t)
return;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
"Tunnel %s state was %s\n",
peer2s (t->peer),
GNUNET_MESH_DEBUG_TS2S (t->state));
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
"Tunnel %s state is now %s\n",
peer2s (t->peer),
GNUNET_MESH_DEBUG_TS2S (state));
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);
if (NULL == t)
return;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "destroying tunnel %s\n",
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "destroying tunnel %s\n",
peer2s (t->peer));
// if (GNUNET_YES != GNUNET_CONTAINER_multihashmap_remove (tunnels, &t->id, 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_log (GNUNET_ERROR_TYPE_DEBUG,
- "end-to-end message not known (%u)\n",
- ntohs (msgh->type));
+ GNUNET_break_op (0);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "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;
}
struct MeshConnection *c;
uint16_t type;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Send on Tunnel %s\n",
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Send on Tunnel %s\n",
peer2s (t->peer));
c = tunnel_get_connection (t, fwd);
if (NULL == 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:
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "unkown type %s\n",
- GNUNET_MESH_DEBUG_M2S (type));
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "unkown type %s\n",
+ GNUNET_MESH_DEBUG_M2S (type));
GNUNET_break (0);
}
msg->reserved = 0;