* @file vpn/gnunet-service-vpn.c
* @brief service that opens a virtual interface and allows its clients
* to allocate IPs on the virtual interface and to then redirect
- * IP traffic received on those IPs via the GNUnet mesh
+ * IP traffic received on those IPs via the GNUnet cadet
* @author Philipp Toelke
* @author Christian Grothoff
*
* TODO:
- * - keep multiple peers/mesh channels ready as alternative exits /
+ * - keep multiple peers/cadet channels ready as alternative exits /
* detect & recover from channel-to-exit failure gracefully
*/
#include "platform.h"
#include "gnunet_common.h"
#include "gnunet_protocols.h"
#include "gnunet_applications.h"
-#include "gnunet_mesh_service.h"
+#include "gnunet_cadet_service.h"
#include "gnunet_statistics_service.h"
#include "gnunet_constants.h"
#include "gnunet_tun_lib.h"
/**
- * Maximum number of messages we allow in the queue for mesh.
+ * Maximum number of messages we allow in the queue for cadet.
*/
#define MAX_MESSAGE_QUEUE_SIZE 4
* Information about the channel to use, NULL if no channel
* is available right now.
*/
- struct GNUNET_MESH_Channel *channel;
+ struct GNUNET_CADET_Channel *channel;
/**
* Active query with REGEX to locate exit.
/**
* Active transmission handle, NULL for none.
*/
- struct GNUNET_MESH_TransmitHandle *th;
+ struct GNUNET_CADET_TransmitHandle *th;
/**
* Entry for this entry in the channel_heap, NULL as long as this
static const struct GNUNET_CONFIGURATION_Handle *cfg;
/**
- * Handle to the mesh service.
+ * Handle to the cadet service.
*/
-static struct GNUNET_MESH_Handle *mesh_handle;
+static struct GNUNET_CADET_Handle *cadet_handle;
/**
* Map from IP address to destination information (possibly with a
- * MESH channel handle for fast setup).
+ * CADET channel handle for fast setup).
*/
static struct GNUNET_CONTAINER_MultiHashMap *destination_map;
/**
* Map from source and destination address (IP+port) to connection
- * information (mostly with the respective MESH channel handle).
+ * information (mostly with the respective CADET channel handle).
*/
static struct GNUNET_CONTAINER_MultiHashMap *channel_map;
{
struct GNUNET_HashCode key;
struct ChannelMessageQueueEntry *tnq;
- struct GNUNET_MESH_Channel *channel;
+ struct GNUNET_CADET_Channel *channel;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Cleaning up channel state\n");
GNUNET_assert (0 == ts->tmq_length);
if (NULL != ts->th)
{
- GNUNET_MESH_notify_transmit_ready_cancel (ts->th);
+ GNUNET_CADET_notify_transmit_ready_cancel (ts->th);
ts->th = NULL;
}
GNUNET_assert (NULL == ts->destination.heap_node);
if (NULL != (channel = ts->channel))
{
ts->channel = NULL;
- GNUNET_MESH_channel_destroy (channel);
+ GNUNET_CADET_channel_destroy (channel);
}
if (NULL != ts->search)
{
/**
- * Send a message from the message queue via mesh.
+ * Send a message from the message queue via cadet.
*
* @param cls the `struct ChannelState` with the message queue
* @param size number of bytes available in @a buf
GNUNET_assert (NULL != tnq);
GNUNET_assert (size >= tnq->len);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sending %u bytes via mesh channel\n",
+ "Sending %u bytes via cadet channel\n",
tnq->len);
GNUNET_CONTAINER_DLL_remove (ts->tmq_head,
ts->tmq_tail,
ret = tnq->len;
GNUNET_free (tnq);
if (NULL != (tnq = ts->tmq_head))
- ts->th = GNUNET_MESH_notify_transmit_ready (ts->channel,
+ ts->th = GNUNET_CADET_notify_transmit_ready (ts->channel,
GNUNET_NO /* cork */,
GNUNET_TIME_UNIT_FOREVER_REL,
tnq->len,
&send_to_peer_notify_callback,
ts);
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# Bytes given to mesh for transmission"),
+ gettext_noop ("# Bytes given to cadet for transmission"),
ret, GNUNET_NO);
return ret;
}
struct ChannelState *ts)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Queueing %u bytes for transmission via mesh channel\n",
+ "Queueing %u bytes for transmission via cadet channel\n",
tnq->len);
GNUNET_assert (NULL != ts->channel);
GNUNET_CONTAINER_DLL_insert_tail (ts->tmq_head,
ts->tmq_tail,
dq);
ts->tmq_length--;
- GNUNET_MESH_notify_transmit_ready_cancel (ts->th);
+ GNUNET_CADET_notify_transmit_ready_cancel (ts->th);
ts->th = NULL;
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# Bytes dropped in mesh queue (overflow)"),
+ gettext_noop ("# Bytes dropped in cadet queue (overflow)"),
dq->len,
GNUNET_NO);
GNUNET_free (dq);
}
if (NULL == ts->th)
- ts->th = GNUNET_MESH_notify_transmit_ready (ts->channel,
+ ts->th = GNUNET_CADET_notify_transmit_ready (ts->channel,
GNUNET_NO /* cork */,
GNUNET_TIME_UNIT_FOREVER_REL,
tnq->len,
GNUNET_break (0);
return;
}
- ts->channel = GNUNET_MESH_channel_create (mesh_handle,
+ ts->channel = GNUNET_CADET_channel_create (cadet_handle,
ts,
id,
apptype,
- GNUNET_YES,
- GNUNET_NO);
+ GNUNET_CADET_OPTION_DEFAULT);
}
/**
- * Initialize the given destination entry's mesh channel.
+ * Initialize the given destination entry's cadet channel.
*
* @param dt destination channel for which we need to setup a channel
* @param client_af address family of the address returned to the client
unsigned int apptype;
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# Mesh channels created"),
+ gettext_noop ("# Cadet channels created"),
1, GNUNET_NO);
GNUNET_assert (NULL == dt->ts);
switch (client_af)
ts->destination_container = dt; /* we are referenced from dt */
if (dt->destination->is_service)
{
- ts->channel = GNUNET_MESH_channel_create (mesh_handle,
+ ts->channel = GNUNET_CADET_channel_create (cadet_handle,
ts,
&dt->destination->details.service_destination.target,
apptype,
- GNUNET_YES,
- GNUNET_NO);
+ GNUNET_CADET_OPTION_DEFAULT);
if (NULL == ts->channel)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to setup mesh channel!\n"));
+ _("Failed to setup cadet channel!\n"));
GNUNET_free (ts);
return NULL;
}
char address[GNUNET_TUN_IPV6_REGEXLEN];
GNUNET_TUN_ipv6toregexsearch (&dt->destination->details.exit_destination.ip.v6,
- dt->destination_port,
+ dt->destination_port,
address);
GNUNET_asprintf (&policy, "%s%s",
GNUNET_APPLICATION_TYPE_EXIT_REGEX_PREFIX,
/**
- * Route a packet via mesh to the given destination.
+ * Route a packet via cadet to the given destination.
*
* @param destination description of the destination
* @param af address family on this end (AF_INET or AF_INET6)
/**
* Receive packets from the helper-process (someone send to the local
* virtual channel interface). Find the destination mapping, and if it
- * exists, identify the correct MESH channel (or possibly create it)
+ * exists, identify the correct CADET channel (or possibly create it)
* and forward the packet.
*
* @param cls closure, NULL
/**
- * We got an ICMP packet back from the MESH channel. Pass it on to the
+ * We got an ICMP packet back from the CADET channel. Pass it on to the
* local virtual interface via the helper.
*
* @param cls closure, NULL
*/
static int
receive_icmp_back (void *cls,
- struct GNUNET_MESH_Channel *channel,
+ struct GNUNET_CADET_Channel *channel,
void **channel_ctx,
const struct GNUNET_MessageHeader *message)
{
size_t mlen;
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# ICMP packets received from mesh"),
+ gettext_noop ("# ICMP packets received from cadet"),
1, GNUNET_NO);
mlen = ntohs (message->size);
if (mlen < sizeof (struct GNUNET_EXIT_IcmpToVPNMessage))
char dbuf[INET6_ADDRSTRLEN];
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received ICMP packet from mesh, sending %u bytes from %s -> %s via TUN\n",
+ "Received ICMP packet from cadet, sending %u bytes from %s -> %s via TUN\n",
(unsigned int) mlen,
inet_ntop (ts->af, &ts->destination_ip, sbuf, sizeof (sbuf)),
inet_ntop (ts->af, &ts->source_ip, dbuf, sizeof (dbuf)));
/**
- * We got a UDP packet back from the MESH channel. Pass it on to the
+ * We got a UDP packet back from the CADET channel. Pass it on to the
* local virtual interface via the helper.
*
* @param cls closure, NULL
*/
static int
receive_udp_back (void *cls,
- struct GNUNET_MESH_Channel *channel,
+ struct GNUNET_CADET_Channel *channel,
void **channel_ctx,
const struct GNUNET_MessageHeader *message)
{
size_t mlen;
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# UDP packets received from mesh"),
+ gettext_noop ("# UDP packets received from cadet"),
1, GNUNET_NO);
mlen = ntohs (message->size);
if (mlen < sizeof (struct GNUNET_EXIT_UdpReplyMessage))
char dbuf[INET6_ADDRSTRLEN];
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received UDP reply from mesh, sending %u bytes from %s:%u -> %s:%u via TUN\n",
+ "Received UDP reply from cadet, sending %u bytes from %s:%u -> %s:%u via TUN\n",
(unsigned int) mlen,
inet_ntop (ts->af, &ts->destination_ip, sbuf, sizeof (sbuf)),
ts->destination_port,
/**
- * We got a TCP packet back from the MESH channel. Pass it on to the
+ * We got a TCP packet back from the CADET channel. Pass it on to the
* local virtual interface via the helper.
*
* @param cls closure, NULL
*/
static int
receive_tcp_back (void *cls,
- struct GNUNET_MESH_Channel *channel,
+ struct GNUNET_CADET_Channel *channel,
void **channel_ctx,
const struct GNUNET_MessageHeader *message)
{
size_t mlen;
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# TCP packets received from mesh"),
+ gettext_noop ("# TCP packets received from cadet"),
1, GNUNET_NO);
mlen = ntohs (message->size);
if (mlen < sizeof (struct GNUNET_EXIT_TcpDataMessage))
char dbuf[INET6_ADDRSTRLEN];
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received TCP reply from mesh, sending %u bytes from %s:%u -> %s:%u via TUN\n",
+ "Received TCP reply from cadet, sending %u bytes from %s:%u -> %s:%u via TUN\n",
(unsigned int) mlen,
inet_ntop (ts->af, &ts->destination_ip, sbuf, sizeof (sbuf)),
ts->destination_port,
-1, GNUNET_NO);
while (NULL != (dt = de->dt_head))
{
+ GNUNET_CONTAINER_DLL_remove (de->dt_head,
+ de->dt_tail,
+ dt);
if (NULL != dt->ts)
{
free_channel_state (dt->ts);
GNUNET_assert (NULL == dt->ts);
}
- GNUNET_CONTAINER_DLL_remove (de->dt_head,
- de->dt_tail,
- dt);
GNUNET_free (dt);
}
if (NULL != de->heap_node)
* Function called whenever a channel is destroyed. Should clean up
* any associated state.
*
- * @param cls closure (set from #GNUNET_MESH_connect)
+ * @param cls closure (set from #GNUNET_CADET_connect)
* @param channel connection to the other end (henceforth invalid)
* @param channel_ctx place where local state associated
* with the channel is stored (our `struct ChannelState`)
*/
static void
channel_cleaner (void *cls,
- const struct GNUNET_MESH_Channel *channel,
+ const struct GNUNET_CADET_Channel *channel,
void *channel_ctx)
{
struct ChannelState *ts = channel_ctx;
- ts->channel = NULL; /* we must not call GNUNET_MESH_channel_destroy() anymore */
+ ts->channel = NULL; /* we must not call GNUNET_CADET_channel_destroy() anymore */
free_channel_state (ts);
}
GNUNET_CONTAINER_heap_destroy (channel_heap);
channel_heap = NULL;
}
- if (NULL != mesh_handle)
+ if (NULL != cadet_handle)
{
- GNUNET_MESH_disconnect (mesh_handle);
- mesh_handle = NULL;
+ GNUNET_CADET_disconnect (cadet_handle);
+ cadet_handle = NULL;
}
if (NULL != helper_handle)
{
sizeof (struct RedirectToServiceRequestMessage) },
{NULL, NULL, 0, 0}
};
- static const struct GNUNET_MESH_MessageHandler mesh_handlers[] = {
+ static const struct GNUNET_CADET_MessageHandler cadet_handlers[] = {
{ &receive_udp_back, GNUNET_MESSAGE_TYPE_VPN_UDP_REPLY, 0},
{ &receive_tcp_back, GNUNET_MESSAGE_TYPE_VPN_TCP_DATA_TO_VPN, 0},
{ &receive_icmp_back, GNUNET_MESSAGE_TYPE_VPN_ICMP_TO_VPN, 0},
binary = GNUNET_OS_get_libexec_binary_path ("gnunet-helper-vpn");
if (GNUNET_YES !=
- GNUNET_OS_check_helper_binary (binary, GNUNET_YES, "-d gnunet-vpn - - 169.1.3.3.7 255.255.255.0")) //ipv4 only please!
+ GNUNET_OS_check_helper_binary (binary,
+ GNUNET_YES,
+ "-d gnunet-vpn - - 169.1.3.3.7 255.255.255.0")) //ipv4 only please!
{
- fprintf (stderr,
- "`%s' is not SUID, refusing to run.\n",
- "gnunet-helper-vpn");
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "`%s' is not SUID, refusing to run.\n",
+ "gnunet-helper-vpn");
GNUNET_free (binary);
global_ret = 1;
+ /* we won't "really" exit here, as the 'service' is still running;
+ however, as no handlers are registered, the service won't do
+ anything either */
return;
}
GNUNET_free (binary);
}
vpn_argv[6] = NULL;
- mesh_handle =
- GNUNET_MESH_connect (cfg_, NULL,
+ cadet_handle =
+ GNUNET_CADET_connect (cfg_, NULL,
NULL,
&channel_cleaner,
- mesh_handlers,
+ cadet_handlers,
NULL);
helper_handle = GNUNET_HELPER_start (GNUNET_NO,
"gnunet-helper-vpn", vpn_argv,