diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/block/bg_bf.c | 4 | ||||
-rw-r--r-- | src/dht/gnunet-service-dht_neighbours.c | 151 |
2 files changed, 76 insertions, 79 deletions
diff --git a/src/block/bg_bf.c b/src/block/bg_bf.c index ae8ee0e51..601f605a2 100644 --- a/src/block/bg_bf.c +++ b/src/block/bg_bf.c | |||
@@ -61,7 +61,7 @@ struct BfGroupInternals | |||
61 | * @return #GNUNET_OK on success, #GNUNET_NO if serialization is not | 61 | * @return #GNUNET_OK on success, #GNUNET_NO if serialization is not |
62 | * supported, #GNUNET_SYSERR on error | 62 | * supported, #GNUNET_SYSERR on error |
63 | */ | 63 | */ |
64 | static int | 64 | static enum GNUNET_GenericReturnValue |
65 | bf_group_serialize_cb (struct GNUNET_BLOCK_Group *bg, | 65 | bf_group_serialize_cb (struct GNUNET_BLOCK_Group *bg, |
66 | uint32_t *nonce, | 66 | uint32_t *nonce, |
67 | void **raw_data, | 67 | void **raw_data, |
@@ -124,7 +124,7 @@ bf_group_mark_seen_cb (struct GNUNET_BLOCK_Group *bg, | |||
124 | * @return #GNUNET_OK on success, #GNUNET_NO if the nonces were different and thus | 124 | * @return #GNUNET_OK on success, #GNUNET_NO if the nonces were different and thus |
125 | * we failed. | 125 | * we failed. |
126 | */ | 126 | */ |
127 | static int | 127 | static enum GNUNET_GenericReturnValue |
128 | bf_group_merge_cb (struct GNUNET_BLOCK_Group *bg1, | 128 | bf_group_merge_cb (struct GNUNET_BLOCK_Group *bg1, |
129 | const struct GNUNET_BLOCK_Group *bg2) | 129 | const struct GNUNET_BLOCK_Group *bg2) |
130 | { | 130 | { |
diff --git a/src/dht/gnunet-service-dht_neighbours.c b/src/dht/gnunet-service-dht_neighbours.c index 9aea34354..ea1f454bd 100644 --- a/src/dht/gnunet-service-dht_neighbours.c +++ b/src/dht/gnunet-service-dht_neighbours.c | |||
@@ -39,10 +39,15 @@ | |||
39 | __VA_ARGS__) | 39 | __VA_ARGS__) |
40 | 40 | ||
41 | /** | 41 | /** |
42 | * Enable slow sanity checks to debug issues. | 42 | * Enable slow sanity checks to debug issues. |
43 | * 0: do not check | 43 | * |
44 | * 1: check all external inputs | 44 | * TODO: might want to eventually implement probabilistic |
45 | * 2: check internal computations as well | 45 | * load-based path verification, but for now it is all or nothing |
46 | * based on this define. | ||
47 | * | ||
48 | * 0: do not check -- if signatures become performance critical | ||
49 | * 1: check all external inputs -- normal production for now | ||
50 | * 2: check internal computations as well -- for debugging | ||
46 | */ | 51 | */ |
47 | #define SANITY_CHECKS 2 | 52 | #define SANITY_CHECKS 2 |
48 | 53 | ||
@@ -1796,45 +1801,6 @@ handle_dht_p2p_put (void *cls, | |||
1796 | GNUNET_break_op (0); | 1801 | GNUNET_break_op (0); |
1797 | return; | 1802 | return; |
1798 | } | 1803 | } |
1799 | { | ||
1800 | #if SANITY_CHECKS | ||
1801 | struct GNUNET_DHT_PathElement pp[putlen + 1]; | ||
1802 | |||
1803 | GNUNET_memcpy (pp, | ||
1804 | put_path, | ||
1805 | putlen * sizeof(struct GNUNET_DHT_PathElement)); | ||
1806 | pp[putlen].pred = peer->id; | ||
1807 | /* zero-out signature, not valid until we actually do forward! */ | ||
1808 | memset (&pp[putlen].sig, | ||
1809 | 0, | ||
1810 | sizeof (pp[putlen].sig)); | ||
1811 | for (unsigned int i = 0; i <= putlen; i++) | ||
1812 | { | ||
1813 | for (unsigned int j = 0; j < i; j++) | ||
1814 | { | ||
1815 | GNUNET_break (0 != | ||
1816 | GNUNET_memcmp (&pp[i].pred, | ||
1817 | &pp[j].pred)); | ||
1818 | } | ||
1819 | if (i < putlen) | ||
1820 | GNUNET_break (0 != | ||
1821 | GNUNET_memcmp (&pp[i].pred, | ||
1822 | &peer->id)); | ||
1823 | } | ||
1824 | if (0 != | ||
1825 | GNUNET_DHT_verify_path (bd.data, | ||
1826 | bd.data_size, | ||
1827 | bd.expiration_time, | ||
1828 | pp, | ||
1829 | putlen + 1, | ||
1830 | NULL, 0, /* get_path */ | ||
1831 | &GDS_my_identity)) | ||
1832 | { | ||
1833 | GNUNET_break_op (0); | ||
1834 | putlen = 0; | ||
1835 | } | ||
1836 | #endif | ||
1837 | } | ||
1838 | if (0 == (options & GNUNET_DHT_RO_RECORD_ROUTE)) | 1804 | if (0 == (options & GNUNET_DHT_RO_RECORD_ROUTE)) |
1839 | putlen = 0; | 1805 | putlen = 0; |
1840 | GNUNET_STATISTICS_update (GDS_stats, | 1806 | GNUNET_STATISTICS_update (GDS_stats, |
@@ -1888,6 +1854,8 @@ handle_dht_p2p_put (void *cls, | |||
1888 | bd.put_path_length = putlen + 1; | 1854 | bd.put_path_length = putlen + 1; |
1889 | if (0 != (options & GNUNET_DHT_RO_RECORD_ROUTE)) | 1855 | if (0 != (options & GNUNET_DHT_RO_RECORD_ROUTE)) |
1890 | { | 1856 | { |
1857 | unsigned int failure_offset; | ||
1858 | |||
1891 | GNUNET_memcpy (pp, | 1859 | GNUNET_memcpy (pp, |
1892 | put_path, | 1860 | put_path, |
1893 | putlen * sizeof(struct GNUNET_DHT_PathElement)); | 1861 | putlen * sizeof(struct GNUNET_DHT_PathElement)); |
@@ -1896,6 +1864,29 @@ handle_dht_p2p_put (void *cls, | |||
1896 | memset (&pp[putlen].sig, | 1864 | memset (&pp[putlen].sig, |
1897 | 0, | 1865 | 0, |
1898 | sizeof (pp[putlen].sig)); | 1866 | sizeof (pp[putlen].sig)); |
1867 | #if SANITY_CHECKS | ||
1868 | /* TODO: might want to eventually implement probabilistic | ||
1869 | load-based path verification, but for now it is all or nothing */ | ||
1870 | failure_offset | ||
1871 | = GNUNET_DHT_verify_path (bd.data, | ||
1872 | bd.data_size, | ||
1873 | bd.expiration_time, | ||
1874 | pp, | ||
1875 | putlen + 1, | ||
1876 | NULL, 0, /* get_path */ | ||
1877 | &GDS_my_identity); | ||
1878 | #else | ||
1879 | failure_offset = 0; | ||
1880 | #endif | ||
1881 | if (0 != failure_offset) | ||
1882 | { | ||
1883 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
1884 | "Recorded put path invalid at offset %u, truncating\n", | ||
1885 | failure_offset); | ||
1886 | GNUNET_assert (failure_offset <= putlen); | ||
1887 | bd.put_path = &pp[failure_offset]; | ||
1888 | bd.put_path_length = putlen - failure_offset; | ||
1889 | } | ||
1899 | } | 1890 | } |
1900 | else | 1891 | else |
1901 | { | 1892 | { |
@@ -2365,7 +2356,7 @@ handle_dht_p2p_result (void *cls, | |||
2365 | }; | 2356 | }; |
2366 | const struct GNUNET_DHT_PathElement *get_path | 2357 | const struct GNUNET_DHT_PathElement *get_path |
2367 | = &bd.put_path[bd.put_path_length]; | 2358 | = &bd.put_path[bd.put_path_length]; |
2368 | 2359 | ||
2369 | /* parse and validate message */ | 2360 | /* parse and validate message */ |
2370 | if (GNUNET_TIME_absolute_is_past (bd.expiration_time)) | 2361 | if (GNUNET_TIME_absolute_is_past (bd.expiration_time)) |
2371 | { | 2362 | { |
@@ -2389,34 +2380,6 @@ handle_dht_p2p_result (void *cls, | |||
2389 | GNUNET_break_op (0); | 2380 | GNUNET_break_op (0); |
2390 | return; | 2381 | return; |
2391 | } | 2382 | } |
2392 | { | ||
2393 | #if SANITY_CHECKS | ||
2394 | struct GNUNET_DHT_PathElement gpx[get_path_length + 1]; | ||
2395 | |||
2396 | memcpy (gpx, | ||
2397 | get_path, | ||
2398 | get_path_length | ||
2399 | * sizeof (struct GNUNET_DHT_PathElement)); | ||
2400 | gpx[get_path_length].pred = peer->id; | ||
2401 | memset (&gpx[get_path_length].sig, | ||
2402 | 0, | ||
2403 | sizeof (gpx[get_path_length].sig)); | ||
2404 | if (0 != | ||
2405 | GNUNET_DHT_verify_path (bd.data, | ||
2406 | bd.data_size, | ||
2407 | bd.expiration_time, | ||
2408 | bd.put_path, | ||
2409 | bd.put_path_length, | ||
2410 | gpx, | ||
2411 | get_path_length + 1, | ||
2412 | &GDS_my_identity)) | ||
2413 | { | ||
2414 | GNUNET_break_op (0); | ||
2415 | get_path_length = 0; | ||
2416 | bd.put_path_length = 0; | ||
2417 | } | ||
2418 | #endif | ||
2419 | } | ||
2420 | GNUNET_STATISTICS_update (GDS_stats, | 2383 | GNUNET_STATISTICS_update (GDS_stats, |
2421 | "# P2P RESULTS received", | 2384 | "# P2P RESULTS received", |
2422 | 1, | 2385 | 1, |
@@ -2434,18 +2397,17 @@ handle_dht_p2p_result (void *cls, | |||
2434 | bd.data_size, | 2397 | bd.data_size, |
2435 | &bd.key); | 2398 | &bd.key); |
2436 | if (GNUNET_NO == ret) | 2399 | if (GNUNET_NO == ret) |
2437 | { | ||
2438 | bd.key = prm->key; | 2400 | bd.key = prm->key; |
2439 | return; | ||
2440 | } | ||
2441 | } | 2401 | } |
2442 | 2402 | ||
2443 | /* if we got a HELLO, consider it for our own routing table */ | 2403 | /* if we got a HELLO, consider it for our own routing table */ |
2444 | hello_check (&bd); | 2404 | hello_check (&bd); |
2445 | 2405 | ||
2446 | /* Need to append 'peer' to 'get_path' (normal case) */ | 2406 | /* Need to append 'peer' to 'get_path' */ |
2447 | { | 2407 | { |
2448 | struct GNUNET_DHT_PathElement xget_path[get_path_length + 1]; | 2408 | struct GNUNET_DHT_PathElement xget_path[get_path_length + 1]; |
2409 | struct GNUNET_DHT_PathElement *gp = xget_path; | ||
2410 | unsigned int failure_offset; | ||
2449 | 2411 | ||
2450 | GNUNET_memcpy (xget_path, | 2412 | GNUNET_memcpy (xget_path, |
2451 | get_path, | 2413 | get_path, |
@@ -2454,6 +2416,41 @@ handle_dht_p2p_result (void *cls, | |||
2454 | memset (&xget_path[get_path_length].sig, | 2416 | memset (&xget_path[get_path_length].sig, |
2455 | 0, | 2417 | 0, |
2456 | sizeof (xget_path[get_path_length].sig)); | 2418 | sizeof (xget_path[get_path_length].sig)); |
2419 | #if SANITY_CHECKS | ||
2420 | /* TODO: might want to eventually implement probabilistic | ||
2421 | load-based path verification, but for now it is all or nothing */ | ||
2422 | failure_offset | ||
2423 | = GNUNET_DHT_verify_path (bd.data, | ||
2424 | bd.data_size, | ||
2425 | bd.expiration_time, | ||
2426 | bd.put_path, | ||
2427 | bd.put_path_length, | ||
2428 | xget_path, | ||
2429 | get_path_length + 1, | ||
2430 | &GDS_my_identity); | ||
2431 | #else | ||
2432 | failure_offset = 0; | ||
2433 | #endif | ||
2434 | if (0 != failure_offset) | ||
2435 | { | ||
2436 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
2437 | "Recorded path invalid at offset %u, truncating\n", | ||
2438 | failure_offset); | ||
2439 | GNUNET_assert (failure_offset <= bd.put_path_length + get_path_length); | ||
2440 | if (failure_offset >= bd.put_path_length) | ||
2441 | { | ||
2442 | /* failure on get path */ | ||
2443 | get_path_length -= (failure_offset - bd.put_path_length); | ||
2444 | gp = &xget_path[failure_offset - bd.put_path_length]; | ||
2445 | bd.put_path_length = 0; | ||
2446 | } | ||
2447 | else | ||
2448 | { | ||
2449 | /* failure on put path */ | ||
2450 | bd.put_path = &bd.put_path[failure_offset]; | ||
2451 | bd.put_path_length -= failure_offset; | ||
2452 | } | ||
2453 | } | ||
2457 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2454 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2458 | "Extending GET path of length %u with %s\n", | 2455 | "Extending GET path of length %u with %s\n", |
2459 | get_path_length, | 2456 | get_path_length, |
@@ -2461,7 +2458,7 @@ handle_dht_p2p_result (void *cls, | |||
2461 | GNUNET_break (process_reply_with_path (&bd, | 2458 | GNUNET_break (process_reply_with_path (&bd, |
2462 | &prm->key, | 2459 | &prm->key, |
2463 | get_path_length + 1, | 2460 | get_path_length + 1, |
2464 | xget_path)); | 2461 | gp)); |
2465 | } | 2462 | } |
2466 | } | 2463 | } |
2467 | 2464 | ||