diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-01-11 23:16:37 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-01-11 23:16:37 +0000 |
commit | d02848717c9dd82af12967f9de0b7d6c806bd16a (patch) | |
tree | edfc05f96d3fed9acd27957773321c0187537102 /src/vpn/gnunet-service-vpn.c | |
parent | 7b18ecc675f2c17c518f370ab657840853f31135 (diff) | |
download | gnunet-d02848717c9dd82af12967f9de0b7d6c806bd16a.tar.gz gnunet-d02848717c9dd82af12967f9de0b7d6c806bd16a.zip |
-implementing shutdown code
Diffstat (limited to 'src/vpn/gnunet-service-vpn.c')
-rw-r--r-- | src/vpn/gnunet-service-vpn.c | 144 |
1 files changed, 139 insertions, 5 deletions
diff --git a/src/vpn/gnunet-service-vpn.c b/src/vpn/gnunet-service-vpn.c index 31391bc9f..f6b4f73e2 100644 --- a/src/vpn/gnunet-service-vpn.c +++ b/src/vpn/gnunet-service-vpn.c | |||
@@ -27,7 +27,6 @@ | |||
27 | * @author Christian Grothoff | 27 | * @author Christian Grothoff |
28 | * | 28 | * |
29 | * TODO: | 29 | * TODO: |
30 | * - fully implement shutdown code | ||
31 | * - create secondary mesh tunnels if needed / check overall tunnel creation/management code! | 30 | * - create secondary mesh tunnels if needed / check overall tunnel creation/management code! |
32 | * => test! | 31 | * => test! |
33 | * - better message queue management (bounded state, drop oldest/RED?) | 32 | * - better message queue management (bounded state, drop oldest/RED?) |
@@ -1743,15 +1742,122 @@ tunnel_cleaner (void *cls, const struct GNUNET_MESH_Tunnel *tunnel, void *tunnel | |||
1743 | 1742 | ||
1744 | 1743 | ||
1745 | /** | 1744 | /** |
1745 | * Free memory occupied by an entry in the destination map. | ||
1746 | * | ||
1747 | * @param cls unused | ||
1748 | * @param key unused | ||
1749 | * @param value a 'struct DestinationEntry *' | ||
1750 | * @return GNUNET_OK (continue to iterate) | ||
1751 | */ | ||
1752 | static int | ||
1753 | cleanup_destination (void *cls, | ||
1754 | const GNUNET_HashCode *key, | ||
1755 | void *value) | ||
1756 | { | ||
1757 | struct DestinationEntry *de = value; | ||
1758 | |||
1759 | if (NULL != de->tunnel) | ||
1760 | { | ||
1761 | GNUNET_MESH_tunnel_destroy (de->tunnel); | ||
1762 | de->tunnel = NULL; | ||
1763 | } | ||
1764 | if (NULL != ts->heap_node) | ||
1765 | { | ||
1766 | GNUNET_CONTAINER_heap_remove_node (ts->heap_node); | ||
1767 | ts->heap_node = NULL; | ||
1768 | } | ||
1769 | GNUNET_free (de); | ||
1770 | return GNUNET_OK; | ||
1771 | } | ||
1772 | |||
1773 | |||
1774 | /** | ||
1775 | * Free memory occupied by an entry in the tunnel map. | ||
1776 | * | ||
1777 | * @param cls unused | ||
1778 | * @param key unused | ||
1779 | * @param value a 'struct TunnelState *' | ||
1780 | * @return GNUNET_OK (continue to iterate) | ||
1781 | */ | ||
1782 | static int | ||
1783 | cleanup_tunnel (void *cls, | ||
1784 | const GNUNET_HashCode *key, | ||
1785 | void *value) | ||
1786 | { | ||
1787 | struct TunnelState *ts = value; | ||
1788 | struct TunnelMessageQueueEntry *tnq; | ||
1789 | |||
1790 | while (NULL != (tnq = ts->head)) | ||
1791 | { | ||
1792 | GNUNET_CONTAINER_DLL_remove (ts->head, | ||
1793 | ts->tail, | ||
1794 | tnq); | ||
1795 | GNUNET_free (tnq); | ||
1796 | } | ||
1797 | if (NULL != ts->client) | ||
1798 | { | ||
1799 | GNUNET_SERVER_cliet_drop (ts->client); | ||
1800 | ts->client = NULL; | ||
1801 | } | ||
1802 | if (NULL != ts->th) | ||
1803 | { | ||
1804 | GNUNET_MESH_notify_transmit_ready_cancel (ts->th); | ||
1805 | ts->th = NULL; | ||
1806 | } | ||
1807 | if (NULL != ts->destination.tunnel) | ||
1808 | { | ||
1809 | GNUNET_MESH_tunnel_destroy (ts->destination.tunnel); | ||
1810 | ts->destination.tunnel = NULL; | ||
1811 | } | ||
1812 | if (NULL != ts->heap_node) | ||
1813 | { | ||
1814 | GNUNET_CONTAINER_heap_remove_node (ts->heap_node); | ||
1815 | ts->heap_node = NULL; | ||
1816 | } | ||
1817 | // FIXME... | ||
1818 | GNUNET_free (ts); | ||
1819 | return GNUNET_OK; | ||
1820 | } | ||
1821 | |||
1822 | |||
1823 | /** | ||
1746 | * Function scheduled as very last function, cleans up after us | 1824 | * Function scheduled as very last function, cleans up after us |
1825 | * | ||
1826 | * @param cls unused | ||
1827 | * @param tc unused | ||
1747 | */ | 1828 | */ |
1748 | static void | 1829 | static void |
1749 | cleanup (void *cls GNUNET_UNUSED, | 1830 | cleanup (void *cls GNUNET_UNUSED, |
1750 | const struct GNUNET_SCHEDULER_TaskContext *tskctx) | 1831 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
1751 | { | 1832 | { |
1752 | unsigned int i; | 1833 | unsigned int i; |
1753 | 1834 | ||
1754 | // FIXME: clean up heaps and maps! | 1835 | if (NULL != destination_map) |
1836 | { | ||
1837 | GNUNET_CONTAINER_multihashmap_iterate (destination_map, | ||
1838 | &cleanup_destination, | ||
1839 | NULL); | ||
1840 | GNUNET_CONTAINER_multihashmap_destroy (destination_map); | ||
1841 | destination_map = NULL; | ||
1842 | } | ||
1843 | if (NULL != destination_heap) | ||
1844 | { | ||
1845 | GNUNET_CONTAINER_heap_destroy (destination_heap); | ||
1846 | destination_heap = NULL; | ||
1847 | } | ||
1848 | if (NULL != tunnel_map) | ||
1849 | { | ||
1850 | GNUNET_CONTAINER_multihashmap_iterate (tunnel_map, | ||
1851 | &cleanup_tunnel, | ||
1852 | NULL); | ||
1853 | GNUNET_CONTAINER_multihashmap_destroy (tunnel_map); | ||
1854 | tunnel_map = NULL; | ||
1855 | } | ||
1856 | if (NULL != tunnel_heap) | ||
1857 | { | ||
1858 | GNUNET_CONTAINER_heap_destroy (tunnel_heap); | ||
1859 | tunnel_heap = NULL; | ||
1860 | } | ||
1755 | if (NULL != mesh_handle) | 1861 | if (NULL != mesh_handle) |
1756 | { | 1862 | { |
1757 | GNUNET_MESH_disconnect (mesh_handle); | 1863 | GNUNET_MESH_disconnect (mesh_handle); |
@@ -1773,6 +1879,31 @@ cleanup (void *cls GNUNET_UNUSED, | |||
1773 | 1879 | ||
1774 | 1880 | ||
1775 | /** | 1881 | /** |
1882 | * A client disconnected, clean up all references to it. | ||
1883 | * | ||
1884 | * @param cls the client that disconnected | ||
1885 | * @param key unused | ||
1886 | * @param value a 'struct TunnelState *' | ||
1887 | * @return GNUNET_OK (continue to iterate) | ||
1888 | */ | ||
1889 | static int | ||
1890 | cleanup_tunnel_client (void *cls, | ||
1891 | const GNUNET_HashCode *key, | ||
1892 | void *value) | ||
1893 | { | ||
1894 | struct GNUNET_SERVER_Client *client; | ||
1895 | struct TunnelState *ts = value; | ||
1896 | |||
1897 | if (client == ts->client) | ||
1898 | { | ||
1899 | GNUNET_SERVER_cliet_drop (ts->client); | ||
1900 | ts->client = NULL; | ||
1901 | } | ||
1902 | return GNUNET_OK; | ||
1903 | } | ||
1904 | |||
1905 | |||
1906 | /** | ||
1776 | * A client has disconnected from us. If we are currently building | 1907 | * A client has disconnected from us. If we are currently building |
1777 | * a tunnel for it, cancel the operation. | 1908 | * a tunnel for it, cancel the operation. |
1778 | * | 1909 | * |
@@ -1782,8 +1913,11 @@ cleanup (void *cls GNUNET_UNUSED, | |||
1782 | static void | 1913 | static void |
1783 | client_disconnect (void *cls, struct GNUNET_SERVER_Client *client) | 1914 | client_disconnect (void *cls, struct GNUNET_SERVER_Client *client) |
1784 | { | 1915 | { |
1785 | // FIXME: find all TunnelState's and check if they point | 1916 | // FIXME: check that all truly all 'struct TunnelState's |
1786 | // to the client and if so, clean the reference up! | 1917 | // with clients are always in the tunnel map! |
1918 | GNUNET_CONTAINER_multihashmap_iterate (tunnel_map, | ||
1919 | &cleanup_tunnel_client, | ||
1920 | client); | ||
1787 | } | 1921 | } |
1788 | 1922 | ||
1789 | 1923 | ||