From 4d899684274d4d5d0ce68c897acafc3d6d5ea3ab Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Tue, 17 Jan 2012 18:59:02 +0000 Subject: [PATCH] -rename header --- src/dns/gnunet-service-dns.c | 2 +- src/exit/gnunet-daemon-exit.c | 2 +- src/include/Makefile.am | 4 +- src/include/{tcpip_tun.h => gnunet_tun_lib.h} | 4 +- src/vpn/gnunet-service-vpn.c | 153 +++++++++--------- 5 files changed, 83 insertions(+), 82 deletions(-) rename src/include/{tcpip_tun.h => gnunet_tun_lib.h} (96%) diff --git a/src/dns/gnunet-service-dns.c b/src/dns/gnunet-service-dns.c index 764ede782..76beaaf5c 100644 --- a/src/dns/gnunet-service-dns.c +++ b/src/dns/gnunet-service-dns.c @@ -30,7 +30,7 @@ #include "dns.h" #include "gnunet_dns_service.h" #include "gnunet_statistics_service.h" -#include "tcpip_tun.h" +#include "gnunet_tun_lib.h" #ifndef IPVERSION #define IPVERSION 4 diff --git a/src/exit/gnunet-daemon-exit.c b/src/exit/gnunet-daemon-exit.c index 3909d4a70..3dce69a3e 100644 --- a/src/exit/gnunet-daemon-exit.c +++ b/src/exit/gnunet-daemon-exit.c @@ -44,7 +44,7 @@ #include "gnunet_mesh_service.h" #include "gnunet_statistics_service.h" #include "gnunet_constants.h" -#include "tcpip_tun.h" +#include "gnunet_tun_lib.h" #include "exit.h" /** diff --git a/src/include/Makefile.am b/src/include/Makefile.am index d0cd70d01..85c9f7d4f 100644 --- a/src/include/Makefile.am +++ b/src/include/Makefile.am @@ -72,6 +72,6 @@ gnunetinclude_HEADERS = \ gnunet_time_lib.h \ gnunet_transport_service.h \ gnunet_transport_plugin.h \ + gnunet_tun_lib.h \ gnunet_util_lib.h \ - gnunet_vpn_service.h \ - tcpip_tun.h \ No newline at end of file + gnunet_vpn_service.h diff --git a/src/include/tcpip_tun.h b/src/include/gnunet_tun_lib.h similarity index 96% rename from src/include/tcpip_tun.h rename to src/include/gnunet_tun_lib.h index 80419aae5..ca521db3b 100644 --- a/src/include/tcpip_tun.h +++ b/src/include/gnunet_tun_lib.h @@ -19,8 +19,8 @@ */ /** - * @file include/tcpip_tun.h - * @brief standard TCP/IP network structs for TUN interaction + * @file include/gnunet_tun_lib.h + * @brief standard TCP/IP network structs and IP checksum calculations for TUN interaction * @author Philipp Toelke * @author Christian Grothoff * diff --git a/src/vpn/gnunet-service-vpn.c b/src/vpn/gnunet-service-vpn.c index 381cdb7c8..9c0fb1667 100644 --- a/src/vpn/gnunet-service-vpn.c +++ b/src/vpn/gnunet-service-vpn.c @@ -45,7 +45,7 @@ #include "gnunet_mesh_service.h" #include "gnunet_statistics_service.h" #include "gnunet_constants.h" -#include "tcpip_tun.h" +#include "gnunet_tun_lib.h" #include "vpn.h" #include "exit.h" @@ -499,6 +499,79 @@ send_client_reply (struct GNUNET_SERVER_Client *client, } +/** + * Free resources associated with a tunnel state. + * + * @param ts state to free + */ +static void +free_tunnel_state (struct TunnelState *ts) +{ + GNUNET_HashCode key; + struct TunnelMessageQueueEntry *tnq; + struct GNUNET_MESH_Tunnel *tunnel; + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Cleaning up tunnel state\n"); + GNUNET_STATISTICS_update (stats, + gettext_noop ("# Active tunnels"), + -1, GNUNET_NO); + if (GNUNET_SCHEDULER_NO_TASK != ts->destroy_task) + { + GNUNET_SCHEDULER_cancel (ts->destroy_task); + ts->destroy_task = GNUNET_SCHEDULER_NO_TASK; + } + while (NULL != (tnq = ts->tmq_head)) + { + GNUNET_CONTAINER_DLL_remove (ts->tmq_head, + ts->tmq_tail, + tnq); + ts->tmq_length--; + GNUNET_free (tnq); + } + GNUNET_assert (0 == ts->tmq_length); + if (NULL != ts->client) + { + GNUNET_SERVER_client_drop (ts->client); + ts->client = NULL; + } + if (NULL != ts->th) + { + GNUNET_MESH_notify_transmit_ready_cancel (ts->th); + ts->th = NULL; + } + GNUNET_assert (NULL == ts->destination.heap_node); + if (NULL != (tunnel = ts->tunnel)) + { + ts->tunnel = NULL; + GNUNET_MESH_tunnel_destroy (tunnel); + } + if (NULL != ts->heap_node) + { + GNUNET_CONTAINER_heap_remove_node (ts->heap_node); + ts->heap_node = NULL; + get_tunnel_key_from_ips (ts->af, + ts->protocol, + &ts->source_ip, + ts->source_port, + &ts->destination_ip, + ts->destination_port, + &key); + GNUNET_assert (GNUNET_YES == + GNUNET_CONTAINER_multihashmap_remove (tunnel_map, + &key, + ts)); + } + if (NULL != ts->destination_container) + { + GNUNET_assert (ts == ts->destination_container->ts); + ts->destination_container->ts = NULL; + ts->destination_container = NULL; + } + GNUNET_free (ts); +} + + /** * Destroy the mesh tunnel. * @@ -513,10 +586,11 @@ destroy_tunnel_task (void *cls, struct GNUNET_MESH_Tunnel *tunnel; ts->destroy_task = GNUNET_SCHEDULER_NO_TASK; - if (NULL == (tunnel = ts->tunnel)) - return; + GNUNET_assert (NULL != ts->tunnel); + tunnel = ts->tunnel; ts->tunnel = NULL; GNUNET_MESH_tunnel_destroy (tunnel); + free_tunnel_state (ts); } @@ -763,79 +837,6 @@ create_tunnel_to_destination (struct DestinationEntry *de, } -/** - * Free resources associated with a tunnel state. - * - * @param ts state to free - */ -static void -free_tunnel_state (struct TunnelState *ts) -{ - GNUNET_HashCode key; - struct TunnelMessageQueueEntry *tnq; - struct GNUNET_MESH_Tunnel *tunnel; - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Cleaning up tunnel state\n"); - GNUNET_STATISTICS_update (stats, - gettext_noop ("# Active tunnels"), - -1, GNUNET_NO); - if (GNUNET_SCHEDULER_NO_TASK != ts->destroy_task) - { - GNUNET_SCHEDULER_cancel (ts->destroy_task); - ts->destroy_task = GNUNET_SCHEDULER_NO_TASK; - } - while (NULL != (tnq = ts->tmq_head)) - { - GNUNET_CONTAINER_DLL_remove (ts->tmq_head, - ts->tmq_tail, - tnq); - ts->tmq_length--; - GNUNET_free (tnq); - } - GNUNET_assert (0 == ts->tmq_length); - if (NULL != ts->client) - { - GNUNET_SERVER_client_drop (ts->client); - ts->client = NULL; - } - if (NULL != ts->th) - { - GNUNET_MESH_notify_transmit_ready_cancel (ts->th); - ts->th = NULL; - } - GNUNET_assert (NULL == ts->destination.heap_node); - if (NULL != (tunnel = ts->tunnel)) - { - ts->tunnel = NULL; - GNUNET_MESH_tunnel_destroy (tunnel); - } - if (NULL != ts->heap_node) - { - GNUNET_CONTAINER_heap_remove_node (ts->heap_node); - ts->heap_node = NULL; - get_tunnel_key_from_ips (ts->af, - ts->protocol, - &ts->source_ip, - ts->source_port, - &ts->destination_ip, - ts->destination_port, - &key); - GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multihashmap_remove (tunnel_map, - &key, - ts)); - } - if (NULL != ts->destination_container) - { - GNUNET_assert (ts == ts->destination_container->ts); - ts->destination_container->ts = NULL; - ts->destination_container = NULL; - } - GNUNET_free (ts); -} - - /** * We have too many active tunnels. Clean up the oldest tunnel. * -- 2.25.1