aboutsummaryrefslogtreecommitdiff
path: root/src/mesh
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2014-04-10 15:39:21 +0000
committerBart Polot <bart@net.in.tum.de>2014-04-10 15:39:21 +0000
commit718faa300710089f5925a1dcfb49bc104899d1ce (patch)
treed75c99017b3b933c39fb61d1a1c4f099018c5f02 /src/mesh
parent116b7755459f06579f78830893d0b5f3446eb164 (diff)
downloadgnunet-718faa300710089f5925a1dcfb49bc104899d1ce.tar.gz
gnunet-718faa300710089f5925a1dcfb49bc104899d1ce.zip
- don't free connections in the middle of being build.
- fixes #3373, #3361
Diffstat (limited to 'src/mesh')
-rw-r--r--src/mesh/gnunet-service-mesh_connection.c14
-rw-r--r--src/mesh/gnunet-service-mesh_connection.h10
-rw-r--r--src/mesh/gnunet-service-mesh_tunnel.c35
3 files changed, 51 insertions, 8 deletions
diff --git a/src/mesh/gnunet-service-mesh_connection.c b/src/mesh/gnunet-service-mesh_connection.c
index 663500125..c9c99866f 100644
--- a/src/mesh/gnunet-service-mesh_connection.c
+++ b/src/mesh/gnunet-service-mesh_connection.c
@@ -2799,6 +2799,20 @@ GMC_is_sendable (struct MeshConnection *c, int fwd)
2799 return GNUNET_NO; 2799 return GNUNET_NO;
2800} 2800}
2801 2801
2802
2803/**
2804 * Check if this connection is a direct one (never trim a direct connection).
2805 *
2806 * @param c Connection.
2807 *
2808 * @return #GNUNET_YES in case it's a direct connection, #GNUNET_NO otherwise.
2809 */
2810int
2811GMC_is_direct (struct MeshConnection *c)
2812{
2813 return (c->path->length == 2) ? GNUNET_YES : GNUNET_NO;
2814}
2815
2802/** 2816/**
2803 * Sends an already built message on a connection, properly registering 2817 * Sends an already built message on a connection, properly registering
2804 * all used resources. 2818 * all used resources.
diff --git a/src/mesh/gnunet-service-mesh_connection.h b/src/mesh/gnunet-service-mesh_connection.h
index 39d62adc9..6864c8733 100644
--- a/src/mesh/gnunet-service-mesh_connection.h
+++ b/src/mesh/gnunet-service-mesh_connection.h
@@ -445,6 +445,16 @@ int
445GMC_is_sendable (struct MeshConnection *c, int fwd); 445GMC_is_sendable (struct MeshConnection *c, int fwd);
446 446
447/** 447/**
448 * Check if this connection is a direct one (never trim a direct connection).
449 *
450 * @param c Connection.
451 *
452 * @return #GNUNET_YES in case it's a direct connection, #GNUNET_NO otherwise.
453 */
454int
455GMC_is_direct (struct MeshConnection *c);
456
457/**
448 * Cancel a previously sent message while it's in the queue. 458 * Cancel a previously sent message while it's in the queue.
449 * 459 *
450 * ONLY can be called before the continuation given to the send function 460 * ONLY can be called before the continuation given to the send function
diff --git a/src/mesh/gnunet-service-mesh_tunnel.c b/src/mesh/gnunet-service-mesh_tunnel.c
index 7e3717f0b..7076eedd8 100644
--- a/src/mesh/gnunet-service-mesh_tunnel.c
+++ b/src/mesh/gnunet-service-mesh_tunnel.c
@@ -1886,35 +1886,52 @@ GMT_change_estate (struct MeshTunnel3* t, enum MeshTunnel3EState state)
1886 1886
1887 1887
1888/** 1888/**
1889 * Check that the tunnel doesn't have too many connections, 1889 * @brief Check if tunnel has too many connections, and remove one if necessary.
1890 * remove one if necessary.
1891 * 1890 *
1892 * For the time being, this means the newest connection. 1891 * Currently this means the newest connection, unless it is a direct one.
1892 * Implemented as a task to avoid freeing a connection that is in the middle
1893 * of being created/processed.
1893 * 1894 *
1894 * @param t Tunnel to check. 1895 * @param cls Closure (Tunnel to check).
1896 * @param tc Task context.
1895 */ 1897 */
1896static void 1898static void
1897check_connection_count (struct MeshTunnel3 *t) 1899trim_connections (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1898{ 1900{
1899 if (GMT_count_connections (t) > CONNECTIONS_PER_TUNNEL) 1901 struct MeshTunnel3 *t = cls;
1902
1903 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
1904 return;
1905
1906 if (GMT_count_connections (t) > 2 * CONNECTIONS_PER_TUNNEL)
1900 { 1907 {
1901 struct MeshTConnection *iter; 1908 struct MeshTConnection *iter;
1902 struct MeshTConnection *c; 1909 struct MeshTConnection *c;
1903 1910
1904 for (c = iter = t->connection_head; NULL != iter; iter = iter->next) 1911 for (c = iter = t->connection_head; NULL != iter; iter = iter->next)
1905 { 1912 {
1906 if (NULL == c || iter->created.abs_value_us > c->created.abs_value_us) 1913 if ((NULL == c || iter->created.abs_value_us > c->created.abs_value_us)
1914 && GNUNET_NO == GMC_is_direct (iter->c))
1907 { 1915 {
1908 c = iter; 1916 c = iter;
1909 } 1917 }
1910 } 1918 }
1911 if (NULL != c) 1919 if (NULL != c)
1920 {
1921 LOG (GNUNET_ERROR_TYPE_DEBUG, "Too many connections on tunnel %s\n",
1922 GMT_2s (t));
1923 LOG (GNUNET_ERROR_TYPE_DEBUG, "Destroying connection %s\n",
1924 GMC_2s (c->c));
1912 GMC_destroy (c->c); 1925 GMC_destroy (c->c);
1926 }
1913 else 1927 else
1928 {
1914 GNUNET_break (0); 1929 GNUNET_break (0);
1930 }
1915 } 1931 }
1916} 1932}
1917 1933
1934
1918/** 1935/**
1919 * Add a connection to a tunnel. 1936 * Add a connection to a tunnel.
1920 * 1937 *
@@ -1928,6 +1945,8 @@ GMT_add_connection (struct MeshTunnel3 *t, struct MeshConnection *c)
1928 1945
1929 GNUNET_assert (NULL != c); 1946 GNUNET_assert (NULL != c);
1930 1947
1948 LOG (GNUNET_ERROR_TYPE_DEBUG, "add connection %s\n", GMC_2s (c));
1949 LOG (GNUNET_ERROR_TYPE_DEBUG, " to tunnel %s\n", GMT_2s (t));
1931 for (aux = t->connection_head; aux != NULL; aux = aux->next) 1950 for (aux = t->connection_head; aux != NULL; aux = aux->next)
1932 if (aux->c == c) 1951 if (aux->c == c)
1933 return; 1952 return;
@@ -1938,7 +1957,7 @@ GMT_add_connection (struct MeshTunnel3 *t, struct MeshConnection *c)
1938 1957
1939 GNUNET_CONTAINER_DLL_insert (t->connection_head, t->connection_tail, aux); 1958 GNUNET_CONTAINER_DLL_insert (t->connection_head, t->connection_tail, aux);
1940 1959
1941 check_connection_count (t); 1960 GNUNET_SCHEDULER_add_now (&trim_connections, t);
1942} 1961}
1943 1962
1944 1963