aboutsummaryrefslogtreecommitdiff
path: root/src/mesh/gnunet-service-mesh_tunnel.c
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2014-03-21 18:44:06 +0000
committerBart Polot <bart@net.in.tum.de>2014-03-21 18:44:06 +0000
commitf93509e7e3e0635f4c053d05b89b86eca1f2fc1b (patch)
tree4f719027d410b206013b737acd1a155f4ba1dafc /src/mesh/gnunet-service-mesh_tunnel.c
parentb5a0ff8ddca95adfa1fd1cd02b2068dfb7031522 (diff)
downloadgnunet-f93509e7e3e0635f4c053d05b89b86eca1f2fc1b.tar.gz
gnunet-f93509e7e3e0635f4c053d05b89b86eca1f2fc1b.zip
- add connection count check, doc
Diffstat (limited to 'src/mesh/gnunet-service-mesh_tunnel.c')
-rw-r--r--src/mesh/gnunet-service-mesh_tunnel.c68
1 files changed, 65 insertions, 3 deletions
diff --git a/src/mesh/gnunet-service-mesh_tunnel.c b/src/mesh/gnunet-service-mesh_tunnel.c
index 23bbdd01a..15cac22e0 100644
--- a/src/mesh/gnunet-service-mesh_tunnel.c
+++ b/src/mesh/gnunet-service-mesh_tunnel.c
@@ -36,6 +36,8 @@
36 36
37#define REKEY_WAIT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5) 37#define REKEY_WAIT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5)
38 38
39#define CONNECTIONS_PER_TUNNEL 3
40
39/******************************************************************************/ 41/******************************************************************************/
40/******************************** STRUCTS **********************************/ 42/******************************** STRUCTS **********************************/
41/******************************************************************************/ 43/******************************************************************************/
@@ -47,11 +49,36 @@ struct MeshTChannel
47 struct MeshChannel *ch; 49 struct MeshChannel *ch;
48}; 50};
49 51
52
53/**
54 * Connection list and metadata.
55 */
50struct MeshTConnection 56struct MeshTConnection
51{ 57{
58 /**
59 * Next in DLL.
60 */
52 struct MeshTConnection *next; 61 struct MeshTConnection *next;
62
63 /**
64 * Prev in DLL.
65 */
53 struct MeshTConnection *prev; 66 struct MeshTConnection *prev;
67
68 /**
69 * Connection handle.
70 */
54 struct MeshConnection *c; 71 struct MeshConnection *c;
72
73 /**
74 * Creation time, to keep oldest connection alive.
75 */
76 struct GNUNET_TIME_Absolute created;
77
78 /**
79 * Connection throughput, to keep fastest connection alive.
80 */
81 uint32_t throughput;
55}; 82};
56 83
57/** 84/**
@@ -1820,7 +1847,8 @@ GMT_change_cstate (struct MeshTunnel3* t, enum MeshTunnel3CState cstate)
1820 } 1847 }
1821 t->cstate = cstate; 1848 t->cstate = cstate;
1822 1849
1823 if (MESH_TUNNEL3_READY == cstate && 3 <= GMT_count_connections (t)) 1850 if (MESH_TUNNEL3_READY == cstate
1851 && CONNECTIONS_PER_TUNNEL <= GMT_count_connections (t))
1824 { 1852 {
1825 LOG (GNUNET_ERROR_TYPE_DEBUG, " cstate triggered stop dht\n"); 1853 LOG (GNUNET_ERROR_TYPE_DEBUG, " cstate triggered stop dht\n");
1826 GMP_stop_search (t->peer); 1854 GMP_stop_search (t->peer);
@@ -1856,6 +1884,36 @@ GMT_change_estate (struct MeshTunnel3* t, enum MeshTunnel3EState state)
1856 1884
1857 1885
1858/** 1886/**
1887 * Check that the tunnel doesn't have too many connections,
1888 * remove one if necessary.
1889 *
1890 * For the time being, this means the newest connection.
1891 *
1892 * @param t Tunnel to check.
1893 */
1894static void
1895check_connection_count (struct MeshTunnel3 *t)
1896{
1897 if (GMT_count_connections (t) > CONNECTIONS_PER_TUNNEL)
1898 {
1899 struct MeshTConnection *iter;
1900 struct MeshTConnection *c;
1901
1902 for (iter = t->connection_head; NULL != iter; iter = iter->next)
1903 {
1904 if (NULL == c || iter->created.abs_value_us > c->created.abs_value_us)
1905 {
1906 c = iter;
1907 }
1908 }
1909 if (NULL != c)
1910 GMC_destroy (c->c);
1911 else
1912 GNUNET_break (0);
1913 }
1914}
1915
1916/**
1859 * Add a connection to a tunnel. 1917 * Add a connection to a tunnel.
1860 * 1918 *
1861 * @param t Tunnel. 1919 * @param t Tunnel.
@@ -1874,7 +1932,11 @@ GMT_add_connection (struct MeshTunnel3 *t, struct MeshConnection *c)
1874 1932
1875 aux = GNUNET_new (struct MeshTConnection); 1933 aux = GNUNET_new (struct MeshTConnection);
1876 aux->c = c; 1934 aux->c = c;
1877 GNUNET_CONTAINER_DLL_insert_tail (t->connection_head, t->connection_tail, aux); 1935 aux->created = GNUNET_TIME_absolute_get ();
1936
1937 GNUNET_CONTAINER_DLL_insert (t->connection_head, t->connection_tail, aux);
1938
1939 check_connection_count (t);
1878} 1940}
1879 1941
1880 1942
@@ -2198,7 +2260,7 @@ GMT_use_path (struct MeshTunnel3 *t, struct MeshPeerPath *p)
2198 if (p->peers[own_pos] == myid) 2260 if (p->peers[own_pos] == myid)
2199 break; 2261 break;
2200 } 2262 }
2201 if (own_pos > p->length - 1) 2263 if (own_pos >= p->length)
2202 { 2264 {
2203 GNUNET_break_op (0); 2265 GNUNET_break_op (0);
2204 return NULL; 2266 return NULL;