aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-07-13 20:23:53 +0000
committerChristian Grothoff <christian@grothoff.org>2015-07-13 20:23:53 +0000
commitb199b782b393d0fc04b5978edd69e36d6ae7ea64 (patch)
tree5b5f2c590f3e08240f734a255a8db15f413cfb65 /src
parent16d646a12f744c19e307c1c0139e3303a6263806 (diff)
downloadgnunet-b199b782b393d0fc04b5978edd69e36d6ae7ea64.tar.gz
gnunet-b199b782b393d0fc04b5978edd69e36d6ae7ea64.zip
adding moderately expensive instrumentation to track down invariant violation #3846 in CADET
Diffstat (limited to 'src')
-rw-r--r--src/cadet/gnunet-service-cadet_connection.c186
-rw-r--r--src/cadet/gnunet-service-cadet_connection.h35
-rw-r--r--src/cadet/gnunet-service-cadet_peer.c20
-rw-r--r--src/cadet/gnunet-service-cadet_peer.h11
4 files changed, 195 insertions, 57 deletions
diff --git a/src/cadet/gnunet-service-cadet_connection.c b/src/cadet/gnunet-service-cadet_connection.c
index ad73e9027..75f5bb7fe 100644
--- a/src/cadet/gnunet-service-cadet_connection.c
+++ b/src/cadet/gnunet-service-cadet_connection.c
@@ -314,6 +314,8 @@ static struct GNUNET_TIME_Relative create_connection_time;
314/******************************** STATIC ***********************************/ 314/******************************** STATIC ***********************************/
315/******************************************************************************/ 315/******************************************************************************/
316 316
317
318
317#if 0 // avoid compiler warning for unused static function 319#if 0 // avoid compiler warning for unused static function
318static void 320static void
319fc_debug (struct CadetFlowControl *fc) 321fc_debug (struct CadetFlowControl *fc)
@@ -790,6 +792,53 @@ get_next_hop (const struct CadetConnection *c)
790 792
791 793
792/** 794/**
795 * Check that the direct neighbours (previous and next hop)
796 * are properly associated with this connection.
797 *
798 * @param c connection to check
799 */
800static void
801check_neighbours (const struct CadetConnection *c)
802{
803 if (NULL == c->path)
804 return; /* nothing to check */
805 GCP_check_connection (get_next_hop (c), c);
806 GCP_check_connection (get_prev_hop (c), c);
807}
808
809/**
810 * Helper for #check_connections(). Calls #check_neighbours().
811 *
812 * @param cls NULL
813 * @param key ignored
814 * @param value the `struct CadetConnection` to check
815 * @return #GNUNET_OK (continue to iterate)
816 */
817static int
818check_connection (void *cls,
819 const struct GNUNET_HashCode *key,
820 void *value)
821{
822 struct CadetConnection *c = value;
823
824 check_neighbours (c);
825 return GNUNET_OK;
826}
827
828
829/**
830 * Check all connections using #check_neighbours().
831 */
832static void
833check_connections ()
834{
835 GNUNET_CONTAINER_multihashmap_iterate (connections,
836 &check_connection,
837 NULL);
838}
839
840
841/**
793 * Get the hop in a connection. 842 * Get the hop in a connection.
794 * 843 *
795 * @param c Connection. 844 * @param c Connection.
@@ -1744,9 +1793,8 @@ log_message (const struct GNUNET_MessageHeader *message,
1744 * @param cls Closure (unused). 1793 * @param cls Closure (unused).
1745 * @param peer Sender (neighbor). 1794 * @param peer Sender (neighbor).
1746 * @param message Message. 1795 * @param message Message.
1747 * 1796 * @return #GNUNET_OK to keep the connection open,
1748 * @return GNUNET_OK to keep the connection open, 1797 * #GNUNET_SYSERR to close it (signal serious error)
1749 * GNUNET_SYSERR to close it (signal serious error)
1750 */ 1798 */
1751int 1799int
1752GCC_handle_create (void *cls, const struct GNUNET_PeerIdentity *peer, 1800GCC_handle_create (void *cls, const struct GNUNET_PeerIdentity *peer,
@@ -1762,6 +1810,7 @@ GCC_handle_create (void *cls, const struct GNUNET_PeerIdentity *peer,
1762 unsigned int own_pos; 1810 unsigned int own_pos;
1763 uint16_t size; 1811 uint16_t size;
1764 1812
1813 check_connections ();
1765 /* Check size */ 1814 /* Check size */
1766 size = ntohs (message->size); 1815 size = ntohs (message->size);
1767 if (size < sizeof (struct GNUNET_CADET_ConnectionCreate)) 1816 if (size < sizeof (struct GNUNET_CADET_ConnectionCreate))
@@ -1830,12 +1879,14 @@ GCC_handle_create (void *cls, const struct GNUNET_PeerIdentity *peer,
1830 /* If we are destination, why did the creation fail? */ 1879 /* If we are destination, why did the creation fail? */
1831 GNUNET_break (0); 1880 GNUNET_break (0);
1832 path_destroy (path); 1881 path_destroy (path);
1882 check_connections ();
1833 return GNUNET_OK; 1883 return GNUNET_OK;
1834 } 1884 }
1835 send_broken_unknown (cid, &my_full_id, 1885 send_broken_unknown (cid, &my_full_id,
1836 GNUNET_PEER_resolve2 (path->peers[own_pos + 1]), 1886 GNUNET_PEER_resolve2 (path->peers[own_pos + 1]),
1837 peer); 1887 peer);
1838 path_destroy (path); 1888 path_destroy (path);
1889 check_connections ();
1839 return GNUNET_OK; 1890 return GNUNET_OK;
1840 } 1891 }
1841 GCP_add_path_to_all (path, GNUNET_NO); 1892 GCP_add_path_to_all (path, GNUNET_NO);
@@ -1873,7 +1924,7 @@ GCC_handle_create (void *cls, const struct GNUNET_PeerIdentity *peer,
1873 path_destroy (path); 1924 path_destroy (path);
1874 GCC_destroy (c); 1925 GCC_destroy (c);
1875 send_broken_unknown (cid, &my_full_id, NULL, peer); 1926 send_broken_unknown (cid, &my_full_id, NULL, peer);
1876 1927 check_connections ();
1877 return GNUNET_OK; 1928 return GNUNET_OK;
1878 } 1929 }
1879 1930
@@ -1895,6 +1946,7 @@ GCC_handle_create (void *cls, const struct GNUNET_PeerIdentity *peer,
1895 NULL, NULL)); 1946 NULL, NULL));
1896 } 1947 }
1897 path_destroy (path); 1948 path_destroy (path);
1949 check_connections ();
1898 return GNUNET_OK; 1950 return GNUNET_OK;
1899} 1951}
1900 1952
@@ -1905,12 +1957,12 @@ GCC_handle_create (void *cls, const struct GNUNET_PeerIdentity *peer,
1905 * @param cls closure 1957 * @param cls closure
1906 * @param message message 1958 * @param message message
1907 * @param peer peer identity this notification is about 1959 * @param peer peer identity this notification is about
1908 * 1960 * @return #GNUNET_OK to keep the connection open,
1909 * @return GNUNET_OK to keep the connection open, 1961 * #GNUNET_SYSERR to close it (signal serious error)
1910 * GNUNET_SYSERR to close it (signal serious error)
1911 */ 1962 */
1912int 1963int
1913GCC_handle_confirm (void *cls, const struct GNUNET_PeerIdentity *peer, 1964GCC_handle_confirm (void *cls,
1965 const struct GNUNET_PeerIdentity *peer,
1914 const struct GNUNET_MessageHeader *message) 1966 const struct GNUNET_MessageHeader *message)
1915{ 1967{
1916 struct GNUNET_CADET_ConnectionACK *msg; 1968 struct GNUNET_CADET_ConnectionACK *msg;
@@ -1920,6 +1972,7 @@ GCC_handle_confirm (void *cls, const struct GNUNET_PeerIdentity *peer,
1920 enum CadetConnectionState oldstate; 1972 enum CadetConnectionState oldstate;
1921 int fwd; 1973 int fwd;
1922 1974
1975 check_connections ();
1923 msg = (struct GNUNET_CADET_ConnectionACK *) message; 1976 msg = (struct GNUNET_CADET_ConnectionACK *) message;
1924 log_message (message, peer, &msg->cid); 1977 log_message (message, peer, &msg->cid);
1925 c = connection_get (&msg->cid); 1978 c = connection_get (&msg->cid);
@@ -1927,14 +1980,18 @@ GCC_handle_confirm (void *cls, const struct GNUNET_PeerIdentity *peer,
1927 { 1980 {
1928 GNUNET_STATISTICS_update (stats, "# control on unknown connection", 1981 GNUNET_STATISTICS_update (stats, "# control on unknown connection",
1929 1, GNUNET_NO); 1982 1, GNUNET_NO);
1930 LOG (GNUNET_ERROR_TYPE_DEBUG, " don't know the connection!\n"); 1983 LOG (GNUNET_ERROR_TYPE_DEBUG,
1984 " don't know the connection!\n");
1931 send_broken_unknown (&msg->cid, &my_full_id, NULL, peer); 1985 send_broken_unknown (&msg->cid, &my_full_id, NULL, peer);
1986 check_connections ();
1932 return GNUNET_OK; 1987 return GNUNET_OK;
1933 } 1988 }
1934 1989
1935 if (GNUNET_NO != c->destroy) 1990 if (GNUNET_NO != c->destroy)
1936 { 1991 {
1937 LOG (GNUNET_ERROR_TYPE_DEBUG, " connection being destroyed\n"); 1992 LOG (GNUNET_ERROR_TYPE_DEBUG,
1993 " connection being destroyed\n");
1994 check_connections ();
1938 return GNUNET_OK; 1995 return GNUNET_OK;
1939 } 1996 }
1940 1997
@@ -1994,7 +2051,7 @@ GCC_handle_confirm (void *cls, const struct GNUNET_PeerIdentity *peer,
1994 /* Change tunnel state, trigger KX */ 2051 /* Change tunnel state, trigger KX */
1995 if (CADET_TUNNEL_WAITING == GCT_get_cstate (c->t)) 2052 if (CADET_TUNNEL_WAITING == GCT_get_cstate (c->t))
1996 GCT_change_cstate (c->t, CADET_TUNNEL_READY); 2053 GCT_change_cstate (c->t, CADET_TUNNEL_READY);
1997 2054 check_connections ();
1998 return GNUNET_OK; 2055 return GNUNET_OK;
1999 } 2056 }
2000 2057
@@ -2015,13 +2072,15 @@ GCC_handle_confirm (void *cls, const struct GNUNET_PeerIdentity *peer,
2015 /* Change tunnel state */ 2072 /* Change tunnel state */
2016 if (CADET_TUNNEL_WAITING == GCT_get_cstate (c->t)) 2073 if (CADET_TUNNEL_WAITING == GCT_get_cstate (c->t))
2017 GCT_change_cstate (c->t, CADET_TUNNEL_READY); 2074 GCT_change_cstate (c->t, CADET_TUNNEL_READY);
2018 2075 check_connections ();
2019 return GNUNET_OK; 2076 return GNUNET_OK;
2020 } 2077 }
2021 2078
2022 LOG (GNUNET_ERROR_TYPE_DEBUG, " not for us, retransmitting...\n"); 2079 LOG (GNUNET_ERROR_TYPE_DEBUG, " not for us, retransmitting...\n");
2023 GNUNET_assert (NULL == GCC_send_prebuilt_message (message, 0, 0, c, fwd, 2080 GNUNET_assert (NULL ==
2024 GNUNET_YES, NULL, NULL)); 2081 GCC_send_prebuilt_message (message, 0, 0, c, fwd,
2082 GNUNET_YES, NULL, NULL));
2083 check_connections ();
2025 return GNUNET_OK; 2084 return GNUNET_OK;
2026} 2085}
2027 2086
@@ -2032,7 +2091,6 @@ GCC_handle_confirm (void *cls, const struct GNUNET_PeerIdentity *peer,
2032 * @param cls Closure (unused). 2091 * @param cls Closure (unused).
2033 * @param id Peer identity of sending neighbor. 2092 * @param id Peer identity of sending neighbor.
2034 * @param message Message. 2093 * @param message Message.
2035 *
2036 * @return #GNUNET_OK to keep the connection open, 2094 * @return #GNUNET_OK to keep the connection open,
2037 * #GNUNET_SYSERR to close it (signal serious error) 2095 * #GNUNET_SYSERR to close it (signal serious error)
2038 */ 2096 */
@@ -2047,6 +2105,7 @@ GCC_handle_broken (void* cls,
2047 int pending; 2105 int pending;
2048 int fwd; 2106 int fwd;
2049 2107
2108 check_connections ();
2050 msg = (struct GNUNET_CADET_ConnectionBroken *) message; 2109 msg = (struct GNUNET_CADET_ConnectionBroken *) message;
2051 log_message (message, id, &msg->cid); 2110 log_message (message, id, &msg->cid);
2052 LOG (GNUNET_ERROR_TYPE_DEBUG, " regarding %s\n", 2111 LOG (GNUNET_ERROR_TYPE_DEBUG, " regarding %s\n",
@@ -2057,6 +2116,7 @@ GCC_handle_broken (void* cls,
2057 if (NULL == c) 2116 if (NULL == c)
2058 { 2117 {
2059 LOG (GNUNET_ERROR_TYPE_DEBUG, " duplicate CONNECTION_BROKEN\n"); 2118 LOG (GNUNET_ERROR_TYPE_DEBUG, " duplicate CONNECTION_BROKEN\n");
2119 check_connections ();
2060 return GNUNET_OK; 2120 return GNUNET_OK;
2061 } 2121 }
2062 2122
@@ -2096,7 +2156,7 @@ GCC_handle_broken (void* cls,
2096 GNUNET_YES, NULL, NULL)); 2156 GNUNET_YES, NULL, NULL));
2097 connection_cancel_queues (c, !fwd); 2157 connection_cancel_queues (c, !fwd);
2098 } 2158 }
2099 2159 check_connections ();
2100 return GNUNET_OK; 2160 return GNUNET_OK;
2101} 2161}
2102 2162
@@ -2119,6 +2179,7 @@ GCC_handle_destroy (void *cls,
2119 struct CadetConnection *c; 2179 struct CadetConnection *c;
2120 int fwd; 2180 int fwd;
2121 2181
2182 check_connections ();
2122 msg = (const struct GNUNET_CADET_ConnectionDestroy *) message; 2183 msg = (const struct GNUNET_CADET_ConnectionDestroy *) message;
2123 log_message (message, peer, &msg->cid); 2184 log_message (message, peer, &msg->cid);
2124 c = connection_get (&msg->cid); 2185 c = connection_get (&msg->cid);
@@ -2132,6 +2193,7 @@ GCC_handle_destroy (void *cls,
2132 1, GNUNET_NO); 2193 1, GNUNET_NO);
2133 LOG (GNUNET_ERROR_TYPE_DEBUG, 2194 LOG (GNUNET_ERROR_TYPE_DEBUG,
2134 " connection unknown: already destroyed?\n"); 2195 " connection unknown: already destroyed?\n");
2196 check_connections ();
2135 return GNUNET_OK; 2197 return GNUNET_OK;
2136 } 2198 }
2137 fwd = is_fwd (c, peer); 2199 fwd = is_fwd (c, peer);
@@ -2147,6 +2209,7 @@ GCC_handle_destroy (void *cls,
2147 { 2209 {
2148 LOG (GNUNET_ERROR_TYPE_DEBUG, " directly destroying connection!\n"); 2210 LOG (GNUNET_ERROR_TYPE_DEBUG, " directly destroying connection!\n");
2149 GCC_destroy (c); 2211 GCC_destroy (c);
2212 check_connections ();
2150 return GNUNET_OK; 2213 return GNUNET_OK;
2151 } 2214 }
2152 c->destroy = GNUNET_YES; 2215 c->destroy = GNUNET_YES;
@@ -2156,6 +2219,7 @@ GCC_handle_destroy (void *cls,
2156 GCT_remove_connection (c->t, c); 2219 GCT_remove_connection (c->t, c);
2157 c->t = NULL; 2220 c->t = NULL;
2158 } 2221 }
2222 check_connections ();
2159 2223
2160 return GNUNET_OK; 2224 return GNUNET_OK;
2161} 2225}
@@ -2287,9 +2351,8 @@ check_message (const struct GNUNET_MessageHeader *message,
2287 * 2351 *
2288 * @param peer Peer identity this notification is about. 2352 * @param peer Peer identity this notification is about.
2289 * @param msg Encrypted message. 2353 * @param msg Encrypted message.
2290 * 2354 * @return #GNUNET_OK to keep the connection open,
2291 * @return GNUNET_OK to keep the connection open, 2355 * #GNUNET_SYSERR to close it (signal serious error)
2292 * GNUNET_SYSERR to close it (signal serious error)
2293 */ 2356 */
2294static int 2357static int
2295handle_cadet_encrypted (const struct GNUNET_PeerIdentity *peer, 2358handle_cadet_encrypted (const struct GNUNET_PeerIdentity *peer,
@@ -2305,6 +2368,7 @@ handle_cadet_encrypted (const struct GNUNET_PeerIdentity *peer,
2305 uint32_t ttl; 2368 uint32_t ttl;
2306 int fwd; 2369 int fwd;
2307 2370
2371 check_connections ();
2308 if (GNUNET_MESSAGE_TYPE_CADET_AX == ntohs (message->type)) 2372 if (GNUNET_MESSAGE_TYPE_CADET_AX == ntohs (message->type))
2309 { 2373 {
2310 overhead = sizeof (struct GNUNET_CADET_AX); 2374 overhead = sizeof (struct GNUNET_CADET_AX);
@@ -2329,7 +2393,10 @@ handle_cadet_encrypted (const struct GNUNET_PeerIdentity *peer,
2329 2393
2330 /* If something went wrong, discard message. */ 2394 /* If something went wrong, discard message. */
2331 if (GNUNET_SYSERR == fwd) 2395 if (GNUNET_SYSERR == fwd)
2396 {
2397 check_connections ();
2332 return GNUNET_OK; 2398 return GNUNET_OK;
2399 }
2333 2400
2334 /* Is this message for us? */ 2401 /* Is this message for us? */
2335 if (GCC_is_terminal (c, fwd)) 2402 if (GCC_is_terminal (c, fwd))
@@ -2343,6 +2410,7 @@ handle_cadet_encrypted (const struct GNUNET_PeerIdentity *peer,
2343 } 2410 }
2344 GCT_handle_encrypted (c->t, message); 2411 GCT_handle_encrypted (c->t, message);
2345 GCC_send_ack (c, fwd, GNUNET_NO); 2412 GCC_send_ack (c, fwd, GNUNET_NO);
2413 check_connections ();
2346 return GNUNET_OK; 2414 return GNUNET_OK;
2347 } 2415 }
2348 2416
@@ -2357,6 +2425,7 @@ handle_cadet_encrypted (const struct GNUNET_PeerIdentity *peer,
2357 GNUNET_STATISTICS_update (stats, "# TTL drops", 1, GNUNET_NO); 2425 GNUNET_STATISTICS_update (stats, "# TTL drops", 1, GNUNET_NO);
2358 LOG (GNUNET_ERROR_TYPE_WARNING, " TTL is 0, DROPPING!\n"); 2426 LOG (GNUNET_ERROR_TYPE_WARNING, " TTL is 0, DROPPING!\n");
2359 GCC_send_ack (c, fwd, GNUNET_NO); 2427 GCC_send_ack (c, fwd, GNUNET_NO);
2428 check_connections ();
2360 return GNUNET_OK; 2429 return GNUNET_OK;
2361 } 2430 }
2362 } 2431 }
@@ -2364,18 +2433,18 @@ handle_cadet_encrypted (const struct GNUNET_PeerIdentity *peer,
2364 GNUNET_STATISTICS_update (stats, "# messages forwarded", 1, GNUNET_NO); 2433 GNUNET_STATISTICS_update (stats, "# messages forwarded", 1, GNUNET_NO);
2365 GNUNET_assert (NULL == GCC_send_prebuilt_message (message, 0, 0, c, fwd, 2434 GNUNET_assert (NULL == GCC_send_prebuilt_message (message, 0, 0, c, fwd,
2366 GNUNET_NO, NULL, NULL)); 2435 GNUNET_NO, NULL, NULL));
2367 2436 check_connections ();
2368 return GNUNET_OK; 2437 return GNUNET_OK;
2369} 2438}
2370 2439
2440
2371/** 2441/**
2372 * Generic handler for cadet network encrypted traffic. 2442 * Generic handler for cadet network encrypted traffic.
2373 * 2443 *
2374 * @param peer Peer identity this notification is about. 2444 * @param peer Peer identity this notification is about.
2375 * @param msg Encrypted message. 2445 * @param msg Encrypted message.
2376 * 2446 * @return #GNUNET_OK to keep the connection open,
2377 * @return GNUNET_OK to keep the connection open, 2447 * #GNUNET_SYSERR to close it (signal serious error)
2378 * GNUNET_SYSERR to close it (signal serious error)
2379 */ 2448 */
2380static int 2449static int
2381handle_cadet_kx (const struct GNUNET_PeerIdentity *peer, 2450handle_cadet_kx (const struct GNUNET_PeerIdentity *peer,
@@ -2386,6 +2455,7 @@ handle_cadet_kx (const struct GNUNET_PeerIdentity *peer,
2386 size_t expected_size; 2455 size_t expected_size;
2387 int fwd; 2456 int fwd;
2388 2457
2458 check_connections ();
2389 cid = &msg->cid; 2459 cid = &msg->cid;
2390 log_message (&msg->header, peer, cid); 2460 log_message (&msg->header, peer, cid);
2391 2461
@@ -2409,6 +2479,7 @@ handle_cadet_kx (const struct GNUNET_PeerIdentity *peer,
2409 return GNUNET_OK; 2479 return GNUNET_OK;
2410 } 2480 }
2411 GCT_handle_kx (c->t, &msg[1].header); 2481 GCT_handle_kx (c->t, &msg[1].header);
2482 check_connections ();
2412 return GNUNET_OK; 2483 return GNUNET_OK;
2413 } 2484 }
2414 2485
@@ -2417,7 +2488,7 @@ handle_cadet_kx (const struct GNUNET_PeerIdentity *peer,
2417 GNUNET_STATISTICS_update (stats, "# messages forwarded", 1, GNUNET_NO); 2488 GNUNET_STATISTICS_update (stats, "# messages forwarded", 1, GNUNET_NO);
2418 GNUNET_assert (NULL == GCC_send_prebuilt_message (&msg->header, 0, 0, c, fwd, 2489 GNUNET_assert (NULL == GCC_send_prebuilt_message (&msg->header, 0, 0, c, fwd,
2419 GNUNET_NO, NULL, NULL)); 2490 GNUNET_NO, NULL, NULL));
2420 2491 check_connections ();
2421 return GNUNET_OK; 2492 return GNUNET_OK;
2422} 2493}
2423 2494
@@ -2428,14 +2499,15 @@ handle_cadet_kx (const struct GNUNET_PeerIdentity *peer,
2428 * @param cls Closure (unused). 2499 * @param cls Closure (unused).
2429 * @param message Message received. 2500 * @param message Message received.
2430 * @param peer Peer who sent the message. 2501 * @param peer Peer who sent the message.
2431 * 2502 * @return #GNUNET_OK to keep the connection open,
2432 * @return GNUNET_OK to keep the connection open, 2503 * #GNUNET_SYSERR to close it (signal serious error)
2433 * GNUNET_SYSERR to close it (signal serious error)
2434 */ 2504 */
2435int 2505int
2436GCC_handle_kx (void *cls, const struct GNUNET_PeerIdentity *peer, 2506GCC_handle_kx (void *cls,
2507 const struct GNUNET_PeerIdentity *peer,
2437 const struct GNUNET_MessageHeader *message) 2508 const struct GNUNET_MessageHeader *message)
2438{ 2509{
2510 check_connections ();
2439 return handle_cadet_kx (peer, (struct GNUNET_CADET_KX *) message); 2511 return handle_cadet_kx (peer, (struct GNUNET_CADET_KX *) message);
2440} 2512}
2441 2513
@@ -2446,14 +2518,14 @@ GCC_handle_kx (void *cls, const struct GNUNET_PeerIdentity *peer,
2446 * @param cls Closure (unused). 2518 * @param cls Closure (unused).
2447 * @param message Message received. 2519 * @param message Message received.
2448 * @param peer Peer who sent the message. 2520 * @param peer Peer who sent the message.
2449 * 2521 * @return #GNUNET_OK to keep the connection open,
2450 * @return GNUNET_OK to keep the connection open, 2522 * #GNUNET_SYSERR to close it (signal serious error)
2451 * GNUNET_SYSERR to close it (signal serious error)
2452 */ 2523 */
2453int 2524int
2454GCC_handle_encrypted (void *cls, const struct GNUNET_PeerIdentity *peer, 2525GCC_handle_encrypted (void *cls, const struct GNUNET_PeerIdentity *peer,
2455 const struct GNUNET_MessageHeader *message) 2526 const struct GNUNET_MessageHeader *message)
2456{ 2527{
2528 check_connections ();
2457 return handle_cadet_encrypted (peer, message); 2529 return handle_cadet_encrypted (peer, message);
2458} 2530}
2459 2531
@@ -2464,9 +2536,8 @@ GCC_handle_encrypted (void *cls, const struct GNUNET_PeerIdentity *peer,
2464 * @param cls closure 2536 * @param cls closure
2465 * @param message message 2537 * @param message message
2466 * @param peer peer identity this notification is about 2538 * @param peer peer identity this notification is about
2467 * 2539 * @return #GNUNET_OK to keep the connection open,
2468 * @return GNUNET_OK to keep the connection open, 2540 * #GNUNET_SYSERR to close it (signal serious error)
2469 * GNUNET_SYSERR to close it (signal serious error)
2470 */ 2541 */
2471int 2542int
2472GCC_handle_ack (void *cls, const struct GNUNET_PeerIdentity *peer, 2543GCC_handle_ack (void *cls, const struct GNUNET_PeerIdentity *peer,
@@ -2479,6 +2550,7 @@ GCC_handle_ack (void *cls, const struct GNUNET_PeerIdentity *peer,
2479 uint32_t ack; 2550 uint32_t ack;
2480 int fwd; 2551 int fwd;
2481 2552
2553 check_connections ();
2482 msg = (struct GNUNET_CADET_ACK *) message; 2554 msg = (struct GNUNET_CADET_ACK *) message;
2483 log_message (message, peer, &msg->cid); 2555 log_message (message, peer, &msg->cid);
2484 c = connection_get (&msg->cid); 2556 c = connection_get (&msg->cid);
@@ -2487,6 +2559,7 @@ GCC_handle_ack (void *cls, const struct GNUNET_PeerIdentity *peer,
2487 GNUNET_STATISTICS_update (stats, "# ack on unknown connection", 1, 2559 GNUNET_STATISTICS_update (stats, "# ack on unknown connection", 1,
2488 GNUNET_NO); 2560 GNUNET_NO);
2489 send_broken_unknown (&msg->cid, &my_full_id, NULL, peer); 2561 send_broken_unknown (&msg->cid, &my_full_id, NULL, peer);
2562 check_connections ();
2490 return GNUNET_OK; 2563 return GNUNET_OK;
2491 } 2564 }
2492 2565
@@ -2525,7 +2598,7 @@ GCC_handle_ack (void *cls, const struct GNUNET_PeerIdentity *peer,
2525 } 2598 }
2526 2599
2527 connection_unlock_queue (c, fwd); 2600 connection_unlock_queue (c, fwd);
2528 2601 check_connections ();
2529 return GNUNET_OK; 2602 return GNUNET_OK;
2530} 2603}
2531 2604
@@ -2536,12 +2609,12 @@ GCC_handle_ack (void *cls, const struct GNUNET_PeerIdentity *peer,
2536 * @param cls closure 2609 * @param cls closure
2537 * @param message message 2610 * @param message message
2538 * @param peer peer identity this notification is about 2611 * @param peer peer identity this notification is about
2539 * 2612 * @return #GNUNET_OK to keep the connection open,
2540 * @return GNUNET_OK to keep the connection open, 2613 * #GNUNET_SYSERR to close it (signal serious error)
2541 * GNUNET_SYSERR to close it (signal serious error)
2542 */ 2614 */
2543int 2615int
2544GCC_handle_poll (void *cls, const struct GNUNET_PeerIdentity *peer, 2616GCC_handle_poll (void *cls,
2617 const struct GNUNET_PeerIdentity *peer,
2545 const struct GNUNET_MessageHeader *message) 2618 const struct GNUNET_MessageHeader *message)
2546{ 2619{
2547 struct GNUNET_CADET_Poll *msg; 2620 struct GNUNET_CADET_Poll *msg;
@@ -2551,6 +2624,7 @@ GCC_handle_poll (void *cls, const struct GNUNET_PeerIdentity *peer,
2551 uint32_t pid; 2624 uint32_t pid;
2552 int fwd; 2625 int fwd;
2553 2626
2627 check_connections ();
2554 msg = (struct GNUNET_CADET_Poll *) message; 2628 msg = (struct GNUNET_CADET_Poll *) message;
2555 log_message (message, peer, &msg->cid); 2629 log_message (message, peer, &msg->cid);
2556 c = connection_get (&msg->cid); 2630 c = connection_get (&msg->cid);
@@ -2561,6 +2635,7 @@ GCC_handle_poll (void *cls, const struct GNUNET_PeerIdentity *peer,
2561 LOG (GNUNET_ERROR_TYPE_DEBUG, "POLL message on unknown connection %s!\n", 2635 LOG (GNUNET_ERROR_TYPE_DEBUG, "POLL message on unknown connection %s!\n",
2562 GNUNET_h2s (GC_h2hc (&msg->cid))); 2636 GNUNET_h2s (GC_h2hc (&msg->cid)));
2563 send_broken_unknown (&msg->cid, &my_full_id, NULL, peer); 2637 send_broken_unknown (&msg->cid, &my_full_id, NULL, peer);
2638 check_connections ();
2564 return GNUNET_OK; 2639 return GNUNET_OK;
2565 } 2640 }
2566 2641
@@ -2591,6 +2666,7 @@ GCC_handle_poll (void *cls, const struct GNUNET_PeerIdentity *peer,
2591 fc->last_pid_recv = pid; 2666 fc->last_pid_recv = pid;
2592 fwd = fc == &c->bck_fc; 2667 fwd = fc == &c->bck_fc;
2593 GCC_send_ack (c, fwd, GNUNET_YES); 2668 GCC_send_ack (c, fwd, GNUNET_YES);
2669 check_connections ();
2594 2670
2595 return GNUNET_OK; 2671 return GNUNET_OK;
2596} 2672}
@@ -2609,6 +2685,7 @@ GCC_send_ack (struct CadetConnection *c, int fwd, int force)
2609{ 2685{
2610 unsigned int buffer; 2686 unsigned int buffer;
2611 2687
2688 check_connections ();
2612 LOG (GNUNET_ERROR_TYPE_DEBUG, "GCC send %s ACK on %s\n", 2689 LOG (GNUNET_ERROR_TYPE_DEBUG, "GCC send %s ACK on %s\n",
2613 GC_f2s (fwd), GCC_2s (c)); 2690 GC_f2s (fwd), GCC_2s (c));
2614 2691
@@ -2621,6 +2698,7 @@ GCC_send_ack (struct CadetConnection *c, int fwd, int force)
2621 if (GNUNET_NO != c->destroy) 2698 if (GNUNET_NO != c->destroy)
2622 { 2699 {
2623 LOG (GNUNET_ERROR_TYPE_DEBUG, " being destroyed, why bother...\n"); 2700 LOG (GNUNET_ERROR_TYPE_DEBUG, " being destroyed, why bother...\n");
2701 check_connections ();
2624 return; 2702 return;
2625 } 2703 }
2626 2704
@@ -2637,7 +2715,10 @@ GCC_send_ack (struct CadetConnection *c, int fwd, int force)
2637 } 2715 }
2638 LOG (GNUNET_ERROR_TYPE_DEBUG, " buffer available: %u\n", buffer); 2716 LOG (GNUNET_ERROR_TYPE_DEBUG, " buffer available: %u\n", buffer);
2639 if (0 == buffer && GNUNET_NO == force) 2717 if (0 == buffer && GNUNET_NO == force)
2718 {
2719 check_connections ();
2640 return; 2720 return;
2721 }
2641 2722
2642 /* Send available buffer space */ 2723 /* Send available buffer space */
2643 if (GCC_is_origin (c, fwd)) 2724 if (GCC_is_origin (c, fwd))
@@ -2651,6 +2732,7 @@ GCC_send_ack (struct CadetConnection *c, int fwd, int force)
2651 LOG (GNUNET_ERROR_TYPE_DEBUG, " sending on connection\n"); 2732 LOG (GNUNET_ERROR_TYPE_DEBUG, " sending on connection\n");
2652 send_ack (c, buffer, fwd, force); 2733 send_ack (c, buffer, fwd, force);
2653 } 2734 }
2735 check_connections ();
2654} 2736}
2655 2737
2656 2738
@@ -2725,6 +2807,7 @@ shutdown_iterator (void *cls,
2725void 2807void
2726GCC_shutdown (void) 2808GCC_shutdown (void)
2727{ 2809{
2810 check_connections ();
2728 GNUNET_CONTAINER_multihashmap_iterate (connections, 2811 GNUNET_CONTAINER_multihashmap_iterate (connections,
2729 &shutdown_iterator, 2812 &shutdown_iterator,
2730 NULL); 2813 NULL);
@@ -2752,6 +2835,7 @@ GCC_new (const struct GNUNET_CADET_Hash *cid,
2752 struct CadetConnection *c; 2835 struct CadetConnection *c;
2753 struct CadetPeerPath *p; 2836 struct CadetPeerPath *p;
2754 2837
2838 check_connections ();
2755 p = path_duplicate (path); 2839 p = path_duplicate (path);
2756 c = GNUNET_new (struct CadetConnection); 2840 c = GNUNET_new (struct CadetConnection);
2757 c->id = *cid; 2841 c->id = *cid;
@@ -2787,6 +2871,7 @@ GCC_new (const struct GNUNET_CADET_Hash *cid,
2787 return NULL; 2871 return NULL;
2788 } 2872 }
2789 LOG (GNUNET_ERROR_TYPE_INFO, "New connection %s\n", GCC_2s (c)); 2873 LOG (GNUNET_ERROR_TYPE_INFO, "New connection %s\n", GCC_2s (c));
2874 check_connections ();
2790 return c; 2875 return c;
2791} 2876}
2792 2877
@@ -2794,6 +2879,7 @@ GCC_new (const struct GNUNET_CADET_Hash *cid,
2794void 2879void
2795GCC_destroy (struct CadetConnection *c) 2880GCC_destroy (struct CadetConnection *c)
2796{ 2881{
2882 check_connections ();
2797 if (NULL == c) 2883 if (NULL == c)
2798 { 2884 {
2799 GNUNET_break (0); 2885 GNUNET_break (0);
@@ -2867,6 +2953,7 @@ GCC_destroy (struct CadetConnection *c)
2867 -1, 2953 -1,
2868 GNUNET_NO); 2954 GNUNET_NO);
2869 GNUNET_free (c); 2955 GNUNET_free (c);
2956 check_connections ();
2870} 2957}
2871 2958
2872 2959
@@ -2963,6 +3050,7 @@ GCC_get_buffer (struct CadetConnection *c, int fwd)
2963 return (fc->queue_max - fc->queue_n); 3050 return (fc->queue_max - fc->queue_n);
2964} 3051}
2965 3052
3053
2966/** 3054/**
2967 * Get how many messages have we allowed to send to us from a direction. 3055 * Get how many messages have we allowed to send to us from a direction.
2968 * 3056 *
@@ -2985,6 +3073,7 @@ GCC_get_allowed (struct CadetConnection *c, int fwd)
2985 return (fc->last_ack_sent - fc->last_pid_recv); 3073 return (fc->last_ack_sent - fc->last_pid_recv);
2986} 3074}
2987 3075
3076
2988/** 3077/**
2989 * Get messages queued in a connection. 3078 * Get messages queued in a connection.
2990 * 3079 *
@@ -3056,6 +3145,7 @@ GCC_notify_broken (struct CadetConnection *c,
3056 struct CadetPeer *hop; 3145 struct CadetPeer *hop;
3057 int fwd; 3146 int fwd;
3058 3147
3148 check_connections ();
3059 LOG (GNUNET_ERROR_TYPE_DEBUG, 3149 LOG (GNUNET_ERROR_TYPE_DEBUG,
3060 "Notify broken on %s due to %s disconnect\n", 3150 "Notify broken on %s due to %s disconnect\n",
3061 GCC_2s (c), 3151 GCC_2s (c),
@@ -3072,6 +3162,7 @@ GCC_notify_broken (struct CadetConnection *c,
3072 { 3162 {
3073 /* Local shutdown, no one to notify about this. */ 3163 /* Local shutdown, no one to notify about this. */
3074 GCC_destroy (c); 3164 GCC_destroy (c);
3165 check_connections ();
3075 return; 3166 return;
3076 } 3167 }
3077 if (GNUNET_NO == c->destroy) 3168 if (GNUNET_NO == c->destroy)
@@ -3086,7 +3177,8 @@ GCC_notify_broken (struct CadetConnection *c,
3086 /** 3177 /**
3087 * Cancel all queues, if no message is left, connection will be destroyed. 3178 * Cancel all queues, if no message is left, connection will be destroyed.
3088 */ 3179 */
3089 connection_cancel_queues (c, !fwd); 3180 connection_cancel_queues (c, ! fwd);
3181 check_connections ();
3090} 3182}
3091 3183
3092 3184
@@ -3138,7 +3230,8 @@ GCC_is_sendable (struct CadetConnection *c, int fwd)
3138{ 3230{
3139 struct CadetFlowControl *fc; 3231 struct CadetFlowControl *fc;
3140 3232
3141 LOG (GNUNET_ERROR_TYPE_DEBUG, " checking sendability of %s traffic on %s\n", 3233 LOG (GNUNET_ERROR_TYPE_DEBUG,
3234 " checking sendability of %s traffic on %s\n",
3142 GC_f2s (fwd), GCC_2s (c)); 3235 GC_f2s (fwd), GCC_2s (c));
3143 if (NULL == c) 3236 if (NULL == c)
3144 { 3237 {
@@ -3172,6 +3265,7 @@ GCC_is_direct (struct CadetConnection *c)
3172 return (c->path->length == 2) ? GNUNET_YES : GNUNET_NO; 3265 return (c->path->length == 2) ? GNUNET_YES : GNUNET_NO;
3173} 3266}
3174 3267
3268
3175/** 3269/**
3176 * Sends an already built message on a connection, properly registering 3270 * Sends an already built message on a connection, properly registering
3177 * all used resources. 3271 * all used resources.
@@ -3202,6 +3296,7 @@ GCC_send_prebuilt_message (const struct GNUNET_MessageHeader *message,
3202 uint16_t type; 3296 uint16_t type;
3203 int droppable; 3297 int droppable;
3204 3298
3299 check_connections ();
3205 size = ntohs (message->size); 3300 size = ntohs (message->size);
3206 data = GNUNET_malloc (size); 3301 data = GNUNET_malloc (size);
3207 memcpy (data, message, size); 3302 memcpy (data, message, size);
@@ -3323,10 +3418,12 @@ GCC_send_prebuilt_message (const struct GNUNET_MessageHeader *message,
3323 LOG (GNUNET_ERROR_TYPE_DEBUG, "dropping msg on %s, NULL q\n", GCC_2s (c)); 3418 LOG (GNUNET_ERROR_TYPE_DEBUG, "dropping msg on %s, NULL q\n", GCC_2s (c));
3324 GNUNET_free (data); 3419 GNUNET_free (data);
3325 GNUNET_free (q); 3420 GNUNET_free (q);
3421 check_connections ();
3326 return NULL; 3422 return NULL;
3327 } 3423 }
3328 q->cont = cont; 3424 q->cont = cont;
3329 q->cont_cls = cont_cls; 3425 q->cont_cls = cont_cls;
3426 check_connections ();
3330 return (NULL == cont) ? NULL : q; 3427 return (NULL == cont) ? NULL : q;
3331} 3428}
3332 3429
@@ -3347,6 +3444,7 @@ GCC_cancel (struct CadetConnectionQueue *q)
3347 3444
3348 /* queue destroy calls message_sent, which calls q->cont and frees q */ 3445 /* queue destroy calls message_sent, which calls q->cont and frees q */
3349 GCP_queue_destroy (q->q, GNUNET_YES, GNUNET_NO, 0); 3446 GCP_queue_destroy (q->q, GNUNET_YES, GNUNET_NO, 0);
3447 check_connections ();
3350} 3448}
3351 3449
3352 3450
@@ -3362,6 +3460,7 @@ GCC_send_create (struct CadetConnection *connection)
3362 enum CadetTunnelCState state; 3460 enum CadetTunnelCState state;
3363 size_t size; 3461 size_t size;
3364 3462
3463 check_connections ();
3365 size = sizeof (struct GNUNET_CADET_ConnectionCreate); 3464 size = sizeof (struct GNUNET_CADET_ConnectionCreate);
3366 size += connection->path->length * sizeof (struct GNUNET_PeerIdentity); 3465 size += connection->path->length * sizeof (struct GNUNET_PeerIdentity);
3367 3466
@@ -3382,6 +3481,7 @@ GCC_send_create (struct CadetConnection *connection)
3382 GCT_change_cstate (connection->t, CADET_TUNNEL_WAITING); 3481 GCT_change_cstate (connection->t, CADET_TUNNEL_WAITING);
3383 if (CADET_CONNECTION_NEW == connection->state) 3482 if (CADET_CONNECTION_NEW == connection->state)
3384 connection_change_state (connection, CADET_CONNECTION_SENT); 3483 connection_change_state (connection, CADET_CONNECTION_SENT);
3484 check_connections ();
3385} 3485}
3386 3486
3387 3487
@@ -3401,7 +3501,7 @@ GCC_send_destroy (struct CadetConnection *c)
3401 3501
3402 if (GNUNET_YES == c->destroy) 3502 if (GNUNET_YES == c->destroy)
3403 return; 3503 return;
3404 3504 check_connections ();
3405 msg.header.size = htons (sizeof (msg)); 3505 msg.header.size = htons (sizeof (msg));
3406 msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY); 3506 msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY);
3407 msg.cid = c->id; 3507 msg.cid = c->id;
@@ -3419,6 +3519,7 @@ GCC_send_destroy (struct CadetConnection *c)
3419 NULL, NULL)); 3519 NULL, NULL));
3420 c->destroy = GNUNET_YES; 3520 c->destroy = GNUNET_YES;
3421 c->state = CADET_CONNECTION_DESTROYED; 3521 c->state = CADET_CONNECTION_DESTROYED;
3522 check_connections ();
3422} 3523}
3423 3524
3424 3525
@@ -3474,6 +3575,7 @@ GCC_stop_poll (struct CadetConnection *c, int fwd)
3474 } 3575 }
3475} 3576}
3476 3577
3578
3477/** 3579/**
3478 * Get a (static) string for a connection. 3580 * Get a (static) string for a connection.
3479 * 3581 *
diff --git a/src/cadet/gnunet-service-cadet_connection.h b/src/cadet/gnunet-service-cadet_connection.h
index b72536533..a6d0a7096 100644
--- a/src/cadet/gnunet-service-cadet_connection.h
+++ b/src/cadet/gnunet-service-cadet_connection.h
@@ -102,10 +102,14 @@ struct CadetConnectionQueue;
102 * @param fwd Was this a FWD going message? 102 * @param fwd Was this a FWD going message?
103 * @param size Size of the message. 103 * @param size Size of the message.
104 */ 104 */
105typedef void (*GCC_sent) (void *cls, 105typedef void
106 struct CadetConnection *c, 106(*GCC_sent) (void *cls,
107 struct CadetConnectionQueue *q, 107 struct CadetConnection *c,
108 uint16_t type, int fwd, size_t size); 108 struct CadetConnectionQueue *q,
109 uint16_t type,
110 int fwd,
111 size_t size);
112
109 113
110/** 114/**
111 * Core handler for connection creation. 115 * Core handler for connection creation.
@@ -113,37 +117,38 @@ typedef void (*GCC_sent) (void *cls,
113 * @param cls Closure (unused). 117 * @param cls Closure (unused).
114 * @param peer Sender (neighbor). 118 * @param peer Sender (neighbor).
115 * @param message Message. 119 * @param message Message.
116 * 120 * @return #GNUNET_OK to keep the connection open,
117 * @return GNUNET_OK to keep the connection open, 121 * #GNUNET_SYSERR to close it (signal serious error)
118 * GNUNET_SYSERR to close it (signal serious error)
119 */ 122 */
120int 123int
121GCC_handle_create (void *cls, const struct GNUNET_PeerIdentity *peer, 124GCC_handle_create (void *cls,
125 const struct GNUNET_PeerIdentity *peer,
122 const struct GNUNET_MessageHeader *message); 126 const struct GNUNET_MessageHeader *message);
123 127
128
124/** 129/**
125 * Core handler for path confirmations. 130 * Core handler for path confirmations.
126 * 131 *
127 * @param cls closure 132 * @param cls closure
128 * @param message message 133 * @param message message
129 * @param peer peer identity this notification is about 134 * @param peer peer identity this notification is about
130 * 135 * @return #GNUNET_OK to keep the connection open,
131 * @return GNUNET_OK to keep the connection open, 136 * #GNUNET_SYSERR to close it (signal serious error)
132 * GNUNET_SYSERR to close it (signal serious error)
133 */ 137 */
134int 138int
135GCC_handle_confirm (void *cls, const struct GNUNET_PeerIdentity *peer, 139GCC_handle_confirm (void *cls,
140 const struct GNUNET_PeerIdentity *peer,
136 const struct GNUNET_MessageHeader *message); 141 const struct GNUNET_MessageHeader *message);
137 142
143
138/** 144/**
139 * Core handler for notifications of broken paths 145 * Core handler for notifications of broken paths
140 * 146 *
141 * @param cls Closure (unused). 147 * @param cls Closure (unused).
142 * @param id Peer identity of sending neighbor. 148 * @param id Peer identity of sending neighbor.
143 * @param message Message. 149 * @param message Message.
144 * 150 * @return #GNUNET_OK to keep the connection open,
145 * @return GNUNET_OK to keep the connection open, 151 * #GNUNET_SYSERR to close it (signal serious error)
146 * GNUNET_SYSERR to close it (signal serious error)
147 */ 152 */
148int 153int
149GCC_handle_broken (void* cls, 154GCC_handle_broken (void* cls,
diff --git a/src/cadet/gnunet-service-cadet_peer.c b/src/cadet/gnunet-service-cadet_peer.c
index eaad9136d..488c74b38 100644
--- a/src/cadet/gnunet-service-cadet_peer.c
+++ b/src/cadet/gnunet-service-cadet_peer.c
@@ -2198,6 +2198,26 @@ GCP_remove_path (struct CadetPeer *peer, struct CadetPeerPath *path)
2198 2198
2199 2199
2200/** 2200/**
2201 * Check that we are aware of a connection from a neighboring peer.
2202 *
2203 * @param peer Peer to the connection is with
2204 * @param c Connection that should be in the map with this peer.
2205 */
2206void
2207GCP_check_connection (const struct CadetPeer *peer,
2208 const struct CadetConnection *c)
2209{
2210 if ( (NULL == peer) ||
2211 (NULL == peer->connections) )
2212 return;
2213 GNUNET_assert (GNUNET_YES ==
2214 GNUNET_CONTAINER_multihashmap_contains_value (peer->connections,
2215 GCC_get_h (c),
2216 c));
2217}
2218
2219
2220/**
2201 * Remove a connection from a neighboring peer. 2221 * Remove a connection from a neighboring peer.
2202 * 2222 *
2203 * @param peer Peer to remove connection from. 2223 * @param peer Peer to remove connection from.
diff --git a/src/cadet/gnunet-service-cadet_peer.h b/src/cadet/gnunet-service-cadet_peer.h
index 2bebc8d83..cd1873824 100644
--- a/src/cadet/gnunet-service-cadet_peer.h
+++ b/src/cadet/gnunet-service-cadet_peer.h
@@ -314,6 +314,17 @@ GCP_remove_path (struct CadetPeer *peer,
314 314
315 315
316/** 316/**
317 * Check that we are aware of a connection from a neighboring peer.
318 *
319 * @param peer Peer to the connection is with
320 * @param c Connection that should be in the map with this peer.
321 */
322void
323GCP_check_connection (const struct CadetPeer *peer,
324 const struct CadetConnection *c);
325
326
327/**
317 * Remove a connection from a neighboring peer. 328 * Remove a connection from a neighboring peer.
318 * 329 *
319 * @param peer Peer to remove connection from. 330 * @param peer Peer to remove connection from.